diff options
Diffstat (limited to 'boost/gil/extension/toolbox/color_spaces/hsl.hpp')
-rw-r--r-- | boost/gil/extension/toolbox/color_spaces/hsl.hpp | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/boost/gil/extension/toolbox/color_spaces/hsl.hpp b/boost/gil/extension/toolbox/color_spaces/hsl.hpp index a2e6a1e040..9ed8aa7e46 100644 --- a/boost/gil/extension/toolbox/color_spaces/hsl.hpp +++ b/boost/gil/extension/toolbox/color_spaces/hsl.hpp @@ -8,6 +8,7 @@ #ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HSL_HPP #define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HSL_HPP +#include <boost/gil/color_convert.hpp> #include <boost/gil/typedefs.hpp> namespace boost{ namespace gil { @@ -17,22 +18,24 @@ namespace boost{ namespace gil { namespace hsl_color_space { /// \brief Hue -struct hue_t {}; +struct hue_t {}; /// \brief Saturation struct saturation_t {}; /// \brief Lightness -struct lightness_t {}; +struct lightness_t {}; } /// \} /// \ingroup ColorSpaceModel -typedef mpl::vector3< hsl_color_space::hue_t - , hsl_color_space::saturation_t - , hsl_color_space::lightness_t - > hsl_t; +using hsl_t = mpl::vector3 + < + hsl_color_space::hue_t, + hsl_color_space::saturation_t, + hsl_color_space::lightness_t + >; /// \ingroup LayoutModel -typedef layout<hsl_t> hsl_layout_t; +using hsl_layout_t = layout<hsl_t>; GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, hsl) @@ -80,12 +83,12 @@ struct default_color_converter_impl< rgb_t, hsl_t > if( lightness < 0.5f ) { - saturation = diff + saturation = diff / ( min_color + max_color ); } else { - saturation = ( max_color - min_color ) + saturation = ( max_color - min_color ) / ( 2.f - diff ); } @@ -94,7 +97,7 @@ struct default_color_converter_impl< rgb_t, hsl_t > if( std::abs( max_color - temp_red ) < 0.0001f ) { // max_color is red - hue = ( temp_green - temp_blue ) + hue = ( temp_green - temp_blue ) / diff; } @@ -102,21 +105,21 @@ struct default_color_converter_impl< rgb_t, hsl_t > { // max_color is green // 2.0 + (b - r) / (maxColor - minColor); - hue = 2.f - + ( temp_blue - temp_red ) + hue = 2.f + + ( temp_blue - temp_red ) / diff; } else { // max_color is blue - hue = 4.f - + ( temp_red - temp_blue ) + hue = 4.f + + ( temp_red - temp_blue ) / diff; } hue /= 6.f; - + if( hue < 0.f ) { hue += 1.f; @@ -154,29 +157,29 @@ struct default_color_converter_impl<hsl_t,rgb_t> float tempr, tempg, tempb; //Set the temporary values - if( get_color( src, lightness_t() ) < 0.5 ) + if( get_color( src, lightness_t() ) < 0.5 ) { temp2 = get_color( src, lightness_t() ) * ( 1.f + get_color( src, saturation_t() ) ); } else { - temp2 = ( get_color( src, lightness_t() ) + get_color( src, saturation_t() )) + temp2 = ( get_color( src, lightness_t() ) + get_color( src, saturation_t() )) - ( get_color( src, lightness_t() ) * get_color( src, saturation_t() )); } temp1 = 2.f - * get_color( src, lightness_t() ) + * get_color( src, lightness_t() ) - temp2; - tempr = get_color( src, hue_t() ) + 1.f / 3.f; + tempr = get_color( src, hue_t() ) + 1.f / 3.f; if( tempr > 1.f ) { tempr--; } - tempg = get_color( src, hue_t() ); + tempg = get_color( src, hue_t() ); tempb = get_color( src, hue_t() ) - 1.f / 3.f; if( tempb < 0.f ) @@ -184,7 +187,7 @@ struct default_color_converter_impl<hsl_t,rgb_t> tempb++; } - //Red + //Red if( tempr < 1.f / 6.f ) { red = temp1 + ( temp2 - temp1 ) * 6.f * tempr; @@ -195,7 +198,7 @@ struct default_color_converter_impl<hsl_t,rgb_t> } else if( tempr < 2.f / 3.f ) { - red = temp1 + (temp2 - temp1) + red = temp1 + (temp2 - temp1) * (( 2.f / 3.f ) - tempr) * 6.f; } else @@ -203,7 +206,7 @@ struct default_color_converter_impl<hsl_t,rgb_t> red = temp1; } - //Green + //Green if( tempg < 1.f / 6.f ) { green = temp1 + ( temp2 - temp1 ) * 6.f * tempg; @@ -222,7 +225,7 @@ struct default_color_converter_impl<hsl_t,rgb_t> green = temp1; } - //Blue + //Blue if( tempb < 1.f / 6.f ) { blue = temp1 + (temp2 - temp1) * 6.f * tempb; @@ -233,7 +236,7 @@ struct default_color_converter_impl<hsl_t,rgb_t> } else if( tempb < 2.f / 3.f ) { - blue = temp1 + (temp2 - temp1) + blue = temp1 + (temp2 - temp1) * (( 2.f / 3.f ) - tempb) * 6.f; } else |