summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authortabe <none@none>2008-12-21 09:08:11 +0000
committertabe <none@none>2008-12-21 09:08:11 +0000
commit43be24fd8b4d0c68f1d110b755a3848217e46a5d (patch)
tree5a72ab95d1ae674467dd070aaef3836263c50b74 /tests
parent9e99669aec24768c5ba89545f4e3b5663f45a6f3 (diff)
downloadlibgd-43be24fd8b4d0c68f1d110b755a3848217e46a5d.tar.gz
added new filter gdImagePixelate(). (see FS#184)
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/gdimagepixelate/CMakeLists.txt9
-rw-r--r--tests/gdimagepixelate/Makefile.am4
-rw-r--r--tests/gdimagepixelate/gdimagepixelate.c87
5 files changed, 102 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index ac45d79..9e6b35c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -30,6 +30,7 @@ if (BUILD_TEST)
gdimagecolordeallocate
gdimagecolortransparent
#gdimageellipse
+ gdimagepixelate
gdimageline
gdimagefilledellipse
gdimagecopyrotated
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 532286c..7761e7f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in -*-Makefile-*-
AUTOMAKE_OPTIONS = foreign 1.7
-SUBDIRS = gd2 gdimagecolordeallocate gdimagecolortransparent gdimagefill gdimagefilltoborder gdtest jpeg gdimagearc gdimagecolorexact gdimagecopy gdimagefilledellipse gdimageline gdtiled freetype gdimagecolorclosest gdimagecolorreplace gdimagecolorresolve gdimagecopyrotated gdimagefilledrectangle gdimagerectangle gif png xpm
+SUBDIRS = gd2 gdimagecolordeallocate gdimagecolortransparent gdimagefill gdimagefilltoborder gdtest jpeg gdimagearc gdimagecolorexact gdimagecopy gdimagefilledellipse gdimageline gdimagepixelate gdtiled freetype gdimagecolorclosest gdimagecolorreplace gdimagecolorresolve gdimagecopyrotated gdimagefilledrectangle gdimagerectangle gif png xpm
EXTRA_DIST = CMakeLists.txt
diff --git a/tests/gdimagepixelate/CMakeLists.txt b/tests/gdimagepixelate/CMakeLists.txt
new file mode 100644
index 0000000..205f90c
--- /dev/null
+++ b/tests/gdimagepixelate/CMakeLists.txt
@@ -0,0 +1,9 @@
+SET(TESTS_FILES
+ gdimagepixelate
+)
+
+FOREACH(test_name ${TESTS_FILES})
+ add_executable(${test_name} "${test_name}.c")
+ target_link_libraries (${test_name} ${GDTESTS_TARGET_LINK})
+ ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)
diff --git a/tests/gdimagepixelate/Makefile.am b/tests/gdimagepixelate/Makefile.am
new file mode 100644
index 0000000..d668b51
--- /dev/null
+++ b/tests/gdimagepixelate/Makefile.am
@@ -0,0 +1,4 @@
+## Process this file with automake to produce Makefile.in -*-Makefile-*-
+AUTOMAKE_OPTIONS = foreign 1.7
+
+EXTRA_DIST = CMakeLists.txt gdimagepixelate.c
diff --git a/tests/gdimagepixelate/gdimagepixelate.c b/tests/gdimagepixelate/gdimagepixelate.c
new file mode 100644
index 0000000..82f7216
--- /dev/null
+++ b/tests/gdimagepixelate/gdimagepixelate.c
@@ -0,0 +1,87 @@
+#include "gdtest.h"
+#include "gd.h"
+
+#define WIDTH 12
+#define BLOCK_SIZE 4
+
+static const int expected_upperleft[][3] = {
+ {0x000000, 0x040404, 0x080808},
+ {0x303030, 0x343434, 0x383838},
+ {0x606060, 0x646464, 0x686868}
+};
+
+static const int expected_average[][3] = {
+ {0x131313, 0x171717, 0x1b1b1b},
+ {0x434343, 0x474747, 0x4b4b4b},
+ {0x737373, 0x777777, 0x7b7b7b},
+};
+
+#define SETUP_PIXELS(im) do { \
+ int x, y, i = 0; \
+ for (y = 0; y < (im)->sy; y++) { \
+ for (x = 0; x < (im)->sx; x++) { \
+ int p = gdImageColorResolve(im, i, i, i); \
+ gdImageSetPixel(im, x, y, p); \
+ i++; \
+ } \
+ } \
+ } while (0)
+
+#define CHECK_PIXELS(im, expected) do { \
+ int x, y; \
+ for (y = 0; y < (im)->sy; y++) { \
+ for (x = 0; x < (im)->sx; x++) { \
+ int p = gdImageGetPixel(im, x, y); \
+ int r = ((expected)[y/BLOCK_SIZE][x/BLOCK_SIZE]>>16)&0xFF; \
+ int g = ((expected)[y/BLOCK_SIZE][x/BLOCK_SIZE]>> 8)&0xFF; \
+ int b = ((expected)[y/BLOCK_SIZE][x/BLOCK_SIZE] )&0xFF; \
+ if (r != gdImageRed(im, p)) { \
+ printf("Red %x is expected, but %x\n", r, gdImageRed(im, p)); \
+ return 0; \
+ } \
+ if (g != gdImageGreen(im, p)) { \
+ printf("Green %x is expected, but %x\n", g, gdImageGreen(im, p)); \
+ return 0; \
+ } \
+ if (b != gdImageBlue(im, p)) { \
+ printf("Blue %x is expected, but %x\n", b, gdImageBlue(im, p)); \
+ return 0; \
+ } \
+ } \
+ } \
+ } while (0)
+
+static int testPixelate(gdImagePtr im)
+{
+ if (gdImagePixelate(im, -1, GD_PIXELATE_UPPERLEFT) != 0) return 0;
+ if (gdImagePixelate(im, 1, GD_PIXELATE_UPPERLEFT) != 1) return 0;
+
+ SETUP_PIXELS(im);
+ if (!gdImagePixelate(im, BLOCK_SIZE, GD_PIXELATE_UPPERLEFT)) return 0;
+ CHECK_PIXELS(im, expected_upperleft);
+
+ SETUP_PIXELS(im);
+ if (!gdImagePixelate(im, BLOCK_SIZE, GD_PIXELATE_AVERAGE)) return 0;
+ CHECK_PIXELS(im, expected_average);
+
+ return 1;
+}
+
+int main()
+{
+ gdImagePtr im;
+
+ im = gdImageCreate(WIDTH, WIDTH);
+ if (!testPixelate(im)) {
+ return 1;
+ }
+ gdImageDestroy(im);
+
+ im = gdImageCreateTrueColor(WIDTH, WIDTH);
+ if (!testPixelate(im)) {
+ return 2;
+ }
+ gdImageDestroy(im);
+
+ return 0;
+}