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