26 #ifndef MLN_VALUE_HSL_HH
27 # define MLN_VALUE_HSL_HH
29 #include <mln/value/ops.hh>
31 #include <mln/value/concept/vectorial.hh>
32 #include <mln/value/int_u.hh>
33 #include <mln/algebra/vec.hh>
36 #include <mln/fun/v2v/rgb_to_hsl.hh>
46 template <
typename H,
typename S,
typename L>
61 from_to_(
const value::rgb<16>& from, value::hsl_<float,float,float>&
to);
65 from_to_(
const value::rgb<8>& from, value::hsl_<float,float,float>&
to);
76 template <
typename H,
typename S,
typename L>
77 struct set_precise_binary_< op::
plus, mln::value::hsl_<H,S,L>, mln::value::hsl_<H,S,L> >
79 typedef mln::value::hsl_<H,S,L> ret;
82 template <
typename H,
typename S,
typename L>
83 struct set_precise_binary_< op::
minus, mln::value::hsl_<H,S,L>, mln::value::hsl_<H,S,L> >
85 typedef mln::value::hsl_<H,S,L> ret;
88 template <
typename H,
typename S,
typename L,
typename S2>
89 struct set_precise_binary_< op::
times, mln::value::hsl_<H,S,L>, mln::value::scalar_<S2> >
91 typedef mln::value::hsl_<H,S,L> ret;
94 template <
typename H,
typename S,
typename L,
typename S2>
95 struct set_precise_binary_< op::
div, mln::value::hsl_<H,S,L>, mln::value::scalar_<S2> >
97 typedef mln::value::hsl_<H,S,L> ret;
107 template <
typename H,
typename S,
typename L,
unsigned m>
110 typedef mln::value::hsl_<H,S,L> ret;
113 template <
typename H,
typename S,
typename L,
unsigned m>
116 typedef mln::value::hsl_<H,S,L> ret;
119 template <
typename H,
typename S,
typename L>
120 struct value_< mln::value::hsl_<H,S,L> >
124 nbits = (
sizeof (H) +
sizeof (S) +
sizeof (L)) * 8,
125 card = mln_value_card_from_(nbits)
128 typedef trait::value::nature::vectorial nature;
129 typedef trait::value::kind::color kind;
130 typedef mln_value_quant_from_(card) quant;
137 template <typename V> static comp_0 get_comp_0(const V& v) {
return v.hue(); }
138 template <
typename V>
static comp_1 get_comp_1(
const V& v) {
return v.sat(); }
139 template <
typename V>
static comp_2 get_comp_2(
const V& v) {
return v.lum(); }
142 typedef mln::value::hsl_<H,S,L>
sum;
151 template <
typename E>
152 struct HSL : Object<E>
156 template <
typename H,
typename S,
typename L>
157 class hsl_ :
public HSL< hsl_<H,S,L> >
170 hsl_(
const literal::zero_t&)
178 hsl_(
const H& hue,
const S& sat,
const L& lum)
186 const H& hue()
const;
187 const S& sat()
const;
188 const L& lum()
const;
204 typedef hsl_<float, float, float> hsl_f;
206 typedef hsl_<double, double, double> hsl_d;
215 template <
typename H,
typename S,
typename L>
216 std::ostream& operator<<(std::ostream& ostr, const hsl_<H,S,L>& c);
221 template <
typename H,
typename S,
typename L>
223 operator+(
const hsl_<H,S,L>& lhs,
const hsl_<H,S,L>& rhs);
228 template <
typename H,
typename S,
typename L>
230 operator-(
const hsl_<H,S,L>& lhs,
const hsl_<H,S,L>& rhs);
235 template <
typename H,
typename S,
typename L,
typename S2>
237 operator*(
const hsl_<H,S,L>& lhs,
const mln::value::scalar_<S2>& s);
242 template <
typename H,
typename S,
typename L,
typename S2>
244 operator/(
const hsl_<H,S,L>& lhs,
const mln::value::scalar_<S2>& s);
249 template <
typename H,
typename S,
typename L>
251 operator==(
const hsl_<H,S,L>& lhs,
const hsl_<H,S,L>& rhs);
264 template <
typename T_hsl>
265 struct f_rgb_to_hsl_;
267 typedef f_rgb_to_hsl_<value::hsl_f> f_rgb_to_hsl_f_t;
275 # ifndef MLN_INCLUDE_ONLY
281 template <
typename H,
typename S,
typename L>
283 hsl_<H,S,L>::hue()
const
288 template <
typename H,
typename S,
typename L>
290 hsl_<H,S,L>::sat()
const
295 template <
typename H,
typename S,
typename L>
297 hsl_<H,S,L>::lum()
const
302 template <
typename H,
typename S,
typename L>
309 template <
typename H,
typename S,
typename L>
316 template <
typename H,
typename S,
typename L>
324 template <
typename H,
typename S,
typename L>
326 std::ostream& operator<<(std::ostream& ostr, const hsl_<H,S,L>& v)
335 template <
typename H,
typename S,
typename L>
337 operator+(
const hsl_<H,S,L>& lhs,
const hsl_<H,S,L>& rhs)
339 return hsl_<H,S,L>(lhs.hue() + rhs.hue(),
340 lhs.sat() + rhs.sat(),
341 lhs.lum() + rhs.lum());
345 template <
typename H,
typename S,
typename L>
347 operator-(
const hsl_<H,S,L>& lhs,
const hsl_<H,S,L>& rhs)
349 return hsl_<H,S,L>(lhs.hue() - rhs.hue(),
350 lhs.sat() - rhs.sat(),
351 lhs.lum() - rhs.lum());
355 template <
typename H,
typename S,
typename L,
typename S2>
357 operator*(
const hsl_<H,S,L>& lhs,
const mln::value::scalar_<S2>& s)
359 return hsl_<H,S,L>(lhs.hue() * s,
365 template <
typename H,
typename S,
typename L,
typename S2>
367 operator/(
const hsl_<H,S,L>& lhs,
const mln::value::scalar_<S2>& s)
369 return hsl_<H,S,L>(lhs.hue() / s,
374 template <
typename H,
typename S,
typename L>
376 operator==(
const hsl_<H,S,L>& lhs,
const hsl_<H,S,L>& rhs)
378 return lhs.hue() == rhs.hue()
379 && lhs.sat() == rhs.sat()
380 && lhs.lum() == rhs.lum();
394 from_to_(
const value::rgb<16>& from, value::hsl_<float,float,float>&
to)
401 from_to_(
const value::rgb<8>& from, value::hsl_<float,float,float>&
to)
411 # endif // ! MLN_INCLUDE_ONLY
416 #endif // ! MLN_VALUE_HSL_HH