Use more avifImagePlane*() functions

To reduce and simplify the codebase.
diff --git a/apps/shared/avifjpeg.c b/apps/shared/avifjpeg.c
index 6d7deb8..57f271f 100644
--- a/apps/shared/avifjpeg.c
+++ b/apps/shared/avifjpeg.c
@@ -185,11 +185,9 @@
                         return AVIF_FALSE;
                     }
 
-                    avifPixelFormatInfo info;
-                    avifGetPixelFormatInfo(avif->yuvFormat, &info);
-                    uint32_t uvHeight = (avif->height + info.chromaShiftY) >> info.chromaShiftY;
-                    memset(avif->yuvPlanes[AVIF_CHAN_U], 128, avif->yuvRowBytes[AVIF_CHAN_U] * uvHeight);
-                    memset(avif->yuvPlanes[AVIF_CHAN_V], 128, avif->yuvRowBytes[AVIF_CHAN_V] * uvHeight);
+                    uint32_t uvHeight = avifImagePlaneHeight(avif, AVIF_CHAN_U);
+                    memset(avif->yuvPlanes[AVIF_CHAN_U], 128, (size_t)avif->yuvRowBytes[AVIF_CHAN_U] * uvHeight);
+                    memset(avif->yuvPlanes[AVIF_CHAN_V], 128, (size_t)avif->yuvRowBytes[AVIF_CHAN_V] * uvHeight);
 
                     return AVIF_TRUE;
                 }
diff --git a/apps/shared/y4m.c b/apps/shared/y4m.c
index e6519f6..3283abc 100644
--- a/apps/shared/y4m.c
+++ b/apps/shared/y4m.c
@@ -361,42 +361,22 @@
         goto cleanup;
     }
 
-    avifPixelFormatInfo formatInfo;
-    avifGetPixelFormatInfo(avif->yuvFormat, &formatInfo);
-
-    const int planeCount = formatInfo.monochrome ? 1 : AVIF_PLANE_COUNT_YUV;
-    for (int plane = 0; plane < planeCount; ++plane) {
-        uint32_t planeWidth = (plane > 0) ? ((avif->width + formatInfo.chromaShiftX) >> formatInfo.chromaShiftX) : avif->width;
-        uint32_t planeHeight = (plane > 0) ? ((avif->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY) : avif->height;
-        uint32_t rowBytes = planeWidth << (avif->depth > 8);
-        uint8_t * row = avif->yuvPlanes[plane];
+    for (int plane = AVIF_CHAN_Y; plane <= AVIF_CHAN_A; ++plane) {
+        uint32_t planeHeight = avifImagePlaneHeight(avif, plane); // 0 for A if no alpha and 0 for UV if 4:0:0.
+        uint32_t planeWidthBytes = avifImagePlaneWidth(avif, plane) << (avif->depth > 8);
+        uint8_t * row = avifImagePlane(avif, plane);
+        uint32_t rowBytes = avifImagePlaneRowBytes(avif, plane);
         for (uint32_t y = 0; y < planeHeight; ++y) {
-            uint32_t bytesRead = (uint32_t)fread(row, 1, rowBytes, frame.inputFile);
-            if (bytesRead != rowBytes) {
+            uint32_t bytesRead = (uint32_t)fread(row, 1, planeWidthBytes, frame.inputFile);
+            if (bytesRead != planeWidthBytes) {
                 fprintf(stderr,
                         "Failed to read y4m row (not enough data, wanted %" PRIu32 ", got %" PRIu32 "): %s\n",
-                        rowBytes,
+                        planeWidthBytes,
                         bytesRead,
                         frame.displayFilename);
                 goto cleanup;
             }
-            row += avif->yuvRowBytes[plane];
-        }
-    }
-    if (frame.hasAlpha) {
-        uint32_t rowBytes = avif->width << (avif->depth > 8);
-        uint8_t * row = avif->alphaPlane;
-        for (uint32_t y = 0; y < avif->height; ++y) {
-            uint32_t bytesRead = (uint32_t)fread(row, 1, rowBytes, frame.inputFile);
-            if (bytesRead != rowBytes) {
-                fprintf(stderr,
-                        "Failed to read y4m row (not enough data, wanted %" PRIu32 ", got %" PRIu32 "): %s\n",
-                        rowBytes,
-                        bytesRead,
-                        frame.displayFilename);
-                goto cleanup;
-            }
-            row += avif->alphaRowBytes;
+            row += rowBytes;
         }
     }
 
@@ -517,9 +497,6 @@
         rangeString = "XCOLORRANGE=LIMITED";
     }
 
-    avifPixelFormatInfo formatInfo;
-    avifGetPixelFormatInfo(avif->yuvFormat, &formatInfo);
-
     FILE * f = fopen(outputFilename, "wb");
     if (!f) {
         fprintf(stderr, "Cannot open file for write: %s\n", outputFilename);
@@ -533,31 +510,19 @@
         goto cleanup;
     }
 
-    const int planeCount = formatInfo.monochrome ? 1 : AVIF_PLANE_COUNT_YUV;
-    for (int plane = 0; plane < planeCount; ++plane) {
-        uint32_t planeWidth = (plane > 0) ? ((avif->width + formatInfo.chromaShiftX) >> formatInfo.chromaShiftX) : avif->width;
-        uint32_t planeHeight = (plane > 0) ? ((avif->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY) : avif->height;
-        uint32_t rowBytes = planeWidth << (avif->depth > 8);
-        const uint8_t * row = avif->yuvPlanes[plane];
+    const int lastPlane = writeAlpha ? AVIF_CHAN_A : AVIF_CHAN_V;
+    for (int plane = AVIF_CHAN_Y; plane <= lastPlane; ++plane) {
+        uint32_t planeHeight = avifImagePlaneHeight(avif, plane); // 0 for UV if 4:0:0.
+        uint32_t planeWidthBytes = avifImagePlaneWidth(avif, plane) << (avif->depth > 8);
+        uint8_t * row = avifImagePlane(avif, plane);
+        uint32_t rowBytes = avifImagePlaneRowBytes(avif, plane);
         for (uint32_t y = 0; y < planeHeight; ++y) {
-            if (fwrite(row, 1, rowBytes, f) != rowBytes) {
-                fprintf(stderr, "Failed to write %" PRIu32 " bytes: %s\n", rowBytes, outputFilename);
+            if (fwrite(row, 1, planeWidthBytes, f) != planeWidthBytes) {
+                fprintf(stderr, "Failed to write %" PRIu32 " bytes: %s\n", planeWidthBytes, outputFilename);
                 success = AVIF_FALSE;
                 goto cleanup;
             }
-            row += avif->yuvRowBytes[plane];
-        }
-    }
-    if (writeAlpha) {
-        uint32_t rowBytes = avif->width << (avif->depth > 8);
-        const uint8_t * row = avif->alphaPlane;
-        for (uint32_t y = 0; y < avif->height; ++y) {
-            if (fwrite(row, 1, rowBytes, f) != rowBytes) {
-                fprintf(stderr, "Failed to write %" PRIu32 " bytes: %s\n", rowBytes, outputFilename);
-                success = AVIF_FALSE;
-                goto cleanup;
-            }
-            row += avif->alphaRowBytes;
+            row += rowBytes;
         }
     }
 
diff --git a/src/avif.c b/src/avif.c
index a50d21b..a73c187 100644
--- a/src/avif.c
+++ b/src/avif.c
@@ -3,6 +3,7 @@
 
 #include "avif/internal.h"
 
+#include <assert.h>
 #include <limits.h>
 #include <stdint.h>
 #include <string.h>
@@ -184,39 +185,36 @@
         if (allocationResult != AVIF_RESULT_OK) {
             return allocationResult;
         }
-
-        avifPixelFormatInfo formatInfo;
-        avifGetPixelFormatInfo(srcImage->yuvFormat, &formatInfo);
-        uint32_t uvHeight = (dstImage->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY;
-        for (int yuvPlane = 0; yuvPlane < 3; ++yuvPlane) {
-            uint32_t planeHeight = (yuvPlane == AVIF_CHAN_Y) ? dstImage->height : uvHeight;
-
-            if (!srcImage->yuvRowBytes[yuvPlane]) {
+        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[yuvPlane]);
-                dstImage->yuvPlanes[yuvPlane] = NULL;
-                dstImage->yuvRowBytes[yuvPlane] = 0;
-                continue;
-            }
-
-            for (uint32_t j = 0; j < planeHeight; ++j) {
-                uint8_t * srcRow = &srcImage->yuvPlanes[yuvPlane][j * srcImage->yuvRowBytes[yuvPlane]];
-                uint8_t * dstRow = &dstImage->yuvPlanes[yuvPlane][j * dstImage->yuvRowBytes[yuvPlane]];
-                memcpy(dstRow, srcRow, dstImage->yuvRowBytes[yuvPlane]);
+                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);
         if (allocationResult != AVIF_RESULT_OK) {
             return allocationResult;
         }
-        for (uint32_t j = 0; j < dstImage->height; ++j) {
-            uint8_t * srcAlphaRow = &srcImage->alphaPlane[j * srcImage->alphaRowBytes];
-            uint8_t * dstAlphaRow = &dstImage->alphaPlane[j * dstImage->alphaRowBytes];
-            memcpy(dstAlphaRow, srcAlphaRow, dstImage->alphaRowBytes);
+    }
+    for (int plane = AVIF_CHAN_Y; plane <= AVIF_CHAN_A; ++plane) {
+        uint8_t * dstRow = avifImagePlane(dstImage, plane);
+        if (!dstRow) {
+            continue;
+        }
+        uint8_t * srcRow = avifImagePlane(srcImage, plane);
+        uint32_t srcRowBytes = avifImagePlaneRowBytes(srcImage, plane);
+        uint32_t dstRowBytes = avifImagePlaneRowBytes(dstImage, plane);
+        uint32_t planeWidthBytes = avifImagePlaneWidth(dstImage, plane) << (dstImage->depth > 8);
+        uint32_t planeHeight = avifImagePlaneHeight(dstImage, plane);
+        for (uint32_t j = 0; j < planeHeight; ++j) {
+            memcpy(dstRow, srcRow, planeWidthBytes);
+            srcRow += srcRowBytes;
+            dstRow += dstRowBytes;
         }
     }
     return AVIF_RESULT_OK;
@@ -236,7 +234,7 @@
     dstImage->height = rect->height;
     const uint32_t pixelBytes = (srcImage->depth > 8) ? 2 : 1;
     if (srcImage->yuvPlanes[AVIF_CHAN_Y]) {
-        for (int yuvPlane = 0; yuvPlane < 3; ++yuvPlane) {
+        for (int yuvPlane = AVIF_CHAN_Y; yuvPlane <= AVIF_CHAN_V; ++yuvPlane) {
             if (srcImage->yuvRowBytes[yuvPlane]) {
                 const size_t planeX = (yuvPlane == AVIF_CHAN_Y) ? rect->x : (rect->x >> formatInfo.chromaShiftX);
                 const size_t planeY = (yuvPlane == AVIF_CHAN_Y) ? rect->y : (rect->y >> formatInfo.chromaShiftY);
@@ -309,18 +307,13 @@
         }
 
         if (image->yuvFormat != AVIF_PIXEL_FORMAT_YUV400) {
-            if (!image->yuvPlanes[AVIF_CHAN_U]) {
-                image->yuvRowBytes[AVIF_CHAN_U] = (uint32_t)uvRowBytes;
-                image->yuvPlanes[AVIF_CHAN_U] = avifAlloc(uvSize);
-                if (!image->yuvPlanes[AVIF_CHAN_U]) {
-                    return AVIF_RESULT_OUT_OF_MEMORY;
-                }
-            }
-            if (!image->yuvPlanes[AVIF_CHAN_V]) {
-                image->yuvRowBytes[AVIF_CHAN_V] = (uint32_t)uvRowBytes;
-                image->yuvPlanes[AVIF_CHAN_V] = avifAlloc(uvSize);
-                if (!image->yuvPlanes[AVIF_CHAN_V]) {
-                    return AVIF_RESULT_OUT_OF_MEMORY;
+            for (int uvPlane = AVIF_CHAN_U; uvPlane <= AVIF_CHAN_V; ++uvPlane) {
+                if (!image->yuvPlanes[uvPlane]) {
+                    image->yuvRowBytes[uvPlane] = (uint32_t)uvRowBytes;
+                    image->yuvPlanes[uvPlane] = avifAlloc(uvSize);
+                    if (!image->yuvPlanes[uvPlane]) {
+                        return AVIF_RESULT_OUT_OF_MEMORY;
+                    }
                 }
             }
         }
diff --git a/src/write.c b/src/write.c
index fa981ba..d3cb29c 100644
--- a/src/write.c
+++ b/src/write.c
@@ -742,46 +742,6 @@
     return AVIF_RESULT_OK;
 }
 
-// Copies the pixel from srcPlane to the already allocated dstPlane,
-// filling any extra row or column with border pixel values.
-static void avifCopyAndPadPlane(uint8_t * dstPlane,
-                                uint32_t dstRowBytes,
-                                uint32_t dstWidth,
-                                uint32_t dstHeight,
-                                const uint8_t * srcPlane,
-                                uint32_t srcRowBytes,
-                                uint32_t srcWidth,
-                                uint32_t srcHeight,
-                                uint32_t sampleByteCount)
-{
-    assert(dstWidth >= srcWidth);
-    assert(dstHeight >= srcHeight);
-    for (uint32_t j = 0; j < srcHeight; ++j) {
-        const uint8_t * srcRow = &srcPlane[j * (size_t)srcRowBytes];
-        uint8_t * dstRow = &dstPlane[j * (size_t)dstRowBytes];
-        // Copy srcWidth samples. srcRowBytes might be unrelated.
-        memcpy(dstRow, srcRow, (size_t)srcWidth * sampleByteCount);
-
-        // Pad columns.
-        if (dstWidth > srcWidth) {
-            if (sampleByteCount == 1) {
-                memset(&dstRow[srcWidth], dstRow[srcWidth - 1], dstWidth - srcWidth);
-            } else { // sampleByteCount == 2
-                uint16_t * dstRow16 = (uint16_t *)dstRow;
-                for (uint32_t x = srcWidth; x < dstWidth; ++x) {
-                    dstRow16[x] = dstRow16[srcWidth - 1];
-                }
-            }
-        }
-    }
-
-    // Pad rows.
-    for (uint32_t j = srcHeight; j < dstHeight; ++j) {
-        uint8_t * dstRow = &dstPlane[j * (size_t)dstRowBytes];
-        memcpy(dstRow, dstRow - dstRowBytes, (size_t)dstWidth * sampleByteCount);
-    }
-}
-
 // Same as avifImageCopy() but pads the dstImage with border pixel values to reach dstWidth and dstHeight.
 static avifImage * avifImageCopyAndPad(const avifImage * srcImage, uint32_t dstWidth, uint32_t dstHeight)
 {
@@ -791,6 +751,8 @@
         avifImageDestroy(dstImage);
         return NULL;
     }
+    assert(dstWidth >= srcImage->width);
+    assert(dstHeight >= srcImage->height);
     dstImage->width = dstWidth;
     dstImage->height = dstHeight;
 
@@ -800,49 +762,50 @@
             avifImageDestroy(dstImage);
             return NULL;
         }
-
-        avifPixelFormatInfo formatInfo;
-        avifGetPixelFormatInfo(srcImage->yuvFormat, &formatInfo);
-        const uint32_t srcUvWidth = (srcImage->width + formatInfo.chromaShiftX) >> formatInfo.chromaShiftX;
-        const uint32_t srcUvHeight = (srcImage->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY;
-        const uint32_t dstUvWidth = (dstImage->width + formatInfo.chromaShiftX) >> formatInfo.chromaShiftX;
-        const uint32_t dstUvHeight = (dstImage->height + formatInfo.chromaShiftY) >> formatInfo.chromaShiftY;
-        for (int yuvPlane = 0; yuvPlane < 3; ++yuvPlane) {
-            if (!srcImage->yuvRowBytes[yuvPlane]) {
-                // 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[yuvPlane]);
-                dstImage->yuvPlanes[yuvPlane] = NULL;
-                dstImage->yuvRowBytes[yuvPlane] = 0;
-                continue;
-            }
-            avifCopyAndPadPlane(dstImage->yuvPlanes[yuvPlane],
-                                dstImage->yuvRowBytes[yuvPlane],
-                                (yuvPlane == AVIF_CHAN_Y) ? dstImage->width : dstUvWidth,
-                                (yuvPlane == AVIF_CHAN_Y) ? dstImage->height : dstUvHeight,
-                                srcImage->yuvPlanes[yuvPlane],
-                                srcImage->yuvRowBytes[yuvPlane],
-                                (yuvPlane == AVIF_CHAN_Y) ? srcImage->width : srcUvWidth,
-                                (yuvPlane == AVIF_CHAN_Y) ? srcImage->height : srcUvHeight,
-                                avifImageUsesU16(srcImage) ? 2 : 1);
-        }
     }
-
     if (srcImage->alphaPlane) {
         const avifResult allocationResult = avifImageAllocatePlanes(dstImage, AVIF_PLANES_A);
         if (allocationResult != AVIF_RESULT_OK) {
             avifImageDestroy(dstImage);
             return NULL;
         }
-        avifCopyAndPadPlane(dstImage->alphaPlane,
-                            dstImage->alphaRowBytes,
-                            dstImage->width,
-                            dstImage->height,
-                            srcImage->alphaPlane,
-                            srcImage->alphaRowBytes,
-                            srcImage->width,
-                            srcImage->height,
-                            avifImageUsesU16(srcImage) ? 2 : 1);
+    }
+    for (int plane = AVIF_CHAN_Y; plane <= AVIF_CHAN_A; ++plane) {
+        const uint8_t * srcRow = avifImagePlane(srcImage, plane);
+        const uint32_t srcRowBytes = avifImagePlaneRowBytes(srcImage, plane);
+        const uint32_t srcPlaneWidth = avifImagePlaneWidth(srcImage, plane);
+        const uint32_t srcPlaneHeight = avifImagePlaneHeight(srcImage, plane); // 0 for A if no alpha and 0 for UV if 4:0:0.
+        const size_t srcPlaneWidthBytes = (size_t)srcPlaneWidth << avifImageUsesU16(srcImage);
+
+        uint8_t * dstRow = avifImagePlane(dstImage, plane);
+        const uint32_t dstRowBytes = avifImagePlaneRowBytes(dstImage, plane);
+        const uint32_t dstPlaneWidth = avifImagePlaneWidth(dstImage, plane);
+        const uint32_t dstPlaneHeight = avifImagePlaneHeight(dstImage, plane); // 0 for A if no alpha and 0 for UV if 4:0:0.
+        const size_t dstPlaneWidthBytes = (size_t)dstPlaneWidth << avifImageUsesU16(srcImage);
+
+        for (uint32_t j = 0; j < srcPlaneHeight; ++j) {
+            memcpy(dstRow, srcRow, srcPlaneWidthBytes);
+
+            // Pad columns.
+            if (dstPlaneWidth > srcPlaneWidth) {
+                if (avifImageUsesU16(srcImage)) {
+                    uint16_t * dstRow16 = (uint16_t *)dstRow;
+                    for (uint32_t x = srcPlaneWidth; x < dstPlaneWidth; ++x) {
+                        dstRow16[x] = dstRow16[srcPlaneWidth - 1];
+                    }
+                } else {
+                    memset(&dstRow[srcPlaneWidth], dstRow[srcPlaneWidth - 1], dstPlaneWidth - srcPlaneWidth);
+                }
+            }
+            srcRow += srcRowBytes;
+            dstRow += dstRowBytes;
+        }
+
+        // Pad rows.
+        for (uint32_t j = srcPlaneHeight; j < dstPlaneHeight; ++j) {
+            memcpy(dstRow, dstRow - dstRowBytes, dstPlaneWidthBytes);
+            dstRow += dstRowBytes;
+        }
     }
     return dstImage;
 }
diff --git a/tests/gtest/avifincrtest_helpers.cc b/tests/gtest/avifincrtest_helpers.cc
index b1f2c68..be0a0d2 100644
--- a/tests/gtest/avifincrtest_helpers.cc
+++ b/tests/gtest/avifincrtest_helpers.cc
@@ -33,37 +33,31 @@
 
   avifPixelFormatInfo info;
   avifGetPixelFormatInfo(image1.yuvFormat, &info);
-  const uint32_t uv_width =
-      (image1.width + info.chromaShiftX) >> info.chromaShiftX;
   const uint32_t uv_height =
-      (row_count + info.chromaShiftY) >> info.chromaShiftY;
-  const uint32_t pixel_byte_count =
+      info.monochrome ? 0
+                      : ((row_count + info.chromaShiftY) >> info.chromaShiftY);
+  const size_t pixel_byte_count =
       (image1.depth > 8) ? sizeof(uint16_t) : sizeof(uint8_t);
 
-  for (int plane = 0; plane < (info.monochrome ? 1 : AVIF_PLANE_COUNT_YUV);
-       ++plane) {
-    const uint32_t width = (plane == AVIF_CHAN_Y) ? image1.width : uv_width;
-    const uint32_t width_byte_count = width * pixel_byte_count;
-    const uint32_t height = (plane == AVIF_CHAN_Y) ? row_count : uv_height;
-    const uint8_t* data1 = image1.yuvPlanes[plane];
-    const uint8_t* data2 = image2.yuvPlanes[plane];
-    for (uint32_t y = 0; y < height; ++y) {
-      ASSERT_EQ(std::memcmp(data1, data2, width_byte_count), 0);
-      data1 += image1.yuvRowBytes[plane];
-      data2 += image2.yuvRowBytes[plane];
-    }
-  }
-
   if (image1.alphaPlane) {
     ASSERT_NE(image2.alphaPlane, nullptr);
     ASSERT_EQ(image1.alphaPremultiplied, image2.alphaPremultiplied);
-    const uint32_t width_byte_count = image1.width * pixel_byte_count;
-    const uint8_t* data1 = image1.alphaPlane;
-    const uint8_t* data2 = image2.alphaPlane;
-    for (uint32_t y = 0; y < row_count; ++y) {
-      ASSERT_EQ(std::memcmp(data1, data2, width_byte_count), 0);
-      data1 += image1.alphaRowBytes;
-      data2 += image2.alphaRowBytes;
+  }
+
+  const int last_plane = image1.alphaPlane ? AVIF_CHAN_A : AVIF_CHAN_V;
+  for (int plane = AVIF_CHAN_Y; plane <= last_plane; ++plane) {
+    const size_t width_byte_count =
+        avifImagePlaneWidth(&image1, plane) * pixel_byte_count;
+    const uint32_t height =
+        (plane == AVIF_CHAN_Y || plane == AVIF_CHAN_A) ? row_count : uv_height;
+    const uint8_t* row1 = avifImagePlane(&image1, plane);
+    const uint8_t* row2 = avifImagePlane(&image2, plane);
+    const uint32_t row1_bytes = avifImagePlaneRowBytes(&image1, plane);
+    const uint32_t row2_bytes = avifImagePlaneRowBytes(&image2, plane);
+    for (uint32_t y = 0; y < height; ++y) {
+      ASSERT_EQ(std::memcmp(row1, row2, width_byte_count), 0);
+      row1 += row1_bytes;
+      row2 += row2_bytes;
     }
   }
 }
diff --git a/tests/gtest/aviftest_helpers.cc b/tests/gtest/aviftest_helpers.cc
index c07725b..7cfd87e 100644
--- a/tests/gtest/aviftest_helpers.cc
+++ b/tests/gtest/aviftest_helpers.cc
@@ -73,6 +73,7 @@
   for (avifChannelIndex c :
        {AVIF_CHAN_Y, AVIF_CHAN_U, AVIF_CHAN_V, AVIF_CHAN_A}) {
     const uint32_t plane_width = avifImagePlaneWidth(image, c);
+    // 0 for A if no alpha and 0 for UV if 4:0:0.
     const uint32_t plane_height = avifImagePlaneHeight(image, c);
     uint8_t* row = avifImagePlane(image, c);
     const uint32_t row_bytes = avifImagePlaneRowBytes(image, c);
@@ -93,6 +94,7 @@
   for (avifChannelIndex c :
        {AVIF_CHAN_Y, AVIF_CHAN_U, AVIF_CHAN_V, AVIF_CHAN_A}) {
     const uint32_t plane_width = avifImagePlaneWidth(image, c);
+    // 0 for A if no alpha and 0 for UV if 4:0:0.
     const uint32_t plane_height = avifImagePlaneHeight(image, c);
     uint8_t* row = avifImagePlane(image, c);
     const uint32_t row_bytes = avifImagePlaneRowBytes(image, c);
@@ -168,6 +170,7 @@
     const uint32_t row_bytes1 = avifImagePlaneRowBytes(&image1, c);
     const uint32_t row_bytes2 = avifImagePlaneRowBytes(&image2, c);
     const uint32_t plane_width = avifImagePlaneWidth(&image1, c);
+    // 0 for A if no alpha and 0 for UV if 4:0:0.
     const uint32_t plane_height = avifImagePlaneHeight(&image1, c);
     for (uint32_t y = 0; y < plane_height; ++y) {
       if (avifImageUsesU16(&image1)) {
@@ -205,6 +208,7 @@
     const uint32_t from_row_bytes = avifImagePlaneRowBytes(&from, c);
     const uint32_t to_row_bytes = avifImagePlaneRowBytes(to, c);
     const uint32_t plane_width = avifImagePlaneWidth(&from, c);
+    // 0 for A if no alpha and 0 for UV if 4:0:0.
     const uint32_t plane_height = avifImagePlaneHeight(&from, c);
     for (uint32_t y = 0; y < plane_height; ++y) {
       if (avifImageUsesU16(&from)) {