Code

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