Cap AVIF lossy quality at 99

Before this commit, lossy compression with 100 quality meant lossless compression, leading to a big gap between 99 and 100.

This commit caps the lossy quality at 99, ensuring that lossy compression is always lossy.

Fixes #14981
This commit is contained in:
Bjørn Erik Pedersen
2026-06-04 14:42:08 +02:00
committed by GitHub
parent 4e47d95db9
commit 248241b6e1
2 changed files with 4 additions and 0 deletions
+4
View File
@@ -685,6 +685,8 @@ void handle_commands(FILE *stream)
if (quality < 1) quality = 1;
if (quality > 100) quality = 100;
int avif_quality = (int)((quality - 1.0) / 99.0 * 100.0);
// Keep lossy strictly below lossless so quality 100 stays lossy. See issue 14981.
if (avif_quality >= AVIF_QUALITY_LOSSLESS) avif_quality = AVIF_QUALITY_LOSSLESS - 1;
encoder->quality = avif_quality;
encoder->qualityAlpha = avif_quality;
}
@@ -809,6 +811,8 @@ void handle_commands(FILE *stream)
if (quality < 1) quality = 1;
if (quality > 100) quality = 100;
int avif_quality = (int)((quality - 1.0) / 99.0 * 100.0);
// Keep lossy strictly below lossless so quality 100 stays lossy. See issue 14981.
if (avif_quality >= AVIF_QUALITY_LOSSLESS) avif_quality = AVIF_QUALITY_LOSSLESS - 1;
encoder->quality = avif_quality;
}
encoder->qualityAlpha = AVIF_QUALITY_LOSSLESS;
Binary file not shown.