Image/ExifTool/Writer.pl

filter: Statementstmt 66.9% 2742 / 4095 Branchbran 57.0% 1963 / 3444 Conditioncond 51.7% 944 / 1825 MC/DCmcdc 32.9% 340 / 1032 Subroutinesub 73.9% 85 / 115 Podpod 17.1% 17 / 99 totaltotal 57.4% 6091 / 10610 CC 2437 SCAR 82.2
CC
2437
Cov
60%
WriteJPEG
15978.1
WriteInfo
6258.7
SetFileName
1858.2
CRAP 3717.5
« Image/ExifTool/QuickTime.pm ↑ Summary Image/ExifTool/GIF.pm »
1 #------------------------------------------------------------------------------
2 # File: Writer.pl
3 #
4 # Description: ExifTool write routines
5 #
6 # Notes: Also contains some less used ExifTool functions
7 #
8 # URL: https://exiftool.org/
9 #
10 # Revisions: 12/16/2004 - P. Harvey Created
11 #------------------------------------------------------------------------------
12  
13 package Image::ExifTool;
14  
15 61 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 61 ▶use Image::ExifTool::TagLookup qw(FindTagInfo TagExists);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 61 ▶use Image::ExifTool::Fixup;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 sub AssembleRational($$@);
21 sub LastInList($);
22 sub NextFreeTagKey($$);
23 sub RemoveNewValueHash($$$);
24 sub RemoveNewValuesForGroup($$);
25 sub GetWriteGroup1($$);
26 sub Sanitize($$);
27 sub ConvInv($$$$$;$$);
28 sub PushValue($$$;$);
29  
30 61 my $loadedAllTables; # flag indicating we loaded all tables
31  
32 # the following is a road map of where we write each directory
33 # in the different types of files.
34 61 my %tiffMap = (
35 IFD0 => 'TIFF',
36 IFD1 => 'IFD0',
37 XMP => 'IFD0',
38 ICC_Profile => 'IFD0',
39 ExifIFD => 'IFD0',
40 GPS => 'IFD0',
41 SubIFD => 'IFD0',
42 GlobParamIFD => 'IFD0',
43 PrintIM => 'IFD0',
44 IPTC => 'IFD0',
45 Photoshop => 'IFD0',
46 SEAL => 'IFD0',
47 InteropIFD => 'ExifIFD',
48 MakerNotes => 'ExifIFD',
49 CanonVRD => 'MakerNotes', # (so VRDOffset will get updated)
50 NikonCapture => 'MakerNotes', # (to allow delete by group)
51 PhaseOne => 'MakerNotes', # (for editing PhaseOne SensorCalibration tags)
52 );
53 61 my %exifMap = (
54 IFD1 => 'IFD0',
55 EXIF => 'IFD0', # to write EXIF as a block
56 ExifIFD => 'IFD0',
57 GPS => 'IFD0',
58 SubIFD => 'IFD0',
59 GlobParamIFD => 'IFD0',
60 PrintIM => 'IFD0',
61 InteropIFD => 'ExifIFD',
62 MakerNotes => 'ExifIFD',
63 NikonCapture => 'MakerNotes', # (to allow delete by group)
64 # (no CanonVRD trailer allowed)
65 );
66 61 my %jpegMap = (
67 %exifMap, # covers all JPEG EXIF mappings
68 JFIF => 'APP0',
69 CIFF => 'APP0',
70 IFD0 => 'APP1',
71 XMP => 'APP1',
72 ICC_Profile => 'APP2',
73 FlashPix => 'APP2',
74 MPF => 'APP2',
75 Meta => 'APP3',
76 MetaIFD => 'Meta',
77 RMETA => 'APP5',
78 SEAL => ['APP8','APP9'], # (note: add 'IFD0' if this is a possibility)
79 AROT => 'APP10',
80 JUMBF => 'APP11',
81 Ducky => 'APP12',
82 Photoshop => 'APP13',
83 Adobe => 'APP14',
84 IPTC => 'Photoshop',
85 MakerNotes => ['ExifIFD', 'CIFF'], # (first parent is the default)
86 CanonVRD => 'MakerNotes', # (so VRDOffset will get updated)
87 NikonCapture => 'MakerNotes', # (to allow delete by group)
88 Comment => 'COM',
89 );
90 61 my %dirMap = (
91 JPEG => \%jpegMap,
92 EXV => \%jpegMap,
93 TIFF => \%tiffMap,
94 ORF => \%tiffMap,
95 RAW => \%tiffMap,
96 EXIF => \%exifMap,
97 );
98  
99 # module names and write functions for each writable file type
100 # (defaults to "$type" and "Process$type" if not defined)
101 # - types that are handled specially will not appear in this list
102 61 my %writableType = (
103 CRW => [ 'CanonRaw', 'WriteCRW' ],
104 DR4 => 'CanonVRD',
105 EPS => [ 'PostScript', 'WritePS' ],
106 FLIF=> [ undef, 'WriteFLIF'],
107 GIF => undef,
108 ICC => [ 'ICC_Profile', 'WriteICC' ],
109 IND => 'InDesign',
110 JP2 => 'Jpeg2000',
111 JXL => 'Jpeg2000',
112 MIE => undef,
113 MOV => [ 'QuickTime', 'WriteMOV' ],
114 MRW => 'MinoltaRaw',
115 PDF => [ undef, 'WritePDF' ],
116 PNG => undef,
117 PPM => undef,
118 PS => [ 'PostScript', 'WritePS' ],
119 PSD => 'Photoshop',
120 RAF => [ 'FujiFilm', 'WriteRAF' ],
121 RIFF=> [ 'RIFF', 'WriteRIFF'],
122 VRD => 'CanonVRD',
123 WEBP=> [ 'RIFF', 'WriteRIFF'],
124 X3F => 'SigmaRaw',
125 XMP => [ undef, 'WriteXMP' ],
126 );
127  
128 # RAW file types (2 = raw file where we can delete maker notes from ExifIFD)
129 61 my %rawType = (
130 '3FR'=> 1, CR3 => 2, IIQ => 1, NEF => 1, RW2 => 1,
131 ARQ => 1, CRW => 1, K25 => 1, NRW => 1, RWL => 1,
132 ARW => 1, DCR => 1, KDC => 1, ORF => 1, SR2 => 1,
133 ARW => 1, ERF => 1, MEF => 1, PEF => 1, SRF => 1,
134 CR2 => 1, FFF => 1, MOS => 1, RAW => 1, SRW => 1,
135 );
136  
137 # groups we are allowed to delete
138 # Notes:
139 # 1) these names must either exist in %dirMap, or be translated in InitWriteDirs())
140 # 2) any dependencies must be added to %excludeGroups
141 61 my @delGroups = qw(
142 Adobe AFCP APP0 APP1 APP2 APP3 APP4 APP5 APP6 APP7 APP8 APP9 APP10 APP11 APP12
143 APP13 APP14 APP15 AROT AudioKeys CanonVRD CIFF Ducky EXIF ExifIFD File FlashPix
144 FotoStation GlobParamIFD GPS ICC_Profile IFD0 IFD1 Insta360 InteropIFD IPTC
145 ItemList iTunes JFIF Jpeg2000 JUMBF Keys MakerNotes Meta MetaIFD Microsoft MIE
146 MPF Nextbase NikonApp NikonCapture PDF PDF-update PhotoMechanic Photoshop PNG
147 PNG-pHYs PrintIM QuickTime RMETA RSRC SEAL SubIFD Trailer UserData VideoKeys
148 Vivo XML XML-* XMP XMP-*
149 );
150 # family 2 group names that we can delete
151 61 my @delGroup2 = qw(
152 Audio Author Camera Document ExifTool Image Location Other Preview Printing
153 Time Video
154 );
155 # Extra groups to delete when deleting another group
156 61 my %delMore = (
157 QuickTime => [ qw(ItemList UserData Keys) ],
158 XMP => [ 'XMP-*' ],
159 XML => [ 'XML-*' ],
160 SEAL => [ 'XMP-SEAL' ],
161 );
162  
163 # family 0 groups where directories should never be deleted
164 61 my %permanentDir = ( QuickTime => 1, Jpeg2000 => 1 );
165  
166 # lookup for all valid family 2 groups (lower case)
167 61 my %family2groups = map { lc $_ => 1 } @delGroup2, 'Unknown';
168  
169 # groups we don't delete when deleting all information
170 61 my $protectedGroups = '(IFD1|SubIFD|InteropIFD|GlobParamIFD|PDF-update|Adobe)';
171  
172 # other group names of new tag values to remove when deleting an entire group
173 61 my %removeGroups = (
174 IFD0 => [ 'EXIF', 'MakerNotes' ],
175 EXIF => [ 'MakerNotes' ],
176 ExifIFD => [ 'MakerNotes', 'InteropIFD' ],
177 Trailer => [ 'CanonVRD' ], #(because we can add back CanonVRD as a block)
178 );
179 # related family 0/1 groups in @delGroups (and not already in %jpegMap)
180 # that must be removed from delete list when excluding a group
181 61 my %excludeGroups = (
182 EXIF => [ qw(IFD0 IFD1 ExifIFD GPS MakerNotes GlobParamIFD InteropIFD PrintIM SubIFD) ],
183 IFD0 => [ 'EXIF' ],
184 IFD1 => [ 'EXIF' ],
185 ExifIFD => [ 'EXIF' ],
186 GPS => [ 'EXIF' ],
187 MakerNotes => [ 'EXIF' ],
188 InteropIFD => [ 'EXIF' ],
189 GlobParamIFD => [ 'EXIF' ],
190 PrintIM => [ 'EXIF' ],
191 CIFF => [ 'MakerNotes' ],
192 # technically correct, but very uncommon and not a good reason to avoid deleting trailer
193 # IPTC => [ qw(AFCP FotoStation Trailer) ],
194 AFCP => [ 'Trailer' ],
195 FotoStation => [ 'Trailer' ],
196 CanonVRD => [ 'Trailer' ],
197 PhotoMechanic=> [ 'Trailer' ],
198 MIE => [ 'Trailer' ],
199 QuickTime => [ qw(ItemList UserData Keys) ],
200 );
201 # translate (lower case) wanted group when writing for tags where group name may change
202 61 my %translateWantGroup = (
203 ciff => 'canonraw',
204 );
205 # group names to translate for writing
206 61 my %translateWriteGroup = (
207 EXIF => 'ExifIFD',
208 Meta => 'MetaIFD',
209 File => 'Comment',
210 # any entry in this table causes the write group to be set from the
211 # tag information instead of whatever the user specified...
212 MIE => 'MIE',
213 APP14 => 'APP14',
214 );
215 # names of valid EXIF and Meta directories (lower case keys):
216 61 my %exifDirs = (
217 gps => 'GPS',
218 exififd => 'ExifIFD',
219 subifd => 'SubIFD',
220 globparamifd => 'GlobParamIFD',
221 interopifd => 'InteropIFD',
222 previewifd => 'PreviewIFD', # (in MakerNotes)
223 metaifd => 'MetaIFD', # Kodak APP3 Meta
224 makernotes => 'MakerNotes',
225 );
226 # valid family 0 groups when WriteGroup is set to "All"
227 61 my %allFam0 = (
228 exif => 1,
229 makernotes => 1,
230 );
231  
232 61 my @writableMacOSTags = qw(
233 FileCreateDate MDItemFinderComment MDItemFSCreationDate MDItemFSLabel MDItemUserTags
234 XAttrQuarantine XAttrMDItemWhereFroms
235 );
236  
237 # min/max values for integer formats
238 61 my %intRange = (
239 'int8u' => [0, 0xff],
240 'int8s' => [-0x80, 0x7f],
241 'int16u' => [0, 0xffff],
242 'int16uRev' => [0, 0xffff],
243 'int16s' => [-0x8000, 0x7fff],
244 'int32u' => [0, 0xffffffff],
245 'int32s' => [-0x80000000, 0x7fffffff],
246 'int64u' => [0, 18446744073709551615],
247 'int64s' => [-9223372036854775808, 9223372036854775807],
248 );
249 # lookup for file types with block-writable EXIF
250 61 my %blockExifTypes = map { $_ => 1 } qw(JPEG PNG JP2 JXL MIE EXIF FLIF MOV MP4 RIFF);
251  
252 61 my $maxSegmentLen = 0xfffd; # maximum length of data in a JPEG segment
253 61 my $maxXMPLen = $maxSegmentLen; # maximum length of XMP data in JPEG
254  
255 # value separators when conversion list is used (in SetNewValue)
256 61 my %listSep = ( PrintConv => '; ?', ValueConv => ' ' );
257  
258 # printConv hash keys to ignore when doing reverse lookup
259 61 my %ignorePrintConv = map { $_ => 1 } qw(OTHER BITMASK Notes);
260  
261 #------------------------------------------------------------------------------
262 # Set tag value
263 # Inputs: 0) ExifTool object reference
264 # 1) tag key, tag name, or '*' (optionally prefixed by group name),
265 # or undef to reset all previous SetNewValue() calls
266 # 2) new value (scalar, scalar ref or list ref), or undef to delete tag
267 # 3-N) Options:
268 # Type => PrintConv, ValueConv or Raw - specifies value type
269 # AddValue => true to add to list of existing values instead of overwriting
270 # DelValue => true to delete this existing value value from a list, or
271 # or doing a conditional delete, or to shift a time value
272 # Group => family 0 or 1 group name (case insensitive)
273 # Replace => 0, 1 or 2 - overwrite previous new values (2=reset)
274 # Protected => bitmask to write tags with specified protections
275 # EditOnly => true to only edit existing tags (don't create new tag)
276 # EditGroup => true to only edit existing groups (don't create new group)
277 # Shift => undef, 0, +1 or -1 - shift value if possible
278 # NoFlat => treat flattened tags as 'unsafe'
279 # NoShortcut => true to prevent looking up shortcut tags
280 # ProtectSaved => protect existing new values with a save count greater than this
281 # IgnorePermanent => ignore attempts to delete a permanent tag
282 # CreateGroups => [internal use] createGroups hash ref from related tags
283 # ListOnly => [internal use] set only list or non-list tags
284 # SetTags => [internal use] hash ref to return tagInfo refs of set tags
285 # Sanitized => [internal use] set to avoid double-sanitizing the value
286 # Fixup => [internal use] fixup information when writing maker notes
287 # Returns: number of tags set (plus error string in list context)
288 # Notes: For tag lists (like Keywords), call repeatedly with the same tag name for
289 # each value in the list. Internally, the new information is stored in
290 # the following members of the $$self{NEW_VALUE}{$tagInfo} hash:
291 # TagInfo - tag info ref
292 # DelValue - list ref for raw values to delete
293 # Value - list ref for raw values to add (not defined if deleting the tag)
294 # IsCreating - must be set for the tag to be added for the standard file types,
295 # otherwise just changed if it already exists. This may be
296 # overridden for file types with a PREFERRED metadata type.
297 # Set to 2 to create individual tags but not new groups
298 # EditOnly - flag set if tag should never be created (regardless of file type).
299 # If this is set, then IsCreating must be false
300 # CreateOnly - flag set if creating only (never edit existing tag)
301 # CreateGroups - hash of all family 0 group names where tag may be created
302 # WriteGroup - group name where information is being written (correct case)
303 # WantGroup - group name as specified in call to function (case insensitive)
304 # Next - pointer to next new value hash (if more than one for this tag)
305 # NoReplace - set if value was created with Replace=0
306 # AddBefore - number of list items added by a subsequent Replace=0 call
307 # IsNVH - flag indicating this is a new value hash
308 # Order - counter to indicate the order that new value hashes were created
309 # Shift - shift value
310 # Save - counter used by SaveNewValues()/RestoreNewValues()
311 # MAKER_NOTE_FIXUP - pointer to fixup if necessary for a maker note value
312 sub SetNewValue($;$$%)
313 5774 ▶{
Subroutine SetNewValue: called CC=436 SCAR=71.7
Pod documented
314 5774 local $_;
315 5774 my ($self, $tag, $value, %options) = @_;
316 5774 my ($err, $tagInfo, $family);
317 5774 my $verbose = $$self{OPTIONS}{Verbose};
318 5774 my $out = $$self{OPTIONS}{TextOut};
319 5774 ▶ my $protected = $options{Protected} || 0;
Condition100%2/2
$options{'Protected'} || 0
l!l
3275447
MC/DC100%1/1
$options{'Protected'} || 0
$options{'Protected'}
Truth table100%2/2
A
A= $options{'Protected'}
Aresult
11
00
320 5774 my $listOnly = $options{ListOnly};
321 5774 my $setTags = $options{SetTags};
322 5774 my $noFlat = $options{NoFlat};
323 5774 my $numSet = 0;
324  
325 5774 ▶ unless (defined $tag) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tag) 43 5731 5774
326 43 delete $$self{NEW_VALUE};
327 43 $$self{SAVE_COUNT} = $$self{NV_COUNT} = 0;
328 43 $$self{DEL_GROUP} = { };
329 43 return 1;
330 }
331 # allow value to be scalar or list reference
332 5731 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) 218 5513 5731
333 218 ▶ if (ref $value eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 78 140 218
elsif (ref $value eq 'SCALAR') { } 127 13 140
334 # value is an ARRAY so it may have more than one entry
335 # - set values both separately and as a combined string if there are more than one
336 78 ▶ if (@$value > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$value > 1) { } 51 27 78
337 # set all list-type tags first
338 51 my $replace = $options{Replace};
339 51 my $noJoin;
340 51 foreach (@$value) {
341 153 ▶ $noJoin = 1 if ref $_;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 2 151 153
342 153 my ($n, $e) = SetNewValue($self, $tag, $_, %options, ListOnly => 1);
343 153 ▶ $err = $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 21 132 153
344 153 $numSet += $n;
345 153 delete $options{Replace}; # don't replace earlier values in list
346 }
347 51 ▶ return $numSet if $noJoin; # don't join if list contains objects
Branch: 1 branch
BranchTrueFalseTotal
if $noJoin 1 50 51
348 # and now set only non-list tags
349 50 $value = join $$self{OPTIONS}{ListSep}, @$value;
350 50 $options{Replace} = $replace;
351 50 $listOnly = $options{ListOnly} = 0;
352 } else {
353 27 $value = $$value[0];
354 27 ▶ $value = $$value if ref $value eq 'SCALAR'; # (handle single scalar ref in a list)
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "SCALAR" 0 27 27
355 }
356 } elsif (ref $value eq 'SCALAR') {
357 127 $value = $$value;
358 }
359 }
360 # un-escape as necessary and make sure the Perl UTF-8 flag is OFF for the value
361 # if perl is 5.6 or greater (otherwise our byte manipulations get corrupted!!)
362 5730 ▶ $self->Sanitize(\$value) if defined $value and not ref $value and not $options{Sanitized};
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and not ref $value and not $options{"Sanitized"} 5394 336 5730
Condition100%6/6
defined $value and not ref $value and not $options{"Sanitized"}
!ll&&!rl&&r
33335394
defined $value and not ref $value
!ll&&!rl&&r
307265397
MC/DC100%3/3
defined $value and not ref $value and not $options{"Sanitized"}
defined $value not ref $value not $options{"Sanitized"}
Truth table100%4/4
A and not(B) and not(C)
A= defined $valueB= not ref $valueC= not $options{"Sanitized"}
ABCresult
0XX0
10X0
1100
1111
363  
364 # set group name in options if specified
365 5730 ▶ ($options{Group}, $tag) = ($1, $2) if $tag =~ /(.*):(.+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /(.*):(.+)/ 574 5156 5730
366  
367 # allow trailing '#' for ValueConv value
368 5730 ▶ $options{Type} = 'ValueConv' if $tag =~ s/#$//;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ s/#$// 4 5726 5730
369 5730 ▶ my $convType = $options{Type} || ($$self{OPTIONS}{PrintConv} ? 'PrintConv' : 'ValueConv');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'OPTIONS'}{'PrintConv'} ? : 5185 151 5336
Condition66%2/3
$options{'Type'} || ($self->{'OPTIONS'}{'PrintConv'} ? 'PrintConv' : 'ValueConv')
l!l&&r!l&&!r
39453360
MC/DC0%0/2
$options{'Type'} || ($self->{'OPTIONS'}{'PrintConv'} ? 'PrintConv' : 'ValueConv')
$options{'Type'} ($self->{'OPTIONS'}{'PrintConv'} ? 'PrintConv' : 'ValueConv')
Truth table66%2/3
A || B
A= $options{'Type'}B= ($self->{'OPTIONS'}{'PrintConv'} ? 'PrintConv' : 'ValueConv')
ABresult
1X1
011
000
370  
371 # filter value if necessary
372 5730 ▶ $self->Filter($$self{OPTIONS}{FilterW}, \$value) or return 0 if $convType eq 'PrintConv';
Branch: 1 branch
BranchTrueFalseTotal
if $convType eq "PrintConv" 5208 522 5730
Condition60%3/5
$convType eq 'PrintConv' && ($self->Filter($self->{'OPTIONS'}{'FilterW'}, \$value) || (return 0))
!ll
52252080
$self->Filter($self->{"OPTIONS"}{"FilterW"}, \$value) or return 0
l!l
52080
MC/DC0%0/2
$convType eq 'PrintConv' && ($self->Filter($self->{'OPTIONS'}{'FilterW'}, \$value) || (return 0))
$convType eq 'PrintConv' $self->Filter($self->{"OPTIONS"}{"FilterW"}, \$value)
Truth table33%1/3
A && B
A= $convType eq 'PrintConv'B= $self->Filter($self->{"OPTIONS"}{"FilterW"}, \$value)
ABresult
0X0
100
111
373  
374 5730 my (@wantGroup, $family2);
375 5730 my $wantGroup = $options{Group};
376 5730 ▶ if ($wantGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantGroup) 2469 3261 5730
377 2469 foreach (split /:/, $wantGroup) {
378 2497 ▶ next unless length($_) and /^(\d+)?(.*)/; # separate family number and group name
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ and /^(\d+)?(.*)/ 0 2497 2497
Condition33%1/3
length $_ and /^(\d+)?(.*)/
!ll&&!rl&&r
002497
MC/DC0%0/2
length $_ and /^(\d+)?(.*)/
length $_ /^(\d+)?(.*)/
Truth table33%1/3
A and B
A= length $_B= /^(\d+)?(.*)/
ABresult
0X0
100
111
379 2497 my ($f, $g) = ($1, $2);
380 2497 my $lcg = lc $g;
381 # save group/family unless '*' or 'all'
382 2497 ▶ push @wantGroup, [ $f, $lcg ] unless $lcg eq '*' or $lcg eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
unless $lcg eq "*" or $lcg eq "all" 2388 109 2497
Condition66%2/3
$lcg eq "*" or $lcg eq "all"
l!l&&r!l&&!r
01092388
MC/DC50%1/2
$lcg eq "*" or $lcg eq "all"
$lcg eq "*" $lcg eq "all"
Truth table66%2/3
A or B
A= $lcg eq "*"B= $lcg eq "all"
ABresult
1X1
011
000
383 2497 ▶ if ($g =~ s/^ID-//i) { # family 7 is a tag ID
Branch: 2 branches
BranchTrueFalseTotal
if ($g =~ s/^ID-//i) { } 1 2496 2497
elsif (defined $f) { } 30 2466 2496
384 1 ▶ return 0 if defined $f and $f ne 7;
Branch: 1 branch
BranchTrueFalseTotal
if defined $f and $f ne 7 0 1 1
Condition33%1/3
defined $f and $f ne 7
!ll&&!rl&&r
100
MC/DC0%0/2
defined $f and $f ne 7
defined $f $f ne 7
Truth table33%1/3
A and B
A= defined $fB= $f ne 7
ABresult
0X0
100
111
385 1 $wantGroup[-1] = [ 7, $g ]; # group name with 'ID-' removed and case preserved
386 } elsif (defined $f) {
387 30 ▶ $f > 2 and return 0; # only allow family 0, 1 or 2
Branch: 1 branch
BranchTrueFalseTotal
$f > 2 and return 0 0 30 30
388 30 ▶ $family2 = 1 if $f == 2; # set flag indicating family 2 was used
Branch: 1 branch
BranchTrueFalseTotal
if $f == 2 9 21 30
389 } else {
390 2466 ▶ $family2 = 1 if $family2groups{$lcg};
Branch: 1 branch
BranchTrueFalseTotal
if $family2groups{$lcg} 102 2364 2466
391 }
392 }
393 2469 ▶ undef $wantGroup unless @wantGroup;
Branch: 1 branch
BranchTrueFalseTotal
unless @wantGroup 109 2360 2469
394 }
395  
396 5730 $tag =~ s/ .*//; # convert from tag key to tag name if necessary
397 5730 ▶ $tag = '*' if lc($tag) eq 'all'; # use '*' instead of 'all'
Branch: 1 branch
BranchTrueFalseTotal
if lc $tag eq "all" 39 5691 5730
398 #
399 # handle group delete
400 #
401 5730 ▶ while ($tag eq '*' and not defined $value and not $family2 and @wantGroup < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "*" and not defined $value and not $family2 and @wantGroup < 2) 49 5681 5730
Condition88%8/9
$tag eq "*" and not defined $value and not $family2 and @wantGroup < 2
!ll&&!rl&&r
5681049
$tag eq "*" and not defined $value and not $family2
!ll&&!rl&&r
5679249
$tag eq "*" and not defined $value
!ll&&!rl&&r
5678151
MC/DC75%3/4
$tag eq "*" and not defined $value and not $family2 and @wantGroup < 2
$tag eq "*" not defined $value not $family2 @wantGroup < 2
Truth table80%4/5
A and not(B) and not(C) and D
A= $tag eq "*"B= not defined $valueC= not $family2D= @wantGroup < 2
ABCDresult
0XXX0
10XX0
110X0
11100
11111
402 # set groups to delete
403 49 my (@del, $grp);
404 49 ▶ my $remove = ($options{Replace} and $options{Replace} > 1);
Condition66%2/3
$options{'Replace'} && $options{'Replace'} > 1
!ll&&!rl&&r
4207
MC/DC50%1/2
$options{'Replace'} && $options{'Replace'} > 1
$options{'Replace'} $options{'Replace'} > 1
Truth table66%2/3
A && B
A= $options{'Replace'}B= $options{'Replace'} > 1
ABresult
0X0
100
111
405 49 ▶ if ($wantGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantGroup) { } 35 14 49
406 35 ▶ @del = grep /^$wantGroup$/i, @delGroups unless $wantGroup =~ /^XM[LP]-\*$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $wantGroup =~ /^XM[LP]-\*$/i 35 0 35
407 # remove associated groups when excluding from mass delete
408 35 ▶ if (@del and $remove) {
Branch: 1 branch
BranchTrueFalseTotal
if (@del and $remove) 4 31 35
Condition100%3/3
@del and $remove
!ll&&!rl&&r
7244
MC/DC100%2/2
@del and $remove
@del $remove
Truth table100%3/3
A and B
A= @delB= $remove
ABresult
0X0
100
111
409 # remove associated groups in other family
410 4 ▶ push @del, @{$excludeGroups{$del[0]}} if $excludeGroups{$del[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $excludeGroups{$del[0]} 2 2 4
411 # remove upstream groups according to JPEG map
412 4 my $dirName = $del[0];
413 4 my @dirNames;
414 4 for (;;) {
415 10 my $parent = $jpegMap{$dirName};
416 10 ▶ if (ref $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parent) 0 10 10
417 0 push @dirNames, @$parent;
418 0 $parent = pop @dirNames;
419 }
420 10 ▶ $dirName = $parent || shift @dirNames or last;
Branch: 1 branch
BranchTrueFalseTotal
$dirName = $parent || shift @dirNames or last 6 4 10
Condition66%2/3
$parent || shift @dirNames
l!l&&r!l&&!r
604
MC/DC50%1/2
$parent || shift @dirNames
$parent shift @dirNames
Truth table66%2/3
A || B
A= $parentB= shift @dirNames
ABresult
1X1
011
000
421 6 push @del, $dirName; # exclude this too
422 }
423 }
424 # allow MIE groups to be deleted by number,
425 # and allow any XMP family 1 group to be deleted
426 35 ▶ push @del, uc($wantGroup) if $wantGroup =~ /^(MIE\d+|XM[LP]-[-\w]*\w)$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $wantGroup =~ /^(MIE\d+|XM[LP]-[-\w]*\w)$/i 7 28 35
427 } else {
428 # push all groups plus '*', except the protected groups
429 14 push @del, (grep !/^$protectedGroups$/, @delGroups), '*';
430 }
431 49 ▶ if (@del) {
Branch: 2 branches
BranchTrueFalseTotal
if (@del) { } 49 0 49
elsif (grep /^$wantGroup$/i, @delGroup2) { } 0 0 0
432 49 ++$numSet;
433 49 my @donegrps;
434 49 my $delGroup = $$self{DEL_GROUP};
435 49 foreach $grp (@del) {
436 975 ▶ if ($remove) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove) { } 23 952 975
437 23 my $didExcl;
438 23 ▶ if ($grp =~ /^(XM[LP])(-.*)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grp =~ /^(XM[LP])(-.*)?$/) 4 19 23
439 4 my $x = $1;
440 4 ▶ if ($grp eq $x) {
Branch: 2 branches
BranchTrueFalseTotal
if ($grp eq $x) { } 1 3 4
elsif ($$delGroup{"$x-*"} and not $$delGroup{"-$grp"}) { } 3 0 3
441 # exclude all related family 1 groups too
442 1 foreach (keys %$delGroup) {
443 67 ▶ next unless /^(-?)$x-/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^(-?)$x-/ 65 2 67
444 2 ▶ push @donegrps, $_ unless $1;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 2 0 2
445 2 delete $$delGroup{$_};
446 }
447 ▶ } elsif ($$delGroup{"$x-*"} and not $$delGroup{"-$grp"}) {
Condition33%1/3
$$delGroup{"$x-*"} and not $$delGroup{"-$grp"}
!ll&&!rl&&r
003
MC/DC0%0/2
$$delGroup{"$x-*"} and not $$delGroup{"-$grp"}
$$delGroup{"$x-*"} not $$delGroup{"-$grp"}
Truth table33%1/3
A and not(B)
A= $$delGroup{"$x-*"}B= not $$delGroup{"-$grp"}
ABresult
0X0
100
111
448 # must also exclude XMP or XML to prevent bulk delete
449 3 ▶ if ($$delGroup{$x}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delGroup->{$x}) 2 1 3
450 2 push @donegrps, $x;
451 2 delete $$delGroup{$x};
452 }
453 # flag XMP/XML family 1 group for exclusion with leading '-'
454 3 $$delGroup{"-$grp"} = 1;
455 3 $didExcl = 1;
456 }
457 }
458 23 ▶ if (exists $$delGroup{$grp}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $delGroup->{$grp}) { } 15 8 23
459 15 delete $$delGroup{$grp};
460 } else {
461 8 ▶ next unless $didExcl;
Branch: 1 branch
BranchTrueFalseTotal
unless $didExcl 5 3 8
462 }
463 } else {
464 952 $$delGroup{$grp} = 1;
465 # add extra groups to delete if necessary
466 952 ▶ if ($delMore{$grp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delMore{$grp}) 66 886 952
467 66 $$delGroup{$_} = 1, push @donegrps, $_ foreach @{$delMore{$grp}};
468 }
469 # remove all of this group from previous new values
470 952 $self->RemoveNewValuesForGroup($grp);
471 }
472 970 push @donegrps, $grp;
473 }
474 49 ▶ if ($verbose > 1 and @donegrps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1 and @donegrps) 1 48 49
Condition66%2/3
$verbose > 1 and @donegrps
!ll&&!rl&&r
4801
MC/DC50%1/2
$verbose > 1 and @donegrps
$verbose > 1 @donegrps
Truth table66%2/3
A and B
A= $verbose > 1B= @donegrps
ABresult
0X0
100
111
475 1 @donegrps = sort @donegrps;
476 1 ▶ my $msg = $remove ? 'Excluding from deletion' : 'Deleting tags in';
Branch: 1 branch
BranchTrueFalseTotal
$remove ? : 0 1 1
477 1 print $out " $msg: @donegrps\n";
478 }
479 } elsif (grep /^$wantGroup$/i, @delGroup2) {
480 0 last; # allow tags to be deleted by group2 name
481 } else {
482 0 $err = "Not a deletable group: $wantGroup";
483 }
484 # all done
485 49 ▶ return ($numSet, $err) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 49 49
486 49 ▶ $err and warn "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$err and warn "$err\n" 0 49 49
487 49 return $numSet;
488 }
489  
490 # initialize write/create flags
491 5681 my $createOnly;
492 5681 my $editOnly = $options{EditOnly};
493 5681 my $editGroup = $options{EditGroup};
494 5681 my $writeMode = $$self{OPTIONS}{WriteMode};
495 5681 ▶ if ($writeMode ne 'wcg') {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeMode ne "wcg") 27 5654 5681
496 27 ▶ $createOnly = 1 if $writeMode !~ /w/i; # don't write existing tags
Branch: 1 branch
BranchTrueFalseTotal
unless $writeMode =~ /w/i 25 2 27
497 27 ▶ if ($writeMode !~ /c/i) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $writeMode =~ /c/i) { } 2 25 27
elsif (not $writeMode =~ /g/i) { } 8 17 25
498 2 ▶ return 0 if $createOnly; # nothing to do unless writing existing tags
Branch: 1 branch
BranchTrueFalseTotal
if $createOnly 0 2 2
499 2 $editOnly = 1; # don't create new tags
500 } elsif ($writeMode !~ /g/i) {
501 8 $editGroup = 1; # don't create new groups
502 }
503 }
504 5681 my ($ifdName, $mieGroup, $movGroup, $fg);
505 # set family 1 group names
506 5681 foreach $fg (@wantGroup) {
507 2353 ▶ next if defined $$fg[0] and $$fg[0] != 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fg->[0] and $fg->[0] != 1 19 2334 2353
Condition100%3/3
defined $fg->[0] and $fg->[0] != 1
!ll&&!rl&&r
23221219
MC/DC100%2/2
defined $fg->[0] and $fg->[0] != 1
defined $fg->[0] $fg->[0] != 1
Truth table100%3/3
A and B
A= defined $fg->[0]B= $fg->[0] != 1
ABresult
0X0
100
111
508 2334 $_ = $$fg[1];
509 # set $ifdName if this group is a valid IFD or SubIFD name
510 2334 my $grpName;
511 2334 ▶ if (/^IFD(\d+)$/i) {
Branch: 8 branches
BranchTrueFalseTotal
if (/^IFD(\d+)$/i) { } 131 2203 2334
elsif (/^SubIFD(\d+)$/i) { } 0 2203 2203
elsif (/^Version(\d+)$/i) { } 0 2203 2203
elsif ($exifDirs{$_}) { } 274 1929 2203
elsif ($allFam0{$_}) { } 293 1636 1929
elsif (/^Track(\d+)$/i) { } 1 1635 1636
elsif (/^MIE(\d*-?)(\w+)$/i) { } 2 1633 1635
elsif (not $ifdName and /^XMP\b/i) { } 519 1120 1639
512 131 $grpName = $ifdName = "IFD$1";
513 } elsif (/^SubIFD(\d+)$/i) {
514 0 $grpName = $ifdName = "SubIFD$1";
515 } elsif (/^Version(\d+)$/i) {
516 0 $grpName = $ifdName = "Version$1"; # Sony IDC VersionIFD
517 } elsif ($exifDirs{$_}) {
518 274 $grpName = $exifDirs{$_};
519 274 ▶ $ifdName = $grpName unless $ifdName and $allFam0{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $ifdName and $allFam0{$_} 274 0 274
Condition33%1/3
$ifdName and $allFam0{$_}
!ll&&!rl&&r
27400
MC/DC0%0/2
$ifdName and $allFam0{$_}
$ifdName $allFam0{$_}
Truth table33%1/3
A and B
A= $ifdNameB= $allFam0{$_}
ABresult
0X0
100
111
520 } elsif ($allFam0{$_}) {
521 293 $grpName = $allFam0{$_};
522 } elsif (/^Track(\d+)$/i) {
523 1 $grpName = $movGroup = "Track$1"; # QuickTime track
524 } elsif (/^MIE(\d*-?)(\w+)$/i) {
525 2 $grpName = $mieGroup = "MIE$1" . ucfirst(lc($2));
526 ▶ } elsif (not $ifdName and /^XMP\b/i) {
Condition100%3/3
not $ifdName and /^XMP\b/i
!ll&&!rl&&r
61108519
MC/DC100%2/2
not $ifdName and /^XMP\b/i
not $ifdName /^XMP\b/i
Truth table100%3/3
not(A) and B
A= not $ifdNameB= /^XMP\b/i
ABresult
0X0
100
111
527 # must load XMP table to set group1 names
528 519 my $table = GetTagTable('Image::ExifTool::XMP::Main');
529 519 my $writeProc = $$table{WRITE_PROC};
530 519 ▶ if ($writeProc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeProc) 519 0 519
531 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
532 519 &$writeProc();
533 }
534 }
535 # fix case for known groups
536 2334 ▶ $wantGroup =~ s/$grpName/$grpName/i if $grpName and $grpName ne $_;
Branch: 1 branch
BranchTrueFalseTotal
if $grpName and $grpName ne $_ 701 1633 2334
Condition66%2/3
$grpName and $grpName ne $_
!ll&&!rl&&r
16330701
MC/DC50%1/2
$grpName and $grpName ne $_
$grpName $grpName ne $_
Truth table66%2/3
A and B
A= $grpNameB= $grpName ne $_
ABresult
0X0
100
111
537 }
538 #
539 # get list of tags we want to set
540 #
541 5681 my $origTag = $tag;
542 5681 my @matchingTags = FindTagInfo($tag);
543 5681 ▶ until (@matchingTags) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@matchingTags) 1422 4259 5681
544 1422 my $langCode;
545 # allow language suffix of form "-en_CA" or "-<rfc3066>" on tag name
546 1422 ▶ if ($tag =~ /^([?*\w]+)-([a-z]{2})(_[a-z]{2})$/i or # MIE
Branch: 2 branches
BranchTrueFalseTotal
if ($tag =~ /^([?*\w]+)-([a-z]{2})(_[a-z]{2})$/i or $tag =~ /^([?*\w]+)-([a-z]{2,3}|[xi])(-[a-z\d]{2,8}(-[a-z\d]{1,8})*)?$/i) { } 55 1367 1422
elsif (not $options{'NoShortcut'}) { } 1367 0 1367
Condition100%3/3
$tag =~ /^([?*\w]+)-([a-z]{2})(_[a-z]{2})$/i or $tag =~ /^([?*\w]+)-([a-z]{2,3}|[xi])(-[a-z\d]{2,8}(-[a-z\d]{1,8})*)?$/i
l!l&&r!l&&!r
12431367
MC/DC100%2/2
$tag =~ /^([?*\w]+)-([a-z]{2})(_[a-z]{2})$/i or $tag =~ /^([?*\w]+)-([a-z]{2,3}|[xi])(-[a-z\d]{2,8}(-[a-z\d]{1,8})*)?$/i
$tag =~ /^([?*\w]+)-([a-z]{2})(_[a-z]{2})$/i $tag =~ /^([?*\w]+)-([a-z]{2,3}|[xi])(-[a-z\d]{2,8}(-[a-z\d]{1,8})*)?$/i
Truth table100%3/3
A or B
A= $tag =~ /^([?*\w]+)-([a-z]{2})(_[a-z]{2})$/iB= $tag =~ /^([?*\w]+)-([a-z]{2,3}|[xi])(-[a-z\d]{2,8}(-[a-z\d]{1,8})*)?$/i
ABresult
1X1
011
000
547 $tag =~ /^([?*\w]+)-([a-z]{2,3}|[xi])(-[a-z\d]{2,8}(-[a-z\d]{1,8})*)?$/i) # XMP/PNG/QuickTime
548 {
549 55 $tag = $1;
550 # normalize case of language codes
551 55 $langCode = lc($2);
552 55 ▶ $langCode .= (length($3) == 3 ? uc($3) : lc($3)) if $3;
Branch: 2 branches
BranchTrueFalseTotal
if $3 25 30 55
length $3 == 3 ? : 22 3 25
553 55 my @newMatches = FindTagInfo($tag);
554 55 foreach $tagInfo (@newMatches) {
555 # only allow language codes in tables which support them
556 291 ▶ next unless $$tagInfo{Table};
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo->{"Table"} 0 291 291
557 291 ▶ my $langInfoProc = $$tagInfo{Table}{LANG_INFO} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $langInfoProc = $tagInfo->{"Table"}{"LANG_INFO"} or next 226 65 291
558 226 my $langInfo = &$langInfoProc($tagInfo, $langCode);
559 226 ▶ push @matchingTags, $langInfo if $langInfo;
Branch: 1 branch
BranchTrueFalseTotal
if $langInfo 200 26 226
560 }
561 55 ▶ last if @matchingTags;
Branch: 1 branch
BranchTrueFalseTotal
if @matchingTags 53 2 55
562 } elsif (not $options{NoShortcut}) {
563 # look for a shortcut or alias
564 1367 require Image::ExifTool::Shortcuts;
565 1367 my ($match) = grep /^\Q$tag\E$/i, keys %Image::ExifTool::Shortcuts::Main;
566 1367 undef $err;
567 1367 ▶ if ($match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match) 1 1366 1367
568 1 $options{NoShortcut} = $options{Sanitized} = 1;
569 1 foreach $tag (@{$Image::ExifTool::Shortcuts::Main{$match}}) {
570 3 my ($n, $e) = $self->SetNewValue($tag, $value, %options);
571 3 $numSet += $n;
572 3 ▶ $e and $err = $e;
Branch: 1 branch
BranchTrueFalseTotal
$e and $err = $e 0 3 3
573 }
574 1 ▶ undef $err if $numSet; # no error if any set successfully
Branch: 1 branch
BranchTrueFalseTotal
if $numSet 1 0 1
575 1 ▶ return ($numSet, $err) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 1 1
576 1 ▶ $err and warn "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$err and warn "$err\n" 0 1 1
577 1 return $numSet;
578 }
579 }
580 1368 ▶ unless ($listOnly) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($listOnly) 1368 0 1368
581 1368 ▶ if (not TagExists($tag)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not &TagExists($tag)) { } 47 1321 1368
elsif ($langCode) { } 0 1321 1321
elsif ($wantGroup) { } 509 812 1321
582 47 ▶ if ($tag =~ /^[-\w*?]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^[-\w*?]+$/) { } 47 0 47
583 47 ▶ my $pre = $wantGroup ? $wantGroup . ':' : '';
Branch: 1 branch
BranchTrueFalseTotal
$wantGroup ? : 28 19 47
584 47 $err = "Tag '$pre${origTag}' is not defined";
585 47 ▶ $err .= ' or has a bad language code' if $origTag =~ /-/;
Branch: 1 branch
BranchTrueFalseTotal
if $origTag =~ /-/ 2 45 47
586 47 ▶ if (not $pre and uc($origTag) eq 'TAG') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pre and uc $origTag eq "TAG") 0 47 47
Condition66%2/3
not $pre and uc $origTag eq "TAG"
!ll&&!rl&&r
28190
MC/DC0%0/2
not $pre and uc $origTag eq "TAG"
not $pre uc $origTag eq "TAG"
Truth table66%2/3
not(A) and B
A= not $preB= uc $origTag eq "TAG"
ABresult
0X0
100
111
587 0 $err .= " (specify a writable tag name, not '${origTag}' literally)"
588 }
589 } else {
590 0 $err = "Invalid tag name '${tag}'";
591 0 ▶ $err .= " (remove the leading '\$')" if $tag =~ /^\$/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^\$/ 0 0 0
592 }
593 } elsif ($langCode) {
594 0 $err = "Tag '${tag}' does not support alternate languages";
595 } elsif ($wantGroup) {
596 509 $err = "Sorry, $wantGroup:$origTag doesn't exist or isn't writable";
597 } else {
598 812 $err = "Sorry, $origTag is not writable";
599 }
600 1368 ▶ $verbose > 2 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "$err\n" 0 1368 1368
601 }
602 # all done
603 1368 ▶ return ($numSet, $err) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1368 0 1368
604 0 ▶ $err and warn "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$err and warn "$err\n" 0 0 0
605 0 return $numSet;
606 }
607 # get group name that we're looking for
608 4312 my $foundMatch = 0;
609 #
610 # determine the groups for all tags found, and the tag with
611 # the highest priority group
612 #
613 4312 my (@tagInfoList, @writeAlsoList, %writeGroup, %preferred, %tagPriority);
614 4312 my (%avoid, $wasProtected, $noCreate, %highestPriority, %highestQT);
615  
616 4312 TAG: foreach $tagInfo (@matchingTags) {
617 75823 $tag = $$tagInfo{Name}; # get tag name for warnings
618 75823 my $lcTag = lc $tag; # get lower-case tag name for use in variables
619 # initialize highest priority if we are starting a new tag
620 75823 ▶ $highestPriority{$lcTag} = -999 unless defined $highestPriority{$lcTag};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $highestPriority{$lcTag} 26060 49763 75823
621 75823 my ($priority, $writeGroup);
622 75823 ▶ my $prfTag = defined $$tagInfo{Preferred} ? $$tagInfo{Preferred} : $$tagInfo{Table}{PREFERRED};
Branch: 1 branch
BranchTrueFalseTotal
defined $tagInfo->{'Preferred'} ? : 812 75011 75823
623 75823 ▶ if ($wantGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantGroup) 54905 20918 75823
624 # a WriteGroup of All is special
625 54905 ▶ my $wgAll = ($$tagInfo{WriteGroup} and $$tagInfo{WriteGroup} eq 'All');
Condition100%3/3
$tagInfo->{'WriteGroup'} && $tagInfo->{'WriteGroup'} eq 'All'
!ll&&!rl&&r
533821411112
MC/DC100%2/2
$tagInfo->{'WriteGroup'} && $tagInfo->{'WriteGroup'} eq 'All'
$tagInfo->{'WriteGroup'} $tagInfo->{'WriteGroup'} eq 'All'
Truth table100%3/3
A && B
A= $tagInfo->{'WriteGroup'}B= $tagInfo->{'WriteGroup'} eq 'All'
ABresult
0X0
100
111
626 54905 my @grp = $self->GetGroup($tagInfo);
627 54905 my $hiPri = 1000;
628 54905 foreach $fg (@wantGroup) {
629 54945 my ($fam, $lcWant) = @$fg;
630 54945 ▶ $lcWant = $translateWantGroup{$lcWant} if $translateWantGroup{$lcWant};
Branch: 1 branch
BranchTrueFalseTotal
if $translateWantGroup{$lcWant} 235 54710 54945
631 # only set tag in specified group
632 # bump priority of preferred tag
633 54945 ▶ $hiPri += $prfTag if $prfTag;
Branch: 1 branch
BranchTrueFalseTotal
if $prfTag 2230 52715 54945
634 54945 ▶ if (not defined $fam) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $fam) { } 54665 280 54945
elsif ($fam == 7) { } 2 278 280
elsif ($fam != 1 and not $tagInfo->{'AllowGroup'}) { } 156 244 400
635 54665 ▶ if ($lcWant eq lc $grp[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lcWant eq lc $grp[0]) 2244 52421 54665
636 # don't go to more general write group of "All"
637 # if something more specific was wanted
638 2244 ▶ $writeGroup = $grp[0] if $wgAll and not $writeGroup;
Branch: 1 branch
BranchTrueFalseTotal
if $wgAll and not $writeGroup 4 2240 2244
Condition100%3/3
$wgAll and not $writeGroup
!ll&&!rl&&r
223554
MC/DC100%2/2
$wgAll and not $writeGroup
$wgAll not $writeGroup
Truth table100%3/3
A and not(B)
A= $wgAllB= not $writeGroup
ABresult
0X0
100
111
639 2244 next;
640 }
641 52421 ▶ next if $lcWant eq lc $grp[2];
Branch: 1 branch
BranchTrueFalseTotal
if $lcWant eq lc $grp[2] 12080 40341 52421
642 } elsif ($fam == 7) {
643 2 ▶ next if IsSameID($$tagInfo{TagID}, $lcWant);
Branch: 1 branch
BranchTrueFalseTotal
if &IsSameID($tagInfo->{"TagID"}, $lcWant) 1 1 2
644 ▶ } elsif ($fam != 1 and not $$tagInfo{AllowGroup}) {
Condition66%2/3
$fam != 1 and not $tagInfo->{"AllowGroup"}
!ll&&!rl&&r
1220156
MC/DC50%1/2
$fam != 1 and not $tagInfo->{"AllowGroup"}
$fam != 1 not $tagInfo->{"AllowGroup"}
Truth table66%2/3
A and not(B)
A= $fam != 1B= not $tagInfo->{"AllowGroup"}
ABresult
0X0
100
111
645 156 ▶ next if $lcWant eq lc $grp[$fam];
Branch: 1 branch
BranchTrueFalseTotal
if $lcWant eq lc $grp[$fam] 24 132 156
646 132 ▶ if ($wgAll and not $fam and $allFam0{$lcWant}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wgAll and not $fam and $allFam0{$lcWant}) 5 127 132
Condition100%6/6
$wgAll and not $fam and $allFam0{$lcWant}
!ll&&!rl&&r
117105
$wgAll and not $fam
!ll&&!rl&&r
1051215
MC/DC100%3/3
$wgAll and not $fam and $allFam0{$lcWant}
$wgAll not $fam $allFam0{$lcWant}
Truth table100%4/4
A and not(B) and C
A= $wgAllB= not $famC= $allFam0{$lcWant}
ABCresult
0XX0
10X0
1100
1111
647 5 ▶ $writeGroup or $writeGroup = $allFam0{$lcWant};
Branch: 1 branch
BranchTrueFalseTotal
$writeGroup or $writeGroup = $allFam0{$lcWant} 2 3 5
648 5 next;
649 }
650 127 next TAG; # wrong group
651 }
652 # handle family 1 groups specially
653 40464 ▶ if ($grp[0] eq 'EXIF' or $grp[0] eq 'SonyIDC' or $wgAll) {
Branch: 4 branches
BranchTrueFalseTotal
if ($grp[0] eq 'EXIF' or $grp[0] eq 'SonyIDC' or $wgAll) { } 1644 38820 40464
elsif ($grp[0] eq 'QuickTime') { } 1765 37055 38820
elsif ($grp[0] eq 'MIE') { } 768 36287 37055
elsif (not $tagInfo->{'AllowGroup'} && $lcWant =~ /^$tagInfo->{'AllowGroup'}$/i) { } 36281 6 36287
Condition83%5/6
$grp[0] eq "EXIF" or $grp[0] eq "SonyIDC" or $wgAll
l!l&&r!l&&!r
16123238820
$grp[0] eq "EXIF" or $grp[0] eq "SonyIDC"
l!l&&r!l&&!r
1612038852
MC/DC66%2/3
$grp[0] eq "EXIF" or $grp[0] eq "SonyIDC" or $wgAll
$grp[0] eq "EXIF" $grp[0] eq "SonyIDC" $wgAll
Truth table75%3/4
A or B or C
A= $grp[0] eq "EXIF"B= $grp[0] eq "SonyIDC"C= $wgAll
ABCresult
1XX1
01X1
0011
0000
654 1644 ▶ unless ($ifdName and $lcWant eq lc $ifdName) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ifdName and $lcWant eq lc $ifdName) 1194 450 1644
Condition100%3/3
$ifdName and $lcWant eq lc $ifdName
!ll&&!rl&&r
118410450
MC/DC100%2/2
$ifdName and $lcWant eq lc $ifdName
$ifdName $lcWant eq lc $ifdName
Truth table100%3/3
A and B
A= $ifdNameB= $lcWant eq lc $ifdName
ABresult
0X0
100
111
655 1194 ▶ next TAG unless $wgAll and not $fam and $allFam0{$lcWant};
Branch: 1 branch
BranchTrueFalseTotal
unless $wgAll and not $fam and $allFam0{$lcWant} 1187 7 1194
Condition100%6/6
$wgAll and not $fam and $allFam0{$lcWant}
!ll&&!rl&&r
1162257
$wgAll and not $fam
!ll&&!rl&&r
11501232
MC/DC100%3/3
$wgAll and not $fam and $allFam0{$lcWant}
$wgAll not $fam $allFam0{$lcWant}
Truth table100%4/4
A and not(B) and C
A= $wgAllB= not $famC= $allFam0{$lcWant}
ABCresult
0XX0
10X0
1100
1111
656 7 ▶ $writeGroup = $allFam0{$lcWant} unless $writeGroup;
Branch: 1 branch
BranchTrueFalseTotal
unless $writeGroup 2 5 7
657 7 next;
658 }
659 450 ▶ next TAG if $wgAll and $allFam0{$lcWant} and $fam;
Branch: 1 branch
BranchTrueFalseTotal
if $wgAll and $allFam0{$lcWant} and $fam 2 448 450
Condition100%6/6
$wgAll and $allFam0{$lcWant} and $fam
!ll&&!rl&&r
44082
$wgAll and $allFam0{$lcWant}
!ll&&!rl&&r
4013910
MC/DC100%3/3
$wgAll and $allFam0{$lcWant} and $fam
$wgAll $allFam0{$lcWant} $fam
Truth table100%4/4
A and B and C
A= $wgAllB= $allFam0{$lcWant}C= $fam
ABCresult
0XX0
10X0
1100
1111
660 # can't yet write PreviewIFD tags (except for image)
661 448 ▶ $lcWant eq 'PreviewIFD' and ++$foundMatch, next TAG;
Branch: 1 branch
BranchTrueFalseTotal
$lcWant eq "PreviewIFD" and ++$foundMatch, next TAG 0 448 448
662 448 $writeGroup = $ifdName; # write to the specified IFD
663 } elsif ($grp[0] eq 'QuickTime') {
664 1765 ▶ if ($grp[1] eq 'Track#') {
Branch: 1 branch
BranchTrueFalseTotal
if ($grp[1] eq 'Track#') { } 16 1749 1765
665 16 ▶ next TAG unless $movGroup and $lcWant eq lc($movGroup);
Branch: 1 branch
BranchTrueFalseTotal
unless $movGroup and $lcWant eq lc $movGroup 15 1 16
Condition66%2/3
$movGroup and $lcWant eq lc $movGroup
!ll&&!rl&&r
1501
MC/DC50%1/2
$movGroup and $lcWant eq lc $movGroup
$movGroup $lcWant eq lc $movGroup
Truth table66%2/3
A and B
A= $movGroupB= $lcWant eq lc $movGroup
ABresult
0X0
100
111
666 1 $writeGroup = $movGroup;
667 } else {
668 1749 my $grp = $$tagInfo{Table}{WRITE_GROUP};
669 1749 ▶ next TAG unless $grp and $lcWant eq lc $grp;
Branch: 1 branch
BranchTrueFalseTotal
unless $grp and $lcWant eq lc $grp 1701 48 1749
Condition100%3/3
$grp and $lcWant eq lc $grp
!ll&&!rl&&r
81162048
MC/DC100%2/2
$grp and $lcWant eq lc $grp
$grp $lcWant eq lc $grp
Truth table100%3/3
A and B
A= $grpB= $lcWant eq lc $grp
ABresult
0X0
100
111
670 48 $writeGroup = $grp;
671 }
672 } elsif ($grp[0] eq 'MIE') {
673 768 ▶ next TAG unless $mieGroup and $lcWant eq lc($mieGroup);
Branch: 1 branch
BranchTrueFalseTotal
unless $mieGroup and $lcWant eq lc $mieGroup 766 2 768
Condition66%2/3
$mieGroup and $lcWant eq lc $mieGroup
!ll&&!rl&&r
76602
MC/DC50%1/2
$mieGroup and $lcWant eq lc $mieGroup
$mieGroup $lcWant eq lc $mieGroup
Truth table66%2/3
A and B
A= $mieGroupB= $lcWant eq lc $mieGroup
ABresult
0X0
100
111
674 2 $writeGroup = $mieGroup; # write to specific MIE group
675 # set specific write group with document number if specified
676 2 ▶ if ($writeGroup =~ /^MIE\d+$/ and $$tagInfo{Table}{WRITE_GROUP}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeGroup =~ /^MIE\d+$/ and $tagInfo->{"Table"}{"WRITE_GROUP"}) 0 2 2
Condition33%1/3
$writeGroup =~ /^MIE\d+$/ and $tagInfo->{"Table"}{"WRITE_GROUP"}
!ll&&!rl&&r
200
MC/DC0%0/2
$writeGroup =~ /^MIE\d+$/ and $tagInfo->{"Table"}{"WRITE_GROUP"}
$writeGroup =~ /^MIE\d+$/ $tagInfo->{"Table"}{"WRITE_GROUP"}
Truth table33%1/3
A and B
A= $writeGroup =~ /^MIE\d+$/B= $tagInfo->{"Table"}{"WRITE_GROUP"}
ABresult
0X0
100
111
677 0 $writeGroup = $$tagInfo{Table}{WRITE_GROUP};
678 0 $writeGroup =~ s/^MIE/$mieGroup/;
679 }
680 ▶ } elsif (not $$tagInfo{AllowGroup} or $lcWant !~ /^$$tagInfo{AllowGroup}$/i) {
Condition100%3/3
$tagInfo->{'AllowGroup'} && $lcWant =~ /^$tagInfo->{'AllowGroup'}$/i
!ll&&!rl&&r
3627386
MC/DC100%2/2
$tagInfo->{'AllowGroup'} && $lcWant =~ /^$tagInfo->{'AllowGroup'}$/i
$tagInfo->{'AllowGroup'} $lcWant =~ /^$tagInfo->{'AllowGroup'}$/i
Truth table100%3/3
A && B
A= $tagInfo->{'AllowGroup'}B= $lcWant =~ /^$tagInfo->{'AllowGroup'}$/i
ABresult
0X0
100
111
681 # allow group1 name to be specified
682 36281 ▶ next TAG unless $lcWant eq lc $grp[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $lcWant eq lc $grp[1] 35736 545 36281
683 }
684 }
685 15371 ▶ $writeGroup or $writeGroup = ($$tagInfo{WriteGroup} || $$tagInfo{Table}{WRITE_GROUP} || $grp[0]);
Branch: 1 branch
BranchTrueFalseTotal
$writeGroup or $writeGroup = $tagInfo->{"WriteGroup"} || $tagInfo->{"Table"}{"WRITE_GROUP"} || $grp[0] 497 14874 15371
Condition83%5/6
$tagInfo->{'WriteGroup'} || $tagInfo->{'Table'}{'WRITE_GROUP'} || $grp[0]
l!l&&r!l&&!r
1162137120
$tagInfo->{"WriteGroup"} or $tagInfo->{"Table"}{"WRITE_GROUP"}
l!l&&r!l&&!r
38377913712
MC/DC0%0/3
$tagInfo->{'WriteGroup'} || $tagInfo->{'Table'}{'WRITE_GROUP'} || $grp[0]
$tagInfo->{"WriteGroup"} $tagInfo->{"Table"}{"WRITE_GROUP"} $grp[0]
Truth table0%0/4
A or B || C
A= $tagInfo->{"WriteGroup"}B= $tagInfo->{"Table"}{"WRITE_GROUP"}C= $grp[0]
ABCresult
1XX1
01X1
0011
0000
686 15371 $priority = $hiPri; # highest priority since group was specified
687 }
688 36289 ++$foundMatch;
689 # must do a dummy call to the write proc to autoload write package
690 # before checking Writable flag
691 36289 my $table = $$tagInfo{Table};
692 36289 my $writeProc = $$table{WRITE_PROC};
693 # load source table if this was a user-defined table
694 36289 ▶ if ($$table{SRC_TABLE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table->{"SRC_TABLE"}) 9 36280 36289
695 9 my $src = GetTagTable($$table{SRC_TABLE});
696 9 ▶ $writeProc = $$src{WRITE_PROC} unless $writeProc;
Branch: 1 branch
BranchTrueFalseTotal
unless $writeProc 0 9 9
697 }
698 36289 ▶ if ($writeProc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeProc) 36289 0 36289
699 # make sure module is loaded if the writeProc is a string
700 36289 ▶ unless (ref $writeProc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $writeProc) 13 36276 36289
701 13 my $module = $writeProc;
702 13 ▶ $module =~ s/::\w+$// and eval "require $module";
Branch: 1 branch
BranchTrueFalseTotal
$module =~ s/::\w+$// and eval "require $module" 13 0 13
703 }
704 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
705 36289 ▶ next unless $writeProc and &$writeProc();
Branch: 1 branch
BranchTrueFalseTotal
unless $writeProc and &$writeProc() 119 36170 36289
Condition66%2/3
$writeProc and &$writeProc()
!ll&&!rl&&r
011936170
MC/DC50%1/2
$writeProc and &$writeProc()
$writeProc &$writeProc()
Truth table66%2/3
A and B
A= $writeProcB= &$writeProc()
ABresult
0X0
100
111
706 }
707 # must still check writable flags in case of UserDefined tags
708 36170 my $writable = $$tagInfo{Writable};
709 next unless $writable or ($$table{WRITABLE} and
710 36170 ▶ not defined $writable and not $$tagInfo{SubDirectory});
Branch: 1 branch
BranchTrueFalseTotal
unless $writable or $table->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"} 1 36169 36170
Condition77%7/9
$writable or $table->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}
l!l&&r!l&&!r
13221229481
$table->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
1022948
$table->{"WRITABLE"} and not defined $writable
!ll&&!rl&&r
1022948
MC/DC50%2/4
$writable or $table->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}
$writable $table->{"WRITABLE"} not defined $writable not $tagInfo->{"SubDirectory"}
Truth table60%3/5
A or B and not(C) and not(D)
A= $writableB= $table->{"WRITABLE"}C= not defined $writableD= not $tagInfo->{"SubDirectory"}
ABCDresult
1XXX1
01111
00XX0
010X0
01100
711 # set specific write group (if we didn't already)
712 36169 ▶ if (not $writeGroup or ($translateWriteGroup{$writeGroup} and
Branch: 1 branch
BranchTrueFalseTotal
if (not $writeGroup or $translateWriteGroup{$writeGroup} and !$tagInfo->{"WriteGroup"} || $tagInfo->{"WriteGroup"} ne "All") 20894 15275 36169
Condition88%8/9
not $writeGroup or $translateWriteGroup{$writeGroup} and !$tagInfo->{"WriteGroup"} || $tagInfo->{"WriteGroup"} ne "All"
l!l&&r!l&&!r
208138115275
$translateWriteGroup{$writeGroup} and !$tagInfo->{"WriteGroup"} || $tagInfo->{"WriteGroup"} ne "All"
!ll&&!rl&&r
15272381
not $tagInfo->{"WriteGroup"} or $tagInfo->{"WriteGroup"} ne "All"
l!l&&r!l&&!r
8103
MC/DC75%3/4
not $writeGroup or $translateWriteGroup{$writeGroup} and !$tagInfo->{"WriteGroup"} || $tagInfo->{"WriteGroup"} ne "All"
not $writeGroup $translateWriteGroup{$writeGroup} not $tagInfo->{"WriteGroup"} $tagInfo->{"WriteGroup"} ne "All"
Truth table80%4/5
not(A) or B and not(C) or D
A= not $writeGroupB= $translateWriteGroup{$writeGroup}C= not $tagInfo->{"WriteGroup"}D= $tagInfo->{"WriteGroup"} ne "All"
ABCDresult
1XXX1
011X1
01011
00XX0
01000
713 (not $$tagInfo{WriteGroup} or $$tagInfo{WriteGroup} ne 'All')))
714 {
715 # use default write group
716 20894 ▶ $writeGroup = $$tagInfo{WriteGroup} || $$tagInfo{Table}{WRITE_GROUP};
Condition100%3/3
$tagInfo->{'WriteGroup'} || $tagInfo->{'Table'}{'WRITE_GROUP'}
l!l&&r!l&&!r
1676229916919
MC/DC100%2/2
$tagInfo->{'WriteGroup'} || $tagInfo->{'Table'}{'WRITE_GROUP'}
$tagInfo->{'WriteGroup'} $tagInfo->{'Table'}{'WRITE_GROUP'}
Truth table100%3/3
A || B
A= $tagInfo->{'WriteGroup'}B= $tagInfo->{'Table'}{'WRITE_GROUP'}
ABresult
1X1
011
000
717 # use group 0 name if no WriteGroup specified
718 20894 my $group0 = $self->GetGroup($tagInfo, 0);
719 20894 ▶ $writeGroup or $writeGroup = $group0;
Branch: 1 branch
BranchTrueFalseTotal
$writeGroup or $writeGroup = $group0 3975 16919 20894
720 # get priority for this group
721 20894 ▶ unless ($priority) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($priority) 20813 81 20894
722 20813 ▶ if ($$tagInfo{Avoid} and $$tagInfo{WriteAlso}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'Avoid'} and $tagInfo->{'WriteAlso'}) { } 26 20787 20813
Condition100%3/3
$tagInfo->{"Avoid"} and $tagInfo->{"WriteAlso"}
!ll&&!rl&&r
1985393426
MC/DC100%2/2
$tagInfo->{"Avoid"} and $tagInfo->{"WriteAlso"}
$tagInfo->{"Avoid"} $tagInfo->{"WriteAlso"}
Truth table100%3/3
A and B
A= $tagInfo->{"Avoid"}B= $tagInfo->{"WriteAlso"}
ABresult
0X0
100
111
723 26 $priority = 0;
724 } else {
725 20787 $priority = $$self{WRITE_PRIORITY}{lc($writeGroup)};
726 20787 ▶ unless ($priority) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($priority) 3764 17023 20787
727 3764 ▶ $priority = $$self{WRITE_PRIORITY}{lc($group0)} || 0;
Condition100%2/2
$self->{'WRITE_PRIORITY'}{lc $group0} || 0
l!l
24571307
MC/DC100%1/1
$self->{'WRITE_PRIORITY'}{lc $group0} || 0
$self->{'WRITE_PRIORITY'}{lc $group0}
Truth table100%2/2
A
A= $self->{'WRITE_PRIORITY'}{lc $group0}
Aresult
11
00
728 }
729 }
730 }
731 # adjust priority based on Preferred level for this tag
732 20894 ▶ $priority += $prfTag if $prfTag;
Branch: 1 branch
BranchTrueFalseTotal
if $prfTag 1237 19657 20894
733 }
734 # don't write tag if protected
735 36169 my $prot = $$tagInfo{Protected};
736 36169 ▶ $prot = 1 if $noFlat and defined $$tagInfo{Flat};
Branch: 1 branch
BranchTrueFalseTotal
if $noFlat and defined $tagInfo->{"Flat"} 31 36138 36169
Condition100%3/3
$noFlat and defined $tagInfo->{"Flat"}
!ll&&!rl&&r
35109102931
MC/DC100%2/2
$noFlat and defined $tagInfo->{"Flat"}
$noFlat defined $tagInfo->{"Flat"}
Truth table100%3/3
A and B
A= $noFlatB= defined $tagInfo->{"Flat"}
ABresult
0X0
100
111
737 36169 ▶ if ($prot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prot) 2350 33819 36169
738 2350 $prot &= ~$protected;
739 2350 ▶ if ($prot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prot) 1217 1133 2350
740 1217 my %lkup = ( 1=>'unsafe', 2=>'protected', 3=>'unsafe and protected');
741 1217 $wasProtected = $lkup{$prot};
742 1217 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 1 1216 1217
743 1 my $wgrp1 = $self->GetWriteGroup1($tagInfo, $writeGroup);
744 1 print $out "Sorry, $wgrp1:$tag is $wasProtected for writing\n";
745 }
746 1217 next;
747 }
748 }
749 # set priority for this tag
750 34952 $tagPriority{$tagInfo} = $priority;
751 # keep track of highest priority QuickTime tag
752 $highestQT{$lcTag} = $priority if $$table{GROUPS}{0} eq 'QuickTime' and
753 34952 ▶ (not defined $highestQT{$lcTag} or $highestQT{$lcTag} < $priority);
Branch: 1 branch
BranchTrueFalseTotal
if $table->{"GROUPS"}{0} eq "QuickTime" and !defined($highestQT{$lcTag}) || $highestQT{$lcTag} < $priority 467 34485 34952
Condition100%6/6
$table->{"GROUPS"}{0} eq "QuickTime" and !defined($highestQT{$lcTag}) || $highestQT{$lcTag} < $priority
!ll&&!rl&&r
34087398467
not defined $highestQT{$lcTag} or $highestQT{$lcTag} < $priority
l!l&&r!l&&!r
363104398
MC/DC100%3/3
$table->{"GROUPS"}{0} eq "QuickTime" and !defined($highestQT{$lcTag}) || $highestQT{$lcTag} < $priority
$table->{"GROUPS"}{0} eq "QuickTime" not defined $highestQT{$lcTag} $highestQT{$lcTag} < $priority
Truth table100%4/4
A and not(B) or C
A= $table->{"GROUPS"}{0} eq "QuickTime"B= not defined $highestQT{$lcTag}C= $highestQT{$lcTag} < $priority
ABCresult
0XX0
1000
11X1
1011
754 34952 ▶ if ($priority > $highestPriority{$lcTag}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($priority > $highestPriority{$lcTag}) { } 11028 23924 34952
elsif ($priority == $highestPriority{$lcTag}) { } 14719 9205 23924
755 11028 $highestPriority{$lcTag} = $priority;
756 11028 $preferred{$lcTag} = { $tagInfo => 1 };
757 11028 ▶ $avoid{$lcTag} = $$tagInfo{Avoid} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$tagInfo->{'Avoid'} ? : 1460 9568 11028
758 } elsif ($priority == $highestPriority{$lcTag}) {
759 # create all tags with highest priority
760 14719 $preferred{$lcTag}{$tagInfo} = 1;
761 14719 ▶ ++$avoid{$lcTag} if $$tagInfo{Avoid};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"Avoid"} 347 14372 14719
762 }
763 34952 ▶ if ($$tagInfo{WriteAlso}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'WriteAlso'}) { } 115 34837 34952
764 # store WriteAlso tags separately so we can set them first
765 115 push @writeAlsoList, $tagInfo;
766 } else {
767 34837 push @tagInfoList, $tagInfo;
768 }
769 # special case to allow override of XMP WriteGroup
770 34952 ▶ if ($writeGroup eq 'XMP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeGroup eq "XMP") 5928 29024 34952
771 5928 ▶ my $wg = $$tagInfo{WriteGroup} || $$table{WRITE_GROUP};
Condition33%1/3
$tagInfo->{'WriteGroup'} || $table->{'WRITE_GROUP'}
l!l&&r!l&&!r
005928
MC/DC0%0/2
$tagInfo->{'WriteGroup'} || $table->{'WRITE_GROUP'}
$tagInfo->{'WriteGroup'} $table->{'WRITE_GROUP'}
Truth table33%1/3
A || B
A= $tagInfo->{'WriteGroup'}B= $table->{'WRITE_GROUP'}
ABresult
1X1
011
000
772 5928 ▶ $writeGroup = $wg if $wg;
Branch: 1 branch
BranchTrueFalseTotal
if $wg 0 5928 5928
773 }
774 34952 $writeGroup{$tagInfo} = $writeGroup;
775 }
776 # sort tag info list in reverse order of priority (highest number last)
777 # so we get the highest priority error message in the end
778 4312 @tagInfoList = sort { $tagPriority{$a} <=> $tagPriority{$b} } @tagInfoList;
779 # must write any tags which also write other tags first
780 4312 ▶ unshift @tagInfoList, @writeAlsoList if @writeAlsoList;
Branch: 1 branch
BranchTrueFalseTotal
if @writeAlsoList 115 4197 4312
781  
782 # check priorities for each set of tags we are writing
783 4312 my $lcTag;
784 4312 foreach $lcTag (keys %preferred) {
785 # don't create tags with priority 0 if group priorities are set
786 10194 ▶ if ($preferred{$lcTag} and $highestPriority{$lcTag} == 0 and
Branch: 1 branch
BranchTrueFalseTotal
if ($preferred{$lcTag} and $highestPriority{$lcTag} == 0 and %{$self->{"WRITE_PRIORITY"};}) 18 10176 10194
Condition66%4/6
$preferred{$lcTag} and $highestPriority{$lcTag} == 0 and %{$self->{"WRITE_PRIORITY"};}
!ll&&!rl&&r
10176018
$preferred{$lcTag} and $highestPriority{$lcTag} == 0
!ll&&!rl&&r
01017618
MC/DC33%1/3
$preferred{$lcTag} and $highestPriority{$lcTag} == 0 and %{$self->{"WRITE_PRIORITY"};}
$preferred{$lcTag} $highestPriority{$lcTag} == 0 %{$self->{"WRITE_PRIORITY"};}
Truth table50%2/4
A and B and C
A= $preferred{$lcTag}B= $highestPriority{$lcTag} == 0C= %{$self->{"WRITE_PRIORITY"};}
ABCresult
0XX0
10X0
1100
1111
787 18 %{$$self{WRITE_PRIORITY}})
788 {
789 18 delete $preferred{$lcTag}
790 }
791 # avoid creating tags with 'Avoid' flag set if there are other alternatives
792 10194 ▶ if ($avoid{$lcTag} and $preferred{$lcTag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($avoid{$lcTag} and $preferred{$lcTag}) 1541 8653 10194
Condition66%2/3
$avoid{$lcTag} and $preferred{$lcTag}
!ll&&!rl&&r
865301541
MC/DC50%1/2
$avoid{$lcTag} and $preferred{$lcTag}
$avoid{$lcTag} $preferred{$lcTag}
Truth table66%2/3
A and B
A= $avoid{$lcTag}B= $preferred{$lcTag}
ABresult
0X0
100
111
793 1541 ▶ if ($avoid{$lcTag} < scalar(keys %{$preferred{$lcTag}})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($avoid{$lcTag} < scalar keys %{$preferred{$lcTag};}) { } 1380 161 1541
elsif ($highestPriority{$lcTag} < 1000) { } 48 113 161
794 # just remove the 'Avoid' tags since there are other preferred tags
795 1380 foreach $tagInfo (@tagInfoList) {
796 5735844 ▶ next unless $lcTag eq lc $$tagInfo{Name};
Branch: 1 branch
BranchTrueFalseTotal
unless $lcTag eq lc $tagInfo->{"Name"} 5729625 6219 5735844
797 6219 ▶ delete $preferred{$lcTag}{$tagInfo} if $$tagInfo{Avoid};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"Avoid"} 1690 4529 6219
798 }
799 } elsif ($highestPriority{$lcTag} < 1000) {
800 # look for another priority tag to create instead
801 48 my $nextHighest = 0;
802 48 my @nextBestTags;
803 48 foreach $tagInfo (@tagInfoList) {
804 32548 ▶ next unless $lcTag eq lc $$tagInfo{Name};
Branch: 1 branch
BranchTrueFalseTotal
unless $lcTag eq lc $tagInfo->{"Name"} 32426 122 32548
805 122 ▶ my $priority = $tagPriority{$tagInfo} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $priority = $tagPriority{$tagInfo} or next 121 1 122
806 121 ▶ next if $priority == $highestPriority{$lcTag};
Branch: 1 branch
BranchTrueFalseTotal
if $priority == $highestPriority{$lcTag} 49 72 121
807 72 ▶ next if $priority < $nextHighest;
Branch: 1 branch
BranchTrueFalseTotal
if $priority < $nextHighest 0 72 72
808 72 my $permanent = $$tagInfo{Permanent};
809 72 ▶ $permanent = $$tagInfo{Table}{PERMANENT} unless defined $permanent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $permanent 72 0 72
810 72 ▶ next if $$tagInfo{Avoid} or $permanent;
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"Avoid"} or $permanent 5 67 72
Condition100%3/3
$tagInfo->{"Avoid"} or $permanent
l!l&&r!l&&!r
4167
MC/DC100%2/2
$tagInfo->{"Avoid"} or $permanent
$tagInfo->{"Avoid"} $permanent
Truth table100%3/3
A or B
A= $tagInfo->{"Avoid"}B= $permanent
ABresult
1X1
011
000
811 67 ▶ next if $writeGroup{$tagInfo} eq 'MakerNotes';
Branch: 1 branch
BranchTrueFalseTotal
if $writeGroup{$tagInfo} eq "MakerNotes" 44 23 67
812 23 ▶ if ($nextHighest < $priority) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nextHighest < $priority) 18 5 23
813 18 $nextHighest = $priority;
814 18 undef @nextBestTags;
815 }
816 23 push @nextBestTags, $tagInfo;
817 }
818 48 ▶ if (@nextBestTags) {
Branch: 1 branch
BranchTrueFalseTotal
if (@nextBestTags) 13 35 48
819 # change our preferred tags to the next best tags
820 13 delete $preferred{$lcTag};
821 13 foreach $tagInfo (@nextBestTags) {
822 14 $preferred{$lcTag}{$tagInfo} = 1;
823 }
824 }
825 }
826 }
827 }
828 #
829 # generate new value hash for each tag
830 #
831 4312 my ($prioritySet, $createGroups, %alsoWrote);
832  
833 4312 delete $$self{CHECK_WARN}; # reset CHECK_PROC warnings
834  
835 # loop through all valid tags to find the one(s) to write
836 4312 foreach $tagInfo (@tagInfoList) {
837 34936 ▶ next if $alsoWrote{$tagInfo}; # don't rewrite tags we already wrote
Branch: 1 branch
BranchTrueFalseTotal
if $alsoWrote{$tagInfo} 9 34927 34936
838 # only process List or non-List tags if specified
839 34927 ▶ next if defined $listOnly and ($listOnly xor $$tagInfo{List});
Branch: 1 branch
BranchTrueFalseTotal
if defined $listOnly and $listOnly ^^ $tagInfo->{"List"} 221 34706 34927
Condition100%7/7
defined $listOnly and $listOnly ^^ $tagInfo->{"List"}
!ll&&!rl&&r
34435271221
$listOnly xor $tagInfo->{"List"}
l&&rl&&!r!l&&r!l&&!r
2171457654
MC/DC100%3/3
defined $listOnly and $listOnly ^^ $tagInfo->{"List"}
defined $listOnly $listOnly $tagInfo->{"List"}
Truth table100%5/5
A and B xor C
A= defined $listOnlyB= $listOnlyC= $tagInfo->{"List"}
ABCresult
0XX0
1110
1000
1101
1011
840 34706 my $noConv;
841 34706 my $writeGroup = $writeGroup{$tagInfo};
842 34706 my $permanent = $$tagInfo{Permanent};
843 34706 ▶ $permanent = $$tagInfo{Table}{PERMANENT} unless defined $permanent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $permanent 34100 606 34706
844 34706 ▶ $writeGroup eq 'MakerNotes' and $permanent = 1 unless defined $permanent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $permanent 33699 1007 34706
Condition66%4/6
defined $permanent || $writeGroup eq 'MakerNotes' && ($permanent = 1)
l!l
1007336990
$writeGroup eq "MakerNotes" and $permanent = 1
!ll
10838228610
MC/DC0%0/3
defined $permanent || $writeGroup eq 'MakerNotes' && ($permanent = 1)
defined $permanent $writeGroup eq "MakerNotes" $permanent = 1
Truth table0%0/4
A || B and C
A= defined $permanentB= $writeGroup eq "MakerNotes"C= $permanent = 1
ABCresult
1XX1
0111
00X0
0100
845 34706 my $wgrp1 = $self->GetWriteGroup1($tagInfo, $writeGroup);
846 34706 $tag = $$tagInfo{Name}; # get tag name for warnings
847 34706 my $lcTag = lc $tag;
848 34706 ▶ my $pref = $preferred{$lcTag} || { };
Condition100%2/2
$preferred{$lcTag} || {}
l!l
3468818
MC/DC100%1/1
$preferred{$lcTag} || {}
$preferred{$lcTag}
Truth table100%2/2
A
A= $preferred{$lcTag}
Aresult
11
00
849 # don't write Avoid-ed tags with side effect unless preferred
850 34706 ▶ next if not $$pref{$tagInfo} and $$tagInfo{Avoid} and $$tagInfo{WriteAlso};
Branch: 1 branch
BranchTrueFalseTotal
if not $pref->{$tagInfo} and $tagInfo->{"Avoid"} and $tagInfo->{"WriteAlso"} 26 34680 34706
Condition100%6/6
not $pref->{$tagInfo} and $tagInfo->{"Avoid"} and $tagInfo->{"WriteAlso"}
!ll&&!rl&&r
32541213926
not $pref->{$tagInfo} and $tagInfo->{"Avoid"}
!ll&&!rl&&r
20143123982165
MC/DC100%3/3
not $pref->{$tagInfo} and $tagInfo->{"Avoid"} and $tagInfo->{"WriteAlso"}
not $pref->{$tagInfo} $tagInfo->{"Avoid"} $tagInfo->{"WriteAlso"}
Truth table100%4/4
not(A) and B and C
A= not $pref->{$tagInfo}B= $tagInfo->{"Avoid"}C= $tagInfo->{"WriteAlso"}
ABCresult
0XX0
10X0
1100
1111
851 34680 my $shift = $options{Shift};
852 34680 my $addValue = $options{AddValue};
853 34680 ▶ if (defined $shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $shift) 169 34511 34680
854 # (can't currently shift list-type tags)
855 169 my $shiftable;
856 169 ▶ if ($$tagInfo{List}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'List'}) { } 0 169 169
857 0 $shiftable = ''; # can add/delete but not shift
858 } else {
859 169 $shiftable = $$tagInfo{Shift};
860 169 ▶ unless ($shift) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($shift) 24 145 169
861 # set shift according to AddValue/DelValue
862 24 ▶ $shift = 1 if $addValue;
Branch: 1 branch
BranchTrueFalseTotal
if $addValue 24 0 24
863 # can shift a date/time with -=, but this is
864 # a conditional delete operation for other tags
865 24 ▶ $shift = -1 if $options{DelValue} and defined $shiftable and $shiftable eq 'Time';
Branch: 1 branch
BranchTrueFalseTotal
if $options{"DelValue"} and defined $shiftable and $shiftable eq "Time" 0 24 24
Condition33%2/6
$options{"DelValue"} and defined $shiftable and $shiftable eq "Time"
!ll&&!rl&&r
2400
$options{"DelValue"} and defined $shiftable
!ll&&!rl&&r
2400
MC/DC0%0/3
$options{"DelValue"} and defined $shiftable and $shiftable eq "Time"
$options{"DelValue"} defined $shiftable $shiftable eq "Time"
Truth table25%1/4
A and B and C
A= $options{"DelValue"}B= defined $shiftableC= $shiftable eq "Time"
ABCresult
0XX0
10X0
1100
1111
866 }
867 169 ▶ if ($shift and (not defined $value or not length $value)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shift and not defined $value && length $value) 0 169 169
Condition33%2/6
$shift and not defined $value && length $value
!ll&&!rl&&r
01690
defined $value && length $value
!ll&&!rl&&r
00169
MC/DC0%0/3
$shift and not defined $value && length $value
$shift defined $value length $value
Truth table25%1/4
A and not(B && C)
A= $shiftB= defined $valueC= length $value
ABCresult
0XX0
1110
10X1
1101
868 # (now allow -= to be used for shiftable tag - v8.05)
869 #$err = "No value for time shift of $wgrp1:$tag";
870 #$verbose > 2 and print $out "$err\n";
871 #next;
872 0 undef $shift;
873 }
874 }
875 # can't shift List-type tag
876 169 ▶ if ((defined $shiftable and not $shiftable) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $shiftable and not $shiftable and $shift || $shiftable eq 0 && $options{"DelValue"}) 0 169 169
Condition25%3/12
defined $shiftable and not $shiftable and $shift || $shiftable eq 0 && $options{"DelValue"}
!ll&&!rl&&r
16900
defined $shiftable and not $shiftable
!ll&&!rl&&r
118510
$shift or $shiftable eq 0 and $options{"DelValue"}
l!l&&r!l&&!r
000
$shiftable eq 0 and $options{"DelValue"}
!ll&&!rl&&r
000
MC/DC0%0/5
defined $shiftable and not $shiftable and $shift || $shiftable eq 0 && $options{"DelValue"}
defined $shiftable not $shiftable $shift $shiftable eq 0 $options{"DelValue"}
Truth table33%2/6
A and not(B) and C or D and E
A= defined $shiftableB= not $shiftableC= $shiftD= $shiftable eq 0E= $options{"DelValue"}
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
877 # and don't try to conditionally delete if Shift is "0"
878 ($shift or ($shiftable eq '0' and $options{DelValue})))
879 {
880 0 $err = "$wgrp1:$tag is not shiftable";
881 0 ▶ $verbose and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "$err\n" 0 0 0
882 0 next;
883 }
884 }
885 34680 my $val = $value;
886 34680 ▶ if (defined $val) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $val) { } 22333 12347 34680
elsif ($permanent) { } 8138 4209 12347
elsif ($addValue or $options{'DelValue'}) { } 0 4209 4209
887 # check to make sure this is a List or Shift tag if adding
888 22333 ▶ if ($addValue and not ($shift or $$tagInfo{List})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($addValue and not $shift || $tagInfo->{"List"}) 9 22324 22333
Condition100%6/6
$addValue and not $shift || $tagInfo->{"List"}
!ll&&!rl&&r
22285399
$shift || $tagInfo->{'List'}
l!l&&r!l&&!r
24159
MC/DC100%3/3
$addValue and not $shift || $tagInfo->{"List"}
$addValue $shift $tagInfo->{'List'}
Truth table100%4/4
A and not(B || C)
A= $addValueB= $shiftC= $tagInfo->{'List'}
ABCresult
0XX0
11X0
1010
1001
889 9 ▶ if ($addValue eq '2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($addValue eq '2') { } 0 9 9
890 0 undef $addValue; # quietly reset this option
891 } else {
892 9 $err = "Can't add $wgrp1:$tag (not a List type)";
893 9 ▶ $verbose > 2 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "$err\n" 0 9 9
894 9 next;
895 }
896 }
897 22324 ▶ if ($shift) {
Branch: 3 branches
BranchTrueFalseTotal
if ($shift) { } 169 22155 22324
elsif (not length $val and $options{'DelValue'}) { } 39 22116 22155
elsif (ref $val eq 'HASH' and not $tagInfo->{'Struct'}) { } 2 44206 44208
898 169 ▶ if ($$tagInfo{Shift} and $$tagInfo{Shift} eq 'Time') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagInfo->{'Shift'} and $tagInfo->{'Shift'} eq 'Time') { } 51 118 169
elsif (&IsFloat($val)) { } 114 4 118
Condition66%2/3
$tagInfo->{"Shift"} and $tagInfo->{"Shift"} eq "Time"
!ll&&!rl&&r
118051
MC/DC50%1/2
$tagInfo->{"Shift"} and $tagInfo->{"Shift"} eq "Time"
$tagInfo->{"Shift"} $tagInfo->{"Shift"} eq "Time"
Truth table66%2/3
A and B
A= $tagInfo->{"Shift"}B= $tagInfo->{"Shift"} eq "Time"
ABresult
0X0
100
111
899 # add '+' or '-' prefix to indicate shift direction
900 51 ▶ $val = ($shift > 0 ? '+' : '-') . $val;
Branch: 1 branch
BranchTrueFalseTotal
$shift > 0 ? : 19 32 51
901 # check the shift for validity
902 51 require 'Image/ExifTool/Shift.pl';
903 51 my $err2 = CheckShift($$tagInfo{Shift}, $val);
904 51 ▶ if ($err2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err2) 0 51 51
905 0 $err = "$err2 for $wgrp1:$tag";
906 0 ▶ $verbose > 2 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "$err\n" 0 0 0
907 0 next;
908 }
909 } elsif (IsFloat($val)) {
910 114 $val *= $shift;
911 } else {
912 4 $err = "Shift value for $wgrp1:$tag is not a number";
913 4 ▶ $verbose > 2 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "$err\n" 0 4 4
914 4 next;
915 }
916 165 $noConv = 1; # no conversions if shifting tag
917 ▶ } elsif (not length $val and $options{DelValue}) {
Condition100%3/3
not length $val and $options{"DelValue"}
!ll&&!rl&&r
2178433239
MC/DC100%2/2
not length $val and $options{"DelValue"}
not length $val $options{"DelValue"}
Truth table100%3/3
not(A) and B
A= not length $valB= $options{"DelValue"}
ABresult
0X0
100
111
918 39 $noConv = 1; # no conversions for deleting empty value
919 ▶ } elsif (ref $val eq 'HASH' and not $$tagInfo{Struct}) {
Condition100%3/3
ref $val eq "HASH" and not $tagInfo->{"Struct"}
!ll&&!rl&&r
22092222
MC/DC100%2/2
ref $val eq "HASH" and not $tagInfo->{"Struct"}
ref $val eq "HASH" not $tagInfo->{"Struct"}
Truth table100%3/3
A and not(B)
A= ref $val eq "HASH"B= not $tagInfo->{"Struct"}
ABresult
0X0
100
111
920 2 $err = "Can't write a structure to $wgrp1:$tag";
921 2 ▶ $verbose > 2 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "$err\n" 0 2 2
922 2 next;
923 }
924 } elsif ($permanent) {
925 8138 ▶ return 0 if $options{IgnorePermanent};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"IgnorePermanent"} 4 8134 8138
926 # can't delete permanent tags, so set them to DelValue or empty string instead
927 8134 ▶ if (defined $$tagInfo{DelValue}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tagInfo->{'DelValue'}) { } 33 8101 8134
928 33 $val = $$tagInfo{DelValue};
929 33 $noConv = 1; # DelValue is the raw value, so no conversion necessary
930 } else {
931 8101 $val = '';
932 }
933 ▶ } elsif ($addValue or $options{DelValue}) {
Condition33%1/3
$addValue or $options{"DelValue"}
l!l&&r!l&&!r
004209
MC/DC0%0/2
$addValue or $options{"DelValue"}
$addValue $options{"DelValue"}
Truth table33%1/3
A or B
A= $addValueB= $options{"DelValue"}
ABresult
1X1
011
000
934 0 $err = "No value to add or delete in $wgrp1:$tag";
935 0 ▶ $verbose > 2 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "$err\n" 0 0 0
936 0 next;
937 } else {
938 4209 ▶ if ($$tagInfo{DelCheck}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"DelCheck"}) 7 4202 4209
939 #### eval DelCheck ($self, $tagInfo, $wantGroup)
940 7 my $err2 = eval $$tagInfo{DelCheck};
941 7 ▶ $@ and warn($@), $err2 = 'Error evaluating DelCheck';
Branch: 1 branch
BranchTrueFalseTotal
$@ and warn($@), $err2 = "Error evaluating DelCheck" 0 7 7
942 7 ▶ if (defined $err2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err2) 7 0 7
943 # (allow other tags to be set using DelCheck as a hook)
944 7 ▶ $err2 or goto WriteAlso; # GOTO!
Branch: 1 branch
BranchTrueFalseTotal
$err2 or goto WriteAlso 3 4 7
945 3 ▶ $err2 .= ' for' unless $err2 =~ /delete$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $err2 =~ /delete$/ 0 3 3
946 3 $err = "$err2 $wgrp1:$tag";
947 3 ▶ $verbose > 2 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "$err\n" 0 3 3
948 3 next;
949 }
950 }
951 # set group delete flag if this tag represents an entire group
952 4202 ▶ if ($$tagInfo{DelGroup} and not $options{DelValue}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"DelGroup"} and not $options{"DelValue"}) 3 4199 4202
Condition66%2/3
$tagInfo->{"DelGroup"} and not $options{"DelValue"}
!ll&&!rl&&r
419903
MC/DC50%1/2
$tagInfo->{"DelGroup"} and not $options{"DelValue"}
$tagInfo->{"DelGroup"} not $options{"DelValue"}
Truth table66%2/3
A and not(B)
A= $tagInfo->{"DelGroup"}B= not $options{"DelValue"}
ABresult
0X0
100
111
953 3 my @del = ( $tag );
954 3 $$self{DEL_GROUP}{$tag} = 1;
955 # delete extra groups if necessary
956 3 ▶ if ($delMore{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delMore{$tag}) 0 3 3
957 0 $$self{DEL_GROUP}{$_} = 1, push(@del,$_) foreach @{$delMore{$tag}};
958 }
959 # remove all of this group from previous new values
960 3 $self->RemoveNewValuesForGroup($tag);
961 3 ▶ $verbose and print $out " Deleting tags in: @del\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting tags in: @del\n" 0 3 3
962 3 ++$numSet;
963 3 next;
964 }
965 4199 $noConv = 1; # value is not defined, so don't do conversion
966 }
967 # apply inverse PrintConv and ValueConv conversions
968 # save ValueConv setting for use in ConvInv()
969 34651 ▶ unless ($noConv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($noConv) 30215 4436 34651
970 # set default conversion type used by ConvInv() and CHECK_PROC routines
971 30215 $$self{ConvType} = $convType;
972 30215 my $e;
973 30215 ($val,$e) = $self->ConvInv($val,$tagInfo,$tag,$wgrp1,$$self{ConvType},$wantGroup);
974 30215 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 9927 20288 30215
975 # empty error string causes error to be ignored without setting the value
976 9927 ▶ $e or goto WriteAlso; # GOTO!
Branch: 1 branch
BranchTrueFalseTotal
$e or goto WriteAlso 9909 18 9927
977 9909 $err = $e;
978 }
979 }
980 34633 ▶ if (not defined $val and defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val and defined $value) 3052 31581 34633
Condition100%3/3
not defined $val and defined $value
!ll&&!rl&&r
20525110563052
MC/DC100%2/2
not defined $val and defined $value
not defined $val defined $value
Truth table100%3/3
not(A) and B
A= not defined $valB= defined $value
ABresult
0X0
100
111
981 # if value conversion failed, we must still add a NEW_VALUE
982 # entry for this tag it it was a DelValue
983 3052 ▶ next unless $options{DelValue};
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"DelValue"} 3052 0 3052
984 0 $val = 'xxx never delete xxx';
985 }
986 31581 ▶ $$self{NEW_VALUE} or $$self{NEW_VALUE} = { };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"NEW_VALUE"} or $self->{"NEW_VALUE"} = {} 31358 223 31581
987 31581 ▶ if ($options{Replace}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"Replace"}) 14399 17182 31581
988 # delete the previous new value
989 14399 $self->GetNewValueHash($tagInfo, $writeGroup, 'delete', $options{ProtectSaved});
990 # also delete related tag previous new values
991 14399 ▶ if ($$tagInfo{WriteAlso}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"WriteAlso"}) 25 14374 14399
992 25 $$self{INDENT2} = '+';
993 25 my ($wgrp, $wtag);
994 25 ▶ if ($$tagInfo{WriteGroup} and $$tagInfo{WriteGroup} eq 'All' and $writeGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'WriteGroup'} and $tagInfo->{'WriteGroup'} eq 'All' and $writeGroup) { } 6 19 25
Condition66%4/6
$tagInfo->{"WriteGroup"} and $tagInfo->{"WriteGroup"} eq "All" and $writeGroup
!ll&&!rl&&r
1906
$tagInfo->{"WriteGroup"} and $tagInfo->{"WriteGroup"} eq "All"
!ll&&!rl&&r
1906
MC/DC33%1/3
$tagInfo->{"WriteGroup"} and $tagInfo->{"WriteGroup"} eq "All" and $writeGroup
$tagInfo->{"WriteGroup"} $tagInfo->{"WriteGroup"} eq "All" $writeGroup
Truth table50%2/4
A and B and C
A= $tagInfo->{"WriteGroup"}B= $tagInfo->{"WriteGroup"} eq "All"C= $writeGroup
ABCresult
0XX0
10X0
1100
1111
995 6 $wgrp = $writeGroup . ':';
996 } else {
997 19 $wgrp = '';
998 }
999 25 foreach $wtag (sort keys %{$$tagInfo{WriteAlso}}) {
1000 91 my ($n,$e) = $self->SetNewValue($wgrp . $wtag, undef, Replace=>2);
1001 91 $numSet += $n;
1002 }
1003 25 $$self{INDENT2} = '';
1004 }
1005 14399 ▶ $options{Replace} == 2 and ++$numSet, next;
Branch: 1 branch
BranchTrueFalseTotal
$options{"Replace"} == 2 and ++$numSet, next 293 14106 14399
1006 }
1007  
1008 31288 ▶ if (defined $val) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $val) { } 20455 10833 31288
elsif ($permanent) { } 6751 4082 10833
elsif ($addValue or $options{'DelValue'}) { } 0 4082 4082
1009 # we are editing this tag, so create a NEW_VALUE hash entry
1010 my $nvHash = $self->GetNewValueHash($tagInfo, $writeGroup, 'create',
1011 20455 ▶ $options{ProtectSaved}, ($options{DelValue} and not $shift));
Condition66%2/3
$options{'DelValue'} && !$shift
!ll&&!rl&&r
20397058
MC/DC50%1/2
$options{'DelValue'} && !$shift
$options{'DelValue'} !$shift
Truth table66%2/3
A && not(B)
A= $options{'DelValue'}B= !$shift
ABresult
0X0
100
111
1012 # ignore new values protected with ProtectSaved
1013 20455 ▶ $nvHash or ++$numSet, next; # (increment $numSet to avoid warning)
Branch: 1 branch
BranchTrueFalseTotal
$nvHash or ++$numSet, next 20455 0 20455
1014 20455 ▶ $$nvHash{NoReplace} = 1 if $$tagInfo{List} and not $options{Replace};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"List"} and not $options{"Replace"} 325 20130 20455
Condition100%3/3
$tagInfo->{"List"} and not $options{"Replace"}
!ll&&!rl&&r
19912218325
MC/DC100%2/2
$tagInfo->{"List"} and not $options{"Replace"}
$tagInfo->{"List"} not $options{"Replace"}
Truth table100%3/3
A and not(B)
A= $tagInfo->{"List"}B= not $options{"Replace"}
ABresult
0X0
100
111
1015 20455 $$nvHash{WantGroup} = $wantGroup;
1016 20455 ▶ $$nvHash{EditOnly} = 1 if $editOnly;
Branch: 1 branch
BranchTrueFalseTotal
if $editOnly 65 20390 20455
1017 # save maker note fixup information if writing maker notes
1018 20455 ▶ $$nvHash{MAKER_NOTE_FIXUP} = $options{Fixup} if $$tagInfo{MakerNotes};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"MakerNotes"} 27 20428 20455
1019 20455 ▶ if ($createOnly) { # create only (never edit)
Branch: 2 branches
BranchTrueFalseTotal
if ($createOnly) { } 49 20406 20455
elsif ($options{'DelValue'} or $addValue or $shift) { } 236 20170 20406
1020 # empty item in DelValue list to never edit existing value
1021 49 $$nvHash{DelValue} = [ '' ];
1022 49 $$nvHash{CreateOnly} = 1;
1023 ▶ } elsif ($options{DelValue} or $addValue or $shift) {
Condition100%6/6
$options{"DelValue"} or $addValue or $shift
l!l&&r!l&&!r
9514120170
$options{"DelValue"} or $addValue
l!l&&r!l&&!r
583720311
MC/DC100%3/3
$options{"DelValue"} or $addValue or $shift
$options{"DelValue"} $addValue $shift
Truth table100%4/4
A or B or C
A= $options{"DelValue"}B= $addValueC= $shift
ABCresult
1XX1
01X1
0011
0000
1024 # flag any AddValue or DelValue by creating the DelValue list
1025 236 ▶ $$nvHash{DelValue} or $$nvHash{DelValue} = [ ];
Branch: 1 branch
BranchTrueFalseTotal
$nvHash->{"DelValue"} or $nvHash->{"DelValue"} = [] 2 234 236
1026 236 ▶ if ($shift) {
Branch: 2 branches
BranchTrueFalseTotal
if ($shift) { } 165 71 236
elsif ($options{'DelValue'}) { } 58 13 71
1027 # add shift value to list
1028 165 $$nvHash{Shift} = $val;
1029 } elsif ($options{DelValue}) {
1030 # don't create if we are replacing a specific value
1031 58 ▶ $$nvHash{IsCreating} = 0 unless $val eq '' or $$tagInfo{List};
Branch: 1 branch
BranchTrueFalseTotal
unless $val eq "" or $tagInfo->{"List"} 8 50 58
Condition100%3/3
$val eq "" or $tagInfo->{"List"}
l!l&&r!l&&!r
39118
MC/DC100%2/2
$val eq "" or $tagInfo->{"List"}
$val eq "" $tagInfo->{"List"}
Truth table100%3/3
A or B
A= $val eq ""B= $tagInfo->{"List"}
ABresult
1X1
011
000
1032 # add delete value to list
1033 58 ▶ push @{$$nvHash{DelValue}}, ref $val eq 'ARRAY' ? @$val : $val;
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 2 56 58
1034 58 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 58 58
1035 0 ▶ my $verb = $permanent ? 'Replacing' : 'Deleting';
Branch: 1 branch
BranchTrueFalseTotal
$permanent ? : 0 0 0
1036 0 ▶ my $fromList = $$tagInfo{List} ? ' from list' : '';
Branch: 1 branch
BranchTrueFalseTotal
$tagInfo->{'List'} ? : 0 0 0
1037 0 ▶ my @vals = (ref $val eq 'ARRAY' ? @$val : $val);
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 0 0 0
1038 0 foreach (@vals) {
1039 0 ▶ if (ref $_ eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "HASH") 0 0 0
1040 0 require 'Image/ExifTool/XMPStruct.pl';
1041 0 $_ = Image::ExifTool::XMP::SerializeStruct($self, $_);
1042 }
1043 0 print $out "$$self{INDENT2}$verb $wgrp1:$tag$fromList if value is '${_}'\n";
1044 }
1045 }
1046 }
1047 }
1048 # set priority flag to add only the high priority info
1049 # (will only create the priority tag if it doesn't exist,
1050 # others get changed only if they already exist)
1051 20455 ▶ my $prf = defined $$tagInfo{Preferred} ? $$tagInfo{Preferred} : $$tagInfo{Table}{PREFERRED};
Branch: 1 branch
BranchTrueFalseTotal
defined $tagInfo->{'Preferred'} ? : 253 20202 20455
1052 # hack to prefer only a single tag in the QuickTime group
1053 20455 ▶ if ($$tagInfo{Table}{GROUPS}{0} eq 'QuickTime') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"Table"}{"GROUPS"}{0} eq "QuickTime") 793 19662 20455
1054 793 ▶ $prf = 0 if $tagPriority{$tagInfo} < $highestQT{$lcTag};
Branch: 1 branch
BranchTrueFalseTotal
if $tagPriority{$tagInfo} < $highestQT{$lcTag} 472 321 793
1055 }
1056 20455 ▶ if ($$pref{$tagInfo} or $prf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pref->{$tagInfo} or $prf) 9601 10854 20455
Condition100%3/3
$pref->{$tagInfo} or $prf
l!l&&r!l&&!r
873486710854
MC/DC100%2/2
$pref->{$tagInfo} or $prf
$pref->{$tagInfo} $prf
Truth table100%3/3
A or B
A= $pref->{$tagInfo}B= $prf
ABresult
1X1
011
000
1057 9601 ▶ if ($permanent or $shift) {
Branch: 2 branches
BranchTrueFalseTotal
if ($permanent or $shift) { } 5796 3805 9601
elsif ($tagInfo->{'List'} and not $options{'DelValue'} or not $nvHash->{'DelValue'} && @{$nvHash->{'DelValue'};} or grep /^$/, @{$$nvHash{'DelValue'};}) { } 3791 14 3805
Condition100%3/3
$permanent or $shift
l!l&&r!l&&!r
5769273805
MC/DC100%2/2
$permanent or $shift
$permanent $shift
Truth table100%3/3
A or B
A= $permanentB= $shift
ABresult
1X1
011
000
1058 # don't create permanent or Shift-ed tag but define IsCreating
1059 # so we know that it is the preferred tag
1060 5796 $$nvHash{IsCreating} = 0;
1061 ▶ } elsif (($$tagInfo{List} and not $options{DelValue}) or
Condition91%11/12
$tagInfo->{"List"} and not $options{"DelValue"} or not $nvHash->{"DelValue"} && @{$nvHash->{"DelValue"};} or grep /^$/, @{$$nvHash{"DelValue"};}
l!l&&r!l&&!r
37474414
$tagInfo->{"List"} and not $options{"DelValue"} or not $nvHash->{"DelValue"} && @{$nvHash->{"DelValue"};}
l!l&&r!l&&!r
378336958
$tagInfo->{"List"} and not $options{"DelValue"}
!ll&&!rl&&r
34198378
$nvHash->{'DelValue'} && @{$nvHash->{'DelValue'};}
!ll&&!rl&&r
3369058
MC/DC80%4/5
$tagInfo->{"List"} and not $options{"DelValue"} or not $nvHash->{"DelValue"} && @{$nvHash->{"DelValue"};} or grep /^$/, @{$$nvHash{"DelValue"};}
$tagInfo->{"List"} not $options{"DelValue"} $nvHash->{'DelValue'} @{$nvHash->{'DelValue'};} grep /^$/, @{$$nvHash{"DelValue"};}
Truth table55%5/9
A and not(B) or not(C && D) or E
A= $tagInfo->{"List"}B= not $options{"DelValue"}C= $nvHash->{'DelValue'}D= @{$nvHash->{'DelValue'};}E= grep /^$/, @{$$nvHash{"DelValue"};}
ABCDEresult
11XXX1
0X0XX1
0X10X1
100XX1
1010X1
0X1111
101111
0X1100
101100
1062 58 not ($$nvHash{DelValue} and @{$$nvHash{DelValue}}) or
1063 # also create tag if any DelValue value is empty ('')
1064 58 grep(/^$/,@{$$nvHash{DelValue}}))
1065 {
1066 3791 ▶ $$nvHash{IsCreating} = $editOnly ? 0 : ($editGroup ? 2 : 1);
Branch: 2 branches
BranchTrueFalseTotal
$editOnly ? : 14 3777 3791
$editGroup ? : 19 3758 3777
1067 # add to hash of groups where this tag is being created
1068 3791 ▶ $createGroups or $createGroups = $options{CreateGroups} || { };
Branch: 1 branch
BranchTrueFalseTotal
$createGroups or $createGroups = $options{"CreateGroups"} || {} 1314 2477 3791
Condition100%2/2
$options{'CreateGroups'} || {}
l!l
772400
MC/DC100%1/1
$options{'CreateGroups'} || {}
$options{'CreateGroups'}
Truth table100%2/2
A
A= $options{'CreateGroups'}
Aresult
11
00
1069 3791 $$createGroups{$self->GetGroup($tagInfo, 0)} = 1;
1070 3791 $$nvHash{CreateGroups} = $createGroups;
1071 }
1072 }
1073 20455 ▶ if ($$nvHash{IsCreating}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nvHash->{'IsCreating'}) { } 3780 16675 20455
elsif ($createOnly) { } 22 16653 16675
1074 3780 ▶ if (%{$$self{DEL_GROUP}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$self->{"DEL_GROUP"};}) 177 3603 3780
1075 177 my ($grp, @grps);
1076 177 foreach $grp (keys %{$$self{DEL_GROUP}}) {
1077 11060 ▶ next if $$self{DEL_GROUP}{$grp} == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEL_GROUP"}{$grp} == 2 10651 409 11060
1078 # set flag indicating tags were written after this group was deleted
1079 409 $$self{DEL_GROUP}{$grp} = 2;
1080 409 push @grps, $grp;
1081 }
1082 177 ▶ if ($verbose > 1 and @grps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1 and @grps) 1 176 177
Condition66%2/3
$verbose > 1 and @grps
!ll&&!rl&&r
17601
MC/DC50%1/2
$verbose > 1 and @grps
$verbose > 1 @grps
Truth table66%2/3
A and B
A= $verbose > 1B= @grps
ABresult
0X0
100
111
1083 1 @grps = sort @grps;
1084 1 print $out " Writing new tags after deleting groups: @grps\n";
1085 }
1086 }
1087 } elsif ($createOnly) {
1088 22 ▶ $noCreate = $permanent ? 'permanent' : ($$tagInfo{Avoid} ? 'avoided' : '');
Branch: 2 branches
BranchTrueFalseTotal
$permanent ? : 8 14 22
$tagInfo->{'Avoid'} ? : 9 5 14
1089 22 ▶ $noCreate or $noCreate = $shift ? 'shifting' : 'not preferred';
Branch: 2 branches
BranchTrueFalseTotal
$noCreate or $noCreate = $shift ? "shifting" : "not preferred" 17 5 22
$shift ? : 0 5 5
1090 22 ▶ $verbose > 2 and print $out "Not creating $wgrp1:$tag ($noCreate)\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "Not creating ${wgrp1}:$tag ($noCreate)\n" 0 22 22
1091 22 next; # nothing to do (not creating and not editing)
1092 }
1093 20433 ▶ if ($shift or not $options{DelValue}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shift or not $options{"DelValue"}) 20375 58 20433
Condition100%3/3
$shift or not $options{"DelValue"}
l!l&&r!l&&!r
1652021058
MC/DC100%2/2
$shift or not $options{"DelValue"}
$shift not $options{"DelValue"}
Truth table100%3/3
A or not(B)
A= $shiftB= not $options{"DelValue"}
ABresult
1X1
011
000
1094 20375 ▶ $$nvHash{Value} or $$nvHash{Value} = [ ];
Branch: 1 branch
BranchTrueFalseTotal
$nvHash->{"Value"} or $nvHash->{"Value"} = [] 553 19822 20375
1095 20375 ▶ if (not $$tagInfo{List}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $tagInfo->{'List'}) { } 19846 529 20375
elsif (defined $nvHash->{'AddBefore'} and @{$nvHash->{'Value'};} >= $nvHash->{'AddBefore'}) { } 0 529 529
1096 # not a List tag -- overwrite existing value
1097 19846 $$nvHash{Value}[0] = $val;
1098 0 ▶ } elsif (defined $$nvHash{AddBefore} and @{$$nvHash{Value}} >= $$nvHash{AddBefore}) {
Condition33%1/3
defined $nvHash->{"AddBefore"} and @{$nvHash->{"Value"};} >= $nvHash->{"AddBefore"}
!ll&&!rl&&r
52900
MC/DC0%0/2
defined $nvHash->{"AddBefore"} and @{$nvHash->{"Value"};} >= $nvHash->{"AddBefore"}
defined $nvHash->{"AddBefore"} @{$nvHash->{"Value"};} >= $nvHash->{"AddBefore"}
Truth table33%1/3
A and B
A= defined $nvHash->{"AddBefore"}B= @{$nvHash->{"Value"};} >= $nvHash->{"AddBefore"}
ABresult
0X0
100
111
1099 # values from a later argument have been added (ie. Replace=0)
1100 # to this list, so the new values should come before these
1101 0 ▶ splice @{$$nvHash{Value}}, -$$nvHash{AddBefore}, 0, ref $val eq 'ARRAY' ? @$val : $val;
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 0 0 0
1102 } else {
1103 # add at end of existing list
1104 529 ▶ push @{$$nvHash{Value}}, ref $val eq 'ARRAY' ? @$val : $val;
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 45 484 529
1105 }
1106 20375 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 26 20349 20375
1107 26 my $ifExists;
1108 26 ▶ if ($$tagInfo{IsComposite}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'IsComposite'}) { } 0 26 26
1109 # (composite tags don't technically exist in the file)
1110 0 ▶ if ($$tagInfo{WriteAlso}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'WriteAlso'}) { } 0 0 0
1111 0 $ifExists = ' (+' . join(',+',sort keys %{$$tagInfo{WriteAlso}}) . '):';
1112 } else {
1113 0 $ifExists = '';
1114 }
1115 } else {
1116 $ifExists = $$nvHash{IsCreating} ? ( $createOnly ?
1117 ($$nvHash{IsCreating} == 2 ?
1118 " if $writeGroup exists and tag doesn't" :
1119 " if tag doesn't exist") :
1120 ($$nvHash{IsCreating} == 2 ? " if $writeGroup exists" : '')) :
1121 0 ▶ (($$nvHash{DelValue} and @{$$nvHash{DelValue}}) ?
Branch: 5 branches
BranchTrueFalseTotal
$nvHash->{'IsCreating'} ? : 16 10 26
$createOnly ? : 0 16 16
$nvHash->{'IsCreating'} == 2 ? : 0 0 0
$nvHash->{'IsCreating'} == 2 ? : 0 16 16
$nvHash->{'DelValue'} && @{$nvHash->{'DelValue'};} ? : 0 10 10
Condition33%1/3
$nvHash->{"DelValue"} and @{$nvHash->{"DelValue"};}
!ll&&!rl&&r
1000
MC/DC0%0/2
$nvHash->{"DelValue"} and @{$nvHash->{"DelValue"};}
$nvHash->{"DelValue"} @{$nvHash->{"DelValue"};}
Truth table33%1/3
A and B
A= $nvHash->{"DelValue"}B= @{$nvHash->{"DelValue"};}
ABresult
0X0
100
111
1122 ' if tag was deleted' : ' if tag exists');
1123 }
1124 26 ▶ my $verb = ($shift ? 'Shifting' : ($addValue ? 'Adding' : 'Writing'));
Branch: 2 branches
BranchTrueFalseTotal
$shift ? : 0 26 26
$addValue ? : 0 26 26
1125 26 print $out "$$self{INDENT2}$verb $wgrp1:$tag$ifExists\n";
1126 }
1127 }
1128 } elsif ($permanent) {
1129 6751 $err = "Can't delete Permanent tag $wgrp1:$tag";
1130 6751 ▶ $verbose > 1 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print $out "$err\n" 0 6751 6751
1131 6751 next;
1132 ▶ } elsif ($addValue or $options{DelValue}) {
Condition33%1/3
$addValue or $options{"DelValue"}
l!l&&r!l&&!r
004082
MC/DC0%0/2
$addValue or $options{"DelValue"}
$addValue $options{"DelValue"}
Truth table33%1/3
A or B
A= $addValueB= $options{"DelValue"}
ABresult
1X1
011
000
1133 0 ▶ $verbose > 1 and print $out "Adding/Deleting nothing does nothing\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print $out "Adding/Deleting nothing does nothing\n" 0 0 0
1134 0 next;
1135 } else {
1136 # create empty new value hash entry to delete this tag
1137 4082 $self->GetNewValueHash($tagInfo, $writeGroup, 'delete');
1138 4082 my $nvHash = $self->GetNewValueHash($tagInfo, $writeGroup, 'create');
1139 4082 $$nvHash{WantGroup} = $wantGroup;
1140 4082 ▶ $verbose > 1 and print $out "$$self{INDENT2}Deleting $wgrp1:$tag\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print $out qq[$self->{"INDENT2"}Deleting ${wgrp1}:$tag\n] 0 4082 4082
1141 }
1142 24515 ▶ $$setTags{$tagInfo} = 1 if $setTags;
Branch: 1 branch
BranchTrueFalseTotal
if $setTags 1431 23084 24515
1143 24515 ▶ $prioritySet = 1 if $$pref{$tagInfo};
Branch: 1 branch
BranchTrueFalseTotal
if $pref->{$tagInfo} 11492 13023 24515
1144 24537 WriteAlso:
1145 ++$numSet;
1146 # also write related tags
1147 24537 my $writeAlso = $$tagInfo{WriteAlso};
1148 24537 ▶ if ($writeAlso) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeAlso) 76 24461 24537
1149 76 $$self{INDENT2} = '+'; # indicate related tag with a leading "+"
1150 76 my ($wgrp, $wtag, $n);
1151 76 ▶ if ($$tagInfo{WriteGroup} and $$tagInfo{WriteGroup} eq 'All' and $writeGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'WriteGroup'} and $tagInfo->{'WriteGroup'} eq 'All' and $writeGroup) { } 46 30 76
Condition66%4/6
$tagInfo->{"WriteGroup"} and $tagInfo->{"WriteGroup"} eq "All" and $writeGroup
!ll&&!rl&&r
30046
$tagInfo->{"WriteGroup"} and $tagInfo->{"WriteGroup"} eq "All"
!ll&&!rl&&r
30046
MC/DC33%1/3
$tagInfo->{"WriteGroup"} and $tagInfo->{"WriteGroup"} eq "All" and $writeGroup
$tagInfo->{"WriteGroup"} $tagInfo->{"WriteGroup"} eq "All" $writeGroup
Truth table50%2/4
A and B and C
A= $tagInfo->{"WriteGroup"}B= $tagInfo->{"WriteGroup"} eq "All"C= $writeGroup
ABCresult
0XX0
10X0
1100
1111
1152 46 $wgrp = $writeGroup . ':';
1153 } else {
1154 30 $wgrp = '';
1155 }
1156 76 local $SIG{'__WARN__'} = \&SetWarning;
1157 76 foreach $wtag (sort keys %$writeAlso) {
1158 my %opts = (
1159 Type => 'ValueConv',
1160 Protected => $protected | 0x02,
1161 AddValue => $addValue,
1162 DelValue => $options{DelValue},
1163 Shift => $options{Shift},
1164 Replace => $options{Replace}, # handle lists properly
1165 243 CreateGroups=> $createGroups,
1166 SetTags => \%alsoWrote, # remember tags already written
1167 );
1168 243 undef $evalWarning;
1169 #### eval WriteAlso ($val,%opts)
1170 243 my $v = eval $$writeAlso{$wtag};
1171 # we wanted to do the eval in case there are side effect, but we
1172 # don't want to write a value for a tag that is being deleted:
1173 243 ▶ undef $v unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 7 236 243
1174 243 ▶ $@ and $evalWarning = $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and $Image::ExifTool::evalWarning = $@ 0 243 243
1175 243 ▶ unless ($evalWarning) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Image::ExifTool::evalWarning) 243 0 243
1176 243 ($n,$evalWarning) = $self->SetNewValue($wgrp . $wtag, $v, %opts);
1177 243 $numSet += $n;
1178 # count this as being set if any related tag is set
1179 243 ▶ $prioritySet = 1 if $n and $$pref{$tagInfo};
Branch: 1 branch
BranchTrueFalseTotal
if $n and $pref->{$tagInfo} 148 95 243
Condition100%3/3
$n and $pref->{$tagInfo}
!ll&&!rl&&r
1184148
MC/DC100%2/2
$n and $pref->{$tagInfo}
$n $pref->{$tagInfo}
Truth table100%3/3
A and B
A= $nB= $pref->{$tagInfo}
ABresult
0X0
100
111
1180 }
1181 243 ▶ if ($evalWarning and (not $err or $verbose > 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::evalWarning and !$err || $verbose > 2) 9 234 243
Condition83%5/6
$Image::ExifTool::evalWarning and !$err || $verbose > 2
!ll&&!rl&&r
23229
not $err or $verbose > 2
l!l&&r!l&&!r
902
MC/DC66%2/3
$Image::ExifTool::evalWarning and !$err || $verbose > 2
$Image::ExifTool::evalWarning not $err $verbose > 2
Truth table75%3/4
A and not(B) or C
A= $Image::ExifTool::evalWarningB= not $errC= $verbose > 2
ABCresult
0XX0
1000
11X1
1011
1182 9 my $str = CleanWarning();
1183 9 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 9 0 9
1184 9 ▶ $str .= " for $wtag" unless $str =~ / for [-\w:]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ / for [-\w:]+$/ 9 0 9
1185 9 $str .= " in $wgrp1:$tag (WriteAlso)";
1186 9 ▶ $err or $err = $str;
Branch: 1 branch
BranchTrueFalseTotal
$err or $err = $str 0 9 9
1187 9 ▶ print $out "$str\n" if $verbose > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 9 9
1188 }
1189 }
1190 }
1191 76 $$self{INDENT2} = '';
1192 }
1193 }
1194 # print warning if we couldn't set our priority tag
1195 4308 ▶ if (defined $err and not $prioritySet) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $err and not $prioritySet) { } 86 4222 4308
elsif (not $numSet) { } 622 3600 4222
elsif ($self->{'CHECK_WARN'}) { } 0 3600 3600
elsif ($err and not $verbose) { } 456 6288 6744
Condition100%3/3
defined $err and not $prioritySet
!ll&&!rl&&r
376645686
MC/DC100%2/2
defined $err and not $prioritySet
defined $err not $prioritySet
Truth table100%3/3
A and not(B)
A= defined $errB= not $prioritySet
ABresult
0X0
100
111
1196 86 ▶ warn "$err\n" if $err and not wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if $err and not wantarray 0 86 86
Condition33%1/3
$err and not wantarray
!ll&&!rl&&r
0860
MC/DC0%0/2
$err and not wantarray
$err not wantarray
Truth table33%1/3
A and not(B)
A= $errB= not wantarray
ABresult
0X0
100
111
1197 } elsif (not $numSet) {
1198 622 ▶ my $pre = $wantGroup ? $wantGroup . ':' : '';
Branch: 1 branch
BranchTrueFalseTotal
$wantGroup ? : 432 190 622
1199 622 ▶ if ($wasProtected) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wasProtected) { } 363 259 622
elsif (not $listOnly) { } 252 7 259
1200 363 $verbose = 0; # we already printed this verbose message
1201 363 ▶ unless ($options{Replace} and $options{Replace} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"Replace"} and $options{"Replace"} == 2) 351 12 363
Condition100%3/3
$options{"Replace"} and $options{"Replace"} == 2
!ll&&!rl&&r
2532612
MC/DC100%2/2
$options{"Replace"} and $options{"Replace"} == 2
$options{"Replace"} $options{"Replace"} == 2
Truth table100%3/3
A and B
A= $options{"Replace"}B= $options{"Replace"} == 2
ABresult
0X0
100
111
1202 351 $err = "Sorry, $pre$tag is $wasProtected for writing";
1203 }
1204 } elsif (not $listOnly) {
1205 252 ▶ if ($origTag =~ /[?*]/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($origTag =~ /[?*]/) { } 0 252 252
elsif ($noCreate) { } 0 252 252
elsif ($foundMatch) { } 0 252 252
elsif ($wantGroup and @matchingTags) { } 252 0 252
1206 0 ▶ if ($noCreate) {
Branch: 2 branches
BranchTrueFalseTotal
if ($noCreate) { } 0 0 0
elsif ($foundMatch) { } 0 0 0
1207 0 $err = "No tags matching 'pre${origTag}' will be created";
1208 0 $verbose = 0; # (already printed)
1209 } elsif ($foundMatch) {
1210 0 $err = "Sorry, no writable tags matching '$pre${origTag}'";
1211 } else {
1212 0 $err = "No matching tags for '$pre${origTag}'";
1213 }
1214 } elsif ($noCreate) {
1215 0 $err = "Not creating $pre$tag";
1216 0 $verbose = 0; # (already printed)
1217 } elsif ($foundMatch) {
1218 0 $err = "Sorry, $pre$tag is not writable";
1219 ▶ } elsif ($wantGroup and @matchingTags) {
Condition33%1/3
$wantGroup and @matchingTags
!ll&&!rl&&r
00252
MC/DC0%0/2
$wantGroup and @matchingTags
$wantGroup @matchingTags
Truth table33%1/3
A and B
A= $wantGroupB= @matchingTags
ABresult
0X0
100
111
1220 252 $err = "Sorry, $pre$tag doesn't exist or isn't writable";
1221 } else {
1222 0 $err = "Tag '$pre${tag}' is not defined";
1223 }
1224 }
1225 622 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 603 19 622
1226 603 ▶ $verbose > 2 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "$err\n" 0 603 603
1227 603 ▶ warn "$err\n" unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 603 603
1228 }
1229 } elsif ($$self{CHECK_WARN}) {
1230 0 $err = $$self{CHECK_WARN};
1231 0 ▶ $verbose > 2 and print $out "$err\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print $out "$err\n" 0 0 0
1232 ▶ } elsif ($err and not $verbose) {
Condition66%2/3
$err and not $verbose
!ll&&!rl&&r
31440456
MC/DC50%1/2
$err and not $verbose
$err not $verbose
Truth table66%2/3
A and not(B)
A= $errB= not $verbose
ABresult
0X0
100
111
1233 456 undef $err;
1234 }
1235 4308 ▶ return ($numSet, $err) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 3837 471 4308
1236 471 return $numSet;
1237 }
1238  
1239 #------------------------------------------------------------------------------
1240 # set new values from information in specified file
1241 # Inputs: 0) ExifTool object reference, 1) source file name or reference, etc,
1242 # or ExifTool ref to use already-extracted tags from an ExifTool object,
1243 # 2-N) List of tags to set (or all if none specified), or reference(s) to
1244 # hash for options to pass to SetNewValue. The Replace option defaults
1245 # to 1 for SetNewValuesFromFile -- set this to 0 to allow multiple tags
1246 # to be copied to a list
1247 # Returns: Hash of information set successfully (includes Warning or Error messages)
1248 # Notes: Tag names may contain a group prefix, a leading '-' to exclude from copy,
1249 # and/or a trailing '#' to copy the ValueConv value. The tag name '*' may
1250 # be used to represent all tags in a group. An optional destination tag
1251 # may be specified with '>DSTTAG' ('DSTTAG<TAG' also works, but in this
1252 # case the source tag may also be an expression involving tag names).
1253 # Simple assignments are also allowed: 'DSTTAG[#][+-][^]=[string]'
1254 sub SetNewValuesFromFile($$;@)
1255 59 ▶{
Subroutine SetNewValuesFromFile: called CC=153 SCAR=61.5
Pod documented
1256 59 local $_;
1257 59 my ($self, $srcFile, @setTags) = @_;
1258 59 my ($srcExifTool, $key, $tag, @exclude, @reqTags, $info);
1259  
1260 # get initial SetNewValuesFromFile options
1261 59 my %opts = ( Replace => 1 ); # replace existing list items by default
1262 59 ▶ while (ref $setTags[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $setTags[0] eq "HASH") 1 59 60
1263 1 $_ = shift @setTags;
1264 1 foreach $key (keys %$_) {
1265 1 $opts{$key} = $$_{$key};
1266 }
1267 }
1268 # expand shortcuts
1269 59 ▶ @setTags and ExpandShortcuts(\@setTags);
Branch: 1 branch
BranchTrueFalseTotal
@setTags and &ExpandShortcuts(\@setTags) 44 15 59
1270 # set options for our extraction tool
1271 59 my $options = $$self{OPTIONS};
1272 59 my $printConv = $$options{PrintConv};
1273 59 ▶ if ($opts{Type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"Type"}) 0 59 59
1274 # save source type separately because it may be different than dst Type
1275 0 $opts{SrcType} = $opts{Type};
1276 # override PrintConv option with initial Type if given
1277 0 ▶ $printConv = ($opts{Type} eq 'PrintConv' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$opts{'Type'} eq 'PrintConv' ? : 0 0 0
1278 }
1279 59 ▶ my $srcType = $printConv ? 'PrintConv' : 'ValueConv';
Branch: 1 branch
BranchTrueFalseTotal
$printConv ? : 55 4 59
1280 59 ▶ my $structOpt = defined $$options{Struct} ? $$options{Struct} : 2;
Branch: 1 branch
BranchTrueFalseTotal
defined $options->{'Struct'} ? : 0 59 59
1281  
1282 59 ▶ if (ref $srcFile and UNIVERSAL::isa($srcFile,'Image::ExifTool')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $srcFile and UNIVERSAL::isa($srcFile, 'Image::ExifTool')) { } 0 59 59
Condition33%1/3
ref $srcFile and UNIVERSAL::isa($srcFile, "Image::ExifTool")
!ll&&!rl&&r
5900
MC/DC0%0/2
ref $srcFile and UNIVERSAL::isa($srcFile, "Image::ExifTool")
ref $srcFile UNIVERSAL::isa($srcFile, "Image::ExifTool")
Truth table33%1/3
A and B
A= ref $srcFileB= UNIVERSAL::isa($srcFile, "Image::ExifTool")
ABresult
0X0
100
111
1283 0 $srcExifTool = $srcFile;
1284 0 $info = $srcExifTool->GetInfo({ PrintConv => $printConv });
1285 } else {
1286 59 $srcExifTool = Image::ExifTool->new;
1287 59 $srcExifTool->Options(PrintConv => $printConv);
1288 # set flag to indicate we are being called from inside SetNewValuesFromFile()
1289 59 $$srcExifTool{TAGS_FROM_FILE} = 1;
1290 # synchronize and increment the file sequence number
1291 59 $$srcExifTool{FILE_SEQUENCE} = $$self{FILE_SEQUENCE}++;
1292 # copy both structured and flattened tags by default (but flattened tags are "unsafe")
1293 # copy structures only if no tags specified (since flattened tags are "unsafe")
1294 59 ▶ $structOpt = 1 if $structOpt eq '2' and not @setTags;
Branch: 1 branch
BranchTrueFalseTotal
if $structOpt eq 2 and not @setTags 15 44 59
Condition66%2/3
$structOpt eq 2 and not @setTags
!ll&&!rl&&r
04415
MC/DC50%1/2
$structOpt eq 2 and not @setTags
$structOpt eq 2 not @setTags
Truth table66%2/3
A and not(B)
A= $structOpt eq 2B= not @setTags
ABresult
0X0
100
111
1295 # +------------------------------------------+
1296 # ! DON'T FORGET!! Must consider each new !
1297 # ! option to decide how it is handled here. !
1298 # +------------------------------------------+
1299 59 foreach (qw(ByteUnit Charset CharsetEXIF CharsetFileName CharsetID3 CharsetIPTC
1300 CharsetPhotoshop Composite DateFormat Debug EncodeHangs Escape
1301 ExtendedXMP ExtractEmbedded FastScan Filter FixBase Geolocation
1302 GeolocAltNames GeolocFeature GeolocMinPop GeolocMaxDist
1303 GlobalTimeShift GPSQuadrant HexTagIDs IgnoreGroups IgnoreMinorErrors
1304 IgnoreTags ImageHashType KeepUTCTime Lang LargeFileSupport
1305 LigoGPSScale ListItem ListSep MDItemTags MissingTagValue NoPDFList
1306 NoWarning Password PrintConv QuickTimeUTC RequestTags SaveFormat
1307 SavePath ScanForXMP StructFormat SystemTags SystemTimeRes TimeZone
1308 Unknown UserParam Validate WindowsLongPath WindowsWideFile XAttrTags
1309 XMPAutoConv))
1310 {
1311 3363 $srcExifTool->Options($_ => $$options{$_});
1312 }
1313 $srcExifTool->Options(
1314 Binary => 1,
1315 CoordFormat => $$options{CoordFormat} || '%d %d %.8f', # copy coordinates at high resolution unless otherwise specified
1316 Duplicates => 1,
1317 # Exclude (set below)
1318 LimitLongValues => 10000000, # (10 MB)
1319 List => 1,
1320 MakerNotes => $$options{FastScan} && $$options{FastScan} > 1 ? undef : 1,
1321 RequestAll => $$options{RequestAll} || 1, # (must request all because reqTags doesn't cover wildcards)
1322 59 ▶ StrictDate => defined $$options{StrictDate} ? $$options{StrictDate} : 1,
Branch: 2 branches
BranchTrueFalseTotal
$options->{'FastScan'} && $options->{'FastScan'} > 1 ? : 0 59 59
defined $options->{'StrictDate'} ? : 0 59 59
Condition42%3/7
$options->{'CoordFormat'} || '%d %d %.8f'
l!l
059
$options->{"FastScan"} and $options->{"FastScan"} > 1
!ll&&!rl&&r
5900
$options->{'RequestAll'} || 1
l!l
059
MC/DC0%0/1
$options->{'CoordFormat'} || '%d %d %.8f'
$options->{'CoordFormat'}
MC/DC0%0/2
$options->{"FastScan"} and $options->{"FastScan"} > 1
$options->{"FastScan"} $options->{"FastScan"} > 1
MC/DC0%0/1
$options->{'RequestAll'} || 1
$options->{'RequestAll'}
Truth table50%1/2
A
A= $options->{'CoordFormat'}
Aresult
11
00
Truth table33%1/3
A and B
A= $options->{"FastScan"}B= $options->{"FastScan"} > 1
ABresult
0X0
100
111
Truth table50%1/2
A
A= $options->{'RequestAll'}
Aresult
11
00
1323 Struct => $structOpt,
1324 );
1325 # reset Geolocation option if we aren't copying any geolocation tags
1326 59 ▶ if ($$options{Geolocation} and not grep /\bGeolocation/i, @setTags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"Geolocation"} and not grep(/\bGeolocation/i, @setTags)) 0 59 59
Condition33%1/3
$options->{"Geolocation"} and not grep(/\bGeolocation/i, @setTags)
!ll&&!rl&&r
5900
MC/DC0%0/2
$options->{"Geolocation"} and not grep(/\bGeolocation/i, @setTags)
$options->{"Geolocation"} not grep(/\bGeolocation/i, @setTags)
Truth table33%1/3
A and not(B)
A= $options->{"Geolocation"}B= not grep(/\bGeolocation/i, @setTags)
ABresult
0X0
100
111
1327 0 $self->VPrint(0, '(resetting unnecessary Geolocation option)');
1328 0 $$srcExifTool{OPTIONS}{Geolocation} = undef;
1329 }
1330 59 $$srcExifTool{GLOBAL_TIME_OFFSET} = $$self{GLOBAL_TIME_OFFSET};
1331 59 $$srcExifTool{ALT_EXIFTOOL} = $$self{ALT_EXIFTOOL};
1332 59 foreach $tag (@setTags) {
1333 71 ▶ next if ref $tag;
Branch: 1 branch
BranchTrueFalseTotal
if ref $tag 1 70 71
1334 # avoid extracting tags that are excluded
1335 70 ▶ $tag =~ /^-(.*)/ and push(@exclude, $1), next;
Branch: 1 branch
BranchTrueFalseTotal
$tag =~ /^-(.*)/ and push(@exclude, $1), next 8 62 70
1336 # add specified tags to list of requested tags
1337 62 $_ = $tag;
1338 62 ▶ if (/(.+?)\s*(>|<)\s*(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(.+?)\s*(>|<)\s*(.+)/) 31 31 62
1339 31 ▶ if ($2 eq '>') {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq '>') { } 10 21 31
1340 10 $_ = $1;
1341 } else {
1342 21 $_ = $3;
1343 21 ▶ /\$/ and push(@reqTags, /\$\{?(?:[-\w]+:)*([-\w?*]+)/g), next;
Branch: 1 branch
BranchTrueFalseTotal
/\$/ and push(@reqTags, /\$\{?(?:[-\w]+:)*([-\w?*]+)/g), next 8 13 21
1344 }
1345 }
1346 54 ▶ push @reqTags, $2 if /(^|:)([-\w?*]+)#?$/;
Branch: 1 branch
BranchTrueFalseTotal
if /(^|:)([-\w?*]+)#?$/ 54 0 54
1347 }
1348 59 ▶ if (@exclude) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exclude) 7 52 59
1349 7 ExpandShortcuts(\@exclude, 1);
1350 7 $srcExifTool->Options(Exclude => \@exclude);
1351 }
1352 59 ▶ $srcExifTool->Options(RequestTags => \@reqTags) if @reqTags;
Branch: 1 branch
BranchTrueFalseTotal
if @reqTags 43 16 59
1353 # get all tags from source file (including MakerNotes block)
1354 59 $info = $srcExifTool->ImageInfo($srcFile);
1355 }
1356 # (allow processing to continue if we have alternate files that may have been read OK)
1357 59 ▶ return $info if $$info{Error} and $$info{Error} eq 'Error opening file' and not $$self{ALT_EXIFTOOL};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"Error"} and $info->{"Error"} eq "Error opening file" and not $self->{"ALT_EXIFTOOL"} 0 59 59
Condition33%2/6
$info->{"Error"} and $info->{"Error"} eq "Error opening file" and not $self->{"ALT_EXIFTOOL"}
!ll&&!rl&&r
5900
$info->{"Error"} and $info->{"Error"} eq "Error opening file"
!ll&&!rl&&r
5900
MC/DC0%0/3
$info->{"Error"} and $info->{"Error"} eq "Error opening file" and not $self->{"ALT_EXIFTOOL"}
$info->{"Error"} $info->{"Error"} eq "Error opening file" not $self->{"ALT_EXIFTOOL"}
Truth table25%1/4
A and B and not(C)
A= $info->{"Error"}B= $info->{"Error"} eq "Error opening file"C= not $self->{"ALT_EXIFTOOL"}
ABCresult
0XX0
10X0
1100
1111
1358 59 delete $$srcExifTool{VALUE}{Error}; # delete so we can check this later
1359  
1360 # sort tags in file order with priority tags last
1361 59 my (@tags, @prio);
1362 59 foreach (sort { $$srcExifTool{FILE_ORDER}{$a} <=> $$srcExifTool{FILE_ORDER}{$b} } keys %$info) {
1363 9141 ▶ if (/ /) {
Branch: 1 branch
BranchTrueFalseTotal
if (/ /) { } 768 8373 9141
1364 768 push @tags, $_;
1365 } else {
1366 8373 push @prio, $_;
1367 }
1368 }
1369 59 push @tags, @prio;
1370 #
1371 # simply transfer all tags from source image if no tags specified
1372 #
1373 59 ▶ unless (@setTags) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@setTags) 15 44 59
1374 # transfer maker note information to this object
1375 15 $$self{MAKER_NOTE_BYTE_ORDER} = $$srcExifTool{MAKER_NOTE_BYTE_ORDER};
1376 15 my $tagExtra = $$srcExifTool{TAG_EXTRA};
1377 15 foreach $tag (@tags) {
1378 # don't try to set errors or warnings
1379 2651 ▶ next if $tag =~ /^(Error|Warning)\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^(Error|Warning)\b/ 4 2647 2651
1380 # get appropriate value type if necessary
1381 2647 ▶ if ($opts{SrcType} and $opts{SrcType} ne $srcType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"SrcType"} and $opts{"SrcType"} ne $srcType) 0 2647 2647
Condition33%1/3
$opts{"SrcType"} and $opts{"SrcType"} ne $srcType
!ll&&!rl&&r
264700
MC/DC0%0/2
$opts{"SrcType"} and $opts{"SrcType"} ne $srcType
$opts{"SrcType"} $opts{"SrcType"} ne $srcType
Truth table33%1/3
A and B
A= $opts{"SrcType"}B= $opts{"SrcType"} ne $srcType
ABresult
0X0
100
111
1382 0 $$info{$tag} = $srcExifTool->GetValue($tag, $opts{SrcType});
1383 }
1384 2647 my $fixup = $$tagExtra{$tag}{Fixup};
1385 2647 ▶ $opts{Fixup} = $fixup if $fixup;
Branch: 1 branch
BranchTrueFalseTotal
if $fixup 7 2640 2647
1386 # set value for this tag
1387 2647 my ($n, $e) = $self->SetNewValue($tag, $$info{$tag}, %opts);
1388 # delete this tag if we couldn't set it
1389 2647 ▶ $n or delete $$info{$tag};
Branch: 1 branch
BranchTrueFalseTotal
$n or delete $info->{$tag} 1669 978 2647
1390 2647 ▶ delete $opts{Fixup} if $fixup;
Branch: 1 branch
BranchTrueFalseTotal
if $fixup 7 2640 2647
1391 }
1392 15 return $info;
1393 }
1394 #
1395 # transfer specified tags in the proper order
1396 #
1397 # 1) loop through input list of tags to set, and build @setList
1398 44 my (@setList, $set, %setMatches, $t, %altFiles);
1399 44 my $assign = 0;
1400 44 foreach $t (@setTags) {
1401 71 ▶ if (ref $t eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t eq "HASH") 1 70 71
1402 # update current options
1403 1 foreach $key (keys %$t) {
1404 1 $opts{$key} = $$t{$key};
1405 }
1406 1 next;
1407 }
1408 # make a copy of the current options for this setTag
1409 # (also use this hash to store expression and wildcard flags, EXPR and WILD)
1410 70 my $opts = { %opts };
1411 70 $tag = lc $t; # change tag/group names to all lower case
1412 70 my (@fg, $grp, $dst, $dstGrp, $dstTag, $isExclude);
1413 # handle redirection to another tag
1414 70 ▶ if ($tag =~ /(.+?)\s*(>|<|=)(\s*)(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /(.+?)\s*(>|<|=)(\s*)(.*)/) { } 31 39 70
1415 31 $dstGrp = '';
1416 31 my ($opt, $op, $spc);
1417 31 ▶ if ($2 eq '>') {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq '>') { } 10 21 31
1418 10 ($tag, $dstTag) = ($1, $4);
1419 # flag add and delete (eg. '+<' and '-<') redirections
1420 10 ▶ $opt = $1 if $tag =~ s/\s*([-+])$// or $dstTag =~ s/^([-+])\s*//;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ s/\s*([-+])$// or $dstTag =~ s/^([-+])\s*// 0 10 10
Condition33%1/3
$tag =~ s/\s*([-+])$// or $dstTag =~ s/^([-+])\s*//
l!l&&r!l&&!r
0010
MC/DC0%0/2
$tag =~ s/\s*([-+])$// or $dstTag =~ s/^([-+])\s*//
$tag =~ s/\s*([-+])$// $dstTag =~ s/^([-+])\s*//
Truth table33%1/3
A or B
A= $tag =~ s/\s*([-+])$//B= $dstTag =~ s/^([-+])\s*//
ABresult
1X1
011
000
1421 } else {
1422 21 ($dstTag, $op, $spc, $tag) = ($1, $2, $3, $4);
1423 21 ▶ $opt = $1 if $dstTag =~ s/\s*([-+])$//;
Branch: 1 branch
BranchTrueFalseTotal
if $dstTag =~ s/\s*([-+])$// 0 21 21
1424 21 ▶ if ($op eq '=') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '=') { } 0 21 21
elsif ($tag =~ /\$/) { } 8 13 21
1425 # simple assignment ($tag will be the new value)
1426 0 $tag = $spc . $tag;
1427 0 ▶ undef $tag unless $dstTag =~ s/\^$// or length $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $dstTag =~ s/\^$// or length $tag 0 0 0
Condition0%0/3
$dstTag =~ s/\^$// or length $tag
l!l&&r!l&&!r
000
MC/DC0%0/2
$dstTag =~ s/\^$// or length $tag
$dstTag =~ s/\^$// length $tag
Truth table0%0/3
A or B
A= $dstTag =~ s/\^$//B= length $tag
ABresult
1X1
011
000
1428 0 $$opts{ASSIGN} = ++$assign;
1429 } elsif ($tag =~ /\$/) { # handle expressions
1430 8 $tag = $t; # restore original case
1431 # recover leading whitespace (except for initial single space)
1432 8 $tag =~ s/(.+?)\s*(>|<) ?//;
1433 8 $$opts{EXPR} = 1; # flag this expression
1434 } else {
1435 # (not sure why this is here because sign should be before '<')
1436 # (--> allows "<+" or "<-", which is an undocumented feature)
1437 13 ▶ $opt = $1 if $tag =~ s/^([-+])\s*//;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ s/^([-+])\s*// 0 13 13
1438 }
1439 }
1440 31 ▶ $$opts{Replace} = 0 if $dstTag =~ s/^\+//;
Branch: 1 branch
BranchTrueFalseTotal
if $dstTag =~ s/^\+// 3 28 31
1441 # validate tag name(s)
1442 31 ▶ unless ($$opts{EXPR} or $$opts{ASSIGN} or ValidTagName($tag)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"EXPR"} or $opts->{"ASSIGN"} or &ValidTagName($tag)) 0 31 31
Condition66%4/6
$opts->{"EXPR"} or $opts->{"ASSIGN"} or &ValidTagName($tag)
l!l&&r!l&&!r
8230
$opts->{"EXPR"} or $opts->{"ASSIGN"}
l!l&&r!l&&!r
8023
MC/DC0%0/3
$opts->{"EXPR"} or $opts->{"ASSIGN"} or &ValidTagName($tag)
$opts->{"EXPR"} $opts->{"ASSIGN"} &ValidTagName($tag)
Truth table50%2/4
A or B or C
A= $opts->{"EXPR"}B= $opts->{"ASSIGN"}C= &ValidTagName($tag)
ABCresult
1XX1
01X1
0011
0000
1443 0 $self->Warn("Invalid tag name '${tag}'. Use '=' not '<' to assign a tag value");
1444 0 next;
1445 }
1446 31 ▶ ValidTagName($dstTag) or $self->Warn("Invalid tag name '${dstTag}'"), next;
Branch: 1 branch
BranchTrueFalseTotal
&ValidTagName($dstTag) or $self->Warn("Invalid tag name '${dstTag}'"), next 31 0 31
1447 # translate '+' and '-' to appropriate SetNewValue option
1448 31 ▶ if ($opt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt) 0 31 31
1449 0 $$opts{{ '+' => 'AddValue', '-' => 'DelValue' }->{$opt}} = 1;
1450 0 $$opts{Shift} = 0; # shift if shiftable
1451 }
1452 31 ▶ ($dstGrp, $dstTag) = ($1, $2) if $dstTag =~ /(.*):(.+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $dstTag =~ /(.*):(.+)/ 16 15 31
1453 # ValueConv may be specified separately on the destination with '#'
1454 31 ▶ $$opts{Type} = 'ValueConv' if $dstTag =~ s/#$//;
Branch: 1 branch
BranchTrueFalseTotal
if $dstTag =~ s/#$// 0 31 31
1455 # replace tag name of 'all' with '*'
1456 31 ▶ $dstTag = '*' if $dstTag eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $dstTag eq "all" 3 28 31
1457 } else {
1458 39 ▶ $$opts{Replace} = 0 if $tag =~ s/^\+//;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ s/^\+// 0 39 39
1459 }
1460 70 ▶ unless ($$opts{EXPR} or $$opts{ASSIGN}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"EXPR"} or $opts->{"ASSIGN"}) 62 8 70
Condition66%2/3
$opts->{"EXPR"} or $opts->{"ASSIGN"}
l!l&&r!l&&!r
8062
MC/DC50%1/2
$opts->{"EXPR"} or $opts->{"ASSIGN"}
$opts->{"EXPR"} $opts->{"ASSIGN"}
Truth table66%2/3
A or B
A= $opts->{"EXPR"}B= $opts->{"ASSIGN"}
ABresult
1X1
011
000
1461 62 $isExclude = ($tag =~ s/^-//);
1462 62 ▶ if ($tag =~ /(.*):(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /(.*):(.+)/) 34 28 62
1463 34 ($grp, $tag) = ($1, $2);
1464 34 foreach (split /:/, $grp) {
1465 # save family/groups in list (ignoring 'all' and '*')
1466 35 ▶ next unless length($_) and /^(\d+)?(.*)/;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ and /^(\d+)?(.*)/ 0 35 35
Condition33%1/3
length $_ and /^(\d+)?(.*)/
!ll&&!rl&&r
0035
MC/DC0%0/2
length $_ and /^(\d+)?(.*)/
length $_ /^(\d+)?(.*)/
Truth table33%1/3
A and B
A= length $_B= /^(\d+)?(.*)/
ABresult
0X0
100
111
1467 35 my ($f, $g) = ($1, $2);
1468 35 ▶ $f = 7 if (not $f or $f eq '7') and $g =~ s/^ID-//i;
Branch: 1 branch
BranchTrueFalseTotal
if !$f || $f eq 7 and $g =~ s/^ID-//i 0 35 35
Condition33%2/6
!$f || $f eq 7 and $g =~ s/^ID-//i
!ll&&!rl&&r
0350
not $f or $f eq 7
l!l&&r!l&&!r
3500
MC/DC0%0/3
!$f || $f eq 7 and $g =~ s/^ID-//i
not $f $f eq 7 $g =~ s/^ID-//i
Truth table20%1/5
not(A) or B and C
A= not $fB= $f eq 7C= $g =~ s/^ID-//i
ABCresult
00X0
1X00
0100
1X11
0111
1469 35 ▶ if ($g =~ /^file\d+$/i and (not $f or $f eq '8')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($g =~ /^file\d+$/i and !$f || $f eq 8) 3 32 35
Condition50%3/6
$g =~ /^file\d+$/i and !$f || $f eq 8
!ll&&!rl&&r
3203
not $f or $f eq 8
l!l&&r!l&&!r
300
MC/DC33%1/3
$g =~ /^file\d+$/i and !$f || $f eq 8
$g =~ /^file\d+$/i not $f $f eq 8
Truth table50%2/4
A and not(B) or C
A= $g =~ /^file\d+$/iB= not $fC= $f eq 8
ABCresult
0XX0
1000
11X1
1011
1470 3 $f = 8;
1471 3 my $g8 = ucfirst $g;
1472 3 ▶ if ($$srcExifTool{ALT_EXIFTOOL}{$g8}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($srcExifTool->{"ALT_EXIFTOOL"}{$g8}) 3 0 3
1473 3 $$opts{GROUP8} = $g8;
1474 3 ▶ $altFiles{$g8} or $altFiles{$g8} = [ ];
Branch: 1 branch
BranchTrueFalseTotal
$altFiles{$g8} or $altFiles{$g8} = [] 2 1 3
1475 # save list of requested tags for this alternate ExifTool object
1476 3 push @{$altFiles{$g8}}, "$grp:$tag";
1477 }
1478 }
1479 35 ▶ push @fg, [ $f, $g ] unless $g eq '*' or $g eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
unless $g eq "*" or $g eq "all" 26 9 35
Condition100%3/3
$g eq "*" or $g eq "all"
l!l&&r!l&&!r
5426
MC/DC100%2/2
$g eq "*" or $g eq "all"
$g eq "*" $g eq "all"
Truth table100%3/3
A or B
A= $g eq "*"B= $g eq "all"
ABresult
1X1
011
000
1480 }
1481 }
1482 # allow ValueConv to be specified by a '#' on the tag name
1483 62 ▶ if ($tag =~ s/#$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ s/#$//) 0 62 62
1484 0 $$opts{SrcType} = 'ValueConv';
1485 0 ▶ $$opts{Type} = 'ValueConv' unless $dstTag;
Branch: 1 branch
BranchTrueFalseTotal
unless $dstTag 0 0 0
1486 }
1487 # replace 'all' with '*' in tag and group names
1488 62 ▶ $tag = '*' if $tag eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "all" 14 48 62
1489 # allow wildcards in tag names (handle differently from all tags: '*')
1490 62 ▶ if ($tag =~ /[?*]/ and $tag ne '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /[?*]/ and $tag ne "*") 3 59 62
Condition100%3/3
$tag =~ /[?*]/ and $tag ne "*"
!ll&&!rl&&r
39203
MC/DC100%2/2
$tag =~ /[?*]/ and $tag ne "*"
$tag =~ /[?*]/ $tag ne "*"
Truth table100%3/3
A and B
A= $tag =~ /[?*]/B= $tag ne "*"
ABresult
0X0
100
111
1491 3 $$opts{WILD} = 1; # set flag indicating wildcards were used in source tag
1492 3 $tag =~ s/\*/[-\\w]*/g;
1493 3 $tag =~ s/\?/[-\\w]/g;
1494 }
1495 }
1496 # redirect, exclude or set this tag (Note: @fg is empty if we don't care about the group)
1497 70 ▶ if ($dstTag) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dstTag) { } 31 39 70
elsif ($isExclude) { } 8 31 39
1498 # redirect this tag
1499 31 ▶ $isExclude and return { Error => "Can't redirect excluded tag" };
Branch: 1 branch
BranchTrueFalseTotal
$isExclude and return {"Error", "Can't redirect excluded tag"} 0 31 31
1500 # set destination group the same as source if necessary
1501 # (removed in 7.72 so '-*:*<xmp:*' will preserve XMP family 1 groups)
1502 # $dstGrp = $grp if $dstGrp eq '*' and $grp;
1503 # write to specified destination group/tag
1504 31 $dst = [ $dstGrp, $dstTag ];
1505 } elsif ($isExclude) {
1506 # implicitly assume '*' if first entry is an exclusion
1507 8 ▶ unshift @setList, [ [ ], '*', [ '', '*' ], $opts ] unless @setList;
Branch: 1 branch
BranchTrueFalseTotal
unless @setList 1 7 8
1508 # exclude this tag by leaving $dst undefined
1509 } else {
1510 31 ▶ $dst = [ $grp || '', $$opts{WILD} ? '*' : $tag ]; # use same group name for dest
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'WILD'} ? : 1 30 31
Condition100%2/2
$grp || ''
l!l
1318
MC/DC100%1/1
$grp || ''
$grp
Truth table100%2/2
A
A= $grp
Aresult
11
00
1511 }
1512 # save in reverse order so we don't set tags before an exclude
1513 70 unshift @setList, [ \@fg, $tag, $dst, $opts ];
1514 }
1515 # 1b) copy requested tags for each alternate ExifTool object
1516 44 my $g8;
1517 44 foreach $g8 (sort keys %altFiles) {
1518 # request specific alternate tags to load them from the alternate ExifTool object
1519 1 my $altInfo = $srcExifTool->GetInfo($altFiles{$g8});
1520 # add to tags list after dummy entry to signify start of tags for this alt file
1521 1 ▶ if (%$altInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$altInfo) 1 0 1
1522 1 push @tags, 'Warning DUMMY', reverse sort keys %$altInfo;
1523 1 $$info{$_} = $$altInfo{$_} foreach keys %$altInfo;
1524 }
1525 }
1526 # 2) initialize lists of matching tags for each setTag
1527 44 foreach $set (@setList) {
1528 71 ▶ $$set[2] and $setMatches{$set} = [ ];
Branch: 1 branch
BranchTrueFalseTotal
$set->[2] and $setMatches{$set} = [] 63 8 71
1529 }
1530 # no need to search source tags if doing only assignments
1531 44 ▶ undef @tags if $assign == @setList;
Branch: 1 branch
BranchTrueFalseTotal
if $assign == @setList 0 44 44
1532 # 3) loop through all tags in source image and save tags matching each setTag
1533 44 my (%rtnInfo, $isAlt);
1534 44 foreach $tag (@tags) {
1535 # don't try to set errors or warnings
1536 6494 ▶ if ($tag =~ /^(Error|Warning)( |$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^(Error|Warning)( |$)/) 14 6480 6494
1537 14 ▶ if ($tag eq 'Warning DUMMY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'Warning DUMMY') { } 1 13 14
1538 1 $isAlt = 1; # start of the alt tags
1539 } else {
1540 13 $rtnInfo{$tag} = $$info{$tag};
1541 }
1542 14 next;
1543 }
1544 # only set specified tags
1545 6480 my $lcTag = lc(GetTagName($tag));
1546 6480 my (@grp, %grp);
1547 6480 SET: foreach $set (@setList) {
1548 10534 my $opts = $$set[3];
1549 10534 ▶ next if $$opts{EXPR}; # (expressions handled in step 4)
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"EXPR"} 1126 9408 10534
1550 9408 ▶ next if $$opts{GROUP8} xor $isAlt;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"GROUP8"} xor $isAlt 570 8838 9408
Condition100%4/4
$opts->{"GROUP8"} xor $isAlt
l&&rl&&!r!l&&r!l&&!r
956468829
MC/DC100%2/2
$opts->{"GROUP8"} xor $isAlt
$opts->{"GROUP8"} $isAlt
Truth table100%4/4
A xor B
A= $opts->{"GROUP8"}B= $isAlt
ABresult
110
101
011
000
1551 # check first for matching tag
1552 8838 ▶ unless ($$set[1] eq $lcTag or $$set[1] eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($set->[1] eq $lcTag or $set->[1] eq "*") 6212 2626 8838
Condition100%3/3
$set->[1] eq $lcTag or $set->[1] eq "*"
l!l&&r!l&&!r
4525816212
MC/DC100%2/2
$set->[1] eq $lcTag or $set->[1] eq "*"
$set->[1] eq $lcTag $set->[1] eq "*"
Truth table100%3/3
A or B
A= $set->[1] eq $lcTagB= $set->[1] eq "*"
ABresult
1X1
011
000
1553 # handle wildcards
1554 6212 ▶ next unless $$opts{WILD} and $lcTag =~ /^$$set[1]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"WILD"} and $lcTag =~ /^$set->[1]$/ 6196 16 6212
Condition100%3/3
$opts->{"WILD"} and $lcTag =~ /^$set->[1]$/
!ll&&!rl&&r
568151516
MC/DC100%2/2
$opts->{"WILD"} and $lcTag =~ /^$set->[1]$/
$opts->{"WILD"} $lcTag =~ /^$set->[1]$/
Truth table100%3/3
A and B
A= $opts->{"WILD"}B= $lcTag =~ /^$set->[1]$/
ABresult
0X0
100
111
1555 }
1556 # then check for matching group
1557 2642 ▶ if (@{$$set[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$set->[0];}) 1474 1168 2642
1558 # get lower case group names if not done already
1559 1474 ▶ unless (@grp) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@grp) 1370 104 1474
1560 1370 @grp = map(lc, $srcExifTool->GetGroup($tag));
1561 1370 $grp{$_} = 1 foreach @grp;
1562 }
1563 1474 foreach (@{$$set[0]}) {
1564 1516 my ($f, $g) = @$_;
1565 1516 ▶ if (not defined $f) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $f) { } 1512 4 1516
elsif ($f == 7) { } 0 4 4
1566 1512 ▶ next SET unless $grp{$g};
Branch: 1 branch
BranchTrueFalseTotal
unless $grp{$g} 1016 496 1512
1567 } elsif ($f == 7) {
1568 0 ▶ next SET unless IsSameID($srcExifTool->GetTagID($tag), $g);
Branch: 1 branch
BranchTrueFalseTotal
unless &IsSameID(scalar $srcExifTool->GetTagID($tag), $g) 0 0 0
1569 } else {
1570 4 ▶ next SET unless defined $grp[$f] and $g eq $grp[$f];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $grp[$f] and $g eq $grp[$f] 0 4 4
Condition33%1/3
defined $grp[$f] and $g eq $grp[$f]
!ll&&!rl&&r
004
MC/DC0%0/2
defined $grp[$f] and $g eq $grp[$f]
defined $grp[$f] $g eq $grp[$f]
Truth table33%1/3
A and B
A= defined $grp[$f]B= $g eq $grp[$f]
ABresult
0X0
100
111
1571 }
1572 }
1573 }
1574 1626 ▶ last unless $$set[2]; # all done if we hit an exclude
Branch: 1 branch
BranchTrueFalseTotal
unless $set->[2] 174 1452 1626
1575 # add to the list of tags matching this setTag
1576 1452 push @{$setMatches{$set}}, $tag;
1577 }
1578 }
1579 # 4) loop through each setTag in original order, setting new tag values
1580 44 foreach $set (reverse @setList) {
1581 # get options for SetNewValue
1582 71 my $opts = $$set[3];
1583 # handle expressions
1584 71 ▶ if ($$opts{EXPR} or $$opts{ASSIGN}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"EXPR"} or $opts->{"ASSIGN"}) 8 63 71
Condition66%2/3
$opts->{"EXPR"} or $opts->{"ASSIGN"}
l!l&&r!l&&!r
8063
MC/DC50%1/2
$opts->{"EXPR"} or $opts->{"ASSIGN"}
$opts->{"EXPR"} $opts->{"ASSIGN"}
Truth table66%2/3
A or B
A= $opts->{"EXPR"}B= $opts->{"ASSIGN"}
ABresult
1X1
011
000
1585 8 my $val;
1586 8 ▶ if ($$opts{EXPR}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'EXPR'}) { } 8 0 8
1587 8 $val = $srcExifTool->InsertTagValues($$set[1], \@tags, 'Error');
1588 8 my $err = $$srcExifTool{VALUE}{Error};
1589 8 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 8 8
1590 # pass on any error as a warning unless it is suppressed
1591 0 my $noWarn = $$srcExifTool{OPTIONS}{NoWarning};
1592 0 ▶ unless ($noWarn and (eval { $err =~ /$noWarn/ } or
Branch: 1 branch
BranchTrueFalseTotal
unless ($noWarn and eval { do { $err =~ /$noWarn/ } } || $err =~ s/^\[minor\] //i && eval { do { $err =~ /$noWarn/ } }) 0 0 0
Condition0%0/9
$noWarn and eval { do { $err =~ /$noWarn/ } } || $err =~ s/^\[minor\] //i && eval { do { $err =~ /$noWarn/ } }
!ll&&!rl&&r
000
eval { do { $err =~ /$noWarn/ } } or $err =~ s/^\[minor\] //i and eval { do { $err =~ /$noWarn/ } }
l!l&&r!l&&!r
000
$err =~ s/^\[minor\] //i and eval { do { $err =~ /$noWarn/ } }
!ll&&!rl&&r
000
MC/DC0%0/4
$noWarn and eval { do { $err =~ /$noWarn/ } } || $err =~ s/^\[minor\] //i && eval { do { $err =~ /$noWarn/ } }
$noWarn eval { do { $err =~ /$noWarn/ } } $err =~ s/^\[minor\] //i eval { do { $err =~ /$noWarn/ } }
Truth table0%0/5
A and B or C and D
A= $noWarnB= eval { do { $err =~ /$noWarn/ } }C= $err =~ s/^\[minor\] //iD= eval { do { $err =~ /$noWarn/ } }
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1593 # (also apply expression to warning without "[minor] " prefix)
1594 0 ($err =~ s/^\[minor\] //i and eval { $err =~ /$noWarn/ })))
1595 {
1596 0 $tag = NextFreeTagKey(\%rtnInfo, 'Warning');
1597 0 $rtnInfo{$tag} = $$srcExifTool{VALUE}{Error};
1598 }
1599 0 delete $$srcExifTool{VALUE}{Error};
1600 0 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
1601 }
1602 } else {
1603 0 $val = $$set[1];
1604 }
1605 8 my ($dstGrp, $dstTag) = @{$$set[2]};
1606 8 ▶ $$opts{Protected} = 1 unless $dstTag =~ /[?*]/ and $dstTag ne '*';
Branch: 1 branch
BranchTrueFalseTotal
unless $dstTag =~ /[?*]/ and $dstTag ne "*" 8 0 8
Condition33%1/3
$dstTag =~ /[?*]/ and $dstTag ne "*"
!ll&&!rl&&r
800
MC/DC0%0/2
$dstTag =~ /[?*]/ and $dstTag ne "*"
$dstTag =~ /[?*]/ $dstTag ne "*"
Truth table33%1/3
A and B
A= $dstTag =~ /[?*]/B= $dstTag ne "*"
ABresult
0X0
100
111
1607 8 ▶ $$opts{Group} = $dstGrp if $dstGrp;
Branch: 1 branch
BranchTrueFalseTotal
if $dstGrp 0 8 8
1608 8 my @rtnVals = $self->SetNewValue($dstTag, $val, %$opts);
1609 8 ▶ $rtnInfo{$dstTag} = $val if $rtnVals[0]; # tag was set successfully
Branch: 1 branch
BranchTrueFalseTotal
if $rtnVals[0] 8 0 8
1610 # return warning if any
1611 8 ▶ $rtnInfo{NextFreeTagKey(\%rtnInfo, 'Warning')} = $rtnVals[1] if $rtnVals[1];
Branch: 1 branch
BranchTrueFalseTotal
if $rtnVals[1] 0 8 8
1612 8 next;
1613 }
1614 63 foreach $tag (@{$setMatches{$set}}) {
1615 1452 my ($val, $noWarn);
1616 1452 ▶ if ($$opts{SrcType} and $$opts{SrcType} ne $srcType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'SrcType'} and $opts->{'SrcType'} ne $srcType) { } 0 1452 1452
Condition33%1/3
$opts->{"SrcType"} and $opts->{"SrcType"} ne $srcType
!ll&&!rl&&r
145200
MC/DC0%0/2
$opts->{"SrcType"} and $opts->{"SrcType"} ne $srcType
$opts->{"SrcType"} $opts->{"SrcType"} ne $srcType
Truth table33%1/3
A and B
A= $opts->{"SrcType"}B= $opts->{"SrcType"} ne $srcType
ABresult
0X0
100
111
1617 0 $val = $srcExifTool->GetValue($tag, $$opts{SrcType});
1618 } else {
1619 1452 $val = $$info{$tag};
1620 }
1621 1452 my ($dstGrp, $dstTag) = @{$$set[2]};
1622 1452 ▶ if ($dstGrp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dstGrp) { } 1370 82 1452
1623 1370 my @dstGrp = split /:/, $dstGrp;
1624 # destination group of '*' writes to same group as source tag
1625 # (family 1 unless otherwise specified)
1626 1370 foreach (@dstGrp) {
1627 1372 ▶ next unless /^(\d*)(all|\*)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless /^(\d*)(all|\*)$/i 286 1086 1372
1628 1086 ▶ $_ = $1 . $srcExifTool->GetGroup($tag, length $1 ? $1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
length $1 ? : 0 1086 1086
1629 1086 $noWarn = 1; # don't warn on wildcard destinations
1630 }
1631 1370 $$opts{Group} = join ':', @dstGrp;
1632 } else {
1633 82 delete $$opts{Group};
1634 }
1635 # transfer maker note information if setting this tag
1636 1452 ▶ if ($$srcExifTool{TAG_INFO}{$tag}{MakerNotes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($srcExifTool->{"TAG_INFO"}{$tag}{"MakerNotes"}) 7 1445 1452
1637 7 $$opts{Fixup} = $$srcExifTool{TAG_EXTRA}{$tag}{Fixup};
1638 7 $$self{MAKER_NOTE_BYTE_ORDER} = $$srcExifTool{MAKER_NOTE_BYTE_ORDER};
1639 }
1640 1452 ▶ if ($dstTag eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dstTag eq "*") 1419 33 1452
1641 1419 $dstTag = $tag;
1642 1419 $noWarn = 1;
1643 }
1644 1452 ▶ if ($$set[1] eq '*' or $$set[3]{WILD}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->[1] eq '*' or $set->[3]{'WILD'}) { } 1415 37 1452
Condition100%3/3
$set->[1] eq "*" or $set->[3]{"WILD"}
l!l&&r!l&&!r
1407837
MC/DC100%2/2
$set->[1] eq "*" or $set->[3]{"WILD"}
$set->[1] eq "*" $set->[3]{"WILD"}
Truth table100%3/3
A or B
A= $set->[1] eq "*"B= $set->[3]{"WILD"}
ABresult
1X1
011
000
1645 # don't copy from protected binary tags when using wildcards
1646 next if $$srcExifTool{TAG_INFO}{$tag}{Protected} and
1647 1415 ▶ $$srcExifTool{TAG_INFO}{$tag}{Binary};
Branch: 1 branch
BranchTrueFalseTotal
if $srcExifTool->{"TAG_INFO"}{$tag}{"Protected"} and $srcExifTool->{"TAG_INFO"}{$tag}{"Binary"} 26 1389 1415
Condition100%3/3
$srcExifTool->{"TAG_INFO"}{$tag}{"Protected"} and $srcExifTool->{"TAG_INFO"}{$tag}{"Binary"}
!ll&&!rl&&r
127111826
MC/DC100%2/2
$srcExifTool->{"TAG_INFO"}{$tag}{"Protected"} and $srcExifTool->{"TAG_INFO"}{$tag}{"Binary"}
$srcExifTool->{"TAG_INFO"}{$tag}{"Protected"} $srcExifTool->{"TAG_INFO"}{$tag}{"Binary"}
Truth table100%3/3
A and B
A= $srcExifTool->{"TAG_INFO"}{$tag}{"Protected"}B= $srcExifTool->{"TAG_INFO"}{$tag}{"Binary"}
ABresult
0X0
100
111
1648 # don't copy to protected tags when using wildcards
1649 1389 delete $$opts{Protected};
1650 # don't copy flattened tags if copying structures too when copying all
1651 1389 ▶ $$opts{NoFlat} = $structOpt eq '2' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$structOpt eq '2' ? : 1389 0 1389
1652 } else {
1653 # allow protected tags to be copied if specified explicitly
1654 37 ▶ $$opts{Protected} = 1 unless $dstTag =~ /[?*]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $dstTag =~ /[?*]/ 37 0 37
1655 37 delete $$opts{NoFlat};
1656 }
1657 # set value(s) for this tag
1658 1426 my ($rtn, $wrn) = $self->SetNewValue($dstTag, $val, %$opts);
1659 # this was added in version 9.14, and allowed actions like "-subject<all" to
1660 # write values of multiple tags into a list, but it had the side effect of
1661 # duplicating items if there were multiple list tags with the same name
1662 # (eg. -use mwg "-creator<creator"), so disable this as of ExifTool 9.36:
1663 # $$opts{Replace} = 0; # accumulate values from tags matching a single argument
1664 1426 ▶ if ($wrn and not $noWarn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrn and not $noWarn) 0 1426 1426
Condition66%2/3
$wrn and not $noWarn
!ll&&!rl&&r
6657610
MC/DC0%0/2
$wrn and not $noWarn
$wrn not $noWarn
Truth table66%2/3
A and not(B)
A= $wrnB= not $noWarn
ABresult
0X0
100
111
1665 # return this warning
1666 0 $rtnInfo{NextFreeTagKey(\%rtnInfo, 'Warning')} = $wrn;
1667 0 $noWarn = 1;
1668 }
1669 1426 delete $$opts{Fixup};
1670 1426 ▶ $rtnInfo{$tag} = $val if $rtn; # tag was set successfully
Branch: 1 branch
BranchTrueFalseTotal
if $rtn 666 760 1426
1671 }
1672 }
1673 44 return \%rtnInfo; # return information that we set
1674 }
1675  
1676 #------------------------------------------------------------------------------
1677 # Get new value(s) for tag
1678 # Inputs: 0) ExifTool object reference, 1) tag name (or tagInfo or nvHash ref, not public)
1679 # 2) optional pointer to return new value hash reference (not part of public API)
1680 # Returns: List of new Raw values (list may be empty if tag is being deleted)
1681 # Notes: 1) Preferentially returns new value from Extra table if writable Extra tag exists
1682 # 2) Must call AFTER IsOverwriting() returns 1 to get proper value for shifted times
1683 # 3) Tag name is case sensitive and may be prefixed by family 0 or 1 group name
1684 # 4) Value may have been modified by CHECK_PROC routine after ValueConv
1685 sub GetNewValue($$;$)
1686 7319 ▶{
Subroutine GetNewValue: called CC=42 SCAR=43.5
Pod documented
1687 7319 local $_;
1688 7319 my $self = shift;
1689 7319 my $tag = shift;
1690 7319 my $nvHash;
1691 7319 ▶ if ((ref $tag eq 'HASH' and $$tag{IsNVH}) or not defined $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag eq 'HASH' and $tag->{'IsNVH'} or not defined $tag) { } 4243 3076 7319
Condition100%6/6
ref $tag eq "HASH" and $tag->{"IsNVH"} or not defined $tag
l!l&&r!l&&!r
4231123076
ref $tag eq "HASH" and $tag->{"IsNVH"}
!ll&&!rl&&r
3036524231
MC/DC100%3/3
ref $tag eq "HASH" and $tag->{"IsNVH"} or not defined $tag
ref $tag eq "HASH" $tag->{"IsNVH"} not defined $tag
Truth table80%4/5
A and B or not(C)
A= ref $tag eq "HASH"B= $tag->{"IsNVH"}C= not defined $tag
ABCresult
11X1
0X11
1011
0X00
1000
1692 4243 $nvHash = $tag;
1693 } else {
1694 3076 my $newValueHashPt = shift;
1695 3076 ▶ if ($$self{NEW_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"NEW_VALUE"}) 2961 115 3076
1696 2961 my ($group, $tagInfo);
1697 2961 ▶ if (ref $tag) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $tag) { } 52 2909 2961
elsif (defined($tagInfo = $Image::ExifTool::Extra{$tag}) and $tagInfo->{'Writable'}) { } 1551 1358 2909
1698 52 $nvHash = $self->GetNewValueHash($tag);
1699 ▶ } elsif (defined($tagInfo = $Image::ExifTool::Extra{$tag}) and
Condition66%2/3
defined($tagInfo = $Image::ExifTool::Extra{$tag}) and $tagInfo->{"Writable"}
!ll&&!rl&&r
135801551
MC/DC50%1/2
defined($tagInfo = $Image::ExifTool::Extra{$tag}) and $tagInfo->{"Writable"}
defined($tagInfo = $Image::ExifTool::Extra{$tag}) $tagInfo->{"Writable"}
Truth table66%2/3
A and B
A= defined($tagInfo = $Image::ExifTool::Extra{$tag})B= $tagInfo->{"Writable"}
ABresult
0X0
100
111
1700 $$tagInfo{Writable})
1701 {
1702 1551 $nvHash = $self->GetNewValueHash($tagInfo);
1703 } else {
1704 # separate group from tag name
1705 1358 my @groups;
1706 1358 ▶ @groups = split ':', $1 if $tag =~ s/(.*)://;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ s/(.*):// 5 1353 1358
1707 1358 my @tagInfoList = FindTagInfo($tag);
1708 # decide which tag we want
1709 1358 GNV_TagInfo: foreach $tagInfo (@tagInfoList) {
1710 1362 ▶ my $nvh = $self->GetNewValueHash($tagInfo) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $nvh = $self->GetNewValueHash($tagInfo) or next 4 1358 1362
1711 # select tag in specified group(s) if necessary
1712 4 foreach (@groups) {
1713 2 ▶ next if $_ eq $$nvh{WriteGroup};
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $nvh->{"WriteGroup"} 0 2 2
1714 2 my @grps = $self->GetGroup($tagInfo);
1715 2 ▶ if ($grps[0] eq $$nvh{WriteGroup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grps[0] eq $nvh->{'WriteGroup'}) { } 0 2 2
1716 # check family 1 group only if WriteGroup is not specific
1717 0 ▶ next if $_ eq $grps[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $grps[1] 0 0 0
1718 } else {
1719 # otherwise check family 0 group
1720 2 ▶ next if $_ eq $grps[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $grps[0] 2 0 2
1721 }
1722 # also check family 7
1723 0 ▶ next if /^ID-(.*)/i and IsSameID($$tagInfo{TagID}, $1);
Branch: 1 branch
BranchTrueFalseTotal
if /^ID-(.*)/i and &IsSameID($tagInfo->{"TagID"}, $1) 0 0 0
Condition0%0/3
/^ID-(.*)/i and &IsSameID($tagInfo->{"TagID"}, $1)
!ll&&!rl&&r
000
MC/DC0%0/2
/^ID-(.*)/i and &IsSameID($tagInfo->{"TagID"}, $1)
/^ID-(.*)/i &IsSameID($tagInfo->{"TagID"}, $1)
Truth table0%0/3
A and B
A= /^ID-(.*)/iB= &IsSameID($tagInfo->{"TagID"}, $1)
ABresult
0X0
100
111
1724 # step to next entry in list
1725 0 ▶ $nvh = $$nvh{Next} or next GNV_TagInfo;
Branch: 1 branch
BranchTrueFalseTotal
$nvh = $nvh->{"Next"} or next GNV_TagInfo 0 0 0
1726 }
1727 4 $nvHash = $nvh;
1728 # give priority to the one we are creating
1729 4 ▶ last if defined $$nvHash{IsCreating};
Branch: 1 branch
BranchTrueFalseTotal
if defined $nvHash->{"IsCreating"} 2 2 4
1730 }
1731 }
1732 }
1733 # return new value hash if requested
1734 3076 ▶ $newValueHashPt and $$newValueHashPt = $nvHash;
Branch: 1 branch
BranchTrueFalseTotal
$newValueHashPt and $$newValueHashPt = $nvHash 2140 936 3076
1735 }
1736 7319 ▶ unless ($nvHash and $$nvHash{Value}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nvHash and $nvHash->{"Value"}) 4962 2357 7319
Condition100%3/3
$nvHash and $nvHash->{"Value"}
!ll&&!rl&&r
299119712357
MC/DC100%2/2
$nvHash and $nvHash->{"Value"}
$nvHash $nvHash->{"Value"}
Truth table100%3/3
A and B
A= $nvHashB= $nvHash->{"Value"}
ABresult
0X0
100
111
1737 4962 ▶ return () if wantarray; # return empty list
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1940 3022 4962
1738 3022 return undef;
1739 }
1740 2357 my $vals = $$nvHash{Value};
1741 # do inverse raw conversion if necessary
1742 # - must also check after doing a Shift
1743 2357 ▶ if ($$nvHash{TagInfo}{RawConvInv} or $$nvHash{Shift}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash->{"TagInfo"}{"RawConvInv"} or $nvHash->{"Shift"}) 60 2297 2357
Condition100%3/3
$nvHash->{"TagInfo"}{"RawConvInv"} or $nvHash->{"Shift"}
l!l&&r!l&&!r
34262297
MC/DC100%2/2
$nvHash->{"TagInfo"}{"RawConvInv"} or $nvHash->{"Shift"}
$nvHash->{"TagInfo"}{"RawConvInv"} $nvHash->{"Shift"}
Truth table100%3/3
A or B
A= $nvHash->{"TagInfo"}{"RawConvInv"}B= $nvHash->{"Shift"}
ABresult
1X1
011
000
1744 60 my @copyVals = @$vals; # modify a copy of the values
1745 60 $vals = \@copyVals;
1746 60 my $tagInfo = $$nvHash{TagInfo};
1747 60 my $conv = $$tagInfo{RawConvInv};
1748 60 my $table = $$tagInfo{Table};
1749 60 my ($val, $checkProc);
1750 60 ▶ $checkProc = $$table{CHECK_PROC} if $$nvHash{Shift} and $table;
Branch: 1 branch
BranchTrueFalseTotal
if $nvHash->{"Shift"} and $table 26 34 60
Condition66%2/3
$nvHash->{"Shift"} and $table
!ll&&!rl&&r
34026
MC/DC50%1/2
$nvHash->{"Shift"} and $table
$nvHash->{"Shift"} $table
Truth table66%2/3
A and B
A= $nvHash->{"Shift"}B= $table
ABresult
0X0
100
111
1751 60 local $SIG{'__WARN__'} = \&SetWarning;
1752 60 undef $evalWarning;
1753 60 foreach $val (@$vals) {
1754 # must check value now if it was shifted
1755 60 ▶ if ($checkProc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($checkProc) { } 26 34 60
1756 26 my $err = &$checkProc($self, $tagInfo, \$val);
1757 26 ▶ if ($err or not defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err or not defined $val) 0 26 26
Condition33%1/3
$err or not defined $val
l!l&&r!l&&!r
0026
MC/DC0%0/2
$err or not defined $val
$err not defined $val
Truth table33%1/3
A or not(B)
A= $errB= not defined $val
ABresult
1X1
011
000
1758 0 ▶ $err or $err = 'Error generating raw value';
Branch: 1 branch
BranchTrueFalseTotal
$err or $err = "Error generating raw value" 0 0 0
1759 0 $self->Warn("$err for $$tagInfo{Name}");
1760 0 @$vals = ();
1761 0 last;
1762 }
1763 26 ▶ next unless $conv;
Branch: 1 branch
BranchTrueFalseTotal
unless $conv 26 0 26
1764 } else {
1765 34 ▶ last unless $conv;
Branch: 1 branch
BranchTrueFalseTotal
unless $conv 0 34 34
1766 }
1767 # do inverse raw conversion
1768 34 ▶ if (ref($conv) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $conv eq 'CODE') { } 2 32 34
1769 2 $val = &$conv($val, $self);
1770 } else {
1771 #### eval RawConvInv ($self, $val, $tagInfo)
1772 32 $val = eval $conv;
1773 32 ▶ $@ and $evalWarning = $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and $Image::ExifTool::evalWarning = $@ 0 32 32
1774 }
1775 34 ▶ if ($evalWarning) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::evalWarning) 0 34 34
1776 # an empty warning ("\n") ignores tag with no error
1777 0 ▶ if ($evalWarning ne "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::evalWarning ne "\n") 0 0 0
1778 0 my $err = CleanWarning() . " in $$tagInfo{Name} (RawConvInv)";
1779 0 $self->Warn($err);
1780 }
1781 0 @$vals = ();
1782 0 last;
1783 }
1784 }
1785 }
1786 # return our value(s)
1787 2357 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 1168 1189 2357
1788 # remove duplicates if requested
1789 1168 ▶ if (@$vals > 1 and $self->Options('NoDups')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$vals > 1 and $self->Options("NoDups")) 0 1168 1168
Condition66%2/3
@$vals > 1 and $self->Options("NoDups")
!ll&&!rl&&r
1086820
MC/DC0%0/2
@$vals > 1 and $self->Options("NoDups")
@$vals > 1 $self->Options("NoDups")
Truth table66%2/3
A and B
A= @$vals > 1B= $self->Options("NoDups")
ABresult
0X0
100
111
1790 0 my %seen;
1791 0 @$vals = grep { !$seen{$_}++ } @$vals;
1792 }
1793 1168 return @$vals;
1794 }
1795 1189 return $$vals[0];
1796 }
1797  
1798 #------------------------------------------------------------------------------
1799 # Return the total number of new values set
1800 # Inputs: 0) ExifTool object reference
1801 # Returns: Scalar context) Number of new values that have been set (incl pseudo)
1802 # List context) Number of new values (incl pseudo), number of "pseudo" values
1803 # ("pseudo" values are those which don't require rewriting the file to change)
1804 sub CountNewValues($)
1805 245 ▶{
Subroutine CountNewValues: called CC=6 SCAR=17.9
Pod documented
1806 245 my $self = shift;
1807 245 my $newVal = $$self{NEW_VALUE};
1808 245 my ($num, $pseudo) = (0, 0);
1809 245 ▶ if ($newVal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newVal) 226 19 245
1810 226 $num = scalar keys %$newVal;
1811 226 my $nv;
1812 226 foreach $nv (values %$newVal) {
1813 19807 my $tagInfo = $$nv{TagInfo};
1814 # don't count tags that don't write anything
1815 19807 ▶ $$tagInfo{WriteNothing} and --$num, next;
Branch: 1 branch
BranchTrueFalseTotal
$tagInfo->{"WriteNothing"} and --$num, next 19 19788 19807
1816 # count the number of pseudo tags included
1817 19788 ▶ $$tagInfo{WritePseudo} and ++$pseudo;
Branch: 1 branch
BranchTrueFalseTotal
$tagInfo->{"WritePseudo"} and ++$pseudo 1 19787 19788
1818 }
1819 }
1820 245 $num += scalar keys %{$$self{DEL_GROUP}};
1821 245 ▶ return $num unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 245 245
1822 245 return ($num, $pseudo);
1823 }
1824  
1825 #------------------------------------------------------------------------------
1826 # Save new values for subsequent restore
1827 # Inputs: 0) ExifTool object reference
1828 # Returns: Number of times new values have been saved
1829 # Notes: increments SAVE_COUNT flag each time routine is called
1830 sub SaveNewValues($)
1831 1 ▶{
Subroutine SaveNewValues: called CC=4 SCAR=13.9
Pod documented
1832 1 my $self = shift;
1833 1 my $newValues = $$self{NEW_VALUE};
1834 1 my $saveCount = ++$$self{SAVE_COUNT};
1835 1 my $key;
1836 1 foreach $key (keys %$newValues) {
1837 114 my $nvHash = $$newValues{$key};
1838 114 ▶ while ($nvHash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash) 116 114 230
1839 # set Save count if not done already
1840 116 ▶ $$nvHash{Save} or $$nvHash{Save} = $saveCount;
Branch: 1 branch
BranchTrueFalseTotal
$nvHash->{"Save"} or $nvHash->{"Save"} = $saveCount 0 116 116
1841 116 $nvHash = $$nvHash{Next};
1842 }
1843 }
1844 # initialize hash for saving overwritten new values
1845 1 $$self{SAVE_NEW_VALUE} = { };
1846 # make a copy of the delete group hash
1847 1 my %delGrp = %{$$self{DEL_GROUP}};
1848 1 $$self{SAVE_DEL_GROUP} = \%delGrp;
1849 1 return $saveCount;
1850 }
1851  
1852 #------------------------------------------------------------------------------
1853 # Restore new values to last saved state
1854 # Inputs: 0) ExifTool object reference
1855 # Notes: Restores saved new values, but currently doesn't restore them in the
1856 # original order, so there may be some minor side-effects when restoring tags
1857 # with overlapping groups. eg) XMP:Identifier, XMP-dc:Identifier
1858 # Also, this doesn't do the right thing for list-type tags which accumulate
1859 # values across a save point
1860 sub RestoreNewValues($)
1861 1 ▶{
Subroutine RestoreNewValues: called CC=11 SCAR=24.1
Pod documented
1862 1 my $self = shift;
1863 1 my $newValues = $$self{NEW_VALUE};
1864 1 my $savedValues = $$self{SAVE_NEW_VALUE};
1865 1 my $key;
1866 # 1) remove any new values which don't have the Save flag set
1867 1 ▶ if ($newValues) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newValues) 1 0 1
1868 1 my @keys = keys %$newValues;
1869 1 foreach $key (@keys) {
1870 579 my $lastHash;
1871 579 my $nvHash = $$newValues{$key};
1872 579 ▶ while ($nvHash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash) 581 579 1160
1873 581 ▶ if ($$nvHash{Save}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash->{'Save'}) { } 27 554 581
1874 27 $lastHash = $nvHash;
1875 } else {
1876 # remove this entry from the list
1877 554 ▶ if ($lastHash) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lastHash) { } 0 554 554
elsif ($nvHash->{'Next'}) { } 2 552 554
1878 0 $$lastHash{Next} = $$nvHash{Next};
1879 } elsif ($$nvHash{Next}) {
1880 2 $$newValues{$key} = $$nvHash{Next};
1881 } else {
1882 552 delete $$newValues{$key};
1883 }
1884 }
1885 581 $nvHash = $$nvHash{Next};
1886 }
1887 }
1888 }
1889 # 2) restore saved new values
1890 1 ▶ if ($savedValues) {
Branch: 1 branch
BranchTrueFalseTotal
if ($savedValues) 1 0 1
1891 1 ▶ $newValues or $newValues = $$self{NEW_VALUE} = { };
Branch: 1 branch
BranchTrueFalseTotal
$newValues or $newValues = ($self->{"NEW_VALUE"} = {}) 1 0 1
1892 1 foreach $key (keys %$savedValues) {
1893 89 ▶ if ($$newValues{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newValues->{$key}) { } 2 87 89
1894 # add saved values to end of list
1895 2 my $nvHash = LastInList($$newValues{$key});
1896 2 $$nvHash{Next} = $$savedValues{$key};
1897 } else {
1898 87 $$newValues{$key} = $$savedValues{$key};
1899 }
1900 }
1901 1 $$self{SAVE_NEW_VALUE} = { }; # reset saved new values
1902 }
1903 # 3) restore delete groups
1904 1 my %delGrp = %{$$self{SAVE_DEL_GROUP}};
1905 1 $$self{DEL_GROUP} = \%delGrp;
1906 }
1907  
1908 #------------------------------------------------------------------------------
1909 # Set alternate file for extracting information
1910 # Inputs: 0) ExifTool ref, 1) family 8 group name (of the form "File#" where # is any number)
1911 # 2) alternate file name (may contain tag names with leading "$"), or undef to reset
1912 # Returns: 1 on success, or 0 on invalid group name
1913 sub SetAlternateFile($$$)
1914 6 ▶{
Subroutine SetAlternateFile: called CC=6 SCAR=20.8
Pod documented
1915 6 my ($self, $g8, $file) = @_;
1916 6 $g8 = ucfirst lc $g8;
1917 6 ▶ return 0 unless $g8 =~ /^File\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $g8 =~ /^File\d+$/ 0 6 6
1918 # keep the same file if already initialized (possibly has metadata extracted)
1919 6 ▶ if (not defined $file) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $file) { } 0 6 6
elsif (not $self->{'ALT_EXIFTOOL'}{$g8} && !($file =~ /\$/) && $self->{'ALT_EXIFTOOL'}{$g8}{'ALT_FILE'} eq $file) { } 6 0 6
1920 0 delete $$self{ALT_EXIFTOOL}{$g8};
1921 ▶ } elsif (not ($$self{ALT_EXIFTOOL}{$g8} and $file !~ /\$/ and
Condition33%2/6
$self->{'ALT_EXIFTOOL'}{$g8} && !($file =~ /\$/) && $self->{'ALT_EXIFTOOL'}{$g8}{'ALT_FILE'} eq $file
!ll&&!rl&&r
600
$self->{"ALT_EXIFTOOL"}{$g8} and not $file =~ /\$/
!ll&&!rl&&r
600
MC/DC0%0/3
$self->{'ALT_EXIFTOOL'}{$g8} && !($file =~ /\$/) && $self->{'ALT_EXIFTOOL'}{$g8}{'ALT_FILE'} eq $file
$self->{"ALT_EXIFTOOL"}{$g8} not $file =~ /\$/ $self->{'ALT_EXIFTOOL'}{$g8}{'ALT_FILE'} eq $file
Truth table25%1/4
A and not(B) && C
A= $self->{"ALT_EXIFTOOL"}{$g8}B= not $file =~ /\$/C= $self->{'ALT_EXIFTOOL'}{$g8}{'ALT_FILE'} eq $file
ABCresult
0XX0
10X0
1100
1111
1922 $$self{ALT_EXIFTOOL}{$g8}{ALT_FILE} eq $file))
1923 {
1924 6 my $altExifTool = Image::ExifTool->new;
1925 6 $$altExifTool{ALT_FILE} = $file;
1926 6 $$self{ALT_EXIFTOOL}{$g8} = $altExifTool;
1927 }
1928 6 return 1;
1929 }
1930  
1931 #------------------------------------------------------------------------------
1932 # Set filesystem time from from FileModifyDate or FileCreateDate tag
1933 # Inputs: 0) ExifTool object reference, 1) file name or file ref
1934 # 2) time (-M or -C) of original file (used for shift; obtained from file if not given)
1935 # 3) tag name to write (undef for 'FileModifyDate')
1936 # 4) flag set if argument 2 has already been converted to Unix seconds
1937 # Returns: 1=time changed OK, 0=nothing done, -1=error setting time
1938 # (increments CHANGED flag and sets corresponding WRITTEN tag)
1939 sub SetFileModifyDate($$;$$$)
1940 0 ▶{
Subroutine SetFileModifyDate: not called CC=16 SCAR=56.1
Pod documented
1941 0 my ($self, $file, $originalTime, $tag, $isUnixTime) = @_;
1942 0 my $nvHash;
1943 0 ▶ $tag = 'FileModifyDate' unless defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag 0 0 0
1944 0 my $val = $self->GetNewValue($tag, \$nvHash);
1945 0 ▶ return 0 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
1946 0 my $isOverwriting = $self->IsOverwriting($nvHash);
1947 0 ▶ return 0 unless $isOverwriting;
Branch: 1 branch
BranchTrueFalseTotal
unless $isOverwriting 0 0 0
1948 # can currently only set creation date on Windows systems
1949 # (and Mac now too, but that is handled with the MacOS tags)
1950 0 ▶ return 0 if $tag eq 'FileCreateDate' and $^O ne 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "FileCreateDate" and $^O ne "MSWin32" 0 0 0
Condition0%0/3
$tag eq "FileCreateDate" and $^O ne "MSWin32"
!ll&&!rl&&r
000
MC/DC0%0/2
$tag eq "FileCreateDate" and $^O ne "MSWin32"
$tag eq "FileCreateDate" $^O ne "MSWin32"
Truth table0%0/3
A and B
A= $tag eq "FileCreateDate"B= $^O ne "MSWin32"
ABresult
0X0
100
111
1951 0 ▶ if ($isOverwriting < 0) { # are we shifting time?
Branch: 1 branch
BranchTrueFalseTotal
if ($isOverwriting < 0) 0 0 0
1952 # use original time of this file if not specified
1953 0 ▶ unless (defined $originalTime) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $originalTime) 0 0 0
1954 0 my ($aTime, $mTime, $cTime) = $self->GetFileTime($file);
1955 0 ▶ $originalTime = ($tag eq 'FileCreateDate') ? $cTime : $mTime;
Branch: 1 branch
BranchTrueFalseTotal
$tag eq 'FileCreateDate' ? : 0 0 0
1956 0 ▶ return 0 unless defined $originalTime;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $originalTime 0 0 0
1957 0 $isUnixTime = 1;
1958 }
1959 0 ▶ $originalTime = int($^T - $originalTime*(24*3600) + 0.5) unless $isUnixTime;
Branch: 1 branch
BranchTrueFalseTotal
unless $isUnixTime 0 0 0
1960 0 ▶ return 0 unless $self->IsOverwriting($nvHash, $originalTime);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->IsOverwriting($nvHash, $originalTime) 0 0 0
1961 0 $val = $$nvHash{Value}[0]; # get shifted value
1962 }
1963 0 my ($aTime, $mTime, $cTime);
1964 0 ▶ if ($tag eq 'FileCreateDate') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'FileCreateDate') { } 0 0 0
1965 0 ▶ eval { require Win32::API } or $self->Warn("Install Win32::API to set $tag"), return -1;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Win32::API } } or $self->Warn("Install Win32::API to set $tag"), (return -1) 0 0 0
1966 0 ▶ eval { require Win32API::File } or $self->Warn("Install Win32API::File to set $tag"), return -1;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Win32API::File } } or $self->Warn("Install Win32API::File to set $tag"), (return -1) 0 0 0
1967 0 $cTime = $val;
1968 } else {
1969 0 $aTime = $mTime = $val;
1970 }
1971 0 ▶ $self->SetFileTime($file, $aTime, $mTime, $cTime, 1) or $self->Warn("Error setting $tag"), return -1;
Branch: 1 branch
BranchTrueFalseTotal
$self->SetFileTime($file, $aTime, $mTime, $cTime, 1) or $self->Warn("Error setting $tag"), (return -1) 0 0 0
1972 0 ++$$self{CHANGED};
1973 0 $$self{WRITTEN}{$tag} = $val; # remember that we wrote this tag
1974 0 $self->VerboseValue("+ $tag", $val);
1975 0 return 1;
1976 }
1977  
1978 #------------------------------------------------------------------------------
1979 # Change file name and/or directory from FileName and Directory tags
1980 # Inputs: 0) ExifTool object reference, 1) current file name (including path)
1981 # 2) new name (or undef to build from FileName and Directory tags)
1982 # 3) option: 'HardLink'/'SymLink' to create hard/symbolic link instead of renaming
1983 # 'Test' to only print new file name
1984 # 4) 0 to indicate that a file will no longer exist (used for 'Test' only)
1985 # Returns: 1=name changed OK, 0=nothing changed, -1=error changing name
1986 # (and increments CHANGED flag if filename changed)
1987 # Notes: Will not overwrite existing file. Creates directories as necessary.
1988 sub SetFileName($$;$$$)
1989 1 ▶{
Subroutine SetFileName: called CC=59 SCAR=75.3
Pod documented
1990 1 my ($self, $file, $newName, $opt, $usedFlag) = @_;
1991 1 my ($nvHash, $doName, $doDir);
1992  
1993 1 ▶ $opt or $opt = '';
Branch: 1 branch
BranchTrueFalseTotal
$opt or $opt = "" 0 1 1
1994 # determine the new file name
1995 1 ▶ unless (defined $newName) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $newName) 1 0 1
1996 1 ▶ if ($opt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt) { } 0 1 1
1997 0 ▶ if ($opt eq 'HardLink' or $opt eq 'Link') {
Branch: 3 branches
BranchTrueFalseTotal
if ($opt eq 'HardLink' or $opt eq 'Link') { } 0 0 0
elsif ($opt eq 'SymLink') { } 0 0 0
elsif ($opt eq 'Test') { } 0 0 0
Condition0%0/3
$opt eq "HardLink" or $opt eq "Link"
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt eq "HardLink" or $opt eq "Link"
$opt eq "HardLink" $opt eq "Link"
Truth table0%0/3
A or B
A= $opt eq "HardLink"B= $opt eq "Link"
ABresult
1X1
011
000
1998 0 $newName = $self->GetNewValue('HardLink');
1999 } elsif ($opt eq 'SymLink') {
2000 0 $newName = $self->GetNewValue('SymLink');
2001 } elsif ($opt eq 'Test') {
2002 0 $newName = $self->GetNewValue('TestName');
2003 }
2004 0 ▶ return 0 unless defined $newName;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newName 0 0 0
2005 } else {
2006 1 my $filename = $self->GetNewValue('FileName', \$nvHash);
2007 1 ▶ $doName = 1 if defined $filename and $self->IsOverwriting($nvHash, $file);
Branch: 1 branch
BranchTrueFalseTotal
if defined $filename and $self->IsOverwriting($nvHash, $file) 1 0 1
Condition33%1/3
defined $filename and $self->IsOverwriting($nvHash, $file)
!ll&&!rl&&r
001
MC/DC0%0/2
defined $filename and $self->IsOverwriting($nvHash, $file)
defined $filename $self->IsOverwriting($nvHash, $file)
Truth table33%1/3
A and B
A= defined $filenameB= $self->IsOverwriting($nvHash, $file)
ABresult
0X0
100
111
2008 1 my $dir = $self->GetNewValue('Directory', \$nvHash);
2009 1 ▶ $doDir = 1 if defined $dir and $self->IsOverwriting($nvHash, $file);
Branch: 1 branch
BranchTrueFalseTotal
if defined $dir and $self->IsOverwriting($nvHash, $file) 0 1 1
Condition33%1/3
defined $dir and $self->IsOverwriting($nvHash, $file)
!ll&&!rl&&r
100
MC/DC0%0/2
defined $dir and $self->IsOverwriting($nvHash, $file)
defined $dir $self->IsOverwriting($nvHash, $file)
Truth table33%1/3
A and B
A= defined $dirB= $self->IsOverwriting($nvHash, $file)
ABresult
0X0
100
111
2010 1 ▶ return 0 unless $doName or $doDir; # nothing to do
Branch: 1 branch
BranchTrueFalseTotal
unless $doName or $doDir 0 1 1
Condition33%1/3
$doName or $doDir
l!l&&r!l&&!r
100
MC/DC0%0/2
$doName or $doDir
$doName $doDir
Truth table33%1/3
A or B
A= $doNameB= $doDir
ABresult
1X1
011
000
2011 1 ▶ if ($doName) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doName) { } 1 0 1
2012 1 $newName = GetNewFileName($file, $filename);
2013 1 ▶ $newName = GetNewFileName($newName, $dir) if $doDir;
Branch: 1 branch
BranchTrueFalseTotal
if $doDir 0 1 1
2014 } else {
2015 0 $newName = GetNewFileName($file, $dir);
2016 }
2017 }
2018 }
2019 # validate new file name in Windows
2020 1 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 1 1
2021 0 ▶ if ($newName =~ /[\0-\x1f<>"|*]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newName =~ /[\0-\x1f<>"|*]/) 0 0 0
2022 0 $self->Warn('New file name not allowed in Windows (contains reserved characters)');
2023 0 return -1;
2024 }
2025 0 ▶ if ($newName =~ /:/ and $newName !~ /^[A-Z]:[^:]*$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newName =~ /:/ and not $newName =~ /^[A-Z]:[^:]*$/i) 0 0 0
Condition0%0/3
$newName =~ /:/ and not $newName =~ /^[A-Z]:[^:]*$/i
!ll&&!rl&&r
000
MC/DC0%0/2
$newName =~ /:/ and not $newName =~ /^[A-Z]:[^:]*$/i
$newName =~ /:/ not $newName =~ /^[A-Z]:[^:]*$/i
Truth table0%0/3
A and not(B)
A= $newName =~ /:/B= not $newName =~ /^[A-Z]:[^:]*$/i
ABresult
0X0
100
111
2026 0 $self->Warn("New file name not allowed in Windows (contains ':')");
2027 0 return -1;
2028 }
2029 0 ▶ if ($newName =~ /\?/ and $newName !~ m{^[\\/]{2}\?[\\/][^?]*$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newName =~ /\?/ and not $newName =~ m[^[\\/]{2}\?[\\/][^?]*$]) 0 0 0
Condition0%0/3
$newName =~ /\?/ and not $newName =~ m[^[\\/]{2}\?[\\/][^?]*$]
!ll&&!rl&&r
000
MC/DC0%0/2
$newName =~ /\?/ and not $newName =~ m[^[\\/]{2}\?[\\/][^?]*$]
$newName =~ /\?/ not $newName =~ m[^[\\/]{2}\?[\\/][^?]*$]
Truth table0%0/3
A and not(B)
A= $newName =~ /\?/B= not $newName =~ m[^[\\/]{2}\?[\\/][^?]*$]
ABresult
0X0
100
111
2030 0 $self->Warn("New file name not allowed in Windows (contains '?')");
2031 0 return -1;
2032 }
2033 0 ▶ if ($newName =~ m{(^|[\\/])(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.[^.]*)?$}i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newName =~ m[(^|[\\/])(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.[^.]*)?$]i) 0 0 0
2034 0 $self->Warn('New file name not allowed in Windows (reserved device name)');
2035 0 return -1;
2036 }
2037 0 ▶ if ($newName =~ /([. ])$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newName =~ /([. ])$/) 0 0 0
2038 0 ▶ $self->Warn("New file name not recommended for Windows (ends with '${1}')", 2) and return -1;
Branch: 1 branch
BranchTrueFalseTotal
$self->Warn("New file name not recommended for Windows (ends with '$1')", 2) and return -1 0 0 0
2039 }
2040 0 ▶ if (length $newName > 259 and $newName !~ /\?/) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $newName > 259 and not $newName =~ /\?/) 0 0 0
Condition0%0/3
length $newName > 259 and not $newName =~ /\?/
!ll&&!rl&&r
000
MC/DC0%0/2
length $newName > 259 and not $newName =~ /\?/
length $newName > 259 not $newName =~ /\?/
Truth table0%0/3
A and not(B)
A= length $newName > 259B= not $newName =~ /\?/
ABresult
0X0
100
111
2041 0 ▶ $self->Warn('New file name not recommended for Windows (exceeds 260 chars)', 2) and return -1;
Branch: 1 branch
BranchTrueFalseTotal
$self->Warn("New file name not recommended for Windows (exceeds 260 chars)", 2) and return -1 0 0 0
2042 }
2043 } else {
2044 1 $newName =~ tr/\0//d; # make sure name doesn't contain nulls
2045 }
2046 # protect against empty file name
2047 1 ▶ length $newName or $self->Warn('New file name is empty'), return -1;
Branch: 1 branch
BranchTrueFalseTotal
length $newName or $self->Warn("New file name is empty"), (return -1) 1 0 1
2048 # don't replace existing file
2049 1 ▶ if ($self->Exists($newName, 1) and (not defined $usedFlag or $usedFlag)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Exists($newName, 1) and !defined($usedFlag) || $usedFlag) 0 1 1
Condition16%1/6
$self->Exists($newName, 1) and !defined($usedFlag) || $usedFlag
!ll&&!rl&&r
100
not defined $usedFlag or $usedFlag
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->Exists($newName, 1) and !defined($usedFlag) || $usedFlag
$self->Exists($newName, 1) not defined $usedFlag $usedFlag
Truth table25%1/4
A and not(B) or C
A= $self->Exists($newName, 1)B= not defined $usedFlagC= $usedFlag
ABCresult
0XX0
1000
11X1
1011
2050 0 ▶ if ($file ne $newName or $opt =~ /Link$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file ne $newName or $opt =~ /Link$/) { } 0 0 0
Condition0%0/3
$file ne $newName or $opt =~ /Link$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$file ne $newName or $opt =~ /Link$/
$file ne $newName $opt =~ /Link$/
Truth table0%0/3
A or B
A= $file ne $newNameB= $opt =~ /Link$/
ABresult
1X1
011
000
2051 # allow for case-insensitive filesystem
2052 0 ▶ if ($opt =~ /Link$/ or not $self->IsSameFile($file, $newName)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt =~ /Link$/ or not $self->IsSameFile($file, $newName)) 0 0 0
Condition0%0/3
$opt =~ /Link$/ or not $self->IsSameFile($file, $newName)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt =~ /Link$/ or not $self->IsSameFile($file, $newName)
$opt =~ /Link$/ not $self->IsSameFile($file, $newName)
Truth table0%0/3
A or not(B)
A= $opt =~ /Link$/B= not $self->IsSameFile($file, $newName)
ABresult
1X1
011
000
2053 0 $self->Warn("File '${newName}' already exists");
2054 0 return -1;
2055 }
2056 } else {
2057 0 $self->Warn('File name is unchanged');
2058 0 return 0;
2059 }
2060 }
2061 1 ▶ if ($opt eq 'Test') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt eq "Test") 0 1 1
2062 0 my $out = $$self{OPTIONS}{TextOut};
2063 0 print $out "'${file}' --> '${newName}'\n";
2064 0 return 1;
2065 }
2066 # create directory for new file if necessary
2067 1 my $err = $self->CreateDirectory($newName);
2068 1 ▶ if (defined $err) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 0 1 1
2069 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
2070 0 ▶ $self->Warn($err) unless $err =~ /^Error creating/;
Branch: 1 branch
BranchTrueFalseTotal
unless $err =~ /^Error creating/ 0 0 0
2071 0 $self->Warn("Error creating directory for '${newName}'");
2072 0 return -1;
2073 }
2074 0 $self->VPrint(0, "Created directory for '${newName}'\n");
2075 }
2076 1 ▶ if ($opt eq 'HardLink' or $opt eq 'Link') {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt eq 'HardLink' or $opt eq 'Link') { } 0 1 1
elsif ($opt eq 'SymLink') { } 0 1 1
Condition33%1/3
$opt eq "HardLink" or $opt eq "Link"
l!l&&r!l&&!r
001
MC/DC0%0/2
$opt eq "HardLink" or $opt eq "Link"
$opt eq "HardLink" $opt eq "Link"
Truth table33%1/3
A or B
A= $opt eq "HardLink"B= $opt eq "Link"
ABresult
1X1
011
000
2077 0 ▶ unless (link $file, $newName) {
Branch: 1 branch
BranchTrueFalseTotal
unless (link $file, $newName) 0 0 0
2078 0 $self->Warn("Error creating hard link '${newName}'");
2079 0 return -1;
2080 }
2081 0 ++$$self{CHANGED};
2082 0 $self->VerboseValue('+ HardLink', $newName);
2083 0 return 1;
2084 } elsif ($opt eq 'SymLink') {
2085 0 ▶ $^O eq 'MSWin32' and $self->Warn('SymLink not supported in Windows'), return -1;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq "MSWin32" and $self->Warn("SymLink not supported in Windows"), (return -1) 0 0 0
2086 0 $newName =~ s(^\./)(); # remove leading "./" from link name if it exists
2087 # path to linked file must be relative to the $newName directory, but $file
2088 # is relative to the current directory, so convert it to an absolute path
2089 # if using a relative directory and $newName isn't in the current directory
2090 0 ▶ if ($file !~ m(^/) and $newName =~ m(/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $file =~ m[^/] and $newName =~ m[/]) 0 0 0
Condition0%0/3
not $file =~ m[^/] and $newName =~ m[/]
!ll&&!rl&&r
000
MC/DC0%0/2
not $file =~ m[^/] and $newName =~ m[/]
not $file =~ m[^/] $newName =~ m[/]
Truth table0%0/3
not(A) and B
A= not $file =~ m[^/]B= $newName =~ m[/]
ABresult
0X0
100
111
2091 0 ▶ unless (eval { require Cwd }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Cwd } }) 0 0 0
2092 0 $self->Warn('Install Cwd to make symlinks to other directories');
2093 0 return -1;
2094 }
2095 0 $file = eval { Cwd::abs_path($file) };
2096 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
2097 0 $self->Warn('Error in Cwd::abs_path when creating symlink');
2098 0 return -1;
2099 }
2100 }
2101 0 ▶ unless (eval { symlink $file, $newName } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { symlink $file, $newName } }) 0 0 0
2102 0 $self->Warn("Error creating symbolic link '${newName}'");
2103 0 return -1;
2104 }
2105 0 ++$$self{CHANGED};
2106 0 $self->VerboseValue('+ SymLink', $newName);
2107 0 return 1;
2108 }
2109 # attempt to rename the file
2110 1 ▶ unless ($self->Rename($file, $newName)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->Rename($file, $newName)) 0 1 1
2111 0 local (*EXIFTOOL_SFN_IN, *EXIFTOOL_SFN_OUT);
2112 # renaming didn't work, so copy the file instead
2113 0 ▶ unless ($self->Open(\*EXIFTOOL_SFN_IN, $file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->Open(\*EXIFTOOL_SFN_IN, $file)) 0 0 0
2114 0 $self->Error("Error opening '${file}'");
2115 0 return -1;
2116 }
2117 0 ▶ unless ($self->Open(\*EXIFTOOL_SFN_OUT, $newName, '>')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->Open(\*EXIFTOOL_SFN_OUT, $newName, ">")) 0 0 0
2118 0 close EXIFTOOL_SFN_IN;
2119 0 $self->Error("Error creating '${newName}'");
2120 0 return -1;
2121 }
2122 0 binmode EXIFTOOL_SFN_IN;
2123 0 binmode EXIFTOOL_SFN_OUT;
2124 0 my ($buff, $err);
2125 0 ▶ while (read EXIFTOOL_SFN_IN, $buff, 65536) {
Branch: 1 branch
BranchTrueFalseTotal
if (read EXIFTOOL_SFN_IN, $buff, 65536) 0 0 0
2126 0 ▶ print EXIFTOOL_SFN_OUT $buff or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
print EXIFTOOL_SFN_OUT $buff or $err = 1 0 0 0
2127 }
2128 0 ▶ close EXIFTOOL_SFN_OUT or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
close EXIFTOOL_SFN_OUT or $err = 1 0 0 0
2129 0 close EXIFTOOL_SFN_IN;
2130 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
2131 0 $self->Unlink($newName); # erase bad output file
2132 0 $self->Error("Error writing '${newName}'");
2133 0 return -1;
2134 }
2135 # preserve modification time
2136 0 my ($aTime, $mTime, $cTime) = $self->GetFileTime($file);
2137 0 $self->SetFileTime($newName, $aTime, $mTime, $cTime);
2138 # remove the original file
2139 0 ▶ $self->Unlink($file) or $self->Warn('Error removing old file');
Branch: 1 branch
BranchTrueFalseTotal
$self->Unlink($file) or $self->Warn("Error removing old file") 0 0 0
2140 }
2141 1 $$self{NewName} = $newName; # remember new file name
2142 1 ++$$self{CHANGED};
2143 1 $self->VerboseValue('+ FileName', $newName);
2144 1 return 1;
2145 }
2146  
2147 #------------------------------------------------------------------------------
2148 # Set file permissions, group/user id and various MDItem tags from new tag values
2149 # Inputs: 0) ExifTool ref, 1) file name or glob (must be a name for MDItem tags)
2150 # Returns: 1=something was set OK, 0=didn't try, -1=error (and warning set)
2151 # Notes: There may be errors even if 1 is returned
2152 sub SetSystemTags($$)
2153 232 ▶{
Subroutine SetSystemTags: called CC=32 SCAR=64.7
Pod undocumented
2154 232 my ($self, $file) = @_;
2155 232 my $result = 0;
2156  
2157 232 my $perm = $self->GetNewValue('FilePermissions');
2158 232 ▶ if (defined $perm) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $perm) 0 232 232
2159 0 ▶ if (eval { chmod($perm & 07777, $file) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { chmod $perm & 4095, $file } }) { } 0 0 0
2160 0 $self->VerboseValue('+ FilePermissions', $perm);
2161 0 $result = 1;
2162 } else {
2163 0 $self->Warn('Error setting FilePermissions');
2164 0 $result = -1;
2165 }
2166 }
2167 232 my $uid = $self->GetNewValue('FileUserID');
2168 232 my $gid = $self->GetNewValue('FileGroupID');
2169 232 ▶ if (defined $uid or defined $gid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uid or defined $gid) 0 232 232
Condition33%1/3
defined $uid or defined $gid
l!l&&r!l&&!r
00232
MC/DC0%0/2
defined $uid or defined $gid
defined $uid defined $gid
Truth table33%1/3
A or B
A= defined $uidB= defined $gid
ABresult
1X1
011
000
2170 0 ▶ defined $uid or $uid = -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $uid or $uid = -1 0 0 0
2171 0 ▶ defined $gid or $gid = -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $gid or $gid = -1 0 0 0
2172 0 ▶ if (eval { chown($uid, $gid, $file) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { chown $uid, $gid, $file } }) { } 0 0 0
2173 0 ▶ $self->VerboseValue('+ FileUserID', $uid) if $uid >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $uid >= 0 0 0 0
2174 0 ▶ $self->VerboseValue('+ FileGroupID', $gid) if $gid >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $gid >= 0 0 0 0
2175 0 $result = 1;
2176 } else {
2177 0 $self->Warn('Error setting FileGroup/UserID');
2178 0 ▶ $result = -1 unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
2179 }
2180 }
2181 232 my $tag;
2182 232 foreach $tag (@writableMacOSTags) {
2183 1624 my $nvHash;
2184 1624 my $val = $self->GetNewValue($tag, \$nvHash);
2185 1624 ▶ next unless $nvHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash 1624 0 1624
2186 0 ▶ if ($^O eq 'darwin') {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O eq 'darwin') { } 0 0 0
elsif ($tag ne 'FileCreateDate') { } 0 0 0
2187 0 ▶ ref $file and $self->Warn('Setting MDItem tags requires a file name'), last;
Branch: 1 branch
BranchTrueFalseTotal
ref $file and $self->Warn("Setting MDItem tags requires a file name"), last 0 0 0
2188 0 require Image::ExifTool::MacOS;
2189 0 my $res = Image::ExifTool::MacOS::SetMacOSTags($self, $file, \@writableMacOSTags);
2190 0 ▶ $result = $res if $res == 1 or not $result;
Branch: 1 branch
BranchTrueFalseTotal
if $res == 1 or not $result 0 0 0
Condition0%0/3
$res == 1 or not $result
l!l&&r!l&&!r
000
MC/DC0%0/2
$res == 1 or not $result
$res == 1 not $result
Truth table0%0/3
A or not(B)
A= $res == 1B= not $result
ABresult
1X1
011
000
2191 0 last;
2192 } elsif ($tag ne 'FileCreateDate') {
2193 0 $self->Warn('Can only set MDItem tags on MacOS');
2194 0 last;
2195 }
2196 }
2197 # delete Windows Zone.Identifier if specified
2198 232 my $zhash = $self->GetNewValueHash($Image::ExifTool::Extra{ZoneIdentifier});
2199 232 ▶ if ($zhash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zhash) 0 232 232
2200 0 my $res = -1;
2201 0 ▶ if ($^O ne 'MSWin32') {
Branch: 4 branches
BranchTrueFalseTotal
if ($^O ne 'MSWin32') { } 0 0 0
elsif (ref $file) { } 0 0 0
elsif (defined $self->GetNewValue('ZoneIdentifier', \$zhash)) { } 0 0 0
elsif (not eval { do { require Win32API::File } }) { } 0 0 0
2202 0 $self->Warn('ZoneIdentifer is a Windows-only tag');
2203 } elsif (ref $file) {
2204 0 $self->Warn('Writing ZoneIdentifer requires a file name');
2205 } elsif (defined $self->GetNewValue('ZoneIdentifier', \$zhash)) {
2206 0 $self->Warn('ZoneIndentifier may only be deleted');
2207 0 } elsif (not eval { require Win32API::File }) {
2208 0 $self->Warn('Install Win32API::File to write ZoneIdentifier');
2209 } else {
2210 0 my ($wattr, $wide);
2211 0 my $zfile = "${file}:Zone.Identifier";
2212 0 ▶ if ($self->EncodeFileName($zfile)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->EncodeFileName($zfile)) { } 0 0 0
2213 0 $wide = 1;
2214 0 $wattr = eval { Win32API::File::GetFileAttributesW($zfile) };
2215 } else {
2216 0 $wattr = eval { Win32API::File::GetFileAttributes($zfile) };
2217 }
2218 0 ▶ if ($wattr == Win32API::File::INVALID_FILE_ATTRIBUTES()) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wattr == Win32API::File::INVALID_FILE_ATTRIBUTES()) { } 0 0 0
elsif ($wattr & Win32API::File::FILE_ATTRIBUTE_READONLY()) { } 0 0 0
2219 0 $res = 0; # file doesn't exist, nothing to do
2220 } elsif ($wattr & Win32API::File::FILE_ATTRIBUTE_READONLY()) {
2221 0 $self->Warn('Zone.Identifier stream is read-only');
2222 } else {
2223 0 ▶ if ($wide) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wide) { } 0 0 0
2224 0 ▶ $res = 1 if eval { Win32API::File::DeleteFileW($zfile) };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { Win32API::File::DeleteFileW($zfile) } } 0 0 0
2225 } else {
2226 0 ▶ $res = 1 if eval { Win32API::File::DeleteFile($zfile) };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { Win32API::File::DeleteFile($zfile) } } 0 0 0
2227 }
2228 0 ▶ if ($res > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res > 0) { } 0 0 0
2229 0 $self->VPrint(0, " Deleting Zone.Identifier stream\n");
2230 } else {
2231 0 $self->Warn('Error deleting Zone.Identifier stream');
2232 }
2233 }
2234 }
2235 0 ▶ $result = $res if $res == 1 or not $result;
Branch: 1 branch
BranchTrueFalseTotal
if $res == 1 or not $result 0 0 0
Condition0%0/3
$res == 1 or not $result
l!l&&r!l&&!r
000
MC/DC0%0/2
$res == 1 or not $result
$res == 1 not $result
Truth table0%0/3
A or not(B)
A= $res == 1B= not $result
ABresult
1X1
011
000
2236 }
2237 232 return $result;
2238 }
2239  
2240 #------------------------------------------------------------------------------
2241 # Write information back to file
2242 # Inputs: 0) ExifTool object reference,
2243 # 1) input filename, file ref, RAF ref, or scalar ref (or '' or undef to create from scratch)
2244 # 2) output filename, file ref, or scalar ref (or undef to overwrite)
2245 # 3) optional output file type (required only if input file is not specified
2246 # and output file is a reference)
2247 # Returns: 1=file written OK, 2=file written but no changes made, 0=file write error
2248 sub WriteInfo($$;$$)
2249 245 ▶{
Subroutine WriteInfo: called CC=203 SCAR=87.4
Pod documented
2250 245 local ($_, *EXIFTOOL_FILE2, *EXIFTOOL_OUTFILE);
2251 245 my ($self, $infile, $outfile, $outType) = @_;
2252 245 my (@fileTypeList, $fileType, $tiffType, $hdr, $seekErr, $type, $tmpfile);
2253 245 my ($inRef, $outRef, $closeIn, $closeOut, $outPos, $outBuff, $eraseIn, $raf, $fileExt);
2254 245 my ($hardLink, $symLink, $testName);
2255 245 my $oldRaf = $$self{RAF};
2256 245 my $rtnVal = 0;
2257  
2258 # initialize member variables
2259 245 $self->Init();
2260 245 $$self{IsWriting} = 1;
2261  
2262 # first, save original file modify date if necessary
2263 # (do this now in case we are modifying file in place and shifting date)
2264 245 my ($nvHash, $nvHash2, $originalTime, $createTime);
2265 245 my $setModDate = defined $self->GetNewValue('FileModifyDate', \$nvHash);
2266 245 my $setCreateDate = defined $self->GetNewValue('FileCreateDate', \$nvHash2);
2267 245 my ($aTime, $mTime, $cTime);
2268 245 ▶ if ($setModDate and $self->IsOverwriting($nvHash) < 0 and
Branch: 1 branch
BranchTrueFalseTotal
if ($setModDate and $self->IsOverwriting($nvHash) < 0 and defined $infile and ref $infile ne "SCALAR") 0 245 245
Condition33%3/9
$setModDate and $self->IsOverwriting($nvHash) < 0 and defined $infile and ref $infile ne "SCALAR"
!ll&&!rl&&r
24500
$setModDate and $self->IsOverwriting($nvHash) < 0 and defined $infile
!ll&&!rl&&r
24500
$setModDate and $self->IsOverwriting($nvHash) < 0
!ll&&!rl&&r
24500
MC/DC0%0/4
$setModDate and $self->IsOverwriting($nvHash) < 0 and defined $infile and ref $infile ne "SCALAR"
$setModDate $self->IsOverwriting($nvHash) < 0 defined $infile ref $infile ne "SCALAR"
Truth table20%1/5
A and B and C and D
A= $setModDateB= $self->IsOverwriting($nvHash) < 0C= defined $infileD= ref $infile ne "SCALAR"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2269 defined $infile and ref $infile ne 'SCALAR')
2270 {
2271 0 ($aTime, $mTime, $cTime) = $self->GetFileTime($infile);
2272 0 $originalTime = $mTime;
2273 }
2274 245 ▶ if ($setCreateDate and $self->IsOverwriting($nvHash2) < 0 and
Branch: 1 branch
BranchTrueFalseTotal
if ($setCreateDate and $self->IsOverwriting($nvHash2) < 0 and defined $infile and ref $infile ne "SCALAR") 0 245 245
Condition33%3/9
$setCreateDate and $self->IsOverwriting($nvHash2) < 0 and defined $infile and ref $infile ne "SCALAR"
!ll&&!rl&&r
24500
$setCreateDate and $self->IsOverwriting($nvHash2) < 0 and defined $infile
!ll&&!rl&&r
24500
$setCreateDate and $self->IsOverwriting($nvHash2) < 0
!ll&&!rl&&r
24500
MC/DC0%0/4
$setCreateDate and $self->IsOverwriting($nvHash2) < 0 and defined $infile and ref $infile ne "SCALAR"
$setCreateDate $self->IsOverwriting($nvHash2) < 0 defined $infile ref $infile ne "SCALAR"
Truth table20%1/5
A and B and C and D
A= $setCreateDateB= $self->IsOverwriting($nvHash2) < 0C= defined $infileD= ref $infile ne "SCALAR"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2275 defined $infile and ref $infile ne 'SCALAR')
2276 {
2277 0 ▶ ($aTime, $mTime, $cTime) = $self->GetFileTime($infile) unless defined $cTime;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cTime 0 0 0
2278 0 $createTime = $cTime;
2279 }
2280 #
2281 # do quick in-place change of file dir/name or date if that is all we are doing
2282 #
2283 245 my ($numNew, $numPseudo) = $self->CountNewValues();
2284 245 ▶ if (not defined $outfile and defined $infile) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $outfile and defined $infile) 4 241 245
Condition66%2/3
not defined $outfile and defined $infile
!ll&&!rl&&r
24104
MC/DC50%1/2
not defined $outfile and defined $infile
not defined $outfile defined $infile
Truth table66%2/3
not(A) and B
A= not defined $outfileB= defined $infile
ABresult
0X0
100
111
2285 4 $hardLink = $self->GetNewValue('HardLink');
2286 4 $symLink = $self->GetNewValue('SymLink');
2287 4 $testName = $self->GetNewValue('TestName');
2288 4 ▶ undef $hardLink if defined $hardLink and not length $hardLink;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hardLink and not length $hardLink 0 4 4
Condition33%1/3
defined $hardLink and not length $hardLink
!ll&&!rl&&r
400
MC/DC0%0/2
defined $hardLink and not length $hardLink
defined $hardLink not length $hardLink
Truth table33%1/3
A and not(B)
A= defined $hardLinkB= not length $hardLink
ABresult
0X0
100
111
2289 4 ▶ undef $symLink if defined $symLink and not length $symLink;
Branch: 1 branch
BranchTrueFalseTotal
if defined $symLink and not length $symLink 0 4 4
Condition33%1/3
defined $symLink and not length $symLink
!ll&&!rl&&r
400
MC/DC0%0/2
defined $symLink and not length $symLink
defined $symLink not length $symLink
Truth table33%1/3
A and not(B)
A= defined $symLinkB= not length $symLink
ABresult
0X0
100
111
2290 4 ▶ undef $testName if defined $testName and not length $testName;
Branch: 1 branch
BranchTrueFalseTotal
if defined $testName and not length $testName 0 4 4
Condition33%1/3
defined $testName and not length $testName
!ll&&!rl&&r
400
MC/DC0%0/2
defined $testName and not length $testName
defined $testName not length $testName
Truth table33%1/3
A and not(B)
A= defined $testNameB= not length $testName
ABresult
0X0
100
111
2291 4 my $newFileName = $self->GetNewValue('FileName', \$nvHash);
2292 4 my $newDir = $self->GetNewValue('Directory');
2293 4 ▶ if (defined $newDir and length $newDir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newDir and length $newDir) { } 0 4 4
Condition33%1/3
defined $newDir and length $newDir
!ll&&!rl&&r
400
MC/DC0%0/2
defined $newDir and length $newDir
defined $newDir length $newDir
Truth table33%1/3
A and B
A= defined $newDirB= length $newDir
ABresult
0X0
100
111
2294 0 ▶ $newDir .= '/' unless $newDir =~ m{/$};
Branch: 1 branch
BranchTrueFalseTotal
unless $newDir =~ m[/$] 0 0 0
2295 } else {
2296 4 undef $newDir;
2297 }
2298 4 ▶ if ($numNew == $numPseudo) {
Branch: 2 branches
BranchTrueFalseTotal
if ($numNew == $numPseudo) { } 1 3 4
elsif (defined $newFileName and length $newFileName) { } 0 6 6
2299 1 $rtnVal = 2;
2300 1 ▶ if ((defined $newFileName or defined $newDir) and not ref $infile) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newFileName || defined $newDir and not ref $infile) 1 0 1
Condition33%2/6
defined $newFileName || defined $newDir and not ref $infile
!ll&&!rl&&r
001
defined $newFileName or defined $newDir
l!l&&r!l&&!r
100
MC/DC0%0/3
defined $newFileName || defined $newDir and not ref $infile
defined $newFileName defined $newDir not ref $infile
Truth table20%1/5
A or B and not(C)
A= defined $newFileNameB= defined $newDirC= not ref $infile
ABCresult
00X0
1X00
0100
1X11
0111
2301 1 my $result = $self->SetFileName($infile);
2302 1 ▶ if ($result > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result > 0) { } 1 0 1
elsif ($result < 0) { } 0 0 0
2303 1 $infile = $$self{NewName}; # file name changed
2304 1 $rtnVal = 1;
2305 } elsif ($result < 0) {
2306 0 return 0; # don't try to do anything else
2307 }
2308 }
2309 1 ▶ if (not ref $infile or UNIVERSAL::isa($infile,'GLOB')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $infile or UNIVERSAL::isa($infile, "GLOB")) 1 0 1
Condition33%1/3
not ref $infile or UNIVERSAL::isa($infile, "GLOB")
l!l&&r!l&&!r
100
MC/DC0%0/2
not ref $infile or UNIVERSAL::isa($infile, "GLOB")
not ref $infile UNIVERSAL::isa($infile, "GLOB")
Truth table33%1/3
not(A) or B
A= not ref $infileB= UNIVERSAL::isa($infile, "GLOB")
ABresult
1X1
011
000
2310 1 ▶ $self->SetFileModifyDate($infile) > 0 and $rtnVal = 1 if $setModDate;
Branch: 1 branch
BranchTrueFalseTotal
if $setModDate 0 1 1
Condition16%1/6
$setModDate && ($self->SetFileModifyDate($infile) > 0 && ($rtnVal = 1))
!ll&&!rl&&r
100
$self->SetFileModifyDate($infile) > 0 and $rtnVal = 1
!ll&&!rl&&r
000
MC/DC0%0/3
$setModDate && ($self->SetFileModifyDate($infile) > 0 && ($rtnVal = 1))
$setModDate $self->SetFileModifyDate($infile) > 0 $rtnVal = 1
Truth table0%0/4
A && B and C
A= $setModDateB= $self->SetFileModifyDate($infile) > 0C= $rtnVal = 1
ABCresult
0XX0
10X0
1100
1111
2311 1 ▶ $self->SetFileModifyDate($infile, undef, 'FileCreateDate') > 0 and $rtnVal = 1 if $setCreateDate;
Branch: 1 branch
BranchTrueFalseTotal
if $setCreateDate 0 1 1
Condition16%1/6
$setCreateDate && ($self->SetFileModifyDate($infile, undef, 'FileCreateDate') > 0 && ($rtnVal = 1))
!ll&&!rl&&r
100
$self->SetFileModifyDate($infile, undef, "FileCreateDate") > 0 and $rtnVal = 1
!ll&&!rl&&r
000
MC/DC0%0/3
$setCreateDate && ($self->SetFileModifyDate($infile, undef, 'FileCreateDate') > 0 && ($rtnVal = 1))
$setCreateDate $self->SetFileModifyDate($infile, undef, "FileCreateDate") > 0 $rtnVal = 1
Truth table0%0/4
A && B and C
A= $setCreateDateB= $self->SetFileModifyDate($infile, undef, "FileCreateDate") > 0C= $rtnVal = 1
ABCresult
0XX0
10X0
1100
1111
2312 1 ▶ $self->SetSystemTags($infile) > 0 and $rtnVal = 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->SetSystemTags($infile) > 0 and $rtnVal = 1 0 1 1
2313 }
2314 1 ▶ if (defined $hardLink or defined $symLink or defined $testName) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hardLink or defined $symLink or defined $testName) 0 1 1
Condition33%2/6
defined $hardLink or defined $symLink or defined $testName
l!l&&r!l&&!r
001
defined $hardLink or defined $symLink
l!l&&r!l&&!r
001
MC/DC0%0/3
defined $hardLink or defined $symLink or defined $testName
defined $hardLink defined $symLink defined $testName
Truth table25%1/4
A or B or C
A= defined $hardLinkB= defined $symLinkC= defined $testName
ABCresult
1XX1
01X1
0011
0000
2315 0 ▶ $hardLink and $self->SetFileName($infile, $hardLink, 'HardLink') and $rtnVal = 1;
Branch: 1 branch
BranchTrueFalseTotal
$hardLink and $self->SetFileName($infile, $hardLink, "HardLink") and $rtnVal = 1 0 0 0
Condition0%0/3
$hardLink and $self->SetFileName($infile, $hardLink, "HardLink")
!ll&&!rl&&r
000
MC/DC0%0/2
$hardLink and $self->SetFileName($infile, $hardLink, "HardLink")
$hardLink $self->SetFileName($infile, $hardLink, "HardLink")
Truth table0%0/3
A and B
A= $hardLinkB= $self->SetFileName($infile, $hardLink, "HardLink")
ABresult
0X0
100
111
2316 0 ▶ $symLink and $self->SetFileName($infile, $symLink, 'SymLink') and $rtnVal = 1;
Branch: 1 branch
BranchTrueFalseTotal
$symLink and $self->SetFileName($infile, $symLink, "SymLink") and $rtnVal = 1 0 0 0
Condition0%0/3
$symLink and $self->SetFileName($infile, $symLink, "SymLink")
!ll&&!rl&&r
000
MC/DC0%0/2
$symLink and $self->SetFileName($infile, $symLink, "SymLink")
$symLink $self->SetFileName($infile, $symLink, "SymLink")
Truth table0%0/3
A and B
A= $symLinkB= $self->SetFileName($infile, $symLink, "SymLink")
ABresult
0X0
100
111
2317 0 ▶ $testName and $self->SetFileName($infile, $testName, 'Test') and $rtnVal = 1;
Branch: 1 branch
BranchTrueFalseTotal
$testName and $self->SetFileName($infile, $testName, "Test") and $rtnVal = 1 0 0 0
Condition0%0/3
$testName and $self->SetFileName($infile, $testName, "Test")
!ll&&!rl&&r
000
MC/DC0%0/2
$testName and $self->SetFileName($infile, $testName, "Test")
$testName $self->SetFileName($infile, $testName, "Test")
Truth table0%0/3
A and B
A= $testNameB= $self->SetFileName($infile, $testName, "Test")
ABresult
0X0
100
111
2318 }
2319 1 return $rtnVal;
2320 ▶ } elsif (defined $newFileName and length $newFileName) {
Condition33%1/3
defined $newFileName and length $newFileName
!ll&&!rl&&r
300
MC/DC0%0/2
defined $newFileName and length $newFileName
defined $newFileName length $newFileName
Truth table33%1/3
A and B
A= defined $newFileNameB= length $newFileName
ABresult
0X0
100
111
2321 # can't simply rename file, so just set the output name if new FileName
2322 # --> in this case, must erase original copy
2323 0 ▶ if (ref $infile) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $infile) { } 0 0 0
elsif ($self->IsOverwriting($nvHash, $infile)) { } 0 0 0
2324 0 $outfile = $newFileName;
2325 # can't delete original
2326 } elsif ($self->IsOverwriting($nvHash, $infile)) {
2327 0 $outfile = GetNewFileName($infile, $newFileName);
2328 0 $eraseIn = 1; # delete original
2329 }
2330 }
2331 # set new directory if specified
2332 3 ▶ if (defined $newDir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newDir) 0 3 3
2333 0 ▶ $outfile = $infile unless defined $outfile or ref $infile;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $outfile or ref $infile 0 0 0
Condition0%0/3
defined $outfile or ref $infile
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $outfile or ref $infile
defined $outfile ref $infile
Truth table0%0/3
A or B
A= defined $outfileB= ref $infile
ABresult
1X1
011
000
2334 0 ▶ if (defined $outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $outfile) 0 0 0
2335 0 $outfile = GetNewFileName($outfile, $newDir);
2336 0 ▶ $eraseIn = 1 unless ref $infile;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $infile 0 0 0
2337 }
2338 }
2339 }
2340 #
2341 # set up input file
2342 #
2343 244 ▶ if (ref $infile) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $infile) { } 5 239 244
elsif (defined $infile and $infile ne '') { } 215 24 239
elsif (not defined $outfile) { } 0 24 24
2344 5 $inRef = $infile;
2345 5 ▶ if (UNIVERSAL::isa($inRef,'GLOB')) {
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($inRef, 'GLOB')) { } 1 4 5
elsif (UNIVERSAL::isa($inRef, 'File::RandomAccess')) { } 0 4 4
elsif ($] >= 5.006 and $self->{'OPTIONS'}{'EncodeHangs'} || eval { do { require Encode; &Encode::is_utf8($$inRef) } } || $@) { } 0 4 4
2346 1 seek($inRef, 0, 0); # make sure we are at the start of the file
2347 } elsif (UNIVERSAL::isa($inRef,'File::RandomAccess')) {
2348 0 $inRef->Seek(0);
2349 0 $raf = $inRef;
2350 ▶ } elsif ($] >= 5.006 and ($$self{OPTIONS}{EncodeHangs} or
Condition33%3/9
$] >= "5.006" and $self->{"OPTIONS"}{"EncodeHangs"} || eval { do { require Encode; &Encode::is_utf8($$inRef) } } || $@
!ll&&!rl&&r
040
$self->{"OPTIONS"}{"EncodeHangs"} or eval { do { require Encode; &Encode::is_utf8($$inRef) } } or $@
l!l&&r!l&&!r
004
$self->{"OPTIONS"}{"EncodeHangs"} or eval { do { require Encode; &Encode::is_utf8($$inRef) } }
l!l&&r!l&&!r
004
MC/DC0%0/4
$] >= "5.006" and $self->{"OPTIONS"}{"EncodeHangs"} || eval { do { require Encode; &Encode::is_utf8($$inRef) } } || $@
$] >= "5.006" $self->{"OPTIONS"}{"EncodeHangs"} eval { do { require Encode; &Encode::is_utf8($$inRef) } } $@
Truth table20%1/5
A and B or C or D
A= $] >= "5.006"B= $self->{"OPTIONS"}{"EncodeHangs"}C= eval { do { require Encode; &Encode::is_utf8($$inRef) } }D= $@
ABCDresult
0XXX0
10000
11XX1
101X1
10011
2351 4 eval { require Encode; Encode::is_utf8($$inRef) } or $@))
2352 {
2353 0 local $SIG{'__WARN__'} = \&SetWarning;
2354 # convert image data from UTF-8 to character stream if necessary
2355 0 ▶ my $buff = ($$self{OPTIONS}{EncodeHangs} or $@) ? pack('C*', unpack($] < 5.010000 ?
Branch: 2 branches
BranchTrueFalseTotal
$self->{'OPTIONS'}{'EncodeHangs'} || $@ ? : 0 0 0
$] < 5.01 ? : 0 0 0
Condition0%0/3
$self->{"OPTIONS"}{"EncodeHangs"} or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"OPTIONS"}{"EncodeHangs"} or $@
$self->{"OPTIONS"}{"EncodeHangs"} $@
Truth table0%0/3
A or B
A= $self->{"OPTIONS"}{"EncodeHangs"}B= $@
ABresult
1X1
011
000
2356 'U0C*' : 'C0C*', $$inRef)) : Encode::encode('utf8', $$inRef);
2357 0 ▶ if (defined $outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $outfile) { } 0 0 0
2358 0 $inRef = \$buff;
2359 } else {
2360 0 $$inRef = $buff;
2361 }
2362 }
2363 ▶ } elsif (defined $infile and $infile ne '') {
Condition66%2/3
defined $infile and $infile ne ""
!ll&&!rl&&r
240215
MC/DC50%1/2
defined $infile and $infile ne ""
defined $infile $infile ne ""
Truth table66%2/3
A and B
A= defined $infileB= $infile ne ""
ABresult
0X0
100
111
2364 # write to a temporary file if no output file given
2365 215 ▶ $outfile = $tmpfile = "${infile}_exiftool_tmp" unless defined $outfile;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $outfile 2 213 215
2366 215 ▶ if ($self->Open(\*EXIFTOOL_FILE2, $infile)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Open(\*EXIFTOOL_FILE2, $infile)) { } 215 0 215
2367 215 $fileExt = GetFileExtension($infile);
2368 215 $fileType = GetFileType($infile);
2369 215 @fileTypeList = GetFileType($infile);
2370 215 $tiffType = $$self{FILE_EXT} = GetFileExtension($infile);
2371 215 $self->VPrint(0, "Rewriting $infile...\n");
2372 215 $inRef = \*EXIFTOOL_FILE2;
2373 215 $closeIn = 1; # we must close the file since we opened it
2374 } else {
2375 0 $self->Error('Error opening file');
2376 0 return 0;
2377 }
2378 } elsif (not defined $outfile) {
2379 0 $self->Error("WriteInfo(): Must specify infile or outfile\n");
2380 0 return 0;
2381 } else {
2382 # create file from scratch
2383 24 ▶ $outType = GetFileExtension($outfile) unless $outType or ref $outfile;
Branch: 1 branch
BranchTrueFalseTotal
unless $outType or ref $outfile 23 1 24
Condition66%2/3
$outType or ref $outfile
l!l&&r!l&&!r
1023
MC/DC50%1/2
$outType or ref $outfile
$outType ref $outfile
Truth table66%2/3
A or B
A= $outTypeB= ref $outfile
ABresult
1X1
011
000
2384 24 ▶ if (CanCreate($outType)) {
Branch: 2 branches
BranchTrueFalseTotal
if (&CanCreate($outType)) { } 24 0 24
elsif ($outType) { } 0 0 0
2385 24 ▶ if ($$self{OPTIONS}{WriteMode} =~ /g/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'OPTIONS'}{'WriteMode'} =~ /g/i) { } 24 0 24
2386 24 $fileType = $tiffType = $outType; # use output file type if no input file
2387 24 $infile = "$fileType file"; # make bogus file name
2388 24 $self->VPrint(0, "Creating $infile...\n");
2389 24 $inRef = \ ''; # set $inRef to reference to empty data
2390 } else {
2391 0 $self->Error("Not creating new $outType file (disallowed by WriteMode)");
2392 0 return 0;
2393 }
2394 } elsif ($outType) {
2395 0 $self->Error("Can't create $outType files");
2396 0 return 0;
2397 } else {
2398 0 $self->Error("Can't create file (unknown type)");
2399 0 return 0;
2400 }
2401 }
2402 244 ▶ unless (@fileTypeList) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@fileTypeList) 30 214 244
2403 30 ▶ if ($fileType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fileType) { } 24 6 30
2404 24 @fileTypeList = ( $fileType );
2405 } else {
2406 6 @fileTypeList = @fileTypes;
2407 6 $tiffType = 'TIFF';
2408 }
2409 }
2410 #
2411 # set up output file
2412 #
2413 244 ▶ if (ref $outfile) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $outfile) { } 13 231 244
elsif (not defined $outfile) { } 1 230 231
elsif ($self->Exists($outfile, 1)) { } 0 230 230
elsif ($self->Open(\*EXIFTOOL_OUTFILE, $outfile, '>')) { } 230 0 230
2414 13 $outRef = $outfile;
2415 13 ▶ if (UNIVERSAL::isa($outRef,'GLOB')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($outRef, 'GLOB')) { } 0 13 13
2416 0 binmode($outRef);
2417 0 $outPos = tell($outRef);
2418 } else {
2419 # initialize our output buffer if necessary
2420 13 ▶ defined $$outRef or $$outRef = '';
Branch: 1 branch
BranchTrueFalseTotal
defined $$outRef or $$outRef = "" 0 13 13
2421 13 $outPos = length($$outRef);
2422 }
2423 } elsif (not defined $outfile) {
2424 # editing in place, so write to memory first
2425 # (only when infile is a file ref or scalar ref)
2426 1 ▶ if ($raf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf) 0 1 1
2427 0 $self->Error("Can't edit File::RandomAccess object in place");
2428 0 return 0;
2429 }
2430 1 $outBuff = '';
2431 1 $outRef = \$outBuff;
2432 1 $outPos = 0;
2433 } elsif ($self->Exists($outfile, 1)) {
2434 0 $self->Error("File already exists: $outfile");
2435 } elsif ($self->Open(\*EXIFTOOL_OUTFILE, $outfile, '>')) {
2436 230 $outRef = \*EXIFTOOL_OUTFILE;
2437 230 $closeOut = 1; # we must close $outRef
2438 230 binmode($outRef);
2439 230 $outPos = 0;
2440 } else {
2441 0 ▶ my $tmp = $tmpfile ? ' temporary' : '';
Branch: 1 branch
BranchTrueFalseTotal
$tmpfile ? : 0 0 0
2442 0 $self->Error("Error creating$tmp file: $outfile");
2443 }
2444 #
2445 # write the file
2446 #
2447 244 ▶ until ($$self{VALUE}{Error}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"VALUE"}{"Error"}) 244 0 244
2448 # create random access file object (disable seek test in case of straight copy)
2449 244 ▶ $raf or $raf = File::RandomAccess->new($inRef, 1);
Branch: 1 branch
BranchTrueFalseTotal
$raf or $raf = "File::RandomAccess"->new($inRef, 1) 0 244 244
2450 244 $raf->BinMode();
2451 244 ▶ if ($numNew == $numPseudo) {
Branch: 2 branches
BranchTrueFalseTotal
if ($numNew == $numPseudo) { } 1 243 244
elsif (not ref $infile and $infile eq '-' || $infile =~ /\|$/) { } 0 243 243
2452 1 $rtnVal = 1;
2453 # just do a straight copy of the file (no "real" tags are being changed)
2454 1 my $buff;
2455 1 ▶ while ($raf->Read($buff, 65536)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->Read($buff, 65536)) 1 1 2
2456 1 ▶ Write($outRef, $buff) or $rtnVal = -1, last;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outRef, $buff) or $rtnVal = -1, last 1 0 1
2457 }
2458 1 last;
2459 ▶ } elsif (not ref $infile and ($infile eq '-' or $infile =~ /\|$/)) {
Condition50%3/6
not ref $infile and $infile eq "-" || $infile =~ /\|$/
!ll&&!rl&&r
52380
$infile eq "-" or $infile =~ /\|$/
l!l&&r!l&&!r
00238
MC/DC0%0/3
not ref $infile and $infile eq "-" || $infile =~ /\|$/
not ref $infile $infile eq "-" $infile =~ /\|$/
Truth table50%2/4
not(A) and B or C
A= not ref $infileB= $infile eq "-"C= $infile =~ /\|$/
ABCresult
0XX0
1000
11X1
1011
2460 # patch for Windows command shell pipe
2461 0 $$raf{TESTED} = -1; # force buffering
2462 } else {
2463 243 $raf->SeekTest();
2464 }
2465 # $raf->Debug() and warn " RAF debugging enabled!\n";
2466 243 my $inPos = $raf->Tell();
2467 243 $$self{RAF} = $raf;
2468 243 my %dirInfo = (
2469 RAF => $raf,
2470 OutFile => $outRef,
2471 );
2472 243 ▶ $raf->Read($hdr, 1024) or $hdr = '';
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($hdr, 1024) or $hdr = "" 219 24 243
2473 243 ▶ $raf->Seek($inPos, 0) or $seekErr = 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($inPos, 0) or $seekErr = 1 243 0 243
2474 243 my $wrongType;
2475 243 ▶ until ($seekErr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seekErr) 278 0 278
2476 278 $type = shift @fileTypeList;
2477 # do quick test to see if this is the right file type
2478 278 ▶ if ($magicNumber{$type} and length($hdr) and $hdr !~ /^$magicNumber{$type}/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::magicNumber{$type} and length $hdr and not $hdr =~ /^$Image::ExifTool::magicNumber{$type}/s) 35 243 278
Condition83%5/6
$Image::ExifTool::magicNumber{$type} and length $hdr and not $hdr =~ /^$Image::ExifTool::magicNumber{$type}/s
!ll&&!rl&&r
2421935
$Image::ExifTool::magicNumber{$type} and length $hdr
!ll&&!rl&&r
024254
MC/DC66%2/3
$Image::ExifTool::magicNumber{$type} and length $hdr and not $hdr =~ /^$Image::ExifTool::magicNumber{$type}/s
$Image::ExifTool::magicNumber{$type} length $hdr not $hdr =~ /^$Image::ExifTool::magicNumber{$type}/s
Truth table75%3/4
A and B and not(C)
A= $Image::ExifTool::magicNumber{$type}B= length $hdrC= not $hdr =~ /^$Image::ExifTool::magicNumber{$type}/s
ABCresult
0XX0
10X0
1100
1111
2479 35 ▶ next if @fileTypeList;
Branch: 1 branch
BranchTrueFalseTotal
if @fileTypeList 35 0 35
2480 0 $wrongType = 1;
2481 0 last;
2482 }
2483 # save file type in member variable
2484 243 $dirInfo{Parent} = $$self{FILE_TYPE} = $$self{PATH}[0] = $type;
2485 # determine which directories we must write for this file type
2486 243 $self->InitWriteDirs($type);
2487 243 ▶ if ($type eq 'JPEG' or $type eq 'EXV') {
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'JPEG' or $type eq 'EXV') { } 110 133 243
elsif ($type eq 'TIFF') { } 13 120 133
elsif (exists $writableType{$type}) { } 118 2 120
elsif ($type eq 'ORF' or $type eq 'RAW') { } 0 2 2
elsif ($type eq 'EXIF') { } 2 0 2
Condition100%3/3
$type eq "JPEG" or $type eq "EXV"
l!l&&r!l&&!r
1082133
MC/DC100%2/2
$type eq "JPEG" or $type eq "EXV"
$type eq "JPEG" $type eq "EXV"
Truth table100%3/3
A or B
A= $type eq "JPEG"B= $type eq "EXV"
ABresult
1X1
011
000
2488 110 $rtnVal = $self->WriteJPEG(\%dirInfo);
2489 } elsif ($type eq 'TIFF') {
2490 # disallow writing of some TIFF-based RAW images:
2491 13 ▶ if (grep /^$tiffType$/, @{$noWriteFile{TIFF}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^$tiffType$/, @{$Image::ExifTool::noWriteFile{'TIFF'};}) { } 0 13 13
2492 0 $fileType = $tiffType;
2493 0 undef $rtnVal;
2494 } else {
2495 13 ▶ if ($tiffType eq 'FFF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tiffType eq "FFF") 0 13 13
2496 # (see https://exiftool.org/forum/index.php?topic=10848.0)
2497 0 $self->Error('Phocus may not properly update previews of edited FFF images', 1);
2498 }
2499 13 $dirInfo{Parent} = $tiffType;
2500 13 $rtnVal = $self->ProcessTIFF(\%dirInfo);
2501 }
2502 } elsif (exists $writableType{$type}) {
2503 118 my ($module, $func);
2504 118 ▶ if (ref $writableType{$type} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $writableType{$type} eq 'ARRAY') { } 91 27 118
2505 91 ▶ $module = $writableType{$type}[0] || $type;
Condition66%2/3
$writableType{$type}[0] || $type
l!l&&r!l&&!r
32590
MC/DC0%0/2
$writableType{$type}[0] || $type
$writableType{$type}[0] $type
Truth table66%2/3
A || B
A= $writableType{$type}[0]B= $type
ABresult
1X1
011
000
2506 91 $func = $writableType{$type}[1];
2507 } else {
2508 27 ▶ $module = $writableType{$type} || $type;
Condition66%2/3
$writableType{$type} || $type
l!l&&r!l&&!r
16110
MC/DC0%0/2
$writableType{$type} || $type
$writableType{$type} $type
Truth table66%2/3
A || B
A= $writableType{$type}B= $type
ABresult
1X1
011
000
2509 }
2510 118 require "Image/ExifTool/$module.pm";
2511 118 ▶ $func = "Image::ExifTool::${module}::" . ($func || "Process$type");
Condition100%2/2
$func || "Process$type"
l!l
9127
MC/DC100%1/1
$func || "Process$type"
$func
Truth table100%2/2
A
A= $func
Aresult
11
00
2512 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2513 118 $rtnVal = &$func($self, \%dirInfo);
2514 61 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2515 ▶ } elsif ($type eq 'ORF' or $type eq 'RAW') {
Condition33%1/3
$type eq "ORF" or $type eq "RAW"
l!l&&r!l&&!r
002
MC/DC0%0/2
$type eq "ORF" or $type eq "RAW"
$type eq "ORF" $type eq "RAW"
Truth table33%1/3
A or B
A= $type eq "ORF"B= $type eq "RAW"
ABresult
1X1
011
000
2516 0 $rtnVal = $self->ProcessTIFF(\%dirInfo);
2517 } elsif ($type eq 'EXIF') {
2518 # go through WriteDirectory so block writes, etc are handled
2519 2 my $tagTablePtr = GetTagTable('Image::ExifTool::Exif::Main');
2520 2 my $buff = $self->WriteDirectory(\%dirInfo, $tagTablePtr, \&WriteTIFF);
2521 2 ▶ if (defined $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff) { } 2 0 2
2522 2 ▶ $rtnVal = Write($outRef, $buff) ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outRef, $buff) ? : 2 0 2
2523 } else {
2524 0 $rtnVal = 0;
2525 }
2526 } else {
2527 0 undef $rtnVal; # flag that we don't write this type of file
2528 }
2529 # all done unless we got the wrong type
2530 243 ▶ last if $rtnVal;
Branch: 1 branch
BranchTrueFalseTotal
if $rtnVal 243 0 243
2531 0 ▶ last unless @fileTypeList;
Branch: 1 branch
BranchTrueFalseTotal
unless @fileTypeList 0 0 0
2532 # seek back to original position in files for next try
2533 0 ▶ $raf->Seek($inPos, 0) or $seekErr = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($inPos, 0) or $seekErr = 1, last 0 0 0
2534 0 ▶ if (UNIVERSAL::isa($outRef,'GLOB')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($outRef, 'GLOB')) { } 0 0 0
2535 0 seek($outRef, 0, $outPos);
2536 } else {
2537 0 $$outRef = substr($$outRef, 0, $outPos);
2538 }
2539 }
2540 # print file format errors
2541 243 ▶ unless ($rtnVal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rtnVal) 0 243 243
2542 0 my $err;
2543 0 ▶ if ($seekErr) {
Branch: 3 branches
BranchTrueFalseTotal
if ($seekErr) { } 0 0 0
elsif ($fileType and defined $rtnVal) { } 0 0 0
elsif ($fileType) { } 0 0 0
2544 0 $err = 'Error seeking in file';
2545 ▶ } elsif ($fileType and defined $rtnVal) {
Condition0%0/3
$fileType and defined $rtnVal
!ll&&!rl&&r
000
MC/DC0%0/2
$fileType and defined $rtnVal
$fileType defined $rtnVal
Truth table0%0/3
A and B
A= $fileTypeB= defined $rtnVal
ABresult
0X0
100
111
2546 0 ▶ if ($$self{VALUE}{Error}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'VALUE'}{'Error'}) { } 0 0 0
elsif ($fileType eq 'RAW') { } 0 0 0
2547 # existing error message will do
2548 } elsif ($fileType eq 'RAW') {
2549 0 $err = 'Writing this type of RAW file is not supported';
2550 } else {
2551 0 ▶ if ($wrongType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrongType) { } 0 0 0
2552 0 ▶ my $type = $fileExt || ($fileType eq 'TIFF' ? $tiffType : $fileType);
Branch: 1 branch
BranchTrueFalseTotal
$fileType eq 'TIFF' ? : 0 0 0
Condition0%0/3
$fileExt || ($fileType eq 'TIFF' ? $tiffType : $fileType)
l!l&&r!l&&!r
000
MC/DC0%0/2
$fileExt || ($fileType eq 'TIFF' ? $tiffType : $fileType)
$fileExt ($fileType eq 'TIFF' ? $tiffType : $fileType)
Truth table0%0/3
A || B
A= $fileExtB= ($fileType eq 'TIFF' ? $tiffType : $fileType)
ABresult
1X1
011
000
2553 0 $err = "Not a valid $type";
2554 # do a quick check to see what this file looks like
2555 0 foreach $type (@fileTypes) {
2556 0 ▶ next unless $magicNumber{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless $Image::ExifTool::magicNumber{$type} 0 0 0
2557 0 ▶ next unless $hdr =~ /^$magicNumber{$type}/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $hdr =~ /^$Image::ExifTool::magicNumber{$type}/s 0 0 0
2558 0 $err .= " (looks more like a $type)";
2559 0 last;
2560 }
2561 } else {
2562 0 $err = 'Format error in file';
2563 }
2564 }
2565 } elsif ($fileType) {
2566 # get specific type of file from extension
2567 0 ▶ $fileType = GetFileExtension($infile) if $infile and GetFileType($infile);
Branch: 1 branch
BranchTrueFalseTotal
if $infile and &GetFileType($infile) 0 0 0
Condition0%0/3
$infile and &GetFileType($infile)
!ll&&!rl&&r
000
MC/DC0%0/2
$infile and &GetFileType($infile)
$infile &GetFileType($infile)
Truth table0%0/3
A and B
A= $infileB= &GetFileType($infile)
ABresult
0X0
100
111
2568 0 $err = "Writing of $fileType files is not yet supported";
2569 } else {
2570 0 $err = 'Writing of this type of file is not supported';
2571 }
2572 0 ▶ $self->Error($err) if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
2573 0 $rtnVal = 0; # (in case it was undef)
2574 }
2575 # $raf->Close(); # only used to force debug output
2576 243 last; # (didn't really want to loop)
2577 }
2578 # don't return success code if any error occurred
2579 244 ▶ if ($rtnVal > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtnVal > 0) 244 0 244
2580 244 ▶ if ($outType and $type and $outType ne $type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outType and $type and $outType ne $type) 0 244 244
Condition66%4/6
$outType and $type and $outType ne $type
!ll&&!rl&&r
220240
$outType and $type
!ll&&!rl&&r
220024
MC/DC0%0/3
$outType and $type and $outType ne $type
$outType $type $outType ne $type
Truth table50%2/4
A and B and C
A= $outTypeB= $typeC= $outType ne $type
ABCresult
0XX0
10X0
1100
1111
2581 0 my @types = GetFileType($outType);
2582 0 ▶ unless (grep /^$type$/, @types) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$type$/, @types) 0 0 0
2583 0 $self->Error("Can't create $outType file from $type");
2584 0 $rtnVal = 0;
2585 }
2586 }
2587 244 ▶ if ($rtnVal > 0 and not Tell($outRef) and not $$self{VALUE}{Error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtnVal > 0 and not &Tell($outRef) and not $self->{"VALUE"}{"Error"}) 0 244 244
Condition33%2/6
$rtnVal > 0 and not &Tell($outRef) and not $self->{"VALUE"}{"Error"}
!ll&&!rl&&r
24400
$rtnVal > 0 and not &Tell($outRef)
!ll&&!rl&&r
02440
MC/DC0%0/3
$rtnVal > 0 and not &Tell($outRef) and not $self->{"VALUE"}{"Error"}
$rtnVal > 0 not &Tell($outRef) not $self->{"VALUE"}{"Error"}
Truth table25%1/4
A and not(B) and not(C)
A= $rtnVal > 0B= not &Tell($outRef)C= not $self->{"VALUE"}{"Error"}
ABCresult
0XX0
10X0
1100
1111
2588 # don't write a file with zero length
2589 0 ▶ if (defined $hdr and length $hdr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hdr and length $hdr) { } 0 0 0
Condition0%0/3
defined $hdr and length $hdr
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hdr and length $hdr
defined $hdr length $hdr
Truth table0%0/3
A and B
A= defined $hdrB= length $hdr
ABresult
0X0
100
111
2590 0 ▶ $type = '<unk>' unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
2591 0 $self->Error("Can't delete all meta information from $type file");
2592 } else {
2593 0 $self->Error('Nothing to write');
2594 }
2595 }
2596 244 ▶ $rtnVal = 0 if $$self{VALUE}{Error};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"VALUE"}{"Error"} 0 244 244
2597 }
2598  
2599 # rewrite original file in place if required
2600 244 ▶ if (defined $outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $outBuff) 1 243 244
2601 1 ▶ if ($rtnVal <= 0 or not $$self{CHANGED}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rtnVal <= 0 or not $self->{'CHANGED'}) { } 0 1 1
elsif (UNIVERSAL::isa($inRef, 'GLOB')) { } 1 0 1
Condition33%1/3
$rtnVal <= 0 or not $self->{"CHANGED"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$rtnVal <= 0 or not $self->{"CHANGED"}
$rtnVal <= 0 not $self->{"CHANGED"}
Truth table33%1/3
A or not(B)
A= $rtnVal <= 0B= not $self->{"CHANGED"}
ABresult
1X1
011
000
2602 # nothing changed, so no need to write $outBuff
2603 } elsif (UNIVERSAL::isa($inRef,'GLOB')) {
2604 1 my $len = length($outBuff);
2605 1 my $size;
2606 $rtnVal = -1 unless
2607 seek($inRef, 0, 2) and # seek to the end of file
2608 ($size = tell $inRef) >= 0 and # get the file size
2609 seek($inRef, 0, 0) and # seek back to the start
2610 print $inRef $outBuff and # write the new data
2611 ($len >= $size or # if necessary:
2612 1 ▶ eval { truncate($inRef, $len) }); # shorten output file
Branch: 1 branch
BranchTrueFalseTotal
unless seek $inRef, 0, 2 and ($size = tell $inRef) >= 0 and seek $inRef, 0, 0 and print $inRef $outBuff and $len >= $size || eval { do { truncate $inRef, $len } } 0 1 1
Condition33%5/15
seek $inRef, 0, 2 and ($size = tell $inRef) >= 0 and seek $inRef, 0, 0 and print $inRef $outBuff and $len >= $size || eval { do { truncate $inRef, $len } }
!ll&&!rl&&r
001
seek $inRef, 0, 2 and ($size = tell $inRef) >= 0 and seek $inRef, 0, 0 and print $inRef $outBuff
!ll&&!rl&&r
001
seek $inRef, 0, 2 and ($size = tell $inRef) >= 0 and seek $inRef, 0, 0
!ll&&!rl&&r
001
seek $inRef, 0, 2 and ($size = tell $inRef) >= 0
!ll&&!rl&&r
001
$len >= $size or eval { do { truncate $inRef, $len } }
l!l&&r!l&&!r
010
MC/DC0%0/6
seek $inRef, 0, 2 and ($size = tell $inRef) >= 0 and seek $inRef, 0, 0 and print $inRef $outBuff and $len >= $size || eval { do { truncate $inRef, $len } }
seek $inRef, 0, 2 ($size = tell $inRef) >= 0 seek $inRef, 0, 0 print $inRef $outBuff $len >= $size eval { do { truncate $inRef, $len } }
Truth table14%1/7
A and B and C and D and E or F
A= seek $inRef, 0, 2B= ($size = tell $inRef) >= 0C= seek $inRef, 0, 0D= print $inRef $outBuffE= $len >= $sizeF= eval { do { truncate $inRef, $len } }
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
1111000
11111X1
1111011
2613 } else {
2614 0 $$inRef = $outBuff; # replace original data
2615 }
2616 1 $outBuff = ''; # free memory but leave $outBuff defined
2617 }
2618 # close input file if we opened it
2619 244 ▶ if ($closeIn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closeIn) 215 29 244
2620 # errors on input file are significant if we edited the file in place
2621 215 ▶ $rtnVal and $rtnVal = -1 unless close($inRef) or not defined $outBuff;
Branch: 1 branch
BranchTrueFalseTotal
unless close $inRef or not defined $outBuff 0 215 215
Condition22%2/9
close $inRef || !defined($outBuff) || $rtnVal && ($rtnVal = -1)
l!l&&r!l&&!r
21500
close $inRef or not defined $outBuff
l!l&&r!l&&!r
21500
$rtnVal and $rtnVal = -1
!ll&&!rl&&r
000
MC/DC0%0/4
close $inRef || !defined($outBuff) || $rtnVal && ($rtnVal = -1)
close $inRef not defined $outBuff $rtnVal $rtnVal = -1
Truth table20%1/5
A or not(B) || C and D
A= close $inRefB= not defined $outBuffC= $rtnValD= $rtnVal = -1
ABCDresult
1XXX1
01XX1
00111
000X0
00100
2622 215 ▶ if ($rtnVal > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtnVal > 0) 215 0 215
2623 # copy Mac OS resource fork if it exists
2624 215 ▶ if ($^O eq 'darwin' and -s "$infile/..namedfork/rsrc") {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "darwin" and -s "$infile/..namedfork/rsrc") 0 215 215
Condition33%1/3
$^O eq "darwin" and -s "$infile/..namedfork/rsrc"
!ll&&!rl&&r
21500
MC/DC0%0/2
$^O eq "darwin" and -s "$infile/..namedfork/rsrc"
$^O eq "darwin" -s "$infile/..namedfork/rsrc"
Truth table33%1/3
A and B
A= $^O eq "darwin"B= -s "$infile/..namedfork/rsrc"
ABresult
0X0
100
111
2625 0 ▶ if ($$self{DEL_GROUP}{RSRC}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'DEL_GROUP'}{'RSRC'}) { } 0 0 0
2626 0 $self->VPrint(0,"Deleting Mac OS resource fork\n");
2627 0 ++$$self{CHANGED};
2628 } else {
2629 0 $self->VPrint(0,"Copying Mac OS resource fork\n");
2630 0 my ($buf, $err);
2631 0 local (*SRC, *DST);
2632 0 ▶ if ($self->Open(\*SRC, "$infile/..namedfork/rsrc")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Open(\*SRC, "$infile/..namedfork/rsrc")) { } 0 0 0
2633 0 ▶ if ($self->Open(\*DST, "$outfile/..namedfork/rsrc", '>')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Open(\*DST, "$outfile/..namedfork/rsrc", '>')) { } 0 0 0
2634 0 binmode SRC; # (not necessary for Darwin, but let's be thorough)
2635 0 binmode DST;
2636 0 ▶ while (read SRC, $buf, 65536) {
Branch: 1 branch
BranchTrueFalseTotal
if (read SRC, $buf, 65536) 0 0 0
2637 0 ▶ print DST $buf or $err = 'copying', last;
Branch: 1 branch
BranchTrueFalseTotal
print DST $buf or $err = "copying", last 0 0 0
2638 }
2639 0 ▶ close DST or $err or $err = 'closing';
Branch: 1 branch
BranchTrueFalseTotal
close DST or $err or $err = "closing" 0 0 0
Condition0%0/3
close DST or $err
l!l&&r!l&&!r
000
MC/DC0%0/2
close DST or $err
close DST $err
Truth table0%0/3
A or B
A= close DSTB= $err
ABresult
1X1
011
000
2640 } else {
2641 # (this is normal if the destination filesystem isn't Mac OS)
2642 0 $self->Warn('Error creating Mac OS resource fork');
2643 }
2644 0 close SRC;
2645 } else {
2646 0 $err = 'opening';
2647 }
2648 0 ▶ $rtnVal = 0 if $err and $self->Error("Error $err Mac OS resource fork", 2);
Branch: 1 branch
BranchTrueFalseTotal
if $err and $self->Error("Error $err Mac OS resource fork", 2) 0 0 0
Condition0%0/3
$err and $self->Error("Error $err Mac OS resource fork", 2)
!ll&&!rl&&r
000
MC/DC0%0/2
$err and $self->Error("Error $err Mac OS resource fork", 2)
$err $self->Error("Error $err Mac OS resource fork", 2)
Truth table0%0/3
A and B
A= $errB= $self->Error("Error $err Mac OS resource fork", 2)
ABresult
0X0
100
111
2649 }
2650 }
2651 # erase input file if renaming while editing information in place
2652 215 ▶ $self->Unlink($infile) or $self->Warn('Error erasing original file') if $eraseIn;
Branch: 1 branch
BranchTrueFalseTotal
if $eraseIn 0 215 215
Condition16%1/6
$eraseIn && ($self->Unlink($infile) || $self->Warn('Error erasing original file'))
!ll
21500
$self->Unlink($infile) or $self->Warn("Error erasing original file")
l!l&&r!l&&!r
000
MC/DC0%0/3
$eraseIn && ($self->Unlink($infile) || $self->Warn('Error erasing original file'))
$eraseIn $self->Unlink($infile) $self->Warn("Error erasing original file")
Truth table0%0/4
A && B or C
A= $eraseInB= $self->Unlink($infile)C= $self->Warn("Error erasing original file")
ABCresult
0XX0
1000
11X1
1011
2653 }
2654 }
2655 # close output file if we created it
2656 244 ▶ if ($closeOut) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closeOut) 230 14 244
2657 # close file and set $rtnVal to -1 if there was an error
2658 230 ▶ $rtnVal and $rtnVal = -1 unless close($outRef);
Branch: 1 branch
BranchTrueFalseTotal
unless close $outRef 0 230 230
Condition16%1/6
close $outRef || $rtnVal && ($rtnVal = -1)
l!l
23000
$rtnVal and $rtnVal = -1
!ll&&!rl&&r
000
MC/DC0%0/3
close $outRef || $rtnVal && ($rtnVal = -1)
close $outRef $rtnVal $rtnVal = -1
Truth table0%0/4
A || B and C
A= close $outRefB= $rtnValC= $rtnVal = -1
ABCresult
1XX1
0111
00X0
0100
2659 # erase the output file if we weren't successful
2660 230 ▶ if ($rtnVal <= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rtnVal <= 0) { } 0 230 230
elsif ($tmpfile) { } 2 228 230
2661 0 $self->Unlink($outfile);
2662 # else rename temporary file if necessary
2663 } elsif ($tmpfile) {
2664 2 $self->CopyFileAttrs($infile, $tmpfile); # copy attributes to new file
2665 2 ▶ unless ($self->Rename($tmpfile, $infile)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->Rename($tmpfile, $infile)) 0 2 2
2666 # some filesystems won't overwrite with 'rename', so try erasing original
2667 0 ▶ if (not $self->Unlink($infile)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->Unlink($infile)) { } 0 0 0
elsif (not $self->Rename($tmpfile, $infile)) { } 0 0 0
2668 0 $self->Unlink($tmpfile);
2669 0 $self->Error('Error renaming temporary file');
2670 0 $rtnVal = 0;
2671 } elsif (not $self->Rename($tmpfile, $infile)) {
2672 0 $self->Error('Error renaming temporary file after deleting original');
2673 0 $rtnVal = 0;
2674 }
2675 }
2676 # the output file should now have the name of the original infile
2677 2 ▶ $outfile = $infile if $rtnVal > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rtnVal > 0 2 0 2
2678 }
2679 }
2680 # set filesystem attributes if requested (and if possible!)
2681 244 ▶ if ($rtnVal > 0 and ($closeOut or (defined $outBuff and ($closeIn or UNIVERSAL::isa($infile,'GLOB'))))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtnVal > 0 and $closeOut || defined $outBuff && ($closeIn || UNIVERSAL::isa($infile, "GLOB"))) 231 13 244
Condition66%8/12
$rtnVal > 0 and $closeOut || defined $outBuff && ($closeIn || UNIVERSAL::isa($infile, "GLOB"))
!ll&&!rl&&r
013231
$closeOut or defined $outBuff and $closeIn || UNIVERSAL::isa($infile, "GLOB")
l!l&&r!l&&!r
230113
defined $outBuff and $closeIn || UNIVERSAL::isa($infile, "GLOB")
!ll&&!rl&&r
1301
$closeIn or UNIVERSAL::isa($infile, "GLOB")
l!l&&r!l&&!r
010
MC/DC40%2/5
$rtnVal > 0 and $closeOut || defined $outBuff && ($closeIn || UNIVERSAL::isa($infile, "GLOB"))
$rtnVal > 0 $closeOut defined $outBuff $closeIn UNIVERSAL::isa($infile, "GLOB")
Truth table50%3/6
A and B or C and D or E
A= $rtnVal > 0B= $closeOutC= defined $outBuffD= $closeInE= UNIVERSAL::isa($infile, "GLOB")
ABCDEresult
0XXXX0
100XX0
101000
11XXX1
1011X1
101011
2682 231 ▶ my $target = $closeOut ? $outfile : $infile;
Branch: 1 branch
BranchTrueFalseTotal
$closeOut ? : 230 1 231
2683 # set file permissions if requested
2684 231 ▶ ++$$self{CHANGED} if $self->SetSystemTags($target) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->SetSystemTags($target) > 0 0 231 231
2685 231 ▶ if ($closeIn) { # (no use setting file times unless the input file is closed)
Branch: 1 branch
BranchTrueFalseTotal
if ($closeIn) 206 25 231
2686 206 ▶ ++$$self{CHANGED} if $setModDate and $self->SetFileModifyDate($target, $originalTime, undef, 1) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $setModDate and $self->SetFileModifyDate($target, $originalTime, undef, 1) > 0 0 206 206
Condition33%1/3
$setModDate and $self->SetFileModifyDate($target, $originalTime, undef, 1) > 0
!ll&&!rl&&r
20600
MC/DC0%0/2
$setModDate and $self->SetFileModifyDate($target, $originalTime, undef, 1) > 0
$setModDate $self->SetFileModifyDate($target, $originalTime, undef, 1) > 0
Truth table33%1/3
A and B
A= $setModDateB= $self->SetFileModifyDate($target, $originalTime, undef, 1) > 0
ABresult
0X0
100
111
2687 # set FileCreateDate if requested (and if possible!)
2688 206 ▶ ++$$self{CHANGED} if $setCreateDate and $self->SetFileModifyDate($target, $createTime, 'FileCreateDate', 1) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $setCreateDate and $self->SetFileModifyDate($target, $createTime, "FileCreateDate", 1) > 0 0 206 206
Condition33%1/3
$setCreateDate and $self->SetFileModifyDate($target, $createTime, "FileCreateDate", 1) > 0
!ll&&!rl&&r
20600
MC/DC0%0/2
$setCreateDate and $self->SetFileModifyDate($target, $createTime, "FileCreateDate", 1) > 0
$setCreateDate $self->SetFileModifyDate($target, $createTime, "FileCreateDate", 1) > 0
Truth table33%1/3
A and B
A= $setCreateDateB= $self->SetFileModifyDate($target, $createTime, "FileCreateDate", 1) > 0
ABresult
0X0
100
111
2689 # create hard link if requested and no output filename specified (and if possible!)
2690 206 ▶ ++$$self{CHANGED} if defined $hardLink and $self->SetFileName($target, $hardLink, 'HardLink');
Branch: 1 branch
BranchTrueFalseTotal
if defined $hardLink and $self->SetFileName($target, $hardLink, "HardLink") 0 206 206
Condition33%1/3
defined $hardLink and $self->SetFileName($target, $hardLink, "HardLink")
!ll&&!rl&&r
20600
MC/DC0%0/2
defined $hardLink and $self->SetFileName($target, $hardLink, "HardLink")
defined $hardLink $self->SetFileName($target, $hardLink, "HardLink")
Truth table33%1/3
A and B
A= defined $hardLinkB= $self->SetFileName($target, $hardLink, "HardLink")
ABresult
0X0
100
111
2691 206 ▶ ++$$self{CHANGED} if defined $symLink and $self->SetFileName($target, $symLink, 'SymLink');
Branch: 1 branch
BranchTrueFalseTotal
if defined $symLink and $self->SetFileName($target, $symLink, "SymLink") 0 206 206
Condition33%1/3
defined $symLink and $self->SetFileName($target, $symLink, "SymLink")
!ll&&!rl&&r
20600
MC/DC0%0/2
defined $symLink and $self->SetFileName($target, $symLink, "SymLink")
defined $symLink $self->SetFileName($target, $symLink, "SymLink")
Truth table33%1/3
A and B
A= defined $symLinkB= $self->SetFileName($target, $symLink, "SymLink")
ABresult
0X0
100
111
2692 206 ▶ defined $testName and $self->SetFileName($target, $testName, 'Test');
Branch: 1 branch
BranchTrueFalseTotal
defined $testName and $self->SetFileName($target, $testName, "Test") 0 206 206
2693 }
2694 }
2695 # check for write error and set appropriate error message and return value
2696 244 ▶ if ($rtnVal < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rtnVal < 0) { } 0 244 244
elsif ($rtnVal > 0) { } 244 0 244
2697 0 ▶ $self->Error('Error writing output file') unless $$self{VALUE}{Error};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"VALUE"}{"Error"} 0 0 0
2698 0 $rtnVal = 0; # return 0 on failure
2699 } elsif ($rtnVal > 0) {
2700 244 ▶ ++$rtnVal unless $$self{CHANGED};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CHANGED"} 5 239 244
2701 }
2702 # set things back to the way they were
2703 244 $$self{RAF} = $oldRaf;
2704  
2705 244 return $rtnVal;
2706 }
2707  
2708 #------------------------------------------------------------------------------
2709 # Get list of all available tags for specified group
2710 # Inputs: 0) optional group name (or string of names separated by colons)
2711 # Returns: tag list (sorted alphabetically)
2712 # Notes: Can't get tags for specific IFD
2713 sub GetAllTags(;$)
2714 0 ▶{
Subroutine GetAllTags: not called CC=14 SCAR=53.5
Pod documented
2715 0 local $_;
2716 0 my $group = shift;
2717 0 my (%allTags, @groups);
2718 0 ▶ @groups = split ':', $group if $group;
Branch: 1 branch
BranchTrueFalseTotal
if $group 0 0 0
2719  
2720 0 my $et = Image::ExifTool->new;
2721 0 LoadAllTables(); # first load all our tables
2722 0 my @tableNames = keys %allTables;
2723  
2724 # loop through all tables and save tag names to %allTags hash
2725 0 ▶ while (@tableNames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tableNames) 0 0 0
2726 0 my $table = GetTagTable(pop @tableNames);
2727 # generate flattened tag names for structure fields if this is an XMP table
2728 0 ▶ if ($$table{GROUPS} and $$table{GROUPS}{0} eq 'XMP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($table->{"GROUPS"} and $table->{"GROUPS"}{0} eq "XMP") 0 0 0
Condition0%0/3
$table->{"GROUPS"} and $table->{"GROUPS"}{0} eq "XMP"
!ll&&!rl&&r
000
MC/DC0%0/2
$table->{"GROUPS"} and $table->{"GROUPS"}{0} eq "XMP"
$table->{"GROUPS"} $table->{"GROUPS"}{0} eq "XMP"
Truth table0%0/3
A and B
A= $table->{"GROUPS"}B= $table->{"GROUPS"}{0} eq "XMP"
ABresult
0X0
100
111
2729 0 Image::ExifTool::XMP::AddFlattenedTags($table);
2730 }
2731 0 my $tagID;
2732 0 foreach $tagID (TagTableKeys($table)) {
2733 0 my @infoArray = GetTagInfoList($table,$tagID);
2734 0 my $tagInfo;
2735 0 GATInfo: foreach $tagInfo (@infoArray) {
2736 0 my $tag = $$tagInfo{Name};
2737 0 ▶ $tag or warn("no name for tag!\n"), next;
Branch: 1 branch
BranchTrueFalseTotal
$tag or warn("no name for tag!\n"), next 0 0 0
2738 # don't list subdirectories unless they are writable
2739 0 ▶ next if $$tagInfo{SubDirectory} and not $$tagInfo{Writable};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"SubDirectory"} and not $tagInfo->{"Writable"} 0 0 0
Condition0%0/3
$tagInfo->{"SubDirectory"} and not $tagInfo->{"Writable"}
!ll&&!rl&&r
000
MC/DC0%0/2
$tagInfo->{"SubDirectory"} and not $tagInfo->{"Writable"}
$tagInfo->{"SubDirectory"} not $tagInfo->{"Writable"}
Truth table0%0/3
A and not(B)
A= $tagInfo->{"SubDirectory"}B= not $tagInfo->{"Writable"}
ABresult
0X0
100
111
2740 0 ▶ next if $$tagInfo{Hidden}; # ignore hidden tags
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"Hidden"} 0 0 0
2741 0 ▶ if (@groups) {
Branch: 1 branch
BranchTrueFalseTotal
if (@groups) 0 0 0
2742 0 my @tg = $et->GetGroup($tagInfo);
2743 0 foreach $group (@groups) {
2744 0 ▶ next GATInfo unless grep /^$group$/i, @tg;
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$group$/i, @tg 0 0 0
2745 }
2746 }
2747 0 $allTags{$tag} = 1;
2748 }
2749 }
2750 }
2751 0 return sort keys %allTags;
2752 }
2753  
2754 #------------------------------------------------------------------------------
2755 # Get list of all writable tags
2756 # Inputs: 0) optional group name (or names separated by colons)
2757 # Returns: tag list (sorted alphabetically)
2758 sub GetWritableTags(;$)
2759 0 ▶{
Subroutine GetWritableTags: not called CC=17 SCAR=57.2
Pod documented
2760 0 local $_;
2761 0 my $group = shift;
2762 0 my (%writableTags, @groups);
2763 0 ▶ @groups = split ':', $group if $group;
Branch: 1 branch
BranchTrueFalseTotal
if $group 0 0 0
2764  
2765 0 my $et = Image::ExifTool->new;
2766 0 LoadAllTables();
2767 0 my @tableNames = keys %allTables;
2768  
2769 0 ▶ while (@tableNames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tableNames) 0 0 0
2770 0 my $tableName = pop @tableNames;
2771 0 my $table = GetTagTable($tableName);
2772 # generate flattened tag names for structure fields if this is an XMP table
2773 0 ▶ if ($$table{GROUPS} and $$table{GROUPS}{0} eq 'XMP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($table->{"GROUPS"} and $table->{"GROUPS"}{0} eq "XMP") 0 0 0
Condition0%0/3
$table->{"GROUPS"} and $table->{"GROUPS"}{0} eq "XMP"
!ll&&!rl&&r
000
MC/DC0%0/2
$table->{"GROUPS"} and $table->{"GROUPS"}{0} eq "XMP"
$table->{"GROUPS"} $table->{"GROUPS"}{0} eq "XMP"
Truth table0%0/3
A and B
A= $table->{"GROUPS"}B= $table->{"GROUPS"}{0} eq "XMP"
ABresult
0X0
100
111
2774 0 Image::ExifTool::XMP::AddFlattenedTags($table);
2775 }
2776 # attempt to load Write tables if autoloaded
2777 0 my @parts = split(/::/,$tableName);
2778 0 ▶ if (@parts > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts > 3) 0 0 0
2779 0 my $i = $#parts - 1;
2780 0 $parts[$i] = "Write$parts[$i]"; # add 'Write' before class name
2781 0 my $module = join('::',@parts[0..$i]);
2782 0 eval { require $module }; # (fails silently if nothing loaded)
2783 }
2784 0 my $tagID;
2785 0 foreach $tagID (TagTableKeys($table)) {
2786 0 my @infoArray = GetTagInfoList($table,$tagID);
2787 0 my $tagInfo;
2788 0 GWTInfo: foreach $tagInfo (@infoArray) {
2789 0 my $tag = $$tagInfo{Name};
2790 0 ▶ $tag or warn("no name for tag!\n"), next;
Branch: 1 branch
BranchTrueFalseTotal
$tag or warn("no name for tag!\n"), next 0 0 0
2791 0 my $writable = $$tagInfo{Writable};
2792 next unless $writable or ($$table{WRITABLE} and
2793 0 ▶ not defined $writable and not $$tagInfo{SubDirectory});
Branch: 1 branch
BranchTrueFalseTotal
unless $writable or $table->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"} 0 0 0
Condition0%0/9
$writable or $table->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}
l!l&&r!l&&!r
000
$table->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
000
$table->{"WRITABLE"} and not defined $writable
!ll&&!rl&&r
000
MC/DC0%0/4
$writable or $table->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}
$writable $table->{"WRITABLE"} not defined $writable not $tagInfo->{"SubDirectory"}
Truth table0%0/5
A or B and not(C) and not(D)
A= $writableB= $table->{"WRITABLE"}C= not defined $writableD= not $tagInfo->{"SubDirectory"}
ABCDresult
1XXX1
01111
00XX0
010X0
01100
2794 0 ▶ next if $$tagInfo{Hidden}; # ignore hidden tags
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"Hidden"} 0 0 0
2795 0 ▶ if (@groups) {
Branch: 1 branch
BranchTrueFalseTotal
if (@groups) 0 0 0
2796 0 my @tg = $et->GetGroup($tagInfo);
2797 0 foreach $group (@groups) {
2798 0 ▶ next GWTInfo unless grep /^$group$/i, @tg;
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$group$/i, @tg 0 0 0
2799 }
2800 }
2801 0 $writableTags{$tag} = 1;
2802 }
2803 }
2804 }
2805 0 return sort keys %writableTags;
2806 }
2807  
2808 #------------------------------------------------------------------------------
2809 # Get list of all group names
2810 # Inputs: 0) [optional] ExifTool ref, 1) Group family number
2811 # Returns: List of group names (sorted alphabetically)
2812 sub GetAllGroups($;$)
2813 0 ▶{
Subroutine GetAllGroups: not called CC=23 SCAR=61.0
Pod documented
2814 0 local $_;
2815 0 ▶ my $family = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
2816 0 my $self;
2817 0 ▶ ref $family and $self = $family, $family = shift || 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $family and $self = $family, $family = shift() || 0 0 0 0
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
2818  
2819 0 ▶ $family == 3 and return('Doc#', 'Main');
Branch: 1 branch
BranchTrueFalseTotal
$family == 3 and return "Doc#", "Main" 0 0 0
2820 0 ▶ $family == 4 and return('Copy#');
Branch: 1 branch
BranchTrueFalseTotal
$family == 4 and return "Copy#" 0 0 0
2821 0 ▶ $family == 5 and return('[too many possibilities to list]');
Branch: 1 branch
BranchTrueFalseTotal
$family == 5 and return "[too many possibilities to list]" 0 0 0
2822 0 ▶ if ($family == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($family == 6) 0 0 0
2823 0 my $fn = \%Image::ExifTool::Exif::formatNumber;
2824 0 return(sort { $$fn{$a} <=> $$fn{$b} } keys %$fn);
2825 }
2826 0 ▶ $family == 8 and return('File#');
Branch: 1 branch
BranchTrueFalseTotal
$family == 8 and return "File#" 0 0 0
2827  
2828 0 LoadAllTables(); # first load all our tables
2829  
2830 0 my @tableNames = keys %allTables;
2831  
2832 0 my %allGroups;
2833 # add family 1 groups not in tables
2834 61 ▶ no warnings; # (avoid "possible attempt to put comments in qw()")
Subroutine BEGIN: called CC=1 SCAR=0.0
2835 # start with family 1 groups that are missing from the tables
2836 0 ▶ $family == 1 and map { $allGroups{$_} = 1 } qw(Garmin AudioItemList AudioUserData
Branch: 1 branch
BranchTrueFalseTotal
$family == 1 and map {$allGroups{$_} = 1;} "Garmin", "AudioItemList", "AudioUserData", "VideoItemList", "VideoUserData", "Track#Keys", "Track#ItemList", "Track#UserData", "KFIX" 0 0 0
2837 VideoItemList VideoUserData Track#Keys Track#ItemList Track#UserData KFIX);
2838 61 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2839 # loop through all tag tables and get all group names
2840 0 ▶ while (@tableNames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tableNames) 0 0 0
2841 0 my $table = GetTagTable(pop @tableNames);
2842 0 my ($grps, $grp, $tag, $tagInfo);
2843 0 ▶ $allGroups{$grp} = 1 if ($grps = $$table{GROUPS}) and ($grp = $$grps{$family});
Branch: 1 branch
BranchTrueFalseTotal
if $grps = $table->{"GROUPS"} and $grp = $grps->{$family} 0 0 0
Condition0%0/3
$grps = $table->{"GROUPS"} and $grp = $grps->{$family}
!ll&&!rl&&r
000
MC/DC0%0/2
$grps = $table->{"GROUPS"} and $grp = $grps->{$family}
$grps = $table->{"GROUPS"} $grp = $grps->{$family}
Truth table0%0/3
A and B
A= $grps = $table->{"GROUPS"}B= $grp = $grps->{$family}
ABresult
0X0
100
111
2844 0 foreach $tag (TagTableKeys($table)) {
2845 0 my @infoArray = GetTagInfoList($table, $tag);
2846 0 ▶ if ($family == 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($family == 7) { } 0 0 0
2847 0 foreach $tagInfo (@infoArray) {
2848 0 my $id = $$tagInfo{TagID};
2849 0 ▶ if (not defined $id) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $id) { } 0 0 0
elsif ($id =~ /^\d+$/) { } 0 0 0
2850 0 $id = ''; # (just to be safe)
2851 } elsif ($id =~ /^\d+$/) {
2852 0 ▶ $id = sprintf('0x%x', $id) if $self and $$self{OPTIONS}{HexTagIDs};
Branch: 1 branch
BranchTrueFalseTotal
if $self and $self->{"OPTIONS"}{"HexTagIDs"} 0 0 0
Condition0%0/3
$self and $self->{"OPTIONS"}{"HexTagIDs"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self and $self->{"OPTIONS"}{"HexTagIDs"}
$self $self->{"OPTIONS"}{"HexTagIDs"}
Truth table0%0/3
A and B
A= $selfB= $self->{"OPTIONS"}{"HexTagIDs"}
ABresult
0X0
100
111
2853 } else {
2854 0 $id =~ s/([^-_A-Za-z0-9])/sprintf('%.2x',ord $1)/ge;
2855 }
2856 0 $allGroups{'ID-' . $id} = 1;
2857 }
2858 } else {
2859 0 foreach $tagInfo (@infoArray) {
2860 0 ▶ next unless ($grps = $$tagInfo{Groups}) and ($grp = $$grps{$family});
Branch: 1 branch
BranchTrueFalseTotal
unless $grps = $tagInfo->{"Groups"} and $grp = $grps->{$family} 0 0 0
Condition0%0/3
$grps = $tagInfo->{"Groups"} and $grp = $grps->{$family}
!ll&&!rl&&r
000
MC/DC0%0/2
$grps = $tagInfo->{"Groups"} and $grp = $grps->{$family}
$grps = $tagInfo->{"Groups"} $grp = $grps->{$family}
Truth table0%0/3
A and B
A= $grps = $tagInfo->{"Groups"}B= $grp = $grps->{$family}
ABresult
0X0
100
111
2861 0 $allGroups{$grp} = 1;
2862 }
2863 }
2864 }
2865 }
2866 0 delete $allGroups{'*'}; # (not a real group)
2867 0 return sort { lc $a cmp lc $b } keys %allGroups;
2868 }
2869  
2870 #------------------------------------------------------------------------------
2871 # get priority group list for new values
2872 # Inputs: 0) ExifTool object reference
2873 # Returns: List of group names
2874 sub GetNewGroups($)
2875 0 ▶{
Subroutine GetNewGroups: not called CC=1 SCAR=6.9
Pod documented
2876 0 my $self = shift;
2877 0 return @{$$self{WRITE_GROUPS}};
2878 }
2879  
2880 #------------------------------------------------------------------------------
2881 # Get list of all deletable group names
2882 # Returns: List of group names (sorted alphabetically)
2883 sub GetDeleteGroups()
2884 0 ▶{
Subroutine GetDeleteGroups: not called CC=1 SCAR=6.9
Pod documented
2885 0 return sort { lc $a cmp lc $b } @delGroups, @delGroup2;
2886 }
2887  
2888 #------------------------------------------------------------------------------
2889 # Add user-defined tags at run time
2890 # Inputs: 0) destination table name, 1) tagID/tagInfo pairs for tags to add
2891 # Returns: number of tags added
2892 # Notes: will replace existing tags
2893 sub AddUserDefinedTags($%)
2894 2 ▶{
Subroutine AddUserDefinedTags: called CC=4 SCAR=13.9
Pod documented
2895 2 local $_;
2896 2 my ($tableName, %addTags) = @_;
2897 2 ▶ my $table = GetTagTable($tableName) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $table = &GetTagTable($tableName) or return 0 2 0 2
2898 # add tags to writer lookup
2899 2 Image::ExifTool::TagLookup::AddTags(\%addTags, $tableName);
2900 2 my $tagID;
2901 2 my $num = 0;
2902 2 foreach $tagID (keys %addTags) {
2903 2 ▶ next if $specialTags{$tagID};
Branch: 1 branch
BranchTrueFalseTotal
if $Image::ExifTool::specialTags{$tagID} 0 2 2
2904 2 delete $$table{$tagID}; # delete old entry if it existed
2905 2 AddTagToTable($table, $tagID, $addTags{$tagID}, 1);
2906 2 ++$num;
2907 }
2908 2 return $num;
2909 }
2910  
2911 #==============================================================================
2912 # Functions below this are not part of the public API
2913  
2914 #------------------------------------------------------------------------------
2915 # Maintain backward compatibility for old GetNewValues function name
2916 sub GetNewValues($$;$)
2917 0 ▶{
Subroutine GetNewValues: not called CC=1 SCAR=6.9
Pod undocumented
2918 0 my ($self, $tag, $nvHashPt) = @_;
2919 0 return $self->GetNewValue($tag, $nvHashPt);
2920 }
2921  
2922 #------------------------------------------------------------------------------
2923 # Un-escape string according to options settings and clear UTF-8 flag
2924 # Inputs: 0) ExifTool ref, 1) string ref or string ref ref
2925 # Notes: also de-references SCALAR values
2926 sub Sanitize($$)
2927 5467 ▶{
Subroutine Sanitize: called CC=12 SCAR=35.5
Pod undocumented
2928 5467 my ($self, $valPt) = @_;
2929 # de-reference SCALAR references
2930 5467 ▶ $$valPt = $$$valPt if ref $$valPt eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $$valPt eq "SCALAR" 0 5467 5467
2931 # make sure the Perl UTF-8 flag is OFF for the value if perl 5.6 or greater
2932 # (otherwise our byte manipulations get corrupted!!)
2933 # NOTE: Don't use Encode on Windows becase "require Encode" on Windows hangs if cwd is a long path name!!
2934 5467 ▶ if ($] >= 5.006 and ($$self{OPTIONS}{EncodeHangs} or
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.006" and $self->{"OPTIONS"}{"EncodeHangs"} || eval { do { require Encode; &Encode::is_utf8($$valPt) } } || $@) 0 5467 5467
Condition33%3/9
$] >= "5.006" and $self->{"OPTIONS"}{"EncodeHangs"} || eval { do { require Encode; &Encode::is_utf8($$valPt) } } || $@
!ll&&!rl&&r
054670
$self->{"OPTIONS"}{"EncodeHangs"} or eval { do { require Encode; &Encode::is_utf8($$valPt) } } or $@
l!l&&r!l&&!r
005467
$self->{"OPTIONS"}{"EncodeHangs"} or eval { do { require Encode; &Encode::is_utf8($$valPt) } }
l!l&&r!l&&!r
005467
MC/DC0%0/4
$] >= "5.006" and $self->{"OPTIONS"}{"EncodeHangs"} || eval { do { require Encode; &Encode::is_utf8($$valPt) } } || $@
$] >= "5.006" $self->{"OPTIONS"}{"EncodeHangs"} eval { do { require Encode; &Encode::is_utf8($$valPt) } } $@
Truth table20%1/5
A and B or C or D
A= $] >= "5.006"B= $self->{"OPTIONS"}{"EncodeHangs"}C= eval { do { require Encode; &Encode::is_utf8($$valPt) } }D= $@
ABCDresult
0XXX0
10000
11XX1
101X1
10011
2935 5467 eval { require Encode; Encode::is_utf8($$valPt) } or $@))
2936 {
2937 # (SIG handling was added in 10.39. Not sure why, but I've added this to other similar code for 13.02)
2938 0 local $SIG{'__WARN__'} = \&SetWarning;
2939 # repack by hand if Encode isn't available
2940 0 ▶ $$valPt = ($$self{OPTIONS}{EncodeHangs} or $@) ? pack('C*', unpack($] < 5.010000 ?
Branch: 2 branches
BranchTrueFalseTotal
$self->{'OPTIONS'}{'EncodeHangs'} || $@ ? : 0 0 0
$] < 5.01 ? : 0 0 0
Condition0%0/3
$self->{"OPTIONS"}{"EncodeHangs"} or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"OPTIONS"}{"EncodeHangs"} or $@
$self->{"OPTIONS"}{"EncodeHangs"} $@
Truth table0%0/3
A or B
A= $self->{"OPTIONS"}{"EncodeHangs"}B= $@
ABresult
1X1
011
000
2941 'U0C*' : 'C0C*', $$valPt)) : Encode::encode('utf8', $$valPt);
2942 }
2943 # un-escape value if necessary
2944 5467 ▶ if ($$self{OPTIONS}{Escape}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"OPTIONS"}{"Escape"}) 92 5375 5467
2945 # (XMP.pm and HTML.pm were require'd as necessary when option was set)
2946 92 ▶ if ($$self{OPTIONS}{Escape} eq 'XML') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'OPTIONS'}{'Escape'} eq 'XML') { } 0 92 92
elsif ($self->{'OPTIONS'}{'Escape'} eq 'HTML') { } 92 0 92
2947 0 $$valPt = Image::ExifTool::XMP::UnescapeXML($$valPt);
2948 } elsif ($$self{OPTIONS}{Escape} eq 'HTML') {
2949 92 $$valPt = Image::ExifTool::HTML::UnescapeHTML($$valPt, $$self{OPTIONS}{Charset});
2950 }
2951 }
2952 }
2953  
2954 #------------------------------------------------------------------------------
2955 # Apply inverse conversions
2956 # Inputs: 0) ExifTool ref, 1) value, 2) tagInfo (or Struct item) ref,
2957 # 3) tag name, 4) group 1 name, 5) conversion type (or undef),
2958 # 6) [optional] want group ("" for structure field)
2959 # Returns: 0) converted value, 1) error string (or undef on success)
2960 # Notes:
2961 # - uses ExifTool "ConvType" member when conversion type is undef
2962 # - conversion types other than 'ValueConv' and 'PrintConv' are treated as 'Raw'
2963 sub ConvInv($$$$$;$$)
2964 30288 ▶{
Subroutine ConvInv: called CC=71 SCAR=45.3
Pod undocumented
2965 30288 my ($self, $val, $tagInfo, $tag, $wgrp1, $convType, $wantGroup) = @_;
2966 30288 my ($err, $type);
2967  
2968 30288 ▶ $convType or $convType = $$self{ConvType} || 'PrintConv';
Branch: 1 branch
BranchTrueFalseTotal
$convType or $convType = $self->{"ConvType"} || "PrintConv" 30218 70 30288
Condition50%1/2
$self->{'ConvType'} || 'PrintConv'
l!l
700
MC/DC0%0/1
$self->{'ConvType'} || 'PrintConv'
$self->{'ConvType'}
Truth table50%1/2
A
A= $self->{'ConvType'}
Aresult
11
00
2969  
2970 30288 Conv: for (;;) {
2971 77192 ▶ if (not defined $type) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $type) { } 30288 46904 77192
elsif ($type eq 'PrintConv') { } 22727 24177 46904
2972 # split value into list if necessary
2973 30288 ▶ if ($$tagInfo{List}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"List"}) 600 29688 30288
2974 600 ▶ my $listSplit = $$tagInfo{AutoSplit} || $$self{OPTIONS}{ListSplit};
Condition100%3/3
$tagInfo->{'AutoSplit'} || $self->{'OPTIONS'}{'ListSplit'}
l!l&&r!l&&!r
5918523
MC/DC100%2/2
$tagInfo->{'AutoSplit'} || $self->{'OPTIONS'}{'ListSplit'}
$tagInfo->{'AutoSplit'} $self->{'OPTIONS'}{'ListSplit'}
Truth table100%3/3
A || B
A= $tagInfo->{'AutoSplit'}B= $self->{'OPTIONS'}{'ListSplit'}
ABresult
1X1
011
000
2975 600 ▶ if (defined $listSplit and not $$tagInfo{Struct} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $listSplit and not $tagInfo->{"Struct"} and $wantGroup || !defined($wantGroup)) 75 525 600
Condition77%7/9
defined $listSplit and not $tagInfo->{"Struct"} and $wantGroup || !defined($wantGroup)
!ll&&!rl&&r
525075
defined $listSplit and not $tagInfo->{"Struct"}
!ll&&!rl&&r
523275
$wantGroup or not defined $wantGroup
l!l&&r!l&&!r
9660
MC/DC50%2/4
defined $listSplit and not $tagInfo->{"Struct"} and $wantGroup || !defined($wantGroup)
defined $listSplit not $tagInfo->{"Struct"} $wantGroup not defined $wantGroup
Truth table80%4/5
A and not(B) and C or not(D)
A= defined $listSplitB= not $tagInfo->{"Struct"}C= $wantGroupD= not defined $wantGroup
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2976 ($wantGroup or not defined $wantGroup))
2977 {
2978 75 ▶ $listSplit = ',?\s+' if $listSplit eq '1' and $$tagInfo{AutoSplit};
Branch: 1 branch
BranchTrueFalseTotal
if $listSplit eq 1 and $tagInfo->{"AutoSplit"} 59 16 75
Condition66%2/3
$listSplit eq 1 and $tagInfo->{"AutoSplit"}
!ll&&!rl&&r
16059
MC/DC50%1/2
$listSplit eq 1 and $tagInfo->{"AutoSplit"}
$listSplit eq 1 $tagInfo->{"AutoSplit"}
Truth table66%2/3
A and B
A= $listSplit eq 1B= $tagInfo->{"AutoSplit"}
ABresult
0X0
100
111
2979 75 my @splitVal = split /$listSplit/, $val, -1;
2980 75 ▶ $val = @splitVal > 1 ? \@splitVal : @splitVal ? $splitVal[0] : '';
Branch: 2 branches
BranchTrueFalseTotal
@splitVal > 1 ? : 34 41 75
@splitVal ? : 41 0 41
2981 }
2982 }
2983 30288 $type = $convType;
2984 } elsif ($type eq 'PrintConv') {
2985 22727 $type = 'ValueConv';
2986 } else {
2987 # split raw value if necessary
2988 24177 ▶ if ($$tagInfo{RawJoin} and $$tagInfo{List} and not ref $val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"RawJoin"} and $tagInfo->{"List"} and not ref $val) 13 24164 24177
Condition66%4/6
$tagInfo->{"RawJoin"} and $tagInfo->{"List"} and not ref $val
!ll&&!rl&&r
24164013
$tagInfo->{"RawJoin"} and $tagInfo->{"List"}
!ll&&!rl&&r
24164013
MC/DC33%1/3
$tagInfo->{"RawJoin"} and $tagInfo->{"List"} and not ref $val
$tagInfo->{"RawJoin"} $tagInfo->{"List"} not ref $val
Truth table50%2/4
A and B and not(C)
A= $tagInfo->{"RawJoin"}B= $tagInfo->{"List"}C= not ref $val
ABCresult
0XX0
10X0
1100
1111
2989 13 my @splitVal = split ' ', $val;
2990 13 ▶ $val = \@splitVal if @splitVal > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @splitVal > 1 13 0 13
2991 }
2992 # finally, do our value check
2993 24177 my ($err2, $v);
2994 24177 ▶ if ($$tagInfo{WriteCheck}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"WriteCheck"}) 296 23881 24177
2995 #### eval WriteCheck ($self, $tagInfo, $val)
2996 296 $err2 = eval $$tagInfo{WriteCheck};
2997 296 ▶ $@ and warn($@), $err2 = 'Error evaluating WriteCheck';
Branch: 1 branch
BranchTrueFalseTotal
$@ and warn($@), $err2 = "Error evaluating WriteCheck" 0 296 296
2998 }
2999 24177 ▶ unless (defined $err2) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $err2) 24135 42 24177
3000 24135 my $table = $$tagInfo{Table};
3001 24135 ▶ if ($table and $$table{CHECK_PROC} and not $$tagInfo{RawConvInv}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table and $table->{"CHECK_PROC"} and not $tagInfo->{"RawConvInv"}) 23193 942 24135
Condition100%6/6
$table and $table->{"CHECK_PROC"} and not $tagInfo->{"RawConvInv"}
!ll&&!rl&&r
72321923193
$table and $table->{"CHECK_PROC"}
!ll&&!rl&&r
6865523412
MC/DC100%3/3
$table and $table->{"CHECK_PROC"} and not $tagInfo->{"RawConvInv"}
$table $table->{"CHECK_PROC"} not $tagInfo->{"RawConvInv"}
Truth table100%4/4
A and B and not(C)
A= $tableB= $table->{"CHECK_PROC"}C= not $tagInfo->{"RawConvInv"}
ABCresult
0XX0
10X0
1100
1111
3002 23193 my $checkProc = $$table{CHECK_PROC};
3003 23193 ▶ if (ref $val eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'ARRAY') { } 47 23146 23193
3004 # loop through array values
3005 47 foreach $v (@$val) {
3006 139 $err2 = &$checkProc($self, $tagInfo, \$v, $convType);
3007 139 ▶ last if $err2;
Branch: 1 branch
BranchTrueFalseTotal
if $err2 0 139 139
3008 }
3009 } else {
3010 23146 $err2 = &$checkProc($self, $tagInfo, \$val, $convType);
3011 }
3012 }
3013 }
3014 24177 ▶ if (defined $err2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err2) 3816 20361 24177
3015 3816 ▶ if ($err2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err2) { } 3808 8 3816
3016 3808 $err = "$err2 for $wgrp1:$tag";
3017 3808 $self->VPrint(2, "$err\n");
3018 3808 undef $val; # value was invalid
3019 } else {
3020 8 $err = $err2; # empty error (quietly don't write tag)
3021 }
3022 }
3023 24177 last;
3024 }
3025 53015 my $conv = $$tagInfo{$type};
3026 53015 my $convInv = $$tagInfo{"${type}Inv"};
3027 # nothing to do at this level if no conversion defined
3028 53015 ▶ next unless defined $conv or defined $convInv;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conv or defined $convInv 29155 23860 53015
Condition100%3/3
defined $conv or defined $convInv
l!l&&r!l&&!r
2339746329155
MC/DC100%2/2
defined $conv or defined $convInv
defined $conv defined $convInv
Truth table100%3/3
A or B
A= defined $convB= defined $convInv
ABresult
1X1
011
000
3029  
3030 23860 my (@valList, $index, $convList, $convInvList);
3031 23860 ▶ if (ref $val eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq 'ARRAY') { } 12 23848 23860
elsif (ref $conv eq 'ARRAY' or ref $convInv eq 'ARRAY') { } 153 23695 23848
3032 # handle ValueConv of ListSplit and AutoSplit values
3033 12 @valList = @$val;
3034 12 $val = $valList[$index = 0];
3035 ▶ } elsif (ref $conv eq 'ARRAY' or ref $convInv eq 'ARRAY') {
Condition66%2/3
ref $conv eq "ARRAY" or ref $convInv eq "ARRAY"
l!l&&r!l&&!r
153023695
MC/DC50%1/2
ref $conv eq "ARRAY" or ref $convInv eq "ARRAY"
ref $conv eq "ARRAY" ref $convInv eq "ARRAY"
Truth table66%2/3
A or B
A= ref $conv eq "ARRAY"B= ref $convInv eq "ARRAY"
ABresult
1X1
011
000
3036 # handle conversion lists
3037 153 @valList = split /$listSep{$type}/, $val;
3038 153 $val = $valList[$index = 0];
3039 153 ▶ if (ref $conv eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $conv eq "ARRAY") 153 0 153
3040 153 $convList = $conv;
3041 153 $conv = $$conv[0];
3042 }
3043 153 ▶ if (ref $convInv eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $convInv eq "ARRAY") 30 123 153
3044 30 $convInvList = $convInv;
3045 30 $convInv = $$convInv[0];
3046 }
3047 }
3048 # loop through multiple values if necessary
3049 23860 for (;;) {
3050 23912 ▶ if ($convInv) {
Branch: 2 branches
BranchTrueFalseTotal
if ($convInv) { } 13995 9917 23912
elsif ($conv) { } 9914 3 9917
3051 # capture eval warnings too
3052 13995 local $SIG{'__WARN__'} = \&SetWarning;
3053 13995 undef $evalWarning;
3054 13995 ▶ if (ref($convInv) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $convInv eq 'CODE') { } 196 13799 13995
3055 196 $val = &$convInv($val, $self);
3056 } else {
3057 #### eval PrintConvInv/ValueConvInv ($val, $self, $wantGroup)
3058 13799 $val = eval $convInv;
3059 13799 ▶ $@ and $evalWarning = $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and $Image::ExifTool::evalWarning = $@ 199 13600 13799
3060 }
3061 13995 ▶ if ($evalWarning) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Image::ExifTool::evalWarning) { } 227 13768 13995
elsif (not defined $val) { } 137 13631 13768
3062 # an empty warning ("\n") ignores tag with no error
3063 227 ▶ if ($evalWarning eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::evalWarning eq "\n") { } 10 217 227
3064 10 ▶ $err = '' unless defined $err;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $err 10 0 10
3065 } else {
3066 217 $err = CleanWarning() . " in $wgrp1:$tag (${type}Inv)";
3067 217 $self->VPrint(2, "$err\n");
3068 }
3069 227 undef $val;
3070 227 last Conv;
3071 } elsif (not defined $val) {
3072 137 $err = "Error converting value for $wgrp1:$tag (${type}Inv)";
3073 137 $self->VPrint(2, "$err\n");
3074 137 last Conv;
3075 }
3076 } elsif ($conv) {
3077 9914 ▶ if (ref $conv eq 'HASH' and (not exists $$tagInfo{"${type}Inv"} or $convInvList)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $conv eq 'HASH' and !exists($$tagInfo{"${type}Inv"}) || $convInvList) { } 9603 311 9914
elsif (not $tagInfo->{'WriteAlso'}) { } 288 23 311
Condition66%4/6
ref $conv eq "HASH" and !exists($$tagInfo{"${type}Inv"}) || $convInvList
!ll&&!rl&&r
31109603
not exists $$tagInfo{"${type}Inv"} or $convInvList
l!l&&r!l&&!r
959850
MC/DC33%1/3
ref $conv eq "HASH" and !exists($$tagInfo{"${type}Inv"}) || $convInvList
ref $conv eq "HASH" not exists $$tagInfo{"${type}Inv"} $convInvList
Truth table75%3/4
A and not(B) or C
A= ref $conv eq "HASH"B= not exists $$tagInfo{"${type}Inv"}C= $convInvList
ABCresult
0XX0
1000
11X1
1011
3078 9603 my ($multi, $lc);
3079 # insert alternate language print conversions if required
3080 9603 ▶ if ($$self{CUR_LANG} and $type eq 'PrintConv' and
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CUR_LANG"} and $type eq "PrintConv" and ref($lc = $self->{"CUR_LANG"}{$tag}) eq "HASH" and $lc = $lc->{"PrintConv"}) 0 9603 9603
Condition33%3/9
$self->{"CUR_LANG"} and $type eq "PrintConv" and ref($lc = $self->{"CUR_LANG"}{$tag}) eq "HASH" and $lc = $lc->{"PrintConv"}
!ll&&!rl&&r
960300
$self->{"CUR_LANG"} and $type eq "PrintConv" and ref($lc = $self->{"CUR_LANG"}{$tag}) eq "HASH"
!ll&&!rl&&r
960300
$self->{"CUR_LANG"} and $type eq "PrintConv"
!ll&&!rl&&r
960300
MC/DC0%0/4
$self->{"CUR_LANG"} and $type eq "PrintConv" and ref($lc = $self->{"CUR_LANG"}{$tag}) eq "HASH" and $lc = $lc->{"PrintConv"}
$self->{"CUR_LANG"} $type eq "PrintConv" ref($lc = $self->{"CUR_LANG"}{$tag}) eq "HASH" $lc = $lc->{"PrintConv"}
Truth table20%1/5
A and B and C and D
A= $self->{"CUR_LANG"}B= $type eq "PrintConv"C= ref($lc = $self->{"CUR_LANG"}{$tag}) eq "HASH"D= $lc = $lc->{"PrintConv"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3081 ref($lc = $$self{CUR_LANG}{$tag}) eq 'HASH' and
3082 ($lc = $$lc{PrintConv}))
3083 {
3084 0 my %newConv;
3085 0 foreach (keys %$conv) {
3086 0 my $val = $$conv{$_};
3087 0 ▶ defined $$lc{$val} or $newConv{$_} = $val, next;
Branch: 1 branch
BranchTrueFalseTotal
defined $lc->{$val} or $newConv{$_} = $val, next 0 0 0
3088 0 $newConv{$_} = $self->Decode($$lc{$val}, 'UTF8');
3089 }
3090 0 ▶ if ($$conv{BITMASK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conv->{"BITMASK"}) 0 0 0
3091 0 foreach (keys %{$$conv{BITMASK}}) {
3092 0 my $val = $$conv{BITMASK}{$_};
3093 0 ▶ defined $$lc{$val} or $newConv{BITMASK}{$_} = $val, next;
Branch: 1 branch
BranchTrueFalseTotal
defined $lc->{$val} or $newConv{"BITMASK"}{$_} = $val, next 0 0 0
3094 0 $newConv{BITMASK}{$_} = $self->Decode($$lc{$val}, 'UTF8');
3095 }
3096 }
3097 0 $conv = \%newConv;
3098 }
3099 9603 undef $evalWarning;
3100 9603 ▶ if ($$conv{BITMASK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conv->{'BITMASK'}) { } 105 9498 9603
3101 105 my $lookupBits = $$conv{BITMASK};
3102 105 my ($wbits, $tbits) = @$tagInfo{'BitsPerWord','BitsTotal'};
3103 105 my ($val2, $err2) = EncodeBits($val, $lookupBits, $wbits, $tbits);
3104 105 ▶ if ($err2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($err2) { } 2 103 105
elsif (defined $val2) { } 72 31 103
3105 # ok, try matching a straight value
3106 2 ($val, $multi) = ReverseLookup($val, $conv);
3107 2 ▶ unless (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 2 0 2
3108 2 $err = "Can't encode $wgrp1:$tag ($err2)";
3109 2 $self->VPrint(2, "$err\n");
3110 2 last Conv;
3111 }
3112 } elsif (defined $val2) {
3113 72 $val = $val2;
3114 } else {
3115 31 delete $$conv{BITMASK};
3116 31 ($val, $multi) = ReverseLookup($val, $conv);
3117 31 $$conv{BITMASK} = $lookupBits;
3118 }
3119 } else {
3120 9498 ($val, $multi) = ReverseLookup($val, $conv);
3121 }
3122 9601 ▶ if (not defined $val) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $val) { } 5457 4144 9601
elsif ($Image::ExifTool::evalWarning) { } 0 4144 4144
3123 5457 ▶ my $prob = $evalWarning ? lcfirst CleanWarning() : ($multi ? 'matches more than one ' : 'not in ') . $type;
Branch: 2 branches
BranchTrueFalseTotal
$Image::ExifTool::evalWarning ? : 0 5457 5457
$multi ? : 3555 1902 5457
3124 5457 $err = "Can't convert $wgrp1:$tag ($prob)";
3125 5457 $self->VPrint(2, "$err\n");
3126 5457 last Conv;
3127 } elsif ($evalWarning) {
3128 0 $self->VPrint(2, CleanWarning() . " for $wgrp1:$tag\n");
3129 }
3130 } elsif (not $$tagInfo{WriteAlso}) {
3131 288 $err = "Can't convert value for $wgrp1:$tag (no ${type}Inv)";
3132 288 $self->VPrint(2, "$err\n");
3133 288 undef $val;
3134 288 last Conv;
3135 }
3136 }
3137 17801 ▶ last unless @valList;
Branch: 1 branch
BranchTrueFalseTotal
unless @valList 17677 124 17801
3138 124 $valList[$index] = $val;
3139 124 ▶ if (++$index >= @valList) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$index >= @valList) 72 52 124
3140 # leave AutoSplit lists in ARRAY form, or join conversion lists
3141 72 ▶ $val = $$tagInfo{List} ? \@valList : join ' ', @valList;
Branch: 1 branch
BranchTrueFalseTotal
$tagInfo->{'List'} ? : 12 60 72
3142 72 last;
3143 }
3144 52 ▶ $conv = $$convList[$index] if $convList;
Branch: 1 branch
BranchTrueFalseTotal
if $convList 16 36 52
3145 52 ▶ $convInv = $$convInvList[$index] if $convInvList;
Branch: 1 branch
BranchTrueFalseTotal
if $convInvList 11 41 52
3146 52 $val = $valList[$index];
3147 }
3148 } # end ValueConv/PrintConv loop
3149  
3150 30288 return($val, $err);
3151 }
3152  
3153 #------------------------------------------------------------------------------
3154 # Dereference value and push onto list
3155 # Inputs: 0) ExifTool ref, 1) value, 2) list ref, 3) flag to push MissingTagValue for undef value
3156 sub PushValue($$$;$)
3157 21 ▶{
Subroutine PushValue: called CC=12 SCAR=34.0
Pod undocumented
3158 21 local $_;
3159 21 my ($self, $val, $list, $missing) = @_;
3160 21 ▶ if (ref $val eq 'ARRAY' and ref $$val[0] ne 'HASH') {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $val eq 'ARRAY' and ref $val->[0] ne 'HASH') { } 1 20 21
elsif (ref $val eq 'SCALAR') { } 0 20 20
elsif (ref $val eq 'HASH' or ref $val eq 'ARRAY') { } 0 20 20
elsif (not defined $val) { } 1 19 20
Condition66%2/3
ref $val eq "ARRAY" and ref $val->[0] ne "HASH"
!ll&&!rl&&r
2001
MC/DC50%1/2
ref $val eq "ARRAY" and ref $val->[0] ne "HASH"
ref $val eq "ARRAY" ref $val->[0] ne "HASH"
Truth table66%2/3
A and B
A= ref $val eq "ARRAY"B= ref $val->[0] ne "HASH"
ABresult
0X0
100
111
3161 1 $self->PushValue($_, $list, $missing) foreach @$val;
3162 } elsif (ref $val eq 'SCALAR') {
3163 0 ▶ if ($$self{OPTIONS}{Binary} or $$val =~ /^Binary data/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'OPTIONS'}{'Binary'} or $$val =~ /^Binary data/) { } 0 0 0
Condition0%0/3
$self->{"OPTIONS"}{"Binary"} or $$val =~ /^Binary data/
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"OPTIONS"}{"Binary"} or $$val =~ /^Binary data/
$self->{"OPTIONS"}{"Binary"} $$val =~ /^Binary data/
Truth table0%0/3
A or B
A= $self->{"OPTIONS"}{"Binary"}B= $$val =~ /^Binary data/
ABresult
1X1
011
000
3164 0 push @$list, $$val;
3165 } else {
3166 0 push @$list, 'Binary data ' . length($$val) . ' bytes';
3167 }
3168 ▶ } elsif (ref $val eq 'HASH' or ref $val eq 'ARRAY') {
Condition33%1/3
ref $val eq "HASH" or ref $val eq "ARRAY"
l!l&&r!l&&!r
0020
MC/DC0%0/2
ref $val eq "HASH" or ref $val eq "ARRAY"
ref $val eq "HASH" ref $val eq "ARRAY"
Truth table33%1/3
A or B
A= ref $val eq "HASH"B= ref $val eq "ARRAY"
ABresult
1X1
011
000
3169 0 require 'Image/ExifTool/XMPStruct.pl';
3170 0 push @$list, Image::ExifTool::XMP::SerializeStruct($self, $val);
3171 } elsif (not defined $val) {
3172 1 my $mval = $$self{OPTIONS}{MissingTagValue};
3173 1 ▶ push @$list, $mval if $missing and defined $mval;
Branch: 1 branch
BranchTrueFalseTotal
if $missing and defined $mval 0 1 1
Condition33%1/3
$missing and defined $mval
!ll&&!rl&&r
010
MC/DC0%0/2
$missing and defined $mval
$missing defined $mval
Truth table33%1/3
A and B
A= $missingB= defined $mval
ABresult
0X0
100
111
3174 } else {
3175 19 push @$list, $val;
3176 }
3177 }
3178  
3179 #------------------------------------------------------------------------------
3180 # Convert tag names to values or variables in a string
3181 # (eg. '${EXIF:ISO}x $$' --> '100x $' without hash ref, or "$info{'EXIF:ISO'}x $" with)
3182 # Inputs: 0) ExifTool object ref, 1) string with embedded tag names,
3183 # 2) reference to list of found tags or undef to use FOUND_TAGS, 3) Options:
3184 # undef - set missing tags to ''
3185 # 'Error' - issue minor error on missing tag (and return undef if error sent)
3186 # 'Warn' - issue minor warning on missing tag (and return undef if warning sent)
3187 # 'Silent' - just return undef on missing tag (no errors/warnings)
3188 # Hash ref - defined to interpolate as variables in string instead of values
3189 # --> receives tag/value pairs for interpolation of the variables
3190 # 4) document group name if extracting from a specific document
3191 # 5) hash ref to cache tag keys for subsequent calls in document loop
3192 # Returns: string with embedded tag values (or '$info{TAGNAME}' entries with Hash ref option)
3193 # Notes:
3194 # - tag names are not case sensitive and may end with '#' for ValueConv value
3195 # - uses MissingTagValue option if set
3196 # - '$GROUP:all' evaluates to 1 if any tag from GROUP exists, or 0 otherwise
3197 # - advanced feature allows Perl expressions inside braces (eg. '${model;tr/ //d}')
3198 # - an error/warning in an advanced expression ("${TAG;EXPR}") generates an error
3199 # if option set to 'Error', or a warning otherwise
3200 sub InsertTagValues($$;$$$$)
3201 10 ▶{
Subroutine InsertTagValues: called CC=99 SCAR=73.1
Pod undocumented
3202 10 local $_;
3203 10 my ($self, $line, $foundTags, $opt, $docGrp, $cache) = @_;
3204 10 my $rtnStr = '';
3205 10 my ($docNum, $tag);
3206  
3207 10 ▶ if ($docGrp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($docGrp) { } 0 10 10
3208 0 ▶ $docNum = $docGrp =~ /(\d+(-\d+)*)$/ ? $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$docGrp =~ /(\d+(-\d+)*)$/ ? : 0 0 0
3209 } else {
3210 10 undef $cache; # no cache if no document groups
3211 }
3212 10 ▶ $foundTags or $foundTags = $$self{FOUND_TAGS} || [];
Branch: 1 branch
BranchTrueFalseTotal
$foundTags or $foundTags = $self->{"FOUND_TAGS"} || [] 10 0 10
Condition0%0/2
$self->{'FOUND_TAGS'} || []
l!l
00
MC/DC0%0/1
$self->{'FOUND_TAGS'} || []
$self->{'FOUND_TAGS'}
Truth table0%0/2
A
A= $self->{'FOUND_TAGS'}
Aresult
11
00
3213 10 ▶ while ($line =~ s/(.*?)\$(\{\s*)?([-\w]*\w|\$|\/)//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s[(.*?)\$(\{\s*)?([-\w]*\w|\$|/)][]s) 14 10 24
3214 14 my ($pre, $bra, $var) = ($1, $2, $3);
3215 14 my (@tags, $tg, $val, @val, $type, $expr, $didExpr, $level, $asList);
3216 # "$$" represents a "$" symbol, and "$/" is a newline
3217 14 ▶ if ($var eq '$' or $var eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($var eq "\$" or $var eq "/") 0 14 14
Condition33%1/3
$var eq "\$" or $var eq "/"
l!l&&r!l&&!r
0014
MC/DC0%0/2
$var eq "\$" or $var eq "/"
$var eq "\$" $var eq "/"
Truth table33%1/3
A or B
A= $var eq "\$"B= $var eq "/"
ABresult
1X1
011
000
3218 0 ▶ $line =~ s/^\s*\}// if $bra;
Branch: 1 branch
BranchTrueFalseTotal
if $bra 0 0 0
3219 0 ▶ if ($var eq '/') {
Branch: 2 branches
BranchTrueFalseTotal
if ($var eq '/') { } 0 0 0
elsif ($line =~ /^self\b/ and not $rtnStr =~ /\$$/) { } 0 0 0
3220 0 $var = "\n";
3221 ▶ } elsif ($line =~ /^self\b/ and not $rtnStr =~ /\$$/) {
Condition0%0/3
$line =~ /^self\b/ and not $rtnStr =~ /\$$/
!ll&&!rl&&r
000
MC/DC0%0/2
$line =~ /^self\b/ and not $rtnStr =~ /\$$/
$line =~ /^self\b/ not $rtnStr =~ /\$$/
Truth table0%0/3
A and not(B)
A= $line =~ /^self\b/B= not $rtnStr =~ /\$$/
ABresult
0X0
100
111
3222 0 $var = '$$'; # ("$$self{var}" in string)
3223 }
3224 0 $rtnStr .= "$pre$var";
3225 0 next;
3226 }
3227 # allow multiple group names
3228 14 ▶ while ($line =~ /^:([-\w]*\w)(.*)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^:([-\w]*\w)(.*)/s) 9 14 23
3229 9 my $group = $var;
3230 9 ($var, $line) = ($1, $2);
3231 9 $var = "$group:$var";
3232 }
3233 # allow trailing '#' to indicate ValueConv value
3234 14 ▶ $type = 'ValueConv' if $line =~ s/^#//;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ s/^#// 0 14 14
3235 # special advanced formatting '@' feature to evaluate list values separately
3236 14 ▶ if ($bra and $line =~ s/^\@(#)?//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bra and $line =~ s/^\@(#)?//) 2 12 14
Condition100%3/3
$bra and $line =~ s/^\@(#)?//
!ll&&!rl&&r
662
MC/DC100%2/2
$bra and $line =~ s/^\@(#)?//
$bra $line =~ s/^\@(#)?//
Truth table100%3/3
A and B
A= $braB= $line =~ s/^\@(#)?//
ABresult
0X0
100
111
3237 2 $asList = 1;
3238 2 ▶ $type = 'ValueConv' if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 2 2
3239 }
3240 # remove trailing bracket if there was a leading one
3241 # and extract Perl expression from inside brackets if it exists
3242 14 ▶ if ($bra and $line !~ s/^\s*\}// and $line =~ s/^\s*;\s*(.*?)\s*\}//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bra and not $line =~ s/^\s*\}// and $line =~ s/^\s*;\s*(.*?)\s*\}//s) 4 10 14
Condition83%5/6
$bra and not $line =~ s/^\s*\}// and $line =~ s/^\s*;\s*(.*?)\s*\}//s
!ll&&!rl&&r
1004
$bra and not $line =~ s/^\s*\}//
!ll&&!rl&&r
644
MC/DC66%2/3
$bra and not $line =~ s/^\s*\}// and $line =~ s/^\s*;\s*(.*?)\s*\}//s
$bra not $line =~ s/^\s*\}// $line =~ s/^\s*;\s*(.*?)\s*\}//s
Truth table75%3/4
A and not(B) and C
A= $braB= not $line =~ s/^\s*\}//C= $line =~ s/^\s*;\s*(.*?)\s*\}//s
ABCresult
0XX0
10X0
1100
1111
3243 4 my $part = $1;
3244 4 $expr = '';
3245 4 for ($level=0; ; --$level) {
3246 # increase nesting level for each opening brace
3247 8 ▶ ++$level while $part =~ /\{/g;
Branch: 1 branch
BranchTrueFalseTotal
$part =~ /\{/g and do { ++$level } 4 8 12
3248 8 $expr .= $part;
3249 8 ▶ last unless $level and $line =~ s/^(.*?)\s*\}//s; # get next part
Branch: 1 branch
BranchTrueFalseTotal
unless $level and $line =~ s/^(.*?)\s*\}//s 4 4 8
Condition66%2/3
$level and $line =~ s/^(.*?)\s*\}//s
!ll&&!rl&&r
404
MC/DC50%1/2
$level and $line =~ s/^(.*?)\s*\}//s
$level $line =~ s/^(.*?)\s*\}//s
Truth table66%2/3
A and B
A= $levelB= $line =~ s/^(.*?)\s*\}//s
ABresult
0X0
100
111
3250 4 $part = $1;
3251 4 $expr .= '}'; # this brace was part of the expression
3252 }
3253 # use default Windows filename filter if expression is empty
3254 4 ▶ $expr = 'tr(/\\\\?*:|"<>\\0)()d' unless length $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless length $expr 0 4 4
3255 }
3256 14 push @tags, $var;
3257 14 ExpandShortcuts(\@tags);
3258 14 ▶ @tags or $rtnStr .= $pre, next;
Branch: 1 branch
BranchTrueFalseTotal
@tags or $rtnStr .= $pre, next 14 0 14
3259 # save advanced formatting expression to allow access by user-defined ValueConv
3260 14 $$self{FMT_EXPR} = $expr;
3261  
3262 14 for (;;) {
3263 # temporarily reset ListJoin option if evaluating list values separately
3264 14 my $oldListJoin;
3265 14 ▶ $oldListJoin = $self->Options(ListJoin => undef) if $asList;
Branch: 1 branch
BranchTrueFalseTotal
if $asList 2 12 14
3266 14 $tag = shift @tags;
3267 14 my $lcTag = lc $tag;
3268 14 ▶ if ($cache and $lcTag !~ /(^|:)all$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache and not $lcTag =~ /(^|:)all$/) { } 0 14 14
Condition33%1/3
$cache and not $lcTag =~ /(^|:)all$/
!ll&&!rl&&r
1400
MC/DC0%0/2
$cache and not $lcTag =~ /(^|:)all$/
$cache not $lcTag =~ /(^|:)all$/
Truth table33%1/3
A and not(B)
A= $cacheB= not $lcTag =~ /(^|:)all$/
ABresult
0X0
100
111
3269 # remove group from tag name (but not lower-case version)
3270 0 my $group;
3271 0 ▶ $tag =~ s/^(.*):// and $group = $1;
Branch: 1 branch
BranchTrueFalseTotal
$tag =~ s/^(.*):// and $group = $1 0 0 0
3272 # cache tag keys to speed processing for a large number of sub-documents
3273 # (similar to code in BuildCompositeTags(), but this is case-insensitive)
3274 0 my $cacheTag = $$cache{$lcTag};
3275 0 ▶ unless ($cacheTag) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cacheTag) 0 0 0
3276 0 $cacheTag = $$cache{$lcTag} = { };
3277 # find all matching keys, organize into groups, and store in cache
3278 0 my $ex = $$self{TAG_EXTRA};
3279 0 my @matches = grep /^$tag(\s|$)/i, @$foundTags;
3280 0 ▶ @matches = $self->GroupMatches($group, \@matches) if defined $group;
Branch: 1 branch
BranchTrueFalseTotal
if defined $group 0 0 0
3281 0 foreach (@matches) {
3282 0 ▶ my $doc = $$ex{$_}{G3} || 0;
Condition0%0/2
$ex->{$_}{'G3'} || 0
l!l
00
MC/DC0%0/1
$ex->{$_}{'G3'} || 0
$ex->{$_}{'G3'}
Truth table0%0/2
A
A= $ex->{$_}{'G3'}
Aresult
11
00
3283 0 ▶ if (defined $$cacheTag{$doc}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cacheTag->{$doc}) 0 0 0
3284 0 ▶ next unless $$cacheTag{$doc} =~ / \((\d+)\)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $cacheTag->{$doc} =~ / \((\d+)\)$/ 0 0 0
3285 0 my $cur = $1;
3286 # keep the most recently extracted tag
3287 0 ▶ next if / \((\d+)\)$/ and $1 < $cur;
Branch: 1 branch
BranchTrueFalseTotal
if / \((\d+)\)$/ and $1 < $cur 0 0 0
Condition0%0/3
/ \((\d+)\)$/ and $1 < $cur
!ll&&!rl&&r
000
MC/DC0%0/2
/ \((\d+)\)$/ and $1 < $cur
/ \((\d+)\)$/ $1 < $cur
Truth table0%0/3
A and B
A= / \((\d+)\)$/B= $1 < $cur
ABresult
0X0
100
111
3288 }
3289 0 $$cacheTag{$doc} = $_;
3290 }
3291 }
3292 0 ▶ my $doc = $lcTag =~ /\b(main|doc(\d+(-\d+)*)):/ ? ($2 || 0) : $docNum;
Branch: 1 branch
BranchTrueFalseTotal
$lcTag =~ /\b(main|doc(\d+(-\d+)*)):/ ? : 0 0 0
Condition0%0/2
$2 or 0
l!l
00
MC/DC0%0/1
$2 or 0
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
3293 0 ▶ if ($$cacheTag{$doc}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cacheTag->{$doc}) 0 0 0
3294 0 $tag = $$cacheTag{$doc};
3295 0 $val = $self->GetValue($tag, $type);
3296 }
3297 } else {
3298 # add document number to tag if specified and it doesn't already exist
3299 14 ▶ if ($docGrp and $lcTag !~ /\b(main|doc\d+):/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($docGrp and not $lcTag =~ /\b(main|doc\d+):/) 0 14 14
Condition33%1/3
$docGrp and not $lcTag =~ /\b(main|doc\d+):/
!ll&&!rl&&r
1400
MC/DC0%0/2
$docGrp and not $lcTag =~ /\b(main|doc\d+):/
$docGrp not $lcTag =~ /\b(main|doc\d+):/
Truth table33%1/3
A and not(B)
A= $docGrpB= not $lcTag =~ /\b(main|doc\d+):/
ABresult
0X0
100
111
3300 0 $tag = $docGrp . ':' . $tag;
3301 0 $lcTag = lc $tag;
3302 }
3303 14 my ($et, $fileTags) = ($self, $foundTags);
3304 14 ▶ if ($tag =~ s/(\bfile\d+)://i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ s/(\bfile\d+)://i) 3 11 14
3305 3 $et = $$self{ALT_EXIFTOOL}{ucfirst lc $1};
3306 3 ▶ if ($et) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et) { } 3 0 3
3307 3 $fileTags = $$et{FoundTags};
3308 } else {
3309 0 $et = $self;
3310 0 $tag = 'no_alt_file';
3311 }
3312 }
3313 14 ▶ if ($lcTag eq 'all') {
Branch: 4 branches
BranchTrueFalseTotal
if ($lcTag eq 'all') { } 0 14 14
elsif (defined $et->{'OPTIONS'}{'UserParam'}{$lcTag}) { } 0 14 14
elsif ($tag =~ /(.*):(.+)/) { } 4 10 14
elsif ($tag eq 'self') { } 0 10 10
3314 0 $val = 1; # always some tag available
3315 } elsif (defined $$et{OPTIONS}{UserParam}{$lcTag}) {
3316 0 $val = $$et{OPTIONS}{UserParam}{$lcTag};
3317 } elsif ($tag =~ /(.*):(.+)/) {
3318 4 my ($group, @matches);
3319 4 ($group, $tag) = ($1, $2);
3320 # join values of all matching tags if "All" group is used
3321 # (and remove "All" from group prefix)
3322 4 ▶ if ($group =~ s/(^|:)(all|\*)(:|$)/$1 and $3/ei) {
Branch: 2 branches
BranchTrueFalseTotal
if ($group =~ s/(^|:)(all|\*)(:|$)/$1 and $3;/ie) { } 1 3 4
elsif (lc $tag eq 'all') { } 0 3 3
Condition33%1/3
$1 && $3
!ll&&!rl&&r
010
MC/DC0%0/2
$1 && $3
$1 $3
Truth table33%1/3
A && B
A= $1B= $3
ABresult
0X0
100
111
3323 1 ▶ if (lc $tag eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $tag eq 'all') { } 1 0 1
3324 1 ▶ @matches = $group ? $et->GroupMatches($group, $fileTags) : @$fileTags;
Branch: 1 branch
BranchTrueFalseTotal
$group ? : 1 0 1
3325 } else {
3326 0 @matches = grep /^$tag(\s|$)/i, @$fileTags;
3327 0 ▶ @matches = $et->GroupMatches($group, \@matches) if $group;
Branch: 1 branch
BranchTrueFalseTotal
if $group 0 0 0
3328 }
3329 1 $self->PushValue(scalar $et->GetValue($_, $type), \@val) foreach @matches;
3330 } elsif (lc $tag eq 'all') {
3331 # return "1" if any tag from the specified group exists
3332 0 ▶ $val = $et->GroupMatches($group, $fileTags) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$et->GroupMatches($group, $fileTags) ? : 0 0 0
3333 } else {
3334 # find the specified tag
3335 3 @matches = grep /^$tag(\s|$)/i, @$fileTags;
3336 3 @matches = $et->GroupMatches($group, \@matches);
3337 3 foreach $tg (@matches) {
3338 3 ▶ if (defined $val and $tg =~ / \((\d+)\)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $tg =~ / \((\d+)\)$/) 0 3 3
Condition33%1/3
defined $val and $tg =~ / \((\d+)\)$/
!ll&&!rl&&r
300
MC/DC0%0/2
defined $val and $tg =~ / \((\d+)\)$/
defined $val $tg =~ / \((\d+)\)$/
Truth table33%1/3
A and B
A= defined $valB= $tg =~ / \((\d+)\)$/
ABresult
0X0
100
111
3339 # take the most recently extracted tag
3340 0 my $tagNum = $1;
3341 0 ▶ next if $tag !~ / \((\d+)\)$/ or $1 > $tagNum;
Branch: 1 branch
BranchTrueFalseTotal
if not $tag =~ / \((\d+)\)$/ or $1 > $tagNum 0 0 0
Condition0%0/3
not $tag =~ / \((\d+)\)$/ or $1 > $tagNum
l!l&&r!l&&!r
000
MC/DC0%0/2
not $tag =~ / \((\d+)\)$/ or $1 > $tagNum
not $tag =~ / \((\d+)\)$/ $1 > $tagNum
Truth table0%0/3
not(A) or B
A= not $tag =~ / \((\d+)\)$/B= $1 > $tagNum
ABresult
1X1
011
000
3342 }
3343 3 $val = $et->GetValue($tg, $type);
3344 3 $tag = $tg;
3345 3 ▶ last unless $tag =~ / /; # all done if we got our best match
Branch: 1 branch
BranchTrueFalseTotal
unless $tag =~ / / 2 1 3
3346 }
3347 }
3348 } elsif ($tag eq 'self') {
3349 0 $val = $et; # ("$self{var}" or "$file1:self{var}" in string)
3350 } else {
3351 # get the tag value (note: this direct access allows excluded tags
3352 # to be accessed if the case is correct and a group name is not used)
3353 10 $val = $et->GetValue($tag, $type);
3354 10 ▶ unless (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 7 3 10
3355 # check for tag name with different case
3356 7 ($tg) = grep /^$tag$/i, @$fileTags;
3357 7 ▶ if (defined $tg) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tg) 7 0 7
3358 7 $val = $et->GetValue($tg, $type);
3359 7 $tag = $tg;
3360 }
3361 }
3362 }
3363 }
3364 14 ▶ $self->Options(ListJoin => $oldListJoin) if $asList;
Branch: 1 branch
BranchTrueFalseTotal
if $asList 2 12 14
3365 14 $self->PushValue($val, \@val, $asList);
3366 14 undef $val;
3367 14 ▶ last unless @tags;
Branch: 1 branch
BranchTrueFalseTotal
unless @tags 14 0 14
3368 }
3369 14 ▶ if (@val) {
Branch: 2 branches
BranchTrueFalseTotal
if (@val) { } 14 0 14
elsif (defined $val) { } 0 0 0
3370 14 ▶ $self->PushValue($val, \@val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 14 14
3371 14 $val = join $$self{OPTIONS}{ListSep}, @val;
3372 } elsif (defined $val) {
3373 0 $self->PushValue($val, \@val); # (so the eval has access to @val if required)
3374 }
3375 # evaluate advanced formatting expression if given (eg. "${TAG;EXPR}")
3376 14 ▶ if (defined $expr and defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr and defined $val) 4 10 14
Condition66%2/3
defined $expr and defined $val
!ll&&!rl&&r
1004
MC/DC50%1/2
defined $expr and defined $val
defined $expr defined $val
Truth table66%2/3
A and B
A= defined $exprB= defined $val
ABresult
0X0
100
111
3377 4 local $SIG{'__WARN__'} = \&SetWarning;
3378 4 undef $evalWarning;
3379 4 $advFmtSelf = $self; # set variable for access to $self in helper functions
3380 4 ▶ if ($asList) {
Branch: 1 branch
BranchTrueFalseTotal
if ($asList) { } 2 2 4
3381 2 foreach (@val) {
3382 #### eval advanced formatting expression ($_, $self, @val, $tag, $advFmtSelf)
3383 7 eval $expr;
3384 7 ▶ $@ and $evalWarning = $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and $Image::ExifTool::evalWarning = $@ 0 7 7
3385 }
3386 # join back together if any values are still defined
3387 2 @val = grep defined, @val;
3388 2 ▶ $val = @val ? join $$self{OPTIONS}{ListSep}, @val : undef;
Branch: 1 branch
BranchTrueFalseTotal
@val ? : 2 0 2
3389 } else {
3390 2 $_ = $val;
3391 #### eval advanced formatting expression ($_, $self, @val, $tag, $advFmtSelf)
3392 2 eval $expr;
3393 2 ▶ $@ and $evalWarning = $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and $Image::ExifTool::evalWarning = $@ 0 2 2
3394 2 ▶ $val = ref $_ eq 'ARRAY' ? join($$self{OPTIONS}{ListSep}, @$_): $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 2 2
3395 }
3396 4 ▶ if ($evalWarning) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::evalWarning) 0 4 4
3397 0 ▶ my $g3 = ($docGrp and $var !~ /\b(main|doc\d+):/i) ? $docGrp . ':' : '';
Branch: 1 branch
BranchTrueFalseTotal
$docGrp && !($var =~ /\b(main|doc\d+):/i) ? : 0 0 0
Condition0%0/3
$docGrp and not $var =~ /\b(main|doc\d+):/i
!ll&&!rl&&r
000
MC/DC0%0/2
$docGrp and not $var =~ /\b(main|doc\d+):/i
$docGrp not $var =~ /\b(main|doc\d+):/i
Truth table0%0/3
A and not(B)
A= $docGrpB= not $var =~ /\b(main|doc\d+):/i
ABresult
0X0
100
111
3398 0 my $str = CleanWarning() . " for '$g3${var}'";
3399 0 ▶ if ($opt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt) 0 0 0
3400 0 ▶ if ($opt eq 'Error') {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt eq 'Error') { } 0 0 0
elsif ($opt ne 'Silent') { } 0 0 0
3401 0 $self->Error($str);
3402 } elsif ($opt ne 'Silent') {
3403 0 $self->Warn($str);
3404 }
3405 }
3406 }
3407 4 undef $advFmtSelf;
3408 4 $didExpr = 1; # set flag indicating an expression was evaluated
3409 }
3410 14 ▶ unless (defined $val or (ref $opt and $$self{OPTIONS}{UndefTags})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val or ref $opt and $self->{"OPTIONS"}{"UndefTags"}) 0 14 14
Condition16%1/6
defined $val or ref $opt and $self->{"OPTIONS"}{"UndefTags"}
l!l&&r!l&&!r
1400
ref $opt and $self->{"OPTIONS"}{"UndefTags"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $val or ref $opt and $self->{"OPTIONS"}{"UndefTags"}
defined $val ref $opt $self->{"OPTIONS"}{"UndefTags"}
Truth table25%1/4
A or B and C
A= defined $valB= ref $optC= $self->{"OPTIONS"}{"UndefTags"}
ABCresult
1XX1
0111
00X0
0100
3411 0 $val = $$self{OPTIONS}{MissingTagValue};
3412 0 ▶ unless (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
3413 0 ▶ my $g3 = ($docGrp and $var !~ /\b(main|doc\d+):/i) ? $docGrp . ':' : '';
Branch: 1 branch
BranchTrueFalseTotal
$docGrp && !($var =~ /\b(main|doc\d+):/i) ? : 0 0 0
Condition0%0/3
$docGrp and not $var =~ /\b(main|doc\d+):/i
!ll&&!rl&&r
000
MC/DC0%0/2
$docGrp and not $var =~ /\b(main|doc\d+):/i
$docGrp not $var =~ /\b(main|doc\d+):/i
Truth table0%0/3
A and not(B)
A= $docGrpB= not $var =~ /\b(main|doc\d+):/i
ABresult
0X0
100
111
3414 0 ▶ my $msg = $didExpr ? "Advanced formatting expression returned undef for '$g3${var}'" :
Branch: 1 branch
BranchTrueFalseTotal
$didExpr ? : 0 0 0
3415 "Tag '$g3${var}' not defined";
3416 0 ▶ if (ref $opt) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $opt) { } 0 0 0
elsif ($opt) { } 0 0 0
3417 0 ▶ $val = '' if $$self{OPTIONS}{IgnoreMinorErrors};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"OPTIONS"}{"IgnoreMinorErrors"} 0 0 0
3418 } elsif ($opt) {
3419 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3420 0 ▶ ($opt eq 'Silent' or &$opt($self, $msg, 2)) and return $$self{FMT_EXPR} = undef;
Branch: 1 branch
BranchTrueFalseTotal
$opt eq "Silent" || &$opt($self, $msg, 2) and return $self->{"FMT_EXPR"} = undef 0 0 0
Condition0%0/3
$opt eq "Silent" or &$opt($self, $msg, 2)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt eq "Silent" or &$opt($self, $msg, 2)
$opt eq "Silent" &$opt($self, $msg, 2)
Truth table0%0/3
A or B
A= $opt eq "Silent"B= &$opt($self, $msg, 2)
ABresult
1X1
011
000
3421 0 $val = '';
3422 }
3423 }
3424 }
3425 14 ▶ if (ref $opt eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opt eq 'HASH') { } 0 14 14
3426 0 ▶ $var .= '#' if $type;
Branch: 1 branch
BranchTrueFalseTotal
if $type 0 0 0
3427 0 ▶ if (defined $expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr) 0 0 0
3428 # generate unique variable name for this modified tag value
3429 0 my $i = 1;
3430 0 ▶ ++$i while exists $$opt{"$var.expr$i"};
Branch: 1 branch
BranchTrueFalseTotal
exists $$opt{"$var.expr$i"} and do { ++$i } 0 0 0
3431 0 $var .= '.expr' . $i;
3432 }
3433 0 $rtnStr .= "$pre\$info{'${var}'}";
3434 0 $$opt{$var} = $val;
3435 } else {
3436 14 $rtnStr .= "$pre$val";
3437 }
3438 }
3439 10 $$self{FMT_EXPR} = undef;
3440 10 return $rtnStr . $line;
3441 }
3442  
3443 #------------------------------------------------------------------------------
3444 # Reformat date/time value in $_ based on specified format string
3445 # Inputs: 0) date/time format string
3446 # Returns: Reformatted date/time string
3447 sub DateFmt($)
3448 0 ▶{
Subroutine DateFmt: not called CC=5 SCAR=34.0
Pod undocumented
3449 0 my $et = bless { OPTIONS => { DateFormat => shift, StrictDate => 1 } };
3450 0 my $shift;
3451 0 ▶ if ($advFmtSelf and defined($shift = $$advFmtSelf{OPTIONS}{GlobalTimeShift})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::advFmtSelf and defined($shift = $Image::ExifTool::advFmtSelf->{"OPTIONS"}{"GlobalTimeShift"})) 0 0 0
Condition0%0/3
$Image::ExifTool::advFmtSelf and defined($shift = $Image::ExifTool::advFmtSelf->{"OPTIONS"}{"GlobalTimeShift"})
!ll&&!rl&&r
000
MC/DC0%0/2
$Image::ExifTool::advFmtSelf and defined($shift = $Image::ExifTool::advFmtSelf->{"OPTIONS"}{"GlobalTimeShift"})
$Image::ExifTool::advFmtSelf defined($shift = $Image::ExifTool::advFmtSelf->{"OPTIONS"}{"GlobalTimeShift"})
Truth table0%0/3
A and B
A= $Image::ExifTool::advFmtSelfB= defined($shift = $Image::ExifTool::advFmtSelf->{"OPTIONS"}{"GlobalTimeShift"})
ABresult
0X0
100
111
3452 0 $$et{OPTIONS}{GlobalTimeShift} = $shift;
3453 0 $$et{GLOBAL_TIME_OFFSET} = $$advFmtSelf{GLOBAL_TIME_OFFSET};
3454 }
3455 0 $_ = $et->ConvertDateTime($_);
3456 0 ▶ defined $_ or warn "Error converting date/time\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or warn "Error converting date/time\n" 0 0 0
3457 0 ▶ $$advFmtSelf{GLOBAL_TIME_OFFSET} = $$et{GLOBAL_TIME_OFFSET} if $shift;
Branch: 1 branch
BranchTrueFalseTotal
if $shift 0 0 0
3458 0 return $_;
3459 }
3460  
3461 #------------------------------------------------------------------------------
3462 # Utility routine to remove duplicate items from default input string
3463 # Inputs: 0) true to set $_ to undef if not changed
3464 # Notes: - for use only in advanced formatting expressions
3465 sub NoDups
3466 0 ▶{
Subroutine NoDups: not called CC=4 SCAR=30.0
Pod documented
3467 0 my %seen;
3468 0 ▶ my $sep = $advFmtSelf ? $$advFmtSelf{OPTIONS}{ListSep} : ', ';
Branch: 1 branch
BranchTrueFalseTotal
$Image::ExifTool::advFmtSelf ? : 0 0 0
3469 0 my $new = join $sep, grep { !$seen{$_}++ } split /\Q$sep\E/, $_;
3470 0 ▶ $_ = ($_[0] and $new eq $_) ? undef : $new;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && $new eq $_ ? : 0 0 0
Condition0%0/3
$_[0] and $new eq $_
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and $new eq $_
$_[0] $new eq $_
Truth table0%0/3
A and B
A= $_[0]B= $new eq $_
ABresult
0X0
100
111
3471 }
3472  
3473 #------------------------------------------------------------------------------
3474 # Utility routine to set in $_ image from current object
3475 # Inputs: 0-N) list of tags to copy
3476 # Returns: Return value from WriteInfo
3477 # Notes: - for use only in advanced formatting expressions
3478 sub SetTags(@)
3479 0 ▶{
Subroutine SetTags: not called CC=1 SCAR=6.9
Pod undocumented
3480 0 my $self = $advFmtSelf;
3481 0 my $et = Image::ExifTool->new;
3482 0 $et->SetNewValuesFromFile($self, @_);
3483 0 return $et->WriteInfo(\$_);
3484 }
3485  
3486 #------------------------------------------------------------------------------
3487 # Is specified tag writable
3488 # Inputs: 0) tag name, case insensitive (optional group name currently ignored)
3489 # Returns: 0=exists but not writable, 1=writable, undef=doesn't exist
3490 sub IsWritable($)
3491 0 ▶{
Subroutine IsWritable: not called CC=9 SCAR=42.4
Pod undocumented
3492 0 my $tag = shift;
3493 0 $tag =~ s/^(.*)://; # ignore group name
3494 0 my @tagInfo = FindTagInfo($tag);
3495 0 ▶ unless (@tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@tagInfo) 0 0 0
3496 0 ▶ return 0 if TagExists($tag);
Branch: 1 branch
BranchTrueFalseTotal
if &TagExists($tag) 0 0 0
3497 0 return undef;
3498 }
3499 0 my $tagInfo;
3500 0 foreach $tagInfo (@tagInfo) {
3501 0 ▶ return $$tagInfo{Writable} ? 1 : 0 if defined $$tagInfo{Writable};
Branch: 2 branches
BranchTrueFalseTotal
if defined $tagInfo->{"Writable"} 0 0 0
$tagInfo->{'Writable'} ? : 0 0 0
3502 0 ▶ return 1 if $$tagInfo{Table}{WRITABLE};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"Table"}{"WRITABLE"} 0 0 0
3503 # must call WRITE_PROC to autoload writer because this may set the writable tag
3504 0 my $writeProc = $$tagInfo{Table}{WRITE_PROC};
3505 0 ▶ if ($writeProc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeProc) 0 0 0
3506 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3507 0 &$writeProc(); # dummy call to autoload writer
3508 0 ▶ return 1 if $$tagInfo{Writable};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"Writable"} 0 0 0
3509 }
3510 }
3511 0 return 0;
3512 }
3513  
3514 #------------------------------------------------------------------------------
3515 # Check to see if these are the same file
3516 # Inputs: 0) ExifTool ref, 1) first file name, 2) second file name
3517 # Returns: true if file names reference the same file
3518 sub IsSameFile($$$)
3519 0 ▶{
Subroutine IsSameFile: not called CC=6 SCAR=34.8
Pod undocumented
3520 0 my ($self, $file, $file2) = @_;
3521 0 ▶ return 0 unless lc $file eq lc $file2; # (only looking for differences in case)
Branch: 1 branch
BranchTrueFalseTotal
unless lc $file eq lc $file2 0 0 0
3522 0 my ($isSame, $interrupted);
3523 0 my $tmp1 = "${file}_ExifTool_tmp_$$";
3524 0 my $tmp2 = "${file2}_ExifTool_tmp_$$";
3525 {
3526 0 local *TMP1;
3527 0 ▶ local $SIG{INT} = sub { $interrupted = 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
3528 0 ▶ if ($self->Open(\*TMP1, $tmp1, '>')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Open(\*TMP1, $tmp1, ">")) 0 0 0
3529 0 close TMP1;
3530 0 ▶ $isSame = 1 if $self->Exists($tmp2);
Branch: 1 branch
BranchTrueFalseTotal
if $self->Exists($tmp2) 0 0 0
3531 0 $self->Unlink($tmp1);
3532 }
3533 }
3534 0 ▶ if ($interrupted and $SIG{INT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interrupted and $SIG{"INT"}) 0 0 0
Condition0%0/3
$interrupted and $SIG{"INT"}
!ll&&!rl&&r
000
MC/DC0%0/2
$interrupted and $SIG{"INT"}
$interrupted $SIG{"INT"}
Truth table0%0/3
A and B
A= $interruptedB= $SIG{"INT"}
ABresult
0X0
100
111
3535 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3536 0 &{$SIG{INT}}();
3537 }
3538 0 return $isSame;
3539 }
3540  
3541 #------------------------------------------------------------------------------
3542 # Is this a raw file type?
3543 # Inputs: 0) ExifTool ref
3544 # Returns: true if FileType is a type of RAW image
3545 sub IsRawType($)
3546 13 ▶{
Subroutine IsRawType: called CC=1 SCAR=0.0
Pod undocumented
3547 13 my $self = shift;
3548 13 return $rawType{$$self{FileType}};
3549 }
3550  
3551 #------------------------------------------------------------------------------
3552 # Copy file attributes from one file to another
3553 # Inputs: 0) ExifTool ref, 1) source file name, 2) destination file name
3554 # Notes: eventually add support for extended attributes?
3555 sub CopyFileAttrs($$$)
3556 2 ▶{
Subroutine CopyFileAttrs: called CC=9 SCAR=25.9
Pod undocumented
3557 2 my ($self, $src, $dst) = @_;
3558 2 my ($mode, $uid, $gid) = (stat($src))[2, 4, 5];
3559 # copy file attributes unless we already set them
3560 2 ▶ if (defined $mode and not defined $self->GetNewValue('FilePermissions')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mode and not defined $self->GetNewValue("FilePermissions")) 2 0 2
Condition33%1/3
defined $mode and not defined $self->GetNewValue("FilePermissions")
!ll&&!rl&&r
002
MC/DC0%0/2
defined $mode and not defined $self->GetNewValue("FilePermissions")
defined $mode not defined $self->GetNewValue("FilePermissions")
Truth table33%1/3
A and not(B)
A= defined $modeB= not defined $self->GetNewValue("FilePermissions")
ABresult
0X0
100
111
3561 2 eval { chmod($mode & 07777, $dst) };
3562 }
3563 2 my $newUid = $self->GetNewValue('FileUserID');
3564 2 my $newGid = $self->GetNewValue('FileGroupID');
3565 2 ▶ if (defined $uid and defined $gid and (not defined $newUid or not defined $newGid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uid and defined $gid and not defined $newUid && defined $newGid) 2 0 2
Condition33%3/9
defined $uid and defined $gid and not defined $newUid && defined $newGid
!ll&&!rl&&r
002
defined $uid and defined $gid
!ll&&!rl&&r
002
defined $newUid && defined $newGid
!ll&&!rl&&r
200
MC/DC0%0/4
defined $uid and defined $gid and not defined $newUid && defined $newGid
defined $uid defined $gid defined $newUid defined $newGid
Truth table20%1/5
A and B and not(C && D)
A= defined $uidB= defined $gidC= defined $newUidD= defined $newGid
ABCDresult
0XXX0
10XX0
11110
110X1
11101
3566 2 ▶ defined $newGid and $gid = $newGid;
Branch: 1 branch
BranchTrueFalseTotal
defined $newGid and $gid = $newGid 0 2 2
3567 2 ▶ defined $newUid and $uid = $newUid;
Branch: 1 branch
BranchTrueFalseTotal
defined $newUid and $uid = $newUid 0 2 2
3568 2 eval { chown($uid, $gid, $dst) };
3569 }
3570 }
3571  
3572 #------------------------------------------------------------------------------
3573 # Get new file path name
3574 # Inputs: 0) existing name (may contain directory),
3575 # 1) new file name, new directory, or new path (dir+name)
3576 # Returns: new file path name
3577 sub GetNewFileName($$)
3578 1 ▶{
Subroutine GetNewFileName: called CC=4 SCAR=15.0
Pod undocumented
3579 1 my ($oldName, $newName) = @_;
3580 1 my ($dir, $name) = ($oldName =~ m{(.*/)(.*)});
3581 1 ▶ ($dir, $name) = ('', $oldName) unless defined $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir 0 1 1
3582 1 ▶ if ($newName =~ m{/$}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($newName =~ m[/$]) { } 0 1 1
elsif (not $newName =~ m[/]) { } 1 0 1
3583 0 $newName = "$newName$name"; # change dir only
3584 } elsif ($newName !~ m{/}) {
3585 1 $newName = "$dir$newName"; # change name only if newname doesn't specify dir
3586 } # else change dir and name
3587 1 return $newName;
3588 }
3589  
3590 #------------------------------------------------------------------------------
3591 # Get next available tag key
3592 # Inputs: 0) hash reference (keys are tag keys), 1) tag name
3593 # Returns: next available tag key
3594 sub NextFreeTagKey($$)
3595 0 ▶{
Subroutine NextFreeTagKey: not called CC=3 SCAR=24.8
Pod undocumented
3596 0 my ($info, $tag) = @_;
3597 0 ▶ return $tag unless exists $$info{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{$tag} 0 0 0
3598 0 my $i;
3599 0 for ($i=1; ; ++$i) {
3600 0 my $key = "$tag ($i)";
3601 0 ▶ return $key unless exists $$info{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{$key} 0 0 0
3602 }
3603 }
3604  
3605 #------------------------------------------------------------------------------
3606 # Reverse hash lookup
3607 # Inputs: 0) value, 1) hash reference
3608 # Returns: Hash key or undef if not found (plus flag for multiple matches in list context)
3609 sub ReverseLookup($$)
3610 9598 ▶{
Subroutine ReverseLookup: called CC=19 SCAR=29.5
Pod undocumented
3611 9598 my ($val, $conv) = @_;
3612 9598 ▶ return undef unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 62 9536 9598
3613 9536 my $multi;
3614 9536 ▶ if ($val =~ /^Unknown\s*\((.*)\)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^Unknown\s*\((.*)\)$/i) { } 40 9496 9536
3615 40 $val = $1; # was unknown
3616 40 ▶ if ($val =~ /^0x([\da-fA-F]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^0x([\da-fA-F]+)$/) 0 40 40
3617 # disable "Hexadecimal number > 0xffffffff non-portable" warning
3618 0 ▶ local $SIG{'__WARN__'} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
3619 0 $val = hex($val); # convert hex value
3620 }
3621 } else {
3622 9496 my $qval = $val;
3623 9496 $qval =~ s/\s+$//; # remove trailing whitespace
3624 9496 $qval = quotemeta $qval;
3625 9496 my @patterns = (
3626 "^$qval\$", # exact match
3627 "^(?i)$qval\$", # case-insensitive
3628 "^(?i)$qval", # beginning of string
3629 "(?i)$qval", # substring
3630 );
3631 # hash entries to ignore in reverse lookup
3632 9496 my ($pattern, $found, $matches);
3633 9496 PAT: foreach $pattern (@patterns) {
3634 24799 $matches = scalar grep /$pattern/, values(%$conv);
3635 24799 ▶ next unless $matches;
Branch: 1 branch
BranchTrueFalseTotal
unless $matches 17328 7471 24799
3636 # multiple matches are bad unless they were exact
3637 7471 ▶ if ($matches > 1 and $pattern !~ /\$$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matches > 1 and not $pattern =~ /\$$/) 3910 3561 7471
Condition100%3/3
$matches > 1 and not $pattern =~ /\$$/
!ll&&!rl&&r
33881733910
MC/DC100%2/2
$matches > 1 and not $pattern =~ /\$$/
$matches > 1 not $pattern =~ /\$$/
Truth table100%3/3
A and not(B)
A= $matches > 1B= not $pattern =~ /\$$/
ABresult
0X0
100
111
3638 # don't match entries that we should ignore
3639 3910 foreach (keys %ignorePrintConv) {
3640 11730 ▶ --$matches if defined $$conv{$_} and $$conv{$_} =~ /$pattern/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $conv->{$_} and $conv->{$_} =~ /$pattern/ 461 11269 11730
Condition100%3/3
defined $conv->{$_} and $conv->{$_} =~ /$pattern/
!ll&&!rl&&r
1125019461
MC/DC100%2/2
defined $conv->{$_} and $conv->{$_} =~ /$pattern/
defined $conv->{$_} $conv->{$_} =~ /$pattern/
Truth table100%3/3
A and B
A= defined $conv->{$_}B= $conv->{$_} =~ /$pattern/
ABresult
0X0
100
111
3641 }
3642 3910 ▶ last if $matches > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $matches > 1 3778 132 3910
3643 }
3644 3693 foreach (sort keys %$conv) {
3645 10862 ▶ next if $$conv{$_} !~ /$pattern/ or $ignorePrintConv{$_};
Branch: 1 branch
BranchTrueFalseTotal
if not $conv->{$_} =~ /$pattern/ or $ignorePrintConv{$_} 7422 3440 10862
Condition100%3/3
not $conv->{$_} =~ /$pattern/ or $ignorePrintConv{$_}
l!l&&r!l&&!r
71692533440
MC/DC100%2/2
not $conv->{$_} =~ /$pattern/ or $ignorePrintConv{$_}
not $conv->{$_} =~ /$pattern/ $ignorePrintConv{$_}
Truth table100%3/3
not(A) or B
A= not $conv->{$_} =~ /$pattern/B= $ignorePrintConv{$_}
ABresult
1X1
011
000
3646 3440 $val = $_;
3647 3440 $found = 1;
3648 3440 last PAT;
3649 }
3650 }
3651 9496 ▶ unless ($found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 6056 3440 9496
3652 # call OTHER conversion routine if available
3653 6056 ▶ if ($$conv{OTHER}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conv->{'OTHER'}) { } 808 5248 6056
3654 808 local $SIG{'__WARN__'} = \&SetWarning;
3655 808 undef $evalWarning;
3656 808 $val = &{$$conv{OTHER}}($val,1,$conv);
3657 } else {
3658 5248 $val = undef;
3659 }
3660 6056 ▶ $multi = 1 if $matches > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $matches > 1 3778 2278 6056
3661 }
3662 }
3663 9536 ▶ return ($val, $multi) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 9489 47 9536
3664 47 return $val;
3665 }
3666  
3667 #------------------------------------------------------------------------------
3668 # Return true if we are deleting or overwriting the specified tag
3669 # Inputs: 0) ExifTool object ref, 1) new value hash reference
3670 # 2) optional tag value (before RawConv) if deleting specific values
3671 # Returns: >0 - tag should be overwritten
3672 # =0 - the tag should be preserved
3673 # <0 - not sure, we need the old value to tell (if there is no old value
3674 # then the tag should be written if $$nvHash{IsCreating} is true)
3675 # Notes: $$nvHash{Value} is updated with the new value when shifting a value
3676 sub IsOverwriting($$;$)
3677 6725 ▶{
Subroutine IsOverwriting: called CC=27 SCAR=41.9
Pod undocumented
3678 6725 my ($self, $nvHash, $val) = @_;
3679 6725 ▶ return 0 unless $nvHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash 42 6683 6725
3680 # overwrite regardless if no DelValues specified
3681 6683 ▶ return 1 unless $$nvHash{DelValue};
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash->{"DelValue"} 6566 117 6683
3682 # never overwrite if DelValue list exists but is empty
3683 117 my $shift = $$nvHash{Shift};
3684 117 ▶ return 0 unless @{$$nvHash{DelValue}} or defined $shift;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$nvHash->{"DelValue"};} or defined $shift 13 104 117
Condition100%3/3
@{$nvHash->{"DelValue"};} or defined $shift
l!l&&r!l&&!r
752913
MC/DC100%2/2
@{$nvHash->{"DelValue"};} or defined $shift
@{$nvHash->{"DelValue"};} defined $shift
Truth table100%3/3
A or B
A= @{$nvHash->{"DelValue"};}B= defined $shift
ABresult
1X1
011
000
3685 # return "don't know" if we don't have a value to test
3686 104 ▶ return -1 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 58 46 104
3687 # apply raw conversion if necessary
3688 46 my $tagInfo = $$nvHash{TagInfo};
3689 46 my $conv = $$tagInfo{RawConv};
3690 46 ▶ if ($conv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conv) 3 43 46
3691 3 local $SIG{'__WARN__'} = \&SetWarning;
3692 3 undef $evalWarning;
3693 3 ▶ if (ref $conv eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $conv eq 'CODE') { } 0 3 3
3694 0 $val = &$conv($val, $self);
3695 } else {
3696 3 my ($priority, @grps);
3697 3 my $tag = $$tagInfo{Name};
3698 #### eval RawConv ($self, $val, $tag, $tagInfo, $priority, @grps)
3699 3 $val = eval $conv;
3700 3 ▶ $@ and $evalWarning = $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and $Image::ExifTool::evalWarning = $@ 0 3 3
3701 }
3702 3 ▶ return -1 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 3 3
3703 }
3704 # do not overwrite if only creating
3705 46 ▶ return 0 if $$nvHash{CreateOnly};
Branch: 1 branch
BranchTrueFalseTotal
if $nvHash->{"CreateOnly"} 6 40 46
3706 # apply time/number shift if necessary
3707 40 ▶ if (defined $shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $shift) 13 27 40
3708 13 my $shiftType = $$tagInfo{Shift};
3709 13 ▶ unless ($shiftType and $shiftType eq 'Time') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($shiftType and $shiftType eq "Time") 6 7 13
Condition66%2/3
$shiftType and $shiftType eq "Time"
!ll&&!rl&&r
607
MC/DC50%1/2
$shiftType and $shiftType eq "Time"
$shiftType $shiftType eq "Time"
Truth table66%2/3
A and B
A= $shiftTypeB= $shiftType eq "Time"
ABresult
0X0
100
111
3710 6 ▶ unless (IsFloat($val)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&IsFloat($val)) 0 6 6
3711 # do the ValueConv to try to get a number
3712 0 my $conv = $$tagInfo{ValueConv};
3713 0 ▶ if (defined $conv) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $conv) 0 0 0
3714 0 local $SIG{'__WARN__'} = \&SetWarning;
3715 0 undef $evalWarning;
3716 0 ▶ if (ref $conv eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $conv eq 'CODE') { } 0 0 0
elsif (not ref $conv) { } 0 0 0
3717 0 $val = &$conv($val, $self);
3718 } elsif (not ref $conv) {
3719 #### eval ValueConv ($val, $self)
3720 0 $val = eval $conv;
3721 0 ▶ $@ and $evalWarning = $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and $Image::ExifTool::evalWarning = $@ 0 0 0
3722 }
3723 0 ▶ if ($evalWarning) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::evalWarning) 0 0 0
3724 0 $self->Warn("ValueConv $$tagInfo{Name}: " . CleanWarning());
3725 0 return 0;
3726 }
3727 }
3728 0 ▶ unless (defined $val and IsFloat($val)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val and &IsFloat($val)) 0 0 0
Condition0%0/3
defined $val and &IsFloat($val)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and &IsFloat($val)
defined $val &IsFloat($val)
Truth table0%0/3
A and B
A= defined $valB= &IsFloat($val)
ABresult
0X0
100
111
3729 0 $self->Warn("Can't shift $$tagInfo{Name} (not a number)");
3730 0 return 0;
3731 }
3732 }
3733 6 $shiftType = 'Number'; # allow any number to be shifted
3734 }
3735 13 require 'Image/ExifTool/Shift.pl';
3736 13 my $err = $self->ApplyShift($shiftType, $shift, $val, $nvHash);
3737 13 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 13 13
3738 0 $self->Warn("$err when shifting $$tagInfo{Name}");
3739 0 return 0;
3740 }
3741 # ensure that the shifted value is valid and reformat if necessary
3742 13 my $checkVal = $self->GetNewValue($nvHash);
3743 13 ▶ return 0 unless defined $checkVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $checkVal 0 13 13
3744 # don't bother overwriting if value is the same
3745 13 ▶ return 0 if $val eq $$nvHash{Value}[0];
Branch: 1 branch
BranchTrueFalseTotal
if $val eq $nvHash->{"Value"}[0] 0 13 13
3746 13 return 1;
3747 }
3748 # return 1 if value matches a DelValue
3749 27 my $delVal;
3750 27 foreach $delVal (@{$$nvHash{DelValue}}) {
3751 32 ▶ return 1 if $val eq $delVal;
Branch: 1 branch
BranchTrueFalseTotal
if $val eq $delVal 10 22 32
3752 }
3753 17 return 0;
3754 }
3755  
3756 #------------------------------------------------------------------------------
3757 # Get write group for specified tag
3758 # Inputs: 0) new value hash reference
3759 # Returns: Write group name
3760 sub GetWriteGroup($)
3761 0 ▶{
Subroutine GetWriteGroup: not called CC=1 SCAR=6.9
Pod undocumented
3762 0 return $_[0]{WriteGroup};
3763 }
3764  
3765 #------------------------------------------------------------------------------
3766 # Get name of write group or family 1 group
3767 # Inputs: 0) ExifTool ref, 1) tagInfo ref, 2) write group name
3768 # Returns: Name of group for verbose message
3769 sub GetWriteGroup1($$)
3770 34707 ▶{
Subroutine GetWriteGroup1: called CC=2 SCAR=6.9
Pod undocumented
3771 34707 my ($self, $tagInfo, $writeGroup) = @_;
3772 34707 ▶ return $writeGroup unless $writeGroup =~ /^(MakerNotes|XMP|Composite|QuickTime)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $writeGroup =~ /^(MakerNotes|XMP|Composite|QuickTime)$/ 5678 29029 34707
3773 29029 return $self->GetGroup($tagInfo, 1);
3774 }
3775  
3776 #------------------------------------------------------------------------------
3777 # Get list of tags to write for Geolocate feature
3778 # Inputs: 0) ExifTool ref, 1) group name(s),
3779 # 2) 0=prefer writing City, 1=prefer writing GPS, undef=deleting tags
3780 # Returns: list of tags to write/delete
3781 sub GetGeolocateTags($$;$)
3782 5 ▶{
Subroutine GetGeolocateTags: called CC=23 SCAR=32.8
Pod undocumented
3783 5 my ($self, $wantGroup, $writeGPS) = @_;
3784 5 ▶ my @grps = $wantGroup ? map lc, split(/:/, $wantGroup) : ();
Branch: 1 branch
BranchTrueFalseTotal
$wantGroup ? : 3 2 5
3785 5 my %grps = map { $_ => $_ } @grps; # lookup for specified groups
3786 5 ▶ $grps{exif} and not $grps{gps} and $grps{gps} = 'gps', push(@grps, 'gps');
Branch: 1 branch
BranchTrueFalseTotal
$grps{"exif"} and not $grps{"gps"} and $grps{"gps"} = "gps", push(@grps, "gps") 0 5 5
Condition33%1/3
$grps{"exif"} and not $grps{"gps"}
!ll&&!rl&&r
500
MC/DC0%0/2
$grps{"exif"} and not $grps{"gps"}
$grps{"exif"} not $grps{"gps"}
Truth table33%1/3
A and not(B)
A= $grps{"exif"}B= not $grps{"gps"}
ABresult
0X0
100
111
3787 5 my %tagGroups = (
3788 'xmp-iptcext' => [ qw(LocationShownCity LocationShownProvinceState LocationShownCountryCode
3789 LocationShownCountryName LocationShownGPSLatitude LocationShownGPSLongitude) ],
3790 'xmp-photoshop' => [ qw(City State Country) ],
3791 'xmp-iptccore' => [ 'CountryCode' ],
3792 'iptc' => [ qw(City Province-State Country-PrimaryLocationCode Country-PrimaryLocationName) ],
3793 'gps' => [ qw(GPSLatitude GPSLongitude GPSLatitudeRef GPSLongitudeRef) ],
3794 'xmp-exif' => [ qw(GPSLatitude GPSLongitude) ],
3795 'itemlist' => [ 'GPSCoordinates' ],
3796 'userdata' => [ 'GPSCoordinates' ],
3797 # more general groups not in this lookup: XMP and QuickTime
3798 );
3799 5 my (@tags, $grp);
3800 # set specific City and GPS tags
3801 5 foreach $grp (@grps) {
3802 4 ▶ $tagGroups{$grp} and push @tags, map("$grp:$_", @{$tagGroups{$grp}});
Branch: 1 branch
BranchTrueFalseTotal
$tagGroups{$grp} and push @tags, map(("${grp}:$_"), @{$tagGroups{$grp};}) 2 2 4
3803 }
3804 # set default XMP City tags if necessary
3805 5 ▶ if (not $writeGPS) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($writeGPS) 4 1 5
3806 4 ▶ push @tags, 'Keys:LocationName' if $grps{'keys'};
Branch: 1 branch
BranchTrueFalseTotal
if $grps{"keys"} 0 4 4
3807 4 ▶ if ($grps{xmp} or (not @tags and not $grps{quicktime})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grps{"xmp"} or not @tags || $grps{"quicktime"}) 3 1 4
Condition83%5/6
$grps{"xmp"} or not @tags || $grps{"quicktime"}
l!l&&r!l&&!r
121
@tags || $grps{'quicktime'}
l!l&&r!l&&!r
102
MC/DC66%2/3
$grps{"xmp"} or not @tags || $grps{"quicktime"}
$grps{"xmp"} @tags $grps{'quicktime'}
Truth table75%3/4
A or not(B || C)
A= $grps{"xmp"}B= @tagsC= $grps{'quicktime'}
ABCresult
1XX1
0001
01X0
0010
3808 3 push @tags, qw(XMP:City XMP:State XMP:CountryCode XMP:Country Keys:LocationName);
3809 }
3810 }
3811 5 ▶ $writeGPS = 1 unless defined $writeGPS; # (delete both City and GPS)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $writeGPS 1 4 5
3812 5 ▶ push @tags, 'Keys:GPSCoordinates' if $writeGPS and $grps{'keys'};
Branch: 1 branch
BranchTrueFalseTotal
if $writeGPS and $grps{"keys"} 0 5 5
Condition66%2/3
$writeGPS and $grps{"keys"}
!ll&&!rl&&r
320
MC/DC0%0/2
$writeGPS and $grps{"keys"}
$writeGPS $grps{"keys"}
Truth table66%2/3
A and B
A= $writeGPSB= $grps{"keys"}
ABresult
0X0
100
111
3813 # set default QuickTime tag if necessary
3814 5 my $didQT = grep /GPSCoordinates$/, @tags;
3815 5 ▶ if (($grps{quicktime} and not $didQT) or ($writeGPS and not @tags and not $grps{xmp})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grps{"quicktime"} and not $didQT or $writeGPS and not @tags and not $grps{"xmp"}) 1 4 5
Condition66%8/12
$grps{"quicktime"} and not $didQT or $writeGPS and not @tags and not $grps{"xmp"}
l!l&&r!l&&!r
014
$grps{"quicktime"} and not $didQT
!ll&&!rl&&r
500
$writeGPS and not @tags and not $grps{"xmp"}
!ll&&!rl&&r
401
$writeGPS and not @tags
!ll&&!rl&&r
311
MC/DC40%2/5
$grps{"quicktime"} and not $didQT or $writeGPS and not @tags and not $grps{"xmp"}
$grps{"quicktime"} not $didQT $writeGPS not @tags not $grps{"xmp"}
Truth table33%3/9
A and not(B) or C and not(D) and not(E)
A= $grps{"quicktime"}B= not $didQTC= $writeGPSD= not @tagsE= not $grps{"xmp"}
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
3816 1 push @tags, 'QuickTime:GPSCoordinates';
3817 }
3818 # set default GPS tags if necessary
3819 5 ▶ if ($writeGPS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeGPS) 2 3 5
3820 2 ▶ push @tags, qw(XMP:GPSLatitude XMP:GPSLongitude) if $grps{xmp} and not $grps{'xmp-exif'};
Branch: 1 branch
BranchTrueFalseTotal
if $grps{"xmp"} and not $grps{"xmp-exif"} 0 2 2
Condition33%1/3
$grps{"xmp"} and not $grps{"xmp-exif"}
!ll&&!rl&&r
200
MC/DC0%0/2
$grps{"xmp"} and not $grps{"xmp-exif"}
$grps{"xmp"} not $grps{"xmp-exif"}
Truth table33%1/3
A and not(B)
A= $grps{"xmp"}B= not $grps{"xmp-exif"}
ABresult
0X0
100
111
3821 2 ▶ push @tags, qw(GPSLatitude GPSLongitude GPSLatitudeRef GPSLongitudeRef) if not $wantGroup;
Branch: 1 branch
BranchTrueFalseTotal
unless $wantGroup 1 1 2
3822 }
3823 5 return @tags;
3824 }
3825  
3826 #------------------------------------------------------------------------------
3827 # Get new value hash for specified tagInfo/writeGroup
3828 # Inputs: 0) ExifTool object reference, 1) reference to tag info hash
3829 # 2) Write group name, 3) Options: 'delete' or 'create' new value hash
3830 # 4) optional ProtectSaved value, 5) true if we are deleting a value
3831 # Returns: new value hash reference for specified write group
3832 # (or first new value hash in linked list if write group not specified)
3833 # Notes: May return undef when 'create' is used with ProtectSaved
3834 sub GetNewValueHash($$;$$$$)
3835 70016 ▶{
Subroutine GetNewValueHash: called CC=31 SCAR=38.2
Pod undocumented
3836 70016 my ($self, $tagInfo, $writeGroup, $opts) = @_;
3837 70016 ▶ return undef unless $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo 4 70012 70016
3838 70012 my $nvHash = $$self{NEW_VALUE}{$tagInfo};
3839  
3840 70012 my %opts; # quick lookup for options
3841 70012 ▶ $opts and $opts{$opts} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$opts and $opts{$opts} = 1 43018 26994 70012
3842 70012 ▶ $writeGroup = '' unless defined $writeGroup;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $writeGroup 22573 47439 70012
3843  
3844 70012 ▶ if ($writeGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeGroup) 47439 22573 70012
3845 # find the new value in the list with the specified write group
3846 47439 ▶ while ($nvHash and $$nvHash{WriteGroup} ne $writeGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash and $nvHash->{"WriteGroup"} ne $writeGroup) 2010 47400 49410
Condition100%3/3
$nvHash and $nvHash->{"WriteGroup"} ne $writeGroup
!ll&&!rl&&r
4207253282010
MC/DC100%2/2
$nvHash and $nvHash->{"WriteGroup"} ne $writeGroup
$nvHash $nvHash->{"WriteGroup"} ne $writeGroup
Truth table100%3/3
A and B
A= $nvHashB= $nvHash->{"WriteGroup"} ne $writeGroup
ABresult
0X0
100
111
3847 # QuickTime and All are special cases because all group1 tags may be updated at once
3848 2010 ▶ last if $$nvHash{WriteGroup} =~ /^(QuickTime|All)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $nvHash->{"WriteGroup"} =~ /^(QuickTime|All)$/ 36 1974 2010
3849 # replace existing entry if WriteGroup is 'All' (avoids confusion of forum10349)
3850 #last if $$tagInfo{WriteGroup} and $$tagInfo{WriteGroup} eq 'All'; # (didn't work for forum17770)
3851 # forum17770 patch (also handles case where "EXIF" is specified as a write group)
3852 1974 ▶ last if $writeGroup eq 'All' or $$nvHash{WriteGroup} eq 'EXIF' and $writeGroup =~ /IFD/;
Branch: 1 branch
BranchTrueFalseTotal
if $writeGroup eq "All" or $nvHash->{"WriteGroup"} eq "EXIF" and $writeGroup =~ /IFD/ 3 1971 1974
Condition50%3/6
$writeGroup eq "All" or $nvHash->{"WriteGroup"} eq "EXIF" and $writeGroup =~ /IFD/
l!l&&r!l&&!r
301971
$nvHash->{"WriteGroup"} eq "EXIF" and $writeGroup =~ /IFD/
!ll&&!rl&&r
197100
MC/DC33%1/3
$writeGroup eq "All" or $nvHash->{"WriteGroup"} eq "EXIF" and $writeGroup =~ /IFD/
$writeGroup eq "All" $nvHash->{"WriteGroup"} eq "EXIF" $writeGroup =~ /IFD/
Truth table50%2/4
A or B and C
A= $writeGroup eq "All"B= $nvHash->{"WriteGroup"} eq "EXIF"C= $writeGroup =~ /IFD/
ABCresult
1XX1
0111
00X0
0100
3853 1971 $nvHash = $$nvHash{Next};
3854 }
3855 }
3856 # remove this entry if deleting, or if creating a new entry and
3857 # this entry is marked with "Save" flag
3858 70012 ▶ if (defined $nvHash and ($opts{'delete'} or ($opts{'create'} and $$nvHash{Save}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nvHash and $opts{"delete"} || $opts{"create"} && $nvHash->{"Save"}) 2402 67610 70012
Condition100%9/9
defined $nvHash and $opts{"delete"} || $opts{"create"} && $nvHash->{"Save"}
!ll&&!rl&&r
45720218902402
$opts{"delete"} or $opts{"create"} and $nvHash->{"Save"}
l!l&&r!l&&!r
23921021890
$opts{"create"} and $nvHash->{"Save"}
!ll&&!rl&&r
2128660410
MC/DC100%4/4
defined $nvHash and $opts{"delete"} || $opts{"create"} && $nvHash->{"Save"}
defined $nvHash $opts{"delete"} $opts{"create"} $nvHash->{"Save"}
Truth table100%5/5
A and B or C and D
A= defined $nvHashB= $opts{"delete"}C= $opts{"create"}D= $nvHash->{"Save"}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
3859 2402 ▶ my $protect = (defined $_[4] and defined $$nvHash{Save} and $$nvHash{Save} > $_[4]);
Condition33%2/6
defined $_[4] && defined $nvHash->{'Save'} && $nvHash->{'Save'} > $_[4]
!ll&&!rl&&r
240200
defined $_[4] and defined $nvHash->{"Save"}
!ll&&!rl&&r
240200
MC/DC0%0/3
defined $_[4] && defined $nvHash->{'Save'} && $nvHash->{'Save'} > $_[4]
defined $_[4] defined $nvHash->{"Save"} $nvHash->{'Save'} > $_[4]
Truth table25%1/4
A and B && C
A= defined $_[4]B= defined $nvHash->{"Save"}C= $nvHash->{'Save'} > $_[4]
ABCresult
0XX0
10X0
1100
1111
3860 # this is a bit tricky: we want to add to a protected nvHash only if we
3861 # are adding a conditional delete ($_[5] true or DelValue with no Shift)
3862 # or accumulating List items (NoReplace true)
3863 # (NOTE: this should be looked into --> lists may be accumulated instead of being replaced
3864 # as expected when copying to the same list from different dynamic -tagsFromFile source files)
3865 2402 ▶ if ($protect and not ($opts{create} and ($$nvHash{NoReplace} or $_[5] or
Branch: 2 branches
BranchTrueFalseTotal
if ($protect and not $opts{'create'} && ($nvHash->{'NoReplace'} || $_[5] || $nvHash->{'DelValue'} && !defined($nvHash->{'Shift'}))) { } 0 2402 2402
elsif ($opts{'delete'}) { } 2392 10 2402
Condition6%1/15
$protect and not $opts{"create"} && ($nvHash->{"NoReplace"} || $_[5] || $nvHash->{"DelValue"} && !defined($nvHash->{"Shift"}))
!ll&&!rl&&r
240200
$opts{'create'} && ($nvHash->{'NoReplace'} || $_[5] || $nvHash->{'DelValue'} && !defined($nvHash->{'Shift'}))
!ll&&!rl&&r
000
$nvHash->{"NoReplace"} or $_[5] or $nvHash->{"DelValue"} and not defined $nvHash->{"Shift"}
l!l&&r!l&&!r
000
$nvHash->{"NoReplace"} or $_[5]
l!l&&r!l&&!r
000
$nvHash->{"DelValue"} and not defined $nvHash->{"Shift"}
!ll&&!rl&&r
000
MC/DC0%0/6
$protect and not $opts{"create"} && ($nvHash->{"NoReplace"} || $_[5] || $nvHash->{"DelValue"} && !defined($nvHash->{"Shift"}))
$protect $opts{'create'} $nvHash->{"NoReplace"} $_[5] $nvHash->{"DelValue"} not defined $nvHash->{"Shift"}
Truth table14%1/7
A and not(B && C or D or E and not(F))
A= $protectB= $opts{'create'}C= $nvHash->{"NoReplace"}D= $_[5]E= $nvHash->{"DelValue"}F= not defined $nvHash->{"Shift"}
ABCDEFresult
0XXXXX0
111XXX0
1101XX0
1100110
10XXXX1
11000X1
1100101
3866 ($$nvHash{DelValue} and not defined $$nvHash{Shift}))))
3867 {
3868 0 return undef; # honour ProtectSaved value by not writing this tag
3869 } elsif ($opts{'delete'}) {
3870 2392 $self->RemoveNewValueHash($nvHash, $tagInfo);
3871 2392 undef $nvHash;
3872 } else {
3873 # save a copy of this new value hash
3874 10 my %copy = %$nvHash;
3875 # make copy of Value and DelValue lists
3876 10 my $key;
3877 10 foreach $key (keys %copy) {
3878 85 ▶ next unless ref $copy{$key} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $copy{$key} eq "ARRAY" 75 10 85
3879 10 $copy{$key} = [ @{$copy{$key}} ];
3880 }
3881 10 my $saveHash = $$self{SAVE_NEW_VALUE};
3882 # add to linked list of saved new value hashes
3883 10 $copy{Next} = $$saveHash{$tagInfo};
3884 10 $$saveHash{$tagInfo} = \%copy;
3885 10 delete $$nvHash{Save}; # don't save it again
3886 0 ▶ $$nvHash{AddBefore} = scalar @{$$nvHash{Value}} if $protect and $$nvHash{Value};
Branch: 1 branch
BranchTrueFalseTotal
if $protect and $nvHash->{"Value"} 0 10 10
Condition33%1/3
$protect and $nvHash->{"Value"}
!ll&&!rl&&r
1000
MC/DC0%0/2
$protect and $nvHash->{"Value"}
$protect $nvHash->{"Value"}
Truth table33%1/3
A and B
A= $protectB= $nvHash->{"Value"}
ABresult
0X0
100
111
3887 }
3888 }
3889 70012 ▶ if (not defined $nvHash and $opts{'create'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $nvHash and $opts{"create"}) 23923 46089 70012
Condition100%3/3
not defined $nvHash and $opts{"create"}
!ll&&!rl&&r
219002418923923
MC/DC100%2/2
not defined $nvHash and $opts{"create"}
not defined $nvHash $opts{"create"}
Truth table100%3/3
not(A) and B
A= not defined $nvHashB= $opts{"create"}
ABresult
0X0
100
111
3890 # create a new entry
3891 $nvHash = {
3892 TagInfo => $tagInfo,
3893 WriteGroup => $writeGroup,
3894 IsNVH => 1, # set flag so we can recognize a new value hash
3895 23923 Order => $$self{NV_COUNT}++,
3896 };
3897 # add entry to our NEW_VALUE hash
3898 23923 ▶ if ($$self{NEW_VALUE}{$tagInfo}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'NEW_VALUE'}{$tagInfo}) { } 36 23887 23923
3899 # add to end of linked list
3900 36 my $lastHash = LastInList($$self{NEW_VALUE}{$tagInfo});
3901 36 $$lastHash{Next} = $nvHash;
3902 } else {
3903 23887 $$self{NEW_VALUE}{$tagInfo} = $nvHash;
3904 }
3905 }
3906 70012 return $nvHash;
3907 }
3908  
3909 #------------------------------------------------------------------------------
3910 # Load all tag tables
3911 sub LoadAllTables()
3912 0 ▶{
Subroutine LoadAllTables: not called CC=12 SCAR=48.6
Pod undocumented
3913 0 ▶ return if $loadedAllTables;
Branch: 1 branch
BranchTrueFalseTotal
if $loadedAllTables 0 0 0
3914  
3915 # load all of our non-referenced tables (first our modules)
3916 0 my $table;
3917 0 foreach $table (@loadAllTables) {
3918 0 my $tableName = "Image::ExifTool::$table";
3919 0 ▶ $tableName .= '::Main' unless $table =~ /:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $table =~ /:/ 0 0 0
3920 0 GetTagTable($tableName);
3921 }
3922 # (then our special tables)
3923 0 GetTagTable('Image::ExifTool::Extra');
3924 0 GetTagTable('Image::ExifTool::Composite');
3925 # recursively load all tables referenced by the current tables
3926 0 my @tableNames = keys %allTables;
3927 0 my %pushedTables;
3928 0 ▶ while (@tableNames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tableNames) 0 0 0
3929 0 $table = GetTagTable(shift @tableNames);
3930 # call write proc if it exists in case it adds tags to the table
3931 0 my $writeProc = $$table{WRITE_PROC};
3932 0 ▶ if ($writeProc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeProc) 0 0 0
3933 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3934 0 &$writeProc();
3935 }
3936 # recursively scan through tables in subdirectories
3937 0 foreach (TagTableKeys($table)) {
3938 0 my @infoArray = GetTagInfoList($table,$_);
3939 0 my $tagInfo;
3940 0 foreach $tagInfo (@infoArray) {
3941 0 ▶ my $subdir = $$tagInfo{SubDirectory} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $subdir = $tagInfo->{"SubDirectory"} or next 0 0 0
3942 0 ▶ my $tableName = $$subdir{TagTable} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $tableName = $subdir->{"TagTable"} or next 0 0 0
3943 # next if table already loaded or queued for loading
3944 0 ▶ next if $allTables{$tableName} or $pushedTables{$tableName};
Branch: 1 branch
BranchTrueFalseTotal
if $Image::ExifTool::allTables{$tableName} or $pushedTables{$tableName} 0 0 0
Condition0%0/3
$Image::ExifTool::allTables{$tableName} or $pushedTables{$tableName}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Image::ExifTool::allTables{$tableName} or $pushedTables{$tableName}
$Image::ExifTool::allTables{$tableName} $pushedTables{$tableName}
Truth table0%0/3
A or B
A= $Image::ExifTool::allTables{$tableName}B= $pushedTables{$tableName}
ABresult
1X1
011
000
3945 0 push @tableNames, $tableName; # must scan this one too
3946 0 $pushedTables{$tableName} = 1;
3947 }
3948 }
3949 }
3950 0 $loadedAllTables = 1;
3951 }
3952  
3953 #------------------------------------------------------------------------------
3954 # Remove new value hash from linked list (and save if necessary)
3955 # Inputs: 0) ExifTool object reference, 1) new value hash ref, 2) tagInfo ref
3956 sub RemoveNewValueHash($$$)
3957 2665 ▶{
Subroutine RemoveNewValueHash: called CC=5 SCAR=18.0
Pod undocumented
3958 2665 my ($self, $nvHash, $tagInfo) = @_;
3959 2665 my $firstHash = $$self{NEW_VALUE}{$tagInfo};
3960 2665 ▶ if ($nvHash eq $firstHash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash eq $firstHash) { } 2665 0 2665
3961 # remove first entry from linked list
3962 2665 ▶ if ($$nvHash{Next}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash->{'Next'}) { } 0 2665 2665
3963 0 $$self{NEW_VALUE}{$tagInfo} = $$nvHash{Next};
3964 } else {
3965 2665 delete $$self{NEW_VALUE}{$tagInfo};
3966 }
3967 } else {
3968 # find the list element pointing to this hash
3969 0 ▶ $firstHash = $$firstHash{Next} while $$firstHash{Next} ne $nvHash;
Branch: 1 branch
BranchTrueFalseTotal
$firstHash->{"Next"} ne $nvHash and do { $firstHash = $firstHash->{"Next"} } 0 0 0
3970 # remove from linked list
3971 0 $$firstHash{Next} = $$nvHash{Next};
3972 }
3973 # save the existing entry if necessary
3974 2665 ▶ if ($$nvHash{Save}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash->{"Save"}) 79 2586 2665
3975 79 my $saveHash = $$self{SAVE_NEW_VALUE};
3976 # add to linked list of saved new value hashes
3977 79 $$nvHash{Next} = $$saveHash{$tagInfo};
3978 79 $$saveHash{$tagInfo} = $nvHash;
3979 }
3980 }
3981  
3982 #------------------------------------------------------------------------------
3983 # Remove all new value entries for specified group
3984 # Inputs: 0) ExifTool object reference, 1) group name
3985 sub RemoveNewValuesForGroup($$)
3986 955 ▶{
Subroutine RemoveNewValuesForGroup: called CC=11 SCAR=24.2
Pod undocumented
3987 955 my ($self, $group) = @_;
3988  
3989 955 ▶ return unless $$self{NEW_VALUE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"NEW_VALUE"} 944 11 955
3990  
3991 # make list of all groups we must remove
3992 11 my @groups = ( $group );
3993 11 ▶ push @groups, @{$removeGroups{$group}} if $removeGroups{$group};
Branch: 1 branch
BranchTrueFalseTotal
if $removeGroups{$group} 3 8 11
3994  
3995 11 my ($out, @keys, $hashKey);
3996 11 ▶ $out = $$self{OPTIONS}{TextOut} if $$self{OPTIONS}{Verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"OPTIONS"}{"Verbose"} > 1 0 11 11
3997  
3998 # loop though all new values, and remove any in this group
3999 11 @keys = keys %{$$self{NEW_VALUE}};
4000 11 foreach $hashKey (@keys) {
4001 2009 my $nvHash = $$self{NEW_VALUE}{$hashKey};
4002 # loop through each entry in linked list
4003 2009 for (;;) {
4004 2015 my $nextHash = $$nvHash{Next};
4005 2015 my $tagInfo = $$nvHash{TagInfo};
4006 2015 my ($grp0,$grp1) = $self->GetGroup($tagInfo);
4007 2015 my $wgrp = $$nvHash{WriteGroup};
4008 # use group1 if write group is not specific
4009 2015 ▶ $wgrp = $grp1 if $wgrp eq $grp0;
Branch: 1 branch
BranchTrueFalseTotal
if $wgrp eq $grp0 1593 422 2015
4010 2015 ▶ if ($grp0 eq '*' or $wgrp eq '*' or grep /^($grp0|$wgrp)$/i, @groups) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grp0 eq "*" or $wgrp eq "*" or grep /^($grp0|$wgrp)$/i, @groups) 273 1742 2015
Condition50%3/6
$grp0 eq "*" or $wgrp eq "*" or grep /^($grp0|$wgrp)$/i, @groups
l!l&&r!l&&!r
02731742
$grp0 eq "*" or $wgrp eq "*"
l!l&&r!l&&!r
002015
MC/DC33%1/3
$grp0 eq "*" or $wgrp eq "*" or grep /^($grp0|$wgrp)$/i, @groups
$grp0 eq "*" $wgrp eq "*" grep /^($grp0|$wgrp)$/i, @groups
Truth table50%2/4
A or B or C
A= $grp0 eq "*"B= $wgrp eq "*"C= grep /^($grp0|$wgrp)$/i, @groups
ABCresult
1XX1
01X1
0011
0000
4011 273 ▶ $out and print $out "Removed new value for $wgrp:$$tagInfo{Name}\n";
Branch: 1 branch
BranchTrueFalseTotal
$out and print $out qq[Removed new value for ${wgrp}:$tagInfo->{"Name"}\n] 0 273 273
4012 # remove from linked list
4013 273 $self->RemoveNewValueHash($nvHash, $tagInfo);
4014 }
4015 2015 ▶ $nvHash = $nextHash or last;
Branch: 1 branch
BranchTrueFalseTotal
$nvHash = $nextHash or last 6 2009 2015
4016 }
4017 }
4018 }
4019  
4020 #------------------------------------------------------------------------------
4021 # Get list of tagInfo hashes for all new data
4022 # Inputs: 0) ExifTool object reference, 1) optional tag table pointer
4023 # Returns: list of tagInfo hashes in no particular order
4024 sub GetNewTagInfoList($;$)
4025 1257 ▶{
Subroutine GetNewTagInfoList: called CC=5 SCAR=16.1
Pod undocumented
4026 1257 my ($self, $tagTablePtr) = @_;
4027 1257 my @tagInfoList;
4028 1257 my $nv = $$self{NEW_VALUE};
4029 1257 ▶ if ($nv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nv) 1236 21 1257
4030 1236 my $hashKey;
4031 1236 foreach $hashKey (keys %$nv) {
4032 92030 my $tagInfo = $$nv{$hashKey}{TagInfo};
4033 92030 ▶ next if $tagTablePtr and $tagTablePtr ne $$tagInfo{Table};
Branch: 1 branch
BranchTrueFalseTotal
if $tagTablePtr and $tagTablePtr ne $tagInfo->{"Table"} 58463 33567 92030
Condition100%3/3
$tagTablePtr and $tagTablePtr ne $tagInfo->{"Table"}
!ll&&!rl&&r
31283228458463
MC/DC100%2/2
$tagTablePtr and $tagTablePtr ne $tagInfo->{"Table"}
$tagTablePtr $tagTablePtr ne $tagInfo->{"Table"}
Truth table100%3/3
A and B
A= $tagTablePtrB= $tagTablePtr ne $tagInfo->{"Table"}
ABresult
0X0
100
111
4034 33567 push @tagInfoList, $tagInfo;
4035 }
4036 }
4037 1257 return @tagInfoList;
4038 }
4039  
4040 #------------------------------------------------------------------------------
4041 # Get hash of tagInfo references keyed on tagID for a specific table
4042 # Inputs: 0) ExifTool object reference, 1-N) tag table pointers
4043 # Returns: hash reference
4044 # Notes: returns only one tagInfo ref for each conditional list
4045 sub GetNewTagInfoHash($@)
4046 585 ▶{
Subroutine GetNewTagInfoHash: called CC=6 SCAR=17.9
Pod undocumented
4047 585 my $self = shift;
4048 585 my (%tagInfoHash, $hashKey);
4049 585 my $nv = $$self{NEW_VALUE};
4050 585 ▶ while ($nv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nv) 1157 9 1166
4051 1157 ▶ my $tagTablePtr = shift || last;
Condition100%2/2
shift() || (last)
l!l
581576
MC/DC100%1/1
shift() || (last)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
4052 581 foreach $hashKey (keys %$nv) {
4053 22328 my $tagInfo = $$nv{$hashKey}{TagInfo};
4054 22328 ▶ next if $tagTablePtr and $tagTablePtr ne $$tagInfo{Table};
Branch: 1 branch
BranchTrueFalseTotal
if $tagTablePtr and $tagTablePtr ne $tagInfo->{"Table"} 22014 314 22328
Condition66%2/3
$tagTablePtr and $tagTablePtr ne $tagInfo->{"Table"}
!ll&&!rl&&r
031422014
MC/DC50%1/2
$tagTablePtr and $tagTablePtr ne $tagInfo->{"Table"}
$tagTablePtr $tagTablePtr ne $tagInfo->{"Table"}
Truth table66%2/3
A and B
A= $tagTablePtrB= $tagTablePtr ne $tagInfo->{"Table"}
ABresult
0X0
100
111
4055 314 $tagInfoHash{$$tagInfo{TagID}} = $tagInfo;
4056 }
4057 }
4058 585 return \%tagInfoHash;
4059 }
4060  
4061 #------------------------------------------------------------------------------
4062 # Get a tagInfo/tagID hash for subdirectories we need to add
4063 # Inputs: 0) ExifTool object reference, 1) parent tag table reference
4064 # 2) parent directory name (taken from GROUP0 of tag table if not defined)
4065 # Returns: Reference to Hash of subdirectory tagInfo references keyed by tagID
4066 # (plus Reference to edit directory hash in list context)
4067 sub GetAddDirHash($$;$)
4068 516 ▶{
Subroutine GetAddDirHash: called CC=10 SCAR=23.0
Pod undocumented
4069 516 my ($self, $tagTablePtr, $parent) = @_;
4070 516 ▶ $parent or $parent = $$tagTablePtr{GROUPS}{0};
Branch: 1 branch
BranchTrueFalseTotal
$parent or $parent = $tagTablePtr->{"GROUPS"}{0} 484 32 516
4071 516 my $tagID;
4072 my %addDirHash;
4073 516 my %editDirHash;
4074 516 my $addDirs = $$self{ADD_DIRS};
4075 516 my $editDirs = $$self{EDIT_DIRS};
4076 516 foreach $tagID (TagTableKeys($tagTablePtr)) {
4077 181585 my @infoArray = GetTagInfoList($tagTablePtr,$tagID);
4078 181585 my $tagInfo;
4079 181585 foreach $tagInfo (@infoArray) {
4080 219953 ▶ next unless $$tagInfo{SubDirectory};
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo->{"SubDirectory"} 181295 38658 219953
4081 # get name for this sub directory
4082 # (take directory name from SubDirectory DirName if it exists,
4083 # otherwise Group0 name of SubDirectory TagTable or tag Group1 name)
4084 38658 my $dirName = $$tagInfo{SubDirectory}{DirName};
4085 38658 ▶ unless ($dirName) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirName) 4262 34396 38658
4086 # use tag name for directory name and save for next time
4087 4262 $dirName = $$tagInfo{Name};
4088 4262 $$tagInfo{SubDirectory}{DirName} = $dirName;
4089 }
4090 # save this directory information if we are writing it
4091 38658 ▶ if ($$editDirs{$dirName} and $$editDirs{$dirName} eq $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($editDirs->{$dirName} and $editDirs->{$dirName} eq $parent) 287 38371 38658
Condition100%3/3
$editDirs->{$dirName} and $editDirs->{$dirName} eq $parent
!ll&&!rl&&r
37731640287
MC/DC100%2/2
$editDirs->{$dirName} and $editDirs->{$dirName} eq $parent
$editDirs->{$dirName} $editDirs->{$dirName} eq $parent
Truth table100%3/3
A and B
A= $editDirs->{$dirName}B= $editDirs->{$dirName} eq $parent
ABresult
0X0
100
111
4092 287 $editDirHash{$tagID} = $tagInfo;
4093 287 ▶ $addDirHash{$tagID} = $tagInfo if $$addDirs{$dirName};
Branch: 1 branch
BranchTrueFalseTotal
if $addDirs->{$dirName} 151 136 287
4094 }
4095 }
4096 }
4097 516 ▶ return (\%addDirHash, \%editDirHash) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 78 438 516
4098 438 return \%addDirHash;
4099 }
4100  
4101 #------------------------------------------------------------------------------
4102 # Get localized version of tagInfo hash (used by MIE, XMP, PNG and QuickTime)
4103 # Inputs: 0) tagInfo hash ref, 1) locale code (eg. "en_CA" for MIE)
4104 # Returns: new tagInfo hash ref, or undef if invalid
4105 # - sets LangCode member in new tagInfo
4106 sub GetLangInfo($$)
4107 335 ▶{
Subroutine GetLangInfo: called CC=2 SCAR=6.9
Pod undocumented
4108 335 my ($tagInfo, $langCode) = @_;
4109 # make a new tagInfo hash for this locale
4110 335 my $table = $$tagInfo{Table};
4111 335 my $tagID = $$tagInfo{TagID} . '-' . $langCode;
4112 335 my $langInfo = $$table{$tagID};
4113 335 ▶ unless ($langInfo) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($langInfo) 192 143 335
4114 # make a new tagInfo entry for this locale
4115 $langInfo = {
4116 %$tagInfo,
4117 Name => $$tagInfo{Name} . '-' . $langCode,
4118 192 Description => Image::ExifTool::MakeDescription($$tagInfo{Name}) .
4119 " ($langCode)",
4120 LangCode => $langCode,
4121 SrcTagInfo => $tagInfo, # save reference to original tagInfo
4122 };
4123 192 AddTagToTable($table, $tagID, $langInfo);
4124 }
4125 335 return $langInfo;
4126 }
4127  
4128 #------------------------------------------------------------------------------
4129 # initialize ADD_DIRS and EDIT_DIRS hashes for all directories that need
4130 # to be created or will have tags changed in them
4131 # Inputs: 0) ExifTool object reference, 1) file type string (or map hash ref)
4132 # 2) preferred family 0 group for creating tags, 3) alternate preferred group
4133 # Notes:
4134 # - the ADD_DIRS and EDIT_DIRS keys are the directory names, and the values
4135 # are the names of the parent directories (undefined for a top-level directory)
4136 # - also initializes FORCE_WRITE lookup
4137 sub InitWriteDirs($$;$$)
4138 332 ▶{
Subroutine InitWriteDirs: called CC=43 SCAR=38.6
Pod undocumented
4139 332 my ($self, $fileType, $preferredGroup, $altGroup) = @_;
4140 332 my $editDirs = $$self{EDIT_DIRS} = { };
4141 332 my $addDirs = $$self{ADD_DIRS} = { };
4142 332 my $fileDirs = $dirMap{$fileType};
4143 332 ▶ unless ($fileDirs) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fileDirs) 203 129 332
4144 203 ▶ return unless ref $fileType eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fileType eq "HASH" 118 85 203
4145 85 $fileDirs = $fileType;
4146 }
4147 214 my @tagInfoList = $self->GetNewTagInfoList();
4148 214 my ($tagInfo, $nvHash);
4149  
4150 # save the preferred group
4151 214 $$self{PreferredGroup} = $preferredGroup;
4152  
4153 214 foreach $tagInfo (@tagInfoList) {
4154 # cycle through all hashes in linked list
4155 13312 ▶ for ($nvHash=$self->GetNewValueHash($tagInfo); $nvHash; $nvHash=$$nvHash{Next}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash) 13340 13312 26652
4156 # are we creating this tag? (otherwise just deleting or editing it)
4157 13340 my $isCreating = $$nvHash{IsCreating};
4158 13340 ▶ if ($preferredGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preferredGroup) 3605 9735 13340
4159 3605 my $g0 = $self->GetGroup($tagInfo, 0);
4160 3605 ▶ if ($isCreating) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isCreating) { } 805 2800 3605
4161 # if another group is taking priority, only create
4162 # directory if specifically adding tags to this group
4163 # or if this tag isn't being added to the priority group
4164 $isCreating = 0 if $preferredGroup ne $g0 and
4165 805 ▶ $$nvHash{CreateGroups}{$preferredGroup} and
Branch: 1 branch
BranchTrueFalseTotal
if $preferredGroup ne $g0 and $nvHash->{"CreateGroups"}{$preferredGroup} and !$altGroup || $altGroup ne $g0 143 662 805
Condition100%9/9
$preferredGroup ne $g0 and $nvHash->{"CreateGroups"}{$preferredGroup} and !$altGroup || $altGroup ne $g0
!ll&&!rl&&r
6611143
$preferredGroup ne $g0 and $nvHash->{"CreateGroups"}{$preferredGroup}
!ll&&!rl&&r
110551144
not $altGroup or $altGroup ne $g0
l!l&&r!l&&!r
14211
MC/DC100%4/4
$preferredGroup ne $g0 and $nvHash->{"CreateGroups"}{$preferredGroup} and !$altGroup || $altGroup ne $g0
$preferredGroup ne $g0 $nvHash->{"CreateGroups"}{$preferredGroup} not $altGroup $altGroup ne $g0
Truth table100%5/5
A and B and not(C) or D
A= $preferredGroup ne $g0B= $nvHash->{"CreateGroups"}{$preferredGroup}C= not $altGroupD= $altGroup ne $g0
ABCDresult
0XXX0
10XX0
11000
111X1
11011
4166 (not $altGroup or $altGroup ne $g0);
4167 } else {
4168 # create this directory if any tag is preferred and has a value
4169 # (unless group creation is disabled via the WriteMode option)
4170 $isCreating = 1 if $$nvHash{Value} and $preferredGroup eq $g0 and
4171 2800 ▶ not $$nvHash{EditOnly} and $$self{OPTIONS}{WriteMode} =~ /g/;
Branch: 1 branch
BranchTrueFalseTotal
if $nvHash->{"Value"} and $preferredGroup eq $g0 and not $nvHash->{"EditOnly"} and $self->{"OPTIONS"}{"WriteMode"} =~ /g/ 92 2708 2800
Condition77%7/9
$nvHash->{"Value"} and $preferredGroup eq $g0 and not $nvHash->{"EditOnly"} and $self->{"OPTIONS"}{"WriteMode"} =~ /g/
!ll&&!rl&&r
2708092
$nvHash->{"Value"} and $preferredGroup eq $g0 and not $nvHash->{"EditOnly"}
!ll&&!rl&&r
2708092
$nvHash->{"Value"} and $preferredGroup eq $g0
!ll&&!rl&&r
12269692
MC/DC50%2/4
$nvHash->{"Value"} and $preferredGroup eq $g0 and not $nvHash->{"EditOnly"} and $self->{"OPTIONS"}{"WriteMode"} =~ /g/
$nvHash->{"Value"} $preferredGroup eq $g0 not $nvHash->{"EditOnly"} $self->{"OPTIONS"}{"WriteMode"} =~ /g/
Truth table60%3/5
A and B and not(C) and D
A= $nvHash->{"Value"}B= $preferredGroup eq $g0C= not $nvHash->{"EditOnly"}D= $self->{"OPTIONS"}{"WriteMode"} =~ /g/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4172 }
4173 }
4174 # tag belongs to directory specified by WriteGroup, or by
4175 # the Group0 name if WriteGroup not defined
4176 13340 my $dirName = $$nvHash{WriteGroup};
4177 # remove MIE copy number(s) if they exist
4178 13340 ▶ if ($dirName =~ /^MIE\d*(-[a-z]+)?\d*$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName =~ /^MIE\d*(-[a-z]+)?\d*$/i) 398 12942 13340
4179 398 ▶ $dirName = 'MIE' . ($1 || '');
Condition50%1/2
$1 || ''
l!l
3980
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
4180 }
4181 13340 my @dirNames;
4182 # allow a group name of '*' to force writing EXIF/IPTC/XMP/PNG (ForceWrite tag)
4183 13340 ▶ if ($dirName eq '*' and $$nvHash{Value}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dirName eq '*' and $nvHash->{'Value'}) { } 0 13340 13340
elsif ($dirName eq 'QuickTime') { } 46 13294 13340
Condition33%1/3
$dirName eq "*" and $nvHash->{"Value"}
!ll&&!rl&&r
1334000
MC/DC0%0/2
$dirName eq "*" and $nvHash->{"Value"}
$dirName eq "*" $nvHash->{"Value"}
Truth table33%1/3
A and B
A= $dirName eq "*"B= $nvHash->{"Value"}
ABresult
0X0
100
111
4184 0 my $val = $$nvHash{Value}[0];
4185 0 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 0 0
4186 0 foreach (qw(EXIF IPTC XMP PNG FixBase)) {
4187 0 ▶ next unless $val =~ /\b($_|All)\b/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /\b($_|All)\b/i 0 0 0
4188 0 push @dirNames, $_;
4189 0 ▶ push @dirNames, 'EXIF' if $_ eq 'FixBase';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "FixBase" 0 0 0
4190 0 $$self{FORCE_WRITE}{$_} = 1;
4191 }
4192 }
4193 0 $dirName = shift @dirNames;
4194 } elsif ($dirName eq 'QuickTime') {
4195 # write to specific QuickTime group
4196 46 $dirName = $self->GetGroup($tagInfo, 1);
4197 }
4198 13340 ▶ while ($dirName) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName) 53850 13340 67190
4199 53850 my $parent = $$fileDirs{$dirName};
4200 53850 ▶ if (ref $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parent) 6476 47374 53850
4201 6476 push @dirNames, reverse @$parent;
4202 6476 $parent = pop @dirNames;
4203 }
4204 53850 $$editDirs{$dirName} = $parent;
4205 53850 ▶ $$addDirs{$dirName} = $parent if $isCreating and $isCreating != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $isCreating and $isCreating != 2 5079 48771 53850
Condition100%3/3
$isCreating and $isCreating != 2
!ll&&!rl&&r
48719525079
MC/DC100%2/2
$isCreating and $isCreating != 2
$isCreating $isCreating != 2
Truth table100%3/3
A and B
A= $isCreatingB= $isCreating != 2
ABresult
0X0
100
111
4206 53850 ▶ $dirName = $parent || shift @dirNames
Condition100%3/3
$parent || shift @dirNames
l!l&&r!l&&!r
34034647613340
MC/DC100%2/2
$parent || shift @dirNames
$parent shift @dirNames
Truth table100%3/3
A || B
A= $parentB= shift @dirNames
ABresult
1X1
011
000
4207 }
4208 }
4209 }
4210 214 ▶ if (%{$$self{DEL_GROUP}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$self->{"DEL_GROUP"};}) 39 175 214
4211 # add delete groups to list of edited groups
4212 39 foreach (keys %{$$self{DEL_GROUP}}) {
4213 1036 ▶ next if /^-/; # ignore excluded groups
Branch: 1 branch
BranchTrueFalseTotal
if /^-/ 2 1034 1036
4214 1034 my $dirName = $_;
4215 # translate necessary group 0 names
4216 1034 ▶ $dirName = $translateWriteGroup{$dirName} if $translateWriteGroup{$dirName};
Branch: 1 branch
BranchTrueFalseTotal
if $translateWriteGroup{$dirName} 78 956 1034
4217 # convert XMP group 1 names
4218 1034 ▶ $dirName = 'XMP' if $dirName =~ /^XMP-/;
Branch: 1 branch
BranchTrueFalseTotal
if $dirName =~ /^XMP-/ 41 993 1034
4219 1034 my @dirNames;
4220 1034 ▶ while ($dirName) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName) 1484 1034 2518
4221 1484 my $parent = $$fileDirs{$dirName};
4222 1484 ▶ if (ref $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parent) 17 1467 1484
4223 17 push @dirNames, reverse @$parent;
4224 17 $parent = pop @dirNames;
4225 }
4226 1484 $$editDirs{$dirName} = $parent;
4227 1484 ▶ $dirName = $parent || shift @dirNames
Condition100%3/3
$parent || shift @dirNames
l!l&&r!l&&!r
433171034
MC/DC100%2/2
$parent || shift @dirNames
$parent shift @dirNames
Truth table100%3/3
A || B
A= $parentB= shift @dirNames
ABresult
1X1
011
000
4228 }
4229 }
4230 }
4231 # special case to edit JFIF to get resolutions if editing EXIF information
4232 214 ▶ if ($$editDirs{IFD0} and $$fileDirs{JFIF}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($editDirs->{"IFD0"} and $fileDirs->{"JFIF"}) 88 126 214
Condition100%3/3
$editDirs->{"IFD0"} and $fileDirs->{"JFIF"}
!ll&&!rl&&r
883888
MC/DC100%2/2
$editDirs->{"IFD0"} and $fileDirs->{"JFIF"}
$editDirs->{"IFD0"} $fileDirs->{"JFIF"}
Truth table100%3/3
A and B
A= $editDirs->{"IFD0"}B= $fileDirs->{"JFIF"}
ABresult
0X0
100
111
4233 88 $$editDirs{JFIF} = 'IFD1';
4234 88 $$editDirs{APP0} = undef;
4235 }
4236  
4237 214 ▶ if ($$self{OPTIONS}{Verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"OPTIONS"}{"Verbose"}) 2 212 214
4238 2 my $out = $$self{OPTIONS}{TextOut};
4239 2 print $out " Editing tags in: ";
4240 2 foreach (sort keys %$editDirs) { print $out "$_ "; }
4241 2 print $out "\n";
4242 2 ▶ return unless $$self{OPTIONS}{Verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"OPTIONS"}{"Verbose"} > 1 0 2 2
4243 2 print $out " Creating tags in: ";
4244 2 foreach (sort keys %$addDirs) { print $out "$_ "; }
4245 2 print $out "\n";
4246 }
4247 }
4248  
4249 #------------------------------------------------------------------------------
4250 # Write an image directory
4251 # Inputs: 0) ExifTool object reference, 1) source directory information reference
4252 # 2) tag table reference, 3) optional reference to writing procedure
4253 # Returns: New directory data or undefined on error (or empty string to delete directory)
4254 sub WriteDirectory($$$;$)
4255 1947 ▶{
Subroutine WriteDirectory: called CC=105 SCAR=64.6
Pod undocumented
4256 1947 my ($self, $dirInfo, $tagTablePtr, $writeProc) = @_;
4257 1947 my ($out, $nvHash, $delFlag);
4258  
4259 1947 ▶ $tagTablePtr or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$tagTablePtr or return undef 1947 0 1947
4260 1947 ▶ $out = $$self{OPTIONS}{TextOut} if $$self{OPTIONS}{Verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"OPTIONS"}{"Verbose"} 4 1943 1947
4261 # set directory name from default group0 name if not done already
4262 1947 my $dirName = $$dirInfo{DirName};
4263 1947 ▶ my $parent = $$dirInfo{Parent} || '';
Condition100%2/2
$dirInfo->{'Parent'} || ''
l!l
188463
MC/DC100%1/1
$dirInfo->{'Parent'} || ''
$dirInfo->{'Parent'}
Truth table100%2/2
A
A= $dirInfo->{'Parent'}
Aresult
11
00
4264 1947 my $dataPt = $$dirInfo{DataPt};
4265 1947 my $grp0 = $$tagTablePtr{GROUPS}{0};
4266 1947 ▶ $dirName or $dirName = $$dirInfo{DirName} = $grp0;
Branch: 1 branch
BranchTrueFalseTotal
$dirName or $dirName = ($dirInfo->{"DirName"} = $grp0) 1353 594 1947
4267 1947 ▶ if (%{$$self{DEL_GROUP}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$self->{"DEL_GROUP"};}) 287 1660 1947
4268 287 my $delGroup = $$self{DEL_GROUP};
4269 # delete entire directory if specified
4270 287 my $grp1 = $dirName;
4271 287 ▶ $delFlag = ($$delGroup{$grp0} or $$delGroup{$grp1});
Condition100%3/3
$delGroup->{$grp0} || $delGroup->{$grp1}
l!l&&r!l&&!r
1754108
MC/DC100%2/2
$delGroup->{$grp0} || $delGroup->{$grp1}
$delGroup->{$grp0} $delGroup->{$grp1}
Truth table100%3/3
A || B
A= $delGroup->{$grp0}B= $delGroup->{$grp1}
ABresult
1X1
011
000
4272 287 ▶ if ($permanentDir{$grp0} and not ($$dirInfo{TagInfo} and $$dirInfo{TagInfo}{Deletable})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($permanentDir{$grp0} and not $dirInfo->{"TagInfo"} && $dirInfo->{"TagInfo"}{"Deletable"}) 186 101 287
Condition66%4/6
$permanentDir{$grp0} and not $dirInfo->{"TagInfo"} && $dirInfo->{"TagInfo"}{"Deletable"}
!ll&&!rl&&r
1010186
$dirInfo->{'TagInfo'} && $dirInfo->{'TagInfo'}{'Deletable'}
!ll&&!rl&&r
11850
MC/DC33%1/3
$permanentDir{$grp0} and not $dirInfo->{"TagInfo"} && $dirInfo->{"TagInfo"}{"Deletable"}
$permanentDir{$grp0} $dirInfo->{'TagInfo'} $dirInfo->{'TagInfo'}{'Deletable'}
Truth table75%3/4
A and not(B && C)
A= $permanentDir{$grp0}B= $dirInfo->{'TagInfo'}C= $dirInfo->{'TagInfo'}{'Deletable'}
ABCresult
0XX0
1110
10X1
1101
4273 186 undef $delFlag;
4274 }
4275 287 ▶ if ($delFlag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delFlag) 42 245 287
4276 42 ▶ if ($$dirInfo{Permanent}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($dirInfo->{'Permanent'}) { } 0 42 42
elsif ($grp0 =~ /^(MakerNotes)$/ || $grp1 =~ /^(IFD0|ExifIFD|MakerNotes)$/ and $self->IsRawType and !($dirInfo->{'TagInfo'} && defined $dirInfo->{'TagInfo'}{'Permanent'}) || $dirInfo->{'TagInfo'}{'Permanent'} and not $self->IsRawType == 2 && $parent eq 'ExifIFD') { } 0 42 42
elsif (not $blockExifTypes{$self->{'FILE_TYPE'}}) { } 10 32 42
4277 0 $self->Warn("Not deleting permanent $dirName directory");
4278 0 undef $grp1;
4279 ▶ } elsif (($grp0 =~ /^(MakerNotes)$/ or $grp1 =~ /^(IFD0|ExifIFD|MakerNotes)$/) and
Condition33%7/21
$grp0 =~ /^(MakerNotes)$/ || $grp1 =~ /^(IFD0|ExifIFD|MakerNotes)$/ and $self->IsRawType and !($dirInfo->{"TagInfo"} && defined $dirInfo->{"TagInfo"}{"Permanent"}) || $dirInfo->{"TagInfo"}{"Permanent"} and not $self->IsRawType == 2 && $parent eq "ExifIFD"
!ll&&!rl&&r
4200
$grp0 =~ /^(MakerNotes)$/ || $grp1 =~ /^(IFD0|ExifIFD|MakerNotes)$/ and $self->IsRawType and !($dirInfo->{"TagInfo"} && defined $dirInfo->{"TagInfo"}{"Permanent"}) || $dirInfo->{"TagInfo"}{"Permanent"}
!ll&&!rl&&r
4200
$grp0 =~ /^(MakerNotes)$/ || $grp1 =~ /^(IFD0|ExifIFD|MakerNotes)$/ and $self->IsRawType
!ll&&!rl&&r
30120
$grp0 =~ /^(MakerNotes)$/ or $grp1 =~ /^(IFD0|ExifIFD|MakerNotes)$/
l!l&&r!l&&!r
3930
not $dirInfo->{"TagInfo"} && defined $dirInfo->{"TagInfo"}{"Permanent"} or $dirInfo->{"TagInfo"}{"Permanent"}
l!l&&r!l&&!r
000
$dirInfo->{'TagInfo'} && defined $dirInfo->{'TagInfo'}{'Permanent'}
!ll&&!rl&&r
000
$self->IsRawType == 2 && $parent eq 'ExifIFD'
!ll&&!rl&&r
000
MC/DC0%0/8
$grp0 =~ /^(MakerNotes)$/ || $grp1 =~ /^(IFD0|ExifIFD|MakerNotes)$/ and $self->IsRawType and !($dirInfo->{"TagInfo"} && defined $dirInfo->{"TagInfo"}{"Permanent"}) || $dirInfo->{"TagInfo"}{"Permanent"} and not $self->IsRawType == 2 && $parent eq "ExifIFD"
$grp0 =~ /^(MakerNotes)$/ $grp1 =~ /^(IFD0|ExifIFD|MakerNotes)$/ $self->IsRawType $dirInfo->{'TagInfo'} defined $dirInfo->{'TagInfo'}{'Permanent'} $dirInfo->{"TagInfo"}{"Permanent"} $self->IsRawType == 2 $parent eq 'ExifIFD'
Truth table13%3/23
A or B and C and not(D && E) or F and not(G && H)
A= $grp0 =~ /^(MakerNotes)$/B= $grp1 =~ /^(IFD0|ExifIFD|MakerNotes)$/C= $self->IsRawTypeD= $dirInfo->{'TagInfo'}E= defined $dirInfo->{'TagInfo'}{'Permanent'}F= $dirInfo->{"TagInfo"}{"Permanent"}G= $self->IsRawType == 2H= $parent eq 'ExifIFD'
ABCDEFGHresult
00XXXXXX0
1X0XXXXX0
010XXXXX0
1X1110XX0
011110XX0
1X10XX110
1X110X110
1X1111110
0110XX110
01110X110
011111110
1X10XX0X1
1X10XX101
1X110X0X1
1X110X101
1X11110X1
1X1111101
0110XX0X1
0110XX101
01110X0X1
01110X101
0111110X1
011111101
4280 $self->IsRawType() and
4281 # allow non-permanent MakerNote directories to be deleted (ie. NikonCapture)
4282 (not $$dirInfo{TagInfo} or not defined $$dirInfo{TagInfo}{Permanent} or
4283 $$dirInfo{TagInfo}{Permanent}) and
4284 # allow MakerNotes to be deleted from ExifIFD of CR3 file
4285 not ($self->IsRawType() == 2 and $parent eq 'ExifIFD'))
4286 {
4287 0 $self->Warn("Can't delete $1 from $$self{FileType}",1);
4288 0 undef $grp1;
4289 } elsif (not $blockExifTypes{$$self{FILE_TYPE}}) {
4290 # restrict delete logic to prevent entire tiff image from being killed
4291 # (don't allow IFD0 to be deleted, and delete only ExifIFD if EXIF specified)
4292 10 ▶ if ($$self{FILE_TYPE} eq 'PSD') {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'FILE_TYPE'} eq 'PSD') { } 0 10 10
elsif ($self->{'FILE_TYPE'} =~ /^(EPS|PS)$/) { } 0 10 10
elsif ($grp1 eq 'IFD0') { } 0 10 10
elsif ($grp0 eq 'EXIF' and $delGroup->{$grp0}) { } 0 20 20
4293 # don't delete Photoshop directories from PSD image
4294 0 ▶ undef $grp1 if $grp0 eq 'Photoshop';
Branch: 1 branch
BranchTrueFalseTotal
if $grp0 eq "Photoshop" 0 0 0
4295 } elsif ($$self{FILE_TYPE} =~ /^(EPS|PS)$/) {
4296 # allow anything to be deleted from PostScript files
4297 } elsif ($grp1 eq 'IFD0') {
4298 0 ▶ my $type = $$self{TIFF_TYPE} || $$self{FILE_TYPE};
Condition0%0/3
$self->{'TIFF_TYPE'} || $self->{'FILE_TYPE'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'TIFF_TYPE'} || $self->{'FILE_TYPE'}
$self->{'TIFF_TYPE'} $self->{'FILE_TYPE'}
Truth table0%0/3
A || B
A= $self->{'TIFF_TYPE'}B= $self->{'FILE_TYPE'}
ABresult
1X1
011
000
4299 0 ▶ $$delGroup{IFD0} and $self->Warn("Can't delete IFD0 from $type",1);
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"IFD0"} and $self->Warn("Can't delete IFD0 from $type", 1) 0 0 0
4300 0 undef $grp1;
4301 ▶ } elsif ($grp0 eq 'EXIF' and $$delGroup{$grp0}) {
Condition33%1/3
$grp0 eq "EXIF" and $delGroup->{$grp0}
!ll&&!rl&&r
1000
MC/DC0%0/2
$grp0 eq "EXIF" and $delGroup->{$grp0}
$grp0 eq "EXIF" $delGroup->{$grp0}
Truth table33%1/3
A and B
A= $grp0 eq "EXIF"B= $delGroup->{$grp0}
ABresult
0X0
100
111
4302 0 ▶ undef $grp1 unless $$delGroup{$grp1} or $grp1 eq 'ExifIFD';
Branch: 1 branch
BranchTrueFalseTotal
unless $delGroup->{$grp1} or $grp1 eq "ExifIFD" 0 0 0
Condition0%0/3
$delGroup->{$grp1} or $grp1 eq "ExifIFD"
l!l&&r!l&&!r
000
MC/DC0%0/2
$delGroup->{$grp1} or $grp1 eq "ExifIFD"
$delGroup->{$grp1} $grp1 eq "ExifIFD"
Truth table0%0/3
A or B
A= $delGroup->{$grp1}B= $grp1 eq "ExifIFD"
ABresult
1X1
011
000
4303 }
4304 }
4305 42 ▶ if ($grp1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grp1) 42 0 42
4306 42 ▶ if ($dataPt or $$dirInfo{RAF}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataPt or $dirInfo->{"RAF"}) 32 10 42
Condition66%2/3
$dataPt or $dirInfo->{"RAF"}
l!l&&r!l&&!r
32010
MC/DC50%1/2
$dataPt or $dirInfo->{"RAF"}
$dataPt $dirInfo->{"RAF"}
Truth table66%2/3
A or B
A= $dataPtB= $dirInfo->{"RAF"}
ABresult
1X1
011
000
4307 32 ++$$self{CHANGED};
4308 32 ▶ $out and print $out " Deleting $grp1\n";
Branch: 1 branch
BranchTrueFalseTotal
$out and print $out " Deleting $grp1\n" 1 31 32
4309 32 ▶ $self->Warn('ICC_Profile deleted. Image colors may be affected') if $grp1 eq 'ICC_Profile';
Branch: 1 branch
BranchTrueFalseTotal
if $grp1 eq "ICC_Profile" 3 29 32
4310 # can no longer validate TIFF_END if deleting an entire IFD
4311 32 ▶ delete $$self{TIFF_END} if $dirName =~ /IFD/;
Branch: 1 branch
BranchTrueFalseTotal
if $dirName =~ /IFD/ 6 26 32
4312 }
4313 # don't add back into the wrong location
4314 42 my $right = $$self{ADD_DIRS}{$grp1};
4315 # (take care because EXIF directory name may be either EXIF or IFD0,
4316 # but IFD0 will be the one that appears in the directory map)
4317 42 ▶ $right = $$self{ADD_DIRS}{IFD0} if not $right and $grp1 eq 'EXIF';
Branch: 1 branch
BranchTrueFalseTotal
if not $right and $grp1 eq "EXIF" 1 41 42
Condition100%3/3
not $right and $grp1 eq "EXIF"
!ll&&!rl&&r
21201
MC/DC100%2/2
not $right and $grp1 eq "EXIF"
not $right $grp1 eq "EXIF"
Truth table100%3/3
not(A) and B
A= not $rightB= $grp1 eq "EXIF"
ABresult
0X0
100
111
4318 42 ▶ if ($delFlag == 2 and $right) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delFlag == 2 and $right) { } 21 21 42
Condition100%3/3
$delFlag == 2 and $right
!ll&&!rl&&r
18321
MC/DC100%2/2
$delFlag == 2 and $right
$delFlag == 2 $right
Truth table100%3/3
A and B
A= $delFlag == 2B= $right
ABresult
0X0
100
111
4319 # also check grandparent because some routines create 2 levels in 1
4320 21 ▶ my $right2 = $$self{ADD_DIRS}{$right} || '';
Condition100%2/2
$self->{'ADD_DIRS'}{$right} || ''
l!l
714
MC/DC100%1/1
$self->{'ADD_DIRS'}{$right} || ''
$self->{'ADD_DIRS'}{$right}
Truth table100%2/2
A
A= $self->{'ADD_DIRS'}{$right}
Aresult
11
00
4321 21 ▶ if (not $parent or $parent eq $right or $parent eq $right2) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $parent or $parent eq $right or $parent eq $right2) { } 21 0 21
Condition50%3/6
not $parent or $parent eq $right or $parent eq $right2
l!l&&r!l&&!r
2100
not $parent or $parent eq $right
l!l&&r!l&&!r
8130
MC/DC0%0/3
not $parent or $parent eq $right or $parent eq $right2
not $parent $parent eq $right $parent eq $right2
Truth table50%2/4
not(A) or B or C
A= not $parentB= $parent eq $rightC= $parent eq $right2
ABCresult
1XX1
01X1
0011
0000
4322 # prevent duplicate directories from being recreated at the same path
4323 21 my $path = join '-', @{$$self{PATH}}, $dirName;
4324 21 ▶ $$self{Recreated} or $$self{Recreated} = { };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"Recreated"} or $self->{"Recreated"} = {} 12 9 21
4325 21 ▶ if ($$self{Recreated}{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Recreated"}{$path}) 0 21 21
4326 0 ▶ my $p = $parent ? " in $parent" : '';
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
4327 0 $self->Warn("Not recreating duplicate $grp1$p",1);
4328 0 return '';
4329 }
4330 21 $$self{Recreated}{$path} = 1;
4331 # empty the directory
4332 21 my $data = '';
4333 21 $$dirInfo{DataPt} = \$data;
4334 21 $$dirInfo{DataLen} = 0;
4335 21 $$dirInfo{DirStart} = 0;
4336 21 $$dirInfo{DirLen} = 0;
4337 21 delete $$dirInfo{RAF};
4338 21 delete $$dirInfo{Base};
4339 21 delete $$dirInfo{DataPos};
4340 } else {
4341 0 $self->Warn("Not recreating $grp1 in $parent (should be in $right)",1);
4342 0 return '';
4343 }
4344 } else {
4345 21 ▶ return '' unless $$dirInfo{NoDelete};
Branch: 1 branch
BranchTrueFalseTotal
unless $dirInfo->{"NoDelete"} 20 1 21
4346 }
4347 }
4348 }
4349 }
4350 # use default proc from tag table if no proc specified
4351 1927 ▶ $writeProc or $writeProc = $$tagTablePtr{WRITE_PROC} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$writeProc or $writeProc = $tagTablePtr->{"WRITE_PROC"} or return undef 1634 293 1927
Condition100%3/3
$writeProc or $writeProc = $tagTablePtr->{"WRITE_PROC"}
l!l&&r!l&&!r
1511483293
MC/DC100%2/2
$writeProc or $writeProc = $tagTablePtr->{"WRITE_PROC"}
$writeProc $writeProc = $tagTablePtr->{"WRITE_PROC"}
Truth table100%3/3
A or B
A= $writeProcB= $writeProc = $tagTablePtr->{"WRITE_PROC"}
ABresult
1X1
011
000
4352  
4353 # are we rewriting a pre-existing directory?
4354 1634 ▶ my $isRewriting = ($$dirInfo{DirLen} or (defined $dataPt and length $$dataPt) or $$dirInfo{RAF});
Condition100%9/9
$dirInfo->{'DirLen'} || defined $dataPt && length $$dataPt || $dirInfo->{'RAF'}
l!l&&r!l&&!r
141517202
$dirInfo->{"DirLen"} or defined $dataPt and length $$dataPt
l!l&&r!l&&!r
1171244219
defined $dataPt and length $$dataPt
!ll&&!rl&&r
17742244
MC/DC100%4/4
$dirInfo->{'DirLen'} || defined $dataPt && length $$dataPt || $dirInfo->{'RAF'}
$dirInfo->{"DirLen"} defined $dataPt length $$dataPt $dirInfo->{'RAF'}
Truth table100%6/6
A or B and C || D
A= $dirInfo->{"DirLen"}B= defined $dataPtC= length $$dataPtD= $dirInfo->{'RAF'}
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
4355  
4356 # copy or delete new directory as a block if specified
4357 1634 my $blockName = $dirName;
4358 1634 ▶ $blockName = 'EXIF' if $blockName eq 'IFD0';
Branch: 1 branch
BranchTrueFalseTotal
if $blockName eq "IFD0" 206 1428 1634
4359 1634 ▶ my $tagInfo = $Image::ExifTool::Extra{$blockName} || $$dirInfo{TagInfo};
Condition100%3/3
$Image::ExifTool::Extra{$blockName} || $dirInfo->{'TagInfo'}
l!l&&r!l&&!r
391953290
MC/DC100%2/2
$Image::ExifTool::Extra{$blockName} || $dirInfo->{'TagInfo'}
$Image::ExifTool::Extra{$blockName} $dirInfo->{'TagInfo'}
Truth table100%3/3
A || B
A= $Image::ExifTool::Extra{$blockName}B= $dirInfo->{'TagInfo'}
ABresult
1X1
011
000
4360 1634 ▶ while ($tagInfo and ($nvHash = $$self{NEW_VALUE}{$tagInfo}) and
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo and $nvHash = $self->{"NEW_VALUE"}{$tagInfo} and $self->IsOverwriting($nvHash) and not $nvHash->{"CreateOnly"} && $isRewriting) 11 1623 1634
Condition66%8/12
$tagInfo and $nvHash = $self->{"NEW_VALUE"}{$tagInfo} and $self->IsOverwriting($nvHash) and not $nvHash->{"CreateOnly"} && $isRewriting
!ll&&!rl&&r
1623011
$tagInfo and $nvHash = $self->{"NEW_VALUE"}{$tagInfo} and $self->IsOverwriting($nvHash)
!ll&&!rl&&r
1623011
$tagInfo and $nvHash = $self->{"NEW_VALUE"}{$tagInfo}
!ll&&!rl&&r
290133311
$nvHash->{'CreateOnly'} && $isRewriting
!ll&&!rl&&r
1100
MC/DC40%2/5
$tagInfo and $nvHash = $self->{"NEW_VALUE"}{$tagInfo} and $self->IsOverwriting($nvHash) and not $nvHash->{"CreateOnly"} && $isRewriting
$tagInfo $nvHash = $self->{"NEW_VALUE"}{$tagInfo} $self->IsOverwriting($nvHash) $nvHash->{'CreateOnly'} $isRewriting
Truth table50%3/6
A and B and C and not(D && E)
A= $tagInfoB= $nvHash = $self->{"NEW_VALUE"}{$tagInfo}C= $self->IsOverwriting($nvHash)D= $nvHash->{'CreateOnly'}E= $isRewriting
ABCDEresult
0XXXX0
10XXX0
110XX0
111110
1110X1
111101
4361 $self->IsOverwriting($nvHash) and not ($$nvHash{CreateOnly} and $isRewriting))
4362 {
4363 # protect against writing EXIF to wrong file types, etc
4364 11 ▶ if ($blockName eq 'EXIF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($blockName eq "EXIF") 1 10 11
4365 1 ▶ unless ($blockExifTypes{$$self{FILE_TYPE}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($blockExifTypes{$self->{"FILE_TYPE"}}) 0 1 1
4366 0 $self->Warn("Can't write EXIF as a block to $$self{FILE_TYPE} file");
4367 0 last;
4368 }
4369 # this can happen if we call WriteDirectory for an EXIF directory without going
4370 # through WriteTIFF as the WriteProc (which happens if conditionally replacing
4371 # the EXIF block and the condition fails), but we never want to do a block write
4372 # in this case because the EXIF block would end up with two TIFF headers
4373 1 ▶ last unless $writeProc eq \&Image::ExifTool::WriteTIFF;
Branch: 1 branch
BranchTrueFalseTotal
unless $writeProc eq \&Image::ExifTool::WriteTIFF 0 1 1
4374 }
4375 11 ▶ last unless $self->IsOverwriting($nvHash, $dataPt ? $$dataPt : '');
Branch: 2 branches
BranchTrueFalseTotal
unless $self->IsOverwriting($nvHash, $dataPt ? $$dataPt : "") 0 11 11
$dataPt ? : 4 7 11
4376 11 my $verb = 'Writing';
4377 11 my $newVal = $self->GetNewValue($nvHash);
4378 11 ▶ if (defined $newVal and length $newVal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newVal and length $newVal) { } 11 0 11
Condition33%1/3
defined $newVal and length $newVal
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $newVal and length $newVal
defined $newVal length $newVal
Truth table33%1/3
A and B
A= defined $newValB= length $newVal
ABresult
0X0
100
111
4379 # hack to add back TIFF header when writing MakerNoteCanon to CMT3 in CR3 images
4380 11 ▶ if ($$tagInfo{Name} eq 'MakerNoteCanon') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"Name"} eq "MakerNoteCanon") 0 11 11
4381 0 require Image::ExifTool::Canon;
4382 0 ▶ if ($tagInfo eq $Image::ExifTool::Canon::uuid{CMT3}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo eq $Image::ExifTool::Canon::uuid{"CMT3"}) 0 0 0
4383 0 my $hdr;
4384 0 ▶ if (substr($newVal, 0, 1) eq "\0") {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($newVal, 0, 1) eq "\000") { } 0 0 0
4385 0 $hdr = "MM\0\x2a" . pack('N', 8);
4386 } else {
4387 0 $hdr = "II\x2a\0" . pack('V', 8);
4388 }
4389 0 $newVal = $hdr . $newVal;
4390 }
4391 }
4392 } else {
4393 0 ▶ return '' unless $dataPt or $$dirInfo{RAF}; # nothing to do if block never existed
Branch: 1 branch
BranchTrueFalseTotal
unless $dataPt or $dirInfo->{"RAF"} 0 0 0
Condition0%0/3
$dataPt or $dirInfo->{"RAF"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dataPt or $dirInfo->{"RAF"}
$dataPt $dirInfo->{"RAF"}
Truth table0%0/3
A or B
A= $dataPtB= $dirInfo->{"RAF"}
ABresult
1X1
011
000
4394 # don't allow MakerNotes to be removed from RAW files
4395 0 ▶ if ($blockName eq 'MakerNotes' and $self->IsRawType() and
Branch: 1 branch
BranchTrueFalseTotal
if ($blockName eq "MakerNotes" and $self->IsRawType and not $self->IsRawType == 2 && $parent eq "ExifIFD") 0 0 0
Condition0%0/9
$blockName eq "MakerNotes" and $self->IsRawType and not $self->IsRawType == 2 && $parent eq "ExifIFD"
!ll&&!rl&&r
000
$blockName eq "MakerNotes" and $self->IsRawType
!ll&&!rl&&r
000
$self->IsRawType == 2 && $parent eq 'ExifIFD'
!ll&&!rl&&r
000
MC/DC0%0/4
$blockName eq "MakerNotes" and $self->IsRawType and not $self->IsRawType == 2 && $parent eq "ExifIFD"
$blockName eq "MakerNotes" $self->IsRawType $self->IsRawType == 2 $parent eq 'ExifIFD'
Truth table0%0/5
A and B and not(C && D)
A= $blockName eq "MakerNotes"B= $self->IsRawTypeC= $self->IsRawType == 2D= $parent eq 'ExifIFD'
ABCDresult
0XXX0
10XX0
11110
110X1
11101
4396 # but allow MakerNotes to be deleted from ExifIFD of CR3 image (shouldn't be there)
4397 not ($self->IsRawType() == 2 and $parent eq 'ExifIFD'))
4398 {
4399 0 $self->Warn("Can't delete MakerNotes from $$self{FileType}",1);
4400 0 return undef;
4401 }
4402 0 $verb = 'Deleting';
4403 0 $newVal = '';
4404 }
4405 11 $$dirInfo{BlockWrite} = 1; # set flag indicating we did a block write
4406 11 ▶ $out and print $out " $verb $blockName as a block\n";
Branch: 1 branch
BranchTrueFalseTotal
$out and print $out " $verb $blockName as a block\n" 0 11 11
4407 11 ++$$self{CHANGED};
4408 11 return $newVal;
4409 }
4410 # guard against writing the same directory twice
4411 1623 ▶ if (defined $dataPt and defined $$dirInfo{DirStart} and defined $$dirInfo{DataPos} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dataPt and defined $dirInfo->{"DirStart"} and defined $dirInfo->{"DataPos"} and not $dirInfo->{"NoRefTest"}) 693 930 1623
Condition100%9/9
defined $dataPt and defined $dirInfo->{"DirStart"} and defined $dirInfo->{"DataPos"} and not $dirInfo->{"NoRefTest"}
!ll&&!rl&&r
408522693
defined $dataPt and defined $dirInfo->{"DirStart"} and defined $dirInfo->{"DataPos"}
!ll&&!rl&&r
2371711215
defined $dataPt and defined $dirInfo->{"DirStart"}
!ll&&!rl&&r
219181386
MC/DC100%4/4
defined $dataPt and defined $dirInfo->{"DirStart"} and defined $dirInfo->{"DataPos"} and not $dirInfo->{"NoRefTest"}
defined $dataPt defined $dirInfo->{"DirStart"} defined $dirInfo->{"DataPos"} not $dirInfo->{"NoRefTest"}
Truth table100%5/5
A and B and C and not(D)
A= defined $dataPtB= defined $dirInfo->{"DirStart"}C= defined $dirInfo->{"DataPos"}D= not $dirInfo->{"NoRefTest"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4412 not $$dirInfo{NoRefTest})
4413 {
4414 693 ▶ my $addr = $$dirInfo{DirStart} + $$dirInfo{DataPos} + ($$dirInfo{Base}||0) + $$self{BASE};
Condition100%2/2
$dirInfo->{'Base'} || 0
l!l
475218
MC/DC100%1/1
$dirInfo->{'Base'} || 0
$dirInfo->{'Base'}
Truth table100%2/2
A
A= $dirInfo->{'Base'}
Aresult
11
00
4415 # (Phase One P25 IIQ files have ICC_Profile duplicated in IFD0 and IFD1)
4416 693 ▶ if ($$self{PROCESSED}{$addr} and ($dirName ne 'ICC_Profile' or $$self{TIFF_TYPE} ne 'IIQ')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'PROCESSED'}{$addr} and $dirName ne 'ICC_Profile' || $self->{'TIFF_TYPE'} ne 'IIQ') { } 0 693 693
Condition16%1/6
$self->{"PROCESSED"}{$addr} and $dirName ne "ICC_Profile" || $self->{"TIFF_TYPE"} ne "IIQ"
!ll&&!rl&&r
69300
$dirName ne "ICC_Profile" or $self->{"TIFF_TYPE"} ne "IIQ"
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"PROCESSED"}{$addr} and $dirName ne "ICC_Profile" || $self->{"TIFF_TYPE"} ne "IIQ"
$self->{"PROCESSED"}{$addr} $dirName ne "ICC_Profile" $self->{"TIFF_TYPE"} ne "IIQ"
Truth table25%1/4
A and B or C
A= $self->{"PROCESSED"}{$addr}B= $dirName ne "ICC_Profile"C= $self->{"TIFF_TYPE"} ne "IIQ"
ABCresult
0XX0
1000
11X1
1011
4417 0 ▶ if (defined $$dirInfo{DirLen} and not $$dirInfo{DirLen} and $dirName ne $$self{PROCESSED}{$addr}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $dirInfo->{'DirLen'} and not $dirInfo->{'DirLen'} and $dirName ne $self->{'PROCESSED'}{$addr}) { } 0 0 0
elsif ($self->Error("$dirName pointer references previous $self->{'PROCESSED'}{$addr} directory", 2)) { } 0 0 0
Condition0%0/6
defined $dirInfo->{"DirLen"} and not $dirInfo->{"DirLen"} and $dirName ne $self->{"PROCESSED"}{$addr}
!ll&&!rl&&r
000
defined $dirInfo->{"DirLen"} and not $dirInfo->{"DirLen"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $dirInfo->{"DirLen"} and not $dirInfo->{"DirLen"} and $dirName ne $self->{"PROCESSED"}{$addr}
defined $dirInfo->{"DirLen"} not $dirInfo->{"DirLen"} $dirName ne $self->{"PROCESSED"}{$addr}
Truth table0%0/4
A and not(B) and C
A= defined $dirInfo->{"DirLen"}B= not $dirInfo->{"DirLen"}C= $dirName ne $self->{"PROCESSED"}{$addr}
ABCresult
0XX0
10X0
1100
1111
4418 # it is hypothetically possible to have 2 different directories
4419 # with the same address if one has a length of zero
4420 } elsif ($self->Error("$dirName pointer references previous $$self{PROCESSED}{$addr} directory", 2)) {
4421 0 return undef;
4422 } else {
4423 0 $self->Warn("Deleting duplicate $dirName directory");
4424 0 ▶ $out and print $out " Deleting $dirName\n";
Branch: 1 branch
BranchTrueFalseTotal
$out and print $out " Deleting $dirName\n" 0 0 0
4425 # delete the duplicate directory (don't recreate it when writing new
4426 # tags to prevent propagating a duplicate IFD in cases like when the
4427 # same ExifIFD exists in both IFD0 and IFD1)
4428 0 return '';
4429 }
4430 } else {
4431 693 $$self{PROCESSED}{$addr} = $dirName;
4432 }
4433 }
4434 1623 my $oldDir = $$self{DIR_NAME};
4435 1623 my @save = @$self{'Compression','SubfileType'};
4436 1623 my $name;
4437 1623 ▶ if ($out) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out) 4 1619 1623
4438 $name = ($dirName eq 'MakerNotes' and $$dirInfo{TagInfo}) ?
4439 4 ▶ $$dirInfo{TagInfo}{Name} : $dirName;
Branch: 1 branch
BranchTrueFalseTotal
$dirName eq 'MakerNotes' && $dirInfo->{'TagInfo'} ? : 0 4 4
Condition33%1/3
$dirName eq "MakerNotes" and $dirInfo->{"TagInfo"}
!ll&&!rl&&r
400
MC/DC0%0/2
$dirName eq "MakerNotes" and $dirInfo->{"TagInfo"}
$dirName eq "MakerNotes" $dirInfo->{"TagInfo"}
Truth table33%1/3
A and B
A= $dirName eq "MakerNotes"B= $dirInfo->{"TagInfo"}
ABresult
0X0
100
111
4440 4 ▶ if (not defined $oldDir or $oldDir ne $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $oldDir or $oldDir ne $name) 3 1 4
Condition100%3/3
not defined $oldDir or $oldDir ne $name
l!l&&r!l&&!r
121
MC/DC100%2/2
not defined $oldDir or $oldDir ne $name
not defined $oldDir $oldDir ne $name
Truth table100%3/3
not(A) or B
A= not defined $oldDirB= $oldDir ne $name
ABresult
1X1
011
000
4441 3 ▶ my $verb = $isRewriting ? 'Rewriting' : 'Creating';
Branch: 1 branch
BranchTrueFalseTotal
$isRewriting ? : 1 2 3
4442 3 print $out " $verb $name\n";
4443 }
4444 }
4445 1623 my $saveOrder = GetByteOrder();
4446 1623 my $oldChanged = $$self{CHANGED};
4447 1623 $$self{DIR_NAME} = $dirName;
4448 1623 push @{$$self{PATH}}, $dirName;
4449 1623 $$dirInfo{IsWriting} = 1;
4450 1623 my $newData;
4451 {
4452 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
4453 1623 $newData = &$writeProc($self, $dirInfo, $tagTablePtr);
4454 }
4455 1623 pop @{$$self{PATH}};
4456 # nothing changed if error occurred or nothing was created
4457 1623 ▶ $$self{CHANGED} = $oldChanged unless defined $newData and (length($newData) or $isRewriting);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newData and length $newData || $isRewriting 59 1564 1623
Condition100%6/6
defined $newData and length $newData || $isRewriting
!ll&&!rl&&r
5541564
length $newData or $isRewriting
l!l&&r!l&&!r
1523414
MC/DC100%3/3
defined $newData and length $newData || $isRewriting
defined $newData length $newData $isRewriting
Truth table100%4/4
A and B or C
A= defined $newDataB= length $newDataC= $isRewriting
ABCresult
0XX0
1000
11X1
1011
4458 1623 $$self{DIR_NAME} = $oldDir;
4459 1623 @$self{'Compression','SubfileType'} = @save;
4460 1623 SetByteOrder($saveOrder);
4461 1623 ▶ if ($out) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out) 4 1619 1623
4462 4 ▶ print $out " Deleting $name\n" if defined $newData and not length $newData;
Branch: 1 branch
BranchTrueFalseTotal
if defined $newData and not length $newData 0 4 4
Condition33%1/3
defined $newData and not length $newData
!ll&&!rl&&r
040
MC/DC0%0/2
defined $newData and not length $newData
defined $newData not length $newData
Truth table33%1/3
A and not(B)
A= defined $newDataB= not length $newData
ABresult
0X0
100
111
4463 4 ▶ if ($$self{CHANGED} == $oldChanged and $$self{OPTIONS}{Verbose} > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CHANGED"} == $oldChanged and $self->{"OPTIONS"}{"Verbose"} > 2) 0 4 4
Condition33%1/3
$self->{"CHANGED"} == $oldChanged and $self->{"OPTIONS"}{"Verbose"} > 2
!ll&&!rl&&r
400
MC/DC0%0/2
$self->{"CHANGED"} == $oldChanged and $self->{"OPTIONS"}{"Verbose"} > 2
$self->{"CHANGED"} == $oldChanged $self->{"OPTIONS"}{"Verbose"} > 2
Truth table33%1/3
A and B
A= $self->{"CHANGED"} == $oldChangedB= $self->{"OPTIONS"}{"Verbose"} > 2
ABresult
0X0
100
111
4464 0 print $out "$$self{INDENT} [nothing changed in $name]\n";
4465 }
4466 }
4467 1623 return $newData;
4468 }
4469  
4470 #------------------------------------------------------------------------------
4471 # Uncommon utility routines to for reading binary data values
4472 # Inputs: 0) data reference, 1) offset into data
4473 sub Get64s($$)
4474 12 ▶{
Subroutine Get64s: called CC=2 SCAR=7.0
Pod undocumented
4475 12 my ($dataPt, $pos) = @_;
4476 12 ▶ my $pt = GetByteOrder() eq 'MM' ? 0 : 4; # get position of high word
Branch: 1 branch
BranchTrueFalseTotal
&GetByteOrder() eq 'MM' ? : 12 0 12
4477 12 my $hi = Get32s($dataPt, $pos + $pt); # preserve sign bit of high word
4478 12 my $lo = Get32u($dataPt, $pos + 4 - $pt);
4479 12 return $hi * 4294967296 + $lo;
4480 }
4481 sub Get64u($$)
4482 197 ▶{
Subroutine Get64u: called CC=2 SCAR=6.9
Pod undocumented
4483 197 my ($dataPt, $pos) = @_;
4484 197 ▶ my $pt = GetByteOrder() eq 'MM' ? 0 : 4; # get position of high word
Branch: 1 branch
BranchTrueFalseTotal
&GetByteOrder() eq 'MM' ? : 83 114 197
4485 197 my $hi = Get32u($dataPt, $pos + $pt); # (unsigned this time)
4486 197 my $lo = Get32u($dataPt, $pos + 4 - $pt);
4487 197 return $hi * 4294967296 + $lo;
4488 }
4489 sub GetFixed64s($$)
4490 0 ▶{
Subroutine GetFixed64s: not called CC=2 SCAR=17.9
Pod undocumented
4491 0 my ($dataPt, $pos) = @_;
4492 0 my $val = Get64s($dataPt, $pos) / 4294967296;
4493 # remove insignificant digits
4494 0 ▶ return int($val * 1e10 + ($val>0 ? 0.5 : -0.5)) / 1e10;
Branch: 1 branch
BranchTrueFalseTotal
$val > 0 ? : 0 0 0
4495 }
4496 # Decode extended 80-bit float used by Apple SANE and Intel 8087
4497 # (note: different than the IEEE standard 80-bit float)
4498 sub GetExtended($$)
4499 1 ▶{
Subroutine GetExtended: called CC=3 SCAR=11.2
Pod undocumented
4500 1 my ($dataPt, $pos) = @_;
4501 1 ▶ my $pt = GetByteOrder() eq 'MM' ? 0 : 2; # get position of exponent
Branch: 1 branch
BranchTrueFalseTotal
&GetByteOrder() eq 'MM' ? : 1 0 1
4502 1 my $exp = Get16u($dataPt, $pos + $pt);
4503 1 my $sig = Get64u($dataPt, $pos + 2 - $pt); # get significand as int64u
4504 1 ▶ my $sign = $exp & 0x8000 ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$exp & 32768 ? : 0 1 1
4505 1 $exp = ($exp & 0x7fff) - 16383 - 63; # (-63 to fractionalize significand)
4506 1 return $sign * $sig * 2 ** $exp;
4507 }
4508  
4509 #------------------------------------------------------------------------------
4510 # Dump data in hex and ASCII to console
4511 # Inputs: 0) data reference, 1) length or undef, 2-N) Options:
4512 # Options: Start => offset to start of data (default=0)
4513 # Addr => address to print for data start (default=DataPos+Base+Start)
4514 # DataPos => position of data within block (relative to Base)
4515 # Base => base offset for pointers from start of file
4516 # Width => width of printout (bytes, default=16)
4517 # Prefix => prefix to print at start of line (default='')
4518 # MaxLen => maximum length to dump
4519 # Out => output file reference
4520 # Len => data length
4521 sub HexDump($;$%)
4522 169 ▶{
Subroutine HexDump: called CC=16 SCAR=28.5
Pod undocumented
4523 169 my $dataPt = shift;
4524 169 my $len = shift;
4525 169 my %opts = @_;
4526 169 ▶ my $start = $opts{Start} || 0;
Condition100%2/2
$opts{'Start'} || 0
l!l
1654
MC/DC100%1/1
$opts{'Start'} || 0
$opts{'Start'}
Truth table100%2/2
A
A= $opts{'Start'}
Aresult
11
00
4527 169 my $addr = $opts{Addr};
4528 169 ▶ my $wid = $opts{Width} || 16;
Condition50%1/2
$opts{'Width'} || 16
l!l
0169
MC/DC0%0/1
$opts{'Width'} || 16
$opts{'Width'}
Truth table50%1/2
A
A= $opts{'Width'}
Aresult
11
00
4529 169 ▶ my $prefix = $opts{Prefix} || '';
Condition50%1/2
$opts{'Prefix'} || ''
l!l
1690
MC/DC0%0/1
$opts{'Prefix'} || ''
$opts{'Prefix'}
Truth table50%1/2
A
A= $opts{'Prefix'}
Aresult
11
00
4530 169 ▶ my $out = $opts{Out} || \*STDOUT;
Condition50%1/2
$opts{'Out'} || \*STDOUT
l!l
1690
MC/DC0%0/1
$opts{'Out'} || \*STDOUT
$opts{'Out'}
Truth table50%1/2
A
A= $opts{'Out'}
Aresult
11
00
4531 169 my $maxLen = $opts{MaxLen};
4532 169 my $datLen = length($$dataPt) - $start;
4533 169 my $more;
4534 169 ▶ $len = $opts{Len} if defined $opts{Len};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"Len"} 0 169 169
4535  
4536 169 ▶ $addr = $start + ($opts{DataPos} || 0) + ($opts{Base} || 0) unless defined $addr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $addr 70 99 169
Condition50%2/4
$opts{'DataPos'} || 0
l!l
700
$opts{'Base'} || 0
l!l
070
MC/DC0%0/1
$opts{'DataPos'} || 0
$opts{'DataPos'}
MC/DC0%0/1
$opts{'Base'} || 0
$opts{'Base'}
Truth table50%1/2
A
A= $opts{'DataPos'}
Aresult
11
00
Truth table50%1/2
A
A= $opts{'Base'}
Aresult
11
00
4537 169 ▶ $len = $datLen unless defined $len;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 4 165 169
4538 169 ▶ if ($maxLen and $len > $maxLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maxLen and $len > $maxLen) 5 164 169
Condition66%2/3
$maxLen and $len > $maxLen
!ll&&!rl&&r
01645
MC/DC50%1/2
$maxLen and $len > $maxLen
$maxLen $len > $maxLen
Truth table66%2/3
A and B
A= $maxLenB= $len > $maxLen
ABresult
0X0
100
111
4539 # print one line less to allow for $more line below
4540 5 $maxLen = int(($maxLen - 1) / $wid) * $wid;
4541 5 $more = $len - $maxLen;
4542 5 $len = $maxLen;
4543 }
4544 169 ▶ if ($len > $datLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $datLen) 0 169 169
4545 0 print $out "$prefix Warning: Attempted dump outside data\n";
4546 0 print $out "$prefix ($len bytes specified, but only $datLen available)\n";
4547 0 $len = $datLen;
4548 }
4549 169 my $format = sprintf("%%-%ds", $wid * 3);
4550 169 my $tmpl = 'H2' x $wid; # ('(H2)*' would have been nice, but older perl versions don't support it)
4551 169 my $i;
4552 169 ▶ for ($i=0; $i<$len; $i+=$wid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 228 169 397
4553 228 ▶ $wid > $len-$i and $wid = $len-$i, $tmpl = 'H2' x $wid;
Branch: 1 branch
BranchTrueFalseTotal
$wid > $len - $i and $wid = $len - $i, $tmpl = "H2" x $wid 159 69 228
4554 228 printf $out "$prefix%8.4x: ", $addr+$i;
4555 228 my $dat = substr($$dataPt, $i+$start, $wid);
4556 228 my $s = join(' ', unpack($tmpl, $dat));
4557 228 printf $out $format, $s;
4558 228 $dat =~ tr /\x00-\x1f\x7f-\xff/./;
4559 228 print $out "[$dat]\n";
4560 }
4561 169 ▶ $more and print $out "$prefix [snip $more bytes]\n";
Branch: 1 branch
BranchTrueFalseTotal
$more and print $out "$prefix [snip $more bytes]\n" 5 164 169
4562 }
4563  
4564 #------------------------------------------------------------------------------
4565 # Print verbose tag information
4566 # Inputs: 0) ExifTool object reference, 1) tag ID
4567 # 2) tag info reference (or undef)
4568 # 3-N) extra parms:
4569 # Parms: Index => Index of tag in menu (starting at 0)
4570 # Value => Tag value
4571 # DataPt => reference to value data block
4572 # DataPos => location of data block in file
4573 # Base => base added to all offsets
4574 # Size => length of value data within block
4575 # Format => value format string
4576 # Count => number of values
4577 # Extra => Extra Verbose=2 information to put after tag number
4578 # Table => Reference to tag table
4579 # Name => Name to use for unknown tag
4580 # --> plus any of these HexDump() options: Start, Addr, Width
4581 sub VerboseInfo($$$%)
4582 617 ▶{
Subroutine VerboseInfo: called CC=43 SCAR=45.2
Pod undocumented
4583 617 my ($self, $tagID, $tagInfo, %parms) = @_;
4584 617 my $verbose = $$self{OPTIONS}{Verbose};
4585 617 my $out = $$self{OPTIONS}{TextOut};
4586 617 my ($tag, $line, $hexID);
4587  
4588 # generate hex number if tagID is numerical
4589 617 ▶ if (defined $tagID) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tagID) { } 578 39 617
4590 578 ▶ $tagID =~ /^\d+$/ and $hexID = sprintf("0x%.4x", $tagID);
Branch: 1 branch
BranchTrueFalseTotal
$tagID =~ /^\d+$/ and $hexID = sprintf("0x%.4x", $tagID) 563 15 578
4591 } else {
4592 39 $tagID = 'Unknown';
4593 }
4594 # get tag name
4595 617 ▶ if ($tagInfo and $$tagInfo{Name}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagInfo and $tagInfo->{'Name'}) { } 617 0 617
elsif ($parms{'Name'}) { } 0 0 0
Condition33%1/3
$tagInfo and $tagInfo->{"Name"}
!ll&&!rl&&r
00617
MC/DC0%0/2
$tagInfo and $tagInfo->{"Name"}
$tagInfo $tagInfo->{"Name"}
Truth table33%1/3
A and B
A= $tagInfoB= $tagInfo->{"Name"}
ABresult
0X0
100
111
4596 617 $tag = $$tagInfo{Name};
4597 } elsif ($parms{Name}) { # (used for PNG Plus FPX tags)
4598 0 $tag = $parms{Name};
4599 0 undef $hexID;
4600 } else {
4601 0 my $prefix;
4602 0 ▶ $prefix = $parms{Table}{TAG_PREFIX} if $parms{Table};
Branch: 1 branch
BranchTrueFalseTotal
if $parms{"Table"} 0 0 0
4603 0 ▶ if ($prefix or $hexID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix or $hexID) { } 0 0 0
Condition0%0/3
$prefix or $hexID
l!l&&r!l&&!r
000
MC/DC0%0/2
$prefix or $hexID
$prefix $hexID
Truth table0%0/3
A or B
A= $prefixB= $hexID
ABresult
1X1
011
000
4604 0 ▶ $prefix = 'Unknown' unless $prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless $prefix 0 0 0
4605 0 ▶ $tag = $prefix . '_' . ($hexID ? $hexID : $tagID);
Branch: 1 branch
BranchTrueFalseTotal
$hexID ? : 0 0 0
4606 } else {
4607 0 $tag = $tagID;
4608 }
4609 }
4610 617 my $dataPt = $parms{DataPt};
4611 617 my $size = $parms{Size};
4612 617 ▶ $size = length $$dataPt unless defined $size or not $dataPt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size or not $dataPt 0 617 617
Condition66%2/3
defined $size or not $dataPt
l!l&&r!l&&!r
564530
MC/DC0%0/2
defined $size or not $dataPt
defined $size not $dataPt
Truth table66%2/3
A or not(B)
A= defined $sizeB= not $dataPt
ABresult
1X1
011
000
4613 617 my $indent = $$self{INDENT};
4614  
4615 # Level 1: print tag/value information
4616 617 $line = $indent;
4617 617 my $index = $parms{Index};
4618 617 ▶ if (defined $index) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index) 365 252 617
4619 365 $line .= $index . ') ';
4620 365 ▶ $line .= ' ' if length($index) < 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $index < 2 172 193 365
4621 365 $indent .= ' '; # indent everything else to align with tag name
4622 }
4623 617 $line .= $tag;
4624 617 ▶ if ($tagInfo and $$tagInfo{SubDirectory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo and $tagInfo->{'SubDirectory'}) { } 39 578 617
Condition66%2/3
$tagInfo and $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
057839
MC/DC50%1/2
$tagInfo and $tagInfo->{"SubDirectory"}
$tagInfo $tagInfo->{"SubDirectory"}
Truth table66%2/3
A and B
A= $tagInfoB= $tagInfo->{"SubDirectory"}
ABresult
0X0
100
111
4625 39 $line .= ' (SubDirectory) -->';
4626 } else {
4627 578 my $maxLen = 90 - length($line);
4628 578 my $val = $parms{Value};
4629 578 ▶ if (defined $val) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $val) { } 578 0 578
elsif ($dataPt) { } 0 0 0
4630 578 ▶ $val = '[' . join(',',@$val) . ']' if ref $val eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val eq "ARRAY" 0 578 578
4631 578 $line .= ' = ' . $self->Printable($val, $maxLen);
4632 } elsif ($dataPt) {
4633 0 ▶ my $start = $parms{Start} || 0;
Condition0%0/2
$parms{'Start'} || 0
l!l
00
MC/DC0%0/1
$parms{'Start'} || 0
$parms{'Start'}
Truth table0%0/2
A
A= $parms{'Start'}
Aresult
11
00
4634 0 $line .= ' = ' . $self->Printable(substr($$dataPt,$start,$size), $maxLen);
4635 }
4636 }
4637 617 print $out "$line\n";
4638  
4639 # Level 2: print detailed information about the tag
4640 617 ▶ if ($verbose > 1 and ($parms{Extra} or $parms{Format} or
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1 and $parms{"Extra"} || $parms{"Format"} || $parms{"DataPt"} || defined $size || $tagID =~ m[/]) 390 227 617
Condition86%13/15
$verbose > 1 and $parms{"Extra"} || $parms{"Format"} || $parms{"DataPt"} || defined $size || $tagID =~ m[/]
!ll&&!rl&&r
18740390
$parms{"Extra"} or $parms{"Format"} or $parms{"DataPt"} or defined $size or $tagID =~ m[/]
l!l&&r!l&&!r
390040
$parms{"Extra"} or $parms{"Format"} or $parms{"DataPt"} or defined $size
l!l&&r!l&&!r
390040
$parms{"Extra"} or $parms{"Format"} or $parms{"DataPt"}
l!l&&r!l&&!r
3523840
$parms{"Extra"} or $parms{"Format"}
l!l&&r!l&&!r
135178
MC/DC66%4/6
$verbose > 1 and $parms{"Extra"} || $parms{"Format"} || $parms{"DataPt"} || defined $size || $tagID =~ m[/]
$verbose > 1 $parms{"Extra"} $parms{"Format"} $parms{"DataPt"} defined $size $tagID =~ m[/]
Truth table71%5/7
A and B or C or D or E or F
A= $verbose > 1B= $parms{"Extra"}C= $parms{"Format"}D= $parms{"DataPt"}E= defined $sizeF= $tagID =~ m[/]
ABCDEFresult
0XXXXX0
1000000
11XXXX1
101XXX1
1001XX1
10001X1
1000011
4641 $parms{DataPt} or defined $size or $tagID =~ /\//))
4642 {
4643 390 $line = $indent . '- Tag ';
4644 390 ▶ if ($hexID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hexID) { } 389 1 390
4645 389 $line .= $hexID;
4646 } else {
4647 0 $tagID =~ s/([\0-\x1f\x7f-\xff])/sprintf('\\x%.2x',ord $1)/ge;
4648 1 $line .= "'${tagID}'";
4649 }
4650 390 ▶ $line .= $parms{Extra} if defined $parms{Extra};
Branch: 1 branch
BranchTrueFalseTotal
if defined $parms{"Extra"} 1 389 390
4651 390 my $format = $parms{Format};
4652 390 ▶ if ($format or defined $size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format or defined $size) 390 0 390
Condition66%2/3
$format or defined $size
l!l&&r!l&&!r
352380
MC/DC0%0/2
$format or defined $size
$format defined $size
Truth table66%2/3
A or B
A= $formatB= defined $size
ABresult
1X1
011
000
4653 390 $line .= ' (';
4654 390 ▶ if (defined $size) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $size) 390 0 390
4655 390 $line .= "$size bytes";
4656 390 ▶ $line .= ', ' if $format;
Branch: 1 branch
BranchTrueFalseTotal
if $format 352 38 390
4657 }
4658 390 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) 352 38 390
4659 352 $line .= $format;
4660 352 ▶ $line .= '['.$parms{Count}.']' if $parms{Count};
Branch: 1 branch
BranchTrueFalseTotal
if $parms{"Count"} 352 0 352
4661 }
4662 390 $line .= ')';
4663 }
4664 390 ▶ $line .= ':' if $verbose > 2 and $parms{DataPt};
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 and $parms{"DataPt"} 165 225 390
Condition66%2/3
$verbose > 2 and $parms{"DataPt"}
!ll&&!rl&&r
2250165
MC/DC50%1/2
$verbose > 2 and $parms{"DataPt"}
$verbose > 2 $parms{"DataPt"}
Truth table66%2/3
A and B
A= $verbose > 2B= $parms{"DataPt"}
ABresult
0X0
100
111
4665 390 print $out "$line\n";
4666 }
4667  
4668 # Level 3: do hex dump of value
4669 617 ▶ if ($verbose > 2 and $parms{DataPt} and (not $tagInfo or not $$tagInfo{ReadFromRAF})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 2 and $parms{"DataPt"} and not $tagInfo && $tagInfo->{"ReadFromRAF"}) 165 452 617
Condition66%6/9
$verbose > 2 and $parms{"DataPt"} and not $tagInfo && $tagInfo->{"ReadFromRAF"}
!ll&&!rl&&r
4520165
$verbose > 2 and $parms{"DataPt"}
!ll&&!rl&&r
43418165
$tagInfo && $tagInfo->{'ReadFromRAF'}
!ll&&!rl&&r
01650
MC/DC50%2/4
$verbose > 2 and $parms{"DataPt"} and not $tagInfo && $tagInfo->{"ReadFromRAF"}
$verbose > 2 $parms{"DataPt"} $tagInfo $tagInfo->{'ReadFromRAF'}
Truth table60%3/5
A and B and not(C && D)
A= $verbose > 2B= $parms{"DataPt"}C= $tagInfoD= $tagInfo->{'ReadFromRAF'}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
4670 165 $parms{Out} = $out;
4671 165 $parms{Prefix} = $indent;
4672 # limit dump length if Verbose < 5
4673 165 ▶ $parms{MaxLen} = $verbose == 3 ? 96 : 2048 if $verbose < 5;
Branch: 2 branches
BranchTrueFalseTotal
if $verbose < 5 165 0 165
$verbose == 3 ? : 165 0 165
4674 165 HexDump($dataPt, $size, %parms);
4675 }
4676 }
4677  
4678 #------------------------------------------------------------------------------
4679 # Dump trailer information
4680 # Inputs: 0) ExifTool object ref, 1) dirInfo hash (RAF, DirName, DataPos, DirLen)
4681 # Notes: Restores current file position before returning
4682 sub DumpTrailer($$)
4683 1 ▶{
Subroutine DumpTrailer: called CC=18 SCAR=48.2
Pod undocumented
4684 1 my ($self, $dirInfo) = @_;
4685 1 my $raf = $$dirInfo{RAF};
4686 1 my $curPos = $raf->Tell();
4687 1 ▶ my $trailer = $$dirInfo{DirName} || 'Unknown';
Condition50%1/2
$dirInfo->{'DirName'} || 'Unknown'
l!l
10
MC/DC0%0/1
$dirInfo->{'DirName'} || 'Unknown'
$dirInfo->{'DirName'}
Truth table50%1/2
A
A= $dirInfo->{'DirName'}
Aresult
11
00
4688 1 my $pos = $$dirInfo{DataPos};
4689 1 my $verbose = $$self{OPTIONS}{Verbose};
4690 1 my $htmlDump = $$self{HTML_DUMP};
4691 1 my ($buff, $buf2);
4692 1 my $size = $$dirInfo{DirLen};
4693 1 ▶ $pos = $curPos unless defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 1 1
4694  
4695 # get full trailer size if not specified
4696 1 for (;;) {
4697 1 ▶ unless ($size) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($size) 0 1 1
4698 0 ▶ $raf->Seek(0, 2) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek(0, 2) or last 0 0 0
4699 0 $size = $raf->Tell() - $pos;
4700 0 ▶ last unless $size;
Branch: 1 branch
BranchTrueFalseTotal
unless $size 0 0 0
4701 }
4702 1 ▶ $raf->Seek($pos, 0) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($pos, 0) or last 1 0 1
4703 1 ▶ if ($htmlDump) {
Branch: 1 branch
BranchTrueFalseTotal
if ($htmlDump) 0 1 1
4704 0 ▶ my $num = $raf->Read($buff, $size) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $num = $raf->Read($buff, $size) or return 0 0 0
4705 0 my $desc = "$trailer trailer";
4706 0 ▶ $desc = "[$desc]" if $trailer eq 'Unknown';
Branch: 1 branch
BranchTrueFalseTotal
if $trailer eq "Unknown" 0 0 0
4707 0 $self->HDump($pos, $num, $desc, undef, 0x08);
4708 0 last;
4709 }
4710 1 my $out = $$self{OPTIONS}{TextOut};
4711 1 printf $out "$trailer trailer (%d bytes at offset 0x%.4x):\n", $size, $pos;
4712 1 ▶ last unless $verbose > 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $verbose > 2 1 0 1
4713 0 my $num = $size; # number of bytes to read
4714 # limit size if not very verbose
4715 0 ▶ if ($verbose < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose < 5) 0 0 0
4716 0 ▶ my $limit = $verbose < 4 ? 96 : 512;
Branch: 1 branch
BranchTrueFalseTotal
$verbose < 4 ? : 0 0 0
4717 0 ▶ $num = $limit if $num > $limit;
Branch: 1 branch
BranchTrueFalseTotal
if $num > $limit 0 0 0
4718 }
4719 0 ▶ $raf->Read($buff, $num) == $num or return;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $num) == $num or return 0 0 0
4720 # read the end of the trailer too if not done already
4721 0 ▶ if ($size > 2 * $num) {
Branch: 2 branches
BranchTrueFalseTotal
if ($size > 2 * $num) { } 0 0 0
elsif ($size > $num) { } 0 0 0
4722 0 $raf->Seek($pos + $size - $num, 0);
4723 0 $raf->Read($buf2, $num);
4724 } elsif ($size > $num) {
4725 0 $raf->Seek($pos + $num, 0);
4726 0 $raf->Read($buf2, $size - $num);
4727 0 $buff .= $buf2;
4728 0 undef $buf2;
4729 }
4730 0 HexDump(\$buff, undef, Addr => $pos, Out => $out);
4731 0 ▶ if (defined $buf2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buf2) 0 0 0
4732 0 print $out " [snip ", $size - $num * 2, " bytes]\n";
4733 0 HexDump(\$buf2, undef, Addr => $pos + $size - $num, Out => $out);
4734 }
4735 0 last;
4736 }
4737 1 $raf->Seek($curPos, 0);
4738 }
4739  
4740 #------------------------------------------------------------------------------
4741 # Dump unknown trailer information
4742 # Inputs: 0) ExifTool ref, 1) dirInfo ref (with RAF, DataPos and DirLen defined)
4743 # Notes: changes dirInfo elements
4744 sub DumpUnknownTrailer($$)
4745 0 ▶{
Subroutine DumpUnknownTrailer: not called CC=15 SCAR=54.8
Pod undocumented
4746 0 my ($self, $dirInfo) = @_;
4747 0 my $pos = $$dirInfo{DataPos};
4748 0 my $endPos = $pos + $$dirInfo{DirLen};
4749 # account for preview/MPF image trailer
4750 0 my $value = $$self{VALUE};
4751 0 ▶ my $prePos = $$value{PreviewImageStart} || $$self{PreviewImageStart};
Condition0%0/3
$value->{'PreviewImageStart'} || $self->{'PreviewImageStart'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$value->{'PreviewImageStart'} || $self->{'PreviewImageStart'}
$value->{'PreviewImageStart'} $self->{'PreviewImageStart'}
Truth table0%0/3
A || B
A= $value->{'PreviewImageStart'}B= $self->{'PreviewImageStart'}
ABresult
1X1
011
000
4752 0 ▶ my $preLen = $$value{PreviewImageLength} || $$self{PreviewImageLength};
Condition0%0/3
$value->{'PreviewImageLength'} || $self->{'PreviewImageLength'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$value->{'PreviewImageLength'} || $self->{'PreviewImageLength'}
$value->{'PreviewImageLength'} $self->{'PreviewImageLength'}
Truth table0%0/3
A || B
A= $value->{'PreviewImageLength'}B= $self->{'PreviewImageLength'}
ABresult
1X1
011
000
4753 0 my $hidPos = $$value{HiddenDataOffset};
4754 0 my $hidLen = $$value{HiddenDataLength};
4755 0 my $tag = 'PreviewImage';
4756 0 my $mpImageNum = 0;
4757 0 my (%image, $lastOne);
4758 # add HiddenData to list of known trailer blocks
4759 0 ▶ if ($hidPos and $hidLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hidPos and $hidLen) 0 0 0
Condition0%0/3
$hidPos and $hidLen
!ll&&!rl&&r
000
MC/DC0%0/2
$hidPos and $hidLen
$hidPos $hidLen
Truth table0%0/3
A and B
A= $hidPosB= $hidLen
ABresult
0X0
100
111
4760 # call ReadHiddenData to validate hidden data and fix offset if necessary
4761 0 require Image::ExifTool::Sony;
4762 0 my $datPt = Image::ExifTool::Sony::ReadHiddenData($self, $hidPos, $hidLen);
4763 0 ▶ $image{$hidPos} = ['HiddenData', $hidLen] if $datPt;
Branch: 1 branch
BranchTrueFalseTotal
if $datPt 0 0 0
4764 }
4765 0 for (;;) {
4766 # add to Preview block list if valid and in the trailer
4767 0 ▶ $image{$prePos} = [$tag, $preLen] if $prePos and $preLen and $prePos+$preLen > $pos;
Branch: 1 branch
BranchTrueFalseTotal
if $prePos and $preLen and $prePos + $preLen > $pos 0 0 0
Condition0%0/6
$prePos and $preLen and $prePos + $preLen > $pos
!ll&&!rl&&r
000
$prePos and $preLen
!ll&&!rl&&r
000
MC/DC0%0/3
$prePos and $preLen and $prePos + $preLen > $pos
$prePos $preLen $prePos + $preLen > $pos
Truth table0%0/4
A and B and C
A= $prePosB= $preLenC= $prePos + $preLen > $pos
ABCresult
0XX0
10X0
1100
1111
4768 0 ▶ last if $lastOne; # checked all images
Branch: 1 branch
BranchTrueFalseTotal
if $lastOne 0 0 0
4769 # look for MPF images (in the proper order)
4770 0 ++$mpImageNum;
4771 0 $prePos = $$value{"MPImageStart ($mpImageNum)"};
4772 0 ▶ if (defined $prePos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prePos) { } 0 0 0
4773 0 $preLen = $$value{"MPImageLength ($mpImageNum)"};
4774 } else {
4775 0 $prePos = $$value{MPImageStart};
4776 0 $preLen = $$value{MPImageLength};
4777 0 $lastOne = 1;
4778 }
4779 0 $tag = "MPImage$mpImageNum";
4780 }
4781 # dump trailer sections in order
4782 0 $image{$endPos} = [ '', 0 ]; # add terminator "image"
4783 0 foreach $prePos (sort { $a <=> $b } keys %image) {
4784 0 ▶ if ($pos < $prePos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $prePos) 0 0 0
4785 # dump unknown trailer data
4786 0 $$dirInfo{DirName} = 'Unknown';
4787 0 $$dirInfo{DataPos} = $pos;
4788 0 $$dirInfo{DirLen} = $prePos - $pos;
4789 0 $self->DumpTrailer($dirInfo);
4790 }
4791 0 ($tag, $preLen) = @{$image{$prePos}};
4792 0 ▶ last unless $preLen;
Branch: 1 branch
BranchTrueFalseTotal
unless $preLen 0 0 0
4793 # dump image if verbose (it is htmlDump'd by ExtractImage)
4794 0 ▶ if ($$self{OPTIONS}{Verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"OPTIONS"}{"Verbose"}) 0 0 0
4795 0 $$dirInfo{DirName} = $tag;
4796 0 $$dirInfo{DataPos} = $prePos;
4797 0 $$dirInfo{DirLen} = $preLen;
4798 0 $self->DumpTrailer($dirInfo);
4799 }
4800 0 $pos = $prePos + $preLen;
4801 }
4802 }
4803  
4804 #------------------------------------------------------------------------------
4805 # Find last element in linked list
4806 # Inputs: 0) element in list
4807 # Returns: Last element in list
4808 sub LastInList($)
4809 38 ▶{
Subroutine LastInList: called CC=2 SCAR=6.9
Pod undocumented
4810 38 my $element = shift;
4811 38 ▶ while ($$element{Next}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element->{"Next"}) 1 38 39
4812 1 $element = $$element{Next};
4813 }
4814 38 return $element;
4815 }
4816  
4817 #------------------------------------------------------------------------------
4818 # Print verbose value while writing
4819 # Inputs: 0) ExifTool object ref, 1) heading "eg. '+ IPTC:Keywords',
4820 # 2) value, 3) [optional] extra text after value
4821 sub VerboseValue($$$;$)
4822 1089 ▶{
Subroutine VerboseValue: called CC=3 SCAR=11.0
Pod undocumented
4823 1089 ▶ return unless $_[0]{OPTIONS}{Verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"OPTIONS"}{"Verbose"} > 1 1078 11 1089
4824 11 my ($self, $str, $val, $xtra) = @_;
4825 11 my $out = $$self{OPTIONS}{TextOut};
4826 11 ▶ $xtra or $xtra = '';
Branch: 1 branch
BranchTrueFalseTotal
$xtra or $xtra = "" 2 9 11
4827 11 my $maxLen = 81 - length($str) - length($xtra);
4828 11 $val = $self->Printable($val, $maxLen);
4829 11 print $out " $str = '${val}'$xtra\n";
4830 }
4831  
4832 #------------------------------------------------------------------------------
4833 # Pack Unicode numbers into UTF8 string
4834 # Inputs: 0-N) list of Unicode numbers
4835 # Returns: Packed UTF-8 string
4836 sub PackUTF8(@)
4837 0 ▶{
Subroutine PackUTF8: not called CC=5 SCAR=34.0
Pod undocumented
4838 0 my @out;
4839 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
4840 0 my $ch = pop;
4841 0 ▶ unshift(@out, $ch), next if $ch < 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $ch < 128 0 0 0
4842 0 unshift(@out, 0x80 | ($ch & 0x3f));
4843 0 $ch >>= 6;
4844 0 ▶ unshift(@out, 0xc0 | $ch), next if $ch < 0x20;
Branch: 1 branch
BranchTrueFalseTotal
if $ch < 32 0 0 0
4845 0 unshift(@out, 0x80 | ($ch & 0x3f));
4846 0 $ch >>= 6;
4847 0 ▶ unshift(@out, 0xe0 | $ch), next if $ch < 0x10;
Branch: 1 branch
BranchTrueFalseTotal
if $ch < 16 0 0 0
4848 0 unshift(@out, 0x80 | ($ch & 0x3f));
4849 0 $ch >>= 6;
4850 0 unshift(@out, 0xf0 | ($ch & 0x07));
4851 }
4852 0 return pack('C*', @out);
4853 }
4854  
4855 #------------------------------------------------------------------------------
4856 # Unpack numbers from UTF8 string
4857 # Inputs: 0) UTF-8 string
4858 # Returns: List of Unicode numbers (sets $evalWarning on error)
4859 sub UnpackUTF8($)
4860 0 ▶{
Subroutine UnpackUTF8: not called CC=10 SCAR=47.0
Pod undocumented
4861 0 my (@out, $pos);
4862 0 pos($_[0]) = $pos = 0; # start at beginning of string
4863 0 for (;;) {
4864 0 my ($ch, $newPos, $val, $byte);
4865 0 ▶ if ($_[0] =~ /([\x80-\xff])/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /([\x80-\xff])/g) { } 0 0 0
4866 0 $ch = ord($1);
4867 0 $newPos = pos($_[0]) - 1;
4868 } else {
4869 0 $newPos = length $_[0];
4870 }
4871 # unpack 7-bit characters
4872 0 my $len = $newPos - $pos;
4873 0 ▶ push @out, unpack("x${pos}C$len",$_[0]) if $len;
Branch: 1 branch
BranchTrueFalseTotal
if $len 0 0 0
4874 0 ▶ last unless defined $ch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ch 0 0 0
4875 0 $pos = $newPos + 1;
4876 # minimum lead byte for 2-byte sequence is 0xc2 (overlong sequences
4877 # not allowed), 0xf8-0xfd are restricted by RFC 3629 (no 5 or 6 byte
4878 # sequences), and 0xfe and 0xff are not valid in UTF-8 strings
4879 0 ▶ if ($ch < 0xc2 or $ch >= 0xf8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch < 194 or $ch >= 248) 0 0 0
Condition0%0/3
$ch < 194 or $ch >= 248
l!l&&r!l&&!r
000
MC/DC0%0/2
$ch < 194 or $ch >= 248
$ch < 194 $ch >= 248
Truth table0%0/3
A or B
A= $ch < 194B= $ch >= 248
ABresult
1X1
011
000
4880 0 push @out, ord('?'); # invalid UTF-8
4881 0 $evalWarning = 'Bad UTF-8';
4882 0 next;
4883 }
4884 # decode 2, 3 and 4-byte sequences
4885 0 my $n = 1;
4886 0 ▶ if ($ch < 0xe0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ch < 224) { } 0 0 0
elsif ($ch < 240) { } 0 0 0
4887 0 $val = $ch & 0x1f; # 2-byte sequence
4888 } elsif ($ch < 0xf0) {
4889 0 $val = $ch & 0x0f; # 3-byte sequence
4890 0 ++$n;
4891 } else {
4892 0 $val = $ch & 0x07; # 4-byte sequence
4893 0 $n += 2;
4894 }
4895 0 ▶ unless ($_[0] =~ /\G([\x80-\xbf]{$n})/g) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0] =~ /\G([\x80-\xbf]{$n})/g) 0 0 0
4896 0 pos($_[0]) = $pos; # restore position
4897 0 push @out, ord('?'); # invalid UTF-8
4898 0 $evalWarning = 'Bad UTF-8';
4899 0 next;
4900 }
4901 0 foreach $byte (unpack 'C*', $1) {
4902 0 $val = ($val << 6) | ($byte & 0x3f);
4903 }
4904 0 push @out, $val; # save Unicode character value
4905 0 $pos += $n; # position at end of UTF-8 character
4906 }
4907 0 return @out;
4908 }
4909  
4910 #------------------------------------------------------------------------------
4911 # Generate a new, random GUID
4912 # Inputs: <none>
4913 # Returns: GUID string
4914 61 my $guidCount;
4915 sub NewGUID()
4916 61 ▶{
Subroutine NewGUID: called CC=3 SCAR=11.0
Pod undocumented
4917 61 my @tm = localtime time;
4918 61 ▶ $guidCount = 0 unless defined $guidCount and ++$guidCount < 0x100;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $guidCount and ++$guidCount < 256 15 46 61
Condition66%2/3
defined $guidCount and ++$guidCount < 256
!ll&&!rl&&r
15046
MC/DC50%1/2
defined $guidCount and ++$guidCount < 256
defined $guidCount ++$guidCount < 256
Truth table66%2/3
A and B
A= defined $guidCountB= ++$guidCount < 256
ABresult
0X0
100
111
4919 61 return sprintf('%.4d%.2d%.2d%.2d%.2d%.2d%.2X%.4X%.4X%.4X%.4X',
4920 $tm[5]+1900, $tm[4]+1, $tm[3], $tm[2], $tm[1], $tm[0], $guidCount,
4921 $$ & 0xffff, rand(0x10000), rand(0x10000), rand(0x10000));
4922 }
4923  
4924 #------------------------------------------------------------------------------
4925 # Make TIFF header for raw data
4926 # Inputs: 0) width, 1) height, 2) num colour components, 3) bits, 4) resolution
4927 # 5) color-map data for palette-color image (8 or 16 bit)
4928 # Returns: TIFF header
4929 # Notes: Multi-byte data must be little-endian
4930 sub MakeTiffHeader($$$$;$$)
4931 0 ▶{
Subroutine MakeTiffHeader: not called CC=10 SCAR=47.0
Pod undocumented
4932 0 my ($w, $h, $cols, $bits, $res, $cmap) = @_;
4933 0 ▶ $res or $res = 72;
Branch: 1 branch
BranchTrueFalseTotal
$res or $res = 72 0 0 0
4934 0 my $saveOrder = GetByteOrder();
4935 0 SetByteOrder('II');
4936 0 ▶ if (not $cmap) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $cmap) { } 0 0 0
elsif (length $cmap == 3 * 2 ** $bits) { } 0 0 0
elsif (length $cmap != 6 * 2 ** $bits) { } 0 0 0
4937 0 $cmap = '';
4938 } elsif (length $cmap == 3 * 2**$bits) {
4939 # convert to short
4940 0 $cmap = pack 'v*', map { $_ | ($_<<8) } unpack 'C*', $cmap;
4941 } elsif (length $cmap != 6 * 2**$bits) {
4942 0 $cmap = '';
4943 }
4944 0 ▶ my $cmo = $cmap ? 12 : 0; # offset due to ColorMap IFD entry
Branch: 1 branch
BranchTrueFalseTotal
$cmap ? : 0 0 0
4945 0 ▶ my $hdr =
Branch: 4 branches
BranchTrueFalseTotal
$cols == 1 ? : 0 0 0
$cmap ? : 0 0 0
$cols == 1 ? : 0 0 0
$cmap ? : 0 0 0
4946 "\x49\x49\x2a\0\x08\0\0\0\x0e\0" . # 0x00 14 menu entries:
4947 "\xfe\x00\x04\0\x01\0\0\0\x00\0\0\0" . # 0x0a SubfileType = 0
4948 "\x00\x01\x04\0\x01\0\0\0" . Set32u($w) . # 0x16 ImageWidth
4949 "\x01\x01\x04\0\x01\0\0\0" . Set32u($h) . # 0x22 ImageHeight
4950 "\x02\x01\x03\0" . Set32u($cols) . # 0x2e BitsPerSample
4951 Set32u($cols == 1 ? $bits : 0xb6 + $cmo) .
4952 "\x03\x01\x03\0\x01\0\0\0\x01\0\0\0" . # 0x3a Compression = 1
4953 "\x06\x01\x03\0\x01\0\0\0" . # 0x46 PhotometricInterpretation
4954 Set32u($cmap ? 3 : $cols == 1 ? 1 : 2) .
4955 "\x11\x01\x04\0\x01\0\0\0" . # 0x52 StripOffsets
4956 Set32u(0xcc + $cmo + length($cmap)) .
4957 "\x15\x01\x03\0\x01\0\0\0" . Set32u($cols) . # 0x5e SamplesPerPixel
4958 "\x16\x01\x04\0\x01\0\0\0" . Set32u($h) . # 0x6a RowsPerStrip
4959 "\x17\x01\x04\0\x01\0\0\0" . # 0x76 StripByteCounts
4960 Set32u($w * $h * $cols * int(($bits+7)/8)) .
4961 "\x1a\x01\x05\0\x01\0\0\0" . Set32u(0xbc + $cmo) . # 0x82 XResolution
4962 "\x1b\x01\x05\0\x01\0\0\0" . Set32u(0xc4 + $cmo) . # 0x8e YResolution
4963 "\x1c\x01\x03\0\x01\0\0\0\x01\0\0\0" . # 0x9a PlanarConfiguration = 1
4964 "\x28\x01\x03\0\x01\0\0\0\x02\0\0\0" . # 0xa6 ResolutionUnit = 2
4965 ($cmap ? # 0xb2 ColorMap [optional]
4966 "\x40\x01\x03\0" . Set32u(3 * 2**$bits) . "\xd8\0\0\0" : '') .
4967 "\0\0\0\0" . # 0xb2+$cmo (no IFD1)
4968 (Set16u($bits) x 3) . # 0xb6+$cmo BitsPerSample value
4969 Set32u($res) . "\x01\0\0\0" . # 0xbc+$cmo XResolution = 72
4970 Set32u($res) . "\x01\0\0\0" . # 0xc4+$cmo YResolution = 72
4971 $cmap; # 0xcc or 0xd8 (cmap and data go here)
4972 0 SetByteOrder($saveOrder);
4973 0 return $hdr;
4974 }
4975  
4976 #------------------------------------------------------------------------------
4977 # Return current time in EXIF format
4978 # Inputs: 0) [optional] ExifTool ref, 1) flag to include timezone (0 to disable,
4979 # undef or 1 to include)
4980 # Returns: time string
4981 # - a consistent value is returned for each processed file
4982 sub TimeNow(;$$)
4983 61 ▶{
Subroutine TimeNow: called CC=5 SCAR=17.2
Pod undocumented
4984 61 my ($self, $tzFlag) = @_;
4985 61 my $timeNow;
4986 61 ▶ ref $self or $tzFlag = $self, $self = { };
Branch: 1 branch
BranchTrueFalseTotal
ref $self or $tzFlag = $self, $self = {} 61 0 61
4987 61 ▶ if ($$self{Now}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'Now'}) { } 0 61 61
4988 0 $timeNow = $$self{Now}[0];
4989 } else {
4990 61 my $time = time();
4991 61 my @tm = localtime $time;
4992 61 my $tz = TimeZoneString(\@tm, $time);
4993 61 $timeNow = sprintf("%4d:%.2d:%.2d %.2d:%.2d:%.2d",
4994 $tm[5]+1900, $tm[4]+1, $tm[3],
4995 $tm[2], $tm[1], $tm[0]);
4996 61 $$self{Now} = [ $timeNow, $tz ];
4997 }
4998 61 ▶ $timeNow .= $$self{Now}[1] if $tzFlag or not defined $tzFlag;
Branch: 1 branch
BranchTrueFalseTotal
if $tzFlag or not defined $tzFlag 61 0 61
Condition33%1/3
$tzFlag or not defined $tzFlag
l!l&&r!l&&!r
0610
MC/DC0%0/2
$tzFlag or not defined $tzFlag
$tzFlag not defined $tzFlag
Truth table33%1/3
A or not(B)
A= $tzFlagB= not defined $tzFlag
ABresult
1X1
011
000
4999 61 return $timeNow;
5000 }
5001  
5002 #------------------------------------------------------------------------------
5003 # Inverse date/time print conversion (reformat to YYYY:mm:dd HH:MM:SS[.ss][+-HH:MM|Z])
5004 # Inputs: 0) ExifTool object ref, 1) Date/Time string, 2) timezone flag:
5005 # 0 - remove timezone and sub-seconds if they exist
5006 # 1 - add timezone if it doesn't exist
5007 # undef - leave timezone alone
5008 # 3) flag to allow date-only (YYYY, YYYY:mm or YYYY:mm:dd) or time without seconds
5009 # Returns: formatted date/time string (or undef and issues warning on error)
5010 # Notes: currently accepts different separators, but doesn't use DateFormat yet
5011 my $strptimeLib; # strptime library name if available
5012 sub InverseDateTime($$;$$)
5013 474 ▶{
Subroutine InverseDateTime: called CC=56 SCAR=55.3
Pod undocumented
5014 474 my ($self, $val, $tzFlag, $dateOnly) = @_;
5015 474 my ($rtnVal, $tz, $fs);
5016 474 my $fmt = $$self{OPTIONS}{DateFormat};
5017 # strip off timezone first if it exists
5018 474 ▶ if (not $fmt and $val =~ s/([-+])(\d{1,2}):?(\d{2})\s*(DST)?$//i) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $fmt and $val =~ s/([-+])(\d{1,2}):?(\d{2})\s*(DST)?$//i) { } 6 468 474
elsif (not $fmt and $val =~ s/Z$//i) { } 0 468 468
Condition100%3/3
not $fmt and $val =~ s/([-+])(\d{1,2}):?(\d{2})\s*(DST)?$//i
!ll&&!rl&&r
14676
MC/DC100%2/2
not $fmt and $val =~ s/([-+])(\d{1,2}):?(\d{2})\s*(DST)?$//i
not $fmt $val =~ s/([-+])(\d{1,2}):?(\d{2})\s*(DST)?$//i
Truth table100%3/3
not(A) and B
A= not $fmtB= $val =~ s/([-+])(\d{1,2}):?(\d{2})\s*(DST)?$//i
ABresult
0X0
100
111
5019 6 $tz = sprintf("$1%.2d:$3", $2);
5020 ▶ } elsif (not $fmt and $val =~ s/Z$//i) {
Condition66%2/3
not $fmt and $val =~ s/Z$//i
!ll&&!rl&&r
14670
MC/DC0%0/2
not $fmt and $val =~ s/Z$//i
not $fmt $val =~ s/Z$//i
Truth table66%2/3
not(A) and B
A= not $fmtB= $val =~ s/Z$//i
ABresult
0X0
100
111
5021 0 $tz = 'Z';
5022 } else {
5023 468 $tz = '';
5024 # allow special value of 'now'
5025 468 ▶ return $self->TimeNow($tzFlag) if lc($val) eq 'now';
Branch: 1 branch
BranchTrueFalseTotal
if lc $val eq "now" 0 468 468
5026 }
5027 # only convert date if a format was specified and the date is recognizable
5028 474 ▶ if ($fmt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt) 1 473 474
5029 1 ▶ unless (defined $strptimeLib) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $strptimeLib) 1 0 1
5030 1 ▶ if (eval { require POSIX::strptime }) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require POSIX::strptime } }) { } 1 0 1
elsif (eval { do { require Time::Piece } }) { } 0 0 0
5031 1 $strptimeLib = 'POSIX::strptime';
5032 0 } elsif (eval { require Time::Piece }) {
5033 0 $strptimeLib = 'Time::Piece';
5034 # (call use_locale() to convert localized date/time,
5035 # only available in Time::Piece 1.32 and later)
5036 0 eval { Time::Piece->use_locale() };
5037 } else {
5038 0 $strptimeLib = '';
5039 }
5040 }
5041 # handle fractional seconds (%f) and time zone (%z)
5042 1 ($fs, $tz) = ('', '');
5043 1 ▶ if ($fmt =~ /%(f|:?z)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ /%(f|:?z)/) 1 0 1
5044 1 ▶ if ($fmt =~ s/(.*[^%])%f/$1/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ s/(.*[^%])%f/$1/) 1 0 1
5045 1 ▶ $fs = $2 if $val =~ s/(.*)(\.\d+)/$1/; # (take last .### as fractional seconds)
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ s/(.*)(\.\d+)/$1/ 1 0 1
5046 }
5047 1 ▶ if ($fmt =~ s/(.*[^%])%(:?)z/$1/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ s/(.*[^%])%(:?)z/$1/) 1 0 1
5048 1 my $colon = $2;
5049 1 ▶ $tz = "$2:$3" if $val =~ s/(.*)([-+]\d{2})$colon(\d{2})/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ s/(.*)([-+]\d{2})$colon(\d{2})/$1/ 1 0 1
5050 }
5051 }
5052 1 my ($lib, $wrn, @a);
5053 1 TryLib: for ($lib=$strptimeLib; ; $lib='') {
5054 # handle %s format ourself (not supported in Fedora, see forum15032)
5055 1 ▶ if ($fmt eq '%s') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt eq "%s") 0 1 1
5056 0 $val = ConvertUnixTime($val, 1);
5057 0 last;
5058 }
5059 1 ▶ if (not $lib) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $lib) { } 0 1 1
elsif ($lib eq 'POSIX::strptime') { } 1 0 1
5060 0 ▶ last unless $$self{OPTIONS}{StrictDate};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"OPTIONS"}{"StrictDate"} 0 0 0
5061 0 ▶ warn $wrn || "Install POSIX::strptime or Time::Piece for inverse date/time conversions\n";
Condition0%0/2
$wrn || "Install POSIX::strptime or Time::Piece for inverse date/time conversions\n"
l!l
00
MC/DC0%0/1
$wrn || "Install POSIX::strptime or Time::Piece for inverse date/time conversions\n"
$wrn
Truth table0%0/2
A
A= $wrn
Aresult
11
00
5062 0 return undef;
5063 } elsif ($lib eq 'POSIX::strptime') {
5064 1 @a = eval { POSIX::strptime($val, $fmt) };
5065 } else {
5066 # protect against a negative epoch time, it can cause a hard crash in Windows
5067 0 ▶ if ($^O eq 'MSWin32' and $fmt =~ /%s/ and $val =~ /-\d/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32" and $fmt =~ /%s/ and $val =~ /-\d/) 0 0 0
Condition0%0/6
$^O eq "MSWin32" and $fmt =~ /%s/ and $val =~ /-\d/
!ll&&!rl&&r
000
$^O eq "MSWin32" and $fmt =~ /%s/
!ll&&!rl&&r
000
MC/DC0%0/3
$^O eq "MSWin32" and $fmt =~ /%s/ and $val =~ /-\d/
$^O eq "MSWin32" $fmt =~ /%s/ $val =~ /-\d/
Truth table0%0/4
A and B and C
A= $^O eq "MSWin32"B= $fmt =~ /%s/C= $val =~ /-\d/
ABCresult
0XX0
10X0
1100
1111
5068 0 warn "Can't convert negative epoch time\n";
5069 0 return undef;
5070 }
5071 0 @a = eval {
5072 0 my $t = Time::Piece->strptime($val, $fmt);
5073 0 return ($t->sec, $t->min, $t->hour, $t->mday, $t->_mon, $t->_year);
5074 };
5075 }
5076 1 ▶ if (defined $a[5] and length $a[5]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $a[5] and length $a[5]) { } 1 0 1
Condition33%1/3
defined $a[5] and length $a[5]
!ll&&!rl&&r
001
MC/DC0%0/2
defined $a[5] and length $a[5]
defined $a[5] length $a[5]
Truth table33%1/3
A and B
A= defined $a[5]B= length $a[5]
ABresult
0X0
100
111
5077 1 $a[5] += 1900; # add 1900 to year
5078 } else {
5079 0 $wrn = "Invalid date/time (no year) using $lib\n";
5080 0 next;
5081 }
5082 1 ▶ ++$a[4] if defined $a[4] and length $a[4]; # add 1 to month
Branch: 1 branch
BranchTrueFalseTotal
if defined $a[4] and length $a[4] 1 0 1
Condition33%1/3
defined $a[4] and length $a[4]
!ll&&!rl&&r
001
MC/DC0%0/2
defined $a[4] and length $a[4]
defined $a[4] length $a[4]
Truth table33%1/3
A and B
A= defined $a[4]B= length $a[4]
ABresult
0X0
100
111
5083 1 my $i;
5084 1 foreach $i (0..4) {
5085 5 ▶ if (not defined $a[$i] or not length $a[$i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $a[$i] && length $a[$i]) { } 0 5 5
elsif (length $a[$i] < 2) { } 3 2 5
Condition33%1/3
defined $a[$i] && length $a[$i]
!ll&&!rl&&r
005
MC/DC0%0/2
defined $a[$i] && length $a[$i]
defined $a[$i] length $a[$i]
Truth table33%1/3
A && B
A= defined $a[$i]B= length $a[$i]
ABresult
0X0
100
111
5086 0 ▶ if ($i < 2 or $dateOnly) { # (allow missing minutes/seconds)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 2 or $dateOnly) { } 0 0 0
Condition0%0/3
$i < 2 or $dateOnly
l!l&&r!l&&!r
000
MC/DC0%0/2
$i < 2 or $dateOnly
$i < 2 $dateOnly
Truth table0%0/3
A or B
A= $i < 2B= $dateOnly
ABresult
1X1
011
000
5087 0 $a[$i] = ' ';
5088 } else {
5089 0 $wrn = "Incomplete date/time specification using $lib\n";
5090 0 next TryLib;
5091 }
5092 } elsif (length($a[$i]) < 2) {
5093 3 $a[$i] = "0$a[$i]"; # pad to 2 digits if necessary
5094 }
5095 }
5096 1 $val = join(':', @a[5,4,3]) . ' ' . join(':', @a[2,1,0]) . $fs . $tz;
5097 1 last;
5098 }
5099 }
5100 474 ▶ if ($val =~ /(\d{4})/g) { # get YYYY
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /(\d{4})/g) 465 9 474
5101 465 my $yr = $1;
5102 465 my @a = ($val =~ /\d{1,2}/g); # get mm, dd, HH, and maybe MM, SS
5103 465 ▶ length($_) < 2 and $_ = "0$_" foreach @a; # pad to 2 digits if necessary
Branch: 1 branch
BranchTrueFalseTotal
length $_ < 2 and $_ = "0$_" 7 2222 2229
5104 465 ▶ if (@a >= 3) {
Branch: 2 branches
BranchTrueFalseTotal
if (@a >= 3) { } 439 26 465
elsif ($dateOnly) { } 26 0 26
5105 439 my $ss = $a[4]; # get SS
5106 439 ▶ push @a, '00' while @a < 5; # add MM, SS if not given
Branch: 1 branch
BranchTrueFalseTotal
@a < 5 and do { push @a, "00" } 2 439 441
5107 # get sub-seconds if they exist (must be after SS, and have leading ".")
5108 439 ▶ unless ($fmt) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fmt) 438 1 439
5109 438 ▶ $fs = (@a > 5 and $val =~ /(\.\d+)\s*$/) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
@a > 5 && $val =~ /(\.\d+)\s*$/ ? : 5 433 438
Condition100%3/3
@a > 5 and $val =~ /(\.\d+)\s*$/
!ll&&!rl&&r
43035
MC/DC100%2/2
@a > 5 and $val =~ /(\.\d+)\s*$/
@a > 5 $val =~ /(\.\d+)\s*$/
Truth table100%3/3
A and B
A= @a > 5B= $val =~ /(\.\d+)\s*$/
ABresult
0X0
100
111
5110 }
5111 # add/remove timezone if necessary
5112 439 ▶ if ($tzFlag) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tzFlag) { } 34 405 439
elsif (defined $tzFlag) { } 92 313 405
5113 34 ▶ if (not $tz) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tz) 34 0 34
5114 34 ▶ if (eval { require Time::Local }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Time::Local } }) { } 34 0 34
5115 # determine timezone offset for this time
5116 34 my @args = ($a[4],$a[3],$a[2],$a[1],$a[0]-1,$yr);
5117 34 my $diff = Time::Local::timegm(@args) - TimeLocal(@args);
5118 34 $tz = TimeZoneString($diff / 60);
5119 } else {
5120 0 $tz = 'Z'; # don't know time zone
5121 }
5122 }
5123 } elsif (defined $tzFlag) {
5124 92 $tz = $fs = ''; # remove timezone and sub-seconds
5125 }
5126 439 ▶ if (defined $ss and $ss < 60) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ss and $ss < 60) { } 438 1 439
elsif ($dateOnly) { } 1 0 1
Condition66%2/3
defined $ss and $ss < 60
!ll&&!rl&&r
10438
MC/DC50%1/2
defined $ss and $ss < 60
defined $ss $ss < 60
Truth table66%2/3
A and B
A= defined $ssB= $ss < 60
ABresult
0X0
100
111
5127 438 $ss = ":$ss";
5128 } elsif ($dateOnly) {
5129 1 $ss = '';
5130 } else {
5131 0 $ss = ':00';
5132 }
5133 # construct properly formatted date/time string
5134 439 ▶ if ($a[0] < 1 or $a[0] > 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a[0] < 1 or $a[0] > 12) 0 439 439
Condition33%1/3
$a[0] < 1 or $a[0] > 12
l!l&&r!l&&!r
00439
MC/DC0%0/2
$a[0] < 1 or $a[0] > 12
$a[0] < 1 $a[0] > 12
Truth table33%1/3
A or B
A= $a[0] < 1B= $a[0] > 12
ABresult
1X1
011
000
5135 0 warn "Month '$a[0]' out of range 1..12\n";
5136 0 return undef;
5137 }
5138 439 ▶ if ($a[1] < 1 or $a[1] > 31) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a[1] < 1 or $a[1] > 31) 0 439 439
Condition33%1/3
$a[1] < 1 or $a[1] > 31
l!l&&r!l&&!r
00439
MC/DC0%0/2
$a[1] < 1 or $a[1] > 31
$a[1] < 1 $a[1] > 31
Truth table33%1/3
A or B
A= $a[1] < 1B= $a[1] > 31
ABresult
1X1
011
000
5139 0 warn "Day '$a[1]' out of range 1..31\n";
5140 0 return undef;
5141 }
5142 439 ▶ $a[2] > 24 and warn("Hour '$a[2]' out of range 0..24\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
$a[2] > 24 and warn("Hour '$a[2]' out of range 0..24\n"), (return undef) 0 439 439
5143 439 ▶ $a[3] > 59 and warn("Minutes '$a[3]' out of range 0..59\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
$a[3] > 59 and warn("Minutes '$a[3]' out of range 0..59\n"), (return undef) 0 439 439
5144 439 $rtnVal = "$yr:$a[0]:$a[1] $a[2]:$a[3]$ss$fs$tz";
5145 } elsif ($dateOnly) {
5146 26 $rtnVal = join ':', $yr, @a;
5147 }
5148 }
5149 474 ▶ $rtnVal or warn "Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z])\n";
Branch: 1 branch
BranchTrueFalseTotal
$rtnVal or warn "Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z])\n" 465 9 474
5150 474 return $rtnVal;
5151 }
5152  
5153 #------------------------------------------------------------------------------
5154 # Set byte order according to our current preferences
5155 # Inputs: 0) ExifTool object ref, 1) default byte order
5156 # Returns: new byte order ('II' or 'MM') and sets current byte order
5157 # Notes: takes the first of the following that is valid:
5158 # 1) ByteOrder option
5159 # 2) new value for ExifByteOrder
5160 # 3) default byte order passed to this routine
5161 # 4) makenote byte order from last file read
5162 # 5) big endian
5163 sub SetPreferredByteOrder($;$)
5164 46 ▶{
Subroutine SetPreferredByteOrder: called CC=8 SCAR=25.4
Pod undocumented
5165 46 my ($self, $default) = @_;
5166 my $byteOrder = $self->Options('ByteOrder') ||
5167 $self->GetNewValue('ExifByteOrder') ||
5168 46 ▶ $default || $$self{MAKER_NOTE_BYTE_ORDER} || 'MM';
Condition81%9/11
$self->Options('ByteOrder') || $self->GetNewValue('ExifByteOrder') || $default || $self->{'MAKER_NOTE_BYTE_ORDER'} || 'MM'
l!l
1036
$self->Options("ByteOrder") or $self->GetNewValue("ExifByteOrder") or $default or $self->{"MAKER_NOTE_BYTE_ORDER"}
l!l&&r!l&&!r
8236
$self->Options("ByteOrder") or $self->GetNewValue("ExifByteOrder") or $default
l!l&&r!l&&!r
8038
$self->Options("ByteOrder") or $self->GetNewValue("ExifByteOrder")
l!l&&r!l&&!r
0838
MC/DC50%2/4
$self->Options('ByteOrder') || $self->GetNewValue('ExifByteOrder') || $default || $self->{'MAKER_NOTE_BYTE_ORDER'} || 'MM'
$self->Options("ByteOrder") $self->GetNewValue("ExifByteOrder") $default $self->{"MAKER_NOTE_BYTE_ORDER"}
Truth table60%3/5
A or B or C or D
A= $self->Options("ByteOrder")B= $self->GetNewValue("ExifByteOrder")C= $defaultD= $self->{"MAKER_NOTE_BYTE_ORDER"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
5169 46 ▶ unless (SetByteOrder($byteOrder)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&SetByteOrder($byteOrder)) 0 46 46
5170 0 ▶ warn "Invalid byte order '${byteOrder}'\n" if $self->Options('Verbose');
Branch: 1 branch
BranchTrueFalseTotal
if $self->Options("Verbose") 0 0 0
5171 0 ▶ $byteOrder = $$self{MAKER_NOTE_BYTE_ORDER} || 'MM';
Condition0%0/2
$self->{'MAKER_NOTE_BYTE_ORDER'} || 'MM'
l!l
00
MC/DC0%0/1
$self->{'MAKER_NOTE_BYTE_ORDER'} || 'MM'
$self->{'MAKER_NOTE_BYTE_ORDER'}
Truth table0%0/2
A
A= $self->{'MAKER_NOTE_BYTE_ORDER'}
Aresult
11
00
5172 0 SetByteOrder($byteOrder);
5173 }
5174 46 return GetByteOrder();
5175 }
5176  
5177 #------------------------------------------------------------------------------
5178 # Assemble a continuing fraction into a rational value
5179 # Inputs: 0) numerator, 1) denominator
5180 # 2-N) list of fraction denominators, deepest first
5181 # Returns: numerator, denominator (in list context)
5182 sub AssembleRational($$@)
5183 4997 ▶{
Subroutine AssembleRational: called CC=2 SCAR=6.9
Pod undocumented
5184 4997 ▶ @_ < 3 and return @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ < 3 and return @_ 1474 3523 4997
5185 3523 my ($num, $denom, $frac) = splice(@_, 0, 3);
5186 3523 return AssembleRational($frac*$num+$denom, $num, @_);
5187 }
5188  
5189 #------------------------------------------------------------------------------
5190 # Convert a floating point number (or 'inf' or 'undef' or a fraction) into a rational
5191 # Inputs: 0) floating point number, 1) optional maximum value (defaults to 0x7fffffff)
5192 # Returns: numerator, denominator (in list context)
5193 # Notes:
5194 # - the returned rational will be accurate to at least 8 significant figures if possible
5195 # - eg. an input of 3.14159265358979 returns a rational of 104348/33215,
5196 # which equals 3.14159265392142 and is accurate to 10 significant figures
5197 # - the returned rational will be reduced to the lowest common denominator except when
5198 # the input is a fraction in which case the input is returned unchanged
5199 # - these routines were a bit tricky, but fun to write!
5200 sub Rationalize($;$)
5201 633 ▶{
Subroutine Rationalize: called CC=13 SCAR=27.9
Pod undocumented
5202 633 my $val = shift;
5203 633 ▶ return (1, 0) if $val eq 'inf';
Branch: 1 branch
BranchTrueFalseTotal
if $val eq "inf" 0 633 633
5204 633 ▶ return (0, 0) if $val eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $val eq "undef" 0 633 633
5205 633 ▶ return ($1,$2) if $val =~ m{^([-+]?\d+)/(\d+)$}; # accept fractional values
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ m[^([-+]?\d+)/(\d+)$] 16 617 633
5206 # Note: Just testing "if $val" doesn't work because '0.0' is true! (ugghh!)
5207 617 ▶ return (0, 1) if $val == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $val == 0 39 578 617
5208 578 ▶ my $sign = $val < 0 ? ($val = -$val, -1) : 1;
Branch: 1 branch
BranchTrueFalseTotal
$val < 0 ? : 12 566 578
5209 578 my ($num, $denom, @fracs);
5210 578 my $frac = $val;
5211 578 ▶ my $maxInt = shift || 0x7fffffff;
Condition100%2/2
shift() || 2147483647
l!l
54929
MC/DC100%1/1
shift() || 2147483647
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
5212 578 for (;;) {
5213 1474 my ($n, $d) = AssembleRational(int($frac + 0.5), 1, @fracs);
5214 1474 ▶ if ($n > $maxInt or $d > $maxInt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > $maxInt or $d > $maxInt) 0 1474 1474
Condition33%1/3
$n > $maxInt or $d > $maxInt
l!l&&r!l&&!r
001474
MC/DC0%0/2
$n > $maxInt or $d > $maxInt
$n > $maxInt $d > $maxInt
Truth table33%1/3
A or B
A= $n > $maxIntB= $d > $maxInt
ABresult
1X1
011
000
5215 0 ▶ last if defined $num;
Branch: 1 branch
BranchTrueFalseTotal
if defined $num 0 0 0
5216 0 ▶ return ($sign, $maxInt) if $val < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $val < 1 0 0 0
5217 0 return ($sign * $maxInt, 1);
5218 }
5219 1474 ($num, $denom) = ($n, $d); # save last good values
5220 1474 my $err = ($n/$d-$val) / $val; # get error of this rational
5221 1474 ▶ last if abs($err) < 1e-8; # all done if error is small
Branch: 1 branch
BranchTrueFalseTotal
if abs $err < "1e-08" 578 896 1474
5222 896 my $int = int($frac);
5223 896 unshift @fracs, $int;
5224 896 ▶ last unless $frac -= $int;
Branch: 1 branch
BranchTrueFalseTotal
unless $frac -= $int 0 896 896
5225 896 $frac = 1 / $frac;
5226 }
5227 578 return ($num * $sign, $denom);
5228 }
5229  
5230 #------------------------------------------------------------------------------
5231 # Utility routines to for writing binary data values
5232 # Inputs: 0) value, 1) data ref, 2) offset
5233 # Notes: prototype is (@) so values can be passed from list if desired
5234 sub Set16s(@)
5235 188 ▶{
Subroutine Set16s: called CC=2 SCAR=6.9
Pod undocumented
5236 188 my $val = shift;
5237 188 ▶ $val < 0 and $val += 0x10000;
Branch: 1 branch
BranchTrueFalseTotal
$val < 0 and $val += 65536 10 178 188
5238 188 return Set16u($val, @_);
5239 }
5240 sub Set32s(@)
5241 69 ▶{
Subroutine Set32s: called CC=2 SCAR=6.9
Pod undocumented
5242 69 my $val = shift;
5243 69 ▶ $val < 0 and $val += 0xffffffff, ++$val;
Branch: 1 branch
BranchTrueFalseTotal
$val < 0 and $val += 4294967295, ++$val 12 57 69
5244 69 return Set32u($val, @_);
5245 }
5246 sub Set64u(@)
5247 28 ▶{
Subroutine Set64u: called CC=3 SCAR=11.0
Pod undocumented
5248 28 my $val = $_[0];
5249 28 my $hi = int($val / 4294967296);
5250 28 my $lo = Set32u($val - $hi * 4294967296); # NOTE: subject to round-off errors!
5251 28 $hi = Set32u($hi);
5252 28 ▶ $val = GetByteOrder() eq 'MM' ? $hi . $lo : $lo . $hi;
Branch: 1 branch
BranchTrueFalseTotal
&GetByteOrder() eq 'MM' ? : 27 1 28
5253 28 ▶ $_[1] and substr(${$_[1]}, $_[2], length($val)) = $val;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and substr(${$_[1];}, $_[2], length $val) = $val 27 1 28
5254 28 return $val;
5255 }
5256 sub Set64s(@)
5257 0 ▶{
Subroutine Set64s: not called CC=2 SCAR=17.9
Pod undocumented
5258 0 my $val = shift;
5259 0 ▶ $val < 0 and $val += 4294967296 * 4294967296; # (temporary hack won't really work due to round-off errors)
Branch: 1 branch
BranchTrueFalseTotal
$val < 0 and $val += "1.84467440737096e+19" 0 0 0
5260 0 return Set64u($val, @_);
5261 }
5262 319 ▶sub SetRational64u(@) {
Subroutine SetRational64u: called CC=2 SCAR=7.4
Pod undocumented
5263 319 my ($numer,$denom) = Rationalize($_[0],0xffffffff);
5264 319 my $val = Set32u($numer) . Set32u($denom);
5265 0 ▶ $_[1] and substr(${$_[1]}, $_[2], length($val)) = $val;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and substr(${$_[1];}, $_[2], length $val) = $val 0 319 319
5266 319 return $val;
5267 }
5268 44 ▶sub SetRational64s(@) {
Subroutine SetRational64s: called CC=2 SCAR=7.4
Pod undocumented
5269 44 my ($numer,$denom) = Rationalize($_[0]);
5270 44 my $val = Set32s($numer) . Set32u($denom);
5271 0 ▶ $_[1] and substr(${$_[1]}, $_[2], length($val)) = $val;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and substr(${$_[1];}, $_[2], length $val) = $val 0 44 44
5272 44 return $val;
5273 }
5274 0 ▶sub SetRational32u(@) {
Subroutine SetRational32u: not called CC=2 SCAR=17.9
Pod undocumented
5275 0 my ($numer,$denom) = Rationalize($_[0],0xffff);
5276 0 my $val = Set16u($numer) . Set16u($denom);
5277 0 ▶ $_[1] and substr(${$_[1]}, $_[2], length($val)) = $val;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and substr(${$_[1];}, $_[2], length $val) = $val 0 0 0
5278 0 return $val;
5279 }
5280 0 ▶sub SetRational32s(@) {
Subroutine SetRational32s: not called CC=2 SCAR=17.9
Pod undocumented
5281 0 my ($numer,$denom) = Rationalize($_[0],0x7fff);
5282 0 my $val = Set16s($numer) . Set16u($denom);
5283 0 ▶ $_[1] and substr(${$_[1]}, $_[2], length($val)) = $val;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and substr(${$_[1];}, $_[2], length $val) = $val 0 0 0
5284 0 return $val;
5285 }
5286 0 ▶sub SetFixed16u(@) {
Subroutine SetFixed16u: not called CC=1 SCAR=6.9
Pod undocumented
5287 0 my $val = int(shift() * 0x100 + 0.5);
5288 0 return Set16u($val, @_);
5289 }
5290 0 ▶sub SetFixed16s(@) {
Subroutine SetFixed16s: not called CC=2 SCAR=17.9
Pod undocumented
5291 0 my $val = shift;
5292 0 ▶ return Set16s(int($val * 0x100 + ($val < 0 ? -0.5 : 0.5)), @_);
Branch: 1 branch
BranchTrueFalseTotal
$val < 0 ? : 0 0 0
5293 }
5294 0 ▶sub SetFixed32u(@) {
Subroutine SetFixed32u: not called CC=1 SCAR=6.9
Pod undocumented
5295 0 my $val = int(shift() * 0x10000 + 0.5);
5296 0 return Set32u($val, @_);
5297 }
5298 12 ▶sub SetFixed32s(@) {
Subroutine SetFixed32s: called CC=2 SCAR=6.9
Pod undocumented
5299 12 my $val = shift;
5300 12 ▶ return Set32s(int($val * 0x10000 + ($val < 0 ? -0.5 : 0.5)), @_);
Branch: 1 branch
BranchTrueFalseTotal
$val < 0 ? : 2 10 12
5301 }
5302 64 ▶sub SetFloat(@) {
Subroutine SetFloat: called CC=2 SCAR=7.6
Pod undocumented
5303 64 my $val = SwapBytes(pack('f',$_[0]), 4);
5304 0 ▶ $_[1] and substr(${$_[1]}, $_[2], length($val)) = $val;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and substr(${$_[1];}, $_[2], length $val) = $val 0 64 64
5305 64 return $val;
5306 }
5307 66 ▶sub SetDouble(@) {
Subroutine SetDouble: called CC=2 SCAR=7.6
Pod undocumented
5308 # swap 32-bit words (ARM quirk) and bytes if necessary
5309 66 my $val = SwapBytes(SwapWords(pack('d',$_[0])), 8);
5310 0 ▶ $_[1] and substr(${$_[1]}, $_[2], length($val)) = $val;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and substr(${$_[1];}, $_[2], length $val) = $val 0 66 66
5311 66 return $val;
5312 }
5313 #------------------------------------------------------------------------------
5314 # hash lookups for writing binary data values
5315 61 my %writeValueProc = (
5316 int8s => \&Set8s,
5317 int8u => \&Set8u,
5318 int16s => \&Set16s,
5319 int16u => \&Set16u,
5320 int16uRev => \&Set16uRev,
5321 int32s => \&Set32s,
5322 int32u => \&Set32u,
5323 int64s => \&Set64s,
5324 int64u => \&Set64u,
5325 rational32s => \&SetRational32s,
5326 rational32u => \&SetRational32u,
5327 rational64s => \&SetRational64s,
5328 rational64u => \&SetRational64u,
5329 fixed16u => \&SetFixed16u,
5330 fixed16s => \&SetFixed16s,
5331 fixed32u => \&SetFixed32u,
5332 fixed32s => \&SetFixed32s,
5333 float => \&SetFloat,
5334 double => \&SetDouble,
5335 ifd => \&Set32u,
5336 );
5337 # verify that we can write floats on this platform
5338 {
5339 61 my %writeTest = (
5340 float => [ -3.14159, 'c0490fd0' ],
5341 double => [ -3.14159, 'c00921f9f01b866e' ],
5342 );
5343 61 my $format;
5344 61 my $oldOrder = GetByteOrder();
5345 61 SetByteOrder('MM');
5346 61 foreach $format (keys %writeTest) {
5347 122 my ($val, $hex) = @{$writeTest{$format}};
5348 # add floating point entries if we can write them
5349 122 ▶ next if unpack('H*', &{$writeValueProc{$format}}($val)) eq $hex;
Branch: 1 branch
BranchTrueFalseTotal
if unpack("H*", &{$writeValueProc{$format};}($val)) eq $hex 122 0 122
5350 0 delete $writeValueProc{$format}; # we can't write them
5351 }
5352 61 SetByteOrder($oldOrder);
5353 }
5354  
5355 #------------------------------------------------------------------------------
5356 # write binary data value (with current byte ordering)
5357 # Inputs: 0) value, 1) format string
5358 # 2) number of values:
5359 # undef = 1 for numerical types, or data length for string/undef types
5360 # -1 = number of space-delimited values in the input string
5361 # 3) optional data reference, 4) value offset (may be negative for bytes from end)
5362 # Returns: packed value (and sets value in data) or undef on error
5363 # Notes: May modify input value to round for integer formats
5364 sub WriteValue($$;$$$$)
5365 1405 ▶{
Subroutine WriteValue: called CC=27 SCAR=37.5
Pod undocumented
5366 1405 my ($val, $format, $count, $dataPt, $offset) = @_;
5367 1405 my $proc = $writeValueProc{$format};
5368 1405 my $packed;
5369  
5370 1405 ▶ if ($proc) {
Branch: 2 branches
BranchTrueFalseTotal
if ($proc) { } 1064 341 1405
elsif ($format eq 'string' or $format eq 'undef') { } 341 0 341
5371 1064 my @vals = split(' ',$val);
5372 1064 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) { } 571 493 1064
5373 571 ▶ $count = @vals if $count < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $count < 0 64 507 571
5374 } else {
5375 493 $count = 1; # assume 1 if count not specified
5376 }
5377 1064 $packed = '';
5378 1064 ▶ while ($count--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count--) 1569 1064 2633
5379 1569 $val = shift @vals;
5380 1569 ▶ return undef unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 1569 1569
5381 # validate numerical formats
5382 1569 ▶ if ($format =~ /^int/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($format =~ /^int/) { } 1189 380 1569
elsif (not &IsFloat($val)) { } 7 373 380
5383 1189 ▶ unless (IsInt($val) or IsHex($val)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&IsInt($val) or &IsHex($val)) 0 1189 1189
Condition33%1/3
&IsInt($val) or &IsHex($val)
l!l&&r!l&&!r
118900
MC/DC0%0/2
&IsInt($val) or &IsHex($val)
&IsInt($val) &IsHex($val)
Truth table33%1/3
A or B
A= &IsInt($val)B= &IsHex($val)
ABresult
1X1
011
000
5384 0 ▶ return undef unless IsFloat($val);
Branch: 1 branch
BranchTrueFalseTotal
unless &IsFloat($val) 0 0 0
5385 # round to nearest integer
5386 0 ▶ $val = int($val + ($val < 0 ? -0.5 : 0.5));
Branch: 1 branch
BranchTrueFalseTotal
$val < 0 ? : 0 0 0
5387 0 $_[0] = $val;
5388 }
5389 } elsif (not IsFloat($val)) {
5390 7 ▶ return undef unless $format =~ /^rational/ and ($val eq 'inf' or
Branch: 1 branch
BranchTrueFalseTotal
unless $format =~ /^rational/ and $val eq "inf" || $val eq "undef" || &IsRational($val) 0 7 7
Condition33%3/9
$format =~ /^rational/ and $val eq "inf" || $val eq "undef" || &IsRational($val)
!ll&&!rl&&r
007
$val eq "inf" or $val eq "undef" or &IsRational($val)
l!l&&r!l&&!r
070
$val eq "inf" or $val eq "undef"
l!l&&r!l&&!r
007
MC/DC0%0/4
$format =~ /^rational/ and $val eq "inf" || $val eq "undef" || &IsRational($val)
$format =~ /^rational/ $val eq "inf" $val eq "undef" &IsRational($val)
Truth table20%1/5
A and B or C or D
A= $format =~ /^rational/B= $val eq "inf"C= $val eq "undef"D= &IsRational($val)
ABCDresult
0XXX0
10000
11XX1
101X1
10011
5391 $val eq 'undef' or IsRational($val));
5392 }
5393 1569 $packed .= &$proc($val);
5394 }
5395 ▶ } elsif ($format eq 'string' or $format eq 'undef') {
Condition66%2/3
$format eq "string" or $format eq "undef"
l!l&&r!l&&!r
1911500
MC/DC0%0/2
$format eq "string" or $format eq "undef"
$format eq "string" $format eq "undef"
Truth table66%2/3
A or B
A= $format eq "string"B= $format eq "undef"
ABresult
1X1
011
000
5396 341 ▶ $format eq 'string' and $val .= "\0"; # null-terminate strings
Branch: 1 branch
BranchTrueFalseTotal
$format eq "string" and $val .= "\000" 191 150 341
5397 341 ▶ if ($count and $count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count and $count > 0) { } 61 280 341
Condition66%2/3
$count and $count > 0
!ll&&!rl&&r
280061
MC/DC50%1/2
$count and $count > 0
$count $count > 0
Truth table66%2/3
A and B
A= $countB= $count > 0
ABresult
0X0
100
111
5398 61 my $diff = $count - length($val);
5399 61 ▶ if ($diff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diff) 33 28 61
5400 #warn "wrong string length!\n";
5401 # adjust length of string to match specified count
5402 33 ▶ if ($diff < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diff < 0) { } 26 7 33
5403 26 ▶ if ($format eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq 'string') { } 26 0 26
5404 26 ▶ return undef unless $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 0 26 26
5405 26 $val = substr($val, 0, $count - 1) . "\0";
5406 } else {
5407 0 $val = substr($val, 0, $count);
5408 }
5409 } else {
5410 7 $val .= "\0" x $diff;
5411 }
5412 }
5413 } else {
5414 280 $count = length($val);
5415 }
5416 341 ▶ $dataPt and substr($$dataPt, $offset, $count) = $val;
Branch: 1 branch
BranchTrueFalseTotal
$dataPt and substr($$dataPt, $offset, $count) = $val 2 339 341
5417 341 return $val;
5418 } else {
5419 0 warn "Sorry, Can't write $format values on this platform\n";
5420 0 return undef;
5421 }
5422 1064 ▶ $dataPt and substr($$dataPt, $offset, length($packed)) = $packed;
Branch: 1 branch
BranchTrueFalseTotal
$dataPt and substr($$dataPt, $offset, length $packed) = $packed 215 849 1064
5423 1064 return $packed;
5424 }
5425  
5426 #------------------------------------------------------------------------------
5427 # Encode bit mask (the inverse of DecodeBits())
5428 # Inputs: 0) value to encode, 1) Reference to hash for encoding (or undef)
5429 # 2) optional number of bits per word (defaults to 32), 3) total bits
5430 # Returns: bit mask or undef on error (plus error string in list context)
5431 sub EncodeBits($$;$$)
5432 105 ▶{
Subroutine EncodeBits: called CC=14 SCAR=29.2
Pod undocumented
5433 105 my ($val, $lookup, $bits, $num) = @_;
5434 105 ▶ $bits or $bits = 32;
Branch: 1 branch
BranchTrueFalseTotal
$bits or $bits = 32 2 103 105
5435 105 ▶ $num or $num = $bits;
Branch: 1 branch
BranchTrueFalseTotal
$num or $num = $bits 2 103 105
5436 105 my $words = int(($num + $bits - 1) / $bits);
5437 105 my @outVal = (0) x $words;
5438 105 ▶ if ($val ne '(none)') {
Branch: 1 branch
BranchTrueFalseTotal
if ($val ne "(none)") 86 19 105
5439 86 my @vals = split /\s*,\s*/, $val;
5440 86 foreach $val (@vals) {
5441 42 my $bit;
5442 42 ▶ if ($lookup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lookup) { } 42 0 42
5443 42 $bit = ReverseLookup($val, $lookup);
5444 # (Note: may get non-numerical $bit values from Unknown() tags)
5445 42 ▶ unless (defined $bit) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bit) 33 9 42
5446 33 ▶ if ($val =~ /\[(\d+)\]/) { # numerical bit specification
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /\[(\d+)\]/) { } 0 33 33
5447 0 $bit = $1;
5448 } else {
5449 # don't return error string unless more than one value
5450 33 ▶ return undef unless @vals > 1 and wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless @vals > 1 and wantarray 31 2 33
Condition66%2/3
@vals > 1 and wantarray
!ll&&!rl&&r
3102
MC/DC50%1/2
@vals > 1 and wantarray
@vals > 1 wantarray
Truth table66%2/3
A and B
A= @vals > 1B= wantarray
ABresult
0X0
100
111
5451 2 return (undef, "no match for '${val}'");
5452 }
5453 }
5454 } else {
5455 0 $bit = $val;
5456 }
5457 9 ▶ unless (IsInt($bit) and $bit < $num) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&IsInt($bit) and $bit < $num) 0 9 9
Condition33%1/3
&IsInt($bit) and $bit < $num
!ll&&!rl&&r
009
MC/DC0%0/2
&IsInt($bit) and $bit < $num
&IsInt($bit) $bit < $num
Truth table33%1/3
A and B
A= &IsInt($bit)B= $bit < $num
ABresult
0X0
100
111
5458 0 ▶ return undef unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
5459 0 ▶ return (undef, IsInt($bit) ? 'bit number too high' : 'not an integer');
Branch: 1 branch
BranchTrueFalseTotal
&IsInt($bit) ? : 0 0 0
5460 }
5461 9 my $word = int($bit / $bits);
5462 9 $outVal[$word] |= (1 << ($bit - $word * $bits));
5463 }
5464 }
5465 72 return "@outVal";
5466 }
5467  
5468 #------------------------------------------------------------------------------
5469 # get current position in output file (or end of file if a scalar reference)
5470 # Inputs: 0) file or scalar reference
5471 # Returns: Current position or -1 on error
5472 sub Tell($)
5473 334 ▶{
Subroutine Tell: called CC=2 SCAR=6.9
Pod undocumented
5474 334 my $outfile = shift;
5475 334 ▶ if (UNIVERSAL::isa($outfile,'GLOB')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($outfile, 'GLOB')) { } 305 29 334
5476 305 return tell($outfile);
5477 } else {
5478 29 return length($$outfile);
5479 }
5480 }
5481  
5482 #------------------------------------------------------------------------------
5483 # write to file or memory
5484 # Inputs: 0) file or scalar reference, 1-N) list of stuff to write
5485 # Returns: true on success
5486 sub Write($@)
5487 4085 ▶{
Subroutine Write: called CC=3 SCAR=11.2
Pod undocumented
5488 4085 my $outfile = shift;
5489 4085 ▶ if (UNIVERSAL::isa($outfile,'GLOB')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($outfile, 'GLOB')) { } 2355 1730 4085
elsif (ref $outfile eq 'SCALAR') { } 1730 0 1730
5490 2355 return print $outfile @_;
5491 } elsif (ref $outfile eq 'SCALAR') {
5492 1730 $$outfile .= join('', @_);
5493 1730 return 1;
5494 }
5495 0 return 0;
5496 }
5497  
5498 #------------------------------------------------------------------------------
5499 # Write trailer buffer to file (applying fixups if necessary)
5500 # Inputs: 0) ExifTool object ref, 1) trailer dirInfo ref, 2) output file ref
5501 # Returns: 1 on success
5502 sub WriteTrailerBuffer($$$)
5503 12 ▶{
Subroutine WriteTrailerBuffer: called CC=4 SCAR=15.0
Pod undocumented
5504 12 my ($self, $trailInfo, $outfile) = @_;
5505 12 ▶ if ($$self{DEL_GROUP}{Trailer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DEL_GROUP"}{"Trailer"}) 0 12 12
5506 0 $self->VPrint(0, " Deleting trailer ($$trailInfo{Offset} bytes)\n");
5507 0 ++$$self{CHANGED};
5508 0 return 1;
5509 }
5510 12 my $pos = Tell($outfile);
5511 12 my $trailPt = $$trailInfo{OutFile};
5512 # apply fixup if necessary (AFCP requires this)
5513 12 ▶ if ($$trailInfo{Fixup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailInfo->{"Fixup"}) 8 4 12
5514 8 ▶ if ($pos > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos > 0) { } 8 0 8
5515 # shift offsets to final AFCP location and write it out
5516 8 $$trailInfo{Fixup}{Shift} += $pos;
5517 8 $$trailInfo{Fixup}->ApplyFixup($trailPt);
5518 } else {
5519 0 $self->Error("Can't get file position for trailer offset fixup",1);
5520 }
5521 }
5522 12 return Write($outfile, $$trailPt);
5523 }
5524  
5525 #------------------------------------------------------------------------------
5526 # Add trailers as a block
5527 # Inputs: 0) ExifTool object ref, 1) [optional] trailer data raf,
5528 # 1 or 2-N) trailer types to add (or none to add all)
5529 # Returns: new trailer ref, or undef
5530 # - increments CHANGED if trailer was added
5531 sub AddNewTrailers($;@)
5532 133 ▶{
Subroutine AddNewTrailers: called CC=12 SCAR=24.9
Pod undocumented
5533 133 my ($self, @types) = @_;
5534 133 my $trailPt;
5535 133 ▶ ref $types[0] and $trailPt = shift @types;
Branch: 1 branch
BranchTrueFalseTotal
ref $types[0] and $trailPt = shift @types 2 131 133
5536 133 ▶ $types[0] or shift @types; # (in case undef data ref is passed)
Branch: 1 branch
BranchTrueFalseTotal
$types[0] or shift @types 2 131 133
5537 # add all possible trailers if none specified (currently only CanonVRD)
5538 133 ▶ @types or @types = qw(CanonVRD CanonDR4);
Branch: 1 branch
BranchTrueFalseTotal
@types or @types = ("CanonVRD", "CanonDR4") 7 126 133
5539 # add trailers as a block (if not done already)
5540 133 my $type;
5541 133 foreach $type (@types) {
5542 259 ▶ next unless $$self{NEW_VALUE}{$Image::ExifTool::Extra{$type}};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"NEW_VALUE"}{$Image::ExifTool::Extra{$type}} 249 10 259
5543 10 ▶ next if $$self{"Did$type"};
Branch: 1 branch
BranchTrueFalseTotal
if $$self{"Did$type"} 1 9 10
5544 9 ▶ my $val = $self->GetNewValue($type) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $val = $self->GetNewValue($type) or next 8 1 9
5545 # DR4 record must be wrapped in VRD trailer package
5546 8 ▶ if ($type eq 'CanonDR4') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "CanonDR4") 3 5 8
5547 3 ▶ next if $$self{DidCanonVRD}; # (only allow one VRD trailer)
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DidCanonVRD"} 1 2 3
5548 2 require Image::ExifTool::CanonVRD;
5549 2 $val = Image::ExifTool::CanonVRD::WrapDR4($val);
5550 2 $$self{DidCanonVRD} = 1;
5551 }
5552 7 ▶ my $verb = $trailPt ? 'Writing' : 'Adding';
Branch: 1 branch
BranchTrueFalseTotal
$trailPt ? : 0 7 7
5553 7 $self->VPrint(0, " $verb $type as a block\n");
5554 7 ▶ if ($trailPt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailPt) { } 0 7 7
5555 0 $$trailPt .= $val;
5556 } else {
5557 7 $trailPt = \$val;
5558 }
5559 7 $$self{"Did$type"} = 1;
5560 7 ++$$self{CHANGED};
5561 }
5562 133 return $trailPt;
5563 }
5564  
5565 #------------------------------------------------------------------------------
5566 # Write segment, splitting up into multiple segments if necessary
5567 # Inputs: 0) file or scalar reference, 1) segment marker
5568 # 2) segment header, 3) segment data ref, 4) segment type
5569 # Returns: number of segments written, or 0 on error
5570 # Notes: Writes a single empty segment if data is empty
5571 sub WriteMultiSegment($$$$;$)
5572 114 ▶{
Subroutine WriteMultiSegment: called CC=10 SCAR=25.2
Pod undocumented
5573 114 my ($outfile, $marker, $header, $dataPt, $type) = @_;
5574 114 ▶ $type or $type = '';
Branch: 1 branch
BranchTrueFalseTotal
$type or $type = "" 80 34 114
5575 114 my $len = length($$dataPt);
5576 114 my $hdr = "\xff" . chr($marker);
5577 114 my $count = 0;
5578 114 my $maxLen = $maxSegmentLen - length($header);
5579 114 ▶ $maxLen -= 2 if $type eq 'ICC'; # leave room for segment counters
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "ICC" 3 111 114
5580 114 my $num = int(($len + $maxLen - 1) / $maxLen); # number of segments to write
5581 114 my $n = 0;
5582 # write data, splitting into multiple segments if necessary
5583 # (each segment gets its own header)
5584 114 for (;;) {
5585 114 ++$count;
5586 114 my $size = $len - $n;
5587 114 ▶ if ($size > $maxLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > $maxLen) 0 114 114
5588 0 $size = $maxLen;
5589 # avoid starting an Extended EXIF segment with a valid TIFF header
5590 # (because we would interpret that as a separate EXIF segment)
5591 0 ▶ --$size if $type eq 'EXIF' and $n+$maxLen <= $len-4 and
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "EXIF" and $n + $maxLen <= $len - 4 and substr($$dataPt, $n + $maxLen, 4) =~ /^(MM\0\x2a|II\x2a\0)/ 0 0 0
Condition0%0/6
$type eq "EXIF" and $n + $maxLen <= $len - 4 and substr($$dataPt, $n + $maxLen, 4) =~ /^(MM\0\x2a|II\x2a\0)/
!ll&&!rl&&r
000
$type eq "EXIF" and $n + $maxLen <= $len - 4
!ll&&!rl&&r
000
MC/DC0%0/3
$type eq "EXIF" and $n + $maxLen <= $len - 4 and substr($$dataPt, $n + $maxLen, 4) =~ /^(MM\0\x2a|II\x2a\0)/
$type eq "EXIF" $n + $maxLen <= $len - 4 substr($$dataPt, $n + $maxLen, 4) =~ /^(MM\0\x2a|II\x2a\0)/
Truth table0%0/4
A and B and C
A= $type eq "EXIF"B= $n + $maxLen <= $len - 4C= substr($$dataPt, $n + $maxLen, 4) =~ /^(MM\0\x2a|II\x2a\0)/
ABCresult
0XX0
10X0
1100
1111
5592 substr($$dataPt, $n+$maxLen, 4) =~ /^(MM\0\x2a|II\x2a\0)/;
5593 }
5594 114 my $buff = substr($$dataPt,$n,$size);
5595 114 $n += $size;
5596 114 $size += length($header);
5597 114 ▶ if ($type eq 'ICC') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ICC") 3 111 114
5598 3 $buff = pack('CC', $count, $num) . $buff;
5599 3 $size += 2;
5600 }
5601 # write the new segment with appropriate header
5602 114 my $segHdr = $hdr . pack('n', $size + 2);
5603 114 ▶ Write($outfile, $segHdr, $header, $buff) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $segHdr, $header, $buff) or return 0 114 0 114
5604 114 ▶ last if $n >= $len;
Branch: 1 branch
BranchTrueFalseTotal
if $n >= $len 114 0 114
5605 }
5606 114 return $count;
5607 }
5608  
5609 #------------------------------------------------------------------------------
5610 # Write XMP segment(s) to JPEG file
5611 # Inputs: 0) ExifTool object ref, 1) outfile ref, 2) XMP data ref,
5612 # 3) extended XMP data ref, 4) 32-char extended XMP GUID (or undef if no extended data)
5613 # Returns: true on success, false on write error
5614 sub WriteMultiXMP($$$$$)
5615 36 ▶{
Subroutine WriteMultiXMP: called CC=7 SCAR=30.0
Pod undocumented
5616 36 my ($self, $outfile, $dataPt, $extPt, $guid) = @_;
5617 36 my $success = 1;
5618  
5619 # write main XMP segment
5620 36 my $size = length($$dataPt) + length($xmpAPP1hdr);
5621 36 ▶ if ($size > $maxXMPLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > $maxXMPLen) 0 36 36
5622 0 $self->Error("XMP block too large for JPEG segment! ($size bytes)", 1);
5623 0 return 1;
5624 }
5625 36 my $app1hdr = "\xff\xe1" . pack('n', $size + 2);
5626 36 ▶ Write($outfile, $app1hdr, $xmpAPP1hdr, $$dataPt) or $success = 0;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $app1hdr, $Image::ExifTool::xmpAPP1hdr, $$dataPt) or $success = 0 36 0 36
5627 # write extended XMP segment(s) if necessary
5628 36 ▶ if (defined $guid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $guid) 0 36 36
5629 0 $size = length($$extPt);
5630 0 my $maxLen = $maxXMPLen - 75; # maximum size without 75-byte header
5631 0 my $off;
5632 0 ▶ for ($off=0; $off<$size; $off+=$maxLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off < $size) 0 0 0
5633 # header(75) = signature(35) + guid(32) + size(4) + offset(4)
5634 0 my $len = $size - $off;
5635 0 ▶ $len = $maxLen if $len > $maxLen;
Branch: 1 branch
BranchTrueFalseTotal
if $len > $maxLen 0 0 0
5636 0 $app1hdr = "\xff\xe1" . pack('n', $len + 75 + 2);
5637 0 $self->VPrint(0, "Writing extended XMP segment ($len bytes)\n");
5638 0 ▶ Write($outfile, $app1hdr, $xmpExtAPP1hdr, $guid, pack('N2', $size, $off),
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $app1hdr, $Image::ExifTool::xmpExtAPP1hdr, $guid, pack("N2", $size, $off), substr($$extPt, $off, $len)) or $success = 0 0 0 0
5639 substr($$extPt, $off, $len)) or $success = 0;
5640 }
5641 }
5642 36 return $success;
5643 }
5644  
5645 #------------------------------------------------------------------------------
5646 # WriteJPEG : Write JPEG image
5647 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
5648 # Returns: 1 on success, 0 if this wasn't a valid JPEG file, or -1 if
5649 # an output file was specified and a write error occurred
5650 sub WriteJPEG($$)
5651 114 ▶{
Subroutine WriteJPEG: called CC=442 SCAR=96.8
Pod undocumented
5652 114 my ($self, $dirInfo) = @_;
5653 114 my $outfile = $$dirInfo{OutFile};
5654 114 my $raf = $$dirInfo{RAF};
5655 114 my ($ch, $s, $length,$err, %doneDir, $isEXV, $creatingEXV);
5656 114 my $verbose = $$self{OPTIONS}{Verbose};
5657 114 my $out = $$self{OPTIONS}{TextOut};
5658 114 my $rtnVal = 0;
5659 114 my ($writeBuffer, $oldOutfile); # used to buffer writing until PreviewImage position is known
5660  
5661 # check to be sure this is a valid JPG or EXV file
5662 114 ▶ unless ($raf->Read($s,2) == 2 and $s eq "\xff\xd8") {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Read($s, 2) == 2 and $s eq "\377\330") 2 112 114
Condition100%3/3
$raf->Read($s, 2) == 2 and $s eq "\377\330"
!ll&&!rl&&r
11112
MC/DC100%2/2
$raf->Read($s, 2) == 2 and $s eq "\377\330"
$raf->Read($s, 2) == 2 $s eq "\377\330"
Truth table100%3/3
A and B
A= $raf->Read($s, 2) == 2B= $s eq "\377\330"
ABresult
0X0
100
111
5663 2 ▶ if (defined $s and length $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and length $s) { } 1 1 2
Condition66%2/3
defined $s and length $s
!ll&&!rl&&r
011
MC/DC50%1/2
defined $s and length $s
defined $s length $s
Truth table66%2/3
A and B
A= defined $sB= length $s
ABresult
0X0
100
111
5664 1 ▶ return 0 unless $s eq "\xff\x01" and $raf->Read($s,5) == 5 and $s eq 'Exiv2';
Branch: 1 branch
BranchTrueFalseTotal
unless $s eq "\377\1" and $raf->Read($s, 5) == 5 and $s eq "Exiv2" 0 1 1
Condition33%2/6
$s eq "\377\1" and $raf->Read($s, 5) == 5 and $s eq "Exiv2"
!ll&&!rl&&r
001
$s eq "\377\1" and $raf->Read($s, 5) == 5
!ll&&!rl&&r
001
MC/DC0%0/3
$s eq "\377\1" and $raf->Read($s, 5) == 5 and $s eq "Exiv2"
$s eq "\377\1" $raf->Read($s, 5) == 5 $s eq "Exiv2"
Truth table25%1/4
A and B and C
A= $s eq "\377\1"B= $raf->Read($s, 5) == 5C= $s eq "Exiv2"
ABCresult
0XX0
10X0
1100
1111
5665 } else {
5666 1 ▶ return 0 unless $$self{FILE_TYPE} eq 'EXV';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"FILE_TYPE"} eq "EXV" 0 1 1
5667 1 $s = 'Exiv2';
5668 1 $creatingEXV = 1;
5669 }
5670 2 ▶ Write($outfile,"\xff\x01") or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, "\377\1") or $err = 1 2 0 2
5671 2 $isEXV = 1;
5672 }
5673  
5674 114 delete $$self{PREVIEW_INFO}; # reset preview information
5675 114 delete $$self{DEL_PREVIEW}; # reset flag to delete preview
5676  
5677 114 ▶ Write($outfile, $s) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $s) or $err = 1 114 0 114
5678 # figure out what segments we need to write for the tags we have set
5679 114 my $addDirs = $$self{ADD_DIRS};
5680 114 my $editDirs = $$self{EDIT_DIRS};
5681 114 my $delGroup = $$self{DEL_GROUP};
5682 114 my $path = $$self{PATH};
5683 114 my $pn = scalar @$path;
5684  
5685 # set input record separator to 0xff (the JPEG marker) to make reading quicker
5686 114 local $/ = "\xff";
5687 #
5688 # pre-scan image to determine if any create-able segment already exists
5689 #
5690 114 my $pos = $raf->Tell();
5691 114 my ($marker, @dirOrder, %dirCount);
5692 114 Prescan: for (;;) {
5693 # read up to next marker (JPEG markers begin with 0xff)
5694 808 ▶ $raf->ReadLine($s) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->ReadLine($s) or last 807 1 808
5695 # JPEG markers can be padded with unlimited 0xff's
5696 807 for (;;) {
5697 807 ▶ $raf->Read($ch, 1) or last Prescan;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($ch, 1) or last Prescan 807 0 807
5698 807 $marker = ord($ch);
5699 807 ▶ last unless $marker == 0xff;
Branch: 1 branch
BranchTrueFalseTotal
unless $marker == 255 807 0 807
5700 }
5701 807 my $dirName;
5702 # stop pre-scan at SOS (end of meta information) or EOI (end of image)
5703 807 ▶ if ($marker == 0xda or $marker == 0xd9) {
Branch: 1 branch
BranchTrueFalseTotal
if ($marker == 218 or $marker == 217) 113 694 807
Condition100%3/3
$marker == 218 or $marker == 217
l!l&&r!l&&!r
1121694
MC/DC100%2/2
$marker == 218 or $marker == 217
$marker == 218 $marker == 217
Truth table100%3/3
A or B
A= $marker == 218B= $marker == 217
ABresult
1X1
011
000
5704 113 $dirName = $jpegMarker{$marker};
5705 113 push(@dirOrder, $dirName);
5706 113 $dirCount{$dirName} = 1;
5707 113 last;
5708 }
5709 # handle SOF markers: SOF0-SOF15, except DHT(0xc4), JPGA(0xc8) and DAC(0xcc)
5710 694 ▶ if (($marker & 0xf0) == 0xc0 and ($marker == 0xc0 or $marker & 0x03)) {
Branch: 2 branches
BranchTrueFalseTotal
if (($marker & 240) == 192 and $marker == 192 || $marker & 3) { } 112 582 694
elsif ($marker != 0 and $marker != 1 and $marker < 208 || $marker > 215) { } 582 0 582
Condition83%5/6
($marker & 240) == 192 and $marker == 192 || $marker & 3
!ll&&!rl&&r
470112112
$marker == 192 or $marker & 3
l!l&&r!l&&!r
1120112
MC/DC66%2/3
($marker & 240) == 192 and $marker == 192 || $marker & 3
($marker & 240) == 192 $marker == 192 $marker & 3
Truth table75%3/4
A and B or C
A= ($marker & 240) == 192B= $marker == 192C= $marker & 3
ABCresult
0XX0
1000
11X1
1011
5711 112 ▶ last unless $raf->Seek(7, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Seek(7, 1) 0 112 112
5712 # read data for all markers except stand-alone
5713 # markers 0x00, 0x01 and 0xd0-0xd7 (NULL, TEM, RST0-RST7)
5714 ▶ } elsif ($marker!=0x00 and $marker!=0x01 and ($marker<0xd0 or $marker>0xd7)) {
Condition44%4/9
$marker != 0 and $marker != 1 and $marker < 208 || $marker > 215
!ll&&!rl&&r
00582
$marker != 0 and $marker != 1
!ll&&!rl&&r
00582
$marker < 208 or $marker > 215
l!l&&r!l&&!r
1124700
MC/DC0%0/4
$marker != 0 and $marker != 1 and $marker < 208 || $marker > 215
$marker != 0 $marker != 1 $marker < 208 $marker > 215
Truth table40%2/5
A and B and C or D
A= $marker != 0B= $marker != 1C= $marker < 208D= $marker > 215
ABCDresult
0XXX0
10XX0
11000
111X1
11011
5715 # read record length word
5716 582 ▶ last unless $raf->Read($s, 2) == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($s, 2) == 2 0 582 582
5717 582 my $len = unpack('n',$s); # get data length
5718 582 ▶ last unless defined($len) and $len >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len and $len >= 2 0 582 582
Condition33%1/3
defined $len and $len >= 2
!ll&&!rl&&r
00582
MC/DC0%0/2
defined $len and $len >= 2
defined $len $len >= 2
Truth table33%1/3
A and B
A= defined $lenB= $len >= 2
ABresult
0X0
100
111
5719 582 $len -= 2; # subtract size of length word
5720 582 ▶ if (($marker & 0xf0) == 0xe0) { # is this an APP segment?
Branch: 1 branch
BranchTrueFalseTotal
if (($marker & 240) == 224) 347 235 582
5721 347 ▶ my $n = $len < 64 ? $len : 64;
Branch: 1 branch
BranchTrueFalseTotal
$len < 64 ? : 88 259 347
5722 347 ▶ $raf->Read($s, $n) == $n or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($s, $n) == $n or last 347 0 347
5723 347 $len -= $n;
5724 # Note: only necessary to recognize APP segments that we can create,
5725 # or delete as a group (and the names below should match @delGroups)
5726 347 ▶ if ($marker == 0xe0) {
Branch: 10 branches
BranchTrueFalseTotal
if ($marker == 224) { } 45 302 347
elsif ($marker == 225) { } 84 218 302
elsif ($marker == 226) { } 55 163 218
elsif ($marker == 227) { } 9 154 163
elsif ($marker == 229) { } 9 145 154
elsif ($marker == 234) { } 9 136 145
elsif ($marker == 235) { } 18 118 136
elsif ($marker == 236) { } 19 99 118
elsif ($marker == 237) { } 29 70 99
elsif ($marker == 238) { } 16 54 70
5727 45 ▶ $s =~ /^JFIF\0/ and $dirName = 'JFIF';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^JFIF\0/ and $dirName = "JFIF" 18 27 45
5728 45 ▶ $s =~ /^JFXX\0\x10/ and $dirName = 'JFXX';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^JFXX\0\x10/ and $dirName = "JFXX" 9 36 45
5729 45 ▶ $s =~ /^(II|MM).{4}HEAPJPGM/s and $dirName = 'CIFF';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^(II|MM).{4}HEAPJPGM/s and $dirName = "CIFF" 9 36 45
5730 } elsif ($marker == 0xe1) {
5731 84 ▶ if ($s =~ /^(.{0,4})Exif\0.(.{1,4})/is) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(.{0,4})Exif\0.(.{1,4})/is) 60 24 84
5732 60 $dirName = 'IFD0';
5733 60 my ($junk, $bytes) = ($1, $2);
5734 # support multi-segment EXIF
5735 60 ▶ if (@dirOrder and $dirOrder[-1] =~ /^(IFD0|ExtendedEXIF)$/ and
Branch: 1 branch
BranchTrueFalseTotal
if (@dirOrder and $dirOrder[-1] =~ /^(IFD0|ExtendedEXIF)$/ and not length $junk and not $bytes =~ /^(MM\0\x2a|II\x2a\0)/) 0 60 60
Condition44%4/9
@dirOrder and $dirOrder[-1] =~ /^(IFD0|ExtendedEXIF)$/ and not length $junk and not $bytes =~ /^(MM\0\x2a|II\x2a\0)/
!ll&&!rl&&r
6000
@dirOrder and $dirOrder[-1] =~ /^(IFD0|ExtendedEXIF)$/ and not length $junk
!ll&&!rl&&r
6000
@dirOrder and $dirOrder[-1] =~ /^(IFD0|ExtendedEXIF)$/
!ll&&!rl&&r
5370
MC/DC0%0/4
@dirOrder and $dirOrder[-1] =~ /^(IFD0|ExtendedEXIF)$/ and not length $junk and not $bytes =~ /^(MM\0\x2a|II\x2a\0)/
@dirOrder $dirOrder[-1] =~ /^(IFD0|ExtendedEXIF)$/ not length $junk not $bytes =~ /^(MM\0\x2a|II\x2a\0)/
Truth table40%2/5
A and B and not(C) and not(D)
A= @dirOrderB= $dirOrder[-1] =~ /^(IFD0|ExtendedEXIF)$/C= not length $junkD= not $bytes =~ /^(MM\0\x2a|II\x2a\0)/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
5736 not length $junk and $bytes !~ /^(MM\0\x2a|II\x2a\0)/)
5737 {
5738 0 $dirName = 'ExtendedEXIF';
5739 }
5740 }
5741 84 ▶ $s =~ /^$xmpAPP1hdr/ and $dirName = 'XMP';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^$Image::ExifTool::xmpAPP1hdr/ and $dirName = "XMP" 22 62 84
5742 84 ▶ $s =~ /^$xmpExtAPP1hdr/ and $dirName = 'XMP';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^$Image::ExifTool::xmpExtAPP1hdr/ and $dirName = "XMP" 2 82 84
5743 } elsif ($marker == 0xe2) {
5744 55 ▶ $s =~ /^ICC_PROFILE\0/ and $dirName = 'ICC_Profile';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^ICC_PROFILE\0/ and $dirName = "ICC_Profile" 14 41 55
5745 55 ▶ $s =~ /^FPXR\0/ and $dirName = 'FlashPix';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^FPXR\0/ and $dirName = "FlashPix" 32 23 55
5746 55 ▶ $s =~ /^MPF\0/ and $dirName = 'MPF';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^MPF\0/ and $dirName = "MPF" 9 46 55
5747 } elsif ($marker == 0xe3) {
5748 9 ▶ $s =~ /^(Meta|META|Exif)\0\0/ and $dirName = 'Meta';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^(Meta|META|Exif)\0\0/ and $dirName = "Meta" 9 0 9
5749 } elsif ($marker == 0xe5) {
5750 9 ▶ $s =~ /^RMETA\0/ and $dirName = 'RMETA';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^RMETA\0/ and $dirName = "RMETA" 9 0 9
5751 } elsif ($marker == 0xea) {
5752 9 ▶ $s =~ /^AROT\0\0/ and $dirName = 'AROT';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^AROT\0\0/ and $dirName = "AROT" 0 9 9
5753 } elsif ($marker == 0xeb) {
5754 18 ▶ $s =~ /^JP/ and $dirName = 'JUMBF';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^JP/ and $dirName = "JUMBF" 9 9 18
5755 } elsif ($marker == 0xec) {
5756 19 ▶ $s =~ /^Ducky/ and $dirName = 'Ducky';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^Ducky/ and $dirName = "Ducky" 10 9 19
5757 } elsif ($marker == 0xed) {
5758 29 ▶ $s =~ /^$psAPP13hdr/ and $dirName = 'Photoshop';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^$Image::ExifTool::psAPP13hdr/ and $dirName = "Photoshop" 20 9 29
5759 } elsif ($marker == 0xee) {
5760 16 ▶ $s =~ /^Adobe/ and $dirName = 'Adobe';
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^Adobe/ and $dirName = "Adobe" 16 0 16
5761 }
5762 # initialize doneDir as a flag that the directory exists
5763 # (unless we are deleting it anyway)
5764 347 ▶ $doneDir{$dirName} = 0 if defined $dirName and not $$delGroup{$dirName};
Branch: 1 branch
BranchTrueFalseTotal
if defined $dirName and not $delGroup->{$dirName} 216 131 347
Condition100%3/3
defined $dirName and not $delGroup->{$dirName}
!ll&&!rl&&r
9932216
MC/DC100%2/2
defined $dirName and not $delGroup->{$dirName}
defined $dirName not $delGroup->{$dirName}
Truth table100%3/3
A and not(B)
A= defined $dirNameB= not $delGroup->{$dirName}
ABresult
0X0
100
111
5765 }
5766 582 ▶ $raf->Seek($len, 1) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($len, 1) or last 582 0 582
5767 }
5768 694 ▶ $dirName or $dirName = JpegMarkerName($marker);
Branch: 1 branch
BranchTrueFalseTotal
$dirName or $dirName = &JpegMarkerName($marker) 248 446 694
5769 694 ▶ $dirCount{$dirName} = ($dirCount{$dirName} || 0) + 1;
Condition100%2/2
$dirCount{$dirName} || 0
l!l
33661
MC/DC100%1/1
$dirCount{$dirName} || 0
$dirCount{$dirName}
Truth table100%2/2
A
A= $dirCount{$dirName}
Aresult
11
00
5770 694 push @dirOrder, $dirName;
5771 }
5772 114 ▶ unless ($marker and $marker == 0xda) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($marker and $marker == 218) 2 112 114
Condition100%3/3
$marker and $marker == 218
!ll&&!rl&&r
11112
MC/DC100%2/2
$marker and $marker == 218
$marker $marker == 218
Truth table100%3/3
A and B
A= $markerB= $marker == 218
ABresult
0X0
100
111
5773 2 ▶ $isEXV or $self->Error('Corrupted JPEG image'), return 1;
Branch: 1 branch
BranchTrueFalseTotal
$isEXV or $self->Error("Corrupted JPEG image"), (return 1) 2 0 2
5774 2 ▶ $marker and $marker != 0xd9 and $self->Error('Corrupted EXV file'), return 1;
Branch: 1 branch
BranchTrueFalseTotal
$marker and $marker != 217 and $self->Error("Corrupted EXV file"), (return 1) 0 2 2
Condition66%2/3
$marker and $marker != 217
!ll&&!rl&&r
110
MC/DC0%0/2
$marker and $marker != 217
$marker $marker != 217
Truth table66%2/3
A and B
A= $markerB= $marker != 217
ABresult
0X0
100
111
5775 }
5776 114 ▶ $raf->Seek($pos, 0) or $self->Error('Seek error'), return 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($pos, 0) or $self->Error("Seek error"), (return 1) 114 0 114
5777 #
5778 # re-write the image
5779 #
5780 114 my ($combinedSegData, $segPos, $firstSegPos, %extendedXMP);
5781 114 my (@iccChunk, $iccChunkCount, $iccChunksTotal);
5782 # read through each segment in the JPEG file
5783 114 Marker: for (;;) {
5784  
5785 # read up to next marker (JPEG markers begin with 0xff)
5786 808 my $segJunk;
5787 808 ▶ $raf->ReadLine($segJunk) or $segJunk = '';
Branch: 1 branch
BranchTrueFalseTotal
$raf->ReadLine($segJunk) or $segJunk = "" 807 1 808
5788 # remove the 0xff but write the rest of the junk up to this point
5789 # (this will handle the data after the first 7 bytes of SOF segments)
5790 808 chomp($segJunk);
5791 808 ▶ Write($outfile, $segJunk) if length $segJunk;
Branch: 1 branch
BranchTrueFalseTotal
if length $segJunk 112 696 808
5792 # JPEG markers can be padded with unlimited 0xff's
5793 808 for (;;) {
5794 808 ▶ if ($raf->Read($ch, 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($raf->Read($ch, 1)) { } 807 1 808
elsif ($creatingEXV) { } 1 0 1
5795 807 $marker = ord($ch);
5796 807 ▶ last unless $marker == 0xff;
Branch: 1 branch
BranchTrueFalseTotal
unless $marker == 255 807 0 807
5797 } elsif ($creatingEXV) {
5798 # create EXV from scratch
5799 1 $marker = 0xd9; # EOI
5800 1 push @dirOrder, 'EOI';
5801 1 $dirCount{EOI} = 1;
5802 1 last;
5803 } else {
5804 0 $self->Error('Format error');
5805 0 return 1;
5806 }
5807 }
5808 # read the segment data
5809 808 my $segData;
5810 # handle SOF markers: SOF0-SOF15, except DHT(0xc4), JPGA(0xc8) and DAC(0xcc)
5811 808 ▶ if (($marker & 0xf0) == 0xc0 and ($marker == 0xc0 or $marker & 0x03)) {
Branch: 2 branches
BranchTrueFalseTotal
if (($marker & 240) == 192 and $marker == 192 || $marker & 3) { } 112 696 808
elsif ($marker != 0 and $marker != 1 and $marker != 217 and $marker < 208 || $marker > 215) { } 694 4 698
Condition83%5/6
($marker & 240) == 192 and $marker == 192 || $marker & 3
!ll&&!rl&&r
584112112
$marker == 192 or $marker & 3
l!l&&r!l&&!r
1120112
MC/DC66%2/3
($marker & 240) == 192 and $marker == 192 || $marker & 3
($marker & 240) == 192 $marker == 192 $marker & 3
Truth table75%3/4
A and B or C
A= ($marker & 240) == 192B= $marker == 192C= $marker & 3
ABCresult
0XX0
1000
11X1
1011
5812 112 ▶ last unless $raf->Read($segData, 7) == 7;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($segData, 7) == 7 0 112 112
5813 # read data for all markers except stand-alone
5814 # markers 0x00, 0x01 and 0xd0-0xd7 (NULL, TEM, EOI, RST0-RST7)
5815 ▶ } elsif ($marker!=0x00 and $marker!=0x01 and $marker!=0xd9 and
Condition58%7/12
$marker != 0 and $marker != 1 and $marker != 217 and $marker < 208 || $marker > 215
!ll&&!rl&&r
20694
$marker != 0 and $marker != 1 and $marker != 217
!ll&&!rl&&r
02694
$marker != 0 and $marker != 1
!ll&&!rl&&r
00696
$marker < 208 or $marker > 215
l!l&&r!l&&!r
1125820
MC/DC20%1/5
$marker != 0 and $marker != 1 and $marker != 217 and $marker < 208 || $marker > 215
$marker != 0 $marker != 1 $marker != 217 $marker < 208 $marker > 215
Truth table50%3/6
A and B and C and D or E
A= $marker != 0B= $marker != 1C= $marker != 217D= $marker < 208E= $marker > 215
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
5816 ($marker<0xd0 or $marker>0xd7))
5817 {
5818 # read record length word
5819 694 ▶ last unless $raf->Read($s, 2) == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($s, 2) == 2 0 694 694
5820 694 my $len = unpack('n',$s); # get data length
5821 694 ▶ last unless defined($len) and $len >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len and $len >= 2 0 694 694
Condition33%1/3
defined $len and $len >= 2
!ll&&!rl&&r
00694
MC/DC0%0/2
defined $len and $len >= 2
defined $len $len >= 2
Truth table33%1/3
A and B
A= defined $lenB= $len >= 2
ABresult
0X0
100
111
5822 694 $segPos = $raf->Tell();
5823 694 $len -= 2; # subtract size of length word
5824 694 ▶ last unless $raf->Read($segData, $len) == $len;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($segData, $len) == $len 0 694 694
5825 }
5826 # initialize variables for this segment
5827 808 my $hdr = "\xff" . chr($marker); # segment header
5828 808 my $markerName = JpegMarkerName($marker);
5829 808 my $dirName = shift @dirOrder; # get directory name
5830 #
5831 # create all segments that must come before this one
5832 # (nothing comes before SOI or after SOS)
5833 #
5834 808 ▶ while ($markerName ne 'SOI') {
Branch: 1 branch
BranchTrueFalseTotal
if ($markerName ne "SOI") 808 0 808
5835 808 ▶ if (exists $$addDirs{JFIF} and not defined $doneDir{JFIF}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $addDirs->{"JFIF"} and not defined $doneDir{"JFIF"}) 1 807 808
Condition100%3/3
exists $addDirs->{"JFIF"} and not defined $doneDir{"JFIF"}
!ll&&!rl&&r
760471
MC/DC100%2/2
exists $addDirs->{"JFIF"} and not defined $doneDir{"JFIF"}
exists $addDirs->{"JFIF"} not defined $doneDir{"JFIF"}
Truth table100%3/3
A and not(B)
A= exists $addDirs->{"JFIF"}B= not defined $doneDir{"JFIF"}
ABresult
0X0
100
111
5836 1 $doneDir{JFIF} = 1;
5837 1 ▶ if (defined $doneDir{Adobe}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $doneDir{'Adobe'}) { } 1 0 1
5838 # JFIF overrides Adobe APP14 colour components, so don't allow this
5839 # (ref https://docs.oracle.com/javase/8/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html)
5840 1 $self->Warn('Not creating JFIF in JPEG with Adobe APP14');
5841 } else {
5842 0 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
5843 0 print $out "Creating APP0:\n";
5844 0 print $out " Creating JFIF with default values\n";
5845 }
5846 0 my $jfif = "\x01\x02\x01\0\x48\0\x48\0\0";
5847 0 SetByteOrder('MM');
5848 0 my $tagTablePtr = GetTagTable('Image::ExifTool::JFIF::Main');
5849 0 my %dirInfo = (
5850 DataPt => \$jfif,
5851 DirStart => 0,
5852 DirLen => length $jfif,
5853 Parent => 'JFIF',
5854 );
5855 # must temporarily remove JFIF from DEL_GROUP so we can
5856 # delete JFIF and add it back again in a single step
5857 0 my $delJFIF = $$delGroup{JFIF};
5858 0 delete $$delGroup{JFIF};
5859 0 $$path[$pn] = 'JFIF';
5860 0 my $newData = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
5861 0 ▶ $$delGroup{JFIF} = $delJFIF if defined $delJFIF;
Branch: 1 branch
BranchTrueFalseTotal
if defined $delJFIF 0 0 0
5862 0 ▶ if (defined $newData and length $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newData and length $newData) 0 0 0
Condition0%0/3
defined $newData and length $newData
!ll&&!rl&&r
000
MC/DC0%0/2
defined $newData and length $newData
defined $newData length $newData
Truth table0%0/3
A and B
A= defined $newDataB= length $newData
ABresult
0X0
100
111
5863 0 my $app0hdr = "\xff\xe0" . pack('n', length($newData) + 7);
5864 0 ▶ Write($outfile,$app0hdr,"JFIF\0",$newData) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $app0hdr, "JFIF\0", $newData) or $err = 1 0 0 0
5865 }
5866 }
5867 }
5868 # don't create anything before APP0 or APP1 EXIF (containing IFD0)
5869 808 ▶ last if $markerName eq 'APP0' or $dirCount{IFD0} or $dirCount{ExtendedEXIF};
Branch: 1 branch
BranchTrueFalseTotal
if $markerName eq "APP0" or $dirCount{"IFD0"} or $dirCount{"ExtendedEXIF"} 105 703 808
Condition83%5/6
$markerName eq "APP0" or $dirCount{"IFD0"} or $dirCount{"ExtendedEXIF"}
l!l&&r!l&&!r
1050703
$markerName eq "APP0" or $dirCount{"IFD0"}
l!l&&r!l&&!r
4560703
MC/DC66%2/3
$markerName eq "APP0" or $dirCount{"IFD0"} or $dirCount{"ExtendedEXIF"}
$markerName eq "APP0" $dirCount{"IFD0"} $dirCount{"ExtendedEXIF"}
Truth table75%3/4
A or B or C
A= $markerName eq "APP0"B= $dirCount{"IFD0"}C= $dirCount{"ExtendedEXIF"}
ABCresult
1XX1
01X1
0011
0000
5870 # EXIF information must come immediately after APP0
5871 703 ▶ if (exists $$addDirs{IFD0} and not defined $doneDir{IFD0}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $addDirs->{"IFD0"} and not defined $doneDir{"IFD0"}) 33 670 703
Condition100%3/3
exists $addDirs->{"IFD0"} and not defined $doneDir{"IFD0"}
!ll&&!rl&&r
36830233
MC/DC100%2/2
exists $addDirs->{"IFD0"} and not defined $doneDir{"IFD0"}
exists $addDirs->{"IFD0"} not defined $doneDir{"IFD0"}
Truth table100%3/3
A and not(B)
A= exists $addDirs->{"IFD0"}B= not defined $doneDir{"IFD0"}
ABresult
0X0
100
111
5872 33 $doneDir{IFD0} = 1;
5873 33 ▶ $verbose and print $out "Creating APP1:\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "Creating APP1:\n" 1 32 33
5874 # write new EXIF data
5875 33 $$self{TIFF_TYPE} = 'APP1';
5876 33 my $tagTablePtr = GetTagTable('Image::ExifTool::Exif::Main');
5877 33 my %dirInfo = (
5878 DirName => 'IFD0',
5879 Parent => 'APP1',
5880 );
5881 33 $$path[$pn] = 'APP1';
5882 33 my $buff = $self->WriteDirectory(\%dirInfo, $tagTablePtr, \&WriteTIFF);
5883 33 ▶ if (defined $buff and length $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff and length $buff) 31 2 33
Condition66%2/3
defined $buff and length $buff
!ll&&!rl&&r
0231
MC/DC50%1/2
defined $buff and length $buff
defined $buff length $buff
Truth table66%2/3
A and B
A= defined $buffB= length $buff
ABresult
0X0
100
111
5884 31 ▶ if (length($buff) + length($exifAPP1hdr) > $maxSegmentLen) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($buff) + length($Image::ExifTool::exifAPP1hdr) > $maxSegmentLen) 0 31 31
5885 0 ▶ if ($self->Options('NoMultiExif')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Options('NoMultiExif')) { } 0 0 0
5886 0 $self->Error('EXIF is too large for JPEG segment');
5887 } else {
5888 0 $self->Warn('Creating multi-segment EXIF',1);
5889 }
5890 }
5891 # switch to buffered output if required
5892 31 ▶ if (($$self{PREVIEW_INFO} or $$self{LeicaTrailer} or $$self{HiddenData}) and
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PREVIEW_INFO"} || $self->{"LeicaTrailer"} || $self->{"HiddenData"} and not $oldOutfile) 0 31 31
Condition33%3/9
$self->{"PREVIEW_INFO"} || $self->{"LeicaTrailer"} || $self->{"HiddenData"} and not $oldOutfile
!ll&&!rl&&r
3100
$self->{"PREVIEW_INFO"} or $self->{"LeicaTrailer"} or $self->{"HiddenData"}
l!l&&r!l&&!r
0031
$self->{"PREVIEW_INFO"} or $self->{"LeicaTrailer"}
l!l&&r!l&&!r
0031
MC/DC0%0/4
$self->{"PREVIEW_INFO"} || $self->{"LeicaTrailer"} || $self->{"HiddenData"} and not $oldOutfile
$self->{"PREVIEW_INFO"} $self->{"LeicaTrailer"} $self->{"HiddenData"} not $oldOutfile
Truth table14%1/7
A or B or C and not(D)
A= $self->{"PREVIEW_INFO"}B= $self->{"LeicaTrailer"}C= $self->{"HiddenData"}D= not $oldOutfile
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
5893 not $oldOutfile)
5894 {
5895 0 $writeBuffer = '';
5896 0 $oldOutfile = $outfile;
5897 0 $outfile = \$writeBuffer;
5898 # must account for segment, EXIF and TIFF headers
5899 0 foreach (qw(PREVIEW_INFO LeicaTrailer HiddenData)) {
5900 0 ▶ $$self{$_}{Fixup}{Start} += 18 if $$self{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$_} 0 0 0
5901 }
5902 }
5903 # write as multi-segment
5904 31 my $n = WriteMultiSegment($outfile, 0xe1, $exifAPP1hdr, \$buff, 'EXIF');
5905 31 ▶ if (not $n) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $n) { } 0 31 31
elsif ($n > 1 and $oldOutfile) { } 0 62 62
5906 0 $err = 1;
5907 ▶ } elsif ($n > 1 and $oldOutfile) {
Condition33%1/3
$n > 1 and $oldOutfile
!ll&&!rl&&r
3100
MC/DC0%0/2
$n > 1 and $oldOutfile
$n > 1 $oldOutfile
Truth table33%1/3
A and B
A= $n > 1B= $oldOutfile
ABresult
0X0
100
111
5908 # (punt on this because updating the pointers would be a real pain)
5909 0 $self->Error("Can't write multi-segment EXIF with external pointers");
5910 }
5911 31 ++$$self{CHANGED};
5912 }
5913 }
5914 # APP13 Photoshop segment next
5915 703 ▶ last if $dirCount{Photoshop};
Branch: 1 branch
BranchTrueFalseTotal
if $dirCount{"Photoshop"} 182 521 703
5916 521 ▶ if (exists $$addDirs{Photoshop} and not defined $doneDir{Photoshop}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $addDirs->{"Photoshop"} and not defined $doneDir{"Photoshop"}) 21 500 521
Condition100%3/3
exists $addDirs->{"Photoshop"} and not defined $doneDir{"Photoshop"}
!ll&&!rl&&r
4138721
MC/DC100%2/2
exists $addDirs->{"Photoshop"} and not defined $doneDir{"Photoshop"}
exists $addDirs->{"Photoshop"} not defined $doneDir{"Photoshop"}
Truth table100%3/3
A and not(B)
A= exists $addDirs->{"Photoshop"}B= not defined $doneDir{"Photoshop"}
ABresult
0X0
100
111
5917 21 $doneDir{Photoshop} = 1;
5918 21 ▶ $verbose and print $out "Creating APP13:\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "Creating APP13:\n" 0 21 21
5919 # write new APP13 Photoshop record to memory
5920 21 my $tagTablePtr = GetTagTable('Image::ExifTool::Photoshop::Main');
5921 21 my %dirInfo = (
5922 Parent => 'APP13',
5923 );
5924 21 $$path[$pn] = 'APP13';
5925 21 my $buff = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
5926 21 ▶ if (defined $buff and length $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff and length $buff) 21 0 21
Condition33%1/3
defined $buff and length $buff
!ll&&!rl&&r
0021
MC/DC0%0/2
defined $buff and length $buff
defined $buff length $buff
Truth table33%1/3
A and B
A= defined $buffB= length $buff
ABresult
0X0
100
111
5927 21 ▶ WriteMultiSegment($outfile, 0xed, $psAPP13hdr, \$buff) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&WriteMultiSegment($outfile, 237, $Image::ExifTool::psAPP13hdr, \$buff) or $err = 1 21 0 21
5928 21 ++$$self{CHANGED};
5929 }
5930 }
5931 # then APP1 XMP segment
5932 521 ▶ last if $dirCount{XMP};
Branch: 1 branch
BranchTrueFalseTotal
if $dirCount{"XMP"} 15 506 521
5933 506 ▶ if (exists $$addDirs{XMP} and not defined $doneDir{XMP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $addDirs->{"XMP"} and not defined $doneDir{"XMP"}) 29 477 506
Condition100%3/3
exists $addDirs->{"XMP"} and not defined $doneDir{"XMP"}
!ll&&!rl&&r
36211529
MC/DC100%2/2
exists $addDirs->{"XMP"} and not defined $doneDir{"XMP"}
exists $addDirs->{"XMP"} not defined $doneDir{"XMP"}
Truth table100%3/3
A and not(B)
A= exists $addDirs->{"XMP"}B= not defined $doneDir{"XMP"}
ABresult
0X0
100
111
5934 29 $doneDir{XMP} = 1;
5935 29 ▶ $verbose and print $out "Creating APP1:\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "Creating APP1:\n" 0 29 29
5936 # write new XMP data
5937 29 my $tagTablePtr = GetTagTable('Image::ExifTool::XMP::Main');
5938 29 my %dirInfo = (
5939 Parent => 'APP1',
5940 # specify MaxDataLen so XMP is split if required
5941 MaxDataLen => $maxXMPLen - length($xmpAPP1hdr),
5942 );
5943 29 $$path[$pn] = 'APP1';
5944 29 my $buff = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
5945 29 ▶ if (defined $buff and length $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff and length $buff) 29 0 29
Condition33%1/3
defined $buff and length $buff
!ll&&!rl&&r
0029
MC/DC0%0/2
defined $buff and length $buff
defined $buff length $buff
Truth table33%1/3
A and B
A= defined $buffB= length $buff
ABresult
0X0
100
111
5946 WriteMultiXMP($self, $outfile, \$buff, $dirInfo{ExtendedXMP},
5947 29 ▶ $dirInfo{ExtendedGUID}) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&WriteMultiXMP($self, $outfile, \$buff, $dirInfo{"ExtendedXMP"}, $dirInfo{"ExtendedGUID"}) or $err = 1 29 0 29
5948 }
5949 }
5950 # then APP2 ICC_Profile segment
5951 506 ▶ last if $dirCount{ICC_Profile};
Branch: 1 branch
BranchTrueFalseTotal
if $dirCount{"ICC_Profile"} 5 501 506
5952 501 ▶ if (exists $$addDirs{ICC_Profile} and not defined $doneDir{ICC_Profile}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $addDirs->{"ICC_Profile"} and not defined $doneDir{"ICC_Profile"}) 3 498 501
Condition100%3/3
exists $addDirs->{"ICC_Profile"} and not defined $doneDir{"ICC_Profile"}
!ll&&!rl&&r
485133
MC/DC100%2/2
exists $addDirs->{"ICC_Profile"} and not defined $doneDir{"ICC_Profile"}
exists $addDirs->{"ICC_Profile"} not defined $doneDir{"ICC_Profile"}
Truth table100%3/3
A and not(B)
A= exists $addDirs->{"ICC_Profile"}B= not defined $doneDir{"ICC_Profile"}
ABresult
0X0
100
111
5953 3 $doneDir{ICC_Profile} = 1;
5954 3 ▶ next if $$delGroup{ICC_Profile} and $$delGroup{ICC_Profile} != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $delGroup->{"ICC_Profile"} and $delGroup->{"ICC_Profile"} != 2 0 3 3
Condition66%2/3
$delGroup->{"ICC_Profile"} and $delGroup->{"ICC_Profile"} != 2
!ll&&!rl&&r
210
MC/DC0%0/2
$delGroup->{"ICC_Profile"} and $delGroup->{"ICC_Profile"} != 2
$delGroup->{"ICC_Profile"} $delGroup->{"ICC_Profile"} != 2
Truth table66%2/3
A and B
A= $delGroup->{"ICC_Profile"}B= $delGroup->{"ICC_Profile"} != 2
ABresult
0X0
100
111
5955 3 ▶ $verbose and print $out "Creating APP2:\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "Creating APP2:\n" 0 3 3
5956 # write new ICC_Profile data
5957 3 my $tagTablePtr = GetTagTable('Image::ExifTool::ICC_Profile::Main');
5958 3 my %dirInfo = (
5959 Parent => 'APP2',
5960 );
5961 3 $$path[$pn] = 'APP2';
5962 3 my $buff = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
5963 3 ▶ if (defined $buff and length $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff and length $buff) 3 0 3
Condition33%1/3
defined $buff and length $buff
!ll&&!rl&&r
003
MC/DC0%0/2
defined $buff and length $buff
defined $buff length $buff
Truth table33%1/3
A and B
A= defined $buffB= length $buff
ABresult
0X0
100
111
5964 3 ▶ WriteMultiSegment($outfile, 0xe2, "ICC_PROFILE\0", \$buff, 'ICC') or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&WriteMultiSegment($outfile, 226, "ICC_PROFILE\0", \$buff, "ICC") or $err = 1 3 0 3
5965 3 ++$$self{CHANGED};
5966 }
5967 }
5968 # then APP12 Ducky segment
5969 501 ▶ last if $dirCount{Ducky};
Branch: 1 branch
BranchTrueFalseTotal
if $dirCount{"Ducky"} 1 500 501
5970 500 ▶ if (exists $$addDirs{Ducky} and not defined $doneDir{Ducky}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $addDirs->{"Ducky"} and not defined $doneDir{"Ducky"}) 2 498 500
Condition100%3/3
exists $addDirs->{"Ducky"} and not defined $doneDir{"Ducky"}
!ll&&!rl&&r
488102
MC/DC100%2/2
exists $addDirs->{"Ducky"} and not defined $doneDir{"Ducky"}
exists $addDirs->{"Ducky"} not defined $doneDir{"Ducky"}
Truth table100%3/3
A and not(B)
A= exists $addDirs->{"Ducky"}B= not defined $doneDir{"Ducky"}
ABresult
0X0
100
111
5971 2 $doneDir{Ducky} = 1;
5972 2 ▶ $verbose and print $out "Creating APP12 Ducky:\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "Creating APP12 Ducky:\n" 0 2 2
5973 # write new Ducky segment data
5974 2 my $tagTablePtr = GetTagTable('Image::ExifTool::APP12::Ducky');
5975 2 my %dirInfo = (
5976 Parent => 'APP12',
5977 );
5978 2 $$path[$pn] = 'APP12';
5979 2 my $buff = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
5980 2 ▶ if (defined $buff and length $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff and length $buff) 2 0 2
Condition33%1/3
defined $buff and length $buff
!ll&&!rl&&r
002
MC/DC0%0/2
defined $buff and length $buff
defined $buff length $buff
Truth table33%1/3
A and B
A= defined $buffB= length $buff
ABresult
0X0
100
111
5981 2 my $size = length($buff) + 5;
5982 2 ▶ if ($size <= $maxSegmentLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size <= $maxSegmentLen) { } 2 0 2
5983 # write the new segment with appropriate header
5984 2 my $app12hdr = "\xff\xec" . pack('n', $size + 2);
5985 2 ▶ Write($outfile, $app12hdr, 'Ducky', $buff) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $app12hdr, "Ducky", $buff) or $err = 1 2 0 2
5986 } else {
5987 0 $self->Warn("APP12 Ducky segment too large! ($size bytes)");
5988 }
5989 }
5990 }
5991 # then APP14 Adobe segment
5992 500 ▶ last if $dirCount{Adobe};
Branch: 1 branch
BranchTrueFalseTotal
if $dirCount{"Adobe"} 25 475 500
5993 475 ▶ if (exists $$addDirs{Adobe} and not defined $doneDir{Adobe}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $addDirs->{"Adobe"} and not defined $doneDir{"Adobe"}) 0 475 475
Condition33%1/3
exists $addDirs->{"Adobe"} and not defined $doneDir{"Adobe"}
!ll&&!rl&&r
47500
MC/DC0%0/2
exists $addDirs->{"Adobe"} and not defined $doneDir{"Adobe"}
exists $addDirs->{"Adobe"} not defined $doneDir{"Adobe"}
Truth table33%1/3
A and not(B)
A= exists $addDirs->{"Adobe"}B= not defined $doneDir{"Adobe"}
ABresult
0X0
100
111
5994 0 $doneDir{Adobe} = 1;
5995 0 my $buff = $self->GetNewValue('Adobe');
5996 0 ▶ if ($buff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buff) 0 0 0
5997 0 ▶ $verbose and print $out "Creating APP14:\n Creating Adobe segment\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "Creating APP14:\n Creating Adobe segment\n" 0 0 0
5998 0 my $size = length($buff);
5999 0 ▶ if ($size <= $maxSegmentLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size <= $maxSegmentLen) { } 0 0 0
6000 # write the new segment with appropriate header
6001 0 my $app14hdr = "\xff\xee" . pack('n', $size + 2);
6002 0 ▶ Write($outfile, $app14hdr, $buff) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $app14hdr, $buff) or $err = 1 0 0 0
6003 0 ++$$self{CHANGED};
6004 } else {
6005 0 $self->Warn("APP14 Adobe segment too large! ($size bytes)");
6006 }
6007 }
6008 }
6009 # finally, COM segment
6010 475 ▶ last if $dirCount{COM};
Branch: 1 branch
BranchTrueFalseTotal
if $dirCount{"COM"} 20 455 475
6011 455 ▶ if (exists $$addDirs{COM} and not defined $doneDir{COM}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $addDirs->{"COM"} and not defined $doneDir{"COM"}) 5 450 455
Condition100%3/3
exists $addDirs->{"COM"} and not defined $doneDir{"COM"}
!ll&&!rl&&r
427235
MC/DC100%2/2
exists $addDirs->{"COM"} and not defined $doneDir{"COM"}
exists $addDirs->{"COM"} not defined $doneDir{"COM"}
Truth table100%3/3
A and not(B)
A= exists $addDirs->{"COM"}B= not defined $doneDir{"COM"}
ABresult
0X0
100
111
6012 5 $doneDir{COM} = 1;
6013 5 ▶ next if $$delGroup{File} and $$delGroup{File} != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $delGroup->{"File"} and $delGroup->{"File"} != 2 0 5 5
Condition33%1/3
$delGroup->{"File"} and $delGroup->{"File"} != 2
!ll&&!rl&&r
500
MC/DC0%0/2
$delGroup->{"File"} and $delGroup->{"File"} != 2
$delGroup->{"File"} $delGroup->{"File"} != 2
Truth table33%1/3
A and B
A= $delGroup->{"File"}B= $delGroup->{"File"} != 2
ABresult
0X0
100
111
6014 5 my $newComment = $self->GetNewValue('Comment');
6015 5 ▶ if (defined $newComment) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newComment) 5 0 5
6016 5 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 5 5
6017 0 print $out "Creating COM:\n";
6018 0 $self->VerboseValue('+ Comment', $newComment);
6019 }
6020 5 ▶ WriteMultiSegment($outfile, 0xfe, '', \$newComment) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&WriteMultiSegment($outfile, 254, "", \$newComment) or $err = 1 5 0 5
6021 5 ++$$self{CHANGED};
6022 }
6023 }
6024 455 last; # didn't want to loop anyway
6025 }
6026 808 $$path[$pn] = $markerName;
6027 # decrement counter for this directory since we are about to process it
6028 808 --$dirCount{$dirName};
6029 #
6030 # rewrite existing segments
6031 #
6032 # handle SOF markers: SOF0-SOF15, except DHT(0xc4), JPGA(0xc8) and DAC(0xcc)
6033 808 ▶ if (($marker & 0xf0) == 0xc0 and ($marker == 0xc0 or $marker & 0x03)) {
Branch: 4 branches
BranchTrueFalseTotal
if (($marker & 240) == 192 and $marker == 192 || $marker & 3) { } 112 696 808
elsif ($marker == 218) { } 112 584 696
elsif ($marker == 217 and $isEXV) { } 2 582 584
elsif ($marker == 0 or $marker == 1 or $marker >= 208 and $marker <= 215) { } 0 694 694
Condition83%5/6
($marker & 240) == 192 and $marker == 192 || $marker & 3
!ll&&!rl&&r
584112112
$marker == 192 or $marker & 3
l!l&&r!l&&!r
1120112
MC/DC66%2/3
($marker & 240) == 192 and $marker == 192 || $marker & 3
($marker & 240) == 192 $marker == 192 $marker & 3
Truth table75%3/4
A and B or C
A= ($marker & 240) == 192B= $marker == 192C= $marker & 3
ABCresult
0XX0
1000
11X1
1011
6034 112 ▶ $verbose and print $out "JPEG $markerName:\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "JPEG ${markerName}:\n" 1 111 112
6035 112 ▶ Write($outfile, $hdr, $segData) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hdr, $segData) or $err = 1 112 0 112
6036 112 next;
6037 } elsif ($marker == 0xda) { # SOS
6038 112 pop @$path;
6039 112 ▶ $verbose and print $out "JPEG SOS\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "JPEG SOS\n" 1 111 112
6040 # write SOS segment
6041 112 $s = pack('n', length($segData) + 2);
6042 112 ▶ Write($outfile, $hdr, $s, $segData) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hdr, $s, $segData) or $err = 1 112 0 112
6043 112 my ($buff, $endPos, $trailInfo);
6044 112 my $delPreview = $$self{DEL_PREVIEW};
6045 112 ▶ $trailInfo = $self->IdentifyTrailer($raf) unless $$delGroup{Trailer};
Branch: 1 branch
BranchTrueFalseTotal
unless $delGroup->{"Trailer"} 108 4 112
6046 112 my $nvTrail = $self->GetNewValueHash($Image::ExifTool::Extra{Trailer});
6047 112 ▶ unless ($oldOutfile or $delPreview or $trailInfo or $$delGroup{Trailer} or
Branch: 1 branch
BranchTrueFalseTotal
unless ($oldOutfile or $delPreview or $trailInfo or $delGroup->{"Trailer"} or $nvTrail or $self->{"HiddenData"}) 97 15 112
Condition66%10/15
$oldOutfile or $delPreview or $trailInfo or $delGroup->{"Trailer"} or $nvTrail or $self->{"HiddenData"}
l!l&&r!l&&!r
15097
$oldOutfile or $delPreview or $trailInfo or $delGroup->{"Trailer"} or $nvTrail
l!l&&r!l&&!r
15097
$oldOutfile or $delPreview or $trailInfo or $delGroup->{"Trailer"}
l!l&&r!l&&!r
11497
$oldOutfile or $delPreview or $trailInfo
l!l&&r!l&&!r
011101
$oldOutfile or $delPreview
l!l&&r!l&&!r
00112
MC/DC33%2/6
$oldOutfile or $delPreview or $trailInfo or $delGroup->{"Trailer"} or $nvTrail or $self->{"HiddenData"}
$oldOutfile $delPreview $trailInfo $delGroup->{"Trailer"} $nvTrail $self->{"HiddenData"}
Truth table42%3/7
A or B or C or D or E or F
A= $oldOutfileB= $delPreviewC= $trailInfoD= $delGroup->{"Trailer"}E= $nvTrailF= $self->{"HiddenData"}
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
6048 $nvTrail or $$self{HiddenData})
6049 {
6050 # blindly copy the rest of the file
6051 97 ▶ while ($raf->Read($buff, 65536)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->Read($buff, 65536)) 97 97 194
6052 97 ▶ Write($outfile, $buff) or $err = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $buff) or $err = 1, last 97 0 97
6053 }
6054 97 $rtnVal = 1; # success unless we have a file write error
6055 97 last; # all done
6056 }
6057 # write the rest of the image (as quickly as possible) up to the EOI
6058 15 my $endedWithFF;
6059 15 for (;;) {
6060 15 ▶ my $n = $raf->Read($buff, 65536) or last Marker;
Branch: 1 branch
BranchTrueFalseTotal
my $n = $raf->Read($buff, 65536) or last Marker 15 0 15
6061 15 ▶ if (($endedWithFF and $buff =~ m/^\xd9/sg) or
Branch: 1 branch
BranchTrueFalseTotal
if ($endedWithFF and $buff =~ /^\xd9/gs or $buff =~ /\xff\xd9/gs) 15 0 15
Condition33%2/6
$endedWithFF and $buff =~ /^\xd9/gs or $buff =~ /\xff\xd9/gs
l!l&&r!l&&!r
0150
$endedWithFF and $buff =~ /^\xd9/gs
!ll&&!rl&&r
1500
MC/DC0%0/3
$endedWithFF and $buff =~ /^\xd9/gs or $buff =~ /\xff\xd9/gs
$endedWithFF $buff =~ /^\xd9/gs $buff =~ /\xff\xd9/gs
Truth table20%1/5
A and B or C
A= $endedWithFFB= $buff =~ /^\xd9/gsC= $buff =~ /\xff\xd9/gs
ABCresult
11X1
0X11
1011
0X00
1000
6062 $buff =~ m/\xff\xd9/sg)
6063 {
6064 15 $rtnVal = 1; # the JPEG is OK
6065 # write up to the EOI
6066 15 my $pos = pos($buff);
6067 15 ▶ Write($outfile, substr($buff, 0, $pos)) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, substr($buff, 0, $pos)) or $err = 1 15 0 15
6068 15 $buff = substr($buff, $pos);
6069 15 last;
6070 }
6071 0 ▶ unless ($n == 65536) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n == 65536) 0 0 0
6072 0 $self->Error('JPEG EOI marker not found');
6073 0 last Marker;
6074 }
6075 0 ▶ Write($outfile, $buff) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $buff) or $err = 1 0 0 0
6076 0 ▶ $endedWithFF = substr($buff, 65535, 1) eq "\xff" ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
substr($buff, 65535, 1) eq "\377" ? : 0 0 0
6077 }
6078 # remember position of last data copied
6079 15 $endPos = $$self{TrailerStart} = $raf->Tell() - length($buff);
6080 # write new trailer if specified
6081 15 ▶ if ($nvTrail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvTrail) 0 15 15
6082 # access new value directly to avoid copying a potentially very large data block
6083 0 ▶ if ($$nvTrail{Value} and $$nvTrail{Value}[0]) { # (note: "0" will also delete the trailer)
Branch: 2 branches
BranchTrueFalseTotal
if ($nvTrail->{'Value'} and $nvTrail->{'Value'}[0]) { } 0 0 0
elsif ($raf->Seek(0, 2) and $raf->Tell != $endPos) { } 0 0 0
Condition0%0/3
$nvTrail->{"Value"} and $nvTrail->{"Value"}[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$nvTrail->{"Value"} and $nvTrail->{"Value"}[0]
$nvTrail->{"Value"} $nvTrail->{"Value"}[0]
Truth table0%0/3
A and B
A= $nvTrail->{"Value"}B= $nvTrail->{"Value"}[0]
ABresult
0X0
100
111
6084 0 $self->VPrint(0, ' Writing new trailer');
6085 0 ▶ Write($outfile, $$nvTrail{Value}[0]) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $nvTrail->{"Value"}[0]) or $err = 1 0 0 0
6086 0 ++$$self{CHANGED};
6087 ▶ } elsif ($raf->Seek(0, 2) and $raf->Tell() != $endPos) {
Condition0%0/3
$raf->Seek(0, 2) and $raf->Tell != $endPos
!ll&&!rl&&r
000
MC/DC0%0/2
$raf->Seek(0, 2) and $raf->Tell != $endPos
$raf->Seek(0, 2) $raf->Tell != $endPos
Truth table0%0/3
A and B
A= $raf->Seek(0, 2)B= $raf->Tell != $endPos
ABresult
0X0
100
111
6088 0 $self->VPrint(0, ' Deleting trailer (', $raf->Tell() - $endPos, ' bytes)');
6089 0 ++$$self{CHANGED}; # changed if there was previously a trailer
6090 }
6091 0 last; # all done
6092 }
6093 # rewrite existing trailers into buffer
6094 15 ▶ if ($trailInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailInfo) 11 4 15
6095 11 my $tbuf = '';
6096 11 $raf->Seek(-length($buff), 1); # seek back to just after EOI
6097 11 $$trailInfo{OutFile} = \$tbuf; # rewrite the trailer
6098 11 $$trailInfo{ScanForTrailer} = 1;# scan if necessary
6099 11 ▶ $self->ProcessTrailers($trailInfo) or undef $trailInfo;
Branch: 1 branch
BranchTrueFalseTotal
$self->ProcessTrailers($trailInfo) or undef $trailInfo 11 0 11
6100 }
6101 15 ▶ if ($oldOutfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldOutfile) 0 15 15
6102 0 my $previewInfo;
6103 # copy HiddenData if necessary
6104 0 ▶ if ($$self{HiddenData}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"HiddenData"}) 0 0 0
6105 0 my $pad;
6106 0 my $hd = $$self{HiddenData};
6107 0 my $hdOff = $$hd{Offset} + $$hd{Base};
6108 0 require Image::ExifTool::Sony;
6109 # read HiddenData, updating $hdOff with actual offset if necessary
6110 0 my $dataPt = Image::ExifTool::Sony::ReadHiddenData($self, $hdOff, $$hd{Size});
6111 0 ▶ if ($dataPt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataPt) { } 0 0 0
6112 # preserve padding to avoid invalidating MPF pointers (yuk!)
6113 0 my $padLen = $hdOff - $endPos;
6114 0 ▶ unless ($padLen >= 0 and $raf->Seek($endPos,0) and $raf->Read($pad,$padLen)==$padLen) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($padLen >= 0 and $raf->Seek($endPos, 0) and $raf->Read($pad, $padLen) == $padLen) 0 0 0
Condition0%0/6
$padLen >= 0 and $raf->Seek($endPos, 0) and $raf->Read($pad, $padLen) == $padLen
!ll&&!rl&&r
000
$padLen >= 0 and $raf->Seek($endPos, 0)
!ll&&!rl&&r
000
MC/DC0%0/3
$padLen >= 0 and $raf->Seek($endPos, 0) and $raf->Read($pad, $padLen) == $padLen
$padLen >= 0 $raf->Seek($endPos, 0) $raf->Read($pad, $padLen) == $padLen
Truth table0%0/4
A and B and C
A= $padLen >= 0B= $raf->Seek($endPos, 0)C= $raf->Read($pad, $padLen) == $padLen
ABCresult
0XX0
10X0
1100
1111
6115 0 $self->Error('Error reading HiddenData padding',1);
6116 0 $pad = '';
6117 }
6118 0 $endPos += length($pad) + length($$dataPt); # update end position
6119 } else {
6120 0 $$dataPt = $pad = '';
6121 }
6122 0 my $fixup = $$self{HiddenData}{Fixup};
6123 # set MakerNote pointer and size (subtract 10 for segment and EXIF headers)
6124 0 $fixup->SetMarkerPointers($outfile, 'HiddenData', length($$outfile) + length($pad) - 10);
6125 0 $writeBuffer .= $pad . $$dataPt; # keep padding for now
6126 }
6127 0 ▶ if ($$self{LeicaTrailer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"LeicaTrailer"}) 0 0 0
6128 0 my $trailLen;
6129 0 ▶ if ($trailInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailInfo) { } 0 0 0
6130 0 $trailLen = $$trailInfo{DataPos} - $endPos;
6131 } else {
6132 0 ▶ $raf->Seek(0, 2) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek(0, 2) or $err = 1 0 0 0
6133 0 $trailLen = $raf->Tell() - $endPos;
6134 }
6135 0 my $fixup = $$self{LeicaTrailer}{Fixup};
6136 0 $$self{LeicaTrailer}{TrailPos} = $endPos;
6137 0 $$self{LeicaTrailer}{TrailLen} = $trailLen;
6138 # get _absolute_ position of new Leica trailer
6139 0 my $absPos = Tell($oldOutfile) + length($$outfile);
6140 0 require Image::ExifTool::Panasonic;
6141 0 my $dat = Image::ExifTool::Panasonic::ProcessLeicaTrailer($self, $absPos);
6142 # allow some junk before Leica trailer (just in case)
6143 0 my $junk = $$self{LeicaTrailerPos} - $endPos;
6144 # set MakerNote pointer and size (subtract 10 for segment and EXIF headers)
6145 0 $fixup->SetMarkerPointers($outfile, 'LeicaTrailer', length($$outfile) - 10 + $junk);
6146 # use this fixup to set the size too (sneaky)
6147 0 ▶ my $trailSize = defined($dat) ? length($dat) - $junk : $$self{LeicaTrailer}{Size};
Branch: 1 branch
BranchTrueFalseTotal
defined $dat ? : 0 0 0
6148 0 $$fixup{Start} -= 4; $$fixup{Shift} += 4;
6149 0 ▶ $fixup->SetMarkerPointers($outfile, 'LeicaTrailer', $trailSize) if defined $trailSize;
Branch: 1 branch
BranchTrueFalseTotal
if defined $trailSize 0 0 0
6150 0 $$fixup{Start} += 4; $$fixup{Shift} -= 4;
6151 0 ▶ if (defined $dat) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dat) 0 0 0
6152 0 ▶ Write($outfile, $dat) or $err = 1; # write new Leica trailer
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $dat) or $err = 1 0 0 0
6153 0 $delPreview = 1; # delete existing Leica trailer
6154 }
6155 }
6156 # handle preview image last
6157 0 ▶ if ($$self{PREVIEW_INFO}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PREVIEW_INFO"}) 0 0 0
6158 # locate preview image and fix up preview offsets
6159 0 ▶ my $scanLen = $$self{Make} =~ /^SONY/i ? 65536 : 1024;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'Make'} =~ /^SONY/i ? : 0 0 0
6160 0 ▶ if (length($buff) < $scanLen) { # make sure we have enough trailer to scan
Branch: 1 branch
BranchTrueFalseTotal
if (length $buff < $scanLen) 0 0 0
6161 0 my $buf2;
6162 0 ▶ $buff .= $buf2 if $raf->Read($buf2, $scanLen - length($buff));
Branch: 1 branch
BranchTrueFalseTotal
if $raf->Read($buf2, $scanLen - length($buff)) 0 0 0
6163 }
6164 # get new preview image position, relative to EXIF base
6165 0 my $newPos = length($$outfile) - 10; # (subtract 10 for segment and EXIF headers)
6166 0 my $junkLen;
6167 # adjust position if image isn't at the start (eg. Olympus E-1/E-300)
6168 0 ▶ if ($buff =~ /(\xff\xd8\xff.|.\xd8\xff\xdb)(..)/sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buff =~ /(\xff\xd8\xff.|.\xd8\xff\xdb)(..)/gs) 0 0 0
6169 0 my ($jpegHdr, $segLen) = ($1, $2);
6170 0 $junkLen = pos($buff) - 6;
6171 # Sony previewimage trailer has a 32 byte header
6172 0 ▶ if ($$self{Make} =~ /^SONY/i and $junkLen > 32) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Make"} =~ /^SONY/i and $junkLen > 32) 0 0 0
Condition0%0/3
$self->{"Make"} =~ /^SONY/i and $junkLen > 32
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"Make"} =~ /^SONY/i and $junkLen > 32
$self->{"Make"} =~ /^SONY/i $junkLen > 32
Truth table0%0/3
A and B
A= $self->{"Make"} =~ /^SONY/iB= $junkLen > 32
ABresult
0X0
100
111
6173 # with some newer Sony models, the makernotes preview pointer
6174 # points to JPEG at end of EXIF inside MPImage preview (what a pain!)
6175 0 ▶ if ($jpegHdr eq "\xff\xd8\xff\xe1") { # is the first segment EXIF?
Branch: 1 branch
BranchTrueFalseTotal
if ($jpegHdr eq "\377\330\377\341") 0 0 0
6176 0 $segLen = unpack('n', $segLen); # the EXIF segment length
6177 # Sony PreviewImage starts with last 2 bytes of EXIF segment
6178 # (and first byte is usually "\0", not "\xff", so don't check this)
6179 0 ▶ if (length($buff) > $junkLen + $segLen + 6 and
Branch: 1 branch
BranchTrueFalseTotal
if (length $buff > $junkLen + $segLen + 6 and substr($buff, $junkLen + $segLen + 3, 3) eq "\330\377\333") 0 0 0
Condition0%0/3
length $buff > $junkLen + $segLen + 6 and substr($buff, $junkLen + $segLen + 3, 3) eq "\330\377\333"
!ll&&!rl&&r
000
MC/DC0%0/2
length $buff > $junkLen + $segLen + 6 and substr($buff, $junkLen + $segLen + 3, 3) eq "\330\377\333"
length $buff > $junkLen + $segLen + 6 substr($buff, $junkLen + $segLen + 3, 3) eq "\330\377\333"
Truth table0%0/3
A and B
A= length $buff > $junkLen + $segLen + 6B= substr($buff, $junkLen + $segLen + 3, 3) eq "\330\377\333"
ABresult
0X0
100
111
6180 substr($buff, $junkLen + $segLen + 3, 3) eq "\xd8\xff\xdb")
6181 {
6182 0 $junkLen += $segLen + 2;
6183 # (note: this will not copy the trailer after PreviewImage,
6184 # which is a 14kB block full of zeros for the A77)
6185 }
6186 }
6187 0 $junkLen -= 32;
6188 }
6189 0 $newPos += $junkLen;
6190 }
6191 # fix up the preview offsets to point to the start of the new image
6192 0 $previewInfo = $$self{PREVIEW_INFO};
6193 0 delete $$self{PREVIEW_INFO};
6194 0 my $fixup = $$previewInfo{Fixup};
6195 0 ▶ $newPos += ($$previewInfo{BaseShift} || 0);
Condition0%0/2
$previewInfo->{'BaseShift'} || 0
l!l
00
MC/DC0%0/1
$previewInfo->{'BaseShift'} || 0
$previewInfo->{'BaseShift'}
Truth table0%0/2
A
A= $previewInfo->{'BaseShift'}
Aresult
11
00
6196 # adjust to absolute file offset if necessary (Samsung STMN)
6197 0 ▶ $newPos += Tell($oldOutfile) + 10 if $$previewInfo{Absolute};
Branch: 1 branch
BranchTrueFalseTotal
if $previewInfo->{"Absolute"} 0 0 0
6198 0 ▶ if ($$previewInfo{Relative}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($previewInfo->{'Relative'}) { } 0 0 0
elsif ($previewInfo->{'ChangeBase'}) { } 0 0 0
6199 # adjust for our base by looking at how far the pointer got shifted
6200 0 ▶ $newPos -= ($fixup->GetMarkerPointers($outfile, 'PreviewImage') || 0);
Condition0%0/2
$fixup->GetMarkerPointers($outfile, 'PreviewImage') || 0
l!l
00
MC/DC0%0/1
$fixup->GetMarkerPointers($outfile, 'PreviewImage') || 0
$fixup->GetMarkerPointers($outfile, 'PreviewImage')
Truth table0%0/2
A
A= $fixup->GetMarkerPointers($outfile, 'PreviewImage')
Aresult
11
00
6201 } elsif ($$previewInfo{ChangeBase}) {
6202 # Leica S2 uses relative offsets for the preview only (leica sucks)
6203 0 my $makerOffset = $fixup->GetMarkerPointers($outfile, 'LeicaTrailer');
6204 0 ▶ $newPos -= $makerOffset if $makerOffset;
Branch: 1 branch
BranchTrueFalseTotal
if $makerOffset 0 0 0
6205 }
6206 0 $fixup->SetMarkerPointers($outfile, 'PreviewImage', $newPos);
6207 0 ▶ if ($$previewInfo{Data} ne 'LOAD_PREVIEW') {
Branch: 1 branch
BranchTrueFalseTotal
if ($previewInfo->{"Data"} ne "LOAD_PREVIEW") 0 0 0
6208 # write any junk that existed before the preview image
6209 0 ▶ $$previewInfo{Junk} = substr($buff,0,$junkLen) if $junkLen;
Branch: 1 branch
BranchTrueFalseTotal
if $junkLen 0 0 0
6210 }
6211 }
6212 # clean up and write the buffered data
6213 0 $outfile = $oldOutfile;
6214 0 undef $oldOutfile;
6215 0 ▶ Write($outfile, $writeBuffer) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $writeBuffer) or $err = 1 0 0 0
6216 0 undef $writeBuffer;
6217 # write preview image
6218 0 ▶ if ($previewInfo and $$previewInfo{Data} ne 'LOAD_PREVIEW') {
Branch: 1 branch
BranchTrueFalseTotal
if ($previewInfo and $previewInfo->{"Data"} ne "LOAD_PREVIEW") 0 0 0
Condition0%0/3
$previewInfo and $previewInfo->{"Data"} ne "LOAD_PREVIEW"
!ll&&!rl&&r
000
MC/DC0%0/2
$previewInfo and $previewInfo->{"Data"} ne "LOAD_PREVIEW"
$previewInfo $previewInfo->{"Data"} ne "LOAD_PREVIEW"
Truth table0%0/3
A and B
A= $previewInfoB= $previewInfo->{"Data"} ne "LOAD_PREVIEW"
ABresult
0X0
100
111
6219 # write any junk that existed before the preview image
6220 0 ▶ Write($outfile, $$previewInfo{Junk}) or $err = 1 if defined $$previewInfo{Junk};
Branch: 1 branch
BranchTrueFalseTotal
if defined $previewInfo->{"Junk"} 0 0 0
Condition0%0/6
defined $previewInfo->{'Junk'} && (&Write($outfile, $previewInfo->{'Junk'}) || ($err = 1))
!ll&&!rl&&r
000
&Write($outfile, $previewInfo->{"Junk"}) or $err = 1
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $previewInfo->{'Junk'} && (&Write($outfile, $previewInfo->{'Junk'}) || ($err = 1))
defined $previewInfo->{'Junk'} &Write($outfile, $previewInfo->{"Junk"}) $err = 1
Truth table0%0/4
A && B or C
A= defined $previewInfo->{'Junk'}B= &Write($outfile, $previewInfo->{"Junk"})C= $err = 1
ABCresult
0XX0
1000
11X1
1011
6221 # write the saved preview image
6222 0 ▶ Write($outfile, $$previewInfo{Data}) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $previewInfo->{"Data"}) or $err = 1 0 0 0
6223 0 delete $$previewInfo{Data};
6224 # (don't increment CHANGED because we could be rewriting existing preview)
6225 0 $delPreview = 1; # remove old preview
6226 }
6227 }
6228 # copy over preview image (or other data) if necessary
6229 15 ▶ unless ($delPreview) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($delPreview) 15 0 15
6230 15 my $extra;
6231 15 ▶ if ($trailInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailInfo) { } 11 4 15
6232 # copy everything up to start of first processed trailer
6233 11 ▶ $extra = defined $$trailInfo{DataPos} ? ($$trailInfo{DataPos} - $endPos) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $trailInfo->{'DataPos'} ? : 11 0 11
6234 } else {
6235 # copy everything up to end of file
6236 4 ▶ $raf->Seek(0, 2) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek(0, 2) or $err = 1 4 0 4
6237 4 $extra = $raf->Tell() - $endPos;
6238 }
6239 15 ▶ if ($extra > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra > 0) 3 12 15
6240 3 ▶ if ($$delGroup{Trailer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delGroup->{'Trailer'}) { } 2 1 3
6241 2 ▶ $verbose and print $out " Deleting unknown trailer ($extra bytes)\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting unknown trailer ($extra bytes)\n" 0 2 2
6242 2 ++$$self{CHANGED};
6243 } else {
6244 # copy over unknown trailer
6245 1 ▶ $verbose and print $out " Preserving unknown trailer ($extra bytes)\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Preserving unknown trailer ($extra bytes)\n" 0 1 1
6246 1 ▶ $raf->Seek($endPos, 0) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($endPos, 0) or $err = 1 1 0 1
6247 1 ▶ CopyBlock($raf, $outfile, $extra) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&CopyBlock($raf, $outfile, $extra) or $err = 1 1 0 1
6248 }
6249 }
6250 }
6251 # write trailer if necessary
6252 15 ▶ if ($trailInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailInfo) 11 4 15
6253 11 ▶ $self->WriteTrailerBuffer($trailInfo, $outfile) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->WriteTrailerBuffer($trailInfo, $outfile) or $err = 1 11 0 11
6254 11 undef $trailInfo;
6255 }
6256 15 last; # all done parsing file
6257  
6258 ▶ } elsif ($marker==0xd9 and $isEXV) {
Condition66%2/3
$marker == 217 and $isEXV
!ll&&!rl&&r
58202
MC/DC50%1/2
$marker == 217 and $isEXV
$marker == 217 $isEXV
Truth table66%2/3
A and B
A= $marker == 217B= $isEXV
ABresult
0X0
100
111
6259 # write EXV EOI (any trailer will be lost)
6260 2 ▶ Write($outfile, "\xff\xd9") or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, "\377\331") or $err = 1 2 0 2
6261 2 $rtnVal = 1;
6262 2 last;
6263  
6264 ▶ } elsif ($marker==0x00 or $marker==0x01 or ($marker>=0xd0 and $marker<=0xd7)) {
Condition44%4/9
$marker == 0 or $marker == 1 or $marker >= 208 and $marker <= 215
l!l&&r!l&&!r
00582
$marker == 0 or $marker == 1
l!l&&r!l&&!r
00582
$marker >= 208 and $marker <= 215
!ll&&!rl&&r
1124700
MC/DC0%0/4
$marker == 0 or $marker == 1 or $marker >= 208 and $marker <= 215
$marker == 0 $marker == 1 $marker >= 208 $marker <= 215
Truth table40%2/5
A or B or C and D
A= $marker == 0B= $marker == 1C= $marker >= 208D= $marker <= 215
ABCDresult
1XXX1
01XX1
00111
000X0
00100
6265 0 ▶ $verbose and $marker and print $out "JPEG $markerName:\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and $marker and print $out "JPEG ${markerName}:\n" 0 0 0
Condition0%0/3
$verbose and $marker
!ll&&!rl&&r
000
MC/DC0%0/2
$verbose and $marker
$verbose $marker
Truth table0%0/3
A and B
A= $verboseB= $marker
ABresult
0X0
100
111
6266 # handle stand-alone markers 0x00, 0x01 and 0xd0-0xd7 (NULL, TEM, RST0-RST7)
6267 0 ▶ Write($outfile, $hdr) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hdr) or $err = 1 0 0 0
6268 0 next;
6269 }
6270 #
6271 # NOTE: A 'next' statement after this point will cause $$segDataPt
6272 # not to be written if there is an output file, so in this case
6273 # the $$self{CHANGED} flags must be updated
6274 #
6275 582 my $segDataPt = \$segData;
6276 582 $length = length($segData);
6277 582 ▶ print $out "JPEG $markerName ($length bytes)\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 2 580 582
6278 # group delete of APP segments
6279 582 ▶ if ($$delGroup{$dirName}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delGroup->{$dirName}) 55 527 582
6280 55 ▶ $verbose and print $out " Deleting $dirName segment\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting $dirName segment\n" 0 55 55
6281 55 ▶ $self->Warn('ICC_Profile deleted. Image colors may be affected') if $dirName eq 'ICC_Profile';
Branch: 1 branch
BranchTrueFalseTotal
if $dirName eq "ICC_Profile" 4 51 55
6282 55 ++$$self{CHANGED};
6283 55 next Marker;
6284 }
6285 527 my ($segType, $del);
6286 # rewrite this segment only if we are changing a tag which is contained in its
6287 # directory (or deleting '*', in which case we need to identify the segment type)
6288 527 ▶ while (exists $$editDirs{$markerName} or $$delGroup{'*'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $editDirs->{$markerName} or $delGroup->{"*"}) 131 396 527
Condition100%3/3
exists $editDirs->{$markerName} or $delGroup->{"*"}
l!l&&r!l&&!r
12110396
MC/DC100%2/2
exists $editDirs->{$markerName} or $delGroup->{"*"}
exists $editDirs->{$markerName} $delGroup->{"*"}
Truth table100%3/3
A or B
A= exists $editDirs->{$markerName}B= $delGroup->{"*"}
ABresult
1X1
011
000
6289 131 ▶ if ($marker == 0xe0) { # APP0 (JFIF, CIFF)
Branch: 12 branches
BranchTrueFalseTotal
if ($marker == 224) { } 31 100 131
elsif ($marker == 225) { } 73 27 100
elsif ($marker == 226) { } 0 27 27
elsif ($marker == 227) { } 1 26 27
elsif ($marker == 229) { } 0 26 26
elsif ($marker == 232 or $marker == 233) { } 0 26 26
elsif ($marker == 234) { } 0 26 26
elsif ($marker == 235) { } 0 26 26
elsif ($marker == 236) { } 1 25 26
elsif ($marker == 237) { } 9 16 25
elsif ($marker == 238) { } 4 12 16
elsif ($marker == 254) { } 4 8 12
6290 31 ▶ if ($$segDataPt =~ /^JFIF\0/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$segDataPt =~ /^JFIF\0/) { } 11 20 31
elsif ($$segDataPt =~ /^JFXX\0\x10/) { } 8 12 20
elsif ($$segDataPt =~ /^(II|MM).{4}HEAPJPGM/s) { } 6 6 12
6291 11 $segType = 'JFIF';
6292 11 ▶ $$delGroup{JFIF} and $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"JFIF"} and $del = 1, last 0 11 11
6293 11 ▶ last unless $$editDirs{JFIF};
Branch: 1 branch
BranchTrueFalseTotal
unless $editDirs->{"JFIF"} 0 11 11
6294 11 SetByteOrder('MM');
6295 11 my $tagTablePtr = GetTagTable('Image::ExifTool::JFIF::Main');
6296 11 my %dirInfo = (
6297 DataPt => $segDataPt,
6298 DataPos => $segPos,
6299 DataLen => $length,
6300 DirStart => 5, # directory starts after identifier
6301 DirLen => $length-5,
6302 Parent => $markerName,
6303 );
6304 11 my $newData = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
6305 11 ▶ if (defined $newData and length $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newData and length $newData) 11 0 11
Condition33%1/3
defined $newData and length $newData
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $newData and length $newData
defined $newData length $newData
Truth table33%1/3
A and B
A= defined $newDataB= length $newData
ABresult
0X0
100
111
6306 11 $$segDataPt = "JFIF\0" . $newData;
6307 }
6308 } elsif ($$segDataPt =~ /^JFXX\0\x10/) {
6309 8 $segType = 'JFXX';
6310 8 ▶ $$delGroup{JFIF} and $del = 1;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"JFIF"} and $del = 1 2 6 8
6311 } elsif ($$segDataPt =~ /^(II|MM).{4}HEAPJPGM/s) {
6312 6 $segType = 'CIFF';
6313 6 ▶ $$delGroup{CIFF} and $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"CIFF"} and $del = 1, last 0 6 6
6314 6 ▶ last unless $$editDirs{CIFF};
Branch: 1 branch
BranchTrueFalseTotal
unless $editDirs->{"CIFF"} 2 4 6
6315 4 my $newData = '';
6316 4 my %dirInfo = (
6317 RAF => File::RandomAccess->new($segDataPt),
6318 OutFile => \$newData,
6319 );
6320 4 require Image::ExifTool::CanonRaw;
6321 4 ▶ if (Image::ExifTool::CanonRaw::WriteCRW($self, \%dirInfo) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (Image::ExifTool::CanonRaw::WriteCRW($self, \%dirInfo) > 0) 4 0 4
6322 4 ▶ if (length $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $newData) { } 4 0 4
6323 4 $$segDataPt = $newData;
6324 } else {
6325 0 undef $segDataPt;
6326 0 $del = 1; # delete this segment
6327 }
6328 }
6329 }
6330 } elsif ($marker == 0xe1) { # APP1 (EXIF, XMP)
6331 # check for EXIF data
6332 73 ▶ if ($$segDataPt =~ /^(.{0,4})Exif\0./is) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$segDataPt =~ /^(.{0,4})Exif\0./is) { } 52 21 73
elsif ($$segDataPt =~ /^($Image::ExifTool::xmpAPP1hdr|$Image::ExifTool::xmpExtAPP1hdr)/) { } 21 0 21
elsif ($$segDataPt =~ /^http/ or $$segDataPt =~ /<exif:/) { } 0 0 0
6333 52 my $hdrLen = length $exifAPP1hdr;
6334 52 ▶ if (length $1) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $1) { } 0 52 52
elsif (not $$segDataPt =~ /^Exif\0/) { } 0 52 52
6335 0 $hdrLen += length $1;
6336 0 $self->Error('Unknown garbage at start of EXIF segment',1);
6337 } elsif ($$segDataPt !~ /^Exif\0/) {
6338 0 $self->Error('Incorrect EXIF segment identifier',1);
6339 }
6340 52 $segType = 'EXIF';
6341 52 ▶ last unless $$editDirs{IFD0};
Branch: 1 branch
BranchTrueFalseTotal
unless $editDirs->{"IFD0"} 1 51 52
6342 # add this data to the combined data if it exists
6343 51 ▶ if (defined $combinedSegData) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $combinedSegData) 0 51 51
6344 0 $combinedSegData .= substr($$segDataPt,$hdrLen);
6345 0 $segDataPt = \$combinedSegData;
6346 0 $segPos = $firstSegPos;
6347 0 $length = length $combinedSegData; # update length
6348 }
6349 # peek ahead to see if the next segment is extended EXIF
6350 51 ▶ if ($dirOrder[0] eq 'ExtendedEXIF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirOrder[0] eq "ExtendedEXIF") 0 51 51
6351 # initialize combined data if necessary
6352 0 ▶ unless (defined $combinedSegData) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $combinedSegData) 0 0 0
6353 0 $combinedSegData = $$segDataPt;
6354 0 $firstSegPos = $segPos;
6355 0 $self->Warn('File contains multi-segment EXIF',1);
6356 }
6357 0 next Marker; # get the next segment to combine
6358 }
6359 51 ▶ $doneDir{IFD0} and $self->Warn('Multiple APP1 EXIF records');
Branch: 1 branch
BranchTrueFalseTotal
$doneDir{"IFD0"} and $self->Warn("Multiple APP1 EXIF records") 0 51 51
6360 51 $doneDir{IFD0} = 1;
6361 # check del groups now so we can change byte order in one step
6362 51 ▶ if ($$delGroup{IFD0} or $$delGroup{EXIF}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delGroup->{"IFD0"} or $delGroup->{"EXIF"}) 1 50 51
Condition66%2/3
$delGroup->{"IFD0"} or $delGroup->{"EXIF"}
l!l&&r!l&&!r
0150
MC/DC50%1/2
$delGroup->{"IFD0"} or $delGroup->{"EXIF"}
$delGroup->{"IFD0"} $delGroup->{"EXIF"}
Truth table66%2/3
A or B
A= $delGroup->{"IFD0"}B= $delGroup->{"EXIF"}
ABresult
1X1
011
000
6363 1 delete $doneDir{IFD0}; # delete so we will create a new one
6364 1 $del = 1;
6365 1 last;
6366 }
6367 # rewrite EXIF as if this were a TIFF file in memory
6368 50 my %dirInfo = (
6369 DataPt => $segDataPt,
6370 DataPos => -$hdrLen, # (remember: relative to Base!)
6371 DirStart => $hdrLen,
6372 Base => $segPos + $hdrLen,
6373 Parent => $markerName,
6374 DirName => 'IFD0',
6375 );
6376 # write new EXIF data to memory
6377 50 my $tagTablePtr = GetTagTable('Image::ExifTool::Exif::Main');
6378 50 my $buff = $self->WriteDirectory(\%dirInfo, $tagTablePtr, \&WriteTIFF);
6379 50 ▶ if (defined $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff) { } 50 0 50
6380 50 undef $$segDataPt; # free the old buffer
6381 50 $segDataPt = \$buff;
6382 } else {
6383 0 ▶ last Marker unless $self->Options('IgnoreMinorErrors');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->Options("IgnoreMinorErrors") 0 0 0
6384 }
6385 # delete segment if IFD contains no entries
6386 50 ▶ length $$segDataPt or $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
length $$segDataPt or $del = 1, last 46 4 50
6387 46 ▶ if (length($$segDataPt) + length($exifAPP1hdr) > $maxSegmentLen) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($$segDataPt) + length($Image::ExifTool::exifAPP1hdr) > $maxSegmentLen) 0 46 46
6388 0 ▶ if ($self->Options('NoMultiExif')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Options('NoMultiExif')) { } 0 0 0
6389 0 $self->Error('EXIF is too large for JPEG segment');
6390 } else {
6391 0 $self->Warn('Writing multi-segment EXIF',1);
6392 }
6393 }
6394 # switch to buffered output if required
6395 46 ▶ if (($$self{PREVIEW_INFO} or $$self{LeicaTrailer} or $$self{HiddenData}) and
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PREVIEW_INFO"} || $self->{"LeicaTrailer"} || $self->{"HiddenData"} and not $oldOutfile) 0 46 46
Condition33%3/9
$self->{"PREVIEW_INFO"} || $self->{"LeicaTrailer"} || $self->{"HiddenData"} and not $oldOutfile
!ll&&!rl&&r
4600
$self->{"PREVIEW_INFO"} or $self->{"LeicaTrailer"} or $self->{"HiddenData"}
l!l&&r!l&&!r
0046
$self->{"PREVIEW_INFO"} or $self->{"LeicaTrailer"}
l!l&&r!l&&!r
0046
MC/DC0%0/4
$self->{"PREVIEW_INFO"} || $self->{"LeicaTrailer"} || $self->{"HiddenData"} and not $oldOutfile
$self->{"PREVIEW_INFO"} $self->{"LeicaTrailer"} $self->{"HiddenData"} not $oldOutfile
Truth table14%1/7
A or B or C and not(D)
A= $self->{"PREVIEW_INFO"}B= $self->{"LeicaTrailer"}C= $self->{"HiddenData"}D= not $oldOutfile
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
6396 not $oldOutfile)
6397 {
6398 0 $writeBuffer = '';
6399 0 $oldOutfile = $outfile;
6400 0 $outfile = \$writeBuffer;
6401 # must account for segment, EXIF and TIFF headers
6402 0 foreach (qw(PREVIEW_INFO LeicaTrailer HiddenData)) {
6403 0 ▶ $$self{$_}{Fixup}{Start} += 18 if $$self{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$_} 0 0 0
6404 }
6405 }
6406 # write as multi-segment
6407 46 my $n = WriteMultiSegment($outfile, $marker, $exifAPP1hdr, $segDataPt, 'EXIF');
6408 46 ▶ if (not $n) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $n) { } 0 46 46
elsif ($n > 1 and $oldOutfile) { } 0 92 92
6409 0 $err = 1;
6410 ▶ } elsif ($n > 1 and $oldOutfile) {
Condition33%1/3
$n > 1 and $oldOutfile
!ll&&!rl&&r
4600
MC/DC0%0/2
$n > 1 and $oldOutfile
$n > 1 $oldOutfile
Truth table33%1/3
A and B
A= $n > 1B= $oldOutfile
ABresult
0X0
100
111
6411 # (punt on this because updating the pointers would be a real pain)
6412 0 $self->Error("Can't write multi-segment EXIF with external pointers");
6413 }
6414 46 undef $combinedSegData;
6415 46 undef $$segDataPt;
6416 46 next Marker;
6417 # check for XMP data
6418 } elsif ($$segDataPt =~ /^($xmpAPP1hdr|$xmpExtAPP1hdr)/) {
6419 21 $segType = 'XMP';
6420 21 ▶ $$delGroup{XMP} and $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"XMP"} and $del = 1, last 0 21 21
6421 21 ▶ $doneDir{XMP} = ($doneDir{XMP} || 0) + 1;
Condition100%2/2
$doneDir{'XMP'} || 0
l!l
219
MC/DC100%1/1
$doneDir{'XMP'} || 0
$doneDir{'XMP'}
Truth table100%2/2
A
A= $doneDir{'XMP'}
Aresult
11
00
6422 21 ▶ last unless $$editDirs{XMP};
Branch: 1 branch
BranchTrueFalseTotal
unless $editDirs->{"XMP"} 7 14 21
6423 14 ▶ if ($doneDir{XMP} + $dirCount{XMP} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doneDir{"XMP"} + $dirCount{"XMP"} > 1) 3 11 14
6424 # must assemble all XMP segments before writing
6425 3 my ($guid, $extXMP);
6426 3 ▶ if ($$segDataPt =~ /^$xmpExtAPP1hdr/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$segDataPt =~ /^$Image::ExifTool::xmpExtAPP1hdr/) { } 2 1 3
6427 # save extended XMP data
6428 2 ▶ if (length $$segDataPt < 75) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$segDataPt < 75) { } 0 2 2
6429 0 $extendedXMP{Error} = 'Truncated data';
6430 } else {
6431 2 my ($size, $off) = unpack('x67N2', $$segDataPt);
6432 2 $guid = substr($$segDataPt, 35, 32);
6433 2 ▶ if ($guid =~ /[^A-Za-z0-9]/) { # (technically, should be uppercase)
Branch: 1 branch
BranchTrueFalseTotal
if ($guid =~ /[^A-Za-z0-9]/) { } 0 2 2
6434 0 $extendedXMP{Error} = 'Invalid GUID';
6435 } else {
6436 # remember extended data for each GUID
6437 2 $extXMP = $extendedXMP{$guid};
6438 2 ▶ if ($extXMP) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extXMP) { } 1 1 2
6439 1 ▶ $size == $$extXMP{Size} or $extendedXMP{Error} = 'Inconsistent size';
Branch: 1 branch
BranchTrueFalseTotal
$size == $extXMP->{"Size"} or $extendedXMP{"Error"} = "Inconsistent size" 1 0 1
6440 } else {
6441 1 $extXMP = $extendedXMP{$guid} = { };
6442 }
6443 2 $$extXMP{Size} = $size;
6444 2 $$extXMP{$off} = substr($$segDataPt, 75);
6445 }
6446 }
6447 } else {
6448 # save all main XMP segments (should normally be only one)
6449 1 ▶ $extendedXMP{Main} = [] unless $extendedXMP{Main};
Branch: 1 branch
BranchTrueFalseTotal
unless $extendedXMP{"Main"} 1 0 1
6450 1 push @{$extendedXMP{Main}}, substr($$segDataPt, length $xmpAPP1hdr);
6451 }
6452 # continue processing only if we have read all the segments
6453 3 ▶ next Marker if $dirCount{XMP};
Branch: 1 branch
BranchTrueFalseTotal
if $dirCount{"XMP"} 2 1 3
6454 # reconstruct an XMP super-segment
6455 1 $$segDataPt = $xmpAPP1hdr;
6456 1 my $goodGuid = '';
6457 1 foreach (@{$extendedXMP{Main}}) {
6458 # get the HasExtendedXMP GUID if it exists
6459 1 ▶ if (/:HasExtendedXMP\s*(=\s*['"]|>)(\w{32})/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/:HasExtendedXMP\s*(=\s*['"]|>)(\w{32})/) 1 0 1
6460 # warn of subsequent XMP blocks specifying a different
6461 # HasExtendedXMP (have never seen this)
6462 1 ▶ if ($goodGuid and $goodGuid ne $2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($goodGuid and $goodGuid ne $2) 0 1 1
Condition33%1/3
$goodGuid and $goodGuid ne $2
!ll&&!rl&&r
100
MC/DC0%0/2
$goodGuid and $goodGuid ne $2
$goodGuid $goodGuid ne $2
Truth table33%1/3
A and B
A= $goodGuidB= $goodGuid ne $2
ABresult
0X0
100
111
6463 0 $self->Warn('Multiple XMP segments specifying different extended XMP GUID');
6464 }
6465 1 $goodGuid = $2; # GUID for the standard extended XMP
6466 }
6467 1 $$segDataPt .= $_;
6468 }
6469 # GUID of the extended XMP that we want to read
6470 1 ▶ my $readGuid = $$self{OPTIONS}{ExtendedXMP} || 0;
Condition50%1/2
$self->{'OPTIONS'}{'ExtendedXMP'} || 0
l!l
10
MC/DC0%0/1
$self->{'OPTIONS'}{'ExtendedXMP'} || 0
$self->{'OPTIONS'}{'ExtendedXMP'}
Truth table50%1/2
A
A= $self->{'OPTIONS'}{'ExtendedXMP'}
Aresult
11
00
6471 1 ▶ $readGuid = $goodGuid if $readGuid eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $readGuid eq 1 1 0 1
6472 1 foreach $guid (sort keys %extendedXMP) {
6473 2 ▶ next unless length $guid == 32; # ignore other (internal) keys
Branch: 1 branch
BranchTrueFalseTotal
unless length $guid == 32 1 1 2
6474 1 ▶ if ($guid ne $readGuid and $readGuid ne '2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($guid ne $readGuid and $readGuid ne 2) 0 1 1
Condition33%1/3
$guid ne $readGuid and $readGuid ne 2
!ll&&!rl&&r
100
MC/DC0%0/2
$guid ne $readGuid and $readGuid ne 2
$guid ne $readGuid $readGuid ne 2
Truth table33%1/3
A and B
A= $guid ne $readGuidB= $readGuid ne 2
ABresult
0X0
100
111
6475 0 ▶ my $non = $guid eq $goodGuid ? '' : 'non-';
Branch: 1 branch
BranchTrueFalseTotal
$guid eq $goodGuid ? : 0 0 0
6476 0 $self->Warn("Ignored ${non}standard extended XMP (GUID $guid)");
6477 0 next;
6478 }
6479 1 ▶ if ($guid ne $goodGuid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guid ne $goodGuid) 0 1 1
6480 0 $self->Warn("Reading non-standard extended XMP (GUID $guid)");
6481 }
6482 1 $extXMP = $extendedXMP{$guid};
6483 1 ▶ next unless ref $extXMP eq 'HASH'; # (just to be safe)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extXMP eq "HASH" 0 1 1
6484 1 my $size = $$extXMP{Size};
6485 1 my (@offsets, $off);
6486 1 ▶ for ($off=0; $off<$size; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off < $size) 2 1 3
6487 2 ▶ last unless defined $$extXMP{$off};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extXMP->{$off} 0 2 2
6488 2 push @offsets, $off;
6489 2 $off += length $$extXMP{$off};
6490 }
6491 1 ▶ if ($off == $size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off == $size) { } 1 0 1
6492 # add all XMP to super-segment
6493 1 $$segDataPt .= $$extXMP{$_} foreach @offsets;
6494 } else {
6495 0 $self->Error("Incomplete extended XMP (GUID $guid)", 1);
6496 }
6497 }
6498 1 ▶ $self->Error("$extendedXMP{Error} in extended XMP", 1) if $extendedXMP{Error};
Branch: 1 branch
BranchTrueFalseTotal
if $extendedXMP{"Error"} 0 1 1
6499 }
6500 12 my $start = length $xmpAPP1hdr;
6501 12 my $tagTablePtr = GetTagTable('Image::ExifTool::XMP::Main');
6502 12 my %dirInfo = (
6503 DataPt => $segDataPt,
6504 DirStart => $start,
6505 Parent => $markerName,
6506 # limit XMP size and create extended XMP if necessary
6507 MaxDataLen => $maxXMPLen - length($xmpAPP1hdr),
6508 );
6509 12 my $newData = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
6510 12 ▶ if (defined $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newData) { } 9 3 12
6511 9 undef %extendedXMP;
6512 9 ▶ if (length $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $newData) { } 7 2 9
6513 # write multi-segment XMP (XMP plus extended XMP if necessary)
6514 WriteMultiXMP($self, $outfile, \$newData, $dirInfo{ExtendedXMP},
6515 7 ▶ $dirInfo{ExtendedGUID}) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&WriteMultiXMP($self, $outfile, \$newData, $dirInfo{"ExtendedXMP"}, $dirInfo{"ExtendedGUID"}) or $err = 1 7 0 7
6516 7 undef $$segDataPt; # free the old buffer
6517 7 next Marker;
6518 } else {
6519 2 $$segDataPt = ''; # delete the XMP
6520 }
6521 } else {
6522 3 ▶ $verbose and print $out " [XMP rewritten with no changes]\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " [XMP rewritten with no changes]\n" 0 3 3
6523 3 ▶ if ($doneDir{XMP} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doneDir{"XMP"} > 1) 0 3 3
6524 # re-write original multi-segment XMP
6525 0 my ($dat, $guid, $extXMP, $off);
6526 0 foreach $dat (@{$extendedXMP{Main}}) { # main XMP
6527 0 ▶ next unless length $dat;
Branch: 1 branch
BranchTrueFalseTotal
unless length $dat 0 0 0
6528 0 $s = pack('n', length($xmpAPP1hdr) + length($dat) + 2);
6529 0 ▶ Write($outfile, $hdr, $s, $xmpAPP1hdr, $dat) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hdr, $s, $Image::ExifTool::xmpAPP1hdr, $dat) or $err = 1 0 0 0
6530 }
6531 0 foreach $guid (sort keys %extendedXMP) { # extended XMP
6532 0 ▶ next unless length $guid == 32;
Branch: 1 branch
BranchTrueFalseTotal
unless length $guid == 32 0 0 0
6533 0 $extXMP = $extendedXMP{$guid};
6534 0 ▶ next unless ref $extXMP eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extXMP eq "HASH" 0 0 0
6535 0 ▶ my $size = $$extXMP{Size} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $size = $extXMP->{"Size"} or next 0 0 0
6536 0 ▶ for ($off=0; defined $$extXMP{$off}; $off += length $$extXMP{$off}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extXMP->{$off}) 0 0 0
6537 0 $s = pack('n', length($xmpExtAPP1hdr) + length($$extXMP{$off}) + 42);
6538 Write($outfile, $hdr, $s, $xmpExtAPP1hdr, $guid,
6539 0 ▶ pack('N2', $size, $off), $$extXMP{$off}) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hdr, $s, $Image::ExifTool::xmpExtAPP1hdr, $guid, pack("N2", $size, $off), $extXMP->{$off}) or $err = 1 0 0 0
6540 }
6541 }
6542 0 undef $$segDataPt; # free the old buffer
6543 0 undef %extendedXMP;
6544 0 next Marker;
6545 }
6546 # continue on to re-write original single-segment XMP
6547 }
6548 5 ▶ $del = 1 unless length $$segDataPt;
Branch: 1 branch
BranchTrueFalseTotal
unless length $$segDataPt 2 3 5
6549 ▶ } elsif ($$segDataPt =~ /^http/ or $$segDataPt =~ /<exif:/) {
Condition0%0/3
$$segDataPt =~ /^http/ or $$segDataPt =~ /<exif:/
l!l&&r!l&&!r
000
MC/DC0%0/2
$$segDataPt =~ /^http/ or $$segDataPt =~ /<exif:/
$$segDataPt =~ /^http/ $$segDataPt =~ /<exif:/
Truth table0%0/3
A or B
A= $$segDataPt =~ /^http/B= $$segDataPt =~ /<exif:/
ABresult
1X1
011
000
6550 0 $self->Warn('Ignored APP1 XMP segment with non-standard header', 1);
6551 }
6552 } elsif ($marker == 0xe2) { # APP2 (ICC Profile, FPXR, MPF)
6553 0 ▶ if ($$segDataPt =~ /^ICC_PROFILE\0/ and $length >= 14) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$segDataPt =~ /^ICC_PROFILE\0/ and $length >= 14) { } 0 0 0
elsif ($$segDataPt =~ /^FPXR\0/) { } 0 0 0
elsif ($$segDataPt =~ /^MPF\0/) { } 0 0 0
Condition0%0/3
$$segDataPt =~ /^ICC_PROFILE\0/ and $length >= 14
!ll&&!rl&&r
000
MC/DC0%0/2
$$segDataPt =~ /^ICC_PROFILE\0/ and $length >= 14
$$segDataPt =~ /^ICC_PROFILE\0/ $length >= 14
Truth table0%0/3
A and B
A= $$segDataPt =~ /^ICC_PROFILE\0/B= $length >= 14
ABresult
0X0
100
111
6554 0 $segType = 'ICC_Profile';
6555 0 ▶ $$delGroup{ICC_Profile} and $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"ICC_Profile"} and $del = 1, last 0 0 0
6556 # must concatenate blocks of profile
6557 0 my $chunkNum = Get8u($segDataPt, 12);
6558 0 my $chunksTot = Get8u($segDataPt, 13);
6559 0 ▶ if (defined $iccChunksTotal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $iccChunksTotal) { } 0 0 0
6560 # abort parsing ICC_Profile if the total chunk count is inconsistent
6561 0 ▶ if ($chunksTot != $iccChunksTotal and defined $iccChunkCount) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunksTot != $iccChunksTotal and defined $iccChunkCount) 0 0 0
Condition0%0/3
$chunksTot != $iccChunksTotal and defined $iccChunkCount
!ll&&!rl&&r
000
MC/DC0%0/2
$chunksTot != $iccChunksTotal and defined $iccChunkCount
$chunksTot != $iccChunksTotal defined $iccChunkCount
Truth table0%0/3
A and B
A= $chunksTot != $iccChunksTotalB= defined $iccChunkCount
ABresult
0X0
100
111
6562 # an error because the accumulated profile data will be lost
6563 0 $self->Error('Inconsistent ICC_Profile chunk count', 1);
6564 0 undef $iccChunkCount; # abort ICC_Profile parsing
6565 0 undef $chunkNum; # avoid 2nd warning below
6566 0 ++$$self{CHANGED}; # we are deleting the bad chunks before this one
6567 }
6568 } else {
6569 0 $iccChunkCount = 0;
6570 0 $iccChunksTotal = $chunksTot;
6571 0 ▶ $self->Warn('ICC_Profile chunk count is zero') if !$chunksTot;
Branch: 1 branch
BranchTrueFalseTotal
unless $chunksTot 0 0 0
6572 }
6573 0 ▶ if (defined $iccChunkCount) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $iccChunkCount) { } 0 0 0
elsif (defined $chunkNum) { } 0 0 0
6574 # save this chunk
6575 0 ▶ if (defined $iccChunk[$chunkNum]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $iccChunk[$chunkNum]) { } 0 0 0
6576 0 $self->Warn("Duplicate ICC_Profile chunk number $chunkNum");
6577 0 $iccChunk[$chunkNum] .= substr($$segDataPt, 14);
6578 } else {
6579 0 $iccChunk[$chunkNum] = substr($$segDataPt, 14);
6580 }
6581 # continue accumulating chunks unless we have all of them
6582 0 ▶ next Marker unless ++$iccChunkCount >= $iccChunksTotal;
Branch: 1 branch
BranchTrueFalseTotal
unless ++$iccChunkCount >= $iccChunksTotal 0 0 0
6583 0 undef $iccChunkCount; # prevent reprocessing
6584 0 $doneDir{ICC_Profile} = 1;
6585 # combine the ICC_Profile chunks
6586 0 my $icc_profile = '';
6587 0 ▶ defined $_ and $icc_profile .= $_ foreach @iccChunk;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $icc_profile .= $_ 0 0 0
6588 0 undef @iccChunk; # free memory
6589 0 $segDataPt = \$icc_profile;
6590 0 $length = length $icc_profile;
6591 0 my $tagTablePtr = GetTagTable('Image::ExifTool::ICC_Profile::Main');
6592 0 my %dirInfo = (
6593 DataPt => $segDataPt,
6594 DataPos => $segPos + 14,
6595 DataLen => $length,
6596 DirStart => 0,
6597 DirLen => $length,
6598 Parent => $markerName,
6599 );
6600 0 my $newData = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
6601 0 ▶ if (defined $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newData) 0 0 0
6602 0 undef $$segDataPt; # free the old buffer
6603 0 $segDataPt = \$newData;
6604 }
6605 0 ▶ length $$segDataPt or $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
length $$segDataPt or $del = 1, last 0 0 0
6606 # write as ICC multi-segment
6607 0 ▶ WriteMultiSegment($outfile, $marker, "ICC_PROFILE\0", $segDataPt, 'ICC') or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&WriteMultiSegment($outfile, $marker, "ICC_PROFILE\0", $segDataPt, "ICC") or $err = 1 0 0 0
6608 0 undef $$segDataPt;
6609 0 next Marker;
6610 } elsif (defined $chunkNum) {
6611 0 $self->Warn('Invalid or extraneous ICC_Profile chunk(s)');
6612 # fall through to preserve this extra profile...
6613 }
6614 } elsif ($$segDataPt =~ /^FPXR\0/) {
6615 0 $segType = 'FPXR';
6616 0 ▶ $$delGroup{FlashPix} and $del = 1;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"FlashPix"} and $del = 1 0 0 0
6617 } elsif ($$segDataPt =~ /^MPF\0/) {
6618 0 $segType = 'MPF';
6619 0 ▶ $$delGroup{MPF} and $del = 1;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"MPF"} and $del = 1 0 0 0
6620 }
6621 } elsif ($marker == 0xe3) { # APP3 (Kodak Meta)
6622 1 ▶ if ($$segDataPt =~ /^(Meta|META|Exif)\0\0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$segDataPt =~ /^(Meta|META|Exif)\0\0/) 1 0 1
6623 1 $segType = 'Kodak Meta';
6624 1 ▶ $$delGroup{Meta} and $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"Meta"} and $del = 1, last 0 1 1
6625 1 ▶ $doneDir{Meta} and $self->Warn('Multiple APP3 Meta segments');
Branch: 1 branch
BranchTrueFalseTotal
$doneDir{"Meta"} and $self->Warn("Multiple APP3 Meta segments") 0 1 1
6626 1 $doneDir{Meta} = 1;
6627 1 ▶ last unless $$editDirs{Meta};
Branch: 1 branch
BranchTrueFalseTotal
unless $editDirs->{"Meta"} 0 1 1
6628 # rewrite Meta IFD as if this were a TIFF file in memory
6629 1 my %dirInfo = (
6630 DataPt => $segDataPt,
6631 DataPos => -6, # (remember: relative to Base!)
6632 DirStart => 6,
6633 Base => $segPos + 6,
6634 Parent => $markerName,
6635 DirName => 'Meta',
6636 );
6637 # write new data to memory
6638 1 my $tagTablePtr = GetTagTable('Image::ExifTool::Kodak::Meta');
6639 1 my $buff = $self->WriteDirectory(\%dirInfo, $tagTablePtr, \&WriteTIFF);
6640 1 ▶ if (defined $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff) { } 1 0 1
6641 # update segment with new data
6642 1 $$segDataPt = substr($$segDataPt,0,6) . $buff;
6643 } else {
6644 0 ▶ last Marker unless $self->Options('IgnoreMinorErrors');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->Options("IgnoreMinorErrors") 0 0 0
6645 }
6646 # delete segment if IFD contains no entries
6647 1 ▶ $del = 1 unless length($$segDataPt) > 6;
Branch: 1 branch
BranchTrueFalseTotal
unless length $$segDataPt > 6 0 1 1
6648 }
6649 } elsif ($marker == 0xe5) { # APP5 (Ricoh RMETA)
6650 0 ▶ if ($$segDataPt =~ /^RMETA\0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$segDataPt =~ /^RMETA\0/) 0 0 0
6651 0 $segType = 'Ricoh RMETA';
6652 0 ▶ $$delGroup{RMETA} and $del = 1;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"RMETA"} and $del = 1 0 0 0
6653 }
6654 ▶ } elsif ($marker == 0xe8 or $marker == 0xe9) { # APP8/9 (SEAL)
Condition33%1/3
$marker == 232 or $marker == 233
l!l&&r!l&&!r
0026
MC/DC0%0/2
$marker == 232 or $marker == 233
$marker == 232 $marker == 233
Truth table33%1/3
A or B
A= $marker == 232B= $marker == 233
ABresult
1X1
011
000
6655 0 ▶ if ($$segDataPt =~ /^SEAL\0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$segDataPt =~ /^SEAL\0/) 0 0 0
6656 0 $segType = 'SEAL';
6657 0 ▶ $$delGroup{SEAL} and $del = 1;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"SEAL"} and $del = 1 0 0 0
6658 }
6659 } elsif ($marker == 0xea) { # APP10 (AROT)
6660 0 ▶ if ($$segDataPt =~ /^AROT\0\0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$segDataPt =~ /^AROT\0\0/) 0 0 0
6661 0 $segType = 'AROT';
6662 0 ▶ $$delGroup{AROT} and $del = 1;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"AROT"} and $del = 1 0 0 0
6663 }
6664 } elsif ($marker == 0xeb) { # APP11 (JUMBF)
6665 0 ▶ if ($$segDataPt =~ /^JP/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$segDataPt =~ /^JP/) 0 0 0
6666 0 $segType = 'JUMBF';
6667 0 ▶ $$delGroup{JUMBF} and $del = 1;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"JUMBF"} and $del = 1 0 0 0
6668 }
6669 } elsif ($marker == 0xec) { # APP12 (Ducky)
6670 1 ▶ if ($$segDataPt =~ /^Ducky/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$segDataPt =~ /^Ducky/) 1 0 1
6671 1 $segType = 'Ducky';
6672 1 ▶ $$delGroup{Ducky} and $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"Ducky"} and $del = 1, last 0 1 1
6673 1 ▶ $doneDir{Ducky} and $self->Warn('Multiple APP12 Ducky segments');
Branch: 1 branch
BranchTrueFalseTotal
$doneDir{"Ducky"} and $self->Warn("Multiple APP12 Ducky segments") 0 1 1
6674 1 $doneDir{Ducky} = 1;
6675 1 ▶ last unless $$editDirs{Ducky};
Branch: 1 branch
BranchTrueFalseTotal
unless $editDirs->{"Ducky"} 0 1 1
6676 1 my $tagTablePtr = GetTagTable('Image::ExifTool::APP12::Ducky');
6677 1 my %dirInfo = (
6678 DataPt => $segDataPt,
6679 DataPos => $segPos,
6680 DataLen => $length,
6681 DirStart => 5, # directory starts after identifier
6682 DirLen => $length-5,
6683 Parent => $markerName,
6684 );
6685 1 my $newData = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
6686 1 ▶ if (defined $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newData) 1 0 1
6687 1 undef $$segDataPt; # free the old buffer
6688 # add header to new segment unless empty
6689 1 ▶ $newData = 'Ducky' . $newData if length $newData;
Branch: 1 branch
BranchTrueFalseTotal
if length $newData 0 1 1
6690 1 $segDataPt = \$newData;
6691 }
6692 1 ▶ $del = 1 unless length $$segDataPt;
Branch: 1 branch
BranchTrueFalseTotal
unless length $$segDataPt 1 0 1
6693 }
6694 } elsif ($marker == 0xed) { # APP13 (Photoshop)
6695 9 ▶ if ($$segDataPt =~ /^$psAPP13hdr/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$segDataPt =~ /^$Image::ExifTool::psAPP13hdr/) 8 1 9
6696 8 $segType = 'Photoshop';
6697 # add this data to the combined data if it exists
6698 8 ▶ if (defined $combinedSegData) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $combinedSegData) 0 8 8
6699 0 $combinedSegData .= substr($$segDataPt,length($psAPP13hdr));
6700 0 $segDataPt = \$combinedSegData;
6701 0 $length = length $combinedSegData; # update length
6702 }
6703 # peek ahead to see if the next segment is photoshop data too
6704 8 ▶ if ($dirOrder[0] eq 'Photoshop') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirOrder[0] eq "Photoshop") 0 8 8
6705 # initialize combined data if necessary
6706 0 ▶ $combinedSegData = $$segDataPt unless defined $combinedSegData;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $combinedSegData 0 0 0
6707 0 next Marker; # get the next segment to combine
6708 }
6709 8 ▶ if ($doneDir{Photoshop}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doneDir{"Photoshop"}) 0 8 8
6710 0 $self->Warn('Multiple Photoshop records');
6711 # only rewrite the first Photoshop segment when deleting this group
6712 # (to remove multiples when deleting and adding back in one step)
6713 0 ▶ $$delGroup{Photoshop} and $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
$delGroup->{"Photoshop"} and $del = 1, last 0 0 0
6714 }
6715 8 $doneDir{Photoshop} = 1;
6716 # process APP13 Photoshop record
6717 8 my $tagTablePtr = GetTagTable('Image::ExifTool::Photoshop::Main');
6718 8 my %dirInfo = (
6719 DataPt => $segDataPt,
6720 DataPos => $segPos,
6721 DataLen => $length,
6722 DirStart => 14, # directory starts after identifier
6723 DirLen => $length-14,
6724 Parent => $markerName,
6725 );
6726 8 my $newData = $self->WriteDirectory(\%dirInfo, $tagTablePtr);
6727 8 ▶ if (defined $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newData) 8 0 8
6728 8 undef $$segDataPt; # free the old buffer
6729 8 $segDataPt = \$newData;
6730 }
6731 8 ▶ length $$segDataPt or $del = 1, last;
Branch: 1 branch
BranchTrueFalseTotal
length $$segDataPt or $del = 1, last 6 2 8
6732 # write as multi-segment
6733 6 ▶ WriteMultiSegment($outfile, $marker, $psAPP13hdr, $segDataPt) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&WriteMultiSegment($outfile, $marker, $Image::ExifTool::psAPP13hdr, $segDataPt) or $err = 1 6 0 6
6734 6 undef $combinedSegData;
6735 6 undef $$segDataPt;
6736 6 next Marker;
6737 }
6738 } elsif ($marker == 0xee) { # APP14 (Adobe)
6739 4 ▶ if ($$segDataPt =~ /^Adobe/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$segDataPt =~ /^Adobe/) 4 0 4
6740 4 $segType = 'Adobe';
6741 # delete it and replace it later if editing
6742 4 ▶ if ($$delGroup{Adobe} or $$editDirs{Adobe}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delGroup->{"Adobe"} or $editDirs->{"Adobe"}) 0 4 4
Condition33%1/3
$delGroup->{"Adobe"} or $editDirs->{"Adobe"}
l!l&&r!l&&!r
004
MC/DC0%0/2
$delGroup->{"Adobe"} or $editDirs->{"Adobe"}
$delGroup->{"Adobe"} $editDirs->{"Adobe"}
Truth table33%1/3
A or B
A= $delGroup->{"Adobe"}B= $editDirs->{"Adobe"}
ABresult
1X1
011
000
6743 0 $del = 1;
6744 0 undef $doneDir{Adobe}; # so we can add it back again above
6745 }
6746 }
6747 } elsif ($marker == 0xfe) { # COM (JPEG comment)
6748 4 my $newComment;
6749 4 ▶ unless ($doneDir{COM}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doneDir{"COM"}) 4 0 4
6750 4 $doneDir{COM} = 1;
6751 4 ▶ unless ($$delGroup{File} and $$delGroup{File} != 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($delGroup->{"File"} and $delGroup->{"File"} != 2) 3 1 4
Condition100%3/3
$delGroup->{"File"} and $delGroup->{"File"} != 2
!ll&&!rl&&r
211
MC/DC100%2/2
$delGroup->{"File"} and $delGroup->{"File"} != 2
$delGroup->{"File"} $delGroup->{"File"} != 2
Truth table100%3/3
A and B
A= $delGroup->{"File"}B= $delGroup->{"File"} != 2
ABresult
0X0
100
111
6752 3 my $tagInfo = $Image::ExifTool::Extra{Comment};
6753 3 my $nvHash = $self->GetNewValueHash($tagInfo);
6754 3 my $val = $segData;
6755 3 $val =~ s/\0+$//; # allow for stupid software that adds NULL terminator
6756 3 ▶ if ($self->IsOverwriting($nvHash, $val) or $$delGroup{File}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->IsOverwriting($nvHash, $val) or $delGroup->{'File'}) { } 3 0 3
Condition33%1/3
$self->IsOverwriting($nvHash, $val) or $delGroup->{"File"}
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->IsOverwriting($nvHash, $val) or $delGroup->{"File"}
$self->IsOverwriting($nvHash, $val) $delGroup->{"File"}
Truth table33%1/3
A or B
A= $self->IsOverwriting($nvHash, $val)B= $delGroup->{"File"}
ABresult
1X1
011
000
6757 3 $newComment = $self->GetNewValue($nvHash);
6758 } else {
6759 0 delete $$editDirs{COM}; # we aren't editing COM after all
6760 0 last;
6761 }
6762 }
6763 }
6764 4 $self->VerboseValue('- Comment', $$segDataPt);
6765 4 ▶ if (defined $newComment) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newComment) { } 2 2 4
6766 # write out the comments
6767 2 $self->VerboseValue('+ Comment', $newComment);
6768 2 ▶ WriteMultiSegment($outfile, 0xfe, '', \$newComment) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&WriteMultiSegment($outfile, 254, "", \$newComment) or $err = 1 2 0 2
6769 } else {
6770 2 ▶ $verbose and print $out " Deleting COM segment\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting COM segment\n" 0 2 2
6771 }
6772 4 ++$$self{CHANGED}; # increment the changed flag
6773 4 undef $segDataPt; # don't write existing comment
6774 }
6775 53 last; # didn't want to loop anyway
6776 }
6777  
6778 # delete necessary segments (including unknown segments if deleting all)
6779 466 ▶ if ($del or ($$delGroup{'*'} and not $segType and $marker>=0xe0 and $marker<=0xef)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($del or $delGroup->{"*"} and not $segType and $marker >= 224 and $marker <= 239) 13 453 466
Condition100%12/12
$del or $delGroup->{"*"} and not $segType and $marker >= 224 and $marker <= 239
l!l&&r!l&&!r
121453
$delGroup->{"*"} and not $segType and $marker >= 224 and $marker <= 239
!ll&&!rl&&r
45121
$delGroup->{"*"} and not $segType and $marker >= 224
!ll&&!rl&&r
44383
$delGroup->{"*"} and not $segType
!ll&&!rl&&r
438511
MC/DC100%5/5
$del or $delGroup->{"*"} and not $segType and $marker >= 224 and $marker <= 239
$del $delGroup->{"*"} not $segType $marker >= 224 $marker <= 239
Truth table100%6/6
A or B and not(C) and D and E
A= $delB= $delGroup->{"*"}C= not $segTypeD= $marker >= 224E= $marker <= 239
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
6780 13 ▶ $segType = 'unknown' unless $segType;
Branch: 1 branch
BranchTrueFalseTotal
unless $segType 1 12 13
6781 13 ▶ $verbose and print $out " Deleting $markerName $segType segment\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting $markerName $segType segment\n" 0 13 13
6782 13 ++$$self{CHANGED};
6783 13 next Marker;
6784 }
6785 # write out this segment if $segDataPt is still defined
6786 453 ▶ if (defined $segDataPt and defined $$segDataPt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $segDataPt and defined $$segDataPt) 449 4 453
Condition66%2/3
defined $segDataPt and defined $$segDataPt
!ll&&!rl&&r
40449
MC/DC50%1/2
defined $segDataPt and defined $$segDataPt
defined $segDataPt defined $$segDataPt
Truth table66%2/3
A and B
A= defined $segDataPtB= defined $$segDataPt
ABresult
0X0
100
111
6787 # write the data for this record (the data could have been
6788 # modified, so recalculate the length word)
6789 449 my $size = length($$segDataPt);
6790 449 ▶ if ($size > $maxSegmentLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > $maxSegmentLen) { } 0 449 449
6791 0 ▶ $segType or $segType = 'Unknown';
Branch: 1 branch
BranchTrueFalseTotal
$segType or $segType = "Unknown" 0 0 0
6792 0 $self->Error("$segType $markerName segment too large! ($size bytes)");
6793 0 $err = 1;
6794 } else {
6795 449 $s = pack('n', length($$segDataPt) + 2);
6796 449 ▶ Write($outfile, $hdr, $s, $$segDataPt) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hdr, $s, $$segDataPt) or $err = 1 449 0 449
6797 }
6798 449 undef $$segDataPt; # free the buffer
6799 449 undef $segDataPt;
6800 }
6801 }
6802 # make sure the ICC_Profile was complete
6803 114 ▶ $self->Error('Incomplete ICC_Profile record', 1) if defined $iccChunkCount;
Branch: 1 branch
BranchTrueFalseTotal
if defined $iccChunkCount 0 114 114
6804 114 ▶ pop @$path if @$path > $pn;
Branch: 1 branch
BranchTrueFalseTotal
if @$path > $pn 2 112 114
6805 # if oldOutfile is still set, there was an error copying the JPEG
6806 114 ▶ $oldOutfile and return 0;
Branch: 1 branch
BranchTrueFalseTotal
$oldOutfile and return 0 0 114 114
6807 114 ▶ if ($rtnVal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtnVal) 114 0 114
6808 # add any new trailers we are creating
6809 114 my $trailPt = $self->AddNewTrailers();
6810 114 ▶ Write($outfile, $$trailPt) or $err = 1 if $trailPt;
Branch: 1 branch
BranchTrueFalseTotal
if $trailPt 3 111 114
Condition50%3/6
$trailPt && (&Write($outfile, $$trailPt) || ($err = 1))
!ll
11130
&Write($outfile, $$trailPt) or $err = 1
l!l&&r!l&&!r
300
MC/DC0%0/3
$trailPt && (&Write($outfile, $$trailPt) || ($err = 1))
$trailPt &Write($outfile, $$trailPt) $err = 1
Truth table0%0/4
A && B or C
A= $trailPtB= &Write($outfile, $$trailPt)C= $err = 1
ABCresult
0XX0
1000
11X1
1011
6811 }
6812 # set return value to -1 if we only had a write error
6813 114 ▶ $rtnVal = -1 if $rtnVal and $err;
Branch: 1 branch
BranchTrueFalseTotal
if $rtnVal and $err 0 114 114
Condition33%1/3
$rtnVal and $err
!ll&&!rl&&r
01140
MC/DC0%0/2
$rtnVal and $err
$rtnVal $err
Truth table33%1/3
A and B
A= $rtnValB= $err
ABresult
0X0
100
111
6814 114 ▶ if ($creatingEXV and $rtnVal > 0 and not $$self{CHANGED}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($creatingEXV and $rtnVal > 0 and not $self->{"CHANGED"}) 0 114 114
Condition66%4/6
$creatingEXV and $rtnVal > 0 and not $self->{"CHANGED"}
!ll&&!rl&&r
11310
$creatingEXV and $rtnVal > 0
!ll&&!rl&&r
11301
MC/DC0%0/3
$creatingEXV and $rtnVal > 0 and not $self->{"CHANGED"}
$creatingEXV $rtnVal > 0 not $self->{"CHANGED"}
Truth table50%2/4
A and B and not(C)
A= $creatingEXVB= $rtnVal > 0C= not $self->{"CHANGED"}
ABCresult
0XX0
10X0
1100
1111
6815 0 $self->Error('Nothing written');
6816 0 $rtnVal = -1;
6817 }
6818 114 return $rtnVal;
6819 }
6820  
6821 #------------------------------------------------------------------------------
6822 # Validate an image for writing
6823 # Inputs: 0) ExifTool object reference, 1) raw value reference
6824 # Returns: error string or undef on success
6825 sub CheckImage($$)
6826 138 ▶{
Subroutine CheckImage: called CC=4 SCAR=13.9
Pod undocumented
6827 138 my ($self, $valPtr) = @_;
6828 138 ▶ if (length($$valPtr) and $$valPtr!~/^\xff\xd8/ and not
Branch: 1 branch
BranchTrueFalseTotal
if (length $$valPtr and not $$valPtr =~ /^\xff\xd8/ and not $self->Options("IgnoreMinorErrors")) 25 113 138
Condition100%6/6
length $$valPtr and not $$valPtr =~ /^\xff\xd8/ and not $self->Options("IgnoreMinorErrors")
!ll&&!rl&&r
555825
length $$valPtr and not $$valPtr =~ /^\xff\xd8/
!ll&&!rl&&r
47883
MC/DC100%3/3
length $$valPtr and not $$valPtr =~ /^\xff\xd8/ and not $self->Options("IgnoreMinorErrors")
length $$valPtr not $$valPtr =~ /^\xff\xd8/ not $self->Options("IgnoreMinorErrors")
Truth table100%4/4
A and not(B) and not(C)
A= length $$valPtrB= not $$valPtr =~ /^\xff\xd8/C= not $self->Options("IgnoreMinorErrors")
ABCresult
0XX0
10X0
1100
1111
6829 $self->Options('IgnoreMinorErrors'))
6830 {
6831 25 return '[Minor] Not a valid image';
6832 }
6833 113 return undef;
6834 }
6835  
6836 #------------------------------------------------------------------------------
6837 # check a value for validity
6838 # Inputs: 0) value reference, 1) format string, 2) optional count
6839 # Returns: error string, or undef on success
6840 # Notes: May modify value (if a count is specified for a string, it is null-padded
6841 # to the specified length, and floating point values are rounded to integer if required)
6842 sub CheckValue($$;$)
6843 20030 ▶{
Subroutine CheckValue: called CC=38 SCAR=36.8
Pod undocumented
6844 20030 my ($valPtr, $format, $count) = @_;
6845 20030 my (@vals, $val, $n);
6846  
6847 20030 ▶ if ($format eq 'string' or $format eq 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq "string" or $format eq "undef") 2662 17368 20030
Condition100%3/3
$format eq "string" or $format eq "undef"
l!l&&r!l&&!r
222343917368
MC/DC100%2/2
$format eq "string" or $format eq "undef"
$format eq "string" $format eq "undef"
Truth table100%3/3
A or B
A= $format eq "string"B= $format eq "undef"
ABresult
1X1
011
000
6848 2662 ▶ return undef unless $count and $count > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $count and $count > 0 2297 365 2662
Condition66%2/3
$count and $count > 0
!ll&&!rl&&r
22970365
MC/DC50%1/2
$count and $count > 0
$count $count > 0
Truth table66%2/3
A and B
A= $countB= $count > 0
ABresult
0X0
100
111
6849 365 my $len = length($$valPtr);
6850 365 ▶ if ($format eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq 'string') { } 229 136 365
6851 229 ▶ $len >= $count and return 'String too long';
Branch: 1 branch
BranchTrueFalseTotal
$len >= $count and return "String too long" 10 219 229
6852 } else {
6853 136 ▶ $len > $count and return 'Data too long';
Branch: 1 branch
BranchTrueFalseTotal
$len > $count and return "Data too long" 0 136 136
6854 }
6855 355 ▶ if ($len < $count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len < $count) 269 86 355
6856 269 $$valPtr .= "\0" x ($count - $len);
6857 }
6858 355 return undef;
6859 }
6860 17368 ▶ if ($count and $count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count and $count != 1) { } 2132 15236 17368
Condition66%2/3
$count and $count != 1
!ll&&!rl&&r
1523602132
MC/DC50%1/2
$count and $count != 1
$count $count != 1
Truth table66%2/3
A and B
A= $countB= $count != 1
ABresult
0X0
100
111
6861 2132 @vals = split(' ',$$valPtr);
6862 2132 ▶ $count < 0 and ($count = @vals or return undef);
Branch: 1 branch
BranchTrueFalseTotal
$count < 0 and ($count = @vals) || (return undef) 151 1981 2132
Condition80%4/5
$count < 0 && (($count = @vals) || (return undef))
!ll
19811510
$count = @vals or return undef
l!l
11338
MC/DC0%0/2
$count < 0 && (($count = @vals) || (return undef))
$count < 0 $count = @vals
Truth table66%2/3
A && B
A= $count < 0B= $count = @vals
ABresult
0X0
100
111
6863 } else {
6864 15236 $count = 1;
6865 15236 @vals = ( $$valPtr );
6866 }
6867 17330 ▶ if (@vals != $count) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals != $count) 1059 16271 17330
6868 1059 ▶ my $str = @vals > $count ? 'Too many' : 'Not enough';
Branch: 1 branch
BranchTrueFalseTotal
@vals > $count ? : 3 1056 1059
6869 1059 return "$str values specified ($count required)";
6870 }
6871 16271 ▶ for ($n=0; $n<$count; ++$n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < $count) 19314 13690 33004
6872 19314 $val = shift @vals;
6873 19314 ▶ if ($format =~ /^int/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($format =~ /^int/) { } 17905 1409 19314
elsif ($format =~ /^rational/ or $format eq 'float' or $format eq 'double') { } 1406 3 1409
6874 # make sure the value is integer
6875 17905 ▶ unless (IsInt($val)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&IsInt($val)) 3331 14574 17905
6876 3331 ▶ if (IsHex($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&IsHex($val)) { } 7 3324 3331
6877 7 $val = $$valPtr = hex($val);
6878 } else {
6879 # round single floating point values to the nearest integer
6880 3324 ▶ return 'Not an integer' unless IsFloat($val) and $count == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless &IsFloat($val) and $count == 1 2060 1264 3324
Condition100%3/3
&IsFloat($val) and $count == 1
!ll&&!rl&&r
2048121264
MC/DC100%2/2
&IsFloat($val) and $count == 1
&IsFloat($val) $count == 1
Truth table100%3/3
A and B
A= &IsFloat($val)B= $count == 1
ABresult
0X0
100
111
6881 1264 ▶ $val = $$valPtr = int($val + ($val < 0 ? -0.5 : 0.5));
Branch: 1 branch
BranchTrueFalseTotal
$val < 0 ? : 20 1244 1264
6882 }
6883 }
6884 15845 ▶ my $rng = $intRange{$format} or return "Bad int format: $format";
Branch: 1 branch
BranchTrueFalseTotal
my $rng = $intRange{$format} or return "Bad int format: $format" 15845 0 15845
6885 15845 ▶ return "Value below $format minimum" if $val < $$rng[0];
Branch: 1 branch
BranchTrueFalseTotal
if $val < $rng->[0] 313 15532 15845
6886 # (allow 0xfeedfeed code as value for 16-bit pointers)
6887 15532 ▶ return "Value above $format maximum" if $val > $$rng[1] and $val != 0xfeedfeed;
Branch: 1 branch
BranchTrueFalseTotal
if $val > $rng->[1] and $val != 4277010157 6 15526 15532
Condition66%2/3
$val > $rng->[1] and $val != 4277010157
!ll&&!rl&&r
1552606
MC/DC50%1/2
$val > $rng->[1] and $val != 4277010157
$val > $rng->[1] $val != 4277010157
Truth table66%2/3
A and B
A= $val > $rng->[1]B= $val != 4277010157
ABresult
0X0
100
111
6888 ▶ } elsif ($format =~ /^rational/ or $format eq 'float' or $format eq 'double') {
Condition100%6/6
$format =~ /^rational/ or $format eq "float" or $format eq "double"
l!l&&r!l&&!r
1375313
$format =~ /^rational/ or $format eq "float"
l!l&&r!l&&!r
119817734
MC/DC100%3/3
$format =~ /^rational/ or $format eq "float" or $format eq "double"
$format =~ /^rational/ $format eq "float" $format eq "double"
Truth table100%4/4
A or B or C
A= $format =~ /^rational/B= $format eq "float"C= $format eq "double"
ABCresult
1XX1
01X1
0011
0000
6889 # make sure the value is a valid floating point number
6890 1406 ▶ unless (IsFloat($val)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&IsFloat($val)) 273 1133 1406
6891 # allow 'inf', 'undef' and fractional rational values
6892 273 ▶ if ($format =~ /^rational/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /^rational/) 235 38 273
6893 235 ▶ next if $val eq 'inf' or $val eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $val eq "inf" or $val eq "undef" 1 234 235
Condition66%2/3
$val eq "inf" or $val eq "undef"
l!l&&r!l&&!r
01234
MC/DC50%1/2
$val eq "inf" or $val eq "undef"
$val eq "inf" $val eq "undef"
Truth table66%2/3
A or B
A= $val eq "inf"B= $val eq "undef"
ABresult
1X1
011
000
6894 234 ▶ if ($val =~ m{^([-+]?\d+)/(\d+)$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ m[^([-+]?\d+)/(\d+)$]) 70 164 234
6895 70 ▶ next unless $1 < 0 and $format =~ /u$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 < 0 and $format =~ /u$/ 70 0 70
Condition66%2/3
$1 < 0 and $format =~ /u$/
!ll&&!rl&&r
6190
MC/DC0%0/2
$1 < 0 and $format =~ /u$/
$1 < 0 $format =~ /u$/
Truth table66%2/3
A and B
A= $1 < 0B= $format =~ /u$/
ABresult
0X0
100
111
6896 0 return 'Must be an unsigned rational';
6897 }
6898 }
6899 202 return 'Not a floating point number';
6900 }
6901 1133 ▶ if ($format =~ /^rational\d+u$/ and $val < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /^rational\d+u$/ and $val < 0) 0 1133 1133
Condition66%2/3
$format =~ /^rational\d+u$/ and $val < 0
!ll&&!rl&&r
5575760
MC/DC0%0/2
$format =~ /^rational\d+u$/ and $val < 0
$format =~ /^rational\d+u$/ $val < 0
Truth table66%2/3
A and B
A= $format =~ /^rational\d+u$/B= $val < 0
ABresult
0X0
100
111
6902 0 return 'Must be a positive number';
6903 }
6904 }
6905 }
6906 13690 return undef; # success!
6907 }
6908  
6909 #------------------------------------------------------------------------------
6910 # check new value for binary data block
6911 # Inputs: 0) ExifTool object ref, 1) tagInfo hash ref, 2) raw value ref
6912 # Returns: error string or undef (and may modify value) on success
6913 sub CheckBinaryData($$$)
6914 12532 ▶{
Subroutine CheckBinaryData: called CC=6 SCAR=17.9
Pod undocumented
6915 12532 my ($self, $tagInfo, $valPtr) = @_;
6916 12532 my $format = $$tagInfo{Format};
6917 12532 ▶ unless ($format) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($format) 4712 7820 12532
6918 4712 my $table = $$tagInfo{Table};
6919 4712 ▶ if ($table and $$table{FORMAT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table and $table->{'FORMAT'}) { } 3341 1371 4712
Condition66%2/3
$table and $table->{"FORMAT"}
!ll&&!rl&&r
013713341
MC/DC50%1/2
$table and $table->{"FORMAT"}
$table $table->{"FORMAT"}
Truth table66%2/3
A and B
A= $tableB= $table->{"FORMAT"}
ABresult
0X0
100
111
6920 3341 $format = $$table{FORMAT};
6921 } else {
6922 # use default 'int8u' unless specified
6923 1371 $format = 'int8u';
6924 }
6925 }
6926 12532 my $count;
6927 12532 ▶ if ($format =~ /(.*)\[(.*)\]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /(.*)\[(.*)\]/) 1888 10644 12532
6928 1888 $format = $1;
6929 1888 $count = $2;
6930 # can't evaluate $count now because we don't know $size yet
6931 1888 ▶ $count = -1 if $count =~ /\$size/; # (-1 = any count allowed)
Branch: 1 branch
BranchTrueFalseTotal
if $count =~ /\$size/ 3 1885 1888
6932 }
6933 12532 return CheckValue($valPtr, $format, $count);
6934 }
6935  
6936 #------------------------------------------------------------------------------
6937 # Rename a file (with patch for Windows Unicode file names, and other problem)
6938 # Inputs: 0) ExifTool ref, 1) old name, 2) new name
6939 # Returns: true on success
6940 sub Rename($$$)
6941 3 ▶{
Subroutine Rename: called CC=8 SCAR=31.0
Pod undocumented
6942 3 my ($self, $old, $new) = @_;
6943 3 my ($result, $try, $winUni);
6944  
6945 3 ▶ if ($self->EncodeFileName($old)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->EncodeFileName($old)) { } 0 3 3
elsif ($self->EncodeFileName($new)) { } 0 3 3
6946 0 $self->EncodeFileName($new, 1);
6947 0 $winUni = 1;
6948 } elsif ($self->EncodeFileName($new)) {
6949 0 $old = $_[1];
6950 0 $self->EncodeFileName($old, 1);
6951 0 $winUni = 1;
6952 }
6953 3 for (;;) {
6954 3 ▶ if ($winUni) {
Branch: 1 branch
BranchTrueFalseTotal
if ($winUni) { } 0 3 3
6955 0 $result = eval { Win32API::File::MoveFileExW($old, $new,
6956 Win32API::File::MOVEFILE_REPLACE_EXISTING() |
6957 Win32API::File::MOVEFILE_COPY_ALLOWED()) };
6958 } else {
6959 3 $result = rename($old, $new);
6960 }
6961 3 ▶ last if $result or $^O ne 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $result or $^O ne "MSWin32" 3 0 3
Condition33%1/3
$result or $^O ne "MSWin32"
l!l&&r!l&&!r
300
MC/DC0%0/2
$result or $^O ne "MSWin32"
$result $^O ne "MSWin32"
Truth table33%1/3
A or B
A= $resultB= $^O ne "MSWin32"
ABresult
1X1
011
000
6962 # keep trying for up to 0.5 seconds
6963 # (patch for Windows denial-of-service susceptibility)
6964 0 ▶ $try = ($try || 1) + 1;
Condition0%0/2
$try || 1
l!l
00
MC/DC0%0/1
$try || 1
$try
Truth table0%0/2
A
A= $try
Aresult
11
00
6965 0 ▶ last if $try > 50;
Branch: 1 branch
BranchTrueFalseTotal
if $try > 50 0 0 0
6966 0 select(undef,undef,undef,0.01); # sleep for 0.01 sec
6967 }
6968 3 return $result;
6969 }
6970  
6971 #------------------------------------------------------------------------------
6972 # Delete a file (with patch for Windows Unicode file names)
6973 # Inputs: 0) ExifTool ref, 1-N) names of files to delete
6974 # Returns: number of files deleted
6975 sub Unlink($@)
6976 0 ▶{
Subroutine Unlink: not called CC=5 SCAR=34.0
Pod undocumented
6977 0 my $self = shift;
6978 0 my $result = 0;
6979 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
6980 0 my $file = shift;
6981 0 ▶ if ($self->EncodeFileName($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->EncodeFileName($file)) { } 0 0 0
6982 0 ▶ ++$result if eval { Win32API::File::DeleteFileW($file) };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { Win32API::File::DeleteFileW($file) } } 0 0 0
6983 } else {
6984 0 ▶ ++$result if unlink $file;
Branch: 1 branch
BranchTrueFalseTotal
if unlink $file 0 0 0
6985 }
6986 }
6987 0 return $result;
6988 }
6989  
6990 #------------------------------------------------------------------------------
6991 # Set file times (Unix seconds since the epoch)
6992 # Inputs: 0) ExifTool ref, 1) file name or ref, 2) access time, 3) modification time,
6993 # 4) inode change or creation time (or undef for any time to avoid setting)
6994 # 5) flag to suppress warning
6995 # Returns: 1 on success, 0 on error
6996 61 my $k32SetFileTime;
6997 sub SetFileTime($$;$$$$)
6998 0 ▶{
Subroutine SetFileTime: not called CC=29 SCAR=67.7
Pod undocumented
6999 0 my ($self, $file, $atime, $mtime, $ctime, $noWarn) = @_;
7000 0 my $saveFile;
7001 0 local *FH;
7002  
7003 # open file by name if necessary
7004 0 ▶ unless (ref $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $file) 0 0 0
7005 # (file will be automatically closed when *FH goes out of scope)
7006 0 ▶ unless ($self->Open(\*FH, $file, '+<')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->Open(\*FH, $file, "+<")) 0 0 0
7007 0 my $success;
7008 0 ▶ if (defined $atime or defined $mtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $atime or defined $mtime) 0 0 0
Condition0%0/3
defined $atime or defined $mtime
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $atime or defined $mtime
defined $atime defined $mtime
Truth table0%0/3
A or B
A= defined $atimeB= defined $mtime
ABresult
1X1
011
000
7009 0 my ($a, $m, $c) = $self->GetFileTime($file);
7010 0 ▶ $atime = $a unless defined $atime;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $atime 0 0 0
7011 0 ▶ $mtime = $m unless defined $mtime;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mtime 0 0 0
7012 0 ▶ $success = eval { utime($atime, $mtime, $file) } if defined $atime and defined $mtime;
Branch: 1 branch
BranchTrueFalseTotal
if defined $atime and defined $mtime 0 0 0
Condition0%0/3
defined $atime and defined $mtime
!ll&&!rl&&r
000
MC/DC0%0/2
defined $atime and defined $mtime
defined $atime defined $mtime
Truth table0%0/3
A and B
A= defined $atimeB= defined $mtime
ABresult
0X0
100
111
7013 }
7014 0 ▶ $self->Warn('Error updating file time') unless $success;
Branch: 1 branch
BranchTrueFalseTotal
unless $success 0 0 0
7015 0 return $success;
7016 }
7017 0 $saveFile = $file;
7018 0 $file = \*FH;
7019 }
7020 # on Windows, try to work around incorrect file times when daylight saving time is in effect
7021 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
7022 0 ▶ if (not eval { require Win32::API }) {
Branch: 2 branches
BranchTrueFalseTotal
if (not eval { do { require Win32::API } }) { } 0 0 0
elsif (not eval { do { require Win32API::File } }) { } 0 0 0
7023 0 $self->Warn('Install Win32::API for proper handling of Windows file times');
7024 0 } elsif (not eval { require Win32API::File }) {
7025 0 $self->Warn('Install Win32API::File for proper handling of Windows file times');
7026 } else {
7027 # get Win32 handle, needed for SetFileTime
7028 0 my $win32Handle = eval { Win32API::File::GetOsFHandle($file) };
7029 0 ▶ unless ($win32Handle) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($win32Handle) 0 0 0
7030 0 $self->Warn('Win32API::File GetOsFHandle returned invalid handle');
7031 0 return 0;
7032 }
7033 # convert Unix seconds to FILETIME structs
7034 0 my $time;
7035 0 foreach $time ($atime, $mtime, $ctime) {
7036 # set to NULL if not defined (i.e. do not change)
7037 0 ▶ defined $time or $time = 0, next;
Branch: 1 branch
BranchTrueFalseTotal
defined $time or $time = 0, next 0 0 0
7038 # convert to 100 ns intervals since 0:00 UTC Jan 1, 1601
7039 # (89 leap years between 1601 and 1970)
7040 0 my $wt = ($time + (((1970-1601)*365+89)*24*3600)) * 1e7;
7041 0 my $hi = int($wt / 4294967296);
7042 0 $time = pack 'LL', int($wt - $hi * 4294967296), $hi; # pack FILETIME struct
7043 }
7044 0 ▶ unless ($k32SetFileTime) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($k32SetFileTime) 0 0 0
7045 0 ▶ return 0 if defined $k32SetFileTime;
Branch: 1 branch
BranchTrueFalseTotal
if defined $k32SetFileTime 0 0 0
7046 0 $k32SetFileTime = Win32::API->new('KERNEL32', 'SetFileTime', 'NPPP', 'I');
7047 0 ▶ unless ($k32SetFileTime) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($k32SetFileTime) 0 0 0
7048 0 $self->Warn('Error loading Win32::API SetFileTime');
7049 0 $k32SetFileTime = 0;
7050 0 return 0;
7051 }
7052 }
7053 0 ▶ unless ($k32SetFileTime->Call($win32Handle, $ctime, $atime, $mtime)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($k32SetFileTime->Call($win32Handle, $ctime, $atime, $mtime)) 0 0 0
7054 0 $self->Warn('Win32::API SetFileTime returned ' . Win32::GetLastError());
7055 0 return 0;
7056 }
7057 0 return 1;
7058 }
7059 }
7060 # other OS (or Windows fallback)
7061 0 ▶ if (defined $atime and defined $mtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $atime and defined $mtime) 0 0 0
Condition0%0/3
defined $atime and defined $mtime
!ll&&!rl&&r
000
MC/DC0%0/2
defined $atime and defined $mtime
defined $atime defined $mtime
Truth table0%0/3
A and B
A= defined $atimeB= defined $mtime
ABresult
0X0
100
111
7062 0 my $success;
7063 0 local $SIG{'__WARN__'} = \&SetWarning; # (this may not be necessary)
7064 0 for (;;) {
7065 0 undef $evalWarning;
7066 # (this may fail on the first try if futimes is not implemented)
7067 0 $success = eval { utime($atime, $mtime, $file) };
7068 0 ▶ last if $success or not defined $saveFile;
Branch: 1 branch
BranchTrueFalseTotal
if $success or not defined $saveFile 0 0 0
Condition0%0/3
$success or not defined $saveFile
l!l&&r!l&&!r
000
MC/DC0%0/2
$success or not defined $saveFile
$success not defined $saveFile
Truth table0%0/3
A or not(B)
A= $successB= not defined $saveFile
ABresult
1X1
011
000
7069 0 close $file;
7070 0 $file = $saveFile;
7071 0 undef $saveFile;
7072 }
7073 0 ▶ unless ($noWarn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($noWarn) 0 0 0
7074 0 ▶ if ($@ or $evalWarning) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@ or $Image::ExifTool::evalWarning) { } 0 0 0
elsif (not $success) { } 0 0 0
Condition0%0/3
$@ or $Image::ExifTool::evalWarning
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or $Image::ExifTool::evalWarning
$@ $Image::ExifTool::evalWarning
Truth table0%0/3
A or B
A= $@B= $Image::ExifTool::evalWarning
ABresult
1X1
011
000
7075 0 ▶ $self->Warn(CleanWarning($@ || $evalWarning));
Condition0%0/3
$@ || $Image::ExifTool::evalWarning
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $Image::ExifTool::evalWarning
$@ $Image::ExifTool::evalWarning
Truth table0%0/3
A || B
A= $@B= $Image::ExifTool::evalWarning
ABresult
1X1
011
000
7076 } elsif (not $success) {
7077 0 $self->Warn('Error setting file time');
7078 }
7079 }
7080 0 return $success;
7081 }
7082 0 return 1; # (nothing to do)
7083 }
7084  
7085 #------------------------------------------------------------------------------
7086 # Add data to hash checksum
7087 # Inputs: 0) ExifTool ref, 1) RAF ref, 2) data size (or undef to read to end of file),
7088 # 3) data name (or undef for no warnings or messages), 4) flag for no verbose message
7089 # Returns: number of bytes read and hashed
7090 sub ImageDataHash($$$;$$)
7091 1 ▶{
Subroutine ImageDataHash: called CC=12 SCAR=48.5
Pod undocumented
7092 1 my ($self, $raf, $size, $type, $noMsg) = @_;
7093 1 ▶ my $hash = $$self{ImageDataHash} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $hash = $self->{"ImageDataHash"} or return 0 1 1
7094 0 my ($bytesRead, $n) = (0, 65536);
7095 0 my $buff;
7096 0 for (;;) {
7097 0 ▶ if (defined $size) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $size) 0 0 0
7098 0 ▶ last unless $size;
Branch: 1 branch
BranchTrueFalseTotal
unless $size 0 0 0
7099 0 ▶ $n = $size > 65536 ? 65536 : $size;
Branch: 1 branch
BranchTrueFalseTotal
$size > 65536 ? : 0 0 0
7100 0 $size -= $n;
7101 }
7102 0 ▶ unless ($raf->Read($buff, $n)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Read($buff, $n)) 0 0 0
7103 0 ▶ $self->Warn("Error reading $type data") if $type and defined $size;
Branch: 1 branch
BranchTrueFalseTotal
if $type and defined $size 0 0 0
Condition0%0/3
$type and defined $size
!ll&&!rl&&r
000
MC/DC0%0/2
$type and defined $size
$type defined $size
Truth table0%0/3
A and B
A= $typeB= defined $size
ABresult
0X0
100
111
7104 0 last;
7105 }
7106 0 $hash->add($buff);
7107 0 $bytesRead += length $buff;
7108 }
7109 0 ▶ if ($$self{OPTIONS}{Verbose} and $bytesRead and $type and not $noMsg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"OPTIONS"}{"Verbose"} and $bytesRead and $type and not $noMsg) 0 0 0
Condition0%0/9
$self->{"OPTIONS"}{"Verbose"} and $bytesRead and $type and not $noMsg
!ll&&!rl&&r
000
$self->{"OPTIONS"}{"Verbose"} and $bytesRead and $type
!ll&&!rl&&r
000
$self->{"OPTIONS"}{"Verbose"} and $bytesRead
!ll&&!rl&&r
000
MC/DC0%0/4
$self->{"OPTIONS"}{"Verbose"} and $bytesRead and $type and not $noMsg
$self->{"OPTIONS"}{"Verbose"} $bytesRead $type not $noMsg
Truth table0%0/5
A and B and C and not(D)
A= $self->{"OPTIONS"}{"Verbose"}B= $bytesReadC= $typeD= not $noMsg
ABCDresult
0XXX0
10XX0
110X0
11100
11111
7110 0 $self->VPrint(0, "$$self{INDENT}(ImageDataHash: $bytesRead bytes of $type data)\n");
7111 }
7112 0 return $bytesRead;
7113 }
7114  
7115 #------------------------------------------------------------------------------
7116 # Copy data block from RAF to output file in max 64kB chunks
7117 # Inputs: 0) RAF ref, 1) outfile ref, 2) block size
7118 # Returns: 1 on success, 0 on read error, undef on write error
7119 sub CopyBlock($$$)
7120 74 ▶{
Subroutine CopyBlock: called CC=5 SCAR=16.4
Pod undocumented
7121 74 my ($raf, $outfile, $size) = @_;
7122 74 my $buff;
7123 74 for (;;) {
7124 127 ▶ last unless $size > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $size > 0 74 53 127
7125 53 ▶ my $n = $size > 65536 ? 65536 : $size;
Branch: 1 branch
BranchTrueFalseTotal
$size > 65536 ? : 0 53 53
7126 53 ▶ $raf->Read($buff, $n) == $n or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $n) == $n or return 0 53 0 53
7127 53 ▶ Write($outfile, $buff) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $buff) or return undef 53 0 53
7128 53 $size -= $n;
7129 }
7130 74 return 1;
7131 }
7132  
7133 #------------------------------------------------------------------------------
7134 # Copy image data from one file to another
7135 # Inputs: 0) ExifTool object reference
7136 # 1) reference to list of image data [ position, size, pad bytes ]
7137 # 2) output file ref
7138 # Returns: true on success
7139 sub CopyImageData($$$)
7140 13 ▶{
Subroutine CopyImageData: called CC=10 SCAR=26.2
Pod undocumented
7141 13 my ($self, $imageDataBlocks, $outfile) = @_;
7142 13 my $raf = $$self{RAF};
7143 13 my ($dataBlock, $err);
7144 13 my $num = @$imageDataBlocks;
7145 13 ▶ $self->VPrint(0, " Copying $num image data blocks\n") if $num;
Branch: 1 branch
BranchTrueFalseTotal
if $num 13 0 13
7146 13 foreach $dataBlock (@$imageDataBlocks) {
7147 24 my ($pos, $size, $pad) = @$dataBlock;
7148 24 ▶ $raf->Seek($pos, 0) or $err = 'read', last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($pos, 0) or $err = "read", last 24 0 24
7149 24 my $result = CopyBlock($raf, $outfile, $size);
7150 24 ▶ $result or $err = defined $result ? 'read' : 'writ';
Branch: 2 branches
BranchTrueFalseTotal
$result or $err = defined $result ? "read" : "writ" 24 0 24
defined $result ? : 0 0 0
7151 # pad if necessary
7152 24 ▶ Write($outfile, "\0" x $pad) or $err = 'writ' if $pad;
Branch: 1 branch
BranchTrueFalseTotal
if $pad 3 21 24
Condition50%3/6
$pad && (&Write($outfile, scalar "\000" x $pad) || ($err = 'writ'))
!ll&&!rl&&r
2130
&Write($outfile, scalar "\0" x $pad) or $err = "writ"
l!l&&r!l&&!r
300
MC/DC0%0/3
$pad && (&Write($outfile, scalar "\000" x $pad) || ($err = 'writ'))
$pad &Write($outfile, scalar "\0" x $pad) $err = "writ"
Truth table0%0/4
A && B or C
A= $padB= &Write($outfile, scalar "\0" x $pad)C= $err = "writ"
ABCresult
0XX0
1000
11X1
1011
7153 24 ▶ last if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 24 24
7154 }
7155 13 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 13 13
7156 0 $self->Error("Error ${err}ing image data");
7157 0 return 0;
7158 }
7159 13 return 1;
7160 }
7161  
7162 #------------------------------------------------------------------------------
7163 # Write to binary data block
7164 # Inputs: 0) ExifTool object ref, 1) source dirInfo ref, 2) tag table ref
7165 # Returns: Binary data block or undefined on error
7166 sub WriteBinaryData($$$)
7167 16513 ▶{
Subroutine WriteBinaryData: called CC=82 SCAR=66.8
Pod undocumented
7168 16513 my ($self, $dirInfo, $tagTablePtr) = @_;
7169 16513 ▶ $self or return 1; # allow dummy access to autoload this package
Branch: 1 branch
BranchTrueFalseTotal
$self or return 1 488 16025 16513
7170  
7171 # get default format ('int8u' unless specified)
7172 488 ▶ my $dataPt = $$dirInfo{DataPt} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $dataPt = $dirInfo->{"DataPt"} or return undef 488 0 488
7173 488 my $dataLen = length $$dataPt;
7174 488 ▶ my $defaultFormat = $$tagTablePtr{FORMAT} || 'int8u';
Condition100%2/2
$tagTablePtr->{'FORMAT'} || 'int8u'
l!l
42761
MC/DC100%1/1
$tagTablePtr->{'FORMAT'} || 'int8u'
$tagTablePtr->{'FORMAT'}
Truth table100%2/2
A
A= $tagTablePtr->{'FORMAT'}
Aresult
11
00
7175 488 my $increment = FormatSize($defaultFormat);
7176 488 ▶ unless ($increment) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($increment) 0 488 488
7177 0 warn "Unknown format $defaultFormat\n";
7178 0 return undef;
7179 }
7180 # extract data members first if necessary
7181 488 my @varOffsets;
7182 488 ▶ if ($$tagTablePtr{DATAMEMBER}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagTablePtr->{"DATAMEMBER"}) 220 268 488
7183 220 $$dirInfo{DataMember} = $$tagTablePtr{DATAMEMBER};
7184 220 $$dirInfo{VarFormatData} = \@varOffsets;
7185 220 $self->ProcessBinaryData($dirInfo, $tagTablePtr);
7186 220 delete $$dirInfo{DataMember};
7187 220 delete $$dirInfo{VarFormatData};
7188 }
7189 488 ▶ my $dirStart = $$dirInfo{DirStart} || 0;
Condition100%2/2
$dirInfo->{'DirStart'} || 0
l!l
306182
MC/DC100%1/1
$dirInfo->{'DirStart'} || 0
$dirInfo->{'DirStart'}
Truth table100%2/2
A
A= $dirInfo->{'DirStart'}
Aresult
11
00
7190 488 my $dirLen = $$dirInfo{DirLen};
7191 488 ▶ $dirLen = $dataLen - $dirStart if not defined $dirLen or $dirLen > $dataLen - $dirStart;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $dirLen or $dirLen > $dataLen - $dirStart 1 487 488
Condition66%2/3
not defined $dirLen or $dirLen > $dataLen - $dirStart
l!l&&r!l&&!r
10487
MC/DC50%1/2
not defined $dirLen or $dirLen > $dataLen - $dirStart
not defined $dirLen $dirLen > $dataLen - $dirStart
Truth table66%2/3
not(A) or B
A= not defined $dirLenB= $dirLen > $dataLen - $dirStart
ABresult
1X1
011
000
7192 488 ▶ my $newData = substr($$dataPt, $dirStart, $dirLen) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $newData = substr($$dataPt, $dirStart, $dirLen) or return undef 488 0 488
7193 488 my $dirName = $$dirInfo{DirName};
7194 488 my $varSize = 0;
7195 488 my @varInfo = @varOffsets;
7196 488 my $tagInfo;
7197 488 $dataPt = \$newData;
7198 488 foreach $tagInfo (sort { $$a{TagID} <=> $$b{TagID} } $self->GetNewTagInfoList($tagTablePtr)) {
7199 227 my $tagID = $$tagInfo{TagID};
7200 # evaluate conditional tags now if necessary
7201 227 ▶ if (ref $$tagTablePtr{$tagID} eq 'ARRAY' or $$tagInfo{Condition}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tagTablePtr->{$tagID} eq "ARRAY" or $tagInfo->{"Condition"}) 22 205 227
Condition100%3/3
ref $tagTablePtr->{$tagID} eq "ARRAY" or $tagInfo->{"Condition"}
l!l&&r!l&&!r
175205
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
7202 22 my $writeInfo = $self->GetTagInfo($tagTablePtr, $tagID);
7203 22 ▶ next unless $writeInfo and $writeInfo eq $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
unless $writeInfo and $writeInfo eq $tagInfo 9 13 22
Condition100%3/3
$writeInfo and $writeInfo eq $tagInfo
!ll&&!rl&&r
6313
MC/DC100%2/2
$writeInfo and $writeInfo eq $tagInfo
$writeInfo $writeInfo eq $tagInfo
Truth table100%3/3
A and B
A= $writeInfoB= $writeInfo eq $tagInfo
ABresult
0X0
100
111
7204 }
7205 # add offsets for variable-sized tags if necessary
7206 218 ▶ while (@varInfo and $varInfo[0][0] < $tagID) {
Branch: 1 branch
BranchTrueFalseTotal
if (@varInfo and $varInfo[0][0] < $tagID) 10 218 228
Condition100%3/3
@varInfo and $varInfo[0][0] < $tagID
!ll&&!rl&&r
212610
MC/DC100%2/2
@varInfo and $varInfo[0][0] < $tagID
@varInfo $varInfo[0][0] < $tagID
Truth table100%3/3
A and B
A= @varInfoB= $varInfo[0][0] < $tagID
ABresult
0X0
100
111
7207 10 $varSize = $varInfo[0][1]; # get accumulated variable size
7208 10 shift @varInfo;
7209 }
7210 218 my $count = 1;
7211 218 my $format = $$tagInfo{Format};
7212 218 my $entry = int($tagID) * $increment + $varSize; # relative offset of this entry
7213 218 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) { } 87 131 218
7214 87 ▶ if ($format =~ /(.*)\[(.*)\]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($format =~ /(.*)\[(.*)\]/) { } 36 51 87
elsif ($format eq 'string') { } 1 50 51
7215 36 $format = $1;
7216 36 $count = $2;
7217 36 my $size = $dirLen; # used in eval
7218 # evaluate count to allow count to be based on previous values
7219 #### eval Format size ($size, $self) - NOTE: %val not supported for writing
7220 36 $count = eval $count;
7221 36 ▶ $@ and warn($@), next;
Branch: 1 branch
BranchTrueFalseTotal
$@ and warn($@), next 0 36 36
7222 } elsif ($format eq 'string') {
7223 # string with no specified count runs to end of block
7224 1 ▶ $count = ($dirLen > $entry) ? $dirLen - $entry : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dirLen > $entry ? : 1 0 1
7225 }
7226 } else {
7227 131 $format = $defaultFormat;
7228 }
7229 # read/write using variable format if changed in Hook
7230 218 ▶ $format = $varInfo[0][2] if @varInfo and $varInfo[0][0] == $tagID;
Branch: 1 branch
BranchTrueFalseTotal
if @varInfo and $varInfo[0][0] == $tagID 6 212 218
Condition66%2/3
@varInfo and $varInfo[0][0] == $tagID
!ll&&!rl&&r
21206
MC/DC50%1/2
@varInfo and $varInfo[0][0] == $tagID
@varInfo $varInfo[0][0] == $tagID
Truth table66%2/3
A and B
A= @varInfoB= $varInfo[0][0] == $tagID
ABresult
0X0
100
111
7231 218 my $val = ReadValue($dataPt, $entry, $format, $count, $dirLen-$entry);
7232 218 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 3 215 218
7233 215 my $nvHash = $self->GetNewValueHash($tagInfo, $$self{CUR_WRITE_GROUP});
7234 215 ▶ next unless $self->IsOverwriting($nvHash, $val) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->IsOverwriting($nvHash, $val) > 0 1 214 215
7235 214 my $newVal = $self->GetNewValue($nvHash);
7236 214 ▶ next unless defined $newVal; # can't delete from a binary table
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newVal 1 213 214
7237 # update DataMember with new value if necessary
7238 213 ▶ $$self{$$tagInfo{DataMember}} = $newVal if $$tagInfo{DataMember};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"DataMember"} 6 207 213
7239 # only write masked bits if specified
7240 213 my $mask = $$tagInfo{Mask};
7241 213 ▶ $newVal = (($newVal << $$tagInfo{BitShift}) & $mask) | ($val & ~$mask) if $mask;
Branch: 1 branch
BranchTrueFalseTotal
if $mask 3 210 213
7242 # set the size
7243 213 ▶ if ($$tagInfo{DataTag} and not $$tagInfo{IsOffset}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"DataTag"} and not $tagInfo->{"IsOffset"}) 0 213 213
Condition33%1/3
$tagInfo->{"DataTag"} and not $tagInfo->{"IsOffset"}
!ll&&!rl&&r
21300
MC/DC0%0/2
$tagInfo->{"DataTag"} and not $tagInfo->{"IsOffset"}
$tagInfo->{"DataTag"} not $tagInfo->{"IsOffset"}
Truth table33%1/3
A and not(B)
A= $tagInfo->{"DataTag"}B= not $tagInfo->{"IsOffset"}
ABresult
0X0
100
111
7244 0 ▶ warn 'Internal error' unless $newVal == 0xfeedfeed;
Branch: 1 branch
BranchTrueFalseTotal
unless $newVal == 4277010157 0 0 0
7245 0 my $data = $self->GetNewValue($$tagInfo{DataTag});
7246 0 ▶ $newVal = length($data) if defined $data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data 0 0 0
7247 0 ▶ my $format = $$tagInfo{Format} || $$tagTablePtr{FORMAT} || 'int32u';
Condition0%0/5
$tagInfo->{'Format'} || $tagTablePtr->{'FORMAT'} || 'int32u'
l!l
00
$tagInfo->{"Format"} or $tagTablePtr->{"FORMAT"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tagInfo->{'Format'} || $tagTablePtr->{'FORMAT'} || 'int32u'
$tagInfo->{"Format"} $tagTablePtr->{"FORMAT"}
Truth table0%0/3
A or B
A= $tagInfo->{"Format"}B= $tagTablePtr->{"FORMAT"}
ABresult
1X1
011
000
7248 0 ▶ if ($format =~ /^int16/ and $newVal > 0xffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /^int16/ and $newVal > 65535) 0 0 0
Condition0%0/3
$format =~ /^int16/ and $newVal > 65535
!ll&&!rl&&r
000
MC/DC0%0/2
$format =~ /^int16/ and $newVal > 65535
$format =~ /^int16/ $newVal > 65535
Truth table0%0/3
A and B
A= $format =~ /^int16/B= $newVal > 65535
ABresult
0X0
100
111
7249 0 $self->Error("$$tagInfo{DataTag} is too large (64 KiB max. for this file)");
7250 }
7251 }
7252 213 my $rtnVal = WriteValue($newVal, $format, $count, $dataPt, $entry);
7253 213 ▶ if (defined $rtnVal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rtnVal) { } 213 0 213
7254 213 $self->VerboseValue("- $dirName:$$tagInfo{Name}", $val);
7255 213 $self->VerboseValue("+ $dirName:$$tagInfo{Name}", $newVal);
7256 213 ++$$self{CHANGED};
7257 } else {
7258 0 $self->Warn("Error packing $$tagInfo{Name} value");
7259 }
7260 }
7261 # add necessary fixups for any offsets
7262 488 ▶ if ($$tagTablePtr{IS_OFFSET} and $$dirInfo{Fixup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagTablePtr->{"IS_OFFSET"} and $dirInfo->{"Fixup"}) 1 487 488
Condition66%2/3
$tagTablePtr->{"IS_OFFSET"} and $dirInfo->{"Fixup"}
!ll&&!rl&&r
48701
MC/DC50%1/2
$tagTablePtr->{"IS_OFFSET"} and $dirInfo->{"Fixup"}
$tagTablePtr->{"IS_OFFSET"} $dirInfo->{"Fixup"}
Truth table66%2/3
A and B
A= $tagTablePtr->{"IS_OFFSET"}B= $dirInfo->{"Fixup"}
ABresult
0X0
100
111
7263 1 $varSize = 0;
7264 1 @varInfo = @varOffsets;
7265 1 my $fixup = $$dirInfo{Fixup};
7266 1 my $tagID;
7267 1 foreach $tagID (@{$$tagTablePtr{IS_OFFSET}}) {
7268 1 ▶ $tagInfo = $self->GetTagInfo($tagTablePtr, $tagID) or next;
Branch: 1 branch
BranchTrueFalseTotal
$tagInfo = $self->GetTagInfo($tagTablePtr, $tagID) or next 1 0 1
7269 1 ▶ while (@varInfo and $varInfo[0][0] < $tagID) {
Branch: 1 branch
BranchTrueFalseTotal
if (@varInfo and $varInfo[0][0] < $tagID) 0 1 1
Condition33%1/3
@varInfo and $varInfo[0][0] < $tagID
!ll&&!rl&&r
100
MC/DC0%0/2
@varInfo and $varInfo[0][0] < $tagID
@varInfo $varInfo[0][0] < $tagID
Truth table33%1/3
A and B
A= @varInfoB= $varInfo[0][0] < $tagID
ABresult
0X0
100
111
7270 0 $varSize = $varInfo[0][1];
7271 0 shift @varInfo;
7272 }
7273 1 my $entry = $tagID * $increment + $varSize; # (no offset to dirStart for new dir data)
7274 1 ▶ next unless $entry <= $dirLen - 4;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry <= $dirLen - 4 1 0 1
7275 # (Ricoh has 16-bit preview image offsets, so can't just assume int32u)
7276 0 ▶ my $format = $$tagInfo{Format} || $$tagTablePtr{FORMAT} || 'int32u';
Condition0%0/5
$tagInfo->{'Format'} || $tagTablePtr->{'FORMAT'} || 'int32u'
l!l
00
$tagInfo->{"Format"} or $tagTablePtr->{"FORMAT"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tagInfo->{'Format'} || $tagTablePtr->{'FORMAT'} || 'int32u'
$tagInfo->{"Format"} $tagTablePtr->{"FORMAT"}
Truth table0%0/3
A or B
A= $tagInfo->{"Format"}B= $tagTablePtr->{"FORMAT"}
ABresult
1X1
011
000
7277 0 my $offset = ReadValue($dataPt, $entry, $format, 1, $dirLen-$entry);
7278 # ignore if offset is zero (eg. Ricoh DNG uses this to indicate no preview)
7279 0 ▶ next unless $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless $offset 0 0 0
7280 0 $fixup->AddFixup($entry, $$tagInfo{DataTag}, $format);
7281 0 ▶ next unless $$tagInfo{DataTag} and defined $$tagInfo{OffsetPair};
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo->{"DataTag"} and defined $tagInfo->{"OffsetPair"} 0 0 0
Condition0%0/3
$tagInfo->{"DataTag"} and defined $tagInfo->{"OffsetPair"}
!ll&&!rl&&r
000
MC/DC0%0/2
$tagInfo->{"DataTag"} and defined $tagInfo->{"OffsetPair"}
$tagInfo->{"DataTag"} defined $tagInfo->{"OffsetPair"}
Truth table0%0/3
A and B
A= $tagInfo->{"DataTag"}B= defined $tagInfo->{"OffsetPair"}
ABresult
0X0
100
111
7282 # NOTE: here we assume there are no var-sized tags between the
7283 # OffsetPair tags. If this ever becomes possible we must recalculate
7284 # $varSize for the OffsetPair tag here!
7285 0 $entry = $$tagInfo{OffsetPair} * $increment + $varSize;
7286 0 my $size = ReadValue($dataPt, $entry, $format, 1, $dirLen-$entry);
7287 0 ▶ next unless defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 0 0 0
7288 0 ▶ if ($$tagInfo{DataTag} eq 'HiddenData') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"DataTag"} eq "HiddenData") 0 0 0
7289 $$self{HiddenData} = {
7290 Offset => $offset,
7291 Size => $size,
7292 Fixup => Image::ExifTool::Fixup->new,
7293 Base => $$dirInfo{Base},
7294 0 };
7295 0 next;
7296 }
7297 # handle the preview image now if this is a JPEG file
7298 0 ▶ next unless $$tagInfo{DataTag} eq 'PreviewImage' and $$self{FILE_TYPE} eq 'JPEG';
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo->{"DataTag"} eq "PreviewImage" and $self->{"FILE_TYPE"} eq "JPEG" 0 0 0
Condition0%0/3
$tagInfo->{"DataTag"} eq "PreviewImage" and $self->{"FILE_TYPE"} eq "JPEG"
!ll&&!rl&&r
000
MC/DC0%0/2
$tagInfo->{"DataTag"} eq "PreviewImage" and $self->{"FILE_TYPE"} eq "JPEG"
$tagInfo->{"DataTag"} eq "PreviewImage" $self->{"FILE_TYPE"} eq "JPEG"
Truth table0%0/3
A and B
A= $tagInfo->{"DataTag"} eq "PreviewImage"B= $self->{"FILE_TYPE"} eq "JPEG"
ABresult
0X0
100
111
7299 0 my $previewInfo = $$self{PREVIEW_INFO};
7300 $previewInfo or $previewInfo = $$self{PREVIEW_INFO} = {
7301 0 ▶ Fixup => Image::ExifTool::Fixup->new,
Branch: 1 branch
BranchTrueFalseTotal
$previewInfo or $previewInfo = ($self->{"PREVIEW_INFO"} = {"Fixup", "Image::ExifTool::Fixup"->new}) 0 0 0
7302 };
7303 # set flag indicating we are using short pointers
7304 0 ▶ $$previewInfo{IsShort} = 1 unless $format eq 'int32u';
Branch: 1 branch
BranchTrueFalseTotal
unless $format eq "int32u" 0 0 0
7305 0 ▶ $$previewInfo{Absolute} = 1 if $$tagInfo{IsOffset} and $$tagInfo{IsOffset} eq '3';
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"IsOffset"} and $tagInfo->{"IsOffset"} eq 3 0 0 0
Condition0%0/3
$tagInfo->{"IsOffset"} and $tagInfo->{"IsOffset"} eq 3
!ll&&!rl&&r
000
MC/DC0%0/2
$tagInfo->{"IsOffset"} and $tagInfo->{"IsOffset"} eq 3
$tagInfo->{"IsOffset"} $tagInfo->{"IsOffset"} eq 3
Truth table0%0/3
A and B
A= $tagInfo->{"IsOffset"}B= $tagInfo->{"IsOffset"} eq 3
ABresult
0X0
100
111
7306 # get the value of the Composite::PreviewImage tag
7307 0 $$previewInfo{Data} = $self->GetNewValue(GetCompositeTagInfo('PreviewImage'));
7308 0 ▶ unless (defined $$previewInfo{Data}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $previewInfo->{"Data"}) 0 0 0
7309 0 ▶ if ($offset >= 0 and $offset + $size <= $$dirInfo{DataLen}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= 0 and $offset + $size <= $dirInfo->{'DataLen'}) { } 0 0 0
Condition0%0/3
$offset >= 0 and $offset + $size <= $dirInfo->{"DataLen"}
!ll&&!rl&&r
000
MC/DC0%0/2
$offset >= 0 and $offset + $size <= $dirInfo->{"DataLen"}
$offset >= 0 $offset + $size <= $dirInfo->{"DataLen"}
Truth table0%0/3
A and B
A= $offset >= 0B= $offset + $size <= $dirInfo->{"DataLen"}
ABresult
0X0
100
111
7310 0 $$previewInfo{Data} = substr(${$$dirInfo{DataPt}},$offset,$size);
7311 } else {
7312 0 $$previewInfo{Data} = 'LOAD_PREVIEW'; # flag to load preview later
7313 }
7314 }
7315 }
7316 }
7317 # write any necessary SubDirectories
7318 488 ▶ if ($$tagTablePtr{IS_SUBDIR}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagTablePtr->{"IS_SUBDIR"}) 12 476 488
7319 12 $varSize = 0;
7320 12 @varInfo = @varOffsets;
7321 12 my $tagID;
7322 12 foreach $tagID (@{$$tagTablePtr{IS_SUBDIR}}) {
7323 13 my $tagInfo = $self->GetTagInfo($tagTablePtr, $tagID);
7324 13 ▶ next unless defined $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tagInfo 4 9 13
7325 9 ▶ while (@varInfo and $varInfo[0][0] < $tagID) {
Branch: 1 branch
BranchTrueFalseTotal
if (@varInfo and $varInfo[0][0] < $tagID) 0 9 9
Condition33%1/3
@varInfo and $varInfo[0][0] < $tagID
!ll&&!rl&&r
900
MC/DC0%0/2
@varInfo and $varInfo[0][0] < $tagID
@varInfo $varInfo[0][0] < $tagID
Truth table33%1/3
A and B
A= @varInfoB= $varInfo[0][0] < $tagID
ABresult
0X0
100
111
7326 0 $varSize = $varInfo[0][1];
7327 0 shift @varInfo;
7328 }
7329 9 my $entry = int($tagID) * $increment + $varSize;
7330 9 ▶ last if $entry >= $dirLen;
Branch: 1 branch
BranchTrueFalseTotal
if $entry >= $dirLen 0 9 9
7331 # get value for Condition if necessary
7332 9 ▶ unless ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagInfo) 0 9 9
7333 0 my $more = $dirLen - $entry;
7334 0 ▶ $more = 128 if $more > 128;
Branch: 1 branch
BranchTrueFalseTotal
if $more > 128 0 0 0
7335 0 my $v = substr($newData, $entry, $more);
7336 0 $tagInfo = $self->GetTagInfo($tagTablePtr, $tagID, \$v);
7337 0 ▶ next unless $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo 0 0 0
7338 }
7339 9 ▶ my $subdir = $$tagInfo{SubDirectory} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $subdir = $tagInfo->{"SubDirectory"} or next 9 0 9
7340 9 my $start = $$subdir{Start};
7341 9 my $len;
7342 9 ▶ if (not $start) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $start) { } 9 0 9
elsif ($start =~ /\$/) { } 0 0 0
7343 9 $start = $entry;
7344 9 $len = $dirLen - $start;
7345 } elsif ($start =~ /\$/) {
7346 0 my $count = 1;
7347 0 ▶ my $format = $$tagInfo{Format} || $defaultFormat;
Condition0%0/3
$tagInfo->{'Format'} || $defaultFormat
l!l&&r!l&&!r
000
MC/DC0%0/2
$tagInfo->{'Format'} || $defaultFormat
$tagInfo->{'Format'} $defaultFormat
Truth table0%0/3
A || B
A= $tagInfo->{'Format'}B= $defaultFormat
ABresult
1X1
011
000
7348 0 ▶ $format =~ /(.*)\[(.*)\]/ and ($format, $count) = ($1, $2);
Branch: 1 branch
BranchTrueFalseTotal
$format =~ /(.*)\[(.*)\]/ and ($format, $count) = ($1, $2) 0 0 0
7349 0 my $val = ReadValue($dataPt, $entry, $format, $count, $dirLen - $entry);
7350 # ignore directories with a zero offset (ie. missing Nikon ShotInfo entries)
7351 0 ▶ next unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
7352 0 my $dirStart = 0;
7353 #### eval Start ($val, $dirStart)
7354 0 $start = eval($start);
7355 0 ▶ next if $start < $dirStart or $start > $dataLen;
Branch: 1 branch
BranchTrueFalseTotal
if $start < $dirStart or $start > $dataLen 0 0 0
Condition0%0/3
$start < $dirStart or $start > $dataLen
l!l&&r!l&&!r
000
MC/DC0%0/2
$start < $dirStart or $start > $dataLen
$start < $dirStart $start > $dataLen
Truth table0%0/3
A or B
A= $start < $dirStartB= $start > $dataLen
ABresult
1X1
011
000
7356 0 $len = $$subdir{DirLen};
7357 0 ▶ $len = $dataLen - $start unless $len and $len <= $dataLen - $start;
Branch: 1 branch
BranchTrueFalseTotal
unless $len and $len <= $dataLen - $start 0 0 0
Condition0%0/3
$len and $len <= $dataLen - $start
!ll&&!rl&&r
000
MC/DC0%0/2
$len and $len <= $dataLen - $start
$len $len <= $dataLen - $start
Truth table0%0/3
A and B
A= $lenB= $len <= $dataLen - $start
ABresult
0X0
100
111
7358 }
7359 9 my %subdirInfo = (
7360 DataPt => \$newData,
7361 DirStart => $start,
7362 DirLen => $len,
7363 TagInfo => $tagInfo,
7364 );
7365 9 my $dat = $self->WriteDirectory(\%subdirInfo, GetTagTable($$subdir{TagTable}));
7366 9 ▶ substr($newData, $start, $len) = $dat if defined $dat and length $dat;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dat and length $dat 9 0 9
Condition33%1/3
defined $dat and length $dat
!ll&&!rl&&r
009
MC/DC0%0/2
defined $dat and length $dat
defined $dat length $dat
Truth table33%1/3
A and B
A= defined $datB= length $dat
ABresult
0X0
100
111
7367 }
7368 }
7369 488 return $newData;
7370 }
7371  
7372 #------------------------------------------------------------------------------
7373 # Write TIFF as a directory
7374 # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
7375 # Returns: New directory data or undefined on error
7376 sub WriteTIFF($$$)
7377 113 ▶{
Subroutine WriteTIFF: called CC=3 SCAR=11.8
Pod undocumented
7378 113 my ($self, $dirInfo, $tagTablePtr) = @_;
7379 113 ▶ $self or return 1; # allow dummy access
Branch: 1 branch
BranchTrueFalseTotal
$self or return 1 113 0 113
7380 113 my $buff = '';
7381 113 $$dirInfo{OutFile} = \$buff;
7382 113 ▶ return $buff if $self->ProcessTIFF($dirInfo, $tagTablePtr) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ProcessTIFF($dirInfo, $tagTablePtr) > 0 113 0 113
7383 0 return undef;
7384 }
7385  
7386 61 1; # end
7387  
7388 __END__
« Image/ExifTool/QuickTime.pm ↑ Summary Image/ExifTool/GIF.pm »