jdk/src/share/classes/java/awt/image/BufferedImage.java
author tbell
Wed, 07 Oct 2009 14:15:01 -0700
changeset 3965 63aae8ce7f47
parent 715 f16baef3a20e
child 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.color.ColorSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.ImageCapabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.image.BytePackedRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.awt.image.ShortComponentRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.awt.image.ByteComponentRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.awt.image.IntegerComponentRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.awt.image.OffScreenImageSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The <code>BufferedImage</code> subclass describes an {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * java.awt.Image Image} with an accessible buffer of image data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * A <code>BufferedImage</code> is comprised of a {@link ColorModel} and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * {@link Raster} of image data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * The number and types of bands in the {@link SampleModel} of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <code>Raster</code> must match the number and types required by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>ColorModel</code> to represent its color and alpha components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * All <code>BufferedImage</code> objects have an upper left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * coordinate of (0,&nbsp;0).  Any <code>Raster</code> used to construct a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>BufferedImage</code> must therefore have minX=0 and minY=0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * This class relies on the data fetching and setting methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * of <code>Raster</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * and on the color characterization methods of <code>ColorModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @see ColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @see Raster
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see WritableRaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public class BufferedImage extends java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                           implements WritableRenderedImage, Transparency
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    int        imageType = TYPE_CUSTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    ColorModel colorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    WritableRaster raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    OffScreenImageSource osis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    Hashtable properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    boolean    isAlphaPremultiplied;// If true, alpha has been premultiplied in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // color channels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Image Type Constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Image type is not recognized so it must be a customized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * image.  This type is only used as a return value for the getType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static final int TYPE_CUSTOM = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Represents an image with 8-bit RGB color components packed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * integer pixels.  The image has a {@link DirectColorModel} without
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * alpha.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * When data with non-opaque alpha is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * in an image of this type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * the color data must be adjusted to a non-premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * and the alpha discarded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * {@link java.awt.AlphaComposite} documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public static final int TYPE_INT_RGB = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Represents an image with 8-bit RGBA color components packed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * integer pixels.  The image has a <code>DirectColorModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * with alpha. The color data in this image is considered not to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * premultiplied with alpha.  When this type is used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <code>imageType</code> argument to a <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * constructor, the created image is consistent with images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * created in the JDK1.1 and earlier releases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static final int TYPE_INT_ARGB = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Represents an image with 8-bit RGBA color components packed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * integer pixels.  The image has a <code>DirectColorModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * with alpha.  The color data in this image is considered to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * premultiplied with alpha.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static final int TYPE_INT_ARGB_PRE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Represents an image with 8-bit RGB color components, corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * to a Windows- or Solaris- style BGR color model, with the colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Blue, Green, and Red packed into integer pixels.  There is no alpha.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * The image has a {@link DirectColorModel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * When data with non-opaque alpha is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * in an image of this type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * the color data must be adjusted to a non-premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * and the alpha discarded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * {@link java.awt.AlphaComposite} documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static final int TYPE_INT_BGR = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Represents an image with 8-bit RGB color components, corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * to a Windows-style BGR color model) with the colors Blue, Green,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * and Red stored in 3 bytes.  There is no alpha.  The image has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <code>ComponentColorModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * When data with non-opaque alpha is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * in an image of this type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * the color data must be adjusted to a non-premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * and the alpha discarded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * {@link java.awt.AlphaComposite} documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public static final int TYPE_3BYTE_BGR = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Represents an image with 8-bit RGBA color components with the colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Blue, Green, and Red stored in 3 bytes and 1 byte of alpha.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * image has a <code>ComponentColorModel</code> with alpha.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * color data in this image is considered not to be premultiplied with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * alpha.  The byte data is interleaved in a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * byte array in the order A, B, G, R
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * from lower to higher byte addresses within each pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public static final int TYPE_4BYTE_ABGR = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Represents an image with 8-bit RGBA color components with the colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Blue, Green, and Red stored in 3 bytes and 1 byte of alpha.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * image has a <code>ComponentColorModel</code> with alpha. The color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * data in this image is considered to be premultiplied with alpha.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * The byte data is interleaved in a single byte array in the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * A, B, G, R from lower to higher byte addresses within each pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public static final int TYPE_4BYTE_ABGR_PRE = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Represents an image with 5-6-5 RGB color components (5-bits red,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * 6-bits green, 5-bits blue) with no alpha.  This image has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * a <code>DirectColorModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * When data with non-opaque alpha is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * in an image of this type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * the color data must be adjusted to a non-premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * and the alpha discarded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * {@link java.awt.AlphaComposite} documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public static final int TYPE_USHORT_565_RGB = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Represents an image with 5-5-5 RGB color components (5-bits red,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * 5-bits green, 5-bits blue) with no alpha.  This image has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * a <code>DirectColorModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * When data with non-opaque alpha is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * in an image of this type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * the color data must be adjusted to a non-premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * and the alpha discarded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * {@link java.awt.AlphaComposite} documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public static final int TYPE_USHORT_555_RGB = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Represents a unsigned byte grayscale image, non-indexed.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * image has a <code>ComponentColorModel</code> with a CS_GRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * {@link ColorSpace}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * When data with non-opaque alpha is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * in an image of this type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * the color data must be adjusted to a non-premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * and the alpha discarded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * {@link java.awt.AlphaComposite} documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public static final int TYPE_BYTE_GRAY = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Represents an unsigned short grayscale image, non-indexed).  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * image has a <code>ComponentColorModel</code> with a CS_GRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <code>ColorSpace</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * When data with non-opaque alpha is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * in an image of this type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * the color data must be adjusted to a non-premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * and the alpha discarded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * {@link java.awt.AlphaComposite} documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public static final int TYPE_USHORT_GRAY = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Represents an opaque byte-packed 1, 2, or 4 bit image.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * image has an {@link IndexColorModel} without alpha.  When this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * type is used as the <code>imageType</code> argument to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <code>BufferedImage</code> constructor that takes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * <code>imageType</code> argument but no <code>ColorModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * argument, a 1-bit image is created with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <code>IndexColorModel</code> with two colors in the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * sRGB <code>ColorSpace</code>: {0,&nbsp;0,&nbsp;0} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * {255,&nbsp;255,&nbsp;255}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <p> Images with 2 or 4 bits per pixel may be constructed via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * the <code>BufferedImage</code> constructor that takes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <code>ColorModel</code> argument by supplying a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <code>ColorModel</code> with an appropriate map size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <p> Images with 8 bits per pixel should use the image types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <code>TYPE_BYTE_INDEXED</code> or <code>TYPE_BYTE_GRAY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * depending on their <code>ColorModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <p> When color data is stored in an image of this type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * the closest color in the colormap is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * by the <code>IndexColorModel</code> and the resulting index is stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Approximation and loss of alpha or color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * can result, depending on the colors in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <code>IndexColorModel</code> colormap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public static final int TYPE_BYTE_BINARY = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Represents an indexed byte image.  When this type is used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <code>imageType</code> argument to the <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * constructor that takes an <code>imageType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * but no <code>ColorModel</code> argument, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * <code>IndexColorModel</code> is created with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * a 256-color 6/6/6 color cube palette with the rest of the colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * from 216-255 populated by grayscale values in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * default sRGB ColorSpace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * <p> When color data is stored in an image of this type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * the closest color in the colormap is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * by the <code>IndexColorModel</code> and the resulting index is stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Approximation and loss of alpha or color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * can result, depending on the colors in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <code>IndexColorModel</code> colormap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public static final int TYPE_BYTE_INDEXED = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private static final int DCM_RED_MASK   = 0x00ff0000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static final int DCM_GREEN_MASK = 0x0000ff00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private static final int DCM_BLUE_MASK  = 0x000000ff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static final int DCM_ALPHA_MASK = 0xff000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private static final int DCM_565_RED_MASK = 0xf800;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    private static final int DCM_565_GRN_MASK = 0x07E0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private static final int DCM_565_BLU_MASK = 0x001F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private static final int DCM_555_RED_MASK = 0x7C00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private static final int DCM_555_GRN_MASK = 0x03E0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private static final int DCM_555_BLU_MASK = 0x001F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private static final int DCM_BGR_RED_MASK = 0x0000ff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private static final int DCM_BGR_GRN_MASK = 0x00ff00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private static final int DCM_BGR_BLU_MASK = 0xff0000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    static private native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        ColorModel.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Constructs a <code>BufferedImage</code> of one of the predefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * image types.  The <code>ColorSpace</code> for the image is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * default sRGB space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param width     width of the created image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param height    height of the created image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param imageType type of the created image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see ColorSpace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @see #TYPE_INT_RGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see #TYPE_INT_ARGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see #TYPE_INT_ARGB_PRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see #TYPE_INT_BGR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @see #TYPE_3BYTE_BGR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @see #TYPE_4BYTE_ABGR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see #TYPE_4BYTE_ABGR_PRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @see #TYPE_BYTE_GRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @see #TYPE_USHORT_GRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @see #TYPE_BYTE_BINARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @see #TYPE_BYTE_INDEXED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @see #TYPE_USHORT_565_RGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @see #TYPE_USHORT_555_RGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public BufferedImage(int width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                         int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                         int imageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        switch (imageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        case TYPE_INT_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                colorModel = new DirectColorModel(24,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                                  0x00ff0000,   // Red
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                                  0x0000ff00,   // Green
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                                  0x000000ff,   // Blue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                                  0x0           // Alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                                  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                  raster = colorModel.createCompatibleWritableRaster(width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                                                      height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        case TYPE_INT_ARGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                colorModel = ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                raster = colorModel.createCompatibleWritableRaster(width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                                                   height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        case TYPE_INT_ARGB_PRE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                colorModel = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    DirectColorModel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                     ColorSpace.getInstance(ColorSpace.CS_sRGB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                     32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                     0x00ff0000,// Red
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                     0x0000ff00,// Green
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                     0x000000ff,// Blue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                                     0xff000000,// Alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                     true,       // Alpha Premultiplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                     DataBuffer.TYPE_INT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                     );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                  raster = colorModel.createCompatibleWritableRaster(width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                                                                      height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        case TYPE_INT_BGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                colorModel = new DirectColorModel(24,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                                  0x000000ff,   // Red
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                                  0x0000ff00,   // Green
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                                                  0x00ff0000    // Blue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                                                  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                  raster = colorModel.createCompatibleWritableRaster(width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                                                      height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        case TYPE_3BYTE_BGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                int[] nBits = {8, 8, 8};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                int[] bOffs = {2, 1, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                colorModel = new ComponentColorModel(cs, nBits, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                                                     Transparency.OPAQUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                                                     DataBuffer.TYPE_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                                        width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                                        width*3, 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                                        bOffs, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        case TYPE_4BYTE_ABGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                int[] nBits = {8, 8, 8, 8};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                int[] bOffs = {3, 2, 1, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                colorModel = new ComponentColorModel(cs, nBits, true, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                                     Transparency.TRANSLUCENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                                     DataBuffer.TYPE_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                                        width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                                        width*4, 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                                        bOffs, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        case TYPE_4BYTE_ABGR_PRE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                int[] nBits = {8, 8, 8, 8};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                int[] bOffs = {3, 2, 1, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                colorModel = new ComponentColorModel(cs, nBits, true, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                                                     Transparency.TRANSLUCENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                                                     DataBuffer.TYPE_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                                        width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                                                        width*4, 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                                        bOffs, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        case TYPE_BYTE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                int[] nBits = {8};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                colorModel = new ComponentColorModel(cs, nBits, false, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                                     Transparency.OPAQUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                                     DataBuffer.TYPE_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                raster = colorModel.createCompatibleWritableRaster(width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                                                   height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        case TYPE_USHORT_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                int[] nBits = {16};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                colorModel = new ComponentColorModel(cs, nBits, false, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                                     Transparency.OPAQUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                                     DataBuffer.TYPE_USHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                raster = colorModel.createCompatibleWritableRaster(width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                                                                   height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        case TYPE_BYTE_BINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                byte[] arr = {(byte)0, (byte)0xff};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                colorModel = new IndexColorModel(1, 2, arr, arr, arr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                raster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                                                   width, height, 1, 1, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        case TYPE_BYTE_INDEXED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                // Create a 6x6x6 color cube
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                int[] cmap = new int[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                int i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                for (int r=0; r < 256; r += 51) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    for (int g=0; g < 256; g += 51) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        for (int b=0; b < 256; b += 51) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                            cmap[i++] = (r<<16)|(g<<8)|b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                // And populate the rest of the cmap with gray values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                int grayIncr = 256/(256-i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                // The gray ramp will be between 18 and 252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                int gray = grayIncr*3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                for (; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    cmap[i] = (gray<<16)|(gray<<8)|gray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    gray += grayIncr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                colorModel = new IndexColorModel(8, 256, cmap, 0, false, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                                 DataBuffer.TYPE_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                                                      width, height, 1, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        case TYPE_USHORT_565_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                colorModel = new DirectColorModel(16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                                  DCM_565_RED_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                                  DCM_565_GRN_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                                  DCM_565_BLU_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                                  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                raster = colorModel.createCompatibleWritableRaster(width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                                                   height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        case TYPE_USHORT_555_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                colorModel = new DirectColorModel(15,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                                  DCM_555_RED_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                                  DCM_555_GRN_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                                                  DCM_555_BLU_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                                  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                raster = colorModel.createCompatibleWritableRaster(width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                                                                   height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            throw new IllegalArgumentException ("Unknown image type " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                                imageType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        this.imageType = imageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * Constructs a <code>BufferedImage</code> of one of the predefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * image types:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * <p> If the image type is TYPE_BYTE_BINARY, the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * entries in the color model is used to determine whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * image should have 1, 2, or 4 bits per pixel.  If the color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * has 1 or 2 entries, the image will have 1 bit per pixel.  If it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * has 3 or 4 entries, the image with have 2 bits per pixel.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * it has between 5 and 16 entries, the image will have 4 bits per
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * pixel.  Otherwise, an IllegalArgumentException will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @param width     width of the created image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @param height    height of the created image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @param imageType type of the created image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @param cm        <code>IndexColorModel</code> of the created image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @throws IllegalArgumentException   if the imageType is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED or if the imageType is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * TYPE_BYTE_BINARY and the color map has more than 16 entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @see #TYPE_BYTE_BINARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @see #TYPE_BYTE_INDEXED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public BufferedImage (int width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                          int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                          int imageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                          IndexColorModel cm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (cm.hasAlpha() && cm.isAlphaPremultiplied()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            throw new IllegalArgumentException("This image types do not have "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                               "premultiplied alpha.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        switch(imageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        case TYPE_BYTE_BINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            int bits; // Will be set below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            int mapSize = cm.getMapSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (mapSize <= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                bits = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            } else if (mapSize <= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                bits = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            } else if (mapSize <= 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                bits = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    ("Color map for TYPE_BYTE_BINARY " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                     "must have no more than 16 entries");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            raster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                                width, height, 1, bits, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        case TYPE_BYTE_INDEXED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                                    width, height, 1, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            throw new IllegalArgumentException("Invalid image type (" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                               imageType+").  Image type must"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                               " be either TYPE_BYTE_BINARY or "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                                               " TYPE_BYTE_INDEXED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        if (!cm.isCompatibleRaster(raster)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            throw new IllegalArgumentException("Incompatible image type and IndexColorModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        colorModel = cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        this.imageType = imageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * Constructs a new <code>BufferedImage</code> with a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * <code>ColorModel</code> and <code>Raster</code>.  If the number and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * types of bands in the <code>SampleModel</code> of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * <code>Raster</code> do not match the number and types required by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * the <code>ColorModel</code> to represent its color and alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * components, a {@link RasterFormatException} is thrown.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * method can multiply or divide the color <code>Raster</code> data by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * alpha to match the <code>alphaPremultiplied</code> state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * in the <code>ColorModel</code>.  Properties for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <code>BufferedImage</code> can be established by passing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * in a {@link Hashtable} of <code>String</code>/<code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param cm <code>ColorModel</code> for the new image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @param raster     <code>Raster</code> for the image data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @param isRasterPremultiplied   if <code>true</code>, the data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *                  the raster has been premultiplied with alpha.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @param properties <code>Hashtable</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *                  <code>String</code>/<code>Object</code> pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @exception <code>RasterFormatException</code> if the number and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * types of bands in the <code>SampleModel</code> of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <code>Raster</code> do not match the number and types required by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * the <code>ColorModel</code> to represent its color and alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @exception <code>IllegalArgumentException</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *          <code>raster</code> is incompatible with <code>cm</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @see ColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @see Raster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @see WritableRaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
 *  FOR NOW THE CODE WHICH DEFINES THE RASTER TYPE IS DUPLICATED BY DVF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
 *  SEE THE METHOD DEFINERASTERTYPE @ RASTEROUTPUTMANAGER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public BufferedImage (ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                          WritableRaster raster,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                          boolean isRasterPremultiplied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                          Hashtable<?,?> properties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        if (!cm.isCompatibleRaster(raster)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                IllegalArgumentException("Raster "+raster+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                                         " is incompatible with ColorModel "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                         cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        if ((raster.minX != 0) || (raster.minY != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                IllegalArgumentException("Raster "+raster+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                                         " has minX or minY not equal to zero: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                                         + raster.minX + " " + raster.minY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        colorModel = cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        this.raster  = raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        this.properties = properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        int numBands = raster.getNumBands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        boolean isAlphaPre = cm.isAlphaPremultiplied();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        ColorSpace cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        // Force the raster data alpha state to match the premultiplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        // state in the color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        coerceData(isRasterPremultiplied);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        SampleModel sm = raster.getSampleModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        cs = cm.getColorSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        int csType = cs.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        if (csType != ColorSpace.TYPE_RGB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            if (csType == ColorSpace.TYPE_GRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                && cm instanceof ComponentColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                // Check if this might be a child raster (fix for bug 4240596)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                if (sm instanceof ComponentSampleModel &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    ((ComponentSampleModel)sm).getPixelStride() != numBands) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                    imageType = TYPE_CUSTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                } else if (raster instanceof ByteComponentRaster &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                       raster.getNumBands() == 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                       cm.getComponentSize(0) == 8 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                       ((ByteComponentRaster)raster).getPixelStride() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    imageType = TYPE_BYTE_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                } else if (raster instanceof ShortComponentRaster &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                       raster.getNumBands() == 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                       cm.getComponentSize(0) == 16 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                       ((ShortComponentRaster)raster).getPixelStride() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    imageType = TYPE_USHORT_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                imageType = TYPE_CUSTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if ((raster instanceof IntegerComponentRaster) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            (numBands == 3 || numBands == 4)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            IntegerComponentRaster iraster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                (IntegerComponentRaster) raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            // Check if the raster params and the color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            // are correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            int pixSize = cm.getPixelSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            if (iraster.getPixelStride() == 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                cm instanceof DirectColorModel  &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                (pixSize == 32 || pixSize == 24))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                // Now check on the DirectColorModel params
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                DirectColorModel dcm = (DirectColorModel) cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                int rmask = dcm.getRedMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                int gmask = dcm.getGreenMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                int bmask = dcm.getBlueMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                if (rmask == DCM_RED_MASK && gmask == DCM_GREEN_MASK &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    bmask == DCM_BLUE_MASK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    if (dcm.getAlphaMask() == DCM_ALPHA_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                        imageType = (isAlphaPre
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                                     ? TYPE_INT_ARGB_PRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                                     : TYPE_INT_ARGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                        // No Alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                        if (!dcm.hasAlpha()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                            imageType = TYPE_INT_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                }   // if (dcm.getRedMask() == DCM_RED_MASK &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                else if (rmask == DCM_BGR_RED_MASK && gmask == DCM_BGR_GRN_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                         && bmask == DCM_BGR_BLU_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    if (!dcm.hasAlpha()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                        imageType = TYPE_INT_BGR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                }  // if (rmask == DCM_BGR_RED_MASK &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            }   // if (iraster.getPixelStride() == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }   // ((raster instanceof IntegerComponentRaster) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        else if ((cm instanceof IndexColorModel) && (numBands == 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                 (!cm.hasAlpha() || !isAlphaPre))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            IndexColorModel icm = (IndexColorModel) cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            int pixSize = icm.getPixelSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            if (raster instanceof BytePackedRaster) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                imageType = TYPE_BYTE_BINARY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            }   // if (raster instanceof BytePackedRaster)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            else if (raster instanceof ByteComponentRaster) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                ByteComponentRaster braster = (ByteComponentRaster) raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                if (braster.getPixelStride() == 1 && pixSize <= 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                    imageType = TYPE_BYTE_INDEXED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }   // else if (cm instanceof IndexColorModel) && (numBands == 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        else if ((raster instanceof ShortComponentRaster)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                 && (cm instanceof DirectColorModel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                 && (numBands == 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                 && !cm.hasAlpha())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            DirectColorModel dcm = (DirectColorModel) cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            if (dcm.getRedMask() == DCM_565_RED_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                if (dcm.getGreenMask() == DCM_565_GRN_MASK &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                    dcm.getBlueMask()  == DCM_565_BLU_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                    imageType = TYPE_USHORT_565_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            else if (dcm.getRedMask() == DCM_555_RED_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                if (dcm.getGreenMask() == DCM_555_GRN_MASK &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                    dcm.getBlueMask() == DCM_555_BLU_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    imageType = TYPE_USHORT_555_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }   // else if ((cm instanceof IndexColorModel) && (numBands == 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        else if ((raster instanceof ByteComponentRaster)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                 && (cm instanceof ComponentColorModel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                 && (raster.getSampleModel() instanceof PixelInterleavedSampleModel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                 && (numBands == 3 || numBands == 4))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            ComponentColorModel ccm = (ComponentColorModel) cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            PixelInterleavedSampleModel csm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                (PixelInterleavedSampleModel)raster.getSampleModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            ByteComponentRaster braster = (ByteComponentRaster) raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            int[] offs = csm.getBandOffsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            if (ccm.getNumComponents() != numBands) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                throw new RasterFormatException("Number of components in "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                                                "ColorModel ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                                                ccm.getNumComponents()+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                                                ") does not match # in "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                                                " Raster ("+numBands+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            int[] nBits = ccm.getComponentSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            boolean is8bit = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            for (int i=0; i < numBands; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                if (nBits[i] != 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                    is8bit = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            if (is8bit &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                offs[0] == numBands-1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                offs[1] == numBands-2 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                offs[2] == numBands-3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                if (numBands == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    imageType = TYPE_3BYTE_BGR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                else if (offs[3] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    imageType = (isAlphaPre
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                                 ? TYPE_4BYTE_ABGR_PRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                                 : TYPE_4BYTE_ABGR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        }   // else if ((raster instanceof ByteComponentRaster) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * Returns the image type.  If it is not one of the known types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * TYPE_CUSTOM is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @return the image type of this <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @see #TYPE_INT_RGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @see #TYPE_INT_ARGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @see #TYPE_INT_ARGB_PRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @see #TYPE_INT_BGR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @see #TYPE_3BYTE_BGR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * @see #TYPE_4BYTE_ABGR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * @see #TYPE_4BYTE_ABGR_PRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * @see #TYPE_BYTE_GRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * @see #TYPE_BYTE_BINARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @see #TYPE_BYTE_INDEXED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @see #TYPE_USHORT_GRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * @see #TYPE_USHORT_565_RGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @see #TYPE_USHORT_555_RGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @see #TYPE_CUSTOM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        return imageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * Returns the <code>ColorModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @return the <code>ColorModel</code> of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     *  <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    public ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        return colorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * Returns the {@link WritableRaster}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * @return the <code>WriteableRaster</code> of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *  <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    public WritableRaster getRaster() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        return raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * Returns a <code>WritableRaster</code> representing the alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * channel for <code>BufferedImage</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * with <code>ColorModel</code> objects that support a separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * spatial alpha channel, such as <code>ComponentColorModel</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * <code>DirectColorModel</code>.  Returns <code>null</code> if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * is no alpha channel associated with the <code>ColorModel</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * this image.  This method assumes that for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * <code>ColorModel</code> objects other than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * <code>IndexColorModel</code>, if the <code>ColorModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * supports alpha, there is a separate alpha channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * which is stored as the last band of image data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * If the image uses an <code>IndexColorModel</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * has alpha in the lookup table, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * <code>null</code> since there is no spatially discrete alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * channel.  This method creates a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * <code>WritableRaster</code>, but shares the data array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * @return a <code>WritableRaster</code> or <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *          <code>BufferedImage</code> has no alpha channel associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *          with its <code>ColorModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    public WritableRaster getAlphaRaster() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        return colorModel.getAlphaRaster(raster);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * Returns an integer pixel in the default RGB color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * (TYPE_INT_ARGB) and default sRGB colorspace.  Color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * conversion takes place if this default model does not match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * the image <code>ColorModel</code>.  There are only 8-bits of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * precision for each color component in the returned data when using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * An <code>ArrayOutOfBoundsException</code> may be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * if the coordinates are not in bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * However, explicit bounds checking is not guaranteed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * @param x the X coordinate of the pixel from which to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *          the pixel in the default RGB color model and sRGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     *          color space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @param y the Y coordinate of the pixel from which to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *          the pixel in the default RGB color model and sRGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *          color space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @return an integer pixel in the default RGB color model and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     *          default sRGB colorspace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @see #setRGB(int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @see #setRGB(int, int, int, int, int[], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    public int getRGB(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        return colorModel.getRGB(raster.getDataElements(x, y, null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * Returns an array of integer pixels in the default RGB color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * (TYPE_INT_ARGB) and default sRGB color space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * from a portion of the image data.  Color conversion takes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * place if the default model does not match the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * <code>ColorModel</code>.  There are only 8-bits of precision for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * each color component in the returned data when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * using this method.  With a specified coordinate (x,&nbsp;y) in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * image, the ARGB pixel can be accessed in this way:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     *    pixel   = rgbArray[offset + (y-startY)*scansize + (x-startX)]; </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * An <code>ArrayOutOfBoundsException</code> may be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * if the region is not in bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * However, explicit bounds checking is not guaranteed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @param startX      the starting X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @param startY      the starting Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * @param w           width of region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @param h           height of region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * @param rgbArray    if not <code>null</code>, the rgb pixels are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     *          written here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * @param offset      offset into the <code>rgbArray</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @param scansize    scanline stride for the <code>rgbArray</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @return            array of RGB pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @see #setRGB(int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @see #setRGB(int, int, int, int, int[], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    public int[] getRGB(int startX, int startY, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                        int[] rgbArray, int offset, int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        int yoff  = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        int off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        Object data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        int nbands = raster.getNumBands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        int dataType = raster.getDataBuffer().getDataType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        switch (dataType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        case DataBuffer.TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            data = new byte[nbands];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        case DataBuffer.TYPE_USHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            data = new short[nbands];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        case DataBuffer.TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            data = new int[nbands];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        case DataBuffer.TYPE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            data = new float[nbands];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        case DataBuffer.TYPE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            data = new double[nbands];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            throw new IllegalArgumentException("Unknown data buffer type: "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                                               dataType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        if (rgbArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            rgbArray = new int[offset+h*scansize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        for (int y = startY; y < startY+h; y++, yoff+=scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            off = yoff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            for (int x = startX; x < startX+w; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                rgbArray[off++] = colorModel.getRGB(raster.getDataElements(x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                                                                        y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                                                                        data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        return rgbArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * Sets a pixel in this <code>BufferedImage</code> to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * RGB value. The pixel is assumed to be in the default RGB color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * model, TYPE_INT_ARGB, and default sRGB color space.  For images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * with an <code>IndexColorModel</code>, the index with the nearest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * color is chosen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * An <code>ArrayOutOfBoundsException</code> may be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * if the coordinates are not in bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * However, explicit bounds checking is not guaranteed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * @param x the X coordinate of the pixel to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * @param y the Y coordinate of the pixel to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @param rgb the RGB value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * @see #getRGB(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * @see #getRGB(int, int, int, int, int[], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    public synchronized void setRGB(int x, int y, int rgb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        raster.setDataElements(x, y, colorModel.getDataElements(rgb, null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * Sets an array of integer pixels in the default RGB color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * (TYPE_INT_ARGB) and default sRGB color space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * into a portion of the image data.  Color conversion takes place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * if the default model does not match the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * <code>ColorModel</code>.  There are only 8-bits of precision for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * each color component in the returned data when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * using this method.  With a specified coordinate (x,&nbsp;y) in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * this image, the ARGB pixel can be accessed in this way:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *    pixel   = rgbArray[offset + (y-startY)*scansize + (x-startX)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * WARNING: No dithering takes place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * An <code>ArrayOutOfBoundsException</code> may be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * if the region is not in bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * However, explicit bounds checking is not guaranteed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @param startX      the starting X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @param startY      the starting Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * @param w           width of the region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * @param h           height of the region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * @param rgbArray    the rgb pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * @param offset      offset into the <code>rgbArray</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * @param scansize    scanline stride for the <code>rgbArray</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * @see #getRGB(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * @see #getRGB(int, int, int, int, int[], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public void setRGB(int startX, int startY, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                        int[] rgbArray, int offset, int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        int yoff  = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        int off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        Object pixel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        for (int y = startY; y < startY+h; y++, yoff+=scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            off = yoff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            for (int x = startX; x < startX+w; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                pixel = colorModel.getDataElements(rgbArray[off++], pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                raster.setDataElements(x, y, pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * Returns the width of the <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * @return the width of this <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        return raster.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * Returns the height of the <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * @return the height of this <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        return raster.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * Returns the width of the <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * @param observer ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * @return the width of this <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    public int getWidth(ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        return raster.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * Returns the height of the <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * @param observer ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * @return the height of this <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    public int getHeight(ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        return raster.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * Returns the object that produces the pixels for the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @return the {@link ImageProducer} that is used to produce the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * pixels for this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @see ImageProducer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    public ImageProducer getSource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        if (osis == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            if (properties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                properties = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            osis = new OffScreenImageSource(this, properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        return osis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * Returns a property of the image by name.  Individual property names
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * are defined by the various image formats.  If a property is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * defined for a particular image, this method returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * <code>UndefinedProperty</code> field.  If the properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * for this image are not yet known, then this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * <code>null</code> and the <code>ImageObserver</code> object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * notified later.  The property name "comment" should be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * store an optional comment that can be presented to the user as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * description of the image, its source, or its author.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * @param name the property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * @param observer the <code>ImageObserver</code> that receives
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     *  notification regarding image information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * @return an {@link Object} that is the property referred to by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     *          specified <code>name</code> or <code>null</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     *          properties of this image are not yet known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * @throws <code>NullPointerException</code> if the property name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * @see ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * @see java.awt.Image#UndefinedProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    public Object getProperty(String name, ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        return getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * Returns a property of the image by name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * @param name the property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * @return an <code>Object</code> that is the property referred to by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     *          the specified <code>name</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * @throws <code>NullPointerException</code> if the property name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    public Object getProperty(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            throw new NullPointerException("null property name is not allowed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        if (properties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            return java.awt.Image.UndefinedProperty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        Object o = properties.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        if (o == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            o = java.awt.Image.UndefinedProperty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * This method returns a {@link Graphics2D}, but is here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * for backwards compatibility.  {@link #createGraphics() createGraphics} is more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * convenient, since it is declared to return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * <code>Graphics2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * @return a <code>Graphics2D</code>, which can be used to draw into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *          this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    public java.awt.Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        return createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * Creates a <code>Graphics2D</code>, which can be used to draw into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * this <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @return a <code>Graphics2D</code>, used for drawing into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     *          image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    public Graphics2D createGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        GraphicsEnvironment env =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        return env.createGraphics(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * Returns a subimage defined by a specified rectangular region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * The returned <code>BufferedImage</code> shares the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * data array as the original image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * @param x the X coordinate of the upper-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     *          specified rectangular region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * @param y the Y coordinate of the upper-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     *          specified rectangular region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * @param w the width of the specified rectangular region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @param h the height of the specified rectangular region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * @return a <code>BufferedImage</code> that is the subimage of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *          <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * @exception <code>RasterFormatException</code> if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * area is not contained within this <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    public BufferedImage getSubimage (int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        return new BufferedImage (colorModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                                  raster.createWritableChild(x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                                                             0, 0, null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                                  colorModel.isAlphaPremultiplied(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                                  properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * Returns whether or not the alpha has been premultiplied.  It
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * returns <code>false</code> if there is no alpha.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * @return <code>true</code> if the alpha has been premultiplied;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *          <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    public boolean isAlphaPremultiplied() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        return colorModel.isAlphaPremultiplied();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * Forces the data to match the state specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * <code>isAlphaPremultiplied</code> variable.  It may multiply or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * divide the color raster data by alpha, or do nothing if the data is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * in the correct state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * @param isAlphaPremultiplied <code>true</code> if the alpha has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *          premultiplied; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    public void coerceData (boolean isAlphaPremultiplied) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        if (colorModel.hasAlpha() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            colorModel.isAlphaPremultiplied() != isAlphaPremultiplied) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            // Make the color model do the conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            colorModel = colorModel.coerceData (raster, isAlphaPremultiplied);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * Returns a <code>String</code> representation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * <code>BufferedImage</code> object and its values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @return a <code>String</code> representing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     *          <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    public String toString() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1213
        return "BufferedImage@"+Integer.toHexString(hashCode())
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1214
            +": type = "+imageType
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1215
            +" "+colorModel+" "+raster;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * Returns a {@link Vector} of {@link RenderedImage} objects that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * the immediate sources, not the sources of these immediate sources,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * of image data for this <code>BufferedImage</code>.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * method returns <code>null</code> if the <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * has no information about its immediate sources.  It returns an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * empty <code>Vector</code> if the <code>BufferedImage</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * immediate sources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * @return a <code>Vector</code> containing immediate sources of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     *          this <code>BufferedImage</code> object's image date, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     *          <code>null</code> if this <code>BufferedImage</code> has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     *          no information about its immediate sources, or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     *          <code>Vector</code> if this <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     *          has no immediate sources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    public Vector<RenderedImage> getSources() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * Returns an array of names recognized by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * {@link #getProperty(String) getProperty(String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * or <code>null</code>, if no property names are recognized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @return a <code>String</code> array containing all of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *          names that <code>getProperty(String)</code> recognizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     *          or <code>null</code> if no property names are recognized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    public String[] getPropertyNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
         return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * Returns the minimum x coordinate of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * <code>BufferedImage</code>.  This is always zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * @return the minimum x coordinate of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     *          <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    public int getMinX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        return raster.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * Returns the minimum y coordinate of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * <code>BufferedImage</code>.  This is always zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * @return the minimum y coordinate of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     *          <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    public int getMinY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        return raster.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * Returns the <code>SampleModel</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * @return the <code>SampleModel</code> of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     *          <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    public SampleModel getSampleModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        return raster.getSampleModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * Returns the number of tiles in the x direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * This is always one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * @return the number of tiles in the x direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    public int getNumXTiles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * Returns the number of tiles in the y direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * This is always one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * @return the number of tiles in the y direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    public int getNumYTiles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * Returns the minimum tile index in the x direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * This is always zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * @return the minimum tile index in the x direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    public int getMinTileX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * Returns the minimum tile index in the y direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * This is always zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * @return the mininum tile index in the y direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    public int getMinTileY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * Returns the tile width in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * @return the tile width in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    public int getTileWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
       return raster.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * Returns the tile height in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * @return the tile height in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    public int getTileHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
       return raster.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * Returns the x offset of the tile grid relative to the origin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     * For example, the x coordinate of the location of tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * (0,&nbsp;0).  This is always zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     * @return the x offset of the tile grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    public int getTileGridXOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        return raster.getSampleModelTranslateX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * Returns the y offset of the tile grid relative to the origin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * For example, the y coordinate of the location of tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * (0,&nbsp;0).  This is always zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * @return the y offset of the tile grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    public int getTileGridYOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        return raster.getSampleModelTranslateY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * Returns tile (<code>tileX</code>,&nbsp;<code>tileY</code>).  Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * that <code>tileX</code> and <code>tileY</code> are indices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * into the tile array, not pixel locations.  The <code>Raster</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * that is returned is live, which means that it is updated if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * image is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * @param tileX the x index of the requested tile in the tile array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * @param tileY the y index of the requested tile in the tile array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * @return a <code>Raster</code> that is the tile defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     *          arguments <code>tileX</code> and <code>tileY</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * @exception <code>ArrayIndexOutOfBoundsException</code> if both
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     *          <code>tileX</code> and <code>tileY</code> are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     *          equal to 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    public Raster getTile(int tileX, int tileY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        if (tileX == 0 && tileY == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            return raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        throw new ArrayIndexOutOfBoundsException("BufferedImages only have"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
             " one tile with index 0,0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * Returns the image as one large tile.  The <code>Raster</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * returned is a copy of the image data is not updated if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * image is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * @return a <code>Raster</code> that is a copy of the image data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * @see #setData(Raster)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    public Raster getData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        // REMIND : this allocates a whole new tile if raster is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        // subtile.  (It only copies in the requested area)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        // We should do something smarter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        int width = raster.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        int height = raster.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        int startX = raster.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        int startY = raster.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        WritableRaster wr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
           Raster.createWritableRaster(raster.getSampleModel(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                         new Point(raster.getSampleModelTranslateX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                                   raster.getSampleModelTranslateY()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        Object tdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        for (int i = startY; i < startY+height; i++)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            tdata = raster.getDataElements(startX,i,width,1,tdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            wr.setDataElements(startX,i,width,1, tdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        return wr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * Computes and returns an arbitrary region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * <code>BufferedImage</code>.  The <code>Raster</code> returned is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * copy of the image data and is not updated if the image is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * @param rect the region of the <code>BufferedImage</code> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * @return a <code>Raster</code> that is a copy of the image data of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     *          the specified region of the <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * @see #setData(Raster)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    public Raster getData(Rectangle rect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        SampleModel sm = raster.getSampleModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        SampleModel nsm = sm.createCompatibleSampleModel(rect.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                                                         rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        WritableRaster wr = Raster.createWritableRaster(nsm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                                                  rect.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        int width = rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        int height = rect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        int startX = rect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        int startY = rect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        Object tdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        for (int i = startY; i < startY+height; i++)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            tdata = raster.getDataElements(startX,i,width,1,tdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            wr.setDataElements(startX,i,width,1, tdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        return wr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * Computes an arbitrary rectangular region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     * <code>BufferedImage</code> and copies it into a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * <code>WritableRaster</code>.  The region to be computed is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * determined from the bounds of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * <code>WritableRaster</code>.  The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * <code>WritableRaster</code> must have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * <code>SampleModel</code> that is compatible with this image.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * <code>outRaster</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * an appropriate <code>WritableRaster</code> is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * @param outRaster a <code>WritableRaster</code> to hold the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     *          part of the image, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * @return a reference to the supplied or created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     *          <code>WritableRaster</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    public WritableRaster copyData(WritableRaster outRaster) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        if (outRaster == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            return (WritableRaster) getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        int width = outRaster.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        int height = outRaster.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        int startX = outRaster.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        int startY = outRaster.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        Object tdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        for (int i = startY; i < startY+height; i++)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            tdata = raster.getDataElements(startX,i,width,1,tdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            outRaster.setDataElements(startX,i,width,1, tdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        return outRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * Sets a rectangular region of the image to the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * specified <code>Raster</code> <code>r</code>, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * assumed to be in the same coordinate space as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * <code>BufferedImage</code>. The operation is clipped to the bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * of the <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * @param r the specified <code>Raster</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * @see #getData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * @see #getData(Rectangle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    public void setData(Raster r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        int width = r.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        int height = r.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        int startX = r.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        int startY = r.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        int[] tdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        // Clip to the current Raster
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        Rectangle rclip = new Rectangle(startX, startY, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        Rectangle bclip = new Rectangle(0, 0, raster.width, raster.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        Rectangle intersect = rclip.intersection(bclip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        if (intersect.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        width = intersect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        height = intersect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        startX = intersect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        startY = intersect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        // remind use get/setDataElements for speed if Rasters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        // compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        for (int i = startY; i < startY+height; i++)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            tdata = r.getPixels(startX,i,width,1,tdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            raster.setPixels(startX,i,width,1, tdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
   * Adds a tile observer.  If the observer is already present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
   * it receives multiple notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
   * @param to the specified {@link TileObserver}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
    public void addTileObserver (TileObserver to) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
   * Removes a tile observer.  If the observer was not registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
   * nothing happens.  If the observer was registered for multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
   * notifications, it is now registered for one fewer notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
   * @param to the specified <code>TileObserver</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
    public void removeTileObserver (TileObserver to) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     * Returns whether or not a tile is currently checked out for writing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     * @param tileX the x index of the tile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
     * @param tileY the y index of the tile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
     * @return <code>true</code> if the tile specified by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     *          indices is checked out for writing; <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     *          otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * @exception <code>ArrayIndexOutOfBoundsException</code> if both
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     *          <code>tileX</code> and <code>tileY</code> are not equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     *          to 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    public boolean isTileWritable (int tileX, int tileY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        if (tileX == 0 && tileY == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        throw new IllegalArgumentException("Only 1 tile in image");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     * Returns an array of {@link Point} objects indicating which tiles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * are checked out for writing.  Returns <code>null</code> if none are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     * checked out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     * @return a <code>Point</code> array that indicates the tiles that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     *          are checked out for writing, or <code>null</code> if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     *          tiles are checked out for writing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    public Point[] getWritableTileIndices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        Point[] p = new Point[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        p[0] = new Point(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     * Returns whether or not any tile is checked out for writing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     * Semantically equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     * (getWritableTileIndices() != null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     * @return <code>true</code> if any tile is checked out for writing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     *          <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    public boolean hasTileWriters () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
   * Checks out a tile for writing.  All registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
   * <code>TileObservers</code> are notified when a tile goes from having
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
   * no writers to having one writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
   * @param tileX the x index of the tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
   * @param tileY the y index of the tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
   * @return a <code>WritableRaster</code> that is the tile, indicated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
   *            the specified indices, to be checked out for writing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    public WritableRaster getWritableTile (int tileX, int tileY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        return raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
   * Relinquishes permission to write to a tile.  If the caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
   * continues to write to the tile, the results are undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
   * Calls to this method should only appear in matching pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
   * with calls to {@link #getWritableTile(int, int) getWritableTile(int, int)}.  Any other leads
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
   * to undefined results.  All registered <code>TileObservers</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
   * are notified when a tile goes from having one writer to having no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
   * writers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
   * @param tileX the x index of the tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
   * @param tileY the y index of the tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    public void releaseWritableTile (int tileX, int tileY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * Returns the transparency.  Returns either OPAQUE, BITMASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     * or TRANSLUCENT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * @return the transparency of this <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * @see Transparency#OPAQUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * @see Transparency#BITMASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     * @see Transparency#TRANSLUCENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    public int getTransparency() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        return colorModel.getTransparency();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
}