Advertisement

Getting SDL_Surface Pixel Values

Started by November 05, 2004 11:15 AM
1 comment, last by Calamari 19 years, 10 months ago
Hi, I'll like to get the RGB (and eventually A) values of an SDL Surface. I keep getting a segementation error. Here's the Code: void CSprite::getpixel(int x, int y) { SDL_LockSurface( State[mframe].image ); char * pData; pData = (char*)State[mframe].image->pixels; pData+=(y*State[mframe].image->pitch); pData+=(x*State[mframe].image->format->BytesPerPixel); SDL_PixelFormat *fmt = State[mframe].image->format; Uint8 *lr, *lg, *lb; //-- Craps out here Uint32 pixel = *(Uint32 *)pData; SDL_GetRGB(pixel, fmt, lr, lg, lb); SDL_UnlockSurface( State[mframe].image ); } Can anyone help me? Thanks in advance
 Uint8 *lr, *lg, *lb;//-- Craps out hereUint32 pixel = *(Uint32 *)pData;SDL_GetRGB(pixel, fmt, lr, lg, lb);


lr,lg,and lb are pointers to nowhere, the SDL_GetRGB call is writing to random memory. Try this:
 Uint8 lr, lg, lb;Uint32 pixel = *(Uint32 *)pData;SDL_GetRGB(pixel, fmt, &lr, ≶, &lb);
Advertisement
no luck, i got a different error when i tried that. But perhaps it's more accurate to say that th code seems to crap out at this line:

Uint32 pixel = *(Uint32 *)pData;

Could it the conversion?

This topic is closed to new replies.

Advertisement