Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The changes are relative to the previous release, unless the baseline is specifi
fails to allocate the destination gain map image.
* avifenc: reject mismatched --depth for Y4M input
* Use libaom AOMD_SET_FRAME_SIZE_LIMIT if available
* Fix bug in transfer function 11 (used for gain map creation/tone mapping)

## [1.4.1] - 2026-03-20

Expand Down
2 changes: 1 addition & 1 deletion src/colr.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static float avifToGammaLog100Sqrt10(float linear)
static float avifToLinearIEC61966(float gamma)
{
if (gamma < -4.5f * 0.018053968510807f) {
return powf((-gamma + 0.09929682680944f) / -1.09929682680944f, 1.0f / 0.45f);
return -powf((gamma - 0.09929682680944f) / -1.09929682680944f, 1.0f / 0.45f);
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.

Is this bug fix worth documenting in the changelog?

Note: I didn't compare the new code with the spec, but the original code is incorrect mathematically because the base of the power, (-gamma + 0.09929682680944f) / -1.09929682680944f, is negative.

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 added a changelog entry, I think it's good hygiene, thanks for reminding me.
Fortunately I think this bug is unlikely to have ever affected anyone. It only affects negative values, and only for transfer function 11 which probably nobody uses. And the transfer functions are only used by the gain map code (creation/tone mapping).

} else if (gamma < 4.5f * 0.018053968510807f) {
return gamma / 4.5f;
} else {
Expand Down
23 changes: 23 additions & 0 deletions tests/gtest/avifcolrtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ TEST(TransferCharacteristicsTest, RoundTrip) {
}
}

TEST(TransferCharacteristicsTest, NegativeRoundTrip) {
// Transfer functions that accept negative values.
const avifTransferCharacteristics tcs[] = {
AVIF_TRANSFER_CHARACTERISTICS_IEC61966,
AVIF_TRANSFER_CHARACTERISTICS_BT1361,
};
for (const avifTransferCharacteristics tc : tcs) {
SCOPED_TRACE("transfer characteristics: " + std::to_string(tc));

const avifTransferFunction to_linear =
avifTransferCharacteristicsGetGammaToLinearFunction(tc);
const avifTransferFunction to_gamma =
avifTransferCharacteristicsGetLinearToGammaFunction(tc);

const float test_values[] = {-0.1f, -0.05f, -0.2f};
for (const float v : test_values) {
// Check round trips.
EXPECT_NEAR(to_linear(to_gamma(v)), v, 0.00001f);
EXPECT_NEAR(to_gamma(to_linear(v)), v, 0.00001f);
}
}
}

// Check that the liner->gamma function has the right shape, i.e. it's mostly
// above the y=x diagonal.
// This detects bugs where the linear->gamma and
Expand Down
Loading