* mln/io/magick/internal/init_magick.hh: New.
* mln/io/magick/load.hh,
* mln/io/magick/save.hh: Use init_magick struct and update doc.
* tests/io/magick/load.cc,
* tests/io/magick/save.cc: Remove references to InitializeMagick.
---
milena/ChangeLog | 12 +++++
.../{abort.hh => magick/internal/init_magick.hh} | 43 ++++++++++---------
milena/mln/io/magick/load.hh | 31 +++-----------
milena/mln/io/magick/save.hh | 32 +++-----------
milena/tests/io/magick/load.cc | 18 +-------
milena/tests/io/magick/save.cc | 19 +--------
6 files changed, 53 insertions(+), 102 deletions(-)
copy milena/mln/io/{abort.hh => magick/internal/init_magick.hh} (71%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 277a65d..92f8ad0 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,15 @@
+2013-03-15 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Automatically initialize GraphicsMagick.
+
+ * mln/io/magick/internal/init_magick.hh: New.
+
+ * mln/io/magick/load.hh,
+ * mln/io/magick/save.hh: Use init_magick struct and update doc.
+
+ * tests/io/magick/load.cc,
+ * tests/io/magick/save.cc: Remove references to InitializeMagick.
+
2013-03-08 Guillaume Lazzara <z(a)lrde.epita.fr>
* doc/img/2dgrid.png: New. Add missing file.
diff --git a/milena/mln/io/abort.hh b/milena/mln/io/magick/internal/init_magick.hh
similarity index 71%
copy from milena/mln/io/abort.hh
copy to milena/mln/io/magick/internal/init_magick.hh
index 9d06e7b..35a64a2 100644
--- a/milena/mln/io/abort.hh
+++ b/milena/mln/io/magick/internal/init_magick.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,16 +23,14 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_IO_ABORT_HH
-# define MLN_IO_ABORT_HH
+#ifndef MLN_IO_MAGICK_INTERNAL_INIT_MAGICK_HH
+# define MLN_IO_MAGICK_INTERNAL_INIT_MAGICK_HH
/// \file
+///
+/// \brief Initialize GraphicsMagick library.
-/// Define a function which aborts a process in io module.
-
-# include <cstdlib>
-# include <iostream>
-
+# include <Magick++.h>
namespace mln
{
@@ -41,27 +38,33 @@ namespace mln
namespace io
{
- namespace internal
+ namespace magick
{
- /// The way to abort when an error occur in io processing.
- void abort();
+ namespace internal
+ {
+
+ struct init_magick
+ {
+ init_magick();
+ };
# ifndef MLN_INCLUDE_ONLY
- inline
- void abort()
- {
- std::cerr << "I/O error, aborting." << std::endl;
- std::abort();
- }
+ init_magick::init_magick()
+ {
+ Magick::InitializeMagick(0);
+ }
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::io::internal
+ } // end of namespace mln::io::magick::internal
+
+ } // end of namespace mln::io::magick
} // end of namespace mln::io
} // end of namespace mln
-#endif // ! MLN_IO_ABORT_HH
+
+#endif // ! MLN_IO_MAGICK_INTERNAL_INIT_MAGICK_HH
diff --git a/milena/mln/io/magick/load.hh b/milena/mln/io/magick/load.hh
index 3065db0..e3c07bd 100644
--- a/milena/mln/io/magick/load.hh
+++ b/milena/mln/io/magick/load.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009, 2010, 2012 EPITA Research and Development
+// Copyright (C) 2009, 2010, 2012, 2013 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
@@ -30,11 +30,6 @@
/// \file
///
/// \brief Image intput routines based on Magick++.
-///
-/// Do not forget to call Magick::InitializeMagick(*argv)
-/// <em>before</em> using any of these functions, as advised by the
-/// GraphicsMagick documentation
-/// (
http://www.graphicsmagick.org/Magick++/Image.html).
# include <cstdlib>
@@ -45,6 +40,8 @@
# include <mln/value/int_u8.hh>
# include <mln/value/rgb8.hh>
+# include <mln/io/magick/internal/init_magick.hh>
+
namespace mln
{
@@ -146,6 +143,10 @@ namespace mln
I& ima = exact(ima_);
+ // 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);
@@ -203,24 +204,6 @@ namespace mln
}
- // FIXME: Unfinished?
-#if 0
- template<typename T>
- inline
- void
- load(Image<tiled2d<T> >& ima_, const std::string& filename)
- {
- trace::entering("mln::io::magick::load");
-
- tiled2d<T>& ima = exact(ima_);
-
- tiled2d<T> result(filename);
-
- ima = result;
- trace::exiting("mln::io::magick::load");
- }
-#endif
-
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/io/magick/save.hh b/milena/mln/io/magick/save.hh
index 0ed869b..4c10703 100644
--- a/milena/mln/io/magick/save.hh
+++ b/milena/mln/io/magick/save.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010, 2011, 2012 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2009, 2010, 2011, 2012, 2013 EPITA Research and
+// Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -30,11 +30,6 @@
/// \file
///
/// \brief Image output routines based on Magick++.
-///
-/// Do not forget to call Magick::InitializeMagick(*argv)
-/// <em>before</em> using any of these functions, as advised by the
-/// GraphicsMagick documentation
-/// (
http://www.graphicsmagick.org/Magick++/Image.html).
# include <cstdlib>
@@ -52,6 +47,7 @@
# include <mln/geom/nrows.hh>
# include <mln/geom/ncols.hh>
+# include <mln/io/magick/internal/init_magick.hh>
namespace mln
{
@@ -500,6 +496,10 @@ namespace mln
const I& ima = exact(ima_);
const J& opacity_mask = exact(opacity_mask_);
+ // Initialize GraphicsMagick only once.
+ static internal::init_magick init;
+ (void) init;
+
def::coord
ncols = geom::ncols(ima),
nrows = geom::nrows(ima);
@@ -542,24 +542,6 @@ namespace mln
save(ima, opacity_mask, filename);
}
-
- // FIXME: Unfinished?
-#if 0
- template <typename T>
- void
- save(const Image< tiled2d<T> >& ima_, const std::string&
filename)
- {
- trace::entering("mln::io::magick::save");
-
- tiled2d<T>& ima = exact(ima_);
-
- ima.buffer().write(filename);
-
- trace::exiting("mln::io::magick::save");
- }
-#endif
-
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::io::magick
diff --git a/milena/tests/io/magick/load.cc b/milena/tests/io/magick/load.cc
index 1525545..34af3f8 100644
--- a/milena/tests/io/magick/load.cc
+++ b/milena/tests/io/magick/load.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010, 2013 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -42,21 +43,6 @@ int main(int /* argc */, char* argv[])
{
using namespace mln;
- /* From
http://www.graphicsmagick.org/Magick++/Image.html:
-
- The InitializeMagick() function MUST be invoked before
- constructing any Magick++ objects. This used to be optional,
- but now it is absolutely required. This function initalizes
- semaphores and configuration information necessary for the
- software to work correctly. Failing to invoke
- InitializeMagick() is likely to lead to a program crash or
- thrown assertion. If the program resides in the same directory
- as the GraphicsMagick files, then argv[0] may be passed as an
- argument so that GraphicsMagick knows where its files reside,
- otherwise NULL may be passed and GraphicsMagick will try to use
- other means (if necessary). */
- Magick::InitializeMagick(*argv);
-
// Compare Milena's built-in PBM loaded and Magick++'s support for PBM.
{
typedef image2d<bool> I;
diff --git a/milena/tests/io/magick/save.cc b/milena/tests/io/magick/save.cc
index d01643e..d650180 100644
--- a/milena/tests/io/magick/save.cc
+++ b/milena/tests/io/magick/save.cc
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2013 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -70,21 +70,6 @@ int main(int /* argc */, char* argv[])
{
using namespace mln;
- /* From
http://www.graphicsmagick.org/Magick++/Image.html:
-
- The InitializeMagick() function MUST be invoked before
- constructing any Magick++ objects. This used to be optional,
- but now it is absolutely required. This function initalizes
- semaphores and configuration information necessary for the
- software to work correctly. Failing to invoke
- InitializeMagick() is likely to lead to a program crash or
- thrown assertion. If the program resides in the same directory
- as the GraphicsMagick files, then argv[0] may be passed as an
- argument so that GraphicsMagick knows where its files reside,
- otherwise NULL may be passed and GraphicsMagick will try to use
- other means (if necessary). */
- Magick::InitializeMagick(*argv);
-
point2d p(0,0);
// Grayscale values (PBM -> PBM -> PBM).
--
1.7.2.5