Below is my code snippet.
SDL_Surface *load_image( )
{
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = SDL_LoadBMP("ori.bmp");
if( loadedImage != NULL )
{
optimizedImage = SDL_DisplayFormat( loadedImage );
SDL_FreeSurface( loadedImage );
if( optimizedImage != NULL )
{
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
}
}
return optimizedImage;
}
SDL_Surface *operate( SDL_Surface *original )
{
SDL_Surface *operation = NULL;
if( SDL_SRCCOLORKEY )
{
operation = SDL_CreateRGBSurface( SDL_SWSURFACE, operation ->w, operation->h, operation->format->BitsPerPixel, operation->format->Rmask, surface->format->Gmask, surface->format->Bmask, 0 );
}
else
{
operation = SDL_CreateRGBSurface( SDL_SWSURFACE, operation->w, operation->h, operation->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask );
}
if( SDL_MUSTLOCK( operation ) )
{
SDL_LockSurface( operation );
}
for( int x = 0; x <operation ->w; x++)
{
//Go through rows
for( int y = 0; y < operation ->h; y++)
{
//Get pixel
}
}
//Unlock surface
if( SDL_MUSTLOCK( operation) )
{
SDL_UnlockSurface( operation);
}
//Copy color key
if( SDL_SRCCOLORKEY )
{
SDL_SetColorKey( flipped, SDL_RLEACCEL | SDL_SRCCOLORKEY, orignal->format->colorkey );
}
//Return flipped surface
return operation ;
}