Image/ExifTool/WriteExif.pl

filter: Statementstmt 68.2% 1008 / 1477 Branchbran 58.0% 605 / 1042 Conditioncond 49.7% 433 / 870 MC/DCmcdc 27.4% 129 / 470 Subroutinesub 61.1% 11 / 18 Podpod 0.0% 0 / 15 totaltotal 56.1% 2186 / 3892 CC 842 SCAR 98.6
CC
842
Cov
60%
WriteExif
22867.6
ValidateIFD
272.0
AddImageDataHash
240.0
CRAP 19078.6
« Image/ExifTool/BuildTagLookup.pm ↑ Summary Image/ExifTool/WriteQuickTime.pl »
1 #------------------------------------------------------------------------------
2 # File: WriteExif.pl
3 #
4 # Description: Write EXIF meta information
5 #
6 # Revisions: 12/13/2004 - P. Harvey Created
7 #------------------------------------------------------------------------------
8  
9 package Image::ExifTool::Exif;
10  
11 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 42 ▶use vars qw($VERSION $AUTOLOAD @formatSize @formatName %formatNumber
Subroutine BEGIN: called CC=1 SCAR=0.0
13 42 %compression %photometricInterpretation %orientation);
14  
15 42 ▶use Image::ExifTool::Fixup;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # some information may be stored in different IFD's with the same meaning.
18 # Use this lookup to decide when we should delete information that is stored
19 # in another IFD when we write it to the preferred IFD.
20 42 my %crossDelete = (
21 ExifIFD => 'IFD0',
22 IFD0 => 'ExifIFD',
23 );
24  
25 # mandatory tag default values
26 42 my %mandatory = (
27 IFD0 => {
28 # (optional as of 3.0) 0x011a => 72, # XResolution
29 # (optional as of 3.0) 0x011b => 72, # YResolution
30 # (optional as of 3.0) 0x0128 => 2, # ResolutionUnit (inches)
31 0x0213 => 1, # YCbCrPositioning (centered)
32 # 0x8769 => ????, # ExifOffset
33 },
34 IFD1 => {
35 0x0103 => 6, # Compression (JPEG)
36 0x011a => 72, # XResolution
37 0x011b => 72, # YResolution
38 0x0128 => 2, # ResolutionUnit (inches)
39 },
40 ExifIFD => {
41 0x9000 => '0232', # ExifVersion
42 0x9101 => "1 2 3 0",# ComponentsConfiguration
43 # (optional as of 3.0) 0xa000 => '0100', # FlashpixVersion
44 0xa001 => 0xffff, # ColorSpace (uncalibrated)
45 # 0xa002 => ????, # ExifImageWidth
46 # 0xa003 => ????, # ExifImageHeight
47 },
48 GPS => {
49 0x0000 => '2 3 0 0',# GPSVersionID
50 },
51 InteropIFD => {
52 0x0002 => '0100', # InteropVersion (from the DCF spec, not the EXIF spec)
53 },
54 );
55  
56 #------------------------------------------------------------------------------
57 # Inverse print conversion for OffsetTime tags
58 # Inputs: 0) input time zone or date/time value, 1) ExifTool ref
59 # Returns: Time zone string for writing to EXIF
60 sub InverseOffsetTime($$)
61 0 ▶{
Subroutine InverseOffsetTime: not called CC=4 SCAR=30.0
Pod undocumented
62 0 my ($val, $et) = @_;
63 0 ▶ $val = $et->TimeNow() if lc($val) eq 'now';
Branch: 1 branch
BranchTrueFalseTotal
if lc $val eq "now" 0 0 0
64 0 ▶ return '+00:00' if $val =~ /Z$/;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /Z$/ 0 0 0
65 0 ▶ return sprintf('%s%.2d:%.2d',$1,$2,$3) if $val =~ /([-+])(\d{1,2}):?(\d{2})/;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /([-+])(\d{1,2}):?(\d{2})/ 0 0 0
66 0 return undef;
67 }
68  
69 #------------------------------------------------------------------------------
70 # Inverse print conversion for LensInfo
71 # Inputs: 0) lens info string
72 # Returns: PrintConvInv of string
73 sub ConvertLensInfo($)
74 7 ▶{
Subroutine ConvertLensInfo: called CC=2 SCAR=6.9
Pod undocumented
75 7 my $val = shift;
76 7 my @a = GetLensInfo($val, 1); # (allow unknown "?" values)
77 7 ▶ return @a ? join(' ', @a) : $val;
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 1 6 7
78 }
79  
80 #------------------------------------------------------------------------------
81 # Get binary CFA Pattern from a text string
82 # Inputs: Print-converted CFA pattern (eg. '[Blue,Green][Green,Red]')
83 # Returns: CFA pattern as a string of numbers
84 sub GetCFAPattern($)
85 1 ▶{
Subroutine GetCFAPattern: called CC=7 SCAR=19.7
Pod undocumented
86 1 my $val = shift;
87 1 my @rows = split /\]\s*\[/, $val;
88 1 ▶ @rows or warn("Rows not properly bracketed by '[]'\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
@rows or warn("Rows not properly bracketed by '[]'\n"), (return undef) 1 0 1
89 1 my @cols = split /,/, $rows[0];
90 1 ▶ @cols or warn("Colors not separated by ','\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
@cols or warn("Colors not separated by ','\n"), (return undef) 1 0 1
91 1 my $ny = @cols;
92 1 my @a = (scalar(@rows), scalar(@cols));
93 1 my %cfaLookup = (red=>0, green=>1, blue=>2, cyan=>3, magenta=>4, yellow=>5, white=>6);
94 1 my $row;
95 1 foreach $row (@rows) {
96 2 @cols = split /,/, $row;
97 2 ▶ @cols == $ny or warn("Inconsistent number of colors in each row\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
@cols == $ny or warn("Inconsistent number of colors in each row\n"), (return undef) 2 0 2
98 2 foreach (@cols) {
99 4 tr/ \]\[//d; # remove remaining brackets and any spaces
100 4 my $c = $cfaLookup{lc($_)};
101 4 ▶ defined $c or warn("Unknown color '${_}'\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $c or warn("Unknown color '${_}'\n"), (return undef) 4 0 4
102 4 push @a, $c;
103 }
104 }
105 1 return "@a";
106 }
107  
108 #------------------------------------------------------------------------------
109 # validate raw values for writing
110 # Inputs: 0) ExifTool ref, 1) tagInfo hash ref, 2) raw value ref
111 # Returns: error string or undef (and possibly changes value) on success
112 sub CheckExif($$$)
113 6343 ▶{
Subroutine CheckExif: called CC=6 SCAR=18.4
Pod undocumented
114 6343 my ($et, $tagInfo, $valPtr) = @_;
115 6343 ▶ my $format = $$tagInfo{Format} || $$tagInfo{Writable} || $$tagInfo{Table}{WRITABLE};
Condition83%5/6
$tagInfo->{'Format'} || $tagInfo->{'Writable'} || $tagInfo->{'Table'}{'WRITABLE'}
l!l&&r!l&&!r
59234200
$tagInfo->{"Format"} or $tagInfo->{"Writable"}
l!l&&r!l&&!r
4305493420
MC/DC0%0/3
$tagInfo->{'Format'} || $tagInfo->{'Writable'} || $tagInfo->{'Table'}{'WRITABLE'}
$tagInfo->{"Format"} $tagInfo->{"Writable"} $tagInfo->{'Table'}{'WRITABLE'}
Truth table75%3/4
A or B || C
A= $tagInfo->{"Format"}B= $tagInfo->{"Writable"}C= $tagInfo->{'Table'}{'WRITABLE'}
ABCresult
1XX1
01X1
0011
0000
116 6343 ▶ if (not $format or $format eq '1') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $format or $format eq 1) 129 6214 6343
Condition66%2/3
not $format or $format eq 1
l!l&&r!l&&!r
01296214
MC/DC50%1/2
not $format or $format eq 1
not $format $format eq 1
Truth table66%2/3
not(A) or B
A= not $formatB= $format eq 1
ABresult
1X1
011
000
117 129 ▶ if ($$tagInfo{Groups}{0} eq 'MakerNotes') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'Groups'}{'0'} eq 'MakerNotes') { } 129 0 129
118 129 return undef; # OK to have no format for makernotes
119 } else {
120 0 return 'No writable format';
121 }
122 }
123 6214 return Image::ExifTool::CheckValue($valPtr, $format, $$tagInfo{Count});
124 }
125  
126 #------------------------------------------------------------------------------
127 # encode exif ASCII/Unicode text from UTF8 or Latin
128 # Inputs: 0) ExifTool ref, 1) text string
129 # Returns: encoded string
130 # Note: MUST be called Raw conversion time so the EXIF byte order is known!
131 sub EncodeExifText($$)
132 13 ▶{
Subroutine EncodeExifText: called CC=2 SCAR=8.4
Pod undocumented
133 13 my ($et, $val) = @_;
134 # does the string contain special characters?
135 13 ▶ if ($val =~ /[\x80-\xff]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /[\x80-\xff]/) { } 0 13 13
136 0 my $order = $et->GetNewValue('ExifUnicodeByteOrder');
137 0 return "UNICODE\0" . $et->Encode($val,'UTF16',$order);
138 } else {
139 13 return "ASCII\0\0\0$val";
140 }
141 }
142  
143 #------------------------------------------------------------------------------
144 # rebuild maker notes to properly contain all value data
145 # (some manufacturers put value data outside maker notes!!)
146 # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
147 # Returns: new maker note data (and creates MAKER_NOTE_FIXUP), or undef on error
148 sub RebuildMakerNotes($$$)
149 23 ▶{
Subroutine RebuildMakerNotes: called CC=21 SCAR=34.6
Pod undocumented
150 23 my ($et, $dirInfo, $tagTablePtr) = @_;
151 23 my $dirStart = $$dirInfo{DirStart};
152 23 my $dirLen = $$dirInfo{DirLen};
153 23 my $dataPt = $$dirInfo{DataPt};
154 23 ▶ my $dataPos = $$dirInfo{DataPos} || 0;
Condition100%2/2
$dirInfo->{'DataPos'} || 0
l!l
221
MC/DC100%1/1
$dirInfo->{'DataPos'} || 0
$dirInfo->{'DataPos'}
Truth table100%2/2
A
A= $dirInfo->{'DataPos'}
Aresult
11
00
155 23 my $rtnValue;
156 23 my %subdirInfo = %$dirInfo;
157  
158 23 delete $$et{MAKER_NOTE_FIXUP};
159  
160 # don't need to rebuild text, BinaryData or PreviewImage maker notes
161 23 my $tagInfo = $$dirInfo{TagInfo};
162 23 my $subdir = $$tagInfo{SubDirectory};
163 23 ▶ my $proc = $$subdir{ProcessProc} || $$tagTablePtr{PROCESS_PROC} || \&ProcessExif;
Condition100%5/5
$subdir->{'ProcessProc'} || $tagTablePtr->{'PROCESS_PROC'} || \&Image::ExifTool::Exif::ProcessExif
l!l
167
$subdir->{"ProcessProc"} or $tagTablePtr->{"PROCESS_PROC"}
l!l&&r!l&&!r
1067
MC/DC100%2/2
$subdir->{'ProcessProc'} || $tagTablePtr->{'PROCESS_PROC'} || \&Image::ExifTool::Exif::ProcessExif
$subdir->{"ProcessProc"} $tagTablePtr->{"PROCESS_PROC"}
Truth table100%3/3
A or B
A= $subdir->{"ProcessProc"}B= $tagTablePtr->{"PROCESS_PROC"}
ABresult
1X1
011
000
164 23 ▶ if (($proc ne \&ProcessExif and $$tagInfo{Name} =~ /Text/) or
Branch: 1 branch
BranchTrueFalseTotal
if ($proc ne \&Image::ExifTool::Exif::ProcessExif and $tagInfo->{"Name"} =~ /Text/ or $proc eq \&Image::ExifTool::ProcessBinaryData or $tagInfo->{"PossiblePreview"} and $dirLen > 6 and substr($$dataPt, $dirStart, 3) eq "\377\330\377") 0 23 23
Condition40%6/15
$proc ne \&Image::ExifTool::Exif::ProcessExif and $tagInfo->{"Name"} =~ /Text/ or $proc eq \&Image::ExifTool::ProcessBinaryData or $tagInfo->{"PossiblePreview"} and $dirLen > 6 and substr($$dataPt, $dirStart, 3) eq "\377\330\377"
l!l&&r!l&&!r
0023
$proc ne \&Image::ExifTool::Exif::ProcessExif and $tagInfo->{"Name"} =~ /Text/ or $proc eq \&Image::ExifTool::ProcessBinaryData
l!l&&r!l&&!r
0023
$proc ne \&Image::ExifTool::Exif::ProcessExif and $tagInfo->{"Name"} =~ /Text/
!ll&&!rl&&r
7160
$tagInfo->{"PossiblePreview"} and $dirLen > 6 and substr($$dataPt, $dirStart, 3) eq "\377\330\377"
!ll&&!rl&&r
2300
$tagInfo->{"PossiblePreview"} and $dirLen > 6
!ll&&!rl&&r
2300
MC/DC0%0/6
$proc ne \&Image::ExifTool::Exif::ProcessExif and $tagInfo->{"Name"} =~ /Text/ or $proc eq \&Image::ExifTool::ProcessBinaryData or $tagInfo->{"PossiblePreview"} and $dirLen > 6 and substr($$dataPt, $dirStart, 3) eq "\377\330\377"
$proc ne \&Image::ExifTool::Exif::ProcessExif $tagInfo->{"Name"} =~ /Text/ $proc eq \&Image::ExifTool::ProcessBinaryData $tagInfo->{"PossiblePreview"} $dirLen > 6 substr($$dataPt, $dirStart, 3) eq "\377\330\377"
Truth table18%2/11
A and B or C or D and E and F
A= $proc ne \&Image::ExifTool::Exif::ProcessExifB= $tagInfo->{"Name"} =~ /Text/C= $proc eq \&Image::ExifTool::ProcessBinaryDataD= $tagInfo->{"PossiblePreview"}E= $dirLen > 6F= substr($$dataPt, $dirStart, 3) eq "\377\330\377"
ABCDEFresult
11XXXX1
0X1XXX1
101XXX1
0X01111
1001111
0X00XX0
0X010X0
0X01100
1000XX0
10010X0
1001100
165 $proc eq \&Image::ExifTool::ProcessBinaryData or
166 ($$tagInfo{PossiblePreview} and $dirLen > 6 and
167 substr($$dataPt, $dirStart, 3) eq "\xff\xd8\xff"))
168 {
169 0 return substr($$dataPt, $dirStart, $dirLen);
170 }
171 23 my $saveOrder = GetByteOrder();
172 23 my $loc = Image::ExifTool::MakerNotes::LocateIFD($et,\%subdirInfo);
173 23 ▶ if (defined $loc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $loc) 23 0 23
174 23 my $makerFixup = $subdirInfo{Fixup} = Image::ExifTool::Fixup->new;
175 # create new exiftool object to rewrite the directory without changing it
176 23 my $newTool = Image::ExifTool->new;
177 $newTool->Options(
178 IgnoreMinorErrors => $$et{OPTIONS}{IgnoreMinorErrors},
179 FixBase => $$et{OPTIONS}{FixBase},
180 23 );
181 23 $newTool->Init(); # must do this before calling WriteDirectory()!
182 # don't copy over preview image
183 23 $newTool->SetNewValue(PreviewImage => '');
184 # copy all transient members over in case they are used for writing
185 # (Make, Model, etc)
186 23 foreach (grep /[a-z]/, keys %$et) {
187 284 $$newTool{$_} = $$et{$_};
188 }
189 # fix base offsets if specified
190 23 $newTool->Options(FixBase => $et->Options('FixBase'));
191 # set GENERATE_PREVIEW_INFO flag so PREVIEW_INFO will be generated
192 23 $$newTool{GENERATE_PREVIEW_INFO} = 1;
193 # drop any large tags
194 23 $$newTool{DropTags} = 1;
195 # initialize other necessary data members
196 23 $$newTool{FILE_TYPE} = $$et{FILE_TYPE};
197 23 $$newTool{TIFF_TYPE} = $$et{TIFF_TYPE};
198 # rewrite maker notes
199 23 $rtnValue = $newTool->WriteDirectory(\%subdirInfo, $tagTablePtr);
200 23 ▶ if (defined $rtnValue and length $rtnValue) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rtnValue and length $rtnValue) 23 0 23
Condition33%1/3
defined $rtnValue and length $rtnValue
!ll&&!rl&&r
0023
MC/DC0%0/2
defined $rtnValue and length $rtnValue
defined $rtnValue length $rtnValue
Truth table33%1/3
A and B
A= defined $rtnValueB= length $rtnValue
ABresult
0X0
100
111
201 # add the dummy/empty preview image if necessary
202 23 ▶ if ($$newTool{PREVIEW_INFO}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newTool->{"PREVIEW_INFO"}) 0 23 23
203 0 $makerFixup->SetMarkerPointers(\$rtnValue, 'PreviewImage', length($rtnValue));
204 0 $rtnValue .= $$newTool{PREVIEW_INFO}{Data};
205 0 delete $$newTool{PREVIEW_INFO};
206 }
207 # add makernote header
208 23 ▶ if ($loc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loc) 9 14 23
209 9 my $hdr = substr($$dataPt, $dirStart, $loc);
210 # special case: convert Pentax/Samsung DNG maker notes to JPEG style
211 # (in JPEG, Pentax makernotes are absolute and start with "AOC\0" for some
212 # models, but in DNG images they are stored in tag 0xc634 of IFD0 and
213 # start with either "PENTAX \0" or "SAMSUNG\0")
214 9 ▶ if ($$dirInfo{Parent} eq 'IFD0' and $hdr =~ /^(PENTAX |SAMSUNG)\0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirInfo->{"Parent"} eq "IFD0" and $hdr =~ /^(PENTAX |SAMSUNG)\0/) 0 9 9
Condition33%1/3
$dirInfo->{"Parent"} eq "IFD0" and $hdr =~ /^(PENTAX |SAMSUNG)\0/
!ll&&!rl&&r
900
MC/DC0%0/2
$dirInfo->{"Parent"} eq "IFD0" and $hdr =~ /^(PENTAX |SAMSUNG)\0/
$dirInfo->{"Parent"} eq "IFD0" $hdr =~ /^(PENTAX |SAMSUNG)\0/
Truth table33%1/3
A and B
A= $dirInfo->{"Parent"} eq "IFD0"B= $hdr =~ /^(PENTAX |SAMSUNG)\0/
ABresult
0X0
100
111
215 # convert to JPEG-style AOC maker notes if used by this model
216 # (Note: this expression also appears in Exif.pm)
217 0 ▶ if ($$et{Model} =~ /\b(K(-[57mrx]|(10|20|100|110|200)D|2000)|GX(10|20))\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"Model"} =~ /\b(K(-[57mrx]|(10|20|100|110|200)D|2000)|GX(10|20))\b/) 0 0 0
218 0 $hdr =~ s/^(PENTAX |SAMSUNG)\0/AOC\0/;
219 # save fixup because AOC maker notes have absolute offsets
220 0 $$et{MAKER_NOTE_FIXUP} = $makerFixup;
221 }
222 }
223 9 $rtnValue = $hdr . $rtnValue;
224 # adjust fixup for shift in start position
225 9 $$makerFixup{Start} += length $hdr;
226 }
227 # shift offsets according to original position of maker notes,
228 # and relative to the makernotes Base
229 $$makerFixup{Shift} += $dataPos + $dirStart +
230 23 $$dirInfo{Base} - $subdirInfo{Base};
231 # repair incorrect offsets if offsets were fixed
232 23 ▶ $$makerFixup{Shift} += $subdirInfo{FixedBy} || 0;
Condition50%1/2
$subdirInfo{'FixedBy'} || 0
l!l
023
MC/DC0%0/1
$subdirInfo{'FixedBy'} || 0
$subdirInfo{'FixedBy'}
Truth table50%1/2
A
A= $subdirInfo{'FixedBy'}
Aresult
11
00
233 # fix up pointers to the specified offset
234 23 $makerFixup->ApplyFixup(\$rtnValue);
235 # save fixup information unless offsets were relative
236 23 ▶ unless ($subdirInfo{Relative}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subdirInfo{"Relative"}) 19 4 23
237 # set shift so offsets are all relative to start of maker notes
238 19 $$makerFixup{Shift} -= $dataPos + $dirStart;
239 19 $$et{MAKER_NOTE_FIXUP} = $makerFixup; # save fixup for later
240 }
241 }
242 }
243 23 SetByteOrder($saveOrder);
244  
245 23 return $rtnValue;
246 }
247  
248 #------------------------------------------------------------------------------
249 # Sort IFD directory entries
250 # Inputs: 0) data reference, 1) directory start, 2) number of entries,
251 # 3) flag to treat 0 as a valid tag ID (as opposed to an empty IFD entry)
252 sub SortIFD($$$;$)
253 0 ▶{
Subroutine SortIFD: not called CC=7 SCAR=40.3
Pod undocumented
254 0 my ($dataPt, $dirStart, $numEntries, $allowZero) = @_;
255 0 my ($index, %entries);
256 # split the directory into separate entries
257 0 ▶ for ($index=0; $index<$numEntries; ++$index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < $numEntries) 0 0 0
258 0 my $entry = $dirStart + 2 + 12 * $index;
259 0 my $tagID = Get16u($dataPt, $entry);
260 0 my $entryData = substr($$dataPt, $entry, 12);
261 # silly software can pad directories with zero entries -- put these at the end
262 0 ▶ $tagID = 0x10000 unless $tagID or $index == 0 or $allowZero;
Branch: 1 branch
BranchTrueFalseTotal
unless $tagID or $index == 0 or $allowZero 0 0 0
Condition0%0/6
$tagID or $index == 0 or $allowZero
l!l&&r!l&&!r
000
$tagID or $index == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
$tagID or $index == 0 or $allowZero
$tagID $index == 0 $allowZero
Truth table0%0/4
A or B or C
A= $tagIDB= $index == 0C= $allowZero
ABCresult
1XX1
01X1
0011
0000
263 # add new entry (allow for duplicate tag ID's, which shouldn't normally happen)
264 0 ▶ if ($entries{$tagID}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entries{$tagID}) { } 0 0 0
265 0 $entries{$tagID} .= $entryData;
266 } else {
267 0 $entries{$tagID} = $entryData;
268 }
269 }
270 # sort the directory entries
271 0 my @sortedTags = sort { $a <=> $b } keys %entries;
272 # generate the sorted IFD
273 0 my $newDir = '';
274 0 foreach (@sortedTags) {
275 0 $newDir .= $entries{$_};
276 }
277 # replace original directory with new, sorted one
278 0 substr($$dataPt, $dirStart + 2, 12 * $numEntries) = $newDir;
279 }
280  
281 #------------------------------------------------------------------------------
282 # Validate IFD entries (strict validation to test possible chained IFD's)
283 # Inputs: 0) dirInfo ref (must have RAF set), 1) optional DirStart
284 # Returns: true if IFD looks OK
285 sub ValidateIFD($;$)
286 0 ▶{
Subroutine ValidateIFD: not called CC=16 SCAR=56.1
Pod undocumented
287 0 my ($dirInfo, $dirStart) = @_;
288 0 ▶ my $raf = $$dirInfo{RAF} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $raf = $dirInfo->{"RAF"} or return 0 0 0 0
289 0 my $base = $$dirInfo{Base};
290 0 ▶ $dirStart = $$dirInfo{DirStart} || 0 unless defined $dirStart;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dirStart 0 0 0
Condition0%0/2
$dirInfo->{'DirStart'} || 0
l!l
00
MC/DC0%0/1
$dirInfo->{'DirStart'} || 0
$dirInfo->{'DirStart'}
Truth table0%0/2
A
A= $dirInfo->{'DirStart'}
Aresult
11
00
291 0 ▶ my $offset = $dirStart + ($$dirInfo{DataPos} || 0);
Condition0%0/2
$dirInfo->{'DataPos'} || 0
l!l
00
MC/DC0%0/1
$dirInfo->{'DataPos'} || 0
$dirInfo->{'DataPos'}
Truth table0%0/2
A
A= $dirInfo->{'DataPos'}
Aresult
11
00
292 0 my ($buff, $index);
293 0 ▶ $raf->Seek($offset + $base, 0) and $raf->Read($buff,2) == 2 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($offset + $base, 0) and $raf->Read($buff, 2) == 2 or return 0 0 0 0
Condition0%0/3
$raf->Seek($offset + $base, 0) and $raf->Read($buff, 2) == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$raf->Seek($offset + $base, 0) and $raf->Read($buff, 2) == 2
$raf->Seek($offset + $base, 0) $raf->Read($buff, 2) == 2
Truth table0%0/3
A and B
A= $raf->Seek($offset + $base, 0)B= $raf->Read($buff, 2) == 2
ABresult
0X0
100
111
294 0 my $numEntries = Get16u(\$buff,0);
295 0 ▶ $numEntries > 1 and $numEntries < 64 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$numEntries > 1 and $numEntries < 64 or return 0 0 0 0
Condition0%0/3
$numEntries > 1 and $numEntries < 64
!ll&&!rl&&r
000
MC/DC0%0/2
$numEntries > 1 and $numEntries < 64
$numEntries > 1 $numEntries < 64
Truth table0%0/3
A and B
A= $numEntries > 1B= $numEntries < 64
ABresult
0X0
100
111
296 0 my $len = 12 * $numEntries;
297 0 ▶ $raf->Read($buff, $len) == $len or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $len) == $len or return 0 0 0 0
298 0 my $lastID = -1;
299 0 ▶ for ($index=0; $index<$numEntries; ++$index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < $numEntries) 0 0 0
300 0 my $entry = 12 * $index;
301 0 my $tagID = Get16u(\$buff, $entry);
302 0 ▶ $tagID > $lastID or $$dirInfo{AllowOutOfOrderTags} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$tagID > $lastID or $dirInfo->{"AllowOutOfOrderTags"} or return 0 0 0 0
Condition0%0/3
$tagID > $lastID or $dirInfo->{"AllowOutOfOrderTags"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tagID > $lastID or $dirInfo->{"AllowOutOfOrderTags"}
$tagID > $lastID $dirInfo->{"AllowOutOfOrderTags"}
Truth table0%0/3
A or B
A= $tagID > $lastIDB= $dirInfo->{"AllowOutOfOrderTags"}
ABresult
1X1
011
000
303 0 my $format = Get16u(\$buff, $entry+2);
304 0 ▶ $format > 0 and $format <= 13 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$format > 0 and $format <= 13 or return 0 0 0 0
Condition0%0/3
$format > 0 and $format <= 13
!ll&&!rl&&r
000
MC/DC0%0/2
$format > 0 and $format <= 13
$format > 0 $format <= 13
Truth table0%0/3
A and B
A= $format > 0B= $format <= 13
ABresult
0X0
100
111
305 0 my $count = Get32u(\$buff, $entry+4);
306 0 ▶ $count > 0 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$count > 0 or return 0 0 0 0
307 0 $lastID = $tagID;
308 }
309 0 return 1;
310 }
311  
312 #------------------------------------------------------------------------------
313 # Get sorted list of offsets used in IFD
314 # Inputs: 0) data ref, 1) directory start, 2) dataPos, 3) IFD entries, 4) tag table ref
315 # Returns: 0) sorted list of offsets (only offsets after the end of the IFD)
316 # 1) hash of list indices keyed by offset value
317 # Notes: This is used in a patch to fix the count for tags in Kodak SubIFD3
318 sub GetOffList($$$$$)
319 0 ▶{
Subroutine GetOffList: not called CC=9 SCAR=45.0
Pod undocumented
320 0 my ($dataPt, $dirStart, $dataPos, $numEntries, $tagTablePtr) = @_;
321 0 my $ifdEnd = $dirStart + 2 + 12 * $numEntries + $dataPos;
322 0 my ($index, $offset, %offHash);
323 0 ▶ for ($index=0; $index<$numEntries; ++$index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < $numEntries) 0 0 0
324 0 my $entry = $dirStart + 2 + 12 * $index;
325 0 my $format = Get16u($dataPt, $entry + 2);
326 0 ▶ next if $format < 1 or $format > 13;
Branch: 1 branch
BranchTrueFalseTotal
if $format < 1 or $format > 13 0 0 0
Condition0%0/3
$format < 1 or $format > 13
l!l&&r!l&&!r
000
MC/DC0%0/2
$format < 1 or $format > 13
$format < 1 $format > 13
Truth table0%0/3
A or B
A= $format < 1B= $format > 13
ABresult
1X1
011
000
327 0 my $count = Get16u($dataPt, $entry + 4);
328 0 my $size = $formatSize[$format] * $count;
329 0 ▶ if ($size <= 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size <= 4) 0 0 0
330 0 my $tagID = Get16u($dataPt, $entry);
331 0 ▶ next unless ref $$tagTablePtr{$tagID} eq 'HASH' and $$tagTablePtr{$tagID}{FixCount};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tagTablePtr->{$tagID} eq "HASH" and $tagTablePtr->{$tagID}{"FixCount"} 0 0 0
Condition0%0/3
ref $tagTablePtr->{$tagID} eq "HASH" and $tagTablePtr->{$tagID}{"FixCount"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $tagTablePtr->{$tagID} eq "HASH" and $tagTablePtr->{$tagID}{"FixCount"}
ref $tagTablePtr->{$tagID} eq "HASH" $tagTablePtr->{$tagID}{"FixCount"}
Truth table0%0/3
A and B
A= ref $tagTablePtr->{$tagID} eq "HASH"B= $tagTablePtr->{$tagID}{"FixCount"}
ABresult
0X0
100
111
332 }
333 0 my $offset = Get16u($dataPt, $entry + 8);
334 0 ▶ $offHash{$offset} = 1 if $offset >= $ifdEnd;
Branch: 1 branch
BranchTrueFalseTotal
if $offset >= $ifdEnd 0 0 0
335 }
336 # set offset hash values to indices in list
337 0 my @offList = sort keys %offHash;
338 0 $index = 0;
339 0 foreach $offset (@offList) {
340 0 $offHash{$offset} = $index++;
341 }
342 0 return(\@offList, \%offHash);
343 }
344  
345 #------------------------------------------------------------------------------
346 # Update TIFF_END member if defined
347 # Inputs: 0) ExifTool ref, 1) end of valid TIFF data
348 sub UpdateTiffEnd($$)
349 332 ▶{
Subroutine UpdateTiffEnd: called CC=3 SCAR=11.0
Pod undocumented
350 332 my ($et, $end) = @_;
351 332 ▶ if (defined $$et{TIFF_END} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $et->{"TIFF_END"} and $et->{"TIFF_END"} < $end) 278 54 332
Condition100%3/3
defined $et->{"TIFF_END"} and $et->{"TIFF_END"} < $end
!ll&&!rl&&r
1539278
MC/DC100%2/2
defined $et->{"TIFF_END"} and $et->{"TIFF_END"} < $end
defined $et->{"TIFF_END"} $et->{"TIFF_END"} < $end
Truth table100%3/3
A and B
A= defined $et->{"TIFF_END"}B= $et->{"TIFF_END"} < $end
ABresult
0X0
100
111
352 $$et{TIFF_END} < $end)
353 {
354 278 $$et{TIFF_END} = $end;
355 }
356 }
357  
358 #------------------------------------------------------------------------------
359 # Validate image data size
360 # Inputs: 0) ExifTool ref, 1) validate info hash ref,
361 # 2) flag to issue error (ie. we're writing)
362 # - issues warning or error if problems found
363 sub ValidateImageData($$$;$)
364 85 ▶{
Subroutine ValidateImageData: called CC=28 SCAR=45.0
Pod undocumented
365 85 local $_;
366 85 my ($et, $vInfo, $dirName, $errFlag) = @_;
367  
368 # determine the expected size of the image data for an uncompressed image
369 # (0x102 BitsPerSample, 0x103 Compression and 0x115 SamplesPerPixel
370 # all default to a value of 1 if they don't exist)
371 85 ▶ if ((not defined $$vInfo{0x103} or $$vInfo{0x103} eq '1') and
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($vInfo->{259}) || $vInfo->{259} eq 1 and $vInfo->{256} and $vInfo->{257} and $vInfo->{279} || $vInfo->{325}) 5 80 85
Condition86%13/15
!defined($vInfo->{259}) || $vInfo->{259} eq 1 and $vInfo->{256} and $vInfo->{257} and $vInfo->{279} || $vInfo->{325}
!ll&&!rl&&r
7915
!defined($vInfo->{259}) || $vInfo->{259} eq 1 and $vInfo->{256} and $vInfo->{257}
!ll&&!rl&&r
7906
!defined($vInfo->{259}) || $vInfo->{259} eq 1 and $vInfo->{256}
!ll&&!rl&&r
63166
not defined $vInfo->{259} or $vInfo->{259} eq 1
l!l&&r!l&&!r
16663
$vInfo->{279} or $vInfo->{325}
l!l&&r!l&&!r
501
MC/DC33%2/6
!defined($vInfo->{259}) || $vInfo->{259} eq 1 and $vInfo->{256} and $vInfo->{257} and $vInfo->{279} || $vInfo->{325}
not defined $vInfo->{259} $vInfo->{259} eq 1 $vInfo->{256} $vInfo->{257} $vInfo->{279} $vInfo->{325}
Truth table36%4/11
not(A) or B and C and D and E or F
A= not defined $vInfo->{259}B= $vInfo->{259} eq 1C= $vInfo->{256}D= $vInfo->{257}E= $vInfo->{279}F= $vInfo->{325}
ABCDEFresult
00XXXX0
1X0XXX0
010XXX0
1X10XX0
0110XX0
1X11000
0111000
1X111X1
1X11011
01111X1
0111011
372 $$vInfo{0x100} and $$vInfo{0x101} and ($$vInfo{0x117} or $$vInfo{0x145}))
373 {
374 5 ▶ my $samplesPerPix = $$vInfo{0x115} || 1;
Condition100%2/2
$vInfo->{'277'} || 1
l!l
41
MC/DC100%1/1
$vInfo->{'277'} || 1
$vInfo->{'277'}
Truth table100%2/2
A
A= $vInfo->{'277'}
Aresult
11
00
375 5 ▶ my @bitsPerSample = $$vInfo{0x102} ? split(' ',$$vInfo{0x102}) : (1) x $samplesPerPix;
Branch: 1 branch
BranchTrueFalseTotal
$vInfo->{'258'} ? : 5 0 5
376 5 ▶ my $byteCountInfo = $$vInfo{0x117} || $$vInfo{0x145};
Condition33%1/3
$vInfo->{'279'} || $vInfo->{'325'}
l!l&&r!l&&!r
500
MC/DC0%0/2
$vInfo->{'279'} || $vInfo->{'325'}
$vInfo->{'279'} $vInfo->{'325'}
Truth table33%1/3
A || B
A= $vInfo->{'279'}B= $vInfo->{'325'}
ABresult
1X1
011
000
377 5 my $byteCounts = $$byteCountInfo[1];
378 5 my $totalBytes = 0;
379 5 $totalBytes += $_ foreach split ' ', $byteCounts;
380 5 my $minor;
381 5 ▶ $minor = 1 if $$et{DOC_NUM} or $$et{FILE_TYPE} ne 'TIFF';
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"DOC_NUM"} or $et->{"FILE_TYPE"} ne "TIFF" 0 5 5
Condition33%1/3
$et->{"DOC_NUM"} or $et->{"FILE_TYPE"} ne "TIFF"
l!l&&r!l&&!r
005
MC/DC0%0/2
$et->{"DOC_NUM"} or $et->{"FILE_TYPE"} ne "TIFF"
$et->{"DOC_NUM"} $et->{"FILE_TYPE"} ne "TIFF"
Truth table33%1/3
A or B
A= $et->{"DOC_NUM"}B= $et->{"FILE_TYPE"} ne "TIFF"
ABresult
1X1
011
000
382 5 ▶ unless (@bitsPerSample == $samplesPerPix) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@bitsPerSample == $samplesPerPix) 0 5 5
383 0 ▶ unless ($$et{FILE_TYPE} eq 'EPS' and @bitsPerSample == 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($et->{"FILE_TYPE"} eq "EPS" and @bitsPerSample == 1) 0 0 0
Condition0%0/3
$et->{"FILE_TYPE"} eq "EPS" and @bitsPerSample == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$et->{"FILE_TYPE"} eq "EPS" and @bitsPerSample == 1
$et->{"FILE_TYPE"} eq "EPS" @bitsPerSample == 1
Truth table0%0/3
A and B
A= $et->{"FILE_TYPE"} eq "EPS"B= @bitsPerSample == 1
ABresult
0X0
100
111
384 # (just a warning for this problem)
385 0 ▶ my $s = $samplesPerPix eq '1' ? '' : 's';
Branch: 1 branch
BranchTrueFalseTotal
$samplesPerPix eq '1' ? : 0 0 0
386 0 $et->Warn("$dirName BitsPerSample should have $samplesPerPix value$s", $minor);
387 }
388 0 ▶ push @bitsPerSample, $bitsPerSample[0] while @bitsPerSample < $samplesPerPix;
Branch: 1 branch
BranchTrueFalseTotal
@bitsPerSample < $samplesPerPix and do { push @bitsPerSample, $bitsPerSample[0] } 0 0 0
389 0 foreach (@bitsPerSample) {
390 0 ▶ $et->Warn("$dirName BitsPerSample values are different", $minor) if $_ ne $bitsPerSample[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_ ne $bitsPerSample[0] 0 0 0
391 0 ▶ $et->Warn("Invalid $dirName BitsPerSample value", $minor) if $_ < 1 or $_ > 32;
Branch: 1 branch
BranchTrueFalseTotal
if $_ < 1 or $_ > 32 0 0 0
Condition0%0/3
$_ < 1 or $_ > 32
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ < 1 or $_ > 32
$_ < 1 $_ > 32
Truth table0%0/3
A or B
A= $_ < 1B= $_ > 32
ABresult
1X1
011
000
392 }
393 }
394 5 my $bitsPerPixel = 0;
395 5 $bitsPerPixel += $_ foreach @bitsPerSample;
396 5 my $expectedBytes = int(($$vInfo{0x100} * $$vInfo{0x101} * $bitsPerPixel + 7) / 8);
397 5 ▶ if ($expectedBytes != $totalBytes and
Branch: 1 branch
BranchTrueFalseTotal
if ($expectedBytes != $totalBytes and not $et->{"TIFF_TYPE"} =~ /^(K25|KDC|MEF|ORF|SRF)$/) 1 4 5
Condition66%2/3
$expectedBytes != $totalBytes and not $et->{"TIFF_TYPE"} =~ /^(K25|KDC|MEF|ORF|SRF)$/
!ll&&!rl&&r
401
MC/DC50%1/2
$expectedBytes != $totalBytes and not $et->{"TIFF_TYPE"} =~ /^(K25|KDC|MEF|ORF|SRF)$/
$expectedBytes != $totalBytes not $et->{"TIFF_TYPE"} =~ /^(K25|KDC|MEF|ORF|SRF)$/
Truth table66%2/3
A and not(B)
A= $expectedBytes != $totalBytesB= not $et->{"TIFF_TYPE"} =~ /^(K25|KDC|MEF|ORF|SRF)$/
ABresult
0X0
100
111
398 # (this problem seems normal for certain types of RAW files...)
399 $$et{TIFF_TYPE} !~ /^(K25|KDC|MEF|ORF|SRF)$/)
400 {
401 1 my ($adj, $minor);
402 1 ▶ if ($expectedBytes > $totalBytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expectedBytes > $totalBytes) { } 1 0 1
403 1 $adj = 'Under'; # undersized is a bigger problem because we may lose data
404 1 ▶ $minor = 0 unless $errFlag;
Branch: 1 branch
BranchTrueFalseTotal
unless $errFlag 0 1 1
405 } else {
406 0 $adj = 'Over';
407 0 $minor = 1;
408 }
409 1 my $msg = "${adj}sized $dirName $$byteCountInfo[0]{Name} ($totalBytes bytes, but expected $expectedBytes)";
410 1 ▶ if (not defined $minor) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $minor) { } 1 0 1
411 # this is a serious error if we are writing the file and there
412 # is a chance that we may not copy all of the image data
413 # (but make it minor to allow the file to be written anyway)
414 1 $et->Error($msg, 1);
415 } else {
416 0 $et->Warn($msg, $minor);
417 }
418 }
419 }
420 }
421  
422 #------------------------------------------------------------------------------
423 # Add specified image data to ImageDataHash hash
424 # Inputs: 0) ExifTool ref, 1) dirInfo ref, 2) lookup for [tagInfo,value] based on tagID
425 sub AddImageDataHash($$$)
426 0 ▶{
Subroutine AddImageDataHash: not called CC=15 SCAR=54.8
Pod undocumented
427 0 my ($et, $dirInfo, $offsetInfo) = @_;
428 0 my ($tagID, $offset, $buff);
429  
430 0 my $verbose = $et->Options('Verbose');
431 0 my $hash = $$et{ImageDataHash};
432 0 my $raf = $$dirInfo{RAF};
433  
434 0 foreach $tagID (sort keys %$offsetInfo) {
435 0 ▶ next unless ref $$offsetInfo{$tagID} eq 'ARRAY'; # ignore scalar tag values used for Validate
Branch: 1 branch
BranchTrueFalseTotal
unless ref $offsetInfo->{$tagID} eq "ARRAY" 0 0 0
436 0 my $tagInfo = $$offsetInfo{$tagID}[0];
437 0 ▶ next unless $$tagInfo{IsImageData}; # only consider image data
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo->{"IsImageData"} 0 0 0
438 0 my $sizeID = $$tagInfo{OffsetPair};
439 0 my @sizes;
440 0 ▶ if ($$tagInfo{NotRealPair}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagInfo->{'NotRealPair'}) { } 0 0 0
elsif ($sizeID and $offsetInfo->{$sizeID}) { } 0 0 0
441 0 @sizes = 999999999; # (Panasonic hack: raw data runs to end of file)
442 ▶ } elsif ($sizeID and $$offsetInfo{$sizeID}) {
Condition0%0/3
$sizeID and $offsetInfo->{$sizeID}
!ll&&!rl&&r
000
MC/DC0%0/2
$sizeID and $offsetInfo->{$sizeID}
$sizeID $offsetInfo->{$sizeID}
Truth table0%0/3
A and B
A= $sizeIDB= $offsetInfo->{$sizeID}
ABresult
0X0
100
111
443 0 @sizes = split ' ', $$offsetInfo{$sizeID}[1];
444 } else {
445 0 next;
446 }
447 0 my @offsets = split ' ', $$offsetInfo{$tagID}[1];
448 0 ▶ $sizes[0] = 999999999 if $$tagInfo{NotRealPair};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"NotRealPair"} 0 0 0
449 0 my $total = 0;
450 0 foreach $offset (@offsets) {
451 0 my $size = shift @sizes;
452 0 ▶ next unless $offset =~ /^\d+$/ and $size and $size =~ /^\d+$/ and $size;
Branch: 1 branch
BranchTrueFalseTotal
unless $offset =~ /^\d+$/ and $size and $size =~ /^\d+$/ and $size 0 0 0
Condition0%0/9
$offset =~ /^\d+$/ and $size and $size =~ /^\d+$/ and $size
!ll&&!rl&&r
000
$offset =~ /^\d+$/ and $size and $size =~ /^\d+$/
!ll&&!rl&&r
000
$offset =~ /^\d+$/ and $size
!ll&&!rl&&r
000
MC/DC0%0/4
$offset =~ /^\d+$/ and $size and $size =~ /^\d+$/ and $size
$offset =~ /^\d+$/ $size $size =~ /^\d+$/ $size
Truth table0%0/5
A and B and C and D
A= $offset =~ /^\d+$/B= $sizeC= $size =~ /^\d+$/D= $size
ABCDresult
0XXX0
10XX0
110X0
11100
11111
453 0 ▶ next unless $raf->Seek($offset, 0); # (offset is absolute)
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Seek($offset, 0) 0 0 0
454 0 $total += $et->ImageDataHash($raf, $size);
455 }
456 0 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
457 0 my $name = "$$dirInfo{DirName}:$$tagInfo{Name}";
458 0 $name =~ s/Offsets?|Start$//;
459 0 $et->VPrint(0, "$$et{INDENT}(ImageDataHash: $total bytes of $name data)\n");
460 }
461 }
462 }
463  
464 #------------------------------------------------------------------------------
465 # Handle error while writing EXIF
466 # Inputs: 0) ExifTool ref, 1) error string, 2) tag table ref
467 # Returns: undef on fatal error, or '' if minor error is ignored
468 sub ExifErr($$$)
469 0 ▶{
Subroutine ExifErr: not called CC=7 SCAR=40.3
Pod undocumented
470 0 my ($et, $errStr, $tagTablePtr) = @_;
471 # MakerNote errors are minor by default
472 0 ▶ my $minor = ($$tagTablePtr{GROUPS}{0} eq 'MakerNotes' or $$et{FILE_TYPE} eq 'MOV');
Condition0%0/3
$tagTablePtr->{'GROUPS'}{'0'} eq 'MakerNotes' || $et->{'FILE_TYPE'} eq 'MOV'
l!l&&r!l&&!r
000
MC/DC0%0/2
$tagTablePtr->{'GROUPS'}{'0'} eq 'MakerNotes' || $et->{'FILE_TYPE'} eq 'MOV'
$tagTablePtr->{'GROUPS'}{'0'} eq 'MakerNotes' $et->{'FILE_TYPE'} eq 'MOV'
Truth table0%0/3
A || B
A= $tagTablePtr->{'GROUPS'}{'0'} eq 'MakerNotes'B= $et->{'FILE_TYPE'} eq 'MOV'
ABresult
1X1
011
000
473 0 ▶ if ($$tagTablePtr{VARS} and $$tagTablePtr{VARS}{MINOR_ERRORS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagTablePtr->{"VARS"} and $tagTablePtr->{"VARS"}{"MINOR_ERRORS"}) 0 0 0
Condition0%0/3
$tagTablePtr->{"VARS"} and $tagTablePtr->{"VARS"}{"MINOR_ERRORS"}
!ll&&!rl&&r
000
MC/DC0%0/2
$tagTablePtr->{"VARS"} and $tagTablePtr->{"VARS"}{"MINOR_ERRORS"}
$tagTablePtr->{"VARS"} $tagTablePtr->{"VARS"}{"MINOR_ERRORS"}
Truth table0%0/3
A and B
A= $tagTablePtr->{"VARS"}B= $tagTablePtr->{"VARS"}{"MINOR_ERRORS"}
ABresult
0X0
100
111
474 0 ▶ $et->Warn("$errStr. IFD dropped.") and return '' if $minor;
Branch: 1 branch
BranchTrueFalseTotal
if $minor 0 0 0
Condition0%0/5
$minor && ($et->Warn("$errStr. IFD dropped.") && (return ''))
!ll&&!rl&&r
000
$et->Warn("$errStr. IFD dropped.") and return ""
!ll
00
MC/DC0%0/2
$minor && ($et->Warn("$errStr. IFD dropped.") && (return ''))
$minor $et->Warn("$errStr. IFD dropped.")
Truth table0%0/3
A && B
A= $minorB= $et->Warn("$errStr. IFD dropped.")
ABresult
0X0
100
111
475 0 $minor = 1;
476 }
477 0 ▶ return undef if $et->Error($errStr, $minor);
Branch: 1 branch
BranchTrueFalseTotal
if $et->Error($errStr, $minor) 0 0 0
478 0 return '';
479 }
480  
481 #------------------------------------------------------------------------------
482 # Read/Write IFD with TIFF-like header (used by DNG 1.2)
483 # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
484 # Returns: Reading: 1 on success, otherwise returns 0 and sets a Warning
485 # Writing: new data block or undef on error
486 sub ProcessTiffIFD($$$)
487 0 ▶{
Subroutine ProcessTiffIFD: not called CC=13 SCAR=52.0
Pod undocumented
488 0 my ($et, $dirInfo, $tagTablePtr) = @_;
489 0 ▶ $et or return 1; # allow dummy access
Branch: 1 branch
BranchTrueFalseTotal
$et or return 1 0 0 0
490 0 my $raf = $$dirInfo{RAF};
491 0 ▶ my $base = $$dirInfo{Base} || 0;
Condition0%0/2
$dirInfo->{'Base'} || 0
l!l
00
MC/DC0%0/1
$dirInfo->{'Base'} || 0
$dirInfo->{'Base'}
Truth table0%0/2
A
A= $dirInfo->{'Base'}
Aresult
11
00
492 0 my $dirName = $$dirInfo{DirName};
493 0 ▶ my $magic = $$dirInfo{Subdir}{Magic} || 0x002a;
Condition0%0/2
$dirInfo->{'Subdir'}{'Magic'} || 42
l!l
00
MC/DC0%0/1
$dirInfo->{'Subdir'}{'Magic'} || 42
$dirInfo->{'Subdir'}{'Magic'}
Truth table0%0/2
A
A= $dirInfo->{'Subdir'}{'Magic'}
Aresult
11
00
494 0 my $buff;
495  
496 # structured with a TIFF-like header and relative offsets
497 0 ▶ $raf->Seek($base, 0) and $raf->Read($buff, 8) == 8 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($base, 0) and $raf->Read($buff, 8) == 8 or return 0 0 0 0
Condition0%0/3
$raf->Seek($base, 0) and $raf->Read($buff, 8) == 8
!ll&&!rl&&r
000
MC/DC0%0/2
$raf->Seek($base, 0) and $raf->Read($buff, 8) == 8
$raf->Seek($base, 0) $raf->Read($buff, 8) == 8
Truth table0%0/3
A and B
A= $raf->Seek($base, 0)B= $raf->Read($buff, 8) == 8
ABresult
0X0
100
111
498 0 ▶ unless (SetByteOrder(substr($buff,0,2)) and Get16u(\$buff, 2) == $magic) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&SetByteOrder(substr($buff, 0, 2)) and &Get16u(\$buff, 2) == $magic) 0 0 0
Condition0%0/3
&SetByteOrder(substr($buff, 0, 2)) and &Get16u(\$buff, 2) == $magic
!ll&&!rl&&r
000
MC/DC0%0/2
&SetByteOrder(substr($buff, 0, 2)) and &Get16u(\$buff, 2) == $magic
&SetByteOrder(substr($buff, 0, 2)) &Get16u(\$buff, 2) == $magic
Truth table0%0/3
A and B
A= &SetByteOrder(substr($buff, 0, 2))B= &Get16u(\$buff, 2) == $magic
ABresult
0X0
100
111
499 0 my $msg = "Invalid $dirName header";
500 0 ▶ if ($$dirInfo{IsWriting}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirInfo->{'IsWriting'}) { } 0 0 0
501 0 $et->Error($msg);
502 0 return undef;
503 } else {
504 0 $et->Warn($msg);
505 0 return 0;
506 }
507 }
508 0 my $offset = Get32u(\$buff, 4);
509 my %dirInfo = (
510 DirName => $$dirInfo{DirName},
511 Parent => $$dirInfo{Parent},
512 0 Base => $base,
513 DataPt => \$buff,
514 DataLen => length $buff,
515 DataPos => 0,
516 DirStart => $offset,
517 DirLen => length($buff) - $offset,
518 RAF => $raf,
519 NewDataPos => 8,
520 );
521 0 ▶ if ($$dirInfo{IsWriting}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirInfo->{"IsWriting"}) 0 0 0
522 # rewrite the Camera Profile IFD
523 0 my $newDir = WriteExif($et, \%dirInfo, $tagTablePtr);
524 # don't add header if error writing directory ($newDir is undef)
525 # or if directory is being deleted ($newDir is empty)
526 0 ▶ return $newDir unless $newDir;
Branch: 1 branch
BranchTrueFalseTotal
unless $newDir 0 0 0
527 # return directory with TIFF-like header
528 0 return GetByteOrder() . Set16u($magic) . Set32u(8) . $newDir;
529 }
530 0 ▶ if ($$et{HTML_DUMP}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"HTML_DUMP"}) 0 0 0
531 0 ▶ my $tip = sprintf("Byte order: %s endian\nIdentifier: 0x%.4x\n%s offset: 0x%.4x",
Branch: 1 branch
BranchTrueFalseTotal
&GetByteOrder() eq 'II' ? : 0 0 0
532 (GetByteOrder() eq 'II') ? 'Little' : 'Big', $magic, $dirName, $offset);
533 0 $et->HDump($base, 8, "$dirName header", $tip, 0);
534 }
535 0 return ProcessExif($et, \%dirInfo, $tagTablePtr);
536 }
537  
538 #------------------------------------------------------------------------------
539 # Write EXIF directory
540 # Inputs: 0) ExifTool object ref, 1) source dirInfo ref, 2) tag table ref
541 # Returns: Exif data block (may be empty if no Exif data) or undef on error
542 # Notes: Increments ExifTool CHANGED flag for each tag changed. Also updates
543 # TIFF_END if defined with location of end of original TIFF image.
544 # Returns IFD data in the following order:
545 # 1. IFD0 directory followed by its data
546 # 2. SubIFD directory followed by its data, thumbnail and image
547 # 3. GlobalParameters, EXIF, GPS, Interop IFD's each with their data
548 # 4. IFD1,IFD2,... directories each followed by their data
549 # 5. Thumbnail and/or image data for each IFD, with IFD0 image last
550 sub WriteExif($$$)
551 8715 ▶{
Subroutine WriteExif: called CC=716 SCAR=100.4
Pod undocumented
552 8715 my ($et, $dirInfo, $tagTablePtr) = @_;
553 8715 ▶ $et or return 1; # allow dummy access to autoload this package
Branch: 1 branch
BranchTrueFalseTotal
$et or return 1 335 8380 8715
554 335 my $origDirInfo = $dirInfo; # save original dirInfo
555 335 my $dataPt = $$dirInfo{DataPt};
556 335 ▶ unless ($dataPt) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataPt) 36 299 335
557 36 my $emptyData = '';
558 36 $dataPt = \$emptyData;
559 }
560 335 ▶ my $dataPos = $$dirInfo{DataPos} || 0;
Condition100%2/2
$dirInfo->{'DataPos'} || 0
l!l
39296
MC/DC100%1/1
$dirInfo->{'DataPos'} || 0
$dirInfo->{'DataPos'}
Truth table100%2/2
A
A= $dirInfo->{'DataPos'}
Aresult
11
00
561 335 ▶ my $dirStart = $$dirInfo{DirStart} || 0;
Condition100%2/2
$dirInfo->{'DirStart'} || 0
l!l
28847
MC/DC100%1/1
$dirInfo->{'DirStart'} || 0
$dirInfo->{'DirStart'}
Truth table100%2/2
A
A= $dirInfo->{'DirStart'}
Aresult
11
00
562 335 ▶ my $dataLen = $$dirInfo{DataLen} || length($$dataPt);
Condition66%2/3
$dirInfo->{'DataLen'} || length $$dataPt
l!l&&r!l&&!r
278057
MC/DC50%1/2
$dirInfo->{'DataLen'} || length $$dataPt
$dirInfo->{'DataLen'} length $$dataPt
Truth table66%2/3
A || B
A= $dirInfo->{'DataLen'}B= length $$dataPt
ABresult
1X1
011
000
563 335 ▶ my $dirLen = $$dirInfo{DirLen} || ($dataLen - $dirStart);
Condition100%3/3
$dirInfo->{'DirLen'} || $dataLen - $dirStart
l!l&&r!l&&!r
13410794
MC/DC100%2/2
$dirInfo->{'DirLen'} || $dataLen - $dirStart
$dirInfo->{'DirLen'} $dataLen - $dirStart
Truth table100%3/3
A || B
A= $dirInfo->{'DirLen'}B= $dataLen - $dirStart
ABresult
1X1
011
000
564 335 ▶ my $base = $$dirInfo{Base} || 0;
Condition100%2/2
$dirInfo->{'Base'} || 0
l!l
213122
MC/DC100%1/1
$dirInfo->{'Base'} || 0
$dirInfo->{'Base'}
Truth table100%2/2
A
A= $dirInfo->{'Base'}
Aresult
11
00
565 335 my $firstBase = $base;
566 335 my $raf = $$dirInfo{RAF};
567 335 ▶ my $dirName = $$dirInfo{DirName} || 'unknown';
Condition50%1/2
$dirInfo->{'DirName'} || 'unknown'
l!l
3350
MC/DC0%0/1
$dirInfo->{'DirName'} || 'unknown'
$dirInfo->{'DirName'}
Truth table50%1/2
A
A= $dirInfo->{'DirName'}
Aresult
11
00
568 335 ▶ my $fixup = $$dirInfo{Fixup} || Image::ExifTool::Fixup->new;
Condition66%2/3
$dirInfo->{'Fixup'} || 'Image::ExifTool::Fixup'->new
l!l&&r!l&&!r
2091260
MC/DC0%0/2
$dirInfo->{'Fixup'} || 'Image::ExifTool::Fixup'->new
$dirInfo->{'Fixup'} 'Image::ExifTool::Fixup'->new
Truth table66%2/3
A || B
A= $dirInfo->{'Fixup'}B= 'Image::ExifTool::Fixup'->new
ABresult
1X1
011
000
569 335 ▶ my $imageDataFlag = $$dirInfo{ImageData} || '';
Condition100%2/2
$dirInfo->{'ImageData'} || ''
l!l
192143
MC/DC100%1/1
$dirInfo->{'ImageData'} || ''
$dirInfo->{'ImageData'}
Truth table100%2/2
A
A= $dirInfo->{'ImageData'}
Aresult
11
00
570 335 my $verbose = $et->Options('Verbose');
571 335 my $out = $et->Options('TextOut');
572 335 my $noMandatory = $et->Options('NoMandatory');
573 335 my ($nextIfdPos, %offsetData, $inMakerNotes);
574 335 my (@offsetInfo, %validateInfo, %xDelete, $strEnc);
575 335 my $deleteAll = 0;
576 335 my $newData = ''; # initialize buffer to receive new directory data
577 335 my @imageData; # image data blocks to copy later if requested
578 335 my $name = $$dirInfo{Name};
579 335 ▶ $name = $dirName unless $name and $dirName eq 'MakerNotes' and $name !~ /^MakerNote/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name and $dirName eq "MakerNotes" and not $name =~ /^MakerNote/ 327 8 335
Condition100%6/6
$name and $dirName eq "MakerNotes" and not $name =~ /^MakerNote/
!ll&&!rl&&r
270578
$name and $dirName eq "MakerNotes"
!ll&&!rl&&r
17010065
MC/DC100%3/3
$name and $dirName eq "MakerNotes" and not $name =~ /^MakerNote/
$name $dirName eq "MakerNotes" not $name =~ /^MakerNote/
Truth table100%4/4
A and B and not(C)
A= $nameB= $dirName eq "MakerNotes"C= not $name =~ /^MakerNote/
ABCresult
0XX0
10X0
1100
1111
580  
581 # save byte order of existing EXIF
582 335 ▶ $$et{SaveExifByteOrder} = GetByteOrder() if $dirName eq 'IFD0' or $dirName eq 'ExifIFD';
Branch: 1 branch
BranchTrueFalseTotal
if $dirName eq "IFD0" or $dirName eq "ExifIFD" 201 134 335
Condition100%3/3
$dirName eq "IFD0" or $dirName eq "ExifIFD"
l!l&&r!l&&!r
11685134
MC/DC100%2/2
$dirName eq "IFD0" or $dirName eq "ExifIFD"
$dirName eq "IFD0" $dirName eq "ExifIFD"
Truth table100%3/3
A or B
A= $dirName eq "IFD0"B= $dirName eq "ExifIFD"
ABresult
1X1
011
000
583  
584 # set encoding for strings
585 335 ▶ $strEnc = $et->Options('CharsetEXIF') if $$tagTablePtr{GROUPS}{0} eq 'EXIF';
Branch: 1 branch
BranchTrueFalseTotal
if $tagTablePtr->{"GROUPS"}{0} eq "EXIF" 260 75 335
586  
587 # allow multiple IFD's in IFD0-IFD1-IFD2... chain
588 335 ▶ $$dirInfo{Multi} = 1 if $dirName =~ /^(IFD0|SubIFD)$/ and not defined $$dirInfo{Multi};
Branch: 1 branch
BranchTrueFalseTotal
if $dirName =~ /^(IFD0|SubIFD)$/ and not defined $dirInfo->{"Multi"} 118 217 335
Condition66%2/3
$dirName =~ /^(IFD0|SubIFD)$/ and not defined $dirInfo->{"Multi"}
!ll&&!rl&&r
2170118
MC/DC50%1/2
$dirName =~ /^(IFD0|SubIFD)$/ and not defined $dirInfo->{"Multi"}
$dirName =~ /^(IFD0|SubIFD)$/ not defined $dirInfo->{"Multi"}
Truth table66%2/3
A and not(B)
A= $dirName =~ /^(IFD0|SubIFD)$/B= not defined $dirInfo->{"Multi"}
ABresult
0X0
100
111
589 335 ▶ $inMakerNotes = 1 if $$tagTablePtr{GROUPS}{0} eq 'MakerNotes';
Branch: 1 branch
BranchTrueFalseTotal
if $tagTablePtr->{"GROUPS"}{0} eq "MakerNotes" 74 261 335
590 335 my $ifd;
591  
592 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
593 # loop through each IFD
594 #
595 335 for ($ifd=0; ; ++$ifd) { # loop through multiple IFD's
596  
597 # make sure that Compression and SubfileType are defined for this IFD (for Condition's)
598 383 $$et{Compression} = $$et{SubfileType} = '';
599  
600 # save pointer to start of this IFD within the newData
601 383 my $newStart = length($newData);
602 383 my @subdirs; # list of subdirectory data and tag table pointers
603 # determine if directory is contained within our data
604 my $mustRead;
605 383 ▶ if ($dirStart < 0 or $dirStart > $dataLen-2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dirStart < 0 or $dirStart > $dataLen - 2) { } 122 261 383
elsif ($dirLen >= 2) { } 261 0 261
Condition66%2/3
$dirStart < 0 or $dirStart > $dataLen - 2
l!l&&r!l&&!r
0122261
MC/DC50%1/2
$dirStart < 0 or $dirStart > $dataLen - 2
$dirStart < 0 $dirStart > $dataLen - 2
Truth table66%2/3
A or B
A= $dirStart < 0B= $dirStart > $dataLen - 2
ABresult
1X1
011
000
606 122 $mustRead = 1;
607 } elsif ($dirLen >= 2) {
608 261 my $len = 2 + 12 * Get16u($dataPt, $dirStart);
609 261 ▶ $mustRead = 1 if $dirStart + $len > $dataLen;
Branch: 1 branch
BranchTrueFalseTotal
if $dirStart + $len > $dataLen 0 261 261
610 }
611 # read IFD from file if necessary
612 383 ▶ if ($mustRead) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mustRead) 122 261 383
613 122 ▶ if ($raf) {
Branch: 2 branches
BranchTrueFalseTotal
if ($raf) { } 38 84 122
elsif ($dirLen and $dirStart + 4 >= $dataLen) { } 0 168 168
614 # read the count of entries in this IFD
615 38 my $offset = $dirStart + $dataPos;
616 38 my ($buff, $buf2);
617 38 ▶ unless ($raf->Seek($offset + $base, 0) and $raf->Read($buff,2) == 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Seek($offset + $base, 0) and $raf->Read($buff, 2) == 2) 0 38 38
Condition33%1/3
$raf->Seek($offset + $base, 0) and $raf->Read($buff, 2) == 2
!ll&&!rl&&r
0038
MC/DC0%0/2
$raf->Seek($offset + $base, 0) and $raf->Read($buff, 2) == 2
$raf->Seek($offset + $base, 0) $raf->Read($buff, 2) == 2
Truth table33%1/3
A and B
A= $raf->Seek($offset + $base, 0)B= $raf->Read($buff, 2) == 2
ABresult
0X0
100
111
618 0 return ExifErr($et, "Bad IFD or truncated file in $name", $tagTablePtr);
619 }
620 38 my $len = 12 * Get16u(\$buff,0);
621 # (also read next IFD pointer if available)
622 38 ▶ unless ($raf->Read($buf2, $len+4) >= $len) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Read($buf2, $len + 4) >= $len) 0 38 38
623 0 return ExifErr($et, "Error reading $name", $tagTablePtr);
624 }
625 38 $buff .= $buf2;
626 # make copy of dirInfo since we're going to modify it
627 38 my %newDirInfo = %$dirInfo;
628 38 $dirInfo = \%newDirInfo;
629 # update directory parameters for the newly loaded IFD
630 38 $dataPt = $$dirInfo{DataPt} = \$buff;
631 38 $dirStart = $$dirInfo{DirStart} = 0;
632 38 $dataPos = $$dirInfo{DataPos} = $offset;
633 38 $dataLen = $$dirInfo{DataLen} = length $buff;
634 38 $dirLen = $$dirInfo{DirLen} = $dataLen;
635 # only account for nextIFD pointer if we are going to use it
636 38 ▶ $len += 4 if $dataLen==$len+6 and ($$dirInfo{Multi} or $buff =~ /\0{4}$/);
Branch: 1 branch
BranchTrueFalseTotal
if $dataLen == $len + 6 and $dirInfo->{"Multi"} || $buff =~ /\0{4}$/ 38 0 38
Condition50%3/6
$dataLen == $len + 6 and $dirInfo->{"Multi"} || $buff =~ /\0{4}$/
!ll&&!rl&&r
0038
$dirInfo->{"Multi"} or $buff =~ /\0{4}$/
l!l&&r!l&&!r
25130
MC/DC0%0/3
$dataLen == $len + 6 and $dirInfo->{"Multi"} || $buff =~ /\0{4}$/
$dataLen == $len + 6 $dirInfo->{"Multi"} $buff =~ /\0{4}$/
Truth table50%2/4
A and B or C
A= $dataLen == $len + 6B= $dirInfo->{"Multi"}C= $buff =~ /\0{4}$/
ABCresult
0XX0
1000
11X1
1011
637 38 UpdateTiffEnd($et, $offset+$base+2+$len);
638 ▶ } elsif ($dirLen and $dirStart + 4 >= $dataLen) {
Condition33%1/3
$dirLen and $dirStart + 4 >= $dataLen
!ll&&!rl&&r
8400
MC/DC0%0/2
$dirLen and $dirStart + 4 >= $dataLen
$dirLen $dirStart + 4 >= $dataLen
Truth table33%1/3
A and B
A= $dirLenB= $dirStart + 4 >= $dataLen
ABresult
0X0
100
111
639 # error if we can't load IFD (unless we are creating
640 # from scratch, in which case dirLen will be zero)
641 0 ▶ my $str = $et->Options('IgnoreMinorErrors') ? 'Deleted bad' : 'Bad';
Branch: 1 branch
BranchTrueFalseTotal
$et->Options('IgnoreMinorErrors') ? : 0 0 0
642 0 $et->Error("$str $name directory", 1);
643 }
644 }
645 383 my ($index, $dirEnd, $numEntries, %hasOldID, $unsorted);
646 383 ▶ if ($dirStart + 4 < $dataLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirStart + 4 < $dataLen) { } 292 91 383
647 292 $numEntries = Get16u($dataPt, $dirStart);
648 292 $dirEnd = $dirStart + 2 + 12 * $numEntries;
649 292 ▶ if ($dirEnd > $dataLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirEnd > $dataLen) 0 292 292
650 0 my $n = int(($dataLen - $dirStart - 2) / 12);
651 0 my $rtn = ExifErr($et, "Truncated $name directory", $tagTablePtr);
652 0 ▶ return undef unless $n and defined $rtn;
Branch: 1 branch
BranchTrueFalseTotal
unless $n and defined $rtn 0 0 0
Condition0%0/3
$n and defined $rtn
!ll&&!rl&&r
000
MC/DC0%0/2
$n and defined $rtn
$n defined $rtn
Truth table0%0/3
A and B
A= $nB= defined $rtn
ABresult
0X0
100
111
653 0 $numEntries = $n; # continue processing the entries we have
654 }
655 # create lookup for existing tag ID's and determine if directory is sorted
656 292 my $lastID = -1;
657 292 ▶ for ($index=0; $index<$numEntries; ++$index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < $numEntries) 4721 292 5013
658 4721 my $tagID = Get16u($dataPt, $dirStart + 2 + 12 * $index);
659 4721 $hasOldID{$tagID} = 1;
660 # check for proper sequence (but ignore null entries at end)
661 4721 ▶ $unsorted = 1 if $tagID < $lastID and ($tagID or $$tagTablePtr{0});
Branch: 1 branch
BranchTrueFalseTotal
if $tagID < $lastID and $tagID || $tagTablePtr->{0} 128 4593 4721
Condition100%6/6
$tagID < $lastID and $tagID || $tagTablePtr->{0}
!ll&&!rl&&r
45876128
$tagID or $tagTablePtr->{0}
l!l&&r!l&&!r
106226
MC/DC100%3/3
$tagID < $lastID and $tagID || $tagTablePtr->{0}
$tagID < $lastID $tagID $tagTablePtr->{0}
Truth table100%4/4
A and B or C
A= $tagID < $lastIDB= $tagIDC= $tagTablePtr->{0}
ABCresult
0XX0
1000
11X1
1011
662 4721 $lastID = $tagID;
663 }
664 # sort entries if out-of-order (but not in maker notes IFDs or RAW files)
665 292 ▶ if ($unsorted and not ($inMakerNotes or $et->IsRawType())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unsorted and not $inMakerNotes || $et->IsRawType) 0 292 292
Condition50%3/6
$unsorted and not $inMakerNotes || $et->IsRawType
!ll&&!rl&&r
270220
$inMakerNotes || $et->IsRawType
l!l&&r!l&&!r
2200
MC/DC0%0/3
$unsorted and not $inMakerNotes || $et->IsRawType
$unsorted $inMakerNotes $et->IsRawType
Truth table50%2/4
A and not(B || C)
A= $unsortedB= $inMakerNotesC= $et->IsRawType
ABCresult
0XX0
11X0
1010
1001
666 0 SortIFD($dataPt, $dirStart, $numEntries, $$tagTablePtr{0});
667 0 $et->Warn("Entries in $name were out of sequence. Fixed.",1);
668 0 $unsorted = 0;
669 }
670 } else {
671 91 $numEntries = 0;
672 91 $dirEnd = $dirStart;
673 }
674  
675 # loop through new values and accumulate all information for this IFD
676 383 my (%set, %mayDelete, $tagInfo, %hasNewID);
677 383 my $wrongDir = $crossDelete{$dirName};
678 383 my @newTagInfo = $et->GetNewTagInfoList($tagTablePtr);
679 383 foreach $tagInfo (@newTagInfo) {
680 2057 my $tagID = $$tagInfo{TagID};
681 2057 $hasNewID{$tagID} = 1;
682 # must evaluate Condition later when we have all DataMember's available
683 2057 ▶ $set{$tagID} = (ref $$tagTablePtr{$tagID} eq 'ARRAY' or $$tagInfo{Condition}) ? '' : $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
ref $tagTablePtr->{$tagID} eq 'ARRAY' || $tagInfo->{'Condition'} ? : 168 1889 2057
Condition100%3/3
ref $tagTablePtr->{$tagID} eq "ARRAY" or $tagInfo->{"Condition"}
l!l&&r!l&&!r
115531889
MC/DC100%2/2
ref $tagTablePtr->{$tagID} eq "ARRAY" or $tagInfo->{"Condition"}
ref $tagTablePtr->{$tagID} eq "ARRAY" $tagInfo->{"Condition"}
Truth table100%3/3
A or B
A= ref $tagTablePtr->{$tagID} eq "ARRAY"B= $tagInfo->{"Condition"}
ABresult
1X1
011
000
684 }
685  
686 # fix base offsets (some cameras incorrectly write maker notes in IFD0)
687 383 ▶ if ($dirName eq 'MakerNotes' and $$dirInfo{Parent} =~ /^(ExifIFD|IFD0)$/ and
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName eq "MakerNotes" and $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/ and not $et->{"TIFF_TYPE"} =~ /^(ARW|SR2)$/ and not $et->{"LeicaTrailerPos"} and &Image::ExifTool::MakerNotes::FixBase($et, $dirInfo)) 2 381 383
Condition83%10/12
$dirName eq "MakerNotes" and $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/ and not $et->{"TIFF_TYPE"} =~ /^(ARW|SR2)$/ and not $et->{"LeicaTrailerPos"} and &Image::ExifTool::MakerNotes::FixBase($et, $dirInfo)
!ll&&!rl&&r
327542
$dirName eq "MakerNotes" and $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/ and not $et->{"TIFF_TYPE"} =~ /^(ARW|SR2)$/ and not $et->{"LeicaTrailerPos"}
!ll&&!rl&&r
327056
$dirName eq "MakerNotes" and $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/ and not $et->{"TIFF_TYPE"} =~ /^(ARW|SR2)$/
!ll&&!rl&&r
327056
$dirName eq "MakerNotes" and $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/
!ll&&!rl&&r
3091856
MC/DC60%3/5
$dirName eq "MakerNotes" and $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/ and not $et->{"TIFF_TYPE"} =~ /^(ARW|SR2)$/ and not $et->{"LeicaTrailerPos"} and &Image::ExifTool::MakerNotes::FixBase($et, $dirInfo)
$dirName eq "MakerNotes" $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/ not $et->{"TIFF_TYPE"} =~ /^(ARW|SR2)$/ not $et->{"LeicaTrailerPos"} &Image::ExifTool::MakerNotes::FixBase($et, $dirInfo)
Truth table66%4/6
A and B and not(C) and not(D) and E
A= $dirName eq "MakerNotes"B= $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/C= not $et->{"TIFF_TYPE"} =~ /^(ARW|SR2)$/D= not $et->{"LeicaTrailerPos"}E= &Image::ExifTool::MakerNotes::FixBase($et, $dirInfo)
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
688 $$et{TIFF_TYPE} !~ /^(ARW|SR2)$/ and not $$et{LeicaTrailerPos} and
689 Image::ExifTool::MakerNotes::FixBase($et, $dirInfo))
690 {
691 # update local variables from fixed values
692 2 $base = $$dirInfo{Base};
693 2 $dataPos = $$dirInfo{DataPos};
694 # changed if ForceWrite tag was was set to "FixBase"
695 2 ▶ ++$$et{CHANGED} if $$et{FORCE_WRITE}{FixBase};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"FORCE_WRITE"}{"FixBase"} 0 2 2
696 2 ▶ if ($$et{TIFF_TYPE} eq 'SRW' and $$et{Make} eq 'SAMSUNG' and $$et{Model} eq 'EK-GN120') {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"TIFF_TYPE"} eq "SRW" and $et->{"Make"} eq "SAMSUNG" and $et->{"Model"} eq "EK-GN120") 0 2 2
Condition33%2/6
$et->{"TIFF_TYPE"} eq "SRW" and $et->{"Make"} eq "SAMSUNG" and $et->{"Model"} eq "EK-GN120"
!ll&&!rl&&r
200
$et->{"TIFF_TYPE"} eq "SRW" and $et->{"Make"} eq "SAMSUNG"
!ll&&!rl&&r
200
MC/DC0%0/3
$et->{"TIFF_TYPE"} eq "SRW" and $et->{"Make"} eq "SAMSUNG" and $et->{"Model"} eq "EK-GN120"
$et->{"TIFF_TYPE"} eq "SRW" $et->{"Make"} eq "SAMSUNG" $et->{"Model"} eq "EK-GN120"
Truth table25%1/4
A and B and C
A= $et->{"TIFF_TYPE"} eq "SRW"B= $et->{"Make"} eq "SAMSUNG"C= $et->{"Model"} eq "EK-GN120"
ABCresult
0XX0
10X0
1100
1111
697 0 $et->Error("EK-GN120 SRW files are too buggy to write");
698 }
699 }
700  
701 # initialize variables to handle mandatory tags
702 383 my ($mandatory, $allMandatory, $addMandatory);
703 383 ▶ $mandatory = $mandatory{$dirName} unless $noMandatory;
Branch: 1 branch
BranchTrueFalseTotal
unless $noMandatory 383 0 383
704 383 ▶ if ($mandatory) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mandatory) { } 297 86 383
705 # use X/Y resolution values from JFIF if available
706 297 ▶ if ($dirName eq 'IFD0' and defined $$et{JFIFYResolution}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName eq "IFD0" and defined $et->{"JFIFYResolution"}) 6 291 297
Condition100%3/3
$dirName eq "IFD0" and defined $et->{"JFIFYResolution"}
!ll&&!rl&&r
1811106
MC/DC100%2/2
$dirName eq "IFD0" and defined $et->{"JFIFYResolution"}
$dirName eq "IFD0" defined $et->{"JFIFYResolution"}
Truth table100%3/3
A and B
A= $dirName eq "IFD0"B= defined $et->{"JFIFYResolution"}
ABresult
0X0
100
111
707 6 my %ifd0Vals = %$mandatory;
708 6 $ifd0Vals{0x011a} = $$et{JFIFXResolution};
709 6 $ifd0Vals{0x011b} = $$et{JFIFYResolution};
710 6 $ifd0Vals{0x0128} = $$et{JFIFResolutionUnit} + 1;
711 6 $mandatory = \%ifd0Vals;
712 }
713 297 $allMandatory = $addMandatory = 0; # initialize to zero
714 # add mandatory tags if creating a new directory
715 297 ▶ unless ($numEntries) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($numEntries) 91 206 297
716 91 foreach (keys %$mandatory) {
717 174 ▶ defined $set{$_} or $set{$_} = $$tagTablePtr{$_};
Branch: 1 branch
BranchTrueFalseTotal
defined $set{$_} or $set{$_} = $tagTablePtr->{$_} 38 136 174
718 }
719 }
720 } else {
721 86 undef $deleteAll; # don't remove directory (no mandatory entries)
722 }
723 383 my ($addDirs, @newTags);
724 383 ▶ if ($inMakerNotes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inMakerNotes) { } 74 309 383
725 74 $addDirs = { }; # can't currently add new directories in MakerNotes
726 # allow non-permanent makernotes tags to be added
727 # (note: we may get into trouble if there are too many of these
728 # because we allow out-of-order tags in MakerNote IFD's but our
729 # logic to add new tags relies on ordered entries)
730 74 foreach (keys %set) {
731 41 ▶ next unless $set{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $set{$_} 5 36 41
732 36 my $perm = $set{$_}{Permanent};
733 36 ▶ push @newTags, $_ if defined $perm and not $perm;
Branch: 1 branch
BranchTrueFalseTotal
if defined $perm and not $perm 0 36 36
Condition66%2/3
defined $perm and not $perm
!ll&&!rl&&r
3420
MC/DC0%0/2
defined $perm and not $perm
defined $perm not $perm
Truth table66%2/3
A and not(B)
A= defined $permB= not $perm
ABresult
0X0
100
111
734 }
735 0 ▶ @newTags = sort { $a <=> $b } @newTags if @newTags > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @newTags > 1 0 74 74
736 } else {
737 # get a hash of directories we will be writing in this one
738 309 $addDirs = $et->GetAddDirHash($tagTablePtr, $dirName);
739 # make a union of tags & dirs (can set whole dirs, like MakerNotes)
740 309 my %allTags = ( %set, %$addDirs );
741 # make sorted list of new tags to be added
742 309 @newTags = sort { $a <=> $b } keys(%allTags);
743 }
744 383 my $dirBuff = ''; # buffer for directory data
745 383 my $valBuff = ''; # buffer for value data
746 383 my @valFixups; # list of fixups for offsets in valBuff
747 # fixup for offsets in dirBuff
748 383 my $dirFixup = Image::ExifTool::Fixup->new;
749 383 my $entryBasedFixup;
750 383 my $lastTagID = -1;
751 383 my ($oldInfo, $oldFormat, $oldFormName, $oldCount, $oldSize, $oldValue, $oldImageData);
752 383 my ($readFormat, $readFormName, $readCount); # format for reading old value(s)
753 383 my ($entry, $valueDataPt, $valueDataPos, $valueDataLen, $valuePtr, $valEnd);
754 383 my ($offList, $offHash, $ignoreCount, $fixCount);
755 383 my $oldID = -1;
756 383 my $newID = -1;
757  
758 # patch for Canon EOS 40D firmware 1.0.4 bug (incorrect directory counts)
759 383 ▶ if ($inMakerNotes and $$et{Model} eq 'Canon EOS 40D') {
Branch: 1 branch
BranchTrueFalseTotal
if ($inMakerNotes and $et->{"Model"} eq "Canon EOS 40D") 0 383 383
Condition66%2/3
$inMakerNotes and $et->{"Model"} eq "Canon EOS 40D"
!ll&&!rl&&r
309740
MC/DC0%0/2
$inMakerNotes and $et->{"Model"} eq "Canon EOS 40D"
$inMakerNotes $et->{"Model"} eq "Canon EOS 40D"
Truth table66%2/3
A and B
A= $inMakerNotesB= $et->{"Model"} eq "Canon EOS 40D"
ABresult
0X0
100
111
760 0 my $fmt = Get16u($dataPt, $dirStart + 2 + 12 * ($numEntries - 1) + 2);
761 0 ▶ if ($fmt < 1 or $fmt > 13) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt < 1 or $fmt > 13) 0 0 0
Condition0%0/3
$fmt < 1 or $fmt > 13
l!l&&r!l&&!r
000
MC/DC0%0/2
$fmt < 1 or $fmt > 13
$fmt < 1 $fmt > 13
Truth table0%0/3
A or B
A= $fmt < 1B= $fmt > 13
ABresult
1X1
011
000
762 # adjust the number of directory entries
763 0 --$numEntries;
764 0 $dirEnd -= 12;
765 0 $ignoreCount = 1;
766 }
767 }
768 #..............................................................................
769 # loop through entries in new directory
770 #
771 383 $index = 0;
772 383 Entry: for (;;) {
773  
774 7022 ▶ if (defined $oldID and $oldID == $newID) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oldID and $oldID == $newID) 5104 1918 7022
Condition100%3/3
defined $oldID and $oldID == $newID
!ll&&!rl&&r
17571615104
MC/DC100%2/2
defined $oldID and $oldID == $newID
defined $oldID $oldID == $newID
Truth table100%3/3
A and B
A= defined $oldIDB= $oldID == $newID
ABresult
0X0
100
111
775 #
776 # read next entry from existing directory
777 #
778 5104 ▶ if ($index < $numEntries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < $numEntries) { } 4721 383 5104
779 4721 $entry = $dirStart + 2 + 12 * $index;
780 4721 $oldID = Get16u($dataPt, $entry);
781 4721 $readFormat = $oldFormat = Get16u($dataPt, $entry+2);
782 4721 $readCount = $oldCount = Get32u($dataPt, $entry+4);
783 4721 undef $oldImageData;
784 4721 ▶ if (($oldFormat < 1 or $oldFormat > 13) and $oldFormat != 129 and not ($oldFormat == 16 and $$et{Make} eq 'Apple' and $inMakerNotes)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldFormat < 1 || $oldFormat > 13 and $oldFormat != 129 and not $oldFormat == 16 && $et->{"Make"} eq "Apple" && $inMakerNotes) 0 4721 4721
Condition20%3/15
$oldFormat < 1 || $oldFormat > 13 and $oldFormat != 129 and not $oldFormat == 16 && $et->{"Make"} eq "Apple" && $inMakerNotes
!ll&&!rl&&r
472100
$oldFormat < 1 || $oldFormat > 13 and $oldFormat != 129
!ll&&!rl&&r
472100
$oldFormat < 1 or $oldFormat > 13
l!l&&r!l&&!r
004721
$oldFormat == 16 && $et->{'Make'} eq 'Apple' && $inMakerNotes
!ll&&!rl&&r
000
$oldFormat == 16 and $et->{"Make"} eq "Apple"
!ll&&!rl&&r
000
MC/DC0%0/6
$oldFormat < 1 || $oldFormat > 13 and $oldFormat != 129 and not $oldFormat == 16 && $et->{"Make"} eq "Apple" && $inMakerNotes
$oldFormat < 1 $oldFormat > 13 $oldFormat != 129 $oldFormat == 16 $et->{"Make"} eq "Apple" $inMakerNotes
Truth table9%1/11
A or B and C and not(D and E && F)
A= $oldFormat < 1B= $oldFormat > 13C= $oldFormat != 129D= $oldFormat == 16E= $et->{"Make"} eq "Apple"F= $inMakerNotes
ABCDEFresult
00XXXX0
1X0XXX0
010XXX0
1X11110
0111110
1X10XX1
1X110X1
1X11101
0110XX1
01110X1
0111101
785 0 my $msg = "Bad format ($oldFormat) for $name entry $index";
786 # patch to preserve invalid directory entries in SubIFD3 of
787 # various Kodak Z-series cameras (Z812, Z1085IS, Z1275)
788 # and some Sony cameras such as the DSC-P10
789 0 ▶ if ($dirName eq 'MakerNotes' and (($$et{Make}=~/KODAK/i and
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName eq "MakerNotes" and $et->{"Make"} =~ /KODAK/i && $dirInfo->{"Name"} && $dirInfo->{"Name"} eq "SubIFD3" || $numEntries == 12 && $et->{"Make"} eq "SONY" && $index >= 8) 0 0 0
Condition0%0/18
$dirName eq "MakerNotes" and $et->{"Make"} =~ /KODAK/i && $dirInfo->{"Name"} && $dirInfo->{"Name"} eq "SubIFD3" || $numEntries == 12 && $et->{"Make"} eq "SONY" && $index >= 8
!ll&&!rl&&r
000
$et->{"Make"} =~ /KODAK/i and $dirInfo->{"Name"} and $dirInfo->{"Name"} eq "SubIFD3" or $numEntries == 12 and $et->{"Make"} eq "SONY" and $index >= 8
l!l&&r!l&&!r
000
$et->{"Make"} =~ /KODAK/i and $dirInfo->{"Name"} and $dirInfo->{"Name"} eq "SubIFD3"
!ll&&!rl&&r
000
$et->{"Make"} =~ /KODAK/i and $dirInfo->{"Name"}
!ll&&!rl&&r
000
$numEntries == 12 and $et->{"Make"} eq "SONY" and $index >= 8
!ll&&!rl&&r
000
$numEntries == 12 and $et->{"Make"} eq "SONY"
!ll&&!rl&&r
000
MC/DC0%0/7
$dirName eq "MakerNotes" and $et->{"Make"} =~ /KODAK/i && $dirInfo->{"Name"} && $dirInfo->{"Name"} eq "SubIFD3" || $numEntries == 12 && $et->{"Make"} eq "SONY" && $index >= 8
$dirName eq "MakerNotes" $et->{"Make"} =~ /KODAK/i $dirInfo->{"Name"} $dirInfo->{"Name"} eq "SubIFD3" $numEntries == 12 $et->{"Make"} eq "SONY" $index >= 8
Truth table0%0/14
A and B and C and D or E and F and G
A= $dirName eq "MakerNotes"B= $et->{"Make"} =~ /KODAK/iC= $dirInfo->{"Name"}D= $dirInfo->{"Name"} eq "SubIFD3"E= $numEntries == 12F= $et->{"Make"} eq "SONY"G= $index >= 8
ABCDEFGresult
0XXXXXX0
10XX0XX0
10XX10X0
10XX1100
110X0XX0
110X10X0
110X1100
11100XX0
111010X0
11101100
1111XXX1
10XX1111
110X1111
11101111
790 $$dirInfo{Name} and $$dirInfo{Name} eq 'SubIFD3') or
791 ($numEntries == 12 and $$et{Make} eq 'SONY' and $index >= 8)))
792 {
793 0 $dirBuff .= substr($$dataPt, $entry, 12);
794 0 ++$index;
795 0 $newID = $oldID; # we wrote this
796 0 $et->Warn($msg, 1);
797 0 next;
798 }
799 # don't write out null directory entry
800 0 ▶ if ($oldFormat==0 and $index and $oldCount==0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldFormat == 0 and $index and $oldCount == 0) 0 0 0
Condition0%0/6
$oldFormat == 0 and $index and $oldCount == 0
!ll&&!rl&&r
000
$oldFormat == 0 and $index
!ll&&!rl&&r
000
MC/DC0%0/3
$oldFormat == 0 and $index and $oldCount == 0
$oldFormat == 0 $index $oldCount == 0
Truth table0%0/4
A and B and C
A= $oldFormat == 0B= $indexC= $oldCount == 0
ABCresult
0XX0
10X0
1100
1111
801 0 ▶ $ignoreCount = ($ignoreCount || 0) + 1;
Condition0%0/2
$ignoreCount || 0
l!l
00
MC/DC0%0/1
$ignoreCount || 0
$ignoreCount
Truth table0%0/2
A
A= $ignoreCount
Aresult
11
00
802 # must keep same directory size to avoid messing up our fixed offsets
803 0 ▶ $dirBuff .= ("\0" x 12) if $$dirInfo{FixBase};
Branch: 1 branch
BranchTrueFalseTotal
if $dirInfo->{"FixBase"} 0 0 0
804 0 ++$index;
805 0 $newID = $oldID; # pretend we wrote this
806 0 next;
807 }
808 0 return ExifErr($et, $msg, $tagTablePtr);
809 }
810 4721 $readFormName = $oldFormName = $formatName[$oldFormat];
811 4721 $valueDataPt = $dataPt;
812 4721 $valueDataPos = $dataPos;
813 4721 $valueDataLen = $dataLen;
814 4721 $valuePtr = $entry + 8;
815 # try direct method first for speed
816 4721 $oldInfo = $$tagTablePtr{$oldID};
817 4721 ▶ if (ref $oldInfo ne 'HASH' or $$oldInfo{Condition}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $oldInfo ne "HASH" or $oldInfo->{"Condition"}) 585 4136 4721
Condition100%3/3
ref $oldInfo ne "HASH" or $oldInfo->{"Condition"}
l!l&&r!l&&!r
524614136
MC/DC100%2/2
ref $oldInfo ne "HASH" or $oldInfo->{"Condition"}
ref $oldInfo ne "HASH" $oldInfo->{"Condition"}
Truth table100%3/3
A or B
A= ref $oldInfo ne "HASH"B= $oldInfo->{"Condition"}
ABresult
1X1
011
000
818 # must get unknown tags too
819 # (necessary so we don't miss a tag we want to Drop)
820 585 my $unk = $et->Options(Unknown => 1);
821 585 $oldInfo = $et->GetTagInfo($tagTablePtr, $oldID);
822 585 $et->Options(Unknown => $unk);
823 }
824 # patch incorrect count in Kodak SubIFD3 tags
825 4721 ▶ if ($oldCount < 2 and $oldInfo and $$oldInfo{FixCount}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldCount < 2 and $oldInfo and $oldInfo->{"FixCount"}) 0 4721 4721
Condition83%5/6
$oldCount < 2 and $oldInfo and $oldInfo->{"FixCount"}
!ll&&!rl&&r
191828030
$oldCount < 2 and $oldInfo
!ll&&!rl&&r
1891272803
MC/DC0%0/3
$oldCount < 2 and $oldInfo and $oldInfo->{"FixCount"}
$oldCount < 2 $oldInfo $oldInfo->{"FixCount"}
Truth table75%3/4
A and B and C
A= $oldCount < 2B= $oldInfoC= $oldInfo->{"FixCount"}
ABCresult
0XX0
10X0
1100
1111
826 0 ▶ $offList or ($offList, $offHash) = GetOffList($dataPt, $dirStart, $dataPos,
Branch: 1 branch
BranchTrueFalseTotal
$offList or () = &GetOffList($dataPt, $dirStart, $dataPos, $numEntries, $tagTablePtr) 0 0 0
827 $numEntries, $tagTablePtr);
828 0 my $i = $$offHash{Get32u($dataPt, $valuePtr)};
829 0 ▶ if (defined $i and $i < $#$offList) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i and $i < $offList->$#*) 0 0 0
Condition0%0/3
defined $i and $i < $offList->$#*
!ll&&!rl&&r
000
MC/DC0%0/2
defined $i and $i < $offList->$#*
defined $i $i < $offList->$#*
Truth table0%0/3
A and B
A= defined $iB= $i < $offList->$#*
ABresult
0X0
100
111
830 0 $oldCount = int(($$offList[$i+1] - $$offList[$i]) / $formatSize[$oldFormat]);
831 0 ▶ $fixCount = ($fixCount || 0) + 1 if $oldCount != $readCount;
Branch: 1 branch
BranchTrueFalseTotal
if $oldCount != $readCount 0 0 0
Condition0%0/2
$fixCount || 0
l!l
00
MC/DC0%0/1
$fixCount || 0
$fixCount
Truth table0%0/2
A
A= $fixCount
Aresult
11
00
832 }
833 }
834 4721 $oldSize = $oldCount * $formatSize[$oldFormat];
835 4721 my $readFromFile;
836 4721 ▶ if ($oldSize > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldSize > 4) 2151 2570 4721
837 2151 $valuePtr = Get32u($dataPt, $valuePtr);
838 # fix valuePtr if necessary
839 2151 ▶ if ($$dirInfo{FixOffsets}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirInfo->{"FixOffsets"}) 0 2151 2151
840 0 ▶ $valEnd or $valEnd = $dataPos + $dirStart + 2 + 12 * $numEntries + 4;
Branch: 1 branch
BranchTrueFalseTotal
$valEnd or $valEnd = $dataPos + $dirStart + 2 + 12 * $numEntries + 4 0 0 0
841 0 my ($tagID, $size, $wFlag) = ($oldID, $oldSize, 1);
842 #### eval FixOffsets ($valuePtr, $valEnd, $size, $tagID, $wFlag)
843 0 eval $$dirInfo{FixOffsets};
844 0 ▶ unless (defined $valuePtr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $valuePtr) 0 0 0
845 0 ▶ unless ($$et{DropTags}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($et->{"DropTags"}) 0 0 0
846 0 ▶ my $tagStr = $oldInfo ? $$oldInfo{Name} : sprintf("tag 0x%.4x",$oldID);
Branch: 1 branch
BranchTrueFalseTotal
$oldInfo ? : 0 0 0
847 0 ▶ return undef if $et->Error("Bad $name offset for $tagStr", $inMakerNotes);
Branch: 1 branch
BranchTrueFalseTotal
if $et->Error("Bad $name offset for $tagStr", $inMakerNotes) 0 0 0
848 }
849 0 ++$index; $oldID = $newID; next; # drop this tag
850 }
851 }
852 # offset shouldn't point into TIFF or IFD header
853 2151 my $suspect = ($valuePtr < 8);
854 # convert offset to pointer in $$dataPt
855 2151 ▶ if ($$dirInfo{EntryBased} or (ref $$tagTablePtr{$oldID} eq 'HASH' and
Branch: 1 branch
BranchTrueFalseTotal
if ($dirInfo->{'EntryBased'} or ref $tagTablePtr->{$oldID} eq 'HASH' and $tagTablePtr->{$oldID}{'EntryBased'}) { } 5 2146 2151
Condition66%4/6
$dirInfo->{"EntryBased"} or ref $tagTablePtr->{$oldID} eq "HASH" and $tagTablePtr->{$oldID}{"EntryBased"}
l!l&&r!l&&!r
502146
ref $tagTablePtr->{$oldID} eq "HASH" and $tagTablePtr->{$oldID}{"EntryBased"}
!ll&&!rl&&r
12220240
MC/DC33%1/3
$dirInfo->{"EntryBased"} or ref $tagTablePtr->{$oldID} eq "HASH" and $tagTablePtr->{$oldID}{"EntryBased"}
$dirInfo->{"EntryBased"} ref $tagTablePtr->{$oldID} eq "HASH" $tagTablePtr->{$oldID}{"EntryBased"}
Truth table75%3/4
A or B and C
A= $dirInfo->{"EntryBased"}B= ref $tagTablePtr->{$oldID} eq "HASH"C= $tagTablePtr->{$oldID}{"EntryBased"}
ABCresult
1XX1
0111
00X0
0100
856 $$tagTablePtr{$oldID}{EntryBased}))
857 {
858 5 $valuePtr += $entry;
859 } else {
860 2146 $valuePtr -= $dataPos;
861 }
862 # value shouldn't overlap our directory
863 2151 ▶ $suspect = 1 if $valuePtr < $dirEnd and $valuePtr+$oldSize > $dirStart;
Branch: 1 branch
BranchTrueFalseTotal
if $valuePtr < $dirEnd and $valuePtr + $oldSize > $dirStart 0 2151 2151
Condition66%2/3
$valuePtr < $dirEnd and $valuePtr + $oldSize > $dirStart
!ll&&!rl&&r
214290
MC/DC0%0/2
$valuePtr < $dirEnd and $valuePtr + $oldSize > $dirStart
$valuePtr < $dirEnd $valuePtr + $oldSize > $dirStart
Truth table66%2/3
A and B
A= $valuePtr < $dirEndB= $valuePtr + $oldSize > $dirStart
ABresult
0X0
100
111
864 # get value by seeking in file if we are allowed
865 2151 ▶ if ($valuePtr < 0 or $valuePtr+$oldSize > $dataLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valuePtr < 0 or $valuePtr + $oldSize > $dataLen) 226 1925 2151
Condition100%3/3
$valuePtr < 0 or $valuePtr + $oldSize > $dataLen
l!l&&r!l&&!r
72191925
MC/DC100%2/2
$valuePtr < 0 or $valuePtr + $oldSize > $dataLen
$valuePtr < 0 $valuePtr + $oldSize > $dataLen
Truth table100%3/3
A or B
A= $valuePtr < 0B= $valuePtr + $oldSize > $dataLen
ABresult
1X1
011
000
866 226 my ($pos, $tagStr, $invalidPreview, $tmpInfo, $leicaTrailer);
867 226 ▶ if ($oldInfo) {
Branch: 2 branches
BranchTrueFalseTotal
if ($oldInfo) { } 218 8 226
elsif (defined $oldInfo) { } 8 0 8
868 218 $tagStr = $$oldInfo{Name};
869 218 $leicaTrailer = $$oldInfo{LeicaTrailer};
870 } elsif (defined $oldInfo) {
871 8 $tmpInfo = $et->GetTagInfo($tagTablePtr, $oldID, \ '', $oldFormName, $oldCount);
872 8 ▶ if ($tmpInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpInfo) 8 0 8
873 8 $tagStr = $$tmpInfo{Name};
874 8 $leicaTrailer = $$tmpInfo{LeicaTrailer};
875 }
876 }
877 226 ▶ $tagStr or $tagStr = sprintf("tag 0x%.4x",$oldID);
Branch: 1 branch
BranchTrueFalseTotal
$tagStr or $tagStr = sprintf("tag 0x%.4x", $oldID) 226 0 226
878 # allow PreviewImage to run outside EXIF segment in JPEG images
879 226 ▶ if (not $raf) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf) 0 226 226
880 0 ▶ if ($tagStr eq 'PreviewImage') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagStr eq 'PreviewImage') { } 0 0 0
elsif ($leicaTrailer) { } 0 0 0
881 0 $raf = $$et{RAF};
882 0 ▶ if ($raf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf) { } 0 0 0
883 0 $pos = $raf->Tell();
884 0 ▶ if ($oldInfo and $$oldInfo{ChangeBase}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldInfo and $oldInfo->{"ChangeBase"}) 0 0 0
Condition0%0/3
$oldInfo and $oldInfo->{"ChangeBase"}
!ll&&!rl&&r
000
MC/DC0%0/2
$oldInfo and $oldInfo->{"ChangeBase"}
$oldInfo $oldInfo->{"ChangeBase"}
Truth table0%0/3
A and B
A= $oldInfoB= $oldInfo->{"ChangeBase"}
ABresult
0X0
100
111
885 # adjust base offset for this tag only
886 #### eval ChangeBase ($dirStart,$dataPos)
887 0 my $newBase = eval $$oldInfo{ChangeBase};
888 0 $valuePtr += $newBase;
889 }
890 } else {
891 0 $invalidPreview = 1;
892 }
893 } elsif ($leicaTrailer) {
894 # save information about Leica makernote trailer
895 $$et{LeicaTrailer} = {
896 0 ▶ TagInfo => $oldInfo || $tmpInfo,
Condition0%0/3
$oldInfo || $tmpInfo
l!l&&r!l&&!r
000
MC/DC0%0/2
$oldInfo || $tmpInfo
$oldInfo $tmpInfo
Truth table0%0/3
A || B
A= $oldInfoB= $tmpInfo
ABresult
1X1
011
000
897 Offset => $base + $valuePtr + $dataPos,
898 Size => $oldSize,
899 Fixup => Image::ExifTool::Fixup->new,
900 },
901 $invalidPreview = 2;
902 # remove SubDirectory to prevent processing (for now)
903 0 ▶ my %copy = %{$oldInfo || $tmpInfo};
Condition0%0/3
$oldInfo || $tmpInfo
l!l&&r!l&&!r
000
MC/DC0%0/2
$oldInfo || $tmpInfo
$oldInfo $tmpInfo
Truth table0%0/3
A || B
A= $oldInfoB= $tmpInfo
ABresult
1X1
011
000
904 0 delete $copy{SubDirectory};
905 0 delete $copy{MakerNotes};
906 0 $oldInfo = \%copy;
907 }
908 }
909 226 ▶ if ($oldSize > BINARY_DATA_LIMIT and $$origDirInfo{ImageData} and
Branch: 3 branches
BranchTrueFalseTotal
if ($oldSize > BINARY_DATA_LIMIT() and $origDirInfo->{'ImageData'} and !defined($oldInfo) || $oldInfo && (!$oldInfo->{'SubDirectory'} || $oldInfo->{'ReadFromRAF'})) { } 0 226 226
elsif ($raf) { } 226 0 226
elsif (not $invalidPreview) { } 0 0 0
Condition13%2/15
$oldSize > BINARY_DATA_LIMIT() and $origDirInfo->{"ImageData"} and !defined($oldInfo) || $oldInfo && (!$oldInfo->{"SubDirectory"} || $oldInfo->{"ReadFromRAF"})
!ll&&!rl&&r
22600
$oldSize > BINARY_DATA_LIMIT() and $origDirInfo->{"ImageData"}
!ll&&!rl&&r
22600
not defined $oldInfo or $oldInfo and !$oldInfo->{"SubDirectory"} || $oldInfo->{"ReadFromRAF"}
l!l&&r!l&&!r
000
$oldInfo and !$oldInfo->{"SubDirectory"} || $oldInfo->{"ReadFromRAF"}
!ll&&!rl&&r
000
not $oldInfo->{"SubDirectory"} or $oldInfo->{"ReadFromRAF"}
l!l&&r!l&&!r
000
MC/DC0%0/6
$oldSize > BINARY_DATA_LIMIT() and $origDirInfo->{"ImageData"} and !defined($oldInfo) || $oldInfo && (!$oldInfo->{"SubDirectory"} || $oldInfo->{"ReadFromRAF"})
$oldSize > BINARY_DATA_LIMIT() $origDirInfo->{"ImageData"} not defined $oldInfo $oldInfo not $oldInfo->{"SubDirectory"} $oldInfo->{"ReadFromRAF"}
Truth table14%1/7
A and B and not(C) or D and not(E) or F
A= $oldSize > BINARY_DATA_LIMIT()B= $origDirInfo->{"ImageData"}C= not defined $oldInfoD= $oldInfoE= not $oldInfo->{"SubDirectory"}F= $oldInfo->{"ReadFromRAF"}
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
1101000
111XXX1
11011X1
1101011
910 (not defined $oldInfo or ($oldInfo and
911 (not $$oldInfo{SubDirectory} or $$oldInfo{ReadFromRAF}))))
912 {
913 # copy huge data blocks later instead of loading into memory
914 0 $oldValue = ''; # dummy empty value
915 # copy this value later unless writing a new value
916 0 ▶ unless (defined $set{$oldID}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $set{$oldID}) 0 0 0
917 0 ▶ my $pad = $oldSize & 0x01 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$oldSize & 1 ? : 0 0 0
918 # save block information to copy later (set directory offset later)
919 0 $oldImageData = [$base+$valuePtr+$dataPos, $oldSize, $pad];
920 }
921 } elsif ($raf) {
922 226 ▶ my $success = ($raf->Seek($base+$valuePtr+$dataPos, 0) and
Condition33%1/3
$raf->Seek($base + $valuePtr + $dataPos, 0) && $raf->Read($oldValue, $oldSize) == $oldSize
!ll&&!rl&&r
00226
MC/DC0%0/2
$raf->Seek($base + $valuePtr + $dataPos, 0) && $raf->Read($oldValue, $oldSize) == $oldSize
$raf->Seek($base + $valuePtr + $dataPos, 0) $raf->Read($oldValue, $oldSize) == $oldSize
Truth table33%1/3
A && B
A= $raf->Seek($base + $valuePtr + $dataPos, 0)B= $raf->Read($oldValue, $oldSize) == $oldSize
ABresult
0X0
100
111
923 $raf->Read($oldValue, $oldSize) == $oldSize);
924 226 ▶ if (defined $pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 0 226 226
925 0 $raf->Seek($pos, 0);
926 0 undef $raf;
927 # (sony A700 has 32-byte header on PreviewImage)
928 0 ▶ unless ($success and $oldValue =~ /^(\xff\xd8\xff|(.|.{33})\xd8\xff\xdb)/s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success and $oldValue =~ /^(\xff\xd8\xff|(.|.{33})\xd8\xff\xdb)/s) 0 0 0
Condition0%0/3
$success and $oldValue =~ /^(\xff\xd8\xff|(.|.{33})\xd8\xff\xdb)/s
!ll&&!rl&&r
000
MC/DC0%0/2
$success and $oldValue =~ /^(\xff\xd8\xff|(.|.{33})\xd8\xff\xdb)/s
$success $oldValue =~ /^(\xff\xd8\xff|(.|.{33})\xd8\xff\xdb)/s
Truth table0%0/3
A and B
A= $successB= $oldValue =~ /^(\xff\xd8\xff|(.|.{33})\xd8\xff\xdb)/s
ABresult
0X0
100
111
929 0 $invalidPreview = 1;
930 0 $success = 1; # continue writing directory anyway
931 }
932 }
933 226 ▶ unless ($success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 226 226
934 0 my $wrn = sprintf("Error reading value for $name entry $index, ID 0x%.4x", $oldID);
935 0 my $truncOK;
936 0 ▶ if ($oldInfo and not $$oldInfo{Unknown}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldInfo and not $oldInfo->{"Unknown"}) 0 0 0
Condition0%0/3
$oldInfo and not $oldInfo->{"Unknown"}
!ll&&!rl&&r
000
MC/DC0%0/2
$oldInfo and not $oldInfo->{"Unknown"}
$oldInfo not $oldInfo->{"Unknown"}
Truth table0%0/3
A and not(B)
A= $oldInfoB= not $oldInfo->{"Unknown"}
ABresult
0X0
100
111
937 0 $wrn .= " $$oldInfo{Name}";
938 0 $truncOK = $$oldInfo{TruncateOK};
939 }
940 0 ▶ return undef if $et->Error($wrn, $inMakerNotes || $truncOK);
Branch: 1 branch
BranchTrueFalseTotal
if $et->Error($wrn, $inMakerNotes || $truncOK) 0 0 0
Condition0%0/3
$inMakerNotes || $truncOK
l!l&&r!l&&!r
000
MC/DC0%0/2
$inMakerNotes || $truncOK
$inMakerNotes $truncOK
Truth table0%0/3
A || B
A= $inMakerNotesB= $truncOK
ABresult
1X1
011
000
941 0 ▶ unless ($truncOK) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($truncOK) 0 0 0
942 0 ++$index; $oldID = $newID; next; # drop this tag
943 }
944 }
945 } elsif (not $invalidPreview) {
946 0 ▶ return undef if $et->Error("Bad $name offset for $tagStr", $inMakerNotes);
Branch: 1 branch
BranchTrueFalseTotal
if $et->Error("Bad $name offset for $tagStr", $inMakerNotes) 0 0 0
947 0 ++$index; $oldID = $newID; next; # drop this tag
948 }
949 226 ▶ if ($invalidPreview) {
Branch: 1 branch
BranchTrueFalseTotal
if ($invalidPreview) { } 0 226 226
950 # set value for invalid preview
951 0 ▶ if ($$et{FILE_TYPE} eq 'JPEG') {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'FILE_TYPE'} eq 'JPEG') { } 0 0 0
952 # define dummy value for preview (or Leica MakerNote) to write later
953 # (value must be larger than 4 bytes to generate PREVIEW_INFO,
954 # and an even number of bytes so it won't be padded)
955 0 $oldValue = 'LOAD_PREVIEW';
956 } else {
957 0 $oldValue = 'none';
958 0 $oldSize = length $oldValue;
959 }
960 0 $valuePtr = 0;
961 } else {
962 226 UpdateTiffEnd($et, $base+$valuePtr+$dataPos+$oldSize);
963 }
964 # update pointers for value just read from file
965 226 $valueDataPt = \$oldValue;
966 226 $valueDataPos = $valuePtr + $dataPos;
967 226 $valueDataLen = $oldSize;
968 226 $valuePtr = 0;
969 226 $readFromFile = 1;
970 }
971 2151 ▶ if ($suspect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suspect) 2 2149 2151
972 2 ▶ my $tagStr = $oldInfo ? $$oldInfo{Name} : sprintf('tag 0x%.4x', $oldID);
Branch: 1 branch
BranchTrueFalseTotal
$oldInfo ? : 2 0 2
973 2 my $str = "Suspicious $name offset for $tagStr";
974 2 ▶ if ($inMakerNotes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inMakerNotes) { } 2 0 2
975 2 $et->Warn($str, 1);
976 } else {
977 0 ▶ return undef if $et->Error($str, 1);
Branch: 1 branch
BranchTrueFalseTotal
if $et->Error($str, 1) 0 0 0
978 }
979 }
980 }
981 # read value if we haven't already
982 4721 ▶ $oldValue = substr($$valueDataPt, $valuePtr, $oldSize) unless $readFromFile;
Branch: 1 branch
BranchTrueFalseTotal
unless $readFromFile 4495 226 4721
983 # get tagInfo using value if necessary
984 4721 ▶ if (defined $oldInfo and not $oldInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oldInfo and not $oldInfo) 162 4559 4721
Condition66%2/3
defined $oldInfo and not $oldInfo
!ll&&!rl&&r
04559162
MC/DC50%1/2
defined $oldInfo and not $oldInfo
defined $oldInfo not $oldInfo
Truth table66%2/3
A and not(B)
A= defined $oldInfoB= not $oldInfo
ABresult
0X0
100
111
985 162 my $unk = $et->Options(Unknown => 1);
986 162 $oldInfo = $et->GetTagInfo($tagTablePtr, $oldID, \$oldValue, $oldFormName, $oldCount);
987 162 $et->Options(Unknown => $unk);
988 # now that we have the value, we can resolve the Condition to finally
989 # determine whether we want to delete this tag or not
990 162 ▶ if ($mayDelete{$oldID} and $oldInfo and (not @newTags or $newTags[0] != $oldID)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mayDelete{$oldID} and $oldInfo and !@newTags || $newTags[0] != $oldID) 0 162 162
Condition22%2/9
$mayDelete{$oldID} and $oldInfo and !@newTags || $newTags[0] != $oldID
!ll&&!rl&&r
16200
$mayDelete{$oldID} and $oldInfo
!ll&&!rl&&r
16200
not @newTags or $newTags[0] != $oldID
l!l&&r!l&&!r
000
MC/DC0%0/4
$mayDelete{$oldID} and $oldInfo and !@newTags || $newTags[0] != $oldID
$mayDelete{$oldID} $oldInfo not @newTags $newTags[0] != $oldID
Truth table20%1/5
A and B and not(C) or D
A= $mayDelete{$oldID}B= $oldInfoC= not @newTagsD= $newTags[0] != $oldID
ABCDresult
0XXX0
10XX0
11000
111X1
11011
991 0 my $nvHash = $et->GetNewValueHash($oldInfo, $dirName);
992 0 ▶ if (not $nvHash and $wrongDir) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $nvHash and $wrongDir) 0 0 0
Condition0%0/3
not $nvHash and $wrongDir
!ll&&!rl&&r
000
MC/DC0%0/2
not $nvHash and $wrongDir
not $nvHash $wrongDir
Truth table0%0/3
not(A) and B
A= not $nvHashB= $wrongDir
ABresult
0X0
100
111
993 # delete from wrong directory if necessary
994 0 $nvHash = $et->GetNewValueHash($oldInfo, $wrongDir);
995 0 ▶ $nvHash and $xDelete{$oldID} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$nvHash and $xDelete{$oldID} = 1 0 0 0
996 }
997 0 ▶ if ($nvHash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash) 0 0 0
998 # we want to delete this tag after all, so insert it into our list
999 0 $set{$oldID} = $oldInfo;
1000 0 unshift @newTags, $oldID;
1001 }
1002 }
1003 }
1004 # make sure we are handling the 'ifd' format properly
1005 4721 ▶ if (($oldFormat == 13 or $oldFormat == 18) and
Branch: 1 branch
BranchTrueFalseTotal
if ($oldFormat == 13 || $oldFormat == 18 and not $oldInfo && $oldInfo->{"SubIFD"}) 0 4721 4721
Condition55%5/9
$oldFormat == 13 || $oldFormat == 18 and not $oldInfo && $oldInfo->{"SubIFD"}
!ll&&!rl&&r
471650
$oldFormat == 13 or $oldFormat == 18
l!l&&r!l&&!r
504716
$oldInfo && $oldInfo->{'SubIFD'}
!ll&&!rl&&r
005
MC/DC0%0/4
$oldFormat == 13 || $oldFormat == 18 and not $oldInfo && $oldInfo->{"SubIFD"}
$oldFormat == 13 $oldFormat == 18 $oldInfo $oldInfo->{'SubIFD'}
Truth table28%2/7
A or B and not(C && D)
A= $oldFormat == 13B= $oldFormat == 18C= $oldInfoD= $oldInfo->{'SubIFD'}
ABCDresult
00XX0
1X110
01110
1X0X1
1X101
010X1
01101
1006 (not $oldInfo or not $$oldInfo{SubIFD}))
1007 {
1008 0 my $str = sprintf('%s tag 0x%.4x IFD format not handled', $name, $oldID);
1009 0 $et->Error($str, $inMakerNotes);
1010 }
1011 # override format we use to read the value if specified
1012 4721 ▶ if ($oldInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldInfo) 4721 0 4721
1013 # check for tags which must be integers
1014 4721 ▶ if (($$oldInfo{IsOffset} or $$oldInfo{SubIFD}) and
Branch: 1 branch
BranchTrueFalseTotal
if ($oldInfo->{"IsOffset"} || $oldInfo->{"SubIFD"} and not $Image::ExifTool::Exif::intFormat{$oldFormName}) 0 4721 4721
Condition83%5/6
$oldInfo->{"IsOffset"} || $oldInfo->{"SubIFD"} and not $Image::ExifTool::Exif::intFormat{$oldFormName}
!ll&&!rl&&r
45381830
$oldInfo->{"IsOffset"} or $oldInfo->{"SubIFD"}
l!l&&r!l&&!r
771064538
MC/DC0%0/3
$oldInfo->{"IsOffset"} || $oldInfo->{"SubIFD"} and not $Image::ExifTool::Exif::intFormat{$oldFormName}
$oldInfo->{"IsOffset"} $oldInfo->{"SubIFD"} not $Image::ExifTool::Exif::intFormat{$oldFormName}
Truth table60%3/5
A or B and not(C)
A= $oldInfo->{"IsOffset"}B= $oldInfo->{"SubIFD"}C= not $Image::ExifTool::Exif::intFormat{$oldFormName}
ABCresult
00X0
1X00
0100
1X11
0111
1015 not $intFormat{$oldFormName})
1016 {
1017 0 $et->Error("Invalid format ($oldFormName) for $name $$oldInfo{Name}", $inMakerNotes);
1018 0 ++$index; $oldID = $newID; next; # drop this tag
1019 }
1020 4721 ▶ if ($$oldInfo{Drop} and $$et{DropTags} and
Branch: 1 branch
BranchTrueFalseTotal
if ($oldInfo->{"Drop"} and $et->{"DropTags"} and $oldInfo->{"Drop"} == 1 || $oldInfo->{"Drop"} < $oldSize) 4 4717 4721
Condition66%6/9
$oldInfo->{"Drop"} and $et->{"DropTags"} and $oldInfo->{"Drop"} == 1 || $oldInfo->{"Drop"} < $oldSize
!ll&&!rl&&r
471704
$oldInfo->{"Drop"} and $et->{"DropTags"}
!ll&&!rl&&r
470894
$oldInfo->{"Drop"} == 1 or $oldInfo->{"Drop"} < $oldSize
l!l&&r!l&&!r
400
MC/DC50%2/4
$oldInfo->{"Drop"} and $et->{"DropTags"} and $oldInfo->{"Drop"} == 1 || $oldInfo->{"Drop"} < $oldSize
$oldInfo->{"Drop"} $et->{"DropTags"} $oldInfo->{"Drop"} == 1 $oldInfo->{"Drop"} < $oldSize
Truth table60%3/5
A and B and C or D
A= $oldInfo->{"Drop"}B= $et->{"DropTags"}C= $oldInfo->{"Drop"} == 1D= $oldInfo->{"Drop"} < $oldSize
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1021 ($$oldInfo{Drop} == 1 or $$oldInfo{Drop} < $oldSize))
1022 {
1023 4 ++$index; $oldID = $newID; next; # drop this tag
1024 }
1025 4717 ▶ if ($$oldInfo{Format}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldInfo->{"Format"}) 289 4428 4717
1026 289 $readFormName = $$oldInfo{Format};
1027 289 $readFormat = $formatNumber{$readFormName};
1028 289 ▶ unless ($readFormat) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readFormat) 0 289 289
1029 # we aren't reading in a standard EXIF format, so rewrite in old format
1030 0 $readFormName = $oldFormName;
1031 0 $readFormat = $oldFormat;
1032 }
1033 289 ▶ if ($$oldInfo{FixedSize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldInfo->{"FixedSize"}) 0 289 289
1034 0 ▶ $oldSize = $$oldInfo{FixedSize} if $$oldInfo{FixedSize};
Branch: 1 branch
BranchTrueFalseTotal
if $oldInfo->{"FixedSize"} 0 0 0
1035 0 $oldValue = substr($$valueDataPt, $valuePtr, $oldSize);
1036 }
1037 # adjust number of items to read if format size changed
1038 289 $readCount = $oldSize / $formatSize[$readFormat];
1039 }
1040 }
1041 4717 ▶ if ($oldID <= $lastTagID and not ($inMakerNotes or $et->IsRawType())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldID <= $lastTagID and not $inMakerNotes || $et->IsRawType) 0 4717 4717
Condition50%3/6
$oldID <= $lastTagID and not $inMakerNotes || $et->IsRawType
!ll&&!rl&&r
45831340
$inMakerNotes || $et->IsRawType
l!l&&r!l&&!r
13400
MC/DC0%0/3
$oldID <= $lastTagID and not $inMakerNotes || $et->IsRawType
$oldID <= $lastTagID $inMakerNotes $et->IsRawType
Truth table50%2/4
A and not(B || C)
A= $oldID <= $lastTagIDB= $inMakerNotesC= $et->IsRawType
ABCresult
0XX0
11X0
1010
1001
1042 0 ▶ my $str = $oldInfo ? "$$oldInfo{Name} tag" : sprintf('tag 0x%x',$oldID);
Branch: 1 branch
BranchTrueFalseTotal
$oldInfo ? : 0 0 0
1043 0 ▶ if ($oldID == $lastTagID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldID == $lastTagID) { } 0 0 0
1044 0 $et->Warn("Duplicate $str in $name");
1045 # put this tag back into the newTags list if necessary
1046 0 ▶ unshift @newTags, $oldID if defined $set{$oldID};
Branch: 1 branch
BranchTrueFalseTotal
if defined $set{$oldID} 0 0 0
1047 } else {
1048 0 $et->Warn("\u$str out of sequence in $name");
1049 }
1050 }
1051 4717 $lastTagID = $oldID;
1052 4717 ++$index; # increment index for next time
1053 } else {
1054 383 undef $oldID; # no more existing entries
1055 }
1056 }
1057 #
1058 # write out all new tags, up to and including this one
1059 #
1060 7018 $newID = $newTags[0];
1061 7018 my $isNew; # -1=tag is old, 0=tag same as existing, 1=tag is new
1062 7018 ▶ if (not defined $oldID) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $oldID) { } 2140 4878 7018
elsif (not defined $newID) { } 3252 1626 4878
1063 2140 ▶ last unless defined $newID;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newID 383 1757 2140
1064 1757 $isNew = 1;
1065 } elsif (not defined $newID) {
1066 # maker notes will have no new tags defined
1067 3252 ▶ if (defined $set{$oldID}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set{$oldID}) { } 35 3217 3252
1068 35 $newID = $oldID;
1069 35 $isNew = 0;
1070 } else {
1071 3217 $isNew = -1;
1072 }
1073 } else {
1074 1626 $isNew = $oldID <=> $newID;
1075 # special logic needed if directory has out-of-order entries
1076 1626 ▶ if ($unsorted and $isNew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unsorted and $isNew) 0 1626 1626
Condition33%1/3
$unsorted and $isNew
!ll&&!rl&&r
162600
MC/DC0%0/2
$unsorted and $isNew
$unsorted $isNew
Truth table33%1/3
A and B
A= $unsortedB= $isNew
ABresult
0X0
100
111
1077 0 ▶ if ($isNew > 0 and $hasOldID{$newID}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isNew > 0 and $hasOldID{$newID}) 0 0 0
Condition0%0/3
$isNew > 0 and $hasOldID{$newID}
!ll&&!rl&&r
000
MC/DC0%0/2
$isNew > 0 and $hasOldID{$newID}
$isNew > 0 $hasOldID{$newID}
Truth table0%0/3
A and B
A= $isNew > 0B= $hasOldID{$newID}
ABresult
0X0
100
111
1078 # we wanted to create the new tag, but an old tag
1079 # does exist with this ID, so defer writing the new tag
1080 0 $isNew = -1;
1081 }
1082 0 ▶ if ($isNew < 0 and $hasNewID{$oldID}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isNew < 0 and $hasNewID{$oldID}) 0 0 0
Condition0%0/3
$isNew < 0 and $hasNewID{$oldID}
!ll&&!rl&&r
000
MC/DC0%0/2
$isNew < 0 and $hasNewID{$oldID}
$isNew < 0 $hasNewID{$oldID}
Truth table0%0/3
A and B
A= $isNew < 0B= $hasNewID{$oldID}
ABresult
0X0
100
111
1083 # we wanted to write the old tag, but we have
1084 # a new tag with this ID, so move it up in the order
1085 0 my @tmpTags = ( $oldID );
1086 0 ▶ $_ == $oldID or push @tmpTags, $_ foreach @newTags;
Branch: 1 branch
BranchTrueFalseTotal
$_ == $oldID or push @tmpTags, $_ 0 0 0
1087 0 @newTags = @tmpTags;
1088 0 $newID = $oldID;
1089 0 $isNew = 0;
1090 }
1091 }
1092 }
1093 6635 my $newInfo = $oldInfo;
1094 6635 my $newFormat = $oldFormat;
1095 6635 my $newFormName = $oldFormName;
1096 6635 my $newCount = $oldCount;
1097 6635 my $ifdFormName;
1098 my $newValue;
1099 6635 ▶ my $newValuePt = $isNew >= 0 ? \$newValue : \$oldValue;
Branch: 1 branch
BranchTrueFalseTotal
$isNew >= 0 ? : 2201 4434 6635
1100 6635 my $isOverwriting;
1101  
1102 6635 ▶ if ($isNew >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isNew >= 0) 2201 4434 6635
1103 # add, edit or delete this tag
1104 2201 shift @newTags; # remove from list
1105 2201 my $curInfo = $set{$newID};
1106 # don't allow MakerNotes to be added to ExifIFD of CR3 file
1107 2201 ▶ next if $newID == 0x927c and $isNew > 0 and $$et{FileType} eq 'CR3';
Branch: 1 branch
BranchTrueFalseTotal
if $newID == 37500 and $isNew > 0 and $et->{"FileType"} eq "CR3" 0 2201 2201
Condition83%5/6
$newID == 37500 and $isNew > 0 and $et->{"FileType"} eq "CR3"
!ll&&!rl&&r
2182190
$newID == 37500 and $isNew > 0
!ll&&!rl&&r
2179319
MC/DC0%0/3
$newID == 37500 and $isNew > 0 and $et->{"FileType"} eq "CR3"
$newID == 37500 $isNew > 0 $et->{"FileType"} eq "CR3"
Truth table75%3/4
A and B and C
A= $newID == 37500B= $isNew > 0C= $et->{"FileType"} eq "CR3"
ABCresult
0XX0
10X0
1100
1111
1108 2201 ▶ unless ($curInfo or $$addDirs{$newID}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($curInfo or $addDirs->{$newID}) 110 2091 2201
Condition100%3/3
$curInfo or $addDirs->{$newID}
l!l&&r!l&&!r
201972110
MC/DC100%2/2
$curInfo or $addDirs->{$newID}
$curInfo $addDirs->{$newID}
Truth table100%3/3
A or B
A= $curInfoB= $addDirs->{$newID}
ABresult
1X1
011
000
1109 # we can finally get the specific tagInfo reference for this tag
1110 # (because we can now evaluate the Condition statement since all
1111 # DataMember's have been obtained for tags up to this one)
1112 110 $curInfo = $et->GetTagInfo($tagTablePtr, $newID);
1113 110 ▶ if (defined $curInfo and not $curInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $curInfo and not $curInfo) 24 86 110
Condition66%2/3
defined $curInfo and not $curInfo
!ll&&!rl&&r
08624
MC/DC50%1/2
defined $curInfo and not $curInfo
defined $curInfo not $curInfo
Truth table66%2/3
A and not(B)
A= defined $curInfoB= not $curInfo
ABresult
0X0
100
111
1114 # need value to evaluate the condition
1115 # (tricky because we need the tagInfo ref to get the value,
1116 # so we must loop through all new tagInfo's...)
1117 24 foreach $tagInfo (@newTagInfo) {
1118 532 ▶ next unless $$tagInfo{TagID} == $newID;
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo->{"TagID"} == $newID 508 24 532
1119 24 my $val = $et->GetNewValue($tagInfo);
1120 24 ▶ defined $val or $mayDelete{$newID} = 1, next;
Branch: 1 branch
BranchTrueFalseTotal
defined $val or $mayDelete{$newID} = 1, next 24 0 24
1121 # must convert to binary for evaluating in Condition
1122 24 ▶ my $fmt = $$tagInfo{Format} || $$tagInfo{Writable};
Condition100%3/3
$tagInfo->{'Format'} || $tagInfo->{'Writable'}
l!l&&r!l&&!r
2211
MC/DC100%2/2
$tagInfo->{'Format'} || $tagInfo->{'Writable'}
$tagInfo->{'Format'} $tagInfo->{'Writable'}
Truth table100%3/3
A || B
A= $tagInfo->{'Format'}B= $tagInfo->{'Writable'}
ABresult
1X1
011
000
1123 24 ▶ if ($fmt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt) 23 1 24
1124 23 $val = WriteValue($val, $fmt, $$tagInfo{Count});
1125 23 ▶ defined $val or $mayDelete{$newID} = 1, next;
Branch: 1 branch
BranchTrueFalseTotal
defined $val or $mayDelete{$newID} = 1, next 23 0 23
1126 }
1127 24 $curInfo = $et->GetTagInfo($tagTablePtr, $newID, \$val, $oldFormName, $oldCount);
1128 24 ▶ if ($curInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curInfo) 24 0 24
1129 24 ▶ last if $curInfo eq $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
if $curInfo eq $tagInfo 21 3 24
1130 3 undef $curInfo;
1131 }
1132 }
1133 # may want to delete this, but we need to see the old value first
1134 24 ▶ $mayDelete{$newID} = 1 unless $curInfo;
Branch: 1 branch
BranchTrueFalseTotal
unless $curInfo 3 21 24
1135 }
1136 # don't set this tag unless valid for the current condition
1137 110 ▶ if ($curInfo and $$et{NEW_VALUE}{$curInfo}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curInfo and $et->{'NEW_VALUE'}{$curInfo}) { } 83 27 110
Condition100%3/3
$curInfo and $et->{"NEW_VALUE"}{$curInfo}
!ll&&!rl&&r
32483
MC/DC100%2/2
$curInfo and $et->{"NEW_VALUE"}{$curInfo}
$curInfo $et->{"NEW_VALUE"}{$curInfo}
Truth table100%3/3
A and B
A= $curInfoB= $et->{"NEW_VALUE"}{$curInfo}
ABresult
0X0
100
111
1138 83 $set{$newID} = $curInfo;
1139 } else {
1140 27 ▶ next if $isNew > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $isNew > 0 26 1 27
1141 1 $isNew = -1;
1142 1 undef $curInfo;
1143 }
1144 }
1145 2175 ▶ if ($curInfo) {
Branch: 2 branches
BranchTrueFalseTotal
if ($curInfo) { } 2102 73 2175
elsif (not $addDirs->{$newID}) { } 1 72 73
1146 2102 ▶ if ($$curInfo{WriteCondition}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curInfo->{"WriteCondition"}) 6 2096 2102
1147 6 my $self = $et; # set $self to be used in eval
1148 #### eval WriteCondition ($self)
1149 6 ▶ unless (eval $$curInfo{WriteCondition}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval $curInfo->{"WriteCondition"}) 0 6 6
1150 0 ▶ $@ and warn $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and warn $@ 0 0 0
1151 0 goto NoWrite; # GOTO !
1152 }
1153 }
1154 2102 my $nvHash;
1155 2102 ▶ $nvHash = $et->GetNewValueHash($curInfo, $dirName) if $isNew >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $isNew >= 0 2102 0 2102
1156 2102 ▶ unless ($nvHash or (defined $$mandatory{$newID} and not $noMandatory)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nvHash or defined $mandatory->{$newID} and not $noMandatory) 1100 1002 2102
Condition83%5/6
$nvHash or defined $mandatory->{$newID} and not $noMandatory
l!l&&r!l&&!r
8541481100
defined $mandatory->{$newID} and not $noMandatory
!ll&&!rl&&r
11000148
MC/DC66%2/3
$nvHash or defined $mandatory->{$newID} and not $noMandatory
$nvHash defined $mandatory->{$newID} not $noMandatory
Truth table75%3/4
A or B and not(C)
A= $nvHashB= defined $mandatory->{$newID}C= not $noMandatory
ABCresult
1XX1
0111
00X0
0100
1157 1100 ▶ goto NoWrite unless $wrongDir; # GOTO !
Branch: 1 branch
BranchTrueFalseTotal
unless $wrongDir 435 665 1100
1158 # delete stuff from the wrong directory if setting somewhere else
1159 665 $nvHash = $et->GetNewValueHash($curInfo, $wrongDir);
1160 # don't cross delete if not overwriting
1161 665 ▶ goto NoWrite unless $et->IsOverwriting($nvHash); # GOTO !
Branch: 1 branch
BranchTrueFalseTotal
unless $et->IsOverwriting($nvHash) 29 636 665
1162 # don't cross delete if specifically deleting from the other directory
1163 # (Note: don't call GetValue() here because it shouldn't be called
1164 # if IsOverwriting returns < 0 -- eg. when shifting)
1165 636 ▶ if (not defined $$nvHash{Value} and $$nvHash{WantGroup} and
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $nvHash->{'Value'} and $nvHash->{'WantGroup'} and lc $nvHash->{'WantGroup'} eq lc $wrongDir) { } 2 634 636
Condition100%6/6
not defined $nvHash->{"Value"} and $nvHash->{"WantGroup"} and lc $nvHash->{"WantGroup"} eq lc $wrongDir
!ll&&!rl&&r
63042
not defined $nvHash->{"Value"} and $nvHash->{"WantGroup"}
!ll&&!rl&&r
62466
MC/DC100%3/3
not defined $nvHash->{"Value"} and $nvHash->{"WantGroup"} and lc $nvHash->{"WantGroup"} eq lc $wrongDir
not defined $nvHash->{"Value"} $nvHash->{"WantGroup"} lc $nvHash->{"WantGroup"} eq lc $wrongDir
Truth table100%4/4
not(A) and B and C
A= not defined $nvHash->{"Value"}B= $nvHash->{"WantGroup"}C= lc $nvHash->{"WantGroup"} eq lc $wrongDir
ABCresult
0XX0
10X0
1100
1111
1166 lc($$nvHash{WantGroup}) eq lc($wrongDir))
1167 {
1168 2 goto NoWrite; # GOTO !
1169 } else {
1170 # remove this tag if found in this IFD
1171 634 $xDelete{$newID} = 1;
1172 }
1173 }
1174 } elsif (not $$addDirs{$newID}) {
1175 467 ▶NoWrite: next if $isNew > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $isNew > 0 464 3 467
1176 3 delete $set{$newID};
1177 3 $isNew = -1;
1178 }
1179 1711 ▶ if ($set{$newID}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($set{$newID}) { } 1636 75 1711
elsif ($isNew > 0) { } 42 33 75
elsif ($newInfo->{'Format'} and $newInfo->{'Writable'} and $newInfo->{'Writable'} ne '1') { } 4 29 33
elsif ($addDirs->{$newID} and $newInfo ne $addDirs->{$newID}) { } 0 31 31
1180 #
1181 # set the new tag value (or 'next' if deleting tag)
1182 #
1183 1636 $newInfo = $set{$newID};
1184 1636 $newCount = $$newInfo{Count};
1185 1636 my ($val, $newVal, $n);
1186 1636 my $nvHash = $et->GetNewValueHash($newInfo, $dirName);
1187 1636 ▶ if ($isNew > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($isNew > 0) { } 1386 250 1636
elsif ($nvHash or $xDelete{$newID}) { } 241 9 250
1188 # don't create new entry unless requested
1189 1386 ▶ if ($nvHash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash) { } 616 770 1386
1190 616 ▶ next unless $$nvHash{IsCreating};
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash->{"IsCreating"} 86 530 616
1191 530 ▶ if ($$newInfo{IsOverwriting}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{'IsOverwriting'}) { } 1 529 530
1192 1 my $proc = $$newInfo{IsOverwriting};
1193 1 $isOverwriting = &$proc($et, $nvHash, $val, \$newVal);
1194 } else {
1195 529 $isOverwriting = $et->IsOverwriting($nvHash);
1196 }
1197 } else {
1198 770 ▶ next if $xDelete{$newID}; # don't create if cross deleting
Branch: 1 branch
BranchTrueFalseTotal
if $xDelete{$newID} 631 139 770
1199 139 $newVal = $$mandatory{$newID}; # get value for mandatory tag
1200 139 $isOverwriting = 1;
1201 }
1202 # convert using new format
1203 669 ▶ if ($$newInfo{Format}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{'Format'}) { } 73 596 669
1204 73 $newFormName = $$newInfo{Format};
1205 # use Writable flag to specify IFD format code
1206 73 $ifdFormName = $$newInfo{Writable};
1207 } else {
1208 596 $newFormName = $$newInfo{Writable};
1209 596 ▶ unless ($newFormName) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($newFormName) 0 596 596
1210 0 warn("No format for $name $$newInfo{Name}\n");
1211 0 next;
1212 }
1213 }
1214 669 $newFormat = $formatNumber{$newFormName};
1215 ▶ } elsif ($nvHash or $xDelete{$newID}) {
Condition100%3/3
$nvHash or $xDelete{$newID}
l!l&&r!l&&!r
23839
MC/DC100%2/2
$nvHash or $xDelete{$newID}
$nvHash $xDelete{$newID}
Truth table100%3/3
A or B
A= $nvHashB= $xDelete{$newID}
ABresult
1X1
011
000
1216 241 ▶ unless ($nvHash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nvHash) 3 238 241
1217 3 $nvHash = $et->GetNewValueHash($newInfo, $wrongDir);
1218 }
1219 # read value
1220 241 ▶ if (length $oldValue >= $oldSize) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $oldValue >= $oldSize) { } 241 0 241
1221 241 $val = ReadValue(\$oldValue, 0, $readFormName, $readCount, $oldSize);
1222 } else {
1223 0 $val = '';
1224 }
1225 # determine write format (by default, use 'Writable' format)
1226 241 my $writable = $$newInfo{Writable};
1227 # (or use existing format if 'Writable' not specified)
1228 241 ▶ $writable = $oldFormName unless $writable and $writable ne '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $writable and $writable ne 1 2 239 241
Condition66%2/3
$writable and $writable ne 1
!ll&&!rl&&r
20239
MC/DC50%1/2
$writable and $writable ne 1
$writable $writable ne 1
Truth table66%2/3
A and B
A= $writableB= $writable ne 1
ABresult
0X0
100
111
1229 # (and override write format with 'Format' if specified)
1230 241 ▶ my $writeForm = $$newInfo{Format} || $writable;
Condition66%2/3
$newInfo->{'Format'} || $writable
l!l&&r!l&&!r
222190
MC/DC0%0/2
$newInfo->{'Format'} || $writable
$newInfo->{'Format'} $writable
Truth table66%2/3
A || B
A= $newInfo->{'Format'}B= $writable
ABresult
1X1
011
000
1231 241 ▶ if ($writeForm ne $newFormName) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeForm ne $newFormName) 8 233 241
1232 # write in specified format
1233 8 $newFormName = $writeForm;
1234 8 $newFormat = $formatNumber{$newFormName};
1235 # use different IFD format code if necessary
1236 8 ▶ if ($inMakerNotes) {
Branch: 2 branches
BranchTrueFalseTotal
if ($inMakerNotes) { } 2 6 8
elsif ($writable ne $newFormName) { } 2 4 6
1237 # always preserve IFD format in maker notes
1238 2 $ifdFormName = $oldFormName;
1239 } elsif ($writable ne $newFormName) {
1240 # use specified IFD format
1241 2 $ifdFormName = $writable;
1242 }
1243 }
1244 241 ▶ if ($inMakerNotes and $readFormName ne 'string' and $readFormName ne 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
if ($inMakerNotes and $readFormName ne "string" and $readFormName ne "undef") 26 215 241
Condition83%5/6
$inMakerNotes and $readFormName ne "string" and $readFormName ne "undef"
!ll&&!rl&&r
215026
$inMakerNotes and $readFormName ne "string"
!ll&&!rl&&r
206926
MC/DC66%2/3
$inMakerNotes and $readFormName ne "string" and $readFormName ne "undef"
$inMakerNotes $readFormName ne "string" $readFormName ne "undef"
Truth table75%3/4
A and B and C
A= $inMakerNotesB= $readFormName ne "string"C= $readFormName ne "undef"
ABCresult
0XX0
10X0
1100
1111
1245 # keep same size in maker notes unless string or binary
1246 26 $newCount = $oldCount * $formatSize[$oldFormat] / $formatSize[$newFormat];
1247 }
1248 241 ▶ if ($$newInfo{IsOverwriting}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{'IsOverwriting'}) { } 1 240 241
1249 1 my $proc = $$newInfo{IsOverwriting};
1250 1 $isOverwriting = &$proc($et, $nvHash, $val, \$newVal);
1251 } else {
1252 240 $isOverwriting = $et->IsOverwriting($nvHash, $val);
1253 }
1254 }
1255 919 ▶ if ($isOverwriting) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isOverwriting) { } 904 15 919
1256 904 ▶ $newVal = $et->GetNewValue($nvHash) unless defined $newVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newVal 763 141 904
1257 # value undefined if deleting this tag
1258 # (also delete tag if cross-deleting and this isn't a date/time shift)
1259 904 ▶ if (not defined $newVal or ($xDelete{$newID} and not defined $$nvHash{Shift})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $newVal or $xDelete{$newID} and not defined $nvHash->{"Shift"}) 22 882 904
Condition83%5/6
not defined $newVal or $xDelete{$newID} and not defined $nvHash->{"Shift"}
l!l&&r!l&&!r
202882
$xDelete{$newID} and not defined $nvHash->{"Shift"}
!ll&&!rl&&r
88202
MC/DC66%2/3
not defined $newVal or $xDelete{$newID} and not defined $nvHash->{"Shift"}
not defined $newVal $xDelete{$newID} not defined $nvHash->{"Shift"}
Truth table75%3/4
not(A) or B and not(C)
A= not defined $newValB= $xDelete{$newID}C= not defined $nvHash->{"Shift"}
ABCresult
1XX1
0111
00X0
0100
1260 22 ▶ if (not defined $newVal and $$newInfo{RawConvInv} and defined $$nvHash{Value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $newVal and $newInfo->{"RawConvInv"} and defined $nvHash->{"Value"}) 0 22 22
Condition50%3/6
not defined $newVal and $newInfo->{"RawConvInv"} and defined $nvHash->{"Value"}
!ll&&!rl&&r
2200
not defined $newVal and $newInfo->{"RawConvInv"}
!ll&&!rl&&r
2200
MC/DC0%0/3
not defined $newVal and $newInfo->{"RawConvInv"} and defined $nvHash->{"Value"}
not defined $newVal $newInfo->{"RawConvInv"} defined $nvHash->{"Value"}
Truth table50%2/4
not(A) and B and C
A= not defined $newValB= $newInfo->{"RawConvInv"}C= defined $nvHash->{"Value"}
ABCresult
0XX0
10X0
1100
1111
1261 # error in RawConvInv, so rewrite existing tag
1262 0 goto NoOverwrite; # GOTO!
1263 }
1264 22 ▶ unless ($isNew) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isNew) 22 0 22
1265 22 ++$$et{CHANGED};
1266 22 $et->VerboseValue("- $dirName:$$newInfo{Name}", $val);
1267 }
1268 22 next;
1269 }
1270 882 ▶ if ($newCount and $newCount < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newCount and $newCount < 0) 19 863 882
Condition100%3/3
$newCount and $newCount < 0
!ll&&!rl&&r
73113219
MC/DC100%2/2
$newCount and $newCount < 0
$newCount $newCount < 0
Truth table100%3/3
A and B
A= $newCountB= $newCount < 0
ABresult
0X0
100
111
1271 # set count to number of values if variable
1272 19 my @vals = split ' ',$newVal;
1273 19 $newCount = @vals;
1274 }
1275 # convert to binary format
1276 882 $newValue = WriteValue($newVal, $newFormName, $newCount);
1277 882 ▶ unless (defined $newValue) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $newValue) 0 882 882
1278 0 $et->Warn("Invalid value for $dirName:$$newInfo{Name}");
1279 0 goto NoOverwrite; # GOTO!
1280 }
1281 882 ▶ if (length $newValue) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $newValue) { } 882 0 882
1282 # limit maximum value length in JPEG images
1283 # (max segment size is 65533 bytes and the min EXIF size is 96 incl an additional IFD entry)
1284 882 ▶ if ($$et{FILE_TYPE} eq 'JPEG' and length($newValue) > 65436 and
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"FILE_TYPE"} eq "JPEG" and length $newValue > 65436 and $newInfo->{"Name"} ne "PreviewImage") 0 882 882
Condition50%3/6
$et->{"FILE_TYPE"} eq "JPEG" and length $newValue > 65436 and $newInfo->{"Name"} ne "PreviewImage"
!ll&&!rl&&r
88200
$et->{"FILE_TYPE"} eq "JPEG" and length $newValue > 65436
!ll&&!rl&&r
1966860
MC/DC0%0/3
$et->{"FILE_TYPE"} eq "JPEG" and length $newValue > 65436 and $newInfo->{"Name"} ne "PreviewImage"
$et->{"FILE_TYPE"} eq "JPEG" length $newValue > 65436 $newInfo->{"Name"} ne "PreviewImage"
Truth table50%2/4
A and B and C
A= $et->{"FILE_TYPE"} eq "JPEG"B= length $newValue > 65436C= $newInfo->{"Name"} ne "PreviewImage"
ABCresult
0XX0
10X0
1100
1111
1285 $$newInfo{Name} ne 'PreviewImage')
1286 {
1287 0 ▶ my $name = $$newInfo{MakerNotes} ? 'MakerNotes' : $$newInfo{Name};
Branch: 1 branch
BranchTrueFalseTotal
$newInfo->{'MakerNotes'} ? : 0 0 0
1288 0 $et->Warn("Writing large value for $name",1);
1289 }
1290 # re-code if necessary
1291 882 ▶ if ($newFormName eq 'utf8') {
Branch: 2 branches
BranchTrueFalseTotal
if ($newFormName eq 'utf8') { } 0 882 882
elsif ($strEnc and $newFormName eq 'string') { } 1 1761 1762
1292 0 $newValue = $et->Encode($newValue, 'UTF8');
1293 ▶ } elsif ($strEnc and $newFormName eq 'string') {
Condition100%3/3
$strEnc and $newFormName eq "string"
!ll&&!rl&&r
88011
MC/DC100%2/2
$strEnc and $newFormName eq "string"
$strEnc $newFormName eq "string"
Truth table100%3/3
A and B
A= $strEncB= $newFormName eq "string"
ABresult
0X0
100
111
1294 1 $newValue = $et->Encode($newValue, $strEnc);
1295 }
1296 } else {
1297 0 $et->Warn("Can't write zero length $$newInfo{Name} in $$tagTablePtr{GROUPS}{1}");
1298 0 goto NoOverwrite; # GOTO!
1299 }
1300 882 ▶ if ($isNew >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isNew >= 0) 882 0 882
1301 882 $newCount = length($newValue) / $formatSize[$newFormat];
1302 882 ++$$et{CHANGED};
1303 882 ▶ if (defined $allMandatory) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $allMandatory) 153 729 882
1304 # not all mandatory if we are writing any tag specifically
1305 153 ▶ if ($nvHash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash) { } 82 71 153
1306 82 undef $allMandatory;
1307 82 undef $deleteAll;
1308 } else {
1309 71 ++$addMandatory; # count mandatory tags that we added
1310 }
1311 }
1312 882 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 10 872 882
1313 10 ▶ $et->VerboseValue("- $dirName:$$newInfo{Name}", $val) unless $isNew;
Branch: 1 branch
BranchTrueFalseTotal
unless $isNew 0 10 10
1314 10 ▶ if ($$newInfo{OffsetPair} and $newVal eq '4277010157') { # (0xfeedfeed)
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{'OffsetPair'} and $newVal eq '4277010157') { } 0 10 10
Condition33%1/3
$newInfo->{"OffsetPair"} and $newVal eq "4277010157"
!ll&&!rl&&r
1000
MC/DC0%0/2
$newInfo->{"OffsetPair"} and $newVal eq "4277010157"
$newInfo->{"OffsetPair"} $newVal eq "4277010157"
Truth table33%1/3
A and B
A= $newInfo->{"OffsetPair"}B= $newVal eq "4277010157"
ABresult
0X0
100
111
1315 0 print { $$et{OPTIONS}{TextOut} } " + $dirName:$$newInfo{Name} = <tbd>\n";
1316 } else {
1317 10 ▶ my $str = $nvHash ? '' : ' (mandatory)';
Branch: 1 branch
BranchTrueFalseTotal
$nvHash ? : 8 2 10
1318 10 $et->VerboseValue("+ $dirName:$$newInfo{Name}", $newVal, $str);
1319 }
1320 }
1321 }
1322 } else {
1323 15 ▶NoOverwrite: next if $isNew > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $isNew > 0 0 15 15
1324 15 $isNew = -1; # rewrite existing tag
1325 }
1326 # set format for EXIF IFD if different than conversion format
1327 897 ▶ if ($ifdFormName) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ifdFormName) 76 821 897
1328 76 $newFormName = $ifdFormName;
1329 76 $newFormat = $formatNumber{$newFormName};
1330 }
1331  
1332 } elsif ($isNew > 0) {
1333 #
1334 # create new subdirectory
1335 #
1336 # newInfo may not be defined if we try to add a mandatory tag
1337 # to a directory that doesn't support it (eg. IFD1 in RW2 images)
1338 42 ▶ $newInfo = $$addDirs{$newID} or next;
Branch: 1 branch
BranchTrueFalseTotal
$newInfo = $addDirs->{$newID} or next 42 0 42
1339 # make sure we don't try to generate a new MakerNotes directory
1340 # or a SubIFD
1341 42 ▶ next if $$newInfo{MakerNotes} or $$newInfo{Name} eq 'SubIFD';
Branch: 1 branch
BranchTrueFalseTotal
if $newInfo->{"MakerNotes"} or $newInfo->{"Name"} eq "SubIFD" 0 42 42
Condition33%1/3
$newInfo->{"MakerNotes"} or $newInfo->{"Name"} eq "SubIFD"
l!l&&r!l&&!r
0042
MC/DC0%0/2
$newInfo->{"MakerNotes"} or $newInfo->{"Name"} eq "SubIFD"
$newInfo->{"MakerNotes"} $newInfo->{"Name"} eq "SubIFD"
Truth table33%1/3
A or B
A= $newInfo->{"MakerNotes"}B= $newInfo->{"Name"} eq "SubIFD"
ABresult
1X1
011
000
1342 42 my $subTable;
1343 42 ▶ if ($$newInfo{SubDirectory}{TagTable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{'SubDirectory'}{'TagTable'}) { } 15 27 42
1344 15 $subTable = Image::ExifTool::GetTagTable($$newInfo{SubDirectory}{TagTable});
1345 } else {
1346 27 $subTable = $tagTablePtr;
1347 }
1348 # create empty source directory
1349 42 my %sourceDir = (
1350 Parent => $dirName,
1351 Fixup => Image::ExifTool::Fixup->new,
1352 );
1353 42 ▶ $sourceDir{DirName} = $$newInfo{Groups}{1} if $$newInfo{SubIFD};
Branch: 1 branch
BranchTrueFalseTotal
if $newInfo->{"SubIFD"} 38 4 42
1354 42 $newValue = $et->WriteDirectory(\%sourceDir, $subTable);
1355 # only add new directory if it isn't empty
1356 42 ▶ next unless defined $newValue and length($newValue);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newValue and length $newValue 2 40 42
Condition66%2/3
defined $newValue and length $newValue
!ll&&!rl&&r
0240
MC/DC50%1/2
defined $newValue and length $newValue
defined $newValue length $newValue
Truth table66%2/3
A and B
A= defined $newValueB= length $newValue
ABresult
0X0
100
111
1357 # set the fixup start location
1358 40 ▶ if ($$newInfo{SubIFD}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{'SubIFD'}) { } 36 4 40
1359 # subdirectory is referenced by an offset in value buffer
1360 36 my $subdir = $newValue;
1361 36 $newValue = Set32u(0xfeedf00d);
1362 push @subdirs, {
1363 DataPt => \$subdir,
1364 Table => $subTable,
1365 Fixup => $sourceDir{Fixup},
1366 36 Offset => length($dirBuff) + 8,
1367 Where => 'dirBuff',
1368 };
1369 36 $newFormName = 'int32u';
1370 36 $newFormat = $formatNumber{$newFormName};
1371 } else {
1372 # subdirectory goes directly into value buffer
1373 4 $sourceDir{Fixup}{Start} += length($valBuff);
1374 # use Writable to set format, otherwise 'undef'
1375 4 $newFormName = $$newInfo{Writable};
1376 4 ▶ unless ($newFormName and $formatNumber{$newFormName}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($newFormName and $Image::ExifTool::Exif::formatNumber{$newFormName}) 0 4 4
Condition33%1/3
$newFormName and $Image::ExifTool::Exif::formatNumber{$newFormName}
!ll&&!rl&&r
004
MC/DC0%0/2
$newFormName and $Image::ExifTool::Exif::formatNumber{$newFormName}
$newFormName $Image::ExifTool::Exif::formatNumber{$newFormName}
Truth table33%1/3
A and B
A= $newFormNameB= $Image::ExifTool::Exif::formatNumber{$newFormName}
ABresult
0X0
100
111
1377 0 $newFormName = 'undef';
1378 }
1379 4 $newFormat = $formatNumber{$newFormName};
1380 4 push @valFixups, $sourceDir{Fixup};
1381 }
1382 ▶ } elsif ($$newInfo{Format} and $$newInfo{Writable} and $$newInfo{Writable} ne '1') {
Condition66%4/6
$newInfo->{"Format"} and $newInfo->{"Writable"} and $newInfo->{"Writable"} ne 1
!ll&&!rl&&r
2904
$newInfo->{"Format"} and $newInfo->{"Writable"}
!ll&&!rl&&r
2904
MC/DC33%1/3
$newInfo->{"Format"} and $newInfo->{"Writable"} and $newInfo->{"Writable"} ne 1
$newInfo->{"Format"} $newInfo->{"Writable"} $newInfo->{"Writable"} ne 1
Truth table50%2/4
A and B and C
A= $newInfo->{"Format"}B= $newInfo->{"Writable"}C= $newInfo->{"Writable"} ne 1
ABCresult
0XX0
10X0
1100
1111
1383 # use specified write format
1384 4 $newFormName = $$newInfo{Writable};
1385 4 $newFormat = $formatNumber{$newFormName};
1386 ▶ } elsif ($$addDirs{$newID} and $newInfo ne $$addDirs{$newID}) {
Condition66%2/3
$addDirs->{$newID} and $newInfo ne $addDirs->{$newID}
!ll&&!rl&&r
2270
MC/DC0%0/2
$addDirs->{$newID} and $newInfo ne $addDirs->{$newID}
$addDirs->{$newID} $newInfo ne $addDirs->{$newID}
Truth table66%2/3
A and B
A= $addDirs->{$newID}B= $newInfo ne $addDirs->{$newID}
ABresult
0X0
100
111
1387 # this can happen if we are trying to add a directory that doesn't exist
1388 # in this type of file (eg. try adding a SubIFD tag to an A100 image)
1389 0 $isNew = -1;
1390 }
1391 }
1392 5404 ▶ if ($isNew < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isNew < 0) 4452 952 5404
1393 # just rewrite existing tag
1394 4452 $newID = $oldID;
1395 4452 $newValue = $oldValue;
1396 4452 $newFormat = $oldFormat; # (just in case it changed)
1397 4452 $newFormName = $oldFormName;
1398 # set offset of this entry in the directory so we can update the pointer
1399 # and save block information to copy this large block later
1400 4452 ▶ if ($oldImageData) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldImageData) 0 4452 4452
1401 0 $$oldImageData[3] = $newStart + length($dirBuff) + 2;
1402 0 push @imageData, $oldImageData;
1403 0 $$origDirInfo{ImageData} = \@imageData;
1404 }
1405 }
1406 5404 ▶ if ($newInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo) 5404 0 5404
1407 #
1408 # load necessary data for this tag (thumbnail image, etc)
1409 #
1410 5404 ▶ if ($$newInfo{DataTag} and $isNew >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{"DataTag"} and $isNew >= 0) 8 5396 5404
Condition100%3/3
$newInfo->{"DataTag"} and $isNew >= 0
!ll&&!rl&&r
52831138
MC/DC100%2/2
$newInfo->{"DataTag"} and $isNew >= 0
$newInfo->{"DataTag"} $isNew >= 0
Truth table100%3/3
A and B
A= $newInfo->{"DataTag"}B= $isNew >= 0
ABresult
0X0
100
111
1411 8 my $dataTag = $$newInfo{DataTag};
1412 # load data for this tag
1413 8 ▶ unless (defined $offsetData{$dataTag} or $dataTag eq 'LeicaTrailer') {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $offsetData{$dataTag} or $dataTag eq "LeicaTrailer") 4 4 8
Condition66%2/3
defined $offsetData{$dataTag} or $dataTag eq "LeicaTrailer"
l!l&&r!l&&!r
404
MC/DC50%1/2
defined $offsetData{$dataTag} or $dataTag eq "LeicaTrailer"
defined $offsetData{$dataTag} $dataTag eq "LeicaTrailer"
Truth table66%2/3
A or B
A= defined $offsetData{$dataTag}B= $dataTag eq "LeicaTrailer"
ABresult
1X1
011
000
1414 # prefer tag from Composite table if it exists (otherwise
1415 # PreviewImage data would be taken from Extra tag)
1416 4 my $compInfo = Image::ExifTool::GetCompositeTagInfo($dataTag);
1417 4 ▶ $offsetData{$dataTag} = $et->GetNewValue($compInfo || $dataTag);
Condition33%1/3
$compInfo || $dataTag
l!l&&r!l&&!r
400
MC/DC0%0/2
$compInfo || $dataTag
$compInfo $dataTag
Truth table33%1/3
A || B
A= $compInfoB= $dataTag
ABresult
1X1
011
000
1418 4 my $err;
1419 4 ▶ if (defined $offsetData{$dataTag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offsetData{$dataTag}) { } 4 0 4
1420 4 my $len = length $offsetData{$dataTag};
1421 4 ▶ if ($dataTag eq 'PreviewImage') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataTag eq "PreviewImage") 2 2 4
1422 # must set DEL_PREVIEW flag now if preview fit into IFD
1423 2 ▶ $$et{DEL_PREVIEW} = 1 if $len <= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $len <= 4 2 0 2
1424 }
1425 } else {
1426 0 $err = "$dataTag not found";
1427 }
1428 4 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 4 4
1429 0 ▶ $et->Warn($err) if $$newInfo{IsOffset};
Branch: 1 branch
BranchTrueFalseTotal
if $newInfo->{"IsOffset"} 0 0 0
1430 0 delete $set{$newID}; # remove from list of tags we are setting
1431 0 next;
1432 }
1433 }
1434 }
1435 #
1436 # write maker notes
1437 #
1438 5404 ▶ if ($$newInfo{MakerNotes}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($newInfo->{'MakerNotes'}) { } 43 5361 5404
elsif ($newInfo->{'SubDirectory'} and $isNew <= 0 and not $isOverwriting and !defined($newInfo->{'Writable'}) || $newInfo->{'Writable'} and not $newInfo->{'ReadFromRAF'}) { } 442 4919 5361
elsif ($newInfo->{'OffsetPair'}) { } 158 4761 4919
elsif ($newInfo->{'DataMember'}) { } 272 4489 4761
1439 # don't write new makernotes if we are deleting this group
1440 43 ▶ if ($$et{DEL_GROUP}{MakerNotes} and
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"DEL_GROUP"}{"MakerNotes"} and $et->{"DEL_GROUP"}{"MakerNotes"} != 2 || $isNew <= 0) 1 42 43
Condition50%3/6
$et->{"DEL_GROUP"}{"MakerNotes"} and $et->{"DEL_GROUP"}{"MakerNotes"} != 2 || $isNew <= 0
!ll&&!rl&&r
4201
$et->{"DEL_GROUP"}{"MakerNotes"} != 2 or $isNew <= 0
l!l&&r!l&&!r
100
MC/DC33%1/3
$et->{"DEL_GROUP"}{"MakerNotes"} and $et->{"DEL_GROUP"}{"MakerNotes"} != 2 || $isNew <= 0
$et->{"DEL_GROUP"}{"MakerNotes"} $et->{"DEL_GROUP"}{"MakerNotes"} != 2 $isNew <= 0
Truth table50%2/4
A and B or C
A= $et->{"DEL_GROUP"}{"MakerNotes"}B= $et->{"DEL_GROUP"}{"MakerNotes"} != 2C= $isNew <= 0
ABCresult
0XX0
1000
11X1
1011
1441 ($$et{DEL_GROUP}{MakerNotes} != 2 or $isNew <= 0))
1442 {
1443 1 ▶ if ($et->IsRawType() and not ($et->IsRawType() == 2 and $dirName eq 'ExifIFD')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->IsRawType and not $et->IsRawType == 2 && $dirName eq 'ExifIFD') { } 0 1 1
Condition16%1/6
$et->IsRawType and not $et->IsRawType == 2 && $dirName eq "ExifIFD"
!ll&&!rl&&r
100
$et->IsRawType == 2 && $dirName eq 'ExifIFD'
!ll&&!rl&&r
000
MC/DC0%0/3
$et->IsRawType and not $et->IsRawType == 2 && $dirName eq "ExifIFD"
$et->IsRawType $et->IsRawType == 2 $dirName eq 'ExifIFD'
Truth table25%1/4
A and not(B && C)
A= $et->IsRawTypeB= $et->IsRawType == 2C= $dirName eq 'ExifIFD'
ABCresult
0XX0
1110
10X1
1101
1444 0 $et->Warn("Can't delete MakerNotes from $$et{FileType}",1);
1445 } else {
1446 1 ▶ if ($isNew <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isNew <= 0) 1 0 1
1447 1 ++$$et{CHANGED};
1448 1 ▶ $verbose and print $out " Deleting MakerNotes\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting MakerNotes\n" 0 1 1
1449 }
1450 1 next;
1451 }
1452 }
1453 42 my $saveOrder = GetByteOrder();
1454 42 ▶ if ($isNew >= 0 and defined $set{$newID}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isNew >= 0 and defined $set{$newID}) { } 7 35 42
Condition66%2/3
$isNew >= 0 and defined $set{$newID}
!ll&&!rl&&r
3507
MC/DC50%1/2
$isNew >= 0 and defined $set{$newID}
$isNew >= 0 defined $set{$newID}
Truth table66%2/3
A and B
A= $isNew >= 0B= defined $set{$newID}
ABresult
0X0
100
111
1455 # we are writing a whole new maker note block
1456 # --> add fixup information if necessary
1457 7 my $nvHash = $et->GetNewValueHash($newInfo, $dirName);
1458 7 ▶ if ($nvHash and $$nvHash{MAKER_NOTE_FIXUP}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash and $nvHash->{"MAKER_NOTE_FIXUP"}) 6 1 7
Condition66%2/3
$nvHash and $nvHash->{"MAKER_NOTE_FIXUP"}
!ll&&!rl&&r
016
MC/DC50%1/2
$nvHash and $nvHash->{"MAKER_NOTE_FIXUP"}
$nvHash $nvHash->{"MAKER_NOTE_FIXUP"}
Truth table66%2/3
A and B
A= $nvHashB= $nvHash->{"MAKER_NOTE_FIXUP"}
ABresult
0X0
100
111
1459 # must clone fixup because we will be shifting it
1460 6 my $makerFixup = $$nvHash{MAKER_NOTE_FIXUP}->Clone();
1461 6 my $valLen = length($valBuff);
1462 6 $$makerFixup{Start} += $valLen;
1463 6 push @valFixups, $makerFixup;
1464 }
1465 } else {
1466 # update maker notes if possible
1467 my %subdirInfo = (
1468 Base => $base,
1469 DataPt => $valueDataPt,
1470 DataPos => $valueDataPos,
1471 DataLen => $valueDataLen,
1472 DirStart => $valuePtr,
1473 DirLen => $oldSize,
1474 DirName => 'MakerNotes',
1475 Name => $$newInfo{Name},
1476 35 Parent => $dirName,
1477 TagInfo => $newInfo,
1478 RAF => $raf,
1479 );
1480 35 my ($subTable, $subdir, $loc, $writeProc, $notIFD);
1481 35 ▶ if ($$newInfo{SubDirectory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{"SubDirectory"}) 35 0 35
1482 35 my $sub = $$newInfo{SubDirectory};
1483 35 ▶ $subdirInfo{FixBase} = 1 if $$sub{FixBase};
Branch: 1 branch
BranchTrueFalseTotal
if $sub->{"FixBase"} 4 31 35
1484 35 $subdirInfo{FixOffsets} = $$sub{FixOffsets};
1485 35 $subdirInfo{EntryBased} = $$sub{EntryBased};
1486 35 ▶ $subdirInfo{NoFixBase} = 1 if defined $$sub{Base};
Branch: 1 branch
BranchTrueFalseTotal
if defined $sub->{"Base"} 5 30 35
1487 35 $subdirInfo{AutoFix} = $$sub{AutoFix};
1488 35 ▶ SetByteOrder($$sub{ByteOrder}) if $$sub{ByteOrder};
Branch: 1 branch
BranchTrueFalseTotal
if $sub->{"ByteOrder"} 34 1 35
1489 }
1490 # get the proper tag table for these maker notes
1491 35 ▶ if ($oldInfo and $$oldInfo{SubDirectory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldInfo and $oldInfo->{'SubDirectory'}) { } 35 0 35
Condition33%1/3
$oldInfo and $oldInfo->{"SubDirectory"}
!ll&&!rl&&r
0035
MC/DC0%0/2
$oldInfo and $oldInfo->{"SubDirectory"}
$oldInfo $oldInfo->{"SubDirectory"}
Truth table33%1/3
A and B
A= $oldInfoB= $oldInfo->{"SubDirectory"}
ABresult
0X0
100
111
1492 35 $subTable = $$oldInfo{SubDirectory}{TagTable};
1493 35 ▶ $subTable and $subTable = Image::ExifTool::GetTagTable($subTable);
Branch: 1 branch
BranchTrueFalseTotal
$subTable and $subTable = &Image::ExifTool::GetTagTable($subTable) 35 0 35
1494 35 $writeProc = $$oldInfo{SubDirectory}{WriteProc};
1495 35 $notIFD = $$oldInfo{NotIFD};
1496 } else {
1497 0 $et->Warn('Internal problem getting maker notes tag table');
1498 }
1499 35 ▶ $writeProc or $writeProc = $$subTable{WRITE_PROC} if $subTable;
Branch: 1 branch
BranchTrueFalseTotal
if $subTable 35 0 35
Condition50%3/6
$subTable && ($writeProc || ($writeProc = $subTable->{'WRITE_PROC'}))
!ll&&!rl&&r
0350
$writeProc or $writeProc = $subTable->{"WRITE_PROC"}
l!l&&r!l&&!r
1340
MC/DC0%0/3
$subTable && ($writeProc || ($writeProc = $subTable->{'WRITE_PROC'}))
$subTable $writeProc $writeProc = $subTable->{"WRITE_PROC"}
Truth table0%0/4
A && B or C
A= $subTableB= $writeProcC= $writeProc = $subTable->{"WRITE_PROC"}
ABCresult
0XX0
1000
11X1
1011
1500 35 ▶ $subTable or $subTable = $tagTablePtr;
Branch: 1 branch
BranchTrueFalseTotal
$subTable or $subTable = $tagTablePtr 35 0 35
1501 35 ▶ if ($writeProc and
Branch: 2 branches
BranchTrueFalseTotal
if ($writeProc and $writeProc eq \&Image::ExifTool::MakerNotes::WriteUnknownOrPreview and $oldValue =~ /^\xff\xd8\xff/) { } 0 35 35
elsif (not $notIFD) { } 33 2 35
Condition66%4/6
$writeProc and $writeProc eq \&Image::ExifTool::MakerNotes::WriteUnknownOrPreview and $oldValue =~ /^\xff\xd8\xff/
!ll&&!rl&&r
3410
$writeProc and $writeProc eq \&Image::ExifTool::MakerNotes::WriteUnknownOrPreview
!ll&&!rl&&r
0341
MC/DC0%0/3
$writeProc and $writeProc eq \&Image::ExifTool::MakerNotes::WriteUnknownOrPreview and $oldValue =~ /^\xff\xd8\xff/
$writeProc $writeProc eq \&Image::ExifTool::MakerNotes::WriteUnknownOrPreview $oldValue =~ /^\xff\xd8\xff/
Truth table50%2/4
A and B and C
A= $writeProcB= $writeProc eq \&Image::ExifTool::MakerNotes::WriteUnknownOrPreviewC= $oldValue =~ /^\xff\xd8\xff/
ABCresult
0XX0
10X0
1100
1111
1502 $writeProc eq \&Image::ExifTool::MakerNotes::WriteUnknownOrPreview and
1503 $oldValue =~ /^\xff\xd8\xff/)
1504 {
1505 0 $loc = 0;
1506 } elsif (not $notIFD) {
1507 # look for IFD-style maker notes
1508 33 $loc = Image::ExifTool::MakerNotes::LocateIFD($et,\%subdirInfo);
1509 }
1510 35 ▶ if (defined $loc) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $loc) { } 33 2 35
elsif ($subTable->{'PROCESS_PROC'} and $subTable->{'PROCESS_PROC'} eq \&Image::ExifTool::ProcessBinaryData) { } 1 1 2
elsif ($notIFD) { } 1 0 1
1511 # we need fixup data for this subdirectory
1512 33 $subdirInfo{Fixup} = Image::ExifTool::Fixup->new;
1513 # rewrite maker notes
1514 33 my $changed = $$et{CHANGED};
1515 33 $subdir = $et->WriteDirectory(\%subdirInfo, $subTable, $writeProc);
1516 33 ▶ if ($changed == $$et{CHANGED} and $subdirInfo{Fixup}->IsEmpty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed == $et->{"CHANGED"} and $subdirInfo{"Fixup"}->IsEmpty) 1 32 33
Condition100%3/3
$changed == $et->{"CHANGED"} and $subdirInfo{"Fixup"}->IsEmpty
!ll&&!rl&&r
20121
MC/DC100%2/2
$changed == $et->{"CHANGED"} and $subdirInfo{"Fixup"}->IsEmpty
$changed == $et->{"CHANGED"} $subdirInfo{"Fixup"}->IsEmpty
Truth table100%3/3
A and B
A= $changed == $et->{"CHANGED"}B= $subdirInfo{"Fixup"}->IsEmpty
ABresult
0X0
100
111
1517 # return original data if nothing changed and no fixups
1518 1 undef $subdir;
1519 }
1520 ▶ } elsif ($$subTable{PROCESS_PROC} and
Condition66%2/3
$subTable->{"PROCESS_PROC"} and $subTable->{"PROCESS_PROC"} eq \&Image::ExifTool::ProcessBinaryData
!ll&&!rl&&r
011
MC/DC50%1/2
$subTable->{"PROCESS_PROC"} and $subTable->{"PROCESS_PROC"} eq \&Image::ExifTool::ProcessBinaryData
$subTable->{"PROCESS_PROC"} $subTable->{"PROCESS_PROC"} eq \&Image::ExifTool::ProcessBinaryData
Truth table66%2/3
A and B
A= $subTable->{"PROCESS_PROC"}B= $subTable->{"PROCESS_PROC"} eq \&Image::ExifTool::ProcessBinaryData
ABresult
0X0
100
111
1521 $$subTable{PROCESS_PROC} eq \&Image::ExifTool::ProcessBinaryData)
1522 {
1523 1 my $sub = $$oldInfo{SubDirectory};
1524 1 ▶ if (defined $$sub{Start}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sub->{'Start'}) { } 1 0 1
1525 #### eval Start ($valuePtr)
1526 1 my $start = eval $$sub{Start};
1527 1 $loc = $start - $valuePtr;
1528 1 $subdirInfo{DirStart} = $start;
1529 1 $subdirInfo{DirLen} -= $loc;
1530 } else {
1531 0 $loc = 0;
1532 }
1533 # rewrite maker notes
1534 1 $subdir = $et->WriteDirectory(\%subdirInfo, $subTable);
1535 } elsif ($notIFD) {
1536 1 ▶ if ($writeProc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeProc) 1 0 1
1537 1 $loc = 0;
1538 1 $subdir = $et->WriteDirectory(\%subdirInfo, $subTable);
1539 }
1540 } else {
1541 0 my $msg = 'Maker notes could not be parsed';
1542 0 ▶ if ($$et{FILE_TYPE} eq 'JPEG') {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'FILE_TYPE'} eq 'JPEG') { } 0 0 0
1543 0 $et->Warn($msg, 1);
1544 } else {
1545 0 $et->Error($msg, 1);
1546 }
1547 }
1548 35 ▶ if (defined $subdir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subdir) 34 1 35
1549 34 ▶ length $subdir or SetByteOrder($saveOrder), next;
Branch: 1 branch
BranchTrueFalseTotal
length $subdir or &SetByteOrder($saveOrder), next 34 0 34
1550 34 my $valLen = length($valBuff);
1551 # restore existing header and substitute the new
1552 # maker notes for the old value
1553 34 $newValue = substr($oldValue, 0, $loc) . $subdir;
1554 34 my $makerFixup = $subdirInfo{Fixup};
1555 34 my $previewInfo = $$et{PREVIEW_INFO};
1556 34 ▶ if ($subdirInfo{Relative}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subdirInfo{'Relative'}) { } 5 29 34
elsif (not defined $subdirInfo{'Relative'}) { } 29 0 29
1557 # apply a one-time fixup to $loc since offsets are relative
1558 5 $$makerFixup{Start} += $loc;
1559 # shift all offsets to be relative to new base
1560 5 my $baseShift = $valueDataPos + $valuePtr + $base - $subdirInfo{Base};
1561 5 $$makerFixup{Shift} += $baseShift;
1562 5 $makerFixup->ApplyFixup(\$newValue);
1563 5 ▶ if ($previewInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($previewInfo) 0 5 5
1564 # remove all but PreviewImage fixup (since others shouldn't change)
1565 0 foreach (keys %{$$makerFixup{Pointers}}) {
1566 0 ▶ /_PreviewImage$/ or delete $$makerFixup{Pointers}{$_};
Branch: 1 branch
BranchTrueFalseTotal
/_PreviewImage$/ or delete $makerFixup->{"Pointers"}{$_} 0 0 0
1567 }
1568 # zero pointer so we can see how it gets shifted later
1569 0 $makerFixup->SetMarkerPointers(\$newValue, 'PreviewImage', 0);
1570 # set the pointer to the start of the EXIF information
1571 # add preview image fixup to list of value fixups
1572 0 $$makerFixup{Start} += $valLen;
1573 0 push @valFixups, $makerFixup;
1574 0 $$previewInfo{BaseShift} = $baseShift;
1575 0 $$previewInfo{Relative} = 1;
1576 }
1577 # don't shift anything if relative flag set to zero (Pentax patch)
1578 } elsif (not defined $subdirInfo{Relative}) {
1579 # shift offset base if shifted in the original image or if FixBase
1580 # was used, but be careful of automatic FixBase with negative shifts
1581 # since they may lead to negative (invalid) offsets (casio_edit_problem.jpg)
1582 29 my $baseShift = $base - $subdirInfo{Base};
1583 29 ▶ if ($subdirInfo{AutoFix}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subdirInfo{'AutoFix'}) { } 1 28 29
elsif ($subdirInfo{'FixBase'} and $baseShift < 0 and !$subdirInfo{'MinOffset'} || $subdirInfo{'MinOffset'} + $baseShift < 0) { } 0 56 56
1584 1 $baseShift = 0;
1585 ▶ } elsif ($subdirInfo{FixBase} and $baseShift < 0 and
Condition33%3/9
$subdirInfo{"FixBase"} and $baseShift < 0 and !$subdirInfo{"MinOffset"} || $subdirInfo{"MinOffset"} + $baseShift < 0
!ll&&!rl&&r
2800
$subdirInfo{"FixBase"} and $baseShift < 0
!ll&&!rl&&r
2620
not $subdirInfo{"MinOffset"} or $subdirInfo{"MinOffset"} + $baseShift < 0
l!l&&r!l&&!r
000
MC/DC0%0/4
$subdirInfo{"FixBase"} and $baseShift < 0 and !$subdirInfo{"MinOffset"} || $subdirInfo{"MinOffset"} + $baseShift < 0
$subdirInfo{"FixBase"} $baseShift < 0 not $subdirInfo{"MinOffset"} $subdirInfo{"MinOffset"} + $baseShift < 0
Truth table40%2/5
A and B and not(C) or D
A= $subdirInfo{"FixBase"}B= $baseShift < 0C= not $subdirInfo{"MinOffset"}D= $subdirInfo{"MinOffset"} + $baseShift < 0
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1586 # allow negative base shift if offsets are bigger (PentaxOptioWP.jpg)
1587 (not $subdirInfo{MinOffset} or $subdirInfo{MinOffset} + $baseShift < 0))
1588 {
1589 0 my $fixBase = $et->Options('FixBase');
1590 0 ▶ if (not defined $fixBase) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $fixBase) { } 0 0 0
elsif ($fixBase eq '') { } 0 0 0
1591 0 ▶ my $str = $et->Options('IgnoreMinorErrors') ? 'ignored' : 'fix or ignore?';
Branch: 1 branch
BranchTrueFalseTotal
$et->Options('IgnoreMinorErrors') ? : 0 0 0
1592 0 $et->Error("MakerNotes offsets may be incorrect ($str)", 1);
1593 } elsif ($fixBase eq '') {
1594 0 $et->Warn('Fixed incorrect MakerNotes offsets');
1595 0 $baseShift = 0;
1596 }
1597 }
1598 29 $$makerFixup{Start} += $valLen + $loc;
1599 29 $$makerFixup{Shift} += $baseShift;
1600 # permanently fix makernote offset errors
1601 29 ▶ $$makerFixup{Shift} += $subdirInfo{FixedBy} || 0;
Condition50%1/2
$subdirInfo{'FixedBy'} || 0
l!l
029
MC/DC0%0/1
$subdirInfo{'FixedBy'} || 0
$subdirInfo{'FixedBy'}
Truth table50%1/2
A
A= $subdirInfo{'FixedBy'}
Aresult
11
00
1602 29 push @valFixups, $makerFixup;
1603 29 ▶ if ($previewInfo and not $$previewInfo{NoBaseShift}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($previewInfo and not $previewInfo->{"NoBaseShift"}) 4 25 29
Condition100%3/3
$previewInfo and not $previewInfo->{"NoBaseShift"}
!ll&&!rl&&r
2414
MC/DC100%2/2
$previewInfo and not $previewInfo->{"NoBaseShift"}
$previewInfo not $previewInfo->{"NoBaseShift"}
Truth table100%3/3
A and not(B)
A= $previewInfoB= not $previewInfo->{"NoBaseShift"}
ABresult
0X0
100
111
1604 4 $$previewInfo{BaseShift} = $baseShift;
1605 }
1606 }
1607 34 $newValuePt = \$newValue; # write new value
1608 }
1609 }
1610 42 SetByteOrder($saveOrder);
1611  
1612 # process existing subdirectory unless we are overwriting it entirely
1613 ▶ } elsif ($$newInfo{SubDirectory} and $isNew <= 0 and not $isOverwriting
Condition86%13/15
$newInfo->{"SubDirectory"} and $isNew <= 0 and not $isOverwriting and !defined($newInfo->{"Writable"}) || $newInfo->{"Writable"} and not $newInfo->{"ReadFromRAF"}
!ll&&!rl&&r
49190442
$newInfo->{"SubDirectory"} and $isNew <= 0 and not $isOverwriting and !defined($newInfo->{"Writable"}) || $newInfo->{"Writable"}
!ll&&!rl&&r
490910442
$newInfo->{"SubDirectory"} and $isNew <= 0 and not $isOverwriting
!ll&&!rl&&r
49090452
$newInfo->{"SubDirectory"} and $isNew <= 0
!ll&&!rl&&r
486544452
not defined $newInfo->{"Writable"} or $newInfo->{"Writable"}
l!l&&r!l&&!r
4162610
MC/DC66%4/6
$newInfo->{"SubDirectory"} and $isNew <= 0 and not $isOverwriting and !defined($newInfo->{"Writable"}) || $newInfo->{"Writable"} and not $newInfo->{"ReadFromRAF"}
$newInfo->{"SubDirectory"} $isNew <= 0 not $isOverwriting not defined $newInfo->{"Writable"} $newInfo->{"Writable"} not $newInfo->{"ReadFromRAF"}
Truth table62%5/8
A and B and not(C) and not(D) or E and not(F)
A= $newInfo->{"SubDirectory"}B= $isNew <= 0C= not $isOverwritingD= not defined $newInfo->{"Writable"}E= $newInfo->{"Writable"}F= not $newInfo->{"ReadFromRAF"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
11100X0
1111X00
1110100
1111X11
1110111
1614 # don't edit directory if Writable is set to 0
1615 and (not defined $$newInfo{Writable} or $$newInfo{Writable}) and
1616 not $$newInfo{ReadFromRAF})
1617 {
1618  
1619 442 my $subdir = $$newInfo{SubDirectory};
1620 442 ▶ if ($$newInfo{SubIFD}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($newInfo->{'SubIFD'}) { } 106 336 442
elsif (!defined($subdir->{'Start'}) || $subdir->{'Start'} =~ /\$valuePtr/ and $subdir->{'TagTable'}) { } 336 0 336
1621 #
1622 # rewrite existing sub IFD's
1623 #
1624 106 my $subTable = $tagTablePtr;
1625 106 ▶ if ($$subdir{TagTable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdir->{"TagTable"}) 15 91 106
1626 15 $subTable = Image::ExifTool::GetTagTable($$subdir{TagTable});
1627 }
1628 # determine directory name for this IFD
1629 106 ▶ my $subdirName = $$newInfo{Groups}{1} || $$newInfo{Name};
Condition33%1/3
$newInfo->{'Groups'}{'1'} || $newInfo->{'Name'}
l!l&&r!l&&!r
10600
MC/DC0%0/2
$newInfo->{'Groups'}{'1'} || $newInfo->{'Name'}
$newInfo->{'Groups'}{'1'} $newInfo->{'Name'}
Truth table33%1/3
A || B
A= $newInfo->{'Groups'}{'1'}B= $newInfo->{'Name'}
ABresult
1X1
011
000
1630 # all makernotes directory names must be 'MakerNotes'
1631 106 ▶ $subdirName = 'MakerNotes' if $$subTable{GROUPS}{0} eq 'MakerNotes';
Branch: 1 branch
BranchTrueFalseTotal
if $subTable->{"GROUPS"}{0} eq "MakerNotes" 8 98 106
1632 # must handle sub-IFD's specially since the values
1633 # are actually offsets to subdirectories
1634 106 ▶ unless ($readCount) { # can't have zero count
Branch: 1 branch
BranchTrueFalseTotal
unless ($readCount) 0 106 106
1635 0 ▶ return undef if $et->Error("$name entry $index has zero count", 2);
Branch: 1 branch
BranchTrueFalseTotal
if $et->Error("$name entry $index has zero count", 2) 0 0 0
1636 0 next;
1637 }
1638 106 my $writeCount = 0;
1639 106 my $i;
1640 106 $newValue = ''; # reset value because we regenerate it below
1641 106 ▶ for ($i=0; $i<$readCount; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $readCount) 109 106 215
1642 109 my $off = $i * $formatSize[$readFormat];
1643 109 my $val = ReadValue($valueDataPt, $valuePtr + $off,
1644 $readFormName, 1, $oldSize - $off);
1645 109 my $subdirStart = $val - $dataPos;
1646 109 my $subdirBase = $base;
1647 109 my $hdrLen;
1648 109 ▶ if (defined $$subdir{Start}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subdir->{"Start"}) 109 0 109
1649 #### eval Start ($val)
1650 109 my $newStart = eval $$subdir{Start};
1651 109 ▶ unless (Image::ExifTool::IsInt($newStart)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Image::ExifTool::IsInt($newStart)) 0 109 109
1652 0 $et->Error("Bad subdirectory start for $$newInfo{Name}");
1653 0 next;
1654 }
1655 109 $newStart -= $dataPos;
1656 109 $hdrLen = $newStart - $subdirStart;
1657 109 $subdirStart = $newStart;
1658 }
1659 109 ▶ if ($$subdir{Base}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdir->{"Base"}) 0 109 109
1660 0 my $start = $subdirStart + $dataPos;
1661 #### eval Base ($start,$base)
1662 0 $subdirBase += eval $$subdir{Base};
1663 }
1664 # add IFD number if more than one
1665 109 ▶ $subdirName =~ s/\d*$/$i/ if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 3 106 109
1666 my %subdirInfo = (
1667 Base => $subdirBase,
1668 DataPt => $dataPt,
1669 DataPos => $dataPos - $subdirBase + $base,
1670 DataLen => $dataLen,
1671 DirStart => $subdirStart,
1672 DirName => $subdirName,
1673 Name => $$newInfo{Name},
1674 109 ▶ TagInfo => $newInfo,
Branch: 1 branch
BranchTrueFalseTotal
$imageDataFlag eq 'Main' ? : 67 42 109
1675 Parent => $dirName,
1676 Fixup => Image::ExifTool::Fixup->new,
1677 RAF => $raf,
1678 Subdir => $subdir,
1679 # set ImageData only for 1st level SubIFD's
1680 ImageData=> $imageDataFlag eq 'Main' ? 'SubIFD' : undef,
1681 );
1682 # pass on header pointer only for certain sub IFD's
1683 109 ▶ $subdirInfo{HeaderPtr} = $$dirInfo{HeaderPtr} if $$newInfo{SubIFD} == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $newInfo->{"SubIFD"} == 2 55 54 109
1684 109 ▶ if ($$subdir{RelativeBase}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdir->{"RelativeBase"}) 0 109 109
1685 # apply one-time fixup if offsets are relative (Sony IDC hack)
1686 0 delete $subdirInfo{Fixup};
1687 0 delete $subdirInfo{ImageData};
1688 }
1689 # is the subdirectory outside our current data?
1690 109 ▶ if ($subdirStart < 0 or $subdirStart + 2 > $dataLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdirStart < 0 or $subdirStart + 2 > $dataLen) 15 94 109
Condition66%2/3
$subdirStart < 0 or $subdirStart + 2 > $dataLen
l!l&&r!l&&!r
01594
MC/DC50%1/2
$subdirStart < 0 or $subdirStart + 2 > $dataLen
$subdirStart < 0 $subdirStart + 2 > $dataLen
Truth table66%2/3
A or B
A= $subdirStart < 0B= $subdirStart + 2 > $dataLen
ABresult
1X1
011
000
1691 15 ▶ if ($raf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf) { } 15 0 15
1692 # reset SubDirectory buffer (we will load it later)
1693 15 my $buff = '';
1694 15 $subdirInfo{DataPt} = \$buff;
1695 15 $subdirInfo{DataLen} = 0;
1696 } else {
1697 0 my @err = ("Can't read $subdirName data", $inMakerNotes);
1698 0 ▶ if ($$subTable{VARS} and $$subTable{VARS}{MINOR_ERRORS}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subTable->{'VARS'} and $subTable->{'VARS'}{'MINOR_ERRORS'}) { } 0 0 0
elsif ($et->Error(@err)) { } 0 0 0
Condition0%0/3
$subTable->{"VARS"} and $subTable->{"VARS"}{"MINOR_ERRORS"}
!ll&&!rl&&r
000
MC/DC0%0/2
$subTable->{"VARS"} and $subTable->{"VARS"}{"MINOR_ERRORS"}
$subTable->{"VARS"} $subTable->{"VARS"}{"MINOR_ERRORS"}
Truth table0%0/3
A and B
A= $subTable->{"VARS"}B= $subTable->{"VARS"}{"MINOR_ERRORS"}
ABresult
0X0
100
111
1699 0 $et->Warn($err[0] . '. Ignored.');
1700 } elsif ($et->Error(@err)) {
1701 0 return undef;
1702 }
1703 0 next Entry; # don't write this directory
1704 }
1705 }
1706 109 my $subdirData = $et->WriteDirectory(\%subdirInfo, $subTable, $$subdir{WriteProc});
1707 109 ▶ unless (defined $subdirData) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $subdirData) 0 109 109
1708 # WriteDirectory should have issued an error, but check just in case
1709 0 ▶ $et->Error("Error writing $subdirName") unless $$et{VALUE}{Error};
Branch: 1 branch
BranchTrueFalseTotal
unless $et->{"VALUE"}{"Error"} 0 0 0
1710 0 return undef;
1711 }
1712 # add back original header if necessary (eg. Ricoh GR)
1713 109 ▶ if ($hdrLen and $hdrLen > 0 and $subdirStart <= $dataLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdrLen and $hdrLen > 0 and $subdirStart <= $dataLen) 0 109 109
Condition33%2/6
$hdrLen and $hdrLen > 0 and $subdirStart <= $dataLen
!ll&&!rl&&r
10900
$hdrLen and $hdrLen > 0
!ll&&!rl&&r
10900
MC/DC0%0/3
$hdrLen and $hdrLen > 0 and $subdirStart <= $dataLen
$hdrLen $hdrLen > 0 $subdirStart <= $dataLen
Truth table25%1/4
A and B and C
A= $hdrLenB= $hdrLen > 0C= $subdirStart <= $dataLen
ABCresult
0XX0
10X0
1100
1111
1714 0 $subdirData = substr($$dataPt, $subdirStart - $hdrLen, $hdrLen) . $subdirData;
1715 0 $subdirInfo{Fixup}{Start} += $hdrLen;
1716 }
1717 109 ▶ unless (length $subdirData) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $subdirData) 6 103 109
1718 6 ▶ next unless $inMakerNotes;
Branch: 1 branch
BranchTrueFalseTotal
unless $inMakerNotes 6 0 6
1719 # don't delete MakerNote Sub-IFD's, write empty IFD instead
1720 0 $subdirData = "\0" x 6;
1721 # reset SubIFD ImageData and Fixup just to be safe
1722 0 delete $subdirInfo{ImageData};
1723 0 delete $subdirInfo{Fixup};
1724 }
1725 # handle data blocks that we will transfer later
1726 103 ▶ if (ref $subdirInfo{ImageData}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $subdirInfo{"ImageData"}) 4 99 103
1727 4 push @imageData, @{$subdirInfo{ImageData}};
1728 4 $$origDirInfo{ImageData} = \@imageData;
1729 }
1730 # temporarily set value to subdirectory index
1731 # (will set to actual offset later when we know what it is)
1732 103 $newValue .= Set32u(0xfeedf00d);
1733 103 my ($offset, $where);
1734 103 ▶ if ($readCount > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($readCount > 1) { } 5 98 103
1735 5 $offset = length($valBuff) + $i * 4;
1736 5 $where = 'valBuff';
1737 } else {
1738 98 $offset = length($dirBuff) + 8;
1739 98 $where = 'dirBuff';
1740 }
1741 # add to list of subdirectories we will append later
1742 push @subdirs, {
1743 DataPt => \$subdirData,
1744 Table => $subTable,
1745 Fixup => $subdirInfo{Fixup},
1746 Offset => $offset,
1747 Where => $where,
1748 ImageData => $subdirInfo{ImageData},
1749 103 };
1750 103 ++$writeCount; # count number of subdirs written
1751 }
1752 106 ▶ next unless length $newValue;
Branch: 1 branch
BranchTrueFalseTotal
unless length $newValue 6 100 106
1753 # must change location of subdir offset if we deleted
1754 # a directory and only one remains
1755 100 ▶ if ($writeCount < $readCount and $writeCount == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeCount < $readCount and $writeCount == 1) 0 100 100
Condition33%1/3
$writeCount < $readCount and $writeCount == 1
!ll&&!rl&&r
10000
MC/DC0%0/2
$writeCount < $readCount and $writeCount == 1
$writeCount < $readCount $writeCount == 1
Truth table33%1/3
A and B
A= $writeCount < $readCountB= $writeCount == 1
ABresult
0X0
100
111
1756 0 $subdirs[-1]{Where} = 'dirBuff';
1757 0 $subdirs[-1]{Offset} = length($dirBuff) + 8;
1758 }
1759 # set new format to int32u for IFD
1760 100 ▶ $newFormName = $$newInfo{FixFormat} || 'int32u';
Condition100%2/2
$newInfo->{'FixFormat'} || 'int32u'
l!l
595
MC/DC100%1/1
$newInfo->{'FixFormat'} || 'int32u'
$newInfo->{'FixFormat'}
Truth table100%2/2
A
A= $newInfo->{'FixFormat'}
Aresult
11
00
1761 100 $newFormat = $formatNumber{$newFormName};
1762 100 $newValuePt = \$newValue;
1763  
1764 ▶ } elsif ((not defined $$subdir{Start} or
Condition50%3/6
!defined($subdir->{"Start"}) || $subdir->{"Start"} =~ /\$valuePtr/ and $subdir->{"TagTable"}
!ll&&!rl&&r
00336
not defined $subdir->{"Start"} or $subdir->{"Start"} =~ /\$valuePtr/
l!l&&r!l&&!r
33240
MC/DC0%0/3
!defined($subdir->{"Start"}) || $subdir->{"Start"} =~ /\$valuePtr/ and $subdir->{"TagTable"}
not defined $subdir->{"Start"} $subdir->{"Start"} =~ /\$valuePtr/ $subdir->{"TagTable"}
Truth table40%2/5
not(A) or B and C
A= not defined $subdir->{"Start"}B= $subdir->{"Start"} =~ /\$valuePtr/C= $subdir->{"TagTable"}
ABCresult
00X0
1X00
0100
1X11
0111
1765 $$subdir{Start} =~ /\$valuePtr/) and
1766 $$subdir{TagTable})
1767 {
1768 #
1769 # rewrite other existing subdirectories ('$valuePtr' type only)
1770 #
1771 # set subdirectory Start and Base
1772 336 my $subdirStart = $valuePtr;
1773 336 ▶ if ($$subdir{Start}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdir->{"Start"}) 4 332 336
1774 #### eval Start ($valuePtr)
1775 4 $subdirStart = eval $$subdir{Start};
1776 # must adjust directory size if start changed
1777 4 $oldSize -= $subdirStart - $valuePtr;
1778 }
1779 336 my $subdirBase = $base;
1780 336 ▶ if ($$subdir{Base}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdir->{"Base"}) 1 335 336
1781 1 my $start = $subdirStart + $valueDataPos;
1782 #### eval Base ($start,$base)
1783 1 $subdirBase += eval $$subdir{Base};
1784 }
1785 336 my $subFixup = Image::ExifTool::Fixup->new;
1786 my %subdirInfo = (
1787 Base => $subdirBase,
1788 DataPt => $valueDataPt,
1789 DataPos => $valueDataPos - $subdirBase + $base,
1790 DataLen => $valueDataLen,
1791 DirStart => $subdirStart,
1792 DirName => $$subdir{DirName},
1793 336 DirLen => $oldSize,
1794 Parent => $dirName,
1795 Fixup => $subFixup,
1796 RAF => $raf,
1797 TagInfo => $newInfo,
1798 );
1799 336 ▶ unless ($oldSize) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($oldSize) 0 336 336
1800 # replace with dummy data if empty to prevent WriteDirectory
1801 # routines from accessing data they shouldn't
1802 0 my $tmp = '';
1803 0 $subdirInfo{DataPt} = \$tmp;
1804 0 $subdirInfo{DataLen} = 0;
1805 0 $subdirInfo{DirStart} = 0;
1806 0 $subdirInfo{DataPos} += $subdirStart;
1807 }
1808 336 my $subTable = Image::ExifTool::GetTagTable($$subdir{TagTable});
1809 336 my $oldOrder = GetByteOrder();
1810 336 ▶ SetByteOrder($$subdir{ByteOrder}) if $$subdir{ByteOrder};
Branch: 1 branch
BranchTrueFalseTotal
if $subdir->{"ByteOrder"} 22 314 336
1811 336 $newValue = $et->WriteDirectory(\%subdirInfo, $subTable, $$subdir{WriteProc});
1812 336 SetByteOrder($oldOrder);
1813 336 ▶ if (defined $newValue) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newValue) { } 274 62 336
1814 274 my $hdrLen = $subdirStart - $valuePtr;
1815 274 ▶ if ($hdrLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdrLen) 3 271 274
1816 3 $newValue = substr($$valueDataPt, $valuePtr, $hdrLen) . $newValue;
1817 3 $$subFixup{Start} += $hdrLen;
1818 }
1819 274 $newValuePt = \$newValue;
1820 } else {
1821 62 $newValuePt = \$oldValue;
1822 }
1823 336 ▶ unless (length $$newValuePt) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$newValuePt) 1 335 336
1824 # don't delete a previously empty makernote directory
1825 1 ▶ next if $oldSize or not $inMakerNotes;
Branch: 1 branch
BranchTrueFalseTotal
if $oldSize or not $inMakerNotes 1 0 1
Condition33%1/3
$oldSize or not $inMakerNotes
l!l&&r!l&&!r
100
MC/DC0%0/2
$oldSize or not $inMakerNotes
$oldSize not $inMakerNotes
Truth table33%1/3
A or not(B)
A= $oldSizeB= not $inMakerNotes
ABresult
1X1
011
000
1826 }
1827 335 ▶ if ($$subFixup{Pointers} and $subdirInfo{Base} == $base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subFixup->{'Pointers'} and $subdirInfo{'Base'} == $base) { } 5 330 335
Condition100%3/3
$subFixup->{"Pointers"} and $subdirInfo{"Base"} == $base
!ll&&!rl&&r
32915
MC/DC100%2/2
$subFixup->{"Pointers"} and $subdirInfo{"Base"} == $base
$subFixup->{"Pointers"} $subdirInfo{"Base"} == $base
Truth table100%3/3
A and B
A= $subFixup->{"Pointers"}B= $subdirInfo{"Base"} == $base
ABresult
0X0
100
111
1828 5 $$subFixup{Start} += length $valBuff;
1829 5 push @valFixups, $subFixup;
1830 } else {
1831 # apply fixup in case we added a header ($hdrLen above)
1832 330 $subFixup->ApplyFixup(\$newValue);
1833 }
1834 }
1835  
1836 } elsif ($$newInfo{OffsetPair}) {
1837 #
1838 # keep track of offsets
1839 #
1840 158 ▶ my $dataTag = $$newInfo{DataTag} || '';
Condition100%2/2
$newInfo->{'DataTag'} || ''
l!l
11939
MC/DC100%1/1
$newInfo->{'DataTag'} || ''
$newInfo->{'DataTag'}
Truth table100%2/2
A
A= $newInfo->{'DataTag'}
Aresult
11
00
1841 158 ▶ if ($dataTag eq 'CanonVRD') {
Branch: 2 branches
BranchTrueFalseTotal
if ($dataTag eq 'CanonVRD') { } 10 148 158
elsif ($dataTag eq 'OriginalDecisionData') { } 7 141 148
1842 # must decide now if we will write CanonVRD information
1843 10 my $hasVRD;
1844 10 ▶ if ($$et{NEW_VALUE}{$Image::ExifTool::Extra{CanonVRD}}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($et->{'NEW_VALUE'}{$Image::ExifTool::Extra{'CanonVRD'}}) { } 1 9 10
elsif ($et->{'DEL_GROUP'}{'CanonVRD'} or $et->{'DEL_GROUP'}{'Trailer'}) { } 0 9 9
1845 # adding or deleting as a block
1846 1 ▶ $hasVRD = $et->GetNewValue('CanonVRD') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$et->GetNewValue('CanonVRD') ? : 1 0 1
1847 ▶ } elsif ($$et{DEL_GROUP}{CanonVRD} or
Condition33%1/3
$et->{"DEL_GROUP"}{"CanonVRD"} or $et->{"DEL_GROUP"}{"Trailer"}
l!l&&r!l&&!r
009
MC/DC0%0/2
$et->{"DEL_GROUP"}{"CanonVRD"} or $et->{"DEL_GROUP"}{"Trailer"}
$et->{"DEL_GROUP"}{"CanonVRD"} $et->{"DEL_GROUP"}{"Trailer"}
Truth table33%1/3
A or B
A= $et->{"DEL_GROUP"}{"CanonVRD"}B= $et->{"DEL_GROUP"}{"Trailer"}
ABresult
1X1
011
000
1848 $$et{DEL_GROUP}{Trailer})
1849 {
1850 0 $hasVRD = 0; # deleting as a group
1851 } else {
1852 9 $hasVRD = ($$newValuePt ne "\0\0\0\0");
1853 }
1854 10 ▶ if ($hasVRD) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hasVRD) { } 1 9 10
1855 # add a fixup, and set this offset later
1856 1 $dirFixup->AddFixup(length($dirBuff) + 8, $dataTag);
1857 } else {
1858 # there is (or will soon be) no VRD information, so set pointer to zero
1859 9 $newValue = "\0" x length($$newValuePt);
1860 9 $newValuePt = \$newValue;
1861 }
1862 } elsif ($dataTag eq 'OriginalDecisionData') {
1863 # handle Canon OriginalDecisionData (no associated length tag)
1864 # - I'm going out of my way here to preserve data which is
1865 # invalidated anyway by our edits
1866 7 my $odd;
1867 7 my $oddInfo = Image::ExifTool::GetCompositeTagInfo('OriginalDecisionData');
1868 7 ▶ if ($oddInfo and $$et{NEW_VALUE}{$oddInfo}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($oddInfo and $et->{'NEW_VALUE'}{$oddInfo}) { } 1 6 7
elsif ($$newValuePt ne "\000\000\000\000") { } 1 5 6
Condition66%2/3
$oddInfo and $et->{"NEW_VALUE"}{$oddInfo}
!ll&&!rl&&r
061
MC/DC50%1/2
$oddInfo and $et->{"NEW_VALUE"}{$oddInfo}
$oddInfo $et->{"NEW_VALUE"}{$oddInfo}
Truth table66%2/3
A and B
A= $oddInfoB= $et->{"NEW_VALUE"}{$oddInfo}
ABresult
0X0
100
111
1869 1 $odd = $et->GetNewValue($dataTag);
1870 1 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 1 1
1871 0 ▶ print $out " - $dirName:$dataTag\n" if $$newValuePt ne "\0\0\0\0";
Branch: 1 branch
BranchTrueFalseTotal
if $$newValuePt ne "\0\0\0\0" 0 0 0
1872 0 ▶ print $out " + $dirName:$dataTag\n" if $odd;
Branch: 1 branch
BranchTrueFalseTotal
if $odd 0 0 0
1873 }
1874 1 ++$$et{CHANGED};
1875 } elsif ($$newValuePt ne "\0\0\0\0") {
1876 1 ▶ if (length($$newValuePt) == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$newValuePt == 4) { } 1 0 1
1877 1 require Image::ExifTool::Canon;
1878 1 my $offset = Get32u($newValuePt,0);
1879 # absolute offset in JPEG images only
1880 1 ▶ $offset += $base unless $$et{FILE_TYPE} eq 'JPEG';
Branch: 1 branch
BranchTrueFalseTotal
unless $et->{"FILE_TYPE"} eq "JPEG" 0 1 1
1881 1 $odd = Image::ExifTool::Canon::ReadODD($et, $offset);
1882 1 ▶ $odd = $$odd if ref $odd;
Branch: 1 branch
BranchTrueFalseTotal
if ref $odd 1 0 1
1883 } else {
1884 0 $et->Error("Invalid $$newInfo{Name}",1);
1885 }
1886 }
1887 7 ▶ if ($odd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($odd) { } 2 5 7
1888 2 my $newOffset = length($valBuff);
1889 # (ODD offset is absolute in JPEG, so add base offset!)
1890 2 ▶ $newOffset += $base if $$et{FILE_TYPE} eq 'JPEG';
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"FILE_TYPE"} eq "JPEG" 1 1 2
1891 2 $newValue = Set32u($newOffset);
1892 2 $dirFixup->AddFixup(length($dirBuff) + 8, $dataTag);
1893 2 $valBuff .= $odd; # add original decision data
1894 } else {
1895 5 $newValue = "\0\0\0\0";
1896 }
1897 7 $newValuePt = \$newValue;
1898 } else {
1899 141 my $offsetInfo = $offsetInfo[$ifd];
1900 # save original values (for updating TIFF_END later)
1901 141 my @vals;
1902 141 ▶ if ($isNew <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isNew <= 0) 137 4 141
1903 137 my $oldOrder = GetByteOrder();
1904 # Minolta A200 stores these in the wrong byte order!
1905 137 ▶ SetByteOrder($$newInfo{ByteOrder}) if $$newInfo{ByteOrder};
Branch: 1 branch
BranchTrueFalseTotal
if $newInfo->{"ByteOrder"} 0 137 137
1906 137 @vals = ReadValue(\$oldValue, 0, $readFormName, $readCount, $oldSize);
1907 137 SetByteOrder($oldOrder);
1908 137 ▶ $validateInfo{$newID} = [$newInfo, join(' ',@vals)] unless $$newInfo{IsOffset};
Branch: 1 branch
BranchTrueFalseTotal
unless $newInfo->{"IsOffset"} 68 69 137
1909 }
1910 # only support int32 pointers (for now)
1911 141 ▶ if ($formatSize[$newFormat] != 4 and $$newInfo{IsOffset}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::Exif::formatSize[$newFormat] != 4 and $newInfo->{"IsOffset"}) 0 141 141
Condition33%1/3
$Image::ExifTool::Exif::formatSize[$newFormat] != 4 and $newInfo->{"IsOffset"}
!ll&&!rl&&r
14100
MC/DC0%0/2
$Image::ExifTool::Exif::formatSize[$newFormat] != 4 and $newInfo->{"IsOffset"}
$Image::ExifTool::Exif::formatSize[$newFormat] != 4 $newInfo->{"IsOffset"}
Truth table33%1/3
A and B
A= $Image::ExifTool::Exif::formatSize[$newFormat] != 4B= $newInfo->{"IsOffset"}
ABresult
0X0
100
111
1912 0 ▶ $isNew > 0 and warn("Internal error (Offset not int32)"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
$isNew > 0 and warn("Internal error (Offset not int32)"), (return undef) 0 0 0
1913 0 ▶ $newCount != $readCount and warn("Wrong count!"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
$newCount != $readCount and warn("Wrong count!"), (return undef) 0 0 0
1914 # change to int32
1915 0 $newFormName = 'int32u';
1916 0 $newFormat = $formatNumber{$newFormName};
1917 0 $newValue = WriteValue(join(' ',@vals), $newFormName, $newCount);
1918 0 ▶ unless (defined $newValue) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $newValue) 0 0 0
1919 0 warn "Internal error writing offsets for $$newInfo{Name}\n";
1920 0 return undef;
1921 }
1922 0 $newValuePt = \$newValue;
1923 }
1924 141 ▶ $offsetInfo or $offsetInfo = $offsetInfo[$ifd] = { };
Branch: 1 branch
BranchTrueFalseTotal
$offsetInfo or $offsetInfo = ($offsetInfo[$ifd] = {}) 71 70 141
1925 # save location of valuePtr in new directory
1926 # (notice we add 10 instead of 8 for valuePtr because
1927 # we will put a 2-byte count at start of directory later)
1928 141 my $ptr = $newStart + length($dirBuff) + 10;
1929 141 ▶ $newCount or $newCount = 1; # make sure count is set for offsetInfo
Branch: 1 branch
BranchTrueFalseTotal
$newCount or $newCount = 1 141 0 141
1930 # save value pointer and value count for each tag
1931 141 $$offsetInfo{$newID} = [$newInfo, $ptr, $newCount, \@vals, $newFormat];
1932 }
1933  
1934 } elsif ($$newInfo{DataMember}) {
1935  
1936 # save any necessary data members (Make, Model, etc)
1937 272 my $formatStr = $newFormName;
1938 272 my $count = $newCount;
1939 # change to specified format if necessary
1940 272 ▶ if ($$newInfo{Format} and $$newInfo{Format} ne $formatStr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{"Format"} and $newInfo->{"Format"} ne $formatStr) 0 272 272
Condition33%1/3
$newInfo->{"Format"} and $newInfo->{"Format"} ne $formatStr
!ll&&!rl&&r
27200
MC/DC0%0/2
$newInfo->{"Format"} and $newInfo->{"Format"} ne $formatStr
$newInfo->{"Format"} $newInfo->{"Format"} ne $formatStr
Truth table33%1/3
A and B
A= $newInfo->{"Format"}B= $newInfo->{"Format"} ne $formatStr
ABresult
0X0
100
111
1941 0 $formatStr = $$newInfo{Format};
1942 0 my $format = $formatNumber{$formatStr};
1943 # adjust number of items for new format size
1944 0 ▶ $count = int(length($$newValuePt) / $formatSize[$format]) if $format;
Branch: 1 branch
BranchTrueFalseTotal
if $format 0 0 0
1945 }
1946 272 my $val = ReadValue($newValuePt,0,$formatStr,$count,length($$newValuePt));
1947 272 my $conv = $$newInfo{RawConv};
1948 272 ▶ if ($conv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conv) { } 272 0 272
1949 # let the RawConv store the (possibly converted) data member
1950 272 ▶ if (ref $conv eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $conv eq 'CODE') { } 0 272 272
1951 0 &$conv($val, $et);
1952 } else {
1953 272 my ($priority, @grps);
1954 272 my ($self, $tag, $tagInfo) = ($et, $$newInfo{Name}, $newInfo);
1955 #### eval RawConv ($self, $val, $tag, $tagInfo, $priority, @grps)
1956 272 eval $conv;
1957 }
1958 } else {
1959 0 $$et{$$newInfo{DataMember}} = $val;
1960 }
1961 }
1962 }
1963 #
1964 # write out the directory entry
1965 #
1966 5396 my $newSize = length($$newValuePt);
1967 5396 my $fsize = $formatSize[$newFormat];
1968 5396 my $offsetVal;
1969 # set proper count
1970 5396 ▶ $newCount = int(($newSize + $fsize - 1) / $fsize) unless $oldInfo and $$oldInfo{FixedSize};
Branch: 1 branch
BranchTrueFalseTotal
unless $oldInfo and $oldInfo->{"FixedSize"} 5396 0 5396
Condition66%2/3
$oldInfo and $oldInfo->{"FixedSize"}
!ll&&!rl&&r
65447420
MC/DC0%0/2
$oldInfo and $oldInfo->{"FixedSize"}
$oldInfo $oldInfo->{"FixedSize"}
Truth table66%2/3
A and B
A= $oldInfoB= $oldInfo->{"FixedSize"}
ABresult
0X0
100
111
1971 5396 ▶ if ($saveForValidate{$newID} and $tagTablePtr eq \%Image::ExifTool::Exif::Main) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::Exif::saveForValidate{$newID} and $tagTablePtr eq \%Image::ExifTool::Exif::Main) 153 5243 5396
Condition100%3/3
$Image::ExifTool::Exif::saveForValidate{$newID} and $tagTablePtr eq \%Image::ExifTool::Exif::Main
!ll&&!rl&&r
521726153
MC/DC100%2/2
$Image::ExifTool::Exif::saveForValidate{$newID} and $tagTablePtr eq \%Image::ExifTool::Exif::Main
$Image::ExifTool::Exif::saveForValidate{$newID} $tagTablePtr eq \%Image::ExifTool::Exif::Main
Truth table100%3/3
A and B
A= $Image::ExifTool::Exif::saveForValidate{$newID}B= $tagTablePtr eq \%Image::ExifTool::Exif::Main
ABresult
0X0
100
111
1972 153 my @vals = ReadValue(\$newValue, 0, $newFormName, $newCount, $newSize);
1973 153 $validateInfo{$newID} = join ' ',@vals;
1974 }
1975 5396 ▶ if ($newSize > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newSize > 4) { } 2447 2949 5396
1976 # zero-pad to an even number of bytes (required by EXIF standard)
1977 # and make sure we are a multiple of the format size
1978 2447 ▶ while ($newSize & 0x01 or $newSize < $newCount * $fsize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newSize & 1 or $newSize < $newCount * $fsize) 241 2447 2688
Condition100%3/3
$newSize & 1 or $newSize < $newCount * $fsize
l!l&&r!l&&!r
23742447
MC/DC100%2/2
$newSize & 1 or $newSize < $newCount * $fsize
$newSize & 1 $newSize < $newCount * $fsize
Truth table100%3/3
A or B
A= $newSize & 1B= $newSize < $newCount * $fsize
ABresult
1X1
011
000
1979 241 $$newValuePt .= "\0";
1980 241 ++$newSize;
1981 }
1982 2447 my $entryBased;
1983 2447 ▶ if ($$dirInfo{EntryBased} or ($newInfo and $$newInfo{EntryBased})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirInfo->{'EntryBased'} or $newInfo and $newInfo->{'EntryBased'}) { } 5 2442 2447
Condition50%3/6
$dirInfo->{"EntryBased"} or $newInfo and $newInfo->{"EntryBased"}
l!l&&r!l&&!r
502442
$newInfo and $newInfo->{"EntryBased"}
!ll&&!rl&&r
024420
MC/DC33%1/3
$dirInfo->{"EntryBased"} or $newInfo and $newInfo->{"EntryBased"}
$dirInfo->{"EntryBased"} $newInfo $newInfo->{"EntryBased"}
Truth table50%2/4
A or B and C
A= $dirInfo->{"EntryBased"}B= $newInfoC= $newInfo->{"EntryBased"}
ABCresult
1XX1
0111
00X0
0100
1984 5 $entryBased = 1;
1985 5 $offsetVal = Set32u(length($valBuff) - length($dirBuff));
1986 } else {
1987 2442 $offsetVal = Set32u(length $valBuff);
1988 }
1989 2447 my ($dataTag, $putFirst);
1990 2447 ▶ ($dataTag, $putFirst) = @$newInfo{'DataTag','PutFirst'} if $newInfo;
Branch: 1 branch
BranchTrueFalseTotal
if $newInfo 2447 0 2447
1991 2447 ▶ if ($dataTag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataTag) 2 2445 2447
1992 2 ▶ if ($dataTag eq 'PreviewImage' and ($$et{FILE_TYPE} eq 'JPEG' or
Branch: 2 branches
BranchTrueFalseTotal
if ($dataTag eq 'PreviewImage' and $et->{'FILE_TYPE'} eq 'JPEG' || $et->{'GENERATE_PREVIEW_INFO'}) { } 1 1 2
elsif ($dataTag eq 'LeicaTrailer' and $et->{'LeicaTrailer'}) { } 0 2 2
Condition50%3/6
$dataTag eq "PreviewImage" and $et->{"FILE_TYPE"} eq "JPEG" || $et->{"GENERATE_PREVIEW_INFO"}
!ll&&!rl&&r
101
$et->{"FILE_TYPE"} eq "JPEG" or $et->{"GENERATE_PREVIEW_INFO"}
l!l&&r!l&&!r
100
MC/DC33%1/3
$dataTag eq "PreviewImage" and $et->{"FILE_TYPE"} eq "JPEG" || $et->{"GENERATE_PREVIEW_INFO"}
$dataTag eq "PreviewImage" $et->{"FILE_TYPE"} eq "JPEG" $et->{"GENERATE_PREVIEW_INFO"}
Truth table50%2/4
A and B or C
A= $dataTag eq "PreviewImage"B= $et->{"FILE_TYPE"} eq "JPEG"C= $et->{"GENERATE_PREVIEW_INFO"}
ABCresult
0XX0
1000
11X1
1011
1993 $$et{GENERATE_PREVIEW_INFO}))
1994 {
1995 # hold onto the PreviewImage until we can determine if it fits
1996 $$et{PREVIEW_INFO} or $$et{PREVIEW_INFO} = {
1997 1 ▶ Data => $$newValuePt,
Branch: 1 branch
BranchTrueFalseTotal
$et->{"PREVIEW_INFO"} or $et->{"PREVIEW_INFO"} = {"Data", $$newValuePt, "Fixup", "Image::ExifTool::Fixup"->new} 0 1 1
1998 Fixup => Image::ExifTool::Fixup->new,
1999 };
2000 1 ▶ $$et{PREVIEW_INFO}{ChangeBase} = 1 if $$newInfo{ChangeBase};
Branch: 1 branch
BranchTrueFalseTotal
if $newInfo->{"ChangeBase"} 0 1 1
2001 1 ▶ if ($$newInfo{IsOffset} and $$newInfo{IsOffset} eq '2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{"IsOffset"} and $newInfo->{"IsOffset"} eq 2) 0 1 1
Condition33%1/3
$newInfo->{"IsOffset"} and $newInfo->{"IsOffset"} eq 2
!ll&&!rl&&r
100
MC/DC0%0/2
$newInfo->{"IsOffset"} and $newInfo->{"IsOffset"} eq 2
$newInfo->{"IsOffset"} $newInfo->{"IsOffset"} eq 2
Truth table33%1/3
A and B
A= $newInfo->{"IsOffset"}B= $newInfo->{"IsOffset"} eq 2
ABresult
0X0
100
111
2002 0 $$et{PREVIEW_INFO}{NoBaseShift} = 1;
2003 }
2004 # use original preview size if we will attempt to load it later
2005 1 ▶ $newCount = $oldCount if $$newValuePt eq 'LOAD_PREVIEW';
Branch: 1 branch
BranchTrueFalseTotal
if $$newValuePt eq "LOAD_PREVIEW" 0 1 1
2006 1 $$newValuePt = '';
2007 ▶ } elsif ($dataTag eq 'LeicaTrailer' and $$et{LeicaTrailer}) {
Condition33%1/3
$dataTag eq "LeicaTrailer" and $et->{"LeicaTrailer"}
!ll&&!rl&&r
100
MC/DC0%0/2
$dataTag eq "LeicaTrailer" and $et->{"LeicaTrailer"}
$dataTag eq "LeicaTrailer" $et->{"LeicaTrailer"}
Truth table33%1/3
A and B
A= $dataTag eq "LeicaTrailer"B= $et->{"LeicaTrailer"}
ABresult
0X0
100
111
2008 0 $$newValuePt = '';
2009 }
2010 }
2011 2447 ▶ if ($putFirst and $$dirInfo{HeaderPtr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($putFirst and $dirInfo->{'HeaderPtr'}) { } 1 2446 2447
Condition66%2/3
$putFirst and $dirInfo->{"HeaderPtr"}
!ll&&!rl&&r
244601
MC/DC50%1/2
$putFirst and $dirInfo->{"HeaderPtr"}
$putFirst $dirInfo->{"HeaderPtr"}
Truth table66%2/3
A and B
A= $putFirstB= $dirInfo->{"HeaderPtr"}
ABresult
0X0
100
111
2012 1 my $hdrPtr = $$dirInfo{HeaderPtr};
2013 # place this value immediately after the TIFF header (eg. IIQ maker notes)
2014 1 $offsetVal = Set32u(length $$hdrPtr);
2015 1 $$hdrPtr .= $$newValuePt;
2016 } else {
2017 2446 $valBuff .= $$newValuePt; # add value data to buffer
2018 # must save a fixup pointer for every pointer in the directory
2019 2446 ▶ if ($entryBased) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entryBased) { } 5 2441 2446
2020 5 ▶ $entryBasedFixup or $entryBasedFixup = Image::ExifTool::Fixup->new;
Branch: 1 branch
BranchTrueFalseTotal
$entryBasedFixup or $entryBasedFixup = "Image::ExifTool::Fixup"->new 4 1 5
2021 5 $entryBasedFixup->AddFixup(length($dirBuff) + 8, $dataTag);
2022 } else {
2023 2441 $dirFixup->AddFixup(length($dirBuff) + 8, $dataTag);
2024 }
2025 }
2026 } else {
2027 2949 $offsetVal = $$newValuePt; # save value in offset if 4 bytes or less
2028 # must pad value with zeros if less than 4 bytes
2029 2949 ▶ $newSize < 4 and $offsetVal .= "\0" x (4 - $newSize);
Branch: 1 branch
BranchTrueFalseTotal
$newSize < 4 and $offsetVal .= "\0" x (4 - $newSize) 1910 1039 2949
2030 }
2031 # write the directory entry
2032 5396 $dirBuff .= Set16u($newID) . Set16u($newFormat) .
2033 Set32u($newCount) . $offsetVal;
2034 # update flag to keep track of mandatory tags
2035 5396 ▶ while (defined $allMandatory) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $allMandatory) 374 5219 5593
2036 374 ▶ if (defined $$mandatory{$newID}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mandatory->{$newID}) 186 188 374
2037 # values must correspond to mandatory values
2038 186 ▶ my $form = $$newInfo{Format} || $newFormName;
Condition66%2/3
$newInfo->{'Format'} || $newFormName
l!l&&r!l&&!r
111750
MC/DC0%0/2
$newInfo->{'Format'} || $newFormName
$newInfo->{'Format'} $newFormName
Truth table66%2/3
A || B
A= $newInfo->{'Format'}B= $newFormName
ABresult
1X1
011
000
2039 186 my $mandVal = WriteValue($$mandatory{$newID}, $form, $newCount);
2040 186 ▶ if (defined $mandVal and $mandVal eq $$newValuePt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mandVal and $mandVal eq $$newValuePt) 177 9 186
Condition66%2/3
defined $mandVal and $mandVal eq $$newValuePt
!ll&&!rl&&r
09177
MC/DC50%1/2
defined $mandVal and $mandVal eq $$newValuePt
defined $mandVal $mandVal eq $$newValuePt
Truth table66%2/3
A and B
A= defined $mandValB= $mandVal eq $$newValuePt
ABresult
0X0
100
111
2041 177 ++$allMandatory; # count mandatory tags
2042 177 last;
2043 }
2044 }
2045 197 undef $deleteAll;
2046 197 undef $allMandatory;
2047 }
2048 }
2049 383 ▶ if (%validateInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if (%validateInfo) 80 303 383
2050 80 ValidateImageData($et, \%validateInfo, $dirName, 1);
2051 80 undef %validateInfo;
2052 }
2053 383 ▶ if ($ignoreCount) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ignoreCount) 0 383 383
2054 0 ▶ my $y = $ignoreCount > 1 ? 'ies' : 'y';
Branch: 1 branch
BranchTrueFalseTotal
$ignoreCount > 1 ? : 0 0 0
2055 0 ▶ my $verb = $$dirInfo{FixBase} ? 'Ignored' : 'Removed';
Branch: 1 branch
BranchTrueFalseTotal
$dirInfo->{'FixBase'} ? : 0 0 0
2056 0 $et->Warn("$verb $ignoreCount invalid entr$y from $name", 1);
2057 }
2058 383 ▶ if ($fixCount) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fixCount) 0 383 383
2059 0 ▶ my $s = $fixCount > 1 ? 's' : '';
Branch: 1 branch
BranchTrueFalseTotal
$fixCount > 1 ? : 0 0 0
2060 0 $et->Warn("Fixed invalid count$s for $fixCount $name tag$s", 1);
2061 }
2062 #..............................................................................
2063 # write directory counts and nextIFD pointer and add value data to end of IFD
2064 #
2065 # determine now if there is or will be another IFD after this one
2066 383 my $nextIfdOffset;
2067 383 ▶ if ($dirEnd + 4 <= $dataLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirEnd + 4 <= $dataLen) { } 292 91 383
2068 292 $nextIfdOffset = Get32u($dataPt, $dirEnd);
2069 } else {
2070 91 $nextIfdOffset = 0;
2071 }
2072 my $isNextIFD = ($$dirInfo{Multi} and ($nextIfdOffset or
2073 # account for the case where we will create the next IFD
2074 # (IFD1 only, but not in TIFF-format images)
2075 ($dirName eq 'IFD0' and $$et{ADD_DIRS}{'IFD1'} and
2076 383 ▶ $$et{FILE_TYPE} ne 'TIFF')));
Condition91%11/12
$dirInfo->{'Multi'} && ($nextIfdOffset || $dirName eq 'IFD0' && $et->{'ADD_DIRS'}{'IFD1'} && $et->{'FILE_TYPE'} ne 'TIFF')
!ll&&!rl&&r
21711749
$nextIfdOffset or $dirName eq "IFD0" and $et->{"ADD_DIRS"}{"IFD1"} and $et->{"FILE_TYPE"} ne "TIFF"
l!l&&r!l&&!r
427117
$dirName eq "IFD0" and $et->{"ADD_DIRS"}{"IFD1"} and $et->{"FILE_TYPE"} ne "TIFF"
!ll&&!rl&&r
11707
$dirName eq "IFD0" and $et->{"ADD_DIRS"}{"IFD1"}
!ll&&!rl&&r
44737
MC/DC80%4/5
$dirInfo->{'Multi'} && ($nextIfdOffset || $dirName eq 'IFD0' && $et->{'ADD_DIRS'}{'IFD1'} && $et->{'FILE_TYPE'} ne 'TIFF')
$dirInfo->{'Multi'} $nextIfdOffset $dirName eq "IFD0" $et->{"ADD_DIRS"}{"IFD1"} $et->{"FILE_TYPE"} ne "TIFF"
Truth table83%5/6
A && B or C and D and E
A= $dirInfo->{'Multi'}B= $nextIfdOffsetC= $dirName eq "IFD0"D= $et->{"ADD_DIRS"}{"IFD1"}E= $et->{"FILE_TYPE"} ne "TIFF"
ABCDEresult
0XXXX0
100XX0
1010X0
101100
11XXX1
101111
2077 # calculate number of entries in new directory
2078 383 my $newEntries = length($dirBuff) / 12;
2079 # delete entire directory if we deleted a tag and only mandatory tags remain or we
2080 # attempted to create a directory with only mandatory tags and there is no nextIFD
2081 383 ▶ if ($allMandatory and not $isNextIFD and ($newEntries < $numEntries or $numEntries == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allMandatory and not $isNextIFD and $newEntries < $numEntries || $numEntries == 0) 14 369 383
Condition100%9/9
$allMandatory and not $isNextIFD and $newEntries < $numEntries || $numEntries == 0
!ll&&!rl&&r
366314
$allMandatory and not $isNextIFD
!ll&&!rl&&r
365117
$newEntries < $numEntries or $numEntries == 0
l!l&&r!l&&!r
1043
MC/DC100%4/4
$allMandatory and not $isNextIFD and $newEntries < $numEntries || $numEntries == 0
$allMandatory not $isNextIFD $newEntries < $numEntries $numEntries == 0
Truth table100%5/5
A and not(B) and C or D
A= $allMandatoryB= not $isNextIFDC= $newEntries < $numEntriesD= $numEntries == 0
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2082 14 $newEntries = 0;
2083 14 $dirBuff = '';
2084 14 $valBuff = '';
2085 14 undef $dirFixup; # no fixups in this directory
2086 14 ▶ ++$deleteAll if defined $deleteAll;
Branch: 1 branch
BranchTrueFalseTotal
if defined $deleteAll 13 1 14
2087 14 ▶ $verbose > 1 and print $out " - $allMandatory mandatory tag(s)\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print $out " - $allMandatory mandatory tag(s)\n" 0 14 14
2088 14 $$et{CHANGED} -= $addMandatory; # didn't change these after all
2089 }
2090 383 ▶ if ($ifd and not $newEntries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ifd and not $newEntries) 1 382 383
Condition100%3/3
$ifd and not $newEntries
!ll&&!rl&&r
335471
MC/DC100%2/2
$ifd and not $newEntries
$ifd not $newEntries
Truth table100%3/3
A and not(B)
A= $ifdB= not $newEntries
ABresult
0X0
100
111
2091 1 ▶ $verbose and print $out " Deleting IFD1\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting IFD1\n" 0 1 1
2092 1 last; # don't write IFD1 if empty
2093 }
2094 # apply one-time fixup for entry-based offsets
2095 382 ▶ if ($entryBasedFixup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entryBasedFixup) 1 381 382
2096 1 $$entryBasedFixup{Shift} = length($dirBuff) + 4;
2097 1 $entryBasedFixup->ApplyFixup(\$dirBuff);
2098 1 undef $entryBasedFixup;
2099 }
2100 # initialize next IFD pointer to zero
2101 382 my $nextIFD = Set32u(0);
2102 # some cameras use a different amount of padding after the makernote IFD
2103 382 ▶ if ($dirName eq 'MakerNotes' and $$dirInfo{Parent} =~ /^(ExifIFD|IFD0)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName eq "MakerNotes" and $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/) 56 326 382
Condition100%3/3
$dirName eq "MakerNotes" and $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/
!ll&&!rl&&r
3081856
MC/DC100%2/2
$dirName eq "MakerNotes" and $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/
$dirName eq "MakerNotes" $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/
Truth table100%3/3
A and B
A= $dirName eq "MakerNotes"B= $dirInfo->{"Parent"} =~ /^(ExifIFD|IFD0)$/
ABresult
0X0
100
111
2104 56 my ($rel, $pad) = Image::ExifTool::MakerNotes::GetMakerNoteOffset($et);
2105 56 ▶ $nextIFD = "\0" x $pad if defined $pad and ($pad==0 or ($pad>4 and $pad<=32));
Branch: 1 branch
BranchTrueFalseTotal
if defined $pad and $pad == 0 || $pad > 4 && $pad <= 32 13 43 56
Condition77%7/9
defined $pad and $pad == 0 || $pad > 4 && $pad <= 32
!ll&&!rl&&r
04313
$pad == 0 or $pad > 4 and $pad <= 32
l!l&&r!l&&!r
7643
$pad > 4 and $pad <= 32
!ll&&!rl&&r
4306
MC/DC50%2/4
defined $pad and $pad == 0 || $pad > 4 && $pad <= 32
defined $pad $pad == 0 $pad > 4 $pad <= 32
Truth table60%3/5
A and B or C and D
A= defined $padB= $pad == 0C= $pad > 4D= $pad <= 32
ABCDresult
0XXX0
100X0
10100
11XX1
10111
2106 }
2107 # add directory entry count to start of IFD and next IFD pointer to end
2108 382 $newData .= Set16u($newEntries) . $dirBuff . $nextIFD;
2109 # get position of value data in newData
2110 382 my $valPos = length($newData);
2111 # go back now and set next IFD pointer if this isn't the first IFD
2112 382 ▶ if ($nextIfdPos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nextIfdPos) 47 335 382
2113 # set offset to next IFD
2114 47 Set32u($newStart, \$newData, $nextIfdPos);
2115 47 $fixup->AddFixup($nextIfdPos,'NextIFD'); # add fixup for this offset in newData
2116 }
2117 # remember position of 'next IFD' pointer so we can set it next time around
2118 382 ▶ $nextIfdPos = length($nextIFD) ? $valPos - length($nextIFD) : undef;
Branch: 1 branch
BranchTrueFalseTotal
length $nextIFD ? : 375 7 382
2119 # add value data after IFD
2120 382 $newData .= $valBuff;
2121 #
2122 # add any subdirectories, adding fixup information
2123 #
2124 382 ▶ if (@subdirs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@subdirs) 122 260 382
2125 122 my $subdir;
2126 122 foreach $subdir (@subdirs) {
2127 139 my $len = length($newData); # position of subdirectory in data
2128 139 my $subdirFixup = $$subdir{Fixup};
2129 139 ▶ if ($subdirFixup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdirFixup) 139 0 139
2130 139 $$subdirFixup{Start} += $len;
2131 139 $fixup->AddFixup($subdirFixup);
2132 }
2133 139 my $imageData = $$subdir{ImageData};
2134 139 my $blockSize = 0;
2135 # must also update start position for ImageData fixups
2136 139 ▶ if (ref $imageData) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $imageData) 4 135 139
2137 4 my $blockInfo;
2138 4 foreach $blockInfo (@$imageData) {
2139 4 my ($pos, $size, $pad, $entry, $subFix) = @$blockInfo;
2140 4 ▶ if ($subFix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subFix) 4 0 4
2141 4 $$subFix{Start} += $len;
2142 # save expected image data offset for calculating shift later
2143 4 $$subFix{BlockLen} = length(${$$subdir{DataPt}}) + $blockSize;
2144 }
2145 4 $blockSize += $size + $pad;
2146 }
2147 }
2148 139 $newData .= ${$$subdir{DataPt}}; # add subdirectory to our data
2149 139 undef ${$$subdir{DataPt}}; # free memory now
2150 # set the pointer
2151 139 my $offset = $$subdir{Offset};
2152 # if offset is in valBuff, it was added to the end of dirBuff
2153 # (plus 4 bytes for nextIFD pointer)
2154 139 ▶ $offset += length($dirBuff) + 4 if $$subdir{Where} eq 'valBuff';
Branch: 1 branch
BranchTrueFalseTotal
if $subdir->{"Where"} eq "valBuff" 5 134 139
2155 139 $offset += $newStart + 2; # get offset in newData
2156 # check to be sure we got the right offset
2157 139 ▶ unless (Get32u(\$newData, $offset) == 0xfeedf00d) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Get32u(\$newData, $offset) == 4277006349) 0 139 139
2158 0 $et->Error("Internal error while rewriting $name");
2159 0 return undef;
2160 }
2161 # set the offset to the subdirectory data
2162 139 Set32u($len, \$newData, $offset);
2163 139 $fixup->AddFixup($offset); # add fixup for this offset in newData
2164 }
2165 }
2166 # add fixup for all offsets in directory according to value data position
2167 # (which is at the end of this directory)
2168 382 ▶ if ($dirFixup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirFixup) 369 13 382
2169 369 $$dirFixup{Start} = $newStart + 2;
2170 369 $$dirFixup{Shift} = $valPos - $$dirFixup{Start};
2171 369 $fixup->AddFixup($dirFixup);
2172 }
2173 # add valueData fixups, adjusting for position of value data
2174 382 my $valFixup;
2175 382 foreach $valFixup (@valFixups) {
2176 44 $$valFixup{Start} += $valPos;
2177 44 $fixup->AddFixup($valFixup);
2178 }
2179 # stop if no next IFD pointer
2180 382 ▶ last unless $isNextIFD; # stop unless scanning for multiple IFD's
Branch: 1 branch
BranchTrueFalseTotal
unless $isNextIFD 333 49 382
2181 49 ▶ if ($nextIfdOffset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nextIfdOffset) { } 42 7 49
2182 # continue with next IFD
2183 42 $dirStart = $nextIfdOffset - $dataPos;
2184 } else {
2185 # create IFD1 if necessary
2186 7 ▶ $verbose and print $out " Creating IFD1\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Creating IFD1\n" 0 7 7
2187 7 my $ifd1 = "\0" x 2; # empty IFD1 data (zero entry count)
2188 7 $dataPt = \$ifd1;
2189 7 $dirStart = 0;
2190 7 $dirLen = $dataLen = 2;
2191 }
2192 # increment IFD name
2193 49 ▶ my $ifdNum = $dirName =~ s/(\d+)$// ? $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dirName =~ s/(\d+)$// ? : 49 0 49
2194 49 $dirName .= $ifdNum + 1;
2195 49 $name =~ s/\d+$//;
2196 49 $name .= $ifdNum + 1;
2197 49 $$et{DIR_NAME} = $$et{PATH}[-1] = $dirName;
2198 49 ▶ next unless $nextIfdOffset;
Branch: 1 branch
BranchTrueFalseTotal
unless $nextIfdOffset 7 42 49
2199  
2200 # guard against writing the same directory twice
2201 42 my $addr = $nextIfdOffset + $base;
2202 42 ▶ if ($$et{PROCESSED}{$addr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"PROCESSED"}{$addr}) 0 42 42
2203 0 $et->Error("$name pointer references previous $$et{PROCESSED}{$addr} directory", 1);
2204 0 last;
2205 }
2206 42 $$et{PROCESSED}{$addr} = $name;
2207  
2208 42 ▶ if ($dirName eq 'SubIFD1' and not ValidateIFD($dirInfo, $dirStart)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName eq "SubIFD1" and not &ValidateIFD($dirInfo, $dirStart)) 0 42 42
Condition33%1/3
$dirName eq "SubIFD1" and not &ValidateIFD($dirInfo, $dirStart)
!ll&&!rl&&r
4200
MC/DC0%0/2
$dirName eq "SubIFD1" and not &ValidateIFD($dirInfo, $dirStart)
$dirName eq "SubIFD1" not &ValidateIFD($dirInfo, $dirStart)
Truth table33%1/3
A and not(B)
A= $dirName eq "SubIFD1"B= not &ValidateIFD($dirInfo, $dirStart)
ABresult
0X0
100
111
2209 0 ▶ if ($$et{TIFF_TYPE} eq 'TIFF') {
Branch: 2 branches
BranchTrueFalseTotal
if ($et->{'TIFF_TYPE'} eq 'TIFF') { } 0 0 0
elsif ($verbose) { } 0 0 0
2210 0 $et->Error('Ignored bad IFD linked from SubIFD', 1);
2211 } elsif ($verbose) {
2212 0 $et->Warn('Ignored bad IFD linked from SubIFD');
2213 }
2214 0 last; # don't write bad IFD
2215 }
2216 42 ▶ if ($$et{DEL_GROUP}{$dirName}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'DEL_GROUP'}{$dirName}) { } 1 41 42
2217 1 ▶ $verbose and print $out " Deleting $dirName\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting $dirName\n" 0 1 1
2218 1 ▶ $raf and $et->Error("Deleting $dirName also deletes subsequent" .
Branch: 1 branch
BranchTrueFalseTotal
$raf and $et->Error("Deleting $dirName also deletes subsequent" . q[ IFD's and possibly image data], 1) 0 1 1
2219 " IFD's and possibly image data", 1);
2220 1 ++$$et{CHANGED};
2221 1 ▶ if ($$et{DEL_GROUP}{$dirName} == 2 and
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'DEL_GROUP'}{$dirName} == 2 and $et->{'ADD_DIRS'}{$dirName}) { } 0 1 1
Condition33%1/3
$et->{"DEL_GROUP"}{$dirName} == 2 and $et->{"ADD_DIRS"}{$dirName}
!ll&&!rl&&r
100
MC/DC0%0/2
$et->{"DEL_GROUP"}{$dirName} == 2 and $et->{"ADD_DIRS"}{$dirName}
$et->{"DEL_GROUP"}{$dirName} == 2 $et->{"ADD_DIRS"}{$dirName}
Truth table33%1/3
A and B
A= $et->{"DEL_GROUP"}{$dirName} == 2B= $et->{"ADD_DIRS"}{$dirName}
ABresult
0X0
100
111
2222 $$et{ADD_DIRS}{$dirName})
2223 {
2224 0 my $emptyIFD = "\0" x 2; # start with empty IFD
2225 0 $dataPt = \$emptyIFD;
2226 0 $dirStart = 0;
2227 0 $dirLen = $dataLen = 2;
2228 } else {
2229 1 last; # don't write this IFD (or any subsequent IFD)
2230 }
2231 } else {
2232 41 ▶ $verbose and print $out " Rewriting $name\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Rewriting $name\n" 0 41 41
2233 }
2234 }
2235 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2236  
2237 # do our fixups now so we can more easily calculate offsets below
2238 335 $fixup->ApplyFixup(\$newData);
2239 # write Sony HiddenData now if this is an ARW file
2240 335 ▶ if ($$et{HiddenData} and not $$dirInfo{Fixup} and $$et{FILE_TYPE} eq 'TIFF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"HiddenData"} and not $dirInfo->{"Fixup"} and $et->{"FILE_TYPE"} eq "TIFF") 0 335 335
Condition33%2/6
$et->{"HiddenData"} and not $dirInfo->{"Fixup"} and $et->{"FILE_TYPE"} eq "TIFF"
!ll&&!rl&&r
33500
$et->{"HiddenData"} and not $dirInfo->{"Fixup"}
!ll&&!rl&&r
33500
MC/DC0%0/3
$et->{"HiddenData"} and not $dirInfo->{"Fixup"} and $et->{"FILE_TYPE"} eq "TIFF"
$et->{"HiddenData"} not $dirInfo->{"Fixup"} $et->{"FILE_TYPE"} eq "TIFF"
Truth table25%1/4
A and not(B) and C
A= $et->{"HiddenData"}B= not $dirInfo->{"Fixup"}C= $et->{"FILE_TYPE"} eq "TIFF"
ABCresult
0XX0
10X0
1100
1111
2241 0 $fixup->SetMarkerPointers(\$newData, 'HiddenData', length($newData));
2242 0 my $hbuf;
2243 0 my $hd = $$et{HiddenData};
2244 0 ▶ if ($raf->Seek($$hd{Offset}, 0) and $raf->Read($hbuf, $$hd{Size}) == $$hd{Size} and
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->Seek($hd->{'Offset'}, 0) and $raf->Read($hbuf, $hd->{'Size'}) == $hd->{'Size'} and $hbuf =~ /^\x55\x26\x11\x05\0/) { } 0 0 0
Condition0%0/6
$raf->Seek($hd->{"Offset"}, 0) and $raf->Read($hbuf, $hd->{"Size"}) == $hd->{"Size"} and $hbuf =~ /^\x55\x26\x11\x05\0/
!ll&&!rl&&r
000
$raf->Seek($hd->{"Offset"}, 0) and $raf->Read($hbuf, $hd->{"Size"}) == $hd->{"Size"}
!ll&&!rl&&r
000
MC/DC0%0/3
$raf->Seek($hd->{"Offset"}, 0) and $raf->Read($hbuf, $hd->{"Size"}) == $hd->{"Size"} and $hbuf =~ /^\x55\x26\x11\x05\0/
$raf->Seek($hd->{"Offset"}, 0) $raf->Read($hbuf, $hd->{"Size"}) == $hd->{"Size"} $hbuf =~ /^\x55\x26\x11\x05\0/
Truth table0%0/4
A and B and C
A= $raf->Seek($hd->{"Offset"}, 0)B= $raf->Read($hbuf, $hd->{"Size"}) == $hd->{"Size"}C= $hbuf =~ /^\x55\x26\x11\x05\0/
ABCresult
0XX0
10X0
1100
1111
2245 $hbuf =~ /^\x55\x26\x11\x05\0/)
2246 {
2247 0 $newData .= $hbuf;
2248 } else {
2249 0 $et->Error('Error copying hidden data', 1);
2250 }
2251 }
2252 #
2253 # determine total block size for deferred data
2254 #
2255 335 my $numBlocks = scalar @imageData; # save this so we scan only existing blocks later
2256 335 my $blockSize = 0; # total size of blocks to copy later
2257 335 my $blockInfo;
2258 335 foreach $blockInfo (@imageData) {
2259 4 my ($pos, $size, $pad) = @$blockInfo;
2260 4 $blockSize += $size + $pad;
2261 }
2262 #
2263 # copy over image data for IFD's, starting with the last IFD first
2264 #
2265 335 ▶ if (@offsetInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if (@offsetInfo) 60 275 335
2266 60 my $ttwLen; # length of MRW TTW segment
2267 my @writeLater; # write image data last
2268 60 ▶ for ($ifd=$#offsetInfo; $ifd>=-1; --$ifd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ifd >= -1) 162 17 179
2269 # build list of offsets to process
2270 162 my @offsetList;
2271 162 ▶ if ($ifd >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ifd >= 0) { } 102 60 162
2272 102 ▶ $dirName = $$dirInfo{DirName} || 'unknown';
Condition50%1/2
$dirInfo->{'DirName'} || 'unknown'
l!l
1020
MC/DC0%0/1
$dirInfo->{'DirName'} || 'unknown'
$dirInfo->{'DirName'}
Truth table50%1/2
A
A= $dirInfo->{'DirName'}
Aresult
11
00
2273 102 ▶ if ($ifd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ifd) 42 60 102
2274 42 $dirName =~ s/\d+$//;
2275 42 $dirName .= $ifd;
2276 }
2277 102 ▶ my $offsetInfo = $offsetInfo[$ifd] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $offsetInfo = $offsetInfo[$ifd] or next 70 32 102
2278 70 ▶ if ($$offsetInfo{0x111} and $$offsetInfo{0x144}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offsetInfo->{273} and $offsetInfo->{324}) 0 70 70
Condition66%2/3
$offsetInfo->{273} and $offsetInfo->{324}
!ll&&!rl&&r
47230
MC/DC0%0/2
$offsetInfo->{273} and $offsetInfo->{324}
$offsetInfo->{273} $offsetInfo->{324}
Truth table66%2/3
A and B
A= $offsetInfo->{273}B= $offsetInfo->{324}
ABresult
0X0
100
111
2279 # SubIFD may contain double-referenced data as both strips and tiles
2280 # for Sony ARW files when SonyRawFileType is "Lossless Compressed RAW 2"
2281 0 ▶ if ($dirName eq 'SubIFD' and $$et{TIFF_TYPE} eq 'ARW' and
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName eq 'SubIFD' and $et->{'TIFF_TYPE'} eq 'ARW' and $offsetInfo->{'279'} and $offsetInfo->{'325'} and $offsetInfo->{'273'}[2] == 1) { } 0 0 0
Condition0%0/12
$dirName eq "SubIFD" and $et->{"TIFF_TYPE"} eq "ARW" and $offsetInfo->{279} and $offsetInfo->{325} and $offsetInfo->{273}[2] == 1
!ll&&!rl&&r
000
$dirName eq "SubIFD" and $et->{"TIFF_TYPE"} eq "ARW" and $offsetInfo->{279} and $offsetInfo->{325}
!ll&&!rl&&r
000
$dirName eq "SubIFD" and $et->{"TIFF_TYPE"} eq "ARW" and $offsetInfo->{279}
!ll&&!rl&&r
000
$dirName eq "SubIFD" and $et->{"TIFF_TYPE"} eq "ARW"
!ll&&!rl&&r
000
MC/DC0%0/5
$dirName eq "SubIFD" and $et->{"TIFF_TYPE"} eq "ARW" and $offsetInfo->{279} and $offsetInfo->{325} and $offsetInfo->{273}[2] == 1
$dirName eq "SubIFD" $et->{"TIFF_TYPE"} eq "ARW" $offsetInfo->{279} $offsetInfo->{325} $offsetInfo->{273}[2] == 1
Truth table0%0/6
A and B and C and D and E
A= $dirName eq "SubIFD"B= $et->{"TIFF_TYPE"} eq "ARW"C= $offsetInfo->{279}D= $offsetInfo->{325}E= $offsetInfo->{273}[2] == 1
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
2282 $$offsetInfo{0x117} and $$offsetInfo{0x145} and
2283 $$offsetInfo{0x111}[2]==1) # (must be a single strip or the tile offsets could get out of sync)
2284 {
2285 # check the start offsets to see if they are the same
2286 0 ▶ if ($$offsetInfo{0x111}[3][0] == $$offsetInfo{0x144}[3][0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offsetInfo->{273}[3][0] == $offsetInfo->{324}[3][0]) 0 0 0
2287 # some Sony ARW images contain double-referenced raw data stored as both strips
2288 # and tiles. Copy the data using only the strip tags, but store the TileOffets
2289 # information for updating later (see PanasonicRaw:PatchRawDataOffset for a
2290 # description of offsetInfo elements)
2291 0 $$offsetInfo{0x111}[5] = $$offsetInfo{0x144}; # hack to save TileOffsets
2292 # delete tile information from offsetInfo because we will copy as strips
2293 0 delete $$offsetInfo{0x144};
2294 0 delete $$offsetInfo{0x145};
2295 }
2296 } else {
2297 0 $et->Error("TIFF $dirName contains both strip and tile data");
2298 }
2299 }
2300 # patch Panasonic RAW/RW2 StripOffsets/StripByteCounts if necessary
2301 70 my $stripOffsets = $$offsetInfo{0x111};
2302 70 my $rawDataOffset = $$offsetInfo{0x118};
2303 70 ▶ if ($stripOffsets and $$stripOffsets[0]{PanasonicHack} or
Branch: 1 branch
BranchTrueFalseTotal
if ($stripOffsets and $stripOffsets->[0]{"PanasonicHack"} or $rawDataOffset and $rawDataOffset->[0]{"PanasonicHack"}) 1 69 70
Condition66%6/9
$stripOffsets and $stripOffsets->[0]{"PanasonicHack"} or $rawDataOffset and $rawDataOffset->[0]{"PanasonicHack"}
l!l&&r!l&&!r
1069
$stripOffsets and $stripOffsets->[0]{"PanasonicHack"}
!ll&&!rl&&r
47221
$rawDataOffset and $rawDataOffset->[0]{"PanasonicHack"}
!ll&&!rl&&r
6900
MC/DC50%2/4
$stripOffsets and $stripOffsets->[0]{"PanasonicHack"} or $rawDataOffset and $rawDataOffset->[0]{"PanasonicHack"}
$stripOffsets $stripOffsets->[0]{"PanasonicHack"} $rawDataOffset $rawDataOffset->[0]{"PanasonicHack"}
Truth table42%3/7
A and B or C and D
A= $stripOffsetsB= $stripOffsets->[0]{"PanasonicHack"}C= $rawDataOffsetD= $rawDataOffset->[0]{"PanasonicHack"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2304 $rawDataOffset and $$rawDataOffset[0]{PanasonicHack})
2305 {
2306 1 require Image::ExifTool::PanasonicRaw;
2307 1 my $err = Image::ExifTool::PanasonicRaw::PatchRawDataOffset($offsetInfo, $raf, $ifd);
2308 1 ▶ $err and $et->Error($err);
Branch: 1 branch
BranchTrueFalseTotal
$err and $et->Error($err) 0 1 1
2309 }
2310 70 my $tagID;
2311 # loop through all tags in reverse numerical order so we save thumbnail
2312 # data before main image data if both exist in the same IFD
2313 70 foreach $tagID (reverse sort { $a <=> $b } keys %$offsetInfo) {
2314 140 my $tagInfo = $$offsetInfo{$tagID}[0];
2315 140 ▶ next unless $$tagInfo{IsOffset}; # handle byte counts with offsets
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo->{"IsOffset"} 70 70 140
2316 70 my $sizeInfo = $$offsetInfo{$$tagInfo{OffsetPair}};
2317 70 ▶ $sizeInfo or $et->Error("No size tag for $dirName:$$tagInfo{Name}"), next;
Branch: 1 branch
BranchTrueFalseTotal
$sizeInfo or $et->Error(qq[No size tag for ${dirName}:$tagInfo->{"Name"}]), next 70 0 70
2318 70 my $dataTag = $$tagInfo{DataTag};
2319 # write TIFF image data (strips or tiles) later if requested
2320 70 ▶ if ($raf and defined $$origDirInfo{ImageData} and
Branch: 1 branch
BranchTrueFalseTotal
if ($raf and defined $origDirInfo->{'ImageData'} and $tagID == 273 || $tagID == 324 || $sizeInfo->[3][0] && $sizeInfo->[3][0] * scalar(@{$sizeInfo->[3];}) > 1000000 and not defined $dataTag && defined $offsetData{$dataTag}) { } 24 46 70
Condition77%14/18
$raf and defined $origDirInfo->{"ImageData"} and $tagID == 273 || $tagID == 324 || $sizeInfo->[3][0] && $sizeInfo->[3][0] * scalar(@{$sizeInfo->[3];}) > 1000000 and not defined $dataTag && defined $offsetData{$dataTag}
!ll&&!rl&&r
46024
$raf and defined $origDirInfo->{"ImageData"} and $tagID == 273 || $tagID == 324 || $sizeInfo->[3][0] && $sizeInfo->[3][0] * scalar(@{$sizeInfo->[3];}) > 1000000
!ll&&!rl&&r
42424
$raf and defined $origDirInfo->{"ImageData"}
!ll&&!rl&&r
41128
$tagID == 273 or $tagID == 324 or $sizeInfo->[3][0] and $sizeInfo->[3][0] * scalar(@{$sizeInfo->[3];}) > 1000000
l!l&&r!l&&!r
2404
$tagID == 273 or $tagID == 324
l!l&&r!l&&!r
2314
$sizeInfo->[3][0] and $sizeInfo->[3][0] * scalar(@{$sizeInfo->[3];}) > 1000000
!ll&&!rl&&r
040
MC/DC57%4/7
$raf and defined $origDirInfo->{"ImageData"} and $tagID == 273 || $tagID == 324 || $sizeInfo->[3][0] && $sizeInfo->[3][0] * scalar(@{$sizeInfo->[3];}) > 1000000 and not defined $dataTag && defined $offsetData{$dataTag}
$raf defined $origDirInfo->{"ImageData"} $tagID == 273 $tagID == 324 $sizeInfo->[3][0] $sizeInfo->[3][0] * scalar(@{$sizeInfo->[3];}) > 1000000 not defined $dataTag && defined $offsetData{$dataTag}
Truth table60%6/10
A and B and C or D or E and F and not(G)
A= $rafB= defined $origDirInfo->{"ImageData"}C= $tagID == 273D= $tagID == 324E= $sizeInfo->[3][0]F= $sizeInfo->[3][0] * scalar(@{$sizeInfo->[3];}) > 1000000G= not defined $dataTag && defined $offsetData{$dataTag}
ABCDEFGresult
0XXXXXX0
10XXXXX0
11000XX0
110010X0
111XXX00
1101XX00
11001100
111XXX11
1101XX11
11001111
2321 ($tagID == 0x111 or $tagID == 0x144 or
2322 # also defer writing of other big data such as JpgFromRaw in NEF
2323 ($$sizeInfo[3][0] and
2324 # (calculate approximate combined size of all blocks)
2325 4 ▶ $$sizeInfo[3][0] * scalar(@{$$sizeInfo[3]}) > 1000000)) and
Condition66%2/3
defined $dataTag && defined $offsetData{$dataTag}
!ll&&!rl&&r
1950
MC/DC0%0/2
defined $dataTag && defined $offsetData{$dataTag}
defined $dataTag defined $offsetData{$dataTag}
Truth table66%2/3
A && B
A= defined $dataTagB= defined $offsetData{$dataTag}
ABresult
0X0
100
111
2326 # but don't defer writing if replacing with new value
2327 (not defined $dataTag or not defined $offsetData{$dataTag}))
2328 {
2329 24 push @writeLater, [ $$offsetInfo{$tagID}, $sizeInfo ];
2330 } else {
2331 46 push @offsetList, [ $$offsetInfo{$tagID}, $sizeInfo ];
2332 }
2333 }
2334 } else {
2335 60 ▶ last unless @writeLater;
Branch: 1 branch
BranchTrueFalseTotal
unless @writeLater 43 17 60
2336 # finally, copy all deferred data
2337 17 @offsetList = @writeLater;
2338 }
2339 87 my $offsetPair;
2340 87 foreach $offsetPair (@offsetList) {
2341 70 my ($tagInfo, $offsets, $count, $oldOffset) = @{$$offsetPair[0]};
2342 70 my ($cntInfo, $byteCounts, $count2, $oldSize, $format) = @{$$offsetPair[1]};
2343 # must be the same number of offset and byte count values
2344 70 ▶ unless ($count == $count2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($count == $count2) 0 70 70
2345 0 $et->Error("Offsets/ByteCounts disagree on count for $$tagInfo{Name}");
2346 0 return undef;
2347 }
2348 70 my $formatStr = $formatName[$format];
2349 # follow pointer to value data if necessary
2350 70 ▶ $count > 1 and $offsets = Get32u(\$newData, $offsets);
Branch: 1 branch
BranchTrueFalseTotal
$count > 1 and $offsets = &Get32u(\$newData, $offsets) 0 70 70
2351 70 my $n = $count * $formatSize[$format];
2352 70 ▶ $n > 4 and $byteCounts = Get32u(\$newData, $byteCounts);
Branch: 1 branch
BranchTrueFalseTotal
$n > 4 and $byteCounts = &Get32u(\$newData, $byteCounts) 0 70 70
2353 70 ▶ if ($byteCounts < 0 or $byteCounts + $n > length($newData)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($byteCounts < 0 or $byteCounts + $n > length $newData) 0 70 70
Condition33%1/3
$byteCounts < 0 or $byteCounts + $n > length $newData
l!l&&r!l&&!r
0070
MC/DC0%0/2
$byteCounts < 0 or $byteCounts + $n > length $newData
$byteCounts < 0 $byteCounts + $n > length $newData
Truth table33%1/3
A or B
A= $byteCounts < 0B= $byteCounts + $n > length $newData
ABresult
1X1
011
000
2354 0 $et->Error("Error reading $$tagInfo{Name} byte counts");
2355 0 return undef;
2356 }
2357 # get offset base and data pos (abnormal for some preview images)
2358 70 my ($dbase, $dpos, $wrongBase, $subIfdDataFixup);
2359 70 ▶ if ($$tagInfo{IsOffset} eq '2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'IsOffset'} eq '2') { } 2 68 70
2360 2 $dbase = $firstBase;
2361 2 $dpos = $dataPos + $base - $firstBase;
2362 } else {
2363 68 $dbase = $base;
2364 68 $dpos = $dataPos;
2365 }
2366 # use different base if necessary for some offsets (Minolta A200)
2367 70 ▶ if ($$tagInfo{WrongBase}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'WrongBase'}) { } 0 70 70
2368 0 my $self = $et;
2369 #### eval WrongBase ($self)
2370 0 ▶ $wrongBase = eval $$tagInfo{WrongBase} || 0;
Condition0%0/2
eval $tagInfo->{'WrongBase'} || 0
l!l
00
MC/DC0%0/1
eval $tagInfo->{'WrongBase'} || 0
eval $tagInfo->{'WrongBase'}
Truth table0%0/2
A
A= eval $tagInfo->{'WrongBase'}
Aresult
11
00
2371 0 $dbase += $wrongBase;
2372 0 $dpos -= $wrongBase;
2373 } else {
2374 70 $wrongBase = 0;
2375 }
2376 70 my $oldOrder = GetByteOrder();
2377 70 my $dataTag = $$tagInfo{DataTag};
2378 # use different byte order for values of this offset pair if required (Minolta A200)
2379 70 ▶ SetByteOrder($$tagInfo{ByteOrder}) if $$tagInfo{ByteOrder};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"ByteOrder"} 0 70 70
2380 # transfer the data referenced by all offsets of this tag
2381 70 ▶ for ($n=0; $n<$count; ++$n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < $count) 70 70 140
2382 70 my ($oldEnd, $size);
2383 70 ▶ if (@$oldOffset and @$oldSize) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$oldOffset and @$oldSize) 68 2 70
Condition66%2/3
@$oldOffset and @$oldSize
!ll&&!rl&&r
2068
MC/DC50%1/2
@$oldOffset and @$oldSize
@$oldOffset @$oldSize
Truth table66%2/3
A and B
A= @$oldOffsetB= @$oldSize
ABresult
0X0
100
111
2384 # calculate end offset of this block
2385 68 $oldEnd = $$oldOffset[$n] + $$oldSize[$n];
2386 # update TIFF_END as if we read this data from file
2387 68 UpdateTiffEnd($et, $oldEnd + $dbase);
2388 }
2389 70 my $offsetPos = $offsets + $n * 4;
2390 70 my $byteCountPos = $byteCounts + $n * $formatSize[$format];
2391 70 ▶ if ($$tagInfo{PanasonicHack}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'PanasonicHack'}) { } 1 69 70
2392 # use actual raw data length (may be different than StripByteCounts!)
2393 1 $size = $$oldSize[$n];
2394 } else {
2395 # use size of new data
2396 69 $size = ReadValue(\$newData, $byteCountPos, $formatStr, 1, 4);
2397 }
2398 70 my $offset = $$oldOffset[$n];
2399 70 ▶ if (defined $offset) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $offset) { } 68 2 70
elsif ($size != 4277010157) { } 0 2 2
2400 68 $offset -= $dpos;
2401 } elsif ($size != 0xfeedfeed) {
2402 0 $et->Error('Internal error (no offset)');
2403 0 return undef;
2404 }
2405 70 my $newOffset = length($newData) - $wrongBase;
2406 70 my $buff;
2407 # look for 'feed' code to use our new data
2408 70 ▶ if ($size == 0xfeedfeed) {
Branch: 7 branches
BranchTrueFalseTotal
if ($size == 4277010157) { } 4 66 70
elsif ($ifd < 0) { } 24 42 66
elsif ($offset >= 0 and $offset + $size <= $dataLen) { } 37 5 42
elsif ($et->{'TIFF_TYPE'} eq 'MRW') { } 0 5 5
elsif ($raf and $raf->Seek($offset + $dbase + $dpos, 0) and $raf->Read($buff, $size) == $size) { } 4 1 5
elsif ($tagInfo->{'Name'} eq 'ThumbnailOffset' and $offset >= 0 and $offset < $dataLen) { } 0 1 1
elsif ($tagInfo->{'Name'} eq 'PreviewImageStart' and $et->{'FILE_TYPE'} eq 'JPEG') { } 1 0 1
2409 4 ▶ unless (defined $dataTag) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dataTag) 0 4 4
2410 0 $et->Error("No DataTag defined for $$tagInfo{Name}");
2411 0 return undef;
2412 }
2413 4 ▶ unless (defined $offsetData{$dataTag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $offsetData{$dataTag}) 0 4 4
2414 0 $et->Error("Internal error (no $dataTag)");
2415 0 return undef;
2416 }
2417 4 ▶ if ($count > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 1) 0 4 4
2418 0 $et->Error("Can't modify $$tagInfo{Name} with count $count");
2419 0 return undef;
2420 }
2421 4 $buff = $offsetData{$dataTag};
2422 4 ▶ if ($formatSize[$format] != 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::Exif::formatSize[$format] != 4) 0 4 4
2423 0 $et->Error("$$cntInfo{Name} is not int32");
2424 0 return undef;
2425 }
2426 # set the data size
2427 4 $size = length($buff);
2428 4 Set32u($size, \$newData, $byteCountPos);
2429 } elsif ($ifd < 0) {
2430 # hack for fixed-offset data (Panasonic GH6)
2431 24 ▶ if ($$offsetPair[0][6]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offsetPair->[0][6]) 0 24 24
2432 0 ▶ if ($count > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 1) { } 0 0 0
2433 0 $et->Error("Can't handle fixed offsets with count > 1");
2434 } else {
2435 0 my $fixedOffset = Get32u(\$newData, $offsets);
2436 0 my $padToFixedOffset = $fixedOffset - ($newOffset + $dpos);
2437 # account for blocks that come before this (Pansonic DC-S1RM2, forum17319)
2438 0 $padToFixedOffset -= $$_[1] + $$_[2] foreach @imageData;
2439 0 ▶ if ($padToFixedOffset < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($padToFixedOffset < 0) { } 0 0 0
2440 0 $et->Error('Metadata too large to fit before fixed-offset image data');
2441 } else {
2442 # add necessary padding before raw data
2443 0 push @imageData, [$offset+$dbase+$dpos, 0, $padToFixedOffset];
2444 0 $newOffset += $padToFixedOffset;
2445 0 $et->Warn("Adding $padToFixedOffset bytes of padding before fixed-offset image data", 1);
2446 }
2447 }
2448 }
2449 # pad if necessary (but don't pad contiguous image blocks)
2450 24 my $pad = 0;
2451 24 ▶ ++$pad if ($blockSize + $size) & 0x01 and ($n+1 >= $count or
Branch: 1 branch
BranchTrueFalseTotal
if $blockSize + $size & 1 and $n + 1 >= $count || !$oldEnd || $oldEnd != $$oldOffset[$n + 1] 3 21 24
Condition44%4/9
$blockSize + $size & 1 and $n + 1 >= $count || !$oldEnd || $oldEnd != $$oldOffset[$n + 1]
!ll&&!rl&&r
2103
$n + 1 >= $count or not $oldEnd or $oldEnd != $$oldOffset[$n + 1]
l!l&&r!l&&!r
300
$n + 1 >= $count or not $oldEnd
l!l&&r!l&&!r
300
MC/DC25%1/4
$blockSize + $size & 1 and $n + 1 >= $count || !$oldEnd || $oldEnd != $$oldOffset[$n + 1]
$blockSize + $size & 1 $n + 1 >= $count not $oldEnd $oldEnd != $$oldOffset[$n + 1]
Truth table40%2/5
A and B or not(C) or D
A= $blockSize + $size & 1B= $n + 1 >= $countC= not $oldEndD= $oldEnd != $$oldOffset[$n + 1]
ABCDresult
0XXX0
10000
11XX1
101X1
10011
2452 not $oldEnd or $oldEnd != $$oldOffset[$n+1]);
2453 # preserve original image padding if specified
2454 24 ▶ if ($$origDirInfo{PreserveImagePadding} and $n+1 < $count and
Branch: 1 branch
BranchTrueFalseTotal
if ($origDirInfo->{"PreserveImagePadding"} and $n + 1 < $count and $oldEnd and $$oldOffset[$n + 1] > $oldEnd) 0 24 24
Condition44%4/9
$origDirInfo->{"PreserveImagePadding"} and $n + 1 < $count and $oldEnd and $$oldOffset[$n + 1] > $oldEnd
!ll&&!rl&&r
2400
$origDirInfo->{"PreserveImagePadding"} and $n + 1 < $count and $oldEnd
!ll&&!rl&&r
2400
$origDirInfo->{"PreserveImagePadding"} and $n + 1 < $count
!ll&&!rl&&r
2310
MC/DC0%0/4
$origDirInfo->{"PreserveImagePadding"} and $n + 1 < $count and $oldEnd and $$oldOffset[$n + 1] > $oldEnd
$origDirInfo->{"PreserveImagePadding"} $n + 1 < $count $oldEnd $$oldOffset[$n + 1] > $oldEnd
Truth table40%2/5
A and B and C and D
A= $origDirInfo->{"PreserveImagePadding"}B= $n + 1 < $countC= $oldEndD= $$oldOffset[$n + 1] > $oldEnd
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2455 $oldEnd and $$oldOffset[$n+1] > $oldEnd)
2456 {
2457 0 $pad = $$oldOffset[$n+1] - $oldEnd;
2458 }
2459 # copy data later
2460 24 push @imageData, [$offset+$dbase+$dpos, $size, $pad];
2461 24 $newOffset += $blockSize; # data comes after other deferred data
2462 # create fixup for SubIFD ImageData
2463 24 ▶ if ($imageDataFlag eq 'SubIFD' and not $subIfdDataFixup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($imageDataFlag eq "SubIFD" and not $subIfdDataFixup) 4 20 24
Condition66%2/3
$imageDataFlag eq "SubIFD" and not $subIfdDataFixup
!ll&&!rl&&r
2004
MC/DC50%1/2
$imageDataFlag eq "SubIFD" and not $subIfdDataFixup
$imageDataFlag eq "SubIFD" not $subIfdDataFixup
Truth table66%2/3
A and not(B)
A= $imageDataFlag eq "SubIFD"B= not $subIfdDataFixup
ABresult
0X0
100
111
2464 4 $subIfdDataFixup = Image::ExifTool::Fixup->new;
2465 4 $imageData[-1][4] = $subIfdDataFixup;
2466 }
2467 24 $size += $pad; # account for pad byte if necessary
2468 # return ImageData list
2469 24 $$origDirInfo{ImageData} = \@imageData;
2470 ▶ } elsif ($offset >= 0 and $offset+$size <= $dataLen) {
Condition66%2/3
$offset >= 0 and $offset + $size <= $dataLen
!ll&&!rl&&r
0537
MC/DC50%1/2
$offset >= 0 and $offset + $size <= $dataLen
$offset >= 0 $offset + $size <= $dataLen
Truth table66%2/3
A and B
A= $offset >= 0B= $offset + $size <= $dataLen
ABresult
0X0
100
111
2471 # take data from old dir data buffer
2472 37 $buff = substr($$dataPt, $offset, $size);
2473 } elsif ($$et{TIFF_TYPE} eq 'MRW') {
2474 # TTW segment must be an even 4 bytes long, so pad now if necessary
2475 0 my $n = length $newData;
2476 0 ▶ $buff = ($n & 0x03) ? "\0" x (4 - ($n & 0x03)) : '';
Branch: 1 branch
BranchTrueFalseTotal
$n & 3 ? : 0 0 0
2477 0 $size = length($buff);
2478 # data exists after MRW TTW segment
2479 0 ▶ $ttwLen = length($newData) + $size unless defined $ttwLen;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ttwLen 0 0 0
2480 0 $newOffset = $offset + $dpos + $ttwLen - $dataLen;
2481 ▶ } elsif ($raf and $raf->Seek($offset+$dbase+$dpos,0) and
Condition66%4/6
$raf and $raf->Seek($offset + $dbase + $dpos, 0) and $raf->Read($buff, $size) == $size
!ll&&!rl&&r
104
$raf and $raf->Seek($offset + $dbase + $dpos, 0)
!ll&&!rl&&r
104
MC/DC33%1/3
$raf and $raf->Seek($offset + $dbase + $dpos, 0) and $raf->Read($buff, $size) == $size
$raf $raf->Seek($offset + $dbase + $dpos, 0) $raf->Read($buff, $size) == $size
Truth table50%2/4
A and B and C
A= $rafB= $raf->Seek($offset + $dbase + $dpos, 0)C= $raf->Read($buff, $size) == $size
ABCresult
0XX0
10X0
1100
1111
2482 $raf->Read($buff,$size) == $size)
2483 {
2484 # (data was read OK)
2485 # patch incorrect ThumbnailOffset in Sony A100 1.00 ARW images
2486 4 ▶ if ($$et{TIFF_TYPE} eq 'ARW' and $$tagInfo{Name} eq 'ThumbnailOffset' and
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"TIFF_TYPE"} eq "ARW" and $tagInfo->{"Name"} eq "ThumbnailOffset" and $et->{"Model"} eq "DSLR-A100" and not $buff =~ /^\xff\xd8\xff/) 0 4 4
Condition33%3/9
$et->{"TIFF_TYPE"} eq "ARW" and $tagInfo->{"Name"} eq "ThumbnailOffset" and $et->{"Model"} eq "DSLR-A100" and not $buff =~ /^\xff\xd8\xff/
!ll&&!rl&&r
400
$et->{"TIFF_TYPE"} eq "ARW" and $tagInfo->{"Name"} eq "ThumbnailOffset" and $et->{"Model"} eq "DSLR-A100"
!ll&&!rl&&r
400
$et->{"TIFF_TYPE"} eq "ARW" and $tagInfo->{"Name"} eq "ThumbnailOffset"
!ll&&!rl&&r
400
MC/DC0%0/4
$et->{"TIFF_TYPE"} eq "ARW" and $tagInfo->{"Name"} eq "ThumbnailOffset" and $et->{"Model"} eq "DSLR-A100" and not $buff =~ /^\xff\xd8\xff/
$et->{"TIFF_TYPE"} eq "ARW" $tagInfo->{"Name"} eq "ThumbnailOffset" $et->{"Model"} eq "DSLR-A100" not $buff =~ /^\xff\xd8\xff/
Truth table20%1/5
A and B and C and not(D)
A= $et->{"TIFF_TYPE"} eq "ARW"B= $tagInfo->{"Name"} eq "ThumbnailOffset"C= $et->{"Model"} eq "DSLR-A100"D= not $buff =~ /^\xff\xd8\xff/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2487 $$et{Model} eq 'DSLR-A100' and $buff !~ /^\xff\xd8\xff/)
2488 {
2489 0 my $pos = $offset + $dbase + $dpos;
2490 0 my $try;
2491 0 ▶ if ($pos < 0x10000 and $raf->Seek($pos+0x10000,0) and
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < 65536 and $raf->Seek($pos + 65536, 0) and $raf->Read($try, $size) == $size and $try =~ /^\xff\xd8\xff/) { } 0 0 0
Condition0%0/9
$pos < 65536 and $raf->Seek($pos + 65536, 0) and $raf->Read($try, $size) == $size and $try =~ /^\xff\xd8\xff/
!ll&&!rl&&r
000
$pos < 65536 and $raf->Seek($pos + 65536, 0) and $raf->Read($try, $size) == $size
!ll&&!rl&&r
000
$pos < 65536 and $raf->Seek($pos + 65536, 0)
!ll&&!rl&&r
000
MC/DC0%0/4
$pos < 65536 and $raf->Seek($pos + 65536, 0) and $raf->Read($try, $size) == $size and $try =~ /^\xff\xd8\xff/
$pos < 65536 $raf->Seek($pos + 65536, 0) $raf->Read($try, $size) == $size $try =~ /^\xff\xd8\xff/
Truth table0%0/5
A and B and C and D
A= $pos < 65536B= $raf->Seek($pos + 65536, 0)C= $raf->Read($try, $size) == $sizeD= $try =~ /^\xff\xd8\xff/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2492 $raf->Read($try,$size) == $size and $try =~ /^\xff\xd8\xff/)
2493 {
2494 0 $buff = $try;
2495 0 $et->Warn('Adjusted incorrect A100 ThumbnailOffset', 1);
2496 } else {
2497 0 $et->Error('Invalid ThumbnailImage');
2498 }
2499 }
2500 ▶ } elsif ($$tagInfo{Name} eq 'ThumbnailOffset' and $offset>=0 and $offset<$dataLen) {
Condition33%2/6
$tagInfo->{"Name"} eq "ThumbnailOffset" and $offset >= 0 and $offset < $dataLen
!ll&&!rl&&r
100
$tagInfo->{"Name"} eq "ThumbnailOffset" and $offset >= 0
!ll&&!rl&&r
100
MC/DC0%0/3
$tagInfo->{"Name"} eq "ThumbnailOffset" and $offset >= 0 and $offset < $dataLen
$tagInfo->{"Name"} eq "ThumbnailOffset" $offset >= 0 $offset < $dataLen
Truth table25%1/4
A and B and C
A= $tagInfo->{"Name"} eq "ThumbnailOffset"B= $offset >= 0C= $offset < $dataLen
ABCresult
0XX0
10X0
1100
1111
2501 # Grrr. The Canon 350D writes the thumbnail with an incorrect byte count
2502 0 my $diff = $offset + $size - $dataLen;
2503 0 $et->Warn("ThumbnailImage runs outside EXIF data by $diff bytes (truncated)",1);
2504 # set the size to the available data
2505 0 $size -= $diff;
2506 0 ▶ unless (WriteValue($size, $formatStr, 1, \$newData, $byteCountPos)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&WriteValue($size, $formatStr, 1, \$newData, $byteCountPos)) 0 0 0
2507 0 warn 'Internal error writing thumbnail size';
2508 }
2509 # get the truncated image
2510 0 $buff = substr($$dataPt, $offset, $size);
2511 ▶ } elsif ($$tagInfo{Name} eq 'PreviewImageStart' and $$et{FILE_TYPE} eq 'JPEG') {
Condition33%1/3
$tagInfo->{"Name"} eq "PreviewImageStart" and $et->{"FILE_TYPE"} eq "JPEG"
!ll&&!rl&&r
001
MC/DC0%0/2
$tagInfo->{"Name"} eq "PreviewImageStart" and $et->{"FILE_TYPE"} eq "JPEG"
$tagInfo->{"Name"} eq "PreviewImageStart" $et->{"FILE_TYPE"} eq "JPEG"
Truth table33%1/3
A and B
A= $tagInfo->{"Name"} eq "PreviewImageStart"B= $et->{"FILE_TYPE"} eq "JPEG"
ABresult
0X0
100
111
2512 # try to load the preview image using the specified offset
2513 1 undef $buff;
2514 1 my $r = $$et{RAF};
2515 1 ▶ if ($r and not $raf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r and not $raf) 1 0 1
Condition33%1/3
$r and not $raf
!ll&&!rl&&r
001
MC/DC0%0/2
$r and not $raf
$r not $raf
Truth table33%1/3
A and not(B)
A= $rB= not $raf
ABresult
0X0
100
111
2516 1 my $tell = $r->Tell();
2517 # read and validate
2518 1 ▶ undef $buff unless $r->Seek($offset+$base+$dataPos,0) and
Branch: 1 branch
BranchTrueFalseTotal
unless $r->Seek($offset + $base + $dataPos, 0) and $r->Read($buff, $size) == $size and $buff =~ /^.\xd8\xff[\xc4\xdb\xe0-\xef]/s 1 0 1
Condition33%2/6
$r->Seek($offset + $base + $dataPos, 0) and $r->Read($buff, $size) == $size and $buff =~ /^.\xd8\xff[\xc4\xdb\xe0-\xef]/s
!ll&&!rl&&r
010
$r->Seek($offset + $base + $dataPos, 0) and $r->Read($buff, $size) == $size
!ll&&!rl&&r
001
MC/DC0%0/3
$r->Seek($offset + $base + $dataPos, 0) and $r->Read($buff, $size) == $size and $buff =~ /^.\xd8\xff[\xc4\xdb\xe0-\xef]/s
$r->Seek($offset + $base + $dataPos, 0) $r->Read($buff, $size) == $size $buff =~ /^.\xd8\xff[\xc4\xdb\xe0-\xef]/s
Truth table25%1/4
A and B and C
A= $r->Seek($offset + $base + $dataPos, 0)B= $r->Read($buff, $size) == $sizeC= $buff =~ /^.\xd8\xff[\xc4\xdb\xe0-\xef]/s
ABCresult
0XX0
10X0
1100
1111
2519 $r->Read($buff,$size) == $size and
2520 $buff =~ /^.\xd8\xff[\xc4\xdb\xe0-\xef]/s;
2521 1 ▶ $r->Seek($tell, 0) or $et->Error('Seek error'), return undef;
Branch: 1 branch
BranchTrueFalseTotal
$r->Seek($tell, 0) or $et->Error("Seek error"), (return undef) 1 0 1
2522 }
2523 # set flag if we must load PreviewImage
2524 1 ▶ $buff = 'LOAD_PREVIEW' unless defined $buff;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buff 1 0 1
2525 } else {
2526 0 ▶ my $dataName = $dataTag || $$tagInfo{Name};
Condition0%0/3
$dataTag || $tagInfo->{'Name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dataTag || $tagInfo->{'Name'}
$dataTag $tagInfo->{'Name'}
Truth table0%0/3
A || B
A= $dataTagB= $tagInfo->{'Name'}
ABresult
1X1
011
000
2527 0 ▶ return undef if $et->Error("Error reading $dataName data in $name", $inMakerNotes);
Branch: 1 branch
BranchTrueFalseTotal
if $et->Error("Error reading $dataName data in $name", $inMakerNotes) 0 0 0
2528 0 $buff = '';
2529 }
2530 70 ▶ if ($$tagInfo{Name} eq 'PreviewImageStart') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"Name"} eq "PreviewImageStart") 14 56 70
2531 14 ▶ if ($$et{FILE_TYPE} eq 'JPEG' and not $$tagInfo{MakerPreview}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($et->{'FILE_TYPE'} eq 'JPEG' and not $tagInfo->{'MakerPreview'}) { } 8 6 14
elsif ($et->{'TIFF_TYPE'} eq 'ARW' and $et->{'Model'} eq 'DSLR-A100') { } 0 12 12
Condition66%2/3
$et->{"FILE_TYPE"} eq "JPEG" and not $tagInfo->{"MakerPreview"}
!ll&&!rl&&r
608
MC/DC50%1/2
$et->{"FILE_TYPE"} eq "JPEG" and not $tagInfo->{"MakerPreview"}
$et->{"FILE_TYPE"} eq "JPEG" not $tagInfo->{"MakerPreview"}
Truth table66%2/3
A and not(B)
A= $et->{"FILE_TYPE"} eq "JPEG"B= not $tagInfo->{"MakerPreview"}
ABresult
0X0
100
111
2532 8 ▶ if ($size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size) 5 3 8
2533 # hold onto the PreviewImage until we can determine if it fits
2534 $$et{PREVIEW_INFO} or $$et{PREVIEW_INFO} = {
2535 5 ▶ Data => $buff,
Branch: 1 branch
BranchTrueFalseTotal
$et->{"PREVIEW_INFO"} or $et->{"PREVIEW_INFO"} = {"Data", $buff, "Fixup", "Image::ExifTool::Fixup"->new} 1 4 5
2536 Fixup => Image::ExifTool::Fixup->new,
2537 };
2538 5 ▶ if ($$tagInfo{IsOffset} and $$tagInfo{IsOffset} eq '2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"IsOffset"} and $tagInfo->{"IsOffset"} eq 2) 1 4 5
Condition66%2/3
$tagInfo->{"IsOffset"} and $tagInfo->{"IsOffset"} eq 2
!ll&&!rl&&r
041
MC/DC50%1/2
$tagInfo->{"IsOffset"} and $tagInfo->{"IsOffset"} eq 2
$tagInfo->{"IsOffset"} $tagInfo->{"IsOffset"} eq 2
Truth table66%2/3
A and B
A= $tagInfo->{"IsOffset"}B= $tagInfo->{"IsOffset"} eq 2
ABresult
0X0
100
111
2539 1 $$et{PREVIEW_INFO}{NoBaseShift} = 1;
2540 }
2541 5 ▶ if ($offset >= 0 and $offset+$size <= $dataLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= 0 and $offset + $size <= $dataLen) 5 0 5
Condition33%1/3
$offset >= 0 and $offset + $size <= $dataLen
!ll&&!rl&&r
005
MC/DC0%0/2
$offset >= 0 and $offset + $size <= $dataLen
$offset >= 0 $offset + $size <= $dataLen
Truth table33%1/3
A and B
A= $offset >= 0B= $offset + $size <= $dataLen
ABresult
0X0
100
111
2542 # set flag indicating this preview wasn't in a trailer
2543 5 $$et{PREVIEW_INFO}{WasContained} = 1;
2544 }
2545 }
2546 8 $buff = '';
2547 ▶ } elsif ($$et{TIFF_TYPE} eq 'ARW' and $$et{Model} eq 'DSLR-A100') {
Condition33%1/3
$et->{"TIFF_TYPE"} eq "ARW" and $et->{"Model"} eq "DSLR-A100"
!ll&&!rl&&r
600
MC/DC0%0/2
$et->{"TIFF_TYPE"} eq "ARW" and $et->{"Model"} eq "DSLR-A100"
$et->{"TIFF_TYPE"} eq "ARW" $et->{"Model"} eq "DSLR-A100"
Truth table33%1/3
A and B
A= $et->{"TIFF_TYPE"} eq "ARW"B= $et->{"Model"} eq "DSLR-A100"
ABresult
0X0
100
111
2548 # the A100 double-references the same preview, so ignore the
2549 # second one (the offset and size will be patched later)
2550 0 ▶ next if $$et{A100PreviewLength};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"A100PreviewLength"} 0 0 0
2551 0 ▶ $$et{A100PreviewLength} = length $buff if defined $buff;
Branch: 1 branch
BranchTrueFalseTotal
if defined $buff 0 0 0
2552 }
2553 }
2554 # update offset accordingly and add to end of new data
2555 70 Set32u($newOffset, \$newData, $offsetPos);
2556 # add a pointer to fix up this offset value (marked with DataTag name)
2557 70 $fixup->AddFixup($offsetPos, $dataTag);
2558 # also add to subIfdDataFixup if necessary
2559 70 ▶ $subIfdDataFixup->AddFixup($offsetPos, $dataTag) if $subIfdDataFixup;
Branch: 1 branch
BranchTrueFalseTotal
if $subIfdDataFixup 4 66 70
2560 # must also (sometimes) update StripOffsets in Panasonic RW2 images
2561 # and TileOffsets in Sony ARW images
2562 70 my $otherPos = $$offsetPair[0][5];
2563 70 ▶ if ($otherPos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($otherPos) 0 70 70
2564 0 ▶ if ($$tagInfo{PanasonicHack}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagInfo->{'PanasonicHack'}) { } 0 0 0
elsif (ref $otherPos eq 'ARRAY') { } 0 0 0
2565 0 Set32u($newOffset, \$newData, $otherPos);
2566 0 $fixup->AddFixup($otherPos, $dataTag);
2567 } elsif (ref $otherPos eq 'ARRAY') {
2568 # the image data was copied as one large strip, and is double-referenced
2569 # as tile data, so all we need to do now is properly update the tile offsets
2570 0 my $oldRawDataOffset = $$offsetPair[0][3][0];
2571 0 my $count = $$otherPos[2];
2572 0 my $i;
2573 # point to offsets in value data if more than one pointer
2574 0 ▶ $$otherPos[1] = Get32u(\$newData, $$otherPos[1]) if $count > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $count > 1 0 0 0
2575 0 ▶ for ($i=0; $i<$count; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $count) 0 0 0
2576 0 my $oldTileOffset = $$otherPos[3][$i];
2577 0 my $ptrPos = $$otherPos[1] + 4 * $i;
2578 0 Set32u($newOffset + $oldTileOffset - $oldRawDataOffset, \$newData, $ptrPos);
2579 0 $fixup->AddFixup($ptrPos, $dataTag);
2580 0 ▶ $subIfdDataFixup->AddFixup($ptrPos, $dataTag) if $subIfdDataFixup;
Branch: 1 branch
BranchTrueFalseTotal
if $subIfdDataFixup 0 0 0
2581 }
2582 }
2583 }
2584 70 ▶ if ($ifd >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ifd >= 0) { } 46 24 70
2585 # buff length must be even (Note: may have changed since $size was set)
2586 46 ▶ $buff .= "\0" if length($buff) & 0x01;
Branch: 1 branch
BranchTrueFalseTotal
if length $buff & 1 1 45 46
2587 46 $newData .= $buff; # add this strip to the data
2588 } else {
2589 24 $blockSize += $size; # keep track of total size
2590 }
2591 }
2592 70 SetByteOrder($oldOrder);
2593 }
2594 }
2595 # verify that nothing else got written after determining TTW length
2596 60 ▶ if (defined $ttwLen and $ttwLen != length($newData)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ttwLen and $ttwLen != length $newData) 0 60 60
Condition33%1/3
defined $ttwLen and $ttwLen != length $newData
!ll&&!rl&&r
6000
MC/DC0%0/2
defined $ttwLen and $ttwLen != length $newData
defined $ttwLen $ttwLen != length $newData
Truth table33%1/3
A and B
A= defined $ttwLenB= $ttwLen != length $newData
ABresult
0X0
100
111
2597 0 $et->Error('Internal error writing MRW TTW');
2598 }
2599 }
2600 #
2601 # set offsets and generate fixups for tag values which were too large for memory
2602 #
2603 335 $blockSize = 0;
2604 335 foreach $blockInfo (@imageData) {
2605 28 my ($pos, $size, $pad, $entry, $subFix) = @$blockInfo;
2606 28 ▶ if (defined $entry) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry) 0 28 28
2607 0 my $format = Get16u(\$newData, $entry + 2);
2608 0 ▶ if ($format < 1 or $format > 13) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format < 1 or $format > 13) { } 0 0 0
Condition0%0/3
$format < 1 or $format > 13
l!l&&r!l&&!r
000
MC/DC0%0/2
$format < 1 or $format > 13
$format < 1 $format > 13
Truth table0%0/3
A or B
A= $format < 1B= $format > 13
ABresult
1X1
011
000
2609 0 $et->Error('Internal error copying huge value');
2610 0 last;
2611 } else {
2612 # set count and offset in directory entry
2613 0 Set32u($size / $formatSize[$format], \$newData, $entry + 4);
2614 0 Set32u(length($newData)+$blockSize, \$newData, $entry + 8);
2615 0 $fixup->AddFixup($entry + 8);
2616 # create special fixup for SubIFD data
2617 0 ▶ if ($imageDataFlag eq 'SubIFD') {
Branch: 1 branch
BranchTrueFalseTotal
if ($imageDataFlag eq "SubIFD") 0 0 0
2618 0 my $subIfdDataFixup = Image::ExifTool::Fixup->new;
2619 0 $subIfdDataFixup->AddFixup($entry + 8);
2620 # save fixup in imageData list
2621 0 $$blockInfo[4] = $subIfdDataFixup;
2622 }
2623 # must reset entry pointer so we don't use it again in a parent IFD!
2624 0 $$blockInfo[3] = undef;
2625 }
2626 }
2627 # apply additional shift required for contained SubIFD image data offsets
2628 28 ▶ if ($subFix and defined $$subFix{BlockLen} and $numBlocks > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subFix and defined $subFix->{"BlockLen"} and $numBlocks > 0) 4 24 28
Condition83%5/6
$subFix and defined $subFix->{"BlockLen"} and $numBlocks > 0
!ll&&!rl&&r
2404
$subFix and defined $subFix->{"BlockLen"}
!ll&&!rl&&r
2044
MC/DC66%2/3
$subFix and defined $subFix->{"BlockLen"} and $numBlocks > 0
$subFix defined $subFix->{"BlockLen"} $numBlocks > 0
Truth table75%3/4
A and B and C
A= $subFixB= defined $subFix->{"BlockLen"}C= $numBlocks > 0
ABCresult
0XX0
10X0
1100
1111
2629 # our offset expects the data at the end of the SubIFD block (BlockLen + Start),
2630 # but it will actually be at length($newData) + $blockSize. So adjust
2631 # accordingly (and subtract an extra Start because this shift is applied later)
2632 4 $$subFix{Shift} += length($newData) - $$subFix{BlockLen} - 2 * $$subFix{Start} + $blockSize;
2633 4 $subFix->ApplyFixup(\$newData);
2634 }
2635 28 $blockSize += $size + $pad;
2636 28 --$numBlocks;
2637 }
2638 #
2639 # apply final shift to new data position if this is the top level IFD
2640 #
2641 335 ▶ unless ($$dirInfo{Fixup}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirInfo->{"Fixup"}) 126 209 335
2642 126 my $hdrPtr = $$dirInfo{HeaderPtr};
2643 126 ▶ my $newDataPos = $hdrPtr ? length $$hdrPtr : $$dirInfo{NewDataPos} || 0;
Branch: 1 branch
BranchTrueFalseTotal
$hdrPtr ? : 123 3 126
Condition50%1/2
$dirInfo->{"NewDataPos"} or 0
l!l
30
MC/DC0%0/1
$dirInfo->{"NewDataPos"} or 0
$dirInfo->{"NewDataPos"}
Truth table50%1/2
A
A= $dirInfo->{"NewDataPos"}
Aresult
11
00
2644 # adjust CanonVRD offset to point to end of regular TIFF if necessary
2645 # (NOTE: This will be incorrect if multiple trailers exist,
2646 # but it is unlikely that it could ever be correct in this case anyway.
2647 # Also, this doesn't work for JPEG images (but CanonDPP doesn't set
2648 # this when editing JPEG images anyway))
2649 126 $fixup->SetMarkerPointers(\$newData, 'CanonVRD', length($newData) + $blockSize);
2650 126 ▶ if ($newDataPos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newDataPos) 126 0 126
2651 126 $$fixup{Shift} += $newDataPos;
2652 126 $fixup->ApplyFixup(\$newData);
2653 }
2654 # save fixup for adjusting Leica trailer and Sony HiddenData offsets if necessary
2655 126 ▶ $$et{LeicaTrailer}{Fixup}->AddFixup($fixup) if $$et{LeicaTrailer};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"LeicaTrailer"} 0 126 126
2656 126 ▶ $$et{HiddenData}{Fixup}->AddFixup($fixup) if $$et{HiddenData};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"HiddenData"} 0 126 126
2657 # save fixup for PreviewImage in JPEG file if necessary
2658 126 my $previewInfo = $$et{PREVIEW_INFO};
2659 126 ▶ if ($previewInfo) {
Branch: 3 branches
BranchTrueFalseTotal
if ($previewInfo) { } 5 121 126
elsif (defined $newData and $deleteAll) { } 6 115 121
elsif ($et->{'A100PreviewLength'}) { } 0 115 115
2660 5 my $pt = \$$previewInfo{Data}; # image data or 'LOAD_PREVIEW' flag
2661 # now that we know the size of the EXIF data, first test to see if our new image fits
2662 # inside the EXIF segment (remember about the TIFF and EXIF headers: 8+6 bytes)
2663 5 ▶ if (($$pt ne 'LOAD_PREVIEW' and length($$pt) + length($newData) + 14 <= 0xfffd and
Branch: 1 branch
BranchTrueFalseTotal
if ($$pt ne 'LOAD_PREVIEW' and length($$pt) + length($newData) + 14 <= 65533 and not $previewInfo->{'IsTrailer'} or $previewInfo->{'IsShort'}) { } 5 0 5
Condition33%3/9
$$pt ne "LOAD_PREVIEW" and length($$pt) + length($newData) + 14 <= 65533 and not $previewInfo->{"IsTrailer"} or $previewInfo->{"IsShort"}
l!l&&r!l&&!r
500
$$pt ne "LOAD_PREVIEW" and length($$pt) + length($newData) + 14 <= 65533 and not $previewInfo->{"IsTrailer"}
!ll&&!rl&&r
005
$$pt ne "LOAD_PREVIEW" and length($$pt) + length($newData) + 14 <= 65533
!ll&&!rl&&r
005
MC/DC0%0/4
$$pt ne "LOAD_PREVIEW" and length($$pt) + length($newData) + 14 <= 65533 and not $previewInfo->{"IsTrailer"} or $previewInfo->{"IsShort"}
$$pt ne "LOAD_PREVIEW" length($$pt) + length($newData) + 14 <= 65533 not $previewInfo->{"IsTrailer"} $previewInfo->{"IsShort"}
Truth table14%1/7
A and B and not(C) or D
A= $$pt ne "LOAD_PREVIEW"B= length($$pt) + length($newData) + 14 <= 65533C= not $previewInfo->{"IsTrailer"}D= $previewInfo->{"IsShort"}
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
2664 not $$previewInfo{IsTrailer}) or
2665 $$previewInfo{IsShort}) # must fit in this segment if using short pointers
2666 {
2667 # It fits! (or must exist in EXIF segment), so fixup the
2668 # PreviewImage pointers and stuff the preview image in here
2669 5 my $newPos = length($newData) + $newDataPos;
2670 5 ▶ $newPos += ($$previewInfo{BaseShift} || 0);
Condition50%1/2
$previewInfo->{'BaseShift'} || 0
l!l
05
MC/DC0%0/1
$previewInfo->{'BaseShift'} || 0
$previewInfo->{'BaseShift'}
Truth table50%1/2
A
A= $previewInfo->{'BaseShift'}
Aresult
11
00
2671 5 ▶ if ($$previewInfo{Relative}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($previewInfo->{"Relative"}) 0 5 5
2672 # calculate our base by looking at how far the pointer got shifted
2673 0 ▶ $newPos -= ($fixup->GetMarkerPointers(\$newData, 'PreviewImage') || 0);
Condition0%0/2
$fixup->GetMarkerPointers(\$newData, 'PreviewImage') || 0
l!l
00
MC/DC0%0/1
$fixup->GetMarkerPointers(\$newData, 'PreviewImage') || 0
$fixup->GetMarkerPointers(\$newData, 'PreviewImage')
Truth table0%0/2
A
A= $fixup->GetMarkerPointers(\$newData, 'PreviewImage')
Aresult
11
00
2674 }
2675 5 $fixup->SetMarkerPointers(\$newData, 'PreviewImage', $newPos);
2676 5 $newData .= $$pt;
2677 # set flag to delete old preview unless it was contained in the EXIF
2678 5 ▶ $$et{DEL_PREVIEW} = 1 unless $$et{PREVIEW_INFO}{WasContained};
Branch: 1 branch
BranchTrueFalseTotal
unless $et->{"PREVIEW_INFO"}{"WasContained"} 0 5 5
2679 5 delete $$et{PREVIEW_INFO}; # done with our preview data
2680 } else {
2681 # Doesn't fit, or we still don't know, so save fixup information
2682 # and put the preview at the end of the file
2683 0 ▶ $$previewInfo{Fixup} or $$previewInfo{Fixup} = Image::ExifTool::Fixup->new;
Branch: 1 branch
BranchTrueFalseTotal
$previewInfo->{"Fixup"} or $previewInfo->{"Fixup"} = "Image::ExifTool::Fixup"->new 0 0 0
2684 0 $$previewInfo{Fixup}->AddFixup($fixup);
2685 }
2686 ▶ } elsif (defined $newData and $deleteAll) {
Condition66%2/3
defined $newData and $deleteAll
!ll&&!rl&&r
01156
MC/DC50%1/2
defined $newData and $deleteAll
defined $newData $deleteAll
Truth table66%2/3
A and B
A= defined $newDataB= $deleteAll
ABresult
0X0
100
111
2687 6 $newData = ''; # delete both IFD0 and IFD1 since only mandatory tags remain
2688 } elsif ($$et{A100PreviewLength}) {
2689 # save preview image start for patching A100 quirks later
2690 0 $$et{A100PreviewStart} = $fixup->GetMarkerPointers(\$newData, 'PreviewImage');
2691 }
2692 # save location of last IFD for use in Canon RAW header
2693 126 ▶ if ($newDataPos == 16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newDataPos == 16) 6 120 126
2694 6 my @ifdPos = $fixup->GetMarkerPointers(\$newData,'NextIFD');
2695 6 $$origDirInfo{LastIFD} = pop @ifdPos;
2696 }
2697 # recrypt SR2 SubIFD data if necessary
2698 126 my $key = $$et{SR2SubIFDKey};
2699 126 ▶ if ($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) 0 126 126
2700 0 my $start = $fixup->GetMarkerPointers(\$newData, 'SR2SubIFDOffset');
2701 0 my $len = $$et{SR2SubIFDLength};
2702 # (must subtract 8 for size of TIFF header)
2703 0 ▶ if ($start and $start - 8 + $len <= length $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start and $start - 8 + $len <= length $newData) 0 0 0
Condition0%0/3
$start and $start - 8 + $len <= length $newData
!ll&&!rl&&r
000
MC/DC0%0/2
$start and $start - 8 + $len <= length $newData
$start $start - 8 + $len <= length $newData
Truth table0%0/3
A and B
A= $startB= $start - 8 + $len <= length $newData
ABresult
0X0
100
111
2704 0 require Image::ExifTool::Sony;
2705 0 Image::ExifTool::Sony::Decrypt(\$newData, $start - 8, $len, $key);
2706 }
2707 }
2708 }
2709 # return empty string if no entries in directory
2710 # (could be up to 10 bytes and still be empty)
2711 335 ▶ $newData = '' if defined $newData and length($newData) < 12;
Branch: 1 branch
BranchTrueFalseTotal
if defined $newData and length $newData < 12 13 322 335
Condition66%2/3
defined $newData and length $newData < 12
!ll&&!rl&&r
032213
MC/DC50%1/2
defined $newData and length $newData < 12
defined $newData length $newData < 12
Truth table66%2/3
A and B
A= defined $newDataB= length $newData < 12
ABresult
0X0
100
111
2712  
2713 # set changed if ForceWrite tag was set to "EXIF"
2714 335 ▶ ++$$et{CHANGED} if defined $newData and length $newData and $$et{FORCE_WRITE}{EXIF};
Branch: 1 branch
BranchTrueFalseTotal
if defined $newData and length $newData and $et->{"FORCE_WRITE"}{"EXIF"} 0 335 335
Condition66%4/6
defined $newData and length $newData and $et->{"FORCE_WRITE"}{"EXIF"}
!ll&&!rl&&r
133220
defined $newData and length $newData
!ll&&!rl&&r
013322
MC/DC0%0/3
defined $newData and length $newData and $et->{"FORCE_WRITE"}{"EXIF"}
defined $newData length $newData $et->{"FORCE_WRITE"}{"EXIF"}
Truth table50%2/4
A and B and C
A= defined $newDataB= length $newDataC= $et->{"FORCE_WRITE"}{"EXIF"}
ABCresult
0XX0
10X0
1100
1111
2715  
2716 335 return $newData; # return our directory data
2717 }
2718  
2719 42 1; # end
2720  
2721 __END__
« Image/ExifTool/BuildTagLookup.pm ↑ Summary Image/ExifTool/WriteQuickTime.pl »