From c2a9bfb1af978cfe63a84fe635db5d6d4852c776 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 3 Apr 2019 01:31:30 +0300 Subject: [PATCH] Correct max coefficient calulation Minimal test case: Image.new('RGB', (341, 60), 'pink').resize((170, 60), Image.LANCZOS).save('_out.png') --- src/libImaging/Resample.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libImaging/Resample.c b/src/libImaging/Resample.c index 0c59e0ada..faeab9aa6 100644 --- a/src/libImaging/Resample.c +++ b/src/libImaging/Resample.c @@ -284,11 +284,12 @@ normalize_coeffs_8bpc(int outSize, int ksize, double *prekk) } } - coefs_precision = 0; - while (maxkk < (1 << (MAX_COEFS_PRECISION-1)) && (coefs_precision < PRECISION_BITS)) { - maxkk *= 2; - coefs_precision += 1; - }; + for (coefs_precision = 0; coefs_precision < PRECISION_BITS; coefs_precision += 1) { + int next_value = (int) (0.5 + maxkk * (1 << (coefs_precision + 1))); + // The next value will be outside of the range, so just stop + if (next_value >= (1 << MAX_COEFS_PRECISION)) + break; + } for (x = 0; x < outSize * ksize; x++) { if (prekk[x] < 0) {