home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Examples / c11 / inc / jpencomp.h < prev   
Encoding:
C/C++ Source or Header  |  1998-12-17  |  6.0 KB  |  188 lines

  1. #ifndef __JPENCOMP_H
  2. #define __JPENCOMP_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:  JpegEncoderComponent class definition
  17. //
  18. //  Author:  John M. Miano  miano@colosseumbuilders.com
  19. //
  20. //  Description:
  21. //
  22. //    This class represents a single component while writing a JPEG image.
  23. //
  24.  
  25. #include "bitimage.h"
  26.  
  27. #include "jpeg.h"
  28.  
  29. class JpegEncoder ;
  30. class JpegEncoderComponent ;
  31. class JpegEncoderHuffmanTable ;
  32. class JpegEncoderQuantizationTable ;
  33. class JpegEncoderCoefficientBlock ;
  34.  
  35. class JpegEncoderComponent
  36. {
  37. public:
  38.   JpegEncoderComponent () ;
  39.   virtual ~JpegEncoderComponent () ;
  40.  
  41.   void PrintAcData (int, int, int) ;
  42.   void PrintDcData (int, int) ;
  43.   void GatherAcData (int, int, int) ;
  44.   void GatherDcData (int, int) ;
  45.  
  46.   typedef void (JpegEncoderComponent::*DCOUTPUTFUNCTION) (int, int) ;
  47.   typedef void (JpegEncoderComponent::*ACOUTPUTFUNCTION) (int, int, int) ;
  48.   typedef void (JpegEncoderComponent::*COMPONENTPASSFUNCTION) (
  49.                             unsigned int row, unsigned int col,
  50.                             DCOUTPUTFUNCTION, ACOUTPUTFUNCTION,
  51.                             unsigned int sss, unsigned int sse,
  52.                             unsigned int ssa) ;
  53.   
  54.  
  55.   void EncodeSequential (unsigned int row, unsigned int col,
  56.                          DCOUTPUTFUNCTION dcfunction,
  57.                          ACOUTPUTFUNCTION acfunction,
  58.                          unsigned int, unsigned int, unsigned int) ;
  59.   void ProgressiveDcFirst (unsigned int row, unsigned int col,
  60.                            DCOUTPUTFUNCTION dcfunction, ACOUTPUTFUNCTION,
  61.                            unsigned int, unsigned int,
  62.                            unsigned int ssa) ;
  63.   void ProgressiveDcRefine (unsigned int row, unsigned int col,
  64.                             DCOUTPUTFUNCTION dcfunction, ACOUTPUTFUNCTION,
  65.                             unsigned int, unsigned int,
  66.                             unsigned int) ;
  67.   void ProgressiveAcFirst (unsigned int row, unsigned int col,
  68.                            ACOUTPUTFUNCTION acfunction,
  69.                            unsigned int sss, unsigned int sse,
  70.                            unsigned int ssa) ;
  71.   void ProgressiveAcRefine (unsigned int row, unsigned int col,
  72.                             ACOUTPUTFUNCTION acfunction,
  73.                             unsigned int sss, unsigned int sse,
  74.                             unsigned int ssa) ;
  75.  
  76.   void ResetEobRun () ;
  77.   void PrintEobRun (ACOUTPUTFUNCTION acfunction) ;
  78.   void PrintRefineEobRun (ACOUTPUTFUNCTION acfunction,
  79.                           unsigned int sss, unsigned int sse,
  80.                           unsigned int ssa) ;
  81.  
  82.   void SampleYComponent (JpegEncoder &encoder, const BitmapImage &, unsigned int maxhf, unsigned int maxvf) ;
  83.   void SampleCbComponent (JpegEncoder &encoder, const BitmapImage &, unsigned int maxhf, unsigned int maxvf) ;
  84.   void SampleCrComponent (JpegEncoder &encoder, const BitmapImage &, unsigned int maxhf, unsigned int maxvf) ;
  85.  
  86.   unsigned int GetHorizontalFrequency () const ;
  87.   void SetHorizontalFrequency (unsigned int) ;
  88.   unsigned int GetVerticalFrequency () const ;
  89.   void SetVerticalFrequency (unsigned int) ;
  90.  
  91.   unsigned int DataUnitRows () const ;
  92.   unsigned int DataUnitCols () const ;
  93.   void ResetDcDifference () ;
  94.  
  95.   void SetHuffmanTables (JpegEncoderHuffmanTable &dc,
  96.                          JpegEncoderHuffmanTable &ac) ;
  97.   void SetQuantizationTable (JpegEncoderQuantizationTable &table) ;
  98.  
  99.   void FreeDynamicStorage () ;
  100.  
  101. private:
  102.   JpegEncoderComponent (const JpegEncoderComponent &) ;
  103.   JpegEncoderComponent &operator=(const JpegEncoderComponent &) ;
  104.  
  105.   void CalculateDuDimensions (const BitmapImage &image, unsigned int maxhf, unsigned int maxvf) ;
  106.  
  107.   typedef JPEGSAMPLE (*RGBTOYCBCRFUNCTION)(
  108.                          JPEGSAMPLE red,
  109.                          JPEGSAMPLE green,
  110.                          JPEGSAMPLE blue) ;
  111.   void Sample1to1Component (const BitmapImage &, RGBTOYCBCRFUNCTION) ;
  112.   void SampleNtoNComponent (const BitmapImage &image,
  113.                             RGBTOYCBCRFUNCTION function) ;
  114.  
  115.   JpegEncoder *jpeg_encoder ;
  116.  
  117.   // DCT Coefficients and dimensions
  118.   unsigned int du_rows ;
  119.   unsigned int du_cols ;
  120.   JpegEncoderCoefficientBlock *dct_coefficients ;
  121.  
  122.   // EOB-run in context
  123.   unsigned int eob_run ;
  124.   unsigned int eob_start_du_row ;
  125.   unsigned int eob_start_du_col ;
  126.   unsigned int eob_start_position ;
  127.  
  128.   // Sampling Frequencies and p
  129.   unsigned int v_frequency ;
  130.   unsigned int h_frequency ;
  131.   unsigned int v_period ;
  132.   unsigned int h_period ;
  133.  
  134.   // Huffman and Quantization tables
  135.   JpegEncoderHuffmanTable *ac_table ;
  136.   JpegEncoderHuffmanTable *dc_table ;
  137.   JpegEncoderQuantizationTable *quantization_table ;
  138.  
  139.   // Last DC value used to calculate DC differences
  140.   int last_dc_value ;
  141.  
  142. } ;
  143.  
  144. inline unsigned int JpegEncoderComponent::GetHorizontalFrequency () const
  145. {
  146.   return h_frequency ;
  147. }
  148.  
  149. inline unsigned int JpegEncoderComponent::GetVerticalFrequency () const
  150. {
  151.   return v_frequency ;
  152. }
  153.  
  154. inline unsigned int JpegEncoderComponent::DataUnitRows () const
  155. {
  156.   return du_rows ;
  157. }
  158.  
  159. inline unsigned int JpegEncoderComponent::DataUnitCols () const
  160. {
  161.   return du_cols ;
  162. }
  163.  
  164. inline void JpegEncoderComponent::ResetDcDifference ()
  165. {
  166.   last_dc_value = 0 ;
  167.   return ;
  168. }
  169.  
  170. inline void JpegEncoderComponent::SetHuffmanTables (JpegEncoderHuffmanTable &dc,
  171.                                                     JpegEncoderHuffmanTable &ac)
  172. {
  173.   dc_table = &dc ;
  174.   ac_table = &ac ;
  175.   return ;
  176. }
  177.  
  178.  
  179. inline void JpegEncoderComponent::SetQuantizationTable (JpegEncoderQuantizationTable &table)
  180. {
  181.   quantization_table = &table ;
  182.   return ;
  183. }
  184.  
  185.  
  186. #endif
  187.  
  188.