< prev index next >

src/java.desktop/share/classes/sun/awt/image/BufferedImageGraphicsConfig.java

Print this page

        

*** 43,87 **** public class BufferedImageGraphicsConfig extends GraphicsConfiguration { private static final int numconfigs = BufferedImage.TYPE_BYTE_BINARY; ! private static BufferedImageGraphicsConfig configs[] = ! new BufferedImageGraphicsConfig[numconfigs]; public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg) { BufferedImageGraphicsConfig ret; int type = bImg.getType(); if (type > 0 && type < numconfigs) { ! ret = configs[type]; ! if (ret != null) { return ret; } } ! ret = new BufferedImageGraphicsConfig(bImg, null); if (type > 0 && type < numconfigs) { ! configs[type] = ret; } return ret; } GraphicsDevice gd; ColorModel model; Raster raster; int width, height; public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) { if (comp == null) { this.gd = new BufferedImageDevice(this); } else { Graphics2D g2d = (Graphics2D)comp.getGraphics(); this.gd = g2d.getDeviceConfiguration().getDevice(); } this.model = bufImg.getColorModel(); this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1); this.width = bufImg.getWidth(); this.height = bufImg.getHeight(); } /** * Return the graphics device associated with this configuration. */ --- 43,105 ---- public class BufferedImageGraphicsConfig extends GraphicsConfiguration { private static final int numconfigs = BufferedImage.TYPE_BYTE_BINARY; ! private static BufferedImageGraphicsConfig configs[][] = ! new BufferedImageGraphicsConfig[numconfigs][2]; public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg) { + return getConfig(bImg, 1, 1); + } + + public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg, + double scaleX, + double scaleY) + { BufferedImageGraphicsConfig ret; int type = bImg.getType(); + int index = (scaleX == 1 && scaleY == 1) ? 0 : 1; if (type > 0 && type < numconfigs) { ! ret = configs[type][index]; ! if (ret != null && ret.scaleX == scaleX && ret.scaleY == scaleY) { return ret; } } ! ret = new BufferedImageGraphicsConfig(bImg, null, scaleX, scaleY); if (type > 0 && type < numconfigs) { ! configs[type][index] = ret; } return ret; } GraphicsDevice gd; ColorModel model; Raster raster; int width, height; + private final double scaleX; + private final double scaleY; public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) { + this(bufImg, comp, 1, 1); + } + + public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp, + double scaleX, double scaleY) + { if (comp == null) { this.gd = new BufferedImageDevice(this); } else { Graphics2D g2d = (Graphics2D)comp.getGraphics(); this.gd = g2d.getDeviceConfiguration().getDevice(); } this.model = bufImg.getColorModel(); this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1); this.width = bufImg.getWidth(); this.height = bufImg.getHeight(); + this.scaleX = scaleX; + this.scaleY = scaleY; } /** * Return the graphics device associated with this configuration. */
*** 139,149 **** * the device, with X coordinates * increasing to the right and Y coordinates increasing downwards. * For image buffers, this Transform will be the Identity transform. */ public AffineTransform getDefaultTransform() { ! return new AffineTransform(); } /** * * Returns a Transform that can be composed with the default Transform --- 157,167 ---- * the device, with X coordinates * increasing to the right and Y coordinates increasing downwards. * For image buffers, this Transform will be the Identity transform. */ public AffineTransform getDefaultTransform() { ! return AffineTransform.getScaleInstance(scaleX, scaleY); } /** * * Returns a Transform that can be composed with the default Transform
< prev index next >