Implementation of Image Resizing

The ResizeOp filter works on horizontal bands of image data to conserve memory space (incidentally, probably due to the conservative memory allocation, the gain in operation speed is significant). That is, depending on whether the image is to be expanded or shrunken vertically, one input pixel row is expanded to multiple output pixel row (expansion) or multiple input pixel rows are merged into one output pixel row (shrinking).

Each band in the input is first expanded or shrunken according to the horizontal specification of the source and destination image, respectively. After the horizontal modification of the complete band, the band is expanded or shrunken to the destination band and written back to the destination image.

If the image is neither expanded nor shrunken in the vertical direction, the horizontal expansion or shrinking is done one pixel row after another.

Memory Considerations

The memory usage depends on the source and destination image size. To work on expansion and shrinking, two memory buffers for each of the source and destination are needed. Each buffer consists of an int[] per color channel for red, green, blue and alpha. The size of the int[] is defined as follows :

bufferWidth = max(sourceWidth, destinationWidth)
bufferHeight = (sourceHeight > destinationHeight) ? sourceBandHeight : destinationBandHeight;

The memory requirements for this buffer is 4 * 8 * bufferWidth * bufferHeight (4 bytes per int, 8 int[] of bufferWidth * bufferHeight entries each).