From e361671018068000a8b63b3cdc2ad87468def9a3 Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Fri, 19 Apr 2024 15:39:28 -0400 Subject: Port from OpenEXR to TinyEXR for reduced installer and library size (#1287) --- autobuild.xml | 110 +++++++++++-------------------- indra/cmake/CMakeLists.txt | 2 + indra/cmake/Copy3rdPartyLibs.cmake | 6 -- indra/cmake/OpenEXR.cmake | 18 ----- indra/cmake/TinyEXR.cmake | 7 ++ indra/newview/CMakeLists.txt | 9 +-- indra/newview/llreflectionmapmanager.cpp | 96 ++++++++------------------- indra/newview/viewer_manifest.py | 8 --- 8 files changed, 78 insertions(+), 178 deletions(-) delete mode 100644 indra/cmake/OpenEXR.cmake create mode 100644 indra/cmake/TinyEXR.cmake diff --git a/autobuild.xml b/autobuild.xml index 559b898c25..cfd8b9721b 100644 --- a/autobuild.xml +++ b/autobuild.xml @@ -2198,76 +2198,6 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors description OpenAL Soft is a software implementation of the OpenAL 3D audio API. - openexr - - canonical_repo - https://github.com/secondlife/3p-openexr - copyright - Copyright (c) Contributors to the OpenEXR Project. All rights reserved. - description - OpenEXR provides the specification and reference implementation of the EXR file format, the professional-grade image storage format of the motion picture industry. - license - OpenEXR - license_file - LICENSES/openexr.txt - name - openexr - platforms - - darwin64 - - archive - - hash - 17cd63922214b588d9a36137fadf927237ec0f25 - hash_algorithm - sha1 - url - https://github.com/secondlife/3p-openexr/releases/download/v1.10/openexr-3.2.2-darwin64-df7544d.tar.zst - - name - darwin64 - - linux64 - - archive - - hash - b092658ab5ec009a5875e8b6e5b7109730ad6846 - hash_algorithm - sha1 - url - https://github.com/secondlife/3p-openexr/releases/download/v1.10/openexr-3.2.2-linux64-df7544d.tar.zst - - name - linux64 - - windows64 - - archive - - hash - c511ae9a3e401375af2199b498a75f32cebc010f - hash_algorithm - sha1 - url - https://github.com/secondlife/3p-openexr/releases/download/v1.10/openexr-3.2.2-windows64-df7544d.tar.zst - - name - windows64 - - - source_type - git - vcs_branch - debug_autobuild - vcs_revision - 5cd1075295c17b5f7085e83d5c16b13c7ecb2eb1 - vcs_url - https://github.com/secondlife/3p-openexr - version - 3.2.2 - openjpeg platforms @@ -3084,6 +3014,46 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors description zlib data compression library for the next generation systems + tinyexr + + platforms + + common + + archive + + hash + 9e0092c6a3aed1cb40a9e26df689c42c68142c9d + hash_algorithm + sha1 + url + https://github.com/secondlife/3p-tinyexr/releases/download/v1.0.8-r1/tinyexr-v1.0.8-common-8755737750.tar.zst + + name + common + + + license + 3-clause BSD + license_file + LICENSES/tinyexr_license.txt + copyright + Copyright (c) 2014 - 2021, Syoyo Fujita and many contributors. + version + v1.0.8 + name + tinyexr + vcs_branch + dependabot/github_actions/secondlife/action-autobuild-4 + vcs_revision + 4dc4d1d90d82a22843e2adf5130f9ecb5ee5769e + vcs_url + https://github.com/secondlife/3p-tinyexr + description + tinyexr import library + source_type + git + package_description diff --git a/indra/cmake/CMakeLists.txt b/indra/cmake/CMakeLists.txt index 05c51c018d..da7e4be464 100644 --- a/indra/cmake/CMakeLists.txt +++ b/indra/cmake/CMakeLists.txt @@ -56,6 +56,8 @@ set(cmake_SOURCE_FILES PulseAudio.cmake Python.cmake TemplateCheck.cmake + TinyEXR.cmake + TinyGLTF.cmake Tut.cmake UI.cmake UnixInstall.cmake diff --git a/indra/cmake/Copy3rdPartyLibs.cmake b/indra/cmake/Copy3rdPartyLibs.cmake index 873253b419..9f79c13a97 100644 --- a/indra/cmake/Copy3rdPartyLibs.cmake +++ b/indra/cmake/Copy3rdPartyLibs.cmake @@ -60,12 +60,6 @@ if(WINDOWS) nghttp2.dll libhunspell.dll uriparser.dll - Iex-3_2.dll - IlmThread-3_2.dll - Imath-3_1.dll - OpenEXR-3_2.dll - OpenEXRCore-3_2.dll - OpenEXRUtil-3_2.dll ) # ICU4C (same filenames for 32 and 64 bit builds) diff --git a/indra/cmake/OpenEXR.cmake b/indra/cmake/OpenEXR.cmake deleted file mode 100644 index ee21fac541..0000000000 --- a/indra/cmake/OpenEXR.cmake +++ /dev/null @@ -1,18 +0,0 @@ -# -*- cmake -*- - -include(Prebuilt) - -include_guard() -add_library( ll::openexr INTERFACE IMPORTED ) - -if(USE_CONAN ) - target_link_libraries( ll::openexr INTERFACE CONAN_PKG::openexr ) - return() -endif() - -use_prebuilt_binary(openexr) - -target_link_libraries( ll::openexr INTERFACE Iex-3_2 IlmThread-3_2 Imath-3_1 OpenEXR-3_2 OpenEXRCore-3_2 OpenEXRUtil-3_2) - -target_include_directories( ll::openexr SYSTEM INTERFACE ${LIBS_PREBUILT_DIR}/include/OpenEXR ${LIBS_PREBUILT_DIR}/include/Imath) - diff --git a/indra/cmake/TinyEXR.cmake b/indra/cmake/TinyEXR.cmake new file mode 100644 index 0000000000..e6d142d19d --- /dev/null +++ b/indra/cmake/TinyEXR.cmake @@ -0,0 +1,7 @@ +# -*- cmake -*- +include(Prebuilt) + +use_prebuilt_binary(tinyexr) + +set(TINYEXR_INCLUDE_DIR ${LIBS_PREBUILT_DIR}/include/tinyexr) + diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 011dccb910..ed617ba70e 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -34,11 +34,11 @@ include(LLWindow) include(NDOF) include(NVAPI) include(OPENAL) -include(OpenEXR) include(OpenGL) include(OpenSSL) include(PNG) include(TemplateCheck) +include(TinyEXR) include(ThreeJS) include(Tracy) include(UI) @@ -1750,12 +1750,6 @@ if (WINDOWS) media_plugin_cef media_plugin_libvlc media_plugin_example - ${SHARED_LIB_STAGING_DIR}/Iex-3_2.dll - ${SHARED_LIB_STAGING_DIR}/IlmThread-3_2.dll - ${SHARED_LIB_STAGING_DIR}/Imath-3_1.dll - ${SHARED_LIB_STAGING_DIR}/OpenEXR-3_2.dll - ${SHARED_LIB_STAGING_DIR}/OpenEXRCore-3_2.dll - ${SHARED_LIB_STAGING_DIR}/OpenEXRUtil-3_2.dll ) if (ADDRESS_SIZE EQUAL 64) @@ -1949,7 +1943,6 @@ target_link_libraries(${VIEWER_BINARY_NAME} ll::bugsplat ll::tracy ll::icu4c - ll::openexr ) if( TARGET ll::intel_memops ) diff --git a/indra/newview/llreflectionmapmanager.cpp b/indra/newview/llreflectionmapmanager.cpp index 3e4992e4e7..5a8f44f5c2 100644 --- a/indra/newview/llreflectionmapmanager.cpp +++ b/indra/newview/llreflectionmapmanager.cpp @@ -41,14 +41,17 @@ #include "llviewermenufile.h" #include "llnotificationsutil.h" - -// load an OpenEXR image from a file -#define IMATH_HALF_NO_LOOKUP_TABLE 1 -#include -#include -#include -#include -#include +#if LL_WINDOWS +#pragma warning (push) +#pragma warning (disable : 4702) // compiler complains unreachable code +#endif +#define TINYEXR_USE_MINIZ 0 +#include "zlib.h" +#define TINYEXR_IMPLEMENTATION +#include "tinyexr/tinyexr.h" +#if LL_WINDOWS +#pragma warning (pop) +#endif LLPointer gEXRImage; @@ -58,55 +61,14 @@ void load_exr(const std::string& filename) gPipeline.mReflectionMapManager.reset(); gPipeline.mReflectionMapManager.initReflectionMaps(); - try { - Imf::InputFile file(filename.c_str()); - Imath::Box2i dw = file.header().dataWindow(); - int width = dw.max.x - dw.min.x + 1; - int height = dw.max.y - dw.min.y + 1; - - Imf::Array2D rPixels; - Imf::Array2D gPixels; - Imf::Array2D bPixels; - - rPixels.resizeErase(height, width); - gPixels.resizeErase(height, width); - bPixels.resizeErase(height, width); - - Imf::FrameBuffer frameBuffer; - - frameBuffer.insert("R", // name - Imf::Slice(Imf::HALF, // type - (char*)(&rPixels[0][0] - // base - dw.min.x - - dw.min.y * width), - sizeof(rPixels[0][0]) * 1, // xStride - sizeof(rPixels[0][0]) * width, // yStride - 1, 1, // x/y sampling - 0.0)); // fillValue - - frameBuffer.insert("G", // name - Imf::Slice(Imf::HALF, // type - (char*)(&gPixels[0][0] - // base - dw.min.x - - dw.min.y * width), - sizeof(gPixels[0][0]) * 1, // xStride - sizeof(gPixels[0][0]) * width, // yStride - 1, 1, // x/y sampling - 0.0)); // fillValue - - frameBuffer.insert("B", // name - Imf::Slice(Imf::HALF, // type - (char*)(&bPixels[0][0] - // base - dw.min.x - - dw.min.y * width), - sizeof(bPixels[0][0]) * 1, // xStride - sizeof(bPixels[0][0]) * width, // yStride - 1, 1, // x/y sampling - FLT_MAX)); // fillValue - - file.setFrameBuffer(frameBuffer); - file.readPixels(dw.min.y, dw.max.y); + float* out; // width * height * RGBA + int width; + int height; + const char* err = NULL; // or nullptr in C++11 + int ret = LoadEXRWithLayer(&out, &width, &height, filename.c_str(), /* layername */ nullptr, &err); + if (ret == TINYEXR_SUCCESS) + { U32 texName = 0; LLImageGL::generateTextures(1, &texName); @@ -117,27 +79,25 @@ void load_exr(const std::string& filename) gGL.getTexUnit(0)->bind(gEXRImage); - std::vector data(width * height * 3); - for (int i = 0; i < width * height; ++i) - { - data[i * 3 + 0] = rPixels[i / width][i % width]; - data[i * 3 + 1] = gPixels[i / width][i % width]; - data[i * 3 + 2] = bPixels[i / width][i % width]; - } + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGBA, GL_FLOAT, out); + free(out); // release memory of image data - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, data.data()); - glGenerateMipmap(GL_TEXTURE_2D); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); } - catch (const std::exception& e) { + else + { LLSD notif_args; notif_args["WHAT"] = filename; - notif_args["REASON"] = e.what(); + notif_args["REASON"] = "Unknown"; + if (err) + { + notif_args["REASON"] = std::string(err); + FreeEXRErrorMessage(err); // release memory of error message. + } LLNotificationsUtil::add("CannotLoad", notif_args); - return; } } diff --git a/indra/newview/viewer_manifest.py b/indra/newview/viewer_manifest.py index d51d86aa3c..4de4dc8fc5 100755 --- a/indra/newview/viewer_manifest.py +++ b/indra/newview/viewer_manifest.py @@ -587,14 +587,6 @@ class Windows_x86_64_Manifest(ViewerManifest): self.path("libcrypto-1_1-x64.dll") self.path("libssl-1_1-x64.dll") - # OpenEXR - self.path("Iex-3_2.dll") - self.path("IlmThread-3_2.dll") - self.path("Imath-3_1.dll") - self.path("OpenEXR-3_2.dll") - self.path("OpenEXRCore-3_2.dll") - self.path("OpenEXRUtil-3_2.dll") - # HTTP/2 self.path("nghttp2.dll") -- cgit v1.2.3