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