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