From: Torben on
Is there a perl-ish way to strip the header off a BMP image and get only
the raw image data ?

My BMP input is 256 color, and I need to have only the image data, like
explained in

http://www.autohotkey.com/forum/topic11179.html

The forum speaks of BMP2RAW which I can call for the file from Perl, but I
would like to do it natively.

Is pack() / unpack () the solution ?

From: jl_post on
On Mar 8, 2:58 pm, Torben <dam-kat-jen...(a)gmail-kat-.com> wrote:
> Is there a perl-ish way to strip the header off a BMP image
> and get only the raw image data ?


Unfortunately, there a several variables for BMP files (such as
compressed/non-compressed, different number of bits per pixel), so to
do this correctly you'd have to handle them all.

Are you familiar with *.ppm files (specifically, of type "P6")?
This looks to be just about exactly what you want, where each pixel is
encoded as 24 bits (that is, one byte for RED, one byte for GREEN, and
one byte for BLUE). The only difference is that *.ppm files include a
short header to specify the width, height, and range of intensity
values.

You can read more about this file type here:

http://en.wikipedia.org/wiki/Portable_pixmap

The nice thing about this file format is that several free image
manipulator programs & libraries (such as "ImageMagick", "xv", and
"The Gimp") support this type, so converting an image of a well-known
type to a *.ppm file is very simple.

And writing to this type of file is very simple, as well. Since
there is no compression and just a very short header, all you really
need to know (aside from the width & height of the image) is the RGB
values of each pixel.

As for converting a *.bmp file to a *.ppm file, you'll have to
learn how to read a *.bmp file into an list of pixels, as well as
extract out its width & height. Since there are several variable
things you have to watch out for, it will probably just be better for
you to use a free third-party software tool to convert it to a *.ppm
file for you.

And once you have a *.ppm file, you can just read it in as a binary
file (using Perl if you want), strip off the short header, and you
have exactly what you want!

I hope this helps, Torben.

-- Jean-Luc
From: Torben on
"jl_post(a)hotmail.com" <jl_post(a)hotmail.com> wrote in news:3eddc08d-12db-
469d-bb65-28d75a8d8ad0(a)u5g2000prd.googlegroups.com:

> Unfortunately, there a several variables for BMP files (such as
> compressed/non-compressed, different number of bits per pixel), so to
> do this correctly you'd have to handle them all.
>
> Are you familiar with *.ppm files (specifically, of type "P6")?

Yes, but I need only the 8-bit, as described in the page I linked to.

I have the palette, and just need the "raw" image data in 8 bit.

In this way, the pixel color is directly coded in the file, one byte per
pixel. The total file size in byte is exactly equal to height x width,
example would 320x200 pixel be 64,000 bytes.

Maybe it's just a matter of stripping n bytes from the file, but not sure.

The application btw is an embedded controller run by a Xilinx FPGA. So no
operating system, images are directly output by memory copy. That's why I
need the raw format.

Hope this helps.

Torben
From: Ben Morrow on

Quoth Torben <dam-kat-jensen(a)gmail-kat-.com>:
> Is there a perl-ish way to strip the header off a BMP image and get only
> the raw image data ?
>
> My BMP input is 256 color, and I need to have only the image data, like
> explained in
>
> http://www.autohotkey.com/forum/topic11179.html
>
> The forum speaks of BMP2RAW which I can call for the file from Perl, but I
> would like to do it natively.
>
> Is pack() / unpack () the solution ?

Yes (specifically unpack). You will also need
http://msdn.microsoft.com/en-us/library/dd183391%28VS.85%29.aspx, and
some understanding of C structures.

An alternative would be to use one of the many image-handling libraries
on CPAN, for example Imager, which will let you get the raw bits out in
any format you like.

Ben


From: Torben on
Ben Morrow <ben(a)morrow.me.uk> wrote in
news:9fmh67-p2f.ln1(a)osiris.mauzo.dyndns.org:

> Yes (specifically unpack). You will also need
> http://msdn.microsoft.com/en-us/library/dd183391%28VS.85%29.aspx, and
> some understanding of C structures.
>
> An alternative would be to use one of the many image-handling
> libraries on CPAN, for example Imager, which will let you get the raw
> bits out in any format you like.

Thank you for the links.

Looked at Imager, but can't really an example of how to do.

Can you show an example ?