1. /*
  2. * @(#)RenderableImage.java 1.13 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /* ********************************************************************
  8. **********************************************************************
  9. **********************************************************************
  10. *** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
  11. *** As an unpublished work pursuant to Title 17 of the United ***
  12. *** States Code. All rights reserved. ***
  13. **********************************************************************
  14. **********************************************************************
  15. **********************************************************************/
  16. package java.awt.image.renderable;
  17. import java.util.Vector;
  18. import java.awt.RenderingHints;
  19. import java.awt.image.*;
  20. /**
  21. * A RenderableImage is a common interface for rendering-independent
  22. * images (a notion which subsumes resolution independence). That is,
  23. * images which are described and have operations applied to them
  24. * independent of any specific rendering of the image. For example, a
  25. * RenderableImage can be rotated and cropped in
  26. * resolution-independent terms. Then, it can be rendered for various
  27. * specific contexts, such as a draft preview, a high-quality screen
  28. * display, or a printer, each in an optimal fashion.
  29. *
  30. * <p> A RenderedImage is returned from a RenderableImage via the
  31. * createRendering() method, which takes a RenderContext. The
  32. * RenderContext specifies how the RenderedImage should be
  33. * constructed. Note that it is not possible to extract pixels
  34. * directly from a RenderableImage.
  35. *
  36. * <p> The createDefaultRendering() and createScaledRendering() methods are
  37. * convenience methods that construct an appropriate RenderContext
  38. * internally. All of the rendering methods may return a reference to a
  39. * previously produced rendering.
  40. */
  41. public interface RenderableImage {
  42. /**
  43. * String constant that can be used to identify a property on
  44. * a RenderedImage obtained via the createRendering or
  45. * createScaledRendering methods. If such a property exists,
  46. * the value of the propoery will be a RenderingHints object
  47. * specifying which hints were observed in creating the rendering.
  48. */
  49. static final String HINTS_OBSERVED = "HINTS_OBSERVED";
  50. /**
  51. * Returns a vector of RenderableImages that are the sources of
  52. * image data for this RenderableImage. Note that this method may
  53. * return an empty vector, to indicate that the image has no sources,
  54. * or null, to indicate that no information is available.
  55. *
  56. * @return a (possibly empty) Vector of RenderableImages, or null.
  57. */
  58. Vector getSources();
  59. /**
  60. * Gets a property from the property set of this image.
  61. * If the property name is not recognized, java.awt.Image.UndefinedProperty
  62. * will be returned.
  63. *
  64. * @param name the name of the property to get, as a String.
  65. * @return a reference to the property Object, or the value
  66. * java.awt.Image.UndefinedProperty.
  67. */
  68. Object getProperty(String name);
  69. /**
  70. * Returns a list of names recognized by getProperty.
  71. * @return a list of property names.
  72. */
  73. String[] getPropertyNames();
  74. /**
  75. * Returns true if successive renderings (that is, calls to
  76. * createRendering() or createScaledRendering()) with the same arguments
  77. * may produce different results. This method may be used to
  78. * determine whether an existing rendering may be cached and
  79. * reused. It is always safe to return true.
  80. * @return <code>true</code> if successive renderings with the
  81. * same arguments might produce different results;
  82. * <code>false</code> otherwise.
  83. */
  84. boolean isDynamic();
  85. /**
  86. * Gets the width in user coordinate space. By convention, the
  87. * usual width of a RenderableImage is equal to the image's aspect
  88. * ratio (width divided by height).
  89. *
  90. * @return the width of the image in user coordinates.
  91. */
  92. float getWidth();
  93. /**
  94. * Gets the height in user coordinate space. By convention, the
  95. * usual height of a RenderedImage is equal to 1.0F.
  96. *
  97. * @return the height of the image in user coordinates.
  98. */
  99. float getHeight();
  100. /**
  101. * Gets the minimum X coordinate of the rendering-independent image data.
  102. * @return the minimum X coordinate of the rendering-independent image
  103. * data.
  104. */
  105. float getMinX();
  106. /**
  107. * Gets the minimum Y coordinate of the rendering-independent image data.
  108. * @return the minimum Y coordinate of the rendering-independent image
  109. * data.
  110. */
  111. float getMinY();
  112. /**
  113. * Creates a RenderedImage instance of this image with width w, and
  114. * height h in pixels. The RenderContext is built automatically
  115. * with an appropriate usr2dev transform and an area of interest
  116. * of the full image. All the rendering hints come from hints
  117. * passed in.
  118. *
  119. * <p> If w == 0, it will be taken to equal
  120. * Math.round(h*(getWidth()/getHeight())).
  121. * Similarly, if h == 0, it will be taken to equal
  122. * Math.round(w*(getHeight()/getWidth())). One of
  123. * w or h must be non-zero or else an IllegalArgumentException
  124. * will be thrown.
  125. *
  126. * <p> The created RenderedImage may have a property identified
  127. * by the String HINTS_OBSERVED to indicate which RenderingHints
  128. * were used to create the image. In addition any RenderedImages
  129. * that are obtained via the getSources() method on the created
  130. * RenderedImage may have such a property.
  131. *
  132. * @param w the width of rendered image in pixels, or 0.
  133. * @param h the height of rendered image in pixels, or 0.
  134. * @param hints a RenderingHints object containg hints.
  135. * @return a RenderedImage containing the rendered data.
  136. */
  137. RenderedImage createScaledRendering(int w, int h, RenderingHints hints);
  138. /**
  139. * Returnd a RenderedImage instance of this image with a default
  140. * width and height in pixels. The RenderContext is built
  141. * automatically with an appropriate usr2dev transform and an area
  142. * of interest of the full image. The rendering hints are
  143. * empty. createDefaultRendering may make use of a stored
  144. * rendering for speed.
  145. *
  146. * @return a RenderedImage containing the rendered data.
  147. */
  148. RenderedImage createDefaultRendering();
  149. /**
  150. * Creates a RenderedImage that represented a rendering of this image
  151. * using a given RenderContext. This is the most general way to obtain a
  152. * rendering of a RenderableImage.
  153. *
  154. * <p> The created RenderedImage may have a property identified
  155. * by the String HINTS_OBSERVED to indicate which RenderingHints
  156. * (from the RenderContext) were used to create the image.
  157. * In addition any RenderedImages
  158. * that are obtained via the getSources() method on the created
  159. * RenderedImage may have such a property.
  160. *
  161. * @param renderContext the RenderContext to use to produce the rendering.
  162. * @return a RenderedImage containing the rendered data.
  163. */
  164. RenderedImage createRendering(RenderContext renderContext);
  165. }