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()
~~~~~~~~~~~~~^ ^ ^~~~~~~~~~~~~~
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";
}
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});
}
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;
}
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
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";
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 {
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];
}