Skip to main content
deleted 2111 characters in body
Source Link
biz14
  • 115
  • 1
  • 5

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 ;
}

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 ;
}
deleted 610 characters in body
Source Link
biz14
  • 115
  • 1
  • 5
    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
            int source_color  = get_pixel32( surface, x, y );

            const unsigned int component1 = source_color & 0xff; // red or blue
const unsigned int component2 = (source_color >> 8) & 0xff; // green
const unsigned int component3 = (source_color >> 16) & 0xff; // blue or red
            
            // calculating the average component/color (i.e. grayscale)
const unsigned int gray = (component1 + component2 + component3) / 3;

// back to SDL's RGB color (optional)
const int gray_rgb = 0xff000000 | (gray << 16) | (gray << 8) | gray;
            put_pixel32( flipped, x, y, gray_rgb );
        
        }
    }

    //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 ;
}
    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
            int source_color  = get_pixel32( surface, x, y );

            const unsigned int component1 = source_color & 0xff; // red or blue
const unsigned int component2 = (source_color >> 8) & 0xff; // green
const unsigned int component3 = (source_color >> 16) & 0xff; // blue or red
            
            // calculating the average component/color (i.e. grayscale)
const unsigned int gray = (component1 + component2 + component3) / 3;

// back to SDL's RGB color (optional)
const int gray_rgb = 0xff000000 | (gray << 16) | (gray << 8) | gray;
            put_pixel32( flipped, x, y, gray_rgb );
        
        }
    }

    //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 ;
}
    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 ;
}
added 2725 characters in body
Source Link
biz14
  • 115
  • 1
  • 5

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
            int source_color  = get_pixel32( surface, x, y );

            const unsigned int component1 = source_color & 0xff; // red or blue
const unsigned int component2 = (source_color >> 8) & 0xff; // green
const unsigned int component3 = (source_color >> 16) & 0xff; // blue or red
            
            // calculating the average component/color (i.e. grayscale)
const unsigned int gray = (component1 + component2 + component3) / 3;

// back to SDL's RGB color (optional)
const int gray_rgb = 0xff000000 | (gray << 16) | (gray << 8) | gray;
            put_pixel32( flipped, x, y, gray_rgb );
        
        }
    }

    //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 ;
}

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
            int source_color  = get_pixel32( surface, x, y );

            const unsigned int component1 = source_color & 0xff; // red or blue
const unsigned int component2 = (source_color >> 8) & 0xff; // green
const unsigned int component3 = (source_color >> 16) & 0xff; // blue or red
            
            // calculating the average component/color (i.e. grayscale)
const unsigned int gray = (component1 + component2 + component3) / 3;

// back to SDL's RGB color (optional)
const int gray_rgb = 0xff000000 | (gray << 16) | (gray << 8) | gray;
            put_pixel32( flipped, x, y, gray_rgb );
        
        }
    }

    //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 ;
}
Source Link
biz14
  • 115
  • 1
  • 5
Loading