Skip to content

Commit

Permalink
Use avifDecoderItemShouldBeSkipped when harvesting ispe
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vigneshvg committed Jun 11, 2024
1 parent 37733fb commit 5862132
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 5862132

Please sign in to comment.