convert BMP 256col to raw image data ?

T

Torben

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 ?
 
J

jl_post

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
 
T

Torben

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top