1 /*
   2  * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt.image;
  27 
  28 import java.util.Hashtable;
  29 
  30 import javax.tools.annotation.GenerateNativeHeader;
  31 
  32 /**
  33  * The interface for objects expressing interest in image data through
  34  * the ImageProducer interfaces.  When a consumer is added to an image
  35  * producer, the producer delivers all of the data about the image
  36  * using the method calls defined in this interface.
  37  *
  38  * @see ImageProducer
  39  *
  40  * @author      Jim Graham
  41  */
  42 /* No native methods here, but the constants are needed in the supporting JNI code */
  43 @GenerateNativeHeader
  44 public interface ImageConsumer {
  45     /**
  46      * The dimensions of the source image are reported using the
  47      * setDimensions method call.
  48      * @param width the width of the source image
  49      * @param height the height of the source image
  50      */
  51     void setDimensions(int width, int height);
  52 
  53     /**
  54      * Sets the extensible list of properties associated with this image.
  55      * @param props the list of properties to be associated with this
  56      *        image
  57      */
  58     void setProperties(Hashtable<?,?> props);
  59 
  60     /**
  61      * Sets the ColorModel object used for the majority of
  62      * the pixels reported using the setPixels method
  63      * calls.  Note that each set of pixels delivered using setPixels
  64      * contains its own ColorModel object, so no assumption should
  65      * be made that this model will be the only one used in delivering
  66      * pixel values.  A notable case where multiple ColorModel objects
  67      * may be seen is a filtered image when for each set of pixels
  68      * that it filters, the filter
  69      * determines  whether the
  70      * pixels can be sent on untouched, using the original ColorModel,
  71      * or whether the pixels should be modified (filtered) and passed
  72      * on using a ColorModel more convenient for the filtering process.
  73      * @param model the specified <code>ColorModel</code>
  74      * @see ColorModel
  75      */
  76     void setColorModel(ColorModel model);
  77 
  78     /**
  79      * Sets the hints that the ImageConsumer uses to process the
  80      * pixels delivered by the ImageProducer.
  81      * The ImageProducer can deliver the pixels in any order, but
  82      * the ImageConsumer may be able to scale or convert the pixels
  83      * to the destination ColorModel more efficiently or with higher
  84      * quality if it knows some information about how the pixels will
  85      * be delivered up front.  The setHints method should be called
  86      * before any calls to any of the setPixels methods with a bit mask
  87      * of hints about the manner in which the pixels will be delivered.
  88      * If the ImageProducer does not follow the guidelines for the
  89      * indicated hint, the results are undefined.
  90      * @param hintflags a set of hints that the ImageConsumer uses to
  91      *        process the pixels
  92      */
  93     void setHints(int hintflags);
  94 
  95     /**
  96      * The pixels will be delivered in a random order.  This tells the
  97      * ImageConsumer not to use any optimizations that depend on the
  98      * order of pixel delivery, which should be the default assumption
  99      * in the absence of any call to the setHints method.
 100      * @see #setHints
 101      */
 102     int RANDOMPIXELORDER = 1;
 103 
 104     /**
 105      * The pixels will be delivered in top-down, left-to-right order.
 106      * @see #setHints
 107      */
 108     int TOPDOWNLEFTRIGHT = 2;
 109 
 110     /**
 111      * The pixels will be delivered in (multiples of) complete scanlines
 112      * at a time.
 113      * @see #setHints
 114      */
 115     int COMPLETESCANLINES = 4;
 116 
 117     /**
 118      * The pixels will be delivered in a single pass.  Each pixel will
 119      * appear in only one call to any of the setPixels methods.  An
 120      * example of an image format which does not meet this criterion
 121      * is a progressive JPEG image which defines pixels in multiple
 122      * passes, each more refined than the previous.
 123      * @see #setHints
 124      */
 125     int SINGLEPASS = 8;
 126 
 127     /**
 128      * The image contain a single static image.  The pixels will be defined
 129      * in calls to the setPixels methods and then the imageComplete method
 130      * will be called with the STATICIMAGEDONE flag after which no more
 131      * image data will be delivered.  An example of an image type which
 132      * would not meet these criteria would be the output of a video feed,
 133      * or the representation of a 3D rendering being manipulated
 134      * by the user.  The end of each frame in those types of images will
 135      * be indicated by calling imageComplete with the SINGLEFRAMEDONE flag.
 136      * @see #setHints
 137      * @see #imageComplete
 138      */
 139     int SINGLEFRAME = 16;
 140 
 141     /**
 142      * Delivers the pixels of the image with one or more calls
 143      * to this method.  Each call specifies the location and
 144      * size of the rectangle of source pixels that are contained in
 145      * the array of pixels.  The specified ColorModel object should
 146      * be used to convert the pixels into their corresponding color
 147      * and alpha components.  Pixel (m,n) is stored in the pixels array
 148      * at index (n * scansize + m + off).  The pixels delivered using
 149      * this method are all stored as bytes.
 150      * @param x the X coordinate of the upper-left corner of the
 151      *        area of pixels to be set
 152      * @param y the Y coordinate of the upper-left corner of the
 153      *        area of pixels to be set
 154      * @param w the width of the area of pixels
 155      * @param h the height of the area of pixels
 156      * @param model the specified <code>ColorModel</code>
 157      * @param pixels the array of pixels
 158      * @param off the offset into the <code>pixels</code> array
 159      * @param scansize the distance from one row of pixels to the next in
 160      * the <code>pixels</code> array
 161      * @see ColorModel
 162      */
 163     void setPixels(int x, int y, int w, int h,
 164                    ColorModel model, byte pixels[], int off, int scansize);
 165 
 166     /**
 167      * The pixels of the image are delivered using one or more calls
 168      * to the setPixels method.  Each call specifies the location and
 169      * size of the rectangle of source pixels that are contained in
 170      * the array of pixels.  The specified ColorModel object should
 171      * be used to convert the pixels into their corresponding color
 172      * and alpha components.  Pixel (m,n) is stored in the pixels array
 173      * at index (n * scansize + m + off).  The pixels delivered using
 174      * this method are all stored as ints.
 175      * this method are all stored as ints.
 176      * @param x the X coordinate of the upper-left corner of the
 177      *        area of pixels to be set
 178      * @param y the Y coordinate of the upper-left corner of the
 179      *        area of pixels to be set
 180      * @param w the width of the area of pixels
 181      * @param h the height of the area of pixels
 182      * @param model the specified <code>ColorModel</code>
 183      * @param pixels the array of pixels
 184      * @param off the offset into the <code>pixels</code> array
 185      * @param scansize the distance from one row of pixels to the next in
 186      * the <code>pixels</code> array
 187      * @see ColorModel
 188      */
 189     void setPixels(int x, int y, int w, int h,
 190                    ColorModel model, int pixels[], int off, int scansize);
 191 
 192     /**
 193      * The imageComplete method is called when the ImageProducer is
 194      * finished delivering all of the pixels that the source image
 195      * contains, or when a single frame of a multi-frame animation has
 196      * been completed, or when an error in loading or producing the
 197      * image has occured.  The ImageConsumer should remove itself from the
 198      * list of consumers registered with the ImageProducer at this time,
 199      * unless it is interested in successive frames.
 200      * @param status the status of image loading
 201      * @see ImageProducer#removeConsumer
 202      */
 203     void imageComplete(int status);
 204 
 205     /**
 206      * An error was encountered while producing the image.
 207      * @see #imageComplete
 208      */
 209     int IMAGEERROR = 1;
 210 
 211     /**
 212      * One frame of the image is complete but there are more frames
 213      * to be delivered.
 214      * @see #imageComplete
 215      */
 216     int SINGLEFRAMEDONE = 2;
 217 
 218     /**
 219      * The image is complete and there are no more pixels or frames
 220      * to be delivered.
 221      * @see #imageComplete
 222      */
 223     int STATICIMAGEDONE = 3;
 224 
 225     /**
 226      * The image creation process was deliberately aborted.
 227      * @see #imageComplete
 228      */
 229     int IMAGEABORTED = 4;
 230 }