26 #ifndef MLN_VALUE_QT_RGB32_HH
27 # define MLN_VALUE_QT_RGB32_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/rgb8.hh>
39 # include <mln/literal/zero.hh>
40 # include <mln/literal/black.hh>
41 # include <mln/literal/white.hh>
47 namespace value {
namespace qt {
struct rgb32; } }
87 void from_to_(
const value::int_u<m>& from, value::qt::rgb32&
to);
90 template <
typename H,
typename S,
typename L>
91 void from_to_(
const value::hsl_<H,S,L>&, value::qt::rgb32&
to);
94 void from_to_(
const value::qt::rgb32& from,
bool&
to);
98 void from_to_(
const bool& from, value::qt::rgb32&
to);
120 template <
typename S >
126 template <
typename S >
139 template <
unsigned m >
145 template <
unsigned m >
153 struct value_< mln::value::qt::rgb32 >
158 card = mln_value_card_from_(nbits)
161 typedef trait::value::nature::vectorial nature;
162 typedef trait::value::kind::color kind;
163 typedef trait::value::quant::high quant;
170 template <
typename V>
static comp_0 get_comp_0(
const V& v) {
return v.red(); }
171 template <
typename V>
static comp_1 get_comp_1(
const V& v) {
return v.green(); }
172 template <
typename V>
static comp_2 get_comp_2(
const V& v) {
return v.blue(); }
174 typedef algebra::vec<dim, float>
sum;
176 static const char* name()
178 static std::string s =
"qt_rgb32";
199 public Vectorial< rgb32 >,
200 public internal::value_like_< algebra::vec< 3, int_u<8> >,
201 algebra::vec< 3, int_u<8> >,
202 algebra::vec< 3, int >,
215 int_u<8> green()
const {
return this->v_[1]; }
216 int_u<8>& green() {
return this->v_[1]; }
218 int_u<8> blue()
const {
return this->v_[0]; }
219 int_u<8>& blue() {
return this->v_[0]; }
221 int_u<8> comp(
unsigned k)
const {
return this->v_[k]; }
222 int_u<8>& comp(
unsigned k) {
return this->v_[k]; }
229 rgb32(
int r,
int g,
int b);
232 rgb32(
const algebra::vec<3, int>& rhs);
233 rgb32(
const algebra::vec<3, unsigned>& rhs);
234 rgb32(
const algebra::vec<3, int_u<8> >& rhs);
235 rgb32(
const algebra::vec<3, float>& rhs);
238 operator algebra::vec<3, int>()
const;
240 operator algebra::vec<3, float>()
const;
249 rgb32(
const mln::literal::medium_gray_t&);
250 rgb32(
const mln::literal::dark_gray_t&);
288 std::ostream& operator<<(std::ostream& ostr,
const rgb32& c);
291 std::istream& operator>>(std::istream& istr,
rgb32& c);
305 operator+(
const rgb32& lhs,
const rgb32& rhs);
309 operator+(
const rgb32::interop& lhs,
const rgb32& rhs);
313 operator+(
const rgb32& lhs,
const rgb32::interop& rhs);
320 operator-(
const rgb32& lhs,
const rgb32& rhs);
324 operator-(
const rgb32::interop& lhs,
const rgb32& rhs);
328 operator-(
const rgb32& lhs,
const rgb32::interop& rhs);
333 template <
typename S>
336 operator*(
const rgb32& lhs,
const mln::value::scalar_<S>& s);
338 template <
typename S>
341 operator*(
const mln::value::scalar_<S>& s,
const rgb32& lhs);
346 template <
typename S>
349 operator/(
const rgb32& lhs,
const mln::value::scalar_<S>& s);
361 # ifndef MLN_INCLUDE_ONLY
372 # ifndef MLN_WO_GLOBAL_VARS
376 # endif // !MLN_WO_GLOBAL_VARS
420 this->v_[0] = unsigned(v[2]);
421 this->v_[1] = unsigned(v[1]);
422 this->v_[2] = unsigned(v[0]);
429 mln_precondition(r >= 0);
430 mln_precondition(g >= 0);
431 mln_precondition(b >= 0);
432 mln_precondition(
unsigned(r) <= mln_max(
int_u<8>));
433 mln_precondition(
unsigned(g) <= mln_max(
int_u<8>));
434 mln_precondition(
unsigned(b) <= mln_max(
int_u<8>));
471 this->v_[0] = unsigned(mln_max(
int_u<8>) * 0.75);
472 this->v_[1] = unsigned(mln_max(
int_u<8>) * 0.75);
473 this->v_[2] = unsigned(mln_max(
int_u<8>) * 0.75);
480 this->v_[0] = unsigned(mln_max(int_u<8>) * 0.50);
481 this->v_[1] = unsigned(mln_max(int_u<8>) * 0.50);
482 this->v_[2] = unsigned(mln_max(int_u<8>) * 0.50);
489 this->v_[0] = unsigned(mln_max(int_u<8>) * 0.25);
490 this->v_[1] = unsigned(mln_max(int_u<8>) * 0.25);
491 this->v_[2] = unsigned(mln_max(int_u<8>) * 0.25);
500 this->v_[2] = mln_max(int_u<8>);
508 this->v_[1] = mln_max(int_u<8>);
516 this->v_[0] = mln_max(int_u<8>);
525 this->v_[0] = unsigned(mln_max(int_u<8>) * 0.25);
526 this->v_[1] = unsigned(mln_max(int_u<8>) * 0.50);
527 this->v_[2] = unsigned(mln_max(int_u<8>) * 0.75);
535 this->v_[1] = mln_max(int_u<8>);
536 this->v_[2] = unsigned(mln_max(int_u<8>) * 0.75);
544 this->v_[1] = unsigned(mln_max(int_u<8>) * 0.50);
545 this->v_[2] = mln_max(int_u<8>);
552 this->v_[0] = unsigned(mln_max(int_u<8>) * 0.75);
553 this->v_[1] = unsigned(mln_max(int_u<8>) * 0.75);
554 this->v_[2] = mln_max(int_u<8>);
561 this->v_[0] = unsigned(mln_max(int_u<8>) * 0.25);
563 this->v_[2] = unsigned(mln_max(int_u<8>) * 0.75);
570 this->v_[0] = unsigned(mln_max(int_u<8>) * 0.50);
571 this->v_[1] = unsigned(mln_max(int_u<8>) * 0.50);
579 this->v_[0] = unsigned(mln_max(int_u<8>) * 0.50);
581 this->v_[2] = unsigned(mln_max(int_u<8>) * 0.50);
588 this->v_[0] = mln_max(int_u<8>);
589 this->v_[1] = mln_max(int_u<8>);
597 this->v_[0] = mln_max(int_u<8>);
599 this->v_[2] = mln_max(int_u<8>);
607 this->v_[1] = mln_max(int_u<8>);
608 this->v_[2] = mln_max(int_u<8>);
616 this->v_[1] = unsigned(mln_max(int_u<8>) * 0.50);
617 this->v_[2] = unsigned(mln_max(int_u<8>) * 0.50);
633 rgb32::operator algebra::vec<3, int>()
const
635 algebra::vec<3, int> out;
636 out[0] = this->v_[2];
637 out[1] = this->v_[1];
638 out[2] = this->v_[0];
643 rgb32::operator algebra::vec<3, float>()
const
645 algebra::vec<3, float> out;
646 out[0] = this->v_[2];
647 out[1] = this->v_[1];
648 out[2] = this->v_[0];
660 operator+(
const rgb32& lhs,
const rgb32& rhs)
662 rgb32::interop tmp(lhs.to_interop() + rhs.to_interop());
669 operator+(
const rgb32& lhs,
const rgb32::interop& rhs)
671 rgb32::interop tmp(lhs.to_interop() + rhs);
678 operator+(
const rgb32::interop& lhs,
const rgb32& rhs)
680 rgb32::interop tmp(lhs + rhs.to_interop());
687 operator-(
const rgb32& lhs,
const rgb32& rhs)
689 rgb32::interop tmp(lhs.to_interop() - rhs.to_interop());
696 operator-(
const rgb32& lhs,
const rgb32::interop& rhs)
698 rgb32::interop tmp(lhs.to_interop() - rhs);
705 operator-(
const rgb32::interop& lhs,
const rgb32& rhs)
707 rgb32::interop tmp(lhs - rhs.to_interop());
711 template <
typename S>
714 operator*(
const rgb32& lhs,
const mln::value::scalar_<S>& s)
716 rgb32::interop tmp(lhs.to_interop() * s.to_equiv());
720 template <
typename S>
723 operator*(
const mln::value::scalar_<S>& s,
const rgb32& lhs)
725 rgb32::interop tmp(s.to_equiv() * lhs.to_interop());
729 template <
typename S>
732 operator/(
const rgb32& lhs,
const mln::value::scalar_<S>& s)
734 rgb32::interop tmp(lhs.to_interop() / s.to_equiv());
740 std::ostream& operator<<(std::ostream& ostr,
const rgb32& v)
750 std::istream& operator>>(std::istream& istr, rgb32& c)
752 return istr >> c.red() >> c.green() >> c.blue();
767 template <
unsigned m>
769 from_to_(
const value::int_u<m>& from, value::qt::rgb32&
to)
771 mlc_bool(m <= 8)::check();
772 to = value::qt::rgb32(from, from, from);
777 template <
typename H,
typename S,
typename L>
778 void from_to_(
const value::hsl_<H,S,L>& from, value::qt::rgb32& to)
787 void from_to_(
const value::qt::rgb32& from,
bool& to)
795 void from_to_(
const bool& from, value::qt::rgb32& to)
810 # endif // ! MLN_INCLUDE_ONLY
813 #endif // ! MLN_VALUE_QT_RGB32_HH