diff options
author | Jeff Muizelaar <jeff@infidigm.net> | 2005-08-05 11:15:04 +0000 |
---|---|---|
committer | Jeff Muizelaar <jeff@infidigm.net> | 2005-08-05 11:15:04 +0000 |
commit | 5f78feda5d9819f82ff99911b90cd09e228466a9 (patch) | |
tree | 1c423c861e296aa707975ec410e8c530da819fa0 /test/buffer-diff.c | |
parent | 2e1eaa88ff07fbd2048c76587cd6b9ca565fa047 (diff) |
rewrite buffer_diff to be endian safe and add a new fuction buffer_diff_noalpha
Diffstat (limited to 'test/buffer-diff.c')
-rw-r--r-- | test/buffer-diff.c | 83 |
1 files changed, 57 insertions, 26 deletions
diff --git a/test/buffer-diff.c b/test/buffer-diff.c index 8e0031b1f..78284efcd 100644 --- a/test/buffer-diff.c +++ b/test/buffer-diff.c @@ -33,6 +33,7 @@ #endif #include <errno.h> #include <string.h> +#include <pixman.h> #include "cairo-test.h" @@ -51,18 +52,27 @@ xunlink (const char *pathname) } } -int -buffer_diff (unsigned char *buf_a, - unsigned char *buf_b, - unsigned char *buf_diff, - int width, - int height, - int stride) + +/* This function should be rewritten to compare all formats supported by + * cairo_format_t instead of taking a mask as a parameter. + */ +static int +buffer_diff_core (unsigned char *_buf_a, + unsigned char *_buf_b, + unsigned char *_buf_diff, + int width, + int height, + int stride, + pixman_bits_t mask) { int x, y; - unsigned char *row_a, *row_b, *row; + pixman_bits_t *row_a, *row_b, *row; int pixels_changed = 0; + pixman_bits_t *buf_a = (pixman_bits_t*)_buf_a; + pixman_bits_t *buf_b = (pixman_bits_t*)_buf_b; + pixman_bits_t *buf_diff = (pixman_bits_t*)_buf_diff; + stride /= sizeof(pixman_bits_t); for (y = 0; y < height; y++) { row_a = buf_a + y * stride; @@ -70,33 +80,54 @@ buffer_diff (unsigned char *buf_a, row = buf_diff + y * stride; for (x = 0; x < width; x++) { - int channel; - unsigned char value_a, value_b; - int pixel_differs = 0; - for (channel = 0; channel < 4; channel++) - { - double diff; - value_a = row_a[x * 4 + channel]; - value_b = row_b[x * 4 + channel]; - if (value_a != value_b) - pixel_differs = 1; - diff = value_a - value_b; - row[x * 4 + channel] = 128 + diff / 3.0; - } - if (pixel_differs) { + /* check if the pixels are the same */ + if ((row_a[x] & mask) != (row_b[x] & mask)) { + int channel; + pixman_bits_t diff_pixel = 0; + + /* calculate a difference value for all 4 channels */ + for (channel = 0; channel < 4; channel++) { + unsigned char value_a = (row_a[x] >> (channel*8)); + unsigned char value_b = (row_b[x] >> (channel*8)); + double diff; + diff = value_a - value_b; + diff_pixel |= (unsigned char)(128 + diff / 3.0) << (channel*8); + } + pixels_changed++; + row[x] = diff_pixel; } else { - row[x*4+0] = 0; - row[x*4+1] = 0; - row[x*4+2] = 0; + row[x] = 0; } - row[x * 4 + 3] = 0xff; /* Set ALPHA to 100% (opaque) */ + row[x] |= 0xff000000; /* Set ALPHA to 100% (opaque) */ } } return pixels_changed; } +int +buffer_diff (unsigned char *buf_a, + unsigned char *buf_b, + unsigned char *buf_diff, + int width, + int height, + int stride) +{ + return buffer_diff_core(buf_a, buf_b, buf_diff, width, height, stride, 0xffffffff); +} + +int +buffer_diff_noalpha (unsigned char *buf_a, + unsigned char *buf_b, + unsigned char *buf_diff, + int width, + int height, + int stride) +{ + return buffer_diff_core(buf_a, buf_b, buf_diff, width, height, stride, 0x00ffffff); +} + /* Image comparison code courtesy of Richard Worth <richard@theworths.org> * Returns number of pixels changed, (or -1 on error). * Also saves a "diff" image intended to visually show where the |