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