Add support for flashpals in screenshots

(cherry picked from commit e765b9400cf741eb8aaa72768ef677769ee5c12b)
This commit is contained in:
Jimita the Cat 2019-01-02 00:41:52 -03:00 committed by James R
parent d6493c9101
commit a3732678e0
4 changed files with 15 additions and 13 deletions

View file

@ -1196,14 +1196,14 @@ UINT8 *HWR_GetScreenshot(void)
return buf;
}
boolean HWR_Screenshot(const char *pathname)
boolean HWR_Screenshot(const char *pathname, char **error)
{
boolean ret;
UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf));
if (!buf)
{
CONS_Debug(DBG_RENDER, "HWR_Screenshot: Failed to allocate memory\n");
*error = "Failed to allocate memory for HWR_Screenshot";
return false;
}
@ -1211,7 +1211,7 @@ boolean HWR_Screenshot(const char *pathname)
HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf);
#ifdef USE_PNG
ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL);
ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL, &*error); // c_irl
#else
ret = saveTGA(pathname, buf, vid.width, vid.height);
#endif

View file

@ -53,7 +53,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color);
void HWR_DrawPic(INT32 x,INT32 y,lumpnum_t lumpnum);
UINT8 *HWR_GetScreenshot(void);
boolean HWR_Screenshot(const char *pathname);
boolean HWR_Screenshot(const char *pathname, char **error);
void HWR_AddCommands(void);
void HWR_CorrectSWTricks(void);

View file

@ -1262,8 +1262,9 @@ void M_StopMovie(void)
* \param height Height of the picture.
* \param palette Palette of image data.
* \note if palette is NULL, BGR888 format
* \param error Error string to return, if screenshot failed.
*/
boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette)
boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error)
{
png_structp png_ptr;
png_infop png_info_ptr;
@ -1277,14 +1278,14 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const
png_FILE = fopen(filename,"wb");
if (!png_FILE)
{
CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for write\n", filename);
*error = "Failed to open file for write";
return false;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, PNG_error, PNG_warn);
if (!png_ptr)
{
CONS_Debug(DBG_RENDER, "M_SavePNG: Error on initialize libpng\n");
*error = "Failed to initialize libpng";
fclose(png_FILE);
remove(filename);
return false;
@ -1293,7 +1294,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const
png_info_ptr = png_create_info_struct(png_ptr);
if (!png_info_ptr)
{
CONS_Debug(DBG_RENDER, "M_SavePNG: Error on allocate for libpng\n");
*error = "Failed to allocate memory for libpng";
png_destroy_write_struct(&png_ptr, NULL);
fclose(png_FILE);
remove(filename);
@ -1306,7 +1307,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const
if (setjmp(png_jmpbuf(png_ptr)))
#endif
{
//CONS_Debug(DBG_RENDER, "libpng write error on %s\n", filename);
*error = "libpng write error";
png_destroy_write_struct(&png_ptr, &png_info_ptr);
fclose(png_FILE);
remove(filename);
@ -1457,6 +1458,7 @@ void M_DoScreenShot(void)
#if NUMSCREENS > 2
const char *freename = NULL, *pathname = ".";
boolean ret = false;
char *error = "Unknown error";
UINT8 *linear = NULL;
// Don't take multiple screenshots, obviously
@ -1497,13 +1499,13 @@ void M_DoScreenShot(void)
// save the pcx file
#ifdef HWRENDER
if (rendermode == render_opengl)
ret = HWR_Screenshot(va(pandf,pathname,freename));
ret = HWR_Screenshot(va(pandf,pathname,freename), &error);
else
#endif
{
M_CreateScreenShotPalette();
#ifdef USE_PNG
ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette);
ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette, &error);
#else
ret = WritePCXfile(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette);
#endif
@ -1518,7 +1520,7 @@ failure:
else
{
if (freename)
CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot %s in %s\n"), freename, pathname);
CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot %s in %s (%s)\n"), freename, pathname, error);
else
CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot in %s (all 10000 slots used!)\n"), pathname);

View file

@ -64,7 +64,7 @@ void FIL_ForceExtension(char *path, const char *extension);
boolean FIL_CheckExtension(const char *in);
#ifdef HAVE_PNG
boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette);
boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error);
#endif
extern boolean takescreenshot;