Hey Howie!
On Tue Aug 18 07:38:47 2015, howie@thingy.com wrote:
Show quoted text> I'm working on a VGA textmode implementation in FPGA, and I wanted to
> pre-load my screen memory with a test ANSI screen. I was hoping that
> Image::TextMode would let me load an ANSI and then save a .bin file, but I
> don't see any way to pass a canvas from a reader to a writer - they seem to
> just take filenames.
>
> Is this possible? The data I need is in there somewhere, I guess!
This is an excellent question! The structure is *basically* there to do some conversion, but that really wasn't part of the goals of the module, so it's not tested -- nor truly thought out.
There's also the problem that many formats have features that other formats don't have, so conversion becomes a lossy or inexact science (consider, XBin->ANSI; though ANSI->XBin would work!)
I've done a little digging for you with respect to ANSI->Bin conversion.
First of all, my write() method for bin files made a huge assumption about having a complete canvas with no undefined pixels. I've patched that up on github:
https://github.com/bricas/image-textmode/commit/87bfa0d13bb5136f438815fb960831062b53a355
This now let's us do something cheeky like this:
use Image::TextMode::Format::ANSI;
use Image::TextMode::Format::Bin;
my $ansi = Image::TextMode::Format::ANSI->new;
$ansi->read( shift );
bless $ansi, 'Image::TextMode::Format::Bin';
$ansi->write( 'out.bin' );
Nothing complains and we get valid Bin data out. If you try a conversion to png (note, the width may vary):
textmode2png --readopt width=79 out.bin
We get somthing that looks mostly right, except for the palette. So instead we can do:
textmode2png --pal ANSI --readopt width=79 out.bin
And we get the proper output.
If you want a raw bin with the proper colors, then you'll have to rewrite all of the "attr" values for each pixel, converting from the ANSI pal (
https://metacpan.org/source/BRICAS/Image-TextMode-0.25/lib/Image/TextMode/Palette/ANSI.pm) to the VGA pal (
https://metacpan.org/source/BRICAS/Image-TextMode-0.25/lib/Image/TextMode/Palette/VGA.pm)
Hope that helps!
-Brian