Pass correct src and dst strides to ScalePlane_12 Fix https://github.com/AOMediaCodec/libavif/issues/715.
diff --git a/src/scale.c b/src/scale.c index 69438cb..944ca13 100644 --- a/src/scale.c +++ b/src/scale.c
@@ -83,13 +83,17 @@ const uint32_t dstW = (i == AVIF_CHAN_Y) ? dstWidth : dstUVWidth; const uint32_t dstH = (i == AVIF_CHAN_Y) ? dstHeight : dstUVHeight; if (image->depth > 8) { - uint16_t * srcPlane = (uint16_t *)srcYUVPlanes[i]; - uint16_t * dstPlane = (uint16_t *)image->yuvPlanes[i]; - ScalePlane_12(srcPlane, srcYUVRowBytes[i], srcW, srcH, dstPlane, image->yuvRowBytes[i], dstW, dstH, AVIF_LIBYUV_FILTER_MODE); + uint16_t * const srcPlane = (uint16_t *)srcYUVPlanes[i]; + const uint32_t srcStride = srcYUVRowBytes[i] / 2; + uint16_t * const dstPlane = (uint16_t *)image->yuvPlanes[i]; + const uint32_t dstStride = image->yuvRowBytes[i] / 2; + ScalePlane_12(srcPlane, srcStride, srcW, srcH, dstPlane, dstStride, dstW, dstH, AVIF_LIBYUV_FILTER_MODE); } else { - uint8_t * srcPlane = srcYUVPlanes[i]; - uint8_t * dstPlane = image->yuvPlanes[i]; - ScalePlane(srcPlane, srcYUVRowBytes[i], srcW, srcH, dstPlane, image->yuvRowBytes[i], dstW, dstH, AVIF_LIBYUV_FILTER_MODE); + uint8_t * const srcPlane = srcYUVPlanes[i]; + const uint32_t srcStride = srcYUVRowBytes[i]; + uint8_t * const dstPlane = image->yuvPlanes[i]; + const uint32_t dstStride = image->yuvRowBytes[i]; + ScalePlane(srcPlane, srcStride, srcW, srcH, dstPlane, dstStride, dstW, dstH, AVIF_LIBYUV_FILTER_MODE); } if (srcImageOwnsYUVPlanes) { @@ -102,13 +106,17 @@ avifImageAllocatePlanes(image, AVIF_PLANES_A); if (image->depth > 8) { - uint16_t * srcPlane = (uint16_t *)srcAlphaPlane; - uint16_t * dstPlane = (uint16_t *)image->alphaPlane; - ScalePlane_12(srcPlane, srcAlphaRowBytes, srcWidth, srcHeight, dstPlane, image->alphaRowBytes, dstWidth, dstHeight, AVIF_LIBYUV_FILTER_MODE); + uint16_t * const srcPlane = (uint16_t *)srcAlphaPlane; + const uint32_t srcStride = srcAlphaRowBytes / 2; + uint16_t * const dstPlane = (uint16_t *)image->alphaPlane; + const uint32_t dstStride = image->alphaRowBytes / 2; + ScalePlane_12(srcPlane, srcStride, srcWidth, srcHeight, dstPlane, dstStride, dstWidth, dstHeight, AVIF_LIBYUV_FILTER_MODE); } else { - uint8_t * srcPlane = srcAlphaPlane; - uint8_t * dstPlane = image->alphaPlane; - ScalePlane(srcPlane, srcAlphaRowBytes, srcWidth, srcHeight, dstPlane, image->alphaRowBytes, dstWidth, dstHeight, AVIF_LIBYUV_FILTER_MODE); + uint8_t * const srcPlane = srcAlphaPlane; + const uint32_t srcStride = srcAlphaRowBytes; + uint8_t * const dstPlane = image->alphaPlane; + const uint32_t dstStride = image->alphaRowBytes; + ScalePlane(srcPlane, srcStride, srcWidth, srcHeight, dstPlane, dstStride, dstWidth, dstHeight, AVIF_LIBYUV_FILTER_MODE); } if (srcImageOwnsAlphaPlane) {