/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

  1. // Copyright (C) 2000 Dominic Letourneau (doumdi@yahoo.com)
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but
  9. // WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. // General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this file. If not, write to the Free Software Foundation,
  15. // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. #ifndef _PPMREADER_CC_
  17. #define _PPMREADER_CC_
  18. #include "PPMReader.h"
  19. #include "Object.h"
  20. #include "ObjectRef.h"
  21. #include "Exception.h"
  22. DECLARE_NODE(PPMReader)
  23. /*Node
  24. * @name PPMReader
  25. * @category Image
  26. * @description No description available
  27. * @input_name FILENAME
  28. * @input_description No description available
  29. * @output_name IMAGE_OUT
  30. * @output_description No description available
  31. END*/
  32. PPMReader::PPMReader(string nodeName, ParameterSet params)
  33. : Node(nodeName, params) {
  34. m_filenameID = addInput("FILENAME");
  35. addOutput("IMAGE_OUT");
  36. }
  37. ObjectRef PPMReader::getOutput (int output_id, int count) {
  38. int i;
  39. if (!hasOutput(output_id)) throw new NodeException (this, "Cannot getOutput id",__FILE__,__LINE__);
  40. if (count != processCount) {
  41. //We are updating our output only if needed
  42. try {
  43. //getting all data from our inputs.
  44. int OutputID = inputs[m_filenameID].outputID;
  45. String fname = object_cast<String> (inputs[m_filenameID].node->getOutput(OutputID,count));
  46. RGB24Image *im = new RGB24Image;
  47. //reading fname
  48. bool status = im->read_ppm(fname);
  49. if (!status) {
  50. throw new NodeException (this, "Invalid ppm file",__FILE__,__LINE__);
  51. }
  52. output = ObjectRef(im);
  53. } //end of try block
  54. catch (BaseException *e) {
  55. //Something weird happened
  56. //e->print();
  57. throw e->add(new NodeException (this,string("error caught in PPMReader::getOutput(int,int)") +
  58. inputs[m_filenameID].node->getName()
  59. , __FILE__,__LINE__));
  60. }
  61. //updating processCount
  62. processCount = count;
  63. }
  64. return output;
  65. }
  66. #endif