home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Examples / c03 / src / encoder.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-23  |  1.1 KB  |  67 lines

  1. #include <fstream>
  2. #include <time.h>
  3. #include "xbmencod.h"
  4. #include "bmpdecod.h"
  5.  
  6. using namespace std ;
  7.  
  8. void Usage (int argc, char *argv [])
  9. {
  10.   char *program ;
  11.   if (argc > 0)
  12.     program = argv [0] ;
  13.   else
  14.     program = "DECODER" ;
  15.  
  16.   cerr << "Usage: " << program << " input.bmp output.xbm" << endl ;
  17.  
  18.   exit (1) ;
  19.   return ;
  20. }
  21.  
  22.  
  23. main (int argc, char *argv [])
  24. {
  25.   if (argc != 3)
  26.     Usage (argc, argv) ;
  27.  
  28.   XbmEncoder encoder ;
  29.  
  30.   ifstream input (argv [1], ios::binary) ;
  31.   if (! input)
  32.   {
  33.     cerr << "Can't open input file " << argv [1] << endl ;
  34.     exit (1) ;
  35.   }
  36.  
  37.   BmpDecoder decoder ;
  38.   BitmapImage image ;
  39.   try
  40.   {
  41.     decoder.ReadImage (input, image) ;
  42.   }
  43.   catch (exception &ee)
  44.   {
  45.     cerr << ee.what () << endl ;
  46.     throw ;
  47.   }
  48.  
  49.   ofstream output (argv [2]) ; // XBM files should not use binary mode.
  50.   if (! output)
  51.   {
  52.     cerr << "Can't open output file " << argv [2] << endl ;
  53.     exit (1) ;
  54.   }
  55.  
  56.   try
  57.   {
  58.     encoder.WriteImage (output, image) ;
  59.   }
  60.   catch (exception &ee)
  61.   {
  62.     cerr << ee.what () << endl ;
  63.   }
  64.  
  65.   return 0 ;
  66. }
  67.