1 #ifndef color_rgb_convert_xyz
2 #define color_rgb_convert_xyz
3 
4 #include "../../_internal/convert.hpp"
5 
6 #include "../../xyz/trait/container.hpp"
7 #include "../../xyz/category.hpp"
8 #include "../../xyz/constant.hpp"
9 #include "../../xyz/place/place.hpp"
10 
11 #include "../../_internal/normalize.hpp"
12 #include "../../_internal/diverse.hpp"
13 
14 namespace color
15  {
16   namespace _internal
17    {
18 
19     template< typename rgb_tag_name, typename xyz_tag_name >
20      struct convert
21       <
22         ::color::category::rgb< rgb_tag_name >
23        ,::color::category::xyz<xyz_tag_name>
24       >
25       {
26        public:
27          typedef ::color::category::rgb< rgb_tag_name > category_left_type;
28          typedef ::color::category::xyz<xyz_tag_name> category_right_type;
29 
30          typedef typename ::color::trait::scalar< category_left_type >::instance_type scalar_type;
31 
32          typedef ::color::trait::container<category_left_type>     container_left_trait_type;
33          typedef ::color::trait::container<category_right_type>    container_right_trait_type;
34 
35          typedef typename container_left_trait_type::input_type         container_left_input_type;
36          typedef typename container_right_trait_type::model_type  container_right_const_input_type;
37 
38          typedef ::color::constant::xyz::transformation::matrix< scalar_type > xyz_matrix_type;
39          typedef ::color::constant::xyz::space::gamma< scalar_type, ::color::constant::xyz::space::sRGB_entity > xyz_gamma_type;
40          typedef ::color::constant::xyz::adaptation::matrix< scalar_type > xyz_adaptation_type;
41 
42          typedef ::color::_internal::diverse< category_left_type >    diverse_type;
43          typedef ::color::_internal::normalize< category_right_type > normalize_type;
44 
45          enum
46           {
47             red_p   = ::color::place::_internal::red<category_left_type>::position_enum
48            ,green_p = ::color::place::_internal::green<category_left_type>::position_enum
49            ,blue_p  = ::color::place::_internal::blue<category_left_type>::position_enum
50           };
51 
processcolor::_internal::convert52          static void process
53           (
54             container_left_input_type         left
55            ,container_right_const_input_type  right
56           )
57           {
58            static const scalar_type i11 = xyz_matrix_type::i11(), i12 = xyz_matrix_type::i12(), i13 = xyz_matrix_type::i13();
59            static const scalar_type i21 = xyz_matrix_type::i21(), i22 = xyz_matrix_type::i22(), i23 = xyz_matrix_type::i23();
60            static const scalar_type i31 = xyz_matrix_type::i31(), i32 = xyz_matrix_type::i32(), i33 = xyz_matrix_type::i33();
61 
62            scalar_type x = normalize_type::template process<0>( container_right_trait_type::template get<0>( right ) );
63            scalar_type y = normalize_type::template process<1>( container_right_trait_type::template get<1>( right ) );
64            scalar_type z = normalize_type::template process<2>( container_right_trait_type::template get<2>( right ) );
65 
66            //  TODO xyz_adaptation_type::encode( r, g, b );
67 
68            scalar_type r = i11 * x + i12 * y + i13 * z;
69            scalar_type g = i21 * x + i22 * y + i23 * z;
70            scalar_type b = i31 * x + i32 * y + i33 * z;
71 
72            r = xyz_gamma_type::encode( r );
73            g = xyz_gamma_type::encode( g );
74            b = xyz_gamma_type::encode( b );
75 
76            container_left_trait_type::template set<red_p  >( left, diverse_type::template process<red_p  >( r ) );
77            container_left_trait_type::template set<green_p>( left, diverse_type::template process<green_p>( g ) );
78            container_left_trait_type::template set<blue_p >( left, diverse_type::template process<blue_p >( b ) );
79           }
80       };
81 
82    }
83  }
84 
85 #endif