* mln/io/pnm/load.hh: Use the value equivalent type to read
data correctly.
---
milena/ChangeLog | 7 ++++++
milena/mln/io/pnm/load.hh | 53 +++++++++++++++++++++++++++++++++++++++++---
2 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index efc8740..28a4127 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2009-04-28 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Fix ambiguities while loading PGM images into label values.
+
+ * mln/io/pnm/load.hh: Use the value equivalent type to read
+ data correctly.
+
+2009-04-28 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Small fixes (again).
* headers.mk: update distributed file list.
diff --git a/milena/mln/io/pnm/load.hh b/milena/mln/io/pnm/load.hh
index a5d591e..be37c51 100644
--- a/milena/mln/io/pnm/load.hh
+++ b/milena/mln/io/pnm/load.hh
@@ -47,6 +47,8 @@
# include <mln/io/pnm/max_component.hh>
# include <mln/io/pnm/macros.hh>
+# include <mln/metal/is_a.hh>
+
namespace mln
{
@@ -59,6 +61,35 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
+ template <typename I>
+ void load_ascii_value(std::ifstream& file, I& ima);
+
+ template <typename I>
+ void load_ascii_builtin(std::ifstream& file, I& ima);
+
+
+ namespace internal
+ {
+
+ template <typename I>
+ inline
+ void
+ load_ascii_dispatch(std::ifstream& file, I& ima, const
metal::bool_<true>&)
+ {
+ load_ascii_value(file, ima);
+ }
+
+ template <typename I>
+ inline
+ void
+ load_ascii_dispatch(std::ifstream& file, I& ima, const
metal::bool_<false>&)
+ {
+ load_ascii_builtin(file, ima);
+ }
+
+ } // end of namespace mln::io::pnm::internal
+
+
// Read a Milena rgb value (sizeof(int_u8) != 1).
template <unsigned int n>
inline
@@ -130,10 +161,24 @@ namespace mln
file.read((char*)(&ima(p)), len);
}
- /// load_ascii.
+ /// load_ascii for Milena value types.
+ template <typename I>
+ inline
+ void load_ascii_value(std::ifstream& file, I& ima)
+ {
+ mln_equiv(mln_value_(I)) c;
+ mln_fwd_piter(I) p(ima.domain());
+ for_all(p)
+ {
+ file >> c;
+ ima(p) = c;
+ }
+ }
+
+ /// load_ascii for builtin value types.
template <typename I>
inline
- void load_ascii(std::ifstream& file, I& ima)
+ void load_ascii_builtin(std::ifstream& file, I& ima)
{
mln_fwd_piter(I) p(ima.domain());
for_all(p)
@@ -190,7 +235,7 @@ namespace mln
load_raw_2d(file, ima);
else
if (type == (type_ - 3))
- pnm::load_ascii(file, ima);
+ pnm::internal::load_ascii_dispatch(file, ima, mlc_is_a(V, mln::Value)());
trace::exiting("mln::io::pnm::load");
@@ -242,7 +287,7 @@ namespace mln
load_raw_2d(file, ima);
else
if (type == (type_ - 3))
- pnm::load_ascii(file, ima);
+ pnm::internal::load_ascii_dispatch(file, ima, mlc_is_a(mln_value(I),
mln::Value)());
trace::exiting("mln::io::pnm::load");
}
--
1.5.6.5