Copies the codec type property (av1C or av2C) from the first grid tile to the grid item. Also checks that all tiles have the same codec type and that it's valid.
| 1601 | // Copies the codec type property (av1C or av2C) from the first grid tile to the grid item. |
| 1602 | // Also checks that all tiles have the same codec type and that it's valid. |
| 1603 | static avifResult avifDecoderAdoptGridTileCodecType(avifDecoder * decoder, |
| 1604 | avifDecoderItem * gridItem, |
| 1605 | const uint32_t * dimgIdxToItemIdx, |
| 1606 | uint32_t numTiles) |
| 1607 | { |
| 1608 | avifDecoderItem * firstTileItem = NULL; |
| 1609 | for (uint32_t dimgIdx = 0; dimgIdx < numTiles; ++dimgIdx) { |
| 1610 | const uint32_t itemIdx = dimgIdxToItemIdx[dimgIdx]; |
| 1611 | AVIF_ASSERT_OR_RETURN(itemIdx < gridItem->meta->items.count); |
| 1612 | avifDecoderItem * item = gridItem->meta->items.item[itemIdx]; |
| 1613 | |
| 1614 | // According to HEIF (ISO 14496-12), Section 6.6.2.3.1, the SingleItemTypeReferenceBox of type 'dimg' |
| 1615 | // identifies the input images of the derived image item of type 'grid'. Since the reference_count |
| 1616 | // shall be equal to rows*columns, unknown tile item types cannot be skipped but must be considered |
| 1617 | // as errors. |
| 1618 | const avifCodecType tileCodecType = avifGetCodecType(item->type); |
| 1619 | if (tileCodecType == AVIF_CODEC_TYPE_UNKNOWN) { |
| 1620 | char type[4]; |
| 1621 | for (int j = 0; j < 4; j++) { |
| 1622 | if (isprint((unsigned char)item->type[j])) { |
| 1623 | type[j] = item->type[j]; |
| 1624 | } else { |
| 1625 | type[j] = '.'; |
| 1626 | } |
| 1627 | } |
| 1628 | avifDiagnosticsPrintf(&decoder->diag, |
| 1629 | "Tile item ID %u has an unknown item type '%.4s' (%02x%02x%02x%02x)", |
| 1630 | item->id, |
| 1631 | type, |
| 1632 | item->type[0], |
| 1633 | item->type[1], |
| 1634 | item->type[2], |
| 1635 | item->type[3]); |
| 1636 | return AVIF_RESULT_INVALID_IMAGE_GRID; |
| 1637 | } |
| 1638 | |
| 1639 | if (item->hasUnsupportedEssentialProperty) { |
| 1640 | // An essential property isn't supported by libavif; can't |
| 1641 | // decode a grid image if any tile in the grid isn't supported. |
| 1642 | avifDiagnosticsPrintf(&decoder->diag, "Grid image contains tile with an unsupported property marked as essential"); |
| 1643 | return AVIF_RESULT_INVALID_IMAGE_GRID; |
| 1644 | } |
| 1645 | |
| 1646 | if (firstTileItem == NULL) { |
| 1647 | firstTileItem = item; |
| 1648 | // Adopt the configuration property of the first image item tile, so that it can be queried from |
| 1649 | // the top-level color/alpha item during avifDecoderReset(). |
| 1650 | const avifCodecType codecType = avifGetCodecType(item->type); |
| 1651 | const char * configPropName = avifGetConfigurationPropertyName(codecType); |
| 1652 | const avifProperty * srcProp = avifPropertyArrayFind(&item->properties, configPropName); |
| 1653 | if (!srcProp) { |
| 1654 | avifDiagnosticsPrintf(&decoder->diag, "Grid image's first tile is missing an %s property", configPropName); |
| 1655 | return AVIF_RESULT_INVALID_IMAGE_GRID; |
| 1656 | } |
| 1657 | avifProperty * dstProp = (avifProperty *)avifArrayPush(&gridItem->properties); |
| 1658 | AVIF_CHECKERR(dstProp != NULL, AVIF_RESULT_OUT_OF_MEMORY); |
| 1659 | *dstProp = *srcProp; |
| 1660 |
no test coverage detected