Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(openexr): modernize dwa compression level setting #4434

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/openexr.imageio/exroutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include <OpenEXR/ImfTiledOutputFile.h>

#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.
Expand Down Expand Up @@ -734,16 +731,33 @@ 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);

// Zip and DWA compression have additional ways to set the levels
#if OPENEXR_CODED_VERSION >= 30103
// OpenEXR 3.1.3 and later allow us to pick the quality level. We've found
// that 4 is a great tradeoff between size and speed, so that is our
// default.
if (Strutil::istarts_with(comp, "zip")) {
header.zipCompressionLevel() = (qual >= 1 && qual <= 9) ? qual : 4;
}
#endif
if (Strutil::istarts_with(comp, "dwa") && qual > 0) {
#if OPENEXR_CODED_VERSION >= 30103
// OpenEXR 3.1.3 and later have an API for setting the quality level
// in the Header object. Older ones do it by setting an attribute, as
// below.
header.dwaCompressionLevel() = float(qual);
#endif
// We set this attribute even for older openexr, because even if we
// set in the header (above), it gets saved as metadata in the file so
// that when we re-read it, we know what the compression level was.
spec.attribute("openexr:dwaCompressionLevel", float(qual));
} else {
// If we're not compressing via dwaa/dwab, clear this attrib so we
// aren't incorrectly carrying it around.
spec.erase_attribute("openexr:dwaCompressionLevel");
}

// Default to increasingY line order
if (!spec.find_attribute("openexr:lineOrder"))
Expand Down
Loading