1. /*
  2. * @(#)RenderableImage.java 1.9 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. /* ********************************************************************
  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. /** Returns a list of names recognized by getProperty. */
  70. String[] getPropertyNames();
  71. /**
  72. * Returns true if successive renderings (that is, calls to
  73. * createRendering() or createScaledRendering()) with the same arguments
  74. * may produce different results. This method may be used to
  75. * determine whether an existing rendering may be cached and
  76. * reused. It is always safe to return true.
  77. */
  78. boolean isDynamic();
  79. /**
  80. * Gets the width in user coordinate space. By convention, the
  81. * usual width of a RenderableImage is equal to the image's aspect
  82. * ratio (width divided by height).
  83. *
  84. * @return the width of the image in user coordinates.
  85. */
  86. float getWidth();
  87. /**
  88. * Gets the height in user coordinate space. By convention, the
  89. * usual height of a RenderedImage is equal to 1.0F.
  90. *
  91. * @return the height of the image in user coordinates.
  92. */
  93. float getHeight();
  94. /**
  95. * Gets the minimum X coordinate of the rendering-independent image data.
  96. */
  97. float getMinX();
  98. /**
  99. * Gets the minimum Y coordinate of the rendering-independent image data.
  100. */
  101. float getMinY();
  102. /**
  103. * Creates a RenderedImage instance of this image with width w, and
  104. * height h in pixels. The RenderContext is built automatically
  105. * with an appropriate usr2dev transform and an area of interest
  106. * of the full image. All the rendering hints come from hints
  107. * passed in.
  108. *
  109. * <p> If w == 0, it will be taken to equal
  110. * Math.round(h*(getWidth()/getHeight())).
  111. * Similarly, if h == 0, it will be taken to equal
  112. * Math.round(w*(getHeight()/getWidth())). One of
  113. * w or h must be non-zero or else an IllegalArgumentException
  114. * will be thrown.
  115. *
  116. * <p> The created RenderedImage may have a property identified
  117. * by the String HINTS_OBSERVED to indicate which RenderingHints
  118. * were used to create the image. In addition any RenderedImages
  119. * that are obtained via the getSources() method on the created
  120. * RenderedImage may have such a property.
  121. *
  122. * @param w the width of rendered image in pixels, or 0.
  123. * @param h the height of rendered image in pixels, or 0.
  124. * @param hints a RenderingHints object containg hints.
  125. * @return a RenderedImage containing the rendered data.
  126. */
  127. RenderedImage createScaledRendering(int w, int h, RenderingHints hints);
  128. /**
  129. * Returnd a RenderedImage instance of this image with a default
  130. * width and height in pixels. The RenderContext is built
  131. * automatically with an appropriate usr2dev transform and an area
  132. * of interest of the full image. The rendering hints are
  133. * empty. createDefaultRendering may make use of a stored
  134. * rendering for speed.
  135. *
  136. * @return a RenderedImage containing the rendered data.
  137. */
  138. RenderedImage createDefaultRendering();
  139. /**
  140. * Creates a RenderedImage that represented a rendering of this image
  141. * using a given RenderContext. This is the most general way to obtain a
  142. * rendering of a RenderableImage.
  143. *
  144. * <p> The created RenderedImage may have a property identified
  145. * by the String HINTS_OBSERVED to indicate which RenderingHints
  146. * (from the RenderContext) were used to create the image.
  147. * In addition any RenderedImages
  148. * that are obtained via the getSources() method on the created
  149. * RenderedImage may have such a property.
  150. *
  151. * @param renderContext the RenderContext to use to produce the rendering.
  152. * @return a RenderedImage containing the rendered data.
  153. */
  154. RenderedImage createRendering(RenderContext renderContext);
  155. }