1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sdf-1.c,v 1.3 2000/05/08 20:02:32 kevin Exp $
7 ** Revision 1.3 2000/05/08 20:02:32 kevin
10 ** Revision 1.2 2000/05/03 08:49:50 kevin
13 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
14 ** Initial CVS import for first public release
18 ** This program is free software; you can redistribute it and/or modify
19 ** it under the terms of the GNU General Public License (version 2) as
20 ** published by the Free Software Foundation.
22 ** This program is distributed in the hope that it will be useful,
23 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ** GNU General Public License for more details.
27 ** You should have received a copy of the GNU General Public License
28 ** along with this program; if not, write to the Free Software
29 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 ******************************************************************************/
32 * sdf-1.c Filter a single SDF file
37 enum {O_LOG, O_EXP, O_INVERT, O_VERBOSE, O_HELP, O_VERSION};
39 static struct option my_options[] =
41 {"invert", 0, 0, O_INVERT},
42 {"verbose", 0, 0, O_VERBOSE},
45 {"help", 0, 0, O_HELP},
46 {"version", 0, 0, O_VERSION},
51 usage (const char *program)
53 fprintf(stdout, "usage: %s infile outfile [OPTIONS]\n", kbasename(program));
54 fprintf(stdout, "Generate a SDF2D file from a SDF2D file\n");
55 fprintf(stdout, "\n");
56 fprintf(stdout, " --invert Invert image\n");
57 fprintf(stdout, " --log Natural logrithm of image\n");
58 fprintf(stdout, " --exp Natural exponential of image\n");
59 fprintf(stdout, " --verbose Verbose modem\n");
60 fprintf(stdout, " --version Print version\n");
61 fprintf(stdout, " --help Print this help message\n");
66 main (int argc, char *const argv[])
79 int c = getopt_long (argc, argv, "", my_options, NULL);
100 fprintf(stdout, "Version %s\n", VERSION);
102 fprintf(stderr, "Unknown version number");
115 if (optind + 2 != argc)
121 in_file = argv[optind];
122 out_file = argv[optind + 1];
125 if (opt_invert || opt_log || opt_exp) {
128 im_in = image_load (in_file);
129 im_out = image_create (out_file, im_in->nx, im_in->ny);
132 for (ix = 0; ix < im_in->nx; ix++)
133 for (iy = 0; iy < im_in->ny; iy++)
134 im_out->v[ix][iy] = - im_in->v[ix][iy];
137 for (ix = 0; ix < im_in->nx; ix++)
138 for (iy = 0; iy < im_in->ny; iy++)
139 im_out->v[ix][iy] = log (im_in->v[ix][iy]);
142 for (ix = 0; ix < im_in->nx; ix++)
143 for (iy = 0; iy < im_in->ny; iy++)
144 im_out->v[ix][iy] = exp (im_in->v[ix][iy]);