From d0c8b36de8c35a5c3c88cb994243a0164c946fcb Mon Sep 17 00:00:00 2001 From: xkszltl Date: Sun, 17 Nov 2024 18:37:13 -0800 Subject: [PATCH] Check existence of OpenEXR version macros before using. It is introduced in 2.0.1 (not even in 2.0.0) and some old system like CentOS 7 still has 1.7 in stock. - https://github.com/AcademySoftwareFoundation/openexr/commit/60cdff8a6f5c4e25a374e5f366d6e9b4efd869b3#diff-c4bae0726aebe410e407db9abd406d9cf2684f82dd8a08f46d84e8b7c35cf22aR67 --- modules/imgcodecs/src/grfmt_exr.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_exr.cpp b/modules/imgcodecs/src/grfmt_exr.cpp index d48e067edd..e93448e355 100644 --- a/modules/imgcodecs/src/grfmt_exr.cpp +++ b/modules/imgcodecs/src/grfmt_exr.cpp @@ -754,7 +754,10 @@ bool ExrEncoder::write( const Mat& img, const std::vector& params ) case IMWRITE_EXR_COMPRESSION_B44A: header.compression() = B44A_COMPRESSION; break; -#if ((OPENEXR_VERSION_MAJOR * 1000 + OPENEXR_VERSION_MINOR) >= (2 * 1000 + 2)) // available since version 2.2.0 +// version macros introduced in openexr 2.0.1. +// - https://github.com/AcademySoftwareFoundation/openexr/commit/60cdff8a6f5c4e25a374e5f366d6e9b4efd869b3#diff-c4bae0726aebe410e407db9abd406d9cf2684f82dd8a08f46d84e8b7c35cf22aR67 +#if defined(OPENEXR_VERSION_MAJOR) && defined(OPENEXR_VERSION_MINOR) && OPENEXR_VERSION_MAJOR * 1000 + OPENEXR_VERSION_MINOR >= 2 * 1000 + 2 + // available since version 2.2.0 case IMWRITE_EXR_COMPRESSION_DWAA: header.compression() = DWAA_COMPRESSION; break; @@ -768,10 +771,12 @@ bool ExrEncoder::write( const Mat& img, const std::vector& params ) } if (params[i] == IMWRITE_EXR_DWA_COMPRESSION_LEVEL) { -#if OPENEXR_VERSION_MAJOR >= 3 - header.dwaCompressionLevel() = params[i + 1]; -#else +#if !defined(OPENEXR_VERSION_MAJOR) + CV_LOG_ONCE_WARNING(NULL, "Setting `IMWRITE_EXR_DWA_COMPRESSION_LEVEL` not supported in unknown OpenEXR version possibly prior to 2.0.1 (version 3 is required)"); +#elif OPENEXR_VERSION_MAJOR < 3 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)"); +#else + header.dwaCompressionLevel() = params[i + 1]; #endif } }