Panda3D

pnmFileTypePNM.h

00001 // Filename: pnmFileTypePNM.h
00002 // Created by:  drose (17Jun00)
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 #ifndef PNMFILETYPEPNM_H
00016 #define PNMFILETYPEPNM_H
00017 
00018 #include "pandabase.h"
00019 
00020 #ifdef HAVE_PNM
00021 
00022 #include "pnmFileType.h"
00023 #include "pnmReader.h"
00024 #include "pnmWriter.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : PNMFileTypePNM
00028 // Description : For reading and writing basic PNM files--*.pbm,
00029 //               *.ppm, *.pnm.
00030 ////////////////////////////////////////////////////////////////////
00031 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypePNM : public PNMFileType {
00032 public:
00033   PNMFileTypePNM();
00034 
00035   virtual string get_name() const;
00036 
00037   virtual int get_num_extensions() const;
00038   virtual string get_extension(int n) const;
00039   virtual string get_suggested_extension() const;
00040 
00041   virtual bool has_magic_number() const;
00042   virtual bool matches_magic_number(const string &magic_number) const;
00043 
00044   virtual PNMReader *make_reader(istream *file, bool owns_file = true,
00045                                  const string &magic_number = string());
00046   virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
00047 
00048 public:
00049   class Reader : public PNMReader {
00050   public:
00051     Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
00052 
00053     virtual bool supports_read_row() const;
00054     virtual bool read_row(xel *array, xelval *alpha, int x_size, int y_size);
00055 
00056   private:
00057     int _ftype;
00058   };
00059 
00060   class Writer : public PNMWriter {
00061   public:
00062     Writer(PNMFileType *type, ostream *file, bool owns_file);
00063 
00064     virtual bool supports_write_row() const;
00065     virtual bool write_header();
00066     virtual bool write_row(xel *array, xelval *alpha);
00067 
00068   private:
00069     int _pnm_format;
00070   };
00071 
00072 
00073   // The TypedWritable interface follows.
00074 public:
00075   static void register_with_read_factory();
00076 
00077 protected:
00078   static TypedWritable *make_PNMFileTypePNM(const FactoryParams &params);
00079 
00080 public:
00081   static TypeHandle get_class_type() {
00082     return _type_handle;
00083   }
00084   static void init_type() {
00085     PNMFileType::init_type();
00086     register_type(_type_handle, "PNMFileTypePNM",
00087                   PNMFileType::get_class_type());
00088   }
00089   virtual TypeHandle get_type() const {
00090     return get_class_type();
00091   }
00092   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00093 
00094 private:
00095   static TypeHandle _type_handle;
00096 };
00097 
00098 #endif  // HAVE_PNM
00099 
00100 #endif
00101 
00102 
 All Classes Functions Variables Enumerations