From 29112d35fb89f0929205b5c39dcdc7c31a9a5870 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Tue, 17 Sep 2024 22:05:27 -0700 Subject: [PATCH] fix(openexr): modernize dwa compression level setting Starting with OpenEXR 3.1.3, the preferred API call for setting DWAA/DWAB compression level has changed. We never changed the OIIO side. Luckily, OpenEXR seems to have kept respecting the old API calls we were making (passing as an attribute). But this modernizes the approach, now that we don't have OpenEXR 2.x suppor to maintain. But in the process, we also fixed a bug! Turns out we weren't propagating the compression properly -- if the compression name was plain "dwaa", we ignored any "openexr:dwaCompressionLevel" attribute, effectively. Signed-off-by: Larry Gritz --- src/openexr.imageio/exroutput.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/openexr.imageio/exroutput.cpp b/src/openexr.imageio/exroutput.cpp index e89cb0a528..b644b80209 100644 --- a/src/openexr.imageio/exroutput.cpp +++ b/src/openexr.imageio/exroutput.cpp @@ -22,9 +22,6 @@ #include #include "exr_pvt.h" -#define OPENEXR_CODED_VERSION \ - (OPENEXR_VERSION_MAJOR * 10000 + OPENEXR_VERSION_MINOR * 100 \ - + OPENEXR_VERSION_PATCH) // The way that OpenEXR uses dynamic casting for attributes requires // temporarily suspending "hidden" symbol visibility mode. @@ -734,16 +731,20 @@ OpenEXROutput::spec_to_header(ImageSpec& spec, int subimage, || !ispow2(spec.tile_width) || !ispow2(spec.tile_height))) { comp = "zip"; } - if (Strutil::istarts_with(comp, "dwa")) { - spec.attribute("openexr:dwaCompressionLevel", - qual > 0 ? float(qual) : 45.0f); - } spec.attribute("compression", comp); #if OPENEXR_CODED_VERSION >= 30103 if (Strutil::istarts_with(comp, "zip")) { header.zipCompressionLevel() = (qual >= 1 && qual <= 9) ? qual : 4; } #endif + if (Strutil::istarts_with(comp, "dwa") && qual > 0) { + spec.attribute("openexr:dwaCompressionLevel", float(qual)); + // qual > 0 ? float(qual) : 45.0f); +#if OPENEXR_CODED_VERSION >= 30103 + // header.dwaCompressionLevel() = qual > 0 ? float(qual) : 45.0f; + header.dwaCompressionLevel() = float(qual); +#endif + } // Default to increasingY line order if (!spec.find_attribute("openexr:lineOrder"))