Merge pull request #22790 from reunanen:add-capability-to-set-DWA-compression-level...
authorJuha Reunanen <juha.reunanen@tomaattinen.com>
Fri, 11 Nov 2022 08:40:53 +0000 (10:40 +0200)
committerGitHub <noreply@github.com>
Fri, 11 Nov 2022 08:40:53 +0000 (08:40 +0000)
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
modules/imgcodecs/src/grfmt_exr.cpp

index a95a4cc..b651fdf 100644 (file)
@@ -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
index 0585035..786b9d1 100644 (file)
@@ -691,6 +691,14 @@ bool  ExrEncoder::write( const Mat& img, const std::vector<int>& 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 )