From edcfad6e11ee193e16151eb088d8e88939c089fb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 2 Nov 2019 12:07:15 +0100 Subject: [PATCH] - updated m_png.cpp from GZDoom. --- source/common/utility/m_png.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/source/common/utility/m_png.cpp b/source/common/utility/m_png.cpp index 245546d65..888b705be 100644 --- a/source/common/utility/m_png.cpp +++ b/source/common/utility/m_png.cpp @@ -102,9 +102,6 @@ static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const uint8_ // PUBLIC DATA DEFINITIONS ------------------------------------------------- -int png_level = 5; -int png_gamma = 0; -/* CUSTOM_CVAR(Int, png_level, 5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) { if (self < 0) @@ -113,7 +110,7 @@ CUSTOM_CVAR(Int, png_level, 5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) self = 9; } CVAR(Float, png_gamma, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -*/ + // PRIVATE DATA DEFINITIONS ------------------------------------------------ // CODE -------------------------------------------------------------------- @@ -763,7 +760,7 @@ uint32_t CalcSum(Byte *row, int len) //========================================================================== #if USE_FILTER_HEURISTIC -static int SelectFilter(Byte row[5][1 + MAXWIDTH*3], Byte prior[MAXWIDTH*3], int width) +static int SelectFilter(Byte **row, Byte *prior, int width) { // As it turns out, it seems no filtering is the best for Doom screenshots, // no matter what the heuristic might determine. @@ -898,13 +895,27 @@ static int SelectFilter(Byte row[5][1 + MAXWIDTH*3], Byte prior[MAXWIDTH*3], int bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height, int pitch, FileWriter *file) { -#define MAXWIDTH 2048 + TArray temprow_storage; + #if USE_FILTER_HEURISTIC - Byte prior[MAXWIDTH*3]; - Byte temprow[5][1 + MAXWIDTH*3]; + static const unsigned temprow_count = 5; + + TArray prior_storage(width * 3, true); + Byte *prior = &prior_storage[0]; #else - Byte temprow[1][1 + MAXWIDTH*3]; + static const unsigned temprow_count = 1; #endif + + const unsigned temprow_size = 1 + width * 3; + temprow_storage.Resize(temprow_size * temprow_count); + + Byte* temprow[temprow_count]; + + for (unsigned i = 0; i < temprow_count; ++i) + { + temprow[i] = &temprow_storage[temprow_size * i]; + } + Byte buffer[PNG_WRITE_SIZE]; z_stream stream; int err;