Jump to content
  • Advertisement
Sign in to follow this  
domstyledesign

Bitmap Color Table

This topic is 5477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing a terrain editor that can open and save grayscale bmp's. opening the files is no problem, but saving files made from scratch is. the problem that i have is that i don't know how to output a grayscale color table to a file. i know there are 0 to 255 values, but this unsigned char i; for(i=0;i<256;i++){...} doesn't work. what do i need to do?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
When you are saving the file, are you saving it to 4 or 8 bits, and are you using any rle compression, and are you saving it top-down or regularly? If you are doing 8-bit BI_RGB then it shouldn't have a problem the way you're doing it. You should just write out the BMPFileHeader, the BMPInfoHeader, and then 8 bits for each color (ranging as you said, from 0 to 255), and then the color-indexes to use for each individual pixel.

An unsigned char and a char both encompass 8 bits, so there should be no problem there.

Share this post


Link to post
Share on other sites
well, I think that you should use:

unsigned int i;
for (i = 0; i < 256; i++){...}


that's because 'unsigned char' is in range 0 to 255. if it is greater, then it is clamped to 255. your loop will never end.

Share this post


Link to post
Share on other sites
8bit, no compression, stored bottom to top.

i figured out the problem. i was under the impression that the color table format was different for grayscale.

i was writing 1 byte for each color table entry, when i should've been writing 3 bytes of equal value (rgb) and 1 byte dead.

i thought that since it was grayscale it would only store the 1 necessary byte... storing 3 bytes of the same value seems silly and wasteful, maybe i'm wrong.

but when i compared my grayscale color table with a Photoshop grayscale color table under a hex editor, they were identical.

is this a flaw in photoshop, or (slightly) wasteful mistake in the BMP file specs?

Share this post


Link to post
Share on other sites
No, all color palettes with BMP images, regardless of how the individual pixels are saved are arrays of RGBQuads. Even with OS2 BMP files.


struct RGBQuad
{
unsigned char Blue, Green, Red, Fat;
};



You were trying to save each one as just 0-255 rather than doing the scaling to 24 bits with 8 bits left over then?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!