jdk/src/share/classes/sun/awt/image/ImageRepresentation.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 16880 558619642e45
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 1995, 2010, 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: 5188
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: 5188
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: 5188
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5188
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5188
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 sun.awt.image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.AWTException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.image.DirectColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.image.IndexColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.image.ImageConsumer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.image.ImageObserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.image.ByteComponentRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.image.IntegerComponentRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.image.WritableRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.image.DataBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.image.DataBufferInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.awt.image.ImageWatched;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class ImageRepresentation extends ImageWatched implements ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    InputStreamImageSource src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    ToolkitImage image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    long pData; // used by windows native code only -- internal state REMIND ATTN @@
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    int width = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    int height = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    int availinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    Rectangle newbits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    BufferedImage bimage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    WritableRaster biRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected ColorModel cmodel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    ColorModel srcModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    int[] srcLUT = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    int srcLUTtransIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    int numSrcLUT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    boolean forceCMhint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    int sstride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    boolean isDefaultBI = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    boolean isSameCM = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private native static void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        NativeLibLoader.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Create an ImageRepresentation for the given Image.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * width and height are unknown at this point.  The color
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * model is a hint as to the color model to use when creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * the buffered image.  If null, the src color model will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public ImageRepresentation(ToolkitImage im, ColorModel cmodel, boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                               forceCMhint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        image = im;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (image.getSource() instanceof InputStreamImageSource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            src = (InputStreamImageSource) image.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        setColorModel(cmodel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.forceCMhint = forceCMhint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /* REMIND: Only used for Frame.setIcon - should use ImageWatcher instead */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public synchronized void reconstruct(int flags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        int missinginfo = flags & ~availinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if ((availinfo & ImageObserver.ERROR) == 0 && missinginfo != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            numWaiters++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                startProduction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                missinginfo = flags & ~availinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                while ((availinfo & ImageObserver.ERROR) == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                       missinginfo != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                        wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                        Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    missinginfo = flags & ~availinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                decrementWaiters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void setDimensions(int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        image.setDimensions(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        newInfo(image, (ImageObserver.WIDTH | ImageObserver.HEIGHT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            imageComplete(ImageConsumer.IMAGEERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (width != w || height != h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            // dimension mismatch => trigger recreation of the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            bimage = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        width = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        height = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        availinfo |= ImageObserver.WIDTH | ImageObserver.HEIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return cmodel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    BufferedImage getBufferedImage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return bimage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Returns the BufferedImage that will be used as the representation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * the pixel data.  Subclasses can override this method to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * platform specific subclasses of BufferedImage that may or may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * accelerated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * It is subclass' responsibility to propagate acceleration priority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * to the newly created image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    protected BufferedImage createImage(ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                        WritableRaster raster,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                        boolean isRasterPremultiplied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                        Hashtable properties)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        BufferedImage bi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            new BufferedImage(cm, raster, isRasterPremultiplied, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        bi.setAccelerationPriority(image.getAccelerationPriority());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return bi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public void setProperties(Hashtable<?,?> props) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        image.setProperties(props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        newInfo(image, ImageObserver.PROPERTIES, 0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void setColorModel(ColorModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        srcModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // Check to see if model is INT_RGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (model instanceof IndexColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            if (model.getTransparency() == model.TRANSLUCENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                // REMIND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                // Probably need to composite anyway so force ARGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                cmodel = ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                srcLUT = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                IndexColorModel icm = (IndexColorModel) model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                numSrcLUT = icm.getMapSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                srcLUT = new int[Math.max(numSrcLUT, 256)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                icm.getRGBs(srcLUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                srcLUTtransIndex = icm.getTransparentPixel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                cmodel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (cmodel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                cmodel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                srcLUT   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            else if (model instanceof DirectColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                // If it is INT_RGB or INT_ARGB, use the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                DirectColorModel dcm = (DirectColorModel) model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                if ((dcm.getRedMask() == 0xff0000) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    (dcm.getGreenMask() == 0xff00) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    (dcm.getBlueMask()  == 0x00ff)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    cmodel   = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    srcLUT   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        isSameCM = (cmodel == model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    void createBufferedImage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        // REMIND:  Be careful!  Is this called everytime there is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        // startProduction?  We only want to call it if it is new or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        // there is an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        isDefaultBI = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            biRaster = cmodel.createCompatibleWritableRaster(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            bimage = createImage(cmodel, biRaster,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                 cmodel.isAlphaPremultiplied(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            // Create a default image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            cmodel = ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            biRaster = cmodel.createCompatibleWritableRaster(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            bimage = createImage(cmodel, biRaster, false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        int type = bimage.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if ((cmodel == ColorModel.getRGBdefault()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
               (type == BufferedImage.TYPE_INT_RGB) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
               (type == BufferedImage.TYPE_INT_ARGB_PRE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            isDefaultBI = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        else if (cmodel instanceof DirectColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            DirectColorModel dcm = (DirectColorModel) cmodel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if (dcm.getRedMask() == 0xff0000 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                dcm.getGreenMask() == 0xff00 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                dcm.getBlueMask()  == 0xff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                isDefaultBI = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    private void convertToRGB() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        int w = bimage.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        int h = bimage.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        int size = w*h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        DataBufferInt dbi = new DataBufferInt(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // Note that stealData() requires a markDirty() afterwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        // since we modify the data in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        int newpixels[] = SunWritableRaster.stealData(dbi, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (cmodel instanceof IndexColorModel &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            biRaster instanceof ByteComponentRaster &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            biRaster.getNumDataElements() == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            ByteComponentRaster bct = (ByteComponentRaster) biRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            byte[] data = bct.getDataStorage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            int coff = bct.getDataOffset(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            for (int i=0; i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                newpixels[i] = srcLUT[data[coff+i]&0xff];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            Object srcpixels = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            int off=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            for (int y=0; y < h; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                for (int x=0; x < w; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    srcpixels=biRaster.getDataElements(x, y, srcpixels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    newpixels[off++] = cmodel.getRGB(srcpixels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // We modified the data array directly above so mark it as dirty now...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        SunWritableRaster.markDirty(dbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        isSameCM = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        cmodel = ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        int bandMasks[] = {0x00ff0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                           0x0000ff00,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                           0x000000ff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                           0xff000000};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        biRaster = Raster.createPackedRaster(dbi,w,h,w,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                                             bandMasks,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        bimage = createImage(cmodel, biRaster,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                             cmodel.isAlphaPremultiplied(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        srcLUT = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        isDefaultBI = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public void setHints(int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        hints = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
5188
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   336
    private native void setICMpixels(int x, int y, int w, int h, int[] lut,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                    byte[] pix, int off, int scansize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                    IntegerComponentRaster ict);
5188
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   339
    private native int setDiffICM(int x, int y, int w, int h, int[] lut,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                                 int transPix, int numLut, IndexColorModel icm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                 byte[] pix, int off, int scansize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                 ByteComponentRaster bct, int chanOff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    static boolean s_useNative = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public void setPixels(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                          ColorModel model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                          byte pix[], int off, int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        int lineOff=off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        int poff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        int[] newLUT=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        // REMIND: What if the model doesn't fit in default color model?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            if (bimage == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                if (cmodel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    cmodel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                createBufferedImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            }
5188
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   364
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   365
            if (w <= 0 || h <= 0) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   366
                return;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   367
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   368
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   369
            int biWidth = biRaster.getWidth();
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   370
            int biHeight = biRaster.getHeight();
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   371
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   372
            int x1 = x+w;  // Overflow protection below
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   373
            int y1 = y+h;  // Overflow protection below
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   374
            if (x < 0) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   375
                off -= x;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   376
                x = 0;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   377
            } else if (x1 < 0) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   378
                x1 = biWidth;  // Must be overflow
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   379
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   380
            if (y < 0) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   381
                off -= y*scansize;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   382
                y = 0;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   383
            } else if (y1 < 0) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   384
                y1 = biHeight;  // Must be overflow
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   385
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   386
            if (x1 > biWidth) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   387
                x1 = biWidth;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   388
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   389
            if (y1 > biHeight) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   390
                y1 = biHeight;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   391
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   392
            if (x >= x1 || y >= y1) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   393
                return;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   394
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   395
            // x,y,x1,y1 are all >= 0, so w,h must be >= 0
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   396
            w = x1-x;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   397
            h = y1-y;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   398
            // off is first pixel read so it must be in bounds
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   399
            if (off < 0 || off >= pix.length) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   400
                // They overflowed their own array
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   401
                throw new ArrayIndexOutOfBoundsException("Data offset out of bounds.");
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   402
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   403
            // pix.length and off are >= 0 so remainder >= 0
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   404
            int remainder = pix.length - off;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   405
            if (remainder < w) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   406
                // They overflowed their own array
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   407
                throw new ArrayIndexOutOfBoundsException("Data array is too short.");
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   408
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   409
            int num;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   410
            if (scansize < 0) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   411
                num = (off / -scansize) + 1;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   412
            } else if (scansize > 0) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   413
                num = ((remainder-w) / scansize) + 1;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   414
            } else {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   415
                num = h;
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   416
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   417
            if (h > num) {
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   418
                // They overflowed their own array.
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   419
                throw new ArrayIndexOutOfBoundsException("Data array is too short.");
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   420
            }
6208e3cf4275 6914823: Java AWT Library Invalid Index Vulnerability
bae
parents: 4207
diff changeset
   421
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            if (isSameCM && (cmodel != model) && (srcLUT != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                (model instanceof IndexColorModel) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                (biRaster instanceof ByteComponentRaster))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                IndexColorModel icm = (IndexColorModel) model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                ByteComponentRaster bct = (ByteComponentRaster) biRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                int numlut = numSrcLUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                if (setDiffICM(x, y, w, h, srcLUT, srcLUTtransIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                               numSrcLUT, icm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                               pix, off, scansize, bct,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                               bct.getDataOffset(0)) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    convertToRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    // Note that setDiffICM modified the raster directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    // so we must mark it as changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    bct.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    if (numlut != numSrcLUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                        boolean hasAlpha = icm.hasAlpha();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        if (srcLUTtransIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                            hasAlpha = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        int nbits = icm.getPixelSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        icm = new IndexColorModel(nbits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                                                  numSrcLUT, srcLUT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                                  0, hasAlpha,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                                                  srcLUTtransIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                                                  (nbits > 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                                                   ? DataBuffer.TYPE_USHORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                                                   : DataBuffer.TYPE_BYTE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                        cmodel = icm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                        bimage = createImage(icm, bct, false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    return;
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
            if (isDefaultBI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                int pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                IntegerComponentRaster iraster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                          (IntegerComponentRaster) biRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                if (srcLUT != null && model instanceof IndexColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    if (model != srcModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        // Fill in the new lut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                        ((IndexColorModel)model).getRGBs(srcLUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                        srcModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    if (s_useNative) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        // Note that setICMpixels modifies the raster directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        // so we must mark it as changed afterwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        setICMpixels(x, y, w, h, srcLUT, pix, off, scansize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                                     iraster);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                        iraster.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                        int[] storage = new int[w*h];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        int soff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        // It is an IndexColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        for (int yoff=0; yoff < h; yoff++,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                                 lineOff += scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                            poff = lineOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                            for (int i=0; i < w; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                storage[soff++] = srcLUT[pix[poff++]&0xff];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                        iraster.setDataElements(x, y, w, h, storage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    int[] storage = new int[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    for (int yoff=y; yoff < y+h; yoff++, lineOff += scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        poff = lineOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                        for (int i=0; i < w; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                            storage[i] = model.getRGB(pix[poff++]&0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        iraster.setDataElements(x, yoff, w, 1, storage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    availinfo |= ImageObserver.SOMEBITS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            else if ((cmodel == model) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                     (biRaster instanceof ByteComponentRaster) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                     (biRaster.getNumDataElements() == 1)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                ByteComponentRaster bt = (ByteComponentRaster) biRaster;
4207
a9ca0ff33862 6872358: JRE AWT setBytePixels vulnerable to Heap Overflow
bae
parents: 2
diff changeset
   507
                if (off == 0 && scansize == w) {
a9ca0ff33862 6872358: JRE AWT setBytePixels vulnerable to Heap Overflow
bae
parents: 2
diff changeset
   508
                    bt.putByteData(x, y, w, h, pix);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                else {
4207
a9ca0ff33862 6872358: JRE AWT setBytePixels vulnerable to Heap Overflow
bae
parents: 2
diff changeset
   511
                    byte[] bpix = new byte[w];
a9ca0ff33862 6872358: JRE AWT setBytePixels vulnerable to Heap Overflow
bae
parents: 2
diff changeset
   512
                    poff = off;
a9ca0ff33862 6872358: JRE AWT setBytePixels vulnerable to Heap Overflow
bae
parents: 2
diff changeset
   513
                    for (int yoff=y; yoff < y+h; yoff++) {
a9ca0ff33862 6872358: JRE AWT setBytePixels vulnerable to Heap Overflow
bae
parents: 2
diff changeset
   514
                        System.arraycopy(pix, poff, bpix, 0, w);
a9ca0ff33862 6872358: JRE AWT setBytePixels vulnerable to Heap Overflow
bae
parents: 2
diff changeset
   515
                        bt.putByteData(x, yoff, w, 1, bpix);
a9ca0ff33862 6872358: JRE AWT setBytePixels vulnerable to Heap Overflow
bae
parents: 2
diff changeset
   516
                        poff += scansize;
a9ca0ff33862 6872358: JRE AWT setBytePixels vulnerable to Heap Overflow
bae
parents: 2
diff changeset
   517
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                for (int yoff=y; yoff < y+h; yoff++, lineOff += scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    poff = lineOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    for (int xoff=x; xoff < x+w; xoff++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                        bimage.setRGB(xoff, yoff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                                      model.getRGB(pix[poff++]&0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                availinfo |= ImageObserver.SOMEBITS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if ((availinfo & ImageObserver.FRAMEBITS) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            newInfo(image, ImageObserver.SOMEBITS, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public void setPixels(int x, int y, int w, int h, ColorModel model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                          int pix[], int off, int scansize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        int lineOff=off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        int poff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        // REMIND: What if the model doesn't fit in default color model?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (bimage == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                if (cmodel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    cmodel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                createBufferedImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            int[] storage = new int[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            int yoff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            int pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if (cmodel instanceof IndexColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                // REMIND: Right now we don't support writing back into ICM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                // images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                convertToRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            if ((model == cmodel) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                (biRaster instanceof IntegerComponentRaster)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                IntegerComponentRaster iraster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                         (IntegerComponentRaster) biRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                if (off == 0 && scansize == w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    iraster.setDataElements(x, y, w, h, pix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    // Need to pack the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    for (yoff=y; yoff < y+h; yoff++, lineOff+=scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                        System.arraycopy(pix, lineOff, storage, 0, w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                        iraster.setDataElements(x, yoff, w, 1, storage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                if (model.getTransparency() != model.OPAQUE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    cmodel.getTransparency() == cmodel.OPAQUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    convertToRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                if (isDefaultBI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    IntegerComponentRaster iraster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                                        (IntegerComponentRaster) biRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    int[] data = iraster.getDataStorage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    if (cmodel.equals(model)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                        int sstride = iraster.getScanlineStride();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                        int doff = y*sstride + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                        for (yoff=0; yoff < h; yoff++, lineOff += scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                            System.arraycopy(pix, lineOff, data, doff, w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                            doff += sstride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                        // Note: manual modification of pixels, mark the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                        // raster as changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                        iraster.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                        for (yoff=y; yoff < y+h; yoff++, lineOff += scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                            poff = lineOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                            for (int i=0; i < w; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                                storage[i]=model.getRGB(pix[poff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                            iraster.setDataElements(x, yoff, w, 1, storage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    availinfo |= ImageObserver.SOMEBITS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    Object tmp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    for (yoff=y; yoff < y+h; yoff++, lineOff += scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                        poff = lineOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        for (int xoff=x; xoff < x+w; xoff++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                            pixel = model.getRGB(pix[poff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                            tmp = cmodel.getDataElements(pixel,tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                            biRaster.setDataElements(xoff, yoff,tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    availinfo |= ImageObserver.SOMEBITS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        // Can't do this here since we might need to transform/clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        // the region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        if (((availinfo & ImageObserver.FRAMEBITS) == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            newInfo(image, ImageObserver.SOMEBITS, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    public BufferedImage getOpaqueRGBImage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if (bimage.getType() == BufferedImage.TYPE_INT_ARGB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            int w = bimage.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            int h = bimage.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            int size = w * h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            // Note that we steal the data array here, but only for reading...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            DataBufferInt db = (DataBufferInt)biRaster.getDataBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            int[] pixels = SunWritableRaster.stealData(db, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            for (int i = 0; i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                if ((pixels[i] >>> 24) != 0xff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    return bimage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            ColorModel opModel = new DirectColorModel(24,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                                                      0x00ff0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                                                      0x0000ff00,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                                                      0x000000ff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            int bandmasks[] = {0x00ff0000, 0x0000ff00, 0x000000ff};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            WritableRaster opRaster = Raster.createPackedRaster(db, w, h, w,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                                                                bandmasks,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                                                                null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                BufferedImage opImage = createImage(opModel, opRaster,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                                                    false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                return opImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                return bimage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        return bimage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    private boolean consuming = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    public void imageComplete(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        boolean done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        int info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        switch (status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        case ImageConsumer.IMAGEABORTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            info = ImageObserver.ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        case ImageConsumer.IMAGEERROR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            image.addInfo(ImageObserver.ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            info = ImageObserver.ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        case ImageConsumer.STATICIMAGEDONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            info = ImageObserver.ALLBITS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        case ImageConsumer.SINGLEFRAMEDONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            info = ImageObserver.FRAMEBITS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            if (done) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                image.getSource().removeConsumer(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                consuming = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                newbits = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                if (bimage != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    bimage = getOpaqueRGBImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            availinfo |= info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        newInfo(image, info, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        image.infoDone(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /*synchronized*/ void startProduction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        if (!consuming) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            consuming = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            image.getSource().startProduction(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    private int numWaiters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    private synchronized void checkConsumption() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        if (isWatcherListEmpty() && numWaiters == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            ((availinfo & ImageObserver.ALLBITS) == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    public synchronized void notifyWatcherListEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        checkConsumption();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    private synchronized void decrementWaiters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        --numWaiters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        checkConsumption();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    public boolean prepare(ImageObserver iw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        if ((availinfo & ImageObserver.ERROR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            if (iw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                               -1, -1, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        boolean done = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        if (!done) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            addWatcher(iw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            startProduction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            // Some producers deliver image data synchronously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            done = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    public int check(ImageObserver iw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        if ((availinfo & (ImageObserver.ERROR | ImageObserver.ALLBITS)) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            addWatcher(iw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        return availinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    public boolean drawToBufImage(Graphics g, ToolkitImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                                  int x, int y, Color bg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                                  ImageObserver iw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if ((availinfo & ImageObserver.ERROR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if (iw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                               -1, -1, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        boolean done  = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        boolean abort = ((availinfo & ImageObserver.ABORT) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        if (!done && !abort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            addWatcher(iw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            startProduction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            // Some producers deliver image data synchronously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            done = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        if (done || (0 != (availinfo & ImageObserver.FRAMEBITS))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            g.drawImage (bimage, x, y, bg, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    public boolean drawToBufImage(Graphics g, ToolkitImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                                  int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                                  Color bg, ImageObserver iw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        if ((availinfo & ImageObserver.ERROR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            if (iw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                               -1, -1, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        boolean done  = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        boolean abort = ((availinfo & ImageObserver.ABORT) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        if (!done && !abort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            addWatcher(iw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            startProduction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            // Some producers deliver image data synchronously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            done = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        if (done || (0 != (availinfo & ImageObserver.FRAMEBITS))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            g.drawImage (bimage, x, y, w, h, bg, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    public boolean drawToBufImage(Graphics g, ToolkitImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                                  int dx1, int dy1, int dx2, int dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                                  int sx1, int sy1, int sx2, int sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                                  Color bg, ImageObserver iw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if ((availinfo & ImageObserver.ERROR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            if (iw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                               -1, -1, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        boolean done  = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        boolean abort = ((availinfo & ImageObserver.ABORT) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        if (!done && !abort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            addWatcher(iw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            startProduction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            // Some producers deliver image data synchronously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            done = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        if (done || (0 != (availinfo & ImageObserver.FRAMEBITS))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            g.drawImage (bimage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                         dx1, dy1, dx2, dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                         sx1, sy1, sx2, sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                         bg, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    public boolean drawToBufImage(Graphics g, ToolkitImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                                  AffineTransform xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                  ImageObserver iw)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        Graphics2D g2 = (Graphics2D) g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        if (src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            src.checkSecurity(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        if ((availinfo & ImageObserver.ERROR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            if (iw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                               -1, -1, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        boolean done  = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        boolean abort = ((availinfo & ImageObserver.ABORT) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        if (!done && !abort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            addWatcher(iw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            startProduction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            // Some producers deliver image data synchronously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            done = ((availinfo & ImageObserver.ALLBITS) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (done || (0 != (availinfo & ImageObserver.FRAMEBITS))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            g2.drawImage (bimage, xform, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    synchronized void abort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        image.getSource().removeConsumer(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        consuming = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        newbits = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        bimage = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        biRaster = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        cmodel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        srcLUT = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        isDefaultBI = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        isSameCM = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        newInfo(image, ImageObserver.ABORT, -1, -1, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        availinfo &= ~(ImageObserver.SOMEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                       | ImageObserver.FRAMEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                       | ImageObserver.ALLBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                       | ImageObserver.ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    synchronized void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        image.getSource().removeConsumer(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        consuming = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        newbits = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        availinfo &= ~(ImageObserver.SOMEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                       | ImageObserver.FRAMEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                       | ImageObserver.ALLBITS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    public void setAccelerationPriority(float priority) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        if (bimage != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            bimage.setAccelerationPriority(priority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
}