RageDisplay base no longer needs SDL

This commit is contained in:
Glenn Maynard
2004-06-14 22:27:16 +00:00
parent 6c80079f04
commit e91d77f6aa
3 changed files with 39 additions and 43 deletions
+26 -32
View File
@@ -5,9 +5,9 @@
#include "RageMath.h" #include "RageMath.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "GameConstantsAndTypes.h" #include "GameConstantsAndTypes.h"
#include "SDL_utils.h"
#include "RageFile.h" #include "RageFile.h"
#include "SDL_SaveJPEG.h" #include "SDL_SaveJPEG.h"
#include "RageSurface_Save_BMP.h"
#include "SDL_rotozoom.h" #include "SDL_rotozoom.h"
#include "RageSurface.h" #include "RageSurface.h"
@@ -633,42 +633,12 @@ bool RageDisplay::SaveScreenshot( CString sPath, GraphicsFileFormat format )
{ {
RageSurface* surface = this->CreateScreenshot(); RageSurface* surface = this->CreateScreenshot();
CString buf;
buf.reserve( 1024*1024 );
SDL_RWops rw;
OpenRWops( &rw, &buf );
/* Unless we're in lossless, resize the image to 640x480. If we're saving lossy, /* Unless we're in lossless, resize the image to 640x480. If we're saving lossy,
* there's no sense in saving 1280x960 screenshots, and if we're in a custom * there's no sense in saving 1280x960 screenshots, and if we're in a custom
* resolution (eg. 640x240), we don't want to output in that resolution. */ * resolution (eg. 640x240), we don't want to output in that resolution. */
if( format != SAVE_LOSSLESS && (surface->h != 640 || surface->w != 480) ) if( format != SAVE_LOSSLESS && (surface->h != 640 || surface->w != 480) )
zoomSurface( surface, 640, 480 ); zoomSurface( surface, 640, 480 );
switch( format )
{
case SAVE_LOSSLESS:
{
SDL_Surface *pSDLSurf = SDLSurfaceFromRageSurface( surface );
SDL_SaveBMP_RW( pSDLSurf, &rw, false );
delete pSDLSurf;
break;
}
case SAVE_LOSSY_LOW_QUAL:
IMG_SaveJPG_RW( surface, &rw, false );
case SAVE_LOSSY_HIGH_QUAL:
IMG_SaveJPG_RW( surface, &rw, true );
break;
default:
ASSERT(0);
return false;
}
SDL_RWclose( &rw );
delete surface;
surface = NULL;
RageFile out; RageFile out;
if( !out.Open( sPath, RageFile::WRITE ) ) if( !out.Open( sPath, RageFile::WRITE ) )
{ {
@@ -676,7 +646,31 @@ bool RageDisplay::SaveScreenshot( CString sPath, GraphicsFileFormat format )
return false; return false;
} }
out.Write( buf ); bool bSuccess = false;
switch( format )
{
case SAVE_LOSSLESS:
bSuccess = RageSurface_Save_BMP( surface, out );
break;
case SAVE_LOSSY_LOW_QUAL:
bSuccess = IMG_SaveJPG_RW( surface, out, false );
break;
case SAVE_LOSSY_HIGH_QUAL:
bSuccess = IMG_SaveJPG_RW( surface, out, true );
break;
default:
ASSERT(0);
return false;
}
delete surface;
surface = NULL;
if( !bSuccess )
{
LOG->Trace("Couldn't write %s: %s", sPath.c_str(), out.GetError().c_str() );
return false;
}
return true; return true;
} }
+11 -10
View File
@@ -1,8 +1,8 @@
#include "global.h" #include "global.h"
#include "RageSurface.h" #include "RageSurface.h"
#include "RageSurfaceUtils.h" #include "RageSurfaceUtils.h"
#include "SDL_utils.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "RageFile.h"
#undef FAR /* fix for VC */ #undef FAR /* fix for VC */
namespace jpeg namespace jpeg
@@ -30,7 +30,7 @@ typedef struct
{ {
struct jpeg::jpeg_destination_mgr pub; struct jpeg::jpeg_destination_mgr pub;
SDL_RWops *ctx; RageFile *f;
uint8_t buffer[OUTPUT_BUFFER_SIZE]; uint8_t buffer[OUTPUT_BUFFER_SIZE];
} my_destination_mgr; } my_destination_mgr;
@@ -49,9 +49,8 @@ static void init_destination( jpeg::j_compress_ptr cinfo )
static jpeg::boolean empty_output_buffer( jpeg::j_compress_ptr cinfo ) static jpeg::boolean empty_output_buffer( jpeg::j_compress_ptr cinfo )
{ {
my_destination_mgr * dest = (my_destination_mgr *) cinfo->dest; my_destination_mgr * dest = (my_destination_mgr *) cinfo->dest;
int nbytes; int nbytes = dest->f->Write( dest->buffer, OUTPUT_BUFFER_SIZE );
// XXX err
nbytes = SDL_RWwrite( dest->ctx, dest->buffer, 1, OUTPUT_BUFFER_SIZE );
dest->pub.next_output_byte = dest->buffer; dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUFFER_SIZE; dest->pub.free_in_buffer = OUTPUT_BUFFER_SIZE;
@@ -67,7 +66,8 @@ static void term_destination (jpeg::j_compress_ptr cinfo)
{ {
/* Write data remaining in the buffer */ /* Write data remaining in the buffer */
my_destination_mgr *dest = (my_destination_mgr *) cinfo->dest; my_destination_mgr *dest = (my_destination_mgr *) cinfo->dest;
SDL_RWwrite(dest->ctx, dest->buffer, 1, OUTPUT_BUFFER_SIZE - dest->pub.free_in_buffer); int wrote = dest->f->Write( dest->buffer, OUTPUT_BUFFER_SIZE - dest->pub.free_in_buffer );
// XXX err
dest->pub.next_output_byte = dest->buffer; dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUFFER_SIZE; dest->pub.free_in_buffer = OUTPUT_BUFFER_SIZE;
} }
@@ -77,7 +77,7 @@ static void term_destination (jpeg::j_compress_ptr cinfo)
* The caller must have already opened the stream, and is responsible * The caller must have already opened the stream, and is responsible
* for closing it after finishing decompression. * for closing it after finishing decompression.
*/ */
static void jpeg_SDL_RW_dest( jpeg::j_compress_ptr cinfo, SDL_RWops *ctx ) static void jpeg_RageFile_dest( jpeg::j_compress_ptr cinfo, RageFile &f )
{ {
ASSERT( cinfo->dest == NULL ); ASSERT( cinfo->dest == NULL );
@@ -92,11 +92,11 @@ static void jpeg_SDL_RW_dest( jpeg::j_compress_ptr cinfo, SDL_RWops *ctx )
dest->pub.free_in_buffer = OUTPUT_BUFFER_SIZE; /* forces fill_input_buffer on first read */ dest->pub.free_in_buffer = OUTPUT_BUFFER_SIZE; /* forces fill_input_buffer on first read */
dest->pub.next_output_byte = dest->buffer; /* until buffer loaded */ dest->pub.next_output_byte = dest->buffer; /* until buffer loaded */
dest->ctx = ctx; dest->f = &f;
} }
/* Save a JPEG to a file. cjpeg.c and example.c from jpeglib were helpful in writing this. */ /* Save a JPEG to a file. cjpeg.c and example.c from jpeglib were helpful in writing this. */
void IMG_SaveJPG_RW( RageSurface *surface, SDL_RWops *dest, bool bHighQual ) bool IMG_SaveJPG_RW( RageSurface *surface, RageFile &f, bool bHighQual )
{ {
RageSurface *dst_surface; RageSurface *dst_surface;
if( RageSurfaceUtils::ConvertSurface( surface, dst_surface, if( RageSurfaceUtils::ConvertSurface( surface, dst_surface,
@@ -127,7 +127,7 @@ void IMG_SaveJPG_RW( RageSurface *surface, SDL_RWops *dest, bool bHighQual )
else else
jpeg::jpeg_set_quality( &cinfo, 40, TRUE ); jpeg::jpeg_set_quality( &cinfo, 40, TRUE );
jpeg_SDL_RW_dest( &cinfo, dest ); jpeg_RageFile_dest( &cinfo, f );
/* Start the compressor. */ /* Start the compressor. */
jpeg::jpeg_start_compress( &cinfo, TRUE ); jpeg::jpeg_start_compress( &cinfo, TRUE );
@@ -152,6 +152,7 @@ void IMG_SaveJPG_RW( RageSurface *surface, SDL_RWops *dest, bool bHighQual )
jpeg::jpeg_destroy_compress( &cinfo ); jpeg::jpeg_destroy_compress( &cinfo );
delete dst_surface; delete dst_surface;
return true;
} }
/* /*
+2 -1
View File
@@ -2,7 +2,8 @@
#define SDL_SAVE_JPEG_H #define SDL_SAVE_JPEG_H
struct RageSurface; struct RageSurface;
void IMG_SaveJPG_RW( RageSurface *surface, SDL_RWops *dest, bool bHighQual=true ); class RageFile;
bool IMG_SaveJPG_RW( RageSurface *surface, RageFile &f, bool bHighQual=true );
#endif #endif