From 1ba0984203ab10c9356c56abf4146707bf8e925d Mon Sep 17 00:00:00 2001 From: Juha Reunanen Date: Fri, 11 Nov 2022 10:40:53 +0200 Subject: [PATCH] Merge pull request #22790 from reunanen:add-capability-to-set-DWA-compression-level-in-OpenEXR-encoding OpenEXR encoder: add capability to set the DWA compression level * OpenEXR encoder: add capability to set the DWA compression level from outside * Do not try to call `header.dwaCompressionLevel()` if OpenEXR is not version 3 or later * Minor cleanup --- modules/imgcodecs/include/opencv2/imgcodecs.hpp | 1 + modules/imgcodecs/src/grfmt_exr.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/modules/imgcodecs/include/opencv2/imgcodecs.hpp b/modules/imgcodecs/include/opencv2/imgcodecs.hpp index a95a4cc..b651fdf 100644 --- a/modules/imgcodecs/include/opencv2/imgcodecs.hpp +++ b/modules/imgcodecs/include/opencv2/imgcodecs.hpp @@ -97,6 +97,7 @@ enum ImwriteFlags { IMWRITE_PXM_BINARY = 32, //!< For PPM, PGM, or PBM, it can be a binary format flag, 0 or 1. Default value is 1. IMWRITE_EXR_TYPE = (3 << 4) + 0, /* 48 */ //!< override EXR storage type (FLOAT (FP32) is default) IMWRITE_EXR_COMPRESSION = (3 << 4) + 1, /* 49 */ //!< override EXR compression type (ZIP_COMPRESSION = 3 is default) + IMWRITE_EXR_DWA_COMPRESSION_LEVEL = (3 << 4) + 2, /* 50 */ //!< override EXR DWA compression level (45 is default) IMWRITE_WEBP_QUALITY = 64, //!< For WEBP, it can be a quality from 1 to 100 (the higher is the better). By default (without any parameter) and for quality above 100 the lossless compression is used. IMWRITE_PAM_TUPLETYPE = 128,//!< For PAM, sets the TUPLETYPE field to the corresponding string value that is defined for the format IMWRITE_TIFF_RESUNIT = 256,//!< For TIFF, use to specify which DPI resolution unit to set; see libtiff documentation for valid values diff --git a/modules/imgcodecs/src/grfmt_exr.cpp b/modules/imgcodecs/src/grfmt_exr.cpp index 0585035..786b9d1 100644 --- a/modules/imgcodecs/src/grfmt_exr.cpp +++ b/modules/imgcodecs/src/grfmt_exr.cpp @@ -691,6 +691,14 @@ bool ExrEncoder::write( const Mat& img, const std::vector& params ) CV_Error(Error::StsBadArg, "IMWRITE_EXR_COMPRESSION is invalid or not supported"); } } + if (params[i] == IMWRITE_EXR_DWA_COMPRESSION_LEVEL) + { +#if OPENEXR_VERSION_MAJOR >= 3 + header.dwaCompressionLevel() = params[i + 1]; +#else + CV_LOG_ONCE_WARNING(NULL, "Setting `IMWRITE_EXR_DWA_COMPRESSION_LEVEL` not supported in OpenEXR version " + std::to_string(OPENEXR_VERSION_MAJOR) + " (version 3 is required)"); +#endif + } } if( channels == 3 || channels == 4 ) -- 2.7.4