Skip to content

Add support for Qfactor#308

Merged
aous72 merged 9 commits into
aous72:masterfrom
sandflow:features/add-qfactor
Jun 30, 2026
Merged

Add support for Qfactor#308
aous72 merged 9 commits into
aous72:masterfrom
sandflow:features/add-qfactor

Conversation

@palemieux

Copy link
Copy Markdown
Contributor

To improve interoperability, the feature uses the visual weights library from @osamu620 at https://github.com/osamu620/OpenHTJ2K/blob/main/source/core/codestream/visual_weighting.hpp, which is copied into OpenJPH.

@aous72

aous72 commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Thank you @palemieux for putting this PR.

}

if (qfactor != -1 && quantization_step != -1.0f)
OJPH_ERROR(0x01000101,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please change all 0x0100010x to 0x010000Ax.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/core/CMakeLists.txt Outdated
@@ -1,5 +1,5 @@

file(GLOB CODESTREAM "codestream/*.cpp" "codestream/*.h")
file(GLOB CODESTREAM "codestream/*.cpp" "codestream/*.h" "codestream/*.hpp")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I would be nicer if we can change the name to .h so it matches the rest of the code; what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/core/openjph/ojph_params.h Outdated
class OJPH_EXPORT param_qcd
{
public:
enum comp_type {

@aous72 aous72 Jun 29, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It would nice to associate a type to the enum, as in
enum comp_type : ui8 {}; or enum comp_type : ui32 {};
If we knew for sure that visual weighting or qfactor will not be assigned to any component other than the first three, we would not need this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/core/codestream/ojph_params_local.h Outdated
bool is_qcc_needed(ui32 comp_num, const param_cod &cod, const param_siz &siz);
void set_delta(float delta) { base_delta = delta; }
void set_delta(ui32 comp_idx, float delta);
void set_qfactor(ui32 comp_idx, ui8 qfactor, ojph::param_qcd::comp_type ctype);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is it necessary to pass ojph::param_qcd::comp_type ctype. We can use the comp_idx for this purpose.
It unlikely, although possible, that we will use visual weighting for components other than the first 3.
Perhaps, changing the order is useful to
void set_qfactor(ui32 comp_idx, ojph::param_qcd::comp_type ctype, ui8 qfactor);
What do you think?

@palemieux palemieux Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I expect Qfactor may be applied to channels beyond the first three:

  • At least in the case of OpenEXR, where images routinely have dozens of channels, with potentially more than 3 containing visual information
  • Qfactor can be extended to cover non YCbCr channels by removing/changing the visual weights

Will change the order of the parameters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

float delta_ref = 0;
float G_c = 1;
const open_htj2k::visual_weighting_params vp;
std::vector<double> W_b;

@aous72 aous72 Jun 29, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This std::vector objects call new. I would really like to remove them, even if that meant I have to modify Osamu's library. Ultimately, these are tables with a known number of entries.
The main ojph library have very limited calls to new.
I know Osamu attempts to limit the new calls to one per vector by using reserve.

The horrors of C++.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Questions:

  • would you be happy with reserve() to avoid multiple calls to new()?
  • are you happy with std::array?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think std::array is a good idea.
For the time being, I will merge the PR, but then I will modify Osamu's code. Do you have any objections?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For the time being, I will merge the PR, but then I will modify Osamu's code. Do you have any objections?

Zero objection assuming that you are ok with submitting a PR against Osamu's library with your proposed improvements.

@aous72 aous72 merged commit e3c948f into aous72:master Jun 30, 2026
18 checks passed
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.

2 participants