mm_log((1,"i_writejpeg(im %p, ig %p, qfactor %d)\n", im, ig, qfactor));
i_clear_error();
+ io_glue_commit_types(ig);
if (!(im->channels==1 || im->channels==3)) {
i_push_error(0, "only 1 or 3 channels images can be saved as JPEG");
return 0;
}
- io_glue_commit_types(ig);
jpeg_wiol_dest(&cinfo, ig);
cinfo.image_width = im -> xsize; /* image width and height, in pixels */
use strict;
use lib 't';
use Imager qw(:all);
-use Test::More tests => 54;
+use Test::More tests => 56;
init_log("testout/t101jpeg.log",1);
$im = Imager->new(xsize=>2, ysize=>2);
ok(!$im->write(file=>"testout/nojpeg.jpg"), "should fail to write jpeg");
cmp_ok($im->errstr, '=~', qr/format not supported/, "check no jpeg message");
- skip("no jpeg support", 50);
+ skip("no jpeg support", 52);
}
} else {
open(FH,">testout/t101.jpg") || die "cannot open testout/t101.jpg for writing\n";
my %iptc = $im->parseiptc;
ok(!$saw_warn, "should be no warnings");
}
+
+ { # Issue # 18397
+ # attempting to write a 4 channel image to a bufchain would
+ # cause a seg fault.
+ # it should fail still
+ my $im = Imager->new(xsize => 10, ysize => 10, channels => 4);
+ my $data;
+ ok(!$im->write(data => \$data, type => 'jpeg'),
+ "should fail to write but shouldn't crash");
+ is($im->errstr, "only 1 or 3 channels images can be saved as JPEG",
+ "check the error message");
+ }
}
use Imager qw(:all);
use strict;
use lib 't';
-use Test::More tests=>36;
+use Test::More tests=>38;
BEGIN { require "t/testtools.pl"; }
init_log("testout/t108tga.log",1);
Imager->set_file_limits(reset=>1);
}
+{ # Issue # 18397
+ # the issue is for 4 channel images to jpeg, but 2 channel images have
+ # a similar problem on tga
+ my $im = Imager->new(xsize=>100, ysize=>100, channels => 2);
+ my $data;
+ ok(!$im->write(data => \$data, type=>'tga'),
+ "check failure of writing a 2 channel image");
+ is($im->errstr, "Cannot store 2 channel image in targa format",
+ "check the error message");
+}
+
sub write_test {
my ($im, $filename, $wierdpack, $compress, $idstring) = @_;
local *FH;
mm_log((1, "channels %d\n", img->channels));
i_clear_error();
+ io_glue_commit_types(ig);
switch (img->channels) {
case 1:
return 0;
}
- io_glue_commit_types(ig);
-
header.idlength = idlen;
header.colourmaptype = mapped ? 1 : 0;
header.datatypecode = mapped ? 1 : img->channels == 1 ? 3 : 2;