static RGBImage scaleDownUsingIntegralImage(IIntegralImage img, int w) { ret scaleDownUsingIntegralImage(img, w, heightForWidth(img.getWidth(), img.getHeight(), w)); } static RGBImage scaleDownUsingIntegralImage(IIntegralImage img, int w, int h) { int w1 = img.getWidth(), h1 = img.getHeight(); RGBImage out = new(w, h); for y to h: for x to w: { int x1 = x*w1/w, x2 = max(x1+1, (x+1)*w1/w); int y1 = y*h1/h, y2 = max(y1+1, (y+1)*h1/h); int area = (x2-x1)*(y2-y1); int r = roundedRatio(img.rectSum(x1, y1, x2, y2, 0), area); int g = roundedRatio(img.rectSum(x1, y1, x2, y2, 1), area); int b = roundedRatio(img.rectSum(x1, y1, x2, y2, 2), area); out.setPixel(x, y, r, g, b); } ret out; }