home *** CD-ROM | disk | FTP | other *** search
- #include <fstream>
- #include "jpegdeco.h"
- #include "bitimage.h"
- #include "bmpencod.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 *program ;
- if (argc != 0)
- program = argv [0] ;
- else
- program = "DECODER" ;
-
- cerr << "Usage: " << program << " [-v] input.jpg output.bmp" << endl ;
- exit (1) ;
- }
-
- int main(int argc, char *argv [])
- {
- if (argc < 3)
- {
- Usage (argc, argv) ;
- return 1 ;
- }
-
- JpegDecoder decoder ;
-
- for (unsigned int ii = 1 ; ii < argc - 2 ; ++ ii)
- {
- if (argv [ii][0] != '-')
- Usage (argc, argv) ;
-
- switch (argv [ii][1])
- {
- case 'v':
- decoder.SetVerbose (true) ;
- break ;
- default:
- Usage (argc, argv) ;
- }
- }
-
- decoder.SetProgressFunction (Progress, NULL) ;
-
- ifstream is (argv [argc - 2], ios::binary) ;
- if (! is)
- {
- cerr << "Can't open input file " << argv [argc-2] << endl ;
- return 1 ;
- }
- BitmapImage image ;
- cout << "Reading Image..." << endl ;
- try
- {
- decoder.ReadImage (is, image) ;
- }
- catch (EGraphicsException &ee)
- {
- cerr << ee.what () << endl << flush ;
- return 1 ;
- }
-
- cout << "Writing Output..." << endl ;
- ofstream os (argv [argc-1], ios::binary|ios::trunc) ;
- if (! os)
- {
- cerr << "Can't open output file " << argv [argc-1] << endl ;
- return 1 ;
- }
-
- BmpEncoder bs ;
- try
- {
- bs.WriteImage (os, image) ;
- }
- catch (EGraphicsException &ee)
- {
- cerr << ee.what () << endl << flush ;
- return 1 ;
- }
- cout << "Done..." << endl << flush ;
-
- return 0;
- }
-