| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Visualize; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
32429
|
use 5.008; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
30
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
876
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw( etch paint ); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub readgif { |
|
15
|
0
|
|
|
0
|
0
|
|
my($io, $chrs) = @_; |
|
16
|
0
|
0
|
|
|
|
|
read($io, my $result, $chrs) == $chrs or die "premature end of file: $io\n"; |
|
17
|
0
|
|
|
|
|
|
return $result; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub parsegif { |
|
21
|
0
|
|
|
0
|
0
|
|
my($in) = @_; |
|
22
|
0
|
0
|
|
|
|
|
open my $io, "<$in" or die "failed to parse input file, $in: $@\n"; |
|
23
|
0
|
|
|
|
|
|
my $header = readgif($io, 3); |
|
24
|
0
|
0
|
|
|
|
|
$header eq "GIF" or die "input file is not a GIF\n"; |
|
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
|
0
|
|
|
|
|
my($num_of_colors) = ord($colordesc) & 0b10000000 |
|
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>; |
|
|
0
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
close $io; |
|
38
|
0
|
|
|
|
|
|
return ($width, $height, $colordesc, $bkground, $colortable, $remainder); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub gifcomment { |
|
42
|
0
|
|
|
0
|
0
|
|
my($code) = join '', @_; |
|
43
|
0
|
|
|
|
|
|
my($index) = 1 + ord substr $code, 0, 1; |
|
44
|
0
|
|
|
|
|
|
while ( $index < length $code ) { |
|
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
|
|
|
|
|
|
|
sub perlcomment { |
|
53
|
0
|
|
|
0
|
0
|
|
my($comment) = @_; |
|
54
|
0
|
|
|
|
|
|
$comment =~ s/\x0a/\x0b/g; |
|
55
|
0
|
|
|
|
|
|
return "# $comment"; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub perlstring { |
|
59
|
0
|
|
|
0
|
0
|
|
my($string) = @_; |
|
60
|
0
|
|
|
|
|
|
$string =~ s/\xfe/\xfd/g; |
|
61
|
0
|
|
|
|
|
|
return "q\xfe$string\xfe"; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub deparsegif { |
|
65
|
0
|
|
|
0
|
0
|
|
my($outputfile, $colordesc, $bkground, $colortable, $remainder, $escape, $perl) = @_; |
|
66
|
0
|
0
|
|
|
|
|
open my $io, ">$outputfile" or die "failed to open output file: $@\n"; |
|
67
|
0
|
|
|
|
|
|
$colortable =~ s/\xfe/\xfd/g; |
|
68
|
0
|
|
|
|
|
|
print $io "GIF89a;"; |
|
69
|
0
|
0
|
|
|
|
|
if ( $escape eq "comment" ) { |
|
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
|
|
|
|
|
|
|
sub etch { |
|
81
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub paint { |
|
87
|
0
|
|
|
0
|
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; |
|
93
|
|
|
|
|
|
|
__END__ |