| 1 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # File: WritePNG.pl | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Description: Write PNG meta information | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Revisions: 09/16/2005 - P. Harvey Created | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # References: 1) http://www.libpng.org/pub/png/spec/1.2/ | ||||||||||||||||||||||||||||||||||||||||||
| 9 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 10 | package Image::ExifTool::PNG; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # Calculate CRC or update running CRC (ref 1) | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # Inputs: 0) data reference, 1) running crc to update (undef initially) | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # 2) data position (undef for 0), 3) data length (undef for all data), | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # Returns: updated CRC | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my @crcTable; | |||||||||||||||||||||||||||||||||||||||||
| 20 | sub CalculateCRC($;$$$) | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 98 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CalculateCRC: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 98 | my ($dataPt, $crc, $pos, $len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 98 | ▶ | $crc = 0 unless defined $crc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 98 | ▶ | $pos = 0 unless defined $pos; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 98 | ▶ | $len = length($$dataPt) - $pos unless defined $len; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 98 | $crc ^= 0xffffffff; # undo 1's complement | |||||||||||||||||||||||||||||||||||||||||
| 27 | # build lookup table unless done already | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 98 | ▶ | unless (@crcTable) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my ($c, $n, $k); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | for ($n=0; $n<256; ++$n) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 256 | ▶ | for ($k=0, $c=$n; $k<8; ++$k) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2048 | ▶ | $c = ($c & 1) ? 0xedb88320 ^ ($c >> 1) : $c >> 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 256 | $crcTable[$n] = $c; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # calculate the CRC | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 98 | foreach (unpack("x${pos}C$len", $$dataPt)) { | |||||||||||||||||||||||||||||||||||||||||
| 39 | 11009 | $crc = $crcTable[($crc^$_) & 0xff] ^ ($crc >> 8); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 98 | return $crc ^ 0xffffffff; # return 1's complement | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # Encode data in ASCII Hex | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # Inputs: 0) input data reference | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # Returns: Hex-encoded data (max 72 chars per line) | ||||||||||||||||||||||||||||||||||||||||||
| 48 | sub HexEncode($) | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
HexEncode: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | my $dataPt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my $len = length($$dataPt); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my $hex = ''; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | my $pos; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | for ($pos = 0; $pos < $len; $pos += 36) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 13 | my $n = $len - $pos; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 13 | ▶ | $n > 36 and $n = 36; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 13 | $hex .= unpack('H*',substr($$dataPt,$pos,$n)) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | return $hex; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # Write profile chunk (possibly compressed if Zlib is available) | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # Inputs: 0) outfile, 1) Raw profile type (SCALAR ref for iCCP name), 2) data ref | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # 3) profile header type (undef if not a text profile) | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # Returns: 1 on success | ||||||||||||||||||||||||||||||||||||||||||
| 67 | sub WriteProfile($$$;$) | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
WriteProfile: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | my ($outfile, $rawType, $dataPt, $profile) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | my ($buff, $prefix, $chunk, $deflate); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 4 | ▶ | if ($rawType ne $stdCase{exif} and eval { require Compress::Zlib }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rawType ne $Image::ExifTool::PNG::stdCase{"exif"} and eval {
do {
require Compress::Zlib
}
}
MC/DC50%1/2
$rawType ne $Image::ExifTool::PNG::stdCase{"exif"} and eval {
do {
require Compress::Zlib
}
}
$rawType ne $Image::ExifTool::PNG::stdCase{"exif"}
eval {
do {
require Compress::Zlib
}
}
Truth table66%2/3
A and B
A= $rawType ne $Image::ExifTool::PNG::stdCase{"exif"}B= eval {
do {
require Compress::Zlib
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | $deflate = Compress::Zlib::deflateInit(); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | if (not defined $profile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | # write ICC profile as compressed iCCP chunk if possible | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | if (ref $rawType) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | return 0 unless $deflate; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | $chunk = 'iCCP'; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | $prefix = "$$rawType\0\0"; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | $chunk = $rawType; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | if ($rawType eq $stdCase{zxif}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $prefix = "\0" . pack('N', length $$dataPt); # (proposed compressed EXIF) | |||||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | $prefix = ''; # standard EXIF | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | if ($deflate) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | $buff = $deflate->deflate($$dataPt); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | return 0 unless defined $buff; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | $buff .= $deflate->flush(); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | $dataPt = \$buff; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # write as ASCII-hex encoded profile in tEXt or zTXt chunk | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | my $txtHdr = sprintf("\n$profile profile\n%8d\n", length($$dataPt)); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $buff = $txtHdr . HexEncode($dataPt); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | $chunk = 'tEXt'; # write as tEXt if deflate not available | |||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | $prefix = "Raw profile type $rawType\0"; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $dataPt = \$buff; | |||||||||||||||||||||||||||||||||||||||||
| 101 | # write profile as zTXt chunk if possible | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | if ($deflate) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $buf2 = $deflate->deflate($buff); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | if (defined $buf2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | $dataPt = \$buf2; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | $buf2 .= $deflate->flush(); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | $chunk = 'zTXt'; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | $prefix .= "\0"; # compression type byte (0=deflate) | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | my $hdr = pack('Na4', length($prefix) + length($$dataPt), $chunk) . $prefix; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | my $crc = CalculateCRC(\$hdr, undef, 4); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | $crc = CalculateCRC($dataPt, $crc); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | return Write($outfile, $hdr, $$dataPt, pack('N',$crc)); | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # Add iCCP-related chunks to the PNG image if necessary (must come before PLTE and IDAT) | ||||||||||||||||||||||||||||||||||||||||||
| 120 | # Inputs: 0) ExifTool object ref, 1) output file or scalar ref | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # Returns: true on success | ||||||||||||||||||||||||||||||||||||||||||
| 122 | sub Add_iCCP($$) | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 10 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Add_iCCP: called CC=10 SCAR=26.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 10 | my ($et, $outfile) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 10 | ▶ | if ($$et{ADD_DIRS}{ICC_Profile}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | # write new ICC data | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my $tagTablePtr = Image::ExifTool::GetTagTable('Image::ExifTool::ICC_Profile::Main'); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | my %dirInfo = ( Parent => 'PNG', DirName => 'ICC_Profile' ); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | my $buff = $et->WriteDirectory(\%dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | if (defined $buff and length $buff) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $buff and length $buff
MC/DC0%0/2
defined $buff and length $buff
defined $buff
length $buff
Truth table33%1/3
A and B
A= defined $buffB= length $buff
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | my $profileName = $et->GetNewValue($Image::ExifTool::PNG::Main{'iCCP-name'}); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | $profileName = 'icm' unless defined $profileName; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | if (WriteProfile($outfile, \$profileName, \$buff)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | $et->VPrint(0, "Created ICC profile with name '${profileName}'\n"); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | delete $$et{ADD_DIRS}{ICC_Profile}; # don't add it again | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # must also add sRGB and gAMA before PLTE and IDAT | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 10 | ▶ | if ($$et{ADD_PNG}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | my ($tag, %addBeforePLTE); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | foreach $tag (qw(sRGB gAMA)) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 10 | ▶ | next unless $$et{ADD_PNG}{$tag}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $addBeforePLTE{$tag} = $$et{ADD_PNG}{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | delete $$et{ADD_PNG}{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | ▶ | if (%addBeforePLTE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $save = $$et{ADD_PNG}; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $$et{ADD_PNG} = \%addBeforePLTE; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | AddChunks($et, $outfile); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $$et{ADD_PNG} = $save; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 10 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # This routine is called after we edit an existing directory | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # Inputs: 0) ExifTool ref, 1) dir name, 2) output data ref | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # 3) flag set if location is non-standard (to update, but not create from scratch) | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # - on return, $$outBuff is set to '' if the directory is to be deleted | ||||||||||||||||||||||||||||||||||||||||||
| 162 | sub DoneDir($$$;$) | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DoneDir: called CC=6 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | my ($et, $dir, $outBuff, $nonStandard) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 3 | my $saveDir = $dir; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | ▶ | $dir = 'EXIF' if $dir eq 'IFD0'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | # don't add this directory again unless this is in a non-standard location | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | ▶ | if (not $nonStandard) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | delete $$et{ADD_DIRS}{$dir}; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | ▶ | delete $$et{ADD_DIRS}{IFD0} if $dir eq 'EXIF'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | ▶ | } elsif ($$et{DEL_GROUP}{$dir} or $$et{DEL_GROUP}{$saveDir}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$et->{"DEL_GROUP"}{$dir} or $et->{"DEL_GROUP"}{$saveDir}
MC/DC0%0/2
$et->{"DEL_GROUP"}{$dir} or $et->{"DEL_GROUP"}{$saveDir}
$et->{"DEL_GROUP"}{$dir}
$et->{"DEL_GROUP"}{$saveDir}
Truth table0%0/3
A or B
A= $et->{"DEL_GROUP"}{$dir}B= $et->{"DEL_GROUP"}{$saveDir}
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $et->VPrint(0," Deleting non-standard $dir\n"); | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $$outBuff = ''; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # Generate tEXt, zTXt or iTXt data for writing | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # Inputs: 0) ExifTool ref, 1) tagID, 2) tagInfo ref, 3) value string, 4) language code | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # Returns: chunk data (not including 8-byte chunk header) | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # Notes: Sets ExifTool TextChunkType member to the type of chunk written | ||||||||||||||||||||||||||||||||||||||||||
| 182 | sub BuildTextChunk($$$$$) | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BuildTextChunk: called CC=21 SCAR=44.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 15 | my ($et, $tag, $tagInfo, $val, $lang) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 15 | my ($xtra, $compVal, $iTXt, $comp); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 15 | ▶ | if ($$tagInfo{SubDirectory}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 3 | ▶ | if ($$tagInfo{Name} eq 'XMP') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | $iTXt = 2; # write as iTXt but flag to avoid encoding | |||||||||||||||||||||||||||||||||||||||||
| 189 | # (never compress XMP) | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $comp = 2; # compress raw profile if possible | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # compress if specified | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 12 | ▶ | $comp = 1 if $et->Options('Compress'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 12 | ▶ | if ($lang) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | $iTXt = 1; # write as iTXt if it has a language code | |||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | $tag =~ s/-$lang$//; # remove language code from tagID | |||||||||||||||||||||||||||||||||||||||||
| 199 | ▶ | } elsif ($$et{OPTIONS}{Charset} ne 'Latin' and $val =~ /[\x80-\xff]/) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$et->{"OPTIONS"}{"Charset"} ne "Latin" and $val =~ /[\x80-\xff]/
MC/DC0%0/2
$et->{"OPTIONS"}{"Charset"} ne "Latin" and $val =~ /[\x80-\xff]/
$et->{"OPTIONS"}{"Charset"} ne "Latin"
$val =~ /[\x80-\xff]/
Truth table66%2/3
A and B
A= $et->{"OPTIONS"}{"Charset"} ne "Latin"B= $val =~ /[\x80-\xff]/
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $iTXt = 1; # write as iTXt if it contains non-Latin special characters | |||||||||||||||||||||||||||||||||||||||||
| 201 | } elsif ($$tagInfo{iTXt}) { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $iTXt = 1; # write as iTXt if specified in user-defined tag | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 15 | ▶ | if ($comp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $warn; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if (eval { require Compress::Zlib }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $deflate = Compress::Zlib::deflateInit(); | |||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | $compVal = $deflate->deflate($val) if $deflate; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if (defined $compVal) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $compVal .= $deflate->flush(); | |||||||||||||||||||||||||||||||||||||||||
| 212 | # only compress if it actually saves space | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | unless (length($compVal) < length($val)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | undef $compVal; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $warn = 'uncompressed data is smaller'; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $warn = 'deflate error'; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $warn = 'Compress::Zlib not available'; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | # warn if any user-specified compression fails | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($warn and $comp == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$warn and $comp == 1
MC/DC0%0/2
$warn and $comp == 1
$warn
$comp == 1
Truth table0%0/3
A and B
A= $warnB= $comp == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $et->Warn("PNG:$$tagInfo{Name} not compressed ($warn)", 1); | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # decide whether to write as iTXt, zTXt or tEXt | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 15 | ▶ | if ($iTXt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | $$et{TextChunkType} = 'iTXt'; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | $xtra = (defined $compVal ? "\x01\0" : "\0\0") . ($lang || '') . "\0\0"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$lang || ''
MC/DC100%1/1
$lang || ''
$lang
Truth table100%2/2
A
A= $lang
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | # iTXt is encoded as UTF-8 (but note that XMP is already UTF-8) | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | ▶ | $val = $et->Encode($val, 'UTF8') if $iTXt == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | } elsif (defined $compVal) { | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $$et{TextChunkType} = 'zTXt'; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $xtra = "\0"; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 11 | $$et{TextChunkType} = 'tEXt'; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 11 | $xtra = ''; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 15 | ▶ | return $tag . "\0" . $xtra . (defined $compVal ? $compVal : $val); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # Add any outstanding new chunks to the PNG image | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # Inputs: 0) ExifTool object ref, 1) output file or scalar ref | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # 2-N) dirs to add (empty to add all except EXIF 'IFD0', including PNG tags) | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # Returns: true on success | ||||||||||||||||||||||||||||||||||||||||||
| 249 | sub AddChunks($$;@) | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 20 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddChunks: called CC=34 SCAR=44.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 20 | my ($et, $outfile, @add) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 20 | my ($addTags, $tag, $dir, $err, $tagTablePtr, $specified); | |||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 20 | ▶ | if (@add) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 10 | $addTags = { }; # don't add any PNG tags | |||||||||||||||||||||||||||||||||||||||||
| 256 | 10 | $specified = 1; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 10 | $addTags = $$et{ADD_PNG}; # add all PNG tags... | |||||||||||||||||||||||||||||||||||||||||
| 259 | 10 | delete $$et{ADD_PNG}; # ...once | |||||||||||||||||||||||||||||||||||||||||
| 260 | # add all directories | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 10 | @add = sort keys %{$$et{ADD_DIRS}}; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # write any outstanding PNG tags | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 20 | foreach $tag (sort keys %$addTags) { | |||||||||||||||||||||||||||||||||||||||||
| 265 | 14 | my $tagInfo = $$addTags{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 14 | ▶ | next if $$tagInfo{FakeTag}; # (iCCP-name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 13 | my $nvHash = $et->GetNewValueHash($tagInfo); | |||||||||||||||||||||||||||||||||||||||||
| 268 | # (native PNG information is always preferred, so don't rely on just IsCreating) | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 13 | ▶ | next unless $$nvHash{IsCreating} or $et->IsOverwriting($nvHash) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$nvHash->{"IsCreating"} or $et->IsOverwriting($nvHash) > 0
MC/DC0%0/2
$nvHash->{"IsCreating"} or $et->IsOverwriting($nvHash) > 0
$nvHash->{"IsCreating"}
$et->IsOverwriting($nvHash) > 0
Truth table33%1/3
A or B
A= $nvHash->{"IsCreating"}B= $et->IsOverwriting($nvHash) > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 13 | my $val = $et->GetNewValue($nvHash); | |||||||||||||||||||||||||||||||||||||||||
| 271 | 13 | ▶ | if (defined $val) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 13 | ▶ | next if $$nvHash{EditOnly}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 13 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 13 | ▶ | if ($$tagInfo{Table} eq \%Image::ExifTool::PNG::TextualData) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 12 | $data = BuildTextChunk($et, $tag, $tagInfo, $val, $$tagInfo{LangCode}); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 12 | $data = $$et{TextChunkType} . $data; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 12 | delete $$et{TextChunkType}; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | $data = "$tag$val"; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 13 | my $hdr = pack('N', length($data) - 4); | |||||||||||||||||||||||||||||||||||||||||
| 282 | 13 | my $cbuf = pack('N', CalculateCRC(\$data, undef)); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 13 | ▶ | Write($outfile, $hdr, $data, $cbuf) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 13 | $et->VerboseValue("+ PNG:$$tagInfo{Name}", $val); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 13 | ++$$et{CHANGED}; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | # create any necessary directories | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 20 | foreach $dir (@add) { | |||||||||||||||||||||||||||||||||||||||||
| 290 | 48 | ▶ | next unless $$et{ADD_DIRS}{$dir}; # make sure we want to add it first | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 10 | my $buff; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 10 | my %dirInfo = ( | |||||||||||||||||||||||||||||||||||||||||
| 293 | Parent => 'PNG', | ||||||||||||||||||||||||||||||||||||||||||
| 294 | DirName => $dir, | ||||||||||||||||||||||||||||||||||||||||||
| 295 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 10 | ▶ | if ($dir eq 'IFD0') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 4 | ▶ | next unless $specified; # wait until specifically asked to write EXIF 'IFD0' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 2 | my $chunk = $stdCase{exif}; | |||||||||||||||||||||||||||||||||||||||||
| 299 | # (zxIf was not adopted) | ||||||||||||||||||||||||||||||||||||||||||
| 300 | #if ($et->Options('Compress')) { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # if (eval { require Compress::Zlib }) { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # $chunk = $stdCase{zxif}; | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # } else { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | # $et->Warn("Creating uncompressed $stdCase{exif} chunk (Compress::Zlib not available)"); | ||||||||||||||||||||||||||||||||||||||||||
| 305 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | $et->VPrint(0, "Creating $chunk chunk:\n"); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | $$et{TIFF_TYPE} = 'APP1'; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 2 | $tagTablePtr = Image::ExifTool::GetTagTable('Image::ExifTool::Exif::Main'); | |||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | $buff = $et->WriteDirectory(\%dirInfo, $tagTablePtr, \&Image::ExifTool::WriteTIFF); | |||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | ▶ | if (defined $buff and length $buff) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $buff and length $buff
MC/DC0%0/2
defined $buff and length $buff
defined $buff
length $buff
Truth table33%1/3
A and B
A= defined $buffB= length $buff
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | ▶ | WriteProfile($outfile, $chunk, \$buff) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | } elsif ($dir eq 'XMP') { | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $et->VPrint(0, "Creating XMP iTXt chunk:\n"); | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $tagTablePtr = Image::ExifTool::GetTagTable('Image::ExifTool::XMP::Main'); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $dirInfo{ReadOnly} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $buff = $et->WriteDirectory(\%dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if (defined $buff and length $buff and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $buff and length $buff and &Image::ExifTool::XMP::ValidateXMP(\$buff, "r")
defined $buff and length $buff
MC/DC0%0/3
defined $buff and length $buff and &Image::ExifTool::XMP::ValidateXMP(\$buff, "r")
defined $buff
length $buff
&Image::ExifTool::XMP::ValidateXMP(\$buff, "r")
Truth table0%0/4
A and B and C
A= defined $buffB= length $buffC= &Image::ExifTool::XMP::ValidateXMP(\$buff, "r")
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | # the packet is read-only (because of CRC) | ||||||||||||||||||||||||||||||||||||||||||
| 321 | Image::ExifTool::XMP::ValidateXMP(\$buff, 'r')) | ||||||||||||||||||||||||||||||||||||||||||
| 322 | { | ||||||||||||||||||||||||||||||||||||||||||
| 323 | # (previously, XMP was created as a non-standard XMP profile chunk) | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # $buff = $Image::ExifTool::xmpAPP1hdr . $buff; | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # WriteProfile($outfile, 'APP1', \$buff, 'generic') or $err = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 326 | # (but now write XMP iTXt chunk according to XMP specification) | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $buff = "iTXtXML:com.adobe.xmp\0\0\0\0\0" . $buff; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $hdr = pack('N', length($buff) - 4); | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $cbuf = pack('N', CalculateCRC(\$buff, undef)); | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | Write($outfile, $hdr, $buff, $cbuf) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | } elsif ($dir eq 'IPTC') { | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | $et->Warn('Creating non-standard IPTC in PNG', 1); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | $et->VPrint(0, "Creating IPTC profile:\n"); | |||||||||||||||||||||||||||||||||||||||||
| 335 | # write new IPTC data (stored in a Photoshop directory) | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | $dirInfo{DirName} = 'Photoshop'; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | $tagTablePtr = Image::ExifTool::GetTagTable('Image::ExifTool::Photoshop::Main'); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | $buff = $et->WriteDirectory(\%dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | ▶ | if (defined $buff and length $buff) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $buff and length $buff
MC/DC0%0/2
defined $buff and length $buff
defined $buff
length $buff
Truth table33%1/3
A and B
A= defined $buffB= length $buff
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | ▶ | WriteProfile($outfile, 'iptc', \$buff, 'IPTC') or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } elsif ($dir eq 'ICC_Profile') { | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $et->VPrint(0, "Creating ICC profile:\n"); | |||||||||||||||||||||||||||||||||||||||||
| 344 | # write new ICC data (only done if we couldn't create iCCP chunk) | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $tagTablePtr = Image::ExifTool::GetTagTable('Image::ExifTool::ICC_Profile::Main'); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $buff = $et->WriteDirectory(\%dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if (defined $buff and length $buff) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $buff and length $buff
MC/DC0%0/2
defined $buff and length $buff
defined $buff
length $buff
Truth table0%0/3
A and B
A= defined $buffB= length $buff
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | WriteProfile($outfile, 'icm', \$buff, 'ICC') or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $et->Warn('Wrote ICC as a raw profile (no Compress::Zlib)'); | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | } elsif ($dir eq 'PNG-pHYs') { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | $et->VPrint(0, "Creating pHYs chunk (default 2834 pixels per meter):\n"); | |||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | $tagTablePtr = Image::ExifTool::GetTagTable('Image::ExifTool::PNG::PhysicalPixel'); | |||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | my $blank = "\0\0\x0b\x12\0\0\x0b\x12\x01"; # 2834 pixels per meter (72 dpi) | |||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | $dirInfo{DataPt} = \$blank; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | $buff = $et->WriteDirectory(\%dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | ▶ | if (defined $buff and length $buff) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $buff and length $buff
MC/DC0%0/2
defined $buff and length $buff
defined $buff
length $buff
Truth table33%1/3
A and B
A= defined $buffB= length $buff
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | $buff = 'pHYs' . $buff; # CRC includes chunk name | |||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | my $hdr = pack('N', length($buff) - 4); | |||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | my $cbuf = pack('N', CalculateCRC(\$buff, undef)); | |||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | Write($outfile, $hdr, $buff, $cbuf) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 4 | delete $$et{ADD_DIRS}{$dir}; # don't add again | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 20 | return not $err; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | 1; # end | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | __END__ | ||||||||||||||||||||||||||||||||||||||||||