/**
* resizeImage Gets a source image along with new size for it and resizes
* it.
*
* @param src
* The source image.
* @param destW
* The new width for the destination image.
* @param destH
* The new heigth for the destination image.
* @param mode
* A flag indicating what type of resizing we want to do. It
* currently supports two type: MODE_POINT_SAMPLE - point sampled
* resizing, and MODE_BOX_FILTER - box filtered resizing
* (default).
* @return The resized image.
*/
Image resizeImage(Image src, int destW, int destH, int mode)
{
int srcW = src.getWidth();
int srcH = src.getHeight();
// create pixel arrays
int[] destPixels = new int[destW * destH]; // array to hold destination
// pixels
int[] srcPixels = getPixels(src); // array with source's pixels
if (mode == MODE_POINT_SAMPLE)
{
// simple point smapled resizing
// loop through the destination pixels, find the matching pixel on
// the source and use that
for (int destY = 0; destY < destH; ++destY)
{
for (int destX = 0; destX < destW; ++destX)
{
int srcX = (destX * srcW) / destW;
int srcY = (destY * srcH) / destH;
destPixels[destX + destY * destW] = srcPixels[srcX + srcY
* srcW];
}
}
} else
{
// precalculate src/dest ratios
int ratioW = (srcW << FP_SHIFT) / destW;
int ratioH = (srcH << FP_SHIFT) / destH;