From c13515dd1f46494af5e16a5a8448489ad11ac322 Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Thu, 22 Dec 2005 23:22:26 +0000 Subject: [PATCH] - add tests for: - imagecolorclosest - imagecolorresolve - imagecopy - imageline -imagesetstyle and dashed line - remove HAVE_GDIMAGECOLORRESOLVE, always present --- ext/gd/config.m4 | 1 - ext/gd/gd.c | 60 ----------------- ext/gd/tests/colorclosest.phpt | 71 ++++++++++++++++++++ ext/gd/tests/colorresolve.phpt | 61 +++++++++++++++++ ext/gd/tests/copy.phpt | 109 +++++++++++++++++++++++++++++++ ext/gd/tests/dashedlines.phpt | 79 ++++++++++++++++++++++ ext/gd/tests/lines.phpt | 116 +++++++++++++++++++++++++++++++++ 7 files changed, 436 insertions(+), 61 deletions(-) create mode 100644 ext/gd/tests/colorclosest.phpt create mode 100644 ext/gd/tests/colorresolve.phpt create mode 100644 ext/gd/tests/copy.phpt create mode 100644 ext/gd/tests/dashedlines.phpt create mode 100644 ext/gd/tests/lines.phpt diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index f290893f0b..aaf48f013a 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -333,7 +333,6 @@ dnl FIXME: Cleanup the sources so that these are not needed! AC_DEFINE(HAVE_GD_IMAGEELLIPSE, 1, [ ]) AC_DEFINE(HAVE_GD_IMAGESETBRUSH, 1, [ ]) AC_DEFINE(HAVE_COLORCLOSESTHWB, 1, [ ]) - AC_DEFINE(HAVE_GDIMAGECOLORRESOLVE, 1, [ ]) AC_DEFINE(HAVE_GD_DYNAMIC_CTX_EX, 1, [ ]) dnl T1LIB support is gdlib independent diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 7440c53bbd..eb93d2a8cc 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -98,10 +98,6 @@ typedef FILE gdIOCtx; #define CTX_PUTC(c, fp) fputc(c, fp) #endif -#ifndef HAVE_GDIMAGECOLORRESOLVE -extern int gdImageColorResolve(gdImagePtr, int, int, int); -#endif - #if HAVE_COLORCLOSESTHWB int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b); #endif @@ -584,62 +580,6 @@ PHP_GD_API int phpi_get_le_gd(void) return le_gd; } -#ifndef HAVE_GDIMAGECOLORRESOLVE - -/* {{{ gdImageColorResolve - */ -/********************************************************************/ -/* gdImageColorResolve is a replacement for the old fragment: */ -/* */ -/* if ((color=gdImageColorExact(im,R,G,B)) < 0) */ -/* if ((color=gdImageColorAllocate(im,R,G,B)) < 0) */ -/* color=gdImageColorClosest(im,R,G,B); */ -/* */ -/* in a single function */ - -int gdImageColorResolve(gdImagePtr im, int r, int g, int b) -{ - int c; - int ct = -1; - int op = -1; - long rd, gd, bd, dist; - long mindist = 3*255*255; /* init to max poss dist */ - - for (c = 0; c < im->colorsTotal; c++) { - if (im->open[c]) { - op = c; /* Save open slot */ - continue; /* Color not in use */ - } - rd = (long) (im->red [c] - r); - gd = (long) (im->green[c] - g); - bd = (long) (im->blue [c] - b); - dist = rd * rd + gd * gd + bd * bd; - if (dist < mindist) { - if (dist == 0) { - return c; /* Return exact match color */ - } - mindist = dist; - ct = c; - } - } - /* no exact match. We now know closest, but first try to allocate exact */ - if (op == -1) { - op = im->colorsTotal; - if (op == gdMaxColors) { /* No room for more colors */ - return ct; /* Return closest available color */ - } - im->colorsTotal++; - } - im->red [op] = r; - im->green[op] = g; - im->blue [op] = b; - im->open [op] = 0; - return op; /* Return newly allocated color */ -} -/* }}} */ - -#endif - #define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24)) /* {{{ proto int imageloadfont(string filename) diff --git a/ext/gd/tests/colorclosest.phpt b/ext/gd/tests/colorclosest.phpt new file mode 100644 index 0000000000..f44912d7eb --- /dev/null +++ b/ext/gd/tests/colorclosest.phpt @@ -0,0 +1,71 @@ +--TEST-- +imagecopy +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +FF00FF + +Warning: imagecolorsforindex(): Color index -1 out of range in %s on line %d +Array +( + [red] => 255 + [green] => 0 + [blue] => 255 + [alpha] => 0 +) +Array +( + [red] => 254 + [green] => 0 + [blue] => 0 + [alpha] => 0 +) +Array +( + [red] => 246 + [green] => 10 + [blue] => 10 + [alpha] => 0 +) diff --git a/ext/gd/tests/colorresolve.phpt b/ext/gd/tests/colorresolve.phpt new file mode 100644 index 0000000000..41e1c23758 --- /dev/null +++ b/ext/gd/tests/colorresolve.phpt @@ -0,0 +1,61 @@ +--TEST-- +imagecopy +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +FF00FF +Array +( + [red] => 255 + [green] => 0 + [blue] => 255 + [alpha] => 0 +) +Array +( + [red] => 255 + [green] => 0 + [blue] => 0 + [alpha] => 0 +) +Array +( + [red] => 246 + [green] => 10 + [blue] => 10 + [alpha] => 0 +) diff --git a/ext/gd/tests/copy.phpt b/ext/gd/tests/copy.phpt new file mode 100644 index 0000000000..5aafc31e76 --- /dev/null +++ b/ext/gd/tests/copy.phpt @@ -0,0 +1,109 @@ +--TEST-- +imagecopy +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +TC/TC: ok +TC/P: ok +P/P: ok +P/TC: ok diff --git a/ext/gd/tests/dashedlines.phpt b/ext/gd/tests/dashedlines.phpt new file mode 100644 index 0000000000..30db8f1c71 --- /dev/null +++ b/ext/gd/tests/dashedlines.phpt @@ -0,0 +1,79 @@ +--TEST-- +imageline, dashed +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Horizontal: ok +Vertical: ok +Diagonal: ok diff --git a/ext/gd/tests/lines.phpt b/ext/gd/tests/lines.phpt new file mode 100644 index 0000000000..8f64e12aee --- /dev/null +++ b/ext/gd/tests/lines.phpt @@ -0,0 +1,116 @@ +--TEST-- +imageline no AA +--SKIPIF-- + +--FILE-- + +--EXPECTF-- + +Warning: Wrong parameter count for imageline() in %s on line %d +Horizontal: ok +Vertical: ok +Diagonal: ok +Outside 1: ok +Outside 2: ok -- 2.40.0