00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "imageWriter.h"
00016
00017
00018
00019
00020
00021
00022
00023 ImageWriter::
00024 ImageWriter(bool allow_last_param) :
00025 WithOutputFile(allow_last_param, false, true)
00026 {
00027 clear_runlines();
00028 if (_allow_last_param) {
00029 add_runline("[opts] outputimage");
00030 }
00031 add_runline("[opts] -o outputimage");
00032
00033 string o_description;
00034 if (_allow_last_param) {
00035 o_description =
00036 "Specify the filename to which the resulting image file will be written. "
00037 "If this option is omitted, the last parameter name is taken to be the "
00038 "name of the output file.";
00039 } else {
00040 o_description =
00041 "Specify the filename to which the resulting image file will be written.";
00042 }
00043
00044 add_option
00045 ("o", "filename", 50, o_description,
00046 &ImageWriter::dispatch_filename, &_got_output_filename, &_output_filename);
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056 void ImageWriter::
00057 write_image(const PNMImage &image) {
00058 if (!image.write(get_output_filename())) {
00059 nout << "Unable to write output image to "
00060 << get_output_filename() << "\n";
00061 exit(1);
00062 }
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 bool ImageWriter::
00074 handle_args(ProgramBase::Args &args) {
00075 if (!check_last_arg(args, 0)) {
00076 return false;
00077 }
00078
00079 if (!args.empty()) {
00080 nout << "Unexpected arguments on command line:\n";
00081 Args::const_iterator ai;
00082 for (ai = args.begin(); ai != args.end(); ++ai) {
00083 nout << (*ai) << " ";
00084 }
00085 nout << "\r";
00086 return false;
00087 }
00088
00089 return true;
00090 }