Image/ExifTool/OpenEXR.pm

filter: Statementstmt 61.4% 67 / 109 Branchbran 41.8% 31 / 74 Conditioncond 44.8% 13 / 29 MC/DCmcdc 6.6% 1 / 15 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 50.2% 117 / 233 CC 48 SCAR 58.2
CC
48
Cov
52%
ProcessEXR
363.3
BEGIN
1.0
BEGIN
1.0
CRAP 335.4
« Image/ExifTool/Trailer.pm ↑ Summary Image/ExifTool/IPTC.pm »
1 #------------------------------------------------------------------------------
2 # File: OpenEXR.pm
3 #
4 # Description: Read OpenEXR meta information
5 #
6 # Revisions: 2011/12/10 - P. Harvey Created
7 # 2023/01/31 - PH Added support for multipart images
8 #
9 # References: 1) http://www.openexr.com/
10 #------------------------------------------------------------------------------
11  
12 package Image::ExifTool::OpenEXR;
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 1 ▶use Image::ExifTool::GPS;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 $VERSION = '1.07';
20  
21 # supported EXR value format types (other types are extracted as undef binary data)
22 1 my %formatType = (
23 box2f => 'float[4]',
24 box2i => 'int32s[4]',
25 chlist => 1,
26 chromaticities => 'float[8]',
27 compression => 'int8u',
28 double => 'double',
29 envmap => 'int8u',
30 float => 'float',
31 'int' => 'int32s',
32 keycode => 'int32s[7]',
33 lineOrder => 'int8u',
34 m33f => 'float[9]',
35 m44f => 'float[16]',
36 rational => 'rational64s',
37 string => 'string', # incorrect in specification! (no leading int)
38 stringvector => 1,
39 tiledesc => 1,
40 timecode => 'int32u[2]',
41 v2f => 'float[2]',
42 v2i => 'int32s[2]',
43 v3f => 'float[3]',
44 v3i => 'int32s[3]',
45 );
46  
47 # OpenEXR tags
48 1 %Image::ExifTool::OpenEXR::Main = (
49 GROUPS => { 2 => 'Image' },
50 NOTES => q{
51 Information extracted from EXR images. Use the ExtractEmbedded option to
52 extract information from all frames of a multipart image. See
53 L<http://www.openexr.com/> for the official specification.
54 },
55 _ver => { Name => 'EXRVersion', Notes => 'low byte of Flags word' },
56 _flags => { Name => 'Flags',
57 PrintConv => { BITMASK => {
58 9 => 'Tiled',
59 10 => 'Long names',
60 11 => 'Deep data',
61 12 => 'Multipart',
62 }},
63 },
64 adoptedNeutral => { },
65 altitude => {
66 Name => 'GPSAltitude',
67 Groups => { 2 => 'Location' },
68 PrintConv => q{
69 $val = int($val * 10) / 10;
70 return(($val =~ s/^-// ? "$val m Below" : "$val m Above") . " Sea Level");
71 },
72 },
73 aperture => { PrintConv => 'sprintf("%.1f",$val)' },
74 channels => { },
75 chromaticities => { },
76 capDate => {
77 Name => 'DateTimeOriginal',
78 Description => 'Date/Time Original',
79 Groups => { 2 => 'Time' },
80 PrintConv => '$self->ConvertDateTime($val)',
81 },
82 comments => { },
83 compression => {
84 PrintConvColumns => 2,
85 PrintConv => {
86 0 => 'None',
87 1 => 'RLE',
88 2 => 'ZIPS',
89 3 => 'ZIP',
90 4 => 'PIZ',
91 5 => 'PXR24',
92 6 => 'B44',
93 7 => 'B44A',
94 8 => 'DWAA', #github276
95 9 => 'DWAB', #github276
96 },
97 },
98 dataWindow => { },
99 displayWindow => { },
100 envmap => {
101 Name => 'EnvironmentMap',
102 PrintConv => {
103 0 => 'Latitude/Longitude',
104 1 => 'Cube',
105 },
106 },
107 expTime => {
108 Name => 'ExposureTime',
109 PrintConv => 'Image::ExifTool::Exif::PrintExposureTime($val)',
110 },
111 focus => {
112 Name => 'FocusDistance',
113 PrintConv => '"$val m"',
114 },
115 framesPerSecond => { },
116 keyCode => { },
117 isoSpeed => { Name => 'ISO' },
118 latitude => {
119 Name => 'GPSLatitude',
120 Groups => { 2 => 'Location' },
121 PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "N")',
122 },
123 lineOrder => {
124 PrintConv => {
125 0 => 'Increasing Y',
126 1 => 'Decreasing Y',
127 2 => 'Random Y',
128 },
129 },
130 longitude => {
131 Name => 'GPSLongitude',
132 Groups => { 2 => 'Location' },
133 PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "E")',
134 },
135 lookModTransform => { },
136 multiView => { },
137 owner => { Groups => { 2 => 'Author' } },
138 pixelAspectRatio => { },
139 preview => { Groups => { 2 => 'Preview' } },
140 renderingTransform => { },
141 screenWindowCenter => { },
142 screenWindowWidth => { },
143 tiles => { },
144 timeCode => { },
145 utcOffset => {
146 Name => 'TimeZone',
147 Groups => { 2 => 'Time' },
148 PrintConv => 'TimeZoneString($val / 60)',
149 },
150 whiteLuminance => { },
151 worldToCamera => { },
152 worldToNDC => { },
153 wrapmodes => { Name => 'WrapModes' },
154 xDensity => { Name => 'XResolution' },
155 name => { },
156 type => { },
157 version => { },
158 chunkCount => { },
159 # exif and xmp written by PanoramaStudio4.0.2Pro
160 exif => {
161 Name => 'EXIF',
162 SubDirectory => {
163 TagTable => 'Image::ExifTool::Exif::Main',
164 ProcessProc => \&Image::ExifTool::ProcessTIFF,
165 Start => 4, # (skip leading 4 bytes with data length)
166 },
167 },
168 xmp => {
169 Name => 'XMP',
170 SubDirectory => { TagTable => 'Image::ExifTool::XMP::Main' },
171 },
172 # also observed:
173 # ilut
174 );
175  
176 #------------------------------------------------------------------------------
177 # Extract information from an OpenEXR file
178 # Inputs: 0) ExifTool object reference, 1) DirInfo reference
179 # Returns: 1 on success, 0 if this wasn't a valid OpenEXR file
180 sub ProcessEXR($$)
181 1 ▶{
Subroutine ProcessEXR: called CC=48 SCAR=59.0
Pod undocumented
182 1 my ($et, $dirInfo) = @_;
183 1 my $raf = $$dirInfo{RAF};
184 1 my $verbose = $et->Options('Verbose');
185 1 ▶ my $binary = $et->Options('Binary') || $verbose;
Condition33%1/3
$et->Options('Binary') || $verbose
l!l&&r!l&&!r
001
MC/DC0%0/2
$et->Options('Binary') || $verbose
$et->Options('Binary') $verbose
Truth table33%1/3
A || B
A= $et->Options('Binary')B= $verbose
ABresult
1X1
011
000
186 1 my ($buff, $dim);
187  
188 # verify this is a valid RIFF file
189 1 ▶ return 0 unless $raf->Read($buff, 8) == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 8) == 8 0 1 1
190 1 ▶ return 0 unless $buff =~ /^\x76\x2f\x31\x01/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $buff =~ /^\x76\x2f\x31\x01/s 0 1 1
191 1 $et->SetFileType();
192 1 SetByteOrder('II');
193 1 my $tagTablePtr = GetTagTable('Image::ExifTool::OpenEXR::Main');
194  
195 # extract information from header
196 1 my $flags = unpack('x4V', $buff);
197 1 $et->HandleTag($tagTablePtr, '_ver', $flags & 0xff);
198 1 $et->HandleTag($tagTablePtr, '_flags', $flags & 0xffffff00);
199 1 ▶ my $maxLen = ($flags & 0x400) ? 255 : 31;
Branch: 1 branch
BranchTrueFalseTotal
$flags & 1024 ? : 0 1 1
200 1 my $multi = $flags & 0x1000;
201  
202 # extract attributes
203 1 for (;;) {
204 9 ▶ $raf->Read($buff, ($maxLen + 1) * 2 + 5) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, ($maxLen + 1) * 2 + 5) or last 9 0 9
205 9 ▶ if ($buff =~ /^\0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buff =~ /^\0/) 1 8 9
206 1 ▶ last unless $multi and $et->Options('ExtractEmbedded');
Branch: 1 branch
BranchTrueFalseTotal
unless $multi and $et->Options("ExtractEmbedded") 1 0 1
Condition33%1/3
$multi and $et->Options("ExtractEmbedded")
!ll&&!rl&&r
100
MC/DC0%0/2
$multi and $et->Options("ExtractEmbedded")
$multi $et->Options("ExtractEmbedded")
Truth table33%1/3
A and B
A= $multiB= $et->Options("ExtractEmbedded")
ABresult
0X0
100
111
207 # remove null and process the next frame header as a sub-document
208 # (second null is end of all headers)
209 0 ▶ last if $buff =~ s/^(\0+)// and length($1) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $buff =~ s/^(\0+)// and length $1 > 1 0 0 0
Condition0%0/3
$buff =~ s/^(\0+)// and length $1 > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$buff =~ s/^(\0+)// and length $1 > 1
$buff =~ s/^(\0+)// length $1 > 1
Truth table0%0/3
A and B
A= $buff =~ s/^(\0+)//B= length $1 > 1
ABresult
0X0
100
111
210 0 $$et{DOC_NUM} = ++$$et{DOC_COUNT};
211 }
212 8 ▶ unless ($buff =~ /^([^\0]{1,$maxLen})\0([^\0]{1,$maxLen})\0(.{4})/sg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($buff =~ /^([^\0]{1,$maxLen})\0([^\0]{1,$maxLen})\0(.{4})/gs) 0 8 8
213 0 $et->Warn('EXR format error');
214 0 last;
215 }
216 8 my ($tag, $type, $size) = ($1, $2, unpack('V', $3));
217 8 ▶ unless ($raf->Seek(pos($buff) - length($buff), 1)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Seek(pos($buff) - length($buff), 1)) 0 8 8
218 0 $et->Warn('Seek error');
219 0 last;
220 }
221 8 my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
222 8 ▶ unless ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagInfo) 0 8 8
223 0 my $name = ucfirst $tag;
224 0 $name =~ s/([^a-zA-Z])([a-z])/$1\U$2/g; # capitalize first letter of each word
225 0 $name =~ tr/-_a-zA-Z0-9//dc;
226 0 ▶ if (length $name <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $name <= 1) 0 0 0
227 0 ▶ if (length $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $name) { } 0 0 0
228 0 $name = "Tag$name";
229 } else {
230 0 $name = 'Invalid';
231 }
232 }
233 0 $tagInfo = { Name => $name };
234 0 AddTagToTable($tagTablePtr, $tag, $tagInfo);
235 0 $et->VPrint(0, $$et{INDENT}, "[adding $tag]\n");
236 }
237 8 my ($val, $success, $buf2);
238 8 my $format = $formatType{$type};
239 8 my $subdir = $$tagInfo{SubDirectory};
240 8 ▶ if ($format or $binary or $subdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format or $binary or $subdir) { } 8 0 8
Condition33%2/6
$format or $binary or $subdir
l!l&&r!l&&!r
800
$format or $binary
l!l&&r!l&&!r
800
MC/DC0%0/3
$format or $binary or $subdir
$format $binary $subdir
Truth table25%1/4
A or B or C
A= $formatB= $binaryC= $subdir
ABCresult
1XX1
01X1
0011
0000
241 8 ▶ $raf->Read($buf2, $size) == $size and $success = 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buf2, $size) == $size and $success = 1 8 0 8
242 8 ▶ if ($subdir) {
Branch: 6 branches
BranchTrueFalseTotal
if ($subdir) { } 0 8 8
elsif (not $format) { } 0 8 8
elsif ($format ne '1') { } 7 1 8
elsif ($type eq 'tiledesc') { } 0 1 1
elsif ($type eq 'chlist') { } 1 0 1
elsif ($type eq 'stringvector') { } 0 0 0
243 0 $et->HandleTag($tagTablePtr, $tag, undef,
244 DataPt => \$buf2, DataPos => $raf->Tell() - length($buf2));
245 0 ▶ next if $success;
Branch: 1 branch
BranchTrueFalseTotal
if $success 0 0 0
246 } elsif (not $format) {
247 0 $val = \$buf2; # treat as undef binary data
248 } elsif ($format ne '1') {
249 # handle formats which map nicely into ExifTool format codes
250 7 ▶ if ($format =~ /^(\w+)\[?(\d*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /^(\w+)\[?(\d*)/) 7 0 7
251 7 my ($fmt, $cnt) = ($1, $2);
252 7 ▶ $cnt = $fmt eq 'string' ? $size : 1 unless $cnt;
Branch: 2 branches
BranchTrueFalseTotal
unless $cnt 4 3 7
$fmt eq 'string' ? : 0 4 4
253 7 $val = ReadValue(\$buf2, 0, $fmt, $cnt, $size);
254 }
255 # handle other format types
256 } elsif ($type eq 'tiledesc') {
257 0 ▶ if ($size >= 9) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= 9) 0 0 0
258 0 my $x = Get32u(\$buf2, 0);
259 0 my $y = Get32u(\$buf2, 4);
260 0 my $mode = Get8u(\$buf2, 8);
261 0 my $lvl = { 0 => 'One Level', 1 => 'MIMAP Levels', 2 => 'RIPMAP Levels' }->{$mode & 0x0f};
262 0 ▶ $lvl or $lvl = 'Unknown Levels (' . ($mode & 0xf) . ')';
Branch: 1 branch
BranchTrueFalseTotal
$lvl or $lvl = 'Unknown Levels (' . ($mode & 15) . ')' 0 0 0
263 0 my $rnd = { 0 => 'Round Down', 1 => 'Round Up' }->{$mode >> 4};
264 0 ▶ $rnd or $rnd = 'Unknown Rounding (' . ($mode >> 4) . ')';
Branch: 1 branch
BranchTrueFalseTotal
$rnd or $rnd = 'Unknown Rounding (' . ($mode >> 4) . ')' 0 0 0
265 0 $val = "${x}x$y; $lvl; $rnd";
266 }
267 } elsif ($type eq 'chlist') {
268 1 $val = [ ];
269 1 ▶ while ($buf2 =~ /\G([^\0]{1,31})\0(.{16})/sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf2 =~ /\G([^\0]{1,31})\0(.{16})/gs) 4 1 5
270 4 my ($str, $dat) = ($1, $2);
271 4 my ($pix,$lin,$x,$y) = unpack('VCx3VV', $dat);
272 4 ▶ $pix = { 0 => 'int8u', 1 => 'half', 2 => 'float' }->{$pix} || "unknown($pix)";
Condition50%1/2
{0, 'int8u', 1, 'half', 2, 'float'}->{$pix} || "unknown($pix)"
l!l
40
MC/DC0%0/1
{0, 'int8u', 1, 'half', 2, 'float'}->{$pix} || "unknown($pix)"
{0, 'int8u', 1, 'half', 2, 'float'}->{$pix}
Truth table50%1/2
A
A= {0, 'int8u', 1, 'half', 2, 'float'}->{$pix}
Aresult
11
00
273 4 ▶ push @$val, "$str $pix" . ($lin ? ' linear' : '') . " $x $y";
Branch: 1 branch
BranchTrueFalseTotal
$lin ? : 0 4 4
274 }
275 } elsif ($type eq 'stringvector') {
276 0 $val = [ ];
277 0 my $pos = 0;
278 0 ▶ while ($pos + 4 <= length($buf2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + 4 <= length $buf2) 0 0 0
279 0 my $len = Get32u(\$buf2, $pos);
280 0 ▶ last if $pos + 4 + $len > length($buf2);
Branch: 1 branch
BranchTrueFalseTotal
if $pos + 4 + $len > length $buf2 0 0 0
281 0 push @$val, substr($buf2, $pos + 4, $len);
282 0 $pos += 4 + $len;
283 }
284 } else {
285 0 $val = \$buf2; # (shouldn't happen)
286 }
287 } else {
288 # avoid loading binary data
289 0 $val = \ "Binary data $size bytes";
290 0 $success = $raf->Seek($size, 1);
291 }
292 8 ▶ unless ($success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 8 8
293 0 $et->Warn('Truncated or corrupted EXR file');
294 0 last;
295 }
296 8 ▶ $val = '<bad>' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 8 8
297  
298 # take image dimensions from dataWindow (with displayWindow as backup)
299 8 ▶ if (($tag eq 'dataWindow' or (not $dim and $tag eq 'displayWindow')) and
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "dataWindow" || !$dim && $tag eq "displayWindow" and $val =~ /^(-?\d+) (-?\d+) (-?\d+) (-?\d+)$/ and not $et->{"DOC_NUM"}) 1 7 8
Condition66%8/12
$tag eq "dataWindow" || !$dim && $tag eq "displayWindow" and $val =~ /^(-?\d+) (-?\d+) (-?\d+) (-?\d+)$/ and not $et->{"DOC_NUM"}
!ll&&!rl&&r
701
$tag eq "dataWindow" || !$dim && $tag eq "displayWindow" and $val =~ /^(-?\d+) (-?\d+) (-?\d+) (-?\d+)$/
!ll&&!rl&&r
701
$tag eq "dataWindow" or not $dim and $tag eq "displayWindow"
l!l&&r!l&&!r
107
not $dim and $tag eq "displayWindow"
!ll&&!rl&&r
520
MC/DC20%1/5
$tag eq "dataWindow" || !$dim && $tag eq "displayWindow" and $val =~ /^(-?\d+) (-?\d+) (-?\d+) (-?\d+)$/ and not $et->{"DOC_NUM"}
$tag eq "dataWindow" not $dim $tag eq "displayWindow" $val =~ /^(-?\d+) (-?\d+) (-?\d+) (-?\d+)$/ not $et->{"DOC_NUM"}
Truth table37%3/8
A or not(B) and C and D and not(E)
A= $tag eq "dataWindow"B= not $dimC= $tag eq "displayWindow"D= $val =~ /^(-?\d+) (-?\d+) (-?\d+) (-?\d+)$/E= not $et->{"DOC_NUM"}
ABCDEresult
00XXX0
010XX0
1XX0X0
0110X0
1XX100
011100
1XX111
011111
300 $val =~ /^(-?\d+) (-?\d+) (-?\d+) (-?\d+)$/ and not $$et{DOC_NUM})
301 {
302 1 $dim = [$3 - $1 + 1, $4 - $2 + 1];
303 }
304 8 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 8 8
305 0 ▶ my $dataPt = ref $val eq 'SCALAR' ? $val : \$buf2;
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'SCALAR' ? : 0 0 0
306 0 $et->VerboseInfo($tag, $tagInfo,
307 Table => $tagTablePtr,
308 Value => $val,
309 Size => $size,
310 Format => $type,
311 DataPt => $dataPt,
312 Addr => $raf->Tell() - $size,
313 );
314 }
315 8 $et->FoundTag($tagInfo, $val);
316 }
317 1 delete $$et{DOC_NUM};
318 1 ▶ if ($dim) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dim) 1 0 1
319 1 $et->FoundTag('ImageWidth', $$dim[0]);
320 1 $et->FoundTag('ImageHeight', $$dim[1]);
321 }
322 1 return 1;
323 }
324  
325 1 1; # end
326  
327 __END__
« Image/ExifTool/Trailer.pm ↑ Summary Image/ExifTool/IPTC.pm »