
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2008-04-17 Caroline Vigouroux <vigour_c@epita.fr> red getters. * cmy/fun.hh, hsi/fun.hh, xyz/fun.hh, yiq/fun.hh, yuv/fun.hh: red getters. * cmy/my_cmy.hh, xyz/my_xyz.hh, yiq/my_yiq.hh, cmy/my_yuv.hh: color space updated. * cmy/rgb_to_cmy.hh, hsi/rgb_to_hsi.hh, xyz/rgb_to_xyz.hh, yiq/rgb_to_yiq.hh, yuv/rgb_to_yuv.hh: conversion updated. * cmy/test.cc, xyz/test.cc: . * color/my_hsl.hh: . * color/my_hsv.hh: . * color/my_xyz.hh: . * color/rgb_to_hsi.hh: . * color/rgb_to_hsl.hh: . * color/rgb_to_xyz.hh: . * function.hh: . * testfun.cc: . * xyz/testfun.cc: New test. * xyz: New folder. * yuv/test.cc: . --- cmy/fun.hh | 6 ++- cmy/my_cmy.hh | 59 -------------------------------- cmy/rgb_to_cmy.hh | 6 +++ cmy/test.cc | 10 ++--- color/my_hsl.hh | 79 +++++++++++--------------------------------- color/my_hsv.hh | 65 +++--------------------------------- color/my_xyz.hh | 68 +++++++------------------------------- color/rgb_to_hsi.hh | 3 - color/rgb_to_hsl.hh | 41 ++++++++++++++++------ color/rgb_to_xyz.hh | 50 ++++++++++++++++++++------- function.hh | 49 --------------------------- hsi/fun.hh | 5 ++ hsi/rgb_to_hsi.hh | 6 ++- testfun.cc | 8 ++-- xyz/fun.hh | 52 +++++++++++++++++++++++++++++ xyz/my_xyz.hh | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++ xyz/rgb_to_xyz.hh | 76 ++++++++++++++++++++++++++++++++++++++++++ xyz/test.cc | 28 +++++++++++++++ xyz/testfun.cc | 31 +++++++++++++++++ yiq/fun.hh | 6 ++- yiq/my_yiq.hh | 55 ------------------------------ yiq/rgb_to_yiq.hh | 6 ++- yuv/fun.hh | 6 ++- yuv/my_yuv.hh | 57 ------------------------------- yuv/rgb_to_yuv.hh | 5 ++ yuv/test.cc | 2 - 26 files changed, 437 insertions(+), 435 deletions(-) Index: trunk/milena/sandbox/vigouroux/yuv/test.cc =================================================================== --- trunk/milena/sandbox/vigouroux/yuv/test.cc (revision 1872) +++ trunk/milena/sandbox/vigouroux/yuv/test.cc (revision 1873) @@ -18,7 +18,7 @@ image2d<value::rgb8> lena; io::ppm::load(lena, "../../../img/lena.ppm"); - image2d< value::yuv_<double, double, double> > lena_hsi + image2d< value::yuv_<float, float, float> > lena_hsi = level::transform(lena, fun::v2v::f_rgb_to_yuv_f()); Index: trunk/milena/sandbox/vigouroux/yuv/my_yuv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/yuv/my_yuv.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/yuv/my_yuv.hh (revision 1873) @@ -80,7 +80,7 @@ V v_; }; - typedef yuv_<float, float, float> yuv_3x8; + typedef yuv_<float, float, float> yuv_f; typedef yuv_<double, double, double> yuv_d; @@ -88,59 +88,4 @@ } // 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/yuv/fun.hh =================================================================== --- trunk/milena/sandbox/vigouroux/yuv/fun.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/yuv/fun.hh (revision 1873) @@ -1,4 +1,3 @@ - #include <cmath> #include <mln/core/image_if_value.hh> @@ -12,7 +11,8 @@ #include "my_yuv.hh" - +#ifndef MLN_YUV_FUN_HH +# define MLN_YUV_FUN_HH namespace mln { @@ -54,3 +54,5 @@ } // end of namespace fun } // end of namespace mln + +#endif // ! MLN_VALUE_YUV_HH Index: trunk/milena/sandbox/vigouroux/yuv/rgb_to_yuv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/yuv/rgb_to_yuv.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/yuv/rgb_to_yuv.hh (revision 1873) @@ -12,6 +12,9 @@ #include "my_yuv.hh" +#ifndef MLN_RGB_TO_YUV_HH +# define MLN_RGB_TO_YUV_HH + namespace mln { @@ -39,6 +42,7 @@ }; typedef f_rgb_to_yuv_< mln::value::yuv_<double, double, double> > f_rgb_to_yuv_d; + typedef f_rgb_to_yuv_< mln::value::yuv_<float, float, float> > f_rgb_to_yuv_f; template <typename T_rgb> struct f_yuv_to_rgb_ : public Function_v2v< f_yuv_to_rgb_<T_rgb> > @@ -72,3 +76,4 @@ } // end of namespace mln +#endif // ! MLN_RGB_TO_YUV_HH Index: trunk/milena/sandbox/vigouroux/hsi/fun.hh =================================================================== --- trunk/milena/sandbox/vigouroux/hsi/fun.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/hsi/fun.hh (revision 1873) @@ -11,7 +11,8 @@ #include "../color/my_hsi.hh" - +#ifndef MLN_HSI_FUN_HH +# define MLN_HSI_FUN_HH namespace mln { @@ -62,3 +63,5 @@ } // end of namespace fun } // end of namespace mln + +#endif // ! MLN_HSI_FUN_HH Index: trunk/milena/sandbox/vigouroux/hsi/rgb_to_hsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/hsi/rgb_to_hsi.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/hsi/rgb_to_hsi.hh (revision 1873) @@ -1,4 +1,3 @@ - #include <cmath> #include <mln/core/image_if_value.hh> @@ -12,7 +11,8 @@ #include "my_hsi.hh" - +#ifndef MLN_RGB_TO_HSI_HH +# define MLN_RGB_TO_HSI_HH namespace mln { @@ -106,3 +106,5 @@ } // end of namespace fun } // end of namespace mln + +#endif // ! MLN_RGB_TO_HSI_HH Index: trunk/milena/sandbox/vigouroux/function.hh =================================================================== --- trunk/milena/sandbox/vigouroux/function.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/function.hh (revision 1873) @@ -1,4 +1,3 @@ - #include <mln/core/image_if_value.hh> #include <mln/core/inplace.hh> #include <mln/core/w_window2d_int.hh> @@ -47,7 +46,7 @@ // r = mln::fun::v2v::f_cmy_3x8(col); // std::cout << "cmy" << std::endl; // } -// else if (mlc_is_a(T_col, mln::value::YUV)::value == 1) +// if (mlc_is_a(T_col, mln::value::YUV)::value == 1) // { // r = mln::fun::v2v::f_yuv_3x8(col); // std::cout << "yuv" << std::endl; @@ -66,52 +65,6 @@ } }; -// typedef f_rgb_to_hsi_<value::hsi_f> f_r// gb_to_hsi_f_t; - -// f_rgb_to_hsi_f_t f_rgb_to_hsi_f; - - -// template <typename T_rgb> -// struct f_hsi_to_rgb_ : public Function_v2v< f_hsi_to_rgb_<T_rgb> > -// { -// typedef T_rgb result; - -// template <typename T_hsi> -// T_rgb operator()(const T_hsi& hsi) const -// { -// 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 = sqrt3_3 * hsi.inty() + 2 * inv_sqrt6 * beta; -// green_t g = sqrt3_3 * hsi.inty() + inv_sqrt2 * alpha - inv_sqrt6 * beta; -// blue_t b = sqrt3_3 * hsi.inty() - inv_sqrt2 * alpha - inv_sqrt6 * beta; - -// T_rgb rgb(r, g, b); - -// return rgb; -// } -// }; - -// typedef f_hsi_to_rgb_<value::rgb8> f_hsi_to_rgb_3x8_t; - -// f_hsi_to_rgb_3x8_t f_hsi_to_rgb_3x8; - } // end of namespace fun::v2v } // end of namespace fun Index: trunk/milena/sandbox/vigouroux/cmy/rgb_to_cmy.hh =================================================================== --- trunk/milena/sandbox/vigouroux/cmy/rgb_to_cmy.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/cmy/rgb_to_cmy.hh (revision 1873) @@ -12,6 +12,9 @@ #include "my_cmy.hh" +#ifndef MLN_RGB_TO_CMY_HH +# define MLN_RGB_TO_CMY_HH + namespace mln { @@ -39,6 +42,7 @@ }; typedef f_rgb_to_cmy_< mln::value::cmy_<double, double, double> > f_rgb_to_cmy_d; + typedef f_rgb_to_cmy_< mln::value::cmy_<float, float, float> > f_rgb_to_cmy_f; template <typename T_rgb> struct f_cmy_to_rgb_ : public Function_v2v< f_cmy_to_rgb_<T_rgb> > @@ -70,3 +74,5 @@ } // end of namespace fun } // end of namespace mln + +#endif // ! MLN_RGB_TO_CMY_HH Index: trunk/milena/sandbox/vigouroux/cmy/test.cc =================================================================== --- trunk/milena/sandbox/vigouroux/cmy/test.cc (revision 1872) +++ trunk/milena/sandbox/vigouroux/cmy/test.cc (revision 1873) @@ -1,5 +1,5 @@ -#include "my_yiq.hh" -#include "rgb_to_yiq.hh" +#include "my_cmy.hh" +#include "rgb_to_cmy.hh" #include <cmath> @@ -18,11 +18,11 @@ image2d<value::rgb8> lena; io::ppm::load(lena, "../../../img/lena.ppm"); - image2d< value::yiq_<double, double, double> > lena_hsi + image2d< value::cmy_<float, float, float> > lena_hsi = level::transform(lena, - fun::v2v::f_rgb_to_yiq_d()); + fun::v2v::f_rgb_to_cmy_f()); image2d<value::rgb8> lena_rgb = level::transform(lena_hsi, - fun::v2v::f_yiq_to_rgb_3x8); + fun::v2v::f_cmy_to_rgb_3x8); } Index: trunk/milena/sandbox/vigouroux/cmy/fun.hh =================================================================== --- trunk/milena/sandbox/vigouroux/cmy/fun.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/cmy/fun.hh (revision 1873) @@ -1,4 +1,3 @@ - #include <cmath> #include <mln/core/image_if_value.hh> @@ -12,7 +11,8 @@ #include "my_cmy.hh" - +#ifndef MLN_CMY_FUN_HH +# define MLN_CMY_FUN_HH namespace mln { @@ -50,3 +50,5 @@ } // end of namespace fun } // end of namespace mln + +#endif // ! MLN_CMY_FUN_HH Index: trunk/milena/sandbox/vigouroux/cmy/my_cmy.hh =================================================================== --- trunk/milena/sandbox/vigouroux/cmy/my_cmy.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/cmy/my_cmy.hh (revision 1873) @@ -80,68 +80,11 @@ Y yellow_; }; - typedef cmy_<float, float, float> cmy_3x8; + typedef cmy_<float, float, float> cmy_f; 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/xyz/test.cc =================================================================== --- trunk/milena/sandbox/vigouroux/xyz/test.cc (revision 0) +++ trunk/milena/sandbox/vigouroux/xyz/test.cc (revision 1873) @@ -0,0 +1,28 @@ +#include "my_xyz.hh" +#include "rgb_to_xyz.hh" + +#include <cmath> + +#include <mln/core/image2d.hh> +#include <mln/value/rgb.hh> + +#include <mln/io/ppm/load.hh> +#include <mln/io/ppm/save.hh> +#include <mln/math/round.hh> +#include <mln/level/transform.hh> + +int main() +{ + using namespace mln; + + image2d<value::rgb8> lena; + io::ppm::load(lena, "../../../img/lena.ppm"); + + image2d< value::xyz_<float, float, float> > lena_hsi + = level::transform(lena, + fun::v2v::f_rgb_to_xyz_f_t()); + +// image2d<value::rgb8> lena_rgb = level::transform(lena_hsi, +// fun::v2v::f_xyz_to_rgb_3x8); +} + Index: trunk/milena/sandbox/vigouroux/xyz/rgb_to_xyz.hh =================================================================== --- trunk/milena/sandbox/vigouroux/xyz/rgb_to_xyz.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/xyz/rgb_to_xyz.hh (revision 1873) @@ -0,0 +1,76 @@ +#ifndef OLENA_CONVERT_RGBXYZ_HH +# define OLENA_CONVERT_RGBXYZ_HH + +# 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_xyz.hh" + +namespace mln +{ + + namespace fun + { + + namespace v2v + { + template <typename T_xyz> + struct f_rgb_to_xyz_ : public Function_v2v< f_rgb_to_xyz_<T_xyz> > + { + typedef T_xyz result; + + template <typename T_rgb> + T_xyz operator()(const T_rgb& rgb) const + { + T_xyz xyz; + + xyz.x() = 0.490 * rgb.red() + 0.310 * rgb.green() + 0.200 * rgb.blue(); + xyz.y() = 0.177 * rgb.red() + 0.812 * rgb.green() + 0.011 * rgb.blue(); + xyz.z() = 0.010 * rgb.green() + 0.990 * rgb.blue(); + + return xyz; + } + }; + + typedef f_rgb_to_xyz_<value::xyz_f> f_rgb_to_xyz_f_t; + +// f_rgb_to_xyz_f_t f_rgb_to_xyz_f; + + template <typename T_rgb> + struct f_xyz_to_rgb_ : public Function_v2v< f_xyz_to_rgb_<T_rgb> > + { + typedef T_rgb result; + + template <typename T_xyz> + T_rgb operator()(const T_xyz& xyz) const + { + int r; + int g; + int b; + + r = int(2.365 * xyz.x() - 0.896 * xyz.y() - 0.468 * xyz.z()); + g = int(-0.515 * xyz.x() + 1.425 * xyz.y() + 0.089 * xyz.z()); + b = int(0.005 * xyz.x() - 0.014 * xyz.y() + 1.01 * xyz.z()); + + struct value::rgb<8> rgb(r, g, b); + + return rgb; + } + }; + + typedef f_xyz_to_rgb_<value::rgb8> f_xyz_to_rgb_3x8_t; + + f_xyz_to_rgb_3x8_t f_xyz_to_rgb_3x8; + + } // end of namespace fun::v2v + + } // end of namespace fun + +} // end of namespace mln + +#endif // OLENA_CONVERT_RGBXYZ_HH Index: trunk/milena/sandbox/vigouroux/xyz/fun.hh =================================================================== --- trunk/milena/sandbox/vigouroux/xyz/fun.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/xyz/fun.hh (revision 1873) @@ -0,0 +1,52 @@ +#include <cmath> + +#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 <mln/math/round.hh> + +#include "my_xyz.hh" + +#ifndef MLN_XYZ_FUN_HH +# define MLN_XYZ_FUN_HH + +namespace mln +{ + + + namespace fun + { + + namespace v2v + { + template <typename T_rgb> + struct f_xyz_ : public Function_v2v< f_xyz_<T_rgb> > + { + typedef T_rgb result; + + template <typename T_xyz> + T_rgb operator()(const T_xyz& xyz) const + { + int r; + + r = int(xyz.y() + 1.13983 * xyz.y()); + + struct value::rgb<8> rgb(r, 0, 0); + + return rgb; + } + }; + + typedef f_xyz_<value::rgb8> f_xyz_get_red; + + } // end of namespace fun::v2v + + } // end of namespace fun + +} // end of namespace mln + +#endif // ! MLN_VALUE_XYZ_HH Index: trunk/milena/sandbox/vigouroux/xyz/testfun.cc =================================================================== --- trunk/milena/sandbox/vigouroux/xyz/testfun.cc (revision 0) +++ trunk/milena/sandbox/vigouroux/xyz/testfun.cc (revision 1873) @@ -0,0 +1,31 @@ +#include "my_xyz.hh" +#include "rgb_to_xyz.hh" + +#include <cmath> + +#include <mln/core/image2d.hh> +#include <mln/value/rgb.hh> + +#include <mln/io/ppm/load.hh> +#include <mln/io/ppm/save.hh> +#include <mln/math/round.hh> +#include <mln/level/transform.hh> + +#include "rgb_to_xyz.hh" +#include "fun.hh" + +int main() +{ +// typedef mln::value::xyz_d Col; + using namespace mln::fun::v2v; + + mln::value::xyz_d col; + mln::image2d<mln::value::rgb8> lena; + mln::io::ppm::load(lena, "../../../img/lena.ppm"); + + mln::image2d<mln::value::xyz_f> lena_xyz = mln::level::transform(lena, + mln::fun::v2v::f_rgb_to_xyz_f_t()); + + mln::image2d<mln::value::rgb8> lena_rgb = mln::level::transform(lena_xyz, + f_xyz_get_red ()); +} Index: trunk/milena/sandbox/vigouroux/xyz/my_xyz.hh =================================================================== --- trunk/milena/sandbox/vigouroux/xyz/my_xyz.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/xyz/my_xyz.hh (revision 1873) @@ -0,0 +1,93 @@ +#include <mln/value/ops.hh> + +#include <mln/value/concept/vectorial.hh> +#include <mln/value/int_u.hh> +#include <mln/algebra/vec.hh> + +#include <mln/value/float01_8.hh> + +#ifndef MLN_VALUE_XYZ_HH +# define MLN_VALUE_XYZ_HH + +namespace mln +{ + namespace value + { + + template <typename E> + struct XYZ + : + public internal::value_like_< algebra::vec< 3, float01_8 >, // Equivalent. + algebra::vec< 3, float01_8 >, // Encoding. + algebra::vec< 3, float01_8 >, // Interoperation. + XYZ<E> > + { + }; + + template <typename X, typename Y, typename Z> + class xyz_ : public XYZ< xyz_<X,Y,Z> > + { + public: + + typedef X x_type; + typedef Y y_type; + typedef Z z_type; + + /// Constructor without argument. + xyz_() + { + } + + /// Constructor from component values. + xyz_(const X& x, const Y& y, const Z& z) + : x_(x), + y_(y), + z_(z) + { + } + + /// Read-only access to the x component. + const X& x() const + { + return this->x_; + } + const Y& y() const + { + return this->y_; + } + const Z& z() const + { + return this->z_; + } + + /// Read-write access to the x component. + X& x() + { + 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_f; + + typedef xyz_<double, double, double> xyz_d; + + } // end of namespace mln::value + +} // end of namespace mln + + + +#endif // ! MLN_VALUE_XYZ_HH Index: trunk/milena/sandbox/vigouroux/yiq/my_yiq.hh =================================================================== --- trunk/milena/sandbox/vigouroux/yiq/my_yiq.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/yiq/my_yiq.hh (revision 1873) @@ -88,59 +88,4 @@ } // 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/yiq/fun.hh =================================================================== --- trunk/milena/sandbox/vigouroux/yiq/fun.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/yiq/fun.hh (revision 1873) @@ -1,4 +1,3 @@ - #include <cmath> #include <mln/core/image_if_value.hh> @@ -12,7 +11,8 @@ #include "my_yiq.hh" - +#ifndef MLN_YIQ_FUN_HH +# define MLN_YIQ_FUN_HH namespace mln { @@ -50,3 +50,5 @@ } // end of namespace fun } // end of namespace mln + +#endif // ! MLN_YIQ_FUN_HH Index: trunk/milena/sandbox/vigouroux/yiq/rgb_to_yiq.hh =================================================================== --- trunk/milena/sandbox/vigouroux/yiq/rgb_to_yiq.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/yiq/rgb_to_yiq.hh (revision 1873) @@ -12,6 +12,9 @@ #include "my_yiq.hh" +#ifndef MLN_RGB_TO_YIQ_HH +# define MLN_RGB_TO_YIQ_HH + namespace mln { @@ -72,5 +75,4 @@ } // end of namespace mln - - +#endif // ! MLN_RGB_TO_YIQ_HH Index: trunk/milena/sandbox/vigouroux/testfun.cc =================================================================== --- trunk/milena/sandbox/vigouroux/testfun.cc (revision 1872) +++ trunk/milena/sandbox/vigouroux/testfun.cc (revision 1873) @@ -12,18 +12,20 @@ #include <mln/level/transform.hh> #include "function.hh" +#include "yuv/my_yuv.hh" +#include "yuv/fun.hh" +#include "yuv/rgb_to_yuv.hh" int main() { -// typedef mln::value::hsi_d Col; using namespace mln::fun::v2v; mln::value::hsi_d col; mln::image2d<mln::value::rgb8> lena; mln::io::ppm::load(lena, "../../img/lena.ppm"); - mln::image2d<mln::value::hsi_f> lena_hsi = mln::level::transform(lena, - mln::fun::v2v::f_rgb_to_hsi_f); + mln::image2d<mln::value::yuv_f> lena_hsi = mln::level::transform(lena, + mln::fun::v2v::f_rgb_to_yuv_f()); mln::image2d<mln::value::rgb8> lena_rgb = mln::level::transform(lena_hsi, f_get_red_<mln::value::rgb8>()); Index: trunk/milena/sandbox/vigouroux/color/rgb_to_hsl.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb_to_hsl.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsl.hh (revision 1873) @@ -11,14 +11,23 @@ # include "my_hsl.hh" -namespace mln { - namespace convert { - struct f_rgb_to_hsl +namespace mln { - struct value::hsl<8> - doit(const struct value::rgb<8> rgb) const + + namespace fun + { + + namespace v2v + { + template <typename T_hsl> + struct f_rgb_to_hsl_ : public Function_v2v< f_rgb_to_hsl_<T_hsl> > + { + typedef T_hsl result; + + template <typename T_rgb> + T_hsl operator()(const T_rgb& rgb) const { - struct value::hsl<8> hsl; + T_hsl hsl; double max_in = std::max(rgb.red(), std::max(rgb.blue(), rgb.green())); double min_in = std::min(rgb.red(), std::min(rgb.blue(), rgb.green())); @@ -29,16 +38,23 @@ hsl.s(); hsl.l(); - return (hsl); + return hsl; } }; - struct f_hsl_to_rgb + typedef f_rgb_to_hsl_<value::hsl_f> f_rgb_to_hsl_f_t; + + f_rgb_to_hsl_f_t f_rgb_to_hsl_f; + + template <typename T_rgb> + struct f_hsl_to_rgb_ : public Function_v2v< f_hsl_to_rgb_<T_rgb> > { - struct value::rgb<8> - doit(const struct value::hsl<8> hsl) const + typedef T_rgb result; + + template <typename T_hsl> + T_rgb operator()(const T_hsl& hsl) const { - struct value::rgb<8> rgb; + T_rgb rgb; int r; int g; int b; @@ -56,10 +72,11 @@ struct value::rgb<8> rgb(r, g, b); - return (rgb); + return rgb; } }; } } +} #endif // OLENA_CONVERT_RGBHSL_HH Index: trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh (revision 1873) @@ -11,27 +11,43 @@ # include "my_xyz.hh" -namespace mln { - namespace convert { - struct f_rgb_to_xyz +namespace mln { - struct value::xyz<8> - doit(const struct value::rgb<8> rgb) const + + namespace fun + { + + namespace v2v + { + template <typename T_xyz> + struct f_rgb_to_xyz_ : public Function_v2v< f_rgb_to_xyz_<T_xyz> > { - struct value::xyz<8> xyz; + typedef T_xyz result; + + template <typename T_rgb> + T_xyz operator()(const T_rgb& rgb) const + { + T_xyz xyz; xyz.x(0.490 * rgb.red() + 0.310 * rgb.green() + 0.200 * rgb.blue()); xyz.y(0.177 * rgb.red() + 0.812 * rgb.green() + 0.011 * rgb.blue()); xyz.z(0.010 * rgb.green() + 0.990 * rgb.blue()); - return (xyz); + return xyz; } }; - struct f_xyz_to_rgb + typedef f_rgb_to_xyz_<value::xyz_f> f_rgb_to_xyz_f_t; + + f_rgb_to_xyz_f_t f_rgb_to_xyz_f; + + template <typename T_rgb> + struct f_xyz_to_rgb_ : public Function_v2v< f_xyz_to_rgb_<T_rgb> > { - struct value::rgb<8> - doit(const struct value::xyz<8> xyz) const + typedef T_rgb result; + + template <typename T_xyz> + T_rgb operator()(const T_xyz& xyz) const { int r; int g; @@ -43,10 +59,18 @@ struct value::rgb<8> rgb(r, g, b); - return (rgb); + return rgb; } }; - } -} + + typedef f_xyz_to_rgb_<value::rgb8> f_xyz_to_rgb_3x8_t; + + f_xyz_to_rgb_3x8_t f_xyz_to_rgb_3x8; + + } // end of namespace fun::v2v + + } // end of namespace fun + +} // end of namespace mln #endif // OLENA_CONVERT_RGBXYZ_HH Index: trunk/milena/sandbox/vigouroux/color/my_hsl.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_hsl.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/color/my_hsl.hh (revision 1873) @@ -9,11 +9,17 @@ namespace mln { + namespace value { template <typename E> struct HSL + : + public internal::value_like_< algebra::vec< 3, float01_8 >, // Equivalent. + algebra::vec< 3, float01_8 >, // Encoding. + algebra::vec< 3, float01_8 >, // Interoperation. + HSL<E> > { }; @@ -53,13 +59,27 @@ return this->light_; } + /// Read-write access to the hue component. + H& hue() + { + return this->hue_; + } + S& sat() + { + return this->sat_; + } + L& light() + { + return this->light_; + } + private: H hue_; S sat_; L light_; }; - typedef hsl_<float, float, float> hsl_3x8; + typedef hsl_<float, float, float> hsl_f; typedef hsl_<double, double, double> hsl_d; @@ -67,61 +87,4 @@ } // 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_xyz.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_xyz.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/color/my_xyz.hh (revision 1873) @@ -1,3 +1,11 @@ +#include <mln/value/ops.hh> + +#include <mln/value/concept/vectorial.hh> +#include <mln/value/int_u.hh> +#include <mln/algebra/vec.hh> + +#include <mln/value/float01_8.hh> + #ifndef MLN_VALUE_XYZ_HH # define MLN_VALUE_XYZ_HH @@ -8,6 +16,11 @@ template <typename E> struct XYZ + : + public internal::value_like_< algebra::vec< 3, float01_8 >, // Equivalent. + algebra::vec< 3, float01_8 >, // Encoding. + algebra::vec< 3, float01_8 >, // Interoperation. + XYZ<E> > { }; @@ -75,59 +88,6 @@ } // 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 1872) +++ trunk/milena/sandbox/vigouroux/color/my_hsv.hh (revision 1873) @@ -9,11 +9,17 @@ namespace mln { + namespace value { template <typename E> struct HSV + : + public internal::value_like_< algebra::vec< 3, float01_8 >, // Equivalent. + algebra::vec< 3, float01_8 >, // Encoding. + algebra::vec< 3, float01_8 >, // Interoperation. + HSV<E> > { }; @@ -73,7 +79,7 @@ V value_; }; - typedef hsv_<float, float, float> hsv_3x8; + typedef hsv_<float, float, float> hsv_f; typedef hsv_<double, double, double> hsv_d; @@ -81,61 +87,4 @@ } // 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/rgb_to_hsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1872) +++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1873) @@ -12,12 +12,9 @@ #include "my_hsi.hh" - - namespace mln { - namespace fun {