Panda3D
pnmFileTypeTIFF.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 pnmFileTypeTIFF.h
10  * @author drose
11  * @date 2000-06-17
12  */
13 
14 #ifndef PNMFILETYPETIFF_H
15 #define PNMFILETYPETIFF_H
16 
17 #include "pandabase.h"
18 
19 #ifdef HAVE_TIFF
20 
21 #include "pnmFileType.h"
22 #include "pnmReader.h"
23 #include "pnmWriter.h"
24 
25 #include <stdarg.h> // for va_list
26 
27 
28 #define TIFF_COLORMAP_MAXCOLORS 1024
29 
30 /**
31  * For reading and writing TIFF files.
32  */
33 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeTIFF : public PNMFileType {
34 public:
35  PNMFileTypeTIFF();
36 
37  virtual std::string get_name() const;
38 
39  virtual int get_num_extensions() const;
40  virtual std::string get_extension(int n) const;
41  virtual std::string get_suggested_extension() const;
42 
43  virtual bool has_magic_number() const;
44  virtual bool matches_magic_number(const std::string &magic_number) const;
45 
46  virtual PNMReader *make_reader(std::istream *file, bool owns_file = true,
47  const std::string &magic_number = std::string());
48  virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true);
49 
50 public:
51  class Reader : public PNMReader {
52  public:
53  Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string magic_number);
54  virtual ~Reader();
55 
56  virtual bool is_floating_point();
57  virtual bool read_pfm(PfmFile &pfm);
58  virtual bool supports_read_row() const;
59  virtual bool read_row(xel *array, xelval *alpha, int x_size, int y_size);
60 
61  private:
62  xelval next_sample_lt_8(unsigned char *&buf_ptr, int &bits_left) const;
63  xelval next_sample_8(unsigned char *&buf_ptr, int &bits_left) const;
64  xelval next_sample_16(unsigned char *&buf_ptr, int &bits_left) const;
65  xelval next_sample_32(unsigned char *&buf_ptr, int &bits_left) const;
66  xelval next_sample_general(unsigned char *&buf_ptr, int &bits_left) const;
67 
68  unsigned short sample_format;
69  unsigned short photomet;
70  unsigned short bps, spp;
71  unsigned short unassoc_alpha_sample, assoc_alpha_sample;
72  xel colormap[TIFF_COLORMAP_MAXCOLORS];
73 
74  int current_row;
75  struct tiff *tif;
76  };
77 
78  class Writer : public PNMWriter {
79  public:
80  Writer(PNMFileType *type, std::ostream *file, bool owns_file);
81 
82  virtual bool supports_floating_point();
83  virtual bool supports_integer();
84  virtual bool write_pfm(const PfmFile &pfm);
85  virtual int write_data(xel *array, xelval *alpha);
86  };
87 
88 private:
89  static void install_error_handlers();
90 
91  static void tiff_warning(const char *module, const char *format, va_list ap);
92  static void tiff_error(const char *module, const char *format, va_list ap);
93  static bool _installed_error_handlers;
94 
95  // The TypedWritable interface follows.
96 public:
97  static void register_with_read_factory();
98 
99 protected:
100  static TypedWritable *make_PNMFileTypeTIFF(const FactoryParams &params);
101 
102 public:
103  static TypeHandle get_class_type() {
104  return _type_handle;
105  }
106  static void init_type() {
107  PNMFileType::init_type();
108  register_type(_type_handle, "PNMFileTypeTIFF",
109  PNMFileType::get_class_type());
110  }
111  virtual TypeHandle get_type() const {
112  return get_class_type();
113  }
114  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
115 
116 private:
117  static TypeHandle _type_handle;
118 };
119 
120 #endif // HAVE_TIFF
121 
122 #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.