URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog: 2007-11-28 Matthieu Garrigues garrigues@lrde.epita.fr
Review the mln/io directory. * mln/io/abort.hh, * mln/io/fits/load.hh, * mln/io/pbm/load.hh, * mln/io/pbm/save.hh, * mln/io/pfm/load.hh, * mln/io/pfm/save.hh, * mln/io/pgm/load.hh, * mln/io/pgm/save.hh, * mln/io/pnm/load.hh, * mln/io/pnm/load_header.hh, * mln/io/pnm/max_component.hh, * mln/io/pnm/save.hh, * mln/io/pnm/save_header.hh, * mln/io/ppm/load.hh, * mln/io/ppm/save.hh, * tests/io/ppm/ppm.cc: Add documentation, review the code, put MLN_INCLUDE_ONLY gards, add missing function declaration (outside MLN_INCLUDE_ONLY).
--- mln/io/abort.hh | 8 +++++++- mln/io/fits/load.hh | 29 +++++++++++++++++++++++++++++ mln/io/pbm/load.hh | 28 ++++++++++++++++++++++++++++ mln/io/pbm/save.hh | 5 +++++ mln/io/pfm/load.hh | 32 ++++++++++++++++++++++++++++---- mln/io/pfm/save.hh | 8 ++++++-- mln/io/pgm/load.hh | 32 +++++++++++++++++++++++++++----- mln/io/pgm/save.hh | 5 +++++ mln/io/pnm/load.hh | 2 +- mln/io/pnm/load_header.hh | 3 +++ mln/io/pnm/max_component.hh | 4 +++- mln/io/pnm/save.hh | 1 - mln/io/pnm/save_header.hh | 12 +++--------- mln/io/ppm/load.hh | 31 ++++++++++++++++++++++++++----- mln/io/ppm/save.hh | 5 +++++ tests/io/ppm/ppm.cc | 6 ++++-- 16 files changed, 180 insertions(+), 31 deletions(-)
Index: trunk/milena/tests/io/ppm/ppm.cc =================================================================== --- trunk/milena/tests/io/ppm/ppm.cc (revision 1567) +++ trunk/milena/tests/io/ppm/ppm.cc (revision 1568) @@ -46,8 +46,10 @@ using namespace mln; using value::rgb8;
- image2d<rgb8> lena = io::ppm::load("../../../img/lena.ppm"); + image2d<rgb8> lena = io::ppm::load<rgb8>("../../../img/lena.ppm"); io::ppm::save(lena, "out.ppm"); - image2d<rgb8> lena2 = io::ppm::load("out.ppm"); + + image2d<rgb8> lena2; + io::ppm::load(lena2, "out.ppm"); mln_assertion(lena2 == lena); } Index: trunk/milena/mln/io/pfm/save.hh =================================================================== --- trunk/milena/mln/io/pfm/save.hh (revision 1567) +++ trunk/milena/mln/io/pfm/save.hh (revision 1568) @@ -54,9 +54,15 @@ namespace pfm {
+ /*! Save a milena image as a pfm image. + * + * \param[in] ima The image to save. + * \param[in,out] filename the destination. + */ template <typename I> void save(const Image<I>& ima, const std::string& filename);
+# ifndef MLN_INCLUDE_ONLY
namespace impl { @@ -94,8 +100,6 @@
} // end of namespace mln::io::impl
-# ifndef MLN_INCLUDE_ONLY - template <typename I> void save(const Image<I>& ima, const std::string& filename) { Index: trunk/milena/mln/io/pfm/load.hh =================================================================== --- trunk/milena/mln/io/pfm/load.hh (revision 1567) +++ trunk/milena/mln/io/pfm/load.hh (revision 1568) @@ -37,10 +37,6 @@ * */
-// # include <iostream> -// # include <fstream> -// # include <string> - # include <mln/core/image2d.hh> # include <mln/value/int_u8.hh>
@@ -54,6 +50,25 @@ namespace pfm {
+ /*! Load a pfm image in a milena image. + * + * \param[out] ima A reference to the image2d<float> which will receive + * data. + * \param[in] filename The source. + */ + void load(image2d<float>& ima, + const std::string& filename); + + /*! Load a pfm image in a image2d<float>. + * + * \param[in] filename The image source. + * + * \return An image2d<float> which contains loaded data. + */ + image2d<float> load(const std::string& filename); + +# ifndef MLN_INCLUDE_ONLY + namespace internal {
@@ -136,6 +151,15 @@ return ima; }
+ + void load(image2d<float>& ima, + const std::string& filename) + { + ima = load(filename); + } + +# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::io::pfm
} // end of namespace mln::io Index: trunk/milena/mln/io/pgm/save.hh =================================================================== --- trunk/milena/mln/io/pgm/save.hh (revision 1567) +++ trunk/milena/mln/io/pgm/save.hh (revision 1568) @@ -63,6 +63,11 @@ namespace pgm {
+ /*! Save a milena image as a pgm image. + * + * \param[in] ima The image to save. + * \param[in,out] filename the destination. + */ template <typename I> void save(const Image<I>& ima, const std::string& filename);
Index: trunk/milena/mln/io/pgm/load.hh =================================================================== --- trunk/milena/mln/io/pgm/load.hh (revision 1567) +++ trunk/milena/mln/io/pgm/load.hh (revision 1568) @@ -57,23 +57,45 @@ namespace pgm {
+ /*! Load a pgm image in a milena image. + * + * \param[out] ima A reference to the image which will receive + * data. + * \param[in] filename The source. + */ + template <typename I> + void load(Image<I>& ima, + const std::string& filename); + + + /*! Load a pgm image in a milena image. To use this routine, you + * should specialize the template whith the value type of the + * image loaded. (ex : loadvalue::int_u8("...") ) + * + * \param[in] filename The image source. + * + * \return An image2d which contains loaded data. + */ + template <typename V> + image2d<V> load(const std::string& filename); + +# ifndef MLN_INCLUDE_ONLY + template <typename V> image2d<V> load(const std::string& filename) { return io::pnm::load<V>(PGM, filename); }
- image2dvalue::int_u8 load(const std::string& filename) - { - return loadvalue::int_u8(filename); - } - template <typename I> void load(Image<I>& ima, const std::string& filename) { io::pnm::load<I>(PGM, ima, filename); } + +# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::io::pgm
} // end of namespace mln::io Index: trunk/milena/mln/io/abort.hh =================================================================== --- trunk/milena/mln/io/abort.hh (revision 1567) +++ trunk/milena/mln/io/abort.hh (revision 1568) @@ -44,13 +44,19 @@
namespace internal { + /// The way to abort when an error occur in io processing. + void abort() + +# ifndef MLN_INCLUDE_ONLY
void abort() { - std::cerr << " aborting." << std::endl; + std::cerr << "I/O error, aborting." << std::endl; exit(0); }
+# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::io::internal
} // end of namespace mln::io Index: trunk/milena/mln/io/fits/load.hh =================================================================== --- trunk/milena/mln/io/fits/load.hh (revision 1567) +++ trunk/milena/mln/io/fits/load.hh (revision 1568) @@ -51,8 +51,29 @@ namespace io {
+ namespace fits { + + /*! Load a fits image in a milena image. + * + * \param[out] ima A reference to the image2d<float> which will receive + * data. + * \param[in] filename The source. + */ + void load(image2d<float>& ima, + const std::string& filename); + + /*! Load a fits image in a image2d<float>. + * + * \param[in] filename The image source. + * + * \return An image2d<float> which contains loaded data. + */ + image2d<float> load(const std::string& filename); + +# ifndef MLN_INCLUDE_ONLY + void fits_exit(int status) { if (status) @@ -104,6 +125,14 @@ return output; }
+ void load(image2d<float>& ima, + const std::string& filename) + { + ima = load(filename); + } + +# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::io::fits
} // end of namespace mln::io Index: trunk/milena/mln/io/pnm/save_header.hh =================================================================== --- trunk/milena/mln/io/pnm/save_header.hh (revision 1567) +++ trunk/milena/mln/io/pnm/save_header.hh (revision 1568) @@ -39,6 +39,8 @@ # include <iostream> # include <fstream>
+# include <mln/io/pnm/max_component.hh> + # include <mln/value/rgb.hh> # include <mln/geom/nrows.hh> # include <mln/geom/ncols.hh> @@ -57,21 +59,13 @@ template <typename V> void save_max_val(V&, std::ofstream& file) { - file << mln_max(V) << std::endl; + file << max_component(V()) << std::endl; }
void save_max_val(bool&, std::ofstream& file) { }
- template <unsigned int n> - void save_max_val(value::rgb<n>&, std::ofstream& file) - { - typedef typename value::int_u<n>::enc E; - - file << unsigned(mln_max(E)) << std::endl; - } - template <typename I> void save_header(const char type, const I& ima, const std::string& filename, Index: trunk/milena/mln/io/pnm/max_component.hh =================================================================== --- trunk/milena/mln/io/pnm/max_component.hh (revision 1567) +++ trunk/milena/mln/io/pnm/max_component.hh (revision 1568) @@ -44,8 +44,10 @@
namespace pnm { + /// Give the maximum value which can be stored as a component + /// value type V. template <typename V> - unsigned int max_component(); + unsigned int max_component(const V&);
# ifndef MLN_INCLUDE_ONLY
Index: trunk/milena/mln/io/pnm/load_header.hh =================================================================== --- trunk/milena/mln/io/pnm/load_header.hh (revision 1567) +++ trunk/milena/mln/io/pnm/load_header.hh (revision 1568) @@ -49,6 +49,7 @@ namespace pnm {
+# ifndef MLN_INCLUDE_ONLY
bool read_header(std::ifstream& istr, char& type, @@ -125,6 +126,8 @@ nrows, ncols, maxval); }
+# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::io::pnm
} // end of namespace mln::io Index: trunk/milena/mln/io/pnm/save.hh =================================================================== --- trunk/milena/mln/io/pnm/save.hh (revision 1567) +++ trunk/milena/mln/io/pnm/save.hh (revision 1568) @@ -71,7 +71,6 @@ * \param[in] ima_ The image to save. * \param[in,out] filename the destination. */ - template <typename I> void save(const int type, const Image<I>& ima_, const std::string& filename);
Index: trunk/milena/mln/io/pnm/load.hh =================================================================== --- trunk/milena/mln/io/pnm/load.hh (revision 1567) +++ trunk/milena/mln/io/pnm/load.hh (revision 1568) @@ -179,7 +179,7 @@
}
- /// a new function to load pnm files : + /// An other way to load pnm files : /// the destination is an argument to check if /// the type match the file to load. template <typename I> Index: trunk/milena/mln/io/ppm/save.hh =================================================================== --- trunk/milena/mln/io/ppm/save.hh (revision 1567) +++ trunk/milena/mln/io/ppm/save.hh (revision 1568) @@ -52,6 +52,11 @@ namespace ppm {
+ /*! Save a milena image as a ppm image. + * + * \param[in] ima The image to save. + * \param[in,out] filename the destination. + */ template <typename I> void save(const Image<I>& ima, const std::string& filename);
Index: trunk/milena/mln/io/ppm/load.hh =================================================================== --- trunk/milena/mln/io/ppm/load.hh (revision 1567) +++ trunk/milena/mln/io/ppm/load.hh (revision 1568) @@ -54,17 +54,36 @@
namespace ppm { + + /*! Load a ppm image in a milena image. + * + * \param[out] ima A reference to the image which will receive + * data. + * \param[in] filename The source. + */ + template <typename I> + void load(Image<I>& ima, + const std::string& filename); + + /*! Load a ppm image in a milena image. To use this routine, you + * should specialize the template whith the value type of the + * image loaded. (ex : loadvalue::int_u8("...") ) + * + * \param[in] filename The image source. + * + * \return An image2d which contains loaded data. + */ + template <typename V> + image2d<V> load(const std::string& filename); + +# ifndef MLN_INCLUDE_ONLY + template <typename V> image2d<V> load(const std::string& filename) { return io::pnm::load<V>(PPM, filename); }
- image2dvalue::rgb8 load(const std::string& filename) - { - return loadvalue::rgb8(filename); - } - template <typename I> void load(Image<I>& ima, const std::string& filename) @@ -72,6 +91,8 @@ io::pnm::load<I>(PPM, ima, filename); }
+# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::io::ppm
} // end of namespace mln::io Index: trunk/milena/mln/io/pbm/save.hh =================================================================== --- trunk/milena/mln/io/pbm/save.hh (revision 1567) +++ trunk/milena/mln/io/pbm/save.hh (revision 1568) @@ -63,6 +63,11 @@ namespace pbm {
+ /*! Save a milena image as a pbm image. + * + * \param[in] ima The image to save. + * \param[in,out] filename the destination. + */ template <typename I> void save(const Image<I>& ima, const std::string& filename);
Index: trunk/milena/mln/io/pbm/load.hh =================================================================== --- trunk/milena/mln/io/pbm/load.hh (revision 1567) +++ trunk/milena/mln/io/pbm/load.hh (revision 1568) @@ -54,6 +54,26 @@ namespace pbm {
+ + /*! Load a pbm image in a milena image. + * + * \param[out] ima A reference to the image2d<bool> which will receive + * data. + * \param[in] filename The source. + */ + void load(image2d<bool>& ima, + const std::string& filename); + + /*! Load a pbm image in a image2d<float>. + * + * \param[in] filename The image source. + * + * \return An image2d<float> which contains loaded data. + */ + image2d<bool> load(const std::string& filename); + +# ifndef MLN_INCLUDE_ONLY + namespace internal {
@@ -128,6 +148,14 @@ }
+ void load(image2d<bool>& ima, + const std::string& filename) + { + ima = load(filename); + } + +# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::io::pbm
} // end of namespace mln::io