Panda3D
pnmFileTypeEXR.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pnmFileTypeEXR.h
10  * @author drose
11  * @date 2000-06-17
12  */
13 
14 #ifndef PNMFILETYPEEXR_H
15 #define PNMFILETYPEEXR_H
16 
17 #include "pandabase.h"
18 
19 #ifdef HAVE_OPENEXR
20 
21 #include "pnmFileType.h"
22 #include "pnmReader.h"
23 #include "pnmWriter.h"
24 
25 #include <ImfInputFile.h>
26 #include <OpenEXRConfig.h>
27 
28 #ifdef OPENEXR_IMF_NAMESPACE
29 namespace IMF = OPENEXR_IMF_NAMESPACE;
30 #else
31 namespace IMF = Imf;
32 #endif
33 
34 class ImfStdIstream;
35 
36 /**
37  * For reading and writing EXR floating-point or integer files.
38  */
39 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeEXR : public PNMFileType {
40 public:
41  PNMFileTypeEXR();
42 
43  virtual std::string get_name() const;
44 
45  virtual int get_num_extensions() const;
46  virtual std::string get_extension(int n) const;
47  virtual std::string get_suggested_extension() const;
48 
49  virtual bool has_magic_number() const;
50  virtual bool matches_magic_number(const std::string &magic_number) const;
51 
52  virtual PNMReader *make_reader(std::istream *file, bool owns_file = true,
53  const std::string &magic_number = std::string());
54  virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true);
55 
56 public:
57  class Reader : public PNMReader {
58  public:
59  Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string magic_number);
60  virtual ~Reader();
61 
62  virtual bool is_floating_point();
63  virtual bool read_pfm(PfmFile &pfm);
64  virtual int read_data(xel *array, xelval *alpha);
65 
66  private:
67  class ImfStdIstream *_strm;
68  IMF::InputFile _imf_file;
69 
70  typedef std::vector<std::string> ChannelNames;
71  ChannelNames _channel_names;
72  };
73 
74  class Writer : public PNMWriter {
75  public:
76  Writer(PNMFileType *type, std::ostream *file, bool owns_file);
77 
78  virtual bool supports_floating_point();
79  virtual bool supports_integer();
80  virtual bool write_pfm(const PfmFile &pfm);
81  virtual int write_data(xel *array, xelval *alpha);
82  };
83 
84 private:
85 
86  // The TypedWritable interface follows.
87 public:
88  static void register_with_read_factory();
89 
90 protected:
91  static TypedWritable *make_PNMFileTypeEXR(const FactoryParams &params);
92 
93 public:
94  static TypeHandle get_class_type() {
95  return _type_handle;
96  }
97  static void init_type() {
98  PNMFileType::init_type();
99  register_type(_type_handle, "PNMFileTypeEXR",
100  PNMFileType::get_class_type());
101  }
102  virtual TypeHandle get_type() const {
103  return get_class_type();
104  }
105  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
106 
107 private:
108  static TypeHandle _type_handle;
109 };
110 
111 #endif // HAVE_OPENEXR
112 
113 #endif
virtual PNMReader * make_reader(std::istream *file, bool owns_file=true, const std::string &magic_number=std::string())
Allocates and returns a new PNMReader suitable for reading from this file type, if possible.
Definition: pnmFileType.cxx:96
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:32
Defines a pfm file, a 2-d table of floating-point numbers, either 3-component or 1-component,...
Definition: pfmFile.h:31
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
This is an abstract base class that defines the interface for reading image files of various types.
Definition: pnmReader.h:27
get_extension
Returns the nth possible filename extension associated with this particular file type,...
Definition: pnmFileType.h:44
This is an abstract base class that defines the interface for writing image files of various types.
Definition: pnmWriter.h:27
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool matches_magic_number(const std::string &magic_number) const
Returns true if the indicated "magic number" byte stream (the initial few bytes read from the file) m...
Definition: pnmFileType.cxx:86
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:76
virtual PNMWriter * make_writer(std::ostream *file, bool owns_file=true)
Allocates and returns a new PNMWriter suitable for reading from this file type, if possible.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.