From 34c1e86406451a3604de4982339058088434ab40 Mon Sep 17 00:00:00 2001 From: marha Date: Tue, 17 Jan 2012 08:43:22 +0100 Subject: git update mesa pixman xserver 17 jan 2012 --- pixman/test/alphamap.c | 144 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 111 insertions(+), 33 deletions(-) (limited to 'pixman/test/alphamap.c') diff --git a/pixman/test/alphamap.c b/pixman/test/alphamap.c index 24a350ed7..0c5757ea3 100644 --- a/pixman/test/alphamap.c +++ b/pixman/test/alphamap.c @@ -2,8 +2,8 @@ #include #include "utils.h" -#define WIDTH 100 -#define HEIGHT 100 +#define WIDTH 48 +#define HEIGHT 48 static const pixman_format_code_t formats[] = { @@ -70,24 +70,6 @@ make_image (pixman_format_code_t format) return image; } -static pixman_image_t * -create_image (pixman_format_code_t format, pixman_format_code_t alpha_format, - int alpha_origin_x, int alpha_origin_y) -{ - pixman_image_t *image = make_image (format); - - if (alpha_format != PIXMAN_null) - { - pixman_image_t *alpha = make_image (alpha_format); - - pixman_image_set_alpha_map (image, alpha, - alpha_origin_x, alpha_origin_y); - pixman_image_unref (alpha); - } - - return image; -} - static uint8_t get_alpha (pixman_image_t *image, int x, int y, int orig_x, int orig_y) { @@ -139,6 +121,45 @@ get_alpha (pixman_image_t *image, int x, int y, int orig_x, int orig_y) return r; } +static uint16_t +get_red (pixman_image_t *image, int x, int y, int orig_x, int orig_y) +{ + uint8_t *bits; + uint16_t r; + + bits = (uint8_t *)image->bits.bits; + + if (image->bits.format == PIXMAN_a8) + { + r = 0x00; + } + else if (image->bits.format == PIXMAN_a2r10g10b10) + { + r = ((uint32_t *)bits)[y * WIDTH + x] >> 14; + r &= 0xffc0; + r |= (r >> 10); + } + else if (image->bits.format == PIXMAN_a8r8g8b8) + { + r = ((uint32_t *)bits)[y * WIDTH + x] >> 16; + r &= 0xff; + r |= r << 8; + } + else if (image->bits.format == PIXMAN_a4r4g4b4) + { + r = ((uint16_t *)bits)[y * WIDTH + x] >> 8; + r &= 0xf; + r |= r << 4; + r |= r << 8; + } + else + { + assert (0); + } + + return r; +} + static int run_test (int s, int d, int sa, int da, int soff, int doff) { @@ -146,10 +167,10 @@ run_test (int s, int d, int sa, int da, int soff, int doff) pixman_format_code_t df = formats[d]; pixman_format_code_t saf = alpha_formats[sa]; pixman_format_code_t daf = alpha_formats[da]; - pixman_image_t *src, *dst, *orig_dst; + pixman_image_t *src, *dst, *orig_dst, *alpha, *orig_alpha; pixman_transform_t t1; int j, k; - int n_alpha_bits; + int n_alpha_bits, n_red_bits; soff = origins[soff]; doff = origins[doff]; @@ -158,10 +179,37 @@ run_test (int s, int d, int sa, int da, int soff, int doff) if (daf != PIXMAN_null) n_alpha_bits = PIXMAN_FORMAT_A (daf); + n_red_bits = PIXMAN_FORMAT_R (df); + + /* Source */ + src = make_image (sf); + if (saf != PIXMAN_null) + { + alpha = make_image (saf); + pixman_image_set_alpha_map (src, alpha, soff, soff); + pixman_image_unref (alpha); + } + + /* Destination */ + orig_dst = make_image (df); + dst = make_image (df); + pixman_image_composite (PIXMAN_OP_SRC, orig_dst, NULL, dst, + 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); + + if (daf != PIXMAN_null) + { + orig_alpha = make_image (daf); + alpha = make_image (daf); + + pixman_image_composite (PIXMAN_OP_SRC, orig_alpha, NULL, alpha, + 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); - src = create_image (sf, saf, soff, soff); - orig_dst = create_image (df, daf, doff, doff); - dst = create_image (df, daf, doff, doff); + pixman_image_set_alpha_map (orig_dst, orig_alpha, doff, doff); + pixman_image_set_alpha_map (dst, alpha, doff, doff); + + pixman_image_unref (orig_alpha); + pixman_image_unref (alpha); + } /* Transformations, repeats and filters on destinations should be ignored, * so just set some random ones. @@ -175,9 +223,6 @@ run_test (int s, int d, int sa, int da, int soff, int doff) pixman_image_set_filter (dst, PIXMAN_FILTER_BILINEAR, NULL, 0); pixman_image_set_repeat (dst, PIXMAN_REPEAT_REFLECT); - pixman_image_composite (PIXMAN_OP_SRC, orig_dst, NULL, dst, - 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); - pixman_image_composite (PIXMAN_OP_ADD, src, NULL, dst, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); @@ -185,21 +230,22 @@ run_test (int s, int d, int sa, int da, int soff, int doff) { for (k = MAX (doff, 0); k < MIN (WIDTH, WIDTH + doff); ++k) { - uint8_t sa, da, oda, ref; + uint8_t sa, da, oda, refa; + uint16_t sr, dr, odr, refr; sa = get_alpha (src, k, j, soff, soff); da = get_alpha (dst, k, j, doff, doff); oda = get_alpha (orig_dst, k, j, doff, doff); if (sa + oda > 255) - ref = 255; + refa = 255; else - ref = sa + oda; + refa = sa + oda; - if (da >> (8 - n_alpha_bits) != ref >> (8 - n_alpha_bits)) + if (da >> (8 - n_alpha_bits) != refa >> (8 - n_alpha_bits)) { printf ("\nWrong alpha value at (%d, %d). Should be 0x%x; got 0x%x. Source was 0x%x, original dest was 0x%x\n", - k, j, ref, da, sa, oda); + k, j, refa, da, sa, oda); printf ("src: %s, alpha: %s, origin %d %d\ndst: %s, alpha: %s, origin: %d %d\n\n", format_name (sf), @@ -210,6 +256,38 @@ run_test (int s, int d, int sa, int da, int soff, int doff) doff, doff); return 1; } + + /* There are cases where we go through the 8 bit compositing + * path even with 10bpc formats. This results in incorrect + * results here, so only do the red check for narrow formats + */ + if (n_red_bits <= 8) + { + sr = get_red (src, k, j, soff, soff); + dr = get_red (dst, k, j, doff, doff); + odr = get_red (orig_dst, k, j, doff, doff); + + if (sr + odr > 0xffff) + refr = 0xffff; + else + refr = sr + odr; + + if (abs ((dr >> (16 - n_red_bits)) - (refr >> (16 - n_red_bits))) > 1) + { + printf ("%d red bits\n", n_red_bits); + printf ("\nWrong red value at (%d, %d). Should be 0x%x; got 0x%x. Source was 0x%x, original dest was 0x%x\n", + k, j, refr, dr, sr, odr); + + printf ("src: %s, alpha: %s, origin %d %d\ndst: %s, alpha: %s, origin: %d %d\n\n", + format_name (sf), + format_name (saf), + soff, soff, + format_name (df), + format_name (daf), + doff, doff); + return 1; + } + } } } -- cgit v1.2.3