1 #ifndef color_LuvCH_convert_luv
2 #define color_LuvCH_convert_luv
3 
4 #include "../../_internal/convert.hpp"
5 
6 #include "../category.hpp"
7 #include "../place/place.hpp"
8 
9 #include "../../luv/luv.hpp"
10 
11 
12 
13 
14 
15 
16 namespace color
17  {
18   namespace _internal
19    {
20 
21     template
22      <
23        typename LuvCH_tag_name
24       ,typename luv_tag_name
25      >
26      struct convert
27       <
28         ::color::category::LuvCH< LuvCH_tag_name >
29        ,::color::category::luv<  luv_tag_name >
30       >
31       {
32        public:
33          typedef ::color::category::LuvCH< LuvCH_tag_name >    LuvCH_category_type, category_left_type;
34          typedef ::color::category::luv< luv_tag_name >    luv_category_type, category_right_type;
35 
36          typedef typename ::color::trait::scalar< LuvCH_category_type >::instance_type scalar_type;
37 
38 
39          typedef ::color::trait::container<category_left_type>     container_left_trait_type;
40          typedef ::color::trait::container<category_right_type>    container_right_trait_type;
41 
42          typedef typename container_left_trait_type::input_type         container_left_input_type;
43          typedef typename container_right_trait_type::model_type  container_right_const_input_type;
44 
45          typedef typename ::color::LuvCH< scalar_type >::category_type LuvCHscalar_category_type;
46          typedef typename ::color::luv<   scalar_type >::category_type LUVscalar_category_type;
47 
48          typedef ::color::_internal::reformat< category_left_type, LuvCHscalar_category_type >   reformatCH_type;
49          typedef ::color::_internal::reformat< LUVscalar_category_type, category_right_type >    reformatUV_type;
50 
51          typedef ::color::constant::generic< LUVscalar_category_type > generic_costant_type;
52 
53          enum
54           {
55             lightness_p  = ::color::place::_internal::lightness<category_left_type>::position_enum
56            ,chroma_p     = ::color::place::_internal::chroma<category_left_type>::position_enum
57            ,hue_p        = ::color::place::_internal::hue<category_left_type>::position_enum
58           };
59 
processcolor::_internal::convert60          static void process
61           (
62             container_left_input_type         left
63            ,container_right_const_input_type  right
64           )
65           {
66            scalar_type l = reformatUV_type::template process< 0, 0 >( container_right_trait_type::template get<0>( right ) );
67            scalar_type u = reformatUV_type::template process< 1, 1 >( container_right_trait_type::template get<1>( right ) );
68            scalar_type v = reformatUV_type::template process< 2, 2 >( container_right_trait_type::template get<2>( right ) );
69 
70            scalar_type c = sqrt( u*u + v*v );
71            scalar_type h = atan2( v, u ) * generic_costant_type::rad2deg();
72            if( h < 0 ) h += 360;
73 
74            container_left_trait_type::template set<0>( left, reformatCH_type::template process< lightness_p, 0 >( l ) );
75            container_left_trait_type::template set<1>( left, reformatCH_type::template process< chroma_p,    1 >( c ) );
76            container_left_trait_type::template set<2>( left, reformatCH_type::template process< hue_p,       2 >( h ) );
77           }
78       };
79 
80    }
81  }
82 
83 #endif
84