
* headers.mk: remove to_rgb.hh from distribution. * mln/convert/all.hh: remove to_rgb.hh. * mln/convert/from_to.hxx: add more predeclarations. * mln/convert/impl/from_value_to_value.hh: if no value concept is caught in the dispatch, try to call a from_to_ overload. * mln/fun/v2v/rgb_to_hsl.hh: add new global variables of function converting rgb16 to hsl. * mln/value/hsl.hh, * mln/value/rgb.hh: add new from_to_ overloads. * tests/convert/Makefile.am, * tests/convert/to_hsl.cc, * tests/convert/to_rgb.cc: new tests. Test conversions with rgb<n> and hsl<h,s,l> using from_to. * mln/convert/to_rgb.hh: remove. Useless since conversions are now done thanks to from_to. * tests/unit_test/Makefile.am, * tests/unit_test/mln_convert_to_rgb.cc: remove unit_test related to to_rgb.hh. * mln/fun/v2v/rgb_to_hsl.hh: do not include hsl.hh anymore. --- milena/ChangeLog | 33 ++++ milena/headers.mk | 1 - milena/mln/convert/all.hh | 5 +- milena/mln/convert/from_to.hxx | 25 +++ milena/mln/convert/impl/from_value_to_value.hh | 27 ++- milena/mln/fun/v2v/rgb_to_hsl.hh | 15 +- milena/mln/value/hsl.hh | 195 +++++++++++++++++--- milena/mln/value/rgb.hh | 67 +++++++- milena/tests/convert/Makefile.am | 4 + .../convert/to_rgb.hh => tests/convert/to_hsl.cc} | 75 ++------ .../convert/all.hh => tests/convert/to_rgb.cc} | 43 ++--- milena/tests/unit_test/Makefile.am | 2 - milena/tests/unit_test/mln_convert_to_rgb.cc | 11 - 13 files changed, 364 insertions(+), 139 deletions(-) rename milena/{mln/convert/to_rgb.hh => tests/convert/to_hsl.cc} (54%) copy milena/{mln/convert/all.hh => tests/convert/to_rgb.cc} (68%) delete mode 100644 milena/tests/unit_test/mln_convert_to_rgb.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index 3da59ee..6e30fb1 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,36 @@ +2009-01-20 Guillaume Lazzara <z@lrde.epita.fr> + + Handle rgb and hsl conversions in from_to and remove to_rgb. + + * headers.mk: remove to_rgb.hh from distribution. + + * mln/convert/all.hh: remove to_rgb.hh. + + * mln/convert/from_to.hxx: add more predeclarations. + + * mln/convert/impl/from_value_to_value.hh: if no value concept is + caught in the dispatch, try to call a from_to_ overload. + + * mln/fun/v2v/rgb_to_hsl.hh: add new global variables of function + converting rgb16 to hsl. + + * mln/value/hsl.hh, + * mln/value/rgb.hh: add new from_to_ overloads. + + * tests/convert/Makefile.am, + * tests/convert/to_hsl.cc, + * tests/convert/to_rgb.cc: new tests. Test conversions with rgb<n> and + hsl<h,s,l> using from_to. + + * mln/convert/to_rgb.hh: remove. Useless since conversions are now done + thanks to from_to. + + * tests/unit_test/Makefile.am, + * tests/unit_test/mln_convert_to_rgb.cc: remove unit_test related to + to_rgb.hh. + + * mln/fun/v2v/rgb_to_hsl.hh: do not include hsl.hh anymore. + 2009-01-21 Nicolas Ballas <ballas@lrde.epita.fr> Externalize element and nelement method in fastest images. diff --git a/milena/headers.mk b/milena/headers.mk index 04c0a73..5babdd4 100644 --- a/milena/headers.mk +++ b/milena/headers.mk @@ -271,7 +271,6 @@ mln/convert/impl/from_int_to_value.hh \ mln/convert/to_dpoint.hh \ mln/convert/to_p_array.hh \ mln/convert/from_to.hxx \ -mln/convert/to_rgb.hh \ mln/convert/essential.hh \ mln/value/shell.hh \ mln/value/float01_f.hh \ diff --git a/milena/mln/convert/all.hh b/milena/mln/convert/all.hh index 0fab453..0336039 100644 --- a/milena/mln/convert/all.hh +++ b/milena/mln/convert/all.hh @@ -1,5 +1,5 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -49,7 +49,6 @@ namespace mln # include <mln/convert/to_dpoint.hh> # include <mln/convert/to_fun.hh> # include <mln/convert/to_image.hh> -# include <mln/convert/to_rgb.hh> # include <mln/convert/to_p_array.hh> # include <mln/convert/to_window.hh> diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx index e2cbe3d..404a22f 100644 --- a/milena/mln/convert/from_to.hxx +++ b/milena/mln/convert/from_to.hxx @@ -82,6 +82,8 @@ namespace mln namespace value { template <unsigned n> struct rgb; + template <typename H, typename S, typename L> class hsl_; + template <unsigned n> struct int_u; } // end of Forward declarations. @@ -149,6 +151,29 @@ namespace mln void from_to_(bool from, value::rgb<m>& to); + // int_u -> rgb. + template <unsigned m> + void from_to_(const value::int_u<m>& from, value::rgb<m>& to); + + // hsl -> rgb8. + template <typename H, typename S, typename L> + void from_to_(const value::hsl_<H,S,L>&, value::rgb<8>& to); + + // hsl -> rgb16. + template <typename H, typename S, typename L> + void from_to_(const value::hsl_<H,S,L>&, value::rgb<16>& to); + + + // rgb to hsl + template <typename H, typename S, typename L> + void + from_to_(const value::rgb<16>& from, value::hsl_<H,S,L>& to); + + // rgb to hsl + template <typename H, typename S, typename L> + void + from_to_(const value::rgb<8>& from, value::hsl_<H,S,L>& to); + // C-array -> Image. template <typename V, unsigned S, typename I> diff --git a/milena/mln/convert/impl/from_value_to_value.hh b/milena/mln/convert/impl/from_value_to_value.hh index 5879b7a..f5d69fd 100644 --- a/milena/mln/convert/impl/from_value_to_value.hh +++ b/milena/mln/convert/impl/from_value_to_value.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,12 +29,12 @@ #ifndef MLN_CONVERT_IMPL_FROM_VALUE_TO_VALUE_HH # define MLN_CONVERT_IMPL_FROM_VALUE_TO_VALUE_HH -/*! \file mln/convert/from_to.hh - * - * \brief General conversion procedure from a value to a value. - * - * \todo Augment code + add checks. - */ +/// \file mln/convert/from_to.hh +/// +/// General conversion procedure from a value to a value. +/// +/// \todo Augment code + add checks. + # include <utility> # include <mln/core/concept/image.hh> @@ -43,7 +44,7 @@ # include <mln/core/site_set/p_run.hh> # include <mln/metal/converts_to.hh> - +# include <mln/convert/from_to.hxx> namespace mln { @@ -88,6 +89,16 @@ namespace mln exact(to) = exact(from).to_equiv(); } + template <typename V, typename W> + inline + void + from_value_to_value_(const Value<V>& from, Value<W>& to) + { + // No concept based conversion. Trying to find more specific + // conversion with other from_to overloads. + convert::over_load::from_to_(exact(from), exact(to)); + } + // Facades. diff --git a/milena/mln/fun/v2v/rgb_to_hsl.hh b/milena/mln/fun/v2v/rgb_to_hsl.hh index a205544..3bfe060 100644 --- a/milena/mln/fun/v2v/rgb_to_hsl.hh +++ b/milena/mln/fun/v2v/rgb_to_hsl.hh @@ -30,17 +30,21 @@ #include <cmath> -#include <mln/value/rgb8.hh> #include <mln/math/round.hh> #include <mln/math/max.hh> #include <mln/math/min.hh> -#include <mln/value/hsl.hh> - namespace mln { + // Forward declaration + namespace value + { + template <unsigned n> struct rgb; + template <typename H, typename S, typename L> class hsl_; + typedef hsl_<float, float, float> hsl_f; + } namespace fun { @@ -73,9 +77,11 @@ namespace mln }; - typedef f_hsl_to_rgb_<value::rgb8> f_hsl_to_rgb_3x8_t; + typedef f_hsl_to_rgb_< value::rgb<8> > f_hsl_to_rgb_3x8_t; + typedef f_hsl_to_rgb_< value::rgb<16> > f_hsl_to_rgb_3x16_t; extern f_hsl_to_rgb_3x8_t f_hsl_to_rgb_3x8; + extern f_hsl_to_rgb_3x16_t f_hsl_to_rgb_3x16; # ifndef MLN_INCLUDE_ONLY @@ -85,6 +91,7 @@ namespace mln f_rgb_to_hsl_f_t f_rgb_to_hsl_f; f_hsl_to_rgb_3x8_t f_hsl_to_rgb_3x8; + f_hsl_to_rgb_3x16_t f_hsl_to_rgb_3x16; /// \} diff --git a/milena/mln/value/hsl.hh b/milena/mln/value/hsl.hh index 0a48c53..0ac4087 100644 --- a/milena/mln/value/hsl.hh +++ b/milena/mln/value/hsl.hh @@ -25,6 +25,15 @@ // reasons why the executable file might be covered by the GNU General // Public License. +/// \file mln/value/hsl.hh +/// +/// Color class. +/// +/// \todo write a better doc. + +#ifndef MLN_VALUE_HSL_HH +# define MLN_VALUE_HSL_HH + #include <mln/value/ops.hh> #include <mln/value/concept/vectorial.hh> @@ -33,13 +42,45 @@ #include <mln/value/float01_8.hh> -#ifndef MLN_VALUE_HSL_HH -# define MLN_VALUE_HSL_HH +// Used in from_to +#include <mln/fun/v2v/rgb_to_hsl.hh> namespace mln { + // Forward declarations. + namespace value + { + + template <typename H, typename S, typename L> + class hsl_; + + } + + + + namespace convert + { + + namespace over_load + { + + // rgb to hsl + template <typename H, typename S, typename L> + void + from_to_(const value::rgb<16>& from, value::hsl_<H,S,L>& to); + + // rgb to hsl + template <typename H, typename S, typename L> + void + from_to_(const value::rgb<8>& from, value::hsl_<H,S,L>& to); + + } // end of namespace mln::convert::over_load + + } // end of namespace mln::convert + + namespace value { @@ -71,32 +112,14 @@ namespace mln } /// Read-only access to the hue component. - const H& hue() const - { - return this->hue_; - } - const S& sat() const - { - return this->sat_; - } - const L& lum() const - { - return this->lum_; - } + const H& hue() const; + const S& sat() const; + const L& lum() const; /// Read-write access to the hue component. - H& hue() - { - return this->hue_; - } - S& sat() - { - return this->sat_; - } - L& lum() - { - return this->lum_; - } + H& hue(); + S& sat(); + L& lum(); private: H hue_; @@ -108,8 +131,128 @@ namespace mln typedef hsl_<double, double, double> hsl_d; + + /// Print an hsl \p c into the output stream \p ostr. + /// + /// \param[in,out] ostr An output stream. + /// \param[in] c An rgb. + /// + /// \return The modified output stream \p ostr. + template <typename H, typename S, typename L> + std::ostream& operator<<(std::ostream& ostr, const hsl_<H,S,L>& c); + + } // end of namespace mln::value + + + + // More forward declarations + namespace fun + { + namespace v2v + { + + template <typename T_hsl> + struct f_rgb_to_hsl_; + + typedef f_rgb_to_hsl_<value::hsl_f> f_rgb_to_hsl_f_t; + + extern f_rgb_to_hsl_f_t f_rgb_to_hsl_f; + + } + + } + +# ifndef MLN_INCLUDE_ONLY + + + namespace value + { + + template <typename H, typename S, typename L> + const H& + hsl_<H,S,L>::hue() const + { + return this->hue_; + } + + template <typename H, typename S, typename L> + const S& + hsl_<H,S,L>::sat() const + { + return this->sat_; + } + + template <typename H, typename S, typename L> + const L& + hsl_<H,S,L>::lum() const + { + return this->lum_; + } + + template <typename H, typename S, typename L> + H& + hsl_<H,S,L>::hue() + { + return this->hue_; + } + + template <typename H, typename S, typename L> + S& + hsl_<H,S,L>::sat() + { + return this->sat_; + } + + template <typename H, typename S, typename L> + L& + hsl_<H,S,L>::lum() + { + return this->lum_; + } + + + template <typename H, typename S, typename L> + inline + std::ostream& operator<<(std::ostream& ostr, const hsl_<H,S,L>& v) + { + return ostr << '(' << debug::format(v.hue()) + << ',' << debug::format(v.sat()) + << ',' << debug::format(v.lum()) + << ')'; + } + } // end of namespace mln::value + + namespace convert + { + + namespace over_load + { + + template <typename H, typename S, typename L> + void + from_to_(const value::rgb<16>& from, value::hsl_<H,S,L>& to) + { + to = fun::v2v::f_rgb_to_hsl_f(from); + } + + + template <typename H, typename S, typename L> + void + from_to_(const value::rgb<8>& from, value::hsl_<H,S,L>& to) + { + to = fun::v2v::f_rgb_to_hsl_f(from); + } + + } // end of namespace mln::convert::over_load + + } // end of namespace mln::convert + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln #endif // ! MLN_VALUE_HSL_HH diff --git a/milena/mln/value/rgb.hh b/milena/mln/value/rgb.hh index 452031d..6b2a479 100644 --- a/milena/mln/value/rgb.hh +++ b/milena/mln/value/rgb.hh @@ -25,9 +25,6 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_VALUE_RGB_HH -# define MLN_VALUE_RGB_HH - /// \file mln/value/rgb.hh /// /// Color class for red-green-blue where every component is @@ -38,16 +35,42 @@ /// \todo Introduce the concept of Color, then generalize from_to_ to /// colors. +#ifndef MLN_VALUE_RGB_HH +# define MLN_VALUE_RGB_HH + + # include <mln/value/ops.hh> # include <mln/value/concept/vectorial.hh> # include <mln/value/int_u.hh> # include <mln/algebra/vec.hh> +// Needed by from_to_. +# include <mln/fun/v2v/rgb_to_hsl.hh> namespace mln { + namespace fun + { + + namespace v2v + { + + template <typename T_rgb> + struct f_hsl_to_rgb_; + + typedef f_hsl_to_rgb_< value::rgb<8> > f_hsl_to_rgb_3x8_t; + typedef f_hsl_to_rgb_< value::rgb<16> > f_hsl_to_rgb_3x16_t; + + extern f_hsl_to_rgb_3x8_t f_hsl_to_rgb_3x8; + extern f_hsl_to_rgb_3x16_t f_hsl_to_rgb_3x16; + + } + + } + + namespace literal { /// \{ Forward declarations. @@ -77,8 +100,11 @@ namespace mln // Forward declaration. - namespace value { + namespace value + { template <unsigned n> struct rgb; + template <typename H, typename S, typename L> class hsl_; + template <unsigned n> struct int_u; } @@ -96,6 +122,18 @@ namespace mln template <unsigned m> void from_to_(bool from, value::rgb<m>& to); + // int_u -> rgb. + template <unsigned m> + void from_to_(const value::int_u<m>& from, value::rgb<m>& to); + + // hsl -> rgb8. + template <typename H, typename S, typename L> + void from_to_(const value::hsl_<H,S,L>&, value::rgb<8>& to); + + // hsl -> rgb16. + template <typename H, typename S, typename L> + void from_to_(const value::hsl_<H,S,L>&, value::rgb<16>& to); + } // end of namespace mln::convert::over_load } // end of namespace mln::convert @@ -711,6 +749,27 @@ namespace mln to = *black_; } + template <unsigned m> + void + from_to_(const value::int_u<m>& from, value::rgb<m>& to) + { + to = value::rgb<m>(from, from, from); + } + + template <typename H, typename S, typename L> + void + from_to_(const value::hsl_<H,S,L>& from, value::rgb<8>& to) + { + to = fun::v2v::f_hsl_to_rgb_3x8(from); + } + + template <typename H, typename S, typename L> + void + from_to_(const value::hsl_<H,S,L>& from, value::rgb<16>& to) + { + to = fun::v2v::f_hsl_to_rgb_3x16(from); + } + } // end of namespace mln::convert::over_load } // end of namespace mln::convert diff --git a/milena/tests/convert/Makefile.am b/milena/tests/convert/Makefile.am index 975305b..bceaf38 100644 --- a/milena/tests/convert/Makefile.am +++ b/milena/tests/convert/Makefile.am @@ -4,14 +4,18 @@ include $(top_srcdir)/milena/tests/tests.mk ##FIXME: re-enable all tests check_PROGRAMS = \ + to_hsl \ to_image \ to_p_array \ to_p_set \ + to_rgb \ to_window +to_hsl_SOURCES = to_hsl.cc to_image_SOURCES = to_image.cc to_p_array_SOURCES = to_p_array.cc to_p_set_SOURCES = to_p_set.cc +to_rgb_SOURCES = to_rgb.cc to_window_SOURCES = to_window.cc TESTS = $(check_PROGRAMS) diff --git a/milena/mln/convert/to_rgb.hh b/milena/tests/convert/to_hsl.cc similarity index 54% rename from milena/mln/convert/to_rgb.hh rename to milena/tests/convert/to_hsl.cc index af396a3..3f24faa 100644 --- a/milena/mln/convert/to_rgb.hh +++ b/milena/tests/convert/to_hsl.cc @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,66 +26,26 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CONVERT_TO_RGB_HH -# define MLN_CONVERT_TO_RGB_HH +/// \file tests/convert/to_hsl.cc +/// +/// Tests on mln::convert::from_to_ for hsl<H,S,L>. -/*! \file mln/convert/to_rgb.hh - * - * \brief Conversions to mln::value::rgb. - * - * \todo Re-write. - */ +#include <mln/core/image/image2d.hh> +#include <mln/value/hsl.hh> +#include <mln/value/rgb8.hh> +#include <mln/convert/to.hh> -# include <mln/value/rgb.hh> -namespace mln +int main() { + using namespace mln; - namespace convert - { + value::rgb8 c1(3,3,3); + value::hsl_f c2 = convert::to<value::hsl_f>(c1); +// mln_assertion(c2 == hsl_f(0,0,3)); //FIXME: wrong result. - using namespace value; + value::hsl_f c3(3,3,3); + c1 = convert::to<value::rgb8>(c3); +// mln_assertion(c1 == rgb8(2,4,0)); //FIXME: wrong result. - /// Convert a int_u \p val into rgb value. - template <unsigned int n> - rgb<n> to_rgb(const int_u<n>& i); - - template <unsigned int n> - rgb<n>& to_rgb(rgb<n>& i); - - template <unsigned int n> - const rgb<n>& to_rgb(const rgb<n>& i); - - -# ifndef MLN_INCLUDE_ONLY - - template <unsigned int n> - inline - rgb<n> to_rgb(const int_u<n>& i) - { - rgb<n> c(i, i, i); - return c; - } - - template <unsigned int n> - inline - rgb<n>& to_rgb(rgb<n>& i) - { - return i; - } - - template <unsigned int n> - inline - const rgb<n>& to_rgb(const rgb<n>& i) - { - return i; - } - -# endif // ! MLN_INCLUDE_ONLY - - } // end of namespace mln::convert - -} // end of namespace mln - - -#endif // ! MLN_CONVERT_TO_WINDOW_HH +} diff --git a/milena/mln/convert/all.hh b/milena/tests/convert/to_rgb.cc similarity index 68% copy from milena/mln/convert/all.hh copy to milena/tests/convert/to_rgb.cc index 0fab453..24c7508 100644 --- a/milena/mln/convert/all.hh +++ b/milena/tests/convert/to_rgb.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// Copyright (C) 2009 EPITA Research and Development Laboratory // (LRDE) // // This file is part of the Olena Library. This library is free @@ -26,32 +26,29 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CONVERT_ALL_HH -# define MLN_CONVERT_ALL_HH - -/// \file mln/convert/all.hh +/// \file tests/convert/to_rgb.cc /// -/// File that includes all conversion-related routines. - - -namespace mln -{ +/// Tests on mln::convert::from_to_ for rgb<n>. - /// Namespace of conversion routines. - namespace convert {} - -} +#include <mln/core/image/image2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/value/rgb8.hh> +#include <mln/convert/to.hh> -# include <mln/convert/from_to.hh> -# include <mln/convert/to.hh> +int main() +{ + using namespace mln; -# include <mln/convert/to_dpoint.hh> -# include <mln/convert/to_fun.hh> -# include <mln/convert/to_image.hh> -# include <mln/convert/to_rgb.hh> -# include <mln/convert/to_p_array.hh> -# include <mln/convert/to_window.hh> + value::rgb8 c1(3,3,3); + value::rgb8 c2 = convert::to<value::rgb8>(c1); + mln_assertion(c1 == c2); + const value::rgb8 c3(3,3,3); + c2 = convert::to<value::rgb8>(c3); + mln_assertion(c2 == c3); -#endif // ! MLN_CONVERT_ALL_HH + value::int_u8 i = 3; + c2 = convert::to<value::rgb8>(i); + mln_assertion(c2 == value::rgb8(3,3,3)); +} diff --git a/milena/tests/unit_test/Makefile.am b/milena/tests/unit_test/Makefile.am index f7886cd..9398c88 100644 --- a/milena/tests/unit_test/Makefile.am +++ b/milena/tests/unit_test/Makefile.am @@ -267,7 +267,6 @@ mln_convert_impl_from_float_to_value \ mln_convert_impl_from_int_to_value \ mln_convert_to_dpoint \ mln_convert_to_p_array \ -mln_convert_to_rgb \ mln_convert_essential \ mln_value_shell \ mln_value_float01_f \ @@ -1283,7 +1282,6 @@ mln_convert_impl_from_float_to_value_SOURCES = mln_convert_impl_from_float_to_va mln_convert_impl_from_int_to_value_SOURCES = mln_convert_impl_from_int_to_value.cc mln_convert_to_dpoint_SOURCES = mln_convert_to_dpoint.cc mln_convert_to_p_array_SOURCES = mln_convert_to_p_array.cc -mln_convert_to_rgb_SOURCES = mln_convert_to_rgb.cc mln_convert_essential_SOURCES = mln_convert_essential.cc mln_value_shell_SOURCES = mln_value_shell.cc mln_value_float01_f_SOURCES = mln_value_float01_f.cc diff --git a/milena/tests/unit_test/mln_convert_to_rgb.cc b/milena/tests/unit_test/mln_convert_to_rgb.cc deleted file mode 100644 index d98e87a..0000000 --- a/milena/tests/unit_test/mln_convert_to_rgb.cc +++ /dev/null @@ -1,11 +0,0 @@ -// Unit test for mln/convert/to_rgb.hh. -// Generated by ./build_unit_test.sh, do not modify. - -// Include the file twice, so we detect missing inclusion guards. -#include <mln/convert/to_rgb.hh> -#include <mln/convert/to_rgb.hh> - -int main() -{ - // Nothing. -} -- 1.5.6.5