Fix compilation with 1755 ≤ LIBYUV_VERSION < 1774 ScalePlane_12 only provide optimization for 2x scale up using linear/bilinear filter (when scaling up, box and bilinear are the same), and for the rest cases, it simply calls ScalePlane_16, which handles 2x scale up just fine (slower though). This optimization is thus optional and compilation can be allowed for libyuv versions not providing it. Fixes GH-781 (the function was introduced in libavif https://github.com/AOMediaCodec/libavif/commit/46104d6db42ec2a94a7da6fc0693f24fa90a1b98).
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fc76df..e18156d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -233,12 +233,16 @@ find_package(libyuv QUIET) # not required if(libyuv_FOUND) # libyuv 1755 exposed all of the I*Matrix() functions, which libavif relies on. + # libyuv 1774 exposed ScalePlane_12 function, which libavif can use for some additional optimizations. if(NOT LIBYUV_VERSION) message(STATUS "libavif: libyuv found, but version unknown; libyuv-based fast paths disabled.") elseif(LIBYUV_VERSION LESS 1755) message(STATUS "libavif: libyuv (${LIBYUV_VERSION}) found, but is too old; libyuv-based fast paths disabled.") else() message(STATUS "libavif: libyuv (${LIBYUV_VERSION}) found; libyuv-based fast paths enabled.") + if(LIBYUV_VERSION LESS 1774) + message(STATUS "libavif: some libyuv optimizations require at least version 1774 to work.") + endif() set(AVIF_PLATFORM_DEFINITIONS ${AVIF_PLATFORM_DEFINITIONS} -DAVIF_LIBYUV_ENABLED=1) set(AVIF_PLATFORM_INCLUDES ${AVIF_PLATFORM_INCLUDES} ${LIBYUV_INCLUDE_DIR}) set(AVIF_PLATFORM_LIBRARIES ${AVIF_PLATFORM_LIBRARIES} ${LIBYUV_LIBRARY})
diff --git a/src/scale.c b/src/scale.c index 6ca651b..1bbbdd8 100644 --- a/src/scale.c +++ b/src/scale.c
@@ -107,7 +107,11 @@ const uint32_t srcStride = srcYUVRowBytes[i] / 2; uint16_t * const dstPlane = (uint16_t *)image->yuvPlanes[i]; const uint32_t dstStride = image->yuvRowBytes[i] / 2; +#if LIBYUV_VERSION >= 1774 ScalePlane_12(srcPlane, srcStride, srcW, srcH, dstPlane, dstStride, dstW, dstH, AVIF_LIBYUV_FILTER_MODE); +#else + ScalePlane_16(srcPlane, srcStride, srcW, srcH, dstPlane, dstStride, dstW, dstH, AVIF_LIBYUV_FILTER_MODE); +#endif } else { uint8_t * const srcPlane = srcYUVPlanes[i]; const uint32_t srcStride = srcYUVRowBytes[i]; @@ -130,7 +134,11 @@ const uint32_t srcStride = srcAlphaRowBytes / 2; uint16_t * const dstPlane = (uint16_t *)image->alphaPlane; const uint32_t dstStride = image->alphaRowBytes / 2; +#if LIBYUV_VERSION >= 1774 ScalePlane_12(srcPlane, srcStride, srcWidth, srcHeight, dstPlane, dstStride, dstWidth, dstHeight, AVIF_LIBYUV_FILTER_MODE); +#else + ScalePlane_16(srcPlane, srcStride, srcWidth, srcHeight, dstPlane, dstStride, dstWidth, dstHeight, AVIF_LIBYUV_FILTER_MODE); +#endif } else { uint8_t * const srcPlane = srcAlphaPlane; const uint32_t srcStride = srcAlphaRowBytes;