Skip Menu |

This queue is for tickets about the Image-TextMode CPAN distribution.

Report information
The Basics
Id: 106504
Status: open
Priority: 0/
Queue: Image-TextMode

People
Owner: Nobody in particular
Requestors: howie [...] thingy.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Convert between formats in Image::TextMode?
Date: Tue, 18 Aug 2015 11:38:34 +0100
To: bug-Image-TextMode [...] rt.cpan.org
From: Howard Jones <howie [...] thingy.com>
Hi, 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! Thanks, Howie
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
Subject: Re: [rt.cpan.org #106504] Convert between formats in Image::TextMode?
Date: Fri, 21 Aug 2015 10:17:58 +0100
To: bug-Image-TextMode [...] rt.cpan.org
From: Howard Jones <howie [...] thingy.com>
Thanks for the quick reply Brian! I'll give it a go once I get my timing figured out properly on the electronics side. In my case the palette is just a RAM table, so I can tweak that as necessary. I'll let you know how I get on. Cheers, Howie On 18/08/2015 15:34, Brian Cassidy via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=106504 > > > Hey Howie! > > On Tue Aug 18 07:38:47 2015, howie@thingy.com wrote:
>> 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 >