Skip to content

Commit

Permalink
Do not free alpha plane in grid allocation when only yuvFormat changes (
Browse files Browse the repository at this point in the history
  • Loading branch information
vrabaud committed Jan 22, 2024
1 parent d79c496 commit 4f7d822
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -1464,19 +1464,26 @@ static avifResult avifDecoderDataAllocateGridImagePlanes(avifDecoderData * data,
}

// Lazily populate dstImage with the new frame's properties.
if ((dstImage->width != grid->outputWidth) || (dstImage->height != grid->outputHeight) ||
(dstImage->depth != tile->image->depth) || (!alpha && (dstImage->yuvFormat != tile->image->yuvFormat))) {
const avifBool dimsOrDepthIsDifferent = (dstImage->width != grid->outputWidth) || (dstImage->height != grid->outputHeight) ||
(dstImage->depth != tile->image->depth);
const avifBool yuvFormatIsDifferent = !alpha && (dstImage->yuvFormat != tile->image->yuvFormat);
if (dimsOrDepthIsDifferent || yuvFormatIsDifferent) {
if (alpha) {
// Alpha doesn't match size, just bail out
avifDiagnosticsPrintf(data->diag, "Alpha plane dimensions do not match color plane dimensions");
return AVIF_RESULT_INVALID_IMAGE_GRID;
}

avifImageFreePlanes(dstImage, AVIF_PLANES_ALL);
dstImage->width = grid->outputWidth;
dstImage->height = grid->outputHeight;
dstImage->depth = tile->image->depth;
dstImage->yuvFormat = tile->image->yuvFormat;
if (dimsOrDepthIsDifferent) {
avifImageFreePlanes(dstImage, AVIF_PLANES_ALL);
dstImage->width = grid->outputWidth;
dstImage->height = grid->outputHeight;
dstImage->depth = tile->image->depth;
}
if (yuvFormatIsDifferent) {
avifImageFreePlanes(dstImage, AVIF_PLANES_YUV);
dstImage->yuvFormat = tile->image->yuvFormat;
}
// Keep dstImage->yuvRange which is already set to its correct value
// (extracted from the 'colr' box if parsed or from a Sequence Header OBU otherwise).

Expand Down

0 comments on commit 4f7d822

Please sign in to comment.