- simplified screenshot code.

This commit is contained in:
Christoph Oelckers 2020-05-03 22:01:05 +02:00
parent f2d075e0d0
commit a419181c36
2 changed files with 5 additions and 25 deletions

View file

@ -40,8 +40,6 @@ extern int32_t qsetmode;
extern int32_t g_logFlushWindow; extern int32_t g_logFlushWindow;
bool System_WantGuiCapture(); // During playing this tells us whether the game must be paused due to active GUI elememts. 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" #include "print.h"

View file

@ -62,10 +62,6 @@ static FileWriter *opennextfile(const char *fn)
return FileWriter::Open(name); 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. CVAR(String, screenshotname, "", CVAR_ARCHIVE) // not GLOBALCONFIG - allow setting this per game.
@ -123,25 +119,11 @@ static int SaveScreenshot()
return -1; return -1;
} }
auto truecolor = videoGetRenderMode() >= REND_POLYMOST; float gamma;
TArray<uint8_t> imgBuf(xdim * ydim * (truecolor ? 3 : 1), true); int pitch;
ESSType ctype;
if (truecolor) auto imgBuf = screen->GetScreenshotBuffer(pitch, ctype, gamma);
{ WritePNGfile(fil, imgBuf.Data(), Palette, ctype, xdim, ydim, pitch, gamma);
getScreen(imgBuf.Data());
int bytesPerLine = xdim * 3;
TArray<uint8_t> 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);
delete fil; delete fil;
Printf("screenshot saved\n"); Printf("screenshot saved\n");
return 0; return 0;