Image::TextMode::Writer::IDF - Writes IDF files


Image-TextMode documentation Contained in the Image-TextMode distribution.

Index


Code Index:

NAME

Top

Image::TextMode::Writer::IDF - Writes IDF files

DESCRIPTION

Top

Provides writing capabilities for the IDF format. It currently does not support any RLE compression.

AUTHOR

Top

Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


Image-TextMode documentation Contained in the Image-TextMode distribution.

package Image::TextMode::Writer::IDF;

use Moose;
use charnames ':full';

extends 'Image::TextMode::Writer';

my $header_template = 'A4 v v v v';

sub _write {
    my ( $self, $image, $fh, $options ) = @_;

    my ( $max_x, $max_y ) = map { $_ - 1 } $image->dimensions;

    print $fh pack( $header_template,
        "\N{END OF TRANSMISSION}1.4",
        0, 0, $max_x, $max_y );

    # Don't bother with RLE compression for now
    for my $y ( 0 .. $max_y ) {
        for my $x ( 0 .. $max_x ) {
            my $pixel = $image->getpixel( $x, $y );
            print $fh pack( 'aC', $pixel->{ char }, $pixel->{ attr } );
        }
    }

    for my $char ( @{ $image->font->chars } ) {
        print $fh pack( 'C*', @$char );
    }

    for my $color ( @{ $image->palette->colors } ) {
        print $fh pack( 'C*', map { $_ >> 2 } @$color );
    }
}

no Moose;

__PACKAGE__->meta->make_immutable;

1;