From 7fc569949e8c939f558e9c1ff2b8852c3bf34388 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Thu, 7 Nov 2019 00:14:21 +0100 Subject: [PATCH] Increase JPG/MP3 in-memory threshold - maximum size 512 MB instead of 64 MB - verbose output if JPGs are too large for in-memory (and packJPG is used as fallback) --- contrib/packjpg/precomp_jpg.h | 2 ++ contrib/packmp3/precomp_mp3.h | 2 +- precomp.cpp | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/contrib/packjpg/precomp_jpg.h b/contrib/packjpg/precomp_jpg.h index c105b78..107aa82 100644 --- a/contrib/packjpg/precomp_jpg.h +++ b/contrib/packjpg/precomp_jpg.h @@ -1,6 +1,8 @@ // Motion JPEG DHT header // JPEG DHT Segment for YCrCb omitted from MJPEG data +#define JPG_MAX_MEMORY_SIZE 512 * 1024 * 1024 + #define MJPGDHT_LEN 420 unsigned char MJPGDHT[MJPGDHT_LEN] = { 0xFF,0xC4,0x01,0xA2, diff --git a/contrib/packmp3/precomp_mp3.h b/contrib/packmp3/precomp_mp3.h index 2d7d621..a725fca 100644 --- a/contrib/packmp3/precomp_mp3.h +++ b/contrib/packmp3/precomp_mp3.h @@ -3,7 +3,7 @@ #include "pmp3tbl.h" #undef PRECOMP_MP3 -#define MP3_MAX_MEMORY_SIZE 64 * 1024 * 1024 +#define MP3_MAX_MEMORY_SIZE 512 * 1024 * 1024 // function to convert MP3 to PMP and vice versa, file to file bool pmplib_convert_file2file( char* in, char* out, char* msg ); diff --git a/precomp.cpp b/precomp.cpp index 792c66d..dbb7d9e 100644 --- a/precomp.cpp +++ b/precomp.cpp @@ -4857,7 +4857,7 @@ while (fin_pos < fin_length) { unsigned char* jpg_mem_in = NULL; unsigned char* jpg_mem_out = NULL; unsigned int jpg_mem_out_size = -1; - bool in_memory = (recompressed_data_length <= MAX_IO_BUFFER_SIZE); + bool in_memory = (recompressed_data_length <= JPG_MAX_MEMORY_SIZE); bool recompress_success = false; if (in_memory) { @@ -6587,7 +6587,7 @@ void try_decompression_jpg (long long jpg_length, bool progressive_jpg) { unsigned char* jpg_mem_in = NULL; unsigned char* jpg_mem_out = NULL; unsigned int jpg_mem_out_size = -1; - bool in_memory = ((jpg_length + MJPGDHT_LEN) <= MAX_IO_BUFFER_SIZE); + bool in_memory = ((jpg_length + MJPGDHT_LEN) <= JPG_MAX_MEMORY_SIZE); if (in_memory) { // small stream => do everything in memory jpg_mem_in = new unsigned char[jpg_length + MJPGDHT_LEN]; @@ -6677,7 +6677,10 @@ void try_decompression_jpg (long long jpg_length, bool progressive_jpg) { brotli_used = false; } } else { // large stream => use temporary files - // try to decompress at current position + if (DEBUG_MODE) { + printf("JPG too large for brunsli, using packJPG fallback...\n"); + } + // try to decompress at current position fjpg = tryOpen(tempfile0,"wb"); seek_64(fin, input_file_pos); fast_copy(fin, fjpg, jpg_length);