Board index » delphi » strip unused colors in a bitmap palette

strip unused colors in a bitmap palette

E.g. I may have a bitmap having e.g. 10 or 100 colors (saved as
8bit) or 1000 colors (saved as 32bit) - I can't say on before hand.

I do not wish to reduce actual number of colors used etc.
the only thing I wish is to strip unused colors out of palette
(or maybe as another solution make all unsued colors black).

My objective are:
* Since windows uses "palette switcing/per app" I try to limit number of
unused palette colors.
* Lessen the size of bitmaps generated (much less important than above).

Any functions for that (Delphi, Jedi etc.)?

best regards
Thomas Schulz

 

Re:strip unused colors in a bitmap palette


Quote
> My objective are:

* And then to save the bitmap (i.e. the palette change has to be permanent
and saved to file).

Thomas

Re:strip unused colors in a bitmap palette


Quote
> Somewhere on efg's page is an count-color-algorithm using tbits. After the
> first loop you got all used colors 'marked'. Now you could compare. If a
> color isn't marked in tbits-array, then the color should be eliminated in
> your palette.

Mm... I have found PaletteLab demo.. That is the one you are referring to
(else I can not find it)?
Thanks. I had hoped to find a function or something that could do the whole
process  (since I would
imagine it is a pretty general wish to cut unused colors in a palette away)
for me, but no such luck I guess :).

best regards
Thomas

Re:strip unused colors in a bitmap palette


Quote
"dk_sz" <dk...@hotmail.com> wrote in message

news:3d8cb047$1@newsgroups.borland.com...

Quote
> E.g. I may have a bitmap having e.g. 10 or 100 colors (saved as
> 8bit) or 1000 colors (saved as 32bit) - I can't say on before hand.

> I do not wish to reduce actual number of colors used etc.
> the only thing I wish is to strip unused colors out of palette
> (or maybe as another solution make all unsued colors black).

If you display a pf8bit bitmap in 256 color display mode, you need to worry
about the Windows palette manager.

If you display pf24bit bitmap, which does not have a palette, Windows does
absolutely nothing for you to display such a bitmap "correctly" in 256 color
display mode.  The Show Demo One Lab Report addressed the display of a
single pf24bit bitmap in 256 color rmode:
http://homepages.borland.com/efg2lab/Graphics/Colors/ShowDemoOne.htm
This project computed the "best" 236 colors (or you could specify the number
you want).

Remember in 256 color display mode, you can only use 236 colors per palette
since Windows reserves 20 for display of icons, panels, buttons, etc.

There is no "science" behind the Windows palette manager in 256 color mode.
In reality you're simply lucky that the palette at any given time is "OK"
enough to display the colors in the various windows on a screen.  Such
problems go away in high color and true color display modes.

Quote
> My objective are:
> * Since windows uses "palette switcing/per app" I try to limit number of
> unused palette colors.
> * Lessen the size of bitmaps generated (much less important than above).

You can spend a lot of time getting palettes right.  It's far easier to use
pf24bit bitmaps in high color or true color display modes.

--
efg -- Earl F. Glynn, Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab
Mirror:  http://homepages.borland.com/efg2lab/Default.htm

Re:strip unused colors in a bitmap palette


Posting 3.30 am (bear with me):

Quote
> If you display a pf8bit bitmap in 256 color display mode, you need to
worry
> about the Windows palette manager.

Yep.

Quote
> If you display pf24bit bitmap, which does not have a palette, Windows does
> absolutely nothing for you to display such a bitmap "correctly" in 256
color
> display mode.  The Show Demo One Lab Report addressed the display of a
> single pf24bit bitmap in 256 color rmode:
> http://homepages.borland.com/efg2lab/Graphics/Colors/ShowDemoOne.htm
> This project computed the "best" 236 colors (or you could specify the
number
> you want).

What I am trying to achieve is..
I am extending some glyphs I have (so they instead of being 16x16 now are
32x16, i.e. enabled and disabled).
In doing so each bitmap (when saved as 8 bit bitmap) gets a 236 color
palette (I thought there were 256 colors, but from what you tell me - that
can not be) with lots of unused colors specified. I will check out the demo
you link to (I guess that with a color counter it should solve my problem
cutting maximum unused colors). I guess the demo then has code to generate
palettes (I will check it).

Quote
> Remember in 256 color display mode, you can only use 236 colors per
palette
> since Windows reserves 20 for display of icons, panels, buttons, etc.

OK.

Quote
> There is no "science" behind the Windows palette manager in 256 color
mode.
> In reality you're simply lucky that the palette at any given time is "OK"
> enough to display the colors in the various windows on a screen.  Such
> problems go away in high color and true color display modes.

Indeed. But I can not be sure where, how, and in which combinations I will
use my glyphs.
So to minimize the chances of color clashes. Imageine e.g. if I use 100
glyphs
- where un-optimized each palette would referer to e.g. 200 different
colors..
.. -- ..
But are you saying Windows do not care which palette the different bitmaps
in my program specify
- it only checks with the actual colors shown on screen - and generates its
app-specific palette from that
(seems logical enough, I just have not thought of it that way, I can not say
why)?

Quote
> You can spend a lot of time getting palettes right.  It's far easier to
use
> pf24bit bitmaps in high color or true color display modes.

And then use the code used in the program/demo you posted link to (and
thereby make it work/look fairly for 256 color too)?

Thanks for all the input, suggestions, and help.

best regards
Thomas Schulz

Re:strip unused colors in a bitmap palette


Quote
> I've only got a few minutes myself, so I'll be brief too.

After having messed around with palettes..
I have decided to use the easy path (for now) - I believe one you originally
suggested as a possible solution.
Basicly I save my bitmaps as 32bit. No palettes created.
The bitmaps use the colors they do - and that is that.

And well.. If my combined use of glyphs suddenly went over 256 (236) colors
(or used other colors than on default palette)...
And user runs in 256 color mode... That is just too bad :).
I am 31% sure <G!> that this will not happen for my usage.

I wil however save this thread for future "inspection" (if I.muster up some
more courage).

Thanks everyone!

best regards
Thomas Schulz

Other Threads