2105: Add the ability to load images of built-in (POD) values.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Add the ability to load images of built-in (POD) values. * mln/io/pnm/load.hh (mln::io::pnm::read_value(std::ifstream&, V&): Turn into... (mln::io::pnm::read_value(std::ifstream&, value::Scalar<V>&)): ...this. (mln::io::pnm::read_value(std::ifstream&, V&): New overload. * mln/value/int_u8.hh (mln::io::pnm::int_u8): Use a fully qualified type name to help swig wrap this typedef. * mln/io/pgm/save.hh: Typo in comment. io/pgm/save.hh | 2 +- io/pnm/load.hh | 28 ++++++++++++++++++---------- value/int_u8.hh | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) Index: mln/value/int_u8.hh --- mln/value/int_u8.hh (revision 2104) +++ mln/value/int_u8.hh (working copy) @@ -44,7 +44,7 @@ /// Alias for unsigned 8 bit integers. - typedef int_u<8> int_u8; + typedef mln::value::int_u<8> int_u8; } // end of namespace mln::value Index: mln/io/pgm/save.hh --- mln/io/pgm/save.hh (revision 2104) +++ mln/io/pgm/save.hh (working copy) @@ -78,7 +78,7 @@ inline void save(const Image<I>& ima, const std::string& filename) { - // FIXME : this is to restrictive. Check if I is compatible with PGM. + // FIXME : this is too restrictive. Check if I is compatible with PGM. // mln::metal::or_< // mln::metal::templated_by<mln_value(I), value::int_u >, // mln::metal::templated_by<mln_value(I), value::int_u_sat > Index: mln/io/pnm/load.hh --- mln/io/pnm/load.hh (revision 2104) +++ mln/io/pnm/load.hh (working copy) @@ -58,12 +58,13 @@ namespace pnm { + # ifndef MLN_INCLUDE_ONLY - //read a rgb value (sizeof(int_u8) != 1) + + // Read a Milena rgb value (sizeof(int_u8) != 1). template <unsigned int n> inline - void read_value(std::ifstream& file, - value::rgb<n>& v) + void read_value(std::ifstream& file, value::rgb<n>& v) { typedef typename value::int_u<n>::enc E; @@ -76,25 +77,32 @@ v.blue() = c; } - - //read a scalar value (sizeof(int_u8) != 1) + // Read a Milena scalar value (sizeof(int_u8) != 1). template <class V> inline - void read_value(std::ifstream& file, - V& v) + void read_value(std::ifstream& file, value::Scalar<V>& v) { - typedef typename V::enc E; // FIXME : if V = int + typedef typename V::enc E; E c; file.read((char*)(&c), sizeof(E)); + exact(v) = c; + } + + // Read a builtin scalar value. + template <typename V> + inline + void read_value(std::ifstream& file, V& v) + { + V c; + file.read((char*)(&c), sizeof(V)); v = c; } // used when (sizeof(int_u8) != 1) template <typename V> inline - void load_raw_2d_uncontiguous(std::ifstream& file, - image2d<V>& ima) + void load_raw_2d_uncontiguous(std::ifstream& file, image2d<V>& ima) { const int min_row = geom::min_row(ima),
participants (1)
-
Roland Levillain