Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SDL_Surface* CSurface::RGB2Sepia( SDL_Surface* Surf_Src){
- if(Surf_Src == NULL) { //verify if source surface exists
- return NULL;
- }
- SDL_Surface* Surf_Dest = NULL;
- Surf_Dest = SDL_DisplayFormatAlpha(Surf_Src);
- if(Surf_Dest == NULL) { //verify if temporary surface exists
- return NULL;
- }
- Uint8 R, G, B, A;
- Uint32* srcpixels = (Uint32 *)Surf_Src->pixels;;
- Uint32* dstpixels = (Uint32 *)Surf_Dest->pixels;
- uint Rintensity, Gintensity, Bintensity;
- for(uint y = 0; y != Surf_Src->h; y++){
- for(uint x = 0; x != Surf_Src->w ; x++){
- SDL_GetRGBA(srcpixels[ ( y * Surf_Src->w ) + x ],Surf_Src->format, &R, &G, &B, &A);
- Rintensity = (R * 0.393) + (G * 0.769) + (B * 0.189);
- if ( Rintensity > 255 ) Rintensity = 255;
- Gintensity = (R * 0.349) + (G * 0.686) + (B * 0.168);
- if ( Gintensity > 255 ) Gintensity = 255;
- Bintensity = (R * 0.272) + (G * 0.534) + (B * 0.131);
- if ( Bintensity > 255 ) Bintensity = 255;
- dstpixels[ ( y * Surf_Src->w ) + x ] = SDL_MapRGBA(Surf_Dest->format, Rintensity, Gintensity, Bintensity, A);
- }
- }
- return Surf_Dest;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement