]> git.imager.perl.org - imager.git/commitdiff
fix Imager::Color->new(channels => []) with a short array
authorTony Cook <tony@develop-help.com>
Sat, 13 Feb 2016 02:07:42 +0000 (13:07 +1100)
committerTony Cook <tony@develop-help.com>
Tue, 16 Feb 2016 09:33:13 +0000 (20:33 +1100)
Previously this would fail.

lib/Imager/Color.pm
t/100-base/020-color.t

index 478f437ec46e2d8f8dab947df2ab72c58bf21eab..f2bd30d61c21b6d45cc68a4815375f998b5cbf2b 100644 (file)
@@ -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;
index edcb923cc48400131570a8d7b5a9154b1e843e01..c506a8b6a6c5f0f9606eda985c725cb1f8699e21 100644 (file)
@@ -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'));