diff --git a/rtengine/iimage.h b/rtengine/iimage.h index e7dd5865d..1f82ea3e6 100644 --- a/rtengine/iimage.h +++ b/rtengine/iimage.h @@ -818,33 +818,21 @@ public: } } } else if (interp == TI_Bilinear) { - for (int i = 0; i < nh; i++) { - int sy = i * height / nh; + float heightByNh = float(height) / float(nh); + float widthByNw = float(width) / float(nw); + float syf = 0.f; - if (sy >= height) { - sy = height - 1; - } + for (int i = 0; i < nh; i++, syf += heightByNh) { + int sy = syf; + float dy = syf - float(sy); + int ny = sy < height - 1 ? sy + 1 : sy; - float dy = float(i) * float(height) / float(nh) - float(sy); - int ny = sy + 1; + float sxf = 0.f; - if (ny >= height) { - ny = sy; - } - - for (int j = 0; j < nw; j++) { - int sx = j * width / nw; - - if (sx >= width) { - sx = width; - } - - float dx = float(j) * float(width) / float(nw) - float(sx); - int nx = sx + 1; - - if (nx >= width) { - nx = sx; - } + for (int j = 0; j < nw; j++, sxf += widthByNw) { + int sx = sxf; + float dx = sxf - float(sx); + int nx = sx < width - 1 ? sx + 1 : sx; convertTo(r(sy, sx) * (1.f - dx) * (1.f - dy) + r(sy, nx)*dx * (1.f - dy) + r(ny, sx) * (1.f - dx)*dy + r(ny, nx)*dx * dy, imgPtr->r(i, j)); convertTo(g(sy, sx) * (1.f - dx) * (1.f - dy) + g(sy, nx)*dx * (1.f - dy) + g(ny, sx) * (1.f - dx)*dy + g(ny, nx)*dx * dy, imgPtr->g(i, j));