use SDL_LoadImage in mySDL_SaveSurface, mySDL_LoadSurface
This commit is contained in:
+11
-20
@@ -545,8 +545,8 @@ struct SurfaceHeader
|
|||||||
/* Save and load SDL_Surfaces to disk. This avoids problems with bitmaps. */
|
/* Save and load SDL_Surfaces to disk. This avoids problems with bitmaps. */
|
||||||
bool mySDL_SaveSurface( SDL_Surface *img, CString file )
|
bool mySDL_SaveSurface( SDL_Surface *img, CString file )
|
||||||
{
|
{
|
||||||
FILE *f = fopen(file.c_str(), "wb+");
|
RageFile f;
|
||||||
if(f == NULL)
|
if( !f.Open( file, RageFile::WRITE ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SurfaceHeader h;
|
SurfaceHeader h;
|
||||||
@@ -570,37 +570,30 @@ bool mySDL_SaveSurface( SDL_Surface *img, CString file )
|
|||||||
h.colorkey = 0;
|
h.colorkey = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite(&h, sizeof(h), 1, f);
|
f.Write( &h, sizeof(h) );
|
||||||
|
|
||||||
if(h.bpp == 8)
|
if(h.bpp == 8)
|
||||||
fwrite(img->format->palette->colors, 256 * sizeof(SDL_Color), 1, f);
|
f.Write( img->format->palette->colors, 256 * sizeof(SDL_Color) );
|
||||||
|
|
||||||
fwrite(img->pixels, img->h * img->pitch, 1, f);
|
f.Write( img->pixels, img->h * img->pitch );
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface *mySDL_LoadSurface( CString file )
|
SDL_Surface *mySDL_LoadSurface( CString file )
|
||||||
{
|
{
|
||||||
FILE *f = fopen(file.c_str(), "rb");
|
RageFile f;
|
||||||
if(f == NULL)
|
if( !f.Open( file ) )
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
SurfaceHeader h;
|
SurfaceHeader h;
|
||||||
if( fread(&h, sizeof(h), 1, f) != 1 )
|
if( f.Read( &h, sizeof(h) ) != sizeof(h) )
|
||||||
{
|
|
||||||
fclose(f);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Color palette[256];
|
SDL_Color palette[256];
|
||||||
if(h.bpp == 8)
|
if(h.bpp == 8)
|
||||||
if( fread(palette, 256 * sizeof(SDL_Color), 1, f) != 1 )
|
if( f.Read( palette, 256 * sizeof(SDL_Color) != 256 * sizeof(SDL_Color) ) )
|
||||||
{
|
|
||||||
fclose(f);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the surface. */
|
/* Create the surface. */
|
||||||
SDL_Surface *img = SDL_CreateRGBSurface(
|
SDL_Surface *img = SDL_CreateRGBSurface(
|
||||||
@@ -608,9 +601,8 @@ SDL_Surface *mySDL_LoadSurface( CString file )
|
|||||||
h.Rmask, h.Gmask, h.Bmask, h.Amask);
|
h.Rmask, h.Gmask, h.Bmask, h.Amask);
|
||||||
ASSERT( h.pitch == img->pitch );
|
ASSERT( h.pitch == img->pitch );
|
||||||
|
|
||||||
if( fread(img->pixels, h.height * h.pitch, 1, f) != 1 )
|
if( f.Read( img->pixels, h.height * h.pitch ) != h.height * h.pitch )
|
||||||
{
|
{
|
||||||
fclose(f);
|
|
||||||
SDL_FreeSurface( img );
|
SDL_FreeSurface( img );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -623,7 +615,6 @@ SDL_Surface *mySDL_LoadSurface( CString file )
|
|||||||
SDL_SetColorKey( img, SDL_SRCCOLORKEY, h.colorkey );
|
SDL_SetColorKey( img, SDL_SRCCOLORKEY, h.colorkey );
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user