@@ -404,18 +404,14 @@ static avifBool avifProcessAOMOptionsPreInit(avifCodec * codec, avifBool alpha,
404404 return AVIF_TRUE ;
405405}
406406
407- static avifBool avifImageUsesTuneIq (const avifCodec * codec , avifBool alpha , avifBool useLibavifDefaultTuneMetric , aom_tune_metric libavifDefaultTuneMetric )
407+ static avifBool avifImageUsesTuneIq (const avifCodec * codec , avifBool alpha )
408408{
409409#if !defined(AOM_HAVE_TUNE_IQ )
410410// Define the tune IQ value here if libaom doesn't define it. The enum value is guaranteed to never change
411411// in libaom, so this definition won't ever get out of sync.
412412#define AOM_TUNE_IQ 10
413413#endif
414414
415- if (useLibavifDefaultTuneMetric ) {
416- return libavifDefaultTuneMetric == AOM_TUNE_IQ ;
417- }
418-
419415 avifBool useTuneIq = AVIF_FALSE ;
420416 avifBool isAnyTuneDefined = AVIF_FALSE ;
421417
@@ -433,20 +429,23 @@ static avifBool avifImageUsesTuneIq(const avifCodec * codec, avifBool alpha, avi
433429 isAnyTuneDefined = AVIF_TRUE ;
434430
435431 if (aomOptionParseEnum (entry -> value , tuneIqEnum , & val )) {
436- useTuneIq = (val == AOM_TUNE_IQ );
432+ assert (val == AOM_TUNE_IQ );
433+ useTuneIq = AVIF_TRUE ;
434+ } else {
435+ useTuneIq = AVIF_FALSE ;
437436 }
438437 }
439438 }
440439
441- if (!isAnyTuneDefined && codec -> internal -> previousFrameUsedTuneIq ) {
442- // Handle the case where the encoder was called with avifEncoderSetCodecSpecificOption("tune", "iq")
443- // for a previous frame and not called (or called with NULL) for this frame, because the tune
444- // option persists across frames in libaom.
445- // In this case, we know libaom will also use tune=iq for this frame.
446- return AVIF_TRUE ;
440+ if (isAnyTuneDefined ) {
441+ return useTuneIq ;
447442 }
448443
449- return useTuneIq ;
444+ // Handle the case where the encoder was called with avifEncoderSetCodecSpecificOption("tune", "iq")
445+ // for a previous frame and not called (or called with NULL) for this frame, because the tune
446+ // option persists across frames in libaom.
447+ // In this case, return what the previous frame used.
448+ return codec -> internal -> previousFrameUsedTuneIq ;
450449}
451450
452451#if !defined(HAVE_AOM_CODEC_SET_OPTION )
@@ -752,14 +751,13 @@ static avifResult aomCodecEncodeImage(avifCodec * codec,
752751 libavifDefaultTuneMetric = AOM_TUNE_SSIM ;
753752 }
754753 }
755- AVIF_ASSERT_OR_RETURN (!codec -> internal -> previousFrameUsedTuneIq );
756754 }
757755
758756 struct aom_codec_enc_cfg * cfg = & codec -> internal -> cfg ;
759757 avifBool quantizerUpdated = AVIF_FALSE ;
760758 // True if libavif knows that tune=iq is used, either by default by libavif, or explicitly set by the user.
761759 // False otherwise (including if libaom uses tune=iq by default, which is not the case as of v3.13.1 and earlier versions).
762- const avifBool useTuneIq = avifImageUsesTuneIq (codec , alpha , useLibavifDefaultTuneMetric , libavifDefaultTuneMetric );
760+ const avifBool useTuneIq = useLibavifDefaultTuneMetric ? libavifDefaultTuneMetric == AOM_TUNE_IQ : avifImageUsesTuneIq (codec , alpha );
763761 const int quantizer = aomQualityToQuantizer (quality , useTuneIq );
764762
765763 // libavif needs to know whether the current frame uses tune=iq for the next frame, as libaom persists
0 commit comments