pajoye Thu Dec 22 23:22:26 2005 EDT
Added files:
/php-src/ext/gd/tests colorclosest.phpt colorresolve.phpt copy.phpt
dashedlines.phpt lines.phpt
Modified files:
/php-src/ext/gd config.m4 gd.c
Log:
- add tests for:
- imagecolorclosest
- imagecolorresolve
- imagecopy
- imageline
-imagesetstyle and dashed line
- remove HAVE_GDIMAGECOLORRESOLVE, always present
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/config.m4?r1=1.162&r2=1.163&diff_format=u
Index: php-src/ext/gd/config.m4
diff -u php-src/ext/gd/config.m4:1.162 php-src/ext/gd/config.m4:1.163
--- php-src/ext/gd/config.m4:1.162 Fri Dec 16 19:21:55 2005
+++ php-src/ext/gd/config.m4 Thu Dec 22 23:22:26 2005
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.162 2005/12/16 19:21:55 pajoye Exp $
+dnl $Id: config.m4,v 1.163 2005/12/22 23:22:26 pajoye Exp $
dnl
dnl
@@ -333,7 +333,6 @@
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
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/gd.c?r1=1.328&r2=1.329&diff_format=u
Index: php-src/ext/gd/gd.c
diff -u php-src/ext/gd/gd.c:1.328 php-src/ext/gd/gd.c:1.329
--- php-src/ext/gd/gd.c:1.328 Fri Dec 16 19:21:55 2005
+++ php-src/ext/gd/gd.c Thu Dec 22 23:22:26 2005
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: gd.c,v 1.328 2005/12/16 19:21:55 pajoye Exp $ */
+/* $Id: gd.c,v 1.329 2005/12/22 23:22:26 pajoye Exp $ */
/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
Cold Spring Harbor Labs. */
@@ -98,10 +98,6 @@
#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 @@
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)
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/tests/colorclosest.phpt?view=markup&rev=1.1
Index: php-src/ext/gd/tests/colorclosest.phpt
+++ php-src/ext/gd/tests/colorclosest.phpt
--TEST--
imagecopy
--SKIPIF--
<?php
if (!function_exists('imagecopy')) die("skip gd extension not
available\n");
?>
--FILE--
<?php
$im = imagecreatetruecolor(5,5);
$c = imagecolorclosest($im, 255,0,255);
printf("%X\n", $c);
imagedestroy($im);
$im = imagecreate(5,5);
$c = imagecolorclosest($im, 255,0,255);
print_r(imagecolorsforindex($im, $c));
imagedestroy($im);
$im = imagecreate(5,5);
imagecolorallocate($im, 255, 0, 255);
$c = imagecolorclosest($im, 255,0,255);
print_r(imagecolorsforindex($im, $c));
imagedestroy($im);
$im = imagecreate(5,5);
for ($i=0; $i<255; $i++) imagecolorresolve($im, $i,0,0);
$c = imagecolorclosest($im, 255,0,0);
print_r(imagecolorsforindex($im, $c));
$im = imagecreate(5,5);
for ($i=0; $i<256; $i++) {
if ($i == 246) {
imagecolorallocate($im, $i,10,10);
} else {
imagecolorallocate($im, $i,0,0);
}
}
$c = imagecolorclosest($im, 255,10,10);
print_r(imagecolorsforindex($im, $c));
?>
--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
)
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/tests/colorresolve.phpt?view=markup&rev=1.1
Index: php-src/ext/gd/tests/colorresolve.phpt
+++ php-src/ext/gd/tests/colorresolve.phpt
--TEST--
imagecopy
--SKIPIF--
<?php
if (!function_exists('imagecopy')) die("skip gd extension not
available\n");
?>
--FILE--
<?php
$im = imagecreatetruecolor(5,5);
$c = imagecolorresolve($im, 255,0,255);
printf("%X\n", $c);
imagedestroy($im);
$im = imagecreate(5,5);
$c = imagecolorresolve($im, 255,0,255);
print_r(imagecolorsforindex($im, $c));
imagedestroy($im);
$im = imagecreate(5,5);
for ($i=0; $i<255; $i++) imagecolorresolve($im, $i,0,0);
$c = imagecolorresolve($im, 255,0,0);
print_r(imagecolorsforindex($im, $c));
$im = imagecreate(5,5);
for ($i=0; $i<256; $i++) {
if ($i == 246) {
imagecolorresolve($im, $i,10,10);
} else {
imagecolorresolve($im, $i,0,0);
}
}
$c = imagecolorresolve($im, 255,10,10);
print_r(imagecolorsforindex($im, $c));
?>
--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
)
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/tests/copy.phpt?view=markup&rev=1.1
Index: php-src/ext/gd/tests/copy.phpt
+++ php-src/ext/gd/tests/copy.phpt
--TEST--
imagecopy
--SKIPIF--
<?php
if (!function_exists('imagecopy')) die("skip gd extension not
available\n");
?>
--FILE--
<?php
$src_tc = imagecreatetruecolor(5,5);
imagefill($src_tc, 0,0, 0xffffff);
imagesetpixel($src_tc, 3,3, 0xff0000);
imagesetpixel($src_tc, 0,0, 0x0000ff);
imagesetpixel($src_tc, 4,4, 0x00ff00);
$dst_tc = imagecreatetruecolor(5,5);
imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
$p1 = imagecolorat($dst_tc, 3,3) == 0xff0000;
$p2 = imagecolorat($dst_tc, 0,0) == 0x0000ff;
$p3 = imagecolorat($dst_tc, 4,4) == 0x00ff00;
if ($p1 && $p2 && $p3) {
echo "TC/TC: ok\n";
}
imagedestroy($src_tc); imagedestroy($dst_tc);
$src_tc = imagecreatetruecolor(5,5);
imagefill($src_tc, 0,0, 0xffffff);
imagesetpixel($src_tc, 3,3, 0xff0000);
imagesetpixel($src_tc, 0,0, 0x0000ff);
imagesetpixel($src_tc, 4,4, 0x00ff00);
$dst_tc = imagecreate(5,5);
imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
$c1 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 3,3));
$c2 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 0,0));
$c3 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 4,4));
$p1 = $c1['red'] == 0xff && $c1['blue']==0x00 && $c1['green']==0x00;
$p2 = $c2['red'] == 0x00 && $c2['blue']==0xff && $c2['green']==0x00;
$p3 = $c3['red'] == 0x00 && $c3['blue']==0x00 && $c3['green']==0xff;
if ($p1 && $p2 && $p3) {
echo "TC/P: ok\n";
}
imagedestroy($src_tc); imagedestroy($dst_tc);
$src_tc = imagecreate(5,5);
$c0 = imagecolorallocate($src_tc, 0xff, 0xff, 0xff);
$c1 = imagecolorallocate($src_tc, 0xff, 0x00, 0x00);
$c2 = imagecolorallocate($src_tc, 0x00, 0x00, 0xff);
$c3 = imagecolorallocate($src_tc, 0x00, 0xff, 0x00);
imagesetpixel($src_tc, 3,3, $c1);
imagesetpixel($src_tc, 0,0, $c2);
imagesetpixel($src_tc, 4,4, $c3);
$dst_tc = imagecreate(5,5);
imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
$c1 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 3,3));
$c2 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 0,0));
$c3 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 4,4));
$p1 = $c1['red'] == 0xff && $c1['blue']==0x00 && $c1['green']==0x00;
$p2 = $c2['red'] == 0x00 && $c2['blue']==0xff && $c2['green']==0x00;
$p3 = $c3['red'] == 0x00 && $c3['blue']==0x00 && $c3['green']==0xff;
if ($p1 && $p2 && $p3) {
echo "P/P: ok\n";
}
$src_tc = imagecreate(5,5);
$c0 = imagecolorallocate($src_tc, 0xff, 0xff, 0xff);
$c1 = imagecolorallocate($src_tc, 0xff, 0x00, 0x00);
$c2 = imagecolorallocate($src_tc, 0x00, 0x00, 0xff);
$c3 = imagecolorallocate($src_tc, 0x00, 0xff, 0x00);
imagesetpixel($src_tc, 3,3, $c1);
imagesetpixel($src_tc, 0,0, $c2);
imagesetpixel($src_tc, 4,4, $c3);
$dst_tc = imagecreatetruecolor(5,5);
imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
$p1 = imagecolorat($dst_tc, 3,3) == 0xff0000;
$p2 = imagecolorat($dst_tc, 0,0) == 0x0000ff;
$p3 = imagecolorat($dst_tc, 4,4) == 0x00ff00;
if ($p1 && $p2 && $p3) {
echo "P/TC: ok\n";
}
?>
--EXPECTF--
TC/TC: ok
TC/P: ok
P/P: ok
P/TC: ok
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/tests/dashedlines.phpt?view=markup&rev=1.1
Index: php-src/ext/gd/tests/dashedlines.phpt
+++ php-src/ext/gd/tests/dashedlines.phpt
--TEST--
imageline, dashed
--SKIPIF--
<?php
if (!function_exists('imagecreatefromstring')) die("skip gd extension
not available\n");
?>
--FILE--
<?php
$im = imagecreatetruecolor(6,6);
imagefill($im, 0,0, 0xffffff);
$r = 0xff0000;
$b = 0x0000ff;
$style = array($r, $b);
imagesetstyle($im, $style);
// Horizontal line
imageline($im, 0,5, 5,5, IMG_COLOR_STYLED);
$p1 = imagecolorat($im, 0,5) == $r;
$p2 = imagecolorat($im, 1,5) == $b;
$p3 = imagecolorat($im, 2,5) == $r;
$p4 = imagecolorat($im, 3,5) == $b;
$p5 = imagecolorat($im, 4,5) == $r;
$p5 = imagecolorat($im, 5,5) == $b;
if ($p1 && $p2 && $p3 && $p4 && $p5) {
echo "Horizontal: ok\n";
}
imagedestroy($im);
$im = imagecreatetruecolor(6,6);
imagefill($im, 0,0, 0xffffff);
$style = array($r, $b);
imagesetstyle($im, $style);
imageline($im, 2,0, 2,5, IMG_COLOR_STYLED);
$p1 = imagecolorat($im, 2,0) == $r;
$p2 = imagecolorat($im, 2,1) == $b;
$p3 = imagecolorat($im, 2,2) == $r;
$p4 = imagecolorat($im, 2,3) == $b;
$p5 = imagecolorat($im, 2,4) == $r;
$p6 = imagecolorat($im, 2,5) == $b;
imagepng($im, 'b.png');
if ($p1 && $p2 && $p3 && $p4 && $p5 && $p6) {
echo "Vertical: ok\n";
}
imagedestroy($im);
$im = imagecreatetruecolor(6,6);
imagefill($im, 0,0, 0xffffff);
$style = array($r, $b);
imagesetstyle($im, $style);
imageline($im, 0,0, 5,5, IMG_COLOR_STYLED);
$p1 = imagecolorat($im, 0,0) == $r;
$p2 = imagecolorat($im, 1,1) == $b;
$p3 = imagecolorat($im, 2,2) == $r;
$p4 = imagecolorat($im, 3,3) == $b;
$p5 = imagecolorat($im, 4,4) == $r;
$p6 = imagecolorat($im, 5,5) == $b;
if ($p1 && $p2 && $p3 && $p4 && $p5 && $p6) {
echo "Diagonal: ok\n";
}
imagedestroy($im);
?>
--EXPECTF--
Horizontal: ok
Vertical: ok
Diagonal: ok
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/tests/lines.phpt?view=markup&rev=1.1
Index: php-src/ext/gd/tests/lines.phpt
+++ php-src/ext/gd/tests/lines.phpt
--TEST--
imageline no AA
--SKIPIF--
<?php
if (!function_exists('imageline')) die("skip gd extension not
available\n");
?>
--FILE--
<?php
$im = imagecreatetruecolor(6,6);
imagefill($im, 0,0, 0xffffff);
// Wrong argument count
imageline($im, 0,0, 5,5);
// Horizontal line
imageline($im, 0,5, 5,5, 0x00ff00);
$p1 = imagecolorat($im, 0,5)==0x00ff00;
$p2 = imagecolorat($im, 5,5)==0x00ff00;
$p3 = true;
for ($x=1; $x<5; $x++) {
$p3 = $p3 && (imagecolorat($im, $x,5)==0x00ff00);
}
if ($p1 && $p2 && $p3) {
echo "Horizontal: ok\n";
}
$im = imagecreatetruecolor(6,6);
imagefill($im, 0,0, 0xffffff);
imageline($im, 0,0, 0,5, 0x00ff00);
$p1 = imagecolorat($im, 0,0)==0x00ff00;
$p2 = imagecolorat($im, 0,5)==0x00ff00;
$p3 = true;
for ($y=1; $y<5; $y++) {
$p3 = $p3 && (imagecolorat($im, 0,$y)==0x00ff00);
}
if ($p1 && $p2 && $p3) {
echo "Vertical: ok\n";
}
$im = imagecreatetruecolor(6,6);
imagefill($im, 0,0, 0xffffff);
imageline($im, 0,0, 5,5, 0x00ff00);
// Diagonal
$p1 = imagecolorat($im, 0,0)==0x00ff00;
$p2 = imagecolorat($im, 5,5)==0x00ff00;
$x=1;
$p3 = true;
for ($y=1; $y<5; $y++) {
$p3 = $p3 && (imagecolorat($im, $x,$y)==0x00ff00);
$x++;
}
if ($p1 && $p2 && $p3) {
echo "Diagonal: ok\n";
}
imagepng($im, 'a.png');
// Outside
$im = imagecreatetruecolor(6,6);
imagefill($im, 0,0, 0xffffff);
imageline($im, 12, 12, 23,23, 0x00ff00);
$p3 = true;
for ($x=0; $x<6; $x++) {
for ($y=0; $y<6; $y++) {
$p3 = $p3 && (imagecolorat($im, $x,$y)!=0x00ff00);
}
}
if ($p3) {
echo "Outside 1: ok\n";
}
$im = imagecreatetruecolor(6,6);
imagefill($im, 0,0, 0xffffff);
imageline($im, -12, -12, -23,-23, 0x00ff00);
$p3 = true;
for ($x=0; $x<6; $x++) {
for ($y=0; $y<6; $y++) {
$p3 = $p3 && (imagecolorat($im, $x,$y)!=0x00ff00);
}
}
if ($p3) {
echo "Outside 2: ok\n";
}
$im = imagecreatetruecolor(6,6);
imagefill($im, 0,0, 0xffffff);
imageline($im, -1, -1, 4,4, 0x00ff00);
$p3 = true;
for ($x=0; $x<5; $x++) {
for ($y=0; $y<5; $y++) {
$p3 = $p3 && (imagecolorat($im, $x,$y)==0x00ff00);
}
}
if ($p3) {
echo "Outside 2: ok\n";
}
?>
--EXPECTF--
Warning: Wrong parameter count for imageline() in %s on line %d
Horizontal: ok
Vertical: ok
Diagonal: ok
Outside 1: ok
Outside 2: ok
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php