Image/GIF.pm

filter: Statementstmt 51.2% 186 / 363 Branchbran 37.5% 45 / 120 Conditioncond 23.0% 6 / 26 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 78.5% 11 / 14 Podpod 0.0% 0 / 9 totaltotal 45.4% 248 / 546 CC 70 SCAR 44.3
CC
70
Cov
47%
LZW
210.0
UnLZW
210.0
Open
35.8
CRAP 84.1
« Create/Page.pm ↑ Summary Create.pm »
1 #
2 # PDF::Image::GIF - GIF image support for PDF::Create
3 #
4 # Author: Michael Gross <info@mdgrosse.net>
5 #
6 # Copyright 1999-2001 Fabien Tassin
7 # Copyright 2007 Markus Baertschi <markus@markus.org>
8 #
9 # Please see the CHANGES and Changes file for the detailed change log
10 #
11 # Please do not use any of the methods here directly. You will be
12 # punished with your application no longer working after an upgrade !
13 #
14  
15 package PDF::Image::GIF;
16  
17 18 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 18 our $VERSION = '1.28';
23 18 our $DEBUG = 0;
24  
25 sub new
26 {
27 1 ▶ my $self = {};
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
28  
29 1 $self->{private} = {};
30 1 $self->{colorspace} = 0;
31 1 $self->{width} = 0;
32 1 $self->{height} = 0;
33 1 $self->{colorspace} = "DeviceRGB";
34 1 $self->{colorspacedata} = "";
35 1 $self->{colorspacesize} = 0;
36 1 $self->{filename} = "";
37 1 $self->{error} = "";
38 1 $self->{imagesize} = 0;
39 1 $self->{transparent} = 0;
40 1 $self->{filter} = ["LZWDecode"];
41 1 $self->{decodeparms} = { 'EarlyChange' => 0 };
42 1 $self->{private}->{interlaced} = 0;
43  
44 1 bless($self);
45 1 return $self;
46 }
47  
48 sub LZW
49 {
50 0 ▶ my $self = shift;
Subroutine LZW: not called CC=14 SCAR=53.5
Pod undocumented
51 0 my $data = shift;
52 0 my $result = "";
53 0 my $prefix = "";
54 0 my $c;
55 my %hash;
56 0 my $num;
57 0 my $codesize = 9;
58  
59 #init hash-table
60 0 ▶ for ( $num = 0 ; $num < 256 ; $num++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num < 256) 0 0 0
61 0 $hash{ chr($num) } = $num;
62 }
63  
64 #start with a clear
65 0 $num = 258;
66 0 my $currentvalue = 256;
67 0 my $bits = 9;
68  
69 0 my $pos = 0;
70 0 ▶ while ( $pos < length($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < length $data) 0 0 0
71 0 $c = substr( $data, $pos, 1 );
72  
73 0 ▶ if ( exists( $hash{ $prefix . $c } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash{$prefix . $c}) { } 0 0 0
74 0 $prefix .= $c;
75 } else {
76  
77 #save $hash{$prefix}
78 0 $currentvalue <<= $codesize;
79 0 $currentvalue |= $hash{$prefix};
80 0 $bits += $codesize;
81 0 ▶ while ( $bits >= 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits >= 8) 0 0 0
82 0 $result .= chr( ( $currentvalue >> ( $bits - 8 ) ) & 255 );
83 0 $bits -= 8;
84 0 $currentvalue &= ( 1 << $bits ) - 1;
85 }
86  
87 0 $hash{ $prefix . $c } = $num;
88 0 $prefix = $c;
89 0 $num++;
90  
91 #increase code size?
92 0 ▶ if ( $num == 513 || $num == 1025 || $num == 2049 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num == 513 or $num == 1025 or $num == 2049) 0 0 0
Condition0%0/6
$num == 513 or $num == 1025 or $num == 2049
l!l&&r!l&&!r
000
$num == 513 or $num == 1025
l!l&&r!l&&!r
000
MC/DC0%0/3
$num == 513 or $num == 1025 or $num == 2049
$num == 513 $num == 1025 $num == 2049
Truth table0%0/4
A or B or C
A= $num == 513B= $num == 1025C= $num == 2049
ABCresult
1XX1
01X1
0011
0000
93 0 $codesize++;
94 }
95  
96 #hash table overflow?
97 0 ▶ if ( $num == 4097 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num == 4097) 0 0 0
98  
99 #save clear
100 0 $currentvalue <<= $codesize;
101 0 $currentvalue |= 256;
102 0 $bits += $codesize;
103 0 ▶ while ( $bits >= 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits >= 8) 0 0 0
104 0 $result .= chr( ( $currentvalue >> ( $bits - 8 ) ) & 255 );
105 0 $bits -= 8;
106 0 $currentvalue &= ( 1 << $bits ) - 1;
107 }
108  
109 #reset hash table
110 0 $codesize = 9;
111 0 %hash = ();
112 0 ▶ for ( $num = 0 ; $num < 256 ; $num++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num < 256) 0 0 0
113 0 $hash{ chr($num) } = $num;
114 }
115 0 $num = 258;
116 }
117 }
118 0 $pos++;
119 }
120  
121 #save value for prefix
122 0 $currentvalue <<= $codesize;
123 0 $currentvalue |= $hash{$prefix};
124 0 $bits += $codesize;
125 0 ▶ while ( $bits >= 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits >= 8) 0 0 0
126 0 $result .= chr( ( $currentvalue >> ( $bits - 8 ) ) & 255 );
127 0 $bits -= 8;
128 0 $currentvalue &= ( 1 << $bits ) - 1;
129 }
130  
131 #save eoi
132 0 $currentvalue <<= $codesize;
133 0 $currentvalue |= 257;
134 0 $bits += $codesize;
135 0 ▶ while ( $bits >= 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits >= 8) 0 0 0
136 0 $result .= chr( ( $currentvalue >> ( $bits - 8 ) ) & 255 );
137 0 $bits -= 8;
138 0 $currentvalue &= ( 1 << $bits ) - 1;
139 }
140  
141 #save remainder in $currentvalue
142 0 ▶ if ( $bits > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits > 0) 0 0 0
143 0 $currentvalue = $currentvalue << ( 8 - $bits );
144 0 $result .= chr( $currentvalue & 255 );
145 }
146  
147 0 $result;
148 }
149  
150 sub UnLZW
151 {
152 0 ▶ my $self = shift;
Subroutine UnLZW: not called CC=14 SCAR=53.5
Pod undocumented
153 0 my $data = shift;
154 0 my $result = "";
155  
156 0 my $bits = 0;
157 0 my $currentvalue = 0;
158 0 my $codesize = 9;
159 0 my $pos = 0;
160  
161 0 my $prefix = "";
162 0 my $suffix;
163 my @table;
164  
165 #initialize lookup-table
166 0 my $num;
167 0 ▶ for ( $num = 0 ; $num < 256 ; $num++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num < 256) 0 0 0
168 0 $table[$num] = chr($num);
169 }
170 0 $table[256] = "";
171  
172 0 $num = 257;
173  
174 0 my $c1;
175  
176 #get first word
177 0 ▶ while ( $bits < $codesize ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits < $codesize) 0 0 0
178 0 my $d = ord( substr( $data, $pos, 1 ) );
179 0 $currentvalue = ( $currentvalue << 8 ) + $d;
180 0 $bits += 8;
181 0 $pos++;
182 }
183 0 my $c2 = $currentvalue >> ( $bits - $codesize );
184 0 $bits -= $codesize;
185 0 my $mask = ( 1 << $bits ) - 1;
186 0 $currentvalue = $currentvalue & $mask;
187  
188 0 ▶ DECOMPRESS: while ( $pos < length($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < length $data) 0 0 0
189 0 $c1 = $c2;
190  
191 #get next word
192 0 ▶ while ( $bits < $codesize ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits < $codesize) 0 0 0
193 0 my $d = ord( substr( $data, $pos, 1 ) );
194 0 $currentvalue = ( $currentvalue << 8 ) + $d;
195 0 $bits += 8;
196 0 $pos++;
197 }
198 0 $c2 = $currentvalue >> ( $bits - $codesize );
199 0 $bits -= $codesize;
200 0 $mask = ( 1 << $bits ) - 1;
201 0 $currentvalue = $currentvalue & $mask;
202  
203 #clear code?
204 0 ▶ if ( $c2 == 256 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c2 == 256) 0 0 0
205 0 $result .= $table[$c1];
206 0 $#table = 256;
207 0 $codesize = 9;
208 0 $num = 257;
209 0 next DECOMPRESS;
210 }
211  
212 #End Of Image?
213 0 ▶ if ( $c2 == 257 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c2 == 257) 0 0 0
214 0 last DECOMPRESS;
215 }
216  
217 #get prefix
218 0 ▶ if ( $c1 < $num ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c1 < $num) { } 0 0 0
219 0 $prefix = $table[$c1];
220 } else {
221 0 print "Compression Error ($c1>=$num)\n";
222 }
223  
224 #write prefix
225 0 $result .= $prefix;
226  
227 #get suffix
228 0 ▶ if ( $c2 < $num ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c2 < $num) { } 0 0 0
elsif ($c2 == $num) { } 0 0 0
229 0 $suffix = substr( $table[$c2], 0, 1 );
230 } elsif ( $c2 == $num ) {
231 0 $suffix = substr( $prefix, 0, 1 );
232 } else {
233 0 print "Compression Error ($c2>$num)\n";
234 }
235  
236 #new table entry is prefix.suffix
237 0 $table[$num] = $prefix . $suffix;
238  
239 #next table entry
240 0 $num++;
241  
242 #increase code size?
243 0 ▶ if ( $num == 512 || $num == 1024 || $num == 2048 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num == 512 or $num == 1024 or $num == 2048) 0 0 0
Condition0%0/6
$num == 512 or $num == 1024 or $num == 2048
l!l&&r!l&&!r
000
$num == 512 or $num == 1024
l!l&&r!l&&!r
000
MC/DC0%0/3
$num == 512 or $num == 1024 or $num == 2048
$num == 512 $num == 1024 $num == 2048
Truth table0%0/4
A or B or C
A= $num == 512B= $num == 1024C= $num == 2048
ABCresult
1XX1
01X1
0011
0000
244 0 $codesize++;
245 }
246 }
247  
248 0 ▶ $result .= $table[$c1] if defined $table[$c1];
Branch: 1 branch
BranchTrueFalseTotal
if defined $table[$c1] 0 0 0
249  
250 0 $result;
251 }
252  
253 sub UnInterlace
254 {
255 0 ▶ my $self = shift;
Subroutine UnInterlace: not called CC=5 SCAR=34.0
Pod undocumented
256 0 my $data = shift;
257 0 my $row;
258 my @result;
259 0 my $width = $self->{width};
260 0 my $height = $self->{height};
261 0 my $idx = 0;
262  
263 #Pass 1 - every 8th row, starting with row 0
264 0 $row = 0;
265 0 ▶ while ( $row < $height ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row < $height) 0 0 0
266 0 $result[$row] = substr( $data, $idx * $width, $width );
267 0 $row += 8;
268 0 $idx++;
269 }
270  
271 #Pass 2 - every 8th row, starting with row 4
272 0 $row = 4;
273 0 ▶ while ( $row < $height ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row < $height) 0 0 0
274 0 $result[$row] = substr( $data, $idx * $width, $width );
275 0 $row += 8;
276 0 $idx++;
277 }
278  
279 #Pass 3 - every 4th row, starting with row 2
280 0 $row = 2;
281 0 ▶ while ( $row < $height ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row < $height) 0 0 0
282 0 $result[$row] = substr( $data, $idx * $width, $width );
283 0 $row += 4;
284 0 $idx++;
285 }
286  
287 #Pass 4 - every 2th row, starting with row 1
288 0 $row = 1;
289 0 ▶ while ( $row < $height ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row < $height) 0 0 0
290 0 $result[$row] = substr( $data, $idx * $width, $width );
291 0 $row += 2;
292 0 $idx++;
293 }
294  
295 0 join( '', @result );
296 }
297  
298 sub GetDataBlock
299 {
300 2 ▶ my $self = shift;
Subroutine GetDataBlock: called CC=2 SCAR=6.9
Pod undocumented
301 2 my $fh = shift;
302 2 my $s;
303 my $count;
304 2 my $buf;
305 2 read $fh, $s, 1;
306 2 $count = unpack( "C", $s );
307  
308 2 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 1 1 2
309 1 read $fh, $buf, $count;
310 }
311  
312 2 ( $count, $buf );
313 }
314  
315 sub ReadColorMap
316 {
317 1 ▶ my $self = shift;
Subroutine ReadColorMap: called CC=1 SCAR=0.0
Pod undocumented
318 1 my $fh = shift;
319 1 read $fh, $self->{'colorspacedata'}, 3 * $self->{'colormapsize'};
320 1 1;
321 }
322  
323 sub DoExtension
324 {
325 1 ▶ my $self = shift;
Subroutine DoExtension: called CC=8 SCAR=21.6
Pod undocumented
326 1 my $label = shift;
327 1 my $fh = shift;
328 1 my $res;
329 my $buf;
330 1 my $c;
331 1 my $c2;
332 1 my $c3;
333  
334 1 ▶ if ( $label eq "\001" ) { #Plain Text Extension
Branch: 4 branches
BranchTrueFalseTotal
if ($label eq "\cA") { } 0 1 1
elsif (ord $label == 255) { } 0 1 1
elsif (ord $label == 254) { } 0 1 1
elsif (ord $label == 249) { } 1 0 1
335 } elsif ( ord($label) == 0xFF ) { #Application Extension
336 } elsif ( ord($label) == 0xFE ) { #Comment Extension
337 } elsif ( ord($label) == 0xF9 ) { #Grapgic Control Extension
338 1 ( $res, $buf ) = $self->GetDataBlock($fh); #(p, image, (unsigned char*) buf);
339 1 ( $c, $c2, $c2, $c3 ) = unpack( "CCCC", $buf );
340 1 ▶ if ( $c && 0x1 != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if () 1 0 1
Condition50%1/2
$c and
!ll
01
MC/DC0%0/1
$c and
$c
Truth table50%1/2
A
A= $c
Aresult
00
11
341 1 $self->{transparent} = 1;
342 1 $self->{mask} = $c3;
343 }
344 }
345  
346 1 BLOCK: while (1) {
347 1 ( $res, $buf ) = $self->GetDataBlock($fh);
348 1 ▶ if ( $res == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res == 0) 1 0 1
349 1 last BLOCK;
350 }
351 }
352  
353 1 1;
354 }
355  
356 sub Open
357 {
358 1 ▶ my $self = shift;
Subroutine Open: called CC=17 SCAR=35.8
Pod undocumented
359 1 my $filename = shift;
360  
361 1 my $PDF_STRING_GIF = "\107\111\106";
362 1 my $PDF_STRING_87a = "\070\067\141";
363 1 my $PDF_STRING_89a = "\070\071\141";
364 1 my $LOCALCOLORMAP = 0x80;
365 1 my $INTERLACE = 0x40;
366  
367 1 my $s;
368 my $c;
369 1 my $ar;
370 1 my $flags;
371  
372 1 $self->{filename} = $filename;
373 1 my $fh = FileHandle->new("$filename");
374 1 ▶ if ( !defined $fh ) { $self->{error} = "PDF::Image::GIF.pm: $filename: $!"; return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 1 1
375 1 binmode $fh;
376 1 read $fh, $s, 3;
377 1 ▶ if ( $s ne $PDF_STRING_GIF ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s ne $PDF_STRING_GIF) 0 1 1
378 0 close $fh;
379 0 $self->{error} = "PDF::Image::GIF.pm: Not a gif file.";
380 0 return 0;
381 }
382  
383 1 read $fh, $s, 3;
384 1 ▶ if ( $s ne $PDF_STRING_87a && $s ne $PDF_STRING_89a ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s ne $PDF_STRING_87a and $s ne $PDF_STRING_89a) 0 1 1
Condition33%1/3
$s ne $PDF_STRING_87a and $s ne $PDF_STRING_89a
!ll&&!rl&&r
010
MC/DC0%0/2
$s ne $PDF_STRING_87a and $s ne $PDF_STRING_89a
$s ne $PDF_STRING_87a $s ne $PDF_STRING_89a
Truth table33%1/3
A and B
A= $s ne $PDF_STRING_87aB= $s ne $PDF_STRING_89a
ABresult
0X0
100
111
385 0 close $fh;
386 0 $self->{error} = "PDF::Image::GIF.pm: GIF version $s not supported.";
387 0 return 0;
388 }
389  
390 1 read $fh, $s, 7;
391 1 ( $self->{width}, $self->{height}, $flags, $self->{private}->{background}, $ar ) = unpack( "vvCCC", $s );
392  
393 1 $self->{colormapsize} = 2 << ( $flags & 0x07 );
394 1 $self->{colorspacesize} = 3 * $self->{colormapsize};
395 1 ▶ if ( $flags & $LOCALCOLORMAP ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & $LOCALCOLORMAP) 1 0 1
396 1 ▶ if ( !$self->ReadColorMap($fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->ReadColorMap($fh)) 0 1 1
397 0 close $fh;
398 0 $self->{error} = "PDF::Image::GIF.pm: Cant read color map.";
399 0 return 0;
400 }
401 }
402  
403 1 ▶ if ( $ar != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ar != 0) 0 1 1
404 0 $self->{private}->{dpi_x} = -( $ar + 15.0 ) / 64.0;
405 0 $self->{private}->{dpi_y} = -1.0;
406 }
407  
408 1 my $imageCount = 0;
409 1 IMAGES: while (1) {
410 2 read $fh, $c, 1;
411 2 ▶ if ( $c eq ";" ) { #GIF file terminator
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq ";") 0 2 2
412 0 close $fh;
413 0 $self->{error} = "PDF::Image::GIF.pm: Cant find image in gif file.";
414 0 return 0;
415 }
416  
417 2 ▶ if ( $c eq "!" ) { #Extension
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "!") 1 1 2
418 1 read $fh, $c, 1;
419 1 $self->DoExtension( $c, $fh );
420 1 next;
421 }
422  
423 1 ▶ if ( $c ne "," ) { #must be comma
Branch: 1 branch
BranchTrueFalseTotal
if ($c ne ",") 0 1 1
424 0 next; #ignore
425 }
426  
427 1 $imageCount++;
428  
429 1 read $fh, $s, 9;
430 1 my $x;
431 1 ( $x, $c, $self->{width}, $self->{height}, $flags ) = unpack( "vvvvC", $s );
432  
433 1 ▶ if ( $flags && $INTERLACE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags and $INTERLACE) 0 1 1
Condition33%1/3
$flags and $INTERLACE
!ll&&!rl&&r
100
MC/DC0%0/2
$flags and $INTERLACE
$flags $INTERLACE
Truth table33%1/3
A and B
A= $flagsB= $INTERLACE
ABresult
0X0
100
111
434 0 $self->{private}->{interlaced} = 1;
435 }
436  
437 1 ▶ if ( $flags & $LOCALCOLORMAP ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & $LOCALCOLORMAP) 0 1 1
438 0 ▶ if ( !$self->ReadColorMap($fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->ReadColorMap($fh)) 0 0 0
439 0 close $fh;
440 0 $self->{error} = "PDF::Image::GIF.pm: Cant read color map.";
441 0 return 0;
442 }
443 }
444  
445 1 read $fh, $s, 1; #read "LZW initial code size"
446 1 $self->{bpc} = unpack( "C", $s );
447 1 ▶ if ( $self->{bpc} != 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bpc"} != 8) 0 1 1
448 0 close $fh;
449 0 $self->{error} = "PDF::Image::GIF.pm: LZW minimum code size is " . $self->{bpc} . ", must be 8 to be supported.";
450 0 return 0;
451 }
452  
453 1 ▶ if ( $imageCount == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($imageCount == 1) 1 0 1
454 1 last IMAGES;
455 }
456  
457 }
458  
459 1 $self->{private}->{datapos} = tell($fh);
460 1 close $fh;
461  
462 1 1;
463 }
464  
465 sub ReadData
466 {
467 1 ▶ my $self = shift;
Subroutine ReadData: called CC=16 SCAR=28.0
Pod undocumented
468  
469 # init the LZW transformation vars
470 1 my $c_size = 9; # initial code size
471 1 my $t_size = 257; # initial "table" size
472 1 my $i_buff = 0; # input buffer
473 1 my $i_bits = 0; # input buffer empty
474 1 my $o_bits = 0; # output buffer empty
475 1 my $o_buff = 0;
476 1 my $c_mask;
477 1 my $bytes_available = 0;
478 1 my $n_bytes;
479 my $s;
480 1 my $c;
481 1 my $flag13;
482 1 my $code;
483 1 my $w_bits;
484  
485 1 my $result = "";
486  
487 1 my $fh = FileHandle->new($self->{filename});
488 1 ▶ if ( !defined $fh ) { $self->{error} = "PDF::Image::GIF.pm: $self->{filename}: $!"; return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 1 1
489 1 binmode $fh;
490 1 seek( $fh, $self->{private}->{datapos}, 0 );
491 1 my $pos = 0;
492 1 my $data;
493 1 read $fh, $data, ( -s $self->{filename} );
494  
495 18 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
496  
497 1 $self->{imagesize} = 0;
498 1 BLOCKS: while (1) {
499 96 $s = substr( $data, $pos, 1 );
500 96 $pos++;
501 96 $n_bytes = unpack( "C", $s );
502 96 ▶ if ( !$n_bytes ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n_bytes) 1 95 96
503 1 last BLOCKS;
504 }
505  
506 95 $c_mask = ( 1 << $c_size ) - 1;
507 95 $flag13 = 0;
508  
509 95 BLOCK: while (1) {
510 17319 $w_bits = $c_size; # number of bits to write
511 17319 $code = 0;
512  
513 #get at least c_size bits into i_buff
514 17319 ▶ while ( $i_bits < $c_size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_bits < $c_size) 24173 17225 41398
515 24173 ▶ if ( $n_bytes == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_bytes == 0) 94 24079 24173
516 94 last BLOCK;
517 }
518 24079 $n_bytes--;
519 24079 $s = substr( $data, $pos, 1 );
520 24079 $pos++;
521 24079 $c = unpack( "C", $s );
522 24079 $i_buff |= $c << $i_bits; #EOF will be caught later
523 24079 $i_bits += 8;
524 }
525  
526 17225 $code = $i_buff & $c_mask;
527  
528 17225 $i_bits -= $c_size;
529 17225 $i_buff >>= $c_size;
530  
531 17225 ▶ if ( $flag13 && $code != 256 && $code != 257 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag13 and $code != 256 and $code != 257) 0 17225 17225
Condition50%3/6
$flag13 and $code != 256 and $code != 257
!ll&&!rl&&r
1722500
$flag13 and $code != 256
!ll&&!rl&&r
1722140
MC/DC0%0/3
$flag13 and $code != 256 and $code != 257
$flag13 $code != 256 $code != 257
Truth table50%2/4
A and B and C
A= $flag13B= $code != 256C= $code != 257
ABCresult
0XX0
10X0
1100
1111
532 0 $self->{error} = "PDF::Image::GIF.pm: LZW code size overflow.";
533 0 return 0;
534 }
535  
536 17225 ▶ if ( $o_bits > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o_bits > 0) 14980 2245 17225
537 14980 $o_buff |= $code >> ( $c_size - 8 + $o_bits );
538 14980 $w_bits -= 8 - $o_bits;
539 14980 $result .= chr( $o_buff & 255 );
540 }
541  
542 17225 ▶ if ( $w_bits >= 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w_bits >= 8) 9099 8126 17225
543 9099 $w_bits -= 8;
544 9099 $result .= chr( ( $code >> $w_bits ) & 255 );
545 }
546 17225 $o_bits = $w_bits;
547 17225 ▶ if ( $o_bits > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o_bits > 0) 14980 2245 17225
548 14980 $o_buff = $code << ( 8 - $o_bits );
549 }
550  
551 17225 $t_size++;
552 17225 ▶ if ( $code == 256 ) { #clear code
Branch: 1 branch
BranchTrueFalseTotal
if ($code == 256) 5 17220 17225
553 5 $c_size = 9;
554 5 $c_mask = ( 1 << $c_size ) - 1;
555 5 $t_size = 257;
556 5 $flag13 = 0;
557 }
558  
559 17225 ▶ if ( $code == 257 ) { #end code
Branch: 1 branch
BranchTrueFalseTotal
if ($code == 257) 1 17224 17225
560 1 last BLOCK;
561 }
562  
563 17224 ▶ if ( $t_size == ( 1 << $c_size ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t_size == 1 << $c_size) 19 17205 17224
564 19 ▶ if ( ++$c_size > 12 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$c_size > 12) { } 4 15 19
565 4 $c_size--;
566 4 $flag13 = 1;
567 } else {
568 15 $c_mask = ( 1 << $c_size ) - 1;
569 }
570 }
571 } # while () for block
572 } # while () for all blocks
573  
574 #interlaced?
575 1 ▶ if ( $self->{private}->{interlaced} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"private"}{"interlaced"}) 0 1 1
576  
577 #when interlaced first uncompress image
578 0 $result = $self->UnLZW($result);
579  
580 #remove interlacing
581 0 $result = $self->UnInterlace($result);
582  
583 #compress image again
584 0 $result = $self->LZW($result);
585 }
586  
587 1 $self->{imagesize} = length($result);
588 1 $result;
589 }
590  
591 18 1;
592  
« Create/Page.pm ↑ Summary Create.pm »