Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Palette Color

Credits go to Evert for helping out!
This thread is locked; no one can reply to it. rss feed Print
Palette Color
Onewing
Member #6,152
August 2005
avatar

Okay, common question, but I can not for the life of me connect these dots. I'm in 8-bit color depth and I've got a palette of 256 colors. I thought I could use makecol8 to produce one of the palette colors, but maybe I'm doing something wrong. Here, take a look at the following code:

for(int h = 0; h < 256 ; h++)
{
  
      rectfill(buffer, buffer->w/2, h*2, buffer->w, h*2+2, palette_color[h]);
  get_color(h,test);
      rectfill(buffer, 0, h*2, buffer->w/2, h*2+2, makecol8(test->r,test->g,test->b));
    
}

That bit of code produces:
{"name":"591294","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/b\/0bb82e44a178f8d74de189e7e1ac2761.jpg","w":643,"h":481,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/b\/0bb82e44a178f8d74de189e7e1ac2761"}591294

The colors on the right are the correct colors from the palette. And lastly, what I ultimately want to do is to be able to pull a pixel from the bitmap and say it is # of the palette. I'm missing something, because all my logic/study has just led me in the circles, after reading (misinterpreting?) the manual for quite some time.

[edit]
No progress, other than I found out I could just use h instead of palette_color[h]. It seems the problem with makecol8 is it doesn't use the vga (0-63) colors like I thought it did. I guess in the end, you have to convert them? I'm confused.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Evert
Member #794
November 2000
avatar

Quote:

And lastly, what I ultimately want to do is to be able to pull a pixel from the bitmap and say it is # of the palette.

That's what getpixel does. Am I missing something?

Quote:

It seems the problem with makecol8 is it doesn't use the vga (0-63) colors like I thought it did.

As per the manual, makecol8 takes RGB values in the range 0-255.

Onewing
Member #6,152
August 2005
avatar

My bad, must've been a long day. The problem was I believed there was some connection between palettes and using makecol.

Quote:

That's what getpixel does. Am I missing something?

I've been in 32 bit for so long I was used to getpixel pulling a number that was more abstract (don't take me literally here), for lack of better terms. However, logically it makes since considering I'm in 8bit mode now. I was taking it a step at a time, and since I couldn't get makecol to work, I didn't think getpixel would work. So I spent all my time trying to figure out what the difference was there.

Quote:

As per the manual, makecol8 takes RGB values in the range 0-255.

Not so plainly though, nor directly under makecol8. In fact, you have to go to makecol32:

manual said:

These functions convert colors from a hardware independent form (red, green, and blue values ranging 0-255) into various display dependent pixel formats.

And even "these functions" is a little...vague.

And maybe I missed it somewhere, but the manual doesn't ever seem to say, "this is how you use those colors you set up in your palette."

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Evert
Member #794
November 2000
avatar

Quote:

I've been in 32 bit for so long I was used to getpixel pulling a number that was more abstract (don't take me literally here), for lack of better terms. However, logically it makes since considering I'm in 8bit mode now.

Well, what it does is give you the colour value. In high/true colour mode, this is an RGB value. In 8 bit mode, the colour is the index in the palette (that's alwo why palette_color[n]=n in 8 bit mode; it's the converted RGB value in high/true colour mode).

Quote:

Not so plainly though, nor directly under makecol8. In fact, you have to go to makecol32:

No I don't:

man makecol8 said:

makecol8(3) Allegro manual makecol8(3)

NAME
makecol8, makecol15, makecol16, makecol24, makecol32 - Converts an RGB
value into a display dependent pixel format. Allegro game programming
library.

SYNOPSIS
#include <allegro.h>

int makecol8(int r, int g, int b);

int makecol15(int r, int g, int b);

int makecol16(int r, int g, int b);

int makecol24(int r, int g, int b);

int makecol32(int r, int g, int b);
DESCRIPTION
These functions convert colors from a hardware independent form (red,
green, and blue values ranging 0-255) into various display dependent
pixel formats. Converting to 15, 16, 24, or 32-bit formats only takes a
few shifts, so it is fairly efficient. Converting to an 8-bit color
involves searching the palette to find the closest match, which is
quite slow unless you have set up an RGB mapping table (see below).
Example:

/* 16 bit color version of green. */
int green_color = makecol16(0, 255, 0);

RETURN VALUE
Returns the requested RGB triplet in the specified color depth.

Or, http://alleg.sourceforge.net/stabledocs/en/alleg012.html#makecol8

Quote:

And maybe I missed it somewhere, but the manual doesn't ever seem to say, "this is how you use those colors you set up in your palette."

There's nothing to say. It's no different from how you would use a colour in any other colour depth. Maybe I don't understand what you don't understand though...

Onewing
Member #6,152
August 2005
avatar

Quote:

No I don't:

Well, um, you do if you use the manual on a.cc, which is what I've been using.

Quote:

Maybe I don't understand what you don't understand though...

Oh, I'm sure you don't understand most of what I don't understand, which is quite understandable.

Anywho, who it all makes sense now and very logically, computer-wise that is. I look back now and I don't even really remember what I was having a problem with.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Evert
Member #794
November 2000
avatar

Quote:

Well, um, you do if you use the manual on a.cc, which is what I've been using.

Ah, right! I forgot that the A.cc copy of the manual doesn't deal well with multiple functions grouped together in one heading.
It isn't the manual though. ;)

Go to: