1. /*
  2. * @(#)ImageConsumer.java 1.16 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt.image;
  8. import java.util.Hashtable;
  9. /**
  10. * The interface for objects expressing interest in image data through
  11. * the ImageProducer interfaces. When a consumer is added to an image
  12. * producer, the producer delivers all of the data about the image
  13. * using the method calls defined in this interface.
  14. *
  15. * @see ImageProducer
  16. *
  17. * @version 1.16 11/29/01
  18. * @author Jim Graham
  19. */
  20. public interface ImageConsumer {
  21. /**
  22. * The dimensions of the source image are reported using the
  23. * setDimensions method call.
  24. */
  25. void setDimensions(int width, int height);
  26. /**
  27. * Sets the extensible list of properties associated with this image.
  28. */
  29. void setProperties(Hashtable props);
  30. /**
  31. * The ColorModel object used for the majority of
  32. * the pixels reported using the setPixels method
  33. * calls. Note that each set of pixels delivered using setPixels
  34. * contains its own ColorModel object, so no assumption should
  35. * be made that this model will be the only one used in delivering
  36. * pixel values. A notable case where multiple ColorModel objects
  37. * may be seen is a filtered image when for each set of pixels
  38. * that it filters, the filter
  39. * determines whether the
  40. * pixels can be sent on untouched, using the original ColorModel,
  41. * or whether the pixels should be modified (filtered) and passed
  42. * on using a ColorModel more convenient for the filtering process.
  43. * @see ColorModel
  44. */
  45. void setColorModel(ColorModel model);
  46. /**
  47. * The ImageProducer can deliver the pixels in any order, but
  48. * the ImageConsumer may be able to scale or convert the pixels
  49. * to the destination ColorModel more efficiently or with higher
  50. * quality if it knows some information about how the pixels will
  51. * be delivered up front. The setHints method should be called
  52. * before any calls to any of the setPixels methods with a bit mask
  53. * of hints about the manner in which the pixels will be delivered.
  54. * If the ImageProducer does not follow the guidelines for the
  55. * indicated hint, the results are undefined.
  56. */
  57. void setHints(int hintflags);
  58. /**
  59. * The pixels will be delivered in a random order. This tells the
  60. * ImageConsumer not to use any optimizations that depend on the
  61. * order of pixel delivery, which should be the default assumption
  62. * in the absence of any call to the setHints method.
  63. * @see #setHints
  64. */
  65. int RANDOMPIXELORDER = 1;
  66. /**
  67. * The pixels will be delivered in top-down, left-to-right order.
  68. * @see #setHints
  69. */
  70. int TOPDOWNLEFTRIGHT = 2;
  71. /**
  72. * The pixels will be delivered in (multiples of) complete scanlines
  73. * at a time.
  74. * @see #setHints
  75. */
  76. int COMPLETESCANLINES = 4;
  77. /**
  78. * The pixels will be delivered in a single pass. Each pixel will
  79. * appear in only one call to any of the setPixels methods. An
  80. * example of an image format which does not meet this criterion
  81. * is a progressive JPEG image which defines pixels in multiple
  82. * passes, each more refined than the previous.
  83. * @see #setHints
  84. */
  85. int SINGLEPASS = 8;
  86. /**
  87. * The image contain a single static image. The pixels will be defined
  88. * in calls to the setPixels methods and then the imageComplete method
  89. * will be called with the STATICIMAGEDONE flag after which no more
  90. * image data will be delivered. An example of an image type which
  91. * would not meet these criteria would be the output of a video feed,
  92. * or the representation of a 3D rendering being manipulated
  93. * by the user. The end of each frame in those types of images will
  94. * be indicated by calling imageComplete with the SINGLEFRAMEDONE flag.
  95. * @see #setHints
  96. * @see #imageComplete
  97. */
  98. int SINGLEFRAME = 16;
  99. /**
  100. * The pixels of the image are delivered using one or more calls
  101. * to the setPixels method. Each call specifies the location and
  102. * size of the rectangle of source pixels that are contained in
  103. * the array of pixels. The specified ColorModel object should
  104. * be used to convert the pixels into their corresponding color
  105. * and alpha components. Pixel (m,n) is stored in the pixels array
  106. * at index (n * scansize + m + off). The pixels delivered using
  107. * this method are all stored as bytes.
  108. * @see ColorModel
  109. */
  110. void setPixels(int x, int y, int w, int h,
  111. ColorModel model, byte pixels[], int off, int scansize);
  112. /**
  113. * The pixels of the image are delivered using one or more calls
  114. * to the setPixels method. Each call specifies the location and
  115. * size of the rectangle of source pixels that are contained in
  116. * the array of pixels. The specified ColorModel object should
  117. * be used to convert the pixels into their corresponding color
  118. * and alpha components. Pixel (m,n) is stored in the pixels array
  119. * at index (n * scansize + m + off). The pixels delivered using
  120. * this method are all stored as ints.
  121. * @see ColorModel
  122. */
  123. void setPixels(int x, int y, int w, int h,
  124. ColorModel model, int pixels[], int off, int scansize);
  125. /**
  126. * The imageComplete method is called when the ImageProducer is
  127. * finished delivering all of the pixels that the source image
  128. * contains, or when a single frame of a multi-frame animation has
  129. * been completed, or when an error in loading or producing the
  130. * image has occured. The ImageConsumer should remove itself from the
  131. * list of consumers registered with the ImageProducer at this time,
  132. * unless it is interested in successive frames.
  133. * @see ImageProducer#removeConsumer
  134. */
  135. void imageComplete(int status);
  136. /**
  137. * An error was encountered while producing the image.
  138. * @see #imageComplete
  139. */
  140. int IMAGEERROR = 1;
  141. /**
  142. * One frame of the image is complete but there are more frames
  143. * to be delivered.
  144. * @see #imageComplete
  145. */
  146. int SINGLEFRAMEDONE = 2;
  147. /**
  148. * The image is complete and there are no more pixels or frames
  149. * to be delivered.
  150. * @see #imageComplete
  151. */
  152. int STATICIMAGEDONE = 3;
  153. /**
  154. * The image creation process was deliberately aborted.
  155. * @see #imageComplete
  156. */
  157. int IMAGEABORTED = 4;
  158. }