Image/ExifTool/MIE.pm

filter: Statementstmt 69.5% 458 / 659 Branchbran 49.2% 254 / 516 Conditioncond 38.1% 85 / 223 MC/DCmcdc 14.5% 19 / 131 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 9 totaltotal 53.4% 829 / 1552 CC 340 SCAR 74.4
CC
340
Cov
57%
WriteMIEGroup
3285.1
ProcessMIEGroup
332.7
UpdateMieMap
297.9
CRAP 1695.8
« Image/ExifTool/M2TS.pm ↑ Summary Image/ExifTool/DICOM.pm »
1 #------------------------------------------------------------------------------
2 # File: MIE.pm
3 #
4 # Description: Read/write MIE meta information
5 #
6 # Revisions: 11/18/2005 - P. Harvey Created
7 #------------------------------------------------------------------------------
8  
9 package Image::ExifTool::MIE;
10  
11 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 39 ▶use vars qw($VERSION %tableDefaults);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 39 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 ▶use Image::ExifTool::Exif;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 39 ▶use Image::ExifTool::GPS;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 39 $VERSION = '1.57';
18  
19 sub ProcessMIE($$);
20 sub ProcessMIEGroup($$$);
21 sub WriteMIEGroup($$$);
22 sub CheckMIE($$$);
23 sub GetLangInfo($$);
24  
25 # local variables
26 39 my $hasZlib; # 1=Zlib available, 0=no Zlib
27 my %mieCode; # reverse lookup for MIE format names
28 39 my $doneMieMap; # flag indicating we added user-defined groups to %mieMap
29  
30 # MIE format codes
31 39 my %mieFormat = (
32 0x00 => 'undef',
33 0x10 => 'MIE',
34 0x18 => 'MIE',
35 0x20 => 'string', # ASCII (ISO 8859-1)
36 0x28 => 'utf8',
37 0x29 => 'utf16',
38 0x2a => 'utf32',
39 0x30 => 'string_list',
40 0x38 => 'utf8_list',
41 0x39 => 'utf16_list',
42 0x3a => 'utf32_list',
43 0x40 => 'int8u',
44 0x41 => 'int16u',
45 0x42 => 'int32u',
46 0x43 => 'int64u',
47 0x48 => 'int8s',
48 0x49 => 'int16s',
49 0x4a => 'int32s',
50 0x4b => 'int64s',
51 0x52 => 'rational32u',
52 0x53 => 'rational64u',
53 0x5a => 'rational32s',
54 0x5b => 'rational64s',
55 0x61 => 'fixed16u',
56 0x62 => 'fixed32u',
57 0x69 => 'fixed16s',
58 0x6a => 'fixed32s',
59 0x72 => 'float',
60 0x73 => 'double',
61 0x80 => 'free',
62 );
63  
64 # map of MIE directory locations
65 39 my %mieMap = (
66 'MIE-Meta' => 'MIE',
67 'MIE-Audio' => 'MIE-Meta',
68 'MIE-Camera' => 'MIE-Meta',
69 'MIE-Doc' => 'MIE-Meta',
70 'MIE-Geo' => 'MIE-Meta',
71 'MIE-Image' => 'MIE-Meta',
72 'MIE-MakerNotes' => 'MIE-Meta',
73 'MIE-Preview' => 'MIE-Meta',
74 'MIE-Thumbnail' => 'MIE-Meta',
75 'MIE-Video' => 'MIE-Meta',
76 'MIE-Flash' => 'MIE-Camera',
77 'MIE-Lens' => 'MIE-Camera',
78 'MIE-Orient' => 'MIE-Camera',
79 'MIE-Extender' => 'MIE-Lens',
80 'MIE-GPS' => 'MIE-Geo',
81 'MIE-UTM' => 'MIE-Geo',
82 'MIE-Canon' => 'MIE-MakerNotes',
83 EXIF => 'MIE-Meta',
84 XMP => 'MIE-Meta',
85 IPTC => 'MIE-Meta',
86 ICC_Profile => 'MIE-Meta',
87 ID3 => 'MIE-Meta',
88 CanonVRD => 'MIE-Canon',
89 IFD0 => 'EXIF',
90 IFD1 => 'IFD0',
91 ExifIFD => 'IFD0',
92 GPS => 'IFD0',
93 SubIFD => 'IFD0',
94 GlobParamIFD => 'IFD0',
95 PrintIM => 'IFD0',
96 InteropIFD => 'ExifIFD',
97 MakerNotes => 'ExifIFD',
98 );
99  
100 # convenience variables for common tagInfo entries
101 39 my %binaryConv = (
102 Writable => 'undef',
103 Binary => 1,
104 );
105 39 my %dateInfo = (
106 Shift => 'Time',
107 PrintConv => '$self->ConvertDateTime($val)',
108 PrintConvInv => '$self->InverseDateTime($val)',
109 );
110 39 my %noYes = ( 0 => 'No', 1 => 'Yes' );
111 39 my %offOn = ( 0 => 'Off', 1 => 'On' );
112  
113 # default entries for MIE tag tables
114 39 %tableDefaults = (
115 PROCESS_PROC => \&ProcessMIE,
116 WRITE_PROC => \&ProcessMIE,
117 CHECK_PROC => \&CheckMIE,
118 LANG_INFO => \&GetLangInfo,
119 WRITABLE => 'string',
120 PREFERRED => 1,
121 );
122  
123 # MIE info
124 39 %Image::ExifTool::MIE::Main = (
125 %tableDefaults,
126 GROUPS => { 1 => 'MIE-Main' },
127 WRITE_GROUP => 'MIE-Main',
128 NOTES => q{
129 MIE is a flexible format which may be used as a stand-alone meta information
130 format, for encapsulation of other files and information, or as a trailer
131 appended to other file formats. The tables below represent currently
132 defined MIE tags, however ExifTool will also extract any other information
133 present in a MIE file.
134  
135 When writing MIE information, some special features are supported:
136  
137 1) String values may be written as ASCII (ISO 8859-1) or UTF-8. ExifTool
138 automatically detects the presence of wide characters and treats the string
139 appropriately. Internally, UTF-8 text may be converted to UTF-16 or UTF-32
140 and stored in this format in the file if it is more compact.
141  
142 2) All MIE string-value tags support localized text. Localized values are
143 written by adding a language/country code to the tag name in the form
144 C<TAG-xx_YY>, where C<TAG> is the tag name, C<xx> is a 2-character lower
145 case ISO 639-1 language code, and C<YY> is a 2-character upper case ISO
146 3166-1 alpha 2 country code (eg. C<Title-en_US>). But as usual, the user
147 interface is case-insensitive, and ExifTool will write the correct case to
148 the file.
149  
150 3) Some numerical MIE tags allow units of measurement to be specified. For
151 these tags, units may be added in brackets immediately following the value
152 (eg. C<55(mi/h)>). If no units are specified, the default units are
153 written.
154  
155 4) ExifTool writes compressed metadata to MIE files if the L<Compress|../ExifTool.html#Compress> (-z)
156 option is used and Compress::Zlib is available.
157  
158 See L<https://exiftool.org/MIE1.1-20070121.pdf> for the official MIE
159 specification.
160 },
161 '0Type' => {
162 Name => 'SubfileType',
163 Notes => q{
164 the capitalized common extension for this type of file. If the extension
165 has a dot-3 abbreviation, then the longer version is used here. For
166 instance, JPEG and TIFF are used, not JPG and TIF
167 },
168 },
169 '0Vers' => {
170 Name => 'MIEVersion',
171 Notes => 'version 1.1 is assumed if not specified',
172 },
173 '1Directory' => {
174 Name => 'SubfileDirectory',
175 Notes => 'original directory for the file',
176 },
177 '1Name' => {
178 Name => 'SubfileName',
179 Notes => 'the file name, including extension if it exists',
180 },
181 '2MIME' => { Name => 'SubfileMIMEType' },
182 Meta => {
183 SubDirectory => {
184 TagTable => 'Image::ExifTool::MIE::Meta',
185 DirName => 'MIE-Meta',
186 },
187 },
188 data => {
189 Name => 'SubfileData',
190 Notes => 'the subfile data',
191 %binaryConv,
192 },
193 rsrc => {
194 Name => 'SubfileResource',
195 Notes => 'subfile resource fork if it exists',
196 %binaryConv,
197 },
198 zmd5 => {
199 Name => 'MD5Digest',
200 Notes => q{
201 16-byte MD5 digest written in binary form or as a 32-character hex-encoded
202 ASCII string. Value is an MD5 digest of the entire 0MIE group as it would be
203 with the digest value itself set to all null bytes
204 },
205 },
206 zmie => {
207 Name => 'TrailerSignature',
208 Writable => 'undef',
209 Notes => q{
210 used as the last element in the main "0MIE" group to identify a MIE trailer
211 when appended to another type of file. ExifTool will create this tag if set
212 to any value, but always with an empty data block
213 },
214 ValueConvInv => '""', # data block must be empty
215 },
216 );
217  
218 # MIE meta information group
219 39 %Image::ExifTool::MIE::Meta = (
220 %tableDefaults,
221 GROUPS => { 1 => 'MIE-Meta', 2 => 'Image' },
222 WRITE_GROUP => 'MIE-Meta',
223 Audio => {
224 SubDirectory => {
225 TagTable => 'Image::ExifTool::MIE::Audio',
226 DirName => 'MIE-Audio',
227 },
228 },
229 Camera => {
230 SubDirectory => {
231 TagTable => 'Image::ExifTool::MIE::Camera',
232 DirName => 'MIE-Camera',
233 },
234 },
235 Document => {
236 SubDirectory => {
237 TagTable => 'Image::ExifTool::MIE::Doc',
238 DirName => 'MIE-Doc',
239 },
240 },
241 EXIF => {
242 SubDirectory => {
243 TagTable => 'Image::ExifTool::Exif::Main',
244 ProcessProc => \&Image::ExifTool::ProcessTIFF,
245 WriteProc => \&Image::ExifTool::WriteTIFF,
246 },
247 },
248 Geo => {
249 SubDirectory => {
250 TagTable => 'Image::ExifTool::MIE::Geo',
251 DirName => 'MIE-Geo',
252 },
253 },
254 ICCProfile => {
255 Name => 'ICC_Profile',
256 SubDirectory => { TagTable => 'Image::ExifTool::ICC_Profile::Main' },
257 },
258 ID3 => { SubDirectory => { TagTable => 'Image::ExifTool::ID3::Main' } },
259 IPTC => { SubDirectory => { TagTable => 'Image::ExifTool::IPTC::Main' } },
260 Image => {
261 SubDirectory => {
262 TagTable => 'Image::ExifTool::MIE::Image',
263 DirName => 'MIE-Image',
264 },
265 },
266 MakerNotes => {
267 SubDirectory => {
268 TagTable => 'Image::ExifTool::MIE::MakerNotes',
269 DirName => 'MIE-MakerNotes',
270 },
271 },
272 Preview => {
273 SubDirectory => {
274 TagTable => 'Image::ExifTool::MIE::Preview',
275 DirName => 'MIE-Preview',
276 },
277 },
278 Thumbnail => {
279 SubDirectory => {
280 TagTable => 'Image::ExifTool::MIE::Thumbnail',
281 DirName => 'MIE-Thumbnail',
282 },
283 },
284 Video => {
285 SubDirectory => {
286 TagTable => 'Image::ExifTool::MIE::Video',
287 DirName => 'MIE-Video',
288 },
289 },
290 XMP => { SubDirectory => { TagTable => 'Image::ExifTool::XMP::Main' } },
291 );
292  
293 # MIE document information
294 39 %Image::ExifTool::MIE::Doc = (
295 %tableDefaults,
296 GROUPS => { 1 => 'MIE-Doc', 2 => 'Document' },
297 WRITE_GROUP => 'MIE-Doc',
298 NOTES => 'Information describing the main document, image or file.',
299 Author => { Groups => { 2 => 'Author' } },
300 Comment => { },
301 Contributors=> { Groups => { 2 => 'Author' }, List => 1 },
302 Copyright => { Groups => { 2 => 'Author' } },
303 CreateDate => { Groups => { 2 => 'Time' }, %dateInfo },
304 EMail => { Name => 'Email', Groups => { 2 => 'Author' } },
305 Keywords => { List => 1 },
306 ModifyDate => { Groups => { 2 => 'Time' }, %dateInfo },
307 OriginalDate=> {
308 Name => 'DateTimeOriginal',
309 Description => 'Date/Time Original',
310 Groups => { 2 => 'Time' },
311 %dateInfo,
312 },
313 Phone => { Name => 'PhoneNumber', Groups => { 2 => 'Author' } },
314 References => { List => 1 },
315 Software => { },
316 Title => { },
317 URL => { },
318 );
319  
320 # MIE geographic information
321 39 %Image::ExifTool::MIE::Geo = (
322 %tableDefaults,
323 GROUPS => { 1 => 'MIE-Geo', 2 => 'Location' },
324 WRITE_GROUP => 'MIE-Geo',
325 NOTES => 'Information related to geographic location.',
326 Address => { },
327 City => { },
328 Country => { },
329 GPS => {
330 SubDirectory => {
331 TagTable => 'Image::ExifTool::MIE::GPS',
332 DirName => 'MIE-GPS',
333 },
334 },
335 PostalCode => { },
336 State => { Notes => 'state or province' },
337 UTM => {
338 SubDirectory => {
339 TagTable => 'Image::ExifTool::MIE::UTM',
340 DirName => 'MIE-UTM',
341 },
342 },
343 );
344  
345 # MIE GPS information
346 39 %Image::ExifTool::MIE::GPS = (
347 %tableDefaults,
348 GROUPS => { 1 => 'MIE-GPS', 2 => 'Location' },
349 WRITE_GROUP => 'MIE-GPS',
350 Altitude => {
351 Name => 'GPSAltitude',
352 Writable => 'rational64s',
353 Units => [ qw(m ft) ],
354 Notes => q{'m' above sea level unless 'ft' specified},
355 },
356 Bearing => {
357 Name => 'GPSDestBearing',
358 Writable => 'rational64s',
359 Units => [ qw(deg deg{mag}) ],
360 Notes => q{'deg' CW from true north unless 'deg{mag}' specified},
361 },
362 Datum => { Name => 'GPSMapDatum', Notes => 'WGS-84 assumed if not specified' },
363 Differential => {
364 Name => 'GPSDifferential',
365 Writable => 'int8u',
366 PrintConv => {
367 0 => 'No Correction',
368 1 => 'Differential Corrected',
369 },
370 },
371 Distance => {
372 Name => 'GPSDestDistance',
373 Writable => 'rational64s',
374 Units => [ qw(km mi nmi) ],
375 Notes => q{'km' unless 'mi' or 'nmi' specified},
376 },
377 Heading => {
378 Name => 'GPSTrack',
379 Writable => 'rational64s',
380 Units => [ qw(deg deg{mag}) ],
381 Notes => q{'deg' CW from true north unless 'deg{mag}' specified},
382 },
383 Latitude => {
384 Name => 'GPSLatitude',
385 Writable => 'rational64s',
386 Count => -1,
387 Notes => q{
388 1 to 3 numbers: degrees, minutes then seconds. South latitudes are stored
389 as all negative numbers, but may be entered as positive numbers with a
390 trailing 'S' for convenience. For example, these are all equivalent: "-40
391 -30", "-40.5", "40 30 0.00 S"
392 },
393 ValueConv => 'Image::ExifTool::GPS::ToDegrees($val, 1)',
394 ValueConvInv => 'Image::ExifTool::GPS::ToDMS($self, $val, 3)',
395 PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "N")',
396 PrintConvInv => 'Image::ExifTool::GPS::ToDegrees($val, 1, "lat")',
397 },
398 Longitude => {
399 Name => 'GPSLongitude',
400 Writable => 'rational64s',
401 Count => -1,
402 Notes => q{
403 1 to 3 numbers: degrees, minutes then seconds. West longitudes are
404 negative, but may be entered as positive numbers with a trailing 'W'
405 },
406 ValueConv => 'Image::ExifTool::GPS::ToDegrees($val, 1)',
407 ValueConvInv => 'Image::ExifTool::GPS::ToDMS($self, $val, 3)',
408 PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "E")',
409 PrintConvInv => 'Image::ExifTool::GPS::ToDegrees($val, 1, "lon")',
410 },
411 MeasureMode => {
412 Name => 'GPSMeasureMode',
413 Writable => 'int8u',
414 PrintConv => { 2 => '2-D', 3 => '3-D' },
415 },
416 Satellites => 'GPSSatellites',
417 Speed => {
418 Name => 'GPSSpeed',
419 Writable => 'rational64s',
420 Units => [ qw(km/h mi/h m/s kn) ],
421 Notes => q{'km/h' unless 'mi/h', 'm/s' or 'kn' specified},
422 },
423 DateTime => { Name => 'GPSDateTime', Groups => { 2 => 'Time' }, %dateInfo },
424 );
425  
426 # MIE UTM information
427 39 %Image::ExifTool::MIE::UTM = (
428 %tableDefaults,
429 GROUPS => { 1 => 'MIE-UTM', 2 => 'Location' },
430 WRITE_GROUP => 'MIE-UTM',
431 Datum => { Name => 'UTMMapDatum', Notes => 'WGS-84 assumed if not specified' },
432 Easting => { Name => 'UTMEasting' },
433 Northing => { Name => 'UTMNorthing' },
434 Zone => { Name => 'UTMZone', Writable => 'int8s' },
435 );
436  
437 # MIE image information
438 39 %Image::ExifTool::MIE::Image = (
439 %tableDefaults,
440 GROUPS => { 1 => 'MIE-Image', 2 => 'Image' },
441 WRITE_GROUP => 'MIE-Image',
442 '0Type' => { Name => 'FullSizeImageType', Notes => 'JPEG if not specified' },
443 '1Name' => { Name => 'FullSizeImageName' },
444 BitDepth => { Name => 'BitDepth', Writable => 'int16u' },
445 ColorSpace => { Notes => 'standard ColorSpace values are "sRGB" and "Adobe RGB"' },
446 Components => {
447 Name => 'ComponentsConfiguration',
448 Notes => 'string composed of R, G, B, Y, Cb and Cr',
449 },
450 Compression => { Name => 'CompressionRatio', Writable => 'rational32u' },
451 OriginalImageSize => { # PH added 2022-09-28
452 Writable => 'int16u',
453 Count => -1,
454 Notes => 'size of original image before cropping',
455 PrintConv => '$val=~tr/ /x/;$val',
456 PrintConvInv => '$val=~tr/x/ /;$val',
457 },
458 ImageSize => {
459 Writable => 'int16u',
460 Count => -1,
461 Notes => '2 or 3 values, for number of XY or XYZ pixels',
462 PrintConv => '$val=~tr/ /x/;$val',
463 PrintConvInv => '$val=~tr/x/ /;$val',
464 },
465 Resolution => {
466 Writable => 'rational64u',
467 Units => [ qw(/in /cm /deg /arcmin /arcsec), '' ],
468 Count => -1,
469 Notes => q{
470 1 to 3 values. A single value for equal resolution in all directions, or
471 separate X, Y and Z values if necessary. Units are '/in' unless '/cm',
472 '/deg', '/arcmin', '/arcsec' or '' specified
473 },
474 PrintConv => '$val=~tr/ /x/;$val',
475 PrintConvInv => '$val=~tr/x/ /;$val',
476 },
477 data => {
478 Name => 'FullSizeImage',
479 Groups => { 2 => 'Preview' },
480 %binaryConv,
481 RawConv => '$self->ValidateImage(\$val,$tag)',
482 },
483 );
484  
485 # MIE preview image
486 39 %Image::ExifTool::MIE::Preview = (
487 %tableDefaults,
488 GROUPS => { 1 => 'MIE-Preview', 2 => 'Image' },
489 WRITE_GROUP => 'MIE-Preview',
490 '0Type' => { Name => 'PreviewImageType', Notes => 'JPEG if not specified' },
491 '1Name' => { Name => 'PreviewImageName' },
492 ImageSize => {
493 Name => 'PreviewImageSize',
494 Writable => 'int16u',
495 Count => -1,
496 Notes => '2 or 3 values, for number of XY or XYZ pixels',
497 PrintConv => '$val=~tr/ /x/;$val',
498 PrintConvInv => '$val=~tr/x/ /;$val',
499 },
500 data => {
501 Name => 'PreviewImage',
502 Groups => { 2 => 'Preview' },
503 %binaryConv,
504 RawConv => '$self->ValidateImage(\$val,$tag)',
505 },
506 );
507  
508 # MIE thumbnail image
509 39 %Image::ExifTool::MIE::Thumbnail = (
510 %tableDefaults,
511 GROUPS => { 1 => 'MIE-Thumbnail', 2 => 'Image' },
512 WRITE_GROUP => 'MIE-Thumbnail',
513 '0Type' => { Name => 'ThumbnailImageType', Notes => 'JPEG if not specified' },
514 '1Name' => { Name => 'ThumbnailImageName' },
515 ImageSize => {
516 Name => 'ThumbnailImageSize',
517 Writable => 'int16u',
518 Count => -1,
519 Notes => '2 or 3 values, for number of XY or XYZ pixels',
520 PrintConv => '$val=~tr/ /x/;$val',
521 PrintConvInv => '$val=~tr/x/ /;$val',
522 },
523 data => {
524 Name => 'ThumbnailImage',
525 Groups => { 2 => 'Preview' },
526 %binaryConv,
527 RawConv => '$self->ValidateImage(\$val,$tag)',
528 },
529 );
530  
531 # MIE audio information
532 39 %Image::ExifTool::MIE::Audio = (
533 %tableDefaults,
534 GROUPS => { 1 => 'MIE-Audio', 2 => 'Audio' },
535 WRITE_GROUP => 'MIE-Audio',
536 NOTES => q{
537 For the Audio group (and any other group containing a 'data' element), tags
538 refer to the contained data if present, otherwise they refer to the main
539 SubfileData. The C<0Type> and C<1Name> elements should exist only if C<data>
540 is present.
541 },
542 '0Type' => { Name => 'RelatedAudioFileType', Notes => 'MP3 if not specified' },
543 '1Name' => { Name => 'RelatedAudioFileName' },
544 SampleBits => { Writable => 'int16u' },
545 Channels => { Writable => 'int8u' },
546 Compression => { Name => 'AudioCompression' },
547 Duration => { Writable => 'rational64u', PrintConv => 'ConvertDuration($val)' },
548 SampleRate => { Writable => 'int32u' },
549 data => { Name => 'RelatedAudioFile', %binaryConv },
550 );
551  
552 # MIE video information
553 39 %Image::ExifTool::MIE::Video = (
554 %tableDefaults,
555 GROUPS => { 1 => 'MIE-Video', 2 => 'Video' },
556 WRITE_GROUP => 'MIE-Video',
557 '0Type' => { Name => 'RelatedVideoFileType', Notes => 'MOV if not specified' },
558 '1Name' => { Name => 'RelatedVideoFileName' },
559 Codec => { },
560 Duration => { Writable => 'rational64u', PrintConv => 'ConvertDuration($val)' },
561 data => { Name => 'RelatedVideoFile', %binaryConv },
562 );
563  
564 # MIE camera information
565 39 %Image::ExifTool::MIE::Camera = (
566 %tableDefaults,
567 GROUPS => { 1 => 'MIE-Camera', 2 => 'Camera' },
568 WRITE_GROUP => 'MIE-Camera',
569 Brightness => { Writable => 'int8s' },
570 ColorTemperature=> { Writable => 'int32u' },
571 ColorBalance => {
572 Writable => 'rational64u',
573 Count => 3,
574 Notes => 'RGB scaling factors',
575 },
576 Contrast => { Writable => 'int8s' },
577 DigitalZoom => { Writable => 'rational64u' },
578 ExposureComp => { Name => 'ExposureCompensation', Writable => 'rational64s' },
579 ExposureMode => { },
580 ExposureTime => {
581 Writable => 'rational64u',
582 PrintConv => 'Image::ExifTool::Exif::PrintExposureTime($val)',
583 PrintConvInv => '$val',
584 },
585 Flash => {
586 SubDirectory => {
587 TagTable => 'Image::ExifTool::MIE::Flash',
588 DirName => 'MIE-Flash',
589 },
590 },
591 FirmwareVersion => { },
592 FocusMode => { },
593 ISO => { Writable => 'int16u' },
594 ISOSetting => {
595 Writable => 'int16u',
596 Notes => '0 = Auto, otherwise manual ISO speed setting',
597 },
598 ImageNumber => { Writable => 'int32u' },
599 ImageQuality => { Notes => 'Economy, Normal, Fine, Super Fine or Raw' },
600 ImageStabilization => { Writable => 'int8u', %offOn },
601 Lens => {
602 SubDirectory => {
603 TagTable => 'Image::ExifTool::MIE::Lens',
604 DirName => 'MIE-Lens',
605 },
606 },
607 Make => { },
608 MeasuredEV => { Writable => 'rational64s' },
609 Model => { },
610 OwnerName => { },
611 Orientation => {
612 SubDirectory => {
613 TagTable => 'Image::ExifTool::MIE::Orient',
614 DirName => 'MIE-Orient',
615 },
616 },
617 Saturation => { Writable => 'int8s' },
618 SensorSize => {
619 Writable => 'rational64u',
620 Count => 2,
621 Notes => 'width and height of active sensor area in mm',
622 },
623 SerialNumber => { },
624 Sharpness => { Writable => 'int8s' },
625 ShootingMode => { },
626 );
627  
628 # Camera orientation information
629 39 %Image::ExifTool::MIE::Orient = (
630 %tableDefaults,
631 GROUPS => { 1 => 'MIE-Orient', 2 => 'Camera' },
632 WRITE_GROUP => 'MIE-Orient',
633 NOTES => 'These tags describe the camera orientation.',
634 Azimuth => {
635 Writable => 'rational64s',
636 Units => [ qw(deg deg{mag}) ],
637 Notes => q{'deg' CW from true north unless 'deg{mag}' specified},
638 },
639 Declination => { Writable => 'rational64s' },
640 Elevation => { Writable => 'rational64s' },
641 RightAscension => { Writable => 'rational64s' },
642 Rotation => {
643 Writable => 'rational64s',
644 Notes => 'CW rotation angle of camera about lens axis',
645 },
646 );
647  
648 # MIE camera lens information
649 39 %Image::ExifTool::MIE::Lens = (
650 %tableDefaults,
651 GROUPS => { 1 => 'MIE-Lens', 2 => 'Camera' },
652 WRITE_GROUP => 'MIE-Lens',
653 NOTES => q{
654 All recorded lens parameters (focal length, aperture, etc) include the
655 effects of the extender if present.
656 },
657 Extender => {
658 SubDirectory => {
659 TagTable => 'Image::ExifTool::MIE::Extender',
660 DirName => 'MIE-Extender',
661 },
662 },
663 FNumber => { Writable => 'rational64u' },
664 FocalLength => { Writable => 'rational64u', Notes => 'all focal lengths in mm' },
665 FocusDistance => {
666 Writable => 'rational64u',
667 Units => [ qw(m ft) ],
668 Notes => q{'m' unless 'ft' specified},
669 },
670 Make => { Name => 'LensMake' },
671 MaxAperture => { Writable => 'rational64u' },
672 MaxApertureAtMaxFocal => { Writable => 'rational64u' },
673 MaxFocalLength => { Writable => 'rational64u' },
674 MinAperture => { Writable => 'rational64u' },
675 MinFocalLength => { Writable => 'rational64u' },
676 Model => { Name => 'LensModel' },
677 OpticalZoom => { Writable => 'rational64u' },
678 SerialNumber => { Name => 'LensSerialNumber' },
679 );
680  
681 # MIE lens extender information
682 39 %Image::ExifTool::MIE::Extender = (
683 %tableDefaults,
684 GROUPS => { 1 => 'MIE-Extender', 2 => 'Camera' },
685 WRITE_GROUP => 'MIE-Extender',
686 Magnification => { Name => 'ExtenderMagnification', Writable => 'rational64s' },
687 Make => { Name => 'ExtenderMake' },
688 Model => { Name => 'ExtenderModel' },
689 SerialNumber => { Name => 'ExtenderSerialNumber' },
690 );
691  
692 # MIE camera flash information
693 39 %Image::ExifTool::MIE::Flash = (
694 %tableDefaults,
695 GROUPS => { 1 => 'MIE-Flash', 2 => 'Camera' },
696 WRITE_GROUP => 'MIE-Flash',
697 ExposureComp => { Name => 'FlashExposureComp', Writable => 'rational64s' },
698 Fired => { Name => 'FlashFired', Writable => 'int8u', PrintConv => \%noYes },
699 GuideNumber => { Name => 'FlashGuideNumber' },
700 Make => { Name => 'FlashMake' },
701 Mode => { Name => 'FlashMode' },
702 Model => { Name => 'FlashModel' },
703 SerialNumber => { Name => 'FlashSerialNumber' },
704 Type => { Name => 'FlashType', Notes => '"Internal" or "External"' },
705 );
706  
707 # MIE maker notes information
708 39 %Image::ExifTool::MIE::MakerNotes = (
709 %tableDefaults,
710 GROUPS => { 1 => 'MIE-MakerNotes' },
711 WRITE_GROUP => 'MIE-MakerNotes',
712 NOTES => q{
713 MIE maker notes are contained within separate groups for each manufacturer
714 to avoid name conflicts.
715 },
716 Canon => {
717 SubDirectory => {
718 TagTable => 'Image::ExifTool::MIE::Canon',
719 DirName => 'MIE-Canon',
720 },
721 },
722 Casio => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
723 FujiFilm => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
724 Kodak => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
725 KonicaMinolta=>{ SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
726 Nikon => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
727 Olympus => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
728 Panasonic => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
729 Pentax => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
730 Ricoh => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
731 Sigma => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
732 Sony => { SubDirectory => { TagTable => 'Image::ExifTool::MIE::Unknown' } },
733 );
734  
735 # MIE Canon-specific information
736 39 %Image::ExifTool::MIE::Canon = (
737 %tableDefaults,
738 GROUPS => { 1 => 'MIE-Canon' },
739 WRITE_GROUP => 'MIE-Canon',
740 VRD => {
741 Name => 'CanonVRD',
742 SubDirectory => { TagTable => 'Image::ExifTool::CanonVRD::Main' },
743 },
744 );
745  
746 39 %Image::ExifTool::MIE::Unknown = (
747 PROCESS_PROC => \&ProcessMIE,
748 GROUPS => { 1 => 'MIE-Unknown' },
749 );
750  
751 #------------------------------------------------------------------------------
752 # Add user-defined MIE groups to %mieMap
753 # Inputs: none; Returns: nothing, but sets $doneMieMap flag
754 sub UpdateMieMap()
755 3 ▶{
Subroutine UpdateMieMap: called CC=18 SCAR=57.0
Pod undocumented
756 3 $doneMieMap = 1; # set flag so we only do this once
757 3 ▶ return unless %Image::ExifTool::UserDefined;
Branch: 1 branch
BranchTrueFalseTotal
unless %Image::ExifTool::UserDefined 3 0 3
758 0 my ($tableName, @tables, %doneTable, $tagID);
759 # get list of top-level MIE tables with user-defined tags
760 0 foreach $tableName (keys %Image::ExifTool::UserDefined) {
761 0 ▶ next unless $tableName =~ /^Image::ExifTool::MIE::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tableName =~ /^Image::ExifTool::MIE::/ 0 0 0
762 0 my $userTable = $Image::ExifTool::UserDefined{$tableName};
763 0 ▶ my $tagTablePtr = GetTagTable($tableName) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $tagTablePtr = &GetTagTable($tableName) or next 0 0 0
764 # copy the WRITE_GROUP from the actual table
765 0 $$userTable{WRITE_GROUP} = $$tagTablePtr{WRITE_GROUP};
766 # add to list of tables to process
767 0 $doneTable{$tableName} = 1;
768 0 push @tables, [$tableName, $userTable];
769 }
770 # recursively add all user-defined groups to MIE map
771 0 ▶ while (@tables) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tables) 0 0 0
772 0 my ($tableName, $tagTablePtr) = @{shift @tables};
773 0 my $parent = $$tagTablePtr{WRITE_GROUP};
774 0 ▶ $parent or warn("No WRITE_GROUP for $tableName\n"), next;
Branch: 1 branch
BranchTrueFalseTotal
$parent or warn("No WRITE_GROUP for $tableName\n"), next 0 0 0
775 0 ▶ $mieMap{$parent} or warn("$parent is not in MIE map\n"), next;
Branch: 1 branch
BranchTrueFalseTotal
$mieMap{$parent} or warn("$parent is not in MIE map\n"), next 0 0 0
776 0 foreach $tagID (TagTableKeys($tagTablePtr)) {
777 0 my $tagInfo = $$tagTablePtr{$tagID};
778 0 ▶ next unless ref $tagInfo eq 'HASH' and $$tagInfo{SubDirectory};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tagInfo eq "HASH" and $tagInfo->{"SubDirectory"} 0 0 0
Condition0%0/3
ref $tagInfo eq "HASH" and $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $tagInfo eq "HASH" and $tagInfo->{"SubDirectory"}
ref $tagInfo eq "HASH" $tagInfo->{"SubDirectory"}
Truth table0%0/3
A and B
A= ref $tagInfo eq "HASH"B= $tagInfo->{"SubDirectory"}
ABresult
0X0
100
111
779 0 my $subTableName = $tagInfo->{SubDirectory}->{TagTable};
780 0 ▶ my $subTablePtr = GetTagTable($subTableName) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $subTablePtr = &GetTagTable($subTableName) or next 0 0 0
781 # only care about MIE tables
782 next unless $$subTablePtr{PROCESS_PROC} and
783 0 ▶ $$subTablePtr{PROCESS_PROC} eq \&ProcessMIE;
Branch: 1 branch
BranchTrueFalseTotal
unless $subTablePtr->{"PROCESS_PROC"} and $subTablePtr->{"PROCESS_PROC"} eq \&Image::ExifTool::MIE::ProcessMIE 0 0 0
Condition0%0/3
$subTablePtr->{"PROCESS_PROC"} and $subTablePtr->{"PROCESS_PROC"} eq \&Image::ExifTool::MIE::ProcessMIE
!ll&&!rl&&r
000
MC/DC0%0/2
$subTablePtr->{"PROCESS_PROC"} and $subTablePtr->{"PROCESS_PROC"} eq \&Image::ExifTool::MIE::ProcessMIE
$subTablePtr->{"PROCESS_PROC"} $subTablePtr->{"PROCESS_PROC"} eq \&Image::ExifTool::MIE::ProcessMIE
Truth table0%0/3
A and B
A= $subTablePtr->{"PROCESS_PROC"}B= $subTablePtr->{"PROCESS_PROC"} eq \&Image::ExifTool::MIE::ProcessMIE
ABresult
0X0
100
111
784 0 my $group = $$subTablePtr{WRITE_GROUP};
785 0 ▶ $group or warn("No WRITE_GROUP for $subTableName\n"), next;
Branch: 1 branch
BranchTrueFalseTotal
$group or warn("No WRITE_GROUP for $subTableName\n"), next 0 0 0
786 0 ▶ if ($mieMap{$group} and $mieMap{$group} ne $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mieMap{$group} and $mieMap{$group} ne $parent) 0 0 0
Condition0%0/3
$mieMap{$group} and $mieMap{$group} ne $parent
!ll&&!rl&&r
000
MC/DC0%0/2
$mieMap{$group} and $mieMap{$group} ne $parent
$mieMap{$group} $mieMap{$group} ne $parent
Truth table0%0/3
A and B
A= $mieMap{$group}B= $mieMap{$group} ne $parent
ABresult
0X0
100
111
787 0 warn("$group already has different parent ($mieMap{$group})\n"), next;
788 }
789 0 $mieMap{$group} = $parent; # add to map
790 # process tables within this one too
791 0 ▶ $doneTable{$subTableName} and next;
Branch: 1 branch
BranchTrueFalseTotal
$doneTable{$subTableName} and next 0 0 0
792 0 $doneTable{$subTableName} = 1;
793 0 push @tables, [$subTableName, $subTablePtr];
794 }
795 }
796 }
797  
798 #------------------------------------------------------------------------------
799 # Get localized version of tagInfo hash
800 # Inputs: 0) tagInfo hash ref, 1) locale code (eg. "en_CA")
801 # Returns: new tagInfo hash ref, or undef if invalid
802 sub GetLangInfo($$)
803 62 ▶{
Subroutine GetLangInfo: called CC=5 SCAR=17.2
Pod undocumented
804 62 my ($tagInfo, $langCode) = @_;
805 # check for properly formatted language code
806 62 ▶ return undef unless $langCode =~ /^[a-z]{2}([-_])[A-Z]{2}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $langCode =~ /^[a-z]{2}([-_])[A-Z]{2}$/ 14 48 62
807 # use '_' as a separator, but recognize '_' or '-'
808 48 ▶ $langCode =~ tr/-/_/ if $1 eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "-" 0 48 48
809 # can only set locale on string types
810 48 ▶ return undef if $$tagInfo{Writable} and $$tagInfo{Writable} ne 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"Writable"} and $tagInfo->{"Writable"} ne "string" 0 48 48
Condition33%1/3
$tagInfo->{"Writable"} and $tagInfo->{"Writable"} ne "string"
!ll&&!rl&&r
4800
MC/DC0%0/2
$tagInfo->{"Writable"} and $tagInfo->{"Writable"} ne "string"
$tagInfo->{"Writable"} $tagInfo->{"Writable"} ne "string"
Truth table33%1/3
A and B
A= $tagInfo->{"Writable"}B= $tagInfo->{"Writable"} ne "string"
ABresult
0X0
100
111
811 48 return Image::ExifTool::GetLangInfo($tagInfo, $langCode);
812 }
813  
814 #------------------------------------------------------------------------------
815 # return true if we have Zlib::Compress
816 # Inputs: 0) ExifTool object ref, 1) verb for what you want to do with the info
817 # Returns: 1 if Zlib available, 0 otherwise
818 sub HasZlib($$)
819 0 ▶{
Subroutine HasZlib: not called CC=3 SCAR=24.8
Pod undocumented
820 0 ▶ unless (defined $hasZlib) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hasZlib) 0 0 0
821 0 $hasZlib = eval { require Compress::Zlib };
822 0 ▶ unless ($hasZlib) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hasZlib) 0 0 0
823 0 $hasZlib = 0;
824 0 $_[0]->Warn("Install Compress::Zlib to $_[1] compressed information");
825 }
826 }
827 0 return $hasZlib;
828 }
829  
830 #------------------------------------------------------------------------------
831 # Get format code for MIE group element with current byte order
832 # Inputs: 0) [optional] true to convert result to chr()
833 # Returns: format code
834 sub MIEGroupFormat(;$)
835 32 ▶{
Subroutine MIEGroupFormat: called CC=3 SCAR=11.7
Pod undocumented
836 32 my $chr = shift;
837 32 ▶ my $format = GetByteOrder() eq 'MM' ? 0x10 : 0x18;
Branch: 1 branch
BranchTrueFalseTotal
&GetByteOrder() eq 'MM' ? : 32 0 32
838 32 ▶ return $chr ? chr($format) : $format;
Branch: 1 branch
BranchTrueFalseTotal
$chr ? : 32 0 32
839 }
840  
841 #------------------------------------------------------------------------------
842 # ReadValue() with added support for UTF formats (utf8, utf16 and utf32)
843 # Inputs: 0) data reference, 1) value offset, 2) format string,
844 # 3) number of values (or undef to use all data)
845 # 4) valid data length relative to offset, 5) returned rational ref
846 # Returns: converted value, or undefined if data isn't there
847 # or list of values in list context
848 # Notes: all string formats are converted to UTF8
849 sub ReadMIEValue($$$$$;$)
850 493 ▶{
Subroutine ReadMIEValue: called CC=10 SCAR=24.1
Pod undocumented
851 493 my ($dataPt, $offset, $format, $count, $size, $ratPt) = @_;
852 493 my $val;
853 493 ▶ if ($format =~ /^(utf(8|16|32)|string)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /^(utf(8|16|32)|string)/) { } 332 161 493
854 332 ▶ if ($1 eq 'utf8' or $1 eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq 'utf8' or $1 eq 'string') { } 308 24 332
Condition100%3/3
$1 eq "utf8" or $1 eq "string"
l!l&&r!l&&!r
6024824
MC/DC100%2/2
$1 eq "utf8" or $1 eq "string"
$1 eq "utf8" $1 eq "string"
Truth table100%3/3
A or B
A= $1 eq "utf8"B= $1 eq "string"
ABresult
1X1
011
000
855 # read the 8-bit string
856 308 $val = substr($$dataPt, $offset, $size);
857 # (as of ExifTool 7.62, leave string values unconverted)
858 } else {
859 # convert to UTF8
860 24 my $fmt;
861 24 ▶ if (GetByteOrder() eq 'MM') {
Branch: 1 branch
BranchTrueFalseTotal
if (&GetByteOrder() eq 'MM') { } 24 0 24
862 24 ▶ $fmt = ($1 eq 'utf16') ? 'n' : 'N';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'utf16' ? : 24 0 24
863 } else {
864 0 ▶ $fmt = ($1 eq 'utf16') ? 'v' : 'V';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'utf16' ? : 0 0 0
865 }
866 24 my @unpk = unpack("x$offset$fmt$size",$$dataPt);
867 24 ▶ if ($] >= 5.006001) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.006001) { } 24 0 24
868 24 $val = pack('C0U*', @unpk);
869 } else {
870 0 $val = Image::ExifTool::PackUTF8(@unpk);
871 }
872 }
873 # truncate at null unless this is a list
874 # (strings shouldn't have a null, but just in case)
875 332 ▶ $val =~ s/\0.*//s unless $format =~ /_list$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $format =~ /_list$/ 324 8 332
876 } else {
877 161 ▶ $format = 'undef' if $format eq 'free'; # read 'free' as 'undef'
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "free" 0 161 161
878 161 return ReadValue($dataPt, $offset, $format, $count, $size, $ratPt);
879 }
880 332 return $val;
881 }
882  
883 #------------------------------------------------------------------------------
884 # validate raw values for writing
885 # Inputs: 0) ExifTool object ref, 1) tagInfo hash ref, 2) raw value ref
886 # Returns: error string or undef (and possibly changes value) on success
887 sub CheckMIE($$$)
888 556 ▶{
Subroutine CheckMIE: called CC=13 SCAR=27.3
Pod undocumented
889 556 my ($et, $tagInfo, $valPtr) = @_;
890 556 ▶ my $format = $$tagInfo{Writable} || $tagInfo->{Table}->{WRITABLE};
Condition66%2/3
$tagInfo->{'Writable'} || $tagInfo->{'Table'}{'WRITABLE'}
l!l&&r!l&&!r
2792770
MC/DC0%0/2
$tagInfo->{'Writable'} || $tagInfo->{'Table'}{'WRITABLE'}
$tagInfo->{'Writable'} $tagInfo->{'Table'}{'WRITABLE'}
Truth table66%2/3
A || B
A= $tagInfo->{'Writable'}B= $tagInfo->{'Table'}{'WRITABLE'}
ABresult
1X1
011
000
891 556 my $err;
892  
893 556 ▶ return 'No writable format' if not $format or $format eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if not $format or $format eq 1 0 556 556
Condition33%1/3
not $format or $format eq 1
l!l&&r!l&&!r
00556
MC/DC0%0/2
not $format or $format eq 1
not $format $format eq 1
Truth table33%1/3
not(A) or B
A= not $formatB= $format eq 1
ABresult
1X1
011
000
894 # handle units if supported by this tag
895 556 my $ulist = $$tagInfo{Units};
896 556 ▶ if ($ulist and $$valPtr =~ /(.*)\((.*)\)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ulist and $$valPtr =~ /(.*)\((.*)\)$/) { } 1 555 556
elsif (not $format =~ /^(utf|string|undef)/ and $$valPtr =~ /\)$/) { } 7 548 555
Condition100%3/3
$ulist and $$valPtr =~ /(.*)\((.*)\)$/
!ll&&!rl&&r
542131
MC/DC100%2/2
$ulist and $$valPtr =~ /(.*)\((.*)\)$/
$ulist $$valPtr =~ /(.*)\((.*)\)$/
Truth table100%3/3
A and B
A= $ulistB= $$valPtr =~ /(.*)\((.*)\)$/
ABresult
0X0
100
111
897 1 my ($val, $units) = ($1, $2);
898 1 ($units) = grep /^$units$/i, @$ulist;
899 1 ▶ defined $units or return 'Allowed units: (' . join('|', @$ulist) . ')';
Branch: 1 branch
BranchTrueFalseTotal
defined $units or return 'Allowed units: (' . join("|", @$ulist) . ')' 1 0 1
900 1 $err = Image::ExifTool::CheckValue(\$val, $format, $$tagInfo{Count});
901 # add units back onto value
902 1 ▶ $$valPtr = "$val($units)" unless $err;
Branch: 1 branch
BranchTrueFalseTotal
unless $err 1 0 1
903 ▶ } elsif ($format !~ /^(utf|string|undef)/ and $$valPtr =~ /\)$/) {
Condition100%3/3
not $format =~ /^(utf|string|undef)/ and $$valPtr =~ /\)$/
!ll&&!rl&&r
3172317
MC/DC100%2/2
not $format =~ /^(utf|string|undef)/ and $$valPtr =~ /\)$/
not $format =~ /^(utf|string|undef)/ $$valPtr =~ /\)$/
Truth table100%3/3
not(A) and B
A= not $format =~ /^(utf|string|undef)/B= $$valPtr =~ /\)$/
ABresult
0X0
100
111
904 7 return 'Units not supported';
905 } else {
906 548 ▶ if ($format eq 'string' and $$et{OPTIONS}{Charset} ne 'UTF8' and
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq "string" and $et->{"OPTIONS"}{"Charset"} ne "UTF8" and $$valPtr =~ /[\x80-\xff]/) 0 548 548
Condition50%3/6
$format eq "string" and $et->{"OPTIONS"}{"Charset"} ne "UTF8" and $$valPtr =~ /[\x80-\xff]/
!ll&&!rl&&r
54800
$format eq "string" and $et->{"OPTIONS"}{"Charset"} ne "UTF8"
!ll&&!rl&&r
2712770
MC/DC0%0/3
$format eq "string" and $et->{"OPTIONS"}{"Charset"} ne "UTF8" and $$valPtr =~ /[\x80-\xff]/
$format eq "string" $et->{"OPTIONS"}{"Charset"} ne "UTF8" $$valPtr =~ /[\x80-\xff]/
Truth table50%2/4
A and B and C
A= $format eq "string"B= $et->{"OPTIONS"}{"Charset"} ne "UTF8"C= $$valPtr =~ /[\x80-\xff]/
ABCresult
0XX0
10X0
1100
1111
907 $$valPtr =~ /[\x80-\xff]/)
908 {
909 # convert from Charset to UTF-8
910 0 $$valPtr = $et->Encode($$valPtr,'UTF8');
911 }
912 548 $err = Image::ExifTool::CheckValue($valPtr, $format, $$tagInfo{Count});
913 }
914 549 return $err;
915 }
916  
917 #------------------------------------------------------------------------------
918 # Rewrite a MIE directory
919 # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) tag table ptr
920 # Returns: undef on success, otherwise error message (empty message if nothing to write)
921 sub WriteMIEGroup($$$)
922 46 ▶{
Subroutine WriteMIEGroup: called CC=170 SCAR=81.0
Pod undocumented
923 46 my ($et, $dirInfo, $tagTablePtr) = @_;
924 46 my $outfile = $$dirInfo{OutFile};
925 46 my $dirName = $$dirInfo{DirName};
926 46 ▶ my $toWrite = $$dirInfo{ToWrite} || '';
Condition50%1/2
$dirInfo->{'ToWrite'} || ''
l!l
460
MC/DC0%0/1
$dirInfo->{'ToWrite'} || ''
$dirInfo->{'ToWrite'}
Truth table50%1/2
A
A= $dirInfo->{'ToWrite'}
Aresult
11
00
927 46 my $raf = $$dirInfo{RAF};
928 46 my $verbose = $et->Options('Verbose');
929 46 my $optCompress = $et->Options('Compress');
930 46 my $out = $et->Options('TextOut');
931 46 my ($msg, $err, $ok, $sync, $delGroup);
932 46 my $tag = '';
933 46 my $deletedTag = '';
934  
935 # count each MIE directory found and make name for this specific instance
936 46 my ($grp1, %isWriting);
937 46 my $cnt = $$et{MIE_COUNT};
938 46 my $grp = $tagTablePtr->{GROUPS}->{1};
939 46 ▶ my $n = $$cnt{'MIE-Main'} || 0;
Condition100%2/2
$cnt->{'MIE-Main'} || 0
l!l
379
MC/DC100%1/1
$cnt->{'MIE-Main'} || 0
$cnt->{'MIE-Main'}
Truth table100%2/2
A
A= $cnt->{'MIE-Main'}
Aresult
11
00
940 46 ▶ if ($grp eq 'MIE-Main') {
Branch: 1 branch
BranchTrueFalseTotal
if ($grp eq 'MIE-Main') { } 9 37 46
941 9 $$cnt{$grp} = ++$n;
942 9 ($grp1 = $grp) =~ s/MIE-/MIE$n-/;
943 } else {
944 37 ($grp1 = $grp) =~ s/MIE-/MIE$n-/;
945 37 ▶ my $m = $$cnt{$grp1} = ($$cnt{$grp1} || 0) + 1;
Condition50%1/2
$cnt->{$grp1} || 0
l!l
037
MC/DC0%0/1
$cnt->{$grp1} || 0
$cnt->{$grp1}
Truth table50%1/2
A
A= $cnt->{$grp1}
Aresult
11
00
946 37 $isWriting{"$grp$m"} = 1; # eg. 'MIE-Doc2'
947 37 $isWriting{$grp1} = 1; # eg. 'MIE1-Doc'
948 37 $grp1 .= $m;
949 }
950 # build lookup for all valid group names for this MIE group
951 46 $isWriting{$grp} = 1; # eg. 'MIE-Doc'
952 46 $isWriting{$grp1} = 1; # eg. 'MIE1-Doc2'
953 46 $isWriting{"MIE$n"} = 1; # eg. 'MIE1'
954  
955 # determine if we are deleting this group
956 46 ▶ if (%{$$et{DEL_GROUP}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$et->{"DEL_GROUP"};}) 9 37 46
957 $delGroup = 1 if $$et{DEL_GROUP}{MIE} or
958 $$et{DEL_GROUP}{$grp} or
959 $$et{DEL_GROUP}{$grp1} or
960 9 ▶ $$et{DEL_GROUP}{"MIE$n"};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"DEL_GROUP"}{"MIE"} or $et->{"DEL_GROUP"}{$grp} or $et->{"DEL_GROUP"}{$grp1} or $et->{"DEL_GROUP"}{"MIE$n"} 0 9 9
Condition33%3/9
$et->{"DEL_GROUP"}{"MIE"} or $et->{"DEL_GROUP"}{$grp} or $et->{"DEL_GROUP"}{$grp1} or $et->{"DEL_GROUP"}{"MIE$n"}
l!l&&r!l&&!r
009
$et->{"DEL_GROUP"}{"MIE"} or $et->{"DEL_GROUP"}{$grp} or $et->{"DEL_GROUP"}{$grp1}
l!l&&r!l&&!r
009
$et->{"DEL_GROUP"}{"MIE"} or $et->{"DEL_GROUP"}{$grp}
l!l&&r!l&&!r
009
MC/DC0%0/4
$et->{"DEL_GROUP"}{"MIE"} or $et->{"DEL_GROUP"}{$grp} or $et->{"DEL_GROUP"}{$grp1} or $et->{"DEL_GROUP"}{"MIE$n"}
$et->{"DEL_GROUP"}{"MIE"} $et->{"DEL_GROUP"}{$grp} $et->{"DEL_GROUP"}{$grp1} $et->{"DEL_GROUP"}{"MIE$n"}
Truth table20%1/5
A or B or C or D
A= $et->{"DEL_GROUP"}{"MIE"}B= $et->{"DEL_GROUP"}{$grp}C= $et->{"DEL_GROUP"}{$grp1}D= $et->{"DEL_GROUP"}{"MIE$n"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
961 }
962  
963 # prepare lookups and lists for writing
964 46 my $newTags = $et->GetNewTagInfoHash($tagTablePtr);
965 46 my ($addDirs, $editDirs) = $et->GetAddDirHash($tagTablePtr, $dirName);
966 46 my @editTags = sort keys %$newTags, keys %$editDirs;
967 46 ▶ $verbose and print $out $raf ? 'Writing' : 'Creating', " $grp1:\n";
Branch: 2 branches
BranchTrueFalseTotal
$verbose and print $out $raf ? "Writing" : "Creating", " ${grp1}:\n" 0 46 46
$raf ? : 0 0 0
968  
969 # loop through elements in MIE group
970 46 MieElement: for (;;) {
971 139 my ($format, $tagLen, $valLen, $units, $oldHdr, $buff);
972 139 my $lastTag = $tag;
973 139 ▶ if ($raf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf) 125 14 139
974 # read first 4 bytes of element header
975 125 my $n = $raf->Read($oldHdr, 4);
976 125 ▶ if ($n != 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n != 4) 1 124 125
977 1 ▶ last if $n or defined $sync;
Branch: 1 branch
BranchTrueFalseTotal
if $n or defined $sync 0 1 1
Condition33%1/3
$n or defined $sync
l!l&&r!l&&!r
001
MC/DC0%0/2
$n or defined $sync
$n defined $sync
Truth table33%1/3
A or B
A= $nB= defined $sync
ABresult
1X1
011
000
978 1 undef $raf; # all done reading
979 1 $ok = 1;
980 }
981 }
982 139 ▶ if ($raf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf) { } 124 15 139
983 124 ($sync, $format, $tagLen, $valLen) = unpack('aC3', $oldHdr);
984 124 ▶ $sync eq '~' or $msg = 'Invalid sync byte', last;
Branch: 1 branch
BranchTrueFalseTotal
$sync eq "~" or $msg = "Invalid sync byte", last 124 0 124
985  
986 # read tag name
987 124 ▶ if ($tagLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagLen) { } 93 31 124
988 93 ▶ $raf->Read($tag, $tagLen) == $tagLen or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($tag, $tagLen) == $tagLen or last 93 0 93
989 93 $oldHdr .= $tag; # add tag to element header
990 93 ▶ $et->Warn("MIE tag '${tag}' out of sequence") if $tag lt $lastTag;
Branch: 1 branch
BranchTrueFalseTotal
if $tag lt $lastTag 0 93 93
991 # separate units from tag name if they exist
992 93 ▶ $units = $1 if $tag =~ s/\((.*)\)$//;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ s/\((.*)\)$// 1 92 93
993 } else {
994 31 $tag = '';
995 }
996  
997 # get multi-byte value length if necessary
998 124 ▶ if ($valLen > 252) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valLen > 252) 0 124 124
999 # calculate number of bytes in extended DataLength
1000 0 my $n = 1 << (256 - $valLen);
1001 0 ▶ $raf->Read($buff, $n) == $n or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $n) == $n or last 0 0 0
1002 0 $oldHdr .= $buff; # add to old header
1003 0 my $fmt = 'int' . ($n * 8) . 'u';
1004 0 $valLen = ReadValue(\$buff, 0, $fmt, 1, $n);
1005 0 ▶ if ($valLen > 0x7fffffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valLen > 2147483647) 0 0 0
1006 0 $msg = "Can't write $tag (DataLength > 2GB not yet supported)";
1007 0 last;
1008 }
1009 }
1010 # don't rewrite free bytes or information in deleted groups
1011 124 ▶ if ($format == 0x80 or ($delGroup and $tagLen and ($format & 0xf0) != 0x10)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format == 128 or $delGroup and $tagLen and ($format & 240) != 16) 0 124 124
Condition33%3/9
$format == 128 or $delGroup and $tagLen and ($format & 240) != 16
l!l&&r!l&&!r
00124
$delGroup and $tagLen and ($format & 240) != 16
!ll&&!rl&&r
12400
$delGroup and $tagLen
!ll&&!rl&&r
12400
MC/DC0%0/4
$format == 128 or $delGroup and $tagLen and ($format & 240) != 16
$format == 128 $delGroup $tagLen ($format & 240) != 16
Truth table20%1/5
A or B and C and D
A= $format == 128B= $delGroupC= $tagLenD= ($format & 240) != 16
ABCDresult
1XXX1
01111
00XX0
010X0
01100
1012 0 ▶ $raf->Seek($valLen, 1) or $msg = 'Seek error', last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($valLen, 1) or $msg = "Seek error", last 0 0 0
1013 0 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 0 0
1014 0 ▶ my $free = ($format == 0x80) ? ' free' : '';
Branch: 1 branch
BranchTrueFalseTotal
$format == 128 ? : 0 0 0
1015 0 print $out " - $grp1:$tag ($valLen$free bytes)\n";
1016 }
1017 0 ▶ ++$$et{CHANGED} if $delGroup;
Branch: 1 branch
BranchTrueFalseTotal
if $delGroup 0 0 0
1018 0 next;
1019 }
1020 } else {
1021 # no more elements to read
1022 15 $tagLen = $valLen = 0;
1023 15 $tag = '';
1024 }
1025 #
1026 # write necessary new tags and process directories
1027 #
1028 139 ▶ while (@editTags) {
Branch: 1 branch
BranchTrueFalseTotal
if (@editTags) 138 87 225
1029 138 ▶ last if $tagLen and $editTags[0] gt $tag;
Branch: 1 branch
BranchTrueFalseTotal
if $tagLen and $editTags[0] gt $tag 40 98 138
Condition100%3/3
$tagLen and $editTags[0] gt $tag
!ll&&!rl&&r
811740
MC/DC100%2/2
$tagLen and $editTags[0] gt $tag
$tagLen $editTags[0] gt $tag
Truth table100%3/3
A and B
A= $tagLenB= $editTags[0] gt $tag
ABresult
0X0
100
111
1030 # we are writing the new tag now
1031 98 my ($newVal, $writable, $oldVal, $newFormat, $compress);
1032 98 my $newTag = shift @editTags;
1033 98 ▶ length($newTag) > 255 and $et->Warn('Tag name too long'), next; # (just to be safe)
Branch: 1 branch
BranchTrueFalseTotal
length $newTag > 255 and $et->Warn("Tag name too long"), next 0 98 98
1034 98 my $newInfo = $$editDirs{$newTag};
1035 98 ▶ if ($newInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo) { } 38 60 98
1036 # create the new subdirectory or rewrite existing non-MIE directory
1037 38 my $subTablePtr = GetTagTable($newInfo->{SubDirectory}->{TagTable});
1038 38 ▶ unless ($subTablePtr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subTablePtr) 0 38 38
1039 0 $et->Warn("No tag table for $newTag $$newInfo{Name}");
1040 0 next;
1041 }
1042 38 my %subdirInfo;
1043 my $isMieGroup = ($$subTablePtr{WRITE_PROC} and
1044 38 ▶ $$subTablePtr{WRITE_PROC} eq \&ProcessMIE);
Condition66%2/3
$subTablePtr->{'WRITE_PROC'} && $subTablePtr->{'WRITE_PROC'} eq \&Image::ExifTool::MIE::ProcessMIE
!ll&&!rl&&r
01127
MC/DC50%1/2
$subTablePtr->{'WRITE_PROC'} && $subTablePtr->{'WRITE_PROC'} eq \&Image::ExifTool::MIE::ProcessMIE
$subTablePtr->{'WRITE_PROC'} $subTablePtr->{'WRITE_PROC'} eq \&Image::ExifTool::MIE::ProcessMIE
Truth table66%2/3
A && B
A= $subTablePtr->{'WRITE_PROC'}B= $subTablePtr->{'WRITE_PROC'} eq \&Image::ExifTool::MIE::ProcessMIE
ABresult
0X0
100
111
1045  
1046 38 ▶ if ($newTag eq $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newTag eq $tag) { } 11 27 38
1047 # make sure that either both or neither old and new tags are MIE groups
1048 11 ▶ if ($isMieGroup xor ($format & 0xf3) == 0x10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isMieGroup xor ($format & 243) == 16) 0 11 11
Condition25%1/4
$isMieGroup xor ($format & 243) == 16
l&&rl&&!r!l&&r!l&&!r
11000
MC/DC0%0/2
$isMieGroup xor ($format & 243) == 16
$isMieGroup ($format & 243) == 16
Truth table25%1/4
A xor B
A= $isMieGroupB= ($format & 243) == 16
ABresult
110
101
011
000
1049 0 $et->Warn("Tag '${tag}' not expected type");
1050 0 next; # don't write our new tag
1051 }
1052 # uncompress existing directory into $oldVal since we are editing it
1053 11 ▶ if ($format & 0x04) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format & 4) 0 11 11
1054 0 ▶ last unless HasZlib($et, 'edit');
Branch: 1 branch
BranchTrueFalseTotal
unless &HasZlib($et, "edit") 0 0 0
1055 0 ▶ $raf->Read($oldVal, $valLen) == $valLen or last MieElement;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($oldVal, $valLen) == $valLen or last MieElement 0 0 0
1056 0 my $stat;
1057 0 my $inflate = Compress::Zlib::inflateInit();
1058 0 ▶ $inflate and ($oldVal, $stat) = $inflate->inflate($oldVal);
Branch: 1 branch
BranchTrueFalseTotal
$inflate and ($oldVal, $stat) = $inflate->inflate($oldVal) 0 0 0
1059 0 ▶ unless ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) 0 0 0
Condition0%0/3
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
!ll&&!rl&&r
000
MC/DC0%0/2
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
$inflate $stat == Compress::Zlib::Z_STREAM_END()
Truth table0%0/3
A and B
A= $inflateB= $stat == Compress::Zlib::Z_STREAM_END()
ABresult
0X0
100
111
1060 0 $msg = "Error inflating $tag";
1061 0 last MieElement;
1062 }
1063 0 $compress = 1;
1064 0 $valLen = length $oldVal; # uncompressed value length
1065 }
1066 } else {
1067 # don't create this directory unless necessary
1068 27 ▶ next unless $$addDirs{$newTag};
Branch: 1 branch
BranchTrueFalseTotal
unless $addDirs->{$newTag} 7 20 27
1069 }
1070  
1071 31 ▶ if ($isMieGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isMieGroup) { } 25 6 31
1072 25 my $hdr;
1073 25 ▶ if ($newTag eq $tag) {
Branch: 2 branches
BranchTrueFalseTotal
if ($newTag eq $tag) { } 11 14 25
elsif ($optCompress and not $dirInfo->{'IsCompressed'}) { } 0 14 14
1074 # rewrite existing directory later unless it was compressed
1075 11 ▶ last unless $compress;
Branch: 1 branch
BranchTrueFalseTotal
unless $compress 11 0 11
1076 # rewrite directory to '$newVal'
1077 0 $newVal = '';
1078 0 %subdirInfo = (
1079 OutFile => \$newVal,
1080 RAF => File::RandomAccess->new(\$oldVal),
1081 );
1082 ▶ } elsif ($optCompress and not $$dirInfo{IsCompressed}) {
Condition33%1/3
$optCompress and not $dirInfo->{"IsCompressed"}
!ll&&!rl&&r
1400
MC/DC0%0/2
$optCompress and not $dirInfo->{"IsCompressed"}
$optCompress not $dirInfo->{"IsCompressed"}
Truth table33%1/3
A and not(B)
A= $optCompressB= not $dirInfo->{"IsCompressed"}
ABresult
0X0
100
111
1083 # write to memory so we can compress the new MIE group
1084 0 $compress = 1;
1085 0 %subdirInfo = (
1086 OutFile => \$newVal,
1087 );
1088 } else {
1089 14 $hdr = '~' . MIEGroupFormat(1) . chr(length($newTag)) .
1090 "\0" . $newTag;
1091 14 %subdirInfo = (
1092 OutFile => $outfile,
1093 ToWrite => $toWrite . $hdr,
1094 );
1095 }
1096 14 ▶ $subdirInfo{DirName} = $newInfo->{SubDirectory}->{DirName} || $newTag;
Condition33%1/3
$newInfo->{'SubDirectory'}{'DirName'} || $newTag
l!l&&r!l&&!r
1400
MC/DC0%0/2
$newInfo->{'SubDirectory'}{'DirName'} || $newTag
$newInfo->{'SubDirectory'}{'DirName'} $newTag
Truth table33%1/3
A || B
A= $newInfo->{'SubDirectory'}{'DirName'}B= $newTag
ABresult
1X1
011
000
1097 14 $subdirInfo{Parent} = $dirName;
1098 # don't compress elements of an already compressed group
1099 14 ▶ $subdirInfo{IsCompressed} = $$dirInfo{IsCompressed} || $compress;
Condition33%1/3
$dirInfo->{'IsCompressed'} || $compress
l!l&&r!l&&!r
0014
MC/DC0%0/2
$dirInfo->{'IsCompressed'} || $compress
$dirInfo->{'IsCompressed'} $compress
Truth table33%1/3
A || B
A= $dirInfo->{'IsCompressed'}B= $compress
ABresult
1X1
011
000
1100 14 $msg = WriteMIEGroup($et, \%subdirInfo, $subTablePtr);
1101 14 ▶ last MieElement if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 14 14
1102 # message is defined but empty if nothing was written
1103 14 ▶ if (defined $msg) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $msg) { } 2 12 14
elsif (not $compress) { } 12 0 12
elsif (length $newVal <= 4) { } 0 0 0
1104 2 undef $msg; # not a problem if nothing was written
1105 2 next;
1106 } elsif (not $compress) {
1107 # group was written already
1108 12 $toWrite = '';
1109 12 next;
1110 } elsif (length($newVal) <= 4) { # terminator only?
1111 0 ▶ $verbose and print $out "Deleted compressed $grp1 (empty)\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "Deleted compressed $grp1 (empty)\n" 0 0 0
1112 0 ▶ next MieElement if $newTag eq $tag; # deleting the directory
Branch: 1 branch
BranchTrueFalseTotal
if $newTag eq $tag 0 0 0
1113 0 next; # not creating the new directory
1114 }
1115 0 $writable = 'undef';
1116 0 $newFormat = MIEGroupFormat();
1117 } else {
1118 6 ▶ if ($newTag eq $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newTag eq $tag) 0 6 6
1119 0 ▶ unless ($compress) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($compress) 0 0 0
1120 # read and edit existing directory
1121 0 ▶ $raf->Read($oldVal, $valLen) == $valLen or last MieElement;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($oldVal, $valLen) == $valLen or last MieElement 0 0 0
1122 }
1123 %subdirInfo = (
1124 DataPt => \$oldVal,
1125 DataLen => $valLen,
1126 DirName => $$newInfo{Name},
1127 0 ▶ DataPos => $$dirInfo{IsCompressed} ? undef : $raf->Tell() - $valLen,
Branch: 1 branch
BranchTrueFalseTotal
$dirInfo->{'IsCompressed'} ? : 0 0 0
1128 DirStart=> 0,
1129 DirLen => $valLen,
1130 );
1131 # write Compact subdirectories if we will compress the data
1132 0 ▶ if (($compress or $optCompress or $$dirInfo{IsCompressed}) and
Branch: 1 branch
BranchTrueFalseTotal
if ($compress || $optCompress || $dirInfo->{"IsCompressed"} and eval { do { require Compress::Zlib } }) 0 0 0
Condition0%0/9
$compress || $optCompress || $dirInfo->{"IsCompressed"} and eval { do { require Compress::Zlib } }
!ll&&!rl&&r
000
$compress or $optCompress or $dirInfo->{"IsCompressed"}
l!l&&r!l&&!r
000
$compress or $optCompress
l!l&&r!l&&!r
000
MC/DC0%0/4
$compress || $optCompress || $dirInfo->{"IsCompressed"} and eval { do { require Compress::Zlib } }
$compress $optCompress $dirInfo->{"IsCompressed"} eval { do { require Compress::Zlib } }
Truth table0%0/7
A or B or C and D
A= $compressB= $optCompressC= $dirInfo->{"IsCompressed"}D= eval { do { require Compress::Zlib } }
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
1133 0 eval { require Compress::Zlib })
1134 {
1135 0 $subdirInfo{Compact} = 1;
1136 0 $subdirInfo{ReadOnly} = 1; # because XMP is not writable in place
1137 }
1138 }
1139 6 $subdirInfo{Parent} = $dirName;
1140 6 my $writeProc = $newInfo->{SubDirectory}->{WriteProc};
1141 # reset processed lookup to avoid errors in case of multiple EXIF blocks
1142 6 $$et{PROCESSED} = { };
1143 6 $newVal = $et->WriteDirectory(\%subdirInfo, $subTablePtr, $writeProc);
1144 6 ▶ if (defined $newVal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newVal) { } 5 1 6
1145 5 ▶ if ($newVal eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($newVal eq "") 0 5 5
1146 0 ▶ next MieElement if $newTag eq $tag; # deleting the directory
Branch: 1 branch
BranchTrueFalseTotal
if $newTag eq $tag 0 0 0
1147 0 next; # not creating the new directory
1148 }
1149 } else {
1150 1 ▶ next unless defined $oldVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $oldVal 1 0 1
1151 0 $newVal = $oldVal; # just copy over the old directory
1152 }
1153 5 $writable = 'undef';
1154 5 $newFormat = 0x00; # all other directories are 'undef' format
1155 }
1156 } else {
1157  
1158 # get the new tag information
1159 60 $newInfo = $$newTags{$newTag};
1160 60 my $nvHash = $et->GetNewValueHash($newInfo);
1161 60 my @newVals;
1162  
1163 # write information only to specified group
1164 60 my $writeGroup = $$nvHash{WriteGroup};
1165 60 ▶ last unless $isWriting{$writeGroup};
Branch: 1 branch
BranchTrueFalseTotal
unless $isWriting{$writeGroup} 0 60 60
1166  
1167 # if tag existed, must decide if we want to overwrite the value
1168 60 ▶ if ($newTag eq $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newTag eq $tag) { } 1 59 60
1169 1 my $isOverwriting;
1170 1 my $isList = $$newInfo{List};
1171 1 ▶ if ($isList) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isList) { } 0 1 1
1172 0 ▶ last if $$nvHash{CreateOnly};
Branch: 1 branch
BranchTrueFalseTotal
if $nvHash->{"CreateOnly"} 0 0 0
1173 0 $isOverwriting = -1; # force processing list elements individually
1174 } else {
1175 1 $isOverwriting = $et->IsOverwriting($nvHash);
1176 1 ▶ last unless $isOverwriting;
Branch: 1 branch
BranchTrueFalseTotal
unless $isOverwriting 0 1 1
1177 }
1178 1 my ($val, $cmpVal);
1179 1 ▶ if ($isOverwriting < 0 or $verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isOverwriting < 0 or $verbose > 1) 0 1 1
Condition33%1/3
$isOverwriting < 0 or $verbose > 1
l!l&&r!l&&!r
001
MC/DC0%0/2
$isOverwriting < 0 or $verbose > 1
$isOverwriting < 0 $verbose > 1
Truth table33%1/3
A or B
A= $isOverwriting < 0B= $verbose > 1
ABresult
1X1
011
000
1180 # check to be sure we can uncompress the value if necessary
1181 0 ▶ HasZlib($et, 'edit') or last if $format & 0x04;
Branch: 1 branch
BranchTrueFalseTotal
if $format & 4 0 0 0
Condition0%0/5
$format & 4 && (&HasZlib($et, 'edit') || (last))
!ll&&!rl&&r
000
&HasZlib($et, "edit") or last
l!l
00
MC/DC0%0/2
$format & 4 && (&HasZlib($et, 'edit') || (last))
$format & 4 &HasZlib($et, "edit")
Truth table0%0/3
A && B
A= $format & 4B= &HasZlib($et, "edit")
ABresult
0X0
100
111
1182 # read the old value
1183 0 ▶ $raf->Read($oldVal, $valLen) == $valLen or last MieElement;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($oldVal, $valLen) == $valLen or last MieElement 0 0 0
1184 # uncompress if necessary
1185 0 ▶ if ($format & 0x04) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format & 4) 0 0 0
1186 0 my $stat;
1187 0 my $inflate = Compress::Zlib::inflateInit();
1188 # must save original compressed value in case we decide
1189 # not to overwrite it later
1190 0 $cmpVal = $oldVal;
1191 0 ▶ $inflate and ($oldVal, $stat) = $inflate->inflate($oldVal);
Branch: 1 branch
BranchTrueFalseTotal
$inflate and ($oldVal, $stat) = $inflate->inflate($oldVal) 0 0 0
1192 0 ▶ unless ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) 0 0 0
Condition0%0/3
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
!ll&&!rl&&r
000
MC/DC0%0/2
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
$inflate $stat == Compress::Zlib::Z_STREAM_END()
Truth table0%0/3
A and B
A= $inflateB= $stat == Compress::Zlib::Z_STREAM_END()
ABresult
0X0
100
111
1193 0 $msg = "Error inflating $tag";
1194 0 last MieElement;
1195 }
1196 0 $valLen = length $oldVal; # update value length
1197 }
1198 # convert according to specified format
1199 0 ▶ my $formatStr = $mieFormat{$format & 0xfb} || 'undef';
Condition0%0/2
$mieFormat{$format & 251} || 'undef'
l!l
00
MC/DC0%0/1
$mieFormat{$format & 251} || 'undef'
$mieFormat{$format & 251}
Truth table0%0/2
A
A= $mieFormat{$format & 251}
Aresult
11
00
1200 0 $val = ReadMIEValue(\$oldVal, 0, $formatStr, undef, $valLen);
1201 0 ▶ if ($isOverwriting < 0 and defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isOverwriting < 0 and defined $val) 0 0 0
Condition0%0/3
$isOverwriting < 0 and defined $val
!ll&&!rl&&r
000
MC/DC0%0/2
$isOverwriting < 0 and defined $val
$isOverwriting < 0 defined $val
Truth table0%0/3
A and B
A= $isOverwriting < 0B= defined $val
ABresult
0X0
100
111
1202 # handle list values individually
1203 0 ▶ if ($isList) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isList) { } 0 0 0
1204 0 my (@vals, $v);
1205 0 ▶ if ($formatStr =~ /_list$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($formatStr =~ /_list$/) { } 0 0 0
1206 0 @vals = split "\0", $val;
1207 } else {
1208 0 @vals = $val;
1209 }
1210 # keep any list items that we aren't overwriting
1211 0 foreach $v (@vals) {
1212 0 ▶ next if $et->IsOverwriting($nvHash, $v);
Branch: 1 branch
BranchTrueFalseTotal
if $et->IsOverwriting($nvHash, $v) 0 0 0
1213 0 push @newVals, $v;
1214 }
1215 } else {
1216 # test to see if we really want to overwrite the value
1217 0 $isOverwriting = $et->IsOverwriting($nvHash, $val);
1218 }
1219 }
1220 }
1221 1 ▶ if ($isOverwriting) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isOverwriting) { } 1 0 1
1222 # skip the old value if we didn't read it already
1223 1 ▶ unless (defined $oldVal) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $oldVal) 1 0 1
1224 1 ▶ $raf->Seek($valLen, 1) or $msg = 'Seek error';
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($valLen, 1) or $msg = "Seek error" 1 0 1
1225 }
1226 1 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 1 1
1227 0 ▶ $val .= "($units)" if defined $units;
Branch: 1 branch
BranchTrueFalseTotal
if defined $units 0 0 0
1228 0 $et->VerboseValue("- $grp1:$$newInfo{Name}", $val);
1229 }
1230 1 $deletedTag = $tag; # remember that we deleted this tag
1231 1 ++$$et{CHANGED}; # we deleted the old value
1232 } else {
1233 0 ▶ if (defined $oldVal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oldVal) { } 0 0 0
1234 # write original compressed value
1235 0 ▶ $oldVal = $cmpVal if defined $cmpVal;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmpVal 0 0 0
1236 } else {
1237 0 ▶ $raf->Read($oldVal, $valLen) == $valLen or last MieElement;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($oldVal, $valLen) == $valLen or last MieElement 0 0 0
1238 }
1239 # write the old value now
1240 0 ▶ Write($outfile, $toWrite, $oldHdr, $oldVal) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $toWrite, $oldHdr, $oldVal) or $err = 1 0 0 0
1241 0 $toWrite = '';
1242 0 next MieElement;
1243 }
1244 1 ▶ unless (@newVals) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@newVals) 1 0 1
1245 # unshift the new tag info to write it later
1246 1 unshift @editTags, $newTag;
1247 1 next MieElement; # get next element from file
1248 }
1249 } else {
1250 # write new value if creating, or if List and list existed, or
1251 # if tag was previously deleted
1252 next unless $$nvHash{IsCreating} or
1253 59 ▶ ($newTag eq $lastTag and ($$newInfo{List} or $deletedTag eq $lastTag));
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash->{"IsCreating"} or $newTag eq $lastTag and $newInfo->{"List"} || $deletedTag eq $lastTag 0 59 59
Condition11%1/9
$nvHash->{"IsCreating"} or $newTag eq $lastTag and $newInfo->{"List"} || $deletedTag eq $lastTag
l!l&&r!l&&!r
5900
$newTag eq $lastTag and $newInfo->{"List"} || $deletedTag eq $lastTag
!ll&&!rl&&r
000
$newInfo->{"List"} or $deletedTag eq $lastTag
l!l&&r!l&&!r
000
MC/DC0%0/4
$nvHash->{"IsCreating"} or $newTag eq $lastTag and $newInfo->{"List"} || $deletedTag eq $lastTag
$nvHash->{"IsCreating"} $newTag eq $lastTag $newInfo->{"List"} $deletedTag eq $lastTag
Truth table20%1/5
A or B and C or D
A= $nvHash->{"IsCreating"}B= $newTag eq $lastTagC= $newInfo->{"List"}D= $deletedTag eq $lastTag
ABCDresult
1XXX1
011X1
01011
00XX0
01000
1254 }
1255 # get the new value to write (undef to delete)
1256 59 push @newVals, $et->GetNewValue($nvHash);
1257 59 ▶ next unless @newVals;
Branch: 1 branch
BranchTrueFalseTotal
unless @newVals 0 59 59
1258 59 ▶ $writable = $$newInfo{Writable} || $$tagTablePtr{WRITABLE};
Condition66%2/3
$newInfo->{'Writable'} || $tagTablePtr->{'WRITABLE'}
l!l&&r!l&&!r
19400
MC/DC0%0/2
$newInfo->{'Writable'} || $tagTablePtr->{'WRITABLE'}
$newInfo->{'Writable'} $tagTablePtr->{'WRITABLE'}
Truth table66%2/3
A || B
A= $newInfo->{'Writable'}B= $tagTablePtr->{'WRITABLE'}
ABresult
1X1
011
000
1259 59 ▶ if ($writable eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($writable eq 'string') { } 40 19 59
1260 # join multiple values into a single string
1261 40 $newVal = join "\0", @newVals;
1262 # write string as UTF-8,16 or 32 if value contains valid UTF-8 codes
1263 40 my $isUTF8 = Image::ExifTool::IsUTF8(\$newVal);
1264 40 ▶ if ($isUTF8 > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isUTF8 > 0) 9 31 40
1265 9 $writable = 'utf8';
1266 # write UTF-16 or UTF-32 if it is more compact
1267 9 ▶ my $to = $isUTF8 > 1 ? 'UCS4' : 'UTF16';
Branch: 1 branch
BranchTrueFalseTotal
$isUTF8 > 1 ? : 0 9 9
1268 9 my $tmp = Image::ExifTool::Decode(undef,$newVal,'UTF8',undef,$to);
1269 9 ▶ if (length $tmp < length $newVal) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $tmp < length $newVal) 3 6 9
1270 3 $newVal = $tmp;
1271 3 ▶ $writable = ($isUTF8 > 1) ? 'utf32' : 'utf16';
Branch: 1 branch
BranchTrueFalseTotal
$isUTF8 > 1 ? : 0 3 3
1272 }
1273 }
1274 # write as a list if we have multiple values
1275 40 ▶ $writable .= '_list' if @newVals > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @newVals > 1 1 39 40
1276 } else {
1277 # should only be one element in the list
1278 19 $newVal = shift @newVals;
1279 }
1280 59 $newFormat = $mieCode{$writable};
1281 59 ▶ unless (defined $newFormat) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $newFormat) 0 59 59
1282 0 $msg = "Bad format '${writable}' for $$newInfo{Name}";
1283 0 next MieElement;
1284 }
1285 }
1286  
1287 # write the new or edited element
1288 64 ▶ while (defined $newFormat) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newFormat) 64 0 64
1289 64 my $valPt = \$newVal;
1290 # remove units from value and add to tag name if supported by this tag
1291 64 ▶ if ($$newInfo{Units}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newInfo->{"Units"}) 1 63 64
1292 1 my $val2;
1293 1 ▶ if ($$valPt =~ /(.*)\((.*)\)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$valPt =~ /(.*)\((.*)\)$/) { } 1 0 1
1294 1 $val2 = $1;
1295 1 $newTag .= "($2)";
1296 } else {
1297 0 $val2 = $$valPt;
1298 # add default units
1299 0 my $ustr = '(' . $newInfo->{Units}->[0] . ')';
1300 0 $newTag .= $ustr;
1301 0 $$valPt .= $ustr;
1302 }
1303 1 $valPt = \$val2;
1304 }
1305 # convert value if necessary
1306 64 ▶ if ($writable !~ /^(utf|string|undef)/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($writable =~ /^(utf|string|undef)/) 17 47 64
1307 17 my $val3 = WriteValue($$valPt, $writable, $$newInfo{Count});
1308 17 ▶ defined $val3 or $et->Warn("Error writing $newTag"), last;
Branch: 1 branch
BranchTrueFalseTotal
defined $val3 or $et->Warn("Error writing $newTag"), last 17 0 17
1309 17 $valPt = \$val3;
1310 }
1311 64 my $len = length $$valPt;
1312 # compress value before writing if required
1313 64 ▶ if (($compress or $optCompress) and not $$dirInfo{IsCompressed} and
Branch: 1 branch
BranchTrueFalseTotal
if ($compress || $optCompress and not $dirInfo->{"IsCompressed"} and &HasZlib($et, "write")) 0 64 64
Condition33%3/9
$compress || $optCompress and not $dirInfo->{"IsCompressed"} and &HasZlib($et, "write")
!ll&&!rl&&r
6400
$compress || $optCompress and not $dirInfo->{"IsCompressed"}
!ll&&!rl&&r
6400
$compress or $optCompress
l!l&&r!l&&!r
0064
MC/DC0%0/4
$compress || $optCompress and not $dirInfo->{"IsCompressed"} and &HasZlib($et, "write")
$compress $optCompress not $dirInfo->{"IsCompressed"} &HasZlib($et, "write")
Truth table14%1/7
A or B and not(C) and D
A= $compressB= $optCompressC= not $dirInfo->{"IsCompressed"}D= &HasZlib($et, "write")
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
1314 HasZlib($et, 'write'))
1315 {
1316 0 my $deflate = Compress::Zlib::deflateInit();
1317 0 my $val4;
1318 0 ▶ if ($deflate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deflate) 0 0 0
1319 0 $val4 = $deflate->deflate($$valPt);
1320 0 ▶ $val4 .= $deflate->flush() if defined $val4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val4 0 0 0
1321 }
1322 0 ▶ if (defined $val4) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val4) { } 0 0 0
1323 0 my $len4 = length $val4;
1324 0 my $saved = $len - $len4;
1325 # only use compressed data if it is smaller
1326 0 ▶ if ($saved > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($saved > 0) { } 0 0 0
elsif ($verbose) { } 0 0 0
1327 0 ▶ $verbose and print $out " [$newTag compression saved $saved bytes]\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " [$newTag compression saved $saved bytes]\n" 0 0 0
1328 0 $newFormat |= 0x04; # set compressed bit
1329 0 $len = $len4; # set length
1330 0 $valPt = \$val4; # set value pointer
1331 } elsif ($verbose) {
1332 0 print $out " [$newTag compression saved $saved bytes -- written uncompressed]\n";
1333 }
1334 } else {
1335 0 $et->Warn("Error deflating $newTag (written uncompressed)");
1336 }
1337 }
1338 # calculate the DataLength code
1339 64 my $extLen;
1340 64 ▶ if ($len < 253) {
Branch: 3 branches
BranchTrueFalseTotal
if ($len < 253) { } 61 3 64
elsif ($len < 65536) { } 3 0 3
elsif ($len <= 2147483647) { } 0 0 0
1341 61 $extLen = '';
1342 } elsif ($len < 65536) {
1343 3 $extLen = Set16u($len);
1344 3 $len = 255;
1345 } elsif ($len <= 0x7fffffff) {
1346 0 $extLen = Set32u($len);
1347 0 $len = 254;
1348 } else {
1349 0 $et->Warn("Can't write $newTag (DataLength > 2GB not yet supported)");
1350 0 last; # don't write this tag
1351 }
1352 # write this element (with leading MIE group element if not done already)
1353 64 my $hdr = $toWrite . '~' . chr($newFormat) . chr(length $newTag);
1354 64 ▶ Write($outfile, $hdr, chr($len), $newTag, $extLen, $$valPt) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hdr, chr $len, $newTag, $extLen, $$valPt) or $err = 1 64 0 64
1355 64 $toWrite = '';
1356 # we changed a tag unless just editing a subdirectory
1357 64 ▶ unless ($$editDirs{$newTag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($editDirs->{$newTag}) 59 5 64
1358 59 $et->VerboseValue("+ $grp1:$$newInfo{Name}", $newVal);
1359 59 ++$$et{CHANGED};
1360 }
1361 64 last; # didn't want to loop anyway
1362 }
1363 64 ▶ next MieElement if defined $oldVal;
Branch: 1 branch
BranchTrueFalseTotal
if defined $oldVal 0 64 64
1364 }
1365 #
1366 # rewrite existing element or descend into uncompressed MIE group
1367 #
1368 # all done this MIE group if we reached the terminator element
1369 138 ▶ unless ($tagLen) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagLen) 46 92 138
1370 # skip over existing terminator data (if any)
1371 46 ▶ last if $valLen and not $raf->Seek($valLen, 1);
Branch: 1 branch
BranchTrueFalseTotal
if $valLen and not $raf->Seek($valLen, 1) 0 46 46
Condition66%2/3
$valLen and not $raf->Seek($valLen, 1)
!ll&&!rl&&r
3880
MC/DC0%0/2
$valLen and not $raf->Seek($valLen, 1)
$valLen not $raf->Seek($valLen, 1)
Truth table66%2/3
A and not(B)
A= $valLenB= not $raf->Seek($valLen, 1)
ABresult
0X0
100
111
1372 46 $ok = 1;
1373 # write group terminator if necessary
1374 46 ▶ unless ($toWrite) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($toWrite) 44 2 46
1375 # write end-of-group terminator element
1376 44 my $term = "~\0\0\0";
1377 44 ▶ unless ($$dirInfo{Parent}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirInfo->{"Parent"}) 9 35 44
1378 # write extended terminator for file-level group
1379 9 ▶ my $len = ref $outfile eq 'SCALAR' ? length($$outfile) || 0 : tell $outfile;
Branch: 1 branch
BranchTrueFalseTotal
ref $outfile eq 'SCALAR' ? : 7 2 9
Condition50%1/2
length $$outfile or 0
l!l
70
MC/DC0%0/1
length $$outfile or 0
length $$outfile
Truth table50%1/2
A
A= length $$outfile
Aresult
11
00
1380 # include length of terminator itself minus original $outfile position
1381 9 ▶ $len += 10 - ($$dirInfo{OutPos} || 0);
Condition50%1/2
$dirInfo->{'OutPos'} || 0
l!l
09
MC/DC0%0/1
$dirInfo->{'OutPos'} || 0
$dirInfo->{'OutPos'}
Truth table50%1/2
A
A= $dirInfo->{'OutPos'}
Aresult
11
00
1382 9 ▶ if ($len and $len <= 0x7fffffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len and $len <= 2147483647) 9 0 9
Condition33%1/3
$len and $len <= 2147483647
!ll&&!rl&&r
009
MC/DC0%0/2
$len and $len <= 2147483647
$len $len <= 2147483647
Truth table33%1/3
A and B
A= $lenB= $len <= 2147483647
ABresult
0X0
100
111
1383 9 $term = "~\0\0\x06" . Set32u($len) . MIEGroupFormat(1) . "\x04";
1384 }
1385 }
1386 44 ▶ Write($outfile, $term) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $term) or $err = 1 44 0 44
1387 }
1388 46 last;
1389 }
1390  
1391 # descend into existing uncompressed MIE group
1392 92 ▶ if ($format == 0x10 or $format == 0x18) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format == 16 or $format == 24) 23 69 92
Condition66%2/3
$format == 16 or $format == 24
l!l&&r!l&&!r
23069
MC/DC50%1/2
$format == 16 or $format == 24
$format == 16 $format == 24
Truth table66%2/3
A or B
A= $format == 16B= $format == 24
ABresult
1X1
011
000
1393 23 my ($subTablePtr, $dirName);
1394 23 my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
1395 23 ▶ if ($tagInfo and $$tagInfo{SubDirectory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo and $tagInfo->{'SubDirectory'}) { } 23 0 23
Condition33%1/3
$tagInfo and $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
0023
MC/DC0%0/2
$tagInfo and $tagInfo->{"SubDirectory"}
$tagInfo $tagInfo->{"SubDirectory"}
Truth table33%1/3
A and B
A= $tagInfoB= $tagInfo->{"SubDirectory"}
ABresult
0X0
100
111
1396 23 $dirName = $tagInfo->{SubDirectory}->{DirName};
1397 23 my $subTable = $tagInfo->{SubDirectory}->{TagTable};
1398 23 ▶ $subTablePtr = $subTable ? GetTagTable($subTable) : $tagTablePtr;
Branch: 1 branch
BranchTrueFalseTotal
$subTable ? : 23 0 23
1399 } else {
1400 0 $subTablePtr = GetTagTable('Image::ExifTool::MIE::Unknown');
1401 }
1402 23 my $hdr = '~' . chr($format) . chr(length $tag) . "\0" . $tag;
1403 my %subdirInfo = (
1404 DirName => $dirName || $tag,
1405 RAF => $raf,
1406 ToWrite => $toWrite . $hdr,
1407 OutFile => $outfile,
1408 Parent => $dirName,
1409 IsCompressed => $$dirInfo{IsCompressed},
1410 23 ▶ );
Condition33%1/3
$dirName || $tag
l!l&&r!l&&!r
2300
MC/DC0%0/2
$dirName || $tag
$dirName $tag
Truth table33%1/3
A || B
A= $dirNameB= $tag
ABresult
1X1
011
000
1411 23 my $oldOrder = GetByteOrder();
1412 23 ▶ SetByteOrder($format & 0x08 ? 'II' : 'MM');
Branch: 1 branch
BranchTrueFalseTotal
$format & 8 ? : 0 23 23
1413 23 $msg = WriteMIEGroup($et, \%subdirInfo, $subTablePtr);
1414 23 SetByteOrder($oldOrder);
1415 23 ▶ last if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 23 23
1416 23 ▶ if (defined $msg) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $msg) { } 0 23 23
1417 0 undef $msg; # no problem if nothing written
1418 } else {
1419 23 $toWrite = '';
1420 }
1421 23 next;
1422 }
1423 # just copy existing element
1424 69 my $oldVal;
1425 69 ▶ $raf->Read($oldVal, $valLen) == $valLen or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($oldVal, $valLen) == $valLen or last 69 0 69
1426 69 ▶ if ($toWrite) {
Branch: 1 branch
BranchTrueFalseTotal
if ($toWrite) 15 54 69
1427 15 ▶ Write($outfile, $toWrite) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $toWrite) or $err = 1 15 0 15
1428 15 $toWrite = '';
1429 }
1430 69 ▶ Write($outfile, $oldHdr, $oldVal) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $oldHdr, $oldVal) or $err = 1 69 0 69
1431 }
1432 # return error message
1433 46 ▶ if ($err) {
Branch: 3 branches
BranchTrueFalseTotal
if ($err) { } 0 46 46
elsif (not $ok || $msg) { } 0 46 46
elsif (not $msg and $toWrite) { } 2 44 46
1434 0 $msg = 'Error writing file';
1435 ▶ } elsif (not $ok and not $msg) {
Condition33%1/3
$ok || $msg
l!l&&r!l&&!r
4600
MC/DC0%0/2
$ok || $msg
$ok $msg
Truth table33%1/3
A || B
A= $okB= $msg
ABresult
1X1
011
000
1436 0 $msg = 'Unexpected end of file';
1437 ▶ } elsif (not $msg and $toWrite) {
Condition66%2/3
not $msg and $toWrite
!ll&&!rl&&r
0442
MC/DC50%1/2
not $msg and $toWrite
not $msg $toWrite
Truth table66%2/3
not(A) and B
A= not $msgB= $toWrite
ABresult
0X0
100
111
1438 2 $msg = ''; # flag for nothing written
1439 2 ▶ $verbose and print $out "Deleted $grp1 (empty)\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "Deleted $grp1 (empty)\n" 0 2 2
1440 }
1441 46 return $msg;
1442 }
1443  
1444 #------------------------------------------------------------------------------
1445 # Process MIE directory
1446 # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) tag table ref
1447 # Returns: undef on success, or error message if there was a problem
1448 # Notes: file pointer is positioned at the MIE end on entry
1449 sub ProcessMIEGroup($$$)
1450 140 ▶{
Subroutine ProcessMIEGroup: called CC=74 SCAR=58.1
Pod undocumented
1451 140 my ($et, $dirInfo, $tagTablePtr) = @_;
1452 140 my $raf = $$dirInfo{RAF};
1453 140 my $verbose = $et->Options('Verbose');
1454 140 my $out = $et->Options('TextOut');
1455 140 my $notUTF8 = ($$et{OPTIONS}{Charset} ne 'UTF8');
1456 140 my ($msg, $buff, $ok, $oldIndent, $mime);
1457 140 my $lastTag = '';
1458  
1459 # get group 1 names: $grp doesn't have numbers (eg. 'MIE-Doc'),
1460 # and $grp1 does (eg. 'MIE1-Doc1')
1461 140 my $cnt = $$et{MIE_COUNT};
1462 140 my $grp1 = $tagTablePtr->{GROUPS}->{1};
1463 140 ▶ my $n = $$cnt{'MIE-Main'} || 0;
Condition100%2/2
$cnt->{'MIE-Main'} || 0
l!l
11327
MC/DC100%1/1
$cnt->{'MIE-Main'} || 0
$cnt->{'MIE-Main'}
Truth table100%2/2
A
A= $cnt->{'MIE-Main'}
Aresult
11
00
1464 140 ▶ if ($grp1 eq 'MIE-Main') {
Branch: 1 branch
BranchTrueFalseTotal
if ($grp1 eq 'MIE-Main') { } 27 113 140
1465 27 $$cnt{$grp1} = ++$n;
1466 27 ▶ $grp1 =~ s/MIE-/MIE$n-/ if $n > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 1 0 27 27
1467 } else {
1468 113 ▶ $grp1 =~ s/MIE-/MIE$n-/ if $n > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 1 0 113 113
1469 113 ▶ $$cnt{$grp1} = ($$cnt{$grp1} || 0) + 1;
Condition50%1/2
$cnt->{$grp1} || 0
l!l
0113
MC/DC0%0/1
$cnt->{$grp1} || 0
$cnt->{$grp1}
Truth table50%1/2
A
A= $cnt->{$grp1}
Aresult
11
00
1470 113 ▶ $grp1 .= $$cnt{$grp1} if $$cnt{$grp1} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $cnt->{$grp1} > 1 0 113 113
1471 }
1472 # set group1 name for all tags extracted from this group
1473 140 $$et{SET_GROUP1} = $grp1;
1474  
1475 140 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 140 140
1476 0 $oldIndent = $$et{INDENT};
1477 0 $$et{INDENT} .= '| ';
1478 0 $et->VerboseDir($grp1);
1479 }
1480 140 my $wasCompressed = $$dirInfo{WasCompressed};
1481  
1482 # process all MIE elements
1483 140 for (;;) {
1484 746 ▶ $raf->Read($buff, 4) == 4 or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 4) == 4 or last 746 0 746
1485 746 my ($sync, $format, $tagLen, $valLen) = unpack('aC3', $buff);
1486 746 ▶ $sync eq '~' or $msg = 'Invalid sync byte', last;
Branch: 1 branch
BranchTrueFalseTotal
$sync eq "~" or $msg = "Invalid sync byte", last 746 0 746
1487  
1488 # read tag name
1489 746 my ($tag, $units);
1490 746 ▶ if ($tagLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagLen) { } 606 140 746
1491 606 ▶ $raf->Read($tag, $tagLen) == $tagLen or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($tag, $tagLen) == $tagLen or last 606 0 606
1492 606 ▶ $et->Warn("MIE tag '${tag}' out of sequence") if $tag lt $lastTag;
Branch: 1 branch
BranchTrueFalseTotal
if $tag lt $lastTag 0 606 606
1493 606 $lastTag = $tag;
1494 # separate units from tag name if they exist
1495 606 ▶ $units = $1 if $tag =~ s/\((.*)\)$//;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ s/\((.*)\)$// 8 598 606
1496 } else {
1497 140 $tag = '';
1498 }
1499  
1500 # get multi-byte value length if necessary
1501 746 ▶ if ($valLen > 252) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valLen > 252) 3 743 746
1502 3 my $n = 1 << (256 - $valLen);
1503 3 ▶ $raf->Read($buff, $n) == $n or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $n) == $n or last 3 0 3
1504 3 my $fmt = 'int' . ($n * 8) . 'u';
1505 3 $valLen = ReadValue(\$buff, 0, $fmt, 1, $n);
1506 3 ▶ if ($valLen > 0x7fffffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valLen > 2147483647) 0 3 3
1507 0 $msg = "Can't read $tag (DataLength > 2GB not yet supported)";
1508 0 last;
1509 }
1510 }
1511  
1512 # all done if we reached the group terminator
1513 746 ▶ unless ($tagLen) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagLen) 140 606 746
1514 # skip over terminator data block
1515 140 ▶ $ok = 1 unless $valLen and not $raf->Seek($valLen, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $valLen and not $raf->Seek($valLen, 1) 140 0 140
Condition66%2/3
$valLen and not $raf->Seek($valLen, 1)
!ll&&!rl&&r
113270
MC/DC0%0/2
$valLen and not $raf->Seek($valLen, 1)
$valLen not $raf->Seek($valLen, 1)
Truth table66%2/3
A and not(B)
A= $valLenB= not $raf->Seek($valLen, 1)
ABresult
0X0
100
111
1516 140 last;
1517 }
1518  
1519 # get tag information hash unless this is free space
1520 606 my ($tagInfo, $value);
1521 606 ▶ while ($format != 0x80) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format != 128) 606 0 606
1522 606 $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
1523 606 ▶ last if $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo 570 36 606
1524 # extract tags with locale code
1525 36 ▶ if ($tag =~ /\W/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /\W/) 36 0 36
1526 36 ▶ if ($tag =~ /^(\w+)-([a-z]{2}_[A-Z]{2})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^(\w+)-([a-z]{2}_[A-Z]{2})$/) { } 36 0 36
1527 36 my ($baseTag, $langCode) = ($1, $2);
1528 36 $tagInfo = $et->GetTagInfo($tagTablePtr, $baseTag);
1529 36 ▶ $tagInfo = GetLangInfo($tagInfo, $langCode) if $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo 36 0 36
1530 36 ▶ last if $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo 36 0 36
1531 } else {
1532 0 $et->Warn('Invalid MIE tag name');
1533 0 last;
1534 }
1535 }
1536 # extract unknown tags if specified
1537 $tagInfo = {
1538 0 Name => $tag,
1539 Writable => 0,
1540 PrintConv => \&Image::ExifTool::LimitLongValues,
1541 };
1542 0 AddTagToTable($tagTablePtr, $tag, $tagInfo);
1543 0 last;
1544 }
1545  
1546 # read value and uncompress if necessary
1547 606 ▶ my $formatStr = $mieFormat{$format & 0xfb} || 'undef';
Condition50%1/2
$mieFormat{$format & 251} || 'undef'
l!l
6060
MC/DC0%0/1
$mieFormat{$format & 251} || 'undef'
$mieFormat{$format & 251}
Truth table50%1/2
A
A= $mieFormat{$format & 251}
Aresult
11
00
1548 606 ▶ if ($tagInfo or ($formatStr eq 'MIE' and $format & 0x04)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo or $formatStr eq "MIE" and $format & 4) 606 0 606
Condition16%1/6
$tagInfo or $formatStr eq "MIE" and $format & 4
l!l&&r!l&&!r
60600
$formatStr eq "MIE" and $format & 4
!ll&&!rl&&r
000
MC/DC0%0/3
$tagInfo or $formatStr eq "MIE" and $format & 4
$tagInfo $formatStr eq "MIE" $format & 4
Truth table25%1/4
A or B and C
A= $tagInfoB= $formatStr eq "MIE"C= $format & 4
ABCresult
1XX1
0111
00X0
0100
1549 606 ▶ $raf->Read($value, $valLen) == $valLen or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($value, $valLen) == $valLen or last 606 0 606
1550 606 ▶ if ($format & 0x04) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format & 4) 0 606 606
1551 0 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
1552 0 print $out "$$et{INDENT}\[Tag '${tag}' $valLen bytes compressed]\n";
1553 }
1554 0 ▶ next unless HasZlib($et, 'decode');
Branch: 1 branch
BranchTrueFalseTotal
unless &HasZlib($et, "decode") 0 0 0
1555 0 my $stat;
1556 0 my $inflate = Compress::Zlib::inflateInit();
1557 0 ▶ $inflate and ($value, $stat) = $inflate->inflate($value);
Branch: 1 branch
BranchTrueFalseTotal
$inflate and ($value, $stat) = $inflate->inflate($value) 0 0 0
1558 0 ▶ unless ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) 0 0 0
Condition0%0/3
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
!ll&&!rl&&r
000
MC/DC0%0/2
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
$inflate $stat == Compress::Zlib::Z_STREAM_END()
Truth table0%0/3
A and B
A= $inflateB= $stat == Compress::Zlib::Z_STREAM_END()
ABresult
0X0
100
111
1559 0 $et->Warn("Error inflating $tag");
1560 0 next;
1561 }
1562 0 $valLen = length $value;
1563 0 $wasCompressed = 1;
1564 }
1565 }
1566  
1567 # process this tag
1568 606 ▶ if ($formatStr eq 'MIE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($formatStr eq 'MIE') { } 113 493 606
1569 # process MIE directory
1570 113 my ($subTablePtr, $dirName);
1571 113 ▶ if ($tagInfo and $$tagInfo{SubDirectory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo and $tagInfo->{'SubDirectory'}) { } 113 0 113
Condition33%1/3
$tagInfo and $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
00113
MC/DC0%0/2
$tagInfo and $tagInfo->{"SubDirectory"}
$tagInfo $tagInfo->{"SubDirectory"}
Truth table33%1/3
A and B
A= $tagInfoB= $tagInfo->{"SubDirectory"}
ABresult
0X0
100
111
1572 113 $dirName = $tagInfo->{SubDirectory}->{DirName};
1573 113 my $subTable = $tagInfo->{SubDirectory}->{TagTable};
1574 113 ▶ $subTablePtr = $subTable ? GetTagTable($subTable) : $tagTablePtr;
Branch: 1 branch
BranchTrueFalseTotal
$subTable ? : 113 0 113
1575 } else {
1576 0 $subTablePtr = GetTagTable('Image::ExifTool::MIE::Unknown');
1577 }
1578 113 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 113 113
1579 0 my $order = ', byte order ' . GetByteOrder();
1580 0 $et->VerboseInfo($tag, $tagInfo, Size => $valLen, Extra => $order);
1581 }
1582 my %subdirInfo = (
1583 DirName => $dirName || $tag,
1584 RAF => $raf,
1585 Parent => $$dirInfo{DirName},
1586 113 ▶ WasCompressed => $wasCompressed,
Condition33%1/3
$dirName || $tag
l!l&&r!l&&!r
11300
MC/DC0%0/2
$dirName || $tag
$dirName $tag
Truth table33%1/3
A || B
A= $dirNameB= $tag
ABresult
1X1
011
000
1587 );
1588 # read from uncompressed data instead if necessary
1589 113 ▶ $subdirInfo{RAF} = File::RandomAccess->new(\$value) if $valLen;
Branch: 1 branch
BranchTrueFalseTotal
if $valLen 0 113 113
1590  
1591 113 my $oldOrder = GetByteOrder();
1592 113 ▶ SetByteOrder($format & 0x08 ? 'II' : 'MM');
Branch: 1 branch
BranchTrueFalseTotal
$format & 8 ? : 0 113 113
1593 113 $msg = ProcessMIEGroup($et, \%subdirInfo, $subTablePtr);
1594 113 SetByteOrder($oldOrder);
1595 113 $$et{SET_GROUP1} = $grp1; # restore this group1 name
1596 113 ▶ last if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 113 113
1597 } else {
1598 # process MIE data format types
1599 493 ▶ if ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo) { } 493 0 493
1600 493 my ($rational, $binVal);
1601 # extract tag value
1602 493 my $val = ReadMIEValue(\$value, 0, $formatStr, undef, $valLen, \$rational);
1603 493 ▶ $binVal = substr($value, 0, $valLen) if $$et{OPTIONS}{SaveBin};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"OPTIONS"}{"SaveBin"} 0 493 493
1604 493 ▶ unless (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 493 493
1605 0 $et->Warn("Error reading $tag value");
1606 0 $val = '<err>';
1607 }
1608 # save type or mime type
1609 493 ▶ $mime = $val if $tag eq '0Type' or $tag eq '2MIME';
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "0Type" or $tag eq "2MIME" 16 477 493
Condition100%3/3
$tag eq "0Type" or $tag eq "2MIME"
l!l&&r!l&&!r
88477
MC/DC100%2/2
$tag eq "0Type" or $tag eq "2MIME"
$tag eq "0Type" $tag eq "2MIME"
Truth table100%3/3
A or B
A= $tag eq "0Type"B= $tag eq "2MIME"
ABresult
1X1
011
000
1610 493 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 493 493
1611 0 my $count;
1612 0 my $s = Image::ExifTool::FormatSize($formatStr);
1613 0 ▶ if ($s and $formatStr !~ /^(utf|string|undef)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s and not $formatStr =~ /^(utf|string|undef)/) 0 0 0
Condition0%0/3
$s and not $formatStr =~ /^(utf|string|undef)/
!ll&&!rl&&r
000
MC/DC0%0/2
$s and not $formatStr =~ /^(utf|string|undef)/
$s not $formatStr =~ /^(utf|string|undef)/
Truth table0%0/3
A and not(B)
A= $sB= not $formatStr =~ /^(utf|string|undef)/
ABresult
0X0
100
111
1614 0 $count = $valLen / $s;
1615 }
1616 0 ▶ $et->VerboseInfo($lastTag, $tagInfo,
Branch: 1 branch
BranchTrueFalseTotal
$wasCompressed ? : 0 0 0
1617 DataPt => \$value,
1618 DataPos => $wasCompressed ? undef : $raf->Tell() - $valLen,
1619 Size => $valLen,
1620 Format => $formatStr,
1621 Value => $val,
1622 Count => $count,
1623 );
1624 }
1625 493 ▶ if ($$tagInfo{SubDirectory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'SubDirectory'}) { } 5 488 493
1626 5 my $subTablePtr = GetTagTable($tagInfo->{SubDirectory}->{TagTable});
1627 my %subdirInfo = (
1628 DirName => $$tagInfo{Name},
1629 DataPt => \$value,
1630 DataLen => $valLen,
1631 DirStart=> 0,
1632 DirLen => $valLen,
1633 Parent => $$dirInfo{DirName},
1634 5 WasCompressed => $wasCompressed,
1635 );
1636 # set DataPos and Base for uncompressed information only
1637 5 ▶ unless ($wasCompressed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($wasCompressed) 5 0 5
1638 5 $subdirInfo{DataPos} = 0; # (relative to Base)
1639 5 $subdirInfo{Base} = $raf->Tell() - $valLen;
1640 }
1641 # reset PROCESSED lookup for each MIE directory
1642 # (there is no possibility of double-processing a MIE directory)
1643 5 $$et{PROCESSED} = { };
1644 5 my $processProc = $tagInfo->{SubDirectory}->{ProcessProc};
1645 5 delete $$et{SET_GROUP1};
1646 5 delete $$et{NO_LIST};
1647 5 $et->ProcessDirectory(\%subdirInfo, $subTablePtr, $processProc);
1648 5 $$et{SET_GROUP1} = $grp1;
1649 5 $$et{NO_LIST} = 1;
1650 } else {
1651 # convert to specified character set if necessary
1652 488 ▶ if ($notUTF8 and $formatStr =~ /^(utf|string)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($notUTF8 and $formatStr =~ /^(utf|string)/) 117 371 488
Condition100%3/3
$notUTF8 and $formatStr =~ /^(utf|string)/
!ll&&!rl&&r
32051117
MC/DC100%2/2
$notUTF8 and $formatStr =~ /^(utf|string)/
$notUTF8 $formatStr =~ /^(utf|string)/
Truth table100%3/3
A and B
A= $notUTF8B= $formatStr =~ /^(utf|string)/
ABresult
0X0
100
111
1653 117 $val = $et->Decode($val, 'UTF8');
1654 }
1655 488 ▶ if ($formatStr =~ /_list$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($formatStr =~ /_list$/) 8 480 488
1656 # split list value into separate strings
1657 8 my @vals = split "\0", $val;
1658 8 $val = \@vals;
1659 }
1660 488 ▶ if (defined $units) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $units) 8 480 488
1661 8 ▶ $val = "@$val" if ref $val; # convert string list to number list
Branch: 1 branch
BranchTrueFalseTotal
if ref $val 0 8 8
1662 # add units to value if specified
1663 8 ▶ $val .= "($units)" if defined $units;
Branch: 1 branch
BranchTrueFalseTotal
if defined $units 8 0 8
1664 }
1665 488 my $key = $et->FoundTag($tagInfo, $val);
1666 488 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 488 0 488
1667 488 my $ex = $$et{TAG_EXTRA}{$key};
1668 488 ▶ $$ex{Rational} = $rational if defined $rational;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rational 65 423 488
1669 488 ▶ $$ex{BinVal} = $binVal if defined $binVal;
Branch: 1 branch
BranchTrueFalseTotal
if defined $binVal 0 488 488
1670 488 ▶ $$ex{G6} = $formatStr if $$et{OPTIONS}{SaveFormat};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"OPTIONS"}{"SaveFormat"} 0 488 488
1671 }
1672 }
1673 } else {
1674 # skip over unknown information or free bytes
1675 0 ▶ $raf->Seek($valLen, 1) or $msg = 'Seek error', last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($valLen, 1) or $msg = "Seek error", last 0 0 0
1676 0 ▶ $verbose and $et->VerboseInfo($tag, undef, Size => $valLen);
Branch: 1 branch
BranchTrueFalseTotal
$verbose and $et->VerboseInfo($tag, undef, "Size", $valLen) 0 0 0
1677 }
1678 }
1679 }
1680 # modify MIME type if necessary
1681 140 ▶ $mime and not $$dirInfo{Parent} and $et->ModifyMimeType($mime);
Branch: 1 branch
BranchTrueFalseTotal
$mime and not $dirInfo->{"Parent"} and $et->ModifyMimeType($mime) 8 132 140
Condition66%2/3
$mime and not $dirInfo->{"Parent"}
!ll&&!rl&&r
13208
MC/DC50%1/2
$mime and not $dirInfo->{"Parent"}
$mime not $dirInfo->{"Parent"}
Truth table66%2/3
A and not(B)
A= $mimeB= not $dirInfo->{"Parent"}
ABresult
0X0
100
111
1682  
1683 140 ▶ $ok or $msg or $msg = 'Unexpected end of file';
Branch: 1 branch
BranchTrueFalseTotal
$ok or $msg or $msg = "Unexpected end of file" 140 0 140
Condition33%1/3
$ok or $msg
l!l&&r!l&&!r
14000
MC/DC0%0/2
$ok or $msg
$ok $msg
Truth table33%1/3
A or B
A= $okB= $msg
ABresult
1X1
011
000
1684 140 ▶ $verbose and $$et{INDENT} = $oldIndent;
Branch: 1 branch
BranchTrueFalseTotal
$verbose and $et->{"INDENT"} = $oldIndent 0 140 140
1685 140 return $msg;
1686 }
1687  
1688 #------------------------------------------------------------------------------
1689 # Read/write a MIE file
1690 # Inputs: 0) ExifTool object reference, 1) DirInfo reference
1691 # Returns: 1 on success, 0 if this wasn't a valid MIE file, or -1 on write error
1692 # - process as a trailer if "Trailer" flag set in dirInfo
1693 sub ProcessMIE($$)
1694 708 ▶{
Subroutine ProcessMIE: called CC=52 SCAR=52.4
Pod undocumented
1695 708 my ($et, $dirInfo) = @_;
1696 708 ▶ return 1 unless defined $et;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $et 672 36 708
1697 36 my $raf = $$dirInfo{RAF};
1698 36 my $outfile = $$dirInfo{OutFile};
1699 36 my ($buff, $err, $msg, $pos, $end, $isCreating);
1700 36 my $numDocs = 0;
1701 #
1702 # process as a trailer (from end of file) if specified
1703 #
1704 36 ▶ if ($$dirInfo{Trailer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirInfo->{"Trailer"}) 26 10 36
1705 26 ▶ my $offset = $$dirInfo{Offset} || 0; # offset from end of file
Condition50%1/2
$dirInfo->{'Offset'} || 0
l!l
260
MC/DC0%0/1
$dirInfo->{'Offset'} || 0
$dirInfo->{'Offset'}
Truth table50%1/2
A
A= $dirInfo->{'Offset'}
Aresult
11
00
1706 26 ▶ $raf->Seek(-10 - $offset, 2) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek(-10 - $offset, 2) or return 0 26 0 26
1707 26 for (;;) {
1708 # read and validate last 10 bytes
1709 52 ▶ $raf->Read($buff, 10) == 10 or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 10) == 10 or last 52 0 52
1710 52 ▶ last unless $buff =~ /~\0\0\x06.{4}(\x10|\x18)(\x04)$/s or
Branch: 1 branch
BranchTrueFalseTotal
unless $buff =~ /~\0\0\x06.{4}(\x10|\x18)(\x04)$/s or $buff =~ /(\x10|\x18)(\x08)$/s 26 26 52
Condition66%2/3
$buff =~ /~\0\0\x06.{4}(\x10|\x18)(\x04)$/s or $buff =~ /(\x10|\x18)(\x08)$/s
l!l&&r!l&&!r
26026
MC/DC50%1/2
$buff =~ /~\0\0\x06.{4}(\x10|\x18)(\x04)$/s or $buff =~ /(\x10|\x18)(\x08)$/s
$buff =~ /~\0\0\x06.{4}(\x10|\x18)(\x04)$/s $buff =~ /(\x10|\x18)(\x08)$/s
Truth table66%2/3
A or B
A= $buff =~ /~\0\0\x06.{4}(\x10|\x18)(\x04)$/sB= $buff =~ /(\x10|\x18)(\x08)$/s
ABresult
1X1
011
000
1711 $buff =~ /(\x10|\x18)(\x08)$/s;
1712 26 ▶ SetByteOrder($1 eq "\x10" ? 'MM' : 'II');
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "\cP" ? : 26 0 26
1713 26 ▶ my $len = ($2 eq "\x04") ? Get32u(\$buff, 4) : Get64u(\$buff, 0);
Branch: 1 branch
BranchTrueFalseTotal
$2 eq "\cD" ? : 26 0 26
1714 26 ▶ my $curPos = $raf->Tell() or last;
Branch: 1 branch
BranchTrueFalseTotal
my $curPos = $raf->Tell or last 26 0 26
1715 26 ▶ last if $len < 12 or $len > $curPos;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 12 or $len > $curPos 0 26 26
Condition33%1/3
$len < 12 or $len > $curPos
l!l&&r!l&&!r
0026
MC/DC0%0/2
$len < 12 or $len > $curPos
$len < 12 $len > $curPos
Truth table33%1/3
A or B
A= $len < 12B= $len > $curPos
ABresult
1X1
011
000
1716 # validate element header if 8-byte offset was used
1717 26 ▶ if ($2 eq "\x08") {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq "\b") 0 26 26
1718 0 ▶ last if $len < 14;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 14 0 0 0
1719 0 ▶ $raf->Seek($curPos - 14, 0) and $raf->Read($buff, 4) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($curPos - 14, 0) and $raf->Read($buff, 4) or last 0 0 0
Condition0%0/3
$raf->Seek($curPos - 14, 0) and $raf->Read($buff, 4)
!ll&&!rl&&r
000
MC/DC0%0/2
$raf->Seek($curPos - 14, 0) and $raf->Read($buff, 4)
$raf->Seek($curPos - 14, 0) $raf->Read($buff, 4)
Truth table0%0/3
A and B
A= $raf->Seek($curPos - 14, 0)B= $raf->Read($buff, 4)
ABresult
0X0
100
111
1720 0 ▶ last unless $buff eq "~\0\0\x0a";
Branch: 1 branch
BranchTrueFalseTotal
unless $buff eq "~\0\0\n" 0 0 0
1721 }
1722 # looks like a good group, so remember start position
1723 26 $pos = $curPos - $len;
1724 26 ▶ $end = $curPos unless $end;
Branch: 1 branch
BranchTrueFalseTotal
unless $end 26 0 26
1725 # seek to 10 bytes from end of previous group
1726 26 ▶ $raf->Seek($pos - 10, 0) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($pos - 10, 0) or last 26 0 26
1727 }
1728 # seek to start of first MIE group
1729 26 ▶ return 0 unless defined $pos and $raf->Seek($pos, 0);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos and $raf->Seek($pos, 0) 0 26 26
Condition33%1/3
defined $pos and $raf->Seek($pos, 0)
!ll&&!rl&&r
0026
MC/DC0%0/2
defined $pos and $raf->Seek($pos, 0)
defined $pos $raf->Seek($pos, 0)
Truth table33%1/3
A and B
A= defined $posB= $raf->Seek($pos, 0)
ABresult
0X0
100
111
1730 # update DataPos and DirLen for ProcessTrailers()
1731 26 $$dirInfo{DataPos} = $pos;
1732 26 $$dirInfo{DirLen} = $end - $pos;
1733 26 ▶ if ($outfile and $$et{DEL_GROUP}{MIE}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($outfile and $et->{'DEL_GROUP'}{'MIE'}) { } 0 26 26
elsif ($et->Options('Verbose') or $et->{'HTML_DUMP'}) { } 0 26 26
Condition66%2/3
$outfile and $et->{"DEL_GROUP"}{"MIE"}
!ll&&!rl&&r
1970
MC/DC0%0/2
$outfile and $et->{"DEL_GROUP"}{"MIE"}
$outfile $et->{"DEL_GROUP"}{"MIE"}
Truth table66%2/3
A and B
A= $outfileB= $et->{"DEL_GROUP"}{"MIE"}
ABresult
0X0
100
111
1734 # delete the trailer
1735 0 $et->VPrint(0," Deleting MIE trailer\n");
1736 0 ++$$et{CHANGED};
1737 0 return 1;
1738 ▶ } elsif ($et->Options('Verbose') or $$et{HTML_DUMP}) {
Condition33%1/3
$et->Options("Verbose") or $et->{"HTML_DUMP"}
l!l&&r!l&&!r
0026
MC/DC0%0/2
$et->Options("Verbose") or $et->{"HTML_DUMP"}
$et->Options("Verbose") $et->{"HTML_DUMP"}
Truth table33%1/3
A or B
A= $et->Options("Verbose")B= $et->{"HTML_DUMP"}
ABresult
1X1
011
000
1739 0 $et->DumpTrailer($dirInfo);
1740 }
1741 }
1742 #
1743 # loop through all documents in MIE file
1744 #
1745 36 for (;;) {
1746 # look for "0MIE" group element
1747 72 my $num = $raf->Read($buff, 8);
1748 72 ▶ if ($num == 8) {
Branch: 2 branches
BranchTrueFalseTotal
if ($num == 8) { } 61 11 72
elsif ($numDocs) { } 10 1 11
1749 # verify file identifier
1750 61 ▶ if ($buff =~ /^~(\x10|\x18)\x04(.)0MIE/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buff =~ /^~(\x10|\x18)\x04(.)0MIE/s) { } 35 26 61
1751 35 ▶ SetByteOrder($1 eq "\x10" ? 'MM' : 'II');
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "\cP" ? : 35 0 35
1752 35 my $len = ord($2);
1753 # skip extended DataLength if it exists
1754 35 ▶ if ($len > 252 and not $raf->Seek(1 << (256 - $len), 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 252 and not $raf->Seek(1 << 256 - $len, 1)) 0 35 35
Condition33%1/3
$len > 252 and not $raf->Seek(1 << 256 - $len, 1)
!ll&&!rl&&r
0350
MC/DC0%0/2
$len > 252 and not $raf->Seek(1 << 256 - $len, 1)
$len > 252 not $raf->Seek(1 << 256 - $len, 1)
Truth table33%1/3
A and not(B)
A= $len > 252B= not $raf->Seek(1 << 256 - $len, 1)
ABresult
0X0
100
111
1755 0 $msg = 'Seek error';
1756 0 last;
1757 }
1758 } else {
1759 26 ▶ return 0 unless $numDocs; # not a MIE file
Branch: 1 branch
BranchTrueFalseTotal
unless $numDocs 0 26 26
1760 26 ▶ if ($buff =~ /^~/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buff =~ /^~/) { } 0 26 26
1761 0 $msg = 'Non-standard file-level MIE element';
1762 } else {
1763 26 $msg = 'Invalid MIE file-level data';
1764 }
1765 }
1766 } elsif ($numDocs) {
1767 10 ▶ last unless $num; # OK, all done with file
Branch: 1 branch
BranchTrueFalseTotal
unless $num 10 0 10
1768 0 $msg = 'Truncated MIE element header';
1769 } else {
1770 1 ▶ return 0 if $num or not $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if $num or not $outfile 0 1 1
Condition33%1/3
$num or not $outfile
l!l&&r!l&&!r
001
MC/DC0%0/2
$num or not $outfile
$num not $outfile
Truth table33%1/3
A or not(B)
A= $numB= not $outfile
ABresult
1X1
011
000
1771 # we have the ability to create a MIE file from scratch
1772 1 $buff = ''; # start from nothing
1773 # set byte order according to preferences
1774 1 $et->SetPreferredByteOrder();
1775 1 $isCreating = 1;
1776 }
1777 62 ▶ if ($msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 26 36 62
1778 26 ▶ last if $$dirInfo{Trailer}; # allow other trailers after MIE
Branch: 1 branch
BranchTrueFalseTotal
if $dirInfo->{"Trailer"} 26 0 26
1779 0 ▶ if ($outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile) { } 0 0 0
1780 0 $et->Error($msg);
1781 } else {
1782 0 $et->Warn($msg);
1783 }
1784 0 last;
1785 }
1786 # this is a new MIE document -- increment document count
1787 36 ▶ unless ($numDocs) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($numDocs) 36 0 36
1788 # this is a valid MIE file (unless a trailer on another file)
1789 36 $et->SetFileType();
1790 36 $$et{NO_LIST} = 1; # handle lists ourself
1791 36 $$et{MIE_COUNT} = { };
1792 36 undef $hasZlib;
1793 }
1794 36 ++$numDocs;
1795  
1796 # process the MIE groups recursively, beginning with the main MIE group
1797 36 my $tagTablePtr = GetTagTable('Image::ExifTool::MIE::Main');
1798  
1799 36 my %subdirInfo = (
1800 DirName => 'MIE',
1801 RAF => $raf,
1802 OutFile => $outfile,
1803 # don't define Parent so WriteMIEGroup() writes extended terminator
1804 );
1805 36 ▶ if ($outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile) { } 9 27 36
1806 # save start position in $outfile
1807 9 ▶ $subdirInfo{OutPos} = ref $outfile eq 'SCALAR' ? length($$outfile) || 0 : tell $outfile;
Branch: 1 branch
BranchTrueFalseTotal
ref $outfile eq 'SCALAR' ? : 7 2 9
Condition50%1/2
length $$outfile or 0
l!l
07
MC/DC0%0/1
length $$outfile or 0
length $$outfile
Truth table50%1/2
A
A= length $$outfile
Aresult
11
00
1808 # generate lookup for MIE format codes if not done already
1809 9 ▶ unless (%mieCode) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%mieCode) 3 6 9
1810 3 foreach (keys %mieFormat) {
1811 90 $mieCode{$mieFormat{$_}} = $_;
1812 }
1813 }
1814 # update %mieMap with user-defined MIE groups
1815 9 ▶ UpdateMieMap() unless $doneMieMap;
Branch: 1 branch
BranchTrueFalseTotal
unless $doneMieMap 3 6 9
1816 # initialize write directories, with MIE tags taking priority
1817 # (note that this may re-initialize directories when writing trailer
1818 # to another type of image, but this is OK because we are done writing
1819 # the other format by the time we start writing the trailer)
1820 9 $et->InitWriteDirs(\%mieMap, 'MIE');
1821 9 $subdirInfo{ToWrite} = '~' . MIEGroupFormat(1) . "\x04\xfe0MIE\0\0\0\0";
1822 9 $msg = WriteMIEGroup($et, \%subdirInfo, $tagTablePtr);
1823 9 ▶ if ($msg) {
Branch: 2 branches
BranchTrueFalseTotal
if ($msg) { } 0 9 9
elsif (defined $msg and $isCreating) { } 0 18 18
1824 0 $et->Error($msg);
1825 0 $err = 1;
1826 0 last;
1827 ▶ } elsif (defined $msg and $isCreating) {
Condition33%1/3
defined $msg and $isCreating
!ll&&!rl&&r
900
MC/DC0%0/2
defined $msg and $isCreating
defined $msg $isCreating
Truth table33%1/3
A and B
A= defined $msgB= $isCreating
ABresult
0X0
100
111
1828 0 last;
1829 }
1830 } else {
1831 27 $msg = ProcessMIEGroup($et, \%subdirInfo, $tagTablePtr);
1832 27 ▶ if ($msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 0 27 27
1833 0 $et->Warn($msg);
1834 0 last;
1835 }
1836 }
1837 }
1838 36 delete $$et{NO_LIST};
1839 36 delete $$et{MIE_COUNT};
1840 36 delete $$et{SET_GROUP1};
1841 36 ▶ return $err ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 36 36
1842 }
1843  
1844 39 1; # end
1845  
1846 __END__
« Image/ExifTool/M2TS.pm ↑ Summary Image/ExifTool/DICOM.pm »