Rev 382 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 382 | Rev 493 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | ***************************************************************/ |
8 | ***************************************************************/ |
Line 9... | Line 9... | ||
9 | 9 | ||
10 | import java.util.Vector; |
10 | import java.util.Vector; |
11 | import java.io.*; |
11 | import java.io.*; |
12 | import javax.microedition.io.*; |
- | |
13 | - | ||
- | 12 | import javax.microedition.io.*; |
|
Line 14... | Line 13... | ||
14 | 13 | import javax.microedition.lcdui.*; |
|
15 | 14 | ||
16 | public final class DUBwiseHelper |
15 | public final class DUBwiseHelper |
17 | { |
16 | { |
Line 171... | Line 170... | ||
171 | return res; |
170 | return res; |
Line 172... | Line 171... | ||
172 | 171 | ||
Line -... | Line 172... | ||
- | 172 | ||
- | 173 | } |
|
- | 174 | ||
- | 175 | ||
- | 176 | public static Image scaleImage(Image original, int newWidth) |
|
- | 177 | // this function is from http://willperone.net/Code/codescaling.php |
|
- | 178 | { |
|
- | 179 | ||
- | 180 | int[] rawInput = new int[original.getHeight() * original.getWidth()]; |
|
- | 181 | original.getRGB(rawInput, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight()); |
|
- | 182 | ||
- | 183 | int newHeight=((original.getHeight()* (newWidth/10)) / (original.getWidth()/10)); |
|
- | 184 | int[] rawOutput = new int[newWidth*newHeight]; |
|
- | 185 | ||
- | 186 | ||
- | 187 | // YD compensates for the x loop by subtracting the width back out |
|
- | 188 | int YD = (original.getHeight() / newHeight) * original.getWidth() - original.getWidth(); |
|
- | 189 | int YR = original.getHeight() % newHeight; |
|
- | 190 | int XD = original.getWidth() / newWidth; |
|
- | 191 | int XR = original.getWidth() % newWidth; |
|
- | 192 | ||
- | 193 | ||
- | 194 | ||
- | 195 | int outOffset= 0; |
|
- | 196 | int inOffset= 0; |
|
- | 197 | ||
- | 198 | for (int y= newHeight, YE= 0; y > 0; y--) { |
|
- | 199 | for (int x= newWidth, XE= 0; x > 0; x--) { |
|
- | 200 | rawOutput[outOffset++]= rawInput[inOffset]; |
|
- | 201 | inOffset+=XD; |
|
- | 202 | XE+=XR; |
|
- | 203 | if (XE >= newWidth) { |
|
- | 204 | XE-= newWidth; |
|
- | 205 | inOffset++; |
|
- | 206 | } |
|
- | 207 | } |
|
- | 208 | inOffset+= YD; |
|
- | 209 | YE+= YR; |
|
- | 210 | if (YE >= newHeight) { |
|
- | 211 | YE -= newHeight; |
|
- | 212 | inOffset+=original.getWidth(); |
|
- | 213 | } |
|
- | 214 | } |
|
- | 215 | return Image.createRGBImage(rawOutput, newWidth, newHeight, false); |
|
- | 216 | } |
|
173 | 217 |