| 6727 | } |
| 6728 | |
| 6729 | static avifResult avifDecoderDecodeTiles(avifDecoder * decoder, uint32_t nextImageIndex, avifTileInfo * info) |
| 6730 | { |
| 6731 | const unsigned int oldDecodedTileCount = info->decodedTileCount; |
| 6732 | for (unsigned int tileIndex = oldDecodedTileCount; tileIndex < info->tileCount; ++tileIndex) { |
| 6733 | avifTile * tile = &decoder->data->tiles.tile[info->firstTileIndex + tileIndex]; |
| 6734 | |
| 6735 | const avifDecodeSample * sample = &tile->input->samples.sample[nextImageIndex]; |
| 6736 | if (sample->data.size < sample->size) { |
| 6737 | AVIF_ASSERT_OR_RETURN(decoder->allowIncremental); |
| 6738 | // Data is missing but there is no error yet. Output available pixel rows. |
| 6739 | return AVIF_RESULT_OK; |
| 6740 | } |
| 6741 | |
| 6742 | avifBool isLimitedRangeAlpha = AVIF_FALSE; |
| 6743 | tile->codec->maxThreads = decoder->maxThreads; |
| 6744 | tile->codec->imageSizeLimit = decoder->imageSizeLimit; |
| 6745 | tile->codec->imageDimensionLimit = decoder->imageDimensionLimit; |
| 6746 | if (!tile->codec->getNextImage(tile->codec, sample, avifIsAlpha(tile->input->itemCategory), &isLimitedRangeAlpha, tile->image)) { |
| 6747 | avifDiagnosticsPrintf(&decoder->diag, "tile->codec->getNextImage() failed"); |
| 6748 | return avifGetErrorForItemCategory(tile->input->itemCategory); |
| 6749 | } |
| 6750 | |
| 6751 | // Section 2.3.4 of AV1 Codec ISO Media File Format Binding v1.2.0 says: |
| 6752 | // the full_range_flag in the colr box shall match the color_range |
| 6753 | // flag in the Sequence Header OBU. |
| 6754 | // See https://aomediacodec.github.io/av1-isobmff/v1.2.0.html#av1codecconfigurationbox-semantics. |
| 6755 | // If a 'colr' box of colour_type 'nclx' was parsed, a mismatch between |
| 6756 | // the 'colr' decoder->image->yuvRange and the AV1 OBU |
| 6757 | // tile->image->yuvRange should be treated as an error. |
| 6758 | // However codec_svt.c was not encoding the color_range field for |
| 6759 | // multiple years, so there probably are files in the wild that will |
| 6760 | // fail decoding if this is enforced. Thus this pattern is allowed. |
| 6761 | // Section 12.1.5.1 of ISO 14496-12 (ISOBMFF) says: |
| 6762 | // If colour information is supplied in both this [colr] box, and also |
| 6763 | // in the video bitstream, this box takes precedence, and over-rides |
| 6764 | // the information in the bitstream. |
| 6765 | // So decoder->image->yuvRange is kept because it was either the 'colr' |
| 6766 | // value set when the 'colr' box was parsed, or it was the AV1 OBU value |
| 6767 | // extracted from the sequence header OBU of the first tile of the first |
| 6768 | // frame (if no 'colr' box of colour_type 'nclx' was found). |
| 6769 | |
| 6770 | // Alpha plane with limited range is not allowed by the latest revision |
| 6771 | // of the specification. However, it was allowed in version 1.0.0 of the |
| 6772 | // specification. To allow such files, simply convert the alpha plane to |
| 6773 | // full range. |
| 6774 | if (avifIsAlpha(tile->input->itemCategory) && isLimitedRangeAlpha) { |
| 6775 | avifResult result = avifImageLimitedToFullAlpha(tile->image); |
| 6776 | if (result != AVIF_RESULT_OK) { |
| 6777 | avifDiagnosticsPrintf(&decoder->diag, "avifImageLimitedToFullAlpha failed"); |
| 6778 | return result; |
| 6779 | } |
| 6780 | } |
| 6781 | |
| 6782 | // Scale the decoded image so that it corresponds to this tile's output dimensions |
| 6783 | if ((tile->width != tile->image->width) || (tile->height != tile->image->height)) { |
| 6784 | if (avifImageScaleWithLimit(tile->image, |
| 6785 | tile->width, |
| 6786 | tile->height, |
no test coverage detected