X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=tools%2Fif1.cpp;h=cd97513edc1953fd1328acaf3cf2a38a4684aa5a;hp=b961c0e92473fea4b7b135d087b2dfbdd2d98d6b;hb=e89023477e02d9332f87cab5a7975407625dbd60;hpb=1effc647176613b986232dd2dcefe1abf5884c5f diff --git a/tools/if1.cpp b/tools/if1.cpp index b961c0e..cd97513 100644 --- a/tools/if1.cpp +++ b/tools/if1.cpp @@ -7,9 +7,7 @@ ** Date Started: Aug 1984 ** ** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: if1.cpp,v 1.1 2000/12/18 00:24:28 kevin Exp $ +** Copyright (C) 1983-2009 Kevin Rosenberg ** ** 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 @@ -46,9 +44,9 @@ static struct option my_options[] = {0, 0, 0, 0} }; -static const char* g_szIdStr = "$Id: if1.cpp,v 1.1 2000/12/18 00:24:28 kevin Exp $"; +static const char* g_szIdStr = "$Id$"; -void +void if1_usage (const char *program) { std::cout << "usage: " << fileBasename(program) << " infile outfile [OPTIONS]" << std::endl; @@ -59,16 +57,14 @@ if1_usage (const char *program) std::cout << " --exp Natural exponential of image" << std::endl; std::cout << " --sqr Square of image" << std::endl; std::cout << " --sqrt Square root of image" << std::endl; - std::cout << " --verbose Verbose modem" << std::endl; + std::cout << " --verbose Verbose mode" << std::endl; std::cout << " --version Print version" << std::endl; std::cout << " --help Print this help message" << std::endl; } -int +int if1_main (int argc, char *const argv[]) { - ImageFile *im_in; - ImageFile *im_out; char *in_file; char *out_file; int opt_verbose = 0; @@ -77,49 +73,50 @@ if1_main (int argc, char *const argv[]) int opt_exp = 0; int opt_sqr = 0; int opt_sqrt = 0; - + UNUSED(opt_verbose); + while (1) { int c = getopt_long (argc, argv, "", my_options, NULL); - + if (c == -1) - break; - + break; + switch (c) - { - case O_INVERT: - opt_invert = 1; - break; - case O_LOG: - opt_log = 1; - break; - case O_SQR: - opt_sqr = 1; - break; - case O_SQRT: - opt_sqrt = 1; - break; - case O_EXP: - opt_exp = 1; - break; - case O_VERBOSE: - opt_verbose = 1; - break; + { + case O_INVERT: + opt_invert = 1; + break; + case O_LOG: + opt_log = 1; + break; + case O_SQR: + opt_sqr = 1; + break; + case O_SQRT: + opt_sqrt = 1; + break; + case O_EXP: + opt_exp = 1; + break; + case O_VERBOSE: + opt_verbose = 1; + break; case O_VERSION: #ifdef VERSION - std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl; + std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl; #else std::cout << "Unknown version number" << std::endl; #endif - return (0); - case O_HELP: - case '?': - if1_usage(argv[0]); - return (0); - default: - if1_usage(argv[0]); - return (1); - } + return (0); + case O_HELP: + case '?': + if1_usage(argv[0]); + return (0); + default: + if1_usage(argv[0]); + return (1); + } } if (optind + 2 != argc) @@ -127,66 +124,50 @@ if1_main (int argc, char *const argv[]) if1_usage(argv[0]); return (1); } - + in_file = argv[optind]; out_file = argv[optind + 1]; - std::string histString; if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) { - int ix, iy; - - im_in = new ImageFile (); - im_in->fileRead (in_file); - int nx = im_in->nx(); - int ny = im_in->ny(); - im_out = new ImageFile (nx, ny); - - ImageFileArray vIn = im_in->getArray(); - ImageFileArray vOut = im_out->getArray(); + ImageFile im_in; + im_in.fileRead (in_file); + int nx = im_in.nx(); + int ny = im_in.ny(); + ImageFile im_out (nx, ny); if (opt_invert) { - for (ix = 0; ix < nx; ix++) - for (iy = 0; iy < ny; iy++) - vOut[ix][iy] = - vIn[ix][iy]; + im_in.invertPixelValues (im_out); histString = "Invert transformation"; } if (opt_log) { - for (ix = 0; ix < nx; ix++) - for (iy = 0; iy < ny; iy++) - vOut[ix][iy] = log (vIn[ix][iy]); - histString = "Log transformation"; + im_in.log (im_out); + histString = "Logrithmic transformation"; } if (opt_exp) { - for (ix = 0; ix < nx; ix++) - for (iy = 0; iy < ny; iy++) - vOut[ix][iy] = exp (vIn[ix][iy]); - histString = "Exp transformation"; + im_in.exp (im_out); + histString = "Exponential transformation"; } if (opt_sqr) { - for (ix = 0; ix < nx; ix++) - for (iy = 0; iy < ny; iy++) - vOut[ix][iy] = vIn[ix][iy] * vIn[ix][iy]; - histString = "Sqr transformation"; + im_in.square (im_out); + histString = "Square transformation"; } if (opt_sqrt) { - for (ix = 0; ix < nx; ix++) - for (iy = 0; iy < ny; iy++) - vOut[ix][iy] = sqrt (vIn[ix][iy]); - histString = "Sqrt transformation"; + im_in.sqrt (im_out); + histString = "Square root transformation"; } - im_out->labelsCopy (*im_in); - im_out->labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str()); - im_out->fileWrite (out_file); + im_out.labelsCopy (im_in); + im_out.labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str()); + im_out.fileWrite (out_file); } return (0); } #ifndef NO_MAIN -int +int main (int argc, char *const argv[]) { int retval = 1;