#ifndef PNM_GROK_H #define PNM_GROK_H #include #include #include #include #include #include #include namespace CVD { namespace PNM { class pnm_in; using CVD::Internal::Head; using CVD::Internal::TypeList; 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*); std::string datatype(); std::string name(); typedef TypeList, TypeList, Head>>>>> Types; static bool first_byte_matches(const int b) { return b == 'P'; } private: std::unique_ptr p; }; //////////////////////////////////////////////////////////////////////////////// // // PNM writing. // template struct ComponentMapper { typedef Rgb type; }; template <> struct ComponentMapper<1, 0> { typedef Rgb type; }; template <> struct ComponentMapper<0, 1> { typedef byte type; }; template <> struct ComponentMapper<0, 0> { typedef unsigned short type; }; class pnm_writer; class Writer { public: Writer(std::ostream&, ImageRef size, const std::string& type, const std::map>& p); ~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 Rgb*); template struct Outgoing { typedef typename Pixel::Component::type Element; typedef typename ComponentMapper::value, std::numeric_limits::is_integer && std::numeric_limits::digits <= 8>::type type; }; static const int top_row_first = 1; private: std::unique_ptr p; }; } } #endif