< prev index next >

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

Print this page

        

@@ -43,45 +43,63 @@
 
 public class BufferedImageGraphicsConfig
     extends GraphicsConfiguration
 {
     private static final int numconfigs = BufferedImage.TYPE_BYTE_BINARY;
-    private static BufferedImageGraphicsConfig configs[] =
-        new BufferedImageGraphicsConfig[numconfigs];
+    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];
-            if (ret != null) {
+            ret = configs[type][index];
+            if (ret != null && ret.scaleX == scaleX && ret.scaleY == scaleY) {
                 return ret;
             }
         }
-        ret = new BufferedImageGraphicsConfig(bImg, null);
+        ret = new BufferedImageGraphicsConfig(bImg, null, scaleX, scaleY);
         if (type > 0 && type < numconfigs) {
-            configs[type] = ret;
+            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,11 +157,11 @@
      * 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();
+        return AffineTransform.getScaleInstance(scaleX, scaleY);
     }
 
     /**
      *
      * Returns a Transform that can be composed with the default Transform
< prev index next >