simplify screenshot flip; do it in-place

output 32-bit RGBX; 32-bit formats are generally preferable to 24-bit ones
This commit is contained in:
Glenn Maynard
2004-05-19 00:27:48 +00:00
parent f10b524a99
commit 2b8374e61e
+13 -15
View File
@@ -820,28 +820,26 @@ SDL_Surface* RageDisplay_OGL::CreateScreenshot()
int width = wind->GetVideoModeParams().width; int width = wind->GetVideoModeParams().width;
int height = wind->GetVideoModeParams().height; int height = wind->GetVideoModeParams().height;
const PixelFormatDesc &desc = PIXEL_FORMAT_DESC[FMT_RGB8]; const PixelFormatDesc &desc = PIXEL_FORMAT_DESC[FMT_RGBA8];
SDL_Surface *image = SDL_CreateRGBSurfaceSane( SDL_Surface *image = SDL_CreateRGBSurfaceSane(
SDL_SWSURFACE, width, height, SDL_SWSURFACE, width, height,
desc.bpp, desc.masks[0], desc.masks[1], desc.masks[2], desc.masks[3] ); desc.bpp, desc.masks[0], desc.masks[1], desc.masks[2], 0 );
SDL_Surface *temp = SDL_CreateRGBSurfaceSane( glReadPixels(0, 0, wind->GetVideoModeParams().width, wind->GetVideoModeParams().height, GL_RGBA,
SDL_SWSURFACE, width, height,
desc.bpp, desc.masks[0], desc.masks[1], desc.masks[2], desc.masks[3] );
glReadPixels(0, 0, wind->GetVideoModeParams().width, wind->GetVideoModeParams().height, GL_RGB,
GL_UNSIGNED_BYTE, image->pixels); GL_UNSIGNED_BYTE, image->pixels);
// flip vertically // flip vertically
int pitch = image->pitch; int pitch = image->pitch;
for( int y=0; y<wind->GetVideoModeParams().height; y++ ) int bytes_per_row = image->format->BytesPerPixel * width;
memcpy( char *row = new char[bytes_per_row];
(char *)temp->pixels + pitch * y, for( int y=0; y<wind->GetVideoModeParams().height/2; y++ )
(char *)image->pixels + pitch * (height-1-y), {
3*width ); memcpy( row, (char *)image->pixels + pitch * y, bytes_per_row );
SDL_FreeSurface( image ); memcpy( (char *)image->pixels + pitch * y, (char *)image->pixels + pitch * (height-1-y), bytes_per_row );
memcpy( (char *)image->pixels + pitch * (height-1-y), row, bytes_per_row );
return temp; }
delete [] row;
return image;
} }
RageDisplay::VideoModeParams RageDisplay_OGL::GetVideoModeParams() const { return wind->GetVideoModeParams(); } RageDisplay::VideoModeParams RageDisplay_OGL::GetVideoModeParams() const { return wind->GetVideoModeParams(); }