Skip to content

Commit

Permalink
gdk-pixbuf: new quality settings
Browse files Browse the repository at this point in the history
Now we set the quality parameter directly instead of the old way,
when min_quantizer/maxQuantizer were used.
YUV444 is used for highest quality range from 90 till 100.
  • Loading branch information
novomesk authored and wantehchang committed Jan 4, 2024
1 parent c641380 commit 1410133
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions contrib/gdk-pixbuf/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ avif_image_saver (FILE *f,
gchar **values,
GError **error)
{
int width, height, min_quantizer, max_quantizer, alpha_quantizer;
long quality = 52; /* default; must be between 0 and 100 */
int width, height;
long quality = 68; /* default; must be between 0 and 100 */
gboolean save_alpha;
avifImage *avif;
avifRGBImage rgb;
Expand Down Expand Up @@ -434,19 +434,7 @@ avif_image_saver (FILE *f,
}
}

max_quantizer = AVIF_QUANTIZER_WORST_QUALITY * (100 - (int) quality) / 100;
min_quantizer = 0;
alpha_quantizer = 0;

if (max_quantizer > 20) {
min_quantizer = max_quantizer - 20;

if (max_quantizer > 40) {
alpha_quantizer = max_quantizer - 40;
}
}

avif = avifImageCreate (width, height, 8, AVIF_PIXEL_FORMAT_YUV420);
avif = avifImageCreate (width, height, 8, quality >= 90 ? AVIF_PIXEL_FORMAT_YUV444 : AVIF_PIXEL_FORMAT_YUV420);
avif->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601;
avifRGBImageSetDefaults (&rgb, avif);

Expand Down Expand Up @@ -474,10 +462,14 @@ avif_image_saver (FILE *f,
encoder = avifEncoderCreate ();

encoder->maxThreads = CLAMP (maxThreads, 1, 64);
encoder->minQuantizer = min_quantizer;
encoder->maxQuantizer = max_quantizer;
encoder->minQuantizerAlpha = 0;
encoder->maxQuantizerAlpha = alpha_quantizer;
encoder->quality = (int) quality;
if (save_alpha) {
if (quality >= 50) {
encoder->qualityAlpha = 100;
} else {
encoder->qualityAlpha = 75 + (int) quality / 2;
}
}
encoder->speed = 6;

res = avifEncoderWrite (encoder, avif, &raw);
Expand Down

0 comments on commit 1410133

Please sign in to comment.