Color Palette - Clueless!

Started by
1 comment, last by Patrick_ 16 years, 1 month ago
Hey guys. I'm trying to save an image from raw pixels (specifically, those taken from a GdkPixbuf) as a GIF, using GIFLIB. All is well... the image is fine, except for one thing: the colors are _totally_ off. Black is white, white is black, gray is purple, etc. I know my problem lies in my ColorMapObject -- which is basically a colorpalette, something like:
struct ColorMapObject {
   int size;
   int bits_per_pixel;
   colorPalette *palette;
}
Where colorPalette is a structure array, which has Red, Green, and Blue set as a byte value, one for each color (so there'd be 256 RGB values for 256 colors). I'm sure you guys know how to do this: how can I create a color palette that will just "look right", for any image? I'm totally clueless. I'm going to be saving screenshots, so I guess it needs to match the system color palette? I'd like also to be able to specify the number of colors (256, 2 for monochrome, etc). Any help would be much appreciated. Thanks. :)
Advertisement
Does your application use a 8-bit screen format? If so, it looks like you didn't write your screen's palette in the file.
Yes it does use an 8-bit screen format. The problem is, I don't know how to get my screen's palette, and convert it to a certain color depth when I want (like 256 colors, 16 colors, etc). I don't think GTK/GDK offers this option, because I've asked on the mailing list and IRC channel and no-one seems to be able to answer.

Funny thing is, I was able to do:

int x = 0;for (x = 0; x < 256; ++x) {   color_map[x].red = (unsigned char)x;   color_map[x].green = (unsigned char)x;   color_map[x].blue = (unsigned char)x;}


When I give that to giflib, the screenshot is in grayscale. :D

This topic is closed to new replies.

Advertisement