meta-for IIntegralImage in IIntegralImage, IntegralImage { // one channel static int integralImage_sumRect(IntegralImage img, int x1, int y1, int x2, int y2, int channel) { int bottomLeft = img.get(x1-1, y2-1, channel); int bottomRight = img.get(x2-1, y2-1, channel); int topLeft = img.get(x1-1, y1-1, channel); int topRight = img.get(x2-1, y1-1, channel); ret bottomRight+topLeft-topRight-bottomLeft; } // sum all channels. TODO: might exceed int range on huge images static int integralImage_sumRect(IntegralImage img, int x1, int y1, int x2, int y2) { int bottomLeft = img.get(x1-1, y2-1); int bottomRight = img.get(x2-1, y2-1); int topLeft = img.get(x1-1, y1-1); int topRight = img.get(x2-1, y1-1); ret bottomRight+topLeft-topRight-bottomLeft; } }