From a71b748bde44ce73e89f7cfa89d96897f934c25a Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 3 Apr 2019 01:31:30 +0300 Subject: [PATCH] SIMD Resample. Correct max coefficient calculation 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 e1a015ef9..75756b117 100644 --- a/src/libImaging/Resample.c +++ b/src/libImaging/Resample.c @@ -297,11 +297,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) {