00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PNMFILETYPETIFF_H
00016 #define PNMFILETYPETIFF_H
00017
00018 #include "pandabase.h"
00019
00020 #ifdef HAVE_TIFF
00021
00022 #include "pnmFileType.h"
00023 #include "pnmReader.h"
00024 #include "pnmWriter.h"
00025
00026 #include <stdarg.h>
00027
00028
00029 #define TIFF_COLORMAP_MAXCOLORS 1024
00030
00031
00032
00033
00034
00035 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeTIFF : public PNMFileType {
00036 public:
00037 PNMFileTypeTIFF();
00038
00039 virtual string get_name() const;
00040
00041 virtual int get_num_extensions() const;
00042 virtual string get_extension(int n) const;
00043 virtual string get_suggested_extension() const;
00044
00045 virtual bool has_magic_number() const;
00046 virtual bool matches_magic_number(const string &magic_number) const;
00047
00048 virtual PNMReader *make_reader(istream *file, bool owns_file = true,
00049 const string &magic_number = string());
00050 virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
00051
00052 public:
00053 class Reader : public PNMReader {
00054 public:
00055 Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
00056 virtual ~Reader();
00057
00058 virtual bool supports_read_row() const;
00059 virtual bool read_row(xel *array, xelval *alpha, int x_size, int y_size);
00060
00061 private:
00062 xelval next_sample_lt_8(unsigned char *&buf_ptr, int &bits_left) const;
00063 xelval next_sample_8(unsigned char *&buf_ptr, int &bits_left) const;
00064 xelval next_sample_16(unsigned char *&buf_ptr, int &bits_left) const;
00065 xelval next_sample_32(unsigned char *&buf_ptr, int &bits_left) const;
00066 xelval next_sample_general(unsigned char *&buf_ptr, int &bits_left) const;
00067
00068 unsigned short photomet;
00069 unsigned short bps, spp;
00070 unsigned short unassoc_alpha_sample, assoc_alpha_sample;
00071 xel colormap[TIFF_COLORMAP_MAXCOLORS];
00072
00073 int current_row;
00074 struct tiff *tif;
00075 };
00076
00077 class Writer : public PNMWriter {
00078 public:
00079 Writer(PNMFileType *type, ostream *file, bool owns_file);
00080
00081 virtual int write_data(xel *array, xelval *alpha);
00082 };
00083
00084 private:
00085 static void install_error_handlers();
00086
00087 static void tiff_warning(const char *module, const char *format, va_list ap);
00088 static void tiff_error(const char *module, const char *format, va_list ap);
00089 static bool _installed_error_handlers;
00090
00091
00092 public:
00093 static void register_with_read_factory();
00094
00095 protected:
00096 static TypedWritable *make_PNMFileTypeTIFF(const FactoryParams ¶ms);
00097
00098 public:
00099 static TypeHandle get_class_type() {
00100 return _type_handle;
00101 }
00102 static void init_type() {
00103 PNMFileType::init_type();
00104 register_type(_type_handle, "PNMFileTypeTIFF",
00105 PNMFileType::get_class_type());
00106 }
00107 virtual TypeHandle get_type() const {
00108 return get_class_type();
00109 }
00110 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00111
00112 private:
00113 static TypeHandle _type_handle;
00114 };
00115
00116 #endif // HAVE_TIFF
00117
00118 #endif