Image/ExifTool/ICO.pm

filter: Statementstmt 100% 29 / 29 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 88.6% 39 / 44 CC 6 SCAR 14.9
CC
6
Cov
90%
ProcessICO
6.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.4
« Image/ExifTool/XISF.pm ↑ Summary Image/ExifTool/DPX.pm »
1 #------------------------------------------------------------------------------
2 # File: ICO.pm
3 #
4 # Description: Read Windows ICO and CUR files
5 #
6 # Revisions: 2020-10-18 - P. Harvey Created
7 #
8 # References: 1) https://docs.fileformat.com/image/ico/
9 #------------------------------------------------------------------------------
10  
11 package Image::ExifTool::ICO;
12  
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 $VERSION = '1.01';
18  
19 1 %Image::ExifTool::ICO::Main = (
20 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
21 GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
22 NOTES => 'Information extracted from Windows ICO (icon) and CUR (cursor) files.',
23 2 => {
24 Name => 'ImageType',
25 Format => 'int16u',
26 PrintConv => { 1 => 'Icon', 2 => 'Cursor' },
27 },
28 4 => {
29 Name => 'ImageCount',
30 Format => 'int16u',
31 RawConv => '$$self{ImageCount} = $val',
32 },
33 6 => {
34 Name => 'IconDir',
35 SubDirectory => { TagTable => 'Image::ExifTool::ICO::IconDir' },
36 },
37 );
38  
39 1 %Image::ExifTool::ICO::IconDir = (
40 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
41 GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
42 0 => {
43 Name => 'ImageWidth',
44 ValueConv => '$val or $val + 256',
45 },
46 1 => {
47 Name => 'ImageHeight',
48 ValueConv => '$val or $val + 256',
49 },
50 2 => 'NumColors',
51 4 => [{
52 Name => 'ColorPlanes',
53 Condition => '$$self{FileType} eq "ICO"',
54 Format => 'int16u',
55 Notes => 'ICO files',
56 },{
57 Name => 'HotspotX',
58 Format => 'int16u',
59 Notes => 'CUR files',
60 }],
61 6 => [{
62 Name => 'BitsPerPixel',
63 Condition => '$$self{FileType} eq "ICO"',
64 Format => 'int16u',
65 Notes => 'ICO files',
66 },{
67 Name => 'HotspotY',
68 Format => 'int16u',
69 Notes => 'CUR files',
70 }],
71 8 => {
72 Name => 'ImageLength',
73 Format => 'int32u',
74 },
75 );
76  
77 #------------------------------------------------------------------------------
78 # Process ICO/CUR file
79 # Inputs: 0) ExifTool ref, 1) dirInfo ref
80 # Returns: 1 on success, 0 if this wasn't a valid ICO/CUR file
81 sub ProcessICO($$$)
82 1 ▶{
Subroutine ProcessICO: called CC=6 SCAR=18.1
Pod undocumented
83 1 my ($et, $dirInfo) = @_;
84 1 my $raf = $$dirInfo{RAF};
85 1 my ($i, $buff);
86 # verify this is a valid ICO/CUR file
87 1 ▶ return 0 unless $raf->Read($buff, 6) == 6;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 6) == 6 0 1 1
88 1 ▶ return 0 unless $buff =~ /^\0\0([\x01\x02])\0[^0]\0/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $buff =~ /^\0\0([\x01\x02])\0[^0]\0/s 0 1 1
89 # (note: have seen cursor files in the wild with an 0x01 here,
90 # but SetFileType will use the .cur extension to identify these)
91 1 ▶ $et->SetFileType($1 eq "\x01" ? 'ICO' : 'CUR');
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "\cA" ? : 1 0 1
92 1 SetByteOrder('II');
93 1 my $tagTbl = GetTagTable('Image::ExifTool::ICO::Main');
94 1 my $num = Get16u(\$buff, 4);
95 1 $et->HandleTag($tagTbl, 4, $num);
96 1 ▶ for ($i=0; $i<$num; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 1 1 2
97 1 ▶ $raf->Read($buff, 16) == 16 or $et->Warn('Truncated file'), last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 16) == 16 or $et->Warn("Truncated file"), last 1 0 1
98 1 $$et{DOC_NUM} = ++$$et{DOC_COUNT};
99 1 $et->HandleTag($tagTbl, 6, $buff);
100 }
101 1 delete $$et{DOC_NUM};
102 1 return 1;
103 }
104  
105 1 1; # end
106  
107 __END__
« Image/ExifTool/XISF.pm ↑ Summary Image/ExifTool/DPX.pm »