Skip to main content
GameDev.net gamedev.net
🔒 Locked

Getting SDL_Surface Pixel Values

Started by Calamari Nov 5, 2004 at 11:15 AM 1 replies 1.1k views
Original Post
Calamari
Calamari
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
TravisWells
TravisWells
 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);
Calamari
Calamari
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.