~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/libnr/nr-compose-test.h

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <cxxtest/TestSuite.h>
 
3
 
 
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>
 
10
 
 
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)); }
 
13
 
 
14
template<PIXEL_FORMAT format>
 
15
int IMGCMP(const unsigned char* a, const unsigned char* b, size_t n) { return memcmp(a, b, n); }
 
16
 
 
17
template<>
 
18
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
}
 
34
 
 
35
class NrComposeTest : public CxxTest::TestSuite {
 
36
private:
 
37
    int const w, h;
 
38
 
 
39
    unsigned char* const dst_rgba_n_org;
 
40
    unsigned char* const dst_rgba_p_org;
 
41
    unsigned char* const dst_rgb_org;
 
42
 
 
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;
 
51
 
 
52
    static unsigned int const alpha_vals[7];
 
53
    static unsigned int const rgb_vals[3];
 
54
 
 
55
public:
 
56
    NrComposeTest() :
 
57
        w(13),
 
58
        h(5),
 
59
 
 
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]),
 
63
 
 
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)
 
74
 
 
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;
 
97
 
 
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
    }
 
107
 
 
108
// createSuite and destroySuite get us per-suite setup and teardown
 
109
// without us having to worry about static initialization order, etc.
 
110
    static NrComposeTest *createSuite() { return new NrComposeTest(); }
 
111
    static void destroySuite( NrComposeTest *suite ) { delete suite; }
 
112
 
 
113
    // FINAL DST SRC
 
114
 
 
115
    void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_N()
 
116
    {
 
117
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
118
            unsigned int alpha = alpha_vals[i];
 
119
            char msg[40];
 
120
            sprintf(msg, "alpha = %u", alpha);
 
121
            memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
122
            memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
123
            nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
 
124
            nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
 
125
            TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
126
        }
 
127
    }
 
128
 
 
129
    void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_P()
 
130
    {
 
131
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
132
            unsigned int alpha = alpha_vals[i];
 
133
            char msg[40];
 
134
            sprintf(msg, "alpha = %u", alpha);
 
135
            memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
136
            memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
137
            nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
 
138
            nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
 
139
            TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
140
        }
 
141
    }
 
142
 
 
143
    void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_N()
 
144
    {
 
145
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
146
            unsigned int alpha = alpha_vals[i];
 
147
            char msg[40];
 
148
            sprintf(msg, "alpha = %u", alpha);
 
149
            memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
150
            memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
151
            nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
 
152
            nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
 
153
            TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
154
        }
 
155
    }
 
156
 
 
157
    void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_P()
 
158
    {
 
159
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
160
            unsigned int alpha = alpha_vals[i];
 
161
            char msg[40];
 
162
            sprintf(msg, "alpha = %u", alpha);
 
163
            memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
164
            memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
165
            nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
 
166
            nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
 
167
            TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
168
        }
 
169
    }
 
170
 
 
171
    void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N()
 
172
    {
 
173
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
174
            unsigned int alpha = alpha_vals[i];
 
175
            char msg[40];
 
176
            sprintf(msg, "alpha = %u", alpha);
 
177
            memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
178
            memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
179
            nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
 
180
            nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
 
181
            TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
182
        }
 
183
    }
 
184
 
 
185
    void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P()
 
186
    {
 
187
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
188
            unsigned int alpha = alpha_vals[i];
 
189
            char msg[40];
 
190
            sprintf(msg, "alpha = %u", alpha);
 
191
            memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
192
            memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
193
            nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
 
194
            nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
 
195
            TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
196
        }
 
197
    }
 
198
 
 
199
    void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N()
 
200
    {
 
201
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
202
            unsigned int alpha = alpha_vals[i];
 
203
            char msg[40];
 
204
            sprintf(msg, "alpha = %u", alpha);
 
205
            memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
206
            memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
207
            nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N(dst1_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
 
208
            nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, alpha);
 
209
            TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
210
        }
 
211
    }
 
212
 
 
213
    void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P()
 
214
    {
 
215
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
216
            unsigned int alpha = alpha_vals[i];
 
217
            char msg[40];
 
218
            sprintf(msg, "alpha = %u", alpha);
 
219
            memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
220
            memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
221
            nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P(dst1_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
 
222
            nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, alpha);
 
223
            TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
224
        }
 
225
    }
 
226
 
 
227
    // FINAL DST SRC MASK
 
228
 
 
229
    void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8()
 
230
    {
 
231
        memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
232
        memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
233
        nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
 
234
        nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
 
235
        TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
236
    }
 
237
 
 
238
    void testnr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8()
 
239
    {
 
240
        memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
241
        memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
242
        nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
 
243
        nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
 
244
        TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
245
    }
 
246
 
 
247
    void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8()
 
248
    {
 
249
        memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
250
        memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
251
        nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
 
252
        nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
 
253
        TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
254
    }
 
255
 
 
256
    void testnr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8()
 
257
    {
 
258
        memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
259
        memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
260
        nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
 
261
        nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
 
262
        TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
263
    }
 
264
 
 
265
    void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8()
 
266
    {
 
267
        memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
268
        memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
269
        nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
 
270
        nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
 
271
        TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
272
    }
 
273
 
 
274
    void testnr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8()
 
275
    {
 
276
        memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
277
        memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
278
        nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
 
279
        nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
 
280
        TS_ASSERT( IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
281
    }
 
282
 
 
283
    void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8()
 
284
    {
 
285
        memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
286
        memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
287
        nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8(dst1_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
 
288
        nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8_ref(dst2_rgba, w, h, w*4, src_rgba_n, w*4, mask, w);
 
289
        TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
290
    }
 
291
 
 
292
    void testnr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8()
 
293
    {
 
294
        memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
295
        memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
296
        nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8(dst1_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
 
297
        nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8_ref(dst2_rgba, w, h, w*4, src_rgba_p, w*4, mask, w);
 
298
        TS_ASSERT( IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
299
    }
 
300
 
 
301
    // FINAL DST MASK COLOR
 
302
 
 
303
    void testnr_R8G8B8A8_N_EMPTY_A8_RGBA32()
 
304
    {
 
305
        for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
 
306
            for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
307
                unsigned int rgba = rgb_vals[j]+alpha_vals[i];
 
308
                char msg[100];
 
309
                sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
 
310
                memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
311
                memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
312
                nr_R8G8B8A8_N_EMPTY_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba);
 
313
                nr_R8G8B8A8_N_EMPTY_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba);
 
314
                TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
315
            }
 
316
        }
 
317
    }
 
318
 
 
319
    void testnr_R8G8B8A8_P_EMPTY_A8_RGBA32()
 
320
    {
 
321
        for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
 
322
            for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
323
                unsigned int rgba = rgb_vals[j]+alpha_vals[i];
 
324
                char msg[100];
 
325
                sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
 
326
                memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
327
                memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
328
                nr_R8G8B8A8_P_EMPTY_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba);
 
329
                nr_R8G8B8A8_P_EMPTY_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba);
 
330
                TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
331
            }
 
332
        }
 
333
    }
 
334
 
 
335
    void testnr_R8G8B8_R8G8B8_A8_RGBA32()
 
336
    {
 
337
        for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
 
338
            for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
339
                unsigned int rgba = rgb_vals[j]+alpha_vals[i];
 
340
                char msg[100];
 
341
                sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
 
342
                memcpy(dst1_rgb, dst_rgb_org, w*h*3);
 
343
                memcpy(dst2_rgb, dst_rgb_org, w*h*3);
 
344
                nr_R8G8B8_R8G8B8_A8_RGBA32(dst1_rgb, w, h, w*3, mask, w, rgba);
 
345
                nr_R8G8B8_R8G8B8_A8_RGBA32_ref(dst2_rgb, w, h, w*3, mask, w, rgba);
 
346
                TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
 
347
            }
 
348
        }
 
349
    }
 
350
 
 
351
    void testnr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32()
 
352
    {
 
353
        for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
 
354
            for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
355
                unsigned int rgba = rgb_vals[j]+alpha_vals[i];
 
356
                char msg[100];
 
357
                sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
 
358
                memcpy(dst1_rgba, dst_rgba_n_org, w*h*4);
 
359
                memcpy(dst2_rgba, dst_rgba_n_org, w*h*4);
 
360
                nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba);
 
361
                nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba);
 
362
                TSM_ASSERT(msg, IMGCMP<R8G8B8A8N>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
363
            }
 
364
        }
 
365
    }
 
366
 
 
367
    void testnr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32()
 
368
    {
 
369
        for(size_t j=0; j<G_N_ELEMENTS(rgb_vals); j++) {
 
370
            for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
371
                unsigned int rgba = rgb_vals[j]+alpha_vals[i];
 
372
                char msg[100];
 
373
                sprintf(msg, "color = (%u,%u,%u,%u)", (rgba>>24u)&0xff, (rgba>>16u)&0xff, (rgba>>8u)&0xff, rgba&0xff);
 
374
                memcpy(dst1_rgba, dst_rgba_p_org, w*h*4);
 
375
                memcpy(dst2_rgba, dst_rgba_p_org, w*h*4);
 
376
                nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32(dst1_rgba, w, h, w*4, mask, w, rgba);
 
377
                nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32_ref(dst2_rgba, w, h, w*4, mask, w, rgba);
 
378
                TSM_ASSERT(msg, IMGCMP<R8G8B8A8P>(dst1_rgba, dst2_rgba, w*h*4) == 0 );
 
379
            }
 
380
        }
 
381
    }
 
382
 
 
383
    // RGB
 
384
 
 
385
    void testnr_R8G8B8_R8G8B8_R8G8B8A8_N()
 
386
    {
 
387
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
388
            unsigned int alpha = alpha_vals[i];
 
389
            char msg[40];
 
390
            sprintf(msg, "alpha = %u", alpha);
 
391
            memcpy(dst1_rgb, dst_rgb_org, w*h*3);
 
392
            memcpy(dst2_rgb, dst_rgb_org, w*h*3);
 
393
            nr_R8G8B8_R8G8B8_R8G8B8A8_N(dst1_rgb, w, h, w*3, src_rgba_n, w*4, alpha);
 
394
            nr_R8G8B8_R8G8B8_R8G8B8A8_N_ref(dst2_rgb, w, h, w*3, src_rgba_n, w*4, alpha);
 
395
            TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
 
396
        }
 
397
    }
 
398
 
 
399
    void testnr_R8G8B8_R8G8B8_R8G8B8A8_P()
 
400
    {
 
401
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
402
            unsigned int alpha = alpha_vals[i];
 
403
            char msg[40];
 
404
            sprintf(msg, "alpha = %u", alpha);
 
405
            memcpy(dst1_rgb, dst_rgb_org, w*h*3);
 
406
            memcpy(dst2_rgb, dst_rgb_org, w*h*3);
 
407
            nr_R8G8B8_R8G8B8_R8G8B8A8_P(dst1_rgb, w, h, w*3, src_rgba_p, w*4, alpha);
 
408
            nr_R8G8B8_R8G8B8_R8G8B8A8_P_ref(dst2_rgb, w, h, w*3, src_rgba_p, w*4, alpha);
 
409
            TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
 
410
        }
 
411
    }
 
412
 
 
413
    void testnr_R8G8B8_R8G8B8_R8G8B8A8_N_A8()
 
414
    {
 
415
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
416
            unsigned int alpha = alpha_vals[i];
 
417
            char msg[40];
 
418
            sprintf(msg, "alpha = %u", alpha);
 
419
            memcpy(dst1_rgb, dst_rgb_org, w*h*3);
 
420
            memcpy(dst2_rgb, dst_rgb_org, w*h*3);
 
421
            nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8(dst1_rgb, w, h, w*3, src_rgba_n, w*4, mask, w);
 
422
            nr_R8G8B8_R8G8B8_R8G8B8A8_N_A8_ref(dst2_rgb, w, h, w*3, src_rgba_n, w*4, mask, w);
 
423
            TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
 
424
        }
 
425
    }
 
426
 
 
427
    void testnr_R8G8B8_R8G8B8_R8G8B8A8_P_A8()
 
428
    {
 
429
        for(size_t i=0; i<G_N_ELEMENTS(alpha_vals); i++) {
 
430
            unsigned int alpha = alpha_vals[i];
 
431
            char msg[40];
 
432
            sprintf(msg, "alpha = %u", alpha);
 
433
            memcpy(dst1_rgb, dst_rgb_org, w*h*3);
 
434
            memcpy(dst2_rgb, dst_rgb_org, w*h*3);
 
435
            nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8(dst1_rgb, w, h, w*3, src_rgba_p, w*4, mask, w);
 
436
            nr_R8G8B8_R8G8B8_R8G8B8A8_P_A8_ref(dst2_rgb, w, h, w*3, src_rgba_p, w*4, mask, w);
 
437
            TSM_ASSERT(msg, IMGCMP<R8G8B8>(dst1_rgb, dst2_rgb, w*h*3) == 0 );
 
438
        }
 
439
    }
 
440
};
 
441
 
 
442
unsigned int const NrComposeTest::alpha_vals[7] = {0, 1, 127, 128, 129, 254, 255};
 
443
unsigned int const NrComposeTest::rgb_vals[3] = {
 
444
    (  0u<<24u)+(  1u<<16u)+( 92u<<8u),
 
445
    (127u<<24u)+(128u<<16u)+(129u<<8u),
 
446
    (163u<<24u)+(254u<<16u)+(255u<<8u)};
 
447
 
 
448
/*
 
449
Local Variables:
 
450
mode:c++
 
451
c-file-style:"stroustrup"
 
452
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
453
indent-tabs-mode:nil
 
454
fill-column:99
 
455
End:
 
456
*/
 
457
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :