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

Function avifDecoderDataCopyTileToImage

src/read.c:1823–1878  ·  view source on GitHub ↗

Copies over the pixels from the tile into dstImage. Verifies that the relevant properties of the tile match those of the first tile in case of a grid.

Source from the content-addressed store, hash-verified

1821// Copies over the pixels from the tile into dstImage.
1822// Verifies that the relevant properties of the tile match those of the first tile in case of a grid.
1823static avifResult avifDecoderDataCopyTileToImage(avifDecoderData * data,
1824 const avifTileInfo * info,
1825 avifImage * dstImage,
1826 const avifTile * tile,
1827 unsigned int tileIndex)
1828{
1829 const avifTile * firstTile = &data->tiles.tile[info->firstTileIndex];
1830 if (tile != firstTile) {
1831 // Check for tile consistency. All tiles in a grid image should match the first tile in the properties checked below.
1832 if ((tile->image->width != firstTile->image->width) || (tile->image->height != firstTile->image->height) ||
1833 (tile->image->depth != firstTile->image->depth) || (tile->image->yuvFormat != firstTile->image->yuvFormat) ||
1834 (tile->image->yuvRange != firstTile->image->yuvRange) || (tile->image->colorPrimaries != firstTile->image->colorPrimaries) ||
1835 (tile->image->transferCharacteristics != firstTile->image->transferCharacteristics) ||
1836 (tile->image->matrixCoefficients != firstTile->image->matrixCoefficients)) {
1837 avifDiagnosticsPrintf(data->diag, "Grid image contains mismatched tiles");
1838 return AVIF_RESULT_INVALID_IMAGE_GRID;
1839 }
1840 }
1841
1842 // Only keep the relevant planes in the destination image. Otherwise,
1843 // unjustified failures may come from trying to copy alpha tiles with odd
1844 // coordinates into the dstImage when the chroma planes are subsampled.
1845 avifImage dstView;
1846 avifImageSetDefaults(&dstView);
1847 const avifCropRect srcViewRect = { 0, 0, dstImage->width, dstImage->height };
1848 AVIF_ASSERT_OR_RETURN(avifImageSetViewRect(&dstView, dstImage, &srcViewRect) == AVIF_RESULT_OK);
1849 if (avifIsAlpha(tile->input->itemCategory)) {
1850 avifImageFreePlanes(&dstView, AVIF_PLANES_YUV);
1851 dstView.yuvFormat = AVIF_PIXEL_FORMAT_NONE;
1852 } else {
1853 avifImageFreePlanes(&dstView, AVIF_PLANES_A);
1854 }
1855
1856 avifImage srcTileView;
1857 avifImageSetDefaults(&srcTileView);
1858 avifImage dstTileView;
1859 avifImageSetDefaults(&dstTileView);
1860 avifCropRect dstTileViewRect = { 0, 0, firstTile->image->width, firstTile->image->height };
1861 if (info->grid.rows > 0 && info->grid.columns > 0) {
1862 unsigned int rowIndex = tileIndex / info->grid.columns;
1863 unsigned int colIndex = tileIndex % info->grid.columns;
1864 dstTileViewRect.x = firstTile->image->width * colIndex;
1865 dstTileViewRect.y = firstTile->image->height * rowIndex;
1866 if (dstTileViewRect.x + dstTileViewRect.width > info->grid.outputWidth) {
1867 dstTileViewRect.width = info->grid.outputWidth - dstTileViewRect.x;
1868 }
1869 if (dstTileViewRect.y + dstTileViewRect.height > info->grid.outputHeight) {
1870 dstTileViewRect.height = info->grid.outputHeight - dstTileViewRect.y;
1871 }
1872 }
1873 const avifCropRect srcTileViewRect = { 0, 0, dstTileViewRect.width, dstTileViewRect.height };
1874 AVIF_ASSERT_OR_RETURN(avifImageSetViewRect(&dstTileView, &dstView, &dstTileViewRect) == AVIF_RESULT_OK);
1875 AVIF_ASSERT_OR_RETURN(avifImageSetViewRect(&srcTileView, tile->image, &srcTileViewRect) == AVIF_RESULT_OK);
1876 avifImageCopySamples(&dstTileView, &srcTileView, avifIsAlpha(tile->input->itemCategory) ? AVIF_PLANES_A : AVIF_PLANES_YUV);
1877 return AVIF_RESULT_OK;
1878}
1879
1880// If colorId == 0 (a sentinel value as item IDs must be nonzero), accept any found EXIF/XMP metadata. Passing in 0

Calls 6

avifDiagnosticsPrintfFunction · 0.85
avifImageSetDefaultsFunction · 0.85
avifImageSetViewRectFunction · 0.85
avifIsAlphaFunction · 0.85
avifImageFreePlanesFunction · 0.85
avifImageCopySamplesFunction · 0.85

Tested by

no test coverage detected