
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2008-02-13 Caroline Vigouroux <vigour_c@epita.fr> color structures. * my_cmy.hh: CMY struct. * my_hsi.hh: HSI struct. * my_yuv.hh: YUV struct. * rgb_to_cmy.hh: transform equations. * rgb_to_hsi.hh: transform equations. * rgb_to_yuv.hh: transform equations. * tests.cc: New test. --- my_cmy.hh | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ my_hsi.hh | 46 ++++++++++++++++++++++++++++++++++++++ my_yuv.hh | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rgb_to_cmy.hh | 43 ++++++++++++++++++++++++++++++++++++ rgb_to_hsi.hh | 43 ++++++++++++++++++++++++++++++++++++ rgb_to_yuv.hh | 43 ++++++++++++++++++++++++++++++++++++ tests.cc | 22 ++++++++++++++++++ 7 files changed, 333 insertions(+) Index: trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh (revision 1722) @@ -0,0 +1,43 @@ +#include <mln/core/image_if_value.hh> +#include <mln/core/inplace.hh> +#include <mln/core/w_window2d_int.hh> +#include <mln/display/show.hh> +#include <mln/io/ppm/save.hh> +#include <mln/display/save_and_show.hh> +#include <mln/level/fill.hh> + +#include "my_cmy.hh" + +namespace mln { + namespace convert { + struct f_rgb_to_cmy + { + struct value::cmy + doit(const struct value::rgb<8> rgb) const + { + struct value::cmy cmy; + + cmy.c(1 - rgb.red()); + cmy.m(1 - rgb.green()); + cmy.y(1 - rgb.blue()); + + return (cmy); + } + }; + + struct f_cmy_to_rgb + { + struct value::rgb<8> + doit(const struct value::cmy cmy) const + { + struct value::rgb<8> rgb; + + rgb.red() = 1 - cmy.c(); + rgb.green() = 1 - cmy.m(); + rgb.blue() = 1 - cmy.y(); + + return (rgb); + } + }; + } +} Index: trunk/milena/sandbox/vigouroux/color/tests.cc =================================================================== --- trunk/milena/sandbox/vigouroux/color/tests.cc (revision 0) +++ trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1722) @@ -0,0 +1,22 @@ +#include <mln/core/image_if_value.hh> +#include <mln/core/inplace.hh> +#include <mln/core/w_window2d_int.hh> +#include <mln/display/show.hh> +#include <mln/io/ppm/save.hh> +#include <mln/display/save_and_show.hh> +#include <mln/level/fill.hh> + +#include "rgb_to_yuv.hh" +#include "my_yuv.hh" + +int main() +{ + using namespace mln; + + struct value::yuv yuv(4, 4, 4); + std::cout << yuv.y() << std::endl; + std::cout << yuv.u() << std::endl; + std::cout << yuv.v() << std::endl; + + return (0); +} Index: trunk/milena/sandbox/vigouroux/color/my_hsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1722) @@ -0,0 +1,46 @@ +#include <mln/value/ops.hh> + +#include <mln/value/concept/vectorial.hh> +#include <mln/value/int_u.hh> +#include <mln/metal/vec.hh> + +namespace mln +{ + namespace value + { + template <unsigned n> + struct hsi + { + public: + /// Constructor without argument. + hsi<n>(); + + /// Constructor from component values. + hsi<n>(int h, int s, int i); + + private: + int h_; + int s_; + int i_; + }; + + template <unsigned n> + inline + hsi::hsi<n>() + :h_(0), s_(0), i_(0) + { + } + + template <unsigned n> + inline + hsi::hsi<n>(int h, int s, int i) + { + mln_precondition(h >= 0); + mln_precondition(s >= 0); + mln_precondition(i >= 0); + this->h_ = h; + this->s_ = s; + this->i_ = i; + } + } +} Index: trunk/milena/sandbox/vigouroux/color/my_yuv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_yuv.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/my_yuv.hh (revision 1722) @@ -0,0 +1,69 @@ +// #include <mln/value/ops.hh> + +// #include <mln/value/concept/vectorial.hh> +// #include <mln/value/int_u.hh> +// #include <mln/metal/vec.hh> + +#ifndef MLN_VALUE_YUV_HH +# define MLN_VALUE_YUV_HH + +namespace mln +{ + namespace value + { + 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_cmy.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 1722) @@ -0,0 +1,67 @@ +#ifndef MLN_VALUE_YUV_HH +# define MLN_VALUE_YUV_HH + +namespace mln +{ + namespace value + { +// 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 + yuv::cmy() + :c_(0), m_(0), y_(0) + { + } + +// template <unsigned n> + inline + cmy::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_YUV_HH Index: trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh (revision 1722) @@ -0,0 +1,43 @@ +#include <mln/core/image_if_value.hh> +#include <mln/core/inplace.hh> +#include <mln/core/w_window2d_int.hh> +#include <mln/display/show.hh> +#include <mln/io/ppm/save.hh> +#include <mln/display/save_and_show.hh> +#include <mln/level/fill.hh> + +#include "my_yuv.hh" + +namespace mln { + namespace convert { + struct f_rgb_to_yuv + { + struct mln::value::yuv<8> + doit(const struct value::rgb<8> rgb) const + { + struct value::yuv<8> yuv; + + yuv.y(0.299 * rgb.red() + 0.587 * rgb.green() + 0.114 * rgb.blue()); + yuv.u(0.436 * (rgb.blue() - yuv.y()) / (1 - 0.114)); + yuv.v(0.615 * (rgb.red() - yuv.y()) / (1 - 0.299)); + + return (yuv); + } + }; + + struct f_yuv_to_rgb + { + struct value::rgb<8> + doit(const struct value::yuv<8> yuv) const + { + struct value::rgb<8> rgb; + + rgb.red(yuv.y() + 1.13983 * yuv.v()); + rgb.green(yuv.y() - 0.39465 * yuv.u() - 0.58060 * yuv.v()); + rgb.blue(yuv.y() + 2.03211 * yuv.u()); + + return (rgb); + } + }; + } +} Index: trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1722) @@ -0,0 +1,43 @@ +#include <mln/core/image_if_value.hh> +#include <mln/core/inplace.hh> +#include <mln/core/w_window2d_int.hh> +#include <mln/display/show.hh> +#include <mln/io/ppm/save.hh> +#include <mln/display/save_and_show.hh> +#include <mln/level/fill.hh> + +#include "my_hsi.hh" + +namespace mln { + namespace convert { + struct f_rgb_to_hsi + { + struct value::hsi + doit(const struct value::rgb<8> rgb) const + { + struct value::hsi hsi; + + hsi.h(0.299 * rgb.red() + 0.587 * rgb.green() + 0.114 * rgb.blue()); + hsi.s(0.436 * (rgb.blue() - yuv.y()) / (1 - 0.114)); + hsi.i(0.615 * (rgb.red() - yuv.y()) / (1 - 0.299)); + + return (hsi); + } + }; + + struct f_hsi_to_rgb + { + struct value::rgb<8> + doit(const struct value::hsi hsi) const + { + struct value::rgb<8> rgb; + + rgb.red() = yuv.y() + 1.13983 * yuv.v(); + rgb.green() = yuv.y() - 0.39465 * yuv.u() - 0.58060 * yuv.v(); + rgb.blue() = yuv.y() + 2.03211 * yuv.u(); + + return (rgb); + } + }; + } +}