Panda3D
imageWriter.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file imageWriter.cxx
10  * @author drose
11  * @date 2000-06-19
12  */
13 
14 #include "imageWriter.h"
15 
16 /**
17  * Image-writing type programs *must* specify their output file using -o.
18  */
20 ImageWriter(bool allow_last_param) :
21  WithOutputFile(allow_last_param, false, true)
22 {
23  clear_runlines();
24  if (_allow_last_param) {
25  add_runline("[opts] outputimage");
26  }
27  add_runline("[opts] -o outputimage");
28 
29  std::string o_description;
30  if (_allow_last_param) {
31  o_description =
32  "Specify the filename to which the resulting image file will be written. "
33  "If this option is omitted, the last parameter name is taken to be the "
34  "name of the output file.";
35  } else {
36  o_description =
37  "Specify the filename to which the resulting image file will be written.";
38  }
39 
40  add_option
41  ("o", "filename", 50, o_description,
42  &ImageWriter::dispatch_filename, &_got_output_filename, &_output_filename);
43 }
44 
45 
46 /**
47  * Writes the generated to the user's specified output filename.
48  */
49 void ImageWriter::
50 write_image(const PNMImage &image) {
51  if (!image.write(get_output_filename())) {
52  nout << "Unable to write output image to "
53  << get_output_filename() << "\n";
54  exit(1);
55  }
56 }
57 
58 /**
59  * Does something with the additional arguments on the command line (after all
60  * the -options have been parsed). Returns true if the arguments are good,
61  * false otherwise.
62  */
63 bool ImageWriter::
64 handle_args(ProgramBase::Args &args) {
65  if (!check_last_arg(args, 0)) {
66  return false;
67  }
68 
69  if (!args.empty()) {
70  nout << "Unexpected arguments on command line:\n";
71  Args::const_iterator ai;
72  for (ai = args.begin(); ai != args.end(); ++ai) {
73  nout << (*ai) << " ";
74  }
75  nout << "\r";
76  return false;
77  }
78 
79  return true;
80 }
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:58
bool write(const Filename &filename, PNMFileType *type=nullptr) const
Writes the image to the indicated filename.
Definition: pnmImage.cxx:385
Filename get_output_filename() const
If has_output_filename() returns true, this is the filename that the user specified.
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivati...
ImageWriter(bool allow_last_param)
Image-writing type programs *must* specify their output file using -o.
Definition: imageWriter.cxx:20
void write_image()
Writes the generated to the user's specified output filename.
Definition: imageWriter.I:18
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.