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

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.image;
  27 
  28 import java.awt.AWTException;
  29 import java.awt.Component;
  30 import java.awt.Graphics2D;
  31 import java.awt.GraphicsConfiguration;
  32 import java.awt.GraphicsDevice;
  33 import java.awt.ImageCapabilities;
  34 import java.awt.Rectangle;
  35 import java.awt.Transparency;
  36 import java.awt.geom.AffineTransform;
  37 import java.awt.image.BufferedImage;
  38 import java.awt.image.ColorModel;
  39 import java.awt.image.DirectColorModel;
  40 import java.awt.image.Raster;
  41 import java.awt.image.VolatileImage;
  42 import java.awt.image.WritableRaster;
  43 
  44 public class BufferedImageGraphicsConfig
  45     extends GraphicsConfiguration
  46 {
  47     private static final int numconfigs = BufferedImage.TYPE_BYTE_BINARY;
  48     private static BufferedImageGraphicsConfig configs[] =
  49         new BufferedImageGraphicsConfig[numconfigs];
  50 
  51     public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg) {
  52         BufferedImageGraphicsConfig ret;
  53         int type = bImg.getType();
  54         if (type > 0 && type < numconfigs) {
  55             ret = configs[type];
  56             if (ret != null) {
  57                 return ret;
  58             }
  59         }



  60         ret = new BufferedImageGraphicsConfig(bImg, null);

  61         if (type > 0 && type < numconfigs) {
  62             configs[type] = ret;
  63         }
  64         return ret;
  65     }
  66 
  67     GraphicsDevice gd;
  68     ColorModel model;
  69     Raster raster;
  70     int width, height;
  71 
  72     public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
  73         if (comp == null) {
  74             this.gd = new BufferedImageDevice(this);
  75         } else {
  76             Graphics2D g2d = (Graphics2D)comp.getGraphics();
  77             this.gd = g2d.getDeviceConfiguration().getDevice();
  78         }
  79         this.model = bufImg.getColorModel();
  80         this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.image;
  27 

  28 import java.awt.Component;
  29 import java.awt.Graphics2D;
  30 import java.awt.GraphicsConfiguration;
  31 import java.awt.GraphicsDevice;

  32 import java.awt.Rectangle;
  33 import java.awt.Transparency;
  34 import java.awt.geom.AffineTransform;
  35 import java.awt.image.BufferedImage;
  36 import java.awt.image.ColorModel;
  37 import java.awt.image.DirectColorModel;
  38 import java.awt.image.Raster;

  39 import java.awt.image.WritableRaster;
  40 
  41 public class BufferedImageGraphicsConfig
  42     extends GraphicsConfiguration
  43 {
  44     private static final int numconfigs = BufferedImage.TYPE_BYTE_BINARY;
  45     private static BufferedImageGraphicsConfig configs[] =
  46         new BufferedImageGraphicsConfig[numconfigs];
  47 
  48     public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg) {
  49         BufferedImageGraphicsConfig ret;
  50         int type = bImg.getType();
  51         if (type > 0 && type < numconfigs) {
  52             ret = configs[type];
  53             if (ret != null) {
  54                 return ret;
  55             }
  56         }
  57         if (bImg instanceof OffScreenImage) {
  58             ret = ((OffScreenImage)bImg).new GraphicsConfig();
  59         } else {
  60             ret = new BufferedImageGraphicsConfig(bImg, null);
  61         }
  62         if (type > 0 && type < numconfigs) {
  63             configs[type] = ret;
  64         }
  65         return ret;
  66     }
  67     
  68     GraphicsDevice gd;
  69     ColorModel model;
  70     Raster raster;
  71     int width, height;
  72 
  73     public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
  74         if (comp == null) {
  75             this.gd = new BufferedImageDevice(this);
  76         } else {
  77             Graphics2D g2d = (Graphics2D)comp.getGraphics();
  78             this.gd = g2d.getDeviceConfiguration().getDevice();
  79         }
  80         this.model = bufImg.getColorModel();
  81         this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);