home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Examples / c06 / src / huffdeco.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-20  |  1.0 KB  |  55 lines

  1. #include <fstream>
  2. #include "jpegdeco.h"
  3. #include "jpdehuff.h"
  4.  
  5. using namespace std ;
  6.  
  7. JpegHuffmanDecoder table ;
  8.  
  9. main (int argc, char *argv [])
  10. {
  11.   unsigned int bytes ;
  12.  
  13.   if (argc != 3)
  14.   {
  15.     cerr << "Usage: " << argv [0] << " input-file output-file" << endl ;
  16.     return 1 ;
  17.   }
  18.  
  19.   ifstream input ;
  20.   input.open (argv [1], ios::binary) ;
  21.   if (! input)
  22.   {
  23.     cerr << "Can't open input file" << endl ;
  24.     return 1 ;
  25.   }
  26.  
  27.   JpegDecoder decoder (input) ;
  28.   table.ReadTable (decoder) ;
  29.  
  30.   ofstream output ;
  31.   output.open (argv [2]) ;
  32.   if (! output)
  33.   {
  34.     cerr << "Can't open output file" << endl ;
  35.     return 1 ;
  36.   }
  37.  
  38.   UBYTE1 data = table.Decode (decoder) ;
  39.   bytes = 0 ;
  40.   while (! input.eof ())
  41.   {
  42.     ++ bytes ;
  43.     if (bytes % 1000 == 0)
  44.       cout << bytes << " Bytes\r" ;
  45.     output.write ((char *) &data, 1) ;
  46.     data = table.Decode (decoder) ;
  47.   }
  48.   cout << bytes << " bytes" << endl ;
  49.   output.write ((char *) &data, 1) ;
  50.  
  51.   input.close () ;
  52.   output.close () ;
  53.   return 0 ;
  54. }
  55.