SDL: Simplify code for taking screenshots
This commit is contained in:
parent
6f575e580c
commit
a55ea5d152
1 changed files with 19 additions and 54 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include "common/textconsole.h"
|
#include "common/textconsole.h"
|
||||||
#include "common/translation.h"
|
#include "common/translation.h"
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
|
#include "common/file.h"
|
||||||
#include "common/frac.h"
|
#include "common/frac.h"
|
||||||
#ifdef USE_RGB_COLOR
|
#ifdef USE_RGB_COLOR
|
||||||
#include "common/list.h"
|
#include "common/list.h"
|
||||||
|
@ -42,8 +43,9 @@
|
||||||
#include "gui/debugger.h"
|
#include "gui/debugger.h"
|
||||||
#include "gui/EventRecorder.h"
|
#include "gui/EventRecorder.h"
|
||||||
#ifdef USE_PNG
|
#ifdef USE_PNG
|
||||||
#include "common/file.h"
|
|
||||||
#include "image/png.h"
|
#include "image/png.h"
|
||||||
|
#else
|
||||||
|
#include "image/bmp.h"
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_TTS
|
#ifdef USE_TTS
|
||||||
#include "common/text-to-speech.h"
|
#include "common/text-to-speech.h"
|
||||||
|
@ -439,11 +441,17 @@ OSystem::TransactionError SurfaceSdlGraphicsManager::endGFXTransaction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Graphics::PixelFormat SurfaceSdlGraphicsManager::convertSDLPixelFormat(SDL_PixelFormat *in) const {
|
Graphics::PixelFormat SurfaceSdlGraphicsManager::convertSDLPixelFormat(SDL_PixelFormat *in) const {
|
||||||
return Graphics::PixelFormat(in->BytesPerPixel,
|
Graphics::PixelFormat out(in->BytesPerPixel,
|
||||||
8 - in->Rloss, 8 - in->Gloss,
|
8 - in->Rloss, 8 - in->Gloss,
|
||||||
8 - in->Bloss, 8 - in->Aloss,
|
8 - in->Bloss, 8 - in->Aloss,
|
||||||
in->Rshift, in->Gshift,
|
in->Rshift, in->Gshift,
|
||||||
in->Bshift, in->Ashift);
|
in->Bshift, in->Ashift);
|
||||||
|
|
||||||
|
// Workaround to SDL not providing an accurate Aloss value on some platforms.
|
||||||
|
if (in->Amask == 0)
|
||||||
|
out.aLoss = 8;
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_RGB_COLOR
|
#ifdef USE_RGB_COLOR
|
||||||
|
@ -548,10 +556,6 @@ void SurfaceSdlGraphicsManager::detectSupportedFormats() {
|
||||||
// Get our currently set hardware format
|
// Get our currently set hardware format
|
||||||
Graphics::PixelFormat hwFormat = convertSDLPixelFormat(_hwScreen->format);
|
Graphics::PixelFormat hwFormat = convertSDLPixelFormat(_hwScreen->format);
|
||||||
|
|
||||||
// Workaround to SDL not providing an accurate Aloss value on Mac OS X.
|
|
||||||
if (_hwScreen->format->Amask == 0)
|
|
||||||
hwFormat.aLoss = 8;
|
|
||||||
|
|
||||||
_supportedFormats.push_back(hwFormat);
|
_supportedFormats.push_back(hwFormat);
|
||||||
|
|
||||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
|
@ -1405,69 +1409,30 @@ bool SurfaceSdlGraphicsManager::saveScreenshot(const Common::String &filename) c
|
||||||
assert(_hwScreen != NULL);
|
assert(_hwScreen != NULL);
|
||||||
|
|
||||||
Common::StackLock lock(_graphicsMutex);
|
Common::StackLock lock(_graphicsMutex);
|
||||||
#ifdef USE_PNG
|
|
||||||
Common::DumpFile out;
|
Common::DumpFile out;
|
||||||
if (!out.open(filename)) {
|
if (!out.open(filename)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
int result = SDL_LockSurface(_hwScreen);
|
||||||
SDL_Surface *rgbScreen = SDL_ConvertSurfaceFormat(_hwScreen, SDL_PIXELFORMAT_RGB24, 0);
|
|
||||||
#else
|
|
||||||
// This block of code was taken mostly as-is from SDL 1.2's SDL_SaveBMP_RW
|
|
||||||
SDL_Surface *rgbScreen = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
|
||||||
_hwScreen->w,
|
|
||||||
_hwScreen->h,
|
|
||||||
24,
|
|
||||||
#ifdef SCUMM_LITTLE_ENDIAN
|
|
||||||
0x0000FF, 0x00FF00, 0xFF0000,
|
|
||||||
#else
|
|
||||||
0xFF0000, 0x00FF00, 0x0000FF,
|
|
||||||
#endif
|
|
||||||
0);
|
|
||||||
if (rgbScreen == nullptr) {
|
|
||||||
warning("Could not create RGB24 surface");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Rect bounds;
|
|
||||||
bounds.x = bounds.y = 0;
|
|
||||||
bounds.w = _hwScreen->w;
|
|
||||||
bounds.h = _hwScreen->h;
|
|
||||||
if (SDL_LowerBlit(_hwScreen, &bounds, rgbScreen, &bounds) < 0) {
|
|
||||||
SDL_FreeSurface(rgbScreen);
|
|
||||||
rgbScreen = nullptr;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (rgbScreen == nullptr) {
|
|
||||||
warning("Could not convert hardware surface to RGB24");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int result = SDL_LockSurface(rgbScreen);
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
warning("Could not lock RGB surface");
|
warning("Could not lock RGB surface");
|
||||||
SDL_FreeSurface(rgbScreen);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SCUMM_LITTLE_ENDIAN
|
Graphics::PixelFormat format = convertSDLPixelFormat(_hwScreen->format);
|
||||||
const Graphics::PixelFormat format(3, 8, 8, 8, 0, 0, 8, 16, 0);
|
|
||||||
#else
|
|
||||||
const Graphics::PixelFormat format(3, 8, 8, 8, 0, 16, 8, 0, 0);
|
|
||||||
#endif
|
|
||||||
Graphics::Surface data;
|
Graphics::Surface data;
|
||||||
data.init(rgbScreen->w, rgbScreen->h, rgbScreen->pitch, rgbScreen->pixels, format);
|
data.init(_hwScreen->w, _hwScreen->h, _hwScreen->pitch, _hwScreen->pixels, format);
|
||||||
|
#ifdef USE_PNG
|
||||||
const bool success = Image::writePNG(out, data);
|
const bool success = Image::writePNG(out, data);
|
||||||
|
#else
|
||||||
|
const bool success = Image::writeBMP(out, data);
|
||||||
|
#endif
|
||||||
|
|
||||||
SDL_UnlockSurface(rgbScreen);
|
SDL_UnlockSurface(_hwScreen);
|
||||||
SDL_FreeSurface(rgbScreen);
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
#else
|
|
||||||
return SDL_SaveBMP(_hwScreen, filename.c_str()) == 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SurfaceSdlGraphicsManager::setFullscreenMode(bool enable) {
|
void SurfaceSdlGraphicsManager::setFullscreenMode(bool enable) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue