| 1 | package Image::TextMode::Reader::Tundra; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 2 | ▶ | use Moo; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | 2 | extends 'Image::TextMode::Reader'; | |||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | sub _read { | ||||||||||||||||||
| 8 | 3 | ▶ | my ( $self, $image, $fh, $options ) = @_; | ||||||||||||||||
|
Subroutine
_read: called CC=10 SCAR=23.5
| |||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 3 | my ( $buffer, %header ); | |||||||||||||||||
| 11 | 3 | read( $fh, $buffer, 1 ); | |||||||||||||||||
| 12 | 3 | $header{ int_id } = unpack( 'C', $buffer ); | |||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | 3 | read( $fh, $buffer, 8 ); | |||||||||||||||||
| 15 | 3 | $header{ id } = unpack( 'A8', $buffer ); | |||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | 3 | $image->header( \%header ); | |||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | 3 | ▶ | my $width = $options->{ width } || 80; | ||||||||||||||||
|
Condition50%1/2
$options->{'width'} || 80
MC/DC0%0/1
$options->{'width'} || 80
$options->{'width'}
Truth table50%1/2
A
A= $options->{'width'}
| |||||||||||||||||||
| 20 | 3 | my $pal = Image::TextMode::Palette->new; | |||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | 3 | my ( $x, $y, $attr, $fg, $bg, $pal_index ) = ( 0 ) x 6; | |||||||||||||||||
| 23 | 3 | $pal->colors->[ $pal_index++ ] = [ 0, 0, 0 ]; | |||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 3 | ▶ | while ( read( $fh, $buffer, 1 ) ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 26 | 90 | ▶ | last if tell( $fh ) > $options->{ filesize }; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | 90 | my $command = ord( $buffer ); | |||||||||||||||||
| 29 | |||||||||||||||||||
| 30 | 90 | ▶ | if ( $command == 1 ) { # position | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 31 | 2 | read( $fh, $buffer, 8 ); | |||||||||||||||||
| 32 | 2 | ( $y, $x ) = unpack( 'N*', $buffer ); | |||||||||||||||||
| 33 | 2 | next; | |||||||||||||||||
| 34 | } | ||||||||||||||||||
| 35 | |||||||||||||||||||
| 36 | 88 | my $char; | |||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | 88 | ▶ | if ( $command == 2 ) { # fg | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 39 | 2 | read( $fh, $char, 1 ); | |||||||||||||||||
| 40 | 2 | read( $fh, $buffer, 4 ); | |||||||||||||||||
| 41 | 2 | my $rgb = unpack( 'N', $buffer ); | |||||||||||||||||
| 42 | 2 | $fg = $pal_index++; | |||||||||||||||||
| 43 | 2 | $pal->colors->[ $fg ] = [ | |||||||||||||||||
| 44 | ( $rgb >> 16 ) & 0x000000ff, | ||||||||||||||||||
| 45 | ( $rgb >> 8 ) & 0x000000ff, | ||||||||||||||||||
| 46 | $rgb & 0x000000ff, | ||||||||||||||||||
| 47 | ]; | ||||||||||||||||||
| 48 | } | ||||||||||||||||||
| 49 | elsif ( $command == 4 ) { # bg | ||||||||||||||||||
| 50 | 0 | read( $fh, $char, 1 ); | |||||||||||||||||
| 51 | 0 | read( $fh, $buffer, 4 ); | |||||||||||||||||
| 52 | 0 | my $rgb = unpack( 'N', $buffer ); | |||||||||||||||||
| 53 | 0 | $bg = $pal_index++; | |||||||||||||||||
| 54 | 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 | read( $fh, $char, 1 ); | |||||||||||||||||
| 62 | 86 | read( $fh, $buffer, 8 ); | |||||||||||||||||
| 63 | 86 | my @rgb = unpack( 'N*', $buffer ); | |||||||||||||||||
| 64 | 86 | $fg = $pal_index++; | |||||||||||||||||
| 65 | 86 | $pal->colors->[ $fg ] = [ | |||||||||||||||||
| 66 | ( $rgb[ 0 ] >> 16 ) & 0x000000ff, | ||||||||||||||||||
| 67 | ( $rgb[ 0 ] >> 8 ) & 0x000000ff, | ||||||||||||||||||
| 68 | $rgb[ 0 ] & 0x000000ff, | ||||||||||||||||||
| 69 | ]; | ||||||||||||||||||
| 70 | 86 | $bg = $pal_index++; | |||||||||||||||||
| 71 | 86 | $pal->colors->[ $bg ] = [ | |||||||||||||||||
| 72 | ( $rgb[ 1 ] >> 16 ) & 0x000000ff, | ||||||||||||||||||
| 73 | ( $rgb[ 1 ] >> 8 ) & 0x000000ff, | ||||||||||||||||||
| 74 | $rgb[ 1 ] & 0x000000ff, | ||||||||||||||||||
| 75 | ]; | ||||||||||||||||||
| 76 | } | ||||||||||||||||||
| 77 | |||||||||||||||||||
| 78 | 88 | ▶ | if ( !$char ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 79 | 0 | $char = chr( $command ); | |||||||||||||||||
| 80 | } | ||||||||||||||||||
| 81 | |||||||||||||||||||
| 82 | 88 | $image->putpixel( { char => $char, fg => $fg, bg => $bg }, $x, $y ); | |||||||||||||||||
| 83 | 88 | $x++; | |||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | 88 | ▶ | if ( $x == $width ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 86 | 1 | $x = 0; | |||||||||||||||||
| 87 | 1 | $y++; | |||||||||||||||||
| 88 | } | ||||||||||||||||||
| 89 | } | ||||||||||||||||||
| 90 | |||||||||||||||||||
| 91 | 3 | $image->palette( $pal ); | |||||||||||||||||
| 92 | |||||||||||||||||||
| 93 | 3 | 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 E<lt>bricas@cpan.orgE<gt> | ||||||||||||||||||
| 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 | 2 | 1; | |||||||||||||||||