document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. SDL_Surface* CSurface::RGB2Sepia( SDL_Surface* Surf_Src){
  2.  
  3. if(Surf_Src == NULL) { //verify if source surface exists
  4.     return NULL;
  5. }
  6.  
  7. SDL_Surface* Surf_Dest = NULL;
  8.  
  9.  
  10. Surf_Dest = SDL_DisplayFormatAlpha(Surf_Src);
  11.  
  12. if(Surf_Dest == NULL) { //verify if temporary surface exists
  13.     return NULL;
  14. }
  15.  
  16. Uint8 R, G, B, A;
  17. Uint32* srcpixels = (Uint32 *)Surf_Src->pixels;;
  18. Uint32* dstpixels = (Uint32 *)Surf_Dest->pixels;
  19. uint Rintensity, Gintensity, Bintensity;
  20.  
  21. for(uint y = 0; y != Surf_Src->h; y++){
  22.  
  23.     for(uint x = 0; x != Surf_Src->w ; x++){
  24.  
  25.         SDL_GetRGBA(srcpixels[ ( y * Surf_Src->w ) + x ],Surf_Src->format, &R, &G, &B, &A);
  26.  
  27.         Rintensity = (R * 0.393) + (G * 0.769) + (B * 0.189);
  28.  
  29.         if ( Rintensity > 255 ) Rintensity = 255;
  30.  
  31.         Gintensity = (R * 0.349) + (G * 0.686) + (B * 0.168);
  32.  
  33.         if ( Gintensity > 255 ) Gintensity = 255;
  34.  
  35.         Bintensity = (R * 0.272) + (G * 0.534) + (B * 0.131);
  36.  
  37.         if ( Bintensity > 255 ) Bintensity = 255;
  38.  
  39.     dstpixels[ ( y * Surf_Src->w ) + x ] = SDL_MapRGBA(Surf_Dest->format, Rintensity, Gintensity,   Bintensity, A);
  40.     }
  41. }
  42.  
  43. return Surf_Dest;
  44. }
');