Skip to content

Commit 70894d6

Browse files
committed
gdk-pixbuf: new quality settings
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.
1 parent ab9428a commit 70894d6

1 file changed

Lines changed: 11 additions & 19 deletions

File tree

contrib/gdk-pixbuf/loader.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ avif_image_saver (FILE *f,
344344
gchar **values,
345345
GError **error)
346346
{
347-
int width, height, min_quantizer, max_quantizer, alpha_quantizer;
348-
long quality = 52; /* default; must be between 0 and 100 */
347+
int width, height;
348+
long quality = 68; /* default; must be between 0 and 100 */
349349
gboolean save_alpha;
350350
avifImage *avif;
351351
avifRGBImage rgb;
@@ -434,19 +434,7 @@ avif_image_saver (FILE *f,
434434
}
435435
}
436436

437-
max_quantizer = AVIF_QUANTIZER_WORST_QUALITY * (100 - (int) quality) / 100;
438-
min_quantizer = 0;
439-
alpha_quantizer = 0;
440-
441-
if (max_quantizer > 20) {
442-
min_quantizer = max_quantizer - 20;
443-
444-
if (max_quantizer > 40) {
445-
alpha_quantizer = max_quantizer - 40;
446-
}
447-
}
448-
449-
avif = avifImageCreate (width, height, 8, AVIF_PIXEL_FORMAT_YUV420);
437+
avif = avifImageCreate (width, height, 8, quality >= 90 ? AVIF_PIXEL_FORMAT_YUV444 : AVIF_PIXEL_FORMAT_YUV420);
450438
avif->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601;
451439
avifRGBImageSetDefaults (&rgb, avif);
452440

@@ -474,10 +462,14 @@ avif_image_saver (FILE *f,
474462
encoder = avifEncoderCreate ();
475463

476464
encoder->maxThreads = CLAMP (maxThreads, 1, 64);
477-
encoder->minQuantizer = min_quantizer;
478-
encoder->maxQuantizer = max_quantizer;
479-
encoder->minQuantizerAlpha = 0;
480-
encoder->maxQuantizerAlpha = alpha_quantizer;
465+
encoder->quality = (int) quality;
466+
if (save_alpha) {
467+
if (quality >= 50) {
468+
encoder->qualityAlpha = 100;
469+
} else {
470+
encoder->qualityAlpha = 75 + (int) quality / 2;
471+
}
472+
}
481473
encoder->speed = 6;
482474

483475
res = avifEncoderWrite (encoder, avif, &raw);

0 commit comments

Comments
 (0)