summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <sandmann@redhat.com>2010-01-16 09:48:45 -0500
committerSøren Sandmann Pedersen <sandmann@redhat.com>2010-01-17 16:47:15 -0500
commit042f978b04aefe56ec912c88ec879e668153a287 (patch)
treea435e8a759a7176670fc3351612c44ec1b9c25de /test
parent05c38141b4861348bf61235341d634019e39e8a9 (diff)
test: Add new alphamap test program.
This program demonstrates three bugs relating to alpha maps: - When fetching from an alpha map into 32 bit intermediates, we use the fetcher from the image, and not the one from the alpha map. - For 64 bit intermediates we call fetch_pixel_generic_lossy_32() which then calls fetch_pixel_raw_64, which is NULL because alpha images are never validated. - The alpha map should be used *in place* of any existing alpha channel, but we are actually multiplying it onto the image.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am7
-rw-r--r--test/alphamap.c49
-rw-r--r--test/utils.c14
-rw-r--r--test/utils.h4
4 files changed, 73 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index ab987566..5f6ba13a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -7,6 +7,7 @@ TESTPROGRAMS = \
oob-test \
window-test \
trap-crasher \
+ alphamap \
blitters-test \
scaling-test \
composite
@@ -24,6 +25,9 @@ blitters_test_SOURCES = blitters-test.c utils.c utils.h
scaling_test_LDADD = $(TEST_LDADD)
scaling_test_SOURCES = scaling-test.c utils.c utils.h
+alphamap_LDADD = $(TEST_LDADD)
+alphamap_SOURCES = alphamap.c utils.c utils.h
+
# GTK using test programs
if HAVE_GTK
@@ -39,7 +43,8 @@ TESTPROGRAMS_GTK = \
alpha-test \
screen-test \
convolution-test \
- trap-test
+ trap-test \
+ alphamap
INCLUDES += $(GTK_CFLAGS)
diff --git a/test/alphamap.c b/test/alphamap.c
new file mode 100644
index 00000000..e6a25efc
--- /dev/null
+++ b/test/alphamap.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "utils.h"
+
+#define WIDTH 400
+#define HEIGHT 200
+
+int
+main (int argc, char **argv)
+{
+ uint8_t *alpha = make_random_bytes (WIDTH * HEIGHT);
+ uint32_t *src = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * 4);
+ uint32_t *dest = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * 4);
+ int i;
+
+ pixman_image_t *a = pixman_image_create_bits (PIXMAN_a8, WIDTH, HEIGHT, (uint32_t *)alpha, WIDTH);
+ pixman_image_t *d = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4);
+
+ for (i = 0; i < 2; ++i)
+ {
+ pixman_format_code_t sformat = (i == 0)? PIXMAN_a8r8g8b8 : PIXMAN_a2r10g10b10;
+ pixman_image_t *s = pixman_image_create_bits (sformat, WIDTH, HEIGHT, src, WIDTH * 4);
+ int j, k;
+
+ pixman_image_set_alpha_map (s, a, 0, 0);
+
+ pixman_image_composite (PIXMAN_OP_SRC, s, NULL, d, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
+
+ for (j = 0; j < HEIGHT; ++j)
+ {
+ for (k = 0; k < WIDTH; ++k)
+ {
+ uint8_t ap = ((uint8_t *)alpha)[j * WIDTH + k];
+ uint32_t dap = (dest[j * WIDTH + k] >> 24);
+ uint32_t sap = (src[j * WIDTH + k] >> 24);
+
+ if (ap != dap)
+ {
+ printf ("Wrong alpha value at (%d, %d). Should be %d; got %d (src was %d)\n", k, j, ap, dap, sap);
+ return 1;
+ }
+ }
+ }
+
+ pixman_image_unref (s);
+ }
+
+ return 0;
+}
diff --git a/test/utils.c b/test/utils.c
index 1e42d89d..58cd100e 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -192,3 +192,17 @@ image_endian_swap (pixman_image_t *img, int bpp)
}
}
+uint8_t *
+make_random_bytes (int n_bytes)
+{
+ uint8_t *bytes = malloc (n_bytes);
+ int i;
+
+ if (!bytes)
+ return NULL;
+
+ for (i = 0; i < n_bytes; ++i)
+ bytes[i] = lcg_rand () & 0xff;
+
+ return bytes;
+}
diff --git a/test/utils.h b/test/utils.h
index 8fdb2ce4..fb1ccec4 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -39,3 +39,7 @@ compute_crc32 (uint32_t in_crc32,
*/
void
image_endian_swap (pixman_image_t *img, int bpp);
+
+/* Generate n_bytes random bytes in malloced memory */
+uint8_t *
+make_random_bytes (int n_bytes);