URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-27 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix a bug in p(g|p)m load.
* mln/io/pnm/load.hh: (load(image&, filename)) now work on rgb images.
* mln/io/pnm/max_component.hh: Define a function which give the max of
the component of a value type.
* tests/io/pgm/pgm16.cc: Now test the other way to load an image
(load(image&, filename)).
* tests/io/ppm/ppm16.cc: likewise.
* img/lena_16.ppm: New, lena, ppm 16 bits.
---
mln/io/pnm/load.hh | 12 ++++--
mln/io/pnm/max_component.hh | 77 ++++++++++++++++++++++++++++++++++++++++++++
tests/io/pgm/pgm16.cc | 12 ++++++
tests/io/ppm/ppm16.cc | 12 ++++++
4 files changed, 107 insertions(+), 6 deletions(-)
Index: trunk/milena/tests/io/pgm/pgm16.cc
===================================================================
--- trunk/milena/tests/io/pgm/pgm16.cc (revision 1547)
+++ trunk/milena/tests/io/pgm/pgm16.cc (revision 1548)
@@ -72,6 +72,7 @@
using value::int_u8;
using value::int_u16;
+ {
win::rectangle2d rect(51, 51);
border::thickness = 52;
@@ -90,6 +91,17 @@
level::transform(lena2, to8bits(), out2);
io::pgm::save(out2, "out8.pgm");
+ }
+ {
+ // Abort
+// image2d< value::int_u<8> > a;
+// io::pgm::load(a, "out16.pgm");
+
+ image2d< value::int_u<16> > b;
+ io::pgm::load(b, "out16.pgm");
+
+ }
+
}
Index: trunk/milena/tests/io/ppm/ppm16.cc
===================================================================
--- trunk/milena/tests/io/ppm/ppm16.cc (revision 1547)
+++ trunk/milena/tests/io/ppm/ppm16.cc (revision 1548)
@@ -78,7 +78,7 @@
typedef image2d<rgb8> I;
-
+ {
// load a 8bits image A
image2d<rgb8>
a = io::ppm::load<rgb8>("../../../img/lena.ppm");
@@ -106,5 +106,15 @@
// D should equals A
mln_assertion(d == a);
+ }
+
+ {
+ // Abort
+// image2d<rgb8> a;
+// io::ppm::load(a, "../../../img/lena_16.ppm");
+ image2d< value::rgb<16> > b;
+ io::ppm::load(b, "../../../img/lena_16.ppm");
+
+ }
}
Index: trunk/milena/mln/io/pnm/max_component.hh
===================================================================
--- trunk/milena/mln/io/pnm/max_component.hh (revision 0)
+++ trunk/milena/mln/io/pnm/max_component.hh (revision 1548)
@@ -0,0 +1,77 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
+// Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_IO_PNM_MAX_COMPONENT_HH
+# define MLN_IO_PNM_MAX_COMPONENT_HH
+
+/*!
+ * \file mln/io/pnm/max_component.hh
+ *
+ * \brief Define a function which give the max of the component of a
+ * value type.
+ */
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace pnm
+ {
+ template <typename V>
+ unsigned int max_component();
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ unsigned int max_component(const V&)
+ {
+ return mln_max(V);
+ }
+
+# ifdef MLN_VALUE_RGB_HH
+
+ template <unsigned n>
+ unsigned int max_component(const mln::value::rgb<n>&)
+ {
+ return mln_max( mln::value::int_u<n> );
+ }
+
+# endif
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::pnm
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+
+#endif // ! MLN_IO_PNM_LOAD_HH
Index: trunk/milena/mln/io/pnm/load.hh
===================================================================
--- trunk/milena/mln/io/pnm/load.hh (revision 1547)
+++ trunk/milena/mln/io/pnm/load.hh (revision 1548)
@@ -46,6 +46,7 @@
# include <mln/value/rgb.hh>
# include <mln/io/pnm/load_header.hh>
+# include <mln/io/pnm/max_component.hh>
# include <mln/io/pnm/macros.hh>
namespace mln
@@ -189,15 +190,16 @@
read_header(type_ - 3, type_, file, type,
nrows, ncols, maxval);
- if (mln_max(mln_value(I)) != maxval)
+ if (max_component(mln_value(I)()) != maxval)
{
- std::cerr << "max ref : " << mln_max(mln_value(I))
- << "max image : " << maxval
- << std::endl;
-
std::cerr << "error: file '" << filename
<< "' cannot be loaded into this type of image"
<< std::endl;
+
+ std::cerr << "input image have " << maxval
+ << " as maximum value while the destination's one is "
+ << max_component(mln_value(I)()) << "."
+ << std::endl;
abort();
}
Index: trunk/milena/img/lena_16.ppm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/milena/img/lena_16.ppm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream