View Full Version : pixel level modifications on an SDL_Surface

November 3rd, 2009, 09:00 AM
hi guys,

i'm a newbie using sdl in C++. I did my codes to try to get rgb color components from an 8-bit grayscale image using what was taught here : <html>http://sdl.beuc.net/sdl.wiki/SDL_PixelFormat</html>

However, I keep getting this error: incompatible types in assignment at this line:
color = fmt->palette->colors[index];

My partial code as shown below:

void colorInterpolation(SDL_Surface *s)
SDL_PixelFormat *fmt;
Uint32 temp, pixel;
Uint8 red, green, blue, alpha, index;
SDL_Color *color;


/* Check the bitdepth of the surface */
fprintf(stderr, "Not an 8-bit surface.\n");

/* Get the topleft pixel */
index = *(Uint8 *)s->pixels;
color = fmt->palette->colors[index]; //ERROR : incompatible types in assignment WHY??????

Your advice is highly appreciated!!! thanks! :D

November 3rd, 2009, 11:35 AM
Did you check the return types of what you're trying to assign?

November 3rd, 2009, 12:29 PM
You're getting an SDL_Color type, not a pointer to it (SDL_Color *).

Try redefining your var declaration to "SDL_Color color" or this:

color = &(fmt->palette->colors[index]);

Should be it, but can't check it right now.