milena r1786: correct structures

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2008-03-19 Caroline Vigouroux <vigour_c@epita.fr> correct structures. * my_cmy.hh: correction. * my_hsi.hh: correction. * my_hsl.hh: correction. * my_hsv.hh: correction. * my_xyz.hh: correction. * my_yiq.hh: correction. * my_yuv.hh: correction. * rgb_to_hsi.hh: correction. --- my_cmy.hh | 137 +++++++++++++++++++++++++++++++++++++---------------- my_hsi.hh | 106 ++++++++++++++++++++--------------------- my_hsl.hh | 134 +++++++++++++++++++++++++++++++++++++--------------- my_hsv.hh | 146 ++++++++++++++++++++++++++++++++++++++++++--------------- my_xyz.hh | 148 +++++++++++++++++++++++++++++++++++++++++----------------- my_yiq.hh | 148 +++++++++++++++++++++++++++++++++++++++++----------------- my_yuv.hh | 148 +++++++++++++++++++++++++++++++++++++++++----------------- rgb_to_hsi.hh | 130 +++++++++++++++++++++++++++----------------------- 8 files changed, 739 insertions(+), 358 deletions(-) Index: trunk/milena/sandbox/vigouroux/color/my_hsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1785) +++ trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1786) @@ -83,63 +83,63 @@ - template <unsigned n> - struct hsi - { - public: - /// Constructor without argument. - hsi<n>(); - - /// Constructor from component values. - hsi<n>(double hue, double sat, double i); - - /// Access to component values. - double hue() const { return this->hue_; } - double sat() const { return this->sat_; } - double i() const { return this->int_; } - - /// Set component values. - void hue(double hue) - { - this->hue_ = hue; - } - void sat(double sat) - { - this->sat_ = sat; - } - void i(double i) - { - mln_precondition(i >= 0); - this->int_ = i; - } - - private: - double hue_; - double sat_; - double int_; - }; +// template <unsigned n> +// struct hsi +// { +// public: +// /// Constructor without argument. +// hsi<n>(); + +// /// Constructor from component values. +// hsi<n>(double hue, double sat, double i); + +// /// Access to component values. +// double hue() const { return this->hue_; } +// double sat() const { return this->sat_; } +// double i() const { return this->int_; } + +// /// Set component values. +// void hue(double hue) +// { +// this->hue_ = hue; +// } +// void sat(double sat) +// { +// this->sat_ = sat; +// } +// void i(double i) +// { +// mln_precondition(i >= 0); +// this->int_ = i; +// } + +// private: +// double hue_; +// double sat_; +// double int_; +// }; # ifndef MLN_INCLUDE_ONLY - template <unsigned n> - inline - hsi<n>::hsi() - :hue_(0), sat_(0), int_(0) - { - } - - template <unsigned n> - inline - hsi<n>::hsi(double h, double sat, double i) - { - mln_invariant(h >= 0); - mln_invariant(sat >= 0); - mln_invariant(i >= 0); - this->hue_ = h; - this->sat_ = sat; - this->i_ = i; - } +// template <unsigned n> +// inline +// hsi<n>::hsi() +// :hue_(0), sat_(0), int_(0) +// { +// } + +// template <unsigned n> +// inline +// hsi<n>::hsi(double h, double sat, double i) +// { +// mln_invariant(h >= 0); +// mln_invariant(sat >= 0); +// mln_invariant(i >= 0); +// this->hue_ = h; +// this->sat_ = sat; +// this->i_ = i; +// } # endif // ! MLN_INCLUDE_ONLY Index: trunk/milena/sandbox/vigouroux/color/my_yuv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_yuv.hh (revision 1785) +++ trunk/milena/sandbox/vigouroux/color/my_yuv.hh (revision 1786) @@ -1,9 +1,3 @@ -// #include <mln/value/ops.hh> - -// #include <mln/value/concept/vectorial.hh> -// #include <mln/value/int_u.hh> -// #include <mln/algebra/vec.hh> - #ifndef MLN_VALUE_YUV_HH # define MLN_VALUE_YUV_HH @@ -11,59 +5,129 @@ { namespace value { - template <unsigned n> - struct yuv + + template <typename E> + struct YUV + { + }; + + template <typename Y, typename U, typename V> + class yuv_ : public YUV< yuv_<Y,U,V> > { public: - /// Constructor without argument. - yuv<n>(); - /// Constructor from component values. - yuv<n>(double y, double u, double v); + typedef Y y_type; + typedef U u_type; + typedef V v_type; - /// Access to component values. - double y() const { return this->y_; } - double u() const { return this->u_; } - double v() const { return this->v_; } + /// Constructor without argument. + yuv_() + { + } - /// Set component values. - void y(double y) + /// Constructor from component values. + yuv_(const Y& y, const U& u, const V& v) + : y_(y), + u_(u), + v_(v) { - this->y_ = y; } - void u(double u) + + /// Read-only access to the y component. + const Y& y() const { - this->u_ = u; + return this->y_; } - void v(double v) + const U& u() const { - mln_precondition(v >= 0); - this->v_ = v; + return this->u_; } - - private: - double y_; - double u_; - double v_; - }; - - template <unsigned n> - inline - yuv<n>::yuv() - :y_(0), u_(0), v_(0) + const V& v() const { + return this->v_; } - template <unsigned n> - inline - yuv<n>::yuv(double y, double u, double v) + /// Read-write access to the y component. + Y& y() { - mln_precondition(v >= 0); - this->y_ = y; - this->u_ = u; - this->v_ = v; + return this->y_; } + U& u() + { + return this->u_; } + V& v() + { + return this->v_; } + private: + Y y_; + U u_; + V v_; + }; + + typedef yuv_<float, float, float> yuv_3x8; + + typedef yuv_<double, double, double> yuv_d; + + } // end of namespace mln::value + +} // end of namespace mln + +// template <unsigned n> +// struct yuv +// { +// public: +// /// Constructor without argument. +// yuv<n>(); + +// /// Constructor from component values. +// yuv<n>(double y, double u, double v); + +// /// Access to component values. +// double y() const { return this->y_; } +// double u() const { return this->u_; } +// double v() const { return this->v_; } + +// /// Set component values. +// void y(double y) +// { +// this->y_ = y; +// } +// void u(double u) +// { +// this->u_ = u; +// } +// void v(double v) +// { +// mln_precondition(v >= 0); +// this->v_ = v; +// } + +// private: +// double y_; +// double u_; +// double v_; +// }; + +// template <unsigned n> +// inline +// yuv<n>::yuv() +// :y_(0), u_(0), v_(0) +// { +// } + +// template <unsigned n> +// inline +// yuv<n>::yuv(double y, double u, double v) +// { +// mln_precondition(v >= 0); +// this->y_ = y; +// this->u_ = u; +// this->v_ = v; +// } +// } +// } + #endif // ! MLN_VALUE_YUV_HH Index: trunk/milena/sandbox/vigouroux/color/my_hsl.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_hsl.hh (revision 1785) +++ trunk/milena/sandbox/vigouroux/color/my_hsl.hh (revision 1786) @@ -11,61 +11,117 @@ { namespace value { - template <unsigned n> - struct hsl + + template <typename E> + struct HSL + { + }; + + template <typename H, typename S, typename L> + class hsl_ : public HSL< hsl_<H,S,L> > { public: + + typedef H h_type; + typedef S s_type; + typedef L l_type; + /// Constructor without argument. - hsl<n>(); + hsl_() + { + } /// Constructor from component values. - hsl<n>(int h, int s, int l); - - /// Access to component values. - double h() const { return this->h_; } - double s() const { return this->s_; } - double l() const { return this->l_; } + hsl_(const H& hue, const S& sat, const L& light) + : hue_(hue), + sat_(sat), + light_(light) + { + } - /// Set component values. - void h(double h) + /// Read-only access to the hue component. + const H& hue() const { - this->h_ = h; + return this->hue_; } - void s(double s) + const S& sat() const { - this->s_ = s; + return this->sat_; } - void l(double l) + const L& light() const { - mln_precondition(l >= 0); - this->l_ = l; + return this->light_; } private: - double h_; - double s_; - double l_; + H hue_; + S sat_; + L light_; }; - template <unsigned n> - inline - hsl<n>::hsl() - :h_(0), s_(0), l_(0) - { - } + typedef hsl_<float, float, float> hsl_3x8; - template <unsigned n> - inline - hsl<n>::hsl(int h, int s, int l) - { - mln_precondition(h >= 0); - mln_precondition(s >= 0); - mln_precondition(l >= 0); - this->h_ = h; - this->s_ = s; - this->l_ = l; - } - } -} + typedef hsl_<double, double, double> hsl_d; + + } // end of namespace mln::value + +} // end of namespace mln + +// template <unsigned n> +// struct hsl +// { +// public: +// /// Constructor without argument. +// hsl<n>(); + +// /// Constructor from component values. +// hsl<n>(int h, int s, int l); + +// /// Access to component values. +// double h() const { return this->h_; } +// double s() const { return this->s_; } +// double l() const { return this->l_; } + +// /// Set component values. +// void h(double h) +// { +// this->h_ = h; +// } +// void s(double s) +// { +// this->s_ = s; +// } +// void l(double l) +// { +// mln_precondition(l >= 0); +// this->l_ = l; +// } + +// private: +// double h_; +// double s_; +// double l_; +// }; + +// template <unsigned n> +// inline +// hsl<n>::hsl() +// :h_(0), s_(0), l_(0) +// { +// } + +// template <unsigned n> +// inline +// hsl<n>::hsl(int h, int s, int l) +// { +// mln_precondition(h >= 0); +// mln_precondition(s >= 0); +// mln_precondition(l >= 0); +// this->h_ = h; +// this->s_ = s; +// this->l_ = l; +// } +// } +// } #endif // ! MLN_VALUE_HSL_HH Index: trunk/milena/sandbox/vigouroux/color/my_cmy.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 1785) +++ trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 1786) @@ -1,3 +1,5 @@ +#include <mln/value/float01_8.hh> + #ifndef MLN_VALUE_CMY_HH # define MLN_VALUE_CMY_HH @@ -5,63 +7,116 @@ { namespace value { - template <unsigned n> - struct cmy + + template <typename E> + struct CMY + { + }; + + template <typename C, typename M, typename Y> + class cmy_ : public CMY< cmy_<C,M,Y> > { public: + + typedef C c_type; + typedef M m_type; + typedef Y y_type; + /// Constructor without argument. - cmy(); + cmy_() + { + } /// Constructor from component values. - cmy(double c, double m, double y); - - /// Access to component values. - double c() const { return this->c_; } - double m() const { return this->m_; } - double y() const { return this->y_; } + cmy_(const C& cyan, const M& magenta, const Y& yellow) + : cyan_(cyan), + magenta_(magenta), + yellow_(yellow) + { + } - /// Set component values. - void c(double c) + /// Read-only access to the cyan component. + const C& cyan() const { - mln_precondition(c >= 0); - this->c_ = c; + return this->cyan_; } - void m(double m) + const M& magenta() const { - mln_precondition(m >= 0); - this->m_ = m; + return this->magenta_; } - void y(double y) + const Y& yellow() const { - mln_precondition(y >= 0); - this->y_ = y; + return this->yellow_; } private: - double c_; - double m_; - double y_; + C cyan_; + M magenta_; + Y yellow_; }; - template <unsigned n> - inline - cmy<n>::cmy() - :c_(0), m_(0), y_(0) - { - } + typedef cmy_<float, float, float> cmy_3x8; - template <unsigned n> - inline - cmy<n>::cmy(double c, double m, double y) - { - mln_precondition(c >= 0); - mln_precondition(m >= 0); - mln_precondition(y >= 0); - this->c_ = c; - this->m_ = m; - this->y_ = y; - } - } -} + typedef cmy_<double, double, double> cmy_d; + } // end of namespace mln::value + +} // end of namespace mln + +// template <unsigned n> +// struct cmy +// { +// public: +// /// Constructor without argument. +// cmy(); + +// /// Constructor from component values. +// cmy(double c, double m, double y); + +// /// Access to component values. +// double c() const { return this->c_; } +// double m() const { return this->m_; } +// double y() const { return this->y_; } + +// /// Set component values. +// void c(double c) +// { +// mln_precondition(c >= 0); +// this->c_ = c; +// } +// void m(double m) +// { +// mln_precondition(m >= 0); +// this->m_ = m; +// } +// void y(double y) +// { +// mln_precondition(y >= 0); +// this->y_ = y; +// } + +// private: +// double c_; +// double m_; +// double y_; +// }; + +// template <unsigned n> +// inline +// cmy<n>::cmy() +// :c_(0), m_(0), y_(0) +// { +// } + +// template <unsigned n> +// inline +// cmy<n>::cmy(double c, double m, double y) +// { +// mln_precondition(c >= 0); +// mln_precondition(m >= 0); +// mln_precondition(y >= 0); +// this->c_ = c; +// this->m_ = m; +// this->y_ = y; +// } #endif // ! MLN_VALUE_CMY_HH Index: trunk/milena/sandbox/vigouroux/color/my_xyz.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_xyz.hh (revision 1785) +++ trunk/milena/sandbox/vigouroux/color/my_xyz.hh (revision 1786) @@ -1,9 +1,3 @@ -// #include <mln/value/ops.hh> - -// #include <mln/value/concept/vectorial.hh> -// #include <mln/value/int_u.hh> -// #include <mln/algebra/vec.hh> - #ifndef MLN_VALUE_XYZ_HH # define MLN_VALUE_XYZ_HH @@ -11,59 +5,129 @@ { namespace value { - template <unsigned n> - struct xyz + + template <typename E> + struct XYZ + { + }; + + template <typename X, typename Y, typename Z> + class xyz_ : public XYZ< xyz_<X,Y,Z> > { public: - /// Constructor without argument. - xyz<n>(); - /// Constructor from component values. - xyz<n>(double x, double y, double z); + typedef X x_type; + typedef Y y_type; + typedef Z z_type; - /// Access to component values. - double x() const { return this->x_; } - double y() const { return this->y_; } - double z() const { return this->z_; } + /// Constructor without argument. + xyz_() + { + } - /// Set component values. - void x(double x) + /// Constructor from component values. + xyz_(const X& x, const Y& y, const Z& z) + : x_(x), + y_(y), + z_(z) { - this->x_ = x; } - void y(double y) + + /// Read-only access to the x component. + const X& x() const { - this->y_ = y; + return this->x_; } - void z(double z) + const Y& y() const { - mln_precondition(z >= 0); - this->z_ = z; + return this->y_; } - - private: - double x_; - double y_; - double z_; - }; - - template <unsigned n> - inline - xyz<n>::xyz() - :x_(0), y_(0), z_(0) + const Z& z() const { + return this->z_; } - template <unsigned n> - inline - xyz<n>::xyz(double x, double y, double z) + /// Read-write access to the x component. + X& x() { - mln_precondition(z >= 0); - this->x_ = x; - this->y_ = y; - this->z_ = z; + return this->x_; } + Y& y() + { + return this->y_; } + Z& z() + { + return this->z_; } + private: + X x_; + Y y_; + Z z_; + }; + + typedef xyz_<float, float, float> xyz_3x8; + + typedef xyz_<double, double, double> xyz_d; + + } // end of namespace mln::value + +} // end of namespace mln + +// template <unsigned n> +// struct xyz +// { +// public: +// /// Constructor without argument. +// xyz<n>(); + +// /// Constructor from component values. +// xyz<n>(double x, double y, double z); + +// /// Access to component values. +// double x() const { return this->x_; } +// double y() const { return this->y_; } +// double z() const { return this->z_; } + +// /// Set component values. +// void x(double x) +// { +// this->x_ = x; +// } +// void y(double y) +// { +// this->y_ = y; +// } +// void z(double z) +// { +// mln_precondition(z >= 0); +// this->z_ = z; +// } + +// private: +// double x_; +// double y_; +// double z_; +// }; + +// template <unsigned n> +// inline +// xyz<n>::xyz() +// :x_(0), y_(0), z_(0) +// { +// } + +// template <unsigned n> +// inline +// xyz<n>::xyz(double x, double y, double z) +// { +// mln_precondition(z >= 0); +// this->x_ = x; +// this->y_ = y; +// this->z_ = z; +// } +// } +// } + #endif // ! MLN_VALUE_XYZ_HH Index: trunk/milena/sandbox/vigouroux/color/my_hsv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_hsv.hh (revision 1785) +++ trunk/milena/sandbox/vigouroux/color/my_hsv.hh (revision 1786) @@ -11,61 +11,131 @@ { namespace value { - template <unsigned n> - struct hsv + + template <typename E> + struct HSV + { + }; + + template <typename H, typename S, typename V> + class hsv_ : public HSV< hsv_<H,S,V> > { public: + + typedef H h_type; + typedef S s_type; + typedef V v_type; + /// Constructor without argument. - hsv<n>(); + hsv_() + { + } /// Constructor from component values. - hsv<n>(int h, int s, int v); + hsv_(const H& hue, const S& sat, const V& value) + : hue_(hue), + sat_(sat), + value_(value) + { + } - /// Access to component values. - double h() const { return this->h_; } - double s() const { return this->s_; } - double v() const { return this->v_; } + /// Read-only access to the hue component. + const H& hue() const + { + return this->hue_; + } + const S& sat() const + { + return this->sat_; + } + const V& value() const + { + return this->value_; + } - /// Set component values. - void h(double h) + /// Read-write access to the hue component. + H& hue() { - this->h_ = h; + return this->hue_; } - void s(double s) + S& sat() { - this->s_ = s; + return this->sat_; } - void v(double v) + V& value() { - mln_precondition(v >= 0); - this->v_ = v; + return this->value_; } private: - double h_; - double s_; - double v_; + H hue_; + S sat_; + V value_; }; - template <unsigned n> - inline - hsi<n>::hsv() - :h_(0), s_(0), v_(0) - { - } + typedef hsv_<float, float, float> hsv_3x8; - template <unsigned n> - inline - hsv<n>::hsv(int h, int s, int v) - { - mln_precondition(h >= 0); - mln_precondition(s >= 0); - mln_precondition(v >= 0); - this->h_ = h; - this->s_ = s; - this->v_ = v; - } - } -} + typedef hsv_<double, double, double> hsv_d; + + } // end of namespace mln::value + +} // end of namespace mln + +// template <unsigned n> +// struct hsv +// { +// public: +// /// Constructor without argument. +// hsv<n>(); + +// /// Constructor from component values. +// hsv<n>(int h, int s, int v); + +// /// Access to component values. +// double h() const { return this->h_; } +// double s() const { return this->s_; } +// double v() const { return this->v_; } + +// /// Set component values. +// void h(double h) +// { +// this->h_ = h; +// } +// void s(double s) +// { +// this->s_ = s; +// } +// void v(double v) +// { +// mln_precondition(v >= 0); +// this->v_ = v; +// } + +// private: +// double h_; +// double s_; +// double v_; +// }; + +// template <unsigned n> +// inline +// hsi<n>::hsv() +// :h_(0), s_(0), v_(0) +// { +// } + +// template <unsigned n> +// inline +// hsv<n>::hsv(int h, int s, int v) +// { +// mln_precondition(h >= 0); +// mln_precondition(s >= 0); +// mln_precondition(v >= 0); +// this->h_ = h; +// this->s_ = s; +// this->v_ = v; +// } +// } +// } #endif // ! MLN_VALUE_HSV_HH Index: trunk/milena/sandbox/vigouroux/color/my_yiq.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_yiq.hh (revision 1785) +++ trunk/milena/sandbox/vigouroux/color/my_yiq.hh (revision 1786) @@ -1,9 +1,3 @@ -// #include <mln/value/ops.hh> - -// #include <mln/value/concept/vectorial.hh> -// #include <mln/value/int_u.hh> -// #include <mln/algebra/vec.hh> - #ifndef MLN_VALUE_YIQ_HH # define MLN_VALUE_YIQ_HH @@ -11,59 +5,129 @@ { namespace value { - template <unsigned n> - struct yiq + + template <typename E> + struct YIQ + { + }; + + template <typename Y, typename I, typename Q> + class yiq_ : public YIQ< yiq_<Y,I,Q> > { public: - /// Constructor without argument. - yiq<n>(); - /// Constructor from component values. - yiq<n>(double y, double i, double q); + typedef Y y_type; + typedef I i_type; + typedef Q q_type; - /// Access to component values. - double y() const { return this->y_; } - double i() const { return this->i_; } - double q() const { return this->q_; } + /// Constructor without argument. + yiq_() + { + } - /// Set component values. - void y(double y) + /// Constructor from component values. + yiq_(const Y& y, const I& i, const Q& q) + : y_(y), + i_(i), + q_(q) { - this->y_ = y; } - void i(double i) + + /// Read-only access to the y component. + const Y& y() const { - this->i_ = i; + return this->y_; } - void q(double q) + const I& i() const { - mln_precondition(q >= 0); - this->q_ = q; + return this->i_; } - - private: - double y_; - double i_; - double q_; - }; - - template <unsigned n> - inline - yiq<n>::yiq() - :y_(0), i_(0), q_(0) + const Q& q() const { + return this->q_; } - template <unsigned n> - inline - yiq<n>::yiq(double y, double i, double q) + /// Read-write access to the y component. + Y& y() { - mln_precondition(q >= 0); - this->y_ = y; - this->i_ = i; - this->q_ = q; + return this->y_; } + I& i() + { + return this->i_; } + Q& q() + { + return this->q_; } + private: + Y y_; + I i_; + Q q_; + }; + + typedef yiq_<float, float, float> yiq_3x8; + + typedef yiq_<double, double, double> yiq_d; + + } // end of namespace mln::value + +} // end of namespace mln + +// template <unsigned n> +// struct yiq +// { +// public: +// /// Constructor without argument. +// yiq<n>(); + +// /// Constructor from component values. +// yiq<n>(double y, double i, double q); + +// /// Access to component values. +// double y() const { return this->y_; } +// double i() const { return this->i_; } +// double q() const { return this->q_; } + +// /// Set component values. +// void y(double y) +// { +// this->y_ = y; +// } +// void i(double i) +// { +// this->i_ = i; +// } +// void q(double q) +// { +// mln_precondition(q >= 0); +// this->q_ = q; +// } + +// private: +// double y_; +// double i_; +// double q_; +// }; + +// template <unsigned n> +// inline +// yiq<n>::yiq() +// :y_(0), i_(0), q_(0) +// { +// } + +// template <unsigned n> +// inline +// yiq<n>::yiq(double y, double i, double q) +// { +// mln_precondition(q >= 0); +// this->y_ = y; +// this->i_ = i; +// this->q_ = q; +// } +// } +// } + #endif // ! MLN_VALUE_YIQ_HH Index: trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1785) +++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1786) @@ -8,6 +8,7 @@ #include <mln/io/ppm/save.hh> #include <mln/display/save_and_show.hh> #include <mln/level/fill.hh> +#include <mln/math/round.hh> #include "my_hsi.hh" @@ -77,21 +78,28 @@ template <typename T_hsi> T_rgb operator()(const T_hsi& hsi) const { - int r; - int g; - int b; - - static const double sqrt3_3 = sqrt(3) / 3; - static const double inv_sqrt6 = 1 / sqrt(6); - static const double inv_sqrt2 = 1 / sqrt(2); - - double h = hsi.hue() / 180.0 * 3.1415; - double alpha = hsi.sat() * cos(h); - double beta = hsi.sat() * sin(h); - - r = int(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta); - g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta); - b = int(sqrt3_3 * hsi.i() - inv_sqrt2 * alpha - inv_sqrt6 * beta); + typedef typename T_rgb::red_t red_t; + typedef typename T_rgb::green_t green_t; + typedef typename T_rgb::blue_t blue_t; + + static math::round<red_t> to_r; + static math::round<green_t> to_g; + static math::round<blue_t> to_b; + + static const float + sqrt3_3 = std::sqrt(3) / 3, + inv_sqrt6 = 1 / std::sqrt(6), + inv_sqrt2 = 1 / std::sqrt(2); + + float + h = hsi.hue() / 180.0 * 3.1415, + alpha = hsi.sat() * std::cos(h), + beta = hsi.sat() * std::sin(h); + + + red_t r = to_r(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta); + green_t g = to_g(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta); + blue_t b = to_b(sqrt3_3 * hsi.i() - inv_sqrt2 * alpha - inv_sqrt6 * beta); T_rgb rgb(r, g, b); @@ -110,63 +118,63 @@ } // end of namespace fun +} + // namespace convert +// { - namespace convert - { - - struct f_rgb_to_hsi - { - value::hsi<8> operator()(const value::rgb<8>& rgb) const - { - struct value::hsi<8> hsi; - double sqrt3_3 = sqrt(3) / 3; - double inv_sqrt6 = 1 / sqrt(6); - double inv_sqrt2 = 1 / sqrt(2); - - double alpha = inv_sqrt2 * rgb.green() - inv_sqrt2 * rgb.blue(); - double beta = 2 * inv_sqrt6 * rgb.red() - inv_sqrt6 * rgb.green() - inv_sqrt6 * rgb.blue(); - - hsi.hue(atan2(beta, alpha) / 3.1415 * 180.0); - if (hsi.hue() < 0) - hsi.hue(hsi.hue() + 360.0); - mln_precondition(hsi.hue() >= 0); - hsi.sat(sqrt(alpha * alpha + beta * beta)); - hsi.i(sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue()); +// struct f_rgb_to_hsi +// { +// value::hsi<8> operator()(const value::rgb<8>& rgb) const +// { +// struct value::hsi<8> hsi; +// double sqrt3_3 = sqrt(3) / 3; +// double inv_sqrt6 = 1 / sqrt(6); +// double inv_sqrt2 = 1 / sqrt(2); + +// double alpha = inv_sqrt2 * rgb.green() - inv_sqrt2 * rgb.blue(); +// double beta = 2 * inv_sqrt6 * rgb.red() - inv_sqrt6 * rgb.green() - inv_sqrt6 * rgb.blue(); + +// hsi.hue(atan2(beta, alpha) / 3.1415 * 180.0); +// if (hsi.hue() < 0) +// hsi.hue(hsi.hue() + 360.0); +// mln_precondition(hsi.hue() >= 0); +// hsi.sat(sqrt(alpha * alpha + beta * beta)); +// hsi.i(sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue()); - return hsi; - } - }; +// return hsi; +// } +// }; - struct f_hsi_to_rgb - { +// struct f_hsi_to_rgb +// { - value::rgb<8> doit(const value::hsi<8>& hsi) const - { - int r; - int g; - int b; +// value::rgb<8> doit(const value::hsi<8>& hsi) const +// { +// int r; +// int g; +// int b; - double sqrt3_3 = sqrt(3) / 3; - double inv_sqrt6 = 1 / sqrt(6); - double inv_sqrt2 = 1 / sqrt(2); +// double sqrt3_3 = sqrt(3) / 3; +// double inv_sqrt6 = 1 / sqrt(6); +// double inv_sqrt2 = 1 / sqrt(2); - double h = hsi.hue() / 180.0 * 3.1415; - double alpha = hsi.sat() * cos(h); - double beta = hsi.sat() * sin(h); +// double h = hsi.hue() / 180.0 * 3.1415; +// double alpha = hsi.sat() * cos(h); +// double beta = hsi.sat() * sin(h); - r = int(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta); - g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta); - b = int(sqrt3_3 * hsi.i() - inv_sqrt2 * alpha - inv_sqrt6 * beta); +// r = int(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta); +// g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta); +// b = int(sqrt3_3 * hsi.i() - inv_sqrt2 * alpha - inv_sqrt6 * beta); - value::rgb<8> rgb(r, g, b); +// value::rgb<8> rgb(r, g, b); - return rgb; - } - }; +// return rgb; +// } +// }; - } // end of FIXME +// } // end of FIXME -} // end of FIXME +// } // end of FIXME
participants (1)
-
Caroline Vigouroux