1. /*
  2. * @(#)JPEGDecodeParam.java 1.3 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) 1997-1998 Eastman Kodak Company. ***
  11. *** As an unpublished work pursuant to Title 17 of the United ***
  12. *** States Code. All rights reserved. ***
  13. **********************************************************************
  14. **********************************************************************
  15. **********************************************************************/
  16. package com.sun.image.codec.jpeg;
  17. /**
  18. * JPEGDecodeParam encapsulates tables and options necessary to
  19. * control decoding JPEG datastreams. Parameters are either set explicitly
  20. * by the application for encoding, or read from the JPEG header for
  21. * decoding. In the case of decoding abbreviated data streams the
  22. * application may need to set some/all of the values it's self. <p>
  23. * When working with BufferedImages (@see
  24. * JPEGImageDecoder.decodeBufferedImage), the codec will attempt to
  25. * generate an appropriate ColorModel for the JPEG COLOR_ID. This is
  26. * not always possible (example mappings are listed below) . In cases
  27. * where unsupported conversions are required, or unknown encoded
  28. * COLOR_ID's are in use, the user must request the data as a Raster
  29. * and perform the transformations themselves. When decoding into a
  30. * raster (@see JPEGImageDecoder.decodeRaster) no ColorSpace
  31. * adjustments are made.
  32. * Note: The color ids described herein are simply enumerated values
  33. * that influence data processing by the JPEG codec. JPEG compression
  34. * is by definition color blind. These values are used as hints when
  35. * decompressing JPEG data. Of particular interest is the default
  36. * conversion from YCbCr to sRGB when decoding buffered Images.<P>
  37. * Note: because JPEG is mostly color-blind color fidelity can not be
  38. * garunteed. This will hopefully be rectified in the near future by
  39. * the wide spread inclusion of ICC-profiles in the JPEG data stream
  40. * (as a special marker).
  41. * The following is an example of the conversions that take place.
  42. * This is only a guide to the types of conversions that are allowed.
  43. * This list is likely to change in the future so it is
  44. * <B>strongly</B> recommended that you check for thrown
  45. * ImageFormatExceptions and check the actual ColorModel associated
  46. * with the BufferedImage returned rather than make assumtions.
  47. * <pre>
  48. DECODING:
  49. JPEG (Encoded) Color ID BufferedImage ColorSpace
  50. ======================= ========================
  51. COLOR_ID_UNKNOWN ** Invalid **
  52. COLOR_ID_GRAY CS_GRAY
  53. COLOR_ID_RGB CS_sRGB
  54. COLOR_ID_YCbCr CS_sRGB
  55. COLOR_ID_CMYK ** Invalid **
  56. COLOR_ID_PYCC CS_PYCC
  57. COLOR_ID_RGBA CS_sRGB (w/ alpha)
  58. COLOR_ID_YCbCrA CS_sRGB (w/ alpha)
  59. COLOR_ID_RGBA_INVERTED ** Invalid **
  60. COLOR_ID_YCbCrA_INVERTED ** Invalid **
  61. COLOR_ID_PYCCA CS_PYCC (w/ alpha)
  62. COLOR_ID_YCCK ** Invalid **
  63. </pre>
  64. * If the user needs better control over conversion, the user must
  65. * request the data as a Raster and handle the conversion of the image
  66. * data themselves.<p>
  67. * When decoding JFIF files the encoded COLOR_ID will always be one
  68. * of: COLOR_ID_UNKNOWN, COLOR_ID_GRAY, COLOR_ID_RGB, COLOR_ID_YCbCr,
  69. * COLOR_ID_CMYK, or COLOR_ID_YCCK
  70. * <p>
  71. * Note that the classes in the com.sun.image.codec.jpeg package are not
  72. * part of the core Java APIs. They are a part of Sun's JDK and JRE
  73. * distributions. Although other licensees may choose to distribute these
  74. * classes, developers cannot depend on their availability in non-Sun
  75. * implementations. We expect that equivalent functionality will eventually
  76. * be available in a core API or standard extension.
  77. * <p>
  78. */
  79. public interface JPEGDecodeParam extends Cloneable {
  80. /** Unknown or Undefined Color ID */
  81. public final static int COLOR_ID_UNKNOWN = 0;
  82. /** Monochrome */
  83. public final static int COLOR_ID_GRAY = 1;
  84. /** Red, Green, and Blue */
  85. public final static int COLOR_ID_RGB = 2;
  86. /** YCbCr */
  87. public final static int COLOR_ID_YCbCr = 3;
  88. /** CMYK */
  89. public final static int COLOR_ID_CMYK = 4;
  90. /** PhotoYCC */
  91. public final static int COLOR_ID_PYCC = 5;
  92. /** RGB-Alpha */
  93. public final static int COLOR_ID_RGBA = 6;
  94. /** YCbCr-Alpha */
  95. public final static int COLOR_ID_YCbCrA = 7;
  96. /** RGB-Alpha with R, G, and B inverted.*/
  97. public final static int COLOR_ID_RGBA_INVERTED = 8;
  98. /** YCbCr-Alpha with Y, Cb, and Cr inverted.*/
  99. public final static int COLOR_ID_YCbCrA_INVERTED = 9;
  100. /** PhotoYCC-Alpha */
  101. public final static int COLOR_ID_PYCCA = 10;
  102. /** YCbCrK */
  103. public final static int COLOR_ID_YCCK = 11;
  104. /** Number of color ids defined. */
  105. final static int NUM_COLOR_ID = 12;
  106. /** Number of allowed Huffman and Quantization Tables */
  107. final static int NUM_TABLES = 4;
  108. /** The X and Y units simply indicate the aspect ratio of the pixels. */
  109. public final static int DENSITY_UNIT_ASPECT_RATIO = 0;
  110. /** Pixel density is in pixels per inch. */
  111. public final static int DENSITY_UNIT_DOTS_INCH = 1;
  112. /** Pixel density is in pixels per centemeter. */
  113. public final static int DENSITY_UNIT_DOTS_CM = 2;
  114. /** The max known value for DENSITY_UNIT */
  115. final static int NUM_DENSITY_UNIT = 3;
  116. /** APP0 marker - JFIF info */
  117. public final static int APP0_MARKER = 0xE0;
  118. /** APP1 marker */
  119. public final static int APP1_MARKER = 0xE1;
  120. /** APP2 marker */
  121. public final static int APP2_MARKER = 0xE2;
  122. /** APP3 marker */
  123. public final static int APP3_MARKER = 0xE3;
  124. /** APP4 marker */
  125. public final static int APP4_MARKER = 0xE4;
  126. /** APP5 marker */
  127. public final static int APP5_MARKER = 0xE5;
  128. /** APP6 marker */
  129. public final static int APP6_MARKER = 0xE6;
  130. /** APP7 marker */
  131. public final static int APP7_MARKER = 0xE7;
  132. /** APP8 marker */
  133. public final static int APP8_MARKER = 0xE8;
  134. /** APP9 marker */
  135. public final static int APP9_MARKER = 0xE9;
  136. /** APPA marker */
  137. public final static int APPA_MARKER = 0xEA;
  138. /** APPB marker */
  139. public final static int APPB_MARKER = 0xEB;
  140. /** APPC marker */
  141. public final static int APPC_MARKER = 0xEC;
  142. /** APPD marker */
  143. public final static int APPD_MARKER = 0xED;
  144. /** APPE marker - Adobe info */
  145. public final static int APPE_MARKER = 0xEE;
  146. /** APPF marker */
  147. public final static int APPF_MARKER = 0xEF;
  148. /** Adobe marker indicates presence/need for Adobe marker. */
  149. public final static int COMMENT_MARKER = 0XFE;
  150. public Object clone();
  151. /**
  152. * Get the image width
  153. * @return int the width of the image data in pixels.
  154. */
  155. public int getWidth();
  156. /** Get the image height
  157. * @return The height of the image data in pixels.
  158. */
  159. public int getHeight();
  160. /**
  161. * Return the Horizontal subsampling factor for requested
  162. * Component. The Subsample factor is the number of input pixels
  163. * that contribute to each output pixel. This is distinct from
  164. * the way the JPEG to each output pixel. This is distinct from
  165. * the way the JPEG standard defines this quantity, because
  166. * fractional subsampling factors are not allowed, and it was felt
  167. * @param component The component of the encoded image to return
  168. * the subsampling factor for.
  169. * @return The subsample factor.
  170. */
  171. public int getHorizontalSubsampling(int component);
  172. /**
  173. * Return the Vertical subsampling factor for requested
  174. * Component. The Subsample factor is the number of input pixels
  175. * that contribute to each output pixel. This is distinct from
  176. * the way the JPEG to each output pixel. This is distinct from
  177. * the way the JPEG standard defines this quantity, because
  178. * fractional subsampling factors are not allowed, and it was felt
  179. * @param component The component of the encoded image to return
  180. * the subsampling factor for.
  181. * @return The subsample factor.
  182. */
  183. public int getVerticalSubsampling(int component);
  184. /**
  185. * Returns the coefficient quantization tables or NULL if not
  186. * defined. tableNum must range in value from 0 - 3.
  187. * @param tableNum the index of the table to be returned.
  188. * @return Quantization table stored at index tableNum.
  189. */
  190. public JPEGQTable getQTable(int tableNum );
  191. /**
  192. * Returns the Quantization table for the requested component.
  193. * @param component the image component of interest.
  194. * @return Quantization table associated with component
  195. */
  196. public JPEGQTable getQTableForComponent(int component);
  197. /**
  198. * Returns the DC Huffman coding table requested or null if
  199. * not defined
  200. * @param tableNum the index of the table to be returned.
  201. * @return Huffman table stored at index tableNum.
  202. */
  203. public JPEGHuffmanTable getDCHuffmanTable( int tableNum );
  204. /**
  205. * Returns the DC Huffman coding table for the requested component.
  206. * @param component the image component of interest.
  207. * @return Huffman table associated with component
  208. */
  209. public JPEGHuffmanTable getDCHuffmanTableForComponent(int component);
  210. /**
  211. * Returns the AC Huffman coding table requested or null if
  212. * not defined
  213. * @param tableNum the index of the table to be returned.
  214. * @return Huffman table stored at index tableNum.
  215. */
  216. public JPEGHuffmanTable getACHuffmanTable( int tableNum );
  217. /**
  218. * Returns the AC Huffman coding table for the requested component.
  219. * @param component the image component of interest.
  220. * @return Huffman table associated with component
  221. */
  222. public JPEGHuffmanTable getACHuffmanTableForComponent(int component);
  223. /**
  224. * Get the number of the DC Huffman table that will be used for
  225. * a particular component.
  226. * @param component The Component of interest.
  227. * @return The table number of the DC Huffman table for component.
  228. */
  229. public int getDCHuffmanComponentMapping(int component);
  230. /**
  231. * Get the number of the AC Huffman table that will be used for
  232. * a particular component.
  233. * @param component The Component of interest.
  234. * @return The table number of the AC Huffman table for component.
  235. */
  236. public int getACHuffmanComponentMapping(int component);
  237. /**
  238. * Get the number of the quantization table that will be used for
  239. * a particular component.
  240. * @param component The Component of interest.
  241. * @return The table number of the Quantization table for component.
  242. */
  243. public int getQTableComponentMapping(int component);
  244. /**
  245. * Returns true if the image information in the ParamBlock is
  246. * currently valid. This indicates if image data was read from
  247. * the stream for decoding and weather image data should be
  248. * written when encoding.
  249. */
  250. public boolean isImageInfoValid();
  251. /**
  252. * Returns true if the tables in the ParamBlock are currently
  253. * valid. This indicates that tables were read from the stream
  254. * for decoding. When encoding this indicates wether tables should
  255. * be written to the stream.
  256. */
  257. public boolean isTableInfoValid();
  258. /**
  259. * Returns true if at least one instance of the marker is present
  260. * in the Parameter object. For encoding returns true if there
  261. * is at least one instance of the marker to be written.
  262. * @param marker The marker of interest.
  263. */
  264. public boolean getMarker(int marker);
  265. /**
  266. * Returns a 'byte[][]' associated with the requested marker in
  267. * the parameter object. Each entry in the 'byte[][]' is the data
  268. * associated with one instance of the marker (each marker can
  269. * theoretically appear any number of times in a stream).
  270. * @param marker The marker of interest.
  271. * @return The 'byte[][]' for this marker or null if none
  272. * available.
  273. */
  274. public byte[][] getMarkerData(int marker);
  275. /**
  276. * Returns the JPEG Encoded color id. This is generally
  277. * speaking only used if you are decoding into Rasters. Note
  278. * that when decoding into a Raster no color conversion is
  279. * performed.
  280. * @return The value of the JPEG encoded data's color id.
  281. */
  282. public int getEncodedColorID();
  283. /**
  284. * Returns the number of components for the current encoding
  285. * COLOR_ID.
  286. * @return the number of Components
  287. */
  288. public int getNumComponents();
  289. /**
  290. * Get the MCUs per restart marker.
  291. * @return The number of MCUs between restart markers.
  292. */
  293. public int getRestartInterval();
  294. /**
  295. * Get the code for pixel size units This value is copied from the
  296. * APP0 marker. It isn't used by the JPEG codec. If the APP0
  297. * marker wasn't present then you can not rely on this value.
  298. * @return Value indicating the density unit one of the
  299. * DENSITY_UNIT_* constants.
  300. */
  301. public int getDensityUnit();
  302. /**
  303. * Get the horizontal pixel density This value is copied from the
  304. * APP0 marker. It isn't used by the JPEG code. If the APP0
  305. * marker wasn't present then you can not rely on this value.
  306. * @return The horizontal pixel density, in units described by
  307. * @see JPEGDecodeParam.getDensityUnit.
  308. */
  309. public int getXDensity();
  310. /**
  311. * Get the vertical pixel density This value is copied into the
  312. * APP0 marker. It isn't used by the JPEG code. If the APP0 marker
  313. * wasn't present then you can not rely on this value.
  314. * @return The verticle pixel density, in units described by
  315. * @see JPEGDecodeParam.getDensityUnit.
  316. */
  317. public int getYDensity();
  318. }