From: Tony Cook Date: Wed, 11 May 2005 14:37:29 +0000 (+0000) Subject: - the setcolors() had a fencepost error making it impossible to X-Git-Tag: Imager-0.48^2~154 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/8efd1577a186531a502ccf8203175a4fdca2f166?hp=65eb45d1b045655ebcb1bc23d16c4757cdb0f9b0 - the setcolors() had a fencepost error making it impossible to use it to set the last color in the palette. http://rt.cpan.org/NoAuth/Bug.html?id=12676 --- diff --git a/Changes b/Changes index f7675260..08524412 100644 --- a/Changes +++ b/Changes @@ -1091,6 +1091,9 @@ Revision history for Perl extension Imager. parameter wasn't passed to the read() method would produce diagnostics on stdout, precluding use in web applications. Silenced it. +- the setcolors() had a fencepost error making it impossible to + use it to set the last color in the palette. + http://rt.cpan.org/NoAuth/Bug.html?id=12676 ================================================================= diff --git a/palimg.c b/palimg.c index b655963e..1667238e 100644 --- a/palimg.c +++ b/palimg.c @@ -537,7 +537,7 @@ static int i_maxcolors_p(i_img *im) { =cut */ static int i_setcolors_p(i_img *im, int index, i_color *colors, int count) { - if (index >= 0 && count >= 1 && index + count < PALEXT(im)->count) { + if (index >= 0 && count >= 1 && index + count <= PALEXT(im)->count) { while (count) { PALEXT(im)->pal[index++] = *colors++; --count; diff --git a/t/t023palette.t b/t/t023palette.t index 65e38c9a..31578217 100644 --- a/t/t023palette.t +++ b/t/t023palette.t @@ -2,7 +2,7 @@ # some of this is tested in t01introvert.t too use strict; use lib 't'; -use Test::More tests => 59; +use Test::More tests => 62; BEGIN { use_ok("Imager"); } my $img = Imager->new(xsize=>50, ysize=>50, type=>'paletted'); @@ -190,6 +190,17 @@ cmp_ok(Imager->errstr, '=~', qr/Channels must be positive and <= 4/, cmp_ok($warning, '=~', 't023palette\\.t', "correct file"); } +{ # http://rt.cpan.org/NoAuth/Bug.html?id=12676 + # setcolors() has a fencepost error + my $img = Imager->new(xsize=>10, ysize=>10, type=>'paletted'); + + is($img->addcolors(colors=>[ $black, $red ]), "0 but true", + "add test colors"); + ok($img->setcolors(start=>1, colors=>[ $green ]), "set the last color"); + ok(!$img->setcolors(start=>2, colors=>[ $black ]), + "set after the last color"); +} + sub coloreq { my ($left, $right, $comment) = @_;