home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Examples / c11 / inc / jpegdeco.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-17  |  5.2 KB  |  221 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.   bool IsProgressive () const ;
  57.   unsigned int McuRows () const ;
  58.   unsigned int McuCols () const ;
  59.   unsigned int FrameHeight () const ;
  60.   unsigned int FrameWidth () const ;
  61.   unsigned int MaxVFrequency () const ;
  62.   unsigned int MaxHFrequency () const ;
  63.  
  64.   unsigned int RestartInterval () const ;
  65.  
  66. private:
  67.   void Initialize () ;
  68.   void DoCopy (const JpegDecoder &) ;
  69.   void CallProgressFunction (unsigned int progress) ;
  70.   void GetScanCount () ;
  71.  
  72.   void ReadStreamHeader () ;
  73.   void ReadMarker () ;
  74.   void ReadApplication (UBYTE1 type) ;
  75.   void ReadHuffmanTable () ;
  76.   void ReadQuantization () ;
  77.   void ReadRestartInterval () ;
  78.   void ReadStartOfFrame (UBYTE1 type) ;
  79.   void ReadStartOfScan () ;
  80.   void CalculateMcuDimensions ();
  81.   bool ScanIsInterleaved () const ;
  82.  
  83.   void ReadProgressiveScanData (unsigned int sss, unsigned int sse,
  84.                                 unsigned int sah, unsigned int sal) ;
  85.   void ReadDcFirst (unsigned int ssa) ;
  86.   void ReadDcRefine (unsigned int ssa) ;
  87.   void ReadAcFirst (unsigned int sss, unsigned int sse, unsigned int ssa) ;
  88.   void ReadAcRefine (unsigned int sss,
  89.                      unsigned int sse,
  90.                      unsigned int ssa) ;
  91.   void FreeAllocatedResources () ;
  92.  
  93.   void ReadSequentialScanData () ;
  94.  
  95.   void ReadSequentialInterleavedScan () ;
  96.   void ReadSequentialNonInterleavedScan () ;
  97.   void ResetDcDifferences () ;
  98.   void ProcessRestartMarker () ;
  99.  
  100.   void RefineAcCoefficient (BYTE2 &value, unsigned int ssa) ;
  101.  
  102.   // Huffman tables
  103.   JpegHuffmanDecoder *ac_tables ;
  104.   JpegHuffmanDecoder *dc_tables ;
  105.  
  106.   // Quantization tables
  107.   JpegDecoderQuantizationTable *quantization_tables ;
  108.  
  109.   // Bit I/O state
  110.   int bit_position ;        // Called CNT in Section F.2.2.5
  111.   unsigned char bit_data ;  // Called B in Section F.2.2.5
  112.  
  113.   bool eoi_found ;
  114.   bool sof_found ;
  115.  
  116.   bool verbose_flag ;
  117.  
  118.   std::istream *input_stream ;
  119.  
  120.   unsigned int restart_interval ;
  121.  
  122.   unsigned int frame_width ;
  123.   unsigned int frame_height ;
  124.   unsigned int frame_type ;
  125.  
  126.   unsigned max_horizontal_frequency ;
  127.   unsigned max_vertical_frequency ;
  128.  
  129.   bool progressive_frame ;
  130.  
  131.   unsigned int component_count ;
  132.   JpegDecoderComponent *components ;
  133.   unsigned int *component_indices ;
  134.  
  135.   // Address of the image that is currently being processed.
  136.   BitmapImage *current_image ;
  137.  
  138.   // Progress Counters
  139.   unsigned int current_scan ;
  140.   unsigned int scan_count ;
  141.  
  142.   unsigned int mcu_rows ;
  143.   unsigned int mcu_cols ;
  144.  
  145.   unsigned int mcu_height ;
  146.   unsigned int mcu_width ;
  147.  
  148.   unsigned int scan_component_count ;
  149.   JpegDecoderComponent **scan_components ;
  150.  
  151.   unsigned int expected_restart ;
  152.  
  153.   bool strict_jfif ;
  154.  
  155.   friend class JpegDecoderQuantizationTable ;
  156.   friend class JpegHuffmanDecoder ;
  157.   friend class JpegDecoderComponent ;
  158. } ;
  159.  
  160.  
  161. inline bool JpegDecoder::IsProgressive () const
  162. {
  163.   return progressive_frame ;
  164. }
  165.  
  166. inline unsigned int JpegDecoder::McuRows () const
  167. {
  168.   return mcu_rows ;
  169. }
  170.  
  171. inline unsigned int JpegDecoder::McuCols () const
  172. {
  173.   return mcu_cols ;
  174. }
  175.  
  176. inline unsigned int JpegDecoder::RestartInterval () const
  177. {
  178.   return restart_interval ;
  179. }
  180.  
  181. inline unsigned int JpegDecoder::FrameHeight () const
  182. {
  183.   return frame_height ;
  184. }
  185.  
  186. inline unsigned int JpegDecoder::FrameWidth () const
  187. {
  188.   return frame_width ;
  189. }
  190.  
  191. inline unsigned int JpegDecoder::MaxVFrequency () const
  192. {
  193.   return max_vertical_frequency ;
  194. }
  195.  
  196. inline unsigned int JpegDecoder::MaxHFrequency () const
  197. {
  198.   return max_horizontal_frequency ;
  199. }
  200.  
  201. inline bool JpegDecoder::ScanIsInterleaved () const
  202. {
  203.   if (scan_component_count != 1)
  204.     return true ;
  205.   else
  206.     return false ;
  207. }
  208.  
  209. inline bool JpegDecoder::GetVerbose () const
  210. {
  211.   return verbose_flag ;
  212. }
  213.  
  214. inline void JpegDecoder::SetVerbose (bool value)
  215. {
  216.   verbose_flag = value ;
  217.   return ;
  218. }
  219.  
  220. #endif
  221.