27 #ifndef MLN_IO_MAGICK_LOAD_HH
28 # define MLN_IO_MAGICK_LOAD_HH
41 # include <Magick++.h>
43 # include <mln/core/image/image2d.hh>
45 # include <mln/value/int_u8.hh>
46 # include <mln/value/rgb8.hh>
63 void load(Image<I>& ima,
const std::string& filename);
74 void load(Image<tiled2d<T> >& ima,
const std::string& filename);
78 # ifndef MLN_INCLUDE_ONLY
87 if (in.red() != in.green() || in.green() != in.blue())
90 "error: attempt to load what looks like a color\n"
91 "(mln::value::rgb8) image into a Boolean (bool) image" <<
96 in.red() != mln_max(value::rgb8::red_t))
99 "error: attempt to load what looks like a grayscale\n"
100 "(mln::value::int_u8) image into a Boolean (bool) image" <<
105 out = (in.red() != 0);
113 if (in.red() != in.green() || in.green() != in.blue())
116 "error: attempt to load what looks like a color\n"
117 "(mln::value::rgb8) image into a grayscale\n"
118 "(mln::int_u8 values) image" << std::endl;
137 template <
typename I>
141 trace::entering(
"mln::io::magick::load");
143 I& ima = exact(ima_);
147 Magick::Image magick_ima(filename);
148 magick_ima.read(filename);
149 magick_ima.type(Magick::TrueColorType);
150 int nrows = magick_ima.rows();
151 int ncols = magick_ima.columns();
152 mln_site(I) pmin(0, 0);
153 mln_site(I) pmax(nrows - 1, ncols - 1);
155 mln_concrete(I) result(
box<mln_site(I)>(pmin, pmax));
164 Magick::Pixels view(magick_ima);
166 Magick::PixelPacket* pixels = view.get(0, 0, ima.ncols(), ima.nrows());
167 mln_value(I) *ptr_ima = &ima(ima.domain().pmin());
169 unsigned row_offset = ima.delta_index(
dpoint2d(+1, - ncols));
172 ++row, ptr_ima += row_offset)
173 for (
def::coord col = mincol; col <= maxcol; ++col)
181 value::rgb8 c(pixels->red >> 8 * (
sizeof(Magick::Quantum)
183 pixels->green >> 8 * (
sizeof(Magick::Quantum)
185 pixels->blue >> 8 * (
sizeof(Magick::Quantum)
188 if (!impl::do_it(c, res))
190 std::cerr <<
"while trying to load `" << filename <<
"'"
198 trace::exiting(
"mln::io::magick::load");
207 load(
Image<tiled2d<T> >& ima_,
const std::string& filename)
209 trace::entering(
"mln::io::magick::load");
211 tiled2d<T>& ima = exact(ima_);
213 tiled2d<T> result(filename);
216 trace::exiting(
"mln::io::magick::load");
221 # endif // ! MLN_INCLUDE_ONLY
230 #endif // ! MLN_IO_MAGICK_LOAD_HH