From 58621324090055b33290e0354847b922d8c482f2 Mon Sep 17 00:00:00 2001 From: Vignesh Venkatasubramanian Date: Mon, 10 Jun 2024 23:14:03 +0000 Subject: [PATCH] Use avifDecoderItemShouldBeSkipped when harvesting ispe This function has the same conditions as the ones that are explicitly re-written with one extra condition (thumbnailForID != 0). This extra condition is okay to be checked too in this case since we anyway do not process such items. --- src/read.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/read.c b/src/read.c index 32e279b532..ce09af4c3c 100644 --- a/src/read.c +++ b/src/read.c @@ -4355,6 +4355,17 @@ static avifResult avifDecoderPrepareSample(avifDecoder * decoder, avifDecodeSamp return AVIF_RESULT_OK; } +// Returns AVIF_TRUE if the item should be skipped. Items should be skipped for one of the following reasons: +// * Size is 0. +// * Has an essential property that isn't supported by libavif. +// * Item is not a single image or a grid. +// * Item is a thumbnail. +static avifBool avifDecoderItemShouldBeSkipped(const avifDecoderItem * item) +{ + return !item->size || item->hasUnsupportedEssentialProperty || + (avifGetCodecType(item->type) == AVIF_CODEC_TYPE_UNKNOWN && memcmp(item->type, "grid", 4)) || item->thumbnailForID != 0; +} + avifResult avifDecoderParse(avifDecoder * decoder) { avifDiagnosticsClearError(&decoder->diag); @@ -4384,16 +4395,7 @@ avifResult avifDecoderParse(avifDecoder * decoder) avifDecoderData * data = decoder->data; for (uint32_t itemIndex = 0; itemIndex < data->meta->items.count; ++itemIndex) { avifDecoderItem * item = data->meta->items.item[itemIndex]; - if (!item->size) { - continue; - } - if (item->hasUnsupportedEssentialProperty) { - // An essential property isn't supported by libavif; ignore the item. - continue; - } - avifBool isGrid = (memcmp(item->type, "grid", 4) == 0); - if ((avifGetCodecType(item->type) == AVIF_CODEC_TYPE_UNKNOWN) && !isGrid) { - // probably exif or some other data + if (avifDecoderItemShouldBeSkipped(item)) { continue; } @@ -4539,17 +4541,6 @@ static avifResult avifDecoderCreateCodecs(avifDecoder * decoder) return AVIF_RESULT_OK; } -// Returns AVIF_TRUE if the item should be skipped. Items should be skipped for one of the following reasons: -// * Size is 0. -// * Has an essential property that isn't supported by libavif. -// * Item is not a single image or a grid. -// * Item is a thumbnail. -static avifBool avifDecoderItemShouldBeSkipped(const avifDecoderItem * item) -{ - return !item->size || item->hasUnsupportedEssentialProperty || - (avifGetCodecType(item->type) == AVIF_CODEC_TYPE_UNKNOWN && memcmp(item->type, "grid", 4)) || item->thumbnailForID != 0; -} - // Returns the primary color item if found, or NULL. static avifDecoderItem * avifMetaFindColorItem(avifMeta * meta) {