Fascinating palette behavior...
SiegeLord
        RGB rgb = {1,0,0};
  set_color(1, &rgb);
  int col = palette_color[1];//returns 4!

I have run into a problem running this code, as you can see I set the first color in the palette to RGB(1,0,0) and then I retreive the value from the current palette.

The problem is that instead of returning 1 it returns 4!

Is there a bug here or did I do something wrong?

Sorry if this has been answered before and feel free to direct me to the manual as appropritate ;)...

Fladimir da Gorf

IIRC the palette colors have 6-bit resolution, not full 8-bit so maybe that has something to do with it? If you extend the number one from 0...63 to 0...255, youll get 4.

SiegeLord

Hmm... yes, using get_color() does seem to do the trick of retreiving the correct value(I assume it handles the 6 bit calculations on its own)...

But that is not viable, since the same happens in my actual program. I write to a 8bpp bmp with this color(#1) and then blit it to a 32bpp and get the pixel color, and also get the incorrect color returned (in this case 4)... :-/

Fladimir da Gorf

That's because it simply can't know what the value used to be. No matter what you pass between 1 and 4, you'll get 4 out - the number resolution is reduced.

miran

Yeah, that's just the way palettes work. It's not a bug and you did nothing wrong. Palette colours are taken from a 6 bit colour space (in each component) so rgb = {1, 0, 0} is actually the same as makecol(4,0,0) in 32bpp.

SiegeLord

I see, thanks!

I just ended up writing directly to the palette_color and not using the set_color() function at all...

Kibiz0r

...you wouldn't happen to be Siege_Lord of Clan EotA, would you?

Edit: I just realized that probably should've been a PM. Waste of server space on me.

Thread #587939. Printed from Allegro.cc