Resize image in j2me

public static final Image scale(Image image, int newWidth, int newHeight) {
int[] originalData = new int[image.getWidth() * image.getHeight()];
image.getRGB(originalData, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
int[] currentData = new int[newWidth * newHeight];
int YD = image.getWidth() * ((image.getHeight() / newHeight) – 1);
int YR = image.getHeight() % newHeight;
int XD = image.getWidth() / newWidth;
int XR = image.getWidth() % newWidth;
int outOffset = 0;
int inOffset = 0;
for (int y = newHeight, YE = 0; y > 0; y–) {
for (int x = newWidth, XE = 0; x > 0; x–) {
currentData[outOffset++] = originalData[inOffset];
inOffset += XD;
XE += XR;
if (XE >= newWidth) {
XE -= newWidth;
inOffset++;
}
}
inOffset += YD;
YE += YR;
if (YE >= newHeight) {
YE -= newHeight;
inOffset += image.getWidth();
}
}
return Image.createRGBImage(currentData, newWidth, newHeight, true);
}