1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sdf-1.c,v 1.6 2000/05/24 22:50:04 kevin Exp $
7 ** Revision 1.6 2000/05/24 22:50:04 kevin
8 ** Added support for new SGP library
10 ** Revision 1.5 2000/05/16 04:33:59 kevin
11 ** Improved option processing
13 ** Revision 1.4 2000/05/09 14:52:27 kevin
14 ** added sqr and sqrt functions
16 ** Revision 1.3 2000/05/08 20:02:32 kevin
19 ** Revision 1.2 2000/05/03 08:49:50 kevin
22 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
23 ** Initial CVS import for first public release
27 ** This program is free software; you can redistribute it and/or modify
28 ** it under the terms of the GNU General Public License (version 2) as
29 ** published by the Free Software Foundation.
31 ** This program is distributed in the hope that it will be useful,
32 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ** GNU General Public License for more details.
36 ** You should have received a copy of the GNU General Public License
37 ** along with this program; if not, write to the Free Software
38 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 ******************************************************************************/
42 * sdf-1.c Filter a single SDF file
47 enum {O_LOG, O_EXP, O_SQRT, O_SQR, O_INVERT, O_VERBOSE, O_HELP, O_VERSION};
49 static struct option my_options[] =
51 {"invert", 0, 0, O_INVERT},
52 {"verbose", 0, 0, O_VERBOSE},
56 {"sqrt", 0, 0, O_SQRT},
57 {"help", 0, 0, O_HELP},
58 {"version", 0, 0, O_VERSION},
63 sdf1_usage (const char *program)
65 fprintf(stdout, "sdf1_usage: %s infile outfile [OPTIONS]\n", kbasename(program));
66 fprintf(stdout, "Generate a SDF2D file from a SDF2D file\n");
67 fprintf(stdout, "\n");
68 fprintf(stdout, " --invert Invert image\n");
69 fprintf(stdout, " --log Natural logrithm of image\n");
70 fprintf(stdout, " --exp Natural exponential of image\n");
71 fprintf(stdout, " --sqr Square of image\n");
72 fprintf(stdout, " --sqrt Square root of image\n");
73 fprintf(stdout, " --verbose Verbose modem\n");
74 fprintf(stdout, " --version Print version\n");
75 fprintf(stdout, " --help Print this help message\n");
79 sdf1_main (int argc, char *const argv[])
94 int c = getopt_long (argc, argv, "", my_options, NULL);
121 fprintf(stdout, "Version %s\n", VERSION);
123 fprintf(stderr, "Unknown version number");
136 if (optind + 2 != argc)
142 in_file = argv[optind];
143 out_file = argv[optind + 1];
146 if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
149 im_in = image_load (in_file);
150 im_out = image_create (out_file, im_in->nx, im_in->ny);
153 for (ix = 0; ix < im_in->nx; ix++)
154 for (iy = 0; iy < im_in->ny; iy++)
155 im_out->v[ix][iy] = - im_in->v[ix][iy];
158 for (ix = 0; ix < im_in->nx; ix++)
159 for (iy = 0; iy < im_in->ny; iy++)
160 im_out->v[ix][iy] = log (im_in->v[ix][iy]);
163 for (ix = 0; ix < im_in->nx; ix++)
164 for (iy = 0; iy < im_in->ny; iy++)
165 im_out->v[ix][iy] = exp (im_in->v[ix][iy]);
168 for (ix = 0; ix < im_in->nx; ix++)
169 for (iy = 0; iy < im_in->ny; iy++)
170 im_out->v[ix][iy] = im_in->v[ix][iy] * im_in->v[ix][iy];
173 for (ix = 0; ix < im_in->nx; ix++)
174 for (iy = 0; iy < im_in->ny; iy++)
175 im_out->v[ix][iy] = sqrt (im_in->v[ix][iy]);
186 main (int argc, char *const argv[])
188 return (sdf1_main(argc, argv));