* mln/io/magick/get_header.hh,
* mln/tests/io/magick/get_header.cc: New
* mln/tests/io/magick/Makefile.am: New target.
---
milena/ChangeLog | 9 ++
.../mln/io/{pgms/load.hh => magick/get_header.hh} | 86 +++++++++++++-------
milena/tests/io/magick/Makefile.am | 1 +
.../tests/io/magick/get_header.cc | 45 +++++++----
4 files changed, 94 insertions(+), 47 deletions(-)
copy milena/mln/io/{pgms/load.hh => magick/get_header.hh} (50%)
copy scribo/tests/primitive/extract/lines_h_pattern.cc =>
milena/tests/io/magick/get_header.cc (59%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index edf3a65..1e49435 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,12 @@
+2013-04-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add a new routine to get image headers thanks to GraphicsMagick.
+
+ * mln/io/magick/get_header.hh,
+ * mln/tests/io/magick/get_header.cc: New
+
+ * mln/tests/io/magick/Makefile.am: New target.
+
2013-04-17 Guillaume Lazzara <z(a)lrde.epita.fr>
* doc/mln/convert.dox: Fix from_to_ module name.
diff --git a/milena/mln/io/pgms/load.hh b/milena/mln/io/magick/get_header.hh
similarity index 50%
copy from milena/mln/io/pgms/load.hh
copy to milena/mln/io/magick/get_header.hh
index ce54224..b34c5f3 100644
--- a/milena/mln/io/pgms/load.hh
+++ b/milena/mln/io/magick/get_header.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,23 +23,23 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_IO_PGMS_LOAD_HH
-# define MLN_IO_PGMS_LOAD_HH
+#ifndef MLN_IO_MAGICK_GET_HEADER_HH
+# define MLN_IO_MAGICK_GET_HEADER_HH
/// \file
///
-/// \brief Define a function which loads multiple pgm images into
-/// a 3D image.
+/// \brief Routines reading image headers based on Magick++.
-# include <iostream>
-# include <fstream>
-# include <string>
+# include <cstdlib>
+
+# include <Magick++.h>
# include <mln/core/image/image2d.hh>
-# include <mln/core/image/image3d.hh>
+
# include <mln/value/int_u8.hh>
-# include <mln/io/pnms/load.hh>
-# include <mln/make/image3d.hh>
+# include <mln/value/rgb8.hh>
+
+# include <mln/io/magick/internal/init_magick.hh>
namespace mln
@@ -49,42 +48,67 @@ namespace mln
namespace io
{
- namespace pgms
+ namespace magick
{
- /*! \brief Load pgm images as slices of a 3D Milena image.
- *
- * \param[out] ima A reference to the 3D image which will receive
- * data.
- * \param[in] filenames The list of 2D images to load..
- *
- * \ingroup iopgm
- */
- template <typename V>
- void load(image3d<V>& ima,
- const util::array<std::string>& filenames);
+ /*!
+ \brief Store magick file header.
+ \ingroup iomagick
+ */
+ struct magick_header
+ {
+ int height;
+ int width;
+ unsigned depth;
+ Magick::ImageType image_type;
+ };
+
+
+ /*! \brief Get image header from a file using Magick++.
+
+ \param[in] filename The name of the input file.
+
+ \return A structure with several header information.
+
+ \ingroup iomagick
+ */
+ magick_header get_header(const std::string& filename);
+
# ifndef MLN_INCLUDE_ONLY
- template <typename V>
inline
- void load(image3d<V>& ima,
- const util::array<std::string>& filenames)
+ magick_header get_header(const std::string& filename)
{
- mln_trace("mln::io::pgms::load");
+ mln_trace("mln::io::magick::get_header");
- io::pnms::load<V>(PGM, ima, filenames);
+ // Initialize GraphicsMagick only once.
+ static internal::init_magick init;
+ (void) init;
+ // FIXME: Handle Magick++'s exceptions (see either
+ // ImageMagick++'s or GraphicsMagick++'s documentation).
+ Magick::Image magick_ima(filename);
+ magick_ima.ping(filename);
+
+ magick_header header;
+ header.height = magick_ima.rows();
+ header.width = magick_ima.columns();
+ header.depth = magick_ima.depth();
+ header.image_type = magick_ima.type();
+
+ return header;
}
+
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::io::pgms
+ } // end of namespace mln::io::magick
} // end of namespace mln::io
} // end of namespace mln
-#endif // ! MLN_IO_PGMS_LOAD_HH
+#endif // ! MLN_IO_MAGICK_GET_HEADER_HH
diff --git a/milena/tests/io/magick/Makefile.am b/milena/tests/io/magick/Makefile.am
index cad11e9..e0221d7 100644
--- a/milena/tests/io/magick/Makefile.am
+++ b/milena/tests/io/magick/Makefile.am
@@ -20,6 +20,7 @@ AM_CPPFLAGS += $(MAGICKXX_CPPFLAGS)
AM_LDFLAGS = $(MAGICKXX_LDFLAGS)
check_PROGRAMS = \
+ get_header \
load \
save
diff --git a/scribo/tests/primitive/extract/lines_h_pattern.cc
b/milena/tests/io/magick/get_header.cc
similarity index 59%
copy from scribo/tests/primitive/extract/lines_h_pattern.cc
copy to milena/tests/io/magick/get_header.cc
index 64c09f8..f5f048b 100644
--- a/scribo/tests/primitive/extract/lines_h_pattern.cc
+++ b/milena/tests/io/magick/get_header.cc
@@ -23,29 +23,42 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-// \file
-
-#include <mln/core/image/image2d.hh>
-#include <mln/data/compare.hh>
-#include <mln/io/pbm/load.hh>
-#include <scribo/primitive/extract/lines_h_pattern.hh>
-
+#include <iostream>
+#include <mln/io/magick/get_header.hh>
#include "tests/data.hh"
int main()
{
using namespace mln;
- using namespace scribo;
- image2d<bool> input;
- io::pbm::load(input, SCRIBO_IMG_DIR "/lines_discontinued.pbm");
+ // PBM.
+ {
+ io::magick::magick_header
+ header = io::magick::get_header(MLN_IMG_DIR "/tiny.pbm");
+ mln_assertion(header.width == 18);
+ mln_assertion(header.height == 22);
+ mln_assertion(header.depth == 1);
+ mln_assertion(header.image_type == 1);
+ }
- image2d<bool> ref;
- io::pbm::load(ref,
- SCRIBO_TESTS_DIR "/primitive/extract/lines_h_pattern.ref.pbm");
+ // PGM.
+ {
+ io::magick::magick_header
+ header = io::magick::get_header(MLN_IMG_DIR "/tiny.pgm");
+ mln_assertion(header.width == 16);
+ mln_assertion(header.height == 16);
+ mln_assertion(header.depth == 8);
+ mln_assertion(header.image_type == 2);
+ }
- image2d<bool>
- vlines = primitive::extract::lines_h_pattern(input, 51, 3);
+ // PPM.
+ {
+ io::magick::magick_header
+ header = io::magick::get_header(MLN_IMG_DIR "/tiny.ppm");
+ mln_assertion(header.width == 16);
+ mln_assertion(header.height == 16);
+ mln_assertion(header.depth == 8);
+ mln_assertion(header.image_type == 6);
+ }
- mln_assertion(vlines == ref);
}
--
1.7.2.5