1 #ifndef color_LabCH_convert_lab
2 #define color_LabCH_convert_lab
3 
4 #include "../../_internal/convert.hpp"
5 
6 #include "../category.hpp"
7 #include "../place/place.hpp"
8 
9 #include "../../lab/lab.hpp"
10 
11 
12 
13 
14 
15 
16 namespace color
17  {
18   namespace _internal
19    {
20 
21     template
22      <
23        typename LabCH_tag_name
24       ,typename lab_tag_name
25      >
26      struct convert
27       <
28         ::color::category::LabCH< LabCH_tag_name >
29        ,::color::category::lab<  lab_tag_name, ::color::constant::lab::CIE_entity >
30       >
31       {
32        public:
33          typedef ::color::category::LabCH< LabCH_tag_name >    LabCH_category_type, category_left_type;
34          typedef ::color::category::lab<      lab_tag_name, ::color::constant::lab::CIE_entity >    lab_category_type, category_right_type;
35 
36          typedef typename ::color::trait::scalar< LabCH_category_type >::instance_type scalar_type;
37 
38          typedef ::color::trait::container<category_left_type>     container_left_trait_type;
39          typedef ::color::trait::container<category_right_type>    container_right_trait_type;
40 
41          typedef typename container_left_trait_type::input_type         container_left_input_type;
42          typedef typename container_right_trait_type::model_type  container_right_const_input_type;
43 
44          typedef typename ::color::LabCH< scalar_type >::category_type LabCHscalar_category_type;
45          typedef typename ::color::lab<   scalar_type >::category_type LABscalar_category_type;
46 
47          typedef ::color::_internal::reformat< category_left_type, LabCHscalar_category_type >  reformatCH_type;
48          typedef ::color::_internal::reformat< LABscalar_category_type, category_right_type >    reformatAB_type;
49 
50          typedef ::color::constant::generic< LABscalar_category_type > generic_costant_type;
51 
52          enum
53           {
54             lightness_p  = ::color::place::_internal::lightness<category_left_type>::position_enum
55            ,chroma_p     = ::color::place::_internal::chroma<category_left_type>::position_enum
56            ,hue_p        = ::color::place::_internal::hue<category_left_type>::position_enum
57           };
58 
59          // TODFO enum
60          // TODFO  {
61          // TODFO    lightness_r_p  = ::color::place::_internal::lightness<category_right_type>::position_enum
62          // TODFO  };
63 
processcolor::_internal::convert64          static void process
65           (
66             container_left_input_type         left
67            ,container_right_const_input_type  right
68           )
69           {
70            scalar_type l = reformatAB_type::template process< 0, 0 >( container_right_trait_type::template get<0>( right ) );
71            scalar_type a = reformatAB_type::template process< 1, 1 >( container_right_trait_type::template get<1>( right ) );
72            scalar_type b = reformatAB_type::template process< 2, 2 >( container_right_trait_type::template get<2>( right ) );
73 
74            scalar_type c = sqrt( a*a + b*b );
75            scalar_type h = atan2( b, a ) * generic_costant_type::rad2deg();
76            if( h < 0 ) h += 360;
77 
78            container_left_trait_type::template set<lightness_p>( left, reformatCH_type::template process< lightness_p, 0 >( l ) );
79            container_left_trait_type::template set<chroma_p   >( left, reformatCH_type::template process< chroma_p,    1 >( c ) );
80            container_left_trait_type::template set<hue_p      >( left, reformatCH_type::template process< hue_p,       2 >( h ) );
81           }
82       };
83 
84     template
85      <
86        typename LabCH_tag_name
87       ,typename lab_tag_name
88      >
89      struct convert
90       <
91         ::color::category::LabCH< LabCH_tag_name >
92        ,::color::category::lab<  lab_tag_name, ::color::constant::lab::Hunter_entity >
93       >
94       {
95        public:
96          typedef ::color::category::LabCH< LabCH_tag_name >                                       LabCH_category_type, category_left_type;
97          typedef ::color::category::lab< lab_tag_name, ::color::constant::lab::Hunter_entity >    lab_category_type, category_right_type;
98 
99          typedef typename ::color::trait::scalar< LabCH_category_type >::instance_type scalar_type;
100 
101          typedef ::color::model<   LabCH_category_type >      LabCH_model_type;
102          typedef ::color::model<   lab_category_type >      lab_model_type;
103 
104          typedef ::color::xyz< scalar_type >  xyz_model_type;
105 
106          typedef ::color::trait::container<category_left_type>     container_left_trait_type;
107          typedef ::color::trait::container<category_right_type>    container_right_trait_type;
108 
109          typedef typename container_left_trait_type::input_type         container_left_input_type;
110          typedef typename container_right_trait_type::model_type  container_right_const_input_type;
111 
processcolor::_internal::convert112          static void process
113           (
114             container_left_input_type         left
115            ,container_right_const_input_type  right
116           )
117           {
118            left = LabCH_model_type( xyz_model_type( lab_model_type( right ) ) ).container();
119           }
120       };
121 
122    }
123  }
124 
125 #endif
126