3358: Fix from_to overloads and add missing operators in value::hsl.

* mln/convert/from_to.hxx: Update forward declarations to from_to overloads. * mln/value/hsl.hh: Add missing operators +,-,/,*. --- milena/ChangeLog | 9 ++ milena/mln/convert/from_to.hxx | 6 +- milena/mln/value/hsl.hh | 170 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 166 insertions(+), 19 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 7ffa783..126f352 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,12 @@ +2009-02-12 Guillaume Lazzara <z@lrde.epita.fr> + + Fix from_to overloads and add missing operators in value::hsl. + + * mln/convert/from_to.hxx: Update forward declarations to from_to + overloads. + + * mln/value/hsl.hh: Add missing operators +,-,/,*. + 2009-02-11 Roland Levillain <roland@lrde.epita.fr> Update apps/statues/ to catch up with recent changes of interface. diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx index 4649932..b0c09b5 100644 --- a/milena/mln/convert/from_to.hxx +++ b/milena/mln/convert/from_to.hxx @@ -170,14 +170,12 @@ namespace mln // rgb to hsl - template <typename H, typename S, typename L> void - from_to_(const value::rgb<16>& from, value::hsl_<H,S,L>& to); + from_to_(const value::rgb<16>& from, value::hsl_<float,float,float>& 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); + from_to_(const value::rgb<8>& from, value::hsl_<float,float,float>& to); // C-array -> Image. diff --git a/milena/mln/value/hsl.hh b/milena/mln/value/hsl.hh index 0ac4087..fd84fba 100644 --- a/milena/mln/value/hsl.hh +++ b/milena/mln/value/hsl.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 @@ -30,6 +31,7 @@ /// Color class. /// /// \todo write a better doc. +/// \todo Cleanup/Revamp! #ifndef MLN_VALUE_HSL_HH # define MLN_VALUE_HSL_HH @@ -40,8 +42,6 @@ #include <mln/value/int_u.hh> #include <mln/algebra/vec.hh> -#include <mln/value/float01_8.hh> - // Used in from_to #include <mln/fun/v2v/rgb_to_hsl.hh> @@ -66,26 +66,90 @@ namespace mln namespace over_load { - // rgb to hsl - template <typename H, typename S, typename L> + // rgb to hsl_ void - from_to_(const value::rgb<16>& from, value::hsl_<H,S,L>& to); + from_to_(const value::rgb<16>& from, value::hsl_<float,float,float>& to); - // rgb to hsl - template <typename H, typename S, typename L> + // rgb to hsl_ void - from_to_(const value::rgb<8>& from, value::hsl_<H,S,L>& to); + from_to_(const value::rgb<8>& from, value::hsl_<float,float,float>& to); } // end of namespace mln::convert::over_load } // end of namespace mln::convert + + namespace trait + { + + template <typename H, typename S, typename L> + struct set_precise_binary_< op::plus, mln::value::hsl_<H,S,L>, mln::value::hsl_<H,S,L> > + { + typedef mln::value::hsl_<H,S,L> ret; + }; + + template <typename H, typename S, typename L> + struct set_precise_binary_< op::minus, mln::value::hsl_<H,S,L>, mln::value::hsl_<H,S,L> > + { + typedef mln::value::hsl_<H,S,L> ret; + }; + + template <typename H, typename S, typename L, typename S2> + struct set_precise_binary_< op::times, mln::value::hsl_<H,S,L>, mln::value::scalar_<S2> > + { + typedef mln::value::hsl_<H,S,L> ret; + }; + + template <typename H, typename S, typename L, typename S2> + struct set_precise_binary_< op::div, mln::value::hsl_<H,S,L>, mln::value::scalar_<S2> > + { + typedef mln::value::hsl_<H,S,L> ret; + }; + + + // FIXME : Is there any way more generic? a way to factor + // set_precise_binary_< op::div, mln::value::hsl_<H,S,L>, mln::value::scalar_<S> > + // and + // set_precise_binary_< op::div, mln::value::hsl_<H,S,L>, mln::value::int_u<m> > + // as for op::times. + + template <typename H, typename S, typename L, unsigned m> + struct set_precise_binary_< op::times, mln::value::hsl_<H,S,L>, mln::value::int_u<m> > + { + typedef mln::value::hsl_<H,S,L> ret; + }; + + template <typename H, typename S, typename L, unsigned m> + struct set_precise_binary_< op::div, mln::value::hsl_<H,S,L>, mln::value::int_u<m> > + { + typedef mln::value::hsl_<H,S,L> ret; + }; + + template <typename H, typename S, typename L> + struct value_< mln::value::hsl_<H,S,L> > + { + enum { + nbits = (sizeof (H) + sizeof (S) + sizeof (L)) * 8, + card = mln_value_card_from_(nbits) + }; + + typedef trait::value::nature::vectorial nature; + typedef trait::value::kind::color kind; + typedef mln_value_quant_from_(card) quant; + +// typedef algebra::vec<3, float> sum; + typedef mln::value::hsl_<H,S,L> sum; + }; + + } // end of namespace trait + + namespace value { template <typename E> - struct HSL + struct HSL : Object<E> { }; @@ -103,6 +167,13 @@ namespace mln { } + hsl_(const literal::zero_t&) + : hue_(0), + sat_(0), + lum_(0) + { + } + /// Constructor from component values. hsl_(const H& hue, const S& sat, const L& lum) : hue_(hue), @@ -122,6 +193,7 @@ namespace mln L& lum(); private: + //FIXME: Don't we want to store these values in a vector? H hue_; S sat_; L lum_; @@ -141,6 +213,35 @@ namespace mln template <typename H, typename S, typename L> std::ostream& operator<<(std::ostream& ostr, const hsl_<H,S,L>& c); + + /// Addition. + /// { + template <typename H, typename S, typename L> + hsl_<H,S,L> + operator+(const hsl_<H,S,L>& lhs, const hsl_<H,S,L>& rhs); + /// \} + + /// Subtraction. + /// \{ + template <typename H, typename S, typename L> + hsl_<H,S,L> + operator-(const hsl_<H,S,L>& lhs, const hsl_<H,S,L>& rhs); + /// \} + + /// Product. + /// \{ + template <typename H, typename S, typename L, typename S2> + hsl_<H,S,L> + operator*(const hsl_<H,S,L>& lhs, const mln::value::scalar_<S2>& s); + /// \} + + /// Division. + /// \{ + template <typename H, typename S, typename L, typename S2> + hsl_<H,S,L> + operator/(const hsl_<H,S,L>& lhs, const mln::value::scalar_<S2>& s); + /// \} + } // end of namespace mln::value @@ -221,6 +322,46 @@ namespace mln << ')'; } + + template <typename H, typename S, typename L> + hsl_<H,S,L> + operator+(const hsl_<H,S,L>& lhs, const hsl_<H,S,L>& rhs) + { + return hsl_<H,S,L>(lhs.hue() + rhs.hue(), + lhs.sat() + rhs.sat(), + lhs.lum() + rhs.lum()); + } + + + template <typename H, typename S, typename L> + hsl_<H,S,L> + operator-(const hsl_<H,S,L>& lhs, const hsl_<H,S,L>& rhs) + { + return hsl_<H,S,L>(lhs.hue() - rhs.hue(), + lhs.sat() - rhs.sat(), + lhs.lum() - rhs.lum()); + } + + + template <typename H, typename S, typename L, typename S2> + hsl_<H,S,L> + operator*(const hsl_<H,S,L>& lhs, const mln::value::scalar_<S2>& s) + { + return hsl_<H,S,L>(lhs.hue() * s, + lhs.sat() * s, + lhs.lum() * s); + } + + + template <typename H, typename S, typename L, typename S2> + hsl_<H,S,L> + operator/(const hsl_<H,S,L>& lhs, const mln::value::scalar_<S2>& s) + { + return hsl_<H,S,L>(lhs.hue() / s, + lhs.sat() / s, + lhs.lum() / s); + } + } // end of namespace mln::value @@ -230,17 +371,16 @@ namespace mln namespace over_load { - template <typename H, typename S, typename L> + inline void - from_to_(const value::rgb<16>& from, value::hsl_<H,S,L>& to) + from_to_(const value::rgb<16>& from, value::hsl_<float,float,float>& to) { to = fun::v2v::f_rgb_to_hsl_f(from); } - - template <typename H, typename S, typename L> + inline void - from_to_(const value::rgb<8>& from, value::hsl_<H,S,L>& to) + from_to_(const value::rgb<8>& from, value::hsl_<float,float,float>& to) { to = fun::v2v::f_rgb_to_hsl_f(from); } -- 1.5.6.5
participants (1)
-
Guillaume Lazzara