home *** CD-ROM | disk | FTP | other *** search
- #include <fstream>
- #include <time.h>
- #include "pngencod.h"
- #include "bmpdecod.h"
-
- using namespace std ;
-
- void Progress (BitmapImageCoder &, void*, unsigned int pass, unsigned int passcount,
- unsigned int percent, bool &)
- {
- unsigned int value = 100 * (pass - 1) / passcount + percent / passcount ;
- cout << value << "% \r" << flush ;
- }
-
- void Usage (int argc, char *argv [])
- {
- char *program ;
- if (argc != 0)
- program = argv [0] ;
- else
- program = "ENCODER" ;
-
- cerr << "Usage: " << program << " [-P -F -M -f] input.bmp output.png" << endl ;
-
- exit (1) ;
- return ;
- }
-
-
- main (int argc, char *argv [])
- {
- time_t start = time (NULL) ;
-
- if (argc < 3)
- Usage (argc, argv) ;
-
- PngEncoder encoder ;
-
- for (unsigned int ii = 1 ; ii < argc - 2 ; ++ ii)
- {
- if (argv [ii][0] != '-')
- Usage (argc, argv) ;
-
- switch (argv [ii][1])
- {
- case 'f':
- encoder.SetUseFilters (true) ;
- break ;
- case 'F':
- encoder.SetCompressionLevel (PngEncoder::FastestCompression) ;
- break ;
- case 'M':
- encoder.SetCompressionLevel (PngEncoder::MaximumCompression) ;
- break ;
- case 'P':
- encoder.SetProgressFunction (Progress, NULL) ;
- break ;
- default:
- Usage (argc, argv) ;
- }
- }
-
- ifstream input (argv [argc-2], ios::binary) ;
- if (! input)
- {
- cerr << "Can't open input file " << argv [argc-2] << endl ;
- exit (1) ;
- }
-
- BmpDecoder decoder ;
- BitmapImage image ;
- try
- {
- decoder.ReadImage (input, image) ;
- }
- catch (exception &ee)
- {
- cerr << ee.what () << endl ;
- throw ;
- }
-
- ofstream output (argv [argc-1], ios::binary) ;
- if (! output)
- {
- cerr << "Can't open output file " << argv [argc-1] << endl ;
- exit (1) ;
- }
-
- try
- {
- encoder.WriteImage (output, image) ;
- }
- catch (exception &ee)
- {
- cerr << ee.what () << endl ;
- }
- time_t elapsed = time (NULL) - start ;
- cout << endl << elapsed << " Seconds" << endl ;
- return 0 ;
- }
-