Board index » delphi » Bitmap / Palette Problems

Bitmap / Palette Problems

Hi there,

I know this is an old subject, but I've read everything I can find on the
subject, including many threads on these newsgroups, and although I'm
starting to have a fairly good feel for the topic, I'm still having major
problems.

I can't have more than one 256 color bitmap on A 256 color screen without
having major palette clashes.

What I really want to do is have a CoolBar with a 256 color background, and
buttons with 256 color glyphs on them. Ideally I'd get these bitmaps from a
resource file, but that's not critical. I know the problem was with
palettes, so I've recreated all my bitmaps, with the same palette, but
still I have massive clashes.

The only thing which is anything like working is a call to
CreateHalftonePalette ... but that's creating a palette which is miles away
from the colors I want.

I'm following a lot of tips from Earl Glynn's PaletteLibrary unit  (using
the CreateOptimizedPaletteForManyBitmaps function), but that seems to be
only happy with 24-bit bitmaps. I've got functions which are going through
all the bitmaps on a form, calling ReleasePalette, then setting their
palette (to one called by CreateHalftonePalette for example), but still no
joy (anyway, the bitmaps already have the same palette !).

Has anyone ever actually cracked this one ??

Please help !!!

Thanks in advance

Jason Hankin

 

Re:Bitmap / Palette Problems


Remember that on a 256-colour display, certain palette entries are reserved
by Windows.  I think there are some 20 or so such palette entries.

PaintShop Pro 4.x (and above) allows you to reduce the palette entries in a
bit map and exclude those entrie used by Windows.

Hope this helps,

Best regards,

Jon Souter

Quote
Jason Hankin wrote in message <01bd8fdc$288dca40$2584989e@tecra>...
>Hi there,

>I know this is an old subject, but I've read everything I can find on the
>subject, including many threads on these newsgroups, and although I'm
>starting to have a fairly good feel for the topic, I'm still having major
>problems.

>I can't have more than one 256 color bitmap on A 256 color screen without
>having major palette clashes.

>What I really want to do is have a CoolBar with a 256 color background, and
>buttons with 256 color glyphs on them. Ideally I'd get these bitmaps from a
>resource file, but that's not critical. I know the problem was with
>palettes, so I've recreated all my bitmaps, with the same palette, but
>still I have massive clashes.

>The only thing which is anything like working is a call to
>CreateHalftonePalette ... but that's creating a palette which is miles away
>from the colors I want.

>I'm following a lot of tips from Earl Glynn's PaletteLibrary unit  (using
>the CreateOptimizedPaletteForManyBitmaps function), but that seems to be
>only happy with 24-bit bitmaps. I've got functions which are going through
>all the bitmaps on a form, calling ReleasePalette, then setting their
>palette (to one called by CreateHalftonePalette for example), but still no
>joy (anyway, the bitmaps already have the same palette !).

>Has anyone ever actually cracked this one ??

>Please help !!!

>Thanks in advance

>Jason Hankin

Re:Bitmap / Palette Problems


Thanks for that,

I thought for a minute you were on to something, (I was using paintbrush
but when I created the custom palette I was *including* the windows
colours. So ... I recreated the palettes, and excluded them, but it made no
difference.

Any clues ...

Jason.

Re:Bitmap / Palette Problems


Jon,

thanks for that,

I thought for a moment that you were on to something: I'm using Paintbrush,
but when I was creating the custom palette, I was *including* the Windows
palette.  So ....  I recreated the palette, excluding the windows colours,
but to no avail ....

Any clues ?

Thanks again,

Jason

Re:Bitmap / Palette Problems


Quote
Jason Hankin wrote:

> Hi there,

> I know this is an old subject, but I've read everything I can find on
> the
> subject, including many threads on these newsgroups, and although I'm
> starting to have a fairly good feel for the topic, I'm still having
> major
> problems.

> I can't have more than one 256 color bitmap on A 256 color screen
> without
> having major palette clashes.

> What I really want to do is have a CoolBar with a 256 color
> background, and
> buttons with 256 color glyphs on them. Ideally I'd get these bitmaps
> from a
> resource file, but that's not critical. I know the problem was with
> palettes, so I've recreated all my bitmaps, with the same palette, but
> still I have massive clashes.

> The only thing which is anything like working is a call to
> CreateHalftonePalette ... but that's creating a palette which is miles
> away
> from the colors I want.

> I'm following a lot of tips from Earl Glynn's PaletteLibrary unit
> (using
> the CreateOptimizedPaletteForManyBitmaps function), but that seems to
> be
> only happy with 24-bit bitmaps. I've got functions which are going
> through
> all the bitmaps on a form, calling ReleasePalette, then setting their
> palette (to one called by CreateHalftonePalette for example), but
> still no
> joy (anyway, the bitmaps already have the same palette !).

> Has anyone ever actually cracked this one ??

> Please help !!!

> Thanks in advance

> Jason Hankin

The simplest and also crudest solution is to put all images on one
bitmap. I did that some times just to avoid the problems you have now.
It only works with a limited amount of graphics of course.
AS far as I've found out Windows will trash all palettes but the one it
is using, even if they're the same. Perhaps you could create a palette
independent from any of the bitmaps. Here's some code that could help
you:

procedure makepal;

var
  i:integer;
  pal: PLogPalette;
  hpal: HPALETTE;
  i:integer;
  mypal:array[0..255,1..3] of byte;  {load your palette in here}

begin
  pal := nil;
  try
    GetMem(pal, sizeof(TLogPalette) + sizeof(TPalet{*word*249}try) * 255);
    pal.palVersion := $300;
    pal.palNumEntries := 256;
    for i := 0 to 255 do
    begin
      pal.palPalEntry[i].peRed :=mypal[i,1];
      pal.palPalEntry[i].peGreen :=mypal[i,2];
      pal.palPalEntry[i].peBlue :=mypal[i,3];
    end;
    hpal := CreatePalette(pal^);
    if hpal <> 0 then
      virt.Palette := hpal;
  finally
    FreeMem(pal);
  end;
end;

I found this somewhere in the Delphi-help, but I've only used it to
force the palette on a 8bit-bitmap in truecolormode.

Good luck,

Remco de Korte
http://www.xs4all.nl/~remcodek

Re:Bitmap / Palette Problems


Jason Hankin <ja...@nospamlightwrk.demon.co.uk> wrote in article
<01bd8fdc$288dca40$2584989e@tecra>...
...

Quote
> I can't have more than one 256 color bitmap on A 256 color screen without
> having major palette clashes.

> What I really want to do is have a CoolBar with a 256 color background,
and
> buttons with 256 color glyphs on them. Ideally I'd get these bitmaps from
a
> resource file, but that's not critical. I know the problem was with
> palettes, so I've recreated all my bitmaps, with the same palette, but
> still I have massive clashes.

Did you try to create one palette (handle) and pass this to the palette
property of all bitmaps/images etc? The only potential problem with that is
that all bitmaps think they *own* the palette and will delete the handle
when they are freed. This will cause a crash when the second bitmap is
trying to delete the palette. A way to get around this is to set the
palette handle property of these bitmaps to 0 before freeing the bitmap.

Wim

Re:Bitmap / Palette Problems


Quote
In article <01bd8fdc$288dca40$2584989e@tecra>, "Jason Hankin" <ja...@nospamlightwrk.demon.co.uk> wrote:
>I can't have more than one 256 color bitmap on A 256 color screen without
>having major palette clashes.

>What I really want to do is have a CoolBar with a 256 color background, and
>buttons with 256 color glyphs on them. Ideally I'd get these bitmaps from a
>resource file, but that's not critical. I know the problem was with
>palettes, so I've recreated all my bitmaps, with the same palette, but
>still I have massive clashes.

>Has anyone ever actually cracked this one ??

Yes, I have an app using many bitmaps with a matched 256 colour palette...it
took some hacking but I got it to work in the end! (see the VAZ page on my
site for the proof). I don't have the code to hand here at work, but I'll try
to get the info sorted and posted asap.

Martin

  man(i)kin / 3 track demo now available on mp3
+------------------------------------------------+
| Email: martin....@umist.ac.uk                  |
| Web: http://www.cp.umist.ac.uk/users/martin/   |
+------------------------------------------------+
| See web site for:                              |
| VAZ: Vurtual Analogue Synth Emulator           |
| Demos on mp3: man(i)kin, Curious Yellow        |
+------------------------------------------------+

Other Threads