diff --git a/jsmooth-0.9.9-7-patch/src/net/charabia/jsmoothgen/application/ExeCompiler.java b/jsmooth-0.9.9-7-patch/src/net/charabia/jsmoothgen/application/ExeCompiler.java index fcd97b30..ee045f72 100644 --- a/jsmooth-0.9.9-7-patch/src/net/charabia/jsmoothgen/application/ExeCompiler.java +++ b/jsmooth-0.9.9-7-patch/src/net/charabia/jsmoothgen/application/ExeCompiler.java @@ -430,7 +430,7 @@ public class ExeCompiler if (biggest != null) { - Image result = biggest.getScaledInstance(32, 32, Image.SCALE_AREA_AVERAGING); + BufferedImage result = getScaledInstance((BufferedImage)biggest, 32, 32, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true); checkImageLoaded(result); return getQuantizedImage(result); } @@ -439,6 +439,79 @@ public class ExeCompiler // return null; } + + /** + * Convenience method that returns a scaled instance of the + * provided {@code BufferedImage}. + * + * @param img the original image to be scaled + * @param targetWidth the desired width of the scaled instance, + * in pixels + * @param targetHeight the desired height of the scaled instance, + * in pixels + * @param hint one of the rendering hints that corresponds to + * {@code RenderingHints.KEY_INTERPOLATION} (e.g. + * {@code RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR}, + * {@code RenderingHints.VALUE_INTERPOLATION_BILINEAR}, + * {@code RenderingHints.VALUE_INTERPOLATION_BICUBIC}) + * @param higherQuality if true, this method will use a multi-step + * scaling technique that provides higher quality than the usual + * one-step technique (only useful in downscaling cases, where + * {@code targetWidth} or {@code targetHeight} is + * smaller than the original dimensions, and generally only when + * the {@code BILINEAR} hint is specified) + * @return a scaled version of the original {@code BufferedImage} + */ + public BufferedImage getScaledInstance(BufferedImage img, + int targetWidth, + int targetHeight, + Object hint, + boolean higherQuality) + { + int type = (img.getTransparency() == Transparency.OPAQUE) ? + BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; + BufferedImage ret = (BufferedImage)img; + int w, h; + if (higherQuality) { + // Use multi-step technique: start with original size, then + // scale down in multiple passes with drawImage() + // until the target size is reached + w = img.getWidth(); + h = img.getHeight(); + } else { + // Use one-step technique: scale directly from original + // size to target size with a single drawImage() call + w = targetWidth; + h = targetHeight; + } + + do { + if (higherQuality && w > targetWidth) { + w /= 2; + if (w < targetWidth) { + w = targetWidth; + } + } + + if (higherQuality && h > targetHeight) { + h /= 2; + if (h < targetHeight) { + h = targetHeight; + } + } + + BufferedImage tmp = new BufferedImage(w, h, type); + Graphics2D g2 = tmp.createGraphics(); + g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint); + g2.drawImage(ret, 0, 0, w, h, null); + g2.dispose(); + + ret = tmp; + } while (w != targetWidth || h != targetHeight); + + return ret; + } + private ByteBuffer load(File in) throws Exception diff --git a/lib/jsmoothgen-ant-0.9.9-7-mgu1.jar b/lib/jsmoothgen-ant-0.9.9-7-mgu1.jar index 088ec8bb..b5cb9b03 100644 Binary files a/lib/jsmoothgen-ant-0.9.9-7-mgu1.jar and b/lib/jsmoothgen-ant-0.9.9-7-mgu1.jar differ diff --git a/src/java/tray32.png b/src/java/tray32.png index c314c577..0ecb9430 100644 Binary files a/src/java/tray32.png and b/src/java/tray32.png differ