From cd7550cfe712598727b548d1c90565ac98a274c2 Mon Sep 17 00:00:00 2001 From: Sebastian Parborg Date: Wed, 16 Feb 2022 17:36:47 +0100 Subject: Images: update code to support OpenEXR 3 Compatibility with OpenEXR 2 is preserved, since Blender releases and Linux distribution packages can be on different versions. Ref D14128 --- .../blender/imbuf/intern/openexr/openexr_api.cpp | 84 +++++++++++++--------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index ec8cf36dd49..46abb986259 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -32,30 +32,46 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +/* The OpenEXR version can reliably be found in this header file from OpenEXR, + * for both 2.x and 3.x: + */ +#include +#define COMBINED_OPENEXR_VERSION \ + ((10000 * OPENEXR_VERSION_MAJOR) + (100 * OPENEXR_VERSION_MINOR) + OPENEXR_VERSION_PATCH) + +#if COMBINED_OPENEXR_VERSION >= 20599 +/* >=2.5.99 -> OpenEXR >=3.0 */ +# include +# include +# define exr_file_offset_t uint64_t +#else +/* OpenEXR 2.x, use the old locations. */ +# include +# define exr_file_offset_t Int64 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* multiview/multipart */ -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include "DNA_scene_types.h" /* For OpenEXR compression constants */ @@ -131,12 +147,12 @@ class IMemStream : public Imf::IStream { return false; } - Int64 tellg() override + exr_file_offset_t tellg() override { return _exrpos; } - void seekg(Int64 pos) override + void seekg(exr_file_offset_t pos) override { _exrpos = pos; } @@ -146,8 +162,8 @@ class IMemStream : public Imf::IStream { } private: - Int64 _exrpos; - Int64 _exrsize; + exr_file_offset_t _exrpos; + exr_file_offset_t _exrsize; unsigned char *_exrbuf; }; @@ -182,12 +198,12 @@ class IFileStream : public Imf::IStream { return check_error(); } - Int64 tellg() override + exr_file_offset_t tellg() override { return std::streamoff(ifs.tellg()); } - void seekg(Int64 pos) override + void seekg(exr_file_offset_t pos) override { ifs.seekg(pos); check_error(); @@ -231,19 +247,19 @@ class OMemStream : public OStream { ibuf->encodedsize += n; } - Int64 tellp() override + exr_file_offset_t tellp() override { return offset; } - void seekp(Int64 pos) override + void seekp(exr_file_offset_t pos) override { offset = pos; ensure_size(offset); } private: - void ensure_size(Int64 size) + void ensure_size(exr_file_offset_t size) { /* if buffer is too small increase it. */ while (size > ibuf->encodedbuffersize) { @@ -254,7 +270,7 @@ class OMemStream : public OStream { } ImBuf *ibuf; - Int64 offset; + exr_file_offset_t offset; }; /* File Output Stream */ @@ -284,12 +300,12 @@ class OFileStream : public OStream { check_error(); } - Int64 tellp() override + exr_file_offset_t tellp() override { return std::streamoff(ofs.tellp()); } - void seekp(Int64 pos) override + void seekp(exr_file_offset_t pos) override { ofs.seekp(pos); check_error(); -- cgit v1.2.3 From 2c9931699e2080639bb836357e116b8e340335d9 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 16 Feb 2022 17:38:44 +0100 Subject: Build: update CMake to support OpenEXR 3 FindOpenEXR was updated to find new lib names and separate Imath. It's all added to the list of OpenEXR include dirs and libs. This keeps it compatible with both version 2 and 3 for now, and doesn't require changes outside the find module. Ref D14128 --- build_files/cmake/Modules/FindOpenEXR.cmake | 93 +++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 10 deletions(-) diff --git a/build_files/cmake/Modules/FindOpenEXR.cmake b/build_files/cmake/Modules/FindOpenEXR.cmake index 090f80b8df7..85e2cb55705 100644 --- a/build_files/cmake/Modules/FindOpenEXR.cmake +++ b/build_files/cmake/Modules/FindOpenEXR.cmake @@ -33,14 +33,6 @@ ENDIF() # Old versions (before 2.0?) do not have any version string, just assuming this should be fine though. SET(_openexr_libs_ver_init "2.0") -SET(_openexr_FIND_COMPONENTS - Half - Iex - IlmImf - IlmThread - Imath -) - SET(_openexr_SEARCH_DIRS ${OPENEXR_ROOT_DIR} /opt/lib/openexr @@ -93,6 +85,24 @@ UNSET(_openexr_libs_ver_init) STRING(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _openexr_libs_ver ${OPENEXR_VERSION}) +# Different library names in 3.0, and Imath and Half moved out. +IF(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0") + SET(_openexr_FIND_COMPONENTS + Iex + IlmThread + OpenEXR + OpenEXRCore + ) +ELSE() + SET(_openexr_FIND_COMPONENTS + Half + Iex + IlmImf + IlmThread + Imath + ) +ENDIF() + SET(_openexr_LIBRARIES) FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS}) STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT) @@ -111,6 +121,57 @@ ENDFOREACH() UNSET(_openexr_libs_ver) +IF(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0") + # For OpenEXR 3.x, we also need to find the now separate Imath library. + # For simplicity we add it to the OpenEXR includes and libraries, as we + # have no direct dependency on Imath and it's simpler to support both + # 2.x and 3.x this way. + + # Find include directory + FIND_PATH(IMATH_INCLUDE_DIR + NAMES + Imath/ImathMath.h + HINTS + ${_openexr_SEARCH_DIRS} + PATH_SUFFIXES + include + ) + + # Find version + FIND_FILE(_imath_config + NAMES + ImathConfig.h + PATHS + ${IMATH_INCLUDE_DIR}/Imath + NO_DEFAULT_PATH + ) + + # Find line with version, extract string, and format for library suffix. + FILE(STRINGS "${_imath_config}" _imath_build_specification + REGEX "^[ \t]*#define[ \t]+IMATH_VERSION_STRING[ \t]+\"[.0-9]+\".*$") + STRING(REGEX REPLACE ".*#define[ \t]+IMATH_VERSION_STRING[ \t]+\"([.0-9]+)\".*" + "\\1" _imath_libs_ver ${_imath_build_specification}) + STRING(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _imath_libs_ver ${_imath_libs_ver}) + + # Find library, with or without version number. + FIND_LIBRARY(IMATH_LIBRARY + NAMES + Imath-${_imath_libs_ver} Imath + NAMES_PER_DIR + HINTS + ${_openexr_SEARCH_DIRS} + PATH_SUFFIXES + lib64 lib + ) + LIST(APPEND _openexr_LIBRARIES "${IMATH_LIBRARY}") + + # In cmake version 3.21 and up, we can instead use the NO_CACHE option for + # FIND_FILE so we don't need to clear it from the cache here. + UNSET(_imath_config CACHE) + UNSET(_imath_libs_ver) + UNSET(_imath_build_specification) +ENDIF() + # handle the QUIETLY and REQUIRED arguments and set OPENEXR_FOUND to TRUE if # all listed variables are TRUE INCLUDE(FindPackageHandleStandardArgs) @@ -119,13 +180,25 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenEXR DEFAULT_MSG IF(OPENEXR_FOUND) SET(OPENEXR_LIBRARIES ${_openexr_LIBRARIES}) - # Both include paths are needed because of dummy OSL headers mixing #include and #include :( - SET(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR_INCLUDE_DIR}/OpenEXR) + # Both include paths are needed because of dummy OSL headers mixing + # #include and #include , as well as Alembic + # include directly. + SET(OPENEXR_INCLUDE_DIRS + ${OPENEXR_INCLUDE_DIR} + ${OPENEXR_INCLUDE_DIR}/OpenEXR) + + IF(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0") + LIST(APPEND OPENEXR_INCLUDE_DIRS + ${IMATH_INCLUDE_DIR} + ${IMATH_INCLUDE_DIR}/Imath) + ENDIF() ENDIF() MARK_AS_ADVANCED( OPENEXR_INCLUDE_DIR OPENEXR_VERSION + IMATH_INCLUDE_DIR + IMATH_LIBRARY ) FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS}) STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT) -- cgit v1.2.3 From e5100ca3ad17b1b9a40ffd8a8edccb6cb553e558 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 16 Feb 2022 17:40:20 +0100 Subject: Build: update CMake to support OpenImageIO 2.3.4 FindOpenImageIO was updated to link to separate OpenImageIO_Util for new versions, where it is required. For older versions, we can not link to it because there will be duplicated symbols. Ref D14128 --- build_files/cmake/Modules/FindOpenImageIO.cmake | 41 +++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/build_files/cmake/Modules/FindOpenImageIO.cmake b/build_files/cmake/Modules/FindOpenImageIO.cmake index aac5b5ce0a8..54b6d95e809 100644 --- a/build_files/cmake/Modules/FindOpenImageIO.cmake +++ b/build_files/cmake/Modules/FindOpenImageIO.cmake @@ -48,6 +48,8 @@ FIND_LIBRARY(OPENIMAGEIO_LIBRARY lib64 lib ) +set(_openimageio_LIBRARIES ${OPENIMAGEIO_LIBRARY}) + FIND_FILE(OPENIMAGEIO_IDIFF NAMES idiff @@ -57,14 +59,47 @@ FIND_FILE(OPENIMAGEIO_IDIFF bin ) +# Additionally find util library if needed. In old versions this library was +# included in libOpenImageIO and linking to both would duplicate symbols. In +# new versions we need to link to both. +FIND_FILE(_openimageio_export + NAMES + export.h + PATHS + ${OPENIMAGEIO_INCLUDE_DIR}/OpenImageIO + NO_DEFAULT_PATH +) + +# Use existence of OIIO_UTIL_API to check if it's a separate lib. +FILE(STRINGS "${_openimageio_export}" _openimageio_util_define + REGEX "^[ \t]*#[ \t]*define[ \t]+OIIO_UTIL_API.*$") + +IF(_openimageio_util_define) + FIND_LIBRARY(OPENIMAGEIO_UTIL_LIBRARY + NAMES + OpenImageIO_Util + HINTS + ${_openimageio_SEARCH_DIRS} + PATH_SUFFIXES + lib64 lib + ) + + LIST(APPEND _openimageio_LIBRARIES ${OPENIMAGEIO_UTIL_LIBRARY}) +ENDIF() + +# In cmake version 3.21 and up, we can instead use the NO_CACHE option for +# FIND_FILE so we don't need to clear it from the cache here. +UNSET(_openimageio_export CACHE) +UNSET(_openimageio_util_define) + # handle the QUIETLY and REQUIRED arguments and set OPENIMAGEIO_FOUND to TRUE if # all listed variables are TRUE INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenImageIO DEFAULT_MSG - OPENIMAGEIO_LIBRARY OPENIMAGEIO_INCLUDE_DIR) + _openimageio_LIBRARIES OPENIMAGEIO_INCLUDE_DIR) IF(OPENIMAGEIO_FOUND) - SET(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARY}) + SET(OPENIMAGEIO_LIBRARIES ${_openimageio_LIBRARIES}) SET(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO_INCLUDE_DIR}) IF(EXISTS ${OPENIMAGEIO_INCLUDE_DIR}/OpenImageIO/pugixml.hpp) SET(OPENIMAGEIO_PUGIXML_FOUND TRUE) @@ -78,7 +113,9 @@ ENDIF() MARK_AS_ADVANCED( OPENIMAGEIO_INCLUDE_DIR OPENIMAGEIO_LIBRARY + OPENIMAGEIO_UTIL_LIBRARY OPENIMAGEIO_IDIFF ) UNSET(_openimageio_SEARCH_DIRS) +UNSET(_openimageio_LIBRARIES) -- cgit v1.2.3