convert BMP 256col to raw image data ?

Discussion in 'Perl Misc' started by Torben, Mar 8, 2010.

  1. Torben

    Torben Guest

    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 ?
     
    Torben, Mar 8, 2010
    #1
    1. Advertising

  2. Torben

    Guest

    On Mar 8, 2:58 pm, Torben <> 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
     
    , Mar 8, 2010
    #2
    1. Advertising

  3. Torben

    Torben Guest

    "" <> wrote in news:3eddc08d-12db-
    :

    > 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
     
    Torben, Mar 9, 2010
    #3
  4. Torben

    Torben Guest

    Ben Morrow <> wrote in
    news::

    > Yes (specifically unpack). You will also need
    > http://msdn.microsoft.com/en-us/library/dd183391(VS.85).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 ?
     
    Torben, Mar 10, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry Simpson

    32 dpp BMP to 24dpp BMP??

    Harry Simpson, Oct 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    376
    Harry Simpson
    Oct 30, 2003
  2. Craig
    Replies:
    2
    Views:
    718
    Soni Bergraj
    Dec 4, 2006
  3. bharath
    Replies:
    4
    Views:
    3,358
    Thomas Fritsch
    Mar 16, 2007
  4. Replies:
    2
    Views:
    1,431
    red floyd
    Apr 29, 2009
  5. Jack
    Replies:
    2
    Views:
    213
    Dave Weaver
    Jan 7, 2008
Loading...

Share This Page