From dfecc1229fb0229a02fedd011d55622aa33b243d Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 24 Oct 2019 10:42:39 +0300 Subject: [PATCH] - removed hardcoded width limit for screenshots https://forum.zdoom.org/viewtopic.php?t=66204 --- src/m_misc.cpp | 3 ++- src/utility/m_png.cpp | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/m_misc.cpp b/src/m_misc.cpp index feef6e2c32..0f3fe90724 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -366,7 +366,8 @@ inline void putc(unsigned char chr, FileWriter *file) void WritePCXfile (FileWriter *file, const uint8_t *buffer, const PalEntry *palette, ESSType color_type, int width, int height, int pitch) { - uint8_t temprow[MAXWIDTH * 3]; + TArray temprow_storage(width * 3, true); + uint8_t *temprow = &temprow_storage[0]; const uint8_t *data; int x, y; int runlen; diff --git a/src/utility/m_png.cpp b/src/utility/m_png.cpp index df2ec58601..52d46f3e46 100644 --- a/src/utility/m_png.cpp +++ b/src/utility/m_png.cpp @@ -758,7 +758,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. @@ -893,12 +893,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) { + 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;