Panda3D
 All Classes Functions Variables Enumerations
pnmFileTypePNM.h
1 // Filename: pnmFileTypePNM.h
2 // Created by: drose (17Jun00)
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 #ifndef PNMFILETYPEPNM_H
16 #define PNMFILETYPEPNM_H
17 
18 #include "pandabase.h"
19 
20 #ifdef HAVE_PNM
21 
22 #include "pnmFileType.h"
23 #include "pnmReader.h"
24 #include "pnmWriter.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : PNMFileTypePNM
28 // Description : For reading and writing basic PNM files--*.pbm,
29 // *.ppm, *.pnm.
30 ////////////////////////////////////////////////////////////////////
31 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypePNM : public PNMFileType {
32 public:
33  PNMFileTypePNM();
34 
35  virtual string get_name() const;
36 
37  virtual int get_num_extensions() const;
38  virtual string get_extension(int n) const;
39  virtual string get_suggested_extension() const;
40 
41  virtual bool has_magic_number() const;
42  virtual bool matches_magic_number(const string &magic_number) const;
43 
44  virtual PNMReader *make_reader(istream *file, bool owns_file = true,
45  const string &magic_number = string());
46  virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
47 
48 public:
49  class Reader : public PNMReader {
50  public:
51  Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
52 
53  virtual bool supports_read_row() const;
54  virtual bool read_row(xel *array, xelval *alpha, int x_size, int y_size);
55 
56  private:
57  int _ftype;
58  };
59 
60  class Writer : public PNMWriter {
61  public:
62  Writer(PNMFileType *type, ostream *file, bool owns_file);
63 
64  virtual bool supports_write_row() const;
65  virtual bool write_header();
66  virtual bool write_row(xel *array, xelval *alpha);
67 
68  private:
69  int _pnm_format;
70  };
71 
72 
73  // The TypedWritable interface follows.
74 public:
75  static void register_with_read_factory();
76 
77 protected:
78  static TypedWritable *make_PNMFileTypePNM(const FactoryParams &params);
79 
80 public:
81  static TypeHandle get_class_type() {
82  return _type_handle;
83  }
84  static void init_type() {
85  PNMFileType::init_type();
86  register_type(_type_handle, "PNMFileTypePNM",
87  PNMFileType::get_class_type());
88  }
89  virtual TypeHandle get_type() const {
90  return get_class_type();
91  }
92  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
93 
94 private:
95  static TypeHandle _type_handle;
96 };
97 
98 #endif // HAVE_PNM
99 
100 #endif
101 
102 
virtual string get_extension(int n) const
Returns the nth possible filename extension associated with this particular file type, without a leading dot.
Definition: pnmFileType.cxx:62
virtual PNMWriter * make_writer(ostream *file, bool owns_file=true)
Allocates and returns a new PNMWriter suitable for reading from this file type, if possible...
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:35
virtual int get_num_extensions() const
Returns the number of different possible filename extensions associated with this particular file typ...
Definition: pnmFileType.cxx:50
virtual PNMReader * make_reader(istream *file, bool owns_file=true, const string &magic_number=string())
Allocates and returns a new PNMReader suitable for reading from this file type, if possible...
virtual string get_suggested_extension() const
Returns a suitable filename extension (without a leading dot) to suggest for files of this type...
Definition: pnmFileType.cxx:75
virtual bool has_magic_number() const
Returns true if this particular file type uses a magic number to identify it, false otherwise...
Definition: pnmFileType.cxx:89
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This is an abstract base class that defines the interface for reading image files of various types...
Definition: pnmReader.h:31
This is an abstract base class that defines the interface for writing image files of various types...
Definition: pnmWriter.h:31
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool matches_magic_number(const string &magic_number) const
Returns true if the indicated "magic number" byte stream (the initial few bytes read from the file) m...