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 java.awt.image;
27
28 import java.awt.Graphics2D;
29 import java.awt.GraphicsEnvironment;
30 import java.awt.Point;
31 import java.awt.Rectangle;
32 import java.awt.Transparency;
33 import java.awt.color.ColorSpace;
34 import java.security.AccessController;
35 import java.security.PrivilegedAction;
36 import java.util.Hashtable;
37 import java.util.Set;
38 import java.util.Vector;
39
40 import sun.awt.image.ByteComponentRaster;
41 import sun.awt.image.BytePackedRaster;
42 import sun.awt.image.IntegerComponentRaster;
43 import sun.awt.image.OffScreenImageSource;
44 import sun.awt.image.ShortComponentRaster;
45
46 /**
47 *
48 * The {@code BufferedImage} subclass describes an {@link
49 * java.awt.Image Image} with an accessible buffer of image data.
50 * A {@code BufferedImage} is comprised of a {@link ColorModel} and a
51 * {@link Raster} of image data.
52 * The number and types of bands in the {@link SampleModel} of the
56 * coordinate of (0, 0). Any {@code Raster} used to construct a
57 * {@code BufferedImage} must therefore have minX=0 and minY=0.
58 *
59 * <p>
60 * This class relies on the data fetching and setting methods
61 * of {@code Raster},
62 * and on the color characterization methods of {@code ColorModel}.
63 *
64 * @see ColorModel
65 * @see Raster
66 * @see WritableRaster
67 */
68 public class BufferedImage extends java.awt.Image
69 implements WritableRenderedImage, Transparency
70 {
71 private int imageType = TYPE_CUSTOM;
72 private ColorModel colorModel;
73 private final WritableRaster raster;
74 private OffScreenImageSource osis;
75 private Hashtable<String, Object> properties;
76
77 /**
78 * Image Type Constants
79 */
80
81 /**
82 * Image type is not recognized so it must be a customized
83 * image. This type is only used as a return value for the getType()
84 * method.
85 */
86 public static final int TYPE_CUSTOM = 0;
87
88 /**
89 * Represents an image with 8-bit RGB color components packed into
90 * integer pixels. The image has a {@link DirectColorModel} without
91 * alpha.
92 * When data with non-opaque alpha is stored
93 * in an image of this type,
94 * the color data must be adjusted to a non-premultiplied form
95 * and the alpha discarded,
274 private static final int DCM_565_GRN_MASK = 0x07E0;
275 private static final int DCM_565_BLU_MASK = 0x001F;
276 private static final int DCM_555_RED_MASK = 0x7C00;
277 private static final int DCM_555_GRN_MASK = 0x03E0;
278 private static final int DCM_555_BLU_MASK = 0x001F;
279 private static final int DCM_BGR_RED_MASK = 0x0000ff;
280 private static final int DCM_BGR_GRN_MASK = 0x00ff00;
281 private static final int DCM_BGR_BLU_MASK = 0xff0000;
282
283
284 private static native void initIDs();
285 static {
286 ColorModel.loadLibraries();
287 initIDs();
288 }
289
290 /**
291 * Constructs a {@code BufferedImage} of one of the predefined
292 * image types. The {@code ColorSpace} for the image is the
293 * default sRGB space.
294 * @param width width of the created image
295 * @param height height of the created image
296 * @param imageType type of the created image
297 * @see ColorSpace
298 * @see #TYPE_INT_RGB
299 * @see #TYPE_INT_ARGB
300 * @see #TYPE_INT_ARGB_PRE
301 * @see #TYPE_INT_BGR
302 * @see #TYPE_3BYTE_BGR
303 * @see #TYPE_4BYTE_ABGR
304 * @see #TYPE_4BYTE_ABGR_PRE
305 * @see #TYPE_BYTE_GRAY
306 * @see #TYPE_USHORT_GRAY
307 * @see #TYPE_BYTE_BINARY
308 * @see #TYPE_BYTE_INDEXED
309 * @see #TYPE_USHORT_565_RGB
310 * @see #TYPE_USHORT_555_RGB
311 */
312 public BufferedImage(int width,
313 int height,
834 * @see #TYPE_4BYTE_ABGR_PRE
835 * @see #TYPE_BYTE_GRAY
836 * @see #TYPE_BYTE_BINARY
837 * @see #TYPE_BYTE_INDEXED
838 * @see #TYPE_USHORT_GRAY
839 * @see #TYPE_USHORT_565_RGB
840 * @see #TYPE_USHORT_555_RGB
841 * @see #TYPE_CUSTOM
842 */
843 public int getType() {
844 return imageType;
845 }
846
847 /**
848 * Returns the {@code ColorModel}.
849 * @return the {@code ColorModel} of this
850 * {@code BufferedImage}.
851 */
852 public ColorModel getColorModel() {
853 return colorModel;
854 }
855
856 /**
857 * Returns the {@link WritableRaster}.
858 * @return the {@code WritableRaster} of this
859 * {@code BufferedImage}.
860 */
861 public WritableRaster getRaster() {
862 return raster;
863 }
864
865
866 /**
867 * Returns a {@code WritableRaster} representing the alpha
868 * channel for {@code BufferedImage} objects
869 * with {@code ColorModel} objects that support a separate
870 * spatial alpha channel, such as {@code ComponentColorModel} and
871 * {@code DirectColorModel}. Returns {@code null} if there
872 * is no alpha channel associated with the {@code ColorModel} in
873 * this image. This method assumes that for all
|
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 java.awt.image;
27
28 import java.awt.Graphics2D;
29 import java.awt.GraphicsEnvironment;
30 import java.awt.Point;
31 import java.awt.Rectangle;
32 import java.awt.Transparency;
33 import java.awt.GraphicsConfiguration;
34 import java.awt.color.ColorSpace;
35 import java.security.AccessController;
36 import java.security.PrivilegedAction;
37 import java.util.Hashtable;
38 import java.util.Set;
39 import java.util.Vector;
40
41 import sun.awt.image.ByteComponentRaster;
42 import sun.awt.image.BytePackedRaster;
43 import sun.awt.image.IntegerComponentRaster;
44 import sun.awt.image.OffScreenImageSource;
45 import sun.awt.image.ShortComponentRaster;
46
47 /**
48 *
49 * The {@code BufferedImage} subclass describes an {@link
50 * java.awt.Image Image} with an accessible buffer of image data.
51 * A {@code BufferedImage} is comprised of a {@link ColorModel} and a
52 * {@link Raster} of image data.
53 * The number and types of bands in the {@link SampleModel} of the
57 * coordinate of (0, 0). Any {@code Raster} used to construct a
58 * {@code BufferedImage} must therefore have minX=0 and minY=0.
59 *
60 * <p>
61 * This class relies on the data fetching and setting methods
62 * of {@code Raster},
63 * and on the color characterization methods of {@code ColorModel}.
64 *
65 * @see ColorModel
66 * @see Raster
67 * @see WritableRaster
68 */
69 public class BufferedImage extends java.awt.Image
70 implements WritableRenderedImage, Transparency
71 {
72 private int imageType = TYPE_CUSTOM;
73 private ColorModel colorModel;
74 private final WritableRaster raster;
75 private OffScreenImageSource osis;
76 private Hashtable<String, Object> properties;
77 private GraphicsConfiguration graphicsConfig = null;
78
79 /**
80 * Image Type Constants
81 */
82
83 /**
84 * Image type is not recognized so it must be a customized
85 * image. This type is only used as a return value for the getType()
86 * method.
87 */
88 public static final int TYPE_CUSTOM = 0;
89
90 /**
91 * Represents an image with 8-bit RGB color components packed into
92 * integer pixels. The image has a {@link DirectColorModel} without
93 * alpha.
94 * When data with non-opaque alpha is stored
95 * in an image of this type,
96 * the color data must be adjusted to a non-premultiplied form
97 * and the alpha discarded,
276 private static final int DCM_565_GRN_MASK = 0x07E0;
277 private static final int DCM_565_BLU_MASK = 0x001F;
278 private static final int DCM_555_RED_MASK = 0x7C00;
279 private static final int DCM_555_GRN_MASK = 0x03E0;
280 private static final int DCM_555_BLU_MASK = 0x001F;
281 private static final int DCM_BGR_RED_MASK = 0x0000ff;
282 private static final int DCM_BGR_GRN_MASK = 0x00ff00;
283 private static final int DCM_BGR_BLU_MASK = 0xff0000;
284
285
286 private static native void initIDs();
287 static {
288 ColorModel.loadLibraries();
289 initIDs();
290 }
291
292 /**
293 * Constructs a {@code BufferedImage} of one of the predefined
294 * image types. The {@code ColorSpace} for the image is the
295 * default sRGB space.
296 * @param config graphics configuration
297 * @param width width of the created image
298 * @param height height of the created image
299 * @param imageType type of the created image
300 */
301 public BufferedImage(GraphicsConfiguration config, int width,
302 int height,
303 int imageType) {
304 this(width, height, imageType);
305 this.graphicsConfig = config;
306 }
307
308 /**
309 * Constructs a {@code BufferedImage} of one of the predefined
310 * image types. The {@code ColorSpace} for the image is the
311 * default sRGB space.
312 * @param width width of the created image
313 * @param height height of the created image
314 * @param imageType type of the created image
315 * @see ColorSpace
316 * @see #TYPE_INT_RGB
317 * @see #TYPE_INT_ARGB
318 * @see #TYPE_INT_ARGB_PRE
319 * @see #TYPE_INT_BGR
320 * @see #TYPE_3BYTE_BGR
321 * @see #TYPE_4BYTE_ABGR
322 * @see #TYPE_4BYTE_ABGR_PRE
323 * @see #TYPE_BYTE_GRAY
324 * @see #TYPE_USHORT_GRAY
325 * @see #TYPE_BYTE_BINARY
326 * @see #TYPE_BYTE_INDEXED
327 * @see #TYPE_USHORT_565_RGB
328 * @see #TYPE_USHORT_555_RGB
329 */
330 public BufferedImage(int width,
331 int height,
852 * @see #TYPE_4BYTE_ABGR_PRE
853 * @see #TYPE_BYTE_GRAY
854 * @see #TYPE_BYTE_BINARY
855 * @see #TYPE_BYTE_INDEXED
856 * @see #TYPE_USHORT_GRAY
857 * @see #TYPE_USHORT_565_RGB
858 * @see #TYPE_USHORT_555_RGB
859 * @see #TYPE_CUSTOM
860 */
861 public int getType() {
862 return imageType;
863 }
864
865 /**
866 * Returns the {@code ColorModel}.
867 * @return the {@code ColorModel} of this
868 * {@code BufferedImage}.
869 */
870 public ColorModel getColorModel() {
871 return colorModel;
872 }
873
874 /**
875 * Returns the {@code GraphicsConfiguration}.
876 * @return the {@code GraphicsConfiguration} of this
877 * {@code BufferedImage}.
878 */
879 public GraphicsConfiguration getGraphicsConfig() {
880 return graphicsConfig;
881 }
882
883 /**
884 * Returns the {@link WritableRaster}.
885 * @return the {@code WritableRaster} of this
886 * {@code BufferedImage}.
887 */
888 public WritableRaster getRaster() {
889 return raster;
890 }
891
892
893 /**
894 * Returns a {@code WritableRaster} representing the alpha
895 * channel for {@code BufferedImage} objects
896 * with {@code ColorModel} objects that support a separate
897 * spatial alpha channel, such as {@code ComponentColorModel} and
898 * {@code DirectColorModel}. Returns {@code null} if there
899 * is no alpha channel associated with the {@code ColorModel} in
900 * this image. This method assumes that for all
|