1. /*
  2. * @(#)JPEGEncodeParam.java 1.4 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) 1997-1998 Eastman Kodak Company. ***
  14. *** As an unpublished work pursuant to Title 17 of the United ***
  15. *** States Code. All rights reserved. ***
  16. **********************************************************************
  17. **********************************************************************
  18. **********************************************************************/
  19. package com.sun.image.codec.jpeg;
  20. /**
  21. * JPEGEncodeParam encapsulates tables and options necessary to
  22. * control encoding of JPEG data streams. Parameters are either set
  23. * explicitly by the application for encoding, or read from another
  24. * JPEG header.<p>
  25. * When working with BufferedImages, the codec will attempt to match
  26. * the encoded JPEG COLOR_ID with the ColorModel in the BufferedImage.
  27. * This is not always possible (the default mappings are listed
  28. * below). In cases where unsupported conversions are required (or
  29. * odd image colorspaces are in use) the user must either convert the
  30. * image data to a known ColorSpace or encode the data from a raster.
  31. * When encoding rasters no colorspace adjustments are made, so the
  32. * user must do any conversions required to get to the encoded
  33. * COLOR_ID.
  34. * The COLOR_ID for the encoded images is used to control the JPEG
  35. * codec's inital values for Huffman and Quantization Tables as well
  36. * as subsampling factors. It is also used to determine what color
  37. * conversion should be performed to obtain the best encoding.<p>
  38. * Note: The color ids described herein are simply enumerated values
  39. * that influence data processing by the JPEG codec. JPEG compression
  40. * is, by definition, color blind. These values are used as hints when
  41. * compressing JPEG data. Through these values the JPEG codec can
  42. * perform some default rotation of data into spaces that will aid in
  43. * getting better compression ratios.<P>
  44. * Example behaviour is described below. Since these mappings are
  45. * likely to change in the future it is strongly recommended that you
  46. * make use of the @see JPEGImageEncoder.getDefaultParamBlock calls
  47. * and check the encodedColorID for your particular BufferedImage.
  48. * In extreme cases is may be necessary for the user to convert the
  49. * image to the desired colorspace, and encode it from a Raster. In
  50. * this case the API programmer must specify the colorID of the data
  51. * in the Raster and no color conversion will take place.
  52. <pre>
  53. ENCODING:
  54. BufferedImage Type/Instance JPEG (Encoded) Color ID
  55. ======================== =======================
  56. TYPE_GRAY COLOR_ID_GRAYSCALE
  57. TYPE_RGB COLOR_ID_YCbCr
  58. TYPE_YCbCr COLOR_ID_YCbCr
  59. TYPE_YCbCr/CS_PYCC COLOR_ID_PYCC
  60. TYPE_CMYK COLOR_ID_CMYK
  61. TYPE_RGB (w/ alpha) COLOR_ID_YCbCrA
  62. TYPE_YCbCr (w/ alpha) COLOR_ID_YCbCrA
  63. TYPE_YCbCr/CS_PYCC (w/ alpha) COLOR_ID_PYCCA
  64. ** Any Other ** COLOR_ID_UNKNOWN
  65. </pre>
  66. * When the user wants more control than the BufferedImage conversions
  67. * provide, the user must encode the data from a Raster. In this case
  68. * the data undergoes no color conversion at all. It is the user's
  69. * responsiblity to perform the desired conversions.<P>
  70. * If you intend to write a JFIF image (by including the APP0_MARKER)
  71. * the encoded COLOR_ID must be one of: COLOR_ID_UNKNOWN,
  72. * COLOR_ID_GRAYSCALE, COLOR_ID_YCbCr, or COLOR_ID_CMYK. In all other
  73. * instances an ImageformatException will be thrown.<P>
  74. * <B>IMPORTANT:</B> an Alpha RGB BufferedImage will not map to a
  75. * valid JFIF stream, you must strip off the alpha prior to encoding
  76. * if you want a JFIF file. If the APP0 marker is set and you do not
  77. * strip off the Alpha, an ImageFormatException will be thrown.
  78. * <p>
  79. * Note that the classes in the com.sun.image.codec.jpeg package are not
  80. * part of the core Java APIs. They are a part of Sun's JDK and JRE
  81. * distributions. Although other licensees may choose to distribute these
  82. * classes, developers cannot depend on their availability in non-Sun
  83. * implementations. We expect that equivalent functionality will eventually
  84. * be available in a core API or standard extension.
  85. * <p>
  86. */
  87. public interface JPEGEncodeParam
  88. extends Cloneable, JPEGDecodeParam
  89. {
  90. public Object clone();
  91. /**
  92. * Set the horizontal subsample factor for the given component.
  93. * Note that the subsample factor is the number of input pixels
  94. * that contribute to each output pixel (ussually 2 for YCC).
  95. * @param component The component being specified.
  96. * @param subsample The subsampling factor being specified.
  97. */
  98. public void setHorizontalSubsampling(int component,
  99. int subsample);
  100. /**
  101. * Set the vertical subsample factor for the given component. Note that
  102. * the subsample factor is the number of input pixels that
  103. * contribute to each output pixel (ussually 2 for YCC).
  104. * @param component The component being specified.
  105. * @param subsample The subsampling factor being specified.
  106. */
  107. public void setVerticalSubsampling(int component,
  108. int subsample);
  109. /**
  110. * Sets the coefficient quantization tables at index
  111. * passed. tableNum must range in value from 0 - 3.
  112. * @param qtable that will be used.
  113. * @param tableNum the index of the table to be set.
  114. */
  115. public void setQTable( int tableNum, JPEGQTable qTable );
  116. /** Sets the DC Huffman coding table at index to the table provided.
  117. * @param huffTable JPEGHuffmanTable that will be assigned
  118. * to index tableNum.
  119. * @param tableNum - the index of the table to be set.
  120. * @exception IllegalArgumentException - thrown if the tableNum
  121. * is out of range. Index must range in value from 0 - 3.
  122. */
  123. public void setDCHuffmanTable( int tableNum,
  124. JPEGHuffmanTable huffTable);
  125. /** Sets the AC Huffman coding table at index to the table provided.
  126. * @param huffTable JPEGHuffmanTable that will be assigned
  127. * to index tableNum.
  128. * @param tableNum - the index of the table to be set.
  129. * @exception IllegalArgumentException - thrown if the tableNum
  130. * is out of range. Index must range in value from 0 - 3.
  131. */
  132. public void setACHuffmanTable( int tableNum,
  133. JPEGHuffmanTable huffTable);
  134. /**
  135. * Sets the mapping between a component and it's DC Huffman Table.
  136. * @param component The component to set the mapping for
  137. * @param table The DC Huffman table to use for component
  138. */
  139. public void setDCHuffmanComponentMapping( int component, int table);
  140. /**
  141. * Sets the mapping between a component and it's AC Huffman Table.
  142. * @param component The component to set the mapping for
  143. * @param table The AC Huffman table to use for component
  144. */
  145. public void setACHuffmanComponentMapping( int component, int table);
  146. /**
  147. * Sets the mapping between a component and it's Quantization Table.
  148. * @param component The component to set the mapping for
  149. * @param table The Quantization Table to use for component
  150. */
  151. public void setQTableComponentMapping( int component, int table);
  152. /**
  153. * Set the flag indicating the validity of the table information
  154. * in the ParamBlock. This is used to indicate if tables should
  155. * be included when encoding.
  156. */
  157. public void setImageInfoValid(boolean flag);
  158. /**
  159. * Set the flag indicating the validity of the image information
  160. * in the ParamBlock. This is used to indicates if image data
  161. * should be written when encoding.
  162. */
  163. public void setTableInfoValid(boolean flag);
  164. /**
  165. * Sets the marker data to be written to the output data stream.
  166. * This removes any existing marker data in the JPEParm object.
  167. * This can be used to remove the default APP0 marker by calling
  168. * it with data set to null.
  169. * @param marker The marker to set the data for.
  170. * @param data the new set of data to be written.
  171. */
  172. public void setMarkerData(int marker, byte[][] data);
  173. /**
  174. * Appends 'data' to the array of byte[] associated with
  175. * marker. This will result in additional instance of the marker
  176. * being written (one for each byte[] in the array.).
  177. * @param marker The marker to add and instance of.
  178. * @param data the data to be written.
  179. */
  180. public void addMarkerData(int marker, byte []data);
  181. /**
  182. * Set the MCUs per restart, or 0 for no restart markers.
  183. * @param restartInterval number MCUs per restart marker.
  184. */
  185. public void setRestartInterval( int restartInterval );
  186. /**
  187. * Set the pixel size units This value is copied into the APP0
  188. * marker (if that marker is written). This value isn't used by
  189. * the JPEG code.
  190. * @param units One of the DENSITY_UNIT_* values.
  191. */
  192. public void setDensityUnit( int unit);
  193. /**
  194. * Set the horizontal pixel density This value is written into the
  195. * APP0 marker. It isn't used by the JPEG code.
  196. * @param desnity the horizontal pixel density, in units
  197. * described by @see JPEGParam.getDensityUnit.
  198. */
  199. public void setXDensity( int density );
  200. /**
  201. * Set the vertical pixel density. This value is copied into
  202. * the JFIF APP0 marker. It isn't used by the JPEG code.
  203. * @param density The verticle pixel density, in units
  204. * described by @see JPEGParam.getDensityUnit.
  205. */
  206. public void setYDensity( int density );
  207. /**
  208. * This creates new Quantization tables that replace the currently
  209. * installed Quantization tables. It also updates the Component
  210. * QTable mapping to the default for the current encoded COLOR_ID.
  211. * The Created Quantization table varies from very high
  212. * compression, very low quality, (0.0) to low compression, very
  213. * high quality (1.0) based on the quality parameter.<P>
  214. * At a quality level of 1.0 the table will be all 1's which will
  215. * lead to no loss of data due to quantization (however chrominace
  216. * subsampling, if used, and roundoff error in the DCT will still
  217. * degrade the image some what).<P>
  218. * This is a linear manipulation of the standard Chrominance
  219. * Q-Table.<P>
  220. * <pre>Some guidelines: 0.75 high quality
  221. * 0.5 medium quality
  222. * 0.25 low quality
  223. * </pre>
  224. * @param quality 0.0-1.0 setting of desired quality level.
  225. * @param forceBaseline force baseline quantization table
  226. */
  227. public void setQuality(float quality, boolean forceBaseline );
  228. }