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