| 1 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # File: GIF.pm | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Description: Read and write GIF meta information | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Revisions: 10/18/2005 - P. Harvey Separated from ExifTool.pm | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # 05/23/2008 - P. Harvey Added ability to read/write XMP | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # 10/28/2011 - P. Harvey Added ability to read/write ICC_Profile | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # References: 1) http://www.w3.org/Graphics/GIF/spec-gif89a.txt | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # 2) http://www.adobe.com/devnet/xmp/ | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # 3) http://graphcomp.com/info/specs/ani_gif.html | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # 4) http://www.color.org/icc_specs2.html | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # 5) http://www.midiox.com/mmgif.htm | ||||||||||||||||||||||||||||||||||||||||||
| 15 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | package Image::ExifTool::GIF; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | ▶ | use Image::ExifTool qw(:DataAccess :Utils); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | $VERSION = '1.21'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # road map of directory locations in GIF images | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | my %gifMap = ( | |||||||||||||||||||||||||||||||||||||||||
| 27 | XMP => 'GIF', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ICC_Profile => 'GIF', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # application extensions that we can write, and the order they are written | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | my @appExtensions = ( 'XMP Data/XMP', 'ICCRGBG1/012' ); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | %Image::ExifTool::GIF::Main = ( | |||||||||||||||||||||||||||||||||||||||||
| 35 | GROUPS => { 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | VARS => { ID_FMT => 'none' }, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | NOTES => q{ | ||||||||||||||||||||||||||||||||||||||||||
| 38 | This table lists information extracted from GIF images. See | ||||||||||||||||||||||||||||||||||||||||||
| 39 | L<http://www.w3.org/Graphics/GIF/spec-gif89a.txt> for the official GIF89a | ||||||||||||||||||||||||||||||||||||||||||
| 40 | specification. | ||||||||||||||||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | GIFVersion => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | FrameCount => { Notes => 'number of animated images' }, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | Text => { Notes => 'text displayed in image' }, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | Comment => { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # for documentation only -- flag as writable for the docs, but | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # it won't appear in the TagLookup because there is no WRITE_PROC | ||||||||||||||||||||||||||||||||||||||||||
| 48 | Writable => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | Duration => { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | Notes => 'duration of a single animation iteration', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | PrintConv => 'sprintf("%.2f s",$val)', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ScreenDescriptor => { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | SubDirectory => { TagTable => 'Image::ExifTool::GIF::Screen' }, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | Extensions => { # (for documentation only) | ||||||||||||||||||||||||||||||||||||||||||
| 58 | SubDirectory => { TagTable => 'Image::ExifTool::GIF::Extensions' }, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | TransparentColor => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # GIF89a application extensions: | ||||||||||||||||||||||||||||||||||||||||||
| 64 | %Image::ExifTool::GIF::Extensions = ( | ||||||||||||||||||||||||||||||||||||||||||
| 65 | GROUPS => { 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | NOTES => 'Tags extracted from GIF89a application extensions.', | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 22 | ▶ | WRITE_PROC => sub { return 1 }, # (dummy proc to facilitate writable directories) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | 'NETSCAPE/2.0' => { #3 | |||||||||||||||||||||||||||||||||||||||||
| 69 | Name => 'Animation', | ||||||||||||||||||||||||||||||||||||||||||
| 70 | SubDirectory => { TagTable => 'Image::ExifTool::GIF::Animation' }, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 'XMP Data/XMP' => { #2 | ||||||||||||||||||||||||||||||||||||||||||
| 73 | Name => 'XMP', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # IncludeLengthBytes indicates the length bytes are part of the data value... | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # undef = data may contain nulls and is split into 255-byte blocks | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # 1 = data may not contain nulls and is not split; NULL padding is added as necessary | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # 2 = data is not split and may be edited in place; 257-byte landing zone is added | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # (Terminator may be specified for a value of 1 above, but must be specified for 2) | ||||||||||||||||||||||||||||||||||||||||||
| 79 | IncludeLengthBytes => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | Terminator => q(<\\?xpacket end=['"][wr]['"]\\?>), # (regex to match end of valid data) | ||||||||||||||||||||||||||||||||||||||||||
| 81 | Writable => 2, # (writable directory!) | ||||||||||||||||||||||||||||||||||||||||||
| 82 | SubDirectory => { TagTable => 'Image::ExifTool::XMP::Main' }, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 'ICCRGBG1/012' => { #4 | ||||||||||||||||||||||||||||||||||||||||||
| 85 | Name => 'ICC_Profile', | ||||||||||||||||||||||||||||||||||||||||||
| 86 | Writable => 2, # (writable directory!) | ||||||||||||||||||||||||||||||||||||||||||
| 87 | SubDirectory => { TagTable => 'Image::ExifTool::ICC_Profile::Main' }, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 'MIDICTRL/Jon' => { #5 | ||||||||||||||||||||||||||||||||||||||||||
| 90 | Name => 'MIDIControl', | ||||||||||||||||||||||||||||||||||||||||||
| 91 | SubDirectory => { TagTable => 'Image::ExifTool::GIF::MIDIControl' }, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 'MIDISONG/Dm7' => { #5 | ||||||||||||||||||||||||||||||||||||||||||
| 94 | Name => 'MIDISong', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | Groups => { 2 => 'Audio' }, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | Binary => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 'C2PA_GIF/' => { #https://c2pa.org/specifications/ (NC) (authentication code is 0x010000 binary, so removed from tag ID) | ||||||||||||||||||||||||||||||||||||||||||
| 99 | Name => 'JUMBF', | ||||||||||||||||||||||||||||||||||||||||||
| 100 | SubDirectory => { TagTable => 'Image::ExifTool::Jpeg2000::Main' }, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | # GIF locical screen descriptor | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | %Image::ExifTool::GIF::Screen = ( | |||||||||||||||||||||||||||||||||||||||||
| 106 | PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | GROUPS => { 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | NOTES => 'Information extracted from the GIF logical screen descriptor.', | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 => { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | Name => 'ImageWidth', | ||||||||||||||||||||||||||||||||||||||||||
| 111 | Format => 'int16u', | ||||||||||||||||||||||||||||||||||||||||||
| 112 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 => { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | Name => 'ImageHeight', | ||||||||||||||||||||||||||||||||||||||||||
| 115 | Format => 'int16u', | ||||||||||||||||||||||||||||||||||||||||||
| 116 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 4.1 => { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | Name => 'HasColorMap', | ||||||||||||||||||||||||||||||||||||||||||
| 119 | Mask => 0x80, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | PrintConv => { 0 => 'No', 1 => 'Yes' }, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 4.2 => { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | Name => 'ColorResolutionDepth', | ||||||||||||||||||||||||||||||||||||||||||
| 124 | Mask => 0x70, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | ValueConv => '$val + 1', | ||||||||||||||||||||||||||||||||||||||||||
| 126 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 4.3 => { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | Name => 'BitsPerPixel', | ||||||||||||||||||||||||||||||||||||||||||
| 129 | Mask => 0x07, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | ValueConv => '$val + 1', | ||||||||||||||||||||||||||||||||||||||||||
| 131 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 => 'BackgroundColor', | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 6 => { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | Name => 'PixelAspectRatio', | ||||||||||||||||||||||||||||||||||||||||||
| 135 | RawConv => '$val ? $val : undef', | ||||||||||||||||||||||||||||||||||||||||||
| 136 | ValueConv => '($val + 15) / 64', | ||||||||||||||||||||||||||||||||||||||||||
| 137 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | # GIF Netscape 2.0 animation extension (ref 3) | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 6 | %Image::ExifTool::GIF::Animation = ( | |||||||||||||||||||||||||||||||||||||||||
| 142 | PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | GROUPS => { 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | NOTES => 'Information extracted from the "NETSCAPE2.0" animation extension.', | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 => { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | Name => 'AnimationIterations', | ||||||||||||||||||||||||||||||||||||||||||
| 147 | Format => 'int16u', | ||||||||||||||||||||||||||||||||||||||||||
| 148 | PrintConv => '$val ? $val : "Infinite"', | ||||||||||||||||||||||||||||||||||||||||||
| 149 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | # GIF MIDICTRL extension (ref 5) | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 6 | %Image::ExifTool::GIF::MIDIControl = ( | |||||||||||||||||||||||||||||||||||||||||
| 154 | PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData, | ||||||||||||||||||||||||||||||||||||||||||
| 155 | GROUPS => { 2 => 'Audio' }, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | NOTES => 'Information extracted from the MIDI control block extension.', | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 => 'MIDIControlVersion', | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 => 'SequenceNumber', | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 => 'MelodicPolyphony', | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 => 'PercussivePolyphony', | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 => { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | Name => 'ChannelUsage', | ||||||||||||||||||||||||||||||||||||||||||
| 163 | Format => 'int16u', | ||||||||||||||||||||||||||||||||||||||||||
| 164 | PrintConv => 'sprintf("0x%.4x", $val)', | ||||||||||||||||||||||||||||||||||||||||||
| 165 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 6 => { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | Name => 'DelayTime', | ||||||||||||||||||||||||||||||||||||||||||
| 168 | Format => 'int16u', | ||||||||||||||||||||||||||||||||||||||||||
| 169 | ValueConv => '$val / 100', | ||||||||||||||||||||||||||||||||||||||||||
| 170 | PrintConv => '$val . " s"', | ||||||||||||||||||||||||||||||||||||||||||
| 171 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 175 | # Read/write meta information in GIF image | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # Inputs: 0) ExifTool object reference, 1) Directory information ref | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # Returns: 1 on success, 0 if this wasn't a valid GIF file, or -1 if | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # an output file was specified and a write error occurred | ||||||||||||||||||||||||||||||||||||||||||
| 179 | sub ProcessGIF($$) | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ProcessGIF: called CC=181 SCAR=81.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 7 | my ($et, $dirInfo) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 7 | my $outfile = $$dirInfo{OutFile}; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 7 | my $raf = $$dirInfo{RAF}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 7 | my $verbose = $et->Options('Verbose'); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 7 | my $out = $et->Options('TextOut'); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 7 | my ($a, $s, $ch, $length, $buff); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 7 | my ($err, $newComment, $setComment, $nvComment, $newExt); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 7 | my ($addDirs, %doneDir); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 7 | my ($frameCount, $delayTime) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | # verify this is a valid GIF file | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | ▶ | return 0 unless $raf->Read($buff, 6) == 6 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$raf->Read($buff, 6) == 6 and $buff =~ /^GIF(8[79]a)$/ and $raf->Read($s, 7) == 7
$raf->Read($buff, 6) == 6 and $buff =~ /^GIF(8[79]a)$/
MC/DC0%0/3
$raf->Read($buff, 6) == 6 and $buff =~ /^GIF(8[79]a)$/ and $raf->Read($s, 7) == 7
$raf->Read($buff, 6) == 6
$buff =~ /^GIF(8[79]a)$/
$raf->Read($s, 7) == 7
Truth table25%1/4
A and B and C
A= $raf->Read($buff, 6) == 6B= $buff =~ /^GIF(8[79]a)$/C= $raf->Read($s, 7) == 7
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | and $buff =~ /^GIF(8[79]a)$/ | ||||||||||||||||||||||||||||||||||||||||||
| 194 | and $raf->Read($s, 7) == 7; | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | my $ver = $1; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 7 | my $rtnVal = 0; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 7 | my $tagTablePtr = GetTagTable('Image::ExifTool::GIF::Main'); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 7 | my $extTable = GetTagTable('Image::ExifTool::GIF::Extensions'); | |||||||||||||||||||||||||||||||||||||||||
| 200 | 7 | SetByteOrder('II'); | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 7 | ▶ | if ($outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | # add any user-defined writable app extensions to the list | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | my $ext; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | foreach $ext (sort keys %$extTable) { | |||||||||||||||||||||||||||||||||||||||||
| 206 | 36 | ▶ | next unless ref $$extTable{$ext} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 21 | my $extInfo = $$extTable{$ext}; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 21 | ▶ | next unless $$extInfo{SubDirectory} and $$extInfo{Writable} and not $gifMap{$$extInfo{Name}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$extInfo->{"SubDirectory"} and $extInfo->{"Writable"} and not $gifMap{$extInfo->{"Name"}}
$extInfo->{"SubDirectory"} and $extInfo->{"Writable"}
MC/DC0%0/3
$extInfo->{"SubDirectory"} and $extInfo->{"Writable"} and not $gifMap{$extInfo->{"Name"}}
$extInfo->{"SubDirectory"}
$extInfo->{"Writable"}
not $gifMap{$extInfo->{"Name"}}
Truth table75%3/4
A and B and not(C)
A= $extInfo->{"SubDirectory"}B= $extInfo->{"Writable"}C= not $gifMap{$extInfo->{"Name"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $gifMap{$$extInfo{Name}} = 'GIF'; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | push @appExtensions, $ext; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 3 | $et->InitWriteDirs(\%gifMap, 'XMP'); # make XMP the preferred group for GIF | |||||||||||||||||||||||||||||||||||||||||
| 213 | 3 | $addDirs = $$et{ADD_DIRS}; | |||||||||||||||||||||||||||||||||||||||||
| 214 | # determine if we are editing the File:Comment tag | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 3 | my $delGroup = $$et{DEL_GROUP}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | $newComment = $et->GetNewValue('Comment', \$nvComment); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 3 | ▶ | $setComment = 1 if $nvComment or $$delGroup{File}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$nvComment or $delGroup->{"File"}
MC/DC0%0/2
$nvComment or $delGroup->{"File"}
$nvComment
$delGroup->{"File"}
Truth table33%1/3
A or B
A= $nvCommentB= $delGroup->{"File"}
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | # change to GIF 89a if adding comment, XMP or ICC_Profile | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 3 | ▶ | $buff = 'GIF89a' if %$addDirs or defined $newComment; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
%$addDirs or defined $newComment
MC/DC0%0/2
%$addDirs or defined $newComment
%$addDirs
defined $newComment
Truth table33%1/3
A or B
A= %$addDirsB= defined $newComment
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | ▶ | Write($outfile, $buff, $s) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | $newExt = $et->GetNewTagInfoHash($extTable); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 4 | $et->SetFileType(); # set file type | |||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | $et->HandleTag($tagTablePtr, 'GIFVersion', $ver); | |||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | $et->HandleTag($tagTablePtr, 'ScreenDescriptor', $s); | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 7 | my $flags = Get8u(\$s, 4); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 7 | ▶ | if ($flags & 0x80) { # does this image contain a color table? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | # calculate color table size | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 7 | $length = 3 * (2 << ($flags & 0x07)); | |||||||||||||||||||||||||||||||||||||||||
| 231 | 7 | ▶ | $raf->Read($buff, $length) == $length or return 0; # skip color table | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 7 | ▶ | Write($outfile, $buff) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$outfile && (&Write($outfile, $buff) || ($err = 1))
&Write($outfile, $buff) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $buff) || ($err = 1))
$outfile
&Write($outfile, $buff)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $buff)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | # | ||||||||||||||||||||||||||||||||||||||||||
| 235 | # loop through GIF blocks | ||||||||||||||||||||||||||||||||||||||||||
| 236 | # | ||||||||||||||||||||||||||||||||||||||||||
| 237 | Block: | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 7 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 239 | 33 | ▶ | last unless $raf->Read($ch, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | # write out any new metadata now if this isn't an extension block | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 33 | ▶ | if ($outfile and ord($ch) != 0x21) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$outfile and ord $ch != 33
MC/DC100%2/2
$outfile and ord $ch != 33
$outfile
ord $ch != 33
Truth table100%3/3
A and B
A= $outfileB= ord $ch != 33
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | # write the comment first if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 6 | ▶ | if (defined $newComment and $$nvComment{IsCreating}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $newComment and $nvComment->{"IsCreating"}
MC/DC0%0/2
defined $newComment and $nvComment->{"IsCreating"}
defined $newComment
$nvComment->{"IsCreating"}
Truth table33%1/3
A and B
A= defined $newCommentB= $nvComment->{"IsCreating"}
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | # write comment marker | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | Write($outfile, "\x21\xfe") or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | $verbose and print $out " + Comment = $newComment\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $len = length($newComment); | |||||||||||||||||||||||||||||||||||||||||
| 248 | # write out the comment in 255-byte chunks, each | ||||||||||||||||||||||||||||||||||||||||||
| 249 | # chunk beginning with a length byte | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $n; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | for ($n=0; $n<$len; $n+=255) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $size = $len - $n; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $size > 255 and $size = 255; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my $str = substr($newComment,$n,$size); | |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | Write($outfile, pack('C',$size), $str) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | Write($outfile, "\0") or $err = 1; # empty chunk as terminator | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | undef $newComment; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | undef $nvComment; # delete any other extraneous comments | |||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ++$$et{CHANGED}; # increment file changed flag | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # add application extensions if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | my $ext; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 6 | my @new = sort keys %$newExt; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 6 | foreach $ext (@appExtensions, @new) { | |||||||||||||||||||||||||||||||||||||||||
| 266 | 13 | my $extInfo = $$extTable{$ext}; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 13 | my $name = $$extInfo{Name}; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 13 | ▶ | if ($$newExt{$ext}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | delete $$newExt{$ext}; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | $doneDir{$name} = 1; # (we wrote this as a block instead) | |||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | $buff = $et->GetNewValue($extInfo); | |||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | $et->VerboseValue("+ GIF:$name", $buff); | |||||||||||||||||||||||||||||||||||||||||
| 273 | ▶ | } elsif (exists $$addDirs{$name} and not defined $doneDir{$name}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
exists $addDirs->{$name} and not defined $doneDir{$name}
MC/DC0%0/2
exists $addDirs->{$name} and not defined $doneDir{$name}
exists $addDirs->{$name}
not defined $doneDir{$name}
Truth table66%2/3
A and not(B)
A= exists $addDirs->{$name}B= not defined $doneDir{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $doneDir{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $tbl = GetTagTable($$extInfo{SubDirectory}{TagTable}); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my %dirInfo = ( Parent => 'GIF' ); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | $verbose and print $out "Creating $name application extension block:\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $buff = $et->WriteDirectory(\%dirInfo, $tbl); | |||||||||||||||||||||||||||||||||||||||||
| 279 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 12 | next; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | if (defined $buff and length $buff) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $buff and length $buff
MC/DC0%0/2
defined $buff and length $buff
defined $buff
length $buff
Truth table33%1/3
A and B
A= defined $buffB= length $buff
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 1 | ++$$et{CHANGED}; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | ▶ | Write($outfile, "\x21\xff\x0b", substr($ext,0,8), substr($ext,9,3)) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | ▶ | if (not $$extTable{$ext}{IncludeLengthBytes}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | my $len = length $buff; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | ▶ | while ($pos < length $buff) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | my $n = length($buff) - $pos; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | ▶ | $n = 255 if $n > 255; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 2 | ▶ | Write($outfile, chr($n), substr($buff, $pos, $n)) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | $pos += $n; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | ▶ | Write($outfile, "\0") or $err = 1; # write null terminator | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | } elsif ($$extTable{$ext}{IncludeLengthBytes} < 2) { | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | $pos += ord(substr($buff,$pos,1)) + 1 while $pos < length $buff; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | # write data, null padding and terminator | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | Write($outfile, $buff, "\0" x ($pos - length($buff) + 1)) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # write data, landing zone and null terminator | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | Write($outfile, $buff, pack('C*',1,reverse(0..255),0)) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | ++$doneDir{$name}; # set to 2 to indicate we added it | |||||||||||||||||||||||||||||||||||||||||
| 304 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | $verbose and print $out " -> no $name to add\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 33 | ▶ | if (ord($ch) == 0x2c) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 7 | ++$frameCount; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 7 | ▶ | Write($outfile, $ch) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$outfile && (&Write($outfile, $ch) || ($err = 1))
&Write($outfile, $ch) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $ch) || ($err = 1))
$outfile
&Write($outfile, $ch)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $ch)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | # image descriptor | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 7 | ▶ | last unless $raf->Read($buff, 8) == 8 and $raf->Read($ch, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$raf->Read($buff, 8) == 8 and $raf->Read($ch, 1)
MC/DC0%0/2
$raf->Read($buff, 8) == 8 and $raf->Read($ch, 1)
$raf->Read($buff, 8) == 8
$raf->Read($ch, 1)
Truth table33%1/3
A and B
A= $raf->Read($buff, 8) == 8B= $raf->Read($ch, 1)
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 7 | ▶ | Write($outfile, $buff, $ch) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$outfile && (&Write($outfile, $buff, $ch) || ($err = 1))
&Write($outfile, $buff, $ch) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $buff, $ch) || ($err = 1))
$outfile
&Write($outfile, $buff, $ch)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $buff, $ch)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 7 | ▶ | if ($verbose and not $outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$verbose and not $outfile
MC/DC0%0/2
$verbose and not $outfile
$verbose
not $outfile
Truth table33%1/3
A and not(B)
A= $verboseB= not $outfile
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my ($left, $top, $w, $h) = unpack('v*', $buff); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | print $out "Image: left=$left top=$top width=$w height=$h\n"; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 7 | ▶ | if (ord($ch) & 0x80) { # does color table exist? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $length = 3 * (2 << (ord($ch) & 0x07)); | |||||||||||||||||||||||||||||||||||||||||
| 321 | # skip the color table | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | last unless $raf->Read($buff, $length) == $length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | Write($outfile, $buff) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$outfile && (&Write($outfile, $buff) || ($err = 1))
&Write($outfile, $buff) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $buff) || ($err = 1))
$outfile
&Write($outfile, $buff)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $buff)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # skip "LZW Minimum Code Size" byte | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 7 | ▶ | last unless $raf->Read($buff, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 7 | ▶ | Write($outfile,$buff) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$outfile && (&Write($outfile, $buff) || ($err = 1))
&Write($outfile, $buff) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $buff) || ($err = 1))
$outfile
&Write($outfile, $buff)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $buff)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | # skip image blocks | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 7 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 330 | 14 | ▶ | last unless $raf->Read($ch, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 14 | ▶ | Write($outfile, $ch) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$outfile && (&Write($outfile, $ch) || ($err = 1))
&Write($outfile, $ch) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $ch) || ($err = 1))
$outfile
&Write($outfile, $ch)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $ch)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 14 | ▶ | last unless ord($ch); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 7 | ▶ | last unless $raf->Read($buff, ord($ch)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 7 | ▶ | Write($outfile,$buff) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$outfile && (&Write($outfile, $buff) || ($err = 1))
&Write($outfile, $buff) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $buff) || ($err = 1))
$outfile
&Write($outfile, $buff)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $buff)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 7 | next; # continue with next field | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | # last if ord($ch) == 0x3b; # normal end of GIF marker | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 26 | ▶ | unless (ord($ch) == 0x21) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 7 | ▶ | if ($outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 3 | ▶ | Write($outfile, $ch) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | # copy the rest of the file | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 3 | ▶ | while ($raf->Read($buff, 65536)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | Write($outfile, $buff) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 7 | $rtnVal = 1; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 7 | last; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | # get extension block type/size | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 19 | ▶ | last unless $raf->Read($s, 2) == 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | # get marker and block size | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 19 | ($a,$length) = unpack("C"x2, $s); | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 19 | ▶ | if ($a == 0xfe) { # comment extension | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 7 | my $comment = ''; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 7 | ▶ | while ($length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 10 | ▶ | last unless $raf->Read($buff, $length) == $length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 10 | ▶ | $et->VerboseDump(\$buff) unless $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | # add buffer to comment string | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 10 | $comment .= $buff; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 10 | ▶ | last unless $raf->Read($ch, 1); # read next block header | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 10 | $length = ord($ch); # get next block size | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 7 | ▶ | last if $length; # was a read error if length isn't zero | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 7 | ▶ | if ($outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 3 | my $isOverwriting; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 3 | ▶ | if ($setComment) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 3 | ▶ | if ($nvComment) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 3 | $isOverwriting = $et->IsOverwriting($nvComment,$comment); | |||||||||||||||||||||||||||||||||||||||||
| 372 | # get new comment again (may have been shifted) | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 3 | ▶ | $newComment = $et->GetNewValue($nvComment) if defined $newComment; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 375 | # group delete, or deleting additional comments after writing one | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $isOverwriting = 1; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 3 | ▶ | if ($isOverwriting) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 3 | ++$$et{CHANGED}; # increment file changed flag | |||||||||||||||||||||||||||||||||||||||||
| 381 | 3 | $et->VerboseValue('- GIF:Comment', $comment); | |||||||||||||||||||||||||||||||||||||||||
| 382 | 3 | $comment = $newComment; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 3 | ▶ | $et->VerboseValue('+ GIF:Comment', $comment) if defined $comment; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 3 | undef $nvComment; # just delete remaining comments | |||||||||||||||||||||||||||||||||||||||||
| 385 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | undef $setComment; # leave remaining comments alone | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 3 | ▶ | if (defined $comment) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | # write comment marker | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 3 | ▶ | Write($outfile, "\x21\xfe") or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 3 | my $len = length($comment); | |||||||||||||||||||||||||||||||||||||||||
| 392 | # write out the comment in 255-byte chunks, each | ||||||||||||||||||||||||||||||||||||||||||
| 393 | # chunk beginning with a length byte | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 3 | my $n; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | ▶ | for ($n=0; $n<$len; $n+=255) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 4 | my $size = $len - $n; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 4 | ▶ | $size > 255 and $size = 255; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 4 | my $str = substr($comment,$n,$size); | |||||||||||||||||||||||||||||||||||||||||
| 399 | 4 | ▶ | Write($outfile, pack('C',$size), $str) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 3 | ▶ | Write($outfile, "\0") or $err = 1; # empty chunk as terminator | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 3 | undef $newComment; # don't write the new comment again | |||||||||||||||||||||||||||||||||||||||||
| 404 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 4 | $rtnVal = 1; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 4 | ▶ | $et->FoundTag('Comment', $comment) if $comment; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 4 | undef $comment; | |||||||||||||||||||||||||||||||||||||||||
| 408 | # assume no more than one comment in FastScan mode | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 4 | ▶ | last if $et->Options('FastScan'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 7 | next; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | ▶ | } elsif ($a == 0xff and $length == 0x0b) { # application extension | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$a == 255 and $length == 11
MC/DC0%0/2
$a == 255 and $length == 11
$a == 255
$length == 11
Truth table33%1/3
A and B
A= $a == 255B= $length == 11
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 12 | ▶ | last unless $raf->Read($buff, $length) == $length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 12 | my $hdr = "$ch$s$buff"; | |||||||||||||||||||||||||||||||||||||||||
| 417 | # add "/" for readability | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 12 | my $tag = substr($buff, 0, 8) . '/' . substr($buff, 8); | |||||||||||||||||||||||||||||||||||||||||
| 419 | 12 | $tag =~ tr/\0-\x1f//d; # remove nulls and control characters | |||||||||||||||||||||||||||||||||||||||||
| 420 | 12 | ▶ | $verbose and print $out "Application Extension: $tag\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 12 | my $extInfo = $$extTable{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 12 | my ($subdir, $inclLen, $justCopy, $name); | |||||||||||||||||||||||||||||||||||||||||
| 424 | 12 | ▶ | if ($extInfo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 12 | ▶ | if ($outfile and $$newExt{$$extInfo{TagID}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$outfile and $$newExt{$extInfo->{"TagID"}}
MC/DC100%2/2
$outfile and $$newExt{$extInfo->{"TagID"}}
$outfile
$$newExt{$extInfo->{"TagID"}}
Truth table100%3/3
A and B
A= $outfileB= $$newExt{$extInfo->{"TagID"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | delete $$newExt{$$extInfo{TagID}}; # don't create again | |||||||||||||||||||||||||||||||||||||||||
| 427 | # (write as a block -- don't define $subdir) | ||||||||||||||||||||||||||||||||||||||||||
| 428 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 11 | $subdir = $$extInfo{SubDirectory}; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 12 | $inclLen = $$extInfo{IncludeLengthBytes}; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 12 | $name = $$extInfo{Name}; | |||||||||||||||||||||||||||||||||||||||||
| 433 | # rewrite as-is unless this is a writable | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 12 | ▶ | $justCopy = 1 if $outfile and not $$extInfo{Writable}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$outfile and not $extInfo->{"Writable"}
MC/DC0%0/2
$outfile and not $extInfo->{"Writable"}
$outfile
not $extInfo->{"Writable"}
Truth table66%2/3
A and not(B)
A= $outfileB= not $extInfo->{"Writable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | $justCopy = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 12 | ▶ | Write($outfile, $hdr) or $err = 1 if $justCopy; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$justCopy && (&Write($outfile, $hdr) || ($err = 1))
&Write($outfile, $hdr) or $err = 1
MC/DC0%0/3
$justCopy && (&Write($outfile, $hdr) || ($err = 1))
$justCopy
&Write($outfile, $hdr)
$err = 1
Truth table0%0/4
A && B or C
A= $justCopyB= &Write($outfile, $hdr)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | # read the extension data | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 12 | my $dat = ''; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 12 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 443 | 378 | ▶ | $raf->Read($ch, 1) or last Block; # read next block header | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 378 | ▶ | $length = ord($ch) or last; # get next block size | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 366 | ▶ | $raf->Read($buff, $length) == $length or last Block; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 366 | ▶ | Write($outfile, $ch, $buff) or $err = 1 if $justCopy; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$justCopy && (&Write($outfile, $ch, $buff) || ($err = 1))
&Write($outfile, $ch, $buff) or $err = 1
MC/DC0%0/3
$justCopy && (&Write($outfile, $ch, $buff) || ($err = 1))
$justCopy
&Write($outfile, $ch, $buff)
$err = 1
Truth table0%0/4
A && B or C
A= $justCopyB= &Write($outfile, $ch, $buff)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 366 | ▶ | $dat .= $inclLen ? $ch . $buff : $buff; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 12 | ▶ | if ($justCopy) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | Write($outfile, "\0") or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 452 | } elsif ($inclLen) { | ||||||||||||||||||||||||||||||||||||||||||
| 453 | # remove landing zone or padding | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 7 | ▶ | if ($$extInfo{Terminator} and $dat =~ /$$extInfo{Terminator}/g) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$extInfo->{"Terminator"} and $dat =~ /$extInfo->{"Terminator"}/g
MC/DC0%0/2
$extInfo->{"Terminator"} and $dat =~ /$extInfo->{"Terminator"}/g
$extInfo->{"Terminator"}
$dat =~ /$extInfo->{"Terminator"}/g
Truth table33%1/3
A and B
A= $extInfo->{"Terminator"}B= $dat =~ /$extInfo->{"Terminator"}/g
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 7 | $dat = substr($dat, 0, pos($dat)); | |||||||||||||||||||||||||||||||||||||||||
| 456 | } elsif ($dat =~ /\0/g) { | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $dat = substr($dat, 0, pos($dat) - 1); | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 12 | ▶ | if ($subdir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 11 | my %dirInfo = ( | |||||||||||||||||||||||||||||||||||||||||
| 462 | DataPt => \$dat, | ||||||||||||||||||||||||||||||||||||||||||
| 463 | DataLen => length $dat, | ||||||||||||||||||||||||||||||||||||||||||
| 464 | DirLen => length $dat, | ||||||||||||||||||||||||||||||||||||||||||
| 465 | DirName => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 466 | Parent => 'GIF', | ||||||||||||||||||||||||||||||||||||||||||
| 467 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 11 | my $subTable = GetTagTable($$subdir{TagTable}); | |||||||||||||||||||||||||||||||||||||||||
| 469 | 11 | ▶ | unless ($outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 7 | $et->ProcessDirectory(\%dirInfo, $subTable); | |||||||||||||||||||||||||||||||||||||||||
| 471 | 7 | next; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 4 | ▶ | next if $justCopy; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 4 | ▶ | if ($doneDir{$name} and $doneDir{$name} > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$doneDir{$name} and $doneDir{$name} > 1
MC/DC0%0/2
$doneDir{$name} and $doneDir{$name} > 1
$doneDir{$name}
$doneDir{$name} > 1
Truth table33%1/3
A and B
A= $doneDir{$name}B= $doneDir{$name} > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $et->Warn("Duplicate $name block created"); | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | 4 | $buff = $et->WriteDirectory(\%dirInfo, $subTable); | |||||||||||||||||||||||||||||||||||||||||
| 478 | 4 | ▶ | if (defined $buff) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 3 | ▶ | next unless length $buff; # delete this extension if length is zero | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 2 | $dat = $buff; | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 3 | $doneDir{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 483 | ▶ | } elsif ($outfile and not $justCopy) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$outfile and not $justCopy
MC/DC0%0/2
$outfile and not $justCopy
$outfile
not $justCopy
Truth table33%1/3
A and not(B)
A= $outfileB= not $justCopy
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 1 | my $nvHash = $et->GetNewValueHash($extInfo); | |||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | ▶ | if ($nvHash and $et->IsOverwriting($nvHash, $dat)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$nvHash and $et->IsOverwriting($nvHash, $dat)
MC/DC0%0/2
$nvHash and $et->IsOverwriting($nvHash, $dat)
$nvHash
$et->IsOverwriting($nvHash, $dat)
Truth table33%1/3
A and B
A= $nvHashB= $et->IsOverwriting($nvHash, $dat)
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | ++$$et{CHANGED}; | |||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | my $val = $et->GetNewValue($extInfo); | |||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | $et->VerboseValue("- GIF:$name", $dat); | |||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | ▶ | next unless defined $val and length $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $val and length $val
MC/DC0%0/2
defined $val and length $val
defined $val
length $val
Truth table33%1/3
A and B
A= defined $valB= length $val
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | $dat = $val; | |||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | $et->VerboseValue("+ GIF:$name", $dat); | |||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | $doneDir{$name} = 1; # (possibly wrote dir as a block) | |||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||
| 494 | } elsif (not $outfile) { | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | $et->HandleTag($extTable, $tag, $dat); | |||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 4 | ▶ | Write($outfile, $hdr) or $err = 1; # write extension header | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 4 | ▶ | if ($inclLen) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | # check for null just to be safe | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 3 | ▶ | $et->Error("$name contained NULL character") if $inclLen and $dat =~ /\0/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$inclLen and $dat =~ /\0/
MC/DC0%0/2
$inclLen and $dat =~ /\0/
$inclLen
$dat =~ /\0/
Truth table33%1/3
A and B
A= $inclLenB= $dat =~ /\0/
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 3 | ▶ | if ($inclLen > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | # add landing zone (without terminator, which will be added later) | ||||||||||||||||||||||||||||||||||||||||||
| 504 | 3 | ▶ | $dat .= pack('C*',1,reverse(0..255)) if $inclLen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 506 | # pad with nulls as required | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | ▶ | $pos += ord(substr($dat,$pos,1)) + 1 while $pos < length $dat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | $dat .= "\0" x ($pos - length($dat)); | |||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 511 | # write data and landing zone | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 3 | ▶ | Write($outfile, $dat) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # write as sub-blocks | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | my $len = length $dat; | |||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | ▶ | while ($pos < $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 2 | my $n = $len - $pos; | |||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | ▶ | $n = 255 if $n > 255; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 2 | ▶ | Write($outfile, chr($n), substr($dat, $pos, $n)) or $err = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 2 | $pos += $n; | |||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 4 | ▶ | Write($outfile, "\0") or $err = 1; # write null terminator | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | ▶ | } elsif ($a == 0xf9 and $length == 4) { # graphic control extension | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$a == 249 and $length == 4
MC/DC0%0/2
$a == 249 and $length == 4
$a == 249
$length == 4
Truth table0%0/3
A and B
A= $a == 249B= $length == 4
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | last unless $raf->Read($buff, $length) == $length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | # sum the individual delay times | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | my $delay = Get16u(\$buff, 1); | |||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $delayTime += $delay; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | $verbose and printf $out "Graphic Control: delay=%.2f\n", $delay / 100; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | # get transparent colour | ||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my $bits = Get8u(\$buff, 0); | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | $et->HandleTag($tagTablePtr, 'TransparentColor', Get8u(\$buff,3)) if $bits & 0x01; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | $raf->Seek(-$length, 1) or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | ▶ | } elsif ($a == 0x01 and $length == 12) { # plain text extension | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$a == 1 and $length == 12
MC/DC0%0/2
$a == 1 and $length == 12
$a == 1
$length == 12
Truth table0%0/3
A and B
A= $a == 1B= $length == 12
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | last unless $raf->Read($buff, $length) == $length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | Write($outfile, $ch, $s, $buff) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$outfile && (&Write($outfile, $ch, $s, $buff) || ($err = 1))
&Write($outfile, $ch, $s, $buff) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $ch, $s, $buff) || ($err = 1))
$outfile
&Write($outfile, $ch, $s, $buff)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $ch, $s, $buff)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | if ($verbose and not $outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$verbose and not $outfile
MC/DC0%0/2
$verbose and not $outfile
$verbose
not $outfile
Truth table0%0/3
A and not(B)
A= $verboseB= not $outfile
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | my ($left, $top, $w, $h) = unpack('v4', $buff); | |||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | print $out "Text: left=$left top=$top width=$w height=$h\n"; | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | my $text = ''; | |||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | last unless $raf->Read($ch, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | ▶ | $length = ord($ch) or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | last unless $raf->Read($buff, $length) == $length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | Write($outfile, $ch, $buff) or $err = 1 if $outfile; # write block | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$outfile && (&Write($outfile, $ch, $buff) || ($err = 1))
&Write($outfile, $ch, $buff) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $ch, $buff) || ($err = 1))
$outfile
&Write($outfile, $ch, $buff)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $ch, $buff)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | $text .= $buff; | |||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | Write($outfile, "\0") or $err = 1 if $outfile; # write terminator block | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$outfile && (&Write($outfile, "\000") || ($err = 1))
&Write($outfile, "\0") or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, "\000") || ($err = 1))
$outfile
&Write($outfile, "\0")
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, "\0")C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $et->HandleTag($tagTablePtr, 'Text', $text); | |||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | Write($outfile, $ch, $s) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$outfile && (&Write($outfile, $ch, $s) || ($err = 1))
&Write($outfile, $ch, $s) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $ch, $s) || ($err = 1))
$outfile
&Write($outfile, $ch, $s)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $ch, $s)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | # skip the block | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | while ($length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | last unless $raf->Read($buff, $length) == $length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | Write($outfile, $buff) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$outfile && (&Write($outfile, $buff) || ($err = 1))
&Write($outfile, $buff) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $buff) || ($err = 1))
$outfile
&Write($outfile, $buff)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $buff)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | last unless $raf->Read($ch, 1); # read next block header | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | Write($outfile, $ch) or $err = 1 if $outfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$outfile && (&Write($outfile, $ch) || ($err = 1))
&Write($outfile, $ch) or $err = 1
MC/DC0%0/3
$outfile && (&Write($outfile, $ch) || ($err = 1))
$outfile
&Write($outfile, $ch)
$err = 1
Truth table0%0/4
A && B or C
A= $outfileB= &Write($outfile, $ch)C= $err = 1
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $length = ord($ch); # get next block size | |||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 7 | ▶ | unless ($outfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 4 | ▶ | $et->HandleTag($tagTablePtr, 'FrameCount', $frameCount) if $frameCount > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | 4 | ▶ | $et->HandleTag($tagTablePtr, 'Duration', $delayTime/100) if $delayTime; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | # set return value to -1 if we only had a write error | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 7 | ▶ | $rtnVal = -1 if $rtnVal and $err; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rtnVal and $err
MC/DC0%0/2
$rtnVal and $err
$rtnVal
$err
Truth table33%1/3
A and B
A= $rtnValB= $err
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 7 | return $rtnVal; | |||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 6 | 1; #end | |||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | __END__ | ||||||||||||||||||||||||||||||||||||||||||