2 #include <cxxtest/TestSuite.h>
4 #include "nr-compose.h"
5 #include "nr-compose-reference.h"
6 #include <glib.h>
7 #include <memory.h>
8 #include <stdio.h>
9 #include <stdlib.h>
11 static inline unsigned int DIV_ROUND(unsigned int v, unsigned int divisor) { return (v+divisor/2)/divisor; }
12 static inline unsigned char NR_PREMUL_111(unsigned int c, unsigned int a) { return static_cast<unsigned char>(DIV_ROUND(c*a, 255)); }
14 template<PIXEL_FORMAT format>
15 static int IMGCMP(const unsigned char* a, const unsigned char* b, size_t n) { return memcmp(a, b, n); }
17 template<>
18 static int IMGCMP<R8G8B8A8N>(const unsigned char* a, const unsigned char* b, size_t n)
19 {
20 // If two pixels each have their alpha channel set to zero they're equivalent
21 // Note that this doesn't work for premultiplied values, as their color values should
22 // be zero when alpha is zero.
23 int cr = 0;
24 while(n && cr == 0) {
25 if ( a[3] != 0 || b[3] != 0 ) {
26 cr = memcmp(a, b, 4);
27 }
28 a+=4;
29 b+=4;
30 n-=4;
31 }
32 return cr;
33 }
35 class NrComposeTest : public CxxTest::TestSuite {
36 private:
37 int const w, h;
39 unsigned char* const dst_rgba_n_org;
40 unsigned char* const dst_rgba_p_org;
41 unsigned char* const dst_rgb_org;
43 unsigned char* const dst1_rgba;
44 unsigned char* const dst2_rgba;
45 unsigned char* const src_rgba_n;
46 unsigned char* const src_rgba_p;
47 unsigned char* const dst1_rgb;
48 unsigned char* const dst2_rgb;
49 unsigned char* const src_rgb;
50 unsigned char* const mask;
52 static unsigned int const alpha_vals[7];
53 static unsigned int const rgb_vals[3];
55 public:
56 NrComposeTest() :
57 w(13),
58 h(5),
60 dst_rgba_n_org(new unsigned char[w*h*4]),
61 dst_rgba_p_org(new unsigned char[w*h*4]),
62 dst_rgb_org(new unsigned char[w*h*3]),
64 dst1_rgba(new unsigned char[w*h*4]),
65 dst2_rgba(new unsigned char[w*h*4]),
66 src_rgba_n(new unsigned char[w*h*4]),
67 src_rgba_p(new unsigned char[w*h*4]),
68 dst1_rgb(new unsigned char[w*h*3]),
69 dst2_rgb(new unsigned char[w*h*3]),
70 src_rgb(new unsigned char[w*h*3]),
71 mask(new unsigned char[w*h])
72 {
73 srand(23874683); // It shouldn't really matter what this is, as long as it's always the same (to be reproducible)
75 for(int y=0; y<h; y++) {
76 for(int x=0; x<w; x++) {
77 dst_rgba_n_org[(x+y*w)*4+3] = 255*rand()/RAND_MAX;
78 dst_rgba_p_org[(x+y*w)*4+3] = 255*rand()/RAND_MAX;
79 src_rgba_n[(x+y*w)*4+3] = 255*rand()/RAND_MAX;
80 src_rgba_p[(x+y*w)*4+3] = 255*rand()/RAND_MAX;
81 for(int i=0; i<3; i++) {
82 dst_rgba_n_org[(x+y*w)*4+i] = 255*rand()/RAND_MAX;
83 dst_rgba_p_org[(x+y*w)*4+i] = NR_PREMUL_111(255*rand()/RAND_MAX, dst_rgba_p_org[(x+y*w)*4+3]);
84 src_rgba_n[(x+y*w)*4+i] = 255*rand()/RAND_MAX;
85 src_rgba_p[(x+y*w)*4+i] = NR_PREMUL_111(255*rand()/RAND_MAX, src_rgba_p[(x+y*w)*4+3]);
86 dst_rgb_org[(x+y*w)*3+i] = 255*rand()/RAND_MAX;
87 }
88 mask[x+y*w] = 255*rand()/RAND_MAX;
89 }
90 }
91 }
92 virtual ~NrComposeTest()
93 {
94 delete[] dst_rgba_n_org;
95 delete[] dst_rgba_p_org;
96 delete[] dst_rgb_org;
98 delete[] dst1_rgba;
99 delete[] dst2_rgba;
100 delete[] src_rgba_n;
101 delete[] src_rgba_p;
102 delete[] dst1_rgb;
103 delete[] dst2_rgb;
104 delete[] src_rgb;
105 delete[] mask;
106 }
108 // FINAL DST SRC
110 void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_N()
111 {
112 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
113 unsigned int alpha = alpha_vals[i];
114 char msg[40];
115 sprintf(msg, "alpha = %u", alpha);
116 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
117 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
118 nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
119 nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
120 TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
121 }
122 }
124 void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_P()
125 {
126 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
127 unsigned int alpha = alpha_vals[i];
128 char msg[40];
129 sprintf(msg, "alpha = %u", alpha);
130 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
131 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
132 nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
133 nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
134 TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
135 }
136 }
138 void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_N()
139 {
140 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
141 unsigned int alpha = alpha_vals[i];
142 char msg[40];
143 sprintf(msg, "alpha = %u", alpha);
144 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
145 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
146 nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
147 nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
148 TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
149 }
150 }
152 void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_P()
153 {
154 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
155 unsigned int alpha = alpha_vals[i];
156 char msg[40];
157 sprintf(msg, "alpha = %u", alpha);
158 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
159 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
160 nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
161 nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
162 TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
163 }
164 }
166 void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N()
167 {
168 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
169 unsigned int alpha = alpha_vals[i];
170 char msg[40];
171 sprintf(msg, "alpha = %u", alpha);
172 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
173 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
174 nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
175 nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
176 TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
177 }
178 }
180 void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P()
181 {
182 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
183 unsigned int alpha = alpha_vals[i];
184 char msg[40];
185 sprintf(msg, "alpha = %u", alpha);
186 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
187 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
188 nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
189 nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
190 TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
191 }
192 }
194 void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N()
195 {
196 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
197 unsigned int alpha = alpha_vals[i];
198 char msg[40];
199 sprintf(msg, "alpha = %u", alpha);
200 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
201 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
202 nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
203 nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
204 TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
205 }
206 }
208 void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P()
209 {
210 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
211 unsigned int alpha = alpha_vals[i];
212 char msg[40];
213 sprintf(msg, "alpha = %u", alpha);
214 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
215 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
216 nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
217 nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
218 TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
219 }
220 }
222 // FINAL DST SRC MASK
224 void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8()
225 {
226 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
227 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
228 nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
229 nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
230 TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
231 }
233 void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8()
234 {
235 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
236 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
237 nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
238 nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
239 TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
240 }
242 void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8()
243 {
244 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
245 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
246 nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
247 nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
248 TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
249 }
251 void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8()
252 {
253 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
254 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
255 nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
256 nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
257 TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
258 }
260 void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8()
261 {
262 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
263 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
264 nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
265 nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
266 TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
267 }
269 void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8()
270 {
271 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
272 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
273 nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
274 nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
275 TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
276 }
278 void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8()
279 {
280 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
281 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
282 nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
283 nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
284 TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
285 }
287 void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8()
288 {
289 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
290 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
291 nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
292 nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
293 TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
294 }
296 // FINAL DST MASK COLOR
298 void testnr_R8G8B8A8_N_EMPTY_A8_RGBA32()
299 {
300 for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
301 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
302 unsigned int rgba = rgb_vals[j]+alpha_vals[i];
303 char msg[100];
304 sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
305 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
306 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
307 nr_R8G8B8A8_N_EMPTY_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba);
308 nr_R8G8B8A8_N_EMPTY_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba);
309 TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
310 }
311 }
312 }
314 void testnr_R8G8B8A8_P_EMPTY_A8_RGBA32()
315 {
316 for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
317 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
318 unsigned int rgba = rgb_vals[j]+alpha_vals[i];
319 char msg[100];
320 sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
321 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
322 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
323 nr_R8G8B8A8_P_EMPTY_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba);
324 nr_R8G8B8A8_P_EMPTY_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba);
325 TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
326 }
327 }
328 }
330 void testnr_R8G8B8_R8G8B8_A8_RGBA32()
331 {
332 for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
333 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
334 unsigned int rgba = rgb_vals[j]+alpha_vals[i];
335 char msg[100];
336 sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
337 memcpy(dst1_rgb, dst_rgb_org, w*h*3);
338 memcpy(dst2_rgb, dst_rgb_org, w*h*3);
339 nr_R8G8B8_R8G8B8_A8_RGBA32(dst1_rgb, w, h, w*3, mask, w, rgba);
340 nr_R8G8B8_R8G8B8_A8_RGBA32_ref(dst2_rgb, w, h, w*3, mask, w, rgba);
341 TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
342 }
343 }
344 }
346 void testnr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32()
347 {
348 for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
349 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
350 unsigned int rgba = rgb_vals[j]+alpha_vals[i];
351 char msg[100];
352 sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
353 memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
354 memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
355 nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba);
356 nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba);
357 TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
358 }
359 }
360 }
362 void testnr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32()
363 {
364 for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
365 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
366 unsigned int rgba = rgb_vals[j]+alpha_vals[i];
367 char msg[100];
368 sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
369 memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
370 memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
371 nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba);
372 nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba);
373 TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
374 }
375 }
376 }
378 // RGB
380 void testnr_R8G8B8_R8G8B8_R8G8B8A8_N()
381 {
382 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
383 unsigned int alpha = alpha_vals[i];
384 char msg[40];
385 sprintf(msg, "alpha = %u", alpha);
386 memcpy(dst1_rgb, dst_rgb_org, w*h*3);
387 memcpy(dst2_rgb, dst_rgb_org, w*h*3);
388 nr_R8G8B8_R8G8B8_R8G8B8A8_N(dst1_rgb, w, h, w*3, src_rgba_n, w*4, alpha);
389 nr_R8G8B8_R8G8B8_R8G8B8A8_N_ref(dst2_rgb, w, h, w*3, src_rgba_n, w*4, alpha);
390 TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
391 }
392 }
394 void testnr_R8G8B8_R8G8B8_R8G8B8A8_P()
395 {
396 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
397 unsigned int alpha = alpha_vals[i];
398 char msg[40];
399 sprintf(msg, "alpha = %u", alpha);
400 memcpy(dst1_rgb, dst_rgb_org, w*h*3);
401 memcpy(dst2_rgb, dst_rgb_org, w*h*3);
402 nr_R8G8B8_R8G8B8_R8G8B8A8_P(dst1_rgb, w, h, w*3, src_rgba_p, w*4, alpha);
403 nr_R8G8B8_R8G8B8_R8G8B8A8_P_ref(dst2_rgb, w, h, w*3, src_rgba_p, w*4, alpha);
404 TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
405 }
406 }
408 void testnr_R8G8B8_R8G8B8_R8G8B8A8_N_A8()
409 {
410 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
411 unsigned int alpha = alpha_vals[i];
412 char msg[40];
413 sprintf(msg, "alpha = %u", alpha);
414 memcpy(dst1_rgb, dst_rgb_org, w*h*3);
415 memcpy(dst2_rgb, dst_rgb_org, w*h*3);
416 nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8(dst1_rgb, w, h, w*3, src_rgba_n, w*4, mask, w);
417 nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8_ref(dst2_rgb, w, h, w*3, src_rgba_n, w*4, mask, w);
418 TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
419 }
420 }
422 void testnr_R8G8B8_R8G8B8_R8G8B8A8_P_A8()
423 {
424 for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
425 unsigned int alpha = alpha_vals[i];
426 char msg[40];
427 sprintf(msg, "alpha = %u", alpha);
428 memcpy(dst1_rgb, dst_rgb_org, w*h*3);
429 memcpy(dst2_rgb, dst_rgb_org, w*h*3);
430 nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8(dst1_rgb, w, h, w*3, src_rgba_p, w*4, mask, w);
431 nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8_ref(dst2_rgb, w, h, w*3, src_rgba_p, w*4, mask, w);
432 TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
433 }
434 }
435 };
437 unsigned int const NrComposeTest::alpha_vals[7] = {0, 1, 127, 128, 129, 254, 255};
438 unsigned int const NrComposeTest::rgb_vals[3] = {
439 ( 0u<<24u)+( 1u<<16u)+( 92u<<8u),
440 (127u<<24u)+(128u<<16u)+(129u<<8u),
441 (163u<<24u)+(254u<<16u)+(255u<<8u)};
443 /*
444 Local Variables:
445 mode:c++
446 c-file-style:"stroustrup"
447 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
448 indent-tabs-mode:nil
449 fill-column:99
450 End:
451 */
452 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :