#ifndef PNM_TIFF #define PNM_TIFF #include #include #include #include #include #include namespace CVD { namespace TIFF { using CVD::Internal::Head; using CVD::Internal::TypeList; //////////////////////////////////////////////////////////////////////////////// // // TIFF reading // class TIFFPimpl; class Reader { public: Reader(std::istream&); ~Reader(); ImageRef size(); bool top_row_first(); void get_raw_pixel_line(bool*); void get_raw_pixel_line(unsigned char*); void get_raw_pixel_line(unsigned short*); void get_raw_pixel_line(float*); void get_raw_pixel_line(double*); void get_raw_pixel_line(Rgb*); void get_raw_pixel_line(Rgb*); void get_raw_pixel_line(Rgb*); void get_raw_pixel_line(Rgb*); void get_raw_pixel_line(Rgba*); void get_raw_pixel_line(Rgba*); void get_raw_pixel_line(Rgba*); void get_raw_pixel_line(Rgba*); std::string datatype(); std::string name(); typedef TypeList, TypeList, TypeList, TypeList, TypeList, TypeList, TypeList, TypeList, Head>>>>>>>>>>>>> Types; static bool first_byte_matches(const int c) { return c == 'I' || c == 'M'; } private: std::unique_ptr t; }; //////////////////////////////////////////////////////////////////////////////// // // TIFF writing // //This is a really nasty way of doing pattern matching for ranges of numbers. //The range is encoded un unary notation. The range is on some integer, x. //g1 is set if x > 1. g8 is set if x > 8 and so on. //This allows us to choose a type with a reasonable number of bits. template struct IntMapper { typedef unsigned short type; }; template <> struct IntMapper<1, 0> { typedef unsigned char type; }; template <> struct IntMapper<0, 0> { typedef bool type; }; //Mapping for integral types template struct ComponentMapper_ { typedef typename IntMapper< (Pixel::traits::bits_used > 1), (Pixel::traits::bits_used > 8)>::type type; }; //Mapping for non integral types template struct ComponentMapper_ { typedef double type; }; template <> struct ComponentMapper_ { typedef float type; }; template struct ComponentMapper { typedef typename ComponentMapper_::integral>::type type; }; //Mapping for Rgbish types template struct ComponentMapper> { typedef Rgb::integral>::type> type; }; template struct ComponentMapper> { typedef Rgba::integral>::type> type; }; template <> struct ComponentMapper { typedef Rgb type; }; class TIFFWritePimpl; class tiff_writer { public: tiff_writer(std::ostream&, ImageRef size, const std::string& type, const std::map>& p); ~tiff_writer(); void write_raw_pixel_line(const bool*); void write_raw_pixel_line(const unsigned char*); void write_raw_pixel_line(const unsigned short*); void write_raw_pixel_line(const float*); void write_raw_pixel_line(const double*); void write_raw_pixel_line(const Rgb*); void write_raw_pixel_line(const Rgb*); void write_raw_pixel_line(const Rgb*); void write_raw_pixel_line(const Rgb*); void write_raw_pixel_line(const Rgba*); void write_raw_pixel_line(const Rgba*); void write_raw_pixel_line(const Rgba*); void write_raw_pixel_line(const Rgba*); template struct Outgoing { typedef typename ComponentMapper::type type; }; static const int top_row_first = 1; private: std::unique_ptr t; }; } } #endif