Image/ExifTool/PNG.pm

filter: Statementstmt 61.1% 327 / 535 Branchbran 44.2% 184 / 416 Conditioncond 41.7% 101 / 242 MC/DCmcdc 18.2% 25 / 137 Subroutinesub 86.6% 13 / 15 Podpod 0.0% 0 / 11 totaltotal 47.9% 650 / 1356 CC 288 SCAR 66.0
CC
288
Cov
51%
FoundPNG
1057.1
ProcessPNG
866.3
ProcessProfile
488.4
CRAP 732.1
« Image/ExifTool/PICT.pm ↑ Summary Image/ExifTool/Font.pm »
1 #------------------------------------------------------------------------------
2 # File: PNG.pm
3 #
4 # Description: Read and write PNG meta information
5 #
6 # Revisions: 06/10/2005 - P. Harvey Created
7 # 06/23/2005 - P. Harvey Added MNG and JNG support
8 # 09/16/2005 - P. Harvey Added write support
9 #
10 # References: 1) http://www.libpng.org/pub/png/spec/1.2/
11 # 2) http://www.faqs.org/docs/png/
12 # 3) http://www.libpng.org/pub/mng/
13 # 4) http://www.libpng.org/pub/png/spec/register/
14 # 5) ftp://ftp.simplesystems.org/pub/png/documents/pngext-1.4.0-pdg.html
15 # 6) ftp://ftp.simplesystems.org/pub/png/documents/pngext-1.5.0.html
16 #
17 # Notes: Writing meta information in PNG images is a pain in the butt
18 # for a number of reasons: One biggie is that you have to
19 # decompress then decode the ASCII/hex profile information before
20 # you can edit it, then you have to ASCII/hex-encode, recompress
21 # and calculate a CRC before you can write it out again. gaaaak.
22 #
23 # Although XMP is allowed after the IDAT chunk according to the
24 # PNG specifiction, some apps (Apple Spotlight and Preview for
25 # OS X 10.8.5 and Adobe Photoshop CC 14.0) ignore it unless it
26 # comes before IDAT. As of version 11.58, ExifTool uses a 2-pass
27 # writing algorithm to allow it to be compatible with XMP after
28 # IDAT while writing it before IDAT. (PNG and EXIF are still
29 # written after IDAT.) As of version 11.63, this strategy is
30 # applied to all text chunks (tEXt, zTXt and iTXt).
31 #------------------------------------------------------------------------------
32  
33 package Image::ExifTool::PNG;
34  
35 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 23 ▶use vars qw($VERSION $AUTOLOAD %stdCase);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 23 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 23 $VERSION = '1.71';
40  
41 sub ProcessPNG_tEXt($$$);
42 sub ProcessPNG_iTXt($$$);
43 sub ProcessPNG_eXIf($$$);
44 sub ProcessPNG_Compressed($$$);
45 sub CalculateCRC($;$$$);
46 sub HexEncode($);
47 sub AddChunks($$;@);
48 sub Add_iCCP($$);
49 sub DoneDir($$$;$);
50 sub GetLangInfo($$);
51 sub BuildTextChunk($$$$$);
52 sub ConvertPNGDate($$);
53 sub InversePNGDate($$);
54  
55 # translate lower-case to actual case used for eXIf/zXIf chunks
56 23 %stdCase = ( 'zxif' => 'zxIf', exif => 'eXIf' );
57  
58 23 my $noCompressLib;
59  
60 # look up for file type, header chunk and end chunk, based on file signature
61 23 my %pngLookup = (
62 "\x89PNG\r\n\x1a\n" => ['PNG', 'IHDR', 'IEND' ],
63 "\x8aMNG\r\n\x1a\n" => ['MNG', 'MHDR', 'MEND' ],
64 "\x8bJNG\r\n\x1a\n" => ['JNG', 'JHDR', 'IEND' ],
65 );
66  
67 # map for directories in PNG images
68 23 my %pngMap = (
69 IFD1 => 'IFD0',
70 EXIF => 'IFD0', # to write EXIF as a block
71 ExifIFD => 'IFD0',
72 GPS => 'IFD0',
73 SubIFD => 'IFD0',
74 GlobParamIFD => 'IFD0',
75 PrintIM => 'IFD0',
76 InteropIFD => 'ExifIFD',
77 MakerNotes => 'ExifIFD',
78 IFD0 => 'PNG',
79 XMP => 'PNG',
80 ICC_Profile => 'PNG',
81 Photoshop => 'PNG',
82 'PNG-pHYs' => 'PNG',
83 JUMBF => 'PNG',
84 IPTC => 'Photoshop',
85 MakerNotes => 'ExifIFD',
86 );
87  
88 # color type of current image
89 23 $Image::ExifTool::PNG::colorType = -1;
90  
91 # data and text chunk types
92 23 my %isDatChunk = ( IDAT => 1, JDAT => 1, JDAA => 1 );
93 23 my %isTxtChunk = ( tEXt => 1, zTXt => 1, iTXt => 1, eXIf => 1 );
94  
95 # chunks that we shouldn't move other chunks across (ref 3)
96 23 my %noLeapFrog = ( SAVE => 1, SEEK => 1, IHDR => 1, JHDR => 1, IEND => 1, MEND => 1,
97 DHDR => 1, BASI => 1, CLON => 1, PAST => 1, SHOW => 1, MAGN => 1 );
98  
99 # PNG chunks
100 %Image::ExifTool::PNG::Main = (
101 WRITE_PROC => \&Image::ExifTool::DummyWriteProc,
102 GROUPS => { 2 => 'Image' },
103 PREFERRED => 1, # always add these tags when writing
104 NOTES => q{
105 Tags extracted from PNG images. See
106 L<http://www.libpng.org/pub/png/spec/1.2/> for the official PNG 1.2
107 specification.
108  
109 According to the specification, a PNG file should end at the IEND chunk,
110 however ExifTool will preserve any data found after this when writing unless
111 it is specifically deleted with C<-Trailer:All=>. When reading, a minor
112 warning is issued if this trailer exists, and ExifTool will attempt to parse
113 this data as additional PNG chunks.
114  
115 Also according to the PNG specification, there is no restriction on the
116 location of text-type chunks (tEXt, zTXt and iTXt). However, certain
117 utilities (including some Apple and Adobe utilities) won't read the XMP iTXt
118 chunk if it comes after the IDAT chunk, and at least one utility won't read
119 other text chunks here. For this reason, when writing, ExifTool 11.63 and
120 later create new text chunks (including XMP) before IDAT, and move existing
121 text chunks to before IDAT.
122  
123 The PNG format contains CRC checksums that are validated when reading with
124 either the L<Verbose|../ExifTool.html#Verbose> or L<Validate|../ExifTool.html#Validate> option. When writing, these checksums are
125 validated by default, but the L<FastScan|../ExifTool.html#FastScan> option may be used to bypass this
126 check if speed is more of a concern.
127 },
128 bKGD => {
129 Name => 'BackgroundColor',
130 ValueConv => 'join(" ",unpack(length($val) < 2 ? "C" : "n*", $val))',
131 },
132 cHRM => {
133 Name => 'PrimaryChromaticities',
134 SubDirectory => { TagTable => 'Image::ExifTool::PNG::PrimaryChromaticities' },
135 },
136 dSIG => {
137 Name => 'DigitalSignature',
138 Binary => 1,
139 },
140 fRAc => {
141 Name => 'FractalParameters',
142 Binary => 1,
143 },
144 gAMA => {
145 Name => 'Gamma',
146 Writable => 1,
147 Protected => 1,
148 Notes => q{
149 ExifTool reports the gamma for decoding the image, which is consistent with
150 the EXIF convention, but is the inverse of the stored encoding gamma
151 },
152 ValueConv => 'my $a=unpack("N",$val);$a ? int(1e9/$a+0.5)/1e4 : $val',
153 ValueConvInv => 'pack("N", int(1e5/$val+0.5))',
154 },
155 gIFg => {
156 Name => 'GIFGraphicControlExtension',
157 Binary => 1,
158 },
159 gIFt => {
160 Name => 'GIFPlainTextExtension',
161 Binary => 1,
162 },
163 gIFx => {
164 Name => 'GIFApplicationExtension',
165 Binary => 1,
166 },
167 hIST => {
168 Name => 'PaletteHistogram',
169 Binary => 1,
170 },
171 iCCP => {
172 Name => 'ICC_Profile',
173 Notes => q{
174 this is where ExifTool will write a new ICC_Profile. When creating a new
175 ICC_Profile, the SRGBRendering tag should be deleted if it exists
176 },
177 SubDirectory => {
178 TagTable => 'Image::ExifTool::ICC_Profile::Main',
179 ProcessProc => \&ProcessPNG_Compressed,
180 },
181 },
182 'iCCP-name' => {
183 Name => 'ProfileName',
184 Writable => 1,
185 FakeTag => 1, # (not a real PNG tag, so don't try to write it)
186 Notes => q{
187 not a real tag ID, this tag represents the iCCP profile name, and may only
188 be written when the ICC_Profile is written
189 },
190 },
191 # IDAT
192 # IEND
193 IHDR => {
194 Name => 'ImageHeader',
195 SubDirectory => { TagTable => 'Image::ExifTool::PNG::ImageHeader' },
196 },
197 iTXt => {
198 Name => 'InternationalText',
199 SubDirectory => {
200 TagTable => 'Image::ExifTool::PNG::TextualData',
201 ProcessProc => \&ProcessPNG_iTXt,
202 },
203 },
204 oFFs => {
205 Name => 'ImageOffset',
206 ValueConv => q{
207 my @a = unpack("NNC",$val);
208 $a[2] = ($a[2] ? "microns" : "pixels");
209 return "$a[0], $a[1] ($a[2])";
210 },
211 },
212 pCAL => {
213 Name => 'PixelCalibration',
214 Binary => 1,
215 },
216 pHYs => {
217 Name => 'PhysicalPixel',
218 SubDirectory => {
219 TagTable => 'Image::ExifTool::PNG::PhysicalPixel',
220 DirName => 'PNG-pHYs', # (needed for writing)
221 },
222 },
223 PLTE => {
224 Name => 'Palette',
225 ValueConv => 'length($val) <= 3 ? join(" ",unpack("C*",$val)) : \$val',
226 },
227 sBIT => {
228 Name => 'SignificantBits',
229 ValueConv => 'join(" ",unpack("C*",$val))',
230 },
231 sCAL => { # png 1.4.0
232 Name => 'SubjectScale',
233 SubDirectory => { TagTable => 'Image::ExifTool::PNG::SubjectScale' },
234 },
235 sPLT => {
236 Name => 'SuggestedPalette',
237 Binary => 1,
238 PrintConv => 'split("\0",$$val,1)', # extract palette name
239 },
240 sRGB => {
241 Name => 'SRGBRendering',
242 Writable => 1,
243 Protected => 1,
244 Notes => 'this chunk should not be present if an iCCP chunk exists',
245 ValueConv => 'unpack("C",$val)',
246 ValueConvInv => 'pack("C",$val)',
247 PrintConv => {
248 0 => 'Perceptual',
249 1 => 'Relative Colorimetric',
250 2 => 'Saturation',
251 3 => 'Absolute Colorimetric',
252 },
253 },
254 sTER => { # png 1.4.0
255 Name => 'StereoImage',
256 SubDirectory => { TagTable => 'Image::ExifTool::PNG::StereoImage' },
257 },
258 tEXt => {
259 Name => 'TextualData',
260 SubDirectory => { TagTable => 'Image::ExifTool::PNG::TextualData' },
261 },
262 tIME => {
263 Name => 'ModifyDate',
264 Groups => { 2 => 'Time' },
265 Writable => 1,
266 Shift => 'Time',
267 ValueConv => 'sprintf("%.4d:%.2d:%.2d %.2d:%.2d:%.2d", unpack("nC5", $val))',
268 ValueConvInv => q{
269 my @a = ($val=~/^(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)/);
270 @a == 6 or warn('Invalid date'), return undef;
271 return pack('nC5', @a);
272 },
273 PrintConv => '$self->ConvertDateTime($val)',
274 PrintConvInv => '$self->InverseDateTime($val)',
275 },
276 tRNS => {
277 Name => 'Transparency',
278 # may have as many entries as the PLTE table, but who wants to see all that?
279 ValueConv => q{
280 return \$val if length($val) > 6;
281 join(" ",unpack($Image::ExifTool::PNG::colorType == 3 ? "C*" : "n*", $val));
282 },
283 },
284 tXMP => {
285 Name => 'XMP',
286 Notes => 'obsolete location specified by a September 2001 XMP draft',
287 NonStandard => 'XMP',
288 SubDirectory => { TagTable => 'Image::ExifTool::XMP::Main' },
289 },
290 vpAg => { # private imagemagick chunk
291 Name => 'VirtualPage',
292 SubDirectory => { TagTable => 'Image::ExifTool::PNG::VirtualPage' },
293 },
294 zTXt => {
295 Name => 'CompressedText',
296 SubDirectory => {
297 TagTable => 'Image::ExifTool::PNG::TextualData',
298 ProcessProc => \&ProcessPNG_Compressed,
299 },
300 },
301 # animated PNG (ref https://wiki.mozilla.org/APNG_Specification)
302 acTL => {
303 Name => 'AnimationControl',
304 SubDirectory => {
305 TagTable => 'Image::ExifTool::PNG::AnimationControl',
306 },
307 },
308 # eXIf (ref 6)
309 $stdCase{exif} => {
310 Name => $stdCase{exif},
311 Notes => 'this is where ExifTool will create new EXIF',
312 SubDirectory => {
313 TagTable => 'Image::ExifTool::Exif::Main',
314 DirName => 'EXIF', # (to write as a block)
315 ProcessProc => \&ProcessPNG_eXIf,
316 },
317 },
318 # zXIf
319 $stdCase{zxif} => {
320 Name => $stdCase{zxif},
321 23 Notes => 'a once-proposed chunk for compressed EXIF',
322 NonStandard => 'EXIF',
323 SubDirectory => {
324 TagTable => 'Image::ExifTool::Exif::Main',
325 DirName => 'EXIF', # (to write as a block)
326 ProcessProc => \&ProcessPNG_eXIf,
327 },
328 },
329 # fcTL - animation frame control for each frame
330 # fdAT - animation data for each frame
331 iDOT => { # (ref NealKrawetz)
332 Name => 'AppleDataOffsets',
333 Binary => 1,
334 # Apple offsets into data relative to start of iDOT chunk:
335 # int32u Divisor [only ever seen 2]
336 # int32u Unknown [always 0]
337 # int32u TotalDividedHeight [image height from IDHR/Divisor]
338 # int32u Size [always 40 / 0x28; size of this chunk]
339 # int32u DividedHeight1
340 # int32u DividedHeight2
341 # int32u IDAT_Offset2 [location of IDAT with start of DividedHeight2 segment]
342 },
343 caBX => { # C2PA metadata
344 Name => 'JUMBF',
345 Deletable => 1,
346 SubDirectory => { TagTable => 'Image::ExifTool::Jpeg2000::Main' },
347 },
348 cICP => {
349 Name => 'CICodePoints',
350 SubDirectory => {
351 TagTable => 'Image::ExifTool::PNG::CICodePoints',
352 },
353 },
354 cpIp => { # OLE information found in PNG Plus images written by Picture It!
355 Name => 'OLEInfo',
356 Condition => q{
357 # set FileType to "PNG Plus"
358 if ($$self{VALUE}{FileType} and $$self{VALUE}{FileType} eq "PNG") {
359 $$self{VALUE}{FileType} = 'PNG Plus';
360 }
361 return 1;
362 },
363 SubDirectory => {
364 TagTable => 'Image::ExifTool::FlashPix::Main',
365 ProcessProc => 'Image::ExifTool::FlashPix::ProcessFPX',
366 },
367 },
368 meTa => { # XML in UTF-16 BOM format written by Picture It!
369 SubDirectory => {
370 TagTable => 'Image::ExifTool::XMP::XML',
371 IgnoreProp => { meta => 1 }, # ignore 'meta' container
372 },
373 },
374 gdAT => {
375 Name => 'GainMapImage',
376 Groups => { 2 => 'Preview' },
377 Binary => 1,
378 },
379 # gmAP - https://github.com/w3c/png/issues/380 does't correspond to my only sample
380 seAl => {
381 Name => 'SEAL',
382 SubDirectory => { TagTable => 'Image::ExifTool::XMP::SEAL' },
383 },
384 # mkBF,mkTS,mkBS,mkBT ? - written by Adobe FireWorks
385 );
386  
387 # PNG IHDR chunk
388 23 %Image::ExifTool::PNG::ImageHeader = (
389 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
390 GROUPS => { 2 => 'Image' },
391 0 => {
392 Name => 'ImageWidth',
393 Format => 'int32u',
394 },
395 4 => {
396 Name => 'ImageHeight',
397 Format => 'int32u',
398 },
399 8 => 'BitDepth',
400 9 => {
401 Name => 'ColorType',
402 RawConv => '$Image::ExifTool::PNG::colorType = $val',
403 PrintConv => {
404 0 => 'Grayscale',
405 2 => 'RGB',
406 3 => 'Palette',
407 4 => 'Grayscale with Alpha',
408 6 => 'RGB with Alpha',
409 },
410 },
411 10 => {
412 Name => 'Compression',
413 PrintConv => { 0 => 'Deflate/Inflate' },
414 },
415 11 => {
416 Name => 'Filter',
417 PrintConv => { 0 => 'Adaptive' },
418 },
419 12 => {
420 Name => 'Interlace',
421 PrintConv => { 0 => 'Noninterlaced', 1 => 'Adam7 Interlace' },
422 },
423 );
424  
425 # PNG cHRM chunk
426 23 %Image::ExifTool::PNG::PrimaryChromaticities = (
427 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
428 GROUPS => { 2 => 'Image' },
429 FORMAT => 'int32u',
430 0 => { Name => 'WhitePointX', ValueConv => '$val / 100000' },
431 1 => { Name => 'WhitePointY', ValueConv => '$val / 100000' },
432 2 => { Name => 'RedX', ValueConv => '$val / 100000' },
433 3 => { Name => 'RedY', ValueConv => '$val / 100000' },
434 4 => { Name => 'GreenX', ValueConv => '$val / 100000' },
435 5 => { Name => 'GreenY', ValueConv => '$val / 100000' },
436 6 => { Name => 'BlueX', ValueConv => '$val / 100000' },
437 7 => { Name => 'BlueY', ValueConv => '$val / 100000' },
438 );
439  
440 # PNG pHYs chunk
441 23 %Image::ExifTool::PNG::PhysicalPixel = (
442 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
443 WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
444 CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
445 WRITABLE => 1,
446 GROUPS => { 1 => 'PNG-pHYs', 2 => 'Image' },
447 WRITE_GROUP => 'PNG-pHYs',
448 NOTES => q{
449 These tags are found in the PNG pHYs chunk and belong to the PNG-pHYs family
450 1 group. They are all created together with default values if necessary
451 when any of these tags is written, and may only be deleted as a group.
452 },
453 0 => {
454 Name => 'PixelsPerUnitX',
455 Format => 'int32u',
456 Notes => 'default 2834',
457 },
458 4 => {
459 Name => 'PixelsPerUnitY',
460 Format => 'int32u',
461 Notes => 'default 2834',
462 },
463 8 => {
464 Name => 'PixelUnits',
465 PrintConv => { 0 => 'Unknown', 1 => 'meters' },
466 Notes => 'default meters',
467 },
468 );
469  
470 # PNG cICP chunk
471 23 %Image::ExifTool::PNG::CICodePoints = (
472 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
473 GROUPS => { 1 => 'PNG-cICP', 2 => 'Image' },
474 NOTES => q{
475 These tags are found in the PNG cICP chunk and belong to the PNG-cICP family
476 1 group.
477 },
478 # (same as tags in QuickTime::ColorRep)
479 0 => {
480 Name => 'ColorPrimaries',
481 PrintConv => {
482 1 => 'BT.709',
483 2 => 'Unspecified',
484 4 => 'BT.470 System M (historical)',
485 5 => 'BT.470 System B, G (historical)',
486 6 => 'BT.601',
487 7 => 'SMPTE 240',
488 8 => 'Generic film (color filters using illuminant C)',
489 9 => 'BT.2020, BT.2100',
490 10 => 'SMPTE 428 (CIE 1921 XYZ)',
491 11 => 'SMPTE RP 431-2',
492 12 => 'SMPTE EG 432-1',
493 22 => 'EBU Tech. 3213-E',
494 },
495 },
496 1 => {
497 Name => 'TransferCharacteristics',
498 PrintConv => {
499 0 => 'For future use (0)',
500 1 => 'BT.709',
501 2 => 'Unspecified',
502 3 => 'For future use (3)',
503 4 => 'BT.470 System M (historical)',
504 5 => 'BT.470 System B, G (historical)',
505 6 => 'BT.601',
506 7 => 'SMPTE 240 M',
507 8 => 'Linear',
508 9 => 'Logarithmic (100 : 1 range)',
509 10 => 'Logarithmic (100 * Sqrt(10) : 1 range)',
510 11 => 'IEC 61966-2-4',
511 12 => 'BT.1361',
512 13 => 'sRGB or sYCC',
513 14 => 'BT.2020 10-bit systems',
514 15 => 'BT.2020 12-bit systems',
515 16 => 'SMPTE ST 2084, ITU BT.2100 PQ',
516 17 => 'SMPTE ST 428',
517 18 => 'BT.2100 HLG, ARIB STD-B67',
518 },
519 },
520 2 => {
521 Name => 'MatrixCoefficients',
522 PrintConv => {
523 0 => 'Identity matrix',
524 1 => 'BT.709',
525 2 => 'Unspecified',
526 3 => 'For future use (3)',
527 4 => 'US FCC 73.628',
528 5 => 'BT.470 System B, G (historical)',
529 6 => 'BT.601',
530 7 => 'SMPTE 240 M',
531 8 => 'YCgCo',
532 9 => 'BT.2020 non-constant luminance, BT.2100 YCbCr',
533 10 => 'BT.2020 constant luminance',
534 11 => 'SMPTE ST 2085 YDzDx',
535 12 => 'Chromaticity-derived non-constant luminance',
536 13 => 'Chromaticity-derived constant luminance',
537 14 => 'BT.2100 ICtCp',
538 },
539 },
540 3 => 'VideoFullRangeFlag',
541 );
542  
543 # PNG sCAL chunk
544 23 %Image::ExifTool::PNG::SubjectScale = (
545 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
546 GROUPS => { 2 => 'Image' },
547 0 => {
548 Name => 'SubjectUnits',
549 PrintConv => { 1 => 'meters', 2 => 'radians' },
550 },
551 1 => {
552 Name => 'SubjectPixelWidth',
553 Format => 'var_string',
554 },
555 2 => {
556 Name => 'SubjectPixelHeight',
557 Format => 'var_string',
558 },
559 );
560  
561 # PNG vpAg chunk
562 23 %Image::ExifTool::PNG::VirtualPage = (
563 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
564 GROUPS => { 2 => 'Image' },
565 FORMAT => 'int32u',
566 0 => 'VirtualImageWidth',
567 1 => 'VirtualImageHeight',
568 2 => {
569 Name => 'VirtualPageUnits',
570 Format => 'int8u',
571 # what is the conversion for this?
572 },
573 );
574  
575 # PNG sTER chunk
576 23 %Image::ExifTool::PNG::StereoImage = (
577 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
578 GROUPS => { 2 => 'Image' },
579 0 => {
580 Name => 'StereoMode',
581 PrintConv => {
582 0 => 'Cross-fuse Layout',
583 1 => 'Diverging-fuse Layout',
584 },
585 },
586 );
587  
588 23 my %unreg = ( Notes => 'unregistered' );
589  
590 # Tags for PNG tEXt zTXt and iTXt chunks
591 # (NOTE: ValueConv is set dynamically, so don't set it here!)
592 23 %Image::ExifTool::PNG::TextualData = (
593 PROCESS_PROC => \&ProcessPNG_tEXt,
594 WRITE_PROC => \&Image::ExifTool::DummyWriteProc,
595 WRITABLE => 'string',
596 PREFERRED => 1, # always add these tags when writing
597 GROUPS => { 2 => 'Image' },
598 LANG_INFO => \&GetLangInfo,
599 NOTES => q{
600 The PNG TextualData format allows arbitrary tag names to be used. The tags
601 listed below are the only ones that can be written (unless new user-defined
602 tags are added via the configuration file), however ExifTool will extract
603 any other TextualData tags that are found. All TextualData tags (including
604 tags not listed below) are removed when deleting all PNG tags.
605  
606 These tags may be stored as tEXt, zTXt or iTXt chunks in the PNG image. By
607 default ExifTool writes new string-value tags as as uncompressed tEXt, or
608 compressed zTXt if the L<Compress|../ExifTool.html#Compress> (-z) option is used and Compress::Zlib is
609 available. Alternate language tags and values containing special characters
610 (unless the Latin character set is used) are written as iTXt, and compressed
611 if the L<Compress|../ExifTool.html#Compress> option is used and Compress::Zlib is available. Raw profile
612 information is always created as compressed zTXt if Compress::Zlib is
613 available, or tEXt otherwise. Standard XMP is written as uncompressed iTXt.
614 User-defined tags may set an 'iTXt' flag in the tag definition to be written
615 only as iTXt.
616  
617 Alternate languages are accessed by suffixing the tag name with a '-',
618 followed by an RFC 3066 language code (eg. "PNG:Comment-fr", or
619 "Title-en-US"). See L<http://www.ietf.org/rfc/rfc3066.txt> for the RFC 3066
620 specification.
621  
622 Some of the tags below are not registered as part of the PNG specification,
623 but are included here because they are generated by other software such as
624 ImageMagick.
625 },
626 Title => { },
627 Author => { Groups => { 2 => 'Author' } },
628 Description => { },
629 Copyright => { Groups => { 2 => 'Author' } },
630 'Creation Time' => {
631 Name => 'CreationTime',
632 Groups => { 2 => 'Time' },
633 Shift => 'Time',
634 Notes => 'stored in RFC-1123 format and converted to/from EXIF format by ExifTool',
635 RawConv => \&ConvertPNGDate,
636 ValueConvInv => \&InversePNGDate,
637 PrintConv => '$self->ConvertDateTime($val)',
638 PrintConvInv => '$self->InverseDateTime($val,undef,1)',
639 },
640 Software => { },
641 Disclaimer => { },
642 # change name to differentiate from ExifTool Warning
643 Warning => { Name => 'PNGWarning', },
644 Source => { },
645 Comment => { },
646 Collection => { }, # (PNG extensions, 2004)
647 #
648 # The following tags are not part of the original PNG specification,
649 # but are written by ImageMagick and other software
650 #
651 Artist => { %unreg, Groups => { 2 => 'Author' } },
652 Document => { %unreg },
653 Label => { %unreg },
654 Make => { %unreg, Groups => { 2 => 'Camera' } },
655 Model => { %unreg, Groups => { 2 => 'Camera' } },
656 parameters => { %unreg }, # (written by Stable Diffusion)
657 aesthetic_score => { Name => 'AestheticScore', %unreg }, # (written by Stable Diffusion)
658 'create-date'=> {
659 Name => 'CreateDate',
660 Groups => { 2 => 'Time' },
661 Shift => 'Time',
662 %unreg,
663 ValueConv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::ConvertXMPDate($val)',
664 ValueConvInv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::FormatXMPDate($val)',
665 PrintConv => '$self->ConvertDateTime($val)',
666 PrintConvInv => '$self->InverseDateTime($val,undef,1)',
667 },
668 'modify-date'=> {
669 Name => 'ModDate', # (to distinguish from tIME chunk "ModifyDate")
670 Groups => { 2 => 'Time' },
671 Shift => 'Time',
672 %unreg,
673 ValueConv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::ConvertXMPDate($val)',
674 ValueConvInv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::FormatXMPDate($val)',
675 PrintConv => '$self->ConvertDateTime($val)',
676 PrintConvInv => '$self->InverseDateTime($val,undef,1)',
677 },
678 TimeStamp => { %unreg, Groups => { 2 => 'Time' }, Shift => 'Time' },
679 URL => { %unreg },
680 'XML:com.adobe.xmp' => {
681 Name => 'XMP',
682 Notes => q{
683 unregistered, but this is the location according to the June 2002 or later
684 XMP specification, and is where ExifTool will add a new XMP chunk if the
685 image didn't already contain XMP
686 },
687 SubDirectory => { TagTable => 'Image::ExifTool::XMP::Main' },
688 },
689 'Raw profile type APP1' => [
690 {
691 # EXIF table must come first because we key on this in ProcessProfile()
692 # (No condition because this is just for BuildTagLookup)
693 Name => 'APP1_Profile',
694 %unreg,
695 NonStandard => 'EXIF',
696 SubDirectory => {
697 TagTable => 'Image::ExifTool::Exif::Main',
698 ProcessProc => \&ProcessProfile,
699 },
700 },
701 {
702 Name => 'APP1_Profile',
703 NonStandard => 'XMP',
704 SubDirectory => {
705 TagTable => 'Image::ExifTool::XMP::Main',
706 ProcessProc => \&ProcessProfile,
707 },
708 },
709 ],
710 'Raw profile type exif' => {
711 Name => 'EXIF_Profile',
712 %unreg,
713 NonStandard => 'EXIF',
714 SubDirectory => {
715 TagTable => 'Image::ExifTool::Exif::Main',
716 ProcessProc => \&ProcessProfile,
717 },
718 },
719 'Raw profile type icc' => {
720 Name => 'ICC_Profile',
721 %unreg,
722 SubDirectory => {
723 TagTable => 'Image::ExifTool::ICC_Profile::Main',
724 ProcessProc => \&ProcessProfile,
725 },
726 },
727 'Raw profile type icm' => {
728 Name => 'ICC_Profile',
729 %unreg,
730 SubDirectory => {
731 TagTable => 'Image::ExifTool::ICC_Profile::Main',
732 ProcessProc => \&ProcessProfile,
733 },
734 },
735 'Raw profile type iptc' => {
736 Name => 'IPTC_Profile',
737 Notes => q{
738 unregistered. May be either IPTC IIM or Photoshop IRB format. This is
739 where ExifTool will add new IPTC, inside a Photoshop IRB container
740 },
741 SubDirectory => {
742 TagTable => 'Image::ExifTool::Photoshop::Main',
743 ProcessProc => \&ProcessProfile,
744 },
745 },
746 'Raw profile type xmp' => {
747 Name => 'XMP_Profile',
748 %unreg,
749 NonStandard => 'XMP',
750 SubDirectory => {
751 TagTable => 'Image::ExifTool::XMP::Main',
752 ProcessProc => \&ProcessProfile,
753 },
754 },
755 'Raw profile type 8bim' => {
756 Name => 'Photoshop_Profile',
757 %unreg,
758 SubDirectory => {
759 TagTable => 'Image::ExifTool::Photoshop::Main',
760 ProcessProc => \&ProcessProfile,
761 },
762 },
763 );
764  
765 # Animation control
766 23 %Image::ExifTool::PNG::AnimationControl = (
767 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
768 GROUPS => { 2 => 'Image' },
769 FORMAT => 'int32u',
770 NOTES => q{
771 Tags found in the Animation Control chunk. See
772 L<https://wiki.mozilla.org/APNG_Specification> for details.
773 },
774 0 => {
775 Name => 'AnimationFrames',
776 RawConv => '$self->OverrideFileType("APNG", undef, "PNG"); $val',
777 },
778 1 => {
779 Name => 'AnimationPlays',
780 PrintConv => '$val || "inf"',
781 },
782 );
783  
784 #------------------------------------------------------------------------------
785 # AutoLoad our writer routines when necessary
786 #
787 sub AUTOLOAD
788 1 ▶{
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
789 1 return Image::ExifTool::DoAutoLoad($AUTOLOAD, @_);
790 }
791  
792 #------------------------------------------------------------------------------
793 # Get standard case for language code (this routine copied from XMP.pm)
794 # Inputs: 0) Language code
795 # Returns: Language code in standard case
796 sub StandardLangCase($)
797 28 ▶{
Subroutine StandardLangCase: called CC=2 SCAR=6.9
Pod undocumented
798 28 my $lang = shift;
799 # make 2nd subtag uppercase only if it is 2 letters
800 28 ▶ return lc($1) . uc($2) . lc($3) if $lang =~ /^([a-z]{2,3}|[xi])(-[a-z]{2})\b(.*)/i;
Branch: 1 branch
BranchTrueFalseTotal
if $lang =~ /^([a-z]{2,3}|[xi])(-[a-z]{2})\b(.*)/i 17 11 28
801 11 return lc($lang);
802 }
803  
804 #------------------------------------------------------------------------------
805 # Convert date from PNG to EXIF format
806 # Inputs: 0) Date/time in PNG format, 1) ExifTool ref
807 # Returns: EXIF formatted date/time string
808 23 my %monthNum = (
809 Jan=>1, Feb=>2, Mar=>3, Apr=>4, May=>5, Jun=>6,
810 Jul=>7, Aug=>8, Sep=>9, Oct=>10,Nov=>11,Dec=>12
811 );
812 23 my %tzConv = (
813 UT => '+00:00', GMT => '+00:00', UTC => '+00:00', # (UTC not in spec -- PH addition)
814 EST => '-05:00', EDT => '-04:00',
815 CST => '-06:00', CDT => '-05:00',
816 MST => '-07:00', MDT => '-06:00',
817 PST => '-08:00', PDT => '-07:00',
818 A => '-01:00', N => '+01:00',
819 B => '-02:00', O => '+02:00',
820 C => '-03:00', P => '+03:00',
821 D => '-04:00', Q => '+04:00',
822 E => '-05:00', R => '+05:00',
823 F => '-06:00', S => '+06:00',
824 G => '-07:00', T => '+07:00',
825 H => '-08:00', U => '+08:00',
826 I => '-09:00', V => '+09:00',
827 K => '-10:00', W => '+10:00',
828 L => '-11:00', X => '+11:00',
829 M => '-12:00', Y => '+12:00',
830 Z => '+00:00',
831 );
832 sub ConvertPNGDate($$)
833 0 ▶{
Subroutine ConvertPNGDate: not called CC=12 SCAR=50.5
Pod undocumented
834 0 my ($val, $et) = @_;
835 # standard format is like "Mon, 1 Jan 2018 12:10:22 EST" (RFC-1123 section 5.2.14)
836 0 ▶ while ($val =~ /(\d+)\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*(\d+)\s+(\d+):(\d{2})(:\d{2})?\s*(\S*)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /(\d+)\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*(\d+)\s+(\d+):(\d{2})(:\d{2})?\s*(\S*)/i) 0 0 0
837 0 my ($day,$mon,$yr,$hr,$min,$sec,$tz) = ($1,$2,$3,$4,$5,$6,$7);
838 0 ▶ $yr += $yr > 70 ? 1900 : 2000 if $yr < 100; # boost year to 4 digits if necessary
Branch: 2 branches
BranchTrueFalseTotal
if $yr < 100 0 0 0
$yr > 70 ? : 0 0 0
839 0 ▶ $mon = $monthNum{ucfirst lc $mon} or return $val;
Branch: 1 branch
BranchTrueFalseTotal
$mon = $monthNum{ucfirst lc $mon} or return $val 0 0 0
840 0 ▶ if (not $tz) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $tz) { } 0 0 0
elsif ($tzConv{uc $tz}) { } 0 0 0
elsif ($tz =~ /^([-+]\d+):?(\d{2})/) { } 0 0 0
841 0 $tz = '';
842 } elsif ($tzConv{uc $tz}) {
843 0 $tz = $tzConv{uc $tz};
844 } elsif ($tz =~ /^([-+]\d+):?(\d{2})/) {
845 0 $tz = $1 . ':' . $2;
846 } else {
847 0 last; # (non-standard date)
848 }
849 0 ▶ return sprintf("%.4d:%.2d:%.2d %.2d:%.2d%s%s",$yr,$mon,$day,$hr,$min,$sec||':00',$tz);
Condition0%0/2
$sec || ':00'
l!l
00
MC/DC0%0/1
$sec || ':00'
$sec
Truth table0%0/2
A
A= $sec
Aresult
11
00
850 }
851 0 ▶ if (($et->Options('StrictDate') and not $$et{TAGS_FROM_FILE}) or $et->Options('Validate')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->Options("StrictDate") and not $et->{"TAGS_FROM_FILE"} or $et->Options("Validate")) 0 0 0
Condition0%0/6
$et->Options("StrictDate") and not $et->{"TAGS_FROM_FILE"} or $et->Options("Validate")
l!l&&r!l&&!r
000
$et->Options("StrictDate") and not $et->{"TAGS_FROM_FILE"}
!ll&&!rl&&r
000
MC/DC0%0/3
$et->Options("StrictDate") and not $et->{"TAGS_FROM_FILE"} or $et->Options("Validate")
$et->Options("StrictDate") not $et->{"TAGS_FROM_FILE"} $et->Options("Validate")
Truth table0%0/5
A and not(B) or C
A= $et->Options("StrictDate")B= not $et->{"TAGS_FROM_FILE"}C= $et->Options("Validate")
ABCresult
11X1
0X11
1011
0X00
1000
852 0 $et->Warn('Non standard PNG date/time format', 1);
853 }
854 0 return $val;
855 }
856  
857 #------------------------------------------------------------------------------
858 # Convert EXIF date/time to PNG format
859 # Inputs: 0) Date/time in EXIF format, 1) ExifTool ref
860 # Returns: PNG formatted date/time string
861 sub InversePNGDate($$)
862 0 ▶{
Subroutine InversePNGDate: not called CC=9 SCAR=45.0
Pod undocumented
863 0 my ($val, $et) = @_;
864 0 ▶ if ($et->Options('StrictDate')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->Options("StrictDate")) 0 0 0
865 0 my $err;
866 0 ▶ if ($val =~ /^(\d{4}):(\d{2}):(\d{2}) (\d{2})(:\d{2})(:\d{2})?(?:\.\d*)?\s*(\S*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^(\d{4}):(\d{2}):(\d{2}) (\d{2})(:\d{2})(:\d{2})?(?:\.\d*)?\s*(\S*)/) 0 0 0
867 0 my ($yr,$mon,$day,$hr,$min,$sec,$tz) = ($1,$2,$3,$4,$5,$6,$7);
868 0 ▶ $sec or $sec = '';
Branch: 1 branch
BranchTrueFalseTotal
$sec or $sec = "" 0 0 0
869 0 my %monName = map { $monthNum{$_} => $_ } keys %monthNum;
870 0 ▶ $mon = $monName{$mon + 0} or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
$mon = $monName{$mon + 0} or $err = 1 0 0 0
871 0 ▶ if (length $tz) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $tz) 0 0 0
872 0 ▶ $tz =~ /^(Z|[-+]\d{2}:?\d{2})/ or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
$tz =~ /^(Z|[-+]\d{2}:?\d{2})/ or $err = 1 0 0 0
873 0 $tz =~ tr/://d;
874 0 $tz = ' ' . $tz;
875 }
876 0 ▶ $val = "$day $mon $yr $hr$min$sec$tz" unless $err;
Branch: 1 branch
BranchTrueFalseTotal
unless $err 0 0 0
877 }
878 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
879 0 warn "Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z])\n";
880 0 undef $val;
881 }
882 }
883 0 return $val;
884 }
885  
886 #------------------------------------------------------------------------------
887 # Get localized version of tagInfo hash
888 # Inputs: 0) tagInfo hash ref, 1) language code (eg. "x-default")
889 # Returns: new tagInfo hash ref, or undef if invalid
890 sub GetLangInfo($$)
891 27 ▶{
Subroutine GetLangInfo: called CC=2 SCAR=7.0
Pod undocumented
892 27 my ($tagInfo, $lang) = @_;
893 27 $lang =~ tr/_/-/; # RFC 3066 specifies '-' as a separator
894 # no alternate languages for XMP or raw profile directories
895 27 ▶ return undef if $$tagInfo{SubDirectory};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"SubDirectory"} 0 27 27
896 # language code must normalized for use in tag ID
897 27 return Image::ExifTool::GetLangInfo($tagInfo, StandardLangCase($lang));
898 }
899  
900 #------------------------------------------------------------------------------
901 # Found a PNG tag -- extract info from subdirectory or decompress data if necessary
902 # Inputs: 0) ExifTool object reference, 1) Pointer to tag table,
903 # 2) Tag ID, 3) Tag value, 4) [optional] compressed data flag:
904 # 0=not compressed, 1=unknown compression, 2-N=compression with type N-2
905 # 5) optional output buffer ref, 6) character encoding (tEXt/zTXt/iTXt only)
906 # 6) optional language code
907 # Returns: 1 on success
908 sub FoundPNG($$$$;$$$$)
909 100 ▶{
Subroutine FoundPNG: called CC=91 SCAR=69.6
Pod undocumented
910 100 my ($et, $tagTablePtr, $tag, $val, $compressed, $outBuff, $enc, $lang) = @_;
911 100 ▶ return 0 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 100 100
912 100 my $verbose = $et->Options('Verbose');
913 100 my $id = $tag; # generate tag ID which includes language code
914 100 ▶ if ($lang) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lang) 1 99 100
915 # case of language code must be normalized since they are case insensitive
916 1 $lang = StandardLangCase($lang);
917 1 $id .= '-' . $lang;
918 }
919 100 ▶ my $tagInfo = $et->GetTagInfo($tagTablePtr, $id) ||
Condition66%2/3
$et->GetTagInfo($tagTablePtr, $id) || $et->GetTagInfo($tagTablePtr, ucfirst $id)
l!l&&r!l&&!r
9190
MC/DC0%0/2
$et->GetTagInfo($tagTablePtr, $id) || $et->GetTagInfo($tagTablePtr, ucfirst $id)
$et->GetTagInfo($tagTablePtr, $id) $et->GetTagInfo($tagTablePtr, ucfirst $id)
Truth table66%2/3
A || B
A= $et->GetTagInfo($tagTablePtr, $id)B= $et->GetTagInfo($tagTablePtr, ucfirst $id)
ABresult
1X1
011
000
920 # (some software forgets to capitalize first letter)
921 $et->GetTagInfo($tagTablePtr, ucfirst($id));
922 # create alternate language tag if necessary
923 100 ▶ if (not $tagInfo and $lang) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $tagInfo and $lang) 0 100 100
Condition33%1/3
not $tagInfo and $lang
!ll&&!rl&&r
10000
MC/DC0%0/2
not $tagInfo and $lang
not $tagInfo $lang
Truth table33%1/3
not(A) and B
A= not $tagInfoB= $lang
ABresult
0X0
100
111
924 0 ▶ $tagInfo = $et->GetTagInfo($tagTablePtr, $tag) ||
Condition0%0/3
$et->GetTagInfo($tagTablePtr, $tag) || $et->GetTagInfo($tagTablePtr, ucfirst $tag)
l!l&&r!l&&!r
000
MC/DC0%0/2
$et->GetTagInfo($tagTablePtr, $tag) || $et->GetTagInfo($tagTablePtr, ucfirst $tag)
$et->GetTagInfo($tagTablePtr, $tag) $et->GetTagInfo($tagTablePtr, ucfirst $tag)
Truth table0%0/3
A || B
A= $et->GetTagInfo($tagTablePtr, $tag)B= $et->GetTagInfo($tagTablePtr, ucfirst $tag)
ABresult
1X1
011
000
925 $et->GetTagInfo($tagTablePtr, ucfirst($tag));
926 0 ▶ $tagInfo = GetLangInfo($tagInfo, $lang) if $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo 0 0 0
927 }
928 #
929 # uncompress data if necessary
930 #
931 100 my ($wasCompressed, $deflateErr);
932 100 ▶ if ($compressed and $compressed > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compressed and $compressed > 1) 2 98 100
Condition66%2/3
$compressed and $compressed > 1
!ll&&!rl&&r
9802
MC/DC50%1/2
$compressed and $compressed > 1
$compressed $compressed > 1
Truth table66%2/3
A and B
A= $compressedB= $compressed > 1
ABresult
0X0
100
111
933 2 ▶ if ($compressed == 2) { # Inflate/Deflate compression
Branch: 1 branch
BranchTrueFalseTotal
if ($compressed == 2) { } 2 0 2
934 2 ▶ if (eval { require Compress::Zlib }) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require Compress::Zlib } }) { } 2 0 2
elsif (not $noCompressLib) { } 0 0 0
935 2 my ($v2, $stat);
936 2 my $inflate = Compress::Zlib::inflateInit();
937 2 ▶ $inflate and ($v2, $stat) = $inflate->inflate($val);
Branch: 1 branch
BranchTrueFalseTotal
$inflate and () = $inflate->inflate($val) 2 0 2
938 2 ▶ if ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) { } 2 0 2
Condition33%1/3
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
!ll&&!rl&&r
002
MC/DC0%0/2
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
$inflate $stat == Compress::Zlib::Z_STREAM_END()
Truth table33%1/3
A and B
A= $inflateB= $stat == Compress::Zlib::Z_STREAM_END()
ABresult
0X0
100
111
939 2 $val = $v2;
940 2 $compressed = 0;
941 2 $wasCompressed = 1;
942 } else {
943 0 $deflateErr = "Error inflating $tag";
944 }
945 } elsif (not $noCompressLib) {
946 0 $deflateErr = "Install Compress::Zlib to read compressed information";
947 } else {
948 0 $deflateErr = ''; # flag deflate error but no warning
949 }
950 } else {
951 0 $compressed -= 2;
952 0 $deflateErr = "Unknown compression method $compressed for $tag";
953 }
954 2 ▶ if ($compressed and $verbose and $tagInfo and $$tagInfo{SubDirectory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compressed and $verbose and $tagInfo and $tagInfo->{"SubDirectory"}) 0 2 2
Condition33%3/9
$compressed and $verbose and $tagInfo and $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
200
$compressed and $verbose and $tagInfo
!ll&&!rl&&r
200
$compressed and $verbose
!ll&&!rl&&r
200
MC/DC0%0/4
$compressed and $verbose and $tagInfo and $tagInfo->{"SubDirectory"}
$compressed $verbose $tagInfo $tagInfo->{"SubDirectory"}
Truth table20%1/5
A and B and C and D
A= $compressedB= $verboseC= $tagInfoD= $tagInfo->{"SubDirectory"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
955 0 $et->VerboseDir("Unable to decompress $$tagInfo{Name}", 0, length($val));
956 }
957 # issue warning if relevant
958 2 ▶ if ($deflateErr and not $outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deflateErr and not $outBuff) 0 2 2
Condition33%1/3
$deflateErr and not $outBuff
!ll&&!rl&&r
200
MC/DC0%0/2
$deflateErr and not $outBuff
$deflateErr not $outBuff
Truth table33%1/3
A and not(B)
A= $deflateErrB= not $outBuff
ABresult
0X0
100
111
959 0 $et->Warn($deflateErr);
960 0 ▶ $noCompressLib = 1 if $deflateErr =~ /^Install/;
Branch: 1 branch
BranchTrueFalseTotal
if $deflateErr =~ /^Install/ 0 0 0
961 }
962 }
963 # translate character encoding if necessary (tEXt/zTXt/iTXt string values only)
964 100 ▶ if ($enc and not $compressed and not ($tagInfo and $$tagInfo{SubDirectory})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc and not $compressed and not $tagInfo && $tagInfo->{"SubDirectory"}) 22 78 100
Condition77%7/9
$enc and not $compressed and not $tagInfo && $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
661222
$enc and not $compressed
!ll&&!rl&&r
66034
$tagInfo && $tagInfo->{'SubDirectory'}
!ll&&!rl&&r
02212
MC/DC50%2/4
$enc and not $compressed and not $tagInfo && $tagInfo->{"SubDirectory"}
$enc not $compressed $tagInfo $tagInfo->{'SubDirectory'}
Truth table60%3/5
A and not(B) and not(C && D)
A= $encB= not $compressedC= $tagInfoD= $tagInfo->{'SubDirectory'}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
965 22 $val = $et->Decode($val, $enc);
966 }
967 #
968 # extract information from subdirectory if available
969 #
970 100 ▶ if ($tagInfo) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagInfo) { } 100 0 100
elsif ($outBuff) { } 0 0 0
971 100 my $tagName = $$tagInfo{Name};
972 100 my $processed;
973 100 ▶ if ($$tagInfo{SubDirectory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"SubDirectory"}) 64 36 100
974 64 ▶ if ($$et{OPTIONS}{Validate} and $$tagInfo{NonStandard}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"OPTIONS"}{"Validate"} and $tagInfo->{"NonStandard"}) 0 64 64
Condition33%1/3
$et->{"OPTIONS"}{"Validate"} and $tagInfo->{"NonStandard"}
!ll&&!rl&&r
6400
MC/DC0%0/2
$et->{"OPTIONS"}{"Validate"} and $tagInfo->{"NonStandard"}
$et->{"OPTIONS"}{"Validate"} $tagInfo->{"NonStandard"}
Truth table33%1/3
A and B
A= $et->{"OPTIONS"}{"Validate"}B= $tagInfo->{"NonStandard"}
ABresult
0X0
100
111
975 0 $et->Warn("Non-standard $$tagInfo{NonStandard} in PNG $tag chunk", 1);
976 }
977 64 my $subdir = $$tagInfo{SubDirectory};
978 64 ▶ my $dirName = $$subdir{DirName} || $tagName;
Condition66%2/3
$subdir->{'DirName'} || $tagName
l!l&&r!l&&!r
4600
MC/DC0%0/2
$subdir->{'DirName'} || $tagName
$subdir->{'DirName'} $tagName
Truth table66%2/3
A || B
A= $subdir->{'DirName'}B= $tagName
ABresult
1X1
011
000
979 64 ▶ if (not $compressed) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $compressed) { } 64 0 64
elsif ($outBuff) { } 0 0 0
980 64 my $len = length $val;
981 64 ▶ if ($verbose and $$et{INDENT} ne ' ') {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose and $et->{"INDENT"} ne " ") 0 64 64
Condition66%2/3
$verbose and $et->{"INDENT"} ne " "
!ll&&!rl&&r
6040
MC/DC0%0/2
$verbose and $et->{"INDENT"} ne " "
$verbose $et->{"INDENT"} ne " "
Truth table66%2/3
A and B
A= $verboseB= $et->{"INDENT"} ne " "
ABresult
0X0
100
111
982 0 ▶ if ($wasCompressed and $verbose > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wasCompressed and $verbose > 2) 0 0 0
Condition0%0/3
$wasCompressed and $verbose > 2
!ll&&!rl&&r
000
MC/DC0%0/2
$wasCompressed and $verbose > 2
$wasCompressed $verbose > 2
Truth table0%0/3
A and B
A= $wasCompressedB= $verbose > 2
ABresult
0X0
100
111
983 0 my $name = $tagName;
984 0 ▶ $wasCompressed and $name = "Decompressed $name";
Branch: 1 branch
BranchTrueFalseTotal
$wasCompressed and $name = "Decompressed $name" 0 0 0
985 0 $et->VerboseDir($name, 0, $len);
986 0 $et->VerboseDump(\$val);
987 }
988 # don't indent next directory (since it is really the same data)
989 0 $$et{INDENT} =~ s/..$//;
990 }
991 64 my $processProc = $$subdir{ProcessProc};
992 # nothing more to do if writing and subdirectory is not writable
993 64 my $subTable = GetTagTable($$subdir{TagTable});
994 64 ▶ if ($outBuff and not $$subTable{WRITE_PROC}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outBuff and not $subTable->{"WRITE_PROC"}) 5 59 64
Condition100%3/3
$outBuff and not $subTable->{"WRITE_PROC"}
!ll&&!rl&&r
44155
MC/DC100%2/2
$outBuff and not $subTable->{"WRITE_PROC"}
$outBuff not $subTable->{"WRITE_PROC"}
Truth table100%3/3
A and not(B)
A= $outBuffB= not $subTable->{"WRITE_PROC"}
ABresult
0X0
100
111
995 5 ▶ if ($$et{DEL_GROUP}{$dirName}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"DEL_GROUP"}{$dirName}) 0 5 5
996 # non-writable directories may be deleted as a group (eg. SEAL)
997 0 $et->VPrint(0, " Deleting $dirName\n");
998 0 $$outBuff = '';
999 0 ++$$et{CHANGED};
1000 }
1001 5 return 1;
1002 }
1003 my %subdirInfo = (
1004 DataPt => \$val,
1005 DirStart => 0,
1006 DataLen => $len,
1007 DirLen => $len,
1008 DirName => $dirName,
1009 TagInfo => $tagInfo,
1010 ReadOnly => 1, # (used only by WriteXMP)
1011 OutBuff => $outBuff,
1012 IgnoreProp => $$subdir{IgnoreProp}, # (XML hack for meTa chunk)
1013 59 );
1014 # no need to re-decompress if already done
1015 59 ▶ undef $processProc if $wasCompressed and $processProc and $processProc eq \&ProcessPNG_Compressed;
Branch: 1 branch
BranchTrueFalseTotal
if $wasCompressed and $processProc and $processProc eq \&Image::ExifTool::PNG::ProcessPNG_Compressed 1 58 59
Condition83%5/6
$wasCompressed and $processProc and $processProc eq \&Image::ExifTool::PNG::ProcessPNG_Compressed
!ll&&!rl&&r
5711
$wasCompressed and $processProc
!ll&&!rl&&r
5702
MC/DC66%2/3
$wasCompressed and $processProc and $processProc eq \&Image::ExifTool::PNG::ProcessPNG_Compressed
$wasCompressed $processProc $processProc eq \&Image::ExifTool::PNG::ProcessPNG_Compressed
Truth table75%3/4
A and B and C
A= $wasCompressedB= $processProcC= $processProc eq \&Image::ExifTool::PNG::ProcessPNG_Compressed
ABCresult
0XX0
10X0
1100
1111
1016 # rewrite this directory if necessary (but always process TextualData normally)
1017 59 ▶ if ($outBuff and not $processProc and $subTable ne \%Image::ExifTool::PNG::TextualData) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outBuff and not $processProc and $subTable ne \%Image::ExifTool::PNG::TextualData) { } 5 54 59
Condition100%6/6
$outBuff and not $processProc and $subTable ne \%Image::ExifTool::PNG::TextualData
!ll&&!rl&&r
4955
$outBuff and not $processProc
!ll&&!rl&&r
44510
MC/DC100%3/3
$outBuff and not $processProc and $subTable ne \%Image::ExifTool::PNG::TextualData
$outBuff not $processProc $subTable ne \%Image::ExifTool::PNG::TextualData
Truth table100%4/4
A and not(B) and C
A= $outBuffB= not $processProcC= $subTable ne \%Image::ExifTool::PNG::TextualData
ABCresult
0XX0
10X0
1100
1111
1018 5 ▶ return 1 unless $$et{EDIT_DIRS}{$dirName};
Branch: 1 branch
BranchTrueFalseTotal
unless $et->{"EDIT_DIRS"}{$dirName} 2 3 5
1019 3 $$outBuff = $et->WriteDirectory(\%subdirInfo, $subTable);
1020 3 ▶ if ($tagName eq 'XMP' and $$outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagName eq "XMP" and $$outBuff) 3 0 3
Condition33%1/3
$tagName eq "XMP" and $$outBuff
!ll&&!rl&&r
003
MC/DC0%0/2
$tagName eq "XMP" and $$outBuff
$tagName eq "XMP" $$outBuff
Truth table33%1/3
A and B
A= $tagName eq "XMP"B= $$outBuff
ABresult
0X0
100
111
1021 # make sure the XMP is marked as read-only
1022 3 Image::ExifTool::XMP::ValidateXMP($outBuff,'r');
1023 }
1024 3 DoneDir($et, $dirName, $outBuff, $$tagInfo{NonStandard});
1025 } else {
1026 54 $processed = $et->ProcessDirectory(\%subdirInfo, $subTable, $processProc);
1027 }
1028 57 $compressed = 1; # pretend this is compressed since it is binary data
1029 } elsif ($outBuff) {
1030 0 ▶ if ($$et{DEL_GROUP}{$dirName} or ($dirName eq 'EXIF' and $$et{DEL_GROUP}{IFD0})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'DEL_GROUP'}{$dirName} or $dirName eq 'EXIF' and $et->{'DEL_GROUP'}{'IFD0'}) { } 0 0 0
Condition0%0/6
$et->{"DEL_GROUP"}{$dirName} or $dirName eq "EXIF" and $et->{"DEL_GROUP"}{"IFD0"}
l!l&&r!l&&!r
000
$dirName eq "EXIF" and $et->{"DEL_GROUP"}{"IFD0"}
!ll&&!rl&&r
000
MC/DC0%0/3
$et->{"DEL_GROUP"}{$dirName} or $dirName eq "EXIF" and $et->{"DEL_GROUP"}{"IFD0"}
$et->{"DEL_GROUP"}{$dirName} $dirName eq "EXIF" $et->{"DEL_GROUP"}{"IFD0"}
Truth table0%0/4
A or B and C
A= $et->{"DEL_GROUP"}{$dirName}B= $dirName eq "EXIF"C= $et->{"DEL_GROUP"}{"IFD0"}
ABCresult
1XX1
0111
00X0
0100
1031 0 $$outBuff = '';
1032 0 ++$$et{CHANGED};
1033 0 $et->VPrint(0, " Deleting $tag chunk");
1034 } else {
1035 0 ▶ if ($$et{EDIT_DIRS}{$dirName} or ($dirName eq 'EXIF' and $$et{EDIT_DIRS}{IFD0})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"EDIT_DIRS"}{$dirName} or $dirName eq "EXIF" and $et->{"EDIT_DIRS"}{"IFD0"}) 0 0 0
Condition0%0/6
$et->{"EDIT_DIRS"}{$dirName} or $dirName eq "EXIF" and $et->{"EDIT_DIRS"}{"IFD0"}
l!l&&r!l&&!r
000
$dirName eq "EXIF" and $et->{"EDIT_DIRS"}{"IFD0"}
!ll&&!rl&&r
000
MC/DC0%0/3
$et->{"EDIT_DIRS"}{$dirName} or $dirName eq "EXIF" and $et->{"EDIT_DIRS"}{"IFD0"}
$et->{"EDIT_DIRS"}{$dirName} $dirName eq "EXIF" $et->{"EDIT_DIRS"}{"IFD0"}
Truth table0%0/4
A or B and C
A= $et->{"EDIT_DIRS"}{$dirName}B= $dirName eq "EXIF"C= $et->{"EDIT_DIRS"}{"IFD0"}
ABCresult
1XX1
0111
00X0
0100
1036 0 $et->Warn("Can't write $dirName. Requires Compress::Zlib");
1037 }
1038 # pretend we did this directory so we don't try to recreate it
1039 0 DoneDir($et, $dirName, $outBuff, $$tagInfo{NonStandard});
1040 }
1041 }
1042 }
1043 93 ▶ if ($outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outBuff) 23 70 93
1044 23 my $writable = $$tagInfo{Writable};
1045 23 my $isOverwriting;
1046 23 ▶ if ($writable or ($$tagTablePtr{WRITABLE} and
Branch: 1 branch
BranchTrueFalseTotal
if ($writable or $tagTablePtr->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}) 5 18 23
Condition77%7/9
$writable or $tagTablePtr->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}
l!l&&r!l&&!r
0518
$tagTablePtr->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
1535
$tagTablePtr->{"WRITABLE"} and not defined $writable
!ll&&!rl&&r
1508
MC/DC50%2/4
$writable or $tagTablePtr->{"WRITABLE"} and not defined $writable and not $tagInfo->{"SubDirectory"}
$writable $tagTablePtr->{"WRITABLE"} not defined $writable not $tagInfo->{"SubDirectory"}
Truth table60%3/5
A or B and not(C) and not(D)
A= $writableB= $tagTablePtr->{"WRITABLE"}C= not defined $writableD= not $tagInfo->{"SubDirectory"}
ABCDresult
1XXX1
01111
00XX0
010X0
01100
1047 not defined $writable and not $$tagInfo{SubDirectory}))
1048 {
1049 # write new value for this tag if necessary
1050 5 my $newVal;
1051 5 ▶ if ($$et{DEL_GROUP}{PNG}){
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'DEL_GROUP'}{'PNG'}) { } 1 4 5
1052 # remove this tag now, but keep in ADD_PNG list to add back later
1053 1 $isOverwriting = 1;
1054 } else {
1055 # remove this from the list of PNG tags to add
1056 4 delete $$et{ADD_PNG}{$id};
1057 # (also handle case of tEXt tags written with lowercase first letter)
1058 4 delete $$et{ADD_PNG}{ucfirst($id)};
1059 4 my $nvHash = $et->GetNewValueHash($tagInfo);
1060 4 $isOverwriting = $et->IsOverwriting($nvHash);
1061 4 ▶ if (defined $deflateErr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $deflateErr) { } 0 4 4
1062 0 $newVal = $et->GetNewValue($nvHash);
1063 # can only write tag now if always overwriting
1064 0 ▶ if ($isOverwriting > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($isOverwriting > 0) { } 0 0 0
elsif ($isOverwriting) { } 0 0 0
1065 0 $val = '<deflate error>';
1066 } elsif ($isOverwriting) {
1067 0 $isOverwriting = 0; # can't overwrite
1068 0 ▶ $et->Warn($deflateErr) if $deflateErr;
Branch: 1 branch
BranchTrueFalseTotal
if $deflateErr 0 0 0
1069 }
1070 } else {
1071 4 ▶ if ($isOverwriting < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isOverwriting < 0) 0 4 4
1072 0 $isOverwriting = $et->IsOverwriting($nvHash, $val);
1073 }
1074 # (must get new value after IsOverwriting() in case it was shifted)
1075 4 $newVal = $et->GetNewValue($nvHash);
1076 }
1077 }
1078 5 ▶ if ($isOverwriting) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isOverwriting) 2 3 5
1079 2 ▶ $$outBuff = (defined $newVal) ? $newVal : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $newVal ? : 0 2 2
1080 2 ++$$et{CHANGED};
1081 2 $et->VerboseValue("- PNG:$tagName", $val);
1082 2 ▶ $et->VerboseValue("+ PNG:$tagName", $newVal) if defined $newVal;
Branch: 1 branch
BranchTrueFalseTotal
if defined $newVal 0 2 2
1083 }
1084 }
1085 23 ▶ if (defined $$outBuff and length $$outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$outBuff and length $$outBuff) 6 17 23
Condition100%3/3
defined $$outBuff and length $$outBuff
!ll&&!rl&&r
1346
MC/DC100%2/2
defined $$outBuff and length $$outBuff
defined $$outBuff length $$outBuff
Truth table100%3/3
A and B
A= defined $$outBuffB= length $$outBuff
ABresult
0X0
100
111
1086 6 ▶ if ($enc) { # must be tEXt/zTXt/iTXt if $enc is set
Branch: 2 branches
BranchTrueFalseTotal
if ($enc) { } 3 3 6
elsif ($wasCompressed) { } 0 3 3
1087 3 $$outBuff = BuildTextChunk($et, $tag, $tagInfo, $$outBuff, $lang);
1088 } elsif ($wasCompressed) {
1089 # re-compress the output data
1090 0 my $len = length $$outBuff;
1091 0 my $deflate = Compress::Zlib::deflateInit();
1092 0 ▶ if ($deflate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deflate) { } 0 0 0
1093 0 $$outBuff = $deflate->deflate($$outBuff);
1094 0 ▶ $$outBuff .= $deflate->flush() if defined $$outBuff;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$outBuff 0 0 0
1095 } else {
1096 0 undef $$outBuff;
1097 }
1098 0 ▶ if (not $$outBuff) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $$outBuff) { } 0 0 0
elsif (lc $tag eq 'zxif') { } 0 0 0
1099 0 $et->Warn("PNG:$tagName not written (compress error)");
1100 } elsif (lc $tag eq 'zxif') {
1101 0 $$outBuff = "\0" . pack('N',$len) . $$outBuff; # add zXIf header
1102 }
1103 }
1104 }
1105 23 return 1;
1106 }
1107 70 ▶ return 1 if $processed;
Branch: 1 branch
BranchTrueFalseTotal
if $processed 44 26 70
1108 } elsif ($outBuff) {
1109 0 ▶ if ($$et{DEL_GROUP}{PNG} and $tagTablePtr eq \%Image::ExifTool::PNG::TextualData) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"DEL_GROUP"}{"PNG"} and $tagTablePtr eq \%Image::ExifTool::PNG::TextualData) 0 0 0
Condition0%0/3
$et->{"DEL_GROUP"}{"PNG"} and $tagTablePtr eq \%Image::ExifTool::PNG::TextualData
!ll&&!rl&&r
000
MC/DC0%0/2
$et->{"DEL_GROUP"}{"PNG"} and $tagTablePtr eq \%Image::ExifTool::PNG::TextualData
$et->{"DEL_GROUP"}{"PNG"} $tagTablePtr eq \%Image::ExifTool::PNG::TextualData
Truth table0%0/3
A and B
A= $et->{"DEL_GROUP"}{"PNG"}B= $tagTablePtr eq \%Image::ExifTool::PNG::TextualData
ABresult
0X0
100
111
1110 # delete all TextualData tags if deleting the PNG group
1111 0 $$outBuff = '';
1112 0 ++$$et{CHANGED};
1113 0 $et->VerboseValue("- PNG:$tag", $val);
1114 }
1115 0 return 1;
1116 } else {
1117 0 my $name;
1118 0 ($name = $tag) =~ s/\s+(.)/\u$1/g; # remove white space from tag name
1119 0 $tagInfo = { Name => $name };
1120 0 ▶ $$tagInfo{LangCode} = $lang if $lang;
Branch: 1 branch
BranchTrueFalseTotal
if $lang 0 0 0
1121 # make unknown profiles binary data type
1122 0 ▶ $$tagInfo{Binary} = 1 if $tag =~ /^Raw profile type /;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^Raw profile type / 0 0 0
1123 0 ▶ $verbose and $et->VPrint(0, " [adding $tag]\n");
Branch: 1 branch
BranchTrueFalseTotal
$verbose and $et->VPrint(0, " [adding $tag]\n") 0 0 0
1124 0 AddTagToTable($tagTablePtr, $tag, $tagInfo);
1125 }
1126 #
1127 # store this tag information
1128 #
1129 26 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 26 26
1130 # temporarily remove subdirectory so it isn't printed in verbose information
1131 # since we aren't decoding it anyway;
1132 0 my $subdir = $$tagInfo{SubDirectory};
1133 0 delete $$tagInfo{SubDirectory};
1134 0 $et->VerboseInfo($tag, $tagInfo,
1135 Table => $tagTablePtr,
1136 DataPt => \$val,
1137 );
1138 0 ▶ $$tagInfo{SubDirectory} = $subdir if $subdir;
Branch: 1 branch
BranchTrueFalseTotal
if $subdir 0 0 0
1139 }
1140 # set the RawConv dynamically depending on whether this is binary or not
1141 26 my $delRawConv;
1142 26 ▶ if ($compressed and not defined $$tagInfo{ValueConv}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compressed and not defined $tagInfo->{"ValueConv"}) 0 26 26
Condition33%1/3
$compressed and not defined $tagInfo->{"ValueConv"}
!ll&&!rl&&r
2600
MC/DC0%0/2
$compressed and not defined $tagInfo->{"ValueConv"}
$compressed not defined $tagInfo->{"ValueConv"}
Truth table33%1/3
A and not(B)
A= $compressedB= not defined $tagInfo->{"ValueConv"}
ABresult
0X0
100
111
1143 0 $$tagInfo{RawConv} = '\$val';
1144 0 $delRawConv = 1;
1145 }
1146 26 $et->FoundTag($tagInfo, $val);
1147 26 ▶ delete $$tagInfo{RawConv} if $delRawConv;
Branch: 1 branch
BranchTrueFalseTotal
if $delRawConv 0 26 26
1148 26 return 1;
1149 }
1150  
1151 #------------------------------------------------------------------------------
1152 # Process encoded PNG profile information
1153 # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) Pointer to tag table
1154 # Returns: 1 on success
1155 sub ProcessProfile($$$)
1156 1 ▶{
Subroutine ProcessProfile: called CC=32 SCAR=61.9
Pod undocumented
1157 1 my ($et, $dirInfo, $tagTablePtr) = @_;
1158 1 my $dataPt = $$dirInfo{DataPt};
1159 1 my $tagInfo = $$dirInfo{TagInfo};
1160 1 my $outBuff = $$dirInfo{OutBuff};
1161 1 my $tagName = $$tagInfo{Name};
1162  
1163 # ImageMagick 5.3.6 writes profiles with the following headers:
1164 # "\nICC Profile\n", "\nIPTC profile\n", "\n\xaa\x01{generic prof\n"
1165 # and "\ngeneric profile\n"
1166 1 ▶ return 0 unless $$dataPt =~ /^\n(.*?)\n\s*(\d+)\n(.*)/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $$dataPt =~ /^\n(.*?)\n\s*(\d+)\n(.*)/s 0 1 1
1167 1 my ($profileType, $len) = ($1, $2);
1168 # data is encoded in hex, so change back to binary
1169 1 my $buff = pack('H*', join('',split(' ',$3)));
1170 1 my $actualLen = length $buff;
1171 1 ▶ if ($len ne $actualLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len ne $actualLen) 0 1 1
1172 0 $et->Warn("$tagName is wrong size (should be $len bytes but is $actualLen)");
1173 0 $len = $actualLen;
1174 }
1175 1 my $verbose = $et->Options('Verbose');
1176 1 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 1 1
1177 0 ▶ if ($verbose > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 2) 0 0 0
1178 0 $et->VerboseDir("Decoded $tagName", 0, $len);
1179 0 $et->VerboseDump(\$buff);
1180 }
1181 # don't indent next directory (since it is really the same data)
1182 0 $$et{INDENT} =~ s/..$//;
1183 }
1184 1 my %dirInfo = (
1185 Parent => 'PNG',
1186 DataPt => \$buff,
1187 DataLen => $len,
1188 DirStart => 0,
1189 DirLen => $len,
1190 Base => 0,
1191 OutFile => $outBuff,
1192 );
1193 1 $$et{PROCESSED} = { }; # reset processed directory offsets
1194 1 my $processed = 0;
1195 1 my $oldChanged = $$et{CHANGED};
1196 1 my $exifTable = GetTagTable('Image::ExifTool::Exif::Main');
1197 1 my $editDirs = $$et{EDIT_DIRS};
1198  
1199 1 ▶ if ($tagTablePtr ne $exifTable) {
Branch: 4 branches
BranchTrueFalseTotal
if ($tagTablePtr ne $exifTable) { } 1 0 1
elsif ($buff =~ /^$Image::ExifTool::exifAPP1hdr/) { } 0 0 0
elsif ($buff =~ /^$Image::ExifTool::xmpAPP1hdr/) { } 0 0 0
elsif ($buff =~ /^(MM\0\x2a|II\x2a\0)/) { } 0 0 0
1200 # this is unfortunate, but the "IPTC" profile may be stored as either
1201 # IPTC IIM or a Photoshop IRB resource, so we must test for this
1202 1 ▶ if ($tagName eq 'IPTC_Profile' and $buff =~ /^\x1c/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagName eq "IPTC_Profile" and $buff =~ /^\x1c/) 0 1 1
Condition33%1/3
$tagName eq "IPTC_Profile" and $buff =~ /^\x1c/
!ll&&!rl&&r
010
MC/DC0%0/2
$tagName eq "IPTC_Profile" and $buff =~ /^\x1c/
$tagName eq "IPTC_Profile" $buff =~ /^\x1c/
Truth table33%1/3
A and B
A= $tagName eq "IPTC_Profile"B= $buff =~ /^\x1c/
ABresult
0X0
100
111
1203 0 $tagTablePtr = GetTagTable('Image::ExifTool::IPTC::Main');
1204 }
1205 # process non-EXIF and non-APP1 profile as-is
1206 1 ▶ if ($outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outBuff) { } 0 1 1
1207 # no need to rewrite this if not editing tags in this directory
1208 0 my $dir = $tagName;
1209 0 ▶ $dir =~ s/_Profile// unless $dir =~ /^ICC/;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir =~ /^ICC/ 0 0 0
1210 0 ▶ return 1 unless $$editDirs{$dir};
Branch: 1 branch
BranchTrueFalseTotal
unless $editDirs->{$dir} 0 0 0
1211 0 $$outBuff = $et->WriteDirectory(\%dirInfo, $tagTablePtr);
1212 0 DoneDir($et, $dir, $outBuff, $$tagInfo{NonStandard});
1213 } else {
1214 1 $processed = $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
1215 }
1216 } elsif ($buff =~ /^$Image::ExifTool::exifAPP1hdr/) {
1217 # APP1 EXIF information
1218 0 ▶ return 1 if $outBuff and not $$editDirs{IFD0};
Branch: 1 branch
BranchTrueFalseTotal
if $outBuff and not $editDirs->{"IFD0"} 0 0 0
Condition0%0/3
$outBuff and not $editDirs->{"IFD0"}
!ll&&!rl&&r
000
MC/DC0%0/2
$outBuff and not $editDirs->{"IFD0"}
$outBuff not $editDirs->{"IFD0"}
Truth table0%0/3
A and not(B)
A= $outBuffB= not $editDirs->{"IFD0"}
ABresult
0X0
100
111
1219 0 my $hdrLen = length($Image::ExifTool::exifAPP1hdr);
1220 0 $dirInfo{DirStart} += $hdrLen;
1221 0 $dirInfo{DirLen} -= $hdrLen;
1222 0 ▶ if ($outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outBuff) { } 0 0 0
1223 # delete non-standard EXIF if recreating from scratch
1224 0 ▶ if ($$et{DEL_GROUP}{EXIF} or $$et{DEL_GROUP}{IFD0}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"DEL_GROUP"}{"EXIF"} or $et->{"DEL_GROUP"}{"IFD0"}) 0 0 0
Condition0%0/3
$et->{"DEL_GROUP"}{"EXIF"} or $et->{"DEL_GROUP"}{"IFD0"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$et->{"DEL_GROUP"}{"EXIF"} or $et->{"DEL_GROUP"}{"IFD0"}
$et->{"DEL_GROUP"}{"EXIF"} $et->{"DEL_GROUP"}{"IFD0"}
Truth table0%0/3
A or B
A= $et->{"DEL_GROUP"}{"EXIF"}B= $et->{"DEL_GROUP"}{"IFD0"}
ABresult
1X1
011
000
1225 0 $$outBuff = '';
1226 0 $et->VPrint(0, ' Deleting non-standard APP1 EXIF information');
1227 0 return 1;
1228 }
1229 0 $$outBuff = $et->WriteDirectory(\%dirInfo, $tagTablePtr,
1230 \&Image::ExifTool::WriteTIFF);
1231 0 ▶ $$outBuff = $Image::ExifTool::exifAPP1hdr . $$outBuff if $$outBuff;
Branch: 1 branch
BranchTrueFalseTotal
if $$outBuff 0 0 0
1232 0 DoneDir($et, 'IFD0', $outBuff, $$tagInfo{NonStandard});
1233 } else {
1234 0 $processed = $et->ProcessTIFF(\%dirInfo);
1235 }
1236 } elsif ($buff =~ /^$Image::ExifTool::xmpAPP1hdr/) {
1237 # APP1 XMP information
1238 0 my $hdrLen = length($Image::ExifTool::xmpAPP1hdr);
1239 0 my $tagTablePtr = GetTagTable('Image::ExifTool::XMP::Main');
1240 0 $dirInfo{DirStart} += $hdrLen;
1241 0 $dirInfo{DirLen} -= $hdrLen;
1242 0 ▶ if ($outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outBuff) { } 0 0 0
1243 0 ▶ return 1 unless $$editDirs{XMP};
Branch: 1 branch
BranchTrueFalseTotal
unless $editDirs->{"XMP"} 0 0 0
1244 0 $$outBuff = $et->WriteDirectory(\%dirInfo, $tagTablePtr);
1245 0 ▶ $$outBuff and $$outBuff = $Image::ExifTool::xmpAPP1hdr . $$outBuff;
Branch: 1 branch
BranchTrueFalseTotal
$$outBuff and $$outBuff = $Image::ExifTool::xmpAPP1hdr . $$outBuff 0 0 0
1246 0 DoneDir($et, 'XMP', $outBuff, $$tagInfo{NonStandard});
1247 } else {
1248 0 $processed = $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
1249 }
1250 } elsif ($buff =~ /^(MM\0\x2a|II\x2a\0)/) {
1251 # TIFF information
1252 0 ▶ return 1 if $outBuff and not $$editDirs{IFD0};
Branch: 1 branch
BranchTrueFalseTotal
if $outBuff and not $editDirs->{"IFD0"} 0 0 0
Condition0%0/3
$outBuff and not $editDirs->{"IFD0"}
!ll&&!rl&&r
000
MC/DC0%0/2
$outBuff and not $editDirs->{"IFD0"}
$outBuff not $editDirs->{"IFD0"}
Truth table0%0/3
A and not(B)
A= $outBuffB= not $editDirs->{"IFD0"}
ABresult
0X0
100
111
1253 0 ▶ if ($outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outBuff) { } 0 0 0
1254 # delete non-standard EXIF if recreating from scratch
1255 0 ▶ if ($$et{DEL_GROUP}{EXIF} or $$et{DEL_GROUP}{IFD0}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"DEL_GROUP"}{"EXIF"} or $et->{"DEL_GROUP"}{"IFD0"}) 0 0 0
Condition0%0/3
$et->{"DEL_GROUP"}{"EXIF"} or $et->{"DEL_GROUP"}{"IFD0"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$et->{"DEL_GROUP"}{"EXIF"} or $et->{"DEL_GROUP"}{"IFD0"}
$et->{"DEL_GROUP"}{"EXIF"} $et->{"DEL_GROUP"}{"IFD0"}
Truth table0%0/3
A or B
A= $et->{"DEL_GROUP"}{"EXIF"}B= $et->{"DEL_GROUP"}{"IFD0"}
ABresult
1X1
011
000
1256 0 $$outBuff = '';
1257 0 $et->VPrint(0, ' Deleting non-standard EXIF/TIFF information');
1258 0 return 1;
1259 }
1260 0 $$outBuff = $et->WriteDirectory(\%dirInfo, $tagTablePtr,
1261 \&Image::ExifTool::WriteTIFF);
1262 0 DoneDir($et, 'IFD0', $outBuff, $$tagInfo{NonStandard});
1263 } else {
1264 0 $processed = $et->ProcessTIFF(\%dirInfo);
1265 }
1266 } else {
1267 0 my $profName = $profileType;
1268 0 $profName =~ tr/\x00-\x1f\x7f-\xff/./;
1269 0 $et->Warn("Unknown raw profile '${profName}'");
1270 }
1271 1 ▶ if ($outBuff and defined $$outBuff and length $$outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outBuff and defined $$outBuff and length $$outBuff) 0 1 1
Condition33%2/6
$outBuff and defined $$outBuff and length $$outBuff
!ll&&!rl&&r
100
$outBuff and defined $$outBuff
!ll&&!rl&&r
100
MC/DC0%0/3
$outBuff and defined $$outBuff and length $$outBuff
$outBuff defined $$outBuff length $$outBuff
Truth table25%1/4
A and B and C
A= $outBuffB= defined $$outBuffC= length $$outBuff
ABCresult
0XX0
10X0
1100
1111
1272 0 ▶ if ($$et{CHANGED} != $oldChanged) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'CHANGED'} != $oldChanged) { } 0 0 0
1273 0 my $hdr = sprintf("\n%s\n%8d\n", $profileType, length($$outBuff));
1274 # hex encode the data
1275 0 $$outBuff = $hdr . HexEncode($outBuff);
1276 } else {
1277 0 undef $$outBuff;
1278 }
1279 }
1280 1 return $processed;
1281 }
1282  
1283 #------------------------------------------------------------------------------
1284 # Process PNG compressed zTXt or iCCP chunk
1285 # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) Pointer to tag table
1286 # Returns: 1 on success
1287 # Notes: writes new chunk data to ${$$dirInfo{OutBuff}} if writing tag
1288 sub ProcessPNG_Compressed($$$)
1289 2 ▶{
Subroutine ProcessPNG_Compressed: called CC=9 SCAR=25.4
Pod undocumented
1290 2 my ($et, $dirInfo, $tagTablePtr) = @_;
1291 2 my ($tag, $val) = split /\0/, ${$$dirInfo{DataPt}}, 2;
1292 2 ▶ return 0 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 2 2
1293 # set compressed to 2 + compression method to decompress the data
1294 2 my $compressed = 2 + unpack('C', $val);
1295 2 my $hdr = $tag . "\0" . substr($val, 0, 1);
1296 2 $val = substr($val, 1); # remove compression method byte
1297 2 my $success;
1298 2 my $outBuff = $$dirInfo{OutBuff};
1299 2 my $tagInfo = $$dirInfo{TagInfo};
1300 # use the PNG chunk tag instead of the embedded tag name for iCCP chunks
1301 2 ▶ if ($tagInfo and $$tagInfo{Name} eq 'ICC_Profile') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo and $tagInfo->{'Name'} eq 'ICC_Profile') { } 1 1 2
Condition66%2/3
$tagInfo and $tagInfo->{"Name"} eq "ICC_Profile"
!ll&&!rl&&r
011
MC/DC50%1/2
$tagInfo and $tagInfo->{"Name"} eq "ICC_Profile"
$tagInfo $tagInfo->{"Name"} eq "ICC_Profile"
Truth table66%2/3
A and B
A= $tagInfoB= $tagInfo->{"Name"} eq "ICC_Profile"
ABresult
0X0
100
111
1302 1 $et->VerboseDir('iCCP');
1303 1 $tagTablePtr = \%Image::ExifTool::PNG::Main;
1304 1 ▶ FoundPNG($et, $tagTablePtr, 'iCCP-name', $tag) if length($tag) and not $outBuff;
Branch: 1 branch
BranchTrueFalseTotal
if length $tag and not $outBuff 1 0 1
Condition33%1/3
length $tag and not $outBuff
!ll&&!rl&&r
001
MC/DC0%0/2
length $tag and not $outBuff
length $tag not $outBuff
Truth table33%1/3
A and not(B)
A= length $tagB= not $outBuff
ABresult
0X0
100
111
1305 1 $success = FoundPNG($et, $tagTablePtr, 'iCCP', $val, $compressed, $outBuff);
1306 1 ▶ if ($outBuff and $$outBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outBuff and $$outBuff) 0 1 1
Condition33%1/3
$outBuff and $$outBuff
!ll&&!rl&&r
100
MC/DC0%0/2
$outBuff and $$outBuff
$outBuff $$outBuff
Truth table33%1/3
A and B
A= $outBuffB= $$outBuff
ABresult
0X0
100
111
1307 0 my $profileName = $et->GetNewValue($Image::ExifTool::PNG::Main{'iCCP-name'});
1308 0 ▶ if (defined $profileName) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $profileName) 0 0 0
1309 0 $hdr = $profileName . substr($hdr, length $tag);
1310 0 $et->VerboseValue("+ PNG:ProfileName", $profileName);
1311 }
1312 0 $$outBuff = $hdr . $$outBuff;
1313 }
1314 } else {
1315 1 $success = FoundPNG($et, $tagTablePtr, $tag, $val, $compressed, $outBuff, 'Latin');
1316 }
1317 2 return $success;
1318 }
1319  
1320 #------------------------------------------------------------------------------
1321 # Process PNG tEXt chunk
1322 # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) Pointer to tag table
1323 # Returns: 1 on success
1324 # Notes: writes new chunk data to ${$$dirInfo{OutBuff}} if writing tag
1325 sub ProcessPNG_tEXt($$$)
1326 21 ▶{
Subroutine ProcessPNG_tEXt: called CC=2 SCAR=6.9
Pod undocumented
1327 21 my ($et, $dirInfo, $tagTablePtr) = @_;
1328 21 my ($tag, $val) = split /\0/, ${$$dirInfo{DataPt}}, 2;
1329 21 my $outBuff = $$dirInfo{OutBuff};
1330 21 ▶ $$et{INDENT} = substr($$et{INDENT}, 0, -2) if $$et{OPTIONS}{Verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"OPTIONS"}{"Verbose"} 1 20 21
1331 21 return FoundPNG($et, $tagTablePtr, $tag, $val, undef, $outBuff, 'Latin');
1332 }
1333  
1334 #------------------------------------------------------------------------------
1335 # Process PNG iTXt chunk
1336 # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) Pointer to tag table
1337 # Returns: 1 on success
1338 # Notes: writes new chunk data to ${$$dirInfo{OutBuff}} if writing tag
1339 sub ProcessPNG_iTXt($$$)
1340 12 ▶{
Subroutine ProcessPNG_iTXt: called CC=5 SCAR=16.6
Pod undocumented
1341 12 my ($et, $dirInfo, $tagTablePtr) = @_;
1342 12 my ($tag, $dat) = split /\0/, ${$$dirInfo{DataPt}}, 2;
1343 12 ▶ return 0 unless defined $dat and length($dat) >= 4;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dat and length $dat >= 4 0 12 12
Condition33%1/3
defined $dat and length $dat >= 4
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $dat and length $dat >= 4
defined $dat length $dat >= 4
Truth table33%1/3
A and B
A= defined $datB= length $dat >= 4
ABresult
0X0
100
111
1344 12 my ($compressed, $meth) = unpack('CC', $dat);
1345 12 my ($lang, $trans, $val) = split /\0/, substr($dat, 2), 3;
1346 # set compressed flag so we will decompress it in FoundPNG()
1347 12 ▶ $compressed and $compressed = 2 + $meth;
Branch: 1 branch
BranchTrueFalseTotal
$compressed and $compressed = 2 + $meth 0 12 12
1348 12 my $outBuff = $$dirInfo{OutBuff};
1349 12 ▶ $$et{INDENT} = substr($$et{INDENT}, 0, -2) if $$et{OPTIONS}{Verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"OPTIONS"}{"Verbose"} 1 11 12
1350 12 return FoundPNG($et, $tagTablePtr, $tag, $val, $compressed, $outBuff, 'UTF8', $lang);
1351 }
1352  
1353 #------------------------------------------------------------------------------
1354 # Process PNG eXIf/zXIf chunk
1355 # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) Pointer to tag table
1356 # Returns: 1 on success
1357 # Notes: writes new chunk data to ${$$dirInfo{OutBuff}} if writing tag
1358 sub ProcessPNG_eXIf($$$)
1359 2 ▶{
Subroutine ProcessPNG_eXIf: called CC=12 SCAR=41.0
Pod undocumented
1360 2 my ($et, $dirInfo, $tagTablePtr) = @_;
1361 2 my $outBuff = $$dirInfo{OutBuff};
1362 2 my $dataPt = $$dirInfo{DataPt};
1363 2 my $tagInfo = $$dirInfo{TagInfo};
1364 2 my $tag = $$tagInfo{TagID};
1365 2 ▶ my $del = $outBuff && ($$et{DEL_GROUP}{EXIF} or $$et{DEL_GROUP}{IFD0});
Condition16%1/6
$outBuff && ($et->{'DEL_GROUP'}{'EXIF'} || $et->{'DEL_GROUP'}{'IFD0'})
!ll&&!rl&&r
200
$et->{"DEL_GROUP"}{"EXIF"} or $et->{"DEL_GROUP"}{"IFD0"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$outBuff && ($et->{'DEL_GROUP'}{'EXIF'} || $et->{'DEL_GROUP'}{'IFD0'})
$outBuff $et->{"DEL_GROUP"}{"EXIF"} $et->{"DEL_GROUP"}{"IFD0"}
Truth table25%1/4
A && B or C
A= $outBuffB= $et->{"DEL_GROUP"}{"EXIF"}C= $et->{"DEL_GROUP"}{"IFD0"}
ABCresult
0XX0
1000
11X1
1011
1366 2 my $type;
1367  
1368 2 ▶ if ($$dataPt =~ /^Exif\0\0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dataPt =~ /^Exif\0\0/) 0 2 2
1369 0 $et->Warn('Improper "Exif00" header in EXIF chunk');
1370 0 $$dataPt = substr($$dataPt, 6);
1371 0 $$dirInfo{DataLen} = length $$dataPt;
1372 0 ▶ $$dirInfo{DirLen} -= 6 if $$dirInfo{DirLen};
Branch: 1 branch
BranchTrueFalseTotal
if $dirInfo->{"DirLen"} 0 0 0
1373 }
1374 2 ▶ if ($$dataPt =~ /^(\0|II|MM)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$dataPt =~ /^(\0|II|MM)/) { } 2 0 2
elsif ($del) { } 0 0 0
1375 2 $type = $1;
1376 } elsif ($del) {
1377 0 $et->VPrint(0, " Deleting invalid $tag chunk");
1378 0 $$outBuff = '';
1379 0 ++$$et{CHANGED};
1380 0 return 1;
1381 } else {
1382 0 $et->Warn("Invalid $tag chunk");
1383 0 return 0;
1384 }
1385 2 ▶ if ($type eq "\0") { # is this compressed EXIF?
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq "\000") { } 0 2 2
elsif (not $outBuff) { } 2 0 2
elsif ($del and lc $tag eq 'zxif') { } 0 0 0
elsif ($et->{'EDIT_DIRS'}{'IFD0'}) { } 0 0 0
1386 0 my $buf = substr($$dataPt, 5);
1387 # go around again to uncompress the data
1388 0 $tagTablePtr = GetTagTable('Image::ExifTool::PNG::Main');
1389 0 return FoundPNG($et, $tagTablePtr, $$tagInfo{TagID}, \$buf, 2, $outBuff);
1390 } elsif (not $outBuff) {
1391 2 return $et->ProcessTIFF($dirInfo);
1392 # (zxIf was not adopted)
1393 #} elsif ($del and ($et->Options('Compress') xor lc($tag) eq 'zxif')) {
1394 ▶ } elsif ($del and lc($tag) eq 'zxif') {
Condition0%0/3
$del and lc $tag eq "zxif"
!ll&&!rl&&r
000
MC/DC0%0/2
$del and lc $tag eq "zxif"
$del lc $tag eq "zxif"
Truth table0%0/3
A and B
A= $delB= lc $tag eq "zxif"
ABresult
0X0
100
111
1395 0 $et->VPrint(0, " Deleting $tag chunk");
1396 0 $$outBuff = '';
1397 0 ++$$et{CHANGED};
1398 } elsif ($$et{EDIT_DIRS}{IFD0}) {
1399 0 $$outBuff = $et->WriteDirectory($dirInfo, $tagTablePtr,
1400 \&Image::ExifTool::WriteTIFF);
1401 0 DoneDir($et, 'IFD0', $outBuff, $$tagInfo{NonStandard});
1402 }
1403 0 return 1;
1404 }
1405  
1406 #------------------------------------------------------------------------------
1407 # Extract meta information from a PNG image
1408 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
1409 # Returns: 1 on success, 0 if this wasn't a valid PNG image, or -1 on write error
1410 sub ProcessPNG($$)
1411 12 ▶{
Subroutine ProcessPNG: called CC=122 SCAR=67.6
Pod undocumented
1412 12 my ($et, $dirInfo) = @_;
1413 12 my $outfile = $$dirInfo{OutFile};
1414 12 my $raf = $$dirInfo{RAF};
1415 12 my $datChunk = '';
1416 12 my $datCount = 0;
1417 12 my $datBytes = 0;
1418 12 my $fastScan = $et->Options('FastScan');
1419 12 my $hash = $$et{ImageDataHash};
1420 12 my ($n, $sig, $err, $hbuf, $dbuf, $cbuf);
1421 12 my ($wasHdr, $wasEnd, $wasDat, $doTxt, @txtOffset, $wasTrailer);
1422  
1423 # check to be sure this is a valid PNG/MNG/JNG image
1424 12 ▶ return 0 unless $raf->Read($sig,8) == 8 and $pngLookup{$sig};
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($sig, 8) == 8 and $pngLookup{$sig} 0 12 12
Condition33%1/3
$raf->Read($sig, 8) == 8 and $pngLookup{$sig}
!ll&&!rl&&r
0012
MC/DC0%0/2
$raf->Read($sig, 8) == 8 and $pngLookup{$sig}
$raf->Read($sig, 8) == 8 $pngLookup{$sig}
Truth table33%1/3
A and B
A= $raf->Read($sig, 8) == 8B= $pngLookup{$sig}
ABresult
0X0
100
111
1425  
1426 12 ▶ if ($outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile) { } 5 7 12
1427 5 delete $$et{TextChunkType};
1428 5 ▶ Write($outfile, $sig) or $err = 1 if $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if $outfile 5 0 5
Condition33%2/6
$outfile && (&Write($outfile, $sig) || ($err = 1))
!ll&&!rl&&r
050
&Write($outfile, $sig) or $err = 1
l!l&&r!l&&!r
500
MC/DC0%0/3
$outfile && (&Write($outfile, $sig) || ($err = 1))
$outfile &Write($outfile, $sig) $err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $sig)C= $err = 1
ABCresult
0XX0
1000
11X1
1011
1429 # can only add tags in Main and TextualData tables
1430 5 $$et{ADD_PNG} = $et->GetNewTagInfoHash(
1431 \%Image::ExifTool::PNG::Main,
1432 \%Image::ExifTool::PNG::TextualData);
1433 # initialize with same directories, with PNG tags taking priority
1434 5 $et->InitWriteDirs(\%pngMap,'PNG');
1435 } else {
1436 # disable buffering in FastScan mode
1437 7 ▶ $$raf{NoBuffer} = 1 if $fastScan;
Branch: 1 branch
BranchTrueFalseTotal
if $fastScan 0 7 7
1438 }
1439 12 my ($fileType, $hdrChunk, $endChunk) = @{$pngLookup{$sig}};
1440 12 $et->SetFileType($fileType); # set the FileType tag
1441 12 SetByteOrder('MM'); # PNG files are big-endian
1442 12 my $tagTablePtr = GetTagTable('Image::ExifTool::PNG::Main');
1443 12 my $mngTablePtr;
1444 12 ▶ if ($fileType ne 'PNG') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fileType ne "PNG") 0 12 12
1445 0 $mngTablePtr = GetTagTable('Image::ExifTool::MNG::Main');
1446 }
1447 12 my $verbose = $et->Options('Verbose');
1448 12 my $validate = $et->Options('Validate');
1449 12 my $out = $et->Options('TextOut');
1450  
1451 # scan ahead to find offsets of all text chunks after IDAT
1452 12 ▶ if ($outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile) 5 7 12
1453 5 ▶ while ($raf->Read($hbuf,8) == 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->Read($hbuf, 8) == 8) 30 0 30
1454 30 my ($len, $chunk) = unpack('Na4',$hbuf);
1455 30 ▶ last if $len > 0x7fffffff;
Branch: 1 branch
BranchTrueFalseTotal
if $len > 2147483647 0 30 30
1456 30 ▶ if ($wasDat) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wasDat) { } 15 15 30
elsif ($isDatChunk{$chunk}) { } 5 10 15
1457 15 ▶ last if $noLeapFrog{$chunk}; # (don't move text across these chunks)
Branch: 1 branch
BranchTrueFalseTotal
if $noLeapFrog{$chunk} 5 10 15
1458 10 ▶ push @txtOffset, $raf->Tell() - 8 if $isTxtChunk{$chunk};
Branch: 1 branch
BranchTrueFalseTotal
if $isTxtChunk{$chunk} 10 0 10
1459 } elsif ($isDatChunk{$chunk}) {
1460 5 $wasDat = $chunk;
1461 }
1462 25 ▶ $raf->Seek($len + 4, 1) or last; # skip chunk data
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($len + 4, 1) or last 25 0 25
1463 }
1464 5 ▶ $raf->Seek(8,0) or $et->Error('Error seeking in file'), return -1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek(8, 0) or $et->Error("Error seeking in file"), (return -1) 5 0 5
1465 5 undef $wasDat;
1466 }
1467  
1468 # process the PNG/MNG/JNG chunks
1469 12 undef $noCompressLib;
1470 12 for (;;) {
1471 110 ▶ if ($doTxt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doTxt) 15 95 110
1472 # read text chunks that were found after IDAT so we can write them before
1473 15 ▶ $raf->Seek(shift(@txtOffset), 0) or $et->Error('Seek error'), last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek(shift @txtOffset, 0) or $et->Error("Seek error"), last 15 0 15
1474 # (this is the IDAT offset if @txtOffset is now empty)
1475 15 ▶ undef $doTxt unless @txtOffset;
Branch: 1 branch
BranchTrueFalseTotal
unless @txtOffset 5 10 15
1476 }
1477 110 $n = $raf->Read($hbuf,8); # read chunk header
1478  
1479 110 ▶ if ($wasEnd) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wasEnd) { } 7 103 110
elsif ($n != 8) { } 0 103 103
1480 7 ▶ last unless $n; # stop now if normal end of PNG
Branch: 1 branch
BranchTrueFalseTotal
unless $n 7 0 7
1481 0 $et->Warn("Trailer data after $fileType $endChunk chunk", 1);
1482 0 $wasTrailer = 1;
1483 0 ▶ last if $n < 8;
Branch: 1 branch
BranchTrueFalseTotal
if $n < 8 0 0 0
1484 0 $$et{SET_GROUP1} = 'Trailer';
1485 } elsif ($n != 8) {
1486 0 ▶ $et->Warn("Truncated $fileType image") unless $wasEnd;
Branch: 1 branch
BranchTrueFalseTotal
unless $wasEnd 0 0 0
1487 0 last;
1488 }
1489 103 my ($len, $chunk) = unpack('Na4',$hbuf);
1490 103 ▶ if ($len > 0x7fffffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 2147483647) 0 103 103
1491 0 ▶ $et->Warn("Invalid $fileType chunk size") unless $wasEnd;
Branch: 1 branch
BranchTrueFalseTotal
unless $wasEnd 0 0 0
1492 0 last;
1493 }
1494 103 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 9 94 103
1495 9 ▶ print $out " Moving $chunk from after IDAT ($len bytes)\n" if $doTxt;
Branch: 1 branch
BranchTrueFalseTotal
if $doTxt 2 7 9
1496 # don't dump image data chunks in verbose mode (only give count instead)
1497 9 ▶ if ($datCount and $chunk ne $datChunk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($datCount and $chunk ne $datChunk) 1 8 9
Condition66%2/3
$datCount and $chunk ne $datChunk
!ll&&!rl&&r
801
MC/DC50%1/2
$datCount and $chunk ne $datChunk
$datCount $chunk ne $datChunk
Truth table66%2/3
A and B
A= $datCountB= $chunk ne $datChunk
ABresult
0X0
100
111
1498 1 ▶ my $s = $datCount > 1 ? 's' : '';
Branch: 1 branch
BranchTrueFalseTotal
$datCount > 1 ? : 0 1 1
1499 1 print $out "$fileType $datChunk ($datCount chunk$s, total $datBytes bytes)\n";
1500 1 ▶ print $out "$$et{INDENT}(ImageDataHash: $datBytes bytes of $datChunk data)\n" if $hash;
Branch: 1 branch
BranchTrueFalseTotal
if $hash 0 1 1
1501 1 $datCount = $datBytes = 0;
1502 }
1503 }
1504 103 ▶ unless ($wasHdr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($wasHdr) 12 91 103
1505 12 ▶ if ($chunk eq $hdrChunk) {
Branch: 2 branches
BranchTrueFalseTotal
if ($chunk eq $hdrChunk) { } 12 0 12
elsif ($hdrChunk eq 'IHDR' and $chunk eq 'CgBI') { } 0 0 0
1506 12 $wasHdr = 1;
1507 ▶ } elsif ($hdrChunk eq 'IHDR' and $chunk eq 'CgBI') {
Condition0%0/3
$hdrChunk eq "IHDR" and $chunk eq "CgBI"
!ll&&!rl&&r
000
MC/DC0%0/2
$hdrChunk eq "IHDR" and $chunk eq "CgBI"
$hdrChunk eq "IHDR" $chunk eq "CgBI"
Truth table0%0/3
A and B
A= $hdrChunk eq "IHDR"B= $chunk eq "CgBI"
ABresult
0X0
100
111
1508 0 $et->Warn('Non-standard PNG image (Apple iPhone format)');
1509 } else {
1510 0 $et->Warn("$fileType image did not start with $hdrChunk");
1511 }
1512 }
1513 103 ▶ if ($outfile and ($isDatChunk{$chunk} or $chunk eq $endChunk) and @txtOffset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile and $isDatChunk{$chunk} || $chunk eq $endChunk and @txtOffset) 5 98 103
Condition100%9/9
$outfile and $isDatChunk{$chunk} || $chunk eq $endChunk and @txtOffset
!ll&&!rl&&r
88105
$outfile and $isDatChunk{$chunk} || $chunk eq $endChunk
!ll&&!rl&&r
583015
$isDatChunk{$chunk} or $chunk eq $endChunk
l!l&&r!l&&!r
10530
MC/DC75%3/4
$outfile and $isDatChunk{$chunk} || $chunk eq $endChunk and @txtOffset
$outfile $isDatChunk{$chunk} $chunk eq $endChunk @txtOffset
Truth table83%5/6
A and B or C and D
A= $outfileB= $isDatChunk{$chunk}C= $chunk eq $endChunkD= @txtOffset
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
1514 # continue processing here after we move the text chunks from after IDAT
1515 5 push @txtOffset, $raf->Tell() - 8;
1516 5 $doTxt = 1; # process text chunks now
1517 5 next;
1518 }
1519 98 ▶ if ($isDatChunk{$chunk}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isDatChunk{$chunk}) { } 12 86 98
1520 12 ▶ if ($fastScan and $fastScan >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fastScan and $fastScan >= 2) 0 12 12
Condition33%1/3
$fastScan and $fastScan >= 2
!ll&&!rl&&r
1200
MC/DC0%0/2
$fastScan and $fastScan >= 2
$fastScan $fastScan >= 2
Truth table33%1/3
A and B
A= $fastScanB= $fastScan >= 2
ABresult
0X0
100
111
1521 0 $et->VPrint(0,"End processing at $chunk chunk due to FastScan=$fastScan setting");
1522 0 last;
1523 }
1524 12 $datChunk = $chunk;
1525 12 $datCount++;
1526 12 $datBytes += $len;
1527 12 $wasDat = $chunk;
1528 } else {
1529 86 $datChunk = '';
1530 }
1531 98 ▶ if ($outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile) 40 58 98
1532 # add text chunks (including XMP) before any data chunk end chunk
1533 40 ▶ if ($datChunk or $chunk eq $endChunk) {
Branch: 2 branches
BranchTrueFalseTotal
if ($datChunk or $chunk eq $endChunk) { } 10 30 40
elsif ($chunk eq 'PLTE') { } 0 30 30
Condition100%3/3
$datChunk or $chunk eq $endChunk
l!l&&r!l&&!r
5530
MC/DC100%2/2
$datChunk or $chunk eq $endChunk
$datChunk $chunk eq $endChunk
Truth table100%3/3
A or B
A= $datChunkB= $chunk eq $endChunk
ABresult
1X1
011
000
1534 # write iCCP chunk now if requested because AddChunks will try
1535 # to add it as a text profile chunk if this isn't successful
1536 # (ie. if Compress::Zlib wasn't available)
1537 10 Add_iCCP($et, $outfile);
1538 10 ▶ AddChunks($et, $outfile) or $err = 1; # add all text chunks
Branch: 1 branch
BranchTrueFalseTotal
&AddChunks($et, $outfile) or $err = 1 10 0 10
1539 10 ▶ AddChunks($et, $outfile, 'IFD0') or $err = 1; # and eXIf chunk
Branch: 1 branch
BranchTrueFalseTotal
&AddChunks($et, $outfile, "IFD0") or $err = 1 10 0 10
1540 } elsif ($chunk eq 'PLTE') {
1541 # iCCP chunk must come before PLTE (and IDAT, handled above)
1542 # (ignore errors -- will add later as text profile if this fails)
1543 0 Add_iCCP($et, $outfile);
1544 }
1545 }
1546 98 ▶ if ($chunk eq $endChunk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk eq $endChunk) 12 86 98
1547 # read CRC
1548 12 ▶ unless ($raf->Read($cbuf,4) == 4) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Read($cbuf, 4) == 4) 0 12 12
1549 0 ▶ $et->Warn("Truncated $fileType $endChunk chunk") unless $wasEnd;
Branch: 1 branch
BranchTrueFalseTotal
unless $wasEnd 0 0 0
1550 0 last;
1551 }
1552 12 ▶ $verbose and print $out "$fileType $chunk (end of image)\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out "$fileType $chunk (end of image)\n" 1 11 12
1553 12 $wasEnd = 1;
1554 12 ▶ if ($outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile) 5 7 12
1555 # write the IEND/MEND chunk with CRC
1556 5 ▶ Write($outfile, $hbuf, $cbuf) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hbuf, $cbuf) or $err = 1 5 0 5
1557 5 ▶ if ($$et{DEL_GROUP}{Trailer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'DEL_GROUP'}{'Trailer'}) { } 0 5 5
1558 0 ▶ if ($raf->Read($hbuf, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->Read($hbuf, 1)) 0 0 0
1559 0 ▶ $verbose and printf $out " Deleting PNG trailer\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and printf $out " Deleting PNG trailer\n" 0 0 0
1560 0 ++$$et{CHANGED};
1561 }
1562 } else {
1563 # copy over any existing trailer data
1564 5 my $tot = 0;
1565 5 for (;;) {
1566 5 ▶ $n = $raf->Read($hbuf, 65536) or last;
Branch: 1 branch
BranchTrueFalseTotal
$n = $raf->Read($hbuf, 65536) or last 0 5 5
1567 0 $tot += $n;
1568 0 ▶ Write($outfile, $hbuf) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hbuf) or $err = 1 0 0 0
1569 }
1570 5 ▶ $tot and $verbose and printf $out " Copying PNG trailer ($tot bytes)\n";
Branch: 1 branch
BranchTrueFalseTotal
$tot and $verbose and printf $out " Copying PNG trailer ($tot bytes)\n" 0 5 5
Condition33%1/3
$tot and $verbose
!ll&&!rl&&r
500
MC/DC0%0/2
$tot and $verbose
$tot $verbose
Truth table33%1/3
A and B
A= $totB= $verbose
ABresult
0X0
100
111
1571 }
1572 5 last;
1573 }
1574 7 next;
1575 }
1576 86 ▶ if ($datChunk) {
Branch: 2 branches
BranchTrueFalseTotal
if ($datChunk) { } 12 74 86
elsif ($wasDat and $isTxtChunk{$chunk}) { } 15 118 133
1577 12 my $chunkSizeLimit = 10000000; # largest chunk to read into memory
1578 12 ▶ if ($outfile) {
Branch: 2 branches
BranchTrueFalseTotal
if ($outfile) { } 5 7 12
elsif (not $validate or $len > $chunkSizeLimit) { } 7 0 7
1579 # avoid loading very large data chunks into memory
1580 5 ▶ if ($len > $chunkSizeLimit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $chunkSizeLimit) 0 5 5
1581 0 ▶ Write($outfile, $hbuf) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hbuf) or $err = 1 0 0 0
1582 0 ▶ Image::ExifTool::CopyBlock($raf, $outfile, $len+4) or $et->Error("Error copying $datChunk");
Branch: 1 branch
BranchTrueFalseTotal
&Image::ExifTool::CopyBlock($raf, $outfile, $len + 4) or $et->Error("Error copying $datChunk") 0 0 0
1583 0 next;
1584 }
1585 # skip over data chunks if possible/necessary
1586 ▶ } elsif (not $validate or $len > $chunkSizeLimit) {
Condition33%1/3
not $validate or $len > $chunkSizeLimit
l!l&&r!l&&!r
700
MC/DC0%0/2
not $validate or $len > $chunkSizeLimit
not $validate $len > $chunkSizeLimit
Truth table33%1/3
not(A) or B
A= not $validateB= $len > $chunkSizeLimit
ABresult
1X1
011
000
1587 7 ▶ if ($hash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash) { } 0 7 7
1588 0 $et->ImageDataHash($raf, $len);
1589 0 ▶ $raf->Read($cbuf, 4) == 4 or $et->Warn('Truncated data'), last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($cbuf, 4) == 4 or $et->Warn("Truncated data"), last 0 0 0
1590 } else {
1591 7 ▶ $raf->Seek($len + 4, 1) or $et->Warn('Seek error'), last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($len + 4, 1) or $et->Warn("Seek error"), last 7 0 7
1592 }
1593 7 next;
1594 }
1595 ▶ } elsif ($wasDat and $isTxtChunk{$chunk}) {
Condition66%2/3
$wasDat and $isTxtChunk{$chunk}
!ll&&!rl&&r
59015
MC/DC50%1/2
$wasDat and $isTxtChunk{$chunk}
$wasDat $isTxtChunk{$chunk}
Truth table66%2/3
A and B
A= $wasDatB= $isTxtChunk{$chunk}
ABresult
0X0
100
111
1596 15 my $msg;
1597 15 ▶ if (not $outfile) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $outfile) { } 5 10 15
elsif (defined $doTxt) { } 0 10 10
1598 5 $msg = 'may be ignored by some readers';
1599 } elsif (defined $doTxt) { # $doTxt == 0 if we crossed a noLeapFrog chunk
1600 0 $msg = "can't be moved"; # (but could be deleted then added back again)
1601 } else {
1602 10 $msg = 'fixed';
1603 }
1604 15 $et->Warn("Text/EXIF chunk(s) found after $$et{FileType} $wasDat ($msg)", 1);
1605 }
1606 # read chunk data and CRC
1607 79 ▶ unless ($raf->Read($dbuf,$len)==$len and $raf->Read($cbuf, 4)==4) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Read($dbuf, $len) == $len and $raf->Read($cbuf, 4) == 4) 0 79 79
Condition33%1/3
$raf->Read($dbuf, $len) == $len and $raf->Read($cbuf, 4) == 4
!ll&&!rl&&r
0079
MC/DC0%0/2
$raf->Read($dbuf, $len) == $len and $raf->Read($cbuf, 4) == 4
$raf->Read($dbuf, $len) == $len $raf->Read($cbuf, 4) == 4
Truth table33%1/3
A and B
A= $raf->Read($dbuf, $len) == $lenB= $raf->Read($cbuf, 4) == 4
ABresult
0X0
100
111
1608 0 ▶ $et->Warn("Corrupted $fileType image") unless $wasEnd;
Branch: 1 branch
BranchTrueFalseTotal
unless $wasEnd 0 0 0
1609 0 last;
1610 }
1611 79 ▶ $hash->add($dbuf) if $hash and $datChunk; # add to hash if necessary
Branch: 1 branch
BranchTrueFalseTotal
if $hash and $datChunk 0 79 79
Condition33%1/3
$hash and $datChunk
!ll&&!rl&&r
7900
MC/DC0%0/2
$hash and $datChunk
$hash $datChunk
Truth table33%1/3
A and B
A= $hashB= $datChunk
ABresult
0X0
100
111
1612 79 ▶ if ($verbose or $validate or ($outfile and not $fastScan)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose or $validate or $outfile and not $fastScan) 35 44 79
Condition77%7/9
$verbose or $validate or $outfile and not $fastScan
l!l&&r!l&&!r
72844
$verbose or $validate
l!l&&r!l&&!r
7072
$outfile and not $fastScan
!ll&&!rl&&r
44028
MC/DC50%2/4
$verbose or $validate or $outfile and not $fastScan
$verbose $validate $outfile not $fastScan
Truth table60%3/5
A or B or C and not(D)
A= $verboseB= $validateC= $outfileD= not $fastScan
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1613 # check CRC when in verbose mode (since we don't care about speed)
1614 35 my $crc = CalculateCRC(\$hbuf, undef, 4);
1615 35 $crc = CalculateCRC(\$dbuf, $crc);
1616 35 ▶ unless ($crc == unpack('N',$cbuf)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($crc == unpack("N", $cbuf)) 0 35 35
1617 0 my $msg = "Bad CRC for $chunk chunk";
1618 0 ▶ $outfile ? $et->Error($msg, 1) : $et->Warn($msg);
Branch: 1 branch
BranchTrueFalseTotal
$outfile ? : 0 0 0
1619 }
1620 35 ▶ if ($datChunk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($datChunk) 5 30 35
1621 5 ▶ Write($outfile, $hbuf, $dbuf, $cbuf) or $err = 1 if $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if $outfile 5 0 5
Condition33%2/6
$outfile && (&Write($outfile, $hbuf, $dbuf, $cbuf) || ($err = 1))
!ll&&!rl&&r
050
&Write($outfile, $hbuf, $dbuf, $cbuf) or $err = 1
l!l&&r!l&&!r
500
MC/DC0%0/3
$outfile && (&Write($outfile, $hbuf, $dbuf, $cbuf) || ($err = 1))
$outfile &Write($outfile, $hbuf, $dbuf, $cbuf) $err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $hbuf, $dbuf, $cbuf)C= $err = 1
ABCresult
0XX0
1000
11X1
1011
1622 5 next;
1623 }
1624 # just skip over any text chunk found after IDAT
1625 30 ▶ if ($outfile and $wasDat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile and $wasDat) 10 20 30
Condition66%2/3
$outfile and $wasDat
!ll&&!rl&&r
02010
MC/DC50%1/2
$outfile and $wasDat
$outfile $wasDat
Truth table66%2/3
A and B
A= $outfileB= $wasDat
ABresult
0X0
100
111
1626 10 ▶ if ($isTxtChunk{$chunk} and not defined $doTxt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isTxtChunk{$chunk} and not defined $doTxt) 10 0 10
Condition33%1/3
$isTxtChunk{$chunk} and not defined $doTxt
!ll&&!rl&&r
0010
MC/DC0%0/2
$isTxtChunk{$chunk} and not defined $doTxt
$isTxtChunk{$chunk} not defined $doTxt
Truth table33%1/3
A and not(B)
A= $isTxtChunk{$chunk}B= not defined $doTxt
ABresult
0X0
100
111
1627 10 ▶ ++$$et{CHANGED} if $$et{FORCE_WRITE}{PNG};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"FORCE_WRITE"}{"PNG"} 0 10 10
1628 10 ▶ print $out " Deleting $chunk that was moved ($len bytes)\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 2 8 10
1629 10 next;
1630 }
1631 # done moving text if we hit one of these chunks
1632 0 ▶ $doTxt = 0 if $noLeapFrog{$chunk};
Branch: 1 branch
BranchTrueFalseTotal
if $noLeapFrog{$chunk} 0 0 0
1633 }
1634 20 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 4 16 20
1635 4 print $out "$fileType $chunk ($len bytes):\n";
1636 4 ▶ $et->VerboseDump(\$dbuf, Addr => $raf->Tell() - $len - 4) if $verbose > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 4 4
1637 }
1638 }
1639 # translate case of chunk names that have changed since the first implementation
1640 64 ▶ if (not $$tagTablePtr{$chunk} and $stdCase{lc $chunk}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $tagTablePtr->{$chunk} and $Image::ExifTool::PNG::stdCase{lc $chunk}) 0 64 64
Condition33%1/3
not $tagTablePtr->{$chunk} and $Image::ExifTool::PNG::stdCase{lc $chunk}
!ll&&!rl&&r
6400
MC/DC0%0/2
not $tagTablePtr->{$chunk} and $Image::ExifTool::PNG::stdCase{lc $chunk}
not $tagTablePtr->{$chunk} $Image::ExifTool::PNG::stdCase{lc $chunk}
Truth table33%1/3
not(A) and B
A= not $tagTablePtr->{$chunk}B= $Image::ExifTool::PNG::stdCase{lc $chunk}
ABresult
0X0
100
111
1641 0 my $stdChunk = $stdCase{lc $chunk};
1642 0 ▶ if ($outfile and ($$et{EDIT_DIRS}{IFD0} or $stdChunk !~ /^[ez]xif$/i)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile and $et->{'EDIT_DIRS'}{'IFD0'} || !($stdChunk =~ /^[ez]xif$/i)) { } 0 0 0
Condition0%0/6
$outfile and $et->{"EDIT_DIRS"}{"IFD0"} || !($stdChunk =~ /^[ez]xif$/i)
!ll&&!rl&&r
000
$et->{"EDIT_DIRS"}{"IFD0"} or not $stdChunk =~ /^[ez]xif$/i
l!l&&r!l&&!r
000
MC/DC0%0/3
$outfile and $et->{"EDIT_DIRS"}{"IFD0"} || !($stdChunk =~ /^[ez]xif$/i)
$outfile $et->{"EDIT_DIRS"}{"IFD0"} not $stdChunk =~ /^[ez]xif$/i
Truth table0%0/4
A and B or not(C)
A= $outfileB= $et->{"EDIT_DIRS"}{"IFD0"}C= not $stdChunk =~ /^[ez]xif$/i
ABCresult
0XX0
1000
11X1
1011
1643 0 $et->Warn("Changed $chunk chunk to $stdChunk", 1);
1644 0 ++$$et{CHANGED};
1645 } else {
1646 0 $et->Warn("$chunk chunk should be $stdChunk", 1);
1647 }
1648 0 $chunk = $stdCase{lc $chunk};
1649 }
1650 # only extract information from chunks in our tables
1651 64 my ($theBuff, $outBuff);
1652 64 ▶ $outBuff = \$theBuff if $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if $outfile 20 44 64
1653 64 ▶ if ($$tagTablePtr{$chunk}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagTablePtr->{$chunk}) { } 64 0 64
elsif ($mngTablePtr and $mngTablePtr->{$chunk}) { } 0 0 0
1654 64 FoundPNG($et, $tagTablePtr, $chunk, $dbuf, undef, $outBuff);
1655 ▶ } elsif ($mngTablePtr and $$mngTablePtr{$chunk}) {
Condition0%0/3
$mngTablePtr and $mngTablePtr->{$chunk}
!ll&&!rl&&r
000
MC/DC0%0/2
$mngTablePtr and $mngTablePtr->{$chunk}
$mngTablePtr $mngTablePtr->{$chunk}
Truth table0%0/3
A and B
A= $mngTablePtrB= $mngTablePtr->{$chunk}
ABresult
0X0
100
111
1656 0 FoundPNG($et, $mngTablePtr, $chunk, $dbuf, undef, $outBuff);
1657 }
1658 64 ▶ if ($outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile) 20 44 64
1659 20 ▶ if (defined $theBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $theBuff) 5 15 20
1660 5 ▶ next unless length $theBuff; # empty if we deleted the information
Branch: 1 branch
BranchTrueFalseTotal
unless length $theBuff 2 3 5
1661 # change chunk type if necessary
1662 3 ▶ if ($$et{TextChunkType}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"TextChunkType"}) 3 0 3
1663 3 $chunk = $$et{TextChunkType};
1664 3 delete $$et{TextChunkType};
1665 }
1666 3 $hbuf = pack('Na4', length($theBuff), $chunk);
1667 3 $dbuf = $theBuff;
1668 3 my $crc = CalculateCRC(\$hbuf, undef, 4);
1669 3 $crc = CalculateCRC(\$dbuf, $crc);
1670 3 $cbuf = pack('N', $crc);
1671 }
1672 18 ▶ Write($outfile, $hbuf, $dbuf, $cbuf) or $err = 1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hbuf, $dbuf, $cbuf) or $err = 1 18 0 18
1673 }
1674 }
1675 12 delete $$et{SET_GROUP1};
1676 # read Samsung trailer if it exists
1677 12 ▶ if ($wasTrailer and not $outfile and $raf->Seek(-8, 2) and
Branch: 1 branch
BranchTrueFalseTotal
if ($wasTrailer and not $outfile and $raf->Seek(-8, 2) and $raf->Read($dbuf, 8) and $dbuf =~ /\0\0(QDIOBS|SEFT)$/) 0 12 12
Condition33%4/12
$wasTrailer and not $outfile and $raf->Seek(-8, 2) and $raf->Read($dbuf, 8) and $dbuf =~ /\0\0(QDIOBS|SEFT)$/
!ll&&!rl&&r
1200
$wasTrailer and not $outfile and $raf->Seek(-8, 2) and $raf->Read($dbuf, 8)
!ll&&!rl&&r
1200
$wasTrailer and not $outfile and $raf->Seek(-8, 2)
!ll&&!rl&&r
1200
$wasTrailer and not $outfile
!ll&&!rl&&r
1200
MC/DC0%0/5
$wasTrailer and not $outfile and $raf->Seek(-8, 2) and $raf->Read($dbuf, 8) and $dbuf =~ /\0\0(QDIOBS|SEFT)$/
$wasTrailer not $outfile $raf->Seek(-8, 2) $raf->Read($dbuf, 8) $dbuf =~ /\0\0(QDIOBS|SEFT)$/
Truth table16%1/6
A and not(B) and C and D and E
A= $wasTrailerB= not $outfileC= $raf->Seek(-8, 2)D= $raf->Read($dbuf, 8)E= $dbuf =~ /\0\0(QDIOBS|SEFT)$/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1678 $raf->Read($dbuf,8) and $dbuf =~ /\0\0(QDIOBS|SEFT)$/) # (have only seen SEFT type)
1679 {
1680 0 require Image::ExifTool::Samsung;
1681 0 Image::ExifTool::Samsung::ProcessSamsung($et, { DirName => 'Samsung', RAF => $raf });
1682 }
1683 12 ▶ return -1 if $outfile and ($err or not $wasEnd);
Branch: 1 branch
BranchTrueFalseTotal
if $outfile and $err || !$wasEnd 0 12 12
Condition50%3/6
$outfile and $err || !$wasEnd
!ll&&!rl&&r
750
$err or not $wasEnd
l!l&&r!l&&!r
005
MC/DC0%0/3
$outfile and $err || !$wasEnd
$outfile $err not $wasEnd
Truth table50%2/4
A and B or not(C)
A= $outfileB= $errC= not $wasEnd
ABCresult
0XX0
1000
11X1
1011
1684 12 return 1; # this was a valid PNG/MNG/JNG image
1685 }
1686  
1687 23 1; # end
1688  
1689 __END__
« Image/ExifTool/PICT.pm ↑ Summary Image/ExifTool/Font.pm »