Skip to content

Add support for lossy HTJ2K compressor#2425

Open
palemieux wants to merge 2 commits into
AcademySoftwareFoundation:lossy-htj2kfrom
sandflow:feature/lossy-htj2k
Open

Add support for lossy HTJ2K compressor#2425
palemieux wants to merge 2 commits into
AcademySoftwareFoundation:lossy-htj2kfrom
sandflow:feature/lossy-htj2k

Conversation

@palemieux
Copy link
Copy Markdown
Collaborator

@palemieux palemieux commented May 17, 2026

  • add support for a separate lossy HTJ2K compressor (using a log transfer function as opposed to DWA's log-gamma transfer function)
  • adds log MSE computation to exrmetrics (to measure the distortion introduced by lossy compressors)

See https://academysoftwarefdn.slack.com/archives/CMLRW4N73/p1777317753088359

@palemieux palemieux requested a review from cary-ilm May 17, 2026 21:07
@cary-ilm
Copy link
Copy Markdown
Member

@Vertexwahn, any suggestion to fix the Bazel failure here? I see two errors in the logs:

src/lib/OpenEXRCore/internal_ht.cpp:10:10: fatal error: openjph/ojph_arch.h: No such file or directory
   10 | #include <openjph/ojph_arch.h>

and:

In file included from src/lib/OpenEXRCore/base.c:8:
src/lib/OpenEXRCore/openexr_version.h:11: warning: "OPENEXR_VERSION_MAJOR" redefined
11 | # define OPENEXR_VERSION_MAJOR 4

@cary-ilm
Copy link
Copy Markdown
Member

And @palemieux, can you amend the commits with -s to add the required DCO?

@Vertexwahn
Copy link
Copy Markdown
Contributor

Short time solution: Change in MODULE.bazel the line bazel_dep(name = "openjph", version = "0.27.3") to bazel_dep(name = "openjph", version = "0.27.0")

@Vertexwahn
Copy link
Copy Markdown
Contributor

Once bazelbuild/bazel-central-registry#9032 is merge you can change bazel_dep(name = "openjph", version = "0.27... to bazel_dep(name = "openjph", version = "0.27.3.bcr.1") (bcr.1 is a patch that contains the missing include path)

@palemieux palemieux force-pushed the feature/lossy-htj2k branch 2 times, most recently from cad022b to b87f94b Compare May 28, 2026 17:35
palemieux and others added 2 commits May 28, 2026 11:11
Signed-off-by: Pierre-Anthony Lemieux <pal@sandflow.com>
Signed-off-by: Pierre-Anthony Lemieux <pal@sandflow.com>
@palemieux palemieux force-pushed the feature/lossy-htj2k branch from b87f94b to 5011ecd Compare May 28, 2026 18:22
{
float a = static_cast<float> (orig[px]);
float b = static_cast<float> (rereadPx[px]);
if (std::isfinite (a) && std::isfinite (b))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add code comments on why divide by 0.0000001 is necessary

}

metrics.stats[p].mseCount = count;
metrics.stats[p].mse =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make this more clear, the variable mse could be changed to logmse

@peterhillman
Copy link
Copy Markdown
Contributor

It might be better to put the exrmetrics changes into a separate PR (apart from minimal support for modifying the amount of compression). The MSE changes aren't directly related to lossy HTJ2K

Comment thread cmake/OpenEXRSetup.cmake
"$<BUILD_INTERFACE:${_openexr_imath_cfg_compat}>")
endif()
set(OPENEXR_IMATH_SUBDIR_INCLUDE_PATCH "${_openexr_imath_inc_patch_key}" CACHE INTERNAL "")
target_include_directories(Imath INTERFACE
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix mirrors what I just submitted in #2444, I think. Fine to leave it here.

float& dwaCompressionLevel ();
IMF_EXPORT
float dwaCompressionLevel () const;
IMF_EXPORT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably just following the pattrn of dwa and zip, but is there a reason this is not just stored as a regular float attribute in the header?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following the pattern. I am not convinced that there is a reason to store the quality level in the header.

Copy link
Copy Markdown
Member

@cary-ilm cary-ilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, are the changes to the vendored OpenJPH simply from vendoring in 0.27.3? Are there any changes we need to make sure don't get stomped on?

@palemieux
Copy link
Copy Markdown
Collaborator Author

Just to confirm, are the changes to the vendored OpenJPH simply from vendoring in 0.27.3? Are there any changes we need to make sure don't get stomped on?

Stock 27.3. No additional changes. Thanks for making sure.

@palemieux
Copy link
Copy Markdown
Collaborator Author

It might be better to put the exrmetrics changes into a separate PR (apart from minimal support for modifying the amount of compression). The MSE changes aren't directly related to lossy HTJ2K

Ok. Will split it off before the lossy J2K branch is merged.


exr_set_zip_compression_level (_ctxt, 0, hdr.zipCompressionLevel ());
exr_set_dwa_compression_level (_ctxt, 0, hdr.dwaCompressionLevel ());
exr_set_lossy_htj2k_quality (_ctxt, 0, hdr.lossyHTJ2KQuality ());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exr_set_lossy_htj2k_quality (_ctxt, 0, hdr.lossyHTJ2KQuality ());
exr_set_htj2k_compression_quality (_ctxt, 0, hdr.HTJ2KCompressionQuality ());

HTJ2K Compression Quality

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the existing names that include "lossy", to distinguish it from the non-lossy htj2k

@cary-ilm
Copy link
Copy Markdown
Member

@peterhillman and @palemieux, since this PR is going into the lossy-htj2k feature branch, the exrmetrics changes can stay here and also go into a separate PR for main. That will highlight them more prominently in the commit history and release notes.

@palemieux
Copy link
Copy Markdown
Collaborator Author

Ok. I can create a PR against main.

@cary-ilm
Copy link
Copy Markdown
Member

@palemieux, I think this is only waiting on @michaeldsmith's comment suggestions?

@palemieux
Copy link
Copy Markdown
Collaborator Author

See #2448 for a standalone PR adding MSE to exrmetrics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants