1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

imgcodecs: png: adjust value range for IMWRITE_PNG_ZLIBBUFFER_SIZE

This commit is contained in:
Kumataro
2025-08-01 09:49:43 +09:00
parent 8dc4ad3ff3
commit 1dd06eb0da
4 changed files with 32 additions and 2 deletions
+5 -1
View File
@@ -1007,7 +1007,11 @@ bool PngEncoder::write( const Mat& img, const std::vector<int>& params )
break;
case IMWRITE_PNG_ZLIBBUFFER_SIZE:
png_set_compression_buffer_size(png_ptr, params[i+1]);
// The default value is 8 KiB.
// The minimum limit is 6, which is from from https://github.com/opencv/opencv/blob/4.12.0/3rdparty/libpng/pngset.c#L1600 .
// The maximum limit is 1 MiB, which has been provisionally set. libpng limitation is 2 GiB(INT32_MAX), but it is too large.
// For normal use, 128 or 256 KiB may be sufficient. See https://zlib.net/zlib_how.html .
png_set_compression_buffer_size(png_ptr, MIN(MAX(params[i+1],6), 1024*1024));
break;
default:
+6
View File
@@ -23,6 +23,7 @@
#include <zlib.h>
#include "grfmt_spng.hpp"
#include <opencv2/core/utils/logger.hpp>
/*
* libspng does not support RGB -> Gray conversion. In order to decode colorful images as grayscale
@@ -554,6 +555,11 @@ bool SPngEncoder::write(const Mat &img, const std::vector<int> &params)
filter = params[i+1];
set_filter = true;
}
if( params[i] == IMWRITE_PNG_ZLIBBUFFER_SIZE )
{
// See https://libspng.org/docs/migrate-libpng/#miscellaneous-functions
CV_LOG_WARNING(nullptr, "libspng does not support png_set_compression_buffer_size() which is required for IMWRITE_PNG_ZLIBBUFFER_SIZE");
}
}
ihdr.bit_depth = depth == CV_8U ? isBilevel ? 1 : 8 : 16;