Modified: gd/trunk/libgd/src/CMakeLists.txt =================================================================== --- gd/trunk/libgd/src/CMakeLists.txt 2009-08-06 04:37:07 UTC (rev 286865) +++ gd/trunk/libgd/src/CMakeLists.txt 2009-08-06 04:40:15 UTC (rev 286866) @@ -14,6 +14,7 @@ gdpp.h gd_bmp.c bmp.h + gd_filter.c gd_gd.c gd_gd2.c gd_io.c Modified: gd/trunk/libgd/src/Makefile.am =================================================================== --- gd/trunk/libgd/src/Makefile.am 2009-08-06 04:37:07 UTC (rev 286865) +++ gd/trunk/libgd/src/Makefile.am 2009-08-06 04:40:15 UTC (rev 286866) @@ -13,7 +13,7 @@ lib_LTLIBRARIES = libgd.la -libgd_la_SOURCES = gd.c gd_color.c gd_color_map.c gd_transform.c gdfx.c gd_security.c gd_gd.c gd_gd2.c gd_io.c gd_io_dp.c gd_gif_in.c gd_gif_out.c gd_io_file.c gd_io_ss.c gd_jpeg.c gd_png.c gd_ss.c gd_topal.c gd_wbmp.c gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c gdft.c gdhelpers.c gdhelpers.h gdkanji.c gdtables.c gdxpm.c jisx0208.h wbmp.c wbmp.h gd_pixelate.c +libgd_la_SOURCES = gd.c gd_color.c gd_color_map.c gd_transform.c gdfx.c gd_security.c gd_gd.c gd_gd2.c gd_io.c gd_io_dp.c gd_gif_in.c gd_gif_out.c gd_io_file.c gd_io_ss.c gd_jpeg.c gd_png.c gd_ss.c gd_topal.c gd_wbmp.c gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c gdft.c gdhelpers.c gdhelpers.h gdkanji.c gdtables.c gdxpm.c jisx0208.h wbmp.c wbmp.h gd_pixelate.c gd_filter.c libgd_la_LDFLAGS = -version-info 2:0:0 $(XTRA_LDFLAGS) Modified: gd/trunk/libgd/src/gd.h =================================================================== --- gd/trunk/libgd/src/gd.h 2009-08-06 04:37:07 UTC (rev 286865) +++ gd/trunk/libgd/src/gd.h 2009-08-06 04:40:15 UTC (rev 286866) @@ -784,6 +784,18 @@ BGD_DECLARE(int) gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode); +typedef struct { + int sub; + int plus; + unsigned int num_colors; + int *colors; + unsigned int seed; +} gdScatter, *gdScatterPtr; + +BGD_DECLARE(int) gdImageScatter(gdImagePtr im, int sub, int plus); +BGD_DECLARE(int) gdImageScatterColor(gdImagePtr im, int sub, int plus, int colors[], unsigned int num_colors); +BGD_DECLARE(int) gdImageScatterEx(gdImagePtr im, gdScatterPtr s); + /* Macros to access information about images. */ /* Returns nonzero if the image is a truecolor image, Added: gd/trunk/libgd/src/gd_filter.c =================================================================== --- gd/trunk/libgd/src/gd_filter.c (rev 0) +++ gd/trunk/libgd/src/gd_filter.c 2009-08-06 04:40:15 UTC (rev 286866) @@ -0,0 +1,99 @@ +#include "gd.h" + +#ifdef WIN32 +# include +#else +# include +#endif +#include +#include + +#define PIXEL_FUNCTION_DECLARE(f) int (*f)(gdImagePtr, int, int) + +#define GET_PIXEL_FUNCTION(src)(src->trueColor ? gdImageGetTrueColorPixel : gdImageGetPixel) + +#ifdef WIN32 +# define GD_SCATTER_SEED() (unsigned int)(time(0) * GetCurrentProcessId()) +#else +# define GD_SCATTER_SEED() (unsigned int)(time(0) * getpid()) +#endif + +int gdImageScatter(gdImagePtr im, int sub, int plus) +{ + gdScatter s; + + s.sub = sub; + s.plus = plus; + s.num_colors = 0; + s.seed = GD_SCATTER_SEED(); + return gdImageScatterEx(im, &s); +} + +int gdImageScatterColor(gdImagePtr im, int sub, int plus, int colors[], unsigned int num_colors) +{ + gdScatter s; + + s.sub = sub; + s.plus = plus; + s.colors = colors; + s.num_colors = num_colors; + s.seed = GD_SCATTER_SEED(); + return gdImageScatterEx(im, &s); +} + +#define GD_SCATTER_MAIN() do { \ + dest_x = (int) (x + ((rand() % (plus - sub)) + sub)); \ + dest_y = (int) (y + ((rand() % (plus - sub)) + sub)); \ + \ + if (!gdImageBoundsSafe(im, dest_x, dest_y)) { \ + continue; \ + } \ + \ + pxl = f(im, x, y); \ + new_pxl = f(im, dest_x, dest_y); \ + } while (0) + +int gdImageScatterEx(gdImagePtr im, gdScatterPtr scatter) +{ + register int x, y; + int dest_x, dest_y; + int pxl, new_pxl; + unsigned int n; + int sub = scatter->sub, plus = scatter->plus; + PIXEL_FUNCTION_DECLARE(f); + + if (plus == 0 && sub == 0) { + return 1; + } else if (sub >= plus) { + return 0; + } + + f = GET_PIXEL_FUNCTION(im); + (void)srand(scatter->seed); + + if (scatter->num_colors) { + for (y = 0; y < im->sy; y++) { + for (x = 0; x < im->sx; x++) { + GD_SCATTER_MAIN(); + + for (n = 0; n < scatter->num_colors; n++) { + if (pxl == scatter->colors[n]) { + gdImageSetPixel(im, dest_x, dest_y, pxl); + gdImageSetPixel(im, x, y, new_pxl); + } + } + } + } + } else { + for (y = 0; y < im->sy; y++) { + for (x = 0; x < im->sx; x++) { + GD_SCATTER_MAIN(); + + gdImageSetPixel(im, dest_x, dest_y, pxl); + gdImageSetPixel(im, x, y, new_pxl); + } + } + } + + return 1; +} Modified: gd/trunk/libgd/tests/CMakeLists.txt =================================================================== --- gd/trunk/libgd/tests/CMakeLists.txt 2009-08-06 04:37:07 UTC (rev 286865) +++ gd/trunk/libgd/tests/CMakeLists.txt 2009-08-06 04:40:15 UTC (rev 286866) @@ -43,6 +43,7 @@ gdimageline gdimagepixelate gdimagerectangle + gdimagescatterex gdimagesetpixel gdimagestringft gdimagestringftex Modified: gd/trunk/libgd/tests/Makefile.am =================================================================== --- gd/trunk/libgd/tests/Makefile.am 2009-08-06 04:37:07 UTC (rev 286865) +++ gd/trunk/libgd/tests/Makefile.am 2009-08-06 04:40:15 UTC (rev 286866) @@ -22,6 +22,7 @@ gdimageline \ gdimagepixelate \ gdimagerectangle \ + gdimagescatterex \ gdimagesetpixel \ gdimagestringft \ gdimagestringftex \ Added: gd/trunk/libgd/tests/gdimagescatterex/CMakeLists.txt =================================================================== --- gd/trunk/libgd/tests/gdimagescatterex/CMakeLists.txt (rev 0) +++ gd/trunk/libgd/tests/gdimagescatterex/CMakeLists.txt 2009-08-06 04:40:15 UTC (rev 286866) @@ -0,0 +1,11 @@ +SET(TESTS_FILES + bug00208_1 + bug00208_2 +) + +FOREACH(test_name ${TESTS_FILES}) + add_executable(${test_name} "${test_name}.c") + target_link_libraries (${test_name} ${GDTESTS_TARGET_LINK}) + get_target_property(test_path ${test_name} LOCATION) + ADD_TEST(${test_name} ${test_path}) +ENDFOREACH(test_name) Added: gd/trunk/libgd/tests/gdimagescatterex/Makefile.am =================================================================== --- gd/trunk/libgd/tests/gdimagescatterex/Makefile.am (rev 0) +++ gd/trunk/libgd/tests/gdimagescatterex/Makefile.am 2009-08-06 04:40:15 UTC (rev 286866) @@ -0,0 +1,3 @@ +## Process this file with automake to produce Makefile.in -*-Makefile-*- + +EXTRA_DIST = CMakeLists.txt bug00208_1.c bug00208_2.c bug00208.png bug00208_1.png bug00208_2.png Added: gd/trunk/libgd/tests/gdimagescatterex/bug00208.png =================================================================== (Binary files differ) Property changes on: gd/trunk/libgd/tests/gdimagescatterex/bug00208.png ___________________________________________________________________ Added: svn:mime-type + image/png Added: gd/trunk/libgd/tests/gdimagescatterex/bug00208_1.c =================================================================== --- gd/trunk/libgd/tests/gdimagescatterex/bug00208_1.c (rev 0) +++ gd/trunk/libgd/tests/gdimagescatterex/bug00208_1.c 2009-08-06 04:40:15 UTC (rev 286866) @@ -0,0 +1,37 @@ +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + gdScatter s; + + fp = fopen(GDTEST_TOP_DIR "/gdimagescatterex/bug00208.png", "rb"); + if (!fp) { + fprintf(stderr, "could not open file"); + return 1; + } + im = gdImageCreateFromPng(fp); + fclose(fp); + if (!im) { + fprintf(stderr, "could not create image"); + return 1; + } + + s.sub = 1; + s.plus = 3; + s.seed = 0; + s.num_colors = 0; + if (!gdImageScatterEx(im, &s)) { + gdImageDestroy(im); + fprintf(stderr, "could not scatter"); + return 1; + } + + if (!gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagescatterex/bug00208_1.png", im)) { + gdImageDestroy(im); + return 1; + } + return 0; +} Added: gd/trunk/libgd/tests/gdimagescatterex/bug00208_1.png =================================================================== (Binary files differ) Property changes on: gd/trunk/libgd/tests/gdimagescatterex/bug00208_1.png ___________________________________________________________________ Added: svn:mime-type + image/png Added: gd/trunk/libgd/tests/gdimagescatterex/bug00208_2.c =================================================================== --- gd/trunk/libgd/tests/gdimagescatterex/bug00208_2.c (rev 0) +++ gd/trunk/libgd/tests/gdimagescatterex/bug00208_2.c 2009-08-06 04:40:15 UTC (rev 286866) @@ -0,0 +1,39 @@ +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + gdScatter s; + int colors[] = {0xFF0000, 0x00FF00}; + + fp = fopen(GDTEST_TOP_DIR "/gdimagescatterex/bug00208.png", "rb"); + if (!fp) { + fprintf(stderr, "could not open file"); + return 1; + } + im = gdImageCreateFromPng(fp); + fclose(fp); + if (!im) { + fprintf(stderr, "could not create image"); + return 1; + } + + s.sub = 1; + s.plus = 3; + s.seed = 0; + s.num_colors = 2; + s.colors = colors; + if (!gdImageScatterEx(im, &s)) { + gdImageDestroy(im); + fprintf(stderr, "could not scatter"); + return 1; + } + + if (!gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagescatterex/bug00208_2.png", im)) { + gdImageDestroy(im); + return 1; + } + return 0; +} Added: gd/trunk/libgd/tests/gdimagescatterex/bug00208_2.png =================================================================== (Binary files differ) Property changes on: gd/trunk/libgd/tests/gdimagescatterex/bug00208_2.png ___________________________________________________________________ Added: svn:mime-type + image/png