| 1 | package Image::Info::ICO; | ||
| 2 | $VERSION = '0.02'; | ||
| 3 | |||
| 4 | # Copyright (C) 2009 Slaven Rezic. All rights reserved. | ||
| 5 | # This package is free software; you can redistribute it and/or | ||
| 6 | # modify it under the same terms as Perl itself. | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | |||
| 10 | sub process_file { | ||
| 11 | my($info, $fh) = @_; | ||
| 12 | |||
| 13 | my $buf; | ||
| 14 | if (read($fh, $buf, 6) != 6) { | ||
| 15 | $info->push_info(0, 'error' => 'Short read (expected at least 6 bytes)'); | ||
| 16 | return; | ||
| 17 | } | ||
| 18 | |||
| 19 | $info->push_info(0, 'file_media_type' => 'image/x-icon'); # XXX or is there already an official vnd format? | ||
| 20 | $info->push_info(0, 'file_ext' => 'ico'); | ||
| 21 | |||
| 22 | my($no_icons) = unpack('v', substr($buf, 4, 2)); | ||
| 23 | |||
| 24 | for my $img_no (0 .. $no_icons-1) { | ||
| 25 | if (read($fh, $buf, 16) != 16) { | ||
| 26 | $info->push_info(0, 'error' => "Short read while getting information for image at index $img_no"); | ||
| 27 | return; | ||
| 28 | } | ||
| 29 | my($width, | ||
| 30 | $height, | ||
| 31 | $colors, | ||
| 32 | undef, # reserved | ||
| 33 | undef, # $planes | ||
| 34 | undef, # $bitcount | ||
| 35 | undef, # $size_in_bytes | ||
| 36 | undef, # $file_offset | ||
| 37 | ) = unpack('CCCCvvVV', $buf); | ||
| 38 | if ($colors == 0) { $colors = 256 } | ||
| 39 | |||
| 40 | $info->push_info($img_no, 'width', $width); | ||
| 41 | $info->push_info($img_no, 'height', $height); | ||
| 42 | $info->push_info($img_no, 'color_type', 'Indexed-RGB'); | ||
| 43 | $info->push_info($img_no, 'colors', $colors); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | 1; | ||
| 48 | |||
| 49 | __END__ |