home *** CD-ROM | disk | FTP | other *** search
- #include <fstream>
-
- #include "jpegenco.h"
- #include "bmpdecod.h"
-
- using namespace std ;
-
- #pragma argsused
- void Progress (BitmapImageCoder &coder,
- void *data,
- unsigned int currentpass,
- unsigned int passcount,
- unsigned int progress,
- bool &cancel)
- {
- cout << currentpass << " of " << passcount << " " << progress << "% \r" << flush ;
- return ;
- }
-
- void Usage (int argc, char *argv [])
- {
- char *file ;
- if (argc != 0)
- file = argv [0] ;
- else
- file = argv [0] ;
-
- cerr << "Usage: " << file << " [-flags] bmp-file jpg-file " << endl ;
- cerr << "Flags: -g Grayscale Output" << endl ;
- cerr << " -p Progressive Output" << endl ;
-
- exit (1) ;
- }
-
- int main (int argc, char *argv [])
- {
- if (argc < 3)
- Usage (argc, argv) ;
-
- JpegEncoder encoder ;
- encoder.SetProgressFunction (Progress, NULL) ;
-
- // Change the default. Place each component in a separate scan.
- encoder.SetScanAttributes (0, 2, 0, 0) ;
- encoder.SetScanAttributes (1, 4, 0, 0) ;
- encoder.SetScanAttributes (2, 8, 0, 0) ;
-
- for (int ii = 1 ; ii < argc - 2 ; ++ ii)
- {
- if (argv [ii][0] != '-')
- Usage (argc, argv) ;
-
- switch (argv [ii][1])
- {
- case 'g':
- encoder.SetGrayscale (true) ;
- break ;
- case 'p':
- encoder.SetProgressive (true) ;
- break ;
- default:
- Usage (argc, argv) ;
- }
- }
-
-
- ifstream input (argv [argc-2], ios::binary) ;
- if (! input)
- {
- cerr << "Can't open input file " << argv [argc-2] << endl ;
- return 1 ;
- }
-
- BmpDecoder decoder ;
- BitmapImage image ;
- try
- {
- decoder.ReadImage (input, image) ;
- }
- catch (exception &ee)
- {
- cerr << ee.what () << endl ;
- return 1 ;
- }
-
- ofstream output (argv [argc-1], ios::binary|ios::trunc) ;
- if (! input)
- {
- cerr << "Can't open output file " << argv [argc-1] << endl ;
- return 1 ;
- }
-
- try
- {
- encoder.WriteImage (output, image) ;
- }
- catch (exception &ee)
- {
- cerr << ee.what () << endl ;
- return 1 ;
- }
- return 0 ;
- }
-