27 #ifndef MLN_VALUE_RGB_HH
28 # define MLN_VALUE_RGB_HH
31 # include <mln/value/ops.hh>
33 # include <mln/value/concept/vectorial.hh>
34 # include <mln/value/int_u.hh>
35 # include <mln/algebra/vec.hh>
37 # include <mln/value/internal/make_generic_name.hh>
39 # include <mln/convert/from_to.hh>
49 template <
unsigned n>
struct rgb;
50 template <
typename H,
typename S,
typename L>
class hsl_;
55 template <
typename T_hsl>
struct f_rgb_to_hsl_;
93 template <
typename H,
typename S,
typename L>
class hsl_;
98 template <
unsigned n >
104 template <
unsigned n >
110 template <
unsigned n,
typename S >
116 template <
unsigned n,
typename S >
129 template <
unsigned n,
unsigned m >
135 template <
unsigned n,
unsigned m >
158 template <
unsigned n>
159 struct value_< mln::value::rgb<n> >
164 card = mln_value_card_from_(nbits)
167 typedef trait::value::nature::vectorial
nature;
168 typedef trait::value::kind::color
kind;
169 typedef trait::value::quant::high
quant;
176 template <
typename V>
static comp_0 get_comp_0(
const V& v) {
return v.red(); }
177 template <
typename V>
static comp_1 get_comp_1(
const V& v) {
return v.green(); }
178 template <
typename V>
static comp_2 get_comp_2(
const V& v) {
return v.blue(); }
180 typedef algebra::vec<dim, float>
sum;
182 static const char* name()
204 template <
unsigned n>
210 algebra::vec< 3, int_u<n> >,
211 algebra::vec< 3, int >,
239 rgb<n>(
int r,
int g,
int b);
292 template <
unsigned n>
293 std::ostream& operator<<(std::ostream& ostr, const rgb<n>& c);
301 template <
unsigned n>
314 template <
unsigned n>
318 template <
unsigned n>
322 template <
unsigned n>
329 template <
unsigned n>
333 template <
unsigned n>
337 template <
unsigned n>
344 template <
unsigned n,
typename S>
349 template <
unsigned n,
typename S>
357 template <
unsigned n,
typename S>
372 template <
unsigned m>
384 template <
unsigned m>
393 # include <mln/value/hsl.hh>
394 # include <mln/fun/v2v/rgb_to_hsl.hh>
397 # ifndef MLN_INCLUDE_ONLY
409 template <
unsigned n>
415 template <
unsigned n>
422 template <
unsigned n>
429 template <
unsigned n>
436 template <
unsigned n>
445 template <
unsigned n>
449 mln_precondition(r >= 0);
450 mln_precondition(g >= 0);
451 mln_precondition(b >= 0);
452 mln_precondition(
unsigned(r) <= mln_max(
int_u<n>));
453 mln_precondition(
unsigned(g) <= mln_max(
int_u<n>));
454 mln_precondition(
unsigned(b) <= mln_max(
int_u<n>));
460 template <
unsigned n>
469 template <
unsigned n>
478 template <
unsigned n>
487 template <
unsigned n>
496 template <
unsigned n>
505 template <
unsigned n>
514 template <
unsigned n>
523 template <
unsigned n>
532 template <
unsigned n>
541 template <
unsigned n>
550 template <
unsigned n>
559 template <
unsigned n>
568 template <
unsigned n>
577 template <
unsigned n>
586 template <
unsigned n>
595 template <
unsigned n>
604 template <
unsigned n>
613 template <
unsigned n>
622 template <
unsigned n>
631 template <
unsigned n>
642 template <
unsigned n>
649 template <
unsigned n>
651 typename rgb<n>::interop
652 operator+(
const rgb<n>& lhs,
const rgb<n>& rhs)
654 typename rgb<n>::interop tmp(lhs.to_interop() + rhs.to_interop());
658 template <
unsigned n>
660 typename rgb<n>::interop
661 operator+(
const rgb<n>& lhs,
const typename rgb<n>::interop& rhs)
663 typename rgb<n>::interop tmp(lhs.to_interop() +
rhs);
667 template <
unsigned n>
669 typename rgb<n>::interop
670 operator+(
const typename rgb<n>::interop& lhs,
const rgb<n>& rhs)
672 typename rgb<n>::interop tmp(lhs + rhs.to_interop());
676 template <
unsigned n>
678 typename rgb<n>::interop
679 operator-(
const rgb<n>& lhs,
const rgb<n>& rhs)
681 typename rgb<n>::interop tmp(lhs.to_interop() - rhs.to_interop());
685 template <
unsigned n>
687 typename rgb<n>::interop
688 operator-(
const rgb<n>& lhs,
const typename rgb<n>::interop& rhs)
690 typename rgb<n>::interop tmp(lhs.to_interop() -
rhs);
694 template <
unsigned n>
696 typename rgb<n>::interop
697 operator-(
const typename rgb<n>::interop& lhs,
const rgb<n>& rhs)
699 typename rgb<n>::interop tmp(lhs - rhs.to_interop());
703 template <
unsigned n,
typename S>
705 typename rgb<n>::interop
708 typename rgb<n>::interop tmp(lhs.to_interop() * s.
to_equiv());
712 template <
unsigned n,
typename S>
714 typename rgb<n>::interop
717 typename rgb<n>::interop tmp(s.
to_equiv() * lhs.to_interop());
721 template <
unsigned n,
typename S>
723 typename rgb<n>::interop
726 typename rgb<n>::interop tmp(lhs.to_interop() / s.
to_equiv());
730 template <
unsigned n>
732 std::ostream& operator<<(std::ostream& ostr, const rgb<n>& v)
740 template <
unsigned n>
742 std::istream&
operator>>(std::istream& istr, rgb<n>& c)
744 return istr >> c.red() >> c.green() >> c.blue();
750 template <
unsigned m>
752 from_to_(
const rgb<m>& from,
bool& to)
754 to = (from.red() != 0 && from.green() != 0 && from.blue() != 0);
759 from_to_(
const rgb<16>& from, hsl_<float,float,float>& to)
766 from_to_(
const rgb<8>& from, hsl_<float,float,float>& to)
771 template <
unsigned m>
790 # endif // ! MLN_INCLUDE_ONLY
793 #endif // ! MLN_VALUE_RGB_HH