2362N/A * Copyright (c) 1995, 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class is an implementation of the ImageProducer interface which 0N/A * uses an array to produce pixel values for an Image. Here is an example 0N/A * which calculates a 100x100 image representing a fade from black to blue 0N/A * along the X axis and a fade from black to red along the Y axis: 0N/A * int pix[] = new int[w * h]; 0N/A * for (int y = 0; y < h; y++) { 0N/A * int red = (y * 255) / (h - 1); 0N/A * for (int x = 0; x < w; x++) { 0N/A * int blue = (x * 255) / (w - 1); 0N/A * pix[index++] = (255 << 24) | (red << 16) | blue; 0N/A * Image img = createImage(new MemoryImageSource(w, h, pix, 0, w)); 0N/A * The MemoryImageSource is also capable of managing a memory image which 0N/A * varies over time to allow animation or custom rendering. Here is an 0N/A * example showing how to set up the animation source and signal changes 0N/A * in the data (adapted from the MemoryAnimationSourceDemo by Garth Dickie): 0N/A * MemoryImageSource source; 0N/A * public void init() { 0N/A * int size = width * height; 0N/A * pixels = new int[size]; 0N/A * int value = getBackground().getRGB(); 0N/A * for (int i = 0; i < size; i++) { 0N/A * pixels[i] = value; 0N/A * source = new MemoryImageSource(width, height, pixels, 0, width); 0N/A * source.setAnimated(true); 0N/A * image = createImage(source); 0N/A * public void run() { 0N/A * Thread me = Thread.currentThread( ); 0N/A * me.setPriority(Thread.MIN_PRIORITY); 0N/A * } catch( InterruptedException e ) { 0N/A * // Modify the values in the pixels array at (x, y, w, h) 0N/A * // Send the new data to the interested ImageConsumers 0N/A * source.newPixels(x, y, w, h); 0N/A * @see ImageProducer 0N/A * @author Jim Graham 0N/A * @author Animation capabilities inspired by the 0N/A * MemoryAnimationSource class written by Garth Dickie 0N/A * Constructs an ImageProducer object which uses an array of bytes 0N/A * to produce data for an Image object. 0N/A * @param w the width of the rectangle of pixels 0N/A * @param h the height of the rectangle of pixels 0N/A * @param cm the specified <code>ColorModel</code> 0N/A * @param pix an array of pixels 0N/A * @param off the offset into the array of where to store the 0N/A * @param scan the distance from one row of pixels to the next in 0N/A * @see java.awt.Component#createImage 0N/A * Constructs an ImageProducer object which uses an array of bytes 0N/A * to produce data for an Image object. 0N/A * @param w the width of the rectangle of pixels 0N/A * @param h the height of the rectangle of pixels 0N/A * @param cm the specified <code>ColorModel</code> 0N/A * @param pix an array of pixels 0N/A * @param off the offset into the array of where to store the 0N/A * @param scan the distance from one row of pixels to the next in 0N/A * @param props a list of properties that the <code>ImageProducer</code> 0N/A * uses to process an image 0N/A * @see java.awt.Component#createImage 0N/A * Constructs an ImageProducer object which uses an array of integers 0N/A * to produce data for an Image object. 0N/A * @param w the width of the rectangle of pixels 0N/A * @param h the height of the rectangle of pixels 0N/A * @param cm the specified <code>ColorModel</code> 0N/A * @param pix an array of pixels 0N/A * @param off the offset into the array of where to store the 0N/A * @param scan the distance from one row of pixels to the next in 0N/A * @see java.awt.Component#createImage 0N/A * Constructs an ImageProducer object which uses an array of integers 0N/A * to produce data for an Image object. 0N/A * @param w the width of the rectangle of pixels 0N/A * @param h the height of the rectangle of pixels 0N/A * @param cm the specified <code>ColorModel</code> 0N/A * @param pix an array of pixels 0N/A * @param off the offset into the array of where to store the 0N/A * @param scan the distance from one row of pixels to the next in 0N/A * @param props a list of properties that the <code>ImageProducer</code> 0N/A * uses to process an image 0N/A * @see java.awt.Component#createImage 0N/A * Constructs an ImageProducer object which uses an array of integers 0N/A * in the default RGB ColorModel to produce data for an Image object. 0N/A * @param w the width of the rectangle of pixels 0N/A * @param h the height of the rectangle of pixels 0N/A * @param pix an array of pixels 0N/A * @param off the offset into the array of where to store the 0N/A * @param scan the distance from one row of pixels to the next in 0N/A * @see java.awt.Component#createImage 0N/A * @see ColorModel#getRGBdefault 0N/A * Constructs an ImageProducer object which uses an array of integers 0N/A * in the default RGB ColorModel to produce data for an Image object. 0N/A * @param w the width of the rectangle of pixels 0N/A * @param h the height of the rectangle of pixels 0N/A * @param pix an array of pixels 0N/A * @param off the offset into the array of where to store the 0N/A * @param scan the distance from one row of pixels to the next in 0N/A * @param props a list of properties that the <code>ImageProducer</code> 0N/A * uses to process an image 0N/A * @see java.awt.Component#createImage 0N/A * @see ColorModel#getRGBdefault 0N/A * Adds an ImageConsumer to the list of consumers interested in 0N/A * data for this image. 0N/A * @param ic the specified <code>ImageConsumer</code> 0N/A * @throws NullPointerException if the specified 0N/A * <code>ImageConsumer</code> is null 0N/A * @see ImageConsumer 0N/A * Determines if an ImageConsumer is on the list of consumers currently 0N/A * interested in data for this image. 0N/A * @param ic the specified <code>ImageConsumer</code> 0N/A * @return <code>true</code> if the <code>ImageConsumer</code> 0N/A * is on the list; <code>false</code> otherwise. 0N/A * @see ImageConsumer 0N/A * Removes an ImageConsumer from the list of consumers interested in 0N/A * data for this image. 0N/A * @param ic the specified <code>ImageConsumer</code> 0N/A * @see ImageConsumer 0N/A * Adds an ImageConsumer to the list of consumers interested in 0N/A * data for this image and immediately starts delivery of the 0N/A * image data through the ImageConsumer interface. 0N/A * @param ic the specified <code>ImageConsumer</code> 0N/A * image data through the ImageConsumer interface. 0N/A * @see ImageConsumer 0N/A * Requests that a given ImageConsumer have the image data delivered 0N/A * one more time in top-down, left-right order. 0N/A * @param ic the specified <code>ImageConsumer</code> 0N/A * @see ImageConsumer 0N/A // Ignored. The data is either single frame and already in TDLR 0N/A // format or it is multi-frame and TDLR resends aren't critical. 0N/A * Changes this memory image into a multi-frame animation or a 0N/A * single-frame static image depending on the animated parameter. 0N/A * <p>This method should be called immediately after the 0N/A * MemoryImageSource is constructed and before an image is 0N/A * created with it to ensure that all ImageConsumers will 0N/A * receive the correct multi-frame data. If an ImageConsumer 0N/A * is added to this ImageProducer before this flag is set then 0N/A * that ImageConsumer will see only a snapshot of the pixel 0N/A * data that was available when it connected. 0N/A * @param animated <code>true</code> if the image is a 0N/A * multi-frame animation 0N/A * Specifies whether this animated memory image should always be 0N/A * updated by sending the complete buffer of pixels whenever 0N/A * there is a change. 0N/A * This flag is ignored if the animation flag is not turned on 0N/A * through the setAnimated() method. 0N/A * <p>This method should be called immediately after the 0N/A * MemoryImageSource is constructed and before an image is 0N/A * created with it to ensure that all ImageConsumers will 0N/A * receive the correct pixel delivery hints. 0N/A * @param fullbuffers <code>true</code> if the complete pixel 0N/A * buffer should always 0N/A * Sends a whole new buffer of pixels to any ImageConsumers that 0N/A * are currently interested in the data for this image and notify 0N/A * them that an animation frame is complete. 0N/A * This method only has effect if the animation flag has been 0N/A * turned on through the setAnimated() method. 0N/A * @see #newPixels(int, int, int, int, boolean) 0N/A * @see ImageConsumer 0N/A * Sends a rectangular region of the buffer of pixels to any 0N/A * ImageConsumers that are currently interested in the data for 0N/A * this image and notify them that an animation frame is complete. 0N/A * This method only has effect if the animation flag has been 0N/A * turned on through the setAnimated() method. 0N/A * If the full buffer update flag was turned on with the 0N/A * setFullBufferUpdates() method then the rectangle parameters 0N/A * will be ignored and the entire buffer will always be sent. 0N/A * @param x the x coordinate of the upper left corner of the rectangle 0N/A * of pixels to be sent 0N/A * @param y the y coordinate of the upper left corner of the rectangle 0N/A * of pixels to be sent 0N/A * @param w the width of the rectangle of pixels to be sent 0N/A * @param h the height of the rectangle of pixels to be sent 0N/A * @see #newPixels(int, int, int, int, boolean) 0N/A * @see ImageConsumer 0N/A * @see #setFullBufferUpdates 0N/A public synchronized void newPixels(
int x,
int y,
int w,
int h) {
0N/A * Sends a rectangular region of the buffer of pixels to any 0N/A * ImageConsumers that are currently interested in the data for 0N/A * If the framenotify parameter is true then the consumers are 0N/A * also notified that an animation frame is complete. 0N/A * This method only has effect if the animation flag has been 0N/A * turned on through the setAnimated() method. 0N/A * If the full buffer update flag was turned on with the 0N/A * setFullBufferUpdates() method then the rectangle parameters 0N/A * will be ignored and the entire buffer will always be sent. 0N/A * @param x the x coordinate of the upper left corner of the rectangle 0N/A * of pixels to be sent 0N/A * @param y the y coordinate of the upper left corner of the rectangle 0N/A * of pixels to be sent 0N/A * @param w the width of the rectangle of pixels to be sent 0N/A * @param h the height of the rectangle of pixels to be sent 0N/A * @param framenotify <code>true</code> if the consumers should be sent a 0N/A * {@link ImageConsumer#SINGLEFRAMEDONE SINGLEFRAMEDONE} notification 0N/A * @see ImageConsumer 0N/A * @see #setFullBufferUpdates 0N/A public synchronized void newPixels(
int x,
int y,
int w,
int h,
0N/A if (w >
0 && h >
0) {
0N/A * Changes to a new byte array to hold the pixels for this image. 0N/A * If the animation flag has been turned on through the setAnimated() 0N/A * method, then the new pixels will be immediately delivered to any 0N/A * ImageConsumers that are currently interested in the data for 0N/A * @param newpix the new pixel array 0N/A * @param newmodel the specified <code>ColorModel</code> 0N/A * @param offset the offset into the array 0N/A * @param scansize the distance from one row of pixels to the next in 0N/A * @see #newPixels(int, int, int, int, boolean) 0N/A * Changes to a new int array to hold the pixels for this image. 0N/A * If the animation flag has been turned on through the setAnimated() 0N/A * method, then the new pixels will be immediately delivered to any 0N/A * ImageConsumers that are currently interested in the data for 0N/A * @param newpix the new pixel array 0N/A * @param newmodel the specified <code>ColorModel</code> 0N/A * @param offset the offset into the array 0N/A * @param scansize the distance from one row of pixels to the next in 0N/A * @see #newPixels(int, int, int, int, boolean)