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