~ubuntu-branches/ubuntu/saucy/pixman/saucy-security

« back to all changes in this revision

Viewing changes to test/alphamap.c

  • Committer: Package Import Robot
  • Author(s): Cyril Brulebois
  • Date: 2012-06-15 01:25:20 UTC
  • mfrom: (1.4.7) (2.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120615012520-ijgiax9gy3217z12
Tags: 0.26.0-2
* Cherry-pick from upstream master branch to fix FTBFS on *i386:
  - da6193b1fc “mmx: add missing _mm_empty calls”

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <stdlib.h>
3
3
#include "utils.h"
4
4
 
5
 
#define WIDTH 100
6
 
#define HEIGHT 100
 
5
#define WIDTH 48
 
6
#define HEIGHT 48
7
7
 
8
8
static const pixman_format_code_t formats[] =
9
9
{
70
70
    return image;
71
71
}
72
72
 
73
 
static pixman_image_t *
74
 
create_image (pixman_format_code_t format, pixman_format_code_t alpha_format,
75
 
              int alpha_origin_x, int alpha_origin_y)
76
 
{
77
 
    pixman_image_t *image = make_image (format);
78
 
 
79
 
    if (alpha_format != PIXMAN_null)
80
 
    {
81
 
        pixman_image_t *alpha = make_image (alpha_format);
82
 
 
83
 
        pixman_image_set_alpha_map (image, alpha,
84
 
                                    alpha_origin_x, alpha_origin_y);
85
 
        pixman_image_unref (alpha);
86
 
    }
87
 
 
88
 
    return image;
89
 
}
90
 
 
91
73
static uint8_t
92
74
get_alpha (pixman_image_t *image, int x, int y, int orig_x, int orig_y)
93
75
{
139
121
    return r;
140
122
}
141
123
 
142
 
#define ARRAY_LENGTH(A) ((int) (sizeof (A) / sizeof ((A) [0])))
 
124
static uint16_t
 
125
get_red (pixman_image_t *image, int x, int y, int orig_x, int orig_y)
 
126
{
 
127
    uint8_t *bits;
 
128
    uint16_t r;
 
129
 
 
130
    bits = (uint8_t *)image->bits.bits;
 
131
 
 
132
    if (image->bits.format == PIXMAN_a8)
 
133
    {
 
134
        r = 0x00;
 
135
    }
 
136
    else if (image->bits.format == PIXMAN_a2r10g10b10)
 
137
    {
 
138
        r = ((uint32_t *)bits)[y * WIDTH + x] >> 14;
 
139
        r &= 0xffc0;
 
140
        r |= (r >> 10);
 
141
    }
 
142
    else if (image->bits.format == PIXMAN_a8r8g8b8)
 
143
    {
 
144
        r = ((uint32_t *)bits)[y * WIDTH + x] >> 16;
 
145
        r &= 0xff;
 
146
        r |= r << 8;
 
147
    }
 
148
    else if (image->bits.format == PIXMAN_a4r4g4b4)
 
149
    {
 
150
        r = ((uint16_t *)bits)[y * WIDTH + x] >> 8;
 
151
        r &= 0xf;
 
152
        r |= r << 4;
 
153
        r |= r << 8;
 
154
    }
 
155
    else
 
156
    {
 
157
        assert (0);
 
158
    }
 
159
 
 
160
    return r;
 
161
}
143
162
 
144
163
static int
145
164
run_test (int s, int d, int sa, int da, int soff, int doff)
148
167
    pixman_format_code_t df = formats[d];
149
168
    pixman_format_code_t saf = alpha_formats[sa];
150
169
    pixman_format_code_t daf = alpha_formats[da];
151
 
    pixman_image_t *src, *dst, *orig_dst;
 
170
    pixman_image_t *src, *dst, *orig_dst, *alpha, *orig_alpha;
152
171
    pixman_transform_t t1;
153
172
    int j, k;
154
 
    int n_alpha_bits;
 
173
    int n_alpha_bits, n_red_bits;
155
174
 
156
175
    soff = origins[soff];
157
176
    doff = origins[doff];
160
179
    if (daf != PIXMAN_null)
161
180
        n_alpha_bits = PIXMAN_FORMAT_A (daf);
162
181
 
163
 
 
164
 
    src = create_image (sf, saf, soff, soff);
165
 
    orig_dst = create_image (df, daf, doff, doff);
166
 
    dst = create_image (df, daf, doff, doff);
 
182
    n_red_bits = PIXMAN_FORMAT_R (df);
 
183
 
 
184
    /* Source */
 
185
    src = make_image (sf);
 
186
    if (saf != PIXMAN_null)
 
187
    {
 
188
        alpha = make_image (saf);
 
189
        pixman_image_set_alpha_map (src, alpha, soff, soff);
 
190
        pixman_image_unref (alpha);
 
191
    }
 
192
 
 
193
    /* Destination */
 
194
    orig_dst = make_image (df);
 
195
    dst = make_image (df);
 
196
    pixman_image_composite (PIXMAN_OP_SRC, orig_dst, NULL, dst,
 
197
                            0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
 
198
 
 
199
    if (daf != PIXMAN_null)
 
200
    {
 
201
        orig_alpha = make_image (daf);
 
202
        alpha = make_image (daf);
 
203
 
 
204
        pixman_image_composite (PIXMAN_OP_SRC, orig_alpha, NULL, alpha,
 
205
                                0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
 
206
 
 
207
        pixman_image_set_alpha_map (orig_dst, orig_alpha, doff, doff);
 
208
        pixman_image_set_alpha_map (dst, alpha, doff, doff);
 
209
 
 
210
        pixman_image_unref (orig_alpha);
 
211
        pixman_image_unref (alpha);
 
212
    }
167
213
 
168
214
    /* Transformations, repeats and filters on destinations should be ignored,
169
215
     * so just set some random ones.
177
223
    pixman_image_set_filter (dst, PIXMAN_FILTER_BILINEAR, NULL, 0);
178
224
    pixman_image_set_repeat (dst, PIXMAN_REPEAT_REFLECT);
179
225
 
180
 
    pixman_image_composite (PIXMAN_OP_SRC, orig_dst, NULL, dst,
181
 
                            0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
182
 
 
183
226
    pixman_image_composite (PIXMAN_OP_ADD, src, NULL, dst,
184
227
                            0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
185
228
 
187
230
    {
188
231
        for (k = MAX (doff, 0); k < MIN (WIDTH, WIDTH + doff); ++k)
189
232
        {
190
 
            uint8_t sa, da, oda, ref;
 
233
            uint8_t sa, da, oda, refa;
 
234
            uint16_t sr, dr, odr, refr;
191
235
 
192
236
            sa = get_alpha (src, k, j, soff, soff);
193
237
            da = get_alpha (dst, k, j, doff, doff);
194
238
            oda = get_alpha (orig_dst, k, j, doff, doff);
195
239
 
196
240
            if (sa + oda > 255)
197
 
                ref = 255;
 
241
                refa = 255;
198
242
            else
199
 
                ref = sa + oda;
 
243
                refa = sa + oda;
200
244
 
201
 
            if (da >> (8 - n_alpha_bits) != ref >> (8 - n_alpha_bits))
 
245
            if (da >> (8 - n_alpha_bits) != refa >> (8 - n_alpha_bits))
202
246
            {
203
247
                printf ("\nWrong alpha value at (%d, %d). Should be 0x%x; got 0x%x. Source was 0x%x, original dest was 0x%x\n",
204
 
                        k, j, ref, da, sa, oda);
 
248
                        k, j, refa, da, sa, oda);
205
249
 
206
250
                printf ("src: %s, alpha: %s, origin %d %d\ndst: %s, alpha: %s, origin: %d %d\n\n",
207
251
                        format_name (sf),
212
256
                        doff, doff);
213
257
                return 1;
214
258
            }
 
259
 
 
260
            /* There are cases where we go through the 8 bit compositing
 
261
             * path even with 10bpc formats. This results in incorrect
 
262
             * results here, so only do the red check for narrow formats
 
263
             */
 
264
            if (n_red_bits <= 8)
 
265
            {
 
266
                sr = get_red (src, k, j, soff, soff);
 
267
                dr = get_red (dst, k, j, doff, doff);
 
268
                odr = get_red (orig_dst, k, j, doff, doff);
 
269
 
 
270
                if (sr + odr > 0xffff)
 
271
                    refr = 0xffff;
 
272
                else
 
273
                    refr = sr + odr;
 
274
 
 
275
                if (abs ((dr >> (16 - n_red_bits)) - (refr >> (16 - n_red_bits))) > 1)
 
276
                {
 
277
                    printf ("%d red bits\n", n_red_bits);
 
278
                    printf ("\nWrong red value at (%d, %d). Should be 0x%x; got 0x%x. Source was 0x%x, original dest was 0x%x\n",
 
279
                            k, j, refr, dr, sr, odr);
 
280
 
 
281
                    printf ("src: %s, alpha: %s, origin %d %d\ndst: %s, alpha: %s, origin: %d %d\n\n",
 
282
                            format_name (sf),
 
283
                            format_name (saf),
 
284
                            soff, soff,
 
285
                            format_name (df),
 
286
                            format_name (daf),
 
287
                            doff, doff);
 
288
                    return 1;
 
289
                }
 
290
            }
215
291
        }
216
292
    }
217
293