0N/A/*
2362N/A * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.image;
0N/A
0N/Aimport java.awt.AWTException;
0N/Aimport java.awt.Component;
0N/Aimport java.awt.Graphics2D;
0N/Aimport java.awt.GraphicsConfiguration;
0N/Aimport java.awt.GraphicsDevice;
0N/Aimport java.awt.ImageCapabilities;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.Transparency;
0N/Aimport java.awt.geom.AffineTransform;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.DirectColorModel;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.VolatileImage;
0N/Aimport java.awt.image.WritableRaster;
0N/A
0N/Apublic class BufferedImageGraphicsConfig
0N/A extends GraphicsConfiguration
0N/A{
0N/A private static final int numconfigs = BufferedImage.TYPE_BYTE_BINARY;
0N/A private static BufferedImageGraphicsConfig configs[] =
0N/A new BufferedImageGraphicsConfig[numconfigs];
0N/A
0N/A public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg) {
0N/A BufferedImageGraphicsConfig ret;
0N/A int type = bImg.getType();
0N/A if (type > 0 && type < numconfigs) {
0N/A ret = configs[type];
0N/A if (ret != null) {
0N/A return ret;
0N/A }
0N/A }
0N/A ret = new BufferedImageGraphicsConfig(bImg, null);
0N/A if (type > 0 && type < numconfigs) {
0N/A configs[type] = ret;
0N/A }
0N/A return ret;
0N/A }
0N/A
0N/A GraphicsDevice gd;
0N/A ColorModel model;
0N/A Raster raster;
0N/A int width, height;
0N/A
0N/A public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
0N/A if (comp == null) {
0N/A this.gd = new BufferedImageDevice(this);
0N/A } else {
0N/A Graphics2D g2d = (Graphics2D)comp.getGraphics();
0N/A this.gd = g2d.getDeviceConfiguration().getDevice();
0N/A }
0N/A this.model = bufImg.getColorModel();
0N/A this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
0N/A this.width = bufImg.getWidth();
0N/A this.height = bufImg.getHeight();
0N/A }
0N/A
0N/A /**
0N/A * Return the graphics device associated with this configuration.
0N/A */
0N/A public GraphicsDevice getDevice() {
0N/A return gd;
0N/A }
0N/A
0N/A /**
0N/A * Returns a BufferedImage with channel layout and color model
0N/A * compatible with this graphics configuration. This method
0N/A * has nothing to do with memory-mapping
0N/A * a device. This BufferedImage has
0N/A * a layout and color model
0N/A * that is closest to this native device configuration and thus
0N/A * can be optimally blitted to this device.
0N/A */
0N/A public BufferedImage createCompatibleImage(int width, int height) {
0N/A WritableRaster wr = raster.createCompatibleWritableRaster(width, height);
0N/A return new BufferedImage(model, wr, model.isAlphaPremultiplied(), null);
0N/A }
0N/A
0N/A /**
0N/A * Returns the color model associated with this configuration.
0N/A */
0N/A public ColorModel getColorModel() {
0N/A return model;
0N/A }
0N/A
0N/A /**
0N/A * Returns the color model associated with this configuration that
0N/A * supports the specified transparency.
0N/A */
0N/A public ColorModel getColorModel(int transparency) {
0N/A
0N/A if (model.getTransparency() == transparency) {
0N/A return model;
0N/A }
0N/A switch (transparency) {
0N/A case Transparency.OPAQUE:
0N/A return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
0N/A case Transparency.BITMASK:
0N/A return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
0N/A case Transparency.TRANSLUCENT:
0N/A return ColorModel.getRGBdefault();
0N/A default:
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the default Transform for this configuration. This
0N/A * Transform is typically the Identity transform for most normal
0N/A * screens. Device coordinates for screen and printer devices will
0N/A * have the origin in the upper left-hand corner of the target region of
0N/A * the device, with X coordinates
0N/A * increasing to the right and Y coordinates increasing downwards.
0N/A * For image buffers, this Transform will be the Identity transform.
0N/A */
0N/A public AffineTransform getDefaultTransform() {
0N/A return new AffineTransform();
0N/A }
0N/A
0N/A /**
0N/A *
0N/A * Returns a Transform that can be composed with the default Transform
0N/A * of a Graphics2D so that 72 units in user space will equal 1 inch
0N/A * in device space.
0N/A * Given a Graphics2D, g, one can reset the transformation to create
0N/A * such a mapping by using the following pseudocode:
0N/A * <pre>
0N/A * GraphicsConfiguration gc = g.getGraphicsConfiguration();
0N/A *
0N/A * g.setTransform(gc.getDefaultTransform());
0N/A * g.transform(gc.getNormalizingTransform());
0N/A * </pre>
0N/A * Note that sometimes this Transform will be identity (e.g. for
0N/A * printers or metafile output) and that this Transform is only
0N/A * as accurate as the information supplied by the underlying system.
0N/A * For image buffers, this Transform will be the Identity transform,
0N/A * since there is no valid distance measurement.
0N/A */
0N/A public AffineTransform getNormalizingTransform() {
0N/A return new AffineTransform();
0N/A }
0N/A
0N/A public Rectangle getBounds() {
0N/A return new Rectangle(0, 0, width, height);
0N/A }
0N/A}