From e91d77f6aaebeb4de8601c8013fdc5525325683e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 14 Jun 2004 22:27:16 +0000 Subject: [PATCH] RageDisplay base no longer needs SDL --- stepmania/src/RageDisplay.cpp | 58 +++++++++++++++------------------- stepmania/src/SDL_SaveJPEG.cpp | 21 ++++++------ stepmania/src/SDL_SaveJPEG.h | 3 +- 3 files changed, 39 insertions(+), 43 deletions(-) diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index 16c01567e7..3780dbf6c6 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -5,9 +5,9 @@ #include "RageMath.h" #include "RageUtil.h" #include "GameConstantsAndTypes.h" -#include "SDL_utils.h" #include "RageFile.h" #include "SDL_SaveJPEG.h" +#include "RageSurface_Save_BMP.h" #include "SDL_rotozoom.h" #include "RageSurface.h" @@ -633,42 +633,12 @@ bool RageDisplay::SaveScreenshot( CString sPath, GraphicsFileFormat format ) { 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, * 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. */ if( format != SAVE_LOSSLESS && (surface->h != 640 || surface->w != 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; if( !out.Open( sPath, RageFile::WRITE ) ) { @@ -676,7 +646,31 @@ bool RageDisplay::SaveScreenshot( CString sPath, GraphicsFileFormat format ) 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; } diff --git a/stepmania/src/SDL_SaveJPEG.cpp b/stepmania/src/SDL_SaveJPEG.cpp index 2f48403ece..057db86c47 100644 --- a/stepmania/src/SDL_SaveJPEG.cpp +++ b/stepmania/src/SDL_SaveJPEG.cpp @@ -1,8 +1,8 @@ #include "global.h" #include "RageSurface.h" #include "RageSurfaceUtils.h" -#include "SDL_utils.h" #include "RageUtil.h" +#include "RageFile.h" #undef FAR /* fix for VC */ namespace jpeg @@ -30,7 +30,7 @@ typedef struct { struct jpeg::jpeg_destination_mgr pub; - SDL_RWops *ctx; + RageFile *f; uint8_t buffer[OUTPUT_BUFFER_SIZE]; } 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 ) { my_destination_mgr * dest = (my_destination_mgr *) cinfo->dest; - int nbytes; - - nbytes = SDL_RWwrite( dest->ctx, dest->buffer, 1, OUTPUT_BUFFER_SIZE ); + int nbytes = dest->f->Write( dest->buffer, OUTPUT_BUFFER_SIZE ); + // XXX err dest->pub.next_output_byte = dest->buffer; 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 */ 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.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 * 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 ); @@ -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.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. */ -void IMG_SaveJPG_RW( RageSurface *surface, SDL_RWops *dest, bool bHighQual ) +bool IMG_SaveJPG_RW( RageSurface *surface, RageFile &f, bool bHighQual ) { RageSurface *dst_surface; if( RageSurfaceUtils::ConvertSurface( surface, dst_surface, @@ -127,7 +127,7 @@ void IMG_SaveJPG_RW( RageSurface *surface, SDL_RWops *dest, bool bHighQual ) else jpeg::jpeg_set_quality( &cinfo, 40, TRUE ); - jpeg_SDL_RW_dest( &cinfo, dest ); + jpeg_RageFile_dest( &cinfo, f ); /* Start the compressor. */ 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 ); delete dst_surface; + return true; } /* diff --git a/stepmania/src/SDL_SaveJPEG.h b/stepmania/src/SDL_SaveJPEG.h index d8763e9e36..84e10f42bf 100644 --- a/stepmania/src/SDL_SaveJPEG.h +++ b/stepmania/src/SDL_SaveJPEG.h @@ -2,7 +2,8 @@ #define SDL_SAVE_JPEG_H 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