| 22 | #define AVIF_LIBYUV_FILTER_MODE kFilterBox |
| 23 | |
| 24 | avifResult avifImageScaleWithLimit(avifImage * image, |
| 25 | uint32_t dstWidth, |
| 26 | uint32_t dstHeight, |
| 27 | uint32_t imageSizeLimit, |
| 28 | uint32_t imageDimensionLimit, |
| 29 | avifDiagnostics * diag) |
| 30 | { |
| 31 | if ((image->width == dstWidth) && (image->height == dstHeight)) { |
| 32 | // Nothing to do |
| 33 | return AVIF_RESULT_OK; |
| 34 | } |
| 35 | |
| 36 | if ((dstWidth == 0) || (dstHeight == 0)) { |
| 37 | avifDiagnosticsPrintf(diag, "avifImageScaleWithLimit requested invalid dst dimensions [%ux%u]", dstWidth, dstHeight); |
| 38 | return AVIF_RESULT_INVALID_ARGUMENT; |
| 39 | } |
| 40 | if (avifDimensionsTooLarge(dstWidth, dstHeight, imageSizeLimit, imageDimensionLimit)) { |
| 41 | avifDiagnosticsPrintf(diag, "avifImageScaleWithLimit requested dst dimensions that are too large [%ux%u]", dstWidth, dstHeight); |
| 42 | return AVIF_RESULT_NOT_IMPLEMENTED; |
| 43 | } |
| 44 | |
| 45 | uint8_t * srcYUVPlanes[AVIF_PLANE_COUNT_YUV]; |
| 46 | uint32_t srcYUVRowBytes[AVIF_PLANE_COUNT_YUV]; |
| 47 | for (int i = 0; i < AVIF_PLANE_COUNT_YUV; ++i) { |
| 48 | srcYUVPlanes[i] = image->yuvPlanes[i]; |
| 49 | image->yuvPlanes[i] = NULL; |
| 50 | srcYUVRowBytes[i] = image->yuvRowBytes[i]; |
| 51 | image->yuvRowBytes[i] = 0; |
| 52 | } |
| 53 | const avifBool srcImageOwnsYUVPlanes = image->imageOwnsYUVPlanes; |
| 54 | image->imageOwnsYUVPlanes = AVIF_FALSE; |
| 55 | |
| 56 | uint8_t * srcAlphaPlane = image->alphaPlane; |
| 57 | image->alphaPlane = NULL; |
| 58 | uint32_t srcAlphaRowBytes = image->alphaRowBytes; |
| 59 | image->alphaRowBytes = 0; |
| 60 | const avifBool srcImageOwnsAlphaPlane = image->imageOwnsAlphaPlane; |
| 61 | image->imageOwnsAlphaPlane = AVIF_FALSE; |
| 62 | |
| 63 | const uint32_t srcWidth = image->width; |
| 64 | const uint32_t srcHeight = image->height; |
| 65 | const uint32_t srcUVWidth = avifImagePlaneWidth(image, AVIF_CHAN_U); |
| 66 | const uint32_t srcUVHeight = avifImagePlaneHeight(image, AVIF_CHAN_U); |
| 67 | image->width = dstWidth; |
| 68 | image->height = dstHeight; |
| 69 | |
| 70 | avifResult result = AVIF_RESULT_OK; |
| 71 | if (srcYUVPlanes[0] || srcAlphaPlane) { |
| 72 | // A simple conservative check to avoid integer overflows in libyuv's ScalePlane() and |
| 73 | // ScalePlane_12() functions. |
| 74 | if (srcWidth > 16384) { |
| 75 | avifDiagnosticsPrintf(diag, "avifImageScaleWithLimit requested invalid width scale for libyuv [%u -> %u]", srcWidth, dstWidth); |
| 76 | result = AVIF_RESULT_NOT_IMPLEMENTED; |
| 77 | goto cleanup; |
| 78 | } |
| 79 | if (srcHeight > 16384) { |
| 80 | avifDiagnosticsPrintf(diag, "avifImageScaleWithLimit requested invalid height scale for libyuv [%u -> %u]", srcHeight, dstHeight); |
| 81 | result = AVIF_RESULT_NOT_IMPLEMENTED; |
no test coverage detected