Allocate alpha alongside YUV (if necessary) during y4m decode to avoid incorrect alphaRowBytes math
diff --git a/apps/shared/y4m.c b/apps/shared/y4m.c
index f7270f9..695561e 100644
--- a/apps/shared/y4m.c
+++ b/apps/shared/y4m.c
@@ -356,6 +356,9 @@
avif->yuvRange = frame.range;
avif->yuvChromaSamplePosition = frame.chromaSamplePosition;
avifImageAllocatePlanes(avif, AVIF_PLANES_YUV);
+ if (frame.hasAlpha) {
+ avifImageAllocatePlanes(avif, AVIF_PLANES_A);
+ }
avifPixelFormatInfo info;
avifGetPixelFormatInfo(avif->yuvFormat, &info);
@@ -378,7 +381,6 @@
}
}
if (frame.hasAlpha) {
- avifImageAllocatePlanes(avif, AVIF_PLANES_A);
if (fread(avif->alphaPlane, 1, planeBytes[3], frame.inputFile) != planeBytes[3]) {
fprintf(stderr, "Failed to read y4m plane (not enough data): %s\n", frame.displayFilename);
goto cleanup;