Commit 65886835 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

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.
parent 2a9b240f
2013-03-15 Guillaume Lazzara <z@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@lrde.epita.fr>
 
* doc/img/2dgrid.png: New. Add missing file.
// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project 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_MAGICK_INTERNAL_INIT_MAGICK_HH
# define MLN_IO_MAGICK_INTERNAL_INIT_MAGICK_HH
/// \file
///
/// \brief Initialize GraphicsMagick library.
# include <Magick++.h>
namespace mln
{
namespace io
{
namespace magick
{
namespace internal
{
struct init_magick
{
init_magick();
};
# ifndef MLN_INCLUDE_ONLY
init_magick::init_magick()
{
Magick::InitializeMagick(0);
}
# endif // ! MLN_INCLUDE_ONLY
} // 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_MAGICK_INTERNAL_INIT_MAGICK_HH
// 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
......
// 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
......
// 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;
......
// 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).
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment