home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Examples / c03 / src / decoder.cpp next >
Encoding:
C/C++ Source or Header  |  1998-12-20  |  931 b   |  56 lines

  1. #include <fstream>
  2.  
  3. #include "xbmdecod.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 = "DECODER" ;
  13.   else
  14.     program = argv [0] ;
  15.  
  16.   cout << program << " input-file.xbm output-file.bmp" << 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.   XbmDecoder decoder ;
  27.  
  28.   ifstream in (argv [1]) ;
  29.   if (! in)
  30.   {
  31.     cerr << "Cannot open file " << argv [1] << endl ;
  32.     return 1 ;
  33.   }
  34.   BitmapImage image ;
  35.   try
  36.   {
  37.     decoder.ReadImage (in, image) ;
  38.   }
  39.   catch (exception &ee)
  40.   {
  41.     cout << "-----> " << ee.what () << endl ;
  42.   }
  43.  
  44.   ofstream out (argv [2], ios::binary) ;
  45.   BmpEncoder encoder ;
  46.   try
  47.   {
  48.     encoder.WriteImage (out, image) ;
  49.   }
  50.   catch (exception &ee)
  51.   {
  52.     cout << ee.what () << endl ;
  53.   }
  54.   return 0 ;
  55. }
  56.