27 #ifndef MLN_FUN_V2V_HSI_TO_RGB_HH
28 # define MLN_FUN_V2V_HSI_TO_RGB_HH
36 #include <mln/value/rgb8.hh>
37 #include <mln/math/round.hh>
39 #include <mln/value/hsi.hh>
56 template <
typename T_rgb>
57 struct f_hsi_to_rgb_ :
public Function_v2v< f_hsi_to_rgb_<T_rgb> >
63 template <
typename T_hsi>
64 T_rgb operator()(
const T_hsi& hsi)
const;
68 typedef f_hsi_to_rgb_<value::rgb8> f_hsi_to_rgb_3x8_t;
73 # ifndef MLN_INCLUDE_ONLY
75 # ifndef MLN_WO_GLOBAL_VARS
82 # endif // ! MLN_WO_GLOBAL_VARS
84 template <
typename T_rgb>
85 f_hsi_to_rgb_<T_rgb>::f_hsi_to_rgb_()
90 template <
typename T_rgb>
91 template <
typename T_hsi>
94 f_hsi_to_rgb_<T_rgb>::operator()(
const T_hsi& hsi)
const
96 typedef typename T_rgb::red_t red_t;
97 typedef typename T_rgb::green_t green_t;
98 typedef typename T_rgb::blue_t blue_t;
100 static math::round<red_t> to_r;
101 static math::round<green_t> to_g;
102 static math::round<blue_t> to_b;
105 sqrt3_3 = std::sqrt(3) / 3,
106 inv_sqrt6 = 1 / std::sqrt(6),
107 inv_sqrt2 = 1 / std::sqrt(2);
110 h = hsi.hue() / 180.0 * 3.1415,
111 alpha = hsi.sat() * std::cos(h),
112 beta = hsi.sat() * std::sin(h);
115 red_t r = to_r(sqrt3_3 * hsi.inty() + 2 * inv_sqrt6 * beta);
117 to_g(sqrt3_3 * hsi.inty() + inv_sqrt2 * alpha - inv_sqrt6 * beta);
119 to_b(sqrt3_3 * hsi.inty() - inv_sqrt2 * alpha - inv_sqrt6 * beta);
126 # endif // !MLN_INCLUDE_ONLY
134 #endif // ! MLN_FUN_V2V_HSI_TO_RGB_HH