Use PHYSFS for saving screenshots
parent
f449d9c800
commit
fb9fa49ce8
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "common/make_unique.h"
|
#include "common/make_unique.h"
|
||||||
|
|
||||||
|
#include "common/resources/outputstream.h"
|
||||||
#include "common/resources/resourcemanager.h"
|
#include "common/resources/resourcemanager.h"
|
||||||
|
|
||||||
#include "math/func.h"
|
#include "math/func.h"
|
||||||
|
@ -93,8 +94,8 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
|
||||||
PNG_ERROR = "";
|
PNG_ERROR = "";
|
||||||
|
|
||||||
/* Opening output file */
|
/* Opening output file */
|
||||||
FILE *fp = fopen(filename, "wb");
|
COutputStream ostr(filename);
|
||||||
if (fp == nullptr)
|
if (!ostr.is_open())
|
||||||
{
|
{
|
||||||
PNG_ERROR = std::string("Could not open file '") + std::string(filename) + std::string("' for saving");
|
PNG_ERROR = std::string("Could not open file '") + std::string(filename) + std::string("' for saving");
|
||||||
return false;
|
return false;
|
||||||
|
@ -104,7 +105,7 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
|
||||||
png_structp pngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGUserError, nullptr);
|
png_structp pngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGUserError, nullptr);
|
||||||
if (pngPtr == nullptr)
|
if (pngPtr == nullptr)
|
||||||
{
|
{
|
||||||
fclose(fp);
|
ostr.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,18 +114,30 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
|
||||||
{
|
{
|
||||||
png_destroy_write_struct(&pngPtr, static_cast<png_infopp>(nullptr));
|
png_destroy_write_struct(&pngPtr, static_cast<png_infopp>(nullptr));
|
||||||
PNG_ERROR = "png_create_info_struct() error!";
|
PNG_ERROR = "png_create_info_struct() error!";
|
||||||
fclose(fp);
|
ostr.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setjmp(png_jmpbuf(pngPtr)))
|
if (setjmp(png_jmpbuf(pngPtr)))
|
||||||
{
|
{
|
||||||
png_destroy_write_struct(&pngPtr, &infoPtr);
|
png_destroy_write_struct(&pngPtr, &infoPtr);
|
||||||
fclose(fp);
|
ostr.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_init_io(pngPtr, fp);
|
png_set_write_fn(
|
||||||
|
pngPtr, static_cast<std::ostream*>(&ostr),
|
||||||
|
[](png_structp pngPtr, png_bytep data, png_size_t length)
|
||||||
|
{
|
||||||
|
auto* file = static_cast<std::ostream*>(png_get_io_ptr(pngPtr));
|
||||||
|
file->write(reinterpret_cast<char*>(data), length);
|
||||||
|
},
|
||||||
|
[](png_structp pngPtr)
|
||||||
|
{
|
||||||
|
auto* file = static_cast<std::ostream*>(png_get_io_ptr(pngPtr));
|
||||||
|
file->flush();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
int colortype = PNGColortypeFromSurface(surf);
|
int colortype = PNGColortypeFromSurface(surf);
|
||||||
png_set_IHDR(pngPtr, infoPtr, surf->w, surf->h, 8, colortype, PNG_INTERLACE_NONE,
|
png_set_IHDR(pngPtr, infoPtr, surf->w, surf->h, 8, colortype, PNG_INTERLACE_NONE,
|
||||||
|
@ -141,7 +154,7 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
|
||||||
png_write_end(pngPtr, infoPtr);
|
png_write_end(pngPtr, infoPtr);
|
||||||
|
|
||||||
png_destroy_write_struct(&pngPtr, &infoPtr);
|
png_destroy_write_struct(&pngPtr, &infoPtr);
|
||||||
fclose(fp);
|
ostr.close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4753,7 +4753,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s
|
||||||
m_engine->SetScreenshotMode(true);
|
m_engine->SetScreenshotMode(true);
|
||||||
|
|
||||||
m_engine->Render(); // update (but don't show, we're not swapping buffers here!)
|
m_engine->Render(); // update (but don't show, we're not swapping buffers here!)
|
||||||
m_engine->WriteScreenShot(CResourceManager::GetSaveLocation() + "/" + filescreenshot); //TODO: Use PHYSFS?
|
m_engine->WriteScreenShot(filescreenshot);
|
||||||
m_shotSaving++;
|
m_shotSaving++;
|
||||||
|
|
||||||
m_engine->SetScreenshotMode(false);
|
m_engine->SetScreenshotMode(false);
|
||||||
|
|
Loading…
Reference in New Issue