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