Skip to content

Commit ceff1cc

Browse files
Merge pull request #1001 from SixLabors/issue/997
Fix RGB to HSL conversion
2 parents 29d7ed0 + 7aaaa25 commit ceff1cc

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HslAndRgbConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public Hsl Convert(in Rgb input)
9696
}
9797
else
9898
{
99-
s = chroma / (2F - chroma);
99+
s = chroma / (2F - max - min);
100100
}
101101

102102
return new Hsl(h, s, l);
@@ -157,4 +157,4 @@ private static float MoveIntoRange(float value)
157157
return value;
158158
}
159159
}
160-
}
160+
}

tests/ImageSharp.Tests/Colorspaces/Conversion/RgbAndHslConversionTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -65,6 +65,7 @@ public void Convert_Hsl_To_Rgb(float h, float s, float l, float r, float g, floa
6565
[InlineData(1, 0, 0, 0, 1, .5F)]
6666
[InlineData(0, 1, 0, 120, 1, .5F)]
6767
[InlineData(0, 0, 1, 240, 1, .5F)]
68+
[InlineData(0.7, 0.8, 0.6, 90, 0.3333, 0.7F)]
6869
public void Convert_Rgb_To_Hsl(float r, float g, float b, float h, float s, float l)
6970
{
7071
// Arrange

0 commit comments

Comments
 (0)