Image/ExifTool/MIFF.pm

filter: Statementstmt 73.8% 65 / 88 Branchbran 50.0% 24 / 48 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 63.3% 95 / 150 CC 29 SCAR 42.8
CC
29
Cov
64%
ProcessMIFF
79.8
BEGIN
1.0
BEGIN
1.0
CRAP 72.4
« Image/ExifTool/Pentax.pm ↑ Summary Image/ExifTool/CanonRaw.pm »
1 #------------------------------------------------------------------------------
2 # File: MIFF.pm
3 #
4 # Description: Read Magick Image File Format meta information
5 #
6 # Revisions: 06/10/2005 - P. Harvey Created
7 #
8 # References: 1) http://www.imagemagick.org/script/miff.php
9 # 2) http://www.cs.uni.edu/Help/ImageMagick/www/miff.html
10 #------------------------------------------------------------------------------
11  
12 package Image::ExifTool::MIFF;
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 $VERSION = '1.07';
19  
20 # MIFF chunks
21 1 %Image::ExifTool::MIFF::Main = (
22 GROUPS => { 2 => 'Image' },
23 NOTES => q{
24 The MIFF (Magick Image File Format) format allows aribrary tag names to be
25 used. Only the standard tag names are listed below, however ExifTool will
26 decode any tags found in the image.
27 },
28 'background-color' => 'BackgroundColor',
29 'blue-primary' => 'BluePrimary',
30 'border-color' => 'BorderColor',
31 'matt-color' => 'MattColor',
32 class => 'Class',
33 colors => 'Colors',
34 colorspace => 'ColorSpace',
35 columns => 'ImageWidth',
36 compression => 'Compression',
37 delay => 'Delay',
38 depth => 'Depth',
39 dispose => 'Dispose',
40 gamma => 'Gamma',
41 'green-primary' => 'GreenPrimary',
42 id => 'ID',
43 iterations => 'Iterations',
44 label => 'Label',
45 matte => 'Matte',
46 montage => 'Montage',
47 packets => 'Packets',
48 page => 'Page',
49 # profile tags. Note the SubDirectory is not used by ProcessMIFF(),
50 # but is inserted for documentation purposes only
51 'profile-APP1' => [
52 # [this list is just for the sake of the documentation]
53 {
54 Name => 'APP1_Profile',
55 SubDirectory => {
56 TagTable => 'Image::ExifTool::Exif::Main',
57 },
58 },
59 {
60 Name => 'APP1_Profile',
61 SubDirectory => {
62 TagTable => 'Image::ExifTool::XMP::Main',
63 },
64 },
65 ],
66 'profile-exif' => { # haven't seen this, but it would make sense - PH
67 Name => 'EXIF_Profile',
68 SubDirectory => {
69 TagTable => 'Image::ExifTool::Exif::Main',
70 },
71 },
72 'profile-icc' => {
73 Name => 'ICC_Profile',
74 SubDirectory => {
75 TagTable => 'Image::ExifTool::ICC_Profile::Main',
76 },
77 },
78 'profile-iptc' => {
79 Name => 'IPTC_Profile',
80 SubDirectory => {
81 TagTable => 'Image::ExifTool::Photoshop::Main',
82 },
83 },
84 'profile-xmp' => { # haven't seen this, but it would make sense - PH
85 Name => 'XMP_Profile',
86 SubDirectory => {
87 TagTable => 'Image::ExifTool::XMP::Main',
88 },
89 },
90 'red-primary' => 'RedPrimary',
91 'rendering-intent' => 'RenderingIntent',
92 resolution => 'Resolution',
93 rows => 'ImageHeight',
94 scene => 'Scene',
95 signature => 'Signature',
96 units => 'Units',
97 'white-point' => 'WhitePoint',
98 );
99  
100 #------------------------------------------------------------------------------
101 # Extract meta information from a MIFF image
102 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
103 # Returns: 1 on success, 0 if this wasn't a valid MIFF image
104 sub ProcessMIFF($$)
105 1 ▶{
Subroutine ProcessMIFF: called CC=29 SCAR=43.8
Pod undocumented
106 1 my ($et, $dirInfo) = @_;
107 1 my $raf = $$dirInfo{RAF};
108 1 my $verbose = $$et{OPTIONS}{Verbose};
109 1 my ($hdr, $buff);
110  
111 # validate the MIFF file (note: MIFF files _may_ begin with other
112 # characters, but this starting sequence is strongly suggested.)
113 1 ▶ return 0 unless $raf->Read($hdr, 14) == 14;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($hdr, 14) == 14 0 1 1
114 1 ▶ return 0 unless $hdr eq 'id=ImageMagick';
Branch: 1 branch
BranchTrueFalseTotal
unless $hdr eq "id=ImageMagick" 0 1 1
115 1 $et->SetFileType(); # set the FileType tag
116  
117 # set end-of-line character sequence to read to end of the TEXT
118 # section for new-type MIFF files (text ends with Colon+Ctrl-Z)
119 # Old MIFF files end with Colon+Linefeed, so this will likely
120 # slurp those entire files, which will be slower, but will work
121 # OK except that the profile information won't be decoded
122 1 local $/ = ":\x1a";
123  
124 1 my $mode = '';
125 1 my @profiles;
126 1 ▶ if ($raf->ReadLine($buff)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->ReadLine($buff)) 1 0 1
127 1 chomp $buff; # remove end-of-line chars
128 1 my $tagTablePtr = GetTagTable('Image::ExifTool::MIFF::Main');
129 1 my @entries = split ' ', $buff;
130 1 unshift @entries, $hdr; # put the ID back in
131 1 my ($tag, $val);
132 1 foreach (@entries) {
133 11 ▶ if ($mode eq 'com') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'com') { } 0 11 11
elsif (/^\{/) { } 0 11 11
134 0 ▶ $mode = '' if /\}$/;
Branch: 1 branch
BranchTrueFalseTotal
if /\}$/ 0 0 0
135 0 next;
136 } elsif (/^\{/) {
137 0 $mode = 'com'; # read to the end of the comment
138 0 next;
139 }
140 11 ▶ if ($mode eq 'val') {
Branch: 3 branches
BranchTrueFalseTotal
if ($mode eq 'val') { } 0 11 11
elsif (/(.+)=(.+)/) { } 11 0 11
elsif (/^:/) { } 0 0 0
141 0 $val .= " $_"; # join back together with a space
142 0 ▶ next unless /\}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\}$/ 0 0 0
143 0 $mode = '';
144 0 $val =~ s/(^\{|\}$)//g; # remove braces
145 } elsif (/(.+)=(.+)/) {
146 11 ($tag, $val) = ($1, $2);
147 11 ▶ if ($val =~ /^\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^\{/) 0 11 11
148 0 $mode = 'val'; # read to the end of the value data
149 0 next;
150 }
151 } elsif (/^:/) {
152 # this could be the end of an old-style MIFF file
153 0 last;
154 } else {
155 # something we don't recognize -- stop parsing here
156 0 $et->Warn('Unrecognized MIFF data');
157 0 last;
158 }
159 11 my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
160 11 ▶ unless ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagInfo) 1 10 11
161 1 $tagInfo = { Name => $tag };
162 1 AddTagToTable($tagTablePtr, $tag, $tagInfo);
163 }
164 11 ▶ $verbose and $et->VerboseInfo($tag, $tagInfo,
Branch: 1 branch
BranchTrueFalseTotal
$verbose and $et->VerboseInfo($tag, $tagInfo, "Table", $tagTablePtr, "DataPt", \$val) 0 11 11
165 Table => $tagTablePtr,
166 DataPt => \$val,
167 );
168 # handle profile tags specially
169 11 ▶ if ($tag =~ /^profile-(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^profile-(.*)/) { } 3 8 11
170 3 push @profiles, [$1, $val];
171 } else {
172 8 $et->FoundTag($tagInfo, $val);
173 }
174 }
175 }
176  
177 # process profile information
178 1 foreach (@profiles) {
179 3 my ($type, $len) = @{$_};
180 3 ▶ unless ($len =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($len =~ /^\d+$/) 0 3 3
181 0 $et->Warn("Invalid length for $type profile");
182 0 last; # don't try to read the rest
183 }
184 3 ▶ unless ($raf->Read($buff, $len) == $len) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Read($buff, $len) == $len) 0 3 3
185 0 $et->Warn("Error reading $type profile ($len bytes)");
186 0 next;
187 }
188 3 my $processed = 0;
189 3 my %dirInfo = (
190 Parent => 'PNG',
191 DataPt => \$buff,
192 DataPos => $raf->Tell() - $len,
193 DataLen => $len,
194 DirStart => 0,
195 DirLen => $len,
196 );
197 3 ▶ if ($type eq 'icc') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'icc') { } 0 3 3
elsif ($type eq 'iptc') { } 1 2 3
elsif ($type eq 'APP1' or $type eq 'exif' or $type eq 'xmp') { } 2 0 2
198 # ICC Profile information
199 0 my $tagTablePtr = GetTagTable('Image::ExifTool::ICC_Profile::Main');
200 0 $processed = $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
201 } elsif ($type eq 'iptc') {
202 1 ▶ if ($buff =~ /^8BIM/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buff =~ /^8BIM/) 1 0 1
203 # Photoshop information
204 1 my $tagTablePtr = GetTagTable('Image::ExifTool::Photoshop::Main');
205 1 $processed = $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
206 }
207 # I haven't seen 'exif' or 'xmp' profile types yet, but I have seen them
208 # in newer PNG files so presumably they are possible here as well - PH
209 ▶ } elsif ($type eq 'APP1' or $type eq 'exif' or $type eq 'xmp') {
Condition33%2/6
$type eq "APP1" or $type eq "exif" or $type eq "xmp"
l!l&&r!l&&!r
200
$type eq "APP1" or $type eq "exif"
l!l&&r!l&&!r
200
MC/DC0%0/3
$type eq "APP1" or $type eq "exif" or $type eq "xmp"
$type eq "APP1" $type eq "exif" $type eq "xmp"
Truth table25%1/4
A or B or C
A= $type eq "APP1"B= $type eq "exif"C= $type eq "xmp"
ABCresult
1XX1
01X1
0011
0000
210 2 ▶ if ($buff =~ /^$Image::ExifTool::exifAPP1hdr/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($buff =~ /^$Image::ExifTool::exifAPP1hdr/) { } 1 1 2
elsif ($buff =~ /^$Image::ExifTool::xmpAPP1hdr/) { } 1 0 1
211 # APP1 EXIF
212 1 my $hdrLen = length($Image::ExifTool::exifAPP1hdr);
213 1 $dirInfo{DirStart} += $hdrLen;
214 1 $dirInfo{DirLen} -= $hdrLen;
215 # use the usual position for EXIF data: 12 bytes from start of file
216 # (this may be wrong, but I can't see where the PNG stores this information)
217 1 $dirInfo{Base} = 12; # this is the usual value
218 1 $processed = $et->ProcessTIFF(\%dirInfo);
219 } elsif ($buff =~ /^$Image::ExifTool::xmpAPP1hdr/) {
220 # APP1 XMP
221 1 my $hdrLen = length($Image::ExifTool::xmpAPP1hdr);
222 1 my $tagTablePtr = GetTagTable('Image::ExifTool::XMP::Main');
223 1 $dirInfo{DirStart} += $hdrLen;
224 1 $dirInfo{DirLen} -= $hdrLen;
225 1 $processed = $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
226 }
227 }
228 3 ▶ unless ($processed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($processed) 0 3 3
229 0 $et->Warn("Unknown MIFF $type profile data");
230 0 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
231 0 $et->VerboseDir($type, 0, $len);
232 0 $et->VerboseDump(\$buff);
233 }
234 }
235 }
236 1 return 1;
237 }
238  
239 1 1; # end
240  
241 __END__
« Image/ExifTool/Pentax.pm ↑ Summary Image/ExifTool/CanonRaw.pm »