1 #ifndef  color_cmyk_fix_unique
2 #define  color_cmyk_fix_unique
3 
4 #include "../trait/bound.hpp"
5 #include "../category.hpp"
6 #include "../../generic/fix/unique.hpp"
7 #include "../../generic/operation/diverse.hpp"
8 #include "../../generic/operation/normalize.hpp"
9 
10 
11 
12  namespace color
13   {
14    namespace fix
15     {
16      namespace _internal
17       {
18 
19        template< typename tag_name >
20         struct unique< ::color::category::cmyk< tag_name > >
21          {
22           public:
23             typedef ::color::category::cmyk< tag_name >  category_type;
24 
25             typedef ::color::model<category_type>  model_type;
26             typedef ::color::trait::bound<category_type>      bound_type;
27             typedef typename ::color::trait::scalar<category_type>::instance_type     scalar_type;
28             typedef ::color::_internal::diverse< category_type >    diverse_type;
29             typedef ::color::_internal::normalize< category_type > normalize_type;
30 
31             enum
32              {
33                   cyan_p  = ::color::place::_internal::cyan<category_type>::position_enum
34               ,magenta_p  = ::color::place::_internal::magenta<category_type>::position_enum
35               , yellow_p  = ::color::place::_internal::yellow<category_type>::position_enum
36               ,    key_p  = ::color::place::_internal::key<category_type>::position_enum
37              };
38 
processcolor::fix::_internal::unique39             static void process( model_type &result )
40              {
41               if( result.template get<key_p>() == bound_type::template maximum<key_p>() )
42                {
43                 result.template set<cyan_p>( bound_type::template minimum<cyan_p>() );
44                 result.template set<magenta_p>( bound_type::template minimum<magenta_p>() );
45                 result.template set<yellow_p>( bound_type::template minimum<yellow_p>() );
46                 return ;
47                }
48 
49               if( result.template get<cyan_p>() == bound_type::template minimum<cyan_p>() ) { return; }
50               if( result.template get<magenta_p>() == bound_type::template minimum<magenta_p>() ) { return; }
51               if( result.template get<yellow_p>() == bound_type::template minimum<yellow_p>() ) { return; }
52 
53               scalar_type cyan = normalize_type::template process<cyan_p>( result.template get<cyan_p>() );
54               scalar_type key  = normalize_type::template process<key_p>( result.template get<key_p>() );
55 
56               result.template set<cyan_p>( bound_type::template minimum<cyan_p>() );
57               result.template set<magenta_p>( bound_type::template minimum<magenta_p>() );
58               result.template set<yellow_p>( bound_type::template minimum<yellow_p>() );
59 
60               result.template set<key_p>( diverse_type::template process<key_p>( ( 1- ( 1- cyan)*(1-key) ) ) );
61              }
62 
processcolor::fix::_internal::unique63             static void process(  model_type &result, model_type const& right )
64              {
65               if( result.template get<key_p>() == bound_type::template maximum<key_p>() )
66                {
67                 result.template set<cyan_p>( bound_type::template minimum<cyan_p>() );
68                 result.template set<magenta_p>( bound_type::template minimum<magenta_p>() );
69                 result.template set<yellow_p>( bound_type::template minimum<yellow_p>() );
70                 result.template set<key_p>( bound_type::template maximum<key_p>() );
71                 return ;
72                }
73 
74               result = right;
75 
76               if( result.template get<cyan_p>() == bound_type::template minimum<cyan_p>() ) { return; }
77               if( result.template get<magenta_p>() == bound_type::template minimum<magenta_p>() ) { return; }
78               if( result.template get<yellow_p>() == bound_type::template minimum<yellow_p>() ) { return; }
79 
80               scalar_type cyan = normalize_type::template process<cyan_p>( result.template get<cyan_p>() );
81               scalar_type key  = normalize_type::template process<key_p>( result.template get<key_p>() );
82 
83               result.template set<cyan_p>( bound_type::template minimum<cyan_p>() );
84               result.template set<magenta_p>( bound_type::template minimum<magenta_p>() );
85               result.template set<yellow_p>( bound_type::template minimum<yellow_p>() );
86 
87               result.template set<key_p>( diverse_type::template process<key_p>( ( 1- ( 1- cyan)*(1-key) ) ) );
88 
89              }
90 
91          };
92 
93       }
94     }
95   }
96 
97 #endif
98