mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
@@ -44,6 +44,14 @@ namespace ColorPicker.Helpers
|
||||
return (cyan, magenta, yellow, blackKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a given <see cref="Color"/> to a float color styling(0.1f, 0.1f, 0.1f)
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||
/// <returns>The int / 255d for each value to get value between 0 and 1</returns>
|
||||
internal static (double red, double green, double blue) ConvertToDouble(Color color)
|
||||
=> (color.R / 255d, color.G / 255d, color.B / 255d);
|
||||
|
||||
/// <summary>
|
||||
/// Convert a given <see cref="Color"/> to a HSB color (hue, saturation, brightness)
|
||||
/// </summary>
|
||||
|
||||
@@ -46,6 +46,8 @@ namespace ColorPicker.Helpers
|
||||
ColorRepresentationType.RGB => ColorToRGB(color),
|
||||
ColorRepresentationType.CIELAB => ColorToCIELAB(color),
|
||||
ColorRepresentationType.CIEXYZ => ColorToCIEXYZ(color),
|
||||
ColorRepresentationType.RGBfloat => ColorToFloat(color),
|
||||
ColorRepresentationType.Decimal => ColorToDecimal(color),
|
||||
|
||||
// Fall-back value, when "_userSettings.CopiedColorRepresentation.Value" is incorrect
|
||||
_ => ColorToHex(color),
|
||||
@@ -99,6 +101,29 @@ namespace ColorPicker.Helpers
|
||||
+ $", {brightness.ToString(CultureInfo.InvariantCulture)}%)";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a <see cref="string"/> representation float color styling(0.1f, 0.1f, 0.1f)
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||
/// <returns>a string value (0.1f, 0.1f, 0.1f)</returns>
|
||||
private static string ColorToFloat(Color color)
|
||||
{
|
||||
var (red, green, blue) = ColorHelper.ConvertToDouble(color);
|
||||
var precison = 2;
|
||||
|
||||
return $"({Math.Round(red, precison)}f, {Math.Round(green, precison)}f, {Math.Round(blue, precison)}f, 1)";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a <see cref="string"/> representation decimal color value
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||
/// <returns>a string value number</returns>
|
||||
private static string ColorToDecimal(Color color)
|
||||
{
|
||||
return $"{color.R + (color.G * 256) + (color.B * 65536)}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a <see cref="string"/> representation of a HSI color
|
||||
/// </summary>
|
||||
|
||||
@@ -216,6 +216,18 @@ namespace ColorPicker.ViewModels
|
||||
FormatName = ColorRepresentationType.CIEXYZ.ToString(),
|
||||
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.CIEXYZ); },
|
||||
});
|
||||
_allColorRepresentations.Add(
|
||||
new ColorFormatModel()
|
||||
{
|
||||
FormatName = ColorRepresentationType.RGBfloat.ToString(),
|
||||
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.RGBfloat); },
|
||||
});
|
||||
_allColorRepresentations.Add(
|
||||
new ColorFormatModel()
|
||||
{
|
||||
FormatName = ColorRepresentationType.Decimal.ToString(),
|
||||
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.Decimal); },
|
||||
});
|
||||
|
||||
_userSettings.VisibleColorFormats.CollectionChanged += VisibleColorFormats_CollectionChanged;
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Microsoft.ColorPicker.UnitTests
|
||||
[DataRow(ColorRepresentationType.RGB, "rgb(0, 0, 0)")]
|
||||
[DataRow(ColorRepresentationType.CIELAB, "CIELab(0, 0, 0)")]
|
||||
[DataRow(ColorRepresentationType.CIEXYZ, "xyz(0, 0, 0)")]
|
||||
[DataRow(ColorRepresentationType.RGBfloat, "(0.00f, 0.00f, 0.00f, 1)")]
|
||||
[DataRow(ColorRepresentationType.Decimal, "0")]
|
||||
|
||||
public void GetStringRepresentationTest(ColorRepresentationType type, string expected)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user