59 * coordinate of (0, 0). Any <code>Raster</code> used to construct a
60 * <code>BufferedImage</code> must therefore have minX=0 and minY=0.
61 *
62 * <p>
63 * This class relies on the data fetching and setting methods
64 * of <code>Raster</code>,
65 * and on the color characterization methods of <code>ColorModel</code>.
66 *
67 * @see ColorModel
68 * @see Raster
69 * @see WritableRaster
70 */
71
72 public class BufferedImage extends java.awt.Image
73 implements WritableRenderedImage, Transparency
74 {
75 int imageType = TYPE_CUSTOM;
76 ColorModel colorModel;
77 WritableRaster raster;
78 OffScreenImageSource osis;
79 Hashtable properties;
80
81 boolean isAlphaPremultiplied;// If true, alpha has been premultiplied in
82 // color channels
83
84 /**
85 * Image Type Constants
86 */
87
88 /**
89 * Image type is not recognized so it must be a customized
90 * image. This type is only used as a return value for the getType()
91 * method.
92 */
93 public static final int TYPE_CUSTOM = 0;
94
95 /**
96 * Represents an image with 8-bit RGB color components packed into
97 * integer pixels. The image has a {@link DirectColorModel} without
98 * alpha.
99 * When data with non-opaque alpha is stored
625 WritableRaster raster,
626 boolean isRasterPremultiplied,
627 Hashtable<?,?> properties) {
628
629 if (!cm.isCompatibleRaster(raster)) {
630 throw new
631 IllegalArgumentException("Raster "+raster+
632 " is incompatible with ColorModel "+
633 cm);
634 }
635
636 if ((raster.minX != 0) || (raster.minY != 0)) {
637 throw new
638 IllegalArgumentException("Raster "+raster+
639 " has minX or minY not equal to zero: "
640 + raster.minX + " " + raster.minY);
641 }
642
643 colorModel = cm;
644 this.raster = raster;
645 this.properties = properties;
646 int numBands = raster.getNumBands();
647 boolean isAlphaPre = cm.isAlphaPremultiplied();
648 final boolean isStandard = isStandard(cm, raster);
649 ColorSpace cs;
650
651 // Force the raster data alpha state to match the premultiplied
652 // state in the color model
653 coerceData(isRasterPremultiplied);
654
655 SampleModel sm = raster.getSampleModel();
656 cs = cm.getColorSpace();
657 int csType = cs.getType();
658 if (csType != ColorSpace.TYPE_RGB) {
659 if (csType == ColorSpace.TYPE_GRAY &&
660 isStandard &&
661 cm instanceof ComponentColorModel) {
662 // Check if this might be a child raster (fix for bug 4240596)
663 if (sm instanceof ComponentSampleModel &&
664 ((ComponentSampleModel)sm).getPixelStride() != numBands) {
665 imageType = TYPE_CUSTOM;
1090 }
1091
1092 /**
1093 * Returns the height of the <code>BufferedImage</code>.
1094 * @param observer ignored
1095 * @return the height of this <code>BufferedImage</code>
1096 */
1097 public int getHeight(ImageObserver observer) {
1098 return raster.getHeight();
1099 }
1100
1101 /**
1102 * Returns the object that produces the pixels for the image.
1103 * @return the {@link ImageProducer} that is used to produce the
1104 * pixels for this image.
1105 * @see ImageProducer
1106 */
1107 public ImageProducer getSource() {
1108 if (osis == null) {
1109 if (properties == null) {
1110 properties = new Hashtable();
1111 }
1112 osis = new OffScreenImageSource(this, properties);
1113 }
1114 return osis;
1115 }
1116
1117
1118 /**
1119 * Returns a property of the image by name. Individual property names
1120 * are defined by the various image formats. If a property is not
1121 * defined for a particular image, this method returns the
1122 * <code>UndefinedProperty</code> field. If the properties
1123 * for this image are not yet known, then this method returns
1124 * <code>null</code> and the <code>ImageObserver</code> object is
1125 * notified later. The property name "comment" should be used to
1126 * store an optional comment that can be presented to the user as a
1127 * description of the image, its source, or its author.
1128 * @param name the property name
1129 * @param observer the <code>ImageObserver</code> that receives
1130 * notification regarding image information
|
59 * coordinate of (0, 0). Any <code>Raster</code> used to construct a
60 * <code>BufferedImage</code> must therefore have minX=0 and minY=0.
61 *
62 * <p>
63 * This class relies on the data fetching and setting methods
64 * of <code>Raster</code>,
65 * and on the color characterization methods of <code>ColorModel</code>.
66 *
67 * @see ColorModel
68 * @see Raster
69 * @see WritableRaster
70 */
71
72 public class BufferedImage extends java.awt.Image
73 implements WritableRenderedImage, Transparency
74 {
75 int imageType = TYPE_CUSTOM;
76 ColorModel colorModel;
77 WritableRaster raster;
78 OffScreenImageSource osis;
79 Hashtable<Object, Object> properties;
80
81 boolean isAlphaPremultiplied;// If true, alpha has been premultiplied in
82 // color channels
83
84 /**
85 * Image Type Constants
86 */
87
88 /**
89 * Image type is not recognized so it must be a customized
90 * image. This type is only used as a return value for the getType()
91 * method.
92 */
93 public static final int TYPE_CUSTOM = 0;
94
95 /**
96 * Represents an image with 8-bit RGB color components packed into
97 * integer pixels. The image has a {@link DirectColorModel} without
98 * alpha.
99 * When data with non-opaque alpha is stored
625 WritableRaster raster,
626 boolean isRasterPremultiplied,
627 Hashtable<?,?> properties) {
628
629 if (!cm.isCompatibleRaster(raster)) {
630 throw new
631 IllegalArgumentException("Raster "+raster+
632 " is incompatible with ColorModel "+
633 cm);
634 }
635
636 if ((raster.minX != 0) || (raster.minY != 0)) {
637 throw new
638 IllegalArgumentException("Raster "+raster+
639 " has minX or minY not equal to zero: "
640 + raster.minX + " " + raster.minY);
641 }
642
643 colorModel = cm;
644 this.raster = raster;
645 this.properties = (Hashtable<Object,Object>)properties;
646 int numBands = raster.getNumBands();
647 boolean isAlphaPre = cm.isAlphaPremultiplied();
648 final boolean isStandard = isStandard(cm, raster);
649 ColorSpace cs;
650
651 // Force the raster data alpha state to match the premultiplied
652 // state in the color model
653 coerceData(isRasterPremultiplied);
654
655 SampleModel sm = raster.getSampleModel();
656 cs = cm.getColorSpace();
657 int csType = cs.getType();
658 if (csType != ColorSpace.TYPE_RGB) {
659 if (csType == ColorSpace.TYPE_GRAY &&
660 isStandard &&
661 cm instanceof ComponentColorModel) {
662 // Check if this might be a child raster (fix for bug 4240596)
663 if (sm instanceof ComponentSampleModel &&
664 ((ComponentSampleModel)sm).getPixelStride() != numBands) {
665 imageType = TYPE_CUSTOM;
1090 }
1091
1092 /**
1093 * Returns the height of the <code>BufferedImage</code>.
1094 * @param observer ignored
1095 * @return the height of this <code>BufferedImage</code>
1096 */
1097 public int getHeight(ImageObserver observer) {
1098 return raster.getHeight();
1099 }
1100
1101 /**
1102 * Returns the object that produces the pixels for the image.
1103 * @return the {@link ImageProducer} that is used to produce the
1104 * pixels for this image.
1105 * @see ImageProducer
1106 */
1107 public ImageProducer getSource() {
1108 if (osis == null) {
1109 if (properties == null) {
1110 properties = new Hashtable<>();
1111 }
1112 osis = new OffScreenImageSource(this, properties);
1113 }
1114 return osis;
1115 }
1116
1117
1118 /**
1119 * Returns a property of the image by name. Individual property names
1120 * are defined by the various image formats. If a property is not
1121 * defined for a particular image, this method returns the
1122 * <code>UndefinedProperty</code> field. If the properties
1123 * for this image are not yet known, then this method returns
1124 * <code>null</code> and the <code>ImageObserver</code> object is
1125 * notified later. The property name "comment" should be used to
1126 * store an optional comment that can be presented to the user as a
1127 * description of the image, its source, or its author.
1128 * @param name the property name
1129 * @param observer the <code>ImageObserver</code> that receives
1130 * notification regarding image information
|