]> git.imager.perl.org - imager.git/commitdiff
[rt #75258] fix the utterly broken i_gpixf() for paletted images
authorTony Cook <tony@develop-help.com>
Mon, 5 Mar 2012 09:54:37 +0000 (20:54 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 5 Mar 2012 09:54:37 +0000 (20:54 +1100)
This is implemented as a wrapper around the underlying i_gpix()
implementation and was handling the return value from i_gpix()
incorrectly.

Add tests and fix it.

Changes
image.c
t/t023palette.t

diff --git a/Changes b/Changes
index fd807e4725532f819198af1203d0f740de4ea745..74483bae7d73749d171a2b4d9e0f11e45bab909b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Imager release history.  Older releases can be found in Changes.old
 
+ - getpixel(..., type => "float") and the API i_gpixf() have been
+   broken on paletted images since they were implemented.
+   https://rt.cpan.org/Ticket/Display.html?id=75258
+
 Imager 0.88 - 22 Feb 2012
 ===========
 
diff --git a/image.c b/image.c
index b84d05a031c5d6b620ccfcdc5ba8188981e2fa9a..4369bd52da6790a486bd2efff806410a53ef376e 100644 (file)
--- a/image.c
+++ b/image.c
@@ -1236,7 +1236,7 @@ int i_gpixf_fp(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix) {
   i_color temp;
   int ch;
 
-  if (i_gpix(im, x, y, &temp)) {
+  if (i_gpix(im, x, y, &temp) == 0) {
     for (ch = 0; ch < im->channels; ++ch)
       pix->channel[ch] = Sample8ToF(temp.channel[ch]);
     return 0;
index 04ce77bd3943ed13a1e3d234f41a89c2223cbc18..a3c2ecfb1fff10d19fe1bb3333b764fef889cc94 100644 (file)
@@ -1,10 +1,10 @@
 #!perl -w
 # some of this is tested in t01introvert.t too
 use strict;
-use Test::More tests => 206;
+use Test::More tests => 211;
 BEGIN { use_ok("Imager", ':handy'); }
 
-use Imager::Test qw(image_bounds_checks test_image is_color3 isnt_image is_color4);
+use Imager::Test qw(image_bounds_checks test_image is_color3 isnt_image is_color4 is_fcolor3);
 
 Imager->open_log(log => "testout/t023palette.log");
 
@@ -573,6 +573,23 @@ my $psamp_outside_error = "Image position outside of image";
   print "# end psampf tests\n";
 }
 
+{ # 75258 - gpixf() broken for paletted images
+  my $im = Imager->new(xsize => 10, ysize => 10, type => "paletted");
+  ok($im, "make a test image");
+  my @colors = ( $black, $red, $green, $blue );
+  is($im->addcolors(colors => \@colors), "0 but true",
+     "add some colors");
+  $im->setpixel(x => 0, y => 0, color => $red);
+  $im->setpixel(x => 1, y => 0, color => $green);
+  $im->setpixel(x => 2, y => 0, color => $blue);
+  is_fcolor3($im->getpixel(x => 0, y => 0, type => "float"),
+            1.0, 0, 0, "get a pixel in float form, make sure it's red");
+  is_fcolor3($im->getpixel(x => 1, y => 0, type => "float"),
+            0, 1.0, 0, "get a pixel in float form, make sure it's green");
+  is_fcolor3($im->getpixel(x => 2, y => 0, type => "float"),
+            0, 0, 1.0, "get a pixel in float form, make sure it's blue");
+}
+
 Imager->close_log;
 
 unless ($ENV{IMAGER_KEEP_FILES}) {