last-svn-commit-528-g0d8813e Handle properly non 8-bit Magick::Quantum's.

* mln/io/magick/load.hh (mln::io::magick::load(Image<I>&, const std::string&)) * mln/io/magick/save.hh (mln::io::magick::impl::get_color(const value::int_u8&)) (mln::io::magick::impl::get_color(const value::rgb8&)): Properly convert values between Magick::Quantum and mln::value::int_u8, and vice versa. --- milena/ChangeLog | 12 ++++++++++++ milena/mln/io/magick/load.hh | 17 +++++++++++------ milena/mln/io/magick/save.hh | 30 ++++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 8e94f5d..2b6ae78 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,15 @@ +2010-10-28 Roland Levillain <roland@lrde.epita.fr> + + Handle properly non 8-bit Magick::Quantum's. + + * mln/io/magick/load.hh + (mln::io::magick::load(Image<I>&, const std::string&)) + * mln/io/magick/save.hh + (mln::io::magick::impl::get_color(const value::int_u8&)) + (mln::io::magick::impl::get_color(const value::rgb8&)): + Properly convert values between Magick::Quantum and + mln::value::int_u8, and vice versa. + 2010-10-27 Roland Levillain <roland@lrde.epita.fr> Fix Boost.Tuple handling. diff --git a/milena/mln/io/magick/load.hh b/milena/mln/io/magick/load.hh index 7004a80..60e857e 100644 --- a/milena/mln/io/magick/load.hh +++ b/milena/mln/io/magick/load.hh @@ -35,8 +35,6 @@ /// <em>before</em> using any of these functions, as advised by the /// GraphicsMagick documentation /// (http://www.graphicsmagick.org/Magick++/Image.html). -/// -/// \fixme: re-enable quantum size check # include <cstdlib> @@ -142,9 +140,6 @@ namespace mln { trace::entering("mln::io::magick::load"); - // Ensure a Magick++'s Quantum is an 8-bit value. - //mln::metal::equal<Magick::Quantum, unsigned char>::check(); - I& ima = exact(ima_); // FIXME: Handle Magick++'s exceptions (see either @@ -166,7 +161,17 @@ namespace mln mln_piter(I) p(ima.domain()); for_all(p) { - value::rgb8 c(pixels->red, pixels->green, pixels->blue); + /* Each channel of a Magick++ image is coded on a + Magick::Quantum value, which can be an 8-, 16- or 32-bit + integer. Load the most significant bits of each channel + into a component of an mln::value::rgb8 value (i.e., into + an mln::value::int_u8 value). */ + value::rgb8 c(pixels->red >> 8 * (sizeof(Magick::Quantum) + - sizeof(value::rgb8::red_t)), + pixels->green >> 8 * (sizeof(Magick::Quantum) + - sizeof(value::rgb8::green_t)), + pixels->blue >> 8 * (sizeof(Magick::Quantum) + - sizeof(value::rgb8::blue_t))); mln_value(I) res; if (!impl::do_it(c, res)) { diff --git a/milena/mln/io/magick/save.hh b/milena/mln/io/magick/save.hh index 2c87c88..7a91ee0 100644 --- a/milena/mln/io/magick/save.hh +++ b/milena/mln/io/magick/save.hh @@ -35,8 +35,6 @@ /// <em>before</em> using any of these functions, as advised by the /// GraphicsMagick documentation /// (http://www.graphicsmagick.org/Magick++/Image.html). -/// -/// \fixme: re-enable quantum size check # include <cstdlib> @@ -95,17 +93,33 @@ namespace mln inline Magick::Color get_color(const value::int_u8& value) { - // Ensure a Magick++'s Quantum is an 8-bit value. - //mln::metal::equal<Magick::Quantum, unsigned char>::check(); - return Magick::Color(value, value, value); + /* Each channel of a Magick++ image is coded on a + Magick::Quantum value, which can be an 8-, 16- or 32-bit + integer. Store the data from each mln::value::int_u8 + values into the most significant bits of Magick::Color's + channels. */ + return Magick::Color + (value << 8 * (sizeof(Magick::Quantum) - sizeof(value::int_u8)), + value << 8 * (sizeof(Magick::Quantum) - sizeof(value::int_u8)), + value << 8 * (sizeof(Magick::Quantum) - sizeof(value::int_u8))); } inline Magick::Color get_color(const value::rgb8& value) { - // Ensure a Magick++'s Quantum is an 8-bit value. - //mln::metal::equal<Magick::Quantum, unsigned char>::check(); - return Magick::Color(value.red(), value.green(), value.blue()); + /* Each channel of a Magick++ image is coded on a + Magick::Quantum value, which can be an 8-, 16- or 32-bit + integer. Store the data from each component of + mln::value::rgb8 values (of type mln::value::int_u8) into + the most significant bits of Magick::Color's + channels. */ + return Magick::Color + (value.red() << 8 * (sizeof(Magick::Quantum) + - sizeof(value::rgb8::red_t)), + value.green() << 8 * (sizeof(Magick::Quantum) + - sizeof(value::rgb8::green_t)), + value.blue() << 8 * (sizeof(Magick::Quantum) + - sizeof(value::rgb8::blue_t))); } } // end of namespace mln::io::magick::impl -- 1.5.6.5
participants (1)
-
Roland Levillain