News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Bitmap Color Palette

Started by masitecno, July 03, 2012, 11:57:39 AM

Previous topic - Next topic

masitecno

Hi,

Now Im working with color palette of bitmaps.

How can I create a color palette for a bitmap?

Thanks.

I keep searching  :biggrin:

BogdanOntanu

Honestly... nobody uses an color palette anymore those days.

It is a world with true colors, 32 bits or even more per pixel.

Theoretically you could create an old direct-draw  surface with an attached palette and maybe show a bitmap on a full screen in 256 colors... but why bother when almost every screen today has 32 or 24 bits per pixel?


Ambition is a lame excuse for the ones not brave enough to be lazy, www.oby.ro

dedndave

in the sample program i posted earlier, i use CreateDIBSection to create a DIB
when that DIB is created, a pointer to a BITMAPINFO structure is passed
the one i created is 24 bits per pixel
however, you could just as easily create one with 256 colors
you set the biBitCount member to 8 and create a palette
(i think you also call RealizePalette or something to select the palette into the DC - never tried it)

palettes are used for bitmaps that have 1, 2, 4, or 8 bits per pixel
(2, 4, 16, or 256 color images)

for what you are doing, 256 colors is probably enough
it would mean that each pixel has 1 byte instead of 3, as in a 24-bit image

the palette (or "color table") then has an array of RGBQUAD structures - one for each color
each RGBQUAD has 4 bytes (B, G, R, A) - the A (alpha channel) is only used for transparent images
so - for a 256 color palette, 1024 bytes are used

then - the data for each pixel is an index into the palette
if the pixel data byte is 0, the first color in the palette is used
if the pixel data byte is 255, the last color in the palette is used

Zen

As Bogdan Ontanu mentioned above, you rarely see a 256 color bitmaps anymore on modern hardware..
The format does exist, however. The bitmap is the native Windows type of image. The color palette is optional; all bitmaps with more than 256 colors do NOT have a color palette.
Here is information from MSDN: Bitmap Header Types.
The CodeProject has a HUGE number of bitmap tutorials, and the quality is excellent. General Graphics Articles Listing
Here is: Bitmap Basics - A GDI Tutorial
...And, an old programmer's favorite is: CxImage. This project is like a mini-Photoshop. You will find an immense amount of code, involving almost everything you can do in GDI.



masitecno


All answers are great!

Thank you very much...

Specially to Dave, I will start to try one by one...

dedndave

Zen is right - 256 color BMP's are old stuff
however, i can see where it may be beneficial because it reduces the amount of data you have to move around
256 colors should be plenty for what you are doing
however - if we ever get to 3-D rotation, 24-bit colors is easier to work with   :P

masitecno

Ok, then I will remove the Idea of a color palette.

But, then i don't understand how can I hava a slider and as I move it towards all colors change to be clearer and forwards change to be darker.

And I need to make that effect.


Zen

#8
...nevermind,...