home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Examples / c08 / inc / jpegdeco.h < prev   
Encoding:
C/C++ Source or Header  |  1998-12-23  |  4.6 KB  |  205 lines

  1. #ifndef __JPEGDECO_H
  2. #define __JPEGDECO_H
  3. //
  4. // Copyright (c) 1997,1998 Colosseum Builders, Inc.
  5. // All rights reserved.
  6. //
  7. // Colosseum Builders, Inc. makes no warranty, expressed or implied
  8. // with regards to this software. It is provided as is.
  9. //
  10. // See the README.TXT file that came with this software for restrictions
  11. // on the use and redistribution of this file or send E-mail to
  12. // info@colosseumbuilders.com
  13. //
  14.  
  15. //
  16. //  Title:  JPEG Decoder Class Implementation
  17. //
  18. //  Author:  John M. Miano  miano@colosseumbuilders.com
  19. //
  20.  
  21.  
  22. #include <iostream>
  23.  
  24. #include "datatype.h"
  25. #include "jpgexcep.h"
  26. #include "bitimage.h"
  27.  
  28. class JpegDecoderComponent ;
  29. class JpegHuffmanDecoder ;
  30. class JpegDecoderQuantizationTable ;
  31.  
  32.  
  33. class JpegDecoder : public BitmapImageDecoder
  34. {
  35. public:
  36.   JpegDecoder () ;
  37.   JpegDecoder (const JpegDecoder &) ;
  38.   virtual ~JpegDecoder () ;
  39.   JpegDecoder &operator=(const JpegDecoder &) ;
  40.  
  41.   virtual void ReadImage (std::istream &istrm, BitmapImage &image) ;
  42.   bool GetVerbose () const ;
  43.   void SetVerbose (bool) ;
  44.  
  45.   virtual void UpdateImage () ;
  46.  
  47. protected:
  48.   // While we don't expect classes to be derived from this one,
  49.   // we have placed the functions we expect friend classes to
  50.   // call here.
  51.  
  52.   UBYTE1 ReadByte () ;
  53.   UBYTE2 ReadWord () ;
  54.   int NextBit () ;
  55.   int Receive (unsigned int count) ;
  56.   unsigned int McuRows () const ;
  57.   unsigned int McuCols () const ;
  58.   unsigned int FrameHeight () const ;
  59.   unsigned int FrameWidth () const ;
  60.   unsigned int MaxVFrequency () const ;
  61.   unsigned int MaxHFrequency () const ;
  62.  
  63.   unsigned int RestartInterval () const ;
  64.  
  65. private:
  66.   void Initialize () ;
  67.   void DoCopy (const JpegDecoder &) ;
  68.   void CallProgressFunction (unsigned int progress) ;
  69.   void GetScanCount () ;
  70.  
  71.   void ReadStreamHeader () ;
  72.   void ReadMarker () ;
  73.   void ReadApplication (UBYTE1 type) ;
  74.   void ReadHuffmanTable () ;
  75.   void ReadQuantization () ;
  76.   void ReadRestartInterval () ;
  77.   void ReadStartOfFrame (UBYTE1 type) ;
  78.   void ReadStartOfScan () ;
  79.   void CalculateMcuDimensions ();
  80.   bool ScanIsInterleaved () const ;
  81.  
  82.   void FreeAllocatedResources () ;
  83.  
  84.   void ReadSequentialScanData () ;
  85.  
  86.   void ReadSequentialInterleavedScan () ;
  87.   void ReadSequentialNonInterleavedScan () ;
  88.   void ResetDcDifferences () ;
  89.   void ProcessRestartMarker () ;
  90.  
  91.   void RefineAcCoefficient (BYTE2 &value, unsigned int ssa) ;
  92.  
  93.   // Huffman tables
  94.   JpegHuffmanDecoder *ac_tables ;
  95.   JpegHuffmanDecoder *dc_tables ;
  96.  
  97.   // Quantization tables
  98.   JpegDecoderQuantizationTable *quantization_tables ;
  99.  
  100.   // Bit I/O state
  101.   int bit_position ;        // Called CNT in Section F.2.2.5
  102.   unsigned char bit_data ;  // Called B in Section F.2.2.5
  103.  
  104.   bool eoi_found ;
  105.   bool sof_found ;
  106.  
  107.   bool verbose_flag ;
  108.  
  109.   std::istream *input_stream ;
  110.  
  111.   unsigned int restart_interval ;
  112.  
  113.   unsigned int frame_width ;
  114.   unsigned int frame_height ;
  115.   unsigned int frame_type ;
  116.  
  117.   unsigned max_horizontal_frequency ;
  118.   unsigned max_vertical_frequency ;
  119.  
  120.   unsigned int component_count ;
  121.   JpegDecoderComponent *components ;
  122.   unsigned int *component_indices ;
  123.  
  124.   // Address of the image that is currently being processed.
  125.   BitmapImage *current_image ;
  126.  
  127.   // Progress Counters
  128.   unsigned int current_scan ;
  129.   unsigned int scan_count ;
  130.  
  131.   unsigned int mcu_rows ;
  132.   unsigned int mcu_cols ;
  133.  
  134.   unsigned int mcu_height ;
  135.   unsigned int mcu_width ;
  136.  
  137.   unsigned int scan_component_count ;
  138.   JpegDecoderComponent **scan_components ;
  139.  
  140.   unsigned int expected_restart ;
  141.  
  142.   bool strict_jfif ;
  143.  
  144.   friend class JpegDecoderQuantizationTable ;
  145.   friend class JpegHuffmanDecoder ;
  146.   friend class JpegDecoderComponent ;
  147. } ;
  148.  
  149.  
  150. inline unsigned int JpegDecoder::McuRows () const
  151. {
  152.   return mcu_rows ;
  153. }
  154.  
  155. inline unsigned int JpegDecoder::McuCols () const
  156. {
  157.   return mcu_cols ;
  158. }
  159.  
  160. inline unsigned int JpegDecoder::RestartInterval () const
  161. {
  162.   return restart_interval ;
  163. }
  164.  
  165. inline unsigned int JpegDecoder::FrameHeight () const
  166. {
  167.   return frame_height ;
  168. }
  169.  
  170. inline unsigned int JpegDecoder::FrameWidth () const
  171. {
  172.   return frame_width ;
  173. }
  174.  
  175. inline unsigned int JpegDecoder::MaxVFrequency () const
  176. {
  177.   return max_vertical_frequency ;
  178. }
  179.  
  180. inline unsigned int JpegDecoder::MaxHFrequency () const
  181. {
  182.   return max_horizontal_frequency ;
  183. }
  184.  
  185. inline bool JpegDecoder::ScanIsInterleaved () const
  186. {
  187.   if (scan_component_count != 1)
  188.     return true ;
  189.   else
  190.     return false ;
  191. }
  192.  
  193. inline bool JpegDecoder::GetVerbose () const
  194. {
  195.   return verbose_flag ;
  196. }
  197.  
  198. inline void JpegDecoder::SetVerbose (bool value)
  199. {
  200.   verbose_flag = value ;
  201.   return ;
  202. }
  203.  
  204. #endif
  205.