diff --git a/modules/highgui/include/opencv2/highgui/highgui.hpp b/modules/highgui/include/opencv2/highgui/highgui.hpp index 528893b03265300b55ff0e6f7964b56bddc9185e..969e9051b9d6c9f59258f3d124c97b8f69a51ff1 100644 --- a/modules/highgui/include/opencv2/highgui/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui/highgui.hpp @@ -150,6 +150,12 @@ enum { IMWRITE_JPEG_QUALITY =1, IMWRITE_PNG_COMPRESSION =16, + IMWRITE_PNG_STRATEGY =17, + IMWRITE_PNG_STRATEGY_DEFAULT =0, + IMWRITE_PNG_STRATEGY_FILTERED =1, + IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2, + IMWRITE_PNG_STRATEGY_RLE =3, + IMWRITE_PNG_STRATEGY_FIXED =4, IMWRITE_PXM_BINARY =32 }; diff --git a/modules/highgui/include/opencv2/highgui/highgui_c.h b/modules/highgui/include/opencv2/highgui/highgui_c.h index 841cfcc6de9646e6b763eb7f6c62b3a690a6311d..093578f52ff6a6bd40b55847fe41292a2fdd2548 100644 --- a/modules/highgui/include/opencv2/highgui/highgui_c.h +++ b/modules/highgui/include/opencv2/highgui/highgui_c.h @@ -217,6 +217,12 @@ enum { CV_IMWRITE_JPEG_QUALITY =1, CV_IMWRITE_PNG_COMPRESSION =16, + CV_IMWRITE_PNG_STRATEGY =17, + CV_IMWRITE_PNG_STRATEGY_DEFAULT =0, + CV_IMWRITE_PNG_STRATEGY_FILTERED =1, + CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2, + CV_IMWRITE_PNG_STRATEGY_RLE =3, + CV_IMWRITE_PNG_STRATEGY_FIXED =4, CV_IMWRITE_PXM_BINARY =32 }; diff --git a/modules/highgui/src/grfmt_png.cpp b/modules/highgui/src/grfmt_png.cpp index 045530a977cd48e6dadc59bef1386894588596d8..d58760db42c69362872f7bc11aba1eba73d93032 100644 --- a/modules/highgui/src/grfmt_png.cpp +++ b/modules/highgui/src/grfmt_png.cpp @@ -312,6 +312,7 @@ void PngEncoder::flushBuf(void*) bool PngEncoder::write( const Mat& img, const vector& params ) { int compression_level = 0; + int compression_strategy = Z_RLE; for( size_t i = 0; i < params.size(); i += 2 ) { @@ -320,6 +321,11 @@ bool PngEncoder::write( const Mat& img, const vector& params ) compression_level = params[i+1]; compression_level = MIN(MAX(compression_level, 0), MAX_MEM_LEVEL); } + if( params[i] == CV_IMWRITE_PNG_STRATEGY ) + { + compression_strategy = params[i+1]; + compression_strategy = MIN(MAX(compression_strategy, 0), Z_FIXED); + } } png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 ); @@ -366,7 +372,7 @@ bool PngEncoder::write( const Mat& img, const vector& params ) png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_FILTER_SUB); png_set_compression_level(png_ptr, Z_BEST_SPEED); } - png_set_compression_strategy(png_ptr, Z_FILTERED); + png_set_compression_strategy(png_ptr, compression_strategy); png_set_IHDR( png_ptr, info_ptr, width, height, depth == CV_8U ? 8 : 16, channels == 1 ? PNG_COLOR_TYPE_GRAY :