Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 492 → Rev 493

/DUBwise/trunk/j2me/src/DUBwiseHelper.java
10,9 → 10,8
import java.util.Vector;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
 
 
 
public final class DUBwiseHelper
{
public final static String ip_digit_zeroes(int digit)
173,4 → 172,49
 
}
 
 
public static Image scaleImage(Image original, int newWidth)
// this function is from http://willperone.net/Code/codescaling.php
{
int[] rawInput = new int[original.getHeight() * original.getWidth()];
original.getRGB(rawInput, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
int newHeight=((original.getHeight()* (newWidth/10)) / (original.getWidth()/10));
int[] rawOutput = new int[newWidth*newHeight];
 
// YD compensates for the x loop by subtracting the width back out
int YD = (original.getHeight() / newHeight) * original.getWidth() - original.getWidth();
int YR = original.getHeight() % newHeight;
int XD = original.getWidth() / newWidth;
int XR = original.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--) {
rawOutput[outOffset++]= rawInput[inOffset];
inOffset+=XD;
XE+=XR;
if (XE >= newWidth) {
XE-= newWidth;
inOffset++;
}
}
inOffset+= YD;
YE+= YR;
if (YE >= newHeight) {
YE -= newHeight;
inOffset+=original.getWidth();
}
}
return Image.createRGBImage(rawOutput, newWidth, newHeight, false);
}
 
 
 
}