Skip to content

Commit

Permalink
fix: Wrong RGB -> HSL convertion (#505)
Browse files Browse the repository at this point in the history
Tests will follow as part of #690
  • Loading branch information
eugene-kulak committed Jun 24, 2022
1 parent 1c6c427 commit 5273678
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions include/boost/gil/extension/toolbox/color_spaces/hsl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct default_color_converter_impl< rgb_t, hsl_t >
{

float32_t diff = max_color - min_color;
float32_t sum = max_color + min_color;

// lightness calculation

Expand All @@ -84,13 +85,11 @@ struct default_color_converter_impl< rgb_t, hsl_t >

if( lightness < 0.5f )
{
saturation = diff
/ ( min_color + max_color );
saturation = diff / ( sum );
}
else
{
saturation = ( max_color - min_color )
/ ( 2.f - diff );
saturation = diff / ( 2.f - sum );

}

Expand All @@ -115,7 +114,7 @@ struct default_color_converter_impl< rgb_t, hsl_t >
{
// max_color is blue
hue = 4.f
+ ( temp_red - temp_blue )
+ ( temp_red - temp_green )
/ diff;
}

Expand Down

0 comments on commit 5273678

Please sign in to comment.