simplify OpenRWops, fix error handling
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include "RageSurface_Load_JPEG.h"
|
#include "RageSurface_Load_JPEG.h"
|
||||||
#include "RageSurface_Load_GIF.h"
|
#include "RageSurface_Load_GIF.h"
|
||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
|
#include "RageFile.h"
|
||||||
|
|
||||||
SDL_Surface *RageSurface::LoadFile( const CString &sPath )
|
SDL_Surface *RageSurface::LoadFile( const CString &sPath )
|
||||||
{
|
{
|
||||||
@@ -19,17 +20,17 @@ SDL_Surface *RageSurface::LoadFile( const CString &sPath )
|
|||||||
ret = RageSurface_Load_JPEG( sPath, error );
|
ret = RageSurface_Load_JPEG( sPath, error );
|
||||||
else if( !ext.CompareNoCase("bmp") )
|
else if( !ext.CompareNoCase("bmp") )
|
||||||
{
|
{
|
||||||
SDL_RWops *rw = OpenRWops( sPath, false );
|
RageFile f;
|
||||||
if( rw == NULL )
|
if( !f.Open(sPath) )
|
||||||
{
|
{
|
||||||
/* XXX */
|
SDL_SetError( "%s", f.GetError() );
|
||||||
SDL_SetError( "fail" );
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SDL_LoadBMP_RW( rw, false );
|
SDL_RWops rw;
|
||||||
SDL_RWclose( rw );
|
OpenRWops( &rw, &f );
|
||||||
SDL_FreeRW( rw );
|
ret = SDL_LoadBMP_RW( &rw, false );
|
||||||
|
SDL_RWclose( &rw );
|
||||||
|
|
||||||
if( ret )
|
if( ret )
|
||||||
mySDL_FixupPalettedAlpha( ret );
|
mySDL_FixupPalettedAlpha( ret );
|
||||||
|
|||||||
@@ -1018,30 +1018,16 @@ int RWRageFile_Write( struct SDL_RWops *context, const void *ptr, int size, int
|
|||||||
/* Close and free an allocated SDL_FSops structure */
|
/* Close and free an allocated SDL_FSops structure */
|
||||||
int RWRageFile_Close(struct SDL_RWops *context)
|
int RWRageFile_Close(struct SDL_RWops *context)
|
||||||
{
|
{
|
||||||
RageFile *f = (RageFile *) context->hidden.unknown.data1;
|
|
||||||
delete f;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RWops *OpenRWops( const CString &sPath, bool Write )
|
void OpenRWops( SDL_RWops *rw, RageFile *f )
|
||||||
{
|
{
|
||||||
RageFile *f = new RageFile;
|
|
||||||
if( !f->Open(sPath, Write? RageFile::WRITE:RageFile::READ) )
|
|
||||||
{
|
|
||||||
LOG->Trace("Couldn't open %s: %s", sPath.c_str(), f->GetError().c_str() );
|
|
||||||
delete f;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_RWops *rw = SDL_AllocRW();
|
|
||||||
ASSERT( rw );
|
|
||||||
rw->hidden.unknown.data1 = f;
|
rw->hidden.unknown.data1 = f;
|
||||||
rw->seek = RWRageFile_Seek;
|
rw->seek = RWRageFile_Seek;
|
||||||
rw->read = RWRageFile_Read;
|
rw->read = RWRageFile_Read;
|
||||||
rw->write = RWRageFile_Write;
|
rw->write = RWRageFile_Write;
|
||||||
rw->close = RWRageFile_Close;
|
rw->close = RWRageFile_Close;
|
||||||
|
|
||||||
return rw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RWString
|
struct RWString
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ void mySDL_FixupPalettedAlpha( SDL_Surface *img );
|
|||||||
void mySDL_AddColorKey( SDL_Surface *img, Uint32 color );
|
void mySDL_AddColorKey( SDL_Surface *img, Uint32 color );
|
||||||
void ApplyHotPinkColorKey( SDL_Surface *&img );
|
void ApplyHotPinkColorKey( SDL_Surface *&img );
|
||||||
|
|
||||||
SDL_RWops *OpenRWops( const CString &sPath, bool Write=false );
|
class RageFile;
|
||||||
|
void OpenRWops( SDL_RWops *rw, RageFile *f );
|
||||||
SDL_RWops *OpenRWops( CString &sBuf );
|
SDL_RWops *OpenRWops( CString &sBuf );
|
||||||
SDL_Surface *mySDL_MakeDummySurface( int height, int width );
|
SDL_Surface *mySDL_MakeDummySurface( int height, int width );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user