#ifndef CVD_INTERNAL_IO_PNG_H #define CVD_INTERNAL_IO_PNG_H #include #include #include #include #include #include #include namespace CVD { namespace PNG { using CVD::Internal::Head; using CVD::Internal::TypeList; class PNGPimpl; class WriterPimpl; 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(Rgb*); void get_raw_pixel_line(Rgb*); void get_raw_pixel_line(Rgba*); void get_raw_pixel_line(Rgba*); std::string datatype(); std::string name(); typedef TypeList, TypeList, TypeList, TypeList, Head>>>>>>> Types; static bool first_byte_matches(const int b) { return b == 0x89; } private: std::unique_ptr p; }; //////////////////////////////////////////////////////////////////////////////// // // How to convert Misc types in to PNG compatible types // //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 unsigned short 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 Rgb8 type; }; class png_writer { public: png_writer(std::ostream&, ImageRef size, const std::string& type, const std::map>& p); ~png_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 Rgb*); void write_raw_pixel_line(const Rgb8*); void write_raw_pixel_line(const Rgb*); 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 p; }; } } #endif