From 905856f43d38b5f2932d8b459e805e1c86b7a2f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Sandmann=20Pedersen?= Date: Tue, 23 Jun 2009 16:37:35 -0400 Subject: [PATCH] Add convolution-test.c program --- test/Makefile.am | 4 ++++ test/convolution-test.c | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/convolution-test.c diff --git a/test/Makefile.am b/test/Makefile.am index 01d065b..2590617 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -25,6 +25,7 @@ TESTPROGRAMS += \ gradient-test \ alpha-test \ screen-test \ + convolution-test \ trap-test noinst_PROGRAMS = $(TESTPROGRAMS) @@ -52,5 +53,8 @@ trap_test_SOURCES = trap-test.c utils.c utils.h screen_test_LDADD = $(GTK_LDADD) screen_test_SOURCES = screen-test.c utils.c utils.h +convolution_test_LDADD = $(GTK_LDADD) +convolution_test_SOURCES = convolution-test.c utils.c utils.h + endif diff --git a/test/convolution-test.c b/test/convolution-test.c new file mode 100644 index 0000000..8609d38 --- /dev/null +++ b/test/convolution-test.c @@ -0,0 +1,47 @@ +#include +#include +#include "pixman.h" +#include "utils.h" + +int +main (int argc, char **argv) +{ +#define WIDTH 200 +#define HEIGHT 200 + +#define d2f pixman_double_to_fixed + + uint32_t *src = malloc (WIDTH * HEIGHT * 4); + uint32_t *mask = malloc (WIDTH * HEIGHT * 4); + uint32_t *dest = malloc (WIDTH * HEIGHT * 4); + pixman_fixed_t convolution[] = + { + d2f (3), d2f (3), + d2f (0.5), d2f (0.5), d2f (0.5), + d2f (0.5), d2f (0.5), d2f (0.5), + d2f (0.5), d2f (0.5), d2f (0.5), + }; + pixman_image_t *simg, *mimg, *dimg; + + int i; + + for (i = 0; i < WIDTH * HEIGHT; ++i) + { + src[i] = 0x7f007f00; + mask[i] = (i % 256) * 0x01000000; + dest[i] = 0; + } + + simg = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, src, WIDTH * 4); + mimg = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, mask, WIDTH * 4); + dimg = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4); + + pixman_image_set_filter (mimg, PIXMAN_FILTER_CONVOLUTION, + convolution, 11); + + pixman_image_composite (PIXMAN_OP_OVER, simg, mimg, dimg, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); + + show_image (dimg); + + return 0; +} -- 2.34.1