Panda3D
 All Classes Functions Variables Enumerations
imageWriter.cxx
00001 // Filename: imageWriter.cxx
00002 // Created by:  drose (19Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "imageWriter.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: ImageWriter::Constructor
00019 //       Access: Public
00020 //  Description: Image-writing type programs *must* specify their
00021 //               output file using -o.
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 //     Function: ImageWriter::write_image
00052 //       Access: Public
00053 //  Description: Writes the generated to the user's specified output
00054 //               filename.
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 //     Function: ImageWriter::handle_args
00067 //       Access: Protected, Virtual
00068 //  Description: Does something with the additional arguments on the
00069 //               command line (after all the -options have been
00070 //               parsed).  Returns true if the arguments are good,
00071 //               false otherwise.
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 }
 All Classes Functions Variables Enumerations