1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sdf-1.c,v 1.4 2000/05/09 14:52:27 kevin Exp $
7 ** Revision 1.4 2000/05/09 14:52:27 kevin
8 ** added sqr and sqrt functions
10 ** Revision 1.3 2000/05/08 20:02:32 kevin
13 ** Revision 1.2 2000/05/03 08:49:50 kevin
16 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
17 ** Initial CVS import for first public release
21 ** This program is free software; you can redistribute it and/or modify
22 ** it under the terms of the GNU General Public License (version 2) as
23 ** published by the Free Software Foundation.
25 ** This program is distributed in the hope that it will be useful,
26 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ** GNU General Public License for more details.
30 ** You should have received a copy of the GNU General Public License
31 ** along with this program; if not, write to the Free Software
32 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 ******************************************************************************/
35 * sdf-1.c Filter a single SDF file
40 enum {O_LOG, O_EXP, O_SQRT, O_SQR, O_INVERT, O_VERBOSE, O_HELP, O_VERSION};
42 static struct option my_options[] =
44 {"invert", 0, 0, O_INVERT},
45 {"verbose", 0, 0, O_VERBOSE},
49 {"sqrt", 0, 0, O_SQRT},
50 {"help", 0, 0, O_HELP},
51 {"version", 0, 0, O_VERSION},
56 usage (const char *program)
58 fprintf(stdout, "usage: %s infile outfile [OPTIONS]\n", kbasename(program));
59 fprintf(stdout, "Generate a SDF2D file from a SDF2D file\n");
60 fprintf(stdout, "\n");
61 fprintf(stdout, " --invert Invert image\n");
62 fprintf(stdout, " --log Natural logrithm of image\n");
63 fprintf(stdout, " --exp Natural exponential of image\n");
64 fprintf(stdout, " --sqr Square of image\n");
65 fprintf(stdout, " --sqrt Square root of image\n");
66 fprintf(stdout, " --verbose Verbose modem\n");
67 fprintf(stdout, " --version Print version\n");
68 fprintf(stdout, " --help Print this help message\n");
73 main (int argc, char *const argv[])
88 int c = getopt_long (argc, argv, "", my_options, NULL);
115 fprintf(stdout, "Version %s\n", VERSION);
117 fprintf(stderr, "Unknown version number");
130 if (optind + 2 != argc)
136 in_file = argv[optind];
137 out_file = argv[optind + 1];
140 if (opt_invert || opt_log || opt_exp) {
143 im_in = image_load (in_file);
144 im_out = image_create (out_file, im_in->nx, im_in->ny);
147 for (ix = 0; ix < im_in->nx; ix++)
148 for (iy = 0; iy < im_in->ny; iy++)
149 im_out->v[ix][iy] = - im_in->v[ix][iy];
152 for (ix = 0; ix < im_in->nx; ix++)
153 for (iy = 0; iy < im_in->ny; iy++)
154 im_out->v[ix][iy] = log (im_in->v[ix][iy]);
157 for (ix = 0; ix < im_in->nx; ix++)
158 for (iy = 0; iy < im_in->ny; iy++)
159 im_out->v[ix][iy] = exp (im_in->v[ix][iy]);
162 for (ix = 0; ix < im_in->nx; ix++)
163 for (iy = 0; iy < im_in->ny; iy++)
164 im_out->v[ix][iy] = im_in->v[ix][iy] * im_in->v[ix][iy];
167 for (ix = 0; ix < im_in->nx; ix++)
168 for (iy = 0; iy < im_in->ny; iy++)
169 im_out->v[ix][iy] = sqrt (im_in->v[ix][iy]);