diff --git a/src/Avalonia.Visuals/Media/HsvColor.cs b/src/Avalonia.Visuals/Media/HsvColor.cs
index 8b2f10d088..a18f1032f2 100644
--- a/src/Avalonia.Visuals/Media/HsvColor.cs
+++ b/src/Avalonia.Visuals/Media/HsvColor.cs
@@ -173,7 +173,7 @@ namespace Avalonia.Media
}
///
- /// Converts the given HSV color to it's RGB color equivalent.
+ /// Converts the given HSV color to its RGB color equivalent.
///
/// The color in the HSV color model.
/// A new RGB equivalent to the given HSVA values.
@@ -183,7 +183,7 @@ namespace Avalonia.Media
}
///
- /// Converts the given HSVA color channel values to it's RGB color equivalent.
+ /// Converts the given HSVA color channel values to its RGB color equivalent.
///
/// The hue channel value in the HSV color model in the range from 0..360.
/// The saturation channel value in the HSV color model in the range from 0..1.
@@ -321,7 +321,7 @@ namespace Avalonia.Media
}
///
- /// Converts the given RGB color to it's HSV color equivalent.
+ /// Converts the given RGB color to its HSV color equivalent.
///
/// The color in the RGB color model.
/// A new equivalent to the given RGBA values.
@@ -331,7 +331,7 @@ namespace Avalonia.Media
}
///
- /// Converts the given RGBA color channel values to it's HSV color equivalent.
+ /// Converts the given RGBA color channel values to its HSV color equivalent.
///
/// The red channel value in the RGB color model.
/// The green channel value in the RGB color model.
@@ -343,18 +343,40 @@ namespace Avalonia.Media
byte green,
byte blue,
byte alpha = 0xFF)
+ {
+ // Normalize RGBA channel values into the 0..1 range
+ return HsvColor.FromRgb(
+ (red / 255.0),
+ (green / 255.0),
+ (blue / 255.0),
+ (alpha / 255.0));
+ }
+
+ // TODO: Mark the below method Internal and make Internals visible to Avalonia.Controls...
+
+ ///
+ /// Converts the given RGBA color channel values to its HSV color equivalent.
+ ///
+ ///
+ /// Warning: No bounds checks or clamping is done on the input channel values.
+ /// This method is for internal-use only and the caller must ensure bounds.
+ ///
+ /// The red channel value in the RGB color model within the range 0..1.
+ /// The green channel value in the RGB color model within the range 0..1.
+ /// The blue channel value in the RGB color model within the range 0..1.
+ /// The alpha channel value in the RGB color model within the range 0..1.
+ /// A new equivalent to the given RGBA values.
+ public static HsvColor FromRgb(
+ double r,
+ double g,
+ double b,
+ double a = 1.0)
{
// Note: Conversion code is originally based on the C++ in WinUI (licensed MIT)
// https://github.com/microsoft/microsoft-ui-xaml/blob/main/dev/Common/ColorConversion.cpp
// This was used because it is the best documented and likely most optimized for performance
// Alpha channel support was added
- // Normalize RGBA channel values into the 0..1 range used by this algorithm
- double r = red / 255.0;
- double g = green / 255.0;
- double b = blue / 255.0;
- double a = alpha / 255.0;
-
double hue;
double saturation;
double value;