Indexed images

BlitzMax Forums/BlitzMax Programming/Indexed images

necky(Posted 2007) [#1]
Is there a way of loading in a 256 colour BMP and then having access to it's 256 colour palette and the index value from any of its pixels?

Thanks,
Andy


SoggyP(Posted 2007) [#2]
Hello.

As far as I'm aware only by reading the pixel values and generating the palette from that. BM doesn't use palettes.

I might be talking complete trash by the way but thought I'd try.

Goodbye.


CS_TBL(Posted 2007) [#3]
Isn't an indexed bmp made up from palette-data (3x256 bytes) and then the image data (width*height bytes)?


ImaginaryHuman(Posted 2007) [#4]
Just look up the format of the BMP file and write your own BMP reader so you can load in the palette yourself and then read the values for each pixel.


H&K(Posted 2007) [#5]
Simply answer No
Real Answer yes, but you would be faking it but only using 256 colurs on a 32bit (or 16Bit) image, so it wouldnt be as small as 8bit used to be. Or as angel said do the whole thing,
@Angel But then wouldnt you be stuck plotting the image onto the scree?


ImaginaryHuman(Posted 2007) [#6]
No you'd read the pixels into a pixmap. You'd have to, as you say, store them as colors rather than as indexes to colors. You'd be converting from an indirect index for each pixel, to a direct copy of the color value for each pixel.

You could draw the pixels straight to the backbuffer if you prefer and then grab to an image or a pixmap.

There's not any inbuilt stuff in Max to handle a 256-color image or to treat it as such using a palette. Ie changing the palette doesn't change the image. But if you did want that to happen, what you'd basically have to do is think of the palette as a table of values to REMAP the image to. Each time you change a color in the palette, go through all pixels in the image and if the pixel has that index, change it to the new color. But you'll have to then keep a copy of the indexed image as well as the 32-bit image.


GfK(Posted 2007) [#7]
This link might help:
http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

From what I've quickly read there, you should be able to write a BMP loader which gives you direct access to the RGB data. By modifying this data you should be able to change the colour of any given register.


necky(Posted 2007) [#8]
Thanks for all your help on this guys.
After I posted this question I took a good look at the BMP format and found it had a very easy-to-access header which I was able to use to extract the palette and also the pixel index values.

I`m at work at the moment but, when I go home tonight, I`ll post up my function that loads in a 256 colour index pixmap.
Each red channel of each pixel contains the index value as apposed to the actual colour and a separate array contains the palette.

You can't draw these pixmaps but there handy to use if, for example, you're writing an index paint package.

Thanks again guys!