1. /*
  2. * @(#)JPEGImageDecoder.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. * JPEGImageDecoder Interface
  19. *
  20. * JPEGImageDecoder decompresses an JPEG InputStream into a Raster or
  21. * a BufferedImage depending upon the method invoked. Decoding the
  22. * JPEG input stream is controlled by the parameters in the
  23. * JPEGDecodeParam object. If no JPEGDecodeParam object has been
  24. * specified then one is created to contain information about a
  25. * decompressed JPEG stream.<P>
  26. *
  27. * The JPEGDecodeParam object is updated with information from the
  28. * file header during decompression. If the input stream contains
  29. * tables only information (no image data), the JPEGDecodeParam object
  30. * will be updated and NULL returned for the output image. If the
  31. * input stream contains only image data, the parameters and tables in
  32. * the current JPEGDecodeParam object will be used to decode in
  33. * decoding the JPEG stream. If no tables are set in the
  34. * JPEGDecodeParam object, an exception will be thrown.<P>
  35. *
  36. * ColorSpace comments: First off JPEG by specification is color
  37. * blind! That said, some color space conversion is done in the name
  38. * of better compression ratios. If a BufferedImage is requested
  39. * common color conversions will be applied. Some updates to the
  40. * standard color space designations have been made to allow this
  41. * decoder to handle alpha channels. See the JPEGDecodeParam
  42. * description for more details on additional color space
  43. * designations ( @see JPEGDecodeParam ).<P>
  44. *
  45. * This decoder can process interchange, abbreviated and progressive
  46. * jpeg streams. However, progressive jpeg streams are treated as
  47. * interchange streams. They return once with the entire image in the
  48. * image buffer.
  49. */
  50. import java.io.InputStream;
  51. import java.io.IOException;
  52. import java.awt.Point;
  53. import java.awt.color.ColorSpace;
  54. import java.awt.image.BufferedImage;
  55. import java.awt.image.ColorModel;
  56. import java.awt.image.DirectColorModel;
  57. import java.awt.image.DataBuffer;
  58. import java.awt.image.DataBufferByte;
  59. import java.awt.image.DataBufferInt;
  60. import java.awt.image.Raster;
  61. import java.awt.image.SampleModel;
  62. import java.awt.image.WritableRaster;
  63. /**
  64. * This interface describes a JPEG data stream decoder. This decoder
  65. * takes an InputStream that contains JPEG encoded image data. The
  66. * JPEGImageDecoder will decode the JPEG image data according to the
  67. * parameters set in a JPEGDecodeParam object. The resulting image
  68. * data is returned in either a Raster or a BufferedImage.
  69. * <p>
  70. * Note that the classes in the com.sun.image.codec.jpeg package are not
  71. * part of the core Java APIs. They are a part of Sun's JDK and JRE
  72. * distributions. Although other licensees may choose to distribute these
  73. * classes, developers cannot depend on their availability in non-Sun
  74. * implementations. We expect that equivalent functionality will eventually
  75. * be available in a core API or standard extension.
  76. * <p>
  77. *
  78. * @see JPEGCodec
  79. * @see JPEGDecoderParam
  80. * @see Raster
  81. * @see BufferedImage
  82. * @version 4 December 1997
  83. */
  84. public interface JPEGImageDecoder {
  85. /**
  86. * Returns the JPEGDecodeParam object that resulted from the most
  87. * recent decoding event.
  88. */
  89. public JPEGDecodeParam getJPEGDecodeParam();
  90. /**
  91. * Sets the JPEGDecodeParam object used to determine the features
  92. * of the decompression performed on the JPEG encoded data. This
  93. * is ussually only needed for decoding abbreviated JPEG data
  94. * streams.
  95. * @param jdp JPEGDecodeParam object
  96. */
  97. public void setJPEGDecodeParam(JPEGDecodeParam jdp);
  98. /**
  99. * Get the input stream that decoding will occur from.
  100. * @return The stream that the decoder is currently assciated with.
  101. */
  102. public InputStream getInputStream();
  103. /**
  104. * Decode the JPEG stream that was passed as part of
  105. * construction. The JPEG decompression will be performed
  106. * according to the current settings of the JPEGDecodeParam
  107. * object. For a tables only stream this will return null.
  108. * @return Raster containg the image data. Colorspace and other
  109. * pertinent information can be obtained from the
  110. * JPEGDecodeParam object.
  111. * @exception ImageFormatException if irregularities in the JPEG
  112. * stream or an unknown condition is encountered.
  113. */
  114. public Raster decodeAsRaster()
  115. throws IOException, ImageFormatException;
  116. /**
  117. * Decodes the current JPEG data stream. The result of decoding
  118. * this InputStream is a BufferedImage the ColorModel associated
  119. * with this BufferedImage is determined based on the encoded
  120. * COLOR_ID of the JPEGDecodeParam object. For a tables only
  121. * stream this will return null.
  122. * @return BufferedImage containing the image data.
  123. * @exception ImageFormatException if irregularities in the JPEG
  124. * stream or an unknown condition is encountered.
  125. */
  126. public BufferedImage decodeAsBufferedImage()
  127. throws IOException, ImageFormatException;
  128. } // end class JPEGImageDecoder