1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#------------------------------------------------------------------------------
# File: ICO.pm
#
# Description: Read Windows ICO and CUR files
#
# Revisions: 2020-10-18 - P. Harvey Created
#
# References: 1) https://docs.fileformat.com/image/ico/
#------------------------------------------------------------------------------
package Image::ExifTool::ICO;
use strict;
use vars qw($VERSION);
use Image::ExifTool qw(:DataAccess :Utils);
$VERSION = '1.00';
%Image::ExifTool::ICO::Main = (
PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
NOTES => 'Information extracted from Windows ICO (icon) and CUR (cursor) files.',
2 => {
Name => 'ImageType',
Format => 'int16u',
PrintConv => { 1 => 'Icon', 2 => 'Cursor' },
},
4 => {
Name => 'ImageCount',
Format => 'int16u',
RawConv => '$$self{ImageCount} = $val',
},
6 => {
Name => 'IconDir',
SubDirectory => { TagTable => 'Image::ExifTool::ICO::IconDir' },
},
);
%Image::ExifTool::ICO::IconDir = (
PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
0 => {
Name => 'ImageWidth',
ValueConv => '$val or $val + 256',
},
1 => {
Name => 'ImageHeight',
ValueConv => '$val or $val + 256',
},
2 => 'NumColors',
4 => [{
Name => 'ColorPlanes',
Condition => '$$self{FileType} eq "ICO"',
Format => 'int16u',
Notes => 'ICO files',
},{
Name => 'HotspotX',
Format => 'int16u',
Notes => 'CUR files',
}],
6 => [{
Name => 'BitsPerPixel',
Condition => '$$self{FileType} eq "ICO"',
Format => 'int16u',
Notes => 'ICO files',
},{
Name => 'HotspotY',
Format => 'int16u',
Notes => 'CUR files',
}],
8 => {
Name => 'ImageLength',
Format => 'int32u',
},
);
#------------------------------------------------------------------------------
# Process ICO/CUR file
# Inputs: 0) ExifTool ref, 1) dirInfo ref
# Returns: 1 on success, 0 if this wasn't a valid ICO/CUR file
sub ProcessICO($$$)
{
my ($et, $dirInfo) = @_;
my $raf = $$dirInfo{RAF};
my ($i, $buff);
# verify this is a valid ICO/CUR file
return 0 unless $raf->Read($buff, 6) == 6;
return 0 unless $buff =~ /^\0\0([\x01\x02])\0[^0]\0/s;
# (note: have seen cursor files in the wild with an 0x01 here,
# but SetFileType will use the .cur extension to identify these)
$et->SetFileType($1 eq "\x01" ? 'ICO' : 'CUR');
SetByteOrder('II');
my $tagTbl = GetTagTable('Image::ExifTool::ICO::Main');
my $num = Get16u(\$buff, 4);
$et->HandleTag($tagTbl, 4, $num);
for ($i=0; $i<$num; ++$i) {
$raf->Read($buff, 16) == 16 or $et->Warn('Truncated file'), last;
$$et{DOC_NUM} = ++$$et{DOC_COUNT} if $i;
$et->HandleTag($tagTbl, 6, $buff);
}
delete $$et{DOC_NUM};
return 1;
}
1; # end
__END__
=head1 NAME
Image::ExifTool::ICO - Read ICO meta information
=head1 SYNOPSIS
This module is used by Image::ExifTool
=head1 DESCRIPTION
This module contains definitions required by Image::ExifTool to read
information from Windows ICO (icon) and CUR (cursor) files.
=head1 AUTHOR
Copyright 2003-2023, Phil Harvey (philharvey66 at gmail.com)
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 REFERENCES
=over 4
=item L<https://docs.fileformat.com/image/ico/>
=back
=head1 SEE ALSO
L<Image::ExifTool::TagNames/ICO Tags>,
L<Image::ExifTool(3pm)|Image::ExifTool>
=cut
|