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

Refactor gain map API #2444

Merged
merged 8 commits into from
Sep 30, 2024
Merged

Refactor gain map API #2444

merged 8 commits into from
Sep 30, 2024

Conversation

maryla-uc
Copy link
Collaborator

avifGainMapMetadata and avifGainMapMetadataDouble were not future proof. Instead of adding Create()/Destroy() functions, simply inline avifGainMapMetadata inside avifGainMap and remove avifGainMapMetadataDouble.

Add avifSignedFraction (int32/uint32) and avifUnsignedFraction (uint32/uint32), in addition to the existing avifFraction (int32/int32). It's unfortunate that avifFraction uses a int32 denominator, but I don't think this can be changed now. This is not strictly necessary but makes the API a bit neater.

Expose avifDoubleToSignedFraction and avifDoubleToUnsignedFraction in avif.h
This is not strictly necessary either, since users should rarely have to fill in the fraction values themselves, and even if they do, they can use a naive method like setting the denominator to a large fixed value. But they are convenient and avifjpeg.c does use them right now. However, I'm open to removing them from the API, or putting them behind AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP (although this define should go away eventually).

Remote avifGainMapMetadata and avifGainMapMetadataDouble which were
not extensible. Expose avifDoubleTo(Un)SignedFraction instead.
@maryla-uc maryla-uc requested a review from y-guyon September 26, 2024 09:45
apps/avifgainmaputil/swapbase_command.cc Outdated Show resolved Hide resolved
src/avif.c Outdated Show resolved Hide resolved
src/gainmap.c Outdated Show resolved Hide resolved
src/avif.c Outdated Show resolved Hide resolved
src/gainmap.c Outdated Show resolved Hide resolved
src/gainmap.c Outdated Show resolved Hide resolved
src/gainmap.c Outdated Show resolved Hide resolved
src/gainmap.c Show resolved Hide resolved
tests/gtest/avif_fuzztest_helpers.cc Outdated Show resolved Hide resolved
tests/gtest/avifgainmaptest.cc Outdated Show resolved Hide resolved
include/avif/avif.h Show resolved Hide resolved
{
uint32_t positive_numerator;
if (!avifDoubleToUnsignedFractionImpl(fabs(v), INT32_MAX, &positive_numerator, denominator)) {
if (!avifDoubleToUnsignedFractionImpl(fabs(v), INT32_MAX, &positive_numerator, &fraction->d)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In avifDoubleToUnsignedFractionImpl(), the variable maxD is declared as uint64_t, but it is only used in a comparison with newD, which is a double. So maxD could be declared as double. If maxD should have an integer type, uint32_t is sufficient.

Copy link
Collaborator

@wantehchang wantehchang left a comment

Choose a reason for hiding this comment

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

Maryla: Please consider my review as supplemental. I only reviewed the changes to avif.h. They look good.

@maryla-uc maryla-uc merged commit cdb89c9 into AOMediaCodec:main Sep 30, 2024
16 of 17 checks passed
@wantehchang
Copy link
Collaborator

@vigneshvg FYI.

@maryla-uc Maryla: Could you or Vignesh port the changes to the public header avif.h to CrabbyAvif? Thanks.

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.

3 participants