src/java.desktop/share/classes/java/awt/image/MemoryImageSource.java
author tvaleev
Thu, 04 Oct 2018 12:40:55 -0700
changeset 52248 2e330da7cbf4
parent 47216 71c04702a3d5
permissions -rw-r--r--
8211300: Convert C-style array declarations in JDK client code Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
     2
 * Copyright (c) 1995, 2018, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.image.ImageConsumer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.image.ImageProducer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This class is an implementation of the ImageProducer interface which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * uses an array to produce pixel values for an Image.  Here is an example
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * which calculates a 100x100 image representing a fade from black to blue
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * along the X axis and a fade from black to red along the Y axis:
19169
1807a84c3d63 8022447: Fix doclint warnings in java.awt.image
prr
parents: 5506
diff changeset
    40
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *      int w = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      int h = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      int pix[] = new int[w * h];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      for (int y = 0; y < h; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *          int red = (y * 255) / (h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *          for (int x = 0; x < w; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *              int blue = (x * 255) / (w - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *              pix[index++] = (255 << 24) | (red << 16) | blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      Image img = createImage(new MemoryImageSource(w, h, pix, 0, w));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
19169
1807a84c3d63 8022447: Fix doclint warnings in java.awt.image
prr
parents: 5506
diff changeset
    55
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * The MemoryImageSource is also capable of managing a memory image which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * varies over time to allow animation or custom rendering.  Here is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * example showing how to set up the animation source and signal changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * in the data (adapted from the MemoryAnimationSourceDemo by Garth Dickie):
19169
1807a84c3d63 8022447: Fix doclint warnings in java.awt.image
prr
parents: 5506
diff changeset
    60
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      int pixels[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *      MemoryImageSource source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *      public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *          int width = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *          int height = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *          int size = width * height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *          pixels = new int[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *          int value = getBackground().getRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *          for (int i = 0; i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *              pixels[i] = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *          source = new MemoryImageSource(width, height, pixels, 0, width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *          source.setAnimated(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *          image = createImage(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *      public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *          Thread me = Thread.currentThread( );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *          me.setPriority(Thread.MIN_PRIORITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *          while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *              try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *                  Thread.sleep(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *              } catch( InterruptedException e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *                  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *              // Modify the values in the pixels array at (x, y, w, h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *              // Send the new data to the interested ImageConsumers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *              source.newPixels(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
19169
1807a84c3d63 8022447: Fix doclint warnings in java.awt.image
prr
parents: 5506
diff changeset
    99
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * @see ImageProducer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @author      Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @author      Animation capabilities inspired by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *              MemoryAnimationSource class written by Garth Dickie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
public class MemoryImageSource implements ImageProducer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    ColorModel model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    Object pixels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    int pixeloffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    int pixelscan;
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   114
    Hashtable<?, ?> properties;
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   115
    Vector<ImageConsumer> theConsumers = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    boolean animating;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    boolean fullbuffers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Constructs an ImageProducer object which uses an array of bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * to produce data for an Image object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param w the width of the rectangle of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param h the height of the rectangle of pixels
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   124
     * @param cm the specified {@code ColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param pix an array of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param off the offset into the array of where to store the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *        first pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param scan the distance from one row of pixels to the next in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *        the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see java.awt.Component#createImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public MemoryImageSource(int w, int h, ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                             byte[] pix, int off, int scan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        initialize(w, h, cm, (Object) pix, off, scan, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Constructs an ImageProducer object which uses an array of bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * to produce data for an Image object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param w the width of the rectangle of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param h the height of the rectangle of pixels
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   142
     * @param cm the specified {@code ColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param pix an array of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param off the offset into the array of where to store the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *        first pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param scan the distance from one row of pixels to the next in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *        the array
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   148
     * @param props a list of properties that the {@code ImageProducer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *        uses to process an image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see java.awt.Component#createImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public MemoryImageSource(int w, int h, ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                             byte[] pix, int off, int scan,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                             Hashtable<?,?> props)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        initialize(w, h, cm, (Object) pix, off, scan, props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Constructs an ImageProducer object which uses an array of integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * to produce data for an Image object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param w the width of the rectangle of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param h the height of the rectangle of pixels
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   164
     * @param cm the specified {@code ColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param pix an array of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param off the offset into the array of where to store the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *        first pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param scan the distance from one row of pixels to the next in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *        the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see java.awt.Component#createImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public MemoryImageSource(int w, int h, ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                             int[] pix, int off, int scan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        initialize(w, h, cm, (Object) pix, off, scan, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Constructs an ImageProducer object which uses an array of integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * to produce data for an Image object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param w the width of the rectangle of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param h the height of the rectangle of pixels
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   182
     * @param cm the specified {@code ColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param pix an array of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param off the offset into the array of where to store the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *        first pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param scan the distance from one row of pixels to the next in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *        the array
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   188
     * @param props a list of properties that the {@code ImageProducer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *        uses to process an image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see java.awt.Component#createImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public MemoryImageSource(int w, int h, ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                             int[] pix, int off, int scan,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                             Hashtable<?,?> props)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        initialize(w, h, cm, (Object) pix, off, scan, props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private void initialize(int w, int h, ColorModel cm,
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   200
                            Object pix, int off, int scan, Hashtable<?,?> props) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        width = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        height = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        model = cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        pixels = pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        pixeloffset = off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        pixelscan = scan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (props == null) {
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   208
            props = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        properties = props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Constructs an ImageProducer object which uses an array of integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * in the default RGB ColorModel to produce data for an Image object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param w the width of the rectangle of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param h the height of the rectangle of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param pix an array of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param off the offset into the array of where to store the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *        first pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param scan the distance from one row of pixels to the next in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *        the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see java.awt.Component#createImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @see ColorModel#getRGBdefault
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   226
    public MemoryImageSource(int w, int h, int[] pix, int off, int scan) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        initialize(w, h, ColorModel.getRGBdefault(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                   (Object) pix, off, scan, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Constructs an ImageProducer object which uses an array of integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * in the default RGB ColorModel to produce data for an Image object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param w the width of the rectangle of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param h the height of the rectangle of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param pix an array of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param off the offset into the array of where to store the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *        first pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param scan the distance from one row of pixels to the next in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *        the array
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   241
     * @param props a list of properties that the {@code ImageProducer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *        uses to process an image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see java.awt.Component#createImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see ColorModel#getRGBdefault
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   246
    public MemoryImageSource(int w, int h, int[] pix, int off, int scan,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                             Hashtable<?,?> props)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        initialize(w, h, ColorModel.getRGBdefault(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                   (Object) pix, off, scan, props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Adds an ImageConsumer to the list of consumers interested in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * data for this image.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   256
     * @param ic the specified {@code ImageConsumer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @throws NullPointerException if the specified
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   258
     *           {@code ImageConsumer} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public synchronized void addConsumer(ImageConsumer ic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (theConsumers.contains(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        theConsumers.addElement(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            initConsumer(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            sendPixels(ic, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                ic.imageComplete(animating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                 ? ImageConsumer.SINGLEFRAMEDONE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                 : ImageConsumer.STATICIMAGEDONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                if (!animating && isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    ic.imageComplete(ImageConsumer.IMAGEERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    removeConsumer(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                ic.imageComplete(ImageConsumer.IMAGEERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Determines if an ImageConsumer is on the list of consumers currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * interested in data for this image.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   288
     * @param ic the specified {@code ImageConsumer}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   289
     * @return {@code true} if the {@code ImageConsumer}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   290
     * is on the list; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @see ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public synchronized boolean isConsumer(ImageConsumer ic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return theConsumers.contains(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Removes an ImageConsumer from the list of consumers interested in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * data for this image.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   300
     * @param ic the specified {@code ImageConsumer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public synchronized void removeConsumer(ImageConsumer ic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        theConsumers.removeElement(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Adds an ImageConsumer to the list of consumers interested in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * data for this image and immediately starts delivery of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * image data through the ImageConsumer interface.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   311
     * @param ic the specified {@code ImageConsumer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * image data through the ImageConsumer interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @see ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public void startProduction(ImageConsumer ic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        addConsumer(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Requests that a given ImageConsumer have the image data delivered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * one more time in top-down, left-right order.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   322
     * @param ic the specified {@code ImageConsumer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public void requestTopDownLeftRightResend(ImageConsumer ic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // Ignored.  The data is either single frame and already in TDLR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // format or it is multi-frame and TDLR resends aren't critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Changes this memory image into a multi-frame animation or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * single-frame static image depending on the animated parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <p>This method should be called immediately after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * MemoryImageSource is constructed and before an image is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * created with it to ensure that all ImageConsumers will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * receive the correct multi-frame data.  If an ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * is added to this ImageProducer before this flag is set then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * that ImageConsumer will see only a snapshot of the pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * data that was available when it connected.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   340
     * @param animated {@code true} if the image is a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *       multi-frame animation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public synchronized void setAnimated(boolean animated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        this.animating = animated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (!animating) {
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   346
            Enumeration<ImageConsumer> enum_ = theConsumers.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            while (enum_.hasMoreElements()) {
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   348
                ImageConsumer ic = enum_.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                if (isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    ic.imageComplete(ImageConsumer.IMAGEERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            theConsumers.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Specifies whether this animated memory image should always be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * updated by sending the complete buffer of pixels whenever
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * there is a change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * This flag is ignored if the animation flag is not turned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * through the setAnimated() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <p>This method should be called immediately after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * MemoryImageSource is constructed and before an image is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * created with it to ensure that all ImageConsumers will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * receive the correct pixel delivery hints.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   368
     * @param fullbuffers {@code true} if the complete pixel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *             buffer should always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see #setAnimated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public synchronized void setFullBufferUpdates(boolean fullbuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (this.fullbuffers == fullbuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        this.fullbuffers = fullbuffers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (animating) {
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   379
            Enumeration<ImageConsumer> enum_ = theConsumers.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            while (enum_.hasMoreElements()) {
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   381
                ImageConsumer ic = enum_.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                ic.setHints(fullbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                            ? (ImageConsumer.TOPDOWNLEFTRIGHT |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                               ImageConsumer.COMPLETESCANLINES)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                            : ImageConsumer.RANDOMPIXELORDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Sends a whole new buffer of pixels to any ImageConsumers that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * are currently interested in the data for this image and notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * them that an animation frame is complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * This method only has effect if the animation flag has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * turned on through the setAnimated() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @see #newPixels(int, int, int, int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @see #setAnimated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public void newPixels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        newPixels(0, 0, width, height, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Sends a rectangular region of the buffer of pixels to any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * ImageConsumers that are currently interested in the data for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * this image and notify them that an animation frame is complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * This method only has effect if the animation flag has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * turned on through the setAnimated() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * If the full buffer update flag was turned on with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * setFullBufferUpdates() method then the rectangle parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * will be ignored and the entire buffer will always be sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @param x the x coordinate of the upper left corner of the rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * of pixels to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param y the y coordinate of the upper left corner of the rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * of pixels to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @param w the width of the rectangle of pixels to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param h the height of the rectangle of pixels to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see #newPixels(int, int, int, int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @see ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see #setAnimated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @see #setFullBufferUpdates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public synchronized void newPixels(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        newPixels(x, y, w, h, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Sends a rectangular region of the buffer of pixels to any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * ImageConsumers that are currently interested in the data for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * If the framenotify parameter is true then the consumers are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * also notified that an animation frame is complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * This method only has effect if the animation flag has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * turned on through the setAnimated() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * If the full buffer update flag was turned on with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * setFullBufferUpdates() method then the rectangle parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * will be ignored and the entire buffer will always be sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @param x the x coordinate of the upper left corner of the rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * of pixels to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @param y the y coordinate of the upper left corner of the rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * of pixels to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @param w the width of the rectangle of pixels to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @param h the height of the rectangle of pixels to be sent
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   445
     * @param framenotify {@code true} if the consumers should be sent a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * {@link ImageConsumer#SINGLEFRAMEDONE SINGLEFRAMEDONE} notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @see ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see #setAnimated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @see #setFullBufferUpdates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public synchronized void newPixels(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                       boolean framenotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (animating) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (fullbuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                x = y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                w = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                h = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                if (x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    w += x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                if (x + w > width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    w = width - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                if (y < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    h += y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                if (y + h > height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    h = height - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if ((w <= 0 || h <= 0) && !framenotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   477
            Enumeration<ImageConsumer> enum_ = theConsumers.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            while (enum_.hasMoreElements()) {
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
   479
                ImageConsumer ic = enum_.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                if (w > 0 && h > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    sendPixels(ic, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                if (framenotify && isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * Changes to a new byte array to hold the pixels for this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * If the animation flag has been turned on through the setAnimated()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * method, then the new pixels will be immediately delivered to any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * ImageConsumers that are currently interested in the data for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @param newpix the new pixel array
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   497
     * @param newmodel the specified {@code ColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @param offset the offset into the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @param scansize the distance from one row of pixels to the next in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @see #newPixels(int, int, int, int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see #setAnimated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public synchronized void newPixels(byte[] newpix, ColorModel newmodel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                       int offset, int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        this.pixels = newpix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        this.model = newmodel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        this.pixeloffset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        this.pixelscan = scansize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        newPixels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * Changes to a new int array to hold the pixels for this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * If the animation flag has been turned on through the setAnimated()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * method, then the new pixels will be immediately delivered to any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * ImageConsumers that are currently interested in the data for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @param newpix the new pixel array
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   520
     * @param newmodel the specified {@code ColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @param offset the offset into the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @param scansize the distance from one row of pixels to the next in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @see #newPixels(int, int, int, int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @see #setAnimated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    public synchronized void newPixels(int[] newpix, ColorModel newmodel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                       int offset, int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        this.pixels = newpix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        this.model = newmodel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        this.pixeloffset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        this.pixelscan = scansize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        newPixels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    private void initConsumer(ImageConsumer ic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if (isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            ic.setDimensions(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        if (isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            ic.setProperties(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            ic.setColorModel(model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            ic.setHints(animating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        ? (fullbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                           ? (ImageConsumer.TOPDOWNLEFTRIGHT |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                              ImageConsumer.COMPLETESCANLINES)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                           : ImageConsumer.RANDOMPIXELORDER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                        : (ImageConsumer.TOPDOWNLEFTRIGHT |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                           ImageConsumer.COMPLETESCANLINES |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                           ImageConsumer.SINGLEPASS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                           ImageConsumer.SINGLEFRAME));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    private void sendPixels(ImageConsumer ic, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        int off = pixeloffset + pixelscan * y + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        if (isConsumer(ic)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            if (pixels instanceof byte[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                ic.setPixels(x, y, w, h, model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                             ((byte[]) pixels), off, pixelscan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                ic.setPixels(x, y, w, h, model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                             ((int[]) pixels), off, pixelscan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
}