r141: *** empty log message ***
[ctsim.git] / src / if2img.cpp
index c3a4bfe801ab80d56c42cd8afc4055db9faaaaec..8211d6d3ea7284cbe0932d126d841c2769ef1ad2 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: if2img.cpp,v 1.7 2000/06/19 17:58:13 kevin Exp $
+**  $Id: if2img.cpp,v 1.12 2000/07/09 08:47:41 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ******************************************************************************/
 
-/* FILE
- *   if2img.c          Convert an SDF file to a viewable format image
- */
-
 #include "ct.h"
 
+
 #if HAVE_PNG
 void sdf2d_to_png (ImageFile& im, char *outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax);
 #endif
@@ -61,24 +58,24 @@ static struct option my_options[] =
 };
 
 enum { O_AUTO_FULL, O_AUTO_STD0_1, O_AUTO_STD0_5, O_AUTO_STD1, O_AUTO_STD2, O_AUTO_STD3 };
-#define O_AUTO_FULL_STR  "full"
-#define O_AUTO_STD0_1_STR  "std0.1"
-#define O_AUTO_STD0_5_STR  "std0.5"
-#define O_AUTO_STD1_STR  "std1"
-#define O_AUTO_STD2_STR  "std2"
-#define O_AUTO_STD3_STR  "std3"
+static const char O_AUTO_FULL_STR[]="full";
+static const char O_AUTO_STD0_1_STR[]="std0.1";
+static const char O_AUTO_STD0_5_STR[]="std0.5";
+static const char O_AUTO_STD1_STR[]="std1";
+static const char O_AUTO_STD2_STR[]="std2";
+static const char O_AUTO_STD3_STR[]="std3";
 
 enum { O_CENTER_MEAN, O_CENTER_MODE };
-#define O_CENTER_MEAN_STR  "mean"
-#define O_CENTER_MODE_STR  "mode"
+static const char O_CENTER_MEAN_STR[]="mean";
+static const char O_CENTER_MODE_STR[]="mode";
 
 enum { O_FORMAT_GIF, O_FORMAT_PNG, O_FORMAT_PNG16, O_FORMAT_PGM, O_FORMAT_PGMASC, O_FORMAT_DISP };
-#define O_FORMAT_GIF_STR   "gif"
-#define O_FORMAT_PNG_STR   "png" 
-#define O_FORMAT_PNG16_STR   "png16" 
-#define O_FORMAT_PGM_STR   "pgm"
-#define O_FORMAT_PGMASC_STR "pgmasc"
-#define O_FORMAT_DISP_STR    "disp"
+static const char O_FORMAT_GIF_STR[]="gif";
+static const char O_FORMAT_PNG_STR[]="png" ;
+static const char O_FORMAT_PNG16_STR[]="png16" ;
+static const char O_FORMAT_PGM_STR[]="pgm";
+static const char O_FORMAT_PGMASC_STR[]="pgmasc";
+static const char O_FORMAT_DISP_STR[]="disp";
 
 void 
 if2img_usage (const char *program)
@@ -279,30 +276,15 @@ if2img_main (int argc, char *const argv[])
       out_file = argv[optind+1];
   else out_file = NULL;
 
-  pim = new ImageFile (in_file);
+  pim = new ImageFile ();
   ImageFile& im = *pim;
-  if (! im.fileRead()) {
+  if (! im.fileRead(in_file)) {
     sys_error (ERR_FATAL, "File %s does not exist", in_file);
     return (1);
   }
 
-  if (opt_labels) {
-    int nlabels = im.getNumLabels();
-
-    for (int i = 0; i < nlabels; i++) {
-      Array2dFileLabel label;
-      im.labelRead (label, i);
-
-      if (label.getLabelType() == Array2dFileLabel::L_HISTORY) {
-       cout << "History: " << label.getLabelString() << endl;
-       cout << "  calc time = " << label.getCalcTime() << " secs" << endl;
-       cout << "  Timestamp = " << label.getDateString() << endl;
-      } else if (label.getLabelType() == Array2dFileLabel::L_USER) {
-       cout << "Note: " <<  label.getLabelString() << endl;
-       cout << "  Timestamp = %s" << label.getDateString() << endl;
-      }
-    }
-  }
+  if (opt_labels)
+    im.printLabels(cout);
 
   if (opt_stats || (! (opt_set_max && opt_set_min))) {
     double minfound = HUGE_VAL, maxfound = -HUGE_VAL;
@@ -429,9 +411,9 @@ if2img_main (int argc, char *const argv[])
 #endif
   else if (opt_format == O_FORMAT_DISP) {
 #if HAVE_SGP
-    // image_display_scale (im, opt_scale, densmin, densmax);
-    //  cio_kb_getc();
-      sgp2_close(sgp2_get_active_win());
+    im.displayScaling (opt_scale, densmin, densmax);
+    cio_kb_getc();
+    //    sgp2_close(sgp2_get_active_win());
 #endif
   }
   else
@@ -451,7 +433,7 @@ sdf2d_to_pgm (ImageFile& im, char *outfile, int nxcell, int nycell, double densm
   int ny = im.ny();
   ImageFileArray v = im.getArray();
 
-  unsigned char* rowp = new unsigned char [nx * nxcell];
+  unsigned char rowp [nx * nxcell];
 
   if ((fp = fopen (outfile, "wb")) == NULL)
      return;
@@ -474,7 +456,6 @@ sdf2d_to_pgm (ImageFile& im, char *outfile, int nxcell, int nycell, double densm
        fprintf(fp, "%c ", rowp[ic]);
     }
   }
-  delete rowp;
 
   fclose(fp);
 }
@@ -487,7 +468,7 @@ sdf2d_to_pgmasc (ImageFile& im, char *outfile, int nxcell, int nycell, double de
   int ny = im.ny();
   ImageFileArray v = im.getArray();
 
-  unsigned char* rowp = new unsigned char [nx * nxcell];
+  unsigned char rowp [nx * nxcell];
   if (rowp == NULL)
     return;
 
@@ -513,7 +494,6 @@ sdf2d_to_pgmasc (ImageFile& im, char *outfile, int nxcell, int nycell, double de
       fprintf(fp, "\n");
     }
   }
-  delete rowp;
 
   fclose(fp);
 }
@@ -531,7 +511,7 @@ sdf2d_to_png (ImageFile& im, char *outfile, int bitdepth, int nxcell, int nycell
   int ny = im.ny();
   ImageFileArray v = im.getArray();
 
-  unsigned char* rowp = new unsigned char [nx * nxcell * (bitdepth / 8)];
+  unsigned char rowp [nx * nxcell * (bitdepth / 8)];
 
   if ((fp = fopen (outfile, "wb")) == NULL)
      return;
@@ -580,7 +560,6 @@ sdf2d_to_png (ImageFile& im, char *outfile, int bitdepth, int nxcell, int nycell
     for (int ir = 0; ir < nycell; ir++)
       png_write_rows (png_ptr, &row_pointer, 1);
   }
-  delete rowp;
 
   png_write_end(png_ptr, info_ptr);
   png_destroy_write_struct(&png_ptr, &info_ptr);
@@ -591,7 +570,7 @@ sdf2d_to_png (ImageFile& im, char *outfile, int bitdepth, int nxcell, int nycell
 
 #ifdef HAVE_GD
 #include "gd.h"
-#define N_GRAYSCALE 256
+static const int N_GRAYSCALE=256;
 #endif
 
 void
@@ -605,7 +584,7 @@ sdf2d_to_gif (ImageFile& im, char *outfile, int nxcell, int nycell, double densm
   int ny = im.ny();
   ImageFileArray v = im.getArray();
 
-  usnigned char* rowp = new unsigned char [nx * nxcell];
+  unsigned char rowp [nx * nxcell];
   if (rowp == NULL)
     return;
 
@@ -628,7 +607,6 @@ sdf2d_to_gif (ImageFile& im, char *outfile, int nxcell, int nycell, double densm
       }
     }
   }
-  delete rowp;
 
   if ((out = fopen(outfile,"w")) == NULL) {
     sys_error(ERR_FATAL, "Error opening output file %s for writing", outfile);