home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Library / PNG / decoder.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-07  |  1.6 KB  |  81 lines

  1. #include <fstream>
  2.  
  3. #include "pngdecod.h"
  4. #include "bmpencod.h"
  5.  
  6. using namespace std ;
  7.  
  8. void Progress (BitmapImageCoder &, void*,
  9.                unsigned int pass,
  10.                unsigned int passcount,
  11.                unsigned int percent, bool &)
  12. {
  13.   unsigned int value = 100 * (pass - 1) / passcount + percent / passcount ;
  14.   cout << value << "%                \r" << flush ;
  15.   return ;
  16. }
  17.  
  18.  
  19. void Usage (int argc, char *argv [])
  20. {
  21.   char *program ;
  22.   if (argc == 0)
  23.     program = "pngdecoder" ;
  24.   else
  25.     program = argv [0] ;
  26.  
  27.   cout << program << " input-file output-file" << endl ;
  28.   exit (1) ;
  29.   return ;
  30. }
  31.  
  32. main (int argc, char *argv [])
  33. {
  34.   if (argc < 3)
  35.     Usage (argc, argv) ;
  36.  
  37.   PngDecoder decoder ;
  38.   for (unsigned int ii = 1 ; ii < argc - 2 ; ++ ii)
  39.   {
  40.     if (argv [ii][0] != '-')
  41.       Usage (argc, argv) ;
  42.  
  43.     switch (argv [ii][1])
  44.     {
  45.     case 'v':
  46.       decoder.SetVerbose (true) ;
  47.       break ;
  48.     default:
  49.       Usage (argc, argv) ;
  50.     }
  51.   }
  52.   decoder.SetProgressFunction (Progress, NULL) ;
  53.   ifstream in (argv [argc-2], ios::binary) ;
  54.   if (! in)
  55.   {
  56.     cerr << "Cannot open file " << argv [argc-2] << endl ;
  57.     return 1 ;
  58.   }
  59.   BitmapImage image ;
  60.   try
  61.   {
  62.     decoder.ReadImage (in, image) ;
  63.   }
  64.   catch (exception &ee)
  65.   {
  66.     cout << "-----> " << ee.what () << endl ;
  67.   }
  68.  
  69.   ofstream out (argv [argc-1], ios::binary) ;
  70.   BmpEncoder encoder ;
  71.   try
  72.   {
  73.     encoder.WriteImage (out, image) ;
  74.   }
  75.   catch (exception &ee)
  76.   {
  77.     cout << ee.what () << endl ;
  78.   }
  79.   return 0 ;
  80. }
  81.