From a419181c36a0c7b113d6a158cf078f52da31613b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 3 May 2020 22:01:05 +0200 Subject: [PATCH] - simplified screenshot code. --- source/build/include/baselayer.h | 2 -- source/core/screenshot.cpp | 28 +++++----------------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index 8f89f420a..5edd7e8c4 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -40,8 +40,6 @@ extern int32_t qsetmode; extern int32_t g_logFlushWindow; bool System_WantGuiCapture(); // During playing this tells us whether the game must be paused due to active GUI elememts. -void getScreen(uint8_t* imgBuf); - #include "print.h" diff --git a/source/core/screenshot.cpp b/source/core/screenshot.cpp index 06970a5ec..54f29a217 100644 --- a/source/core/screenshot.cpp +++ b/source/core/screenshot.cpp @@ -62,10 +62,6 @@ static FileWriter *opennextfile(const char *fn) return FileWriter::Open(name); } -void getScreen(uint8_t* imgBuf) -{ - screen->CopyScreenToBuffer(xdim, ydim, imgBuf); -} CVAR(String, screenshotname, "", CVAR_ARCHIVE) // not GLOBALCONFIG - allow setting this per game. @@ -123,25 +119,11 @@ static int SaveScreenshot() return -1; } - auto truecolor = videoGetRenderMode() >= REND_POLYMOST; - TArray imgBuf(xdim * ydim * (truecolor ? 3 : 1), true); - - if (truecolor) - { - getScreen(imgBuf.Data()); - int bytesPerLine = xdim * 3; - - TArray rowBuf(bytesPerLine * 3, true); - - for (int i = 0, numRows = ydim >> 1; i < numRows; ++i) - { - memcpy(rowBuf.Data(), imgBuf.Data() + i * bytesPerLine, bytesPerLine); - memcpy(imgBuf.Data() + i * bytesPerLine, imgBuf.Data() + (ydim - i - 1) * bytesPerLine, bytesPerLine); - memcpy(imgBuf.Data() + (ydim - i - 1) * bytesPerLine, rowBuf.Data(), bytesPerLine); - } - } - - WritePNGfile(fil, imgBuf.Data(), Palette, truecolor ? SS_RGB : SS_PAL, xdim, ydim, truecolor? xdim*3 : xdim, png_gamma); + float gamma; + int pitch; + ESSType ctype; + auto imgBuf = screen->GetScreenshotBuffer(pitch, ctype, gamma); + WritePNGfile(fil, imgBuf.Data(), Palette, ctype, xdim, ydim, pitch, gamma); delete fil; Printf("screenshot saved\n"); return 0;