| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 2 |  |  |  |  |  |  | # File:         FLIF.pm | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | # Description:  Read/write FLIF meta information | 
| 5 |  |  |  |  |  |  | # | 
| 6 |  |  |  |  |  |  | # Revisions:    2016/10/11 - P. Harvey Created | 
| 7 |  |  |  |  |  |  | #               2016/10/14 - PH Added write support | 
| 8 |  |  |  |  |  |  | # | 
| 9 |  |  |  |  |  |  | # References:   1) http://flif.info/ | 
| 10 |  |  |  |  |  |  | #               2) https://github.com/FLIF-hub/FLIF/blob/master/doc/metadata | 
| 11 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | package Image::ExifTool::FLIF; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 1 |  |  | 1 |  | 4776 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 16 | 1 |  |  | 1 |  | 5 | use vars qw($VERSION); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 40 |  | 
| 17 | 1 |  |  | 1 |  | 11 | use Image::ExifTool qw(:DataAccess :Utils); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 1813 |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | $VERSION = '1.02'; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | my %flifMap = ( | 
| 22 |  |  |  |  |  |  | EXIF         => 'FLIF', | 
| 23 |  |  |  |  |  |  | XMP          => 'FLIF', | 
| 24 |  |  |  |  |  |  | ICC_Profile  => 'FLIF', | 
| 25 |  |  |  |  |  |  | IFD0         => 'EXIF', | 
| 26 |  |  |  |  |  |  | IFD1         => 'IFD0', | 
| 27 |  |  |  |  |  |  | ExifIFD      => 'IFD0', | 
| 28 |  |  |  |  |  |  | GPS          => 'IFD0', | 
| 29 |  |  |  |  |  |  | SubIFD       => 'IFD0', | 
| 30 |  |  |  |  |  |  | GlobParamIFD => 'IFD0', | 
| 31 |  |  |  |  |  |  | PrintIM      => 'IFD0', | 
| 32 |  |  |  |  |  |  | InteropIFD   => 'ExifIFD', | 
| 33 |  |  |  |  |  |  | MakerNotes   => 'ExifIFD', | 
| 34 |  |  |  |  |  |  | ); | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # FLIF tags | 
| 37 |  |  |  |  |  |  | %Image::ExifTool::FLIF::Main = ( | 
| 38 |  |  |  |  |  |  | GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' }, | 
| 39 |  |  |  |  |  |  | VARS => { HEX_ID => 0 }, | 
| 40 |  |  |  |  |  |  | NOTES => q{ | 
| 41 |  |  |  |  |  |  | Information extracted from Free Lossless Image Format files.  See | 
| 42 |  |  |  |  |  |  | L for more information. | 
| 43 |  |  |  |  |  |  | }, | 
| 44 |  |  |  |  |  |  | # | 
| 45 |  |  |  |  |  |  | # header information | 
| 46 |  |  |  |  |  |  | # | 
| 47 |  |  |  |  |  |  | 0 => { | 
| 48 |  |  |  |  |  |  | Name => 'ImageType', | 
| 49 |  |  |  |  |  |  | PrintConv => { | 
| 50 |  |  |  |  |  |  | '1' => 'Grayscale (non-interlaced)', | 
| 51 |  |  |  |  |  |  | '3' => 'RGB (non-interlaced)', | 
| 52 |  |  |  |  |  |  | '4' => 'RGBA (non-interlaced)', | 
| 53 |  |  |  |  |  |  | 'A' => 'Grayscale (interlaced)', | 
| 54 |  |  |  |  |  |  | 'C' => 'RGB (interlaced)', | 
| 55 |  |  |  |  |  |  | 'D' => 'RGBA (interlaced)', | 
| 56 |  |  |  |  |  |  | 'Q' => 'Grayscale Animation (non-interlaced)', | 
| 57 |  |  |  |  |  |  | 'S' => 'RGB Animation (non-interlaced)', | 
| 58 |  |  |  |  |  |  | 'T' => 'RGBA Animation (non-interlaced)', | 
| 59 |  |  |  |  |  |  | 'a' => 'Grayscale Animation (interlaced)', | 
| 60 |  |  |  |  |  |  | 'c' => 'RGB Animation (interlaced)', | 
| 61 |  |  |  |  |  |  | 'd' => 'RGBA Animation (interlaced)', | 
| 62 |  |  |  |  |  |  | }, | 
| 63 |  |  |  |  |  |  | }, | 
| 64 |  |  |  |  |  |  | 1 => { | 
| 65 |  |  |  |  |  |  | Name => 'BitDepth', | 
| 66 |  |  |  |  |  |  | PrintConv => { | 
| 67 |  |  |  |  |  |  | '0' => 'Custom', | 
| 68 |  |  |  |  |  |  | '1' => 8, | 
| 69 |  |  |  |  |  |  | '2' => 16, | 
| 70 |  |  |  |  |  |  | }, | 
| 71 |  |  |  |  |  |  | }, | 
| 72 |  |  |  |  |  |  | 2 => 'ImageWidth', | 
| 73 |  |  |  |  |  |  | 3 => 'ImageHeight', | 
| 74 |  |  |  |  |  |  | 4 => 'AnimationFrames', | 
| 75 |  |  |  |  |  |  | 5 => { | 
| 76 |  |  |  |  |  |  | Name => 'Encoding', | 
| 77 |  |  |  |  |  |  | PrintConv => { | 
| 78 |  |  |  |  |  |  | 0 => 'FLIF16', | 
| 79 |  |  |  |  |  |  | }, | 
| 80 |  |  |  |  |  |  | }, | 
| 81 |  |  |  |  |  |  | # | 
| 82 |  |  |  |  |  |  | # metadata chunks | 
| 83 |  |  |  |  |  |  | # | 
| 84 |  |  |  |  |  |  | iCCP => { | 
| 85 |  |  |  |  |  |  | Name => 'ICC_Profile', | 
| 86 |  |  |  |  |  |  | SubDirectory => { | 
| 87 |  |  |  |  |  |  | TagTable => 'Image::ExifTool::ICC_Profile::Main', | 
| 88 |  |  |  |  |  |  | }, | 
| 89 |  |  |  |  |  |  | }, | 
| 90 |  |  |  |  |  |  | eXif => { | 
| 91 |  |  |  |  |  |  | Name => 'EXIF', | 
| 92 |  |  |  |  |  |  | SubDirectory => { | 
| 93 |  |  |  |  |  |  | TagTable => 'Image::ExifTool::Exif::Main', | 
| 94 |  |  |  |  |  |  | ProcessProc => \&Image::ExifTool::ProcessTIFF, | 
| 95 |  |  |  |  |  |  | WriteProc => \&Image::ExifTool::WriteTIFF, | 
| 96 |  |  |  |  |  |  | Start => 6, # (skip "Exif\0\0" header) | 
| 97 |  |  |  |  |  |  | Header => "Exif\0\0", | 
| 98 |  |  |  |  |  |  | }, | 
| 99 |  |  |  |  |  |  | }, | 
| 100 |  |  |  |  |  |  | eXmp => { | 
| 101 |  |  |  |  |  |  | Name => 'XMP', | 
| 102 |  |  |  |  |  |  | SubDirectory => { | 
| 103 |  |  |  |  |  |  | TagTable => 'Image::ExifTool::XMP::Main', | 
| 104 |  |  |  |  |  |  | }, | 
| 105 |  |  |  |  |  |  | }, | 
| 106 |  |  |  |  |  |  | # tRko - list of truncation offsets | 
| 107 |  |  |  |  |  |  | # \0 - FLIF16-format image data | 
| 108 |  |  |  |  |  |  | ); | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 111 |  |  |  |  |  |  | # Read variable-length FLIF integer | 
| 112 |  |  |  |  |  |  | # Inputs: 0) raf reference, 1) number to add to returned value | 
| 113 |  |  |  |  |  |  | # Returns: integer, or undef on EOF | 
| 114 |  |  |  |  |  |  | sub GetVarInt($;$) | 
| 115 |  |  |  |  |  |  | { | 
| 116 | 39 |  |  | 39 | 0 | 81 | my ($raf, $add) = @_; | 
| 117 | 39 |  |  |  |  | 65 | my ($val, $buff); | 
| 118 | 39 |  |  |  |  | 73 | for ($val=0; ; $val<<=7) { | 
| 119 | 53 | 50 |  |  |  | 129 | $raf->Read($buff, 1) or return undef; | 
| 120 | 53 |  |  |  |  | 98 | my $byte = ord($buff); | 
| 121 | 53 |  |  |  |  | 87 | $val |= ($byte & 0x7f); | 
| 122 | 53 | 100 |  |  |  | 164 | last unless $byte & 0x80; | 
| 123 |  |  |  |  |  |  | } | 
| 124 | 39 |  | 100 |  |  | 170 | return $val + ($add || 0); | 
| 125 |  |  |  |  |  |  | } | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 128 |  |  |  |  |  |  | # Construct variable-length FLIF integer | 
| 129 |  |  |  |  |  |  | # Inputs: 0) integer | 
| 130 |  |  |  |  |  |  | # Returns: FLIF variable-length integer byte stream | 
| 131 |  |  |  |  |  |  | sub SetVarInt($) | 
| 132 |  |  |  |  |  |  | { | 
| 133 | 9 |  |  | 9 | 0 | 22 | my $val = shift; | 
| 134 | 9 |  |  |  |  | 16 | my $buff = ''; | 
| 135 | 9 |  |  |  |  | 14 | my $high = 0; | 
| 136 | 9 |  |  |  |  | 16 | for (;;) { | 
| 137 | 15 |  |  |  |  | 50 | $buff = chr(($val & 0x7f) | $high) . $buff; | 
| 138 | 15 | 100 |  |  |  | 47 | last unless $val >>= 7; | 
| 139 | 6 |  |  |  |  | 11 | $high = 0x80; | 
| 140 |  |  |  |  |  |  | } | 
| 141 | 9 |  |  |  |  | 38 | return $buff; | 
| 142 |  |  |  |  |  |  | } | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 145 |  |  |  |  |  |  | # Read FLIF header | 
| 146 |  |  |  |  |  |  | # Inputs: 0) RAF ref | 
| 147 |  |  |  |  |  |  | # Returns: Scalar context: binary header block | 
| 148 |  |  |  |  |  |  | #          List context: header values (4 or 5 elements: type,depth,width,height[,frames]) | 
| 149 |  |  |  |  |  |  | #          or undef if this isn't a valid FLIF file header | 
| 150 |  |  |  |  |  |  | sub ReadFLIFHeader($) | 
| 151 |  |  |  |  |  |  | { | 
| 152 | 9 |  |  | 9 | 0 | 18 | my $raf = shift; | 
| 153 | 9 |  |  |  |  | 19 | my ($buff, @vals); | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | # verify this is a valid FLIF file | 
| 156 | 9 | 50 | 33 |  |  | 30 | return () unless $raf->Read($buff, 6) == 6 and $buff =~ /^FLIF([0-\x6f])([0-2])/; | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | # decode header information ("FLIF" chunk) | 
| 159 | 9 |  |  |  |  | 47 | push @vals, $1, $2;                                 # type, depth | 
| 160 | 9 |  |  |  |  | 38 | push @vals, GetVarInt($raf,+1), GetVarInt($raf,+1); # width, height (+1 each) | 
| 161 | 9 | 50 |  |  |  | 50 | push @vals, GetVarInt($raf,+2) if $vals[0] gt 'H';  # frames (+2) | 
| 162 |  |  |  |  |  |  |  | 
| 163 | 9 | 50 |  |  |  | 26 | return () unless defined $vals[-1]; | 
| 164 | 9 | 100 |  |  |  | 43 | return @vals if wantarray;      # return the decoded header values | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | # return the binary header block | 
| 167 | 4 |  |  |  |  | 13 | my $hdrLen = $raf->Tell(); | 
| 168 | 4 | 50 | 33 |  |  | 21 | return () unless $raf->Seek(0,0) and $raf->Read($buff, $hdrLen) == $hdrLen; | 
| 169 | 4 |  |  |  |  | 34 | return $buff; | 
| 170 |  |  |  |  |  |  | } | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 173 |  |  |  |  |  |  | # WriteFLIF : Write FLIF image | 
| 174 |  |  |  |  |  |  | # Inputs: 0) ExifTool object reference, 1) dirInfo reference | 
| 175 |  |  |  |  |  |  | # Returns: 1 on success, 0 if this wasn't a valid FLIF file, or -1 if | 
| 176 |  |  |  |  |  |  | #          an output file was specified and a write error occurred | 
| 177 |  |  |  |  |  |  | sub WriteFLIF($$) | 
| 178 |  |  |  |  |  |  | { | 
| 179 | 4 |  |  | 4 | 0 | 27 | my ($et, $dirInfo) = @_; | 
| 180 | 4 |  |  |  |  | 14 | my $raf = $$dirInfo{RAF}; | 
| 181 | 4 |  |  |  |  | 11 | my ($buff, $soi, @addTags, %doneTag); | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | # verify FLIF header and copy it to the output file | 
| 184 | 4 | 50 |  |  |  | 22 | $buff = ReadFLIFHeader($raf) or return 0; | 
| 185 | 4 |  |  |  |  | 13 | my $outfile = $$dirInfo{OutFile}; | 
| 186 | 4 | 50 |  |  |  | 20 | Write($outfile, $buff) or return -1; | 
| 187 |  |  |  |  |  |  |  | 
| 188 | 4 |  |  |  |  | 26 | $et->InitWriteDirs(\%flifMap); | 
| 189 | 4 |  |  |  |  | 22 | my $tagTablePtr = GetTagTable('Image::ExifTool::FLIF::Main'); | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | # loop through the FLIF chunks | 
| 192 | 4 |  |  |  |  | 18 | for (;;) { | 
| 193 | 16 |  |  |  |  | 36 | my ($tag, $size, $inflated); | 
| 194 |  |  |  |  |  |  | # read new tag (or soi) unless we already hit the soi (start of image) | 
| 195 | 16 | 100 |  |  |  | 37 | if (not defined $soi) { | 
| 196 | 13 | 50 |  |  |  | 54 | $raf->Read($buff, 4) == 4 or $et->Error('Unexpected EOF'), last; | 
| 197 | 13 | 100 |  |  |  | 48 | if ($buff lt ' ') { | 
| 198 | 4 |  |  |  |  | 19 | $soi = $buff;   # we have hit the start of image (no more metadata) | 
| 199 |  |  |  |  |  |  | # make list of new tags to add | 
| 200 | 4 |  |  |  |  | 14 | foreach $tag ('eXif', 'eXmp', 'iCCP') { | 
| 201 | 12 | 100 | 100 |  |  | 123 | push @addTags, $tag if $$et{ADD_DIRS}{$$tagTablePtr{$tag}{Name}} and not $doneTag{$tag}; | 
| 202 |  |  |  |  |  |  | } | 
| 203 |  |  |  |  |  |  | } | 
| 204 |  |  |  |  |  |  | } | 
| 205 | 16 | 100 |  |  |  | 53 | if (not defined $soi) { | 
|  |  | 100 |  |  |  |  |  | 
| 206 | 9 |  |  |  |  | 16 | $tag = $buff; | 
| 207 | 9 |  |  |  |  | 22 | $size = GetVarInt($raf);    # read the data size | 
| 208 |  |  |  |  |  |  | } elsif (@addTags) { | 
| 209 | 3 |  |  |  |  | 7 | $tag = shift @addTags; | 
| 210 | 3 |  |  |  |  | 9 | ($buff, $size) = ('', 0);   # create metadata from scratch | 
| 211 |  |  |  |  |  |  | } else { | 
| 212 |  |  |  |  |  |  | # finish copying file (no more metadata to add) | 
| 213 | 4 | 50 |  |  |  | 17 | Write($outfile, $soi) or return -1; | 
| 214 | 4 |  | 50 |  |  | 55 | Write($outfile, $buff) or return -1 while $raf->Read($buff, 65536); | 
| 215 | 4 |  |  |  |  | 11 | last;   # all done! | 
| 216 |  |  |  |  |  |  | } | 
| 217 | 12 |  |  |  |  | 52 | my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag); | 
| 218 | 12 | 50 | 33 |  |  | 116 | if ($tagInfo and $$tagInfo{SubDirectory} and $$et{EDIT_DIRS}{$$tagInfo{Name}}) { | 
|  |  | 0 | 33 |  |  |  |  | 
| 219 | 12 |  |  |  |  | 32 | $doneTag{$tag} = 1;         # prevent adding this back again later | 
| 220 | 12 | 100 |  |  |  | 30 | unless (defined $soi) { | 
| 221 | 9 | 50 |  |  |  | 37 | $raf->Read($buff, $size) == $size or $et->Error("Truncated FLIF $tag chunk"), last; | 
| 222 |  |  |  |  |  |  | } | 
| 223 |  |  |  |  |  |  | # rewrite the compressed data | 
| 224 | 12 | 50 | 33 |  |  | 22 | if (eval { require IO::Uncompress::RawInflate } and eval { require IO::Compress::RawDeflate } ) { | 
|  | 12 |  |  |  |  | 104 |  | 
|  | 12 |  |  |  |  | 80 |  | 
| 225 | 12 | 100 |  |  |  | 54 | if (length $buff == 0) { | 
|  |  | 50 |  |  |  |  |  | 
| 226 | 3 |  |  |  |  | 7 | $inflated = $buff;  # (creating from scratch, so no need to inflate) | 
| 227 |  |  |  |  |  |  | } elsif (not IO::Uncompress::RawInflate::rawinflate(\$buff => \$inflated)) { | 
| 228 | 0 |  |  |  |  | 0 | $et->Error("Error inflating FLIF $tag chunk"), last; | 
| 229 |  |  |  |  |  |  | } | 
| 230 | 12 |  |  |  |  | 14581 | my $subdir = $$tagInfo{SubDirectory}; | 
| 231 |  |  |  |  |  |  | my %subdirInfo = ( | 
| 232 |  |  |  |  |  |  | DirName  => $$tagInfo{Name}, | 
| 233 |  |  |  |  |  |  | DataPt   => \$inflated, | 
| 234 |  |  |  |  |  |  | DirStart => length($inflated) ? $$subdir{Start} : undef, | 
| 235 | 12 | 100 |  |  |  | 103 | ReadOnly => 1,      # (used only by WriteXMP) | 
| 236 |  |  |  |  |  |  | ); | 
| 237 | 12 |  |  |  |  | 52 | my $subTable = GetTagTable($$subdir{TagTable}); | 
| 238 | 12 |  |  |  |  | 72 | $inflated = $et->WriteDirectory(\%subdirInfo, $subTable, $$subdir{WriteProc}); | 
| 239 | 12 | 50 |  |  |  | 38 | if (defined $inflated) { | 
| 240 | 12 | 100 |  |  |  | 33 | next unless length $inflated; # (delete directory if length is zero) | 
| 241 | 9 | 100 |  |  |  | 33 | $inflated = $$subdir{Header} . $inflated if $$subdir{Header}; # (add back header if necessary) | 
| 242 | 9 | 50 |  |  |  | 53 | unless (IO::Compress::RawDeflate::rawdeflate(\$inflated => \$buff)) { | 
| 243 | 0 |  |  |  |  | 0 | $et->Error("Error deflating FLIF $tag chunk"), last; | 
| 244 |  |  |  |  |  |  | } | 
| 245 |  |  |  |  |  |  | } | 
| 246 |  |  |  |  |  |  | } else { | 
| 247 | 0 |  |  |  |  | 0 | $et->WarnOnce('Install IO::Compress::RawDeflate to write FLIF metadata'); | 
| 248 |  |  |  |  |  |  | } | 
| 249 | 9 | 50 |  |  |  | 15666 | Write($outfile, $tag, SetVarInt(length $buff), $buff) or return -1; | 
| 250 |  |  |  |  |  |  | } elsif (not defined $soi) { | 
| 251 | 0 | 0 |  |  |  | 0 | Write($outfile, $tag, SetVarInt($size)) or return -1; | 
| 252 | 0 | 0 |  |  |  | 0 | Image::ExifTool::CopyBlock($raf, $outfile, $size) or return -1; | 
| 253 |  |  |  |  |  |  | } | 
| 254 |  |  |  |  |  |  | } | 
| 255 | 4 |  |  |  |  | 20 | return 1; | 
| 256 |  |  |  |  |  |  | } | 
| 257 |  |  |  |  |  |  |  | 
| 258 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 259 |  |  |  |  |  |  | # Extract information from an FLIF file | 
| 260 |  |  |  |  |  |  | # Inputs: 0) ExifTool object reference, 1) DirInfo reference | 
| 261 |  |  |  |  |  |  | # Returns: 1 on success, 0 if this wasn't a valid FLIF file | 
| 262 |  |  |  |  |  |  | sub ProcessFLIF($$) | 
| 263 |  |  |  |  |  |  | { | 
| 264 | 5 |  |  | 5 | 0 | 20 | my ($et, $dirInfo) = @_; | 
| 265 | 5 |  |  |  |  | 13 | my $raf = $$dirInfo{RAF}; | 
| 266 | 5 |  |  |  |  | 10 | my ($buff, $tag, $inflated); | 
| 267 |  |  |  |  |  |  |  | 
| 268 |  |  |  |  |  |  | # verify this is a valid FLIF file and read the header | 
| 269 | 5 | 50 |  |  |  | 17 | my @vals = ReadFLIFHeader($raf) or return 0; | 
| 270 |  |  |  |  |  |  |  | 
| 271 | 5 |  |  |  |  | 32 | $et->SetFileType(); | 
| 272 | 5 |  |  |  |  | 30 | my $tagTablePtr = GetTagTable('Image::ExifTool::FLIF::Main'); | 
| 273 | 5 |  |  |  |  | 28 | my $verbose = $et->Options('Verbose'); | 
| 274 |  |  |  |  |  |  |  | 
| 275 |  |  |  |  |  |  | # save the header information | 
| 276 | 5 | 50 |  |  |  | 27 | $et->VPrint(0, "FLIF header:\n") if $verbose; | 
| 277 | 5 |  |  |  |  | 24 | for ($tag=0; defined $vals[$tag]; ++$tag) { | 
| 278 | 20 |  |  |  |  | 52 | $et->HandleTag($tagTablePtr, $tag, $vals[$tag]); | 
| 279 |  |  |  |  |  |  | } | 
| 280 |  |  |  |  |  |  |  | 
| 281 |  |  |  |  |  |  | # loop through the FLIF chunks | 
| 282 | 5 |  |  |  |  | 16 | for (;;) { | 
| 283 | 17 | 50 |  |  |  | 81 | $raf->Read($tag, 4) == 4 or $et->Warn('Unexpected EOF'), last; | 
| 284 | 17 |  |  |  |  | 50 | my $byte = ord substr($tag, 0, 1); | 
| 285 |  |  |  |  |  |  | # all done if we arrived at the image chunk | 
| 286 | 17 | 100 |  |  |  | 52 | $byte < 32 and $et->HandleTag($tagTablePtr, 5, $byte), last; | 
| 287 | 12 |  |  |  |  | 33 | my $size = GetVarInt($raf); | 
| 288 | 12 | 50 |  |  |  | 47 | $et->VPrint(0, "FLIF $tag ($size bytes):\n") if $verbose; | 
| 289 | 12 | 50 |  |  |  | 32 | if ($$tagTablePtr{$tag}) { | 
| 290 | 12 | 50 |  |  |  | 37 | $raf->Read($buff, $size) == $size or $et->Warn("Truncated FLIF $tag chunk"), last; | 
| 291 | 12 | 50 |  |  |  | 74 | $et->VerboseDump(\$buff, Addr => $raf->Tell() - $size) if $verbose > 2; | 
| 292 |  |  |  |  |  |  | # inflate the compressed data | 
| 293 | 12 | 50 |  |  |  | 24 | if (eval { require IO::Uncompress::RawInflate }) { | 
|  | 12 |  |  |  |  | 87 |  | 
| 294 | 12 | 50 |  |  |  | 53 | if (IO::Uncompress::RawInflate::rawinflate(\$buff => \$inflated)) { | 
| 295 | 12 |  |  |  |  | 18589 | $et->HandleTag($tagTablePtr, $tag, $inflated, | 
| 296 |  |  |  |  |  |  | DataPt => \$inflated, | 
| 297 |  |  |  |  |  |  | Size => length $inflated, | 
| 298 |  |  |  |  |  |  | Extra => ' inflated', | 
| 299 |  |  |  |  |  |  | ); | 
| 300 |  |  |  |  |  |  | } else { | 
| 301 | 0 |  |  |  |  | 0 | $et->Warn("Error inflating FLIF $tag chunk"); | 
| 302 |  |  |  |  |  |  | } | 
| 303 |  |  |  |  |  |  | } else { | 
| 304 | 0 |  |  |  |  | 0 | $et->WarnOnce('Install IO::Uncompress::RawInflate to decode FLIF metadata'); | 
| 305 |  |  |  |  |  |  | } | 
| 306 |  |  |  |  |  |  | } else { | 
| 307 | 0 | 0 |  |  |  | 0 | $raf->Seek($size, 1) or $et->Warn('Seek error'), last; | 
| 308 |  |  |  |  |  |  | } | 
| 309 |  |  |  |  |  |  | } | 
| 310 | 5 |  |  |  |  | 27 | return 1; | 
| 311 |  |  |  |  |  |  | } | 
| 312 |  |  |  |  |  |  |  | 
| 313 |  |  |  |  |  |  | 1;  # end | 
| 314 |  |  |  |  |  |  |  | 
| 315 |  |  |  |  |  |  | __END__ |