line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Image::TextMode::Writer::ANSIMation; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
401
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
288
|
use charnames ':full'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'Image::TextMode::Writer'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _write { |
9
|
1
|
|
|
1
|
|
1
|
my ( $self, $anim, $fh, $options ) = @_; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# clear screen |
12
|
1
|
|
|
|
|
4
|
print $fh "\N{ESCAPE}[2J"; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
2
|
my $prevattr = ''; |
15
|
1
|
|
|
|
|
1
|
for my $image ( @{ $anim->frames } ) { |
|
1
|
|
|
|
|
26
|
|
16
|
2
|
|
|
|
|
15
|
my ( $width, $height ) = $image->dimensions; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
49
|
for my $y ( 0 .. $height - 1 ) { |
19
|
2
|
|
|
|
|
6
|
my $max_x = $image->max_x( $y ); |
20
|
|
|
|
|
|
|
|
21
|
2
|
50
|
|
|
|
4
|
unless ( defined $max_x ) { |
22
|
0
|
|
|
|
|
0
|
print $fh "\n"; |
23
|
0
|
|
|
|
|
0
|
next; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
3
|
for my $x ( 0 .. $max_x ) { |
27
|
8
|
|
50
|
|
|
14
|
my $pixel = $image->getpixel( $x, $y ) |
28
|
|
|
|
|
|
|
|| { char => ' ', attr => 7 }; |
29
|
8
|
|
|
|
|
46
|
my $attr = _gen_args( $pixel->{ attr } ); |
30
|
8
|
50
|
|
|
|
14
|
if ( $attr ne $prevattr ) { |
31
|
8
|
|
|
|
|
13
|
print $fh "\N{ESCAPE}[0;", _gen_args( $pixel->{ attr } ), |
32
|
|
|
|
|
|
|
'm'; |
33
|
8
|
|
|
|
|
7
|
$prevattr = $attr; |
34
|
|
|
|
|
|
|
} |
35
|
8
|
|
|
|
|
13
|
print $fh $pixel->{ char }; |
36
|
|
|
|
|
|
|
} |
37
|
2
|
50
|
|
|
|
6
|
print $fh "\n" unless $max_x == 79; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# set position |
41
|
2
|
100
|
|
|
|
31
|
if ( $image ne $anim->frames->[ -1 ] ) { |
42
|
1
|
|
|
|
|
10
|
print $fh "\N{ESCAPE}[H"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# clear attrs |
47
|
1
|
|
|
|
|
8
|
print $fh "\N{ESCAPE}[0m"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _gen_args { |
51
|
16
|
|
|
16
|
|
10
|
my $attr = shift; |
52
|
16
|
|
|
|
|
12
|
my $fg = 30 + ( $attr & 7 ); |
53
|
16
|
|
|
|
|
17
|
my $bg = 40 + ( ( $attr & 112 ) >> 4 ); |
54
|
16
|
100
|
|
|
|
19
|
my $bl = ( $attr & 128 ) ? 5 : ''; |
55
|
16
|
100
|
|
|
|
17
|
my $in = ( $attr & 8 ) ? 1 : ''; |
56
|
16
|
|
|
|
|
11
|
return join( q{;}, grep { length } ( $bl, $in, $fg, $bg ) ); |
|
64
|
|
|
|
|
69
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Image::TextMode::Writer::ANSIMation - Writes ANSIMation files |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 DESCRIPTION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Provides writing capabilities for the ANSIMation format. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 AUTHOR |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Brian Cassidy Ebricas@cpan.orgE |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Copyright 2008-2015 by Brian Cassidy |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
76
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |