| 1 | #!perl -w | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Test::More tests => 111; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Imager::Test qw(is_image isnt_image test_image); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | BEGIN { use_ok('Imager::File::ICO'); } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | -d 'testout' or mkdir 'testout', 0777; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | my $im = Imager->new; | |||||||||
| 11 | # type=>'ico' or 'cur' and read ico and cur since they're pretty much | ||||||||||
| 12 | # the same | ||||||||||
| 13 | 1 | ▶ | ok($im->read(file => "testimg/rgba3232.ico", type=>"ico", ico_masked => 0), | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | "read 32 bit") | ||||||||||
| 15 | or print "# ", $im->errstr, "\n"; | ||||||||||
| 16 | 1 | is($im->getwidth, 32, "check width"); | |||||||||
| 17 | 1 | is($im->getwidth, 32, "check height"); | |||||||||
| 18 | 1 | is($im->type, 'direct', "check type"); | |||||||||
| 19 | 1 | is($im->tags(name => 'ico_bits'), 32, "check ico_bits tag"); | |||||||||
| 20 | 1 | is($im->tags(name => 'i_format'), 'ico', "check i_format tag"); | |||||||||
| 21 | 1 | my $mask = '.* | |||||||||
| 22 | ..........................****** | ||||||||||
| 23 | ..........................****** | ||||||||||
| 24 | ..........................****** | ||||||||||
| 25 | ..........................****** | ||||||||||
| 26 | ...........................***** | ||||||||||
| 27 | ............................**** | ||||||||||
| 28 | ............................**** | ||||||||||
| 29 | .............................*** | ||||||||||
| 30 | .............................*** | ||||||||||
| 31 | .............................*** | ||||||||||
| 32 | .............................*** | ||||||||||
| 33 | ..............................** | ||||||||||
| 34 | ..............................** | ||||||||||
| 35 | ...............................* | ||||||||||
| 36 | ...............................* | ||||||||||
| 37 | ................................ | ||||||||||
| 38 | ................................ | ||||||||||
| 39 | ................................ | ||||||||||
| 40 | ................................ | ||||||||||
| 41 | ................................ | ||||||||||
| 42 | ................................ | ||||||||||
| 43 | *............................... | ||||||||||
| 44 | **.............................. | ||||||||||
| 45 | **.............................. | ||||||||||
| 46 | ***............................. | ||||||||||
| 47 | ***............................. | ||||||||||
| 48 | ****............................ | ||||||||||
| 49 | ****............................ | ||||||||||
| 50 | *****........................... | ||||||||||
| 51 | *****........................... | ||||||||||
| 52 | *****........................... | ||||||||||
| 53 | *****...........................'; | ||||||||||
| 54 | 1 | is($im->tags(name => 'ico_mask'), $mask, "check ico_mask_tag"); | |||||||||
| 55 | |||||||||||
| 56 | # compare the pixels | ||||||||||
| 57 | # ppm can't store 4 channels | ||||||||||
| 58 | SKIP: | ||||||||||
| 59 | { | ||||||||||
| 60 | 1 | my $work = $im->convert(preset=>'noalpha'); | |||||||||
| 61 | 1 | my $comp = Imager->new; | |||||||||
| 62 | 1 | ▶ | $comp->read(file => "testimg/rgba3232.ppm") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | or skip "could not read 24-bit comparison file:". $comp->errstr, 1; | ||||||||||
| 64 | 1 | is(Imager::i_img_diff($comp->{IMG}, $work->{IMG}), 0, | |||||||||
| 65 | "compare image data"); | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 1 | ▶ | ok($im->read(file => 'testimg/pal83232.ico', type=>'ico', ico_masked => 0), | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | "read 8 bit") | ||||||||||
| 70 | or print "# ", $im->errstr, "\n"; | ||||||||||
| 71 | 1 | is($im->getwidth, 32, "check width"); | |||||||||
| 72 | 1 | is($im->getwidth, 32, "check height"); | |||||||||
| 73 | 1 | is($im->type, 'paletted', "check type"); | |||||||||
| 74 | 1 | is($im->colorcount, 256, "color count"); | |||||||||
| 75 | 1 | is($im->tags(name => 'ico_bits'), 8, "check ico_bits tag"); | |||||||||
| 76 | 1 | is($im->tags(name => 'i_format'), 'ico', "check i_format tag"); | |||||||||
| 77 | SKIP: | ||||||||||
| 78 | { | ||||||||||
| 79 | 1 | my $comp = Imager->new; | |||||||||
| 80 | 1 | ▶ | $comp->read(file => "testimg/pal83232.ppm") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | or skip "could not read 8-bit comparison file:". $comp->errstr, 1; | ||||||||||
| 82 | 1 | is(Imager::i_img_diff($comp->{IMG}, $im->{IMG}), 0, | |||||||||
| 83 | "compare image data"); | ||||||||||
| 84 | } | ||||||||||
| 85 | 1 | $im->write(file=>'testout/pal83232.ppm'); | |||||||||
| 86 | |||||||||||
| 87 | 1 | ▶ | ok($im->read(file => 'testimg/pal43232.ico', type=>'ico', ico_masked => 0), | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | "read 4 bit") | ||||||||||
| 89 | or print "# ", $im->errstr, "\n"; | ||||||||||
| 90 | 1 | is($im->getwidth, 32, "check width"); | |||||||||
| 91 | 1 | is($im->getwidth, 32, "check height"); | |||||||||
| 92 | 1 | is($im->type, 'paletted', "check type"); | |||||||||
| 93 | 1 | is($im->colorcount, 16, "color count"); | |||||||||
| 94 | 1 | is($im->tags(name => 'ico_bits'), 4, "check ico_bits tag"); | |||||||||
| 95 | 1 | is($im->tags(name => 'i_format'), 'ico', "check i_format tag"); | |||||||||
| 96 | SKIP: | ||||||||||
| 97 | { | ||||||||||
| 98 | 1 | my $comp = Imager->new; | |||||||||
| 99 | 1 | ▶ | $comp->read(file => "testimg/pal43232.ppm") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | or skip "could not read 4-bit comparison file:". $comp->errstr, 1; | ||||||||||
| 101 | 1 | is(Imager::i_img_diff($comp->{IMG}, $im->{IMG}), 0, | |||||||||
| 102 | "compare image data"); | ||||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | 1 | $im->write(file=>'testout/pal43232.ppm'); | |||||||||
| 106 | 1 | ▶ | ok($im->read(file => 'testimg/pal13232.ico', type=>'ico', ico_masked => 0), | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | "read 1 bit") | ||||||||||
| 108 | or print "# ", $im->errstr, "\n"; | ||||||||||
| 109 | 1 | is($im->getwidth, 32, "check width"); | |||||||||
| 110 | 1 | is($im->getwidth, 32, "check height"); | |||||||||
| 111 | 1 | is($im->type, 'paletted', "check type"); | |||||||||
| 112 | 1 | is($im->colorcount, 2, "color count"); | |||||||||
| 113 | 1 | is($im->tags(name => 'cur_bits'), 1, "check ico_bits tag"); | |||||||||
| 114 | 1 | is($im->tags(name => 'i_format'), 'cur', "check i_format tag"); | |||||||||
| 115 | 1 | $im->write(file=>'testout/pal13232.ppm'); | |||||||||
| 116 | |||||||||||
| 117 | # combo was created with the GIMP, which has a decent mechanism for selecting | ||||||||||
| 118 | # the output format | ||||||||||
| 119 | # you get different size icon images by making different size layers. | ||||||||||
| 120 | 1 | my @imgs = Imager->read_multi(file => 'testimg/combo.ico', type=>'ico', | |||||||||
| 121 | ico_masked => 0); | ||||||||||
| 122 | 1 | is(scalar(@imgs), 3, "read multiple"); | |||||||||
| 123 | 1 | is($imgs[0]->getwidth, 48, "image 0 width"); | |||||||||
| 124 | 1 | is($imgs[0]->getheight, 48, "image 0 height"); | |||||||||
| 125 | 1 | is($imgs[1]->getwidth, 32, "image 1 width"); | |||||||||
| 126 | 1 | is($imgs[1]->getheight, 32, "image 1 height"); | |||||||||
| 127 | 1 | is($imgs[2]->getwidth, 16, "image 2 width"); | |||||||||
| 128 | 1 | is($imgs[2]->getheight, 16, "image 2 height"); | |||||||||
| 129 | 1 | is($imgs[0]->type, 'direct', "image 0 type"); | |||||||||
| 130 | 1 | is($imgs[1]->type, 'paletted', "image 1 type"); | |||||||||
| 131 | 1 | is($imgs[2]->type, 'paletted', "image 2 type"); | |||||||||
| 132 | 1 | is($imgs[1]->colorcount, 256, "image 1 colorcount"); | |||||||||
| 133 | 1 | is($imgs[2]->colorcount, 16, "image 2 colorcount"); | |||||||||
| 134 | |||||||||||
| 135 | 1 | is_deeply([ $imgs[0]->getpixel(x=>0, 'y'=>0)->rgba ], [ 231, 17, 67, 255 ], | |||||||||
| 136 | "check image data 0(0,0)"); | ||||||||||
| 137 | 1 | is_deeply([ $imgs[1]->getpixel(x=>0, 'y'=>0)->rgba ], [ 231, 17, 67, 255 ], | |||||||||
| 138 | "check image data 1(0,0)"); | ||||||||||
| 139 | 1 | is_deeply([ $imgs[2]->getpixel(x=>0, 'y'=>0)->rgba ], [ 231, 17, 67, 255 ], | |||||||||
| 140 | "check image data 2(0,0)"); | ||||||||||
| 141 | |||||||||||
| 142 | 1 | is_deeply([ $imgs[0]->getpixel(x=>47, 'y'=>0)->rgba ], [ 131, 231, 17, 255 ], | |||||||||
| 143 | "check image data 0(47,0)"); | ||||||||||
| 144 | 1 | is_deeply([ $imgs[1]->getpixel(x=>31, 'y'=>0)->rgba ], [ 131, 231, 17, 255 ], | |||||||||
| 145 | "check image data 1(31,0)"); | ||||||||||
| 146 | 1 | is_deeply([ $imgs[2]->getpixel(x=>15, 'y'=>0)->rgba ], [ 131, 231, 17, 255 ], | |||||||||
| 147 | "check image data 2(15,0)"); | ||||||||||
| 148 | |||||||||||
| 149 | 1 | is_deeply([ $imgs[0]->getpixel(x=>0, 'y'=>47)->rgba ], [ 17, 42, 231, 255 ], | |||||||||
| 150 | "check image data 0(0,47)"); | ||||||||||
| 151 | 1 | is_deeply([ $imgs[1]->getpixel(x=>0, 'y'=>31)->rgba ], [ 17, 42, 231, 255 ], | |||||||||
| 152 | "check image data 1(0,31)"); | ||||||||||
| 153 | 1 | is_deeply([ $imgs[2]->getpixel(x=>0, 'y'=>15)->rgba ], [ 17, 42, 231, 255 ], | |||||||||
| 154 | "check image data 2(0,15)"); | ||||||||||
| 155 | |||||||||||
| 156 | 1 | is_deeply([ $imgs[0]->getpixel(x=>47, 'y'=>47)->rgba ], [ 17, 231, 177, 255 ], | |||||||||
| 157 | "check image data 0(47,47)"); | ||||||||||
| 158 | 1 | is_deeply([ $imgs[1]->getpixel(x=>31, 'y'=>31)->rgba ], [ 17, 231, 177, 255 ], | |||||||||
| 159 | "check image data 1(31,31)"); | ||||||||||
| 160 | 1 | is_deeply([ $imgs[2]->getpixel(x=>15, 'y'=>15)->rgba ], [ 17, 231, 177, 255 ], | |||||||||
| 161 | "check image data 2(15,15)"); | ||||||||||
| 162 | |||||||||||
| 163 | 1 | $im = Imager->new(xsize=>32, ysize=>32); | |||||||||
| 164 | 1 | $im->box(filled=>1, color=>'FF0000'); | |||||||||
| 165 | 1 | $im->box(filled=>1, color=>'0000FF', xmin => 6, ymin=>0, xmax => 21, ymax=>15); | |||||||||
| 166 | 1 | $im->box(filled=>1, color=>'00FF00', xmin => 10, ymin=>16, xmax => 25, ymax=>31); | |||||||||
| 167 | |||||||||||
| 168 | 1 | ok($im->write(file=>'testout/t10_32.ico', type=>'ico'), | |||||||||
| 169 | "write 32-bit icon"); | ||||||||||
| 170 | |||||||||||
| 171 | 1 | my $im2 = Imager->new; | |||||||||
| 172 | 1 | ok($im2->read(file=>'testout/t10_32.ico', type=>'ico', ico_masked => 0), | |||||||||
| 173 | "read it back in"); | ||||||||||
| 174 | |||||||||||
| 175 | 1 | is(Imager::i_img_diff($im->{IMG}, $im2->{IMG}), 0, | |||||||||
| 176 | "check they're the same"); | ||||||||||
| 177 | 1 | is($im->bits, $im2->bits, "check same bits"); | |||||||||
| 178 | |||||||||||
| 179 | { | ||||||||||
| 180 | 1 | my $im = Imager->new(xsize => 32, ysize => 32); | |||||||||
| 181 | 1 | $im->box(filled=>1, color=>'#FF00FF'); | |||||||||
| 182 | 1 | my $data; | |||||||||
| 183 | 1 | ok(Imager->write_multi({ data => \$data, type=>'ico' }, $im, $im), | |||||||||
| 184 | "write multi icons"); | ||||||||||
| 185 | 1 | ok(length $data, "and it wrote data"); | |||||||||
| 186 | 1 | my @im = Imager->read_multi(data => $data, ico_masked => 0); | |||||||||
| 187 | 1 | is(@im, 2, "got all the images back"); | |||||||||
| 188 | 1 | is(Imager::i_img_diff($im->{IMG}, $im[0]{IMG}), 0, "check first image"); | |||||||||
| 189 | 1 | is(Imager::i_img_diff($im->{IMG}, $im[1]{IMG}), 0, "check second image"); | |||||||||
| 190 | } | ||||||||||
| 191 | |||||||||||
| 192 | { # 1 channel image | ||||||||||
| 193 | 1 | my $im = Imager->new(xsize => 32, ysize => 32, channels => 1); | |||||||||
| 194 | 1 | $im->box(filled=>1, color => [ 128, 0, 0 ]); | |||||||||
| 195 | 1 | my $data; | |||||||||
| 196 | 1 | ok($im->write(data => \$data, type=>'ico'), "write 1 channel image"); | |||||||||
| 197 | 1 | my $im2 = Imager->new; | |||||||||
| 198 | 1 | ok($im2->read(data => $data, ico_masked => 0), "read it back"); | |||||||||
| 199 | 1 | is($im2->getchannels, 4, "check channels"); | |||||||||
| 200 | 1 | my $imrgb = $im->convert(preset => 'rgb') | |||||||||
| 201 | ->convert(preset => 'addalpha'); | ||||||||||
| 202 | 1 | is(Imager::i_img_diff($imrgb->{IMG}, $im2->{IMG}), 0, | |||||||||
| 203 | "check image matches expected"); | ||||||||||
| 204 | } | ||||||||||
| 205 | |||||||||||
| 206 | { # 2 channel image | ||||||||||
| 207 | 1 | my $base = Imager->new(xsize => 32, ysize => 32, channels => 2); | |||||||||
| 208 | 1 | $base->box(filled => 1, color => [ 64, 192, 0 ]); | |||||||||
| 209 | 1 | my $data; | |||||||||
| 210 | 1 | ok($base->write(data => \$data, type=>'ico'), "write 2 channel image"); | |||||||||
| 211 | 1 | my $read = Imager->new; | |||||||||
| 212 | 1 | ok($read->read(data => $data, ico_masked => 0), "read it back"); | |||||||||
| 213 | 1 | is($read->getchannels, 4, "check channels"); | |||||||||
| 214 | 1 | my $imrgb = $base->convert(preset => 'rgb'); | |||||||||
| 215 | 1 | is(Imager::i_img_diff($imrgb->{IMG}, $read->{IMG}), 0, | |||||||||
| 216 | "check image matches expected"); | ||||||||||
| 217 | } | ||||||||||
| 218 | |||||||||||
| 219 | { # 4 channel image | ||||||||||
| 220 | 1 | my $base = Imager->new(xsize => 32, ysize => 32, channels => 4); | |||||||||
| 221 | 1 | $base->box(filled=>1, ymax => 15, color => [ 255, 0, 255, 128 ]); | |||||||||
| 222 | 1 | $base->box(filled=>1, ymin => 16, color => [ 0, 255, 255, 255 ]); | |||||||||
| 223 | 1 | my $data; | |||||||||
| 224 | 1 | ok($base->write(data => \$data, type=>'ico'), "write 4 channel image"); | |||||||||
| 225 | 1 | my $read = Imager->new; | |||||||||
| 226 | 1 | ▶ | ok($read->read(data => $data, type=>'ico', ico_masked => 0), "read it back") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 227 | or print "# ", $read->errstr, "\n"; | ||||||||||
| 228 | 1 | is(Imager::i_img_diff($base->{IMG}, $read->{IMG}), 0, | |||||||||
| 229 | "check image matches expected"); | ||||||||||
| 230 | } | ||||||||||
| 231 | |||||||||||
| 232 | { # mask handling | ||||||||||
| 233 | 1 | my $base = Imager->new(xsize => 16, ysize => 16, channels => 3); | |||||||||
| 234 | 1 | $base->box(filled=>1, xmin => 5, xmax => 10, color => '#0000FF'); | |||||||||
| 235 | 1 | $base->box(filled=>1, ymin => 5, ymax => 10, color => '#0000FF'); | |||||||||
| 236 | 1 | my $mask = <<EOS; # CR in this to test it's skipped correctly | |||||||||
| 237 | 01 | ||||||||||
| 238 | 0000011111100000 | ||||||||||
| 239 | 00000111111 00000xx | ||||||||||
| 240 | 00000111111000 | ||||||||||
| 241 | 00000111111000 | ||||||||||
| 242 | 0000011111100000 | ||||||||||
| 243 | 1111111111111111 | ||||||||||
| 244 | 1111111111111111 | ||||||||||
| 245 | 1111111111111111 | ||||||||||
| 246 | 1111111111111111 | ||||||||||
| 247 | 1111111111111111 | ||||||||||
| 248 | 1111111111111111 | ||||||||||
| 249 | 1010101010101010 | ||||||||||
| 250 | 1010101010101010 | ||||||||||
| 251 | 1010101010101010 | ||||||||||
| 252 | 1010101010101010 | ||||||||||
| 253 | 1010101010101010 | ||||||||||
| 254 | EOS | ||||||||||
| 255 | 1 | $mask =~ s/\n/\r\n/g; # to test alternate newline handling is correct | |||||||||
| 256 | 1 | $base->settag(name => 'ico_mask', value => $mask); | |||||||||
| 257 | 1 | my $saved_mask = $base->tags(name => 'ico_mask'); | |||||||||
| 258 | 1 | my $data; | |||||||||
| 259 | 1 | ok($base->write(data => \$data, type => 'ico'), | |||||||||
| 260 | "write with mask tag set"); | ||||||||||
| 261 | 1 | my $read = Imager->new; | |||||||||
| 262 | 1 | ok($read->read(data => $data, ico_masked => 0), "read it back"); | |||||||||
| 263 | 1 | my $mask2 = $mask; | |||||||||
| 264 | 1 | $mask2 =~ tr/01/.*/; | |||||||||
| 265 | 1 | $mask2 =~ s/\n$//; | |||||||||
| 266 | 1 | $mask2 =~ tr/\r x//d; | |||||||||
| 267 | 1 | $mask2 =~ s/^(.{3,19})$/$1 . "." x (16 - length $1)/gem; | |||||||||
| 268 | 1 | my $read_mask = $read->tags(name => 'ico_mask'); | |||||||||
| 269 | 1 | is($read_mask, $mask2, "check mask is correct"); | |||||||||
| 270 | } | ||||||||||
| 271 | |||||||||||
| 272 | { # mask too short to handle | ||||||||||
| 273 | 1 | my $mask = "xx"; | |||||||||
| 274 | 1 | my $base = Imager->new(xsize => 16, ysize => 16, channels => 3); | |||||||||
| 275 | 1 | $base->box(filled=>1, xmin => 5, xmax => 10, color => '#0000FF'); | |||||||||
| 276 | 1 | $base->box(filled=>1, ymin => 5, ymax => 10, color => '#0000FF'); | |||||||||
| 277 | 1 | $base->settag(name => 'ico_mask', value => $mask); | |||||||||
| 278 | 1 | my $data; | |||||||||
| 279 | 1 | ok($base->write(data => \$data, type=>'ico'), | |||||||||
| 280 | "save icon with short mask tag"); | ||||||||||
| 281 | 1 | my $read = Imager->new; | |||||||||
| 282 | 1 | ok($read->read(data => $data, ico_masked => 0), "read it back"); | |||||||||
| 283 | 1 | my $read_mask = $read->tags(name => 'ico_mask'); | |||||||||
| 284 | 1 | my $expected_mask = ".*" . ( "\n" . "." x 16 ) x 16; | |||||||||
| 285 | 1 | is($read_mask, $expected_mask, "check the mask"); | |||||||||
| 286 | |||||||||||
| 287 | # mask that doesn't match what we expect | ||||||||||
| 288 | 1 | $base->settag(name => 'ico_mask', value => 'abcd'); | |||||||||
| 289 | 1 | ok($base->write(data => \$data, type => 'ico'), | |||||||||
| 290 | "write with bad format mask tag"); | ||||||||||
| 291 | 1 | ok($read->read(data => $data, ico_masked => 0), "read it back"); | |||||||||
| 292 | 1 | $read_mask = $read->tags(name => 'ico_mask'); | |||||||||
| 293 | 1 | is($read_mask, $expected_mask, "check the mask"); | |||||||||
| 294 | |||||||||||
| 295 | # mask with invalid char | ||||||||||
| 296 | 1 | $base->settag(name => 'ico_mask', value => ".*\n....xxx.."); | |||||||||
| 297 | 1 | ok($base->write(data => \$data, type => 'ico'), | |||||||||
| 298 | "write with unexpected chars in mask"); | ||||||||||
| 299 | 1 | ok($read->read(data => $data, ico_masked => 0), "read it back"); | |||||||||
| 300 | 1 | $read_mask = $read->tags(name => 'ico_mask'); | |||||||||
| 301 | 1 | is($read_mask, $expected_mask, "check the mask"); | |||||||||
| 302 | } | ||||||||||
| 303 | |||||||||||
| 304 | { # check handling of greyscale paletted | ||||||||||
| 305 | 1 | my $base = Imager->new(xsize => 16, ysize => 16, channels => 1, | |||||||||
| 306 | type => 'paletted'); | ||||||||||
| 307 | 1 | my @grays = map Imager::Color->new($_), | |||||||||
| 308 | "000000", "666666", "CCCCCC", "FFFFFF"; | ||||||||||
| 309 | 1 | ok($base->addcolors(colors => \@grays), "add some colors"); | |||||||||
| 310 | 1 | $base->box(filled => 1, color => $grays[1], xmax => 7, ymax => 7); | |||||||||
| 311 | 1 | $base->box(filled => 1, color => $grays[1], xmax => 7, ymin => 8); | |||||||||
| 312 | 1 | $base->box(filled => 1, color => $grays[1], xmin => 8, ymax => 7); | |||||||||
| 313 | 1 | $base->box(filled => 1, color => $grays[1], xmin => 8, ymax => 8); | |||||||||
| 314 | 1 | my $data; | |||||||||
| 315 | 1 | ok($base->write(data => \$data, type => 'ico'), | |||||||||
| 316 | "write grayscale paletted"); | ||||||||||
| 317 | 1 | my $read = Imager->new; | |||||||||
| 318 | 1 | ▶ | ok($read->read(data => $data, ico_masked => 0), "read it back") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 319 | or print "# ", $read->errstr, "\n"; | ||||||||||
| 320 | 1 | is($read->type, 'paletted', "check type"); | |||||||||
| 321 | 1 | is($read->getchannels, 3, "check channels"); | |||||||||
| 322 | 1 | my $as_rgb = $base->convert(preset => 'rgb'); | |||||||||
| 323 | 1 | is(Imager::i_img_diff($base->{IMG}, $read->{IMG}), 0, | |||||||||
| 324 | "check the image"); | ||||||||||
| 325 | } | ||||||||||
| 326 | |||||||||||
| 327 | { | ||||||||||
| 328 | # check default mask processing | ||||||||||
| 329 | # | ||||||||||
| 330 | # the query at http://www.cpanforum.com/threads/5958 made it fairly | ||||||||||
| 331 | # obvious that the way Imager handled the mask in 0.59 was confusing | ||||||||||
| 332 | # when compared with loading other images with some sort of | ||||||||||
| 333 | # secondary alpha channel (eg. gif) | ||||||||||
| 334 | # So from 0.60 the mask is applied as an alpha channel by default. | ||||||||||
| 335 | # make sure that application works. | ||||||||||
| 336 | |||||||||||
| 337 | # the strange mask checks the optimization paths of the mask application | ||||||||||
| 338 | 1 | my $mask = <<EOS; | |||||||||
| 339 | 01 | ||||||||||
| 340 | 1001 | ||||||||||
| 341 | 1100 | ||||||||||
| 342 | 0011 | ||||||||||
| 343 | 0000 | ||||||||||
| 344 | 0010 | ||||||||||
| 345 | EOS | ||||||||||
| 346 | 1 | chomp $mask; | |||||||||
| 347 | 1 | my $im = Imager->new(xsize => 4, ysize => 5, type => 'paletted'); | |||||||||
| 348 | 1 | $im->addcolors(colors => [ '#FF0000' ]); | |||||||||
| 349 | 1 | $im->box(filled => 1, color => '#FF0000'); | |||||||||
| 350 | 1 | $im->settag(name => 'ico_mask', value => $mask); | |||||||||
| 351 | 1 | my $imcopy = $im->convert(preset=>'addalpha'); | |||||||||
| 352 | 1 | my $red_alpha = Imager::Color->new(255, 0, 0, 0); | |||||||||
| 353 | 1 | $imcopy->setpixel( 'x' => [ qw/0 3 0 1 2 3 2/ ], | |||||||||
| 354 | 'y' => [ qw/0 0 1 1 2 2 4/ ], | ||||||||||
| 355 | color => $red_alpha); | ||||||||||
| 356 | 1 | my $data; | |||||||||
| 357 | 1 | ok($im->write(data => \$data, type => 'ico'), | |||||||||
| 358 | "save icon + mask"); | ||||||||||
| 359 | 1 | my $im2 = Imager->new; | |||||||||
| 360 | 1 | ok($im2->read(data => $data), "read ico with defaults"); | |||||||||
| 361 | 1 | is($im2->type, 'direct', 'expect a direct image'); | |||||||||
| 362 | 1 | is_image($im2, $imcopy, 'check against expected'); | |||||||||
| 363 | } | ||||||||||
| 364 | |||||||||||
| 365 | { | ||||||||||
| 366 | # read 24-bit images | ||||||||||
| 367 | 1 | my $im = Imager->new; | |||||||||
| 368 | 1 | ▶ | ok($im->read(file => 'testimg/rgb1616.ico'), "read 24-bit data image") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 369 | or print "# ", $im->errstr, "\n"; | ||||||||||
| 370 | 1 | my $vs = Imager->new(xsize => 16, ysize => 16); | |||||||||
| 371 | 1 | $vs->box(filled => 1, color => '#333366'); | |||||||||
| 372 | 1 | is_image($im, $vs, "check we got the right colors"); | |||||||||
| 373 | } | ||||||||||
| 374 | |||||||||||
| 375 | |||||||||||
| 376 | { # check close failures are handled correctly | ||||||||||
| 377 | 1 | my $im = test_image(); | |||||||||
| 378 | 1 | ▶ | my $fail_close = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 379 | 1 | Imager::i_push_error(0, "synthetic close failure"); | |||||||||
| 380 | 1 | return 0; | |||||||||
| 381 | 1 | }; | |||||||||
| 382 | 12 | ▶ | ok(!$im->write(type => "ico", callback => sub { 1 }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 383 | 1 | closecb => $fail_close), | |||||||||
| 384 | "check failing close fails"); | ||||||||||
| 385 | 1 | like($im->errstr, qr/synthetic close failure/, | |||||||||
| 386 | "check error message"); | ||||||||||
| 387 | } | ||||||||||
| 388 | |||||||||||
| 389 | { # RT #69599 | ||||||||||
| 390 | 1 | { | |||||||||
| 391 | 1 | my $ico = Imager->new(file => "testimg/pal256.ico", filetype => "ico"); | |||||||||
| 392 | 1 | ▶ | ok($ico, "read a 256x256 pixel wide/high icon") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 393 | or diag "Could not read 256x256 pixel icon: ",Imager->errstr; | ||||||||||
| 394 | } | ||||||||||
| 395 | SKIP: | ||||||||||
| 396 | { | ||||||||||
| 397 | 1 | my $im = test_image(); | |||||||||
| 398 | 1 | ▶ | my $sc = $im->scale(xpixels => 256, ypixels => 256, type => "nonprop") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 399 | or diag("Cannot scale: " . $im->errstr); | ||||||||||
| 400 | 1 | ▶ | $sc | ||||||||
|
Branch: 1 branch
| |||||||||||
| 401 | or skip("Cannot produce scaled image", 3); | ||||||||||
| 402 | 1 | ▶ | my $alpha = $sc->convert(preset => "addalpha") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 403 | or diag "Cannot add alpha channel: " . $sc->errstr ; | ||||||||||
| 404 | |||||||||||
| 405 | 1 | my $data; | |||||||||
| 406 | 1 | ▶ | ok($alpha->write(data => \$data, type => "ico"), | ||||||||
|
Branch: 1 branch
| |||||||||||
| 407 | "save 256x256 image") | ||||||||||
| 408 | or diag("Cannot save 256x256 icon:" . $alpha->errstr); | ||||||||||
| 409 | 1 | my $read = Imager->new(data => $data, filetype => "ico"); | |||||||||
| 410 | 1 | ▶ | ok($read, "read 256x256 pixel image back in") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 411 | or diag(Imager->errstr); | ||||||||||
| 412 | 1 | ▶ | $read | ||||||||
|
Branch: 1 branch
| |||||||||||
| 413 | or skip("Couldn't read to compare", 1); | ||||||||||
| 414 | 1 | is_image($read, $alpha, "check we read what we wrote"); | |||||||||
| 415 | } | ||||||||||
| 416 | } | ||||||||||
| 417 | |||||||||||
| 418 | { # RT #99507 | ||||||||||
| 419 | # we now ignore the mask by default when reading a 32-bit image | ||||||||||
| 420 | 1 | my $im = Imager->new(xsize => 2, ysize => 2, channels => 4); | |||||||||
| 421 | 1 | $im->setpixel(x => 0, y => 0, color => "#FF0000"); | |||||||||
| 422 | 1 | $im->setpixel(x => 1, y => 1, color => "#00FF00"); | |||||||||
| 423 | 1 | my $mask = <<EOS; | |||||||||
| 424 | 01 | ||||||||||
| 425 | 00 | ||||||||||
| 426 | 11 | ||||||||||
| 427 | EOS | ||||||||||
| 428 | 1 | my $data; | |||||||||
| 429 | 1 | ok($im->write(data => \$data, | |||||||||
| 430 | type => "ico", | ||||||||||
| 431 | ico_mask => $mask), "write with dodgy mask"); | ||||||||||
| 432 | 1 | my $im2 = Imager->new(data => \$data, filetype => "ico"); | |||||||||
| 433 | 1 | ok($im2, "read it back"); | |||||||||
| 434 | 1 | is_image($im2, $im, "should match original, despite bad mask"); | |||||||||
| 435 | 1 | my $im3 = Imager->new(data => \$data, filetype => "ico", ico_alpha_masked => 1); | |||||||||
| 436 | 1 | ok($im3, "read it back with ico_alpha_masked => 1"); | |||||||||
| 437 | 1 | my $cmp = $im->copy; | |||||||||
| 438 | 1 | $cmp->setpixel(x => 0, y => 0, color => [ 255, 0, 0, 0 ]); | |||||||||
| 439 | 1 | isnt_image($im3, $cmp, "bad mask makes some pixels transparent"); | |||||||||
| 440 | } | ||||||||||