Skip to content

Commit 474028e

Browse files
authored
Merge pull request opencv#26478 from xkszltl:exr_ver
Check existence of OpenEXR version macros before using.
2 parents 4866811 + d0c8b36 commit 474028e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

modules/imgcodecs/src/grfmt_exr.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,10 @@ bool ExrEncoder::write( const Mat& img, const std::vector<int>& params )
754754
case IMWRITE_EXR_COMPRESSION_B44A:
755755
header.compression() = B44A_COMPRESSION;
756756
break;
757-
#if ((OPENEXR_VERSION_MAJOR * 1000 + OPENEXR_VERSION_MINOR) >= (2 * 1000 + 2)) // available since version 2.2.0
757+
// version macros introduced in openexr 2.0.1.
758+
// - https://github.com/AcademySoftwareFoundation/openexr/commit/60cdff8a6f5c4e25a374e5f366d6e9b4efd869b3#diff-c4bae0726aebe410e407db9abd406d9cf2684f82dd8a08f46d84e8b7c35cf22aR67
759+
#if defined(OPENEXR_VERSION_MAJOR) && defined(OPENEXR_VERSION_MINOR) && OPENEXR_VERSION_MAJOR * 1000 + OPENEXR_VERSION_MINOR >= 2 * 1000 + 2
760+
// available since version 2.2.0
758761
case IMWRITE_EXR_COMPRESSION_DWAA:
759762
header.compression() = DWAA_COMPRESSION;
760763
break;
@@ -768,10 +771,12 @@ bool ExrEncoder::write( const Mat& img, const std::vector<int>& params )
768771
}
769772
if (params[i] == IMWRITE_EXR_DWA_COMPRESSION_LEVEL)
770773
{
771-
#if OPENEXR_VERSION_MAJOR >= 3
772-
header.dwaCompressionLevel() = params[i + 1];
773-
#else
774+
#if !defined(OPENEXR_VERSION_MAJOR)
775+
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)");
776+
#elif OPENEXR_VERSION_MAJOR < 3
774777
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)");
778+
#else
779+
header.dwaCompressionLevel() = params[i + 1];
775780
#endif
776781
}
777782
}

0 commit comments

Comments
 (0)