image->hotspot_y = hotspot_y;
}
- image->width = width;
- image->height = height;
+ /* a width or height of zero here indicates a width/height of 256 */
+ image->width = width ? width : 256;
+ image->height = height ? height : 256;
image->offset = image_offset;
image->size = bytes_in_res;
}
ico_image_t const *image = images + i;
int bits, colors;
int size = ico_image_size(image, &bits, &colors);
+ int width_byte = image->width == 256 ? 0 : image->width;
+ int height_byte = image->height == 256 ? 0 : image->height;
if (type == ICON_ICON) {
- if (!write_packed(ig, "bbbbwwdd", image->width, image->height,
+ if (!write_packed(ig, "bbbbwwdd", width_byte, height_byte,
colors, 0, 1, bits, (unsigned long)size,
(unsigned long)current_offset)) {
*error = ICOERR_Write_Failure;
else if (hotspot_y >= image->height)
hotspot_y = image->height - 1;
- if (!write_packed(ig, "bbbbwwdd", image->width, image->height,
+ if (!write_packed(ig, "bbbbwwdd", width_byte, height_byte,
colors, 0, hotspot_x, hotspot_y, (unsigned long)size,
(unsigned long)current_offset)) {
*error = ICOERR_Write_Failure;
for (i = 0; i < image_count; ++i) {
ico_image_t const *image = images + i;
- if (image->width < 1 || image->width > 255) {
+ if (image->width < 1 || image->width > 256) {
*error = ICOERR_Invalid_Width;
return 0;
}
- if (image->height < 1 || image->height > 255) {
+ if (image->height < 1 || image->height > 256) {
*error = ICOERR_Invalid_Height;
return 0;
}
#!perl -w
use strict;
-use Test::More tests => 102;
+use Test::More tests => 106;
use Imager::Test qw(is_image test_image);
BEGIN { use_ok('Imager::File::ICO'); }
like($im->errstr, qr/synthetic close failure/,
"check error message");
}
+
+{ # RT #69599
+ {
+ my $ico = Imager->new(file => "testimg/pal256.ico", filetype => "ico");
+ ok($ico, "read a 256x256 pixel wide/high icon")
+ or diag "Could not read 256x256 pixel icon: ",Imager->errstr;
+ }
+ SKIP:
+ {
+ my $im = test_image();
+ my $sc = $im->scale(xpixels => 256, ypixels => 256, type => "nonprop")
+ or diag("Cannot scale: " . $im->errstr);
+ $sc
+ or skip("Cannot produce scaled image", 3);
+ my $alpha = $sc->convert(preset => "addalpha")
+ or diag "Cannot add alpha channel: " . $sc->errstr ;
+
+ my $data;
+ ok($alpha->write(data => \$data, type => "ico"),
+ "save 256x256 image")
+ or diag("Cannot save 256x256 icon:" . $alpha->errstr);
+ my $read = Imager->new(data => $data, filetype => "ico");
+ ok($read, "read 256x256 pixel image back in")
+ or diag(Imager->errstr);
+ $read
+ or skip("Couldn't read to compare", 1);
+ is_image($read, $alpha, "check we read what we wrote");
+ }
+}
+