1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sdf-1.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $
7 ** Revision 1.1 2000/06/07 02:29:05 kevin
8 ** Initial C++ versions
10 ** Revision 1.6 2000/05/24 22:50:04 kevin
11 ** Added support for new SGP library
13 ** Revision 1.5 2000/05/16 04:33:59 kevin
14 ** Improved option processing
16 ** Revision 1.4 2000/05/09 14:52:27 kevin
17 ** added sqr and sqrt functions
19 ** Revision 1.3 2000/05/08 20:02:32 kevin
22 ** Revision 1.2 2000/05/03 08:49:50 kevin
25 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
26 ** Initial CVS import for first public release
30 ** This program is free software; you can redistribute it and/or modify
31 ** it under the terms of the GNU General Public License (version 2) as
32 ** published by the Free Software Foundation.
34 ** This program is distributed in the hope that it will be useful,
35 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ** GNU General Public License for more details.
39 ** You should have received a copy of the GNU General Public License
40 ** along with this program; if not, write to the Free Software
41 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42 ******************************************************************************/
45 * sdf-1.c Filter a single SDF file
50 enum {O_LOG, O_EXP, O_SQRT, O_SQR, O_INVERT, O_VERBOSE, O_HELP, O_VERSION};
52 static struct option my_options[] =
54 {"invert", 0, 0, O_INVERT},
55 {"verbose", 0, 0, O_VERBOSE},
59 {"sqrt", 0, 0, O_SQRT},
60 {"help", 0, 0, O_HELP},
61 {"version", 0, 0, O_VERSION},
66 sdf1_usage (const char *program)
68 fprintf(stdout, "sdf1_usage: %s infile outfile [OPTIONS]\n", kbasename(program));
69 fprintf(stdout, "Generate a SDF2D file from a SDF2D file\n");
70 fprintf(stdout, "\n");
71 fprintf(stdout, " --invert Invert image\n");
72 fprintf(stdout, " --log Natural logrithm of image\n");
73 fprintf(stdout, " --exp Natural exponential of image\n");
74 fprintf(stdout, " --sqr Square of image\n");
75 fprintf(stdout, " --sqrt Square root of image\n");
76 fprintf(stdout, " --verbose Verbose modem\n");
77 fprintf(stdout, " --version Print version\n");
78 fprintf(stdout, " --help Print this help message\n");
82 sdf1_main (int argc, char *const argv[])
97 int c = getopt_long (argc, argv, "", my_options, NULL);
124 fprintf(stdout, "Version %s\n", VERSION);
126 fprintf(stderr, "Unknown version number");
139 if (optind + 2 != argc)
145 in_file = argv[optind];
146 out_file = argv[optind + 1];
149 if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
152 im_in = image_load (in_file);
153 im_out = image_create (out_file, im_in->nx, im_in->ny);
156 for (ix = 0; ix < im_in->nx; ix++)
157 for (iy = 0; iy < im_in->ny; iy++)
158 im_out->v[ix][iy] = - im_in->v[ix][iy];
161 for (ix = 0; ix < im_in->nx; ix++)
162 for (iy = 0; iy < im_in->ny; iy++)
163 im_out->v[ix][iy] = log (im_in->v[ix][iy]);
166 for (ix = 0; ix < im_in->nx; ix++)
167 for (iy = 0; iy < im_in->ny; iy++)
168 im_out->v[ix][iy] = exp (im_in->v[ix][iy]);
171 for (ix = 0; ix < im_in->nx; ix++)
172 for (iy = 0; iy < im_in->ny; iy++)
173 im_out->v[ix][iy] = im_in->v[ix][iy] * im_in->v[ix][iy];
176 for (ix = 0; ix < im_in->nx; ix++)
177 for (iy = 0; iy < im_in->ny; iy++)
178 im_out->v[ix][iy] = sqrt (im_in->v[ix][iy]);
189 main (int argc, char *const argv[])
191 return (sdf1_main(argc, argv));