
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-11-27 Matthieu Garrigues <garrigues@lrde.epita.fr> Add an error of incompatible types in pnm loading. * mln/io/pnm/load.hh: io::ppm::load<rgb8>("image16bits.ppm") now abort because we can't store rgb 16 bits into rgb 8 bits (likewise for pgm). * tests/io/ppm/ppm16.cc: Add some tests due to this update. --- mln/io/pnm/load.hh | 13 +++++++++++++ tests/io/ppm/ppm16.cc | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) Index: trunk/milena/tests/io/ppm/ppm16.cc =================================================================== --- trunk/milena/tests/io/ppm/ppm16.cc (revision 1548) +++ trunk/milena/tests/io/ppm/ppm16.cc (revision 1549) @@ -117,4 +117,21 @@ io::ppm::load(b, "../../../img/lena_16.ppm"); } + + { + // Abort +// image2d< value::rgb<8> > a = +// io::ppm::load("../../../img/lena_16.ppm"); + + // Abort +// image2d< value::rgb<16> > a = +// io::ppm::load< value::rgb<16> >("../../../img/lena.ppm"); + + image2d< value::rgb<16> > a = + io::ppm::load< value::rgb<16> >("../../../img/lena_16.ppm"); + + image2d< value::rgb<8> > b = + io::ppm::load< value::rgb<8> >("../../../img/lena.ppm"); + + } } Index: trunk/milena/mln/io/pnm/load.hh =================================================================== --- trunk/milena/mln/io/pnm/load.hh (revision 1548) +++ trunk/milena/mln/io/pnm/load.hh (revision 1549) @@ -156,6 +156,19 @@ read_header(type_ - 3, type_, file, type, nrows, ncols, maxval); + if (max_component(V()) != maxval) + { + 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(V()) << " (should be the same)." + << std::endl; + abort(); + } + image2d<V> ima(nrows, ncols); if (type == type_) load_raw_2d(file, ima);