home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Examples / c09 / inc / jpencomp.h < prev   
Encoding:
C/C++ Source or Header  |  1998-12-23  |  4.8 KB  |  166 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.  
  60.   void SampleYComponent (JpegEncoder &encoder, const BitmapImage &, unsigned int maxhf, unsigned int maxvf) ;
  61.   void SampleCbComponent (JpegEncoder &encoder, const BitmapImage &, unsigned int maxhf, unsigned int maxvf) ;
  62.   void SampleCrComponent (JpegEncoder &encoder, const BitmapImage &, unsigned int maxhf, unsigned int maxvf) ;
  63.  
  64.   unsigned int GetHorizontalFrequency () const ;
  65.   void SetHorizontalFrequency (unsigned int) ;
  66.   unsigned int GetVerticalFrequency () const ;
  67.   void SetVerticalFrequency (unsigned int) ;
  68.  
  69.   unsigned int DataUnitRows () const ;
  70.   unsigned int DataUnitCols () const ;
  71.   void ResetDcDifference () ;
  72.  
  73.   void SetHuffmanTables (JpegEncoderHuffmanTable &dc,
  74.                          JpegEncoderHuffmanTable &ac) ;
  75.   void SetQuantizationTable (JpegEncoderQuantizationTable &table) ;
  76.  
  77.   void FreeDynamicStorage () ;
  78.  
  79. private:
  80.   JpegEncoderComponent (const JpegEncoderComponent &) ;
  81.   JpegEncoderComponent &operator=(const JpegEncoderComponent &) ;
  82.  
  83.   void CalculateDuDimensions (const BitmapImage &image, unsigned int maxhf, unsigned int maxvf) ;
  84.  
  85.   typedef JPEGSAMPLE (*RGBTOYCBCRFUNCTION)(
  86.                          JPEGSAMPLE red,
  87.                          JPEGSAMPLE green,
  88.                          JPEGSAMPLE blue) ;
  89.   void Sample1to1Component (const BitmapImage &, RGBTOYCBCRFUNCTION) ;
  90.   void SampleNtoNComponent (const BitmapImage &image,
  91.                             RGBTOYCBCRFUNCTION function) ;
  92.  
  93.   JpegEncoder *jpeg_encoder ;
  94.  
  95.   // DCT Coefficients and dimensions
  96.   unsigned int du_rows ;
  97.   unsigned int du_cols ;
  98.   JpegEncoderCoefficientBlock *dct_coefficients ;
  99.  
  100.   // EOB-run in context
  101.   unsigned int eob_run ;
  102.   unsigned int eob_start_du_row ;
  103.   unsigned int eob_start_du_col ;
  104.   unsigned int eob_start_position ;
  105.  
  106.   // Sampling Frequencies and p
  107.   unsigned int v_frequency ;
  108.   unsigned int h_frequency ;
  109.   unsigned int v_period ;
  110.   unsigned int h_period ;
  111.  
  112.   // Huffman and Quantization tables
  113.   JpegEncoderHuffmanTable *ac_table ;
  114.   JpegEncoderHuffmanTable *dc_table ;
  115.   JpegEncoderQuantizationTable *quantization_table ;
  116.  
  117.   // Last DC value used to calculate DC differences
  118.   int last_dc_value ;
  119.  
  120. } ;
  121.  
  122. inline unsigned int JpegEncoderComponent::GetHorizontalFrequency () const
  123. {
  124.   return h_frequency ;
  125. }
  126.  
  127. inline unsigned int JpegEncoderComponent::GetVerticalFrequency () const
  128. {
  129.   return v_frequency ;
  130. }
  131.  
  132. inline unsigned int JpegEncoderComponent::DataUnitRows () const
  133. {
  134.   return du_rows ;
  135. }
  136.  
  137. inline unsigned int JpegEncoderComponent::DataUnitCols () const
  138. {
  139.   return du_cols ;
  140. }
  141.  
  142. inline void JpegEncoderComponent::ResetDcDifference ()
  143. {
  144.   last_dc_value = 0 ;
  145.   return ;
  146. }
  147.  
  148. inline void JpegEncoderComponent::SetHuffmanTables (JpegEncoderHuffmanTable &dc,
  149.                                                     JpegEncoderHuffmanTable &ac)
  150. {
  151.   dc_table = &dc ;
  152.   ac_table = &ac ;
  153.   return ;
  154. }
  155.  
  156.  
  157. inline void JpegEncoderComponent::SetQuantizationTable (JpegEncoderQuantizationTable &table)
  158. {
  159.   quantization_table = &table ;
  160.   return ;
  161. }
  162.  
  163.  
  164. #endif
  165.  
  166.