diff --git a/src/dsp/rescaler.c b/src/dsp/rescaler.c index 640b462c..9e5f1b44 100644 --- a/src/dsp/rescaler.c +++ b/src/dsp/rescaler.c @@ -28,16 +28,17 @@ static void RescalerImportRowC(WebPRescaler* const wrk, if (!wrk->x_expand) { int sum = 0; for (x_out = channel; x_out < x_out_max; x_out += x_stride) { + uint32_t base = 0; accum += wrk->x_add; - for (; accum > 0; accum -= wrk->x_sub) { - sum += src[x_in]; + while (accum > 0) { + accum -= wrk->x_sub; + base = src[x_in]; + sum += base; x_in += x_stride; } { // Emit next horizontal pixel. - const int32_t base = src[x_in]; const int32_t frac = base * (-accum); - x_in += x_stride; - wrk->frow[x_out] = (sum + base) * wrk->x_sub - frac; + wrk->frow[x_out] = sum * wrk->x_sub - frac; // fresh fractional start for next pixel sum = (int)MULT_FIX(frac, wrk->fx_scale); } diff --git a/src/dsp/rescaler_mips32.c b/src/dsp/rescaler_mips32.c index 467e6116..330de3c5 100644 --- a/src/dsp/rescaler_mips32.c +++ b/src/dsp/rescaler_mips32.c @@ -22,7 +22,7 @@ static void ImportRow(WebPRescaler* const wrk, const int x_stride = wrk->num_channels; const int x_out_max = wrk->dst_width * wrk->num_channels; const int fx_scale = wrk->fx_scale; - const int x_add = wrk->x_add; + const int x_add = wrk->x_add - wrk->x_sub; const int x_sub = wrk->x_sub; int* frow = wrk->frow + channel; int* irow = wrk->irow + channel; diff --git a/src/dsp/rescaler_mips_dsp_r2.c b/src/dsp/rescaler_mips_dsp_r2.c index 68dcb189..5f2a969b 100644 --- a/src/dsp/rescaler_mips_dsp_r2.c +++ b/src/dsp/rescaler_mips_dsp_r2.c @@ -22,7 +22,7 @@ static void ImportRow(WebPRescaler* const wrk, const int x_stride = wrk->num_channels; const int x_out_max = wrk->dst_width * wrk->num_channels; const int fx_scale = wrk->fx_scale; - const int x_add = wrk->x_add; + const int x_add = wrk->x_add - wrk->x_sub; const int x_sub = wrk->x_sub; int* frow = wrk->frow + channel; int* irow = wrk->irow + channel; diff --git a/src/utils/rescaler.c b/src/utils/rescaler.c index cd45ae8d..db1ea6c9 100644 --- a/src/utils/rescaler.c +++ b/src/utils/rescaler.c @@ -31,7 +31,7 @@ void WebPRescalerInit(WebPRescaler* const wrk, int src_width, int src_height, wrk->dst_stride = dst_stride; wrk->num_channels = num_channels; // for 'x_expand', we use bilinear interpolation - wrk->x_add = wrk->x_expand ? (x_sub - 1) : x_add - x_sub; + wrk->x_add = wrk->x_expand ? (x_sub - 1) : x_add; wrk->x_sub = wrk->x_expand ? (x_add - 1) : x_sub; wrk->y_accum = y_add; wrk->y_add = y_add;