From: Tony Cook Date: Sat, 13 Feb 2016 02:07:42 +0000 (+1100) Subject: fix Imager::Color->new(channels => []) with a short array X-Git-Tag: v1.004_001~26 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/d1baf8e44f4d43902019006495c746bc1f643bd0 fix Imager::Color->new(channels => []) with a short array Previously this would fail. --- diff --git a/lib/Imager/Color.pm b/lib/Imager/Color.pm index 478f437e..f2bd30d6 100644 --- a/lib/Imager/Color.pm +++ b/lib/Imager/Color.pm @@ -4,7 +4,7 @@ use Imager; use strict; use vars qw($VERSION); -$VERSION = "1.011"; +$VERSION = "1.012"; # It's just a front end to the XS creation functions. @@ -335,7 +335,8 @@ sub _pspec { @result = _hsv_to_rgb(@{$args{hsv}}); } elsif ($args{channels}) { - return @{$args{channels}}; + my @ch = @{$args{channels}}; + return ( @ch, (0) x (4 - @ch) ); } elsif (exists $args{channel0} || $args{c0}) { my $i = 0; diff --git a/t/100-base/020-color.t b/t/100-base/020-color.t index edcb923c..c506a8b6 100644 --- a/t/100-base/020-color.t +++ b/t/100-base/020-color.t @@ -7,7 +7,7 @@ # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) -use Test::More tests => 70; +use Test::More tests => 73; use Imager; use Imager::Test qw(is_fcolor4); @@ -62,8 +62,16 @@ color_ok('channel0-3', 129, 130, 131, 134, channel3=>134)); color_ok('c0-3', 129, 130, 131, 134, Imager::Color->new(c0=>129, c1=>130, c2=>131, c3=>134)); -color_ok('channels arrayref', 200, 201, 203, 204, + +color_ok('channels arrayref (1)', 200, 0, 0, 0, + Imager::Color->new(channels=>[ 200, ])); +color_ok('channels arrayref (2)', 200, 201, 0, 0, + Imager::Color->new(channels=>[ 200, 201 ])); +color_ok('channels arrayref (3)', 200, 201, 203, 0, + Imager::Color->new(channels=>[ 200, 201, 203 ])); +color_ok('channels arrayref (4)', 200, 201, 203, 204, Imager::Color->new(channels=>[ 200, 201, 203, 204 ])); + color_ok('name', 255, 250, 250, 255, Imager::Color->new(name=>'snow', palette=>'testimg/test_gimp_pal'));