-
Notifications
You must be signed in to change notification settings - Fork 657
feat(openexr): ACES Container hint for exr outputs #4907
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
Merged
lgritz
merged 30 commits into
AcademySoftwareFoundation:main
from
Glowies:FEAT-ACES-container-exr-writer
Oct 26, 2025
Merged
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d0f8853
feat: ACES Container writer for OpenEXR
Glowies 73d1e75
refactor(openexr): follow clang-format recommendations for exroutput.cpp
Glowies fda980e
fix(openexr): do not write ACES Container metadata when non-compliant…
Glowies e89f01f
test(openexr): test ACES container output with various modes of failure
Glowies 2deb446
docs(openexr): document the oiio:ACESContainer hint
Glowies ca010df
refactor(openexr): rename oiio:ACESContainer hint to openexr:ACESCont…
Glowies 0b3967e
refactor(openexr): add static keyword to AP0 chromaticities array
Glowies f98e2ce
fix(openexr): remove printing warning to stderr
Glowies 2571f37
fix(openexr): chromaticities get set to AP0 in relaxed mode of ACES C…
Glowies c9b40c0
docs(openexr): update permalink to st2065-4 standard
Glowies ee84d2a
fix(openexr): check for existence of correct channel names instead of…
Glowies 0f2feb5
refactor(openexr): update comment in exroutput.cpp
Glowies 9f23db7
fix(openexr): use static and const keywords for the allowed_sets
Glowies 7322ff1
test(openexr): more explanatory test results for aces container
Glowies c30d8f8
fix(openexr): test for non-empty attributes in ACES container
Glowies e94bd5d
feat(openexr): check attributes with exact required values
Glowies 5c3fd08
refactor(openexr): follow clang-format recommendations
Glowies ac1c654
refactor(openexr): make chromaticities check a bit more readable
Glowies 2052c52
feat(openexr): rename ACES container flag to openexr:ACESContainerPolicy
Glowies 1e89fa5
refactor(openexr): apply clang-format recommendations
Glowies ae19a4c
feat(openexr): set aces container attributes in relaxed mode as well
Glowies c177142
docs(openexr): update ACES container mode to reflect changes to relax…
Glowies 25fac3c
feat(openexr): better error messages for each failure case of ACES Co…
Glowies d3530e4
fix(openexr): inconsistent attribute read behaviour with ParamValue
Glowies 21dfe1b
refactor(openexr): apply clang-format recommendations
Glowies d725544
test(openexr): fix issue with using single quotes in windows tests
Glowies b61974a
test(openexr): improve readability of ACES container test outputs
Glowies 5980084
fix(openexr): remove redundant search for found attributes
Glowies 60fba1b
refactor(openexr): replace vector with a c array to avoid extra alloc…
Glowies 9216912
refactor(openexr): rename flag parameter and apply clang-format sugge…
Glowies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,6 +290,167 @@ set_exr_threads() | |
|
|
||
|
|
||
|
|
||
| static constexpr float ACES_AP0_chromaticities[8] = { | ||
| 0.7347f, 0.2653f, // red | ||
| 0.0f, 1.0f, // green | ||
| 0.0001f, -0.077f, // blue | ||
| 0.32168f, 0.33767f // white | ||
| }; | ||
|
|
||
| static const std::string ACES_AP0_colorInteropId = "lin_ap0_scene"; | ||
|
|
||
|
|
||
| bool | ||
| is_spec_aces_container_channels_only(const OIIO::ImageSpec& spec) | ||
| { | ||
| // Note: this is constructing and comparing sets, so that channel order | ||
| // doesn't matter. | ||
|
|
||
| // Allowed channel sets | ||
Glowies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| static const std::vector<std::set<std::string>> allowed_sets | ||
| = { { "B", "G", "R" }, | ||
| { "A", "B", "G", "R" }, | ||
| { "B", "G", "R", "left.B", "left.G", "left.R" }, | ||
| { "A", "B", "G", "R", "left.A", "left.B", "left.G", "left.R" } }; | ||
|
|
||
| // Gather channel set from spec | ||
| std::set<std::string> channels(spec.channelnames.begin(), | ||
| spec.channelnames.end()); | ||
|
|
||
| // Compare to allowed sets (unordered) | ||
| for (const auto& allowed : allowed_sets) { | ||
| if (channels == allowed) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| bool | ||
| is_aces_container_attributes_non_empty(const OIIO::ImageSpec& spec) | ||
| { | ||
| // attributes in this list should NOT be empty if they exist | ||
| static const std::vector<std::string> nonEmptyAttribs = { | ||
Glowies marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "cameraFirmwareVersion", | ||
| "cameraIdentifier", | ||
| "cameraLabel", | ||
| "cameraMake", | ||
| "cameraModel", | ||
| "cameraSerialNumber", | ||
| "comments", | ||
| "creator", | ||
| "lensAttributes", | ||
| "lensFirmwareVersion", | ||
| "lensMake", | ||
| "lensModel", | ||
| "lensSerialNumber", | ||
| "owner", | ||
| "recorderFirmwareVersion", | ||
| "recorderMake", | ||
| "recorderModel", | ||
| "recorderSerialNumber", | ||
| "reelName", | ||
| "storageMediaSerialNumber", | ||
| }; | ||
|
|
||
| for (const auto& label : nonEmptyAttribs) { | ||
| const ParamValue* value = spec.find_attribute(label, | ||
| OIIO::TypeDesc::STRING); | ||
| if (value && value->get<std::string>().empty()) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| bool | ||
| is_aces_container_compliant(const OIIO::ImageSpec& spec) | ||
| { | ||
| if (!is_spec_aces_container_channels_only(spec)) | ||
| return false; | ||
|
|
||
| // Check data type | ||
| if (spec.format != OIIO::TypeDesc::HALF) | ||
| return false; | ||
|
|
||
| // Check compression | ||
| std::string compression = spec.get_string_attribute("compression", "zip"); | ||
| if (compression != "none") | ||
| return false; | ||
|
Comment on lines
+384
to
+395
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the best policy here? For something like "doesn't have the right channels", the only thing to do is fail. But for "wrong data type" or "wrong compression", we could force compliance by just fixing it. |
||
|
|
||
| // Check non-empty attributes | ||
| if (!is_aces_container_attributes_non_empty(spec)) | ||
| return false; | ||
|
|
||
| // Check attributes with exact values if they exist | ||
| if (spec.get_string_attribute("oiio:ColorSpace", ACES_AP0_colorInteropId) | ||
| != ACES_AP0_colorInteropId | ||
| || spec.get_string_attribute("colorInteropId", ACES_AP0_colorInteropId) | ||
| != ACES_AP0_colorInteropId | ||
| || spec.get_int_attribute("acesImageContainerFlag", 1) != 1) | ||
| return false; | ||
|
|
||
| // Check chromaticities | ||
| float chromaticities[8] = { 0., 0., 0., 0., 0., 0., 0., 0. }; | ||
| bool chroms_found | ||
| = spec.getattribute("chromaticities", | ||
| OIIO::TypeDesc(OIIO::TypeDesc::FLOAT, 8), | ||
| chromaticities); | ||
| bool chroms_equal = std::equal(std::begin(chromaticities), | ||
| std::end(chromaticities), | ||
| std::begin(ACES_AP0_chromaticities)); | ||
|
|
||
| if (chroms_found && !chroms_equal) | ||
| return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| void | ||
| set_aces_container_attributes(OIIO::ImageSpec& spec) | ||
| { | ||
| spec.attribute("chromaticities", OIIO::TypeDesc(OIIO::TypeDesc::FLOAT, 8), | ||
| ACES_AP0_chromaticities); | ||
| spec.attribute("colorInteropId", ACES_AP0_colorInteropId); | ||
| spec.attribute("acesImageContainerFlag", 1); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| bool | ||
| process_aces_container(OIIO::ImageSpec& spec, std::string policy, int flag) | ||
| { | ||
| bool treat_as_aces_container = policy == "strict" || flag == 1; | ||
| bool is_compliant = is_aces_container_compliant(spec); | ||
|
|
||
| if (treat_as_aces_container && !is_compliant) { | ||
| return false; | ||
| } | ||
|
|
||
| set_aces_container_attributes(spec); | ||
|
|
||
| if (policy == "relaxed" && !is_compliant) { | ||
| // When image is not compliant in relaxed mode, we should avoid | ||
| // setting the flag, and we should print a warning | ||
|
|
||
| // TODO: When we have a way to report warnings, report one here | ||
| // to indicate that the given image spec is not compliant | ||
| spec.erase_attribute("acesImageContainerFlag"); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| OpenEXROutput::OpenEXROutput() | ||
| { | ||
| pvt::set_exr_threads(); | ||
|
|
@@ -812,6 +973,23 @@ OpenEXROutput::spec_to_header(ImageSpec& spec, int subimage, | |
| Imf::LevelMode(m_levelmode), | ||
| Imf::LevelRoundingMode(m_roundingmode))); | ||
|
|
||
| // Check ACES Container hint | ||
| int aces_container_flag = spec.get_int_attribute("acesImageContainerFlag", | ||
Glowies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 0); | ||
| std::string aces_container_policy | ||
| = spec.get_string_attribute("openexr:ACESContainerPolicy", "none"); | ||
|
|
||
| if (aces_container_policy != "none" || aces_container_flag == 1) { | ||
| bool should_panic = !process_aces_container(spec, aces_container_policy, | ||
| aces_container_flag); | ||
|
|
||
| if (should_panic) { | ||
| errorfmt( | ||
| "Cannot output non-compliant ACES Container in 'strict' mode."); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // Deal with all other params | ||
| for (const auto& p : spec.extra_attribs) | ||
| put_parameter(p.name().string(), p.type(), p.data(), header); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.