| 1 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # File: AFCP.pm | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Description: Read/write AFCP trailer | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Revisions: 12/26/2005 - P. Harvey Created | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # References: 1) http://web.archive.org/web/20080828211305/http://www.tocarte.com/media/axs_afcp_spec.pdf | ||||||||||||||||||||||||||||||||||||||||||
| 9 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | package Image::ExifTool::AFCP; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Image::ExifTool qw(:DataAccess :Utils); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | $VERSION = '1.10'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | sub ProcessAFCP($$); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | %Image::ExifTool::AFCP::Main = ( | |||||||||||||||||||||||||||||||||||||||||
| 22 | PROCESS_PROC => \&ProcessAFCP, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | NOTES => q{ | ||||||||||||||||||||||||||||||||||||||||||
| 24 | AFCP stands for AXS File Concatenation Protocol, and is a poorly designed | ||||||||||||||||||||||||||||||||||||||||||
| 25 | protocol for appending information to the end of files. This can be used as | ||||||||||||||||||||||||||||||||||||||||||
| 26 | an auxiliary technique to store IPTC information in images, but is | ||||||||||||||||||||||||||||||||||||||||||
| 27 | incompatible with some file formats. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | ExifTool will read and write (but not create) AFCP IPTC information in JPEG | ||||||||||||||||||||||||||||||||||||||||||
| 30 | and TIFF images. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | See | ||||||||||||||||||||||||||||||||||||||||||
| 33 | L<http://web.archive.org/web/20080828211305/http://www.tocarte.com/media/axs_afcp_spec.pdf> | ||||||||||||||||||||||||||||||||||||||||||
| 34 | for the AFCP specification. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | IPTC => { SubDirectory => { TagTable => 'Image::ExifTool::IPTC::Main' } }, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | TEXT => 'Text', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | Nail => { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | Name => 'ThumbnailImage', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | Groups => { 2 => 'Preview' }, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # (the specification allows for a variable amount of padding before | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # the image after a 10-byte header, so look for the JPEG SOI marker, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # otherwise assume a fixed 8 bytes of padding) | ||||||||||||||||||||||||||||||||||||||||||
| 44 | RawConv => q{ | ||||||||||||||||||||||||||||||||||||||||||
| 45 | pos($val) = 10; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | my $start = ($val =~ /\xff\xd8\xff/g) ? pos($val) - 3 : 18; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | my $img = substr($val, $start); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | return $self->ValidateImage(\$img, $tag); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | PrVw => { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | Name => 'PreviewImage', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | Groups => { 2 => 'Preview' }, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | RawConv => q{ | ||||||||||||||||||||||||||||||||||||||||||
| 55 | pos($val) = 10; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | my $start = ($val =~ /\xff\xd8\xff/g) ? pos($val) - 3 : 18; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | my $img = substr($val, $start); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | return $self->ValidateImage(\$img, $tag); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # Read/write AFCP information in a file | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # Inputs: 0) ExifTool object reference, 1) dirInfo reference | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # (Set 'ScanForTrailer' member in dirInfo to scan from current position for AFCP) | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # Returns: 1 on success, 0 if this file didn't contain AFCP information | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # -1 on write error or if the offsets were incorrect on reading | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # - updates DataPos to point to actual AFCP start if ScanForTrailer is set | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # - updates DirLen to trailer length | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # - returns Fixup reference in dirInfo hash when writing | ||||||||||||||||||||||||||||||||||||||||||
| 72 | sub ProcessAFCP($$) | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 29 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ProcessAFCP: called CC=39 SCAR=51.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 29 | my ($et, $dirInfo) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 29 | my $raf = $$dirInfo{RAF}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 29 | my $curPos = $raf->Tell(); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 29 | ▶ | my $offset = $$dirInfo{Offset} || 0; # offset from end of file | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$dirInfo->{'Offset'} || 0
MC/DC100%1/1
$dirInfo->{'Offset'} || 0
$dirInfo->{'Offset'}
Truth table100%2/2
A
A= $dirInfo->{'Offset'}
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 29 | my $rtnVal = 0; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 29 | NoAFCP: for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 81 | 29 | my ($buff, $fix, $dirBuff, $valBuff, $fixup, $vers); | |||||||||||||||||||||||||||||||||||||||||
| 82 | # look for AXS trailer | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 29 | ▶ | last unless $raf->Seek(-12-$offset, 2) and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$raf->Seek(-12 - $offset, 2) and $raf->Read($buff, 12) == 12 and $buff =~ /^(AXS(!|\*))/
$raf->Seek(-12 - $offset, 2) and $raf->Read($buff, 12) == 12
MC/DC0%0/3
$raf->Seek(-12 - $offset, 2) and $raf->Read($buff, 12) == 12 and $buff =~ /^(AXS(!|\*))/
$raf->Seek(-12 - $offset, 2)
$raf->Read($buff, 12) == 12
$buff =~ /^(AXS(!|\*))/
Truth table25%1/4
A and B and C
A= $raf->Seek(-12 - $offset, 2)B= $raf->Read($buff, 12) == 12C= $buff =~ /^(AXS(!|\*))/
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | $raf->Read($buff, 12) == 12 and | ||||||||||||||||||||||||||||||||||||||||||
| 85 | $buff =~ /^(AXS(!|\*))/; | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 29 | my $endPos = $raf->Tell(); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 29 | my $hdr = $1; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 29 | ▶ | SetByteOrder($2 eq '!' ? 'MM' : 'II'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 29 | my $startPos = Get32u(\$buff, 4); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 29 | ▶ | if ($raf->Seek($startPos, 0) and $raf->Read($buff, 12) == 12 and $buff =~ /^$hdr/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$raf->Seek($startPos, 0) and $raf->Read($buff, 12) == 12 and $buff =~ /^$hdr/
$raf->Seek($startPos, 0) and $raf->Read($buff, 12) == 12
MC/DC0%0/3
$raf->Seek($startPos, 0) and $raf->Read($buff, 12) == 12 and $buff =~ /^$hdr/
$raf->Seek($startPos, 0)
$raf->Read($buff, 12) == 12
$buff =~ /^$hdr/
Truth table25%1/4
A and B and C
A= $raf->Seek($startPos, 0)B= $raf->Read($buff, 12) == 12C= $buff =~ /^$hdr/
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 29 | $fix = 0; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $rtnVal = -1; | |||||||||||||||||||||||||||||||||||||||||
| 94 | # look for start of AXS trailer if 'ScanForTrailer' | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | last unless $$dirInfo{ScanForTrailer} and $raf->Seek($curPos, 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$dirInfo->{"ScanForTrailer"} and $raf->Seek($curPos, 0)
MC/DC0%0/2
$dirInfo->{"ScanForTrailer"} and $raf->Seek($curPos, 0)
$dirInfo->{"ScanForTrailer"}
$raf->Seek($curPos, 0)
Truth table0%0/3
A and B
A= $dirInfo->{"ScanForTrailer"}B= $raf->Seek($curPos, 0)
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $actualPos = $curPos; | |||||||||||||||||||||||||||||||||||||||||
| 97 | # first look for header right at current position | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | last if $raf->Read($buff, 12) == 12 and $buff =~ /^$hdr/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$raf->Read($buff, 12) == 12 and $buff =~ /^$hdr/
MC/DC0%0/2
$raf->Read($buff, 12) == 12 and $buff =~ /^$hdr/
$raf->Read($buff, 12) == 12
$buff =~ /^$hdr/
Truth table0%0/3
A and B
A= $raf->Read($buff, 12) == 12B= $buff =~ /^$hdr/
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | last NoAFCP if $actualPos != $curPos; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | # scan for AXS header (could be after preview image) | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $buf2; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $raf->Read($buf2, 65536) or last NoAFCP; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $buff .= $buf2; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ($buff =~ /$hdr/g) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $actualPos += pos($buff) - length($hdr); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | last; # ok, now go back and re-read header | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $buf2 = substr($buf2, -3); # only need last 3 bytes for next test | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $actualPos += length($buff) - length($buf2); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $buff = $buf2; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | last unless $raf->Seek($actualPos, 0); # seek to start of AFCP | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # calculate shift for fixing AFCP offsets | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $fix = $actualPos - $startPos; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # set variables returned in dirInfo hash | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 29 | $$dirInfo{DataPos} = $startPos + $fix; # actual start position | |||||||||||||||||||||||||||||||||||||||||
| 121 | 29 | $$dirInfo{DirLen} = $endPos - ($startPos + $fix); | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 29 | $rtnVal = 1; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 29 | my $verbose = $et->Options('Verbose'); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 29 | my $out = $et->Options('TextOut'); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 29 | my $outfile = $$dirInfo{OutFile}; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 29 | ▶ | if ($outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | # allow all AFCP information to be deleted | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | ▶ | if ($$et{DEL_GROUP}{AFCP}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $verbose and print $out " Deleting AFCP\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ++$$et{CHANGED}; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 8 | $dirBuff = $valBuff = ''; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 8 | require Image::ExifTool::Fixup; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 8 | $fixup = $$dirInfo{Fixup}; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 8 | ▶ | $fixup or $fixup = $$dirInfo{Fixup} = Image::ExifTool::Fixup->new; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 8 | $vers = substr($buff, 4, 2); # get version number | |||||||||||||||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 21 | ▶ | $et->DumpTrailer($dirInfo) if $verbose or $$et{HTML_DUMP}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$verbose or $et->{"HTML_DUMP"}
MC/DC0%0/2
$verbose or $et->{"HTML_DUMP"}
$verbose
$et->{"HTML_DUMP"}
Truth table33%1/3
A or B
A= $verboseB= $et->{"HTML_DUMP"}
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # read AFCP directory data | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 29 | my $numEntries = Get16u(\$buff, 6); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 29 | my $dir; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 29 | ▶ | unless ($raf->Read($dir, 12 * $numEntries) == 12 * $numEntries) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $et->Error('Error reading AFCP directory', 1); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 29 | ▶ | if ($verbose > 2 and not $outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$verbose > 2 and not $outfile
MC/DC0%0/2
$verbose > 2 and not $outfile
$verbose > 2
not $outfile
Truth table33%1/3
A and not(B)
A= $verbose > 2B= not $outfile
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $dat = $buff . $dir; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | print $out " AFCP Directory:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $et->VerboseDump(\$dat, Addr => $$dirInfo{DataPos}, Width => 12); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 29 | ▶ | $fix and $et->Warn("Adjusted AFCP offsets by $fix", 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | # | ||||||||||||||||||||||||||||||||||||||||||
| 156 | # process AFCP directory | ||||||||||||||||||||||||||||||||||||||||||
| 157 | # | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 29 | my $tagTablePtr = GetTagTable('Image::ExifTool::AFCP::Main'); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 29 | my ($index, $entry); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 29 | ▶ | for ($index=0; $index<$numEntries; ++$index) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 58 | my $entry = 12 * $index; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 58 | my $tag = substr($dir, $entry, 4); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 58 | my $size = Get32u(\$dir, $entry + 4); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 58 | my $offset = Get32u(\$dir, $entry + 8); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 58 | ▶ | if ($size < 0x80000000 and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$size < 2147483648 and $raf->Seek($offset + $fix, 0) and $raf->Read($buff, $size) == $size
$size < 2147483648 and $raf->Seek($offset + $fix, 0)
MC/DC0%0/3
$size < 2147483648 and $raf->Seek($offset + $fix, 0) and $raf->Read($buff, $size) == $size
$size < 2147483648
$raf->Seek($offset + $fix, 0)
$raf->Read($buff, $size) == $size
Truth table25%1/4
A and B and C
A= $size < 2147483648B= $raf->Seek($offset + $fix, 0)C= $raf->Read($buff, $size) == $size
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | $raf->Seek($offset+$fix, 0) and | ||||||||||||||||||||||||||||||||||||||||||
| 167 | $raf->Read($buff, $size) == $size) | ||||||||||||||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 58 | ▶ | if ($outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | # rewrite this information | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 16 | my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 16 | ▶ | if ($tagInfo and $$tagInfo{SubDirectory}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tagInfo and $tagInfo->{"SubDirectory"}
MC/DC50%1/2
$tagInfo and $tagInfo->{"SubDirectory"}
$tagInfo
$tagInfo->{"SubDirectory"}
Truth table66%2/3
A and B
A= $tagInfoB= $tagInfo->{"SubDirectory"}
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | my %subdirInfo = ( | |||||||||||||||||||||||||||||||||||||||||
| 174 | DataPt => \$buff, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | DirStart => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | DirLen => $size, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | DataPos => $offset + $fix, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | Parent => 'AFCP', | ||||||||||||||||||||||||||||||||||||||||||
| 179 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 8 | my $subTable = GetTagTable($tagInfo->{SubDirectory}->{TagTable}); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 8 | my $newDir = $et->WriteDirectory(\%subdirInfo, $subTable); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 8 | ▶ | if (defined $newDir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | $size = length $newDir; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | $buff = $newDir; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 16 | $fixup->AddFixup(length($dirBuff) + 8); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 16 | $dirBuff .= $tag . Set32u($size) . Set32u(length $valBuff); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 16 | $valBuff .= $buff; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 191 | # extract information | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 42 | $et->HandleTag($tagTablePtr, $tag, $buff, | |||||||||||||||||||||||||||||||||||||||||
| 193 | DataPt => \$buff, | ||||||||||||||||||||||||||||||||||||||||||
| 194 | Size => $size, | ||||||||||||||||||||||||||||||||||||||||||
| 195 | Index => $index, | ||||||||||||||||||||||||||||||||||||||||||
| 196 | DataPos => $offset + $fix, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $et->Warn("Bad AFCP directory"); | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $rtnVal = -1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 29 | ▶ | if ($outfile and length($dirBuff)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$outfile and length $dirBuff
MC/DC50%1/2
$outfile and length $dirBuff
$outfile
length $dirBuff
Truth table66%2/3
A and B
A= $outfileB= length $dirBuff
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 8 | my $outPos = Tell($outfile); # get current outfile position | |||||||||||||||||||||||||||||||||||||||||
| 207 | # apply fixup to directory pointers | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 8 | my $valPos = $outPos + 12; # start of value data | |||||||||||||||||||||||||||||||||||||||||
| 209 | 8 | $fixup->{Shift} += $valPos + length($dirBuff); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 8 | $fixup->ApplyFixup(\$dirBuff); | |||||||||||||||||||||||||||||||||||||||||
| 211 | # write the AFCP header, directory, value data and EOF record (with zero checksums) | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 8 | ▶ | Write($outfile, $hdr, $vers, Set16u(length($dirBuff)/12), Set32u(0), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | $dirBuff, $valBuff, $hdr, Set32u($outPos), Set32u(0)) or $rtnVal = -1; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # complete fixup so the calling routine can apply further shifts | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 8 | $fixup->AddFixup(length($dirBuff) + length($valBuff) + 4); | |||||||||||||||||||||||||||||||||||||||||
| 216 | 8 | $fixup->{Start} += $valPos; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 8 | $fixup->{Shift} -= $valPos; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 29 | last; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 29 | return $rtnVal; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 5 | 1; # end | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | __END__ | ||||||||||||||||||||||||||||||||||||||||||