home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Examples / c14 / src / decoder.cpp next >
Encoding:
C/C++ Source or Header  |  1998-12-17  |  1.2 KB  |  70 lines

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