MCPcopy Create free account
hub / github.com/AOMediaCodec/libavif / avifDecoderCreateCodecs

Function avifDecoderCreateCodecs

src/read.c:5424–5468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5422}
5423
5424static avifResult avifDecoderCreateCodecs(avifDecoder * decoder)
5425{
5426 avifDecoderData * data = decoder->data;
5427 avifDecoderDataResetCodec(data);
5428
5429 if (data->source == AVIF_DECODER_SOURCE_TRACKS) {
5430 // In this case, we will use at most two codec instances (one for the color planes and one for the alpha plane).
5431 // Gain maps are not supported.
5432 AVIF_CHECKRES(avifCodecCreateInternal(decoder->codecChoice, &decoder->data->tiles.tile[0], &decoder->diag, &data->codec));
5433 data->tiles.tile[0].codec = data->codec;
5434 if (data->tiles.count > 1) {
5435 AVIF_CHECKRES(avifCodecCreateInternal(decoder->codecChoice, &decoder->data->tiles.tile[1], &decoder->diag, &data->codecAlpha));
5436 data->tiles.tile[1].codec = data->codecAlpha;
5437 }
5438 } else {
5439 // In this case, we will use one codec instance when there is only one tile or when all of the following conditions are
5440 // met:
5441 // - The image must have exactly one layer (i.e. decoder->imageCount == 1).
5442 // - All the tiles must have the same operating point (because the codecs take operating point once at initialization
5443 // and do not allow it to be changed later).
5444 // - All the tiles must have the same value for allLayers (because the codecs take allLayers once at initialization
5445 // and do not allow it to be changed later).
5446 // - If the image has a single tile, it must not have a single tile alpha plane (in this case we will steal the planes
5447 // from the decoder, so we cannot use the same decoder for both the color and the alpha planes).
5448 // - All tiles have the same type (AV1 or AV2).
5449 // - No tile buffer access after another tile was decoded (i.e. no Sample Transform compositing because it happens
5450 // after decoding all tiles).
5451 // Otherwise, we will use |tiles.count| decoder instances (one instance for each tile).
5452 const avifBool canUseSingleCodecInstance =
5453 ((data->tiles.count == 1) || (decoder->imageCount == 1 && avifTilesCanBeDecodedWithSameCodecInstance(data))) &&
5454 data->sampleTransformNumInputImageItems == 0;
5455 if (canUseSingleCodecInstance) {
5456 AVIF_CHECKRES(avifCodecCreateInternal(decoder->codecChoice, &decoder->data->tiles.tile[0], &decoder->diag, &data->codec));
5457 for (unsigned int i = 0; i < decoder->data->tiles.count; ++i) {
5458 decoder->data->tiles.tile[i].codec = data->codec;
5459 }
5460 } else {
5461 for (unsigned int i = 0; i < decoder->data->tiles.count; ++i) {
5462 avifTile * tile = &decoder->data->tiles.tile[i];
5463 AVIF_CHECKRES(avifCodecCreateInternal(decoder->codecChoice, tile, &decoder->diag, &tile->codec));
5464 }
5465 }
5466 }
5467 return AVIF_RESULT_OK;
5468}
5469
5470// Returns the primary color item if found, or NULL.
5471static avifDecoderItem * avifMetaFindColorItem(avifMeta * meta)

Callers 1

avifDecoderNextImageFunction · 0.85

Tested by

no test coverage detected