Hi,
The documentation for SDL_PixelFormat describes how to convert 8-bit pixel
formats into the associated red, green, and blue colors like so:
SDL_Surface *surface;
SDL_PixelFormat *fmt;
SDL_Color *color;
Uint8 index;
.
.
/* Create surface */
.
.
fmt=surface->format;
/* Check the bitdepth of the surface */
if(fmt->BitsPerPixel!=8){
fprintf(stderr, “Not an 8-bit surface.\n”);
return(-1);
}
/* Lock the surface */
SDL_LockSurface(surface);
/* Get the topleft pixel /
index=(Uint8 *)surface->pixels;
color=fmt->palette->colors[index];
/* Unlock the surface */
SDL_UnlockSurface(surface);
printf(“Pixel Color-> Red: %d, Green: %d, Blue: %d. Index: %d\n”,
color->r, color->g, color->b, index);
I believe that the variable “color” here has been declared incorrectly as
a pointer when it should be an object, i.e.,
SDL_Color *color;
should read
SDL_Color color;
At least, that’s what worked on my compiler (g++ v. 3.2). This is a quick
correction, but it might as well be included in CVS.
Cheers,
Curtis