use vars qw($VERSION @ISA);
BEGIN {
- $VERSION = "0.92";
+ $VERSION = "0.93";
require XSLoader;
XSLoader::load('Imager::File::PNG', $VERSION);
#include "png.h"
#include <stdlib.h>
#include <string.h>
+#include <zlib.h>
/* this is a way to get number of channels from color space
* Color code to channel number */
}
}
+ {
+ int level;
+ if (i_tags_get_int(&im->tags, "png_compression_level", 0, &level)) {
+ if (level >= Z_NO_COMPRESSION && level <= Z_BEST_COMPRESSION)
+ png_set_compression_level(png_ptr, level);
+ else {
+ i_push_errorf(0, "png_compression_level must be between %d and %d",
+ Z_NO_COMPRESSION, Z_BEST_COMPRESSION);
+ return 0;
+ }
+ }
+ }
+
{
/* no bKGD support yet, maybe later
it may be simpler to do it in the individual writers
init_log("testout/t102png.log",1);
-plan tests => 251;
+plan tests => 256;
# this loads Imager::File::PNG too
ok($Imager::formats{"png"}, "must have png format");
}
}
+{
+ # png_compression_level
+ my $im = test_image();
+ my $out1;
+ ok($im->write(data => \$out1, type => "png"), "write default compression");
+ my $out2;
+ ok($im->write(data => \$out2, type => "png", png_compression_level => 9),
+ "write best compression");
+ cmp_ok(length($out1), '>', length($out2), "best compression smaller than default");
+ note "went from ", length($out1), " to ", length($out2);
+ # error handling
+ ok(!$im->write(data => \$out1, type => "png", png_compression_level => -1),
+ "fail with compression level -1");
+ ok(!$im->write(data => \$out1, type => "png", png_compression_level => 10),
+ "fail with compression level 10");
+}
+
sub limited_write {
my ($limit) = @_;
X<tags, png_srgb_intent>C<png_srgb_intent> - the sRGB rendering intent
for the image. an integer from 0 to 3, per the PNG specification. If
this chunk is found in the PNG file the C<gAMA> and C<cHRM> are
-ignored and the C<png_gamme> and C<png_chroma_...> tags are not set.
+ignored and the C<png_gamma> and C<png_chroma_...> tags are not set.
Similarly when writing if C<png_srgb_intent> is set the C<gAMA> and
C<cHRM> chunks are not written.
=back
+X<compression>X<png_compression_level>You can control the level of
+F<zlib> compression used when writing with the
+C<png_compression_level> parameter. This can be an integer between 0
+(uncompressed) and 9 (best compression).
+
=for stopwords
CRC