diff options
Diffstat (limited to 'pixman/test')
-rw-r--r-- | pixman/test/alphamap.c | 144 | ||||
-rw-r--r-- | pixman/test/composite.c | 332 | ||||
-rw-r--r-- | pixman/test/utils.c | 175 | ||||
-rw-r--r-- | pixman/test/utils.h | 35 |
4 files changed, 419 insertions, 267 deletions
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 <stdlib.h> #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; + } + } } } diff --git a/pixman/test/composite.c b/pixman/test/composite.c index fe59eae3c..48bde9c7d 100644 --- a/pixman/test/composite.c +++ b/pixman/test/composite.c @@ -28,16 +28,10 @@ #include <time.h> #include "utils.h" -typedef struct color_t color_t; typedef struct format_t format_t; typedef struct image_t image_t; typedef struct operator_t operator_t; -struct color_t -{ - double r, g, b, a; -}; - struct format_t { pixman_format_code_t format; @@ -480,147 +474,19 @@ do_composite (pixman_op_t op, result->a = calc_op (op, srcval.a, dst->a, srcalpha.a, dst->a); } -static void -color_correct (pixman_format_code_t format, - color_t *color) +static uint32_t +get_value (pixman_image_t *image) { -#define MASK(x) ((1 << (x)) - 1) -#define round_pix(pix, m) \ - ((int)((pix) * (MASK(m)) + .5) / (double) (MASK(m))) - - if (PIXMAN_FORMAT_R (format) == 0) - { - color->r = 0.0; - color->g = 0.0; - color->b = 0.0; - } - else - { - color->r = round_pix (color->r, PIXMAN_FORMAT_R (format)); - color->g = round_pix (color->g, PIXMAN_FORMAT_G (format)); - color->b = round_pix (color->b, PIXMAN_FORMAT_B (format)); - } - - if (PIXMAN_FORMAT_A (format) == 0) - color->a = 1.0; - else - color->a = round_pix (color->a, PIXMAN_FORMAT_A (format)); + uint32_t value = *(uint32_t *)pixman_image_get_data (image); -#undef round_pix -#undef MASK -} - -static void -get_pixel (pixman_image_t *image, - pixman_format_code_t format, - color_t *color) -{ -#define MASK(N) ((1UL << (N))-1) - - unsigned long rs, gs, bs, as; - int a, r, g, b; - unsigned long val; - - val = *(unsigned long *) pixman_image_get_data (image); #ifdef WORDS_BIGENDIAN - val >>= 8 * sizeof(val) - PIXMAN_FORMAT_BPP (format); -#endif - - /* Number of bits in each channel */ - a = PIXMAN_FORMAT_A (format); - r = PIXMAN_FORMAT_R (format); - g = PIXMAN_FORMAT_G (format); - b = PIXMAN_FORMAT_B (format); - - switch (PIXMAN_FORMAT_TYPE (format)) { - case PIXMAN_TYPE_ARGB: - bs = 0; - gs = b + bs; - rs = g + gs; - as = r + rs; - break; - - case PIXMAN_TYPE_ABGR: - rs = 0; - gs = r + rs; - bs = g + gs; - as = b + bs; - break; - - case PIXMAN_TYPE_BGRA: - as = 0; - rs = PIXMAN_FORMAT_BPP (format) - (b + g + r); - gs = r + rs; - bs = g + gs; - break; - - case PIXMAN_TYPE_RGBA: - as = 0; - bs = PIXMAN_FORMAT_BPP (format) - (b + g + r); - gs = b + bs; - rs = g + gs; - break; - - case PIXMAN_TYPE_A: - as = 0; - rs = 0; - gs = 0; - bs = 0; - break; - - case PIXMAN_TYPE_OTHER: - case PIXMAN_TYPE_COLOR: - case PIXMAN_TYPE_GRAY: - case PIXMAN_TYPE_YUY2: - case PIXMAN_TYPE_YV12: - default: - abort (); - as = 0; - rs = 0; - gs = 0; - bs = 0; - break; - } - - if (MASK (a) != 0) - color->a = ((val >> as) & MASK (a)) / (double) MASK (a); - else - color->a = 1.0; - - if (MASK (r) != 0) - { - color->r = ((val >> rs) & MASK (r)) / (double) MASK (r); - color->g = ((val >> gs) & MASK (g)) / (double) MASK (g); - color->b = ((val >> bs) & MASK (b)) / (double) MASK (b); + pixman_format_code_t format = pixman_image_get_format (image); + value >>= 8 * sizeof(value) - PIXMAN_FORMAT_BPP (format); } - else - { - color->r = 0.0; - color->g = 0.0; - color->b = 0.0; - } - -#undef MASK -} - -static double -eval_diff (color_t *expected, color_t *test, pixman_format_code_t format) -{ - double rscale, gscale, bscale, ascale; - double rdiff, gdiff, bdiff, adiff; - - rscale = 1.0 * ((1 << PIXMAN_FORMAT_R (format)) - 1); - gscale = 1.0 * ((1 << PIXMAN_FORMAT_G (format)) - 1); - bscale = 1.0 * ((1 << PIXMAN_FORMAT_B (format)) - 1); - ascale = 1.0 * ((1 << PIXMAN_FORMAT_A (format)) - 1); - - rdiff = fabs (test->r - expected->r) * rscale; - bdiff = fabs (test->g - expected->g) * gscale; - gdiff = fabs (test->b - expected->b) * bscale; - adiff = fabs (test->a - expected->a) * ascale; +#endif - return MAX (MAX (MAX (rdiff, gdiff), bdiff), adiff); + return value; } static char * @@ -628,10 +494,10 @@ describe_image (image_t *info, char *buf) { if (info->size) { - sprintf (buf, "%s %dx%d%s", + sprintf (buf, "%s, %dx%d%s", info->format->name, info->size, info->size, - info->repeat ? "R" :""); + info->repeat ? " R" :""); } else { @@ -641,52 +507,40 @@ describe_image (image_t *info, char *buf) return buf; } -/* Test a composite of a given operation, source, mask, and destination - * picture. - * Fills the window, and samples from the 0,0 pixel corner. - */ +static char * +describe_color (const color_t *color, char *buf) +{ + sprintf (buf, "%.3f %.3f %.3f %.3f", + color->r, color->g, color->b, color->a); + + return buf; +} + static pixman_bool_t composite_test (image_t *dst, const operator_t *op, image_t *src, image_t *mask, - pixman_bool_t component_alpha) + pixman_bool_t component_alpha, + int testno) { pixman_color_t fill; pixman_rectangle16_t rect; - color_t expected, result, tdst, tsrc, tmsk; - double diff; - pixman_bool_t success = TRUE; + color_t expected, tdst, tsrc, tmsk; + pixel_checker_t checker; + /* Initialize dst */ compute_pixman_color (dst->color, &fill); rect.x = rect.y = 0; rect.width = rect.height = dst->size; - pixman_image_fill_rectangles (PIXMAN_OP_SRC, dst->image, - &fill, 1, &rect); + pixman_image_fill_rectangles (PIXMAN_OP_SRC, dst->image, &fill, 1, &rect); - if (mask != NULL) + if (mask) { pixman_image_set_component_alpha (mask->image, component_alpha); - pixman_image_composite (op->op, src->image, mask->image, dst->image, - 0, 0, - 0, 0, - 0, 0, - dst->size, dst->size); - tmsk = *mask->color; - if (mask->size) - { - color_correct (mask->format->format, &tmsk); - - if (component_alpha && - PIXMAN_FORMAT_R (mask->format->format) == 0) - { - /* Ax component-alpha masks expand alpha into - * all color channels. - */ - tmsk.r = tmsk.g = tmsk.b = tmsk.a; - } - } + pixman_image_composite (op->op, src->image, mask->image, dst->image, + 0, 0, 0, 0, 0, 0, dst->size, dst->size); } else { @@ -696,71 +550,81 @@ composite_test (image_t *dst, 0, 0, dst->size, dst->size); } - get_pixel (dst->image, dst->format->format, &result); tdst = *dst->color; - color_correct (dst->format->format, &tdst); + round_color (dst->format->format, &tdst); + tsrc = *src->color; if (src->size) - color_correct (src->format->format, &tsrc); - do_composite (op->op, &tsrc, mask ? &tmsk : NULL, &tdst, - &expected, component_alpha); - color_correct (dst->format->format, &expected); - - diff = eval_diff (&expected, &result, dst->format->format); - - /* FIXME: We should find out what deviation is acceptable. 3.0 - * is clearly absurd for 2 bit formats for example. On the other - * hand currently 1.0 does not work. - */ - if (diff > 3.0) + round_color (src->format->format, &tsrc); + + if (mask) { - char buf[40]; + tmsk = *mask->color; + if (mask->size) + round_color (mask->format->format, &tmsk); + if (component_alpha && PIXMAN_FORMAT_R (mask->format->format) == 0) + { + /* Ax component-alpha masks expand alpha into + * all color channels. + */ + tmsk.r = tmsk.g = tmsk.b = tmsk.a; + } + } - sprintf (buf, "%s %scomposite", - op->name, - component_alpha ? "CA " : ""); + do_composite (op->op, + &tsrc, + mask? &tmsk : NULL, + &tdst, + &expected, + component_alpha); - printf ("%s test error of %.4f --\n" - " R G B A\n" - "got: %.2f %.2f %.2f %.2f [%08lx]\n" - "expected: %.2f %.2f %.2f %.2f\n", - buf, diff, - result.r, result.g, result.b, result.a, - *(unsigned long *) pixman_image_get_data (dst->image), - expected.r, expected.g, expected.b, expected.a); + pixel_checker_init (&checker, dst->format->format); + if (!pixel_checker_check (&checker, get_value (dst->image), &expected)) + { + char buf[40], buf2[40]; + int a, r, g, b; + uint32_t pixel; + + printf ("---- Test %d failed ----\n", testno); + printf ("Operator: %s %s\n", + op->name, component_alpha ? "CA" : ""); + + printf ("Source: %s\n", describe_image (src, buf)); if (mask != NULL) + printf ("Mask: %s\n", describe_image (mask, buf)); + + printf ("Destination: %s\n\n", describe_image (dst, buf)); + printf (" R G B A Rounded\n"); + printf ("Source color: %s %s\n", + describe_color (src->color, buf), + describe_color (&tsrc, buf2)); + if (mask) { - printf ("src color: %.2f %.2f %.2f %.2f\n" - "msk color: %.2f %.2f %.2f %.2f\n" - "dst color: %.2f %.2f %.2f %.2f\n", - src->color->r, src->color->g, - src->color->b, src->color->a, - mask->color->r, mask->color->g, - mask->color->b, mask->color->a, - dst->color->r, dst->color->g, - dst->color->b, dst->color->a); - printf ("src: %s, ", describe_image (src, buf)); - printf ("mask: %s, ", describe_image (mask, buf)); - printf ("dst: %s\n\n", describe_image (dst, buf)); - } - else - { - printf ("src color: %.2f %.2f %.2f %.2f\n" - "dst color: %.2f %.2f %.2f %.2f\n", - src->color->r, src->color->g, - src->color->b, src->color->a, - dst->color->r, dst->color->g, - dst->color->b, dst->color->a); - printf ("src: %s, ", describe_image (src, buf)); - printf ("dst: %s\n\n", describe_image (dst, buf)); + printf ("Mask color: %s %s\n", + describe_color (mask->color, buf), + describe_color (&tmsk, buf2)); } + printf ("Dest. color: %s %s\n", + describe_color (dst->color, buf), + describe_color (&tdst, buf2)); - success = FALSE; - } + pixel = get_value (dst->image); + + printf ("Expected: %s\n", describe_color (&expected, buf)); - return success; + pixel_checker_split_pixel (&checker, pixel, &a, &r, &g, &b); + + printf ("Got: %5d %5d %5d %5d [pixel: 0x%08x]\n", r, g, b, a, pixel); + pixel_checker_get_min (&checker, &expected, &a, &r, &g, &b); + printf ("Min accepted: %5d %5d %5d %5d\n", r, g, b, a); + pixel_checker_get_max (&checker, &expected, &a, &r, &g, &b); + printf ("Max accepted: %5d %5d %5d %5d\n", r, g, b, a); + + return FALSE; + } + return TRUE; } static void @@ -791,7 +655,7 @@ image_init (image_t *info, pixman_image_fill_rectangles (PIXMAN_OP_SRC, info->image, &fill, 1, &rect); - if (size & REPEAT) + if (sizes[size] & REPEAT) { pixman_image_set_repeat (info->image, PIXMAN_REPEAT_NORMAL); info->repeat = PIXMAN_REPEAT_NORMAL; @@ -836,7 +700,7 @@ run_test (uint32_t seed) int ok; lcg_srand (seed); - + image_init (&dst, random_color(), random_format(), 1); image_init (&src, random_color(), random_format(), random_size()); image_init (&mask, random_color(), random_format(), random_size()); @@ -848,14 +712,14 @@ run_test (uint32_t seed) switch (ca) { case 0: - ok = composite_test (&dst, op, &src, NULL, FALSE); + ok = composite_test (&dst, op, &src, NULL, FALSE, seed); break; case 1: - ok = composite_test (&dst, op, &src, &mask, FALSE); + ok = composite_test (&dst, op, &src, &mask, FALSE, seed); break; case 2: ok = composite_test (&dst, op, &src, &mask, - mask.size? TRUE : FALSE); + mask.size? TRUE : FALSE, seed); break; default: ok = FALSE; @@ -879,7 +743,7 @@ main (int argc, char **argv) if (argc > 1) { char *end; - + i = strtol (argv[1], &end, 0); if (end != argv[1]) @@ -900,7 +764,7 @@ main (int argc, char **argv) seed = get_random_seed(); else seed = 1; - + #ifdef USE_OPENMP # pragma omp parallel for default(none) shared(result, argv, seed) #endif @@ -909,10 +773,10 @@ main (int argc, char **argv) if (!result && !run_test (i + seed)) { printf ("Test 0x%08X failed.\n", seed + i); - + result = seed + i; } } - + return result; } diff --git a/pixman/test/utils.c b/pixman/test/utils.c index 204066f9b..379bd71a8 100644 --- a/pixman/test/utils.c +++ b/pixman/test/utils.c @@ -703,3 +703,178 @@ initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb) assert (palette->ent[CONVERT_15 (palette->rgba[i], is_rgb)] == i); } } + +static double +round_channel (double p, int m) +{ + int t; + double r; + + t = p * ((1 << m)); + t -= t >> m; + + r = t / (double)((1 << m) - 1); + + return r; +} + +void +round_color (pixman_format_code_t format, color_t *color) +{ + if (PIXMAN_FORMAT_R (format) == 0) + { + color->r = 0.0; + color->g = 0.0; + color->b = 0.0; + } + else + { + color->r = round_channel (color->r, PIXMAN_FORMAT_R (format)); + color->g = round_channel (color->g, PIXMAN_FORMAT_G (format)); + color->b = round_channel (color->b, PIXMAN_FORMAT_B (format)); + } + + if (PIXMAN_FORMAT_A (format) == 0) + color->a = 1; + else + color->a = round_channel (color->a, PIXMAN_FORMAT_A (format)); +} + +/* Check whether @pixel is a valid quantization of the a, r, g, b + * parameters. Some slack is permitted. + */ +void +pixel_checker_init (pixel_checker_t *checker, pixman_format_code_t format) +{ + assert (PIXMAN_FORMAT_VIS (format)); + + checker->format = format; + + switch (PIXMAN_FORMAT_TYPE (format)) + { + case PIXMAN_TYPE_A: + checker->bs = 0; + checker->gs = 0; + checker->rs = 0; + checker->as = 0; + break; + + case PIXMAN_TYPE_ARGB: + checker->bs = 0; + checker->gs = checker->bs + PIXMAN_FORMAT_B (format); + checker->rs = checker->gs + PIXMAN_FORMAT_G (format); + checker->as = checker->rs + PIXMAN_FORMAT_R (format); + break; + + case PIXMAN_TYPE_ABGR: + checker->rs = 0; + checker->gs = checker->rs + PIXMAN_FORMAT_R (format); + checker->bs = checker->gs + PIXMAN_FORMAT_G (format); + checker->as = checker->bs + PIXMAN_FORMAT_B (format); + break; + + case PIXMAN_TYPE_BGRA: + /* With BGRA formats we start counting at the high end of the pixel */ + checker->bs = PIXMAN_FORMAT_BPP (format) - PIXMAN_FORMAT_B (format); + checker->gs = checker->bs - PIXMAN_FORMAT_B (format); + checker->rs = checker->gs - PIXMAN_FORMAT_G (format); + checker->as = checker->rs - PIXMAN_FORMAT_R (format); + break; + + case PIXMAN_TYPE_RGBA: + /* With BGRA formats we start counting at the high end of the pixel */ + checker->rs = PIXMAN_FORMAT_BPP (format) - PIXMAN_FORMAT_R (format); + checker->gs = checker->rs - PIXMAN_FORMAT_R (format); + checker->bs = checker->gs - PIXMAN_FORMAT_G (format); + checker->as = checker->bs - PIXMAN_FORMAT_B (format); + break; + + default: + assert (0); + break; + } + + checker->am = ((1 << PIXMAN_FORMAT_A (format)) - 1) << checker->as; + checker->rm = ((1 << PIXMAN_FORMAT_R (format)) - 1) << checker->rs; + checker->gm = ((1 << PIXMAN_FORMAT_G (format)) - 1) << checker->gs; + checker->bm = ((1 << PIXMAN_FORMAT_B (format)) - 1) << checker->bs; + + checker->aw = PIXMAN_FORMAT_A (format); + checker->rw = PIXMAN_FORMAT_R (format); + checker->gw = PIXMAN_FORMAT_G (format); + checker->bw = PIXMAN_FORMAT_B (format); +} + +void +pixel_checker_split_pixel (const pixel_checker_t *checker, uint32_t pixel, + int *a, int *r, int *g, int *b) +{ + *a = (pixel & checker->am) >> checker->as; + *r = (pixel & checker->rm) >> checker->rs; + *g = (pixel & checker->gm) >> checker->gs; + *b = (pixel & checker->bm) >> checker->bs; +} + +static int32_t +convert (double v, uint32_t width, uint32_t mask, uint32_t shift, double def) +{ + int32_t r; + + if (!mask) + v = def; + + r = (v * ((mask >> shift) + 1)); + r -= r >> width; + + return r; +} + +static void +get_limits (const pixel_checker_t *checker, double limit, + color_t *color, + int *ao, int *ro, int *go, int *bo) +{ + *ao = convert (color->a + limit, checker->aw, checker->am, checker->as, 1.0); + *ro = convert (color->r + limit, checker->rw, checker->rm, checker->rs, 0.0); + *go = convert (color->g + limit, checker->gw, checker->gm, checker->gs, 0.0); + *bo = convert (color->b + limit, checker->bw, checker->bm, checker->bs, 0.0); +} + +/* The acceptable deviation in units of [0.0, 1.0] + */ +#define DEVIATION (0.004) + +void +pixel_checker_get_max (const pixel_checker_t *checker, color_t *color, + int *am, int *rm, int *gm, int *bm) +{ + get_limits (checker, DEVIATION, color, am, rm, gm, bm); +} + +void +pixel_checker_get_min (const pixel_checker_t *checker, color_t *color, + int *am, int *rm, int *gm, int *bm) +{ + get_limits (checker, - DEVIATION, color, am, rm, gm, bm); +} + +pixman_bool_t +pixel_checker_check (const pixel_checker_t *checker, uint32_t pixel, + color_t *color) +{ + int32_t a_lo, a_hi, r_lo, r_hi, g_lo, g_hi, b_lo, b_hi; + int32_t ai, ri, gi, bi; + pixman_bool_t result; + + pixel_checker_get_min (checker, color, &a_lo, &r_lo, &g_lo, &b_lo); + pixel_checker_get_max (checker, color, &a_hi, &r_hi, &g_hi, &b_hi); + pixel_checker_split_pixel (checker, pixel, &ai, &ri, &gi, &bi); + + result = + a_lo <= ai && ai <= a_hi && + r_lo <= ri && ri <= r_hi && + g_lo <= gi && gi <= g_hi && + b_lo <= bi && bi <= b_hi; + + return result; +} diff --git a/pixman/test/utils.h b/pixman/test/utils.h index 3bff78e76..3c0647bc6 100644 --- a/pixman/test/utils.h +++ b/pixman/test/utils.h @@ -151,3 +151,38 @@ aligned_malloc (size_t align, size_t size); void initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb); + +typedef struct +{ + double r, g, b, a; +} color_t; + +void +round_color (pixman_format_code_t format, color_t *color); + +typedef struct +{ + pixman_format_code_t format; + uint32_t am, rm, gm, bm; + uint32_t as, rs, gs, bs; + uint32_t aw, rw, gw, bw; +} pixel_checker_t; + +void +pixel_checker_init (pixel_checker_t *checker, pixman_format_code_t format); + +void +pixel_checker_split_pixel (const pixel_checker_t *checker, uint32_t pixel, + int *a, int *r, int *g, int *b); + +void +pixel_checker_get_max (const pixel_checker_t *checker, color_t *color, + int *a, int *r, int *g, int *b); + +void +pixel_checker_get_min (const pixel_checker_t *checker, color_t *color, + int *a, int *r, int *g, int *b); + +pixman_bool_t +pixel_checker_check (const pixel_checker_t *checker, + uint32_t pixel, color_t *color); |