| 6937 | } |
| 6938 | |
| 6939 | static 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 | |
| 6972 | avifResult avifDecoderNextImage(avifDecoder * decoder) |
| 6973 | { |
no test coverage detected