Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

hajkr

problem with palette

This topic is 5966 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 have a 8 bit image loaded into memory. this image has its own palette. The palette data is given in 24 bit color values in RGB order. If i try to paint my 8 bit image then the colors are a little bit crazy, so i think i even need the palette for the 8 bit image. I don''t really know how a palette works and i don''t know if i can create maybe a 16 or 24 bit image out of my 8 bit image. Can anybody say me how i get my 16 or 24 bit image ?

Share this post


Link to post
Share on other sites
Advertisement
I don''t know what your exact situation is, but GetDIBits() could do the job. Be aware, though, that GetDIBits() doesn''t handle 8bpp images correctly under some versions of Windows.
Another option is to take the bitmap file, read out the bits, and substitute every indice with the corresp. RGB value. You''d get the bits for the equiv. 24bpp bitmap.

Forever trusting who we are
And nothing else matters
- Metallica

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
I don''t really know how a palette works..


a palette is a set of colors that are then referenced by the image.
so for instance a 4 bit palette is a collection of 16 colors in whatever format is desired..be it 24bit rgb, 16bit rgb, full 32 bit rgba, an intensity range, etc. the image, instead of having actaul colors for each pixel, has an index into its given palette.

the nice thing about palettes is that if you _know_ how a palette is built..you can rebuild it with different colors. this is how we did different color paint jobs in the racing games ive done. the artists built and mapped the cars with a predetermined palette arrangement (like the first 32 colors of the palette is a range from white to main color to black, the second 32 colors is a range from white to a secondary color to black, the next four are the brake light colors, etc. ) then during the car select screen when you would select a different color we would rebuild the palette to match the color scheme you choose.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
forgot something..

if youve got a 4 bit palette each image pixel is only 4 bits. so some shifting fun is needed to extract which palette entry is actaully referenced by this pixel. 8bit indexs for 8 bit palettes, 16 for 16, etc..

Share this post


Link to post
Share on other sites
thanks for your answers.

I think i know now how a palette works. if i have a 8bit image with a 24bit palette i can create a 24bit image. But what if i want to create a a 16 bit image with that 24bit palette.
How can i do this ?

Share this post


Link to post
Share on other sites
An 8 BPP image is made of 256 palette entries á 24 BPP and the image data (bits), where for every pixel you have 1 byte, wich comprizes as an indice into the palette. It should be clear that such a bitmap has a limited amount of color information, i.e. maximim 256 distingt colors.
A 16 BPP image actually has the same structure, withe the difference thet you have 2^16 palette entries, and for each pixel, there are 2 bytes, wich are the indice in the palette.
Converting the 8BPP image into the 16 BPP image is straight forward: Reserve a section of 2^16 RGB triplets (this will be your palette), and copy the palette of your 8BPP image into the first 256 entries. Rezerve a zone for the image bits, twice as large as the one of the 8BPP image. Than take each index of your 8BPP image, expand it to 16 bits (i.e. high byte = 0), and fill the bit area.
There are two more issues here:
1. 8BPP images CAN be RLE compressed. You''d need to de-compress the bits before converting them
2. Each line of pixels in your bitmap (called scanline) must start on an address that is WORD aligned on Win9.x and DWORD aligned on NT. With other words, if your image has an odd width, there will be some padding bytes at the end of each scanline.
Have a look to GetDIBits() in MSDN. The conversion I was talking about here can be done with GetDIBits().

Forever trusting who we are
And nothing else matters
- Metallica

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!