| 1 | package Perl::Visualize; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | require Exporter; | |||||||||
| 8 | |||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||
| 10 | 1 | our @EXPORT_OK = qw( etch paint ); | |||||||||
| 11 | |||||||||||
| 12 | 1 | our $VERSION = '1.02'; | |||||||||
| 13 | |||||||||||
| 14 | 0 | ▶ | sub readgif { | ||||||||
|
Subroutine
readgif: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 15 | 0 | my($io, $chrs) = @_; | |||||||||
| 16 | 0 | ▶ | read($io, my $result, $chrs) == $chrs or die "premature end of file: $io\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 0 | return $result; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub parsegif { | ||||||||
|
Subroutine
parsegif: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 21 | 0 | my($in) = @_; | |||||||||
| 22 | 0 | ▶ | open my $io, "<$in" or die "failed to parse input file, $in: $@\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | my $header = readgif($io, 3); | |||||||||
| 24 | 0 | ▶ | $header eq "GIF" or die "input file is not a GIF\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | |||||||||||
| 26 | 0 | my $version = readgif($io,3); | |||||||||
| 27 | 0 | my $width = readgif($io,2); | |||||||||
| 28 | 0 | my $height = readgif($io,2); | |||||||||
| 29 | 0 | my $colordesc = readgif($io,1); | |||||||||
| 30 | 0 | ▶ | my($num_of_colors) = ord($colordesc) & 0b10000000 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | ? (1 << ((ord($colordesc) & 0b00000111) + 1)) * 3 | ||||||||||
| 32 | : 0; | ||||||||||
| 33 | 0 | my $bkground = readgif($io, 2); | |||||||||
| 34 | 0 | my $colortable = readgif($io,$num_of_colors); | |||||||||
| 35 | |||||||||||
| 36 | 0 | local undef $/; my $remainder = <$io>; | |||||||||
| 37 | 0 | close $io; | |||||||||
| 38 | 0 | return ($width, $height, $colordesc, $bkground, $colortable, $remainder); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub gifcomment { | ||||||||
|
Subroutine
gifcomment: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 42 | 0 | my($code) = join '', @_; | |||||||||
| 43 | 0 | my($index) = 1 + ord substr $code, 0, 1; | |||||||||
| 44 | 0 | ▶ | while ( $index < length $code ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | $index += 1 + ord substr $code, $index, 1; | |||||||||
| 46 | } | ||||||||||
| 47 | 0 | $code .= " " x ($index - length $code); | |||||||||
| 48 | 0 | $code .= "\x04 \x00"; | |||||||||
| 49 | 0 | return $code; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub perlcomment { | ||||||||
|
Subroutine
perlcomment: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 53 | 0 | my($comment) = @_; | |||||||||
| 54 | 0 | $comment =~ s/\x0a/\x0b/g; | |||||||||
| 55 | 0 | return "# $comment"; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | sub perlstring { | ||||||||
|
Subroutine
perlstring: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 59 | 0 | my($string) = @_; | |||||||||
| 60 | 0 | $string =~ s/\xfe/\xfd/g; | |||||||||
| 61 | 0 | return "q\xfe$string\xfe"; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | ▶ | sub deparsegif { | ||||||||
|
Subroutine
deparsegif: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 65 | 0 | my($outputfile, $colordesc, $bkground, $colortable, $remainder, $escape, $perl) = @_; | |||||||||
| 66 | 0 | ▶ | open my $io, ">$outputfile" or die "failed to open output file: $@\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $colortable =~ s/\xfe/\xfd/g; | |||||||||
| 68 | 0 | print $io "GIF89a;"; | |||||||||
| 69 | 0 | ▶ | if ( $escape eq "comment" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | print $io perlcomment ";$colordesc$bkground$colortable\x21\xfe"; | |||||||||
| 71 | 0 | print $io gifcomment "\n$perl" # Comments terminated by EOL | |||||||||
| 72 | } else { | ||||||||||
| 73 | 0 | print $io perlstring ";$colordesc$bkground$colortable\x21"; | |||||||||
| 74 | 0 | print $io gifcomment ";$perl" # String statement terminated by semicolon | |||||||||
| 75 | } | ||||||||||
| 76 | 0 | print $io $remainder; | |||||||||
| 77 | 0 | close $io; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | sub etch { | ||||||||
|
Subroutine
etch: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 81 | 0 | my($imagefile, $outputfile, $perl) = @_; | |||||||||
| 82 | 0 | my($width, $height, $colordesc, $bkground, $colortable, $remainder) = parsegif($imagefile); | |||||||||
| 83 | 0 | deparsegif ( $outputfile, $colordesc, $bkground, $colortable, $remainder, "comment", $perl ); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub paint { | ||||||||
|
Subroutine
paint: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 87 | 0 | my($imagefile, $outputfile, $perl) = @_; | |||||||||
| 88 | 0 | my($width, $height, $colordesc, $bkground, $colortable, $remainder) = parsegif($imagefile); | |||||||||
| 89 | 0 | deparsegif ( $outputfile, $colordesc, $bkground, $colortable, $remainder, "string", $perl ); | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 1 | 1; | |||||||||
| 93 | __END__ | ||||||||||