1 /*
2 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
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
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 standardConfigs[] =
49 new BufferedImageGraphicsConfig[numconfigs];
50 private static BufferedImageGraphicsConfig scaledConfigs[] =
51 new BufferedImageGraphicsConfig[numconfigs];
52
53 public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg) {
54 return getConfig(bImg, 1, 1);
55 }
56
57 public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg,
58 double scaleX,
59 double scaleY)
60 {
61 BufferedImageGraphicsConfig ret;
62 int type = bImg.getType();
63
64 BufferedImageGraphicsConfig[] configs = (scaleX == 1 && scaleY == 1)
65 ? standardConfigs : scaledConfigs;
66
67 if (type > 0 && type < numconfigs) {
68 ret = configs[type];
69 if (ret != null && ret.scaleX == scaleX && ret.scaleY == scaleY) {
70 return ret;
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
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
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[] standardConfigs =
49 new BufferedImageGraphicsConfig[numconfigs];
50 private static BufferedImageGraphicsConfig[] scaledConfigs =
51 new BufferedImageGraphicsConfig[numconfigs];
52
53 public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg) {
54 return getConfig(bImg, 1, 1);
55 }
56
57 public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg,
58 double scaleX,
59 double scaleY)
60 {
61 BufferedImageGraphicsConfig ret;
62 int type = bImg.getType();
63
64 BufferedImageGraphicsConfig[] configs = (scaleX == 1 && scaleY == 1)
65 ? standardConfigs : scaledConfigs;
66
67 if (type > 0 && type < numconfigs) {
68 ret = configs[type];
69 if (ret != null && ret.scaleX == scaleX && ret.scaleY == scaleY) {
70 return ret;
|