| 1 | package Image::TextMode::Writer::ANSIMation; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use charnames ':full'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | extends 'Image::TextMode::Writer'; | |||||||||||
| 7 | |||||||||||||
| 8 | sub _write { | ||||||||||||
| 9 | 1 | ▶ | my ( $self, $anim, $fh, $options ) = @_; | ||||||||||
|
Subroutine
_write: called CC=9 SCAR=22.5
| |||||||||||||
| 10 | |||||||||||||
| 11 | # clear screen | ||||||||||||
| 12 | 1 | print $fh "\N{ESCAPE}[2J"; | |||||||||||
| 13 | |||||||||||||
| 14 | 1 | my $prevattr = ''; | |||||||||||
| 15 | 1 | for my $image ( @{ $anim->frames } ) { | |||||||||||
| 16 | 2 | my ( $width, $height ) = $image->dimensions; | |||||||||||
| 17 | |||||||||||||
| 18 | 2 | for my $y ( 0 .. $height - 1 ) { | |||||||||||
| 19 | 2 | my $max_x = $image->max_x( $y ); | |||||||||||
| 20 | |||||||||||||
| 21 | 2 | ▶ | unless ( defined $max_x ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | 0 | print $fh "\n"; | |||||||||||
| 23 | 0 | next; | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | 2 | for my $x ( 0 .. $max_x ) { | |||||||||||
| 27 | 8 | ▶ | my $pixel = $image->getpixel( $x, $y ) | ||||||||||
|
Condition50%1/2
$image->getpixel($x, $y) || {'char', ' ', 'attr', 7}
MC/DC0%0/1
$image->getpixel($x, $y) || {'char', ' ', 'attr', 7}
$image->getpixel($x, $y)
Truth table50%1/2
A
A= $image->getpixel($x, $y)
| |||||||||||||
| 28 | || { char => ' ', attr => 7 }; | ||||||||||||
| 29 | 8 | my $attr = _gen_args( $pixel->{ attr } ); | |||||||||||
| 30 | 8 | ▶ | if ( $attr ne $prevattr ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 8 | print $fh "\N{ESCAPE}[0;", _gen_args( $pixel->{ attr } ), | |||||||||||
| 32 | 'm'; | ||||||||||||
| 33 | 8 | $prevattr = $attr; | |||||||||||
| 34 | } | ||||||||||||
| 35 | 8 | print $fh $pixel->{ char }; | |||||||||||
| 36 | } | ||||||||||||
| 37 | 2 | ▶ | print $fh "\n" unless $max_x == 79; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | # set position | ||||||||||||
| 41 | 2 | ▶ | if ( $image ne $anim->frames->[ -1 ] ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 1 | print $fh "\N{ESCAPE}[H"; | |||||||||||
| 43 | } | ||||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | # clear attrs | ||||||||||||
| 47 | 1 | print $fh "\N{ESCAPE}[0m"; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | sub _gen_args { | ||||||||||||
| 51 | 16 | ▶ | my $attr = shift; | ||||||||||
|
Subroutine
_gen_args: called CC=3 SCAR=11.0
| |||||||||||||
| 52 | 16 | my $fg = 30 + ( $attr & 7 ); | |||||||||||
| 53 | 16 | my $bg = 40 + ( ( $attr & 112 ) >> 4 ); | |||||||||||
| 54 | 16 | ▶ | my $bl = ( $attr & 128 ) ? 5 : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 16 | ▶ | my $in = ( $attr & 8 ) ? 1 : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 16 | return join( q{;}, grep { length } ( $bl, $in, $fg, $bg ) ); | |||||||||||
| 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 E<lt>bricas@cpan.orgE<gt> | ||||||||||||
| 70 | |||||||||||||
| 71 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 72 | |||||||||||||
| 73 | Copyright 2008-2014 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 | 1; | |||||||||||