From b7eb5777aea46fe030ee7afa3fbad229d5aed6a8 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 8 Nov 2024 22:03:44 +0100 Subject: [PATCH] save savefile previews as png. this finally kills .zga format, but it's kept for backwards compat --- Aquaria/AquariaSaveSlot.cpp | 44 ++++++++++++++++++++++++------------- Aquaria/DSQ.cpp | 10 +++++---- BBGE/Image.cpp | 4 +++- BBGE/Image.h | 2 +- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/Aquaria/AquariaSaveSlot.cpp b/Aquaria/AquariaSaveSlot.cpp index de14637..8d62e7b 100644 --- a/Aquaria/AquariaSaveSlot.cpp +++ b/Aquaria/AquariaSaveSlot.cpp @@ -24,6 +24,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. bool AquariaSaveSlot::closed = false; +static std::string getSavePreviewBaseName(unsigned slot) +{ + const char *pre="./"; +#ifndef BBGE_BUILD_WINDOWS + pre = ""; +#endif + std::ostringstream os; + os << pre << dsq->getSaveDirectory() << "/screen-" << numToZeroString(slot, 4); + return os.str(); +} + + +static std::string getSavePreviewImageName(unsigned slot) +{ + std::string base = getSavePreviewBaseName(slot); + std::string fn = base + ".png"; + if(exists(fn)) + return fn; + fn = base + ".zga"; + if(exists(fn)) + return fn; + fn = base + ".tga"; + if(exists(fn)) + return fn; + return base; // whatev +} + AquariaSaveSlot::AquariaSaveSlot(int slot) : AquariaGuiQuad() { done = false; @@ -86,21 +113,8 @@ AquariaSaveSlot::AquariaSaveSlot(int slot) : AquariaGuiQuad() if (dsq->user.video.saveSlotScreens) { - std::ostringstream os,os2; - std::string tex, tex2; - std::string pre="./"; -#ifndef BBGE_BUILD_WINDOWS - pre = ""; -#endif - os << pre << dsq->getSaveDirectory() << "/screen-" << numToZeroString(slot, 4) << ".tga"; - os2 << pre << dsq->getSaveDirectory() << "/screen-" << numToZeroString(slot, 4) << ".zga"; - tex = os.str(); - tex2 = os2.str(); - - if (exists(tex2)) - screen->setTexture(tex2); - else - screen->setTexture(tex); + std::string tex = getSavePreviewImageName(slot); + screen->setTexture(tex); } else { diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index ddcea56..cdf0bdf 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -2822,16 +2822,18 @@ void DSQ::doSaveSlotMenu(SaveSlotMode ssm, const Vector &position) if (user.video.saveSlotScreens && scrShotData != 0) { std::ostringstream os; - os << getSaveDirectory() << "/screen-" << numToZeroString(selectedSaveSlot->getSlotIndex(), 4) << ".zga"; + os << getSaveDirectory() << "/screen-" << numToZeroString(selectedSaveSlot->getSlotIndex(), 4) << ".png"; // Cut off top and bottom to get a 4:3 aspect ratio. - /*int adjHeight = (scrShotWidth * 3.0f) / 4.0f; + int adjHeight = (scrShotWidth * 3.0f) / 4.0f; int imageDataSize = scrShotWidth * scrShotHeight * 4; int adjImageSize = scrShotWidth * adjHeight * 4; int adjOffset = scrShotWidth * ((scrShotHeight-adjHeight)/2) * 4; memmove(scrShotData, scrShotData + adjOffset, adjImageSize); - memset(scrShotData + adjImageSize, 0, imageDataSize - adjImageSize);*/ - zgaSaveRGBA(os.str().c_str(), scrShotWidth, scrShotHeight, scrShotData); + memset(scrShotData + adjImageSize, 0, imageDataSize - adjImageSize); + + //zgaSaveRGBA(os.str().c_str(), scrShotWidth, scrShotHeight, scrShotData); + pngSaveRGBA(os.str().c_str(), scrShotWidth, adjHeight, scrShotData, 3); } PlaySfx sfx; diff --git a/BBGE/Image.cpp b/BBGE/Image.cpp index 95e42a6..98da7fc 100644 --- a/BBGE/Image.cpp +++ b/BBGE/Image.cpp @@ -21,6 +21,8 @@ bool tgaSaveRGBA(const char *filename, size_t width, size_t height, unsigned cha } +#if 0 +// No longer used -- kept for reference // Aquaria special: zlib-compressed TGA bool zgaSaveRGBA(const char *filename, size_t w, size_t h, unsigned char *data) { @@ -75,7 +77,7 @@ bool zgaSaveRGBA(const char *filename, size_t w, size_t h, unsigned char *data) return ok; } - +#endif static VFILE *imageLoadOpenFile(const char *filename) { diff --git a/BBGE/Image.h b/BBGE/Image.h index a447080..e91fdf2 100644 --- a/BBGE/Image.h +++ b/BBGE/Image.h @@ -4,7 +4,7 @@ #include bool tgaSaveRGBA(const char *filename, size_t width, size_t height, unsigned char *data); -bool zgaSaveRGBA(const char *filename, size_t width, size_t height, unsigned char *data); +//bool zgaSaveRGBA(const char *filename, size_t width, size_t height, unsigned char *data); bool pngSaveRGBA(const char *filename, size_t width, size_t height, unsigned char *data, unsigned compressLevel); struct ImageData