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

Function avifDecoderApplySampleTransform

src/read.c:6939–6970  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6937}
6938
6939static avifResult avifDecoderApplySampleTransform(const avifDecoder * decoder, avifImage * dstImage)
6940{
6941 if (dstImage->depth != decoder->data->meta->sampleTransformDepth) {
6942 AVIF_ASSERT_OR_RETURN(dstImage->yuvPlanes[0] != NULL);
6943 AVIF_ASSERT_OR_RETURN(dstImage->imageOwnsYUVPlanes);
6944
6945 // Use a temporary buffer because dstImage may point to decoder->image, which could be an input image.
6946 avifImage * dstImageWithCorrectDepth =
6947 avifImageCreate(dstImage->width, dstImage->height, decoder->data->meta->sampleTransformDepth, dstImage->yuvFormat);
6948 AVIF_CHECKERR(dstImageWithCorrectDepth != NULL, AVIF_RESULT_OUT_OF_MEMORY);
6949 dstImageWithCorrectDepth->yuvRange = dstImage->yuvRange;
6950 avifResult result =
6951 avifImageAllocatePlanes(dstImageWithCorrectDepth, dstImage->alphaPlane != NULL ? AVIF_PLANES_ALL : AVIF_PLANES_YUV);
6952 if (result == AVIF_RESULT_OK) {
6953 result = avifDecoderApplySampleTransform(decoder, dstImageWithCorrectDepth);
6954 if (result == AVIF_RESULT_OK) {
6955 // Keep the same dstImage object rather than swapping decoder->image, in case the user already accessed it.
6956 avifImageFreePlanes(dstImage, AVIF_PLANES_ALL);
6957 dstImage->depth = dstImageWithCorrectDepth->depth;
6958 avifImageStealPlanes(dstImage, dstImageWithCorrectDepth, AVIF_PLANES_ALL);
6959 }
6960 }
6961 avifImageDestroy(dstImageWithCorrectDepth);
6962 return result;
6963 }
6964
6965 AVIF_CHECKRES(avifDecoderApplySampleTransformForPlanes(decoder, AVIF_PLANES_YUV, dstImage));
6966 if (decoder->alphaPresent) {
6967 AVIF_CHECKRES(avifDecoderApplySampleTransformForPlanes(decoder, AVIF_PLANES_A, dstImage));
6968 }
6969 return AVIF_RESULT_OK;
6970}
6971
6972avifResult avifDecoderNextImage(avifDecoder * decoder)
6973{

Callers 1

avifDecoderNextImageFunction · 0.85

Calls 6

avifImageCreateFunction · 0.85
avifImageAllocatePlanesFunction · 0.85
avifImageFreePlanesFunction · 0.85
avifImageStealPlanesFunction · 0.85
avifImageDestroyFunction · 0.85

Tested by

no test coverage detected