Permalink
Browse files

commiting for test elsewhere

  • Loading branch information...
1 parent a642174 commit e7bc49ec936dea1c1729ca90ee9f701d5db227ae Tony Cook committed Mar 5, 2002
Showing with 175 additions and 84 deletions.
  1. +4 −0 Imager/Changes
  2. +49 −6 Imager/Imager.pm
  3. +2 −1 Imager/io.c
  4. +84 −71 Imager/lib/Imager/Files.pod
  5. +21 −2 Imager/t/t105gif.t
  6. +1 −1 Imager/t/t106tiff.t
  7. +14 −3 Imager/tags.c
View
@@ -598,6 +598,10 @@ Revision history for Perl extension Imager.
- Added lib/Imager/Filters.pod, draft of Filters pod.
- Added lib/Imager/Engines.pod, draft of Engines pod.
- added getpixel() and setpixel() methods
+ - replaced old gif options with tags
+ - we now log which memory block is being freed before giving
+ an error on it being re-freed
+ - fixed stupid bug in deleting tags
=================================================================
View
@@ -1,7 +1,7 @@
package Imager;
use strict;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %formats $DEBUG %filters %DSOs $ERRSTR $fontstate %OPCODES $I2P $FORMATGUESS);
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %formats $DEBUG %filters %DSOs $ERRSTR $fontstate %OPCODES $I2P $FORMATGUESS $warn_obsolete);
use IO::File;
use Imager::Color;
@@ -363,6 +363,8 @@ BEGIN {
};
$FORMATGUESS=\&def_guess_type;
+
+ $warn_obsolete = 1;
}
#
@@ -385,6 +387,9 @@ sub init {
if ($parms{'log'}) {
init_log($parms{'log'},$parms{'loglevel'});
}
+ if (exists $parms{'warn_obsolete'}) {
+ $warn_obsolete = $parms{'warn_obsolete'};
+ }
# if ($parms{T1LIB_CONFIG}) { $ENV{T1LIB_CONFIG}=$parms{T1LIB_CONFIG}; }
# if ( $ENV{T1LIB_CONFIG} and ( $fontstate eq 'missing conf' )) {
@@ -1178,16 +1183,54 @@ sub read {
return $self;
}
+sub _fix_gif_positions {
+ my ($opts, $opt, $msg, @imgs) = @_;
+
+ my $positions = $opts->{'gif_positions'};
+ my $index = 0;
+ for my $pos (@$positions) {
+ my ($x, $y) = @$pos;
+ my $img = $imgs[$index++];
+ $img->settag(gif_left=>$x);
+ $img->settag(gif_top=>$y) if defined $y;
+ }
+ $$msg .= "replaced with the gif_left and gif_top tags";
+}
+
+my %obsolete_opts =
+ (
+ gif_each_palette=>'gif_local_map',
+ interlace => 'gif_interlace',
+ gif_delays => 'gif_delay',
+ gif_positions => \&_fix_gif_positions,
+ gif_loop_count => 'gif_loop',
+ );
+
sub _set_opts {
my ($self, $opts, $prefix, @imgs) = @_;
- for my $opt (grep /^\Q$prefix/, keys %$opts) {
+ for my $opt (keys %$opts) {
+ my $tagname = $opt;
+ if ($obsolete_opts{$opt}) {
+ my $new = $obsolete_opts{$opt};
+ my $msg = "Obsolete option $opt ";
+ if (ref $new) {
+ $new->($opts, $opt, \$msg, @imgs);
+ }
+ else {
+ $msg .= "replaced with the $new tag ";
+ $tagname = $new;
+ }
+ $msg .= "line ".(caller(2))[2]." of file ".(caller(2))[1];
+ warn $msg if $warn_obsolete && $^W;
+ }
+ next unless $tagname =~ /^\Q$prefix/;
my $value = $opts->{$opt};
if (ref $value) {
if (UNIVERSAL::isa($value, "Imager::Color")) {
my $tag = sprintf("color(%d,%d,%d,%d)", $value->rgba);
for my $img (@imgs) {
- $img->settag(name=>$opt, value=>$tag);
+ $img->settag(name=>$tagname, value=>$tag);
}
}
elsif (ref($value) eq 'ARRAY') {
@@ -1197,7 +1240,7 @@ sub _set_opts {
if (UNIVERSAL::isa($val, "Imager::Color")) {
my $tag = sprintf("color(%d,%d,%d,%d)", $value->rgba);
$i < @imgs and
- $imgs[$i]->settag(name=>$opt, value=>$tag);
+ $imgs[$i]->settag(name=>$tagname, value=>$tag);
}
else {
$self->_set_error("Unknown reference type " . ref($value) .
@@ -1207,7 +1250,7 @@ sub _set_opts {
}
else {
$i < @imgs
- and $imgs[$i]->settag(name=>$opt, value=>$val);
+ and $imgs[$i]->settag(name=>$tagname, value=>$val);
}
}
}
@@ -1220,7 +1263,7 @@ sub _set_opts {
else {
# set it as a tag for every image
for my $img (@imgs) {
- $img->settag(name=>$opt, value=>$value);
+ $img->settag(name=>$tagname, value=>$value);
}
}
}
View
@@ -203,14 +203,15 @@ myfree_file_line(void *p, char *file, int line) {
malloc_pointers[i].ptr = NULL;
match++;
}
+
+ mm_log((1, "myfree_file_line: freeing address %p (real %p)\n", pp, pp-UNDRRNVAL));
if (match != 1) {
mm_log((1, "myfree_file_line: INCONSISTENT REFCOUNT %d at %s (%i)\n", match, file, line));
fprintf(stderr, "myfree_file_line: INCONSISTENT REFCOUNT %d at %s (%i)\n", match, file, line);
exit(255);
}
- mm_log((1, "myfree_file_line: freeing address %p (real %p)\n", pp, pp-UNDRRNVAL));
free(pp-UNDRRNVAL);
}
View
@@ -149,6 +149,23 @@ Return either a valid Imager file type, or undef.
The different image formats can write different image type, and some have
different options to control how the images are written.
+When you call C<write()> or C<write_multi()> with an option that has
+the same name as a tag for the image format you're writing, then the
+value supplied to that option will be used to set the corresponding
+tag in the image. Depending on the image format, these values will be
+used when writing the image.
+
+This replaces the previous options that were used when writing GIF
+images. Currently if you use an obsolete option, it will be converted
+to the equivalent tag and Imager will produced a warning. You can
+suppress these warnings by calling the C<Imager::init()> function with
+the C<warn_obsolete> option set to false:
+
+ Imager::init(warn_obsolete=>0);
+
+At some point in the future these obsolete options will no longer be
+supported.
+
=head2 PNM (Portable aNy Map)
Imager can write PGM (Portable Gray Map) and PPM (Portable PixMaps)
@@ -182,75 +199,9 @@ PNM does not support the spatial resolution tags.
=head2 GIF (Graphics Interchange Format)
-You can supply many different options when writing to a GIF file, and
-you can write a multi-image GIF file, eg. for animation, with the
-C<write_multi()> method.
-
-These options can be specified when calling write_multi() or when
-writing a single image with the C<gifquant> option set to 'gen'
-
-Note that some viewers will ignore some of these options
-(C<gif_user_input> in particular).
-
-=over
-
-=item gif_each_palette
-
-Each image in the gif file has it's own palette if this is non-zero.
-All but the first image has a local colour table (the first uses the
-global colour table.
-
-=item interlace
-
-The images are written interlaced if this is non-zero.
-
-=item gif_delays
-
-A reference to an array containing the delays between images, in 1/100
-seconds.
-
-If you want the same delay for every frame you can simply set this to
-the delay in 1/100 seconds.
-
-=item gif_user_input
-
-A reference to an array contains user input flags. If the given flag
-is non-zero the image viewer should wait for input before displaying
-the next image.
-
-=item gif_disposal
-
-A reference to an array of image disposal methods. These define what
-should be done to the image before displaying the next one. These are
-integers, where 0 means unspecified, 1 means the image should be left
-in place, 2 means restore to background colour and 3 means restore to
-the previous value.
-
-=item gif_trans_color
-
-A reference to an Imager::Color object, which is the colour to use for
-the palette entry used to represent transparency in the palette. You
-need to set the transp option (see L<Quantization options>) for this
-value to be used.
-
-=item gif_positions
-
-A reference to an array of references to arrays which represent screen
-positions for each image.
-
-=item gif_loop_count
-
-If this is non-zero the Netscape loop extension block is generated,
-which makes the animation of the images repeat.
-
-This is currently unimplemented due to some limitations in giflib.
-
-=item gif_eliminate_unused
-
-If this is true, when you write a paletted image any unused colors
-will be eliminated from its palette. This is set by default.
-
-=back
+When writing one of more GIF images you can use the same
+L<Quantization Options|Imager::ImageTypes> as you can when converting
+an RGB image into a paletted image.
When reading a GIF all of the sub-images are combined using the screen
size and image positions into one big image, producing an RGB image.
@@ -266,8 +217,8 @@ use the C<getcolors()> method on each image.
GIF does not support the spatial resolution tags.
-GIF will set the following tags in each image when reading, but does
-not use them when saving to GIF:
+Imager will set the following tags in each image when reading, and can
+use most of them when writing to GIF:
=over
@@ -293,6 +244,10 @@ minimum. If any image being written would extend beyond this the
screen size is extended. ("Logical Screen Width", "Logical Screen
Height").
+When writing this is used as a minimum, if the combination of the
+image size and the image's C<gif_left> and C<gif_top> is beyond this
+size then the screen size will be expanded.
+
=item gif_local_map
Non-zero if this image had a local color map. If set for an image
@@ -314,6 +269,13 @@ image has a transparency then it is returned as a 4 channel image with
the alpha set to zero in this palette entry. This value is not used
when writing. ("Transparent Color Index")
+=item gif_trans_color
+
+A reference to an Imager::Color object, which is the colour to use for
+the palette entry used to represent transparency in the palette. You
+need to set the transp option (see L<Quantization options>) for this
+value to be used.
+
=item gif_delay
The delay until the next frame is displayed, in 1/100 of a second.
@@ -336,11 +298,59 @@ the number of loops from the Netscape Loop extension. This may be zero.
the first block of the first gif comment before each image.
+=item gif_eliminate_unused
+
+If this is true, when you write a paletted image any unused colors
+will be eliminated from its palette. This is set by default.
+
=back
Where applicable, the ("name") is the name of that field from the GIF89
standard.
+The following gif writing options are obsolete, you should set the
+corresponding tag in the image, either by using the tags functions, or
+by supplying the tag and value as options.
+
+=over
+
+=item gif_each_palette
+
+Each image in the gif file has it's own palette if this is non-zero.
+All but the first image has a local colour table (the first uses the
+global colour table.
+
+Use C<gif_local_map> in new code.
+
+=item interlace
+
+The images are written interlaced if this is non-zero.
+
+Use C<gif_interlace> in new code.
+
+=item gif_delays
+
+A reference to an array containing the delays between images, in 1/100
+seconds.
+
+Use C<gif_delay> in new code.
+
+=item gif_positions
+
+A reference to an array of references to arrays which represent screen
+positions for each image.
+
+New code should use the C<gif_left> and C<gif_top> tags.
+
+=item gif_loop_count
+
+If this is non-zero the Netscape loop extension block is generated,
+which makes the animation of the images repeat.
+
+This is currently unimplemented due to some limitations in giflib.
+
+=back
+
=head2 TIFF (Tagged Image File Format)
Imager can write images to either paletted or RGB TIFF images,
@@ -546,5 +556,8 @@ When saving Gif images the program does NOT try to shave of extra
colors if it is possible. If you specify 128 colors and there are
only 2 colors used - it will have a 128 colortable anyway.
+=head1 SEE ALSO
+
+Imager(3)
=cut
View
@@ -1,7 +1,7 @@
#!perl -w
use strict;
$|=1;
-print "1..40\n";
+print "1..45\n";
use Imager qw(:all);
sub ok ($$$);
@@ -25,7 +25,7 @@ i_box_filled($timg, 0, 0, 20, 20, $green);
i_box_filled($timg, 2, 2, 18, 18, $trans);
if (!i_has_format("gif")) {
- for (1..40) { print "ok $_ # skip no gif support\n"; }
+ for (1..45) { print "ok $_ # skip no gif support\n"; }
} else {
open(FH,">testout/t105.gif") || die "Cannot open testout/t105.gif\n";
binmode(FH);
@@ -449,6 +449,25 @@ EOS
"re-reading saved paletted images");
ok(39, i_img_diff($imgs[0], $imgs2[0]) == 0, "imgs[0] mismatch");
ok(40, i_img_diff($imgs[1], $imgs2[1]) == 0, "imgs[1] mismatch");
+
+ # test that the OO interface warns when we supply old options
+ {
+ my @warns;
+ local $SIG{__WARN__} = sub { push(@warns, "@_") };
+
+ my $ooim = Imager->new;
+ ok(41, $ooim->read(file=>"testout/t105.gif"), "read into object");
+ ok(42, $ooim->write(file=>"testout/t105_warn.gif", interlace=>1),
+ "save from object");
+ ok(43, grep(/Obsolete .* interlace .* gif_interlace/, @warns),
+ "check for warning");
+ init(warn_obsolete=>0);
+ @warns = ();
+ ok(44, $ooim->write(file=>"testout/t105_warn.gif", interlace=>1),
+ "save from object");
+ ok(45, !grep(/Obsolete .* interlace .* gif_interlace/, @warns),
+ "check for warning");
+ }
}
sub ok ($$$) {
Oops, something went wrong.

0 comments on commit e7bc49e

Please sign in to comment.