/tags/rel-0-4-1/FreeSpeech/video_blocks/src/PPMReader.cc
# · C++ · 100 lines · 36 code · 30 blank · 34 comment · 4 complexity · cdb7581a6ab89af638ca1a86d4ec3cde MD5 · raw file
- // Copyright (C) 2000 Dominic Letourneau (doumdi@yahoo.com)
- //
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation; either version 2, or (at your option)
- // any later version.
- //
- // This program is distributed in the hope that it will be useful, but
- // WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- // General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this file. If not, write to the Free Software Foundation,
- // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- #ifndef _PPMREADER_CC_
- #define _PPMREADER_CC_
- #include "PPMReader.h"
- #include "Object.h"
- #include "ObjectRef.h"
- #include "Exception.h"
- DECLARE_NODE(PPMReader)
- /*Node
- * @name PPMReader
- * @category Image
- * @description No description available
- * @input_name FILENAME
- * @input_description No description available
- * @output_name IMAGE_OUT
- * @output_description No description available
- END*/
- PPMReader::PPMReader(string nodeName, ParameterSet params)
-
- : Node(nodeName, params) {
- m_filenameID = addInput("FILENAME");
- addOutput("IMAGE_OUT");
- }
- ObjectRef PPMReader::getOutput (int output_id, int count) {
-
- int i;
- if (!hasOutput(output_id)) throw new NodeException (this, "Cannot getOutput id",__FILE__,__LINE__);
- if (count != processCount) {
- //We are updating our output only if needed
-
- try {
-
- //getting all data from our inputs.
- int OutputID = inputs[m_filenameID].outputID;
- String fname = object_cast<String> (inputs[m_filenameID].node->getOutput(OutputID,count));
-
- RGB24Image *im = new RGB24Image;
- //reading fname
- bool status = im->read_ppm(fname);
- if (!status) {
- throw new NodeException (this, "Invalid ppm file",__FILE__,__LINE__);
- }
- output = ObjectRef(im);
-
-
- } //end of try block
- catch (BaseException *e) {
- //Something weird happened
- //e->print();
- throw e->add(new NodeException (this,string("error caught in PPMReader::getOutput(int,int)") +
- inputs[m_filenameID].node->getName()
- , __FILE__,__LINE__));
- }
-
-
-
- //updating processCount
- processCount = count;
-
-
- }
-
- return output;
-
- }
- #endif