]> git.imager.perl.org - imager.git/commitdiff
changed Imager::read() to always return an arrayref of Imager::Color
authorTony Cook <tony@develop=help.com>
Mon, 7 May 2001 12:17:20 +0000 (12:17 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 7 May 2001 12:17:20 +0000 (12:17 +0000)
objects rather than an arrayref of arrayrefs

Changes
Imager.pm
t/t70newgif.t

diff --git a/Changes b/Changes
index a6e5f8b99b4454ea0c19698d817a9d6a6b1dbe3c..7c3191f7338c1b06de4de020bea0981cd287bc76 100644 (file)
--- a/Changes
+++ b/Changes
@@ -393,6 +393,10 @@ Revision history for Perl extension Imager.
        palettes for 2 colour images :)
        - initial implementation of a row-based interface to low-level
        images (for performance)
+       - changed Imager::read() for GIF so that the arrayref pointed to 
+       by the ref supplied in colors contains Imager::Color objects 
+       instead of more arrayrefs, keep this interface stable until we 
+       can make an informed choice about i_readgif()
 
 ~~~~~~~~~~~~~^ ^ ^~~~~~~~~~~~~~
 
index f0363f117557ab42d206b20ef7e06e385b442d36..38f7d152645b9c86c731afaa9ae02adc5c420f96 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -493,6 +493,7 @@ sub read {
   if ($input{fd}) { $fd=$input{fd} };
 
   if ( $input{type} eq 'gif' ) {
+    my $colors;
     if ($input{colors} && !ref($input{colors})) {
       # must be a reference to a scalar that accepts the colour map
       $self->{ERRSTR} = "option 'colors' must be a scalar reference";
@@ -500,7 +501,7 @@ sub read {
     }
     if (exists $input{data}) {
       if ($input{colors}) {
-       ($self->{IMG}, ${$input{colors}}) = i_readgif_scalar($input{data});
+       ($self->{IMG}, $colors) = i_readgif_scalar($input{data});
       }
       else {
        $self->{IMG}=i_readgif_scalar($input{data});
@@ -508,12 +509,16 @@ sub read {
     }
     else { 
       if ($input{colors}) {
-       ($self->{IMG}, ${$input{colors}}) = i_readgif( $fd );
+       ($self->{IMG}, $colors) = i_readgif( $fd );
       }
       else {
        $self->{IMG} = i_readgif( $fd )
       }
     }
+    if ($colors) {
+      # we may or may not change i_readgif to return blessed objects...
+      ${$input{colors}} = [ map { NC(@$_) } @$colors ];
+    }
     if ( !defined($self->{IMG}) ) {
       $self->{ERRSTR}= 'reading GIF:'._error_as_msg(); return undef;
     }
@@ -1501,9 +1506,7 @@ such as a database over a DBI connection.
 If you are reading from a gif image file, you can supply a 'colors'
 parameter which must be a reference to a scalar.  The referenced
 scalar will receive an array reference which contains the colors, each
-represented another array reference which has the 3 colour components
-in it, in RGB order.  Note: this may change to be an array reference
-of Imager::Color objects.
+represented as an Imager::Color object.
 
 If you already have an open file handle, for example a socket or a
 pipe, you can specify the 'fd' parameter instead of supplying a
index 5fe1d0c250b2abcc541e60eb17d02a341dac94ba..81e11ceeaf06131eb590c03d6e94e381dffceda9 100644 (file)
@@ -10,7 +10,7 @@
 BEGIN { $| = 1; print "1..8\n"; }
 END {print "not ok 1\n" unless $loaded;}
 
-use Imager;
+use Imager qw(:all :handy);
 $loaded=1;
 
 print "ok 1\n";
@@ -40,13 +40,13 @@ if ($im2->read(file=>'testimg/bandw.gif', colors=>\$map)) {
       print "ok 6\n";
       my @sorted = sort { comp_entry($a,$b) } @$map;
       # first entry must be #000000 and second #FFFFFF
-      if (comp_entry($sorted[0], [0,0,0]) == 0) {
+      if (comp_entry($sorted[0], NC(0,0,0)) == 0) {
        print "ok 7\n";
       }
       else {
        print "not ok 7 # entry should be black\n";
       }
-      if (comp_entry($sorted[1], [255,255,255]) == 0) {
+      if (comp_entry($sorted[1], NC(255,255,255)) == 0) {
        print "ok 8\n";
       }
       else {
@@ -73,7 +73,9 @@ else {
 
 sub comp_entry {
   my ($l, $r) = @_;
-  return $l->[0] <=> $r->[0]
-    || $l->[1] <=> $r->[1]
-      || $l->[2] <=> $r->[2];
+  my @l = $l->rgba;
+  my @r = $r->rgba;
+  return $l[0] <=> $r[0]
+    || $l[1] <=> $r[1]
+      || $l[2] <=> $r[2];
 }