home *** CD-ROM | disk | FTP | other *** search
- #include <fstream>
- #include <stdexcept>
-
- using namespace std ;
-
- #include "jpegenco.h"
- #include "jpenhuff.h"
-
- JpegEncoderHuffmanTable table ;
-
- main (int argc, char *argv [])
- {
- unsigned long bytes ;
-
- if (argc != 3)
- {
- cerr << "Usage: " << argv [0] << " input-file output-file" << endl ;
- return 1 ;
- }
-
- ifstream input ;
- input.open (argv [1]) ;
- if (! input)
- {
- cerr << "Can't open input file" << endl ;
- return 1 ;
- }
-
- unsigned char data ;
- input.read ((char*) &data, 1) ;
- bytes = 0 ;
- while (! input.eof ())
- {
- ++ bytes ;
- if (bytes % 1000 == 0)
- cout << bytes << '\r' ;
- table.IncrementFrequency (data) ;
- input.read ((char*) &data, 1) ;
- }
- cout << "Pass One: " << bytes << " bytes" << endl ;
- table.BuildTable () ;
- input.clear () ;
- input.seekg (0) ;
-
- ofstream output ;
- output.open (argv [2], ios::binary) ;
- if (! output)
- {
- cerr << "Can't open output file" << endl ;
- return 1 ;
- }
-
- JpegEncoder encoder (output) ;
-
- table.PrintTable (encoder) ;
- input.read ((char*) &data, 1) ;
- bytes = 0 ;
- while (! input.eof ())
- {
- ++ bytes ;
- if (bytes % 1000 == 0)
- cout << bytes << '\r' ;
- UBYTE1 length ;
- UBYTE2 code ;
- table.Encode (data, code, length) ;
- encoder.OutputBits (code, length) ;
- input.read ((char*) &data, 1) ;
- }
- cout << "Pass Two: " << bytes << " bytes" << endl ;
- encoder.FlushBitBuffer () ;
-
- input.close () ;
- output.close () ;
- return 0 ;
- }
-