| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Image::TextMode::Reader::Tundra; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1150
|
use Moo; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Image::TextMode::Reader'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub _read { |
|
8
|
3
|
|
|
3
|
|
6
|
my ( $self, $image, $fh, $options ) = @_; |
|
9
|
|
|
|
|
|
|
|
|
10
|
3
|
|
|
|
|
5
|
my ( $buffer, %header ); |
|
11
|
3
|
|
|
|
|
49
|
read( $fh, $buffer, 1 ); |
|
12
|
3
|
|
|
|
|
16
|
$header{ int_id } = unpack( 'C', $buffer ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
7
|
read( $fh, $buffer, 8 ); |
|
15
|
3
|
|
|
|
|
10
|
$header{ id } = unpack( 'A8', $buffer ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
30
|
$image->header( \%header ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
3
|
|
50
|
|
|
1366
|
my $width = $options->{ width } || 80; |
|
20
|
3
|
|
|
|
|
35
|
my $pal = Image::TextMode::Palette->new; |
|
21
|
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
78
|
my ( $x, $y, $attr, $fg, $bg, $pal_index ) = ( 0 ) x 6; |
|
23
|
3
|
|
|
|
|
28
|
$pal->colors->[ $pal_index++ ] = [ 0, 0, 0 ]; |
|
24
|
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
1287
|
while ( read( $fh, $buffer, 1 ) ) { |
|
26
|
90
|
50
|
|
|
|
196
|
last if tell( $fh ) > $options->{ filesize }; |
|
27
|
|
|
|
|
|
|
|
|
28
|
90
|
|
|
|
|
98
|
my $command = ord( $buffer ); |
|
29
|
|
|
|
|
|
|
|
|
30
|
90
|
100
|
|
|
|
140
|
if ( $command == 1 ) { # position |
|
31
|
2
|
|
|
|
|
3
|
read( $fh, $buffer, 8 ); |
|
32
|
2
|
|
|
|
|
7
|
( $y, $x ) = unpack( 'N*', $buffer ); |
|
33
|
2
|
|
|
|
|
7
|
next; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
88
|
|
|
|
|
69
|
my $char; |
|
37
|
|
|
|
|
|
|
|
|
38
|
88
|
100
|
|
|
|
245
|
if ( $command == 2 ) { # fg |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
3
|
read( $fh, $char, 1 ); |
|
40
|
2
|
|
|
|
|
6
|
read( $fh, $buffer, 4 ); |
|
41
|
2
|
|
|
|
|
5
|
my $rgb = unpack( 'N', $buffer ); |
|
42
|
2
|
|
|
|
|
2
|
$fg = $pal_index++; |
|
43
|
2
|
|
|
|
|
54
|
$pal->colors->[ $fg ] = [ |
|
44
|
|
|
|
|
|
|
( $rgb >> 16 ) & 0x000000ff, |
|
45
|
|
|
|
|
|
|
( $rgb >> 8 ) & 0x000000ff, |
|
46
|
|
|
|
|
|
|
$rgb & 0x000000ff, |
|
47
|
|
|
|
|
|
|
]; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
elsif ( $command == 4 ) { # bg |
|
50
|
0
|
|
|
|
|
0
|
read( $fh, $char, 1 ); |
|
51
|
0
|
|
|
|
|
0
|
read( $fh, $buffer, 4 ); |
|
52
|
0
|
|
|
|
|
0
|
my $rgb = unpack( 'N', $buffer ); |
|
53
|
0
|
|
|
|
|
0
|
$bg = $pal_index++; |
|
54
|
0
|
|
|
|
|
0
|
$pal->colors->[ $bg ] = [ |
|
55
|
|
|
|
|
|
|
( $rgb >> 16 ) & 0x000000ff, |
|
56
|
|
|
|
|
|
|
( $rgb >> 8 ) & 0x000000ff, |
|
57
|
|
|
|
|
|
|
$rgb & 0x000000ff, |
|
58
|
|
|
|
|
|
|
]; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
elsif ( $command == 6 ) { # fg + bg |
|
61
|
86
|
|
|
|
|
99
|
read( $fh, $char, 1 ); |
|
62
|
86
|
|
|
|
|
75
|
read( $fh, $buffer, 8 ); |
|
63
|
86
|
|
|
|
|
195
|
my @rgb = unpack( 'N*', $buffer ); |
|
64
|
86
|
|
|
|
|
97
|
$fg = $pal_index++; |
|
65
|
86
|
|
|
|
|
1598
|
$pal->colors->[ $fg ] = [ |
|
66
|
|
|
|
|
|
|
( $rgb[ 0 ] >> 16 ) & 0x000000ff, |
|
67
|
|
|
|
|
|
|
( $rgb[ 0 ] >> 8 ) & 0x000000ff, |
|
68
|
|
|
|
|
|
|
$rgb[ 0 ] & 0x000000ff, |
|
69
|
|
|
|
|
|
|
]; |
|
70
|
86
|
|
|
|
|
378
|
$bg = $pal_index++; |
|
71
|
86
|
|
|
|
|
1399
|
$pal->colors->[ $bg ] = [ |
|
72
|
|
|
|
|
|
|
( $rgb[ 1 ] >> 16 ) & 0x000000ff, |
|
73
|
|
|
|
|
|
|
( $rgb[ 1 ] >> 8 ) & 0x000000ff, |
|
74
|
|
|
|
|
|
|
$rgb[ 1 ] & 0x000000ff, |
|
75
|
|
|
|
|
|
|
]; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
88
|
50
|
|
|
|
459
|
if ( !$char ) { |
|
79
|
0
|
|
|
|
|
0
|
$char = chr( $command ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
88
|
|
|
|
|
336
|
$image->putpixel( { char => $char, fg => $fg, bg => $bg }, $x, $y ); |
|
83
|
88
|
|
|
|
|
3110
|
$x++; |
|
84
|
|
|
|
|
|
|
|
|
85
|
88
|
100
|
|
|
|
325
|
if ( $x == $width ) { |
|
86
|
1
|
|
|
|
|
1
|
$x = 0; |
|
87
|
1
|
|
|
|
|
4
|
$y++; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
3
|
|
|
|
|
46
|
$image->palette( $pal ); |
|
92
|
|
|
|
|
|
|
|
|
93
|
3
|
|
|
|
|
1222
|
return $image; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 NAME |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Image::TextMode::Reader::Tundra - Reads Tundra files |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Provides reading capabilities for the Tundra format. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Brian Cassidy Ebricas@cpan.orgE |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Copyright 2008-2014 by Brian Cassidy |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
113
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |