| 1 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # File: WriteCanonRaw.pl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Description: Write Canon RAW (CRW and CR2) meta information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Revisions: 01/25/2005 - P. Harvey Created | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # 09/16/2010 - PH Added ability to write XMP in CRW images | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | package Image::ExifTool::CanonRaw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use vars qw($VERSION $AUTOLOAD %crwTagFormat); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Image::ExifTool::Fixup; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # map for adding directories to CRW | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | my %crwMap = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | XMP => 'CanonVRD', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | CanonVRD => 'Trailer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # mappings to from RAW tagID to MakerNotes tagID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # (Note: upper two bits of RawTagID are zero) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | my %mapRawTag = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # RawTagID => Canon TagID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0x080b => 0x07, # CanonFirmwareVersion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0x0810 => 0x09, # OwnerName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0x0815 => 0x06, # CanonImageType | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0x1028 => 0x03, # (unknown if no tag name specified) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0x1029 => 0x02, # FocalLength | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0x102a => 0x04, # CanonShotInfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0x102d => 0x01, # CanonCameraSettings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0x1033 => 0x0f, # CanonCustomFunctions (only verified for 10D) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0x1038 => 0x12, # CanonAFInfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0x1039 => 0x13, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0x1093 => 0x93, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0x10a8 => 0xa8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0x10a9 => 0xa9, # WhiteBalanceTable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0x10aa => 0xaa, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0x10ae => 0xae, # ColorTemperature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0x10b4 => 0xb4, # ColorSpace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0x10b5 => 0xb5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0x10c0 => 0xc0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0x10c1 => 0xc1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0x180b => 0x0c, # SerialNumber | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0x1817 => 0x08, # FileNumber | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0x1834 => 0x10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0x183b => 0x15, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # translation from Rotation to Orientation values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 11 | my %mapRotation = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 90 => 6, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 180 => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 270 => 8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Initialize buffers for building MakerNotes from RAW data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # Inputs: 0) ExifTool object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | sub InitMakerNotes($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
InitMakerNotes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | my $et = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | $$et{MAKER_NOTE_INFO} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | Entries => { }, # directory entries keyed by tagID | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ValBuff => "\0\0\0\0", # value data buffer (start with zero nextIFD pointer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | FixupTags => { }, # flags for tags with data in value buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Build maker notes from CanonRaw information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # Inputs: 0) ExifTool object reference, 1) raw tag ID, 2) reference to tagInfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # 3) reference to value, 4) format name, 5) count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Notes: This will build the directory in the order the tags are found in the CRW | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # file, which isn't sequential (but Canon's version isn't sequential either...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | sub BuildMakerNotes($$$$$$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 188 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BuildMakerNotes: called CC=11 SCAR=24.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 188 | my ($et, $rawTag, $tagInfo, $valuePt, $formName, $count) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 188 | ▶ | my $tagID = $mapRawTag{$rawTag} || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mapRawTag{$rawTag} || (return)
MC/DC100%1/1
$mapRawTag{$rawTag} || (return)
$mapRawTag{$rawTag}
Truth table100%2/2
A
A= $mapRawTag{$rawTag}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 57 | ▶ | $formName or warn(sprintf "No format for tag 0x%x!\n",$rawTag), return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # special case: ignore user comment because it gets saved in EXIF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # (and has the same raw tagID as CanonFileDescription) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 57 | ▶ | return if $tagInfo and $$tagInfo{Name} eq 'UserComment'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tagInfo and $tagInfo->{"Name"} eq "UserComment"
MC/DC0%0/2
$tagInfo and $tagInfo->{"Name"} eq "UserComment"
$tagInfo
$tagInfo->{"Name"} eq "UserComment"
Truth table66%2/3
A and B
A= $tagInfoB= $tagInfo->{"Name"} eq "UserComment"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 57 | my $format = $Image::ExifTool::Exif::formatNumber{$formName}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 57 | my $fsiz = $Image::ExifTool::Exif::formatSize[$format]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 57 | my $size = length($$valuePt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 57 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 57 | ▶ | if ($count and $size != $count * $fsiz) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count and $size != $count * $fsiz
MC/DC50%1/2
$count and $size != $count * $fsiz
$count
$size != $count * $fsiz
Truth table66%2/3
A and B
A= $countB= $size != $count * $fsiz
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 19 | ▶ | if ($size < $count * $fsiz) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | warn sprintf("Value too short for raw tag 0x%x\n",$rawTag); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # shorten value appropriately | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 19 | $size = $count * $fsiz; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 19 | $value = substr($$valuePt, 0, $size); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 38 | $count = $size / $fsiz; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 38 | $value = $$valuePt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 57 | my $offsetVal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 57 | my $makerInfo = $$et{MAKER_NOTE_INFO}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 57 | ▶ | if ($size > 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 35 | my $len = length $makerInfo->{ValBuff}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 35 | $offsetVal = Set32u($len); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 35 | $makerInfo->{ValBuff} .= $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # pad to an even number of bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 35 | ▶ | $size & 0x01 and $makerInfo->{ValBuff} .= "\0"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # set flag indicating that this tag needs a fixup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 35 | $makerInfo->{FixupTags}->{$tagID} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 22 | $offsetVal = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 22 | ▶ | $size < 4 and $offsetVal .= "\0" x (4 - $size); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 57 | $makerInfo->{Entries}->{$tagID} = Set16u($tagID) . Set16u($format) . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | Set32u($count) . $offsetVal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Finish building and save MakerNotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # Inputs: 0) ExifTool object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | sub SaveMakerNotes($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SaveMakerNotes: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 6 | my $et = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # save maker notes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | my $makerInfo = $$et{MAKER_NOTE_INFO}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | delete $$et{MAKER_NOTE_INFO}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | my $dirEntries = $makerInfo->{Entries}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 6 | my $numEntries = scalar(keys %$dirEntries); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | my $fixup = Image::ExifTool::Fixup->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | ▶ | return unless $numEntries; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # build the MakerNotes directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 6 | my $makerNotes = Set16u($numEntries); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | my $tagID; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # write the entries in proper tag order (even though Canon doesn't do this...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | foreach $tagID (sort { $a <=> $b } keys %$dirEntries) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 57 | $makerNotes .= $$dirEntries{$tagID}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 57 | ▶ | next unless $makerInfo->{FixupTags}->{$tagID}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # add fixup for this pointer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 35 | $fixup->AddFixup(length($makerNotes) - 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # save position of maker notes for pointer fixups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 6 | $fixup->{Shift} += length($makerNotes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | $$et{MAKER_NOTE_BYTE_ORDER} = GetByteOrder(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # add value data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | $makerNotes .= $makerInfo->{ValBuff}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # get MakerNotes tag info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 6 | my $tagTablePtr = Image::ExifTool::GetTagTable('Image::ExifTool::Exif::Main'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 6 | my $tagInfo = $et->GetTagInfo($tagTablePtr, 0x927c, \$makerNotes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # save the MakerNotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | my $key = $et->FoundTag($tagInfo, $makerNotes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 6 | $$et{TAG_EXTRA}{$key}{Fixup} = $fixup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # save the garbage collection some work later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 6 | delete $makerInfo->{Entries}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 6 | delete $makerInfo->{ValBuff}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | delete $makerInfo->{FixupTags}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # also generate Orientation tag since Rotation isn't transferred from RAW info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | my $rotation = $et->GetValue('Rotation', 'ValueConv'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 6 | ▶ | if (defined $rotation and defined $mapRotation{$rotation}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $rotation and defined $mapRotation{$rotation}
MC/DC0%0/2
defined $rotation and defined $mapRotation{$rotation}
defined $rotation
defined $mapRotation{$rotation}
Truth table33%1/3
A and B
A= defined $rotationB= defined $mapRotation{$rotation}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | $tagInfo = $et->GetTagInfo($tagTablePtr, 0x112); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 6 | $et->FoundTag($tagInfo, $mapRotation{$rotation}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # Check CanonRaw information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # Inputs: 0) ExifTool object reference, 1) tagInfo hash reference, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # 2) raw value reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # Returns: error string or undef (and may change value) on success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | sub CheckCanonRaw($$$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 150 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CheckCanonRaw: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 150 | my ($et, $tagInfo, $valPtr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 150 | my $tagName = $$tagInfo{Name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 150 | ▶ | if ($tagName eq 'JpgFromRaw' or $tagName eq 'ThumbnailImage') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tagName eq "JpgFromRaw" or $tagName eq "ThumbnailImage"
MC/DC100%2/2
$tagName eq "JpgFromRaw" or $tagName eq "ThumbnailImage"
$tagName eq "JpgFromRaw"
$tagName eq "ThumbnailImage"
Truth table100%3/3
A or B
A= $tagName eq "JpgFromRaw"B= $tagName eq "ThumbnailImage"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 5 | ▶ | unless ($$valPtr =~ /^\xff\xd8/ or $et->Options('IgnoreMinorErrors')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$$valPtr =~ /^\xff\xd8/ or $et->Options("IgnoreMinorErrors")
MC/DC100%2/2
$$valPtr =~ /^\xff\xd8/ or $et->Options("IgnoreMinorErrors")
$$valPtr =~ /^\xff\xd8/
$et->Options("IgnoreMinorErrors")
Truth table100%3/3
A or B
A= $$valPtr =~ /^\xff\xd8/B= $et->Options("IgnoreMinorErrors")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | return '[Minor] Not a valid image'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 145 | my $format = $$tagInfo{Format}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 145 | my $count = $$tagInfo{Count}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 145 | ▶ | unless ($format) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 130 | my $tagType = ($$tagInfo{TagID} >> 8) & 0x38; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 130 | $format = $crwTagFormat{$tagType}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 145 | ▶ | $format and return Image::ExifTool::CheckValue($valPtr, $format, $count); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # Write CR2 file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # Inputs: 0) ExifTool ref, 1) dirInfo reference (must have read first 16 bytes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # 2) tag table reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # Returns: true on success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | sub WriteCR2($$$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
WriteCR2: called CC=14 SCAR=35.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 3 | my ($et, $dirInfo, $tagTablePtr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | ▶ | my $dataPt = $$dirInfo{DataPt} or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 3 | ▶ | my $outfile = $$dirInfo{OutFile} or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | $$dirInfo{RAF} or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # check CR2 signature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | ▶ | if ($$dataPt !~ /^.{8}CR\x02\0/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my ($msg, $minor); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ($$dataPt =~ /^.{8}CR/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $msg = 'Unsupported Canon RAW file. May cause problems if rewritten'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $minor = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } elsif ($$dataPt =~ /^.{8}\xba\xb0\xac\xbb/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $msg = 'Can not currently write Canon 1D RAW images'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $msg = 'Unrecognized Canon RAW file'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | return 0 if $et->Error($msg, $minor); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # CR2 has a 16-byte header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 3 | $$dirInfo{NewDataPos} = 16; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 3 | my $newData = $et->WriteDirectory($dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | ▶ | return 0 unless defined $newData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | ▶ | unless ($$dirInfo{LastIFD}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $et->Error("CR2 image IFD may not be deleted"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | ▶ | if (length($newData)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # build 16 byte header for Canon RAW file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | my $header = substr($$dataPt, 0, 16); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # set IFD0 pointer (may not be 16 if edited by PhotoMechanic) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | Set32u(16, \$header, 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # last 4 bytes of header is pointer to last IFD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | Set32u($$dirInfo{LastIFD}, \$header, 12); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | ▶ | Write($outfile, $header, $newData) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | undef $newData; # free memory | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # copy over image data now if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 3 | ▶ | if (ref $$dirInfo{ImageData}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 3 | ▶ | $et->CopyImageData($$dirInfo{ImageData}, $outfile) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 3 | delete $$dirInfo{ImageData}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # Write CanonRaw (CRW) information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # Inputs: 0) ExifTool object reference, 1) source dirInfo reference, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # 2) tag table reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # Returns: true on success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # Notes: Increments ExifTool CHANGED flag for each tag changed This routine is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # different from all of the other write routines because Canon RAW files are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # designed well! So it isn't necessary to buffer the data in memory before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # writing it out. Therefore this routine doesn't return the directory data as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # the rest of the Write routines do. Instead, it writes to the dirInfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # OutFile on the fly --> much faster, efficient, and less demanding on memory! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | sub WriteCanonRaw($$$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 223 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
WriteCanonRaw: called CC=73 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 223 | my ($et, $dirInfo, $tagTablePtr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 223 | ▶ | $et or return 1; # allow dummy access to autoload this package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 49 | my $blockStart = $$dirInfo{DirStart}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 49 | my $blockSize = $$dirInfo{DirLen}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 49 | ▶ | my $raf = $$dirInfo{RAF} or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 49 | ▶ | my $outfile = $$dirInfo{OutFile} or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 49 | ▶ | my $outPos = $$dirInfo{OutPos} or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 49 | my $outBase = $outPos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 49 | my $verbose = $et->Options('Verbose'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 49 | my $out = $et->Options('TextOut'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 49 | my ($buff, $tagInfo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # 4 bytes at end of block give directory position within block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 49 | ▶ | $raf->Seek($blockStart+$blockSize-4, 0) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 49 | ▶ | $raf->Read($buff, 4) == 4 or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 49 | my $dirOffset = Get32u(\$buff,0) + $blockStart; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # avoid infinite recursion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 49 | ▶ | $$et{ProcessedCanonRaw} or $$et{ProcessedCanonRaw} = { }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 49 | ▶ | if ($$et{ProcessedCanonRaw}{$dirOffset}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $et->Error("Double-referenced $$dirInfo{DirName} directory"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 49 | $$et{ProcessedCanonRaw}{$dirOffset} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 49 | ▶ | $raf->Seek($dirOffset, 0) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 49 | ▶ | $raf->Read($buff, 2) == 2 or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 49 | my $entries = Get16u(\$buff,0); # get number of entries in directory | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # read the directory (10 bytes per entry) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 49 | ▶ | $raf->Read($buff, 10 * $entries) == 10 * $entries or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 49 | my $newDir = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # get hash of new information keyed by tagID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 49 | my $newTags = $et->GetNewTagInfoHash($tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # generate list of tags to add or delete (currently, we only allow JpgFromRaw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # and ThumbnailImage, to be added or deleted from the root CanonRaw directory) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 49 | my (@addTags, %delTag); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 49 | ▶ | if ($$dirInfo{Nesting} == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 7 | my $tagID; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 7 | foreach $tagID (keys %$newTags) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 15 | my $permanent = $newTags->{$tagID}->{Permanent}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 15 | ▶ | push(@addTags, $tagID) if defined($permanent) and not $permanent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $permanent and not $permanent
MC/DC50%1/2
defined $permanent and not $permanent
defined $permanent
not $permanent
Truth table66%2/3
A and not(B)
A= defined $permanentB= not $permanent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 49 | my $index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 49 | for ($index=0; ; ++$index) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 336 | my ($pt, $tag, $size, $valuePtr, $ptr, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 336 | ▶ | if ($index<$entries) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 287 | $pt = 10 * $index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 287 | $tag = Get16u(\$buff, $pt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 287 | $size = Get32u(\$buff, $pt+2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 287 | $valuePtr = Get32u(\$buff, $pt+6); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 287 | $ptr = $valuePtr + $blockStart; # all pointers relative to block start | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # add any required new tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # NOTE: can't currently add tags where value is stored in directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 336 | ▶ | if (@addTags and (not defined($tag) or $tag >= $addTags[0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@addTags and !defined($tag) || $tag >= $addTags[0]
not defined $tag or $tag >= $addTags[0]
MC/DC66%2/3
@addTags and !defined($tag) || $tag >= $addTags[0]
@addTags
not defined $tag
$tag >= $addTags[0]
Truth table75%3/4
A and not(B) or C
A= @addTagsB= not defined $tagC= $tag >= $addTags[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | my $addTag = shift @addTags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | $tagInfo = $$newTags{$addTag}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | my $newVal = $et->GetNewValue($tagInfo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | ▶ | if (defined $newVal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # pad value to an even length (Canon ImageBrowser and ZoomBrowser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # version 6.1.1 have problems with odd-sized embedded JPEG images | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # even if the value is padded to maintain alignment, so do this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # before calculating the size for the directory entry) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | ▶ | $newVal .= "\0" if length($newVal) & 0x01; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # add new directory entry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | $newDir .= Set16u($addTag) . Set32u(length($newVal)) . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | Set32u($outPos - $outBase); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # write new value data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | ▶ | Write($outfile, $newVal) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | $outPos += length($newVal); # update current position | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | ▶ | $verbose > 1 and print $out " + CanonRaw:$$tagInfo{Name}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | ++$$et{CHANGED}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # set flag to delete this tag if found later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | $delTag{$addTag} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 336 | ▶ | last unless defined $tag; # all done if no more directory entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 287 | ▶ | return 0 if $tag & 0x8000; # top bit should not be set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 287 | my $tagID = $tag & 0x3fff; # get tag ID | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 287 | my $tagType = ($tag >> 8) & 0x38; # get tag type | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 287 | my $valueInDir = ($tag & 0x4000); # flag for value in directory | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 287 | my $tagInfo = $et->GetTagInfo($tagTablePtr,$tagID); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 287 | my $format = $crwTagFormat{$tagType}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 287 | my ($count, $subdir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 287 | ▶ | if ($tagInfo) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 244 | $subdir = $$tagInfo{SubDirectory}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 244 | ▶ | $format = $$tagInfo{Format} if $$tagInfo{Format}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 244 | $count = $$tagInfo{Count}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 287 | ▶ | if ($valueInDir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 97 | $size = 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 97 | $value = substr($buff, $pt+2, $size); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # set count to 1 by default for normal values in directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 97 | ▶ | $count = 1 if not defined $count and $format and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
not defined $count and $format and $format ne "string" and not $subdir
not defined $count and $format and $format ne "string"
not defined $count and $format
MC/DC75%3/4
not defined $count and $format and $format ne "string" and not $subdir
not defined $count
$format
$format ne "string"
not $subdir
Truth table80%4/5
not(A) and B and C and not(D)
A= not defined $countB= $formatC= $format ne "string"D= not $subdir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | $format ne 'string' and not $subdir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 190 | ▶ | if ($tagType==0x28 or $tagType==0x30) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tagType == 40 or $tagType == 48
MC/DC100%2/2
$tagType == 40 or $tagType == 48
$tagType == 40
$tagType == 48
Truth table100%3/3
A or B
A= $tagType == 40B= $tagType == 48
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # this type of tag specifies a raw subdirectory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 42 | my $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 42 | ▶ | $tagInfo and $name = $$tagInfo{Name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 42 | ▶ | $name or $name = sprintf("CanonRaw_0x%.4x", $tagID); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | my %subdirInfo = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | DirName => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | DataLen => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | DirStart => $ptr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | DirLen => $size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | Nesting => $$dirInfo{Nesting} + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | RAF => $raf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | Parent => $$dirInfo{DirName}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 42 | OutFile => $outfile, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | OutPos => $outPos, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 42 | my $result = $et->WriteDirectory(\%subdirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 42 | ▶ | return 0 unless $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # set size and pointer for this new directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 42 | $size = $subdirInfo{OutPos} - $outPos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 42 | $valuePtr = $outPos - $outBase; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 42 | $outPos = $subdirInfo{OutPos}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # verify that the value data is within this block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 148 | ▶ | $valuePtr + $size <= $blockSize or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # read value from file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 148 | ▶ | $raf->Seek($ptr, 0) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 148 | ▶ | $raf->Read($value, $size) == $size or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # set count from tagInfo count if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 287 | ▶ | if ($format and not $count) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$format and not $count
MC/DC100%2/2
$format and not $count
$format
not $count
Truth table100%3/3
A and not(B)
A= $formatB= not $count
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # set count according to format and size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 167 | my $fnum = $Image::ExifTool::Exif::formatNumber{$format}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 167 | my $fsiz = $Image::ExifTool::Exif::formatSize[$fnum]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 167 | $count = int($size / $fsiz); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # edit subdirectory if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 287 | ▶ | if ($tagInfo) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 244 | ▶ | if ($subdir and $$subdir{TagTable}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$subdir and $subdir->{"TagTable"}
MC/DC100%2/2
$subdir and $subdir->{"TagTable"}
$subdir
$subdir->{"TagTable"}
Truth table100%3/3
A and B
A= $subdirB= $subdir->{"TagTable"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 67 | my $name = $$tagInfo{Name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 67 | my $newTagTable = Image::ExifTool::GetTagTable($$subdir{TagTable}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 67 | ▶ | return 0 unless $newTagTable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 67 | my $subdirStart = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | #### eval Start () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 67 | ▶ | $subdirStart = eval $$subdir{Start} if $$subdir{Start}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 67 | my $dirData = \$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | my %subdirInfo = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | Name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | DataPt => $dirData, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | DataLen => $size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | DirStart => $subdirStart, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | DirLen => $size - $subdirStart, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | Nesting => $$dirInfo{Nesting} + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | RAF => $raf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | Parent => $$dirInfo{DirName}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 67 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | #### eval Validate ($dirData, $subdirStart, $size) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 67 | ▶ | if (defined $$subdir{Validate} and not eval $$subdir{Validate}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $subdir->{"Validate"} and not eval $subdir->{"Validate"}
MC/DC0%0/2
defined $subdir->{"Validate"} and not eval $subdir->{"Validate"}
defined $subdir->{"Validate"}
not eval $subdir->{"Validate"}
Truth table66%2/3
A and not(B)
A= defined $subdir->{"Validate"}B= not eval $subdir->{"Validate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $et->Warn("Invalid $name data"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 67 | $subdir = $et->WriteDirectory(\%subdirInfo, $newTagTable); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 67 | ▶ | if (defined $subdir and length $subdir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $subdir and length $subdir
MC/DC50%1/2
defined $subdir and length $subdir
defined $subdir
length $subdir
Truth table66%2/3
A and B
A= defined $subdirB= length $subdir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 61 | ▶ | if ($subdirStart) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # add header before data directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $value = substr($value, 0, $subdirStart) . $subdir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 61 | $value = $subdir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } elsif ($$newTags{$tagID}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 16 | ▶ | if ($delTag{$tagID}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | ▶ | $verbose > 1 and print $out " - CanonRaw:$$tagInfo{Name}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | ++$$et{CHANGED}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | next; # next since we already added this tag | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 15 | my $oldVal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 15 | ▶ | if ($format) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 15 | $oldVal = ReadValue(\$value, 0, $format, $count, $size); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | $oldVal = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 15 | my $nvHash = $et->GetNewValueHash($tagInfo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 15 | ▶ | if ($et->IsOverwriting($nvHash, $oldVal)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 14 | my $newVal = $et->GetNewValue($nvHash); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 14 | my $verboseVal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 14 | ▶ | $verboseVal = $newVal if $verbose > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # convert to specified format if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 14 | ▶ | if (defined $newVal and $format) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $newVal and $format
MC/DC0%0/2
defined $newVal and $format
defined $newVal
$format
Truth table33%1/3
A and B
A= defined $newValB= $format
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 14 | $newVal = WriteValue($newVal, $format, $count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 14 | ▶ | if (defined $newVal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 14 | $value = $newVal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 14 | ++$$et{CHANGED}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 14 | $et->VerboseValue("- CanonRaw:$$tagInfo{Name}", $oldVal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 14 | $et->VerboseValue("+ CanonRaw:$$tagInfo{Name}", $verboseVal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 286 | ▶ | if ($valueInDir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 97 | my $len = length $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 97 | ▶ | if ($len < 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # pad with original garbage in case it contained something useful | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 5 | $value .= substr($buff, $pt+2+8-$len, 8-$len); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } elsif ($len > 8) { # this shouldn't happen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | warn "Value too long! -- truncated\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $value = substr($value, 0, 8); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # create new directory entry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 97 | $newDir .= Set16u($tag) . $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 97 | next; # all done this entry | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 189 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # don't allow value to change length unless Writable is 'resize' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 147 | my $writable = $$tagInfo{Writable}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 147 | my $diff = length($value) - $size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 147 | ▶ | if ($diff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | if ($writable and $writable eq 'resize') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$writable and $writable eq "resize"
MC/DC0%0/2
$writable and $writable eq "resize"
$writable
$writable eq "resize"
Truth table0%0/3
A and B
A= $writableB= $writable eq "resize"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | $size += $diff; # allow size to change | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } elsif ($diff > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | $value .= ("\0" x $diff); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $value = substr($value, 0, $size); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # pad value if necessary to align on even-byte boundary (as per CIFF spec) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 147 | ▶ | $value .= "\0" if $size & 0x01; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 147 | $valuePtr = $outPos - $outBase; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # write out value data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 147 | ▶ | Write($outfile, $value) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 147 | $outPos += length($value); # update current position in outfile | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # create new directory entry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 189 | $newDir .= Set16u($tag) . Set32u($size) . Set32u($valuePtr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # add the directory counts and offset to the directory start, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 49 | $entries = length($newDir) / 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 49 | $newDir = Set16u($entries) . $newDir . Set32u($outPos - $outBase); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # write directory data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 49 | ▶ | Write($outfile, $newDir) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # update current output file position in dirInfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 49 | $$dirInfo{OutPos} = $outPos + length($newDir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # save outfile directory start (needed for rewriting VRD trailer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 49 | $$dirInfo{OutDirStart} = $outPos - $outBase; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 49 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # write Canon RAW (CRW) file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # Inputs: 0) ExifTool object reference, 1) dirInfo reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # Returns: 1 on success, 0 if this wasn't a valid CRW file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # or -1 if a write error occurred | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | sub WriteCRW($$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
WriteCRW: called CC=26 SCAR=35.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 7 | my ($et, $dirInfo) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 7 | my $outfile = $$dirInfo{OutFile}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 7 | my $raf = $$dirInfo{RAF}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 7 | my $rtnVal = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 7 | my ($buff, $err, $sig); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 7 | ▶ | $raf->Read($buff,2) == 2 or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 7 | ▶ | SetByteOrder($buff) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 7 | ▶ | $raf->Read($buff,4) == 4 or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 7 | ▶ | $raf->Read($sig,8) == 8 or return 0; # get file signature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 7 | ▶ | $sig =~ /^HEAP(CCDR|JPGM)/ or return 0; # validate signature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 7 | my $type = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 7 | my $hlen = Get32u(\$buff, 0); # get header length | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 7 | ▶ | if ($$et{DEL_GROUP}{MakerNotes}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | if ($type eq 'CCDR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $et->Error("Can't delete MakerNotes from CRW"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ++$$et{CHANGED}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | # make XMP the preferred group for CRW files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 7 | ▶ | if ($$et{FILE_TYPE} eq 'CRW') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 3 | $et->InitWriteDirs(\%crwMap, 'XMP'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # write header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 7 | ▶ | $raf->Seek(0, 0) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 7 | ▶ | $raf->Read($buff, $hlen) == $hlen or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 7 | ▶ | Write($outfile, $buff) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 7 | ▶ | $raf->Seek(0, 2) or return 0; # seek to end of file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 7 | ▶ | my $filesize = $raf->Tell() or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | # build directory information for main raw directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 7 | my %dirInfo = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | DataLen => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | DirStart => $hlen, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | DirLen => $filesize - $hlen, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | Nesting => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | RAF => $raf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | Parent => 'CRW', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | OutFile => $outfile, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | OutPos => $hlen, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # process the raw directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 7 | my $tagTablePtr = Image::ExifTool::GetTagTable('Image::ExifTool::CanonRaw::Main'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 7 | my $success = $et->WriteDirectory(\%dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 7 | my $trailPt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 7 | ▶ | while ($success) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # check to see if trailer(s) exist(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 7 | ▶ | my $trailInfo = $et->IdentifyTrailer($raf) or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # rewrite the trailer(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 3 | $buff = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 3 | $$trailInfo{OutFile} = \$buff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 3 | ▶ | $success = $et->ProcessTrailers($trailInfo) or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 3 | $trailPt = $$trailInfo{OutFile}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # nothing to write if trailers were deleted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 3 | ▶ | undef $trailPt if length($$trailPt) < 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 3 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 7 | ▶ | if ($success) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # add CanonVRD trailer if writing as a block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 7 | $trailPt = $et->AddNewTrailers($trailPt,'CanonVRD'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 7 | ▶ | if (not $trailPt and $$et{ADD_DIRS}{CanonVRD}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $trailPt and $et->{"ADD_DIRS"}{"CanonVRD"}
MC/DC100%2/2
not $trailPt and $et->{"ADD_DIRS"}{"CanonVRD"}
not $trailPt
$et->{"ADD_DIRS"}{"CanonVRD"}
Truth table100%3/3
not(A) and B
A= not $trailPtB= $et->{"ADD_DIRS"}{"CanonVRD"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | # create CanonVRD from scratch if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 1 | my $outbuff = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 1 | my $saveOrder = GetByteOrder(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 1 | require Image::ExifTool::CanonVRD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | ▶ | if (Image::ExifTool::CanonVRD::ProcessCanonVRD($et, { OutFile => \$outbuff }) > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | $trailPt = \$outbuff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 1 | SetByteOrder($saveOrder); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # write trailer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 7 | ▶ | if ($trailPt) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | # must append DirStart pointer to end of trailer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 5 | my $newDirStart = Set32u($dirInfo{OutDirStart}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 5 | my $len = length $$trailPt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 5 | ▶ | my $pad = ($len & 0x01) ? ' ' : ''; # add pad byte if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 5 | ▶ | Write($outfile, $pad, substr($$trailPt,0,$len-4), $newDirStart) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 7 | ▶ | $rtnVal = $err ? -1 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | $et->Error('Error rewriting CRW file'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 7 | return $rtnVal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 11 | 1; # end | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||