Require src UV in avifImageCopy() if Y is not NULL
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cd4af43..76d2007 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,8 @@
into cells.
* Apps must be built with libpng version 1.6.32 or above.
* Update svt.cmd/svt.sh: v1.3.0
+* avifImageCopy() no longer accepts source U and V channels to be NULL for
+ non-4:0:0 input if Y is not NULL and if AVIF_PLANES_YUV is specified.
## [0.11.1] - 2022-10-19
diff --git a/src/avif.c b/src/avif.c
index b0ba46b..75ea27c 100644
--- a/src/avif.c
+++ b/src/avif.c
@@ -181,19 +181,14 @@
avifImageSetMetadataXMP(dstImage, srcImage->xmp.data, srcImage->xmp.size);
if ((planes & AVIF_PLANES_YUV) && srcImage->yuvPlanes[AVIF_CHAN_Y]) {
+ if ((srcImage->yuvFormat != AVIF_PIXEL_FORMAT_YUV400) &&
+ (!srcImage->yuvPlanes[AVIF_CHAN_U] || !srcImage->yuvPlanes[AVIF_CHAN_V])) {
+ return AVIF_RESULT_INVALID_ARGUMENT;
+ }
const avifResult allocationResult = avifImageAllocatePlanes(dstImage, AVIF_PLANES_YUV);
if (allocationResult != AVIF_RESULT_OK) {
return allocationResult;
}
- for (int uvPlane = AVIF_CHAN_U; uvPlane <= AVIF_CHAN_V; ++uvPlane) {
- if (!srcImage->yuvRowBytes[uvPlane]) {
- // plane is absent. If we're copying from a source without
- // them, mimic the source image's state by removing our copy.
- avifFree(dstImage->yuvPlanes[uvPlane]);
- dstImage->yuvPlanes[uvPlane] = NULL;
- dstImage->yuvRowBytes[uvPlane] = 0;
- }
- }
}
if ((planes & AVIF_PLANES_A) && srcImage->alphaPlane) {
const avifResult allocationResult = avifImageAllocatePlanes(dstImage, AVIF_PLANES_A);