home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Library / include / jpenhuff.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-17  |  2.8 KB  |  90 lines

  1. #ifndef __JPENHUFF_H
  2. #define __JPENHUFF_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:  JpegEncoderHuffmanTable class definition
  17. //
  18. //  Author:  John M. Miano  miano@colosseumbuilders.com
  19. //
  20. //  Description:
  21. //
  22. //    This class represents a Huffman Table used for compression
  23. //    by the JpegEncoder class.
  24. //
  25.  
  26. #include "jpeg.h"
  27.  
  28. class JpegEncoder ;
  29.  
  30. class JpegEncoderHuffmanTable
  31. {
  32. public:
  33.   JpegEncoderHuffmanTable () ;
  34.   virtual ~JpegEncoderHuffmanTable () {}
  35.  
  36.   // ENCODING FUNCTIONS
  37.  
  38.   // This function resets the table so that the object can be used
  39.   // over again.
  40.   void Reset () ;
  41.  
  42.   // This function increases the frequency for a huffman value.
  43.   void IncrementFrequency (unsigned int value) ;
  44.  
  45.   // This function creates the Huffman codes from the code frequencies.
  46.   void BuildTable () ;
  47.  
  48.   // This function returns the Huffman code and code length to encode the
  49.   // specified value.
  50.   void Encode (unsigned int value, UBYTE2 &code, UBYTE1 &size) const ;
  51.  
  52.   // Returns the number of bytes required to write the table to the output
  53.   // file.
  54.   unsigned int OutputSize () const ;
  55.  
  56.   // Function to print the table definition to the output stream.
  57.   void PrintTable (JpegEncoder &encoder) const ;
  58.  
  59. private:
  60.   JpegEncoderHuffmanTable (const JpegEncoderHuffmanTable &) ;
  61.   JpegEncoderHuffmanTable &operator=(const JpegEncoderHuffmanTable &) ;
  62.  
  63.   // This function builds the structures needed for Huffman
  64.   // decoding after the table data has been read.
  65.   void MakeTable () ;
  66.  
  67.   // frequencies [n] is the number of times the value "n" needs to
  68.   // be encoded.
  69.   unsigned int frequencies [JpegMaxNumberOfHuffmanCodes + 1] ;
  70.  
  71.   // Values used to represent Huffman tables in a JPEG stream
  72.   //  huff_bits [n] is the number of codes of length "n+1"
  73.   //  huff_values is the list of Huffman values sorted in order
  74.   //   of code length.
  75.   UBYTE1 huff_bits [2 * JpegMaxHuffmanCodeLength] ; // 2x needed for encoding only.
  76.   UBYTE1 huff_values [JpegMaxNumberOfHuffmanCodes] ;
  77.  
  78.   // Values used to encode values.
  79.   //   ehufsi [n] is the number of bits required to code "n"
  80.   //   ehufco [n] is the Huffman code for "n"
  81.   UBYTE1 ehufsi [JpegMaxNumberOfHuffmanCodes+ 1] ;
  82.   UBYTE2 ehufco [JpegMaxNumberOfHuffmanCodes+1] ;
  83.  
  84.   // The flag is set to true when the Huffman code sizes has been determined.
  85.   // It is cleared when the object is Reset().
  86.   bool sizes_found ;
  87. } ;
  88.  
  89. #endif
  90.