mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Add Ncol, HWB, HSB color format + cleanup
This commit is contained in:
@@ -4,37 +4,10 @@
|
|||||||
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||||
{
|
{
|
||||||
public enum ColorRepresentationType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Color presentation as hexadecimal color value without the alpha-value (e.g. #0055FF)
|
|
||||||
/// </summary>
|
|
||||||
HEX = 0,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Color presentation as RGB color value (red[0..255], green[0..255], blue[0..255])
|
|
||||||
/// </summary>
|
|
||||||
RGB = 1,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Color presentation as CMYK color value (cyan[0%..100%], magenta[0%..100%], yellow[0%..100%], black key[0%..100%])
|
|
||||||
/// </summary>
|
|
||||||
CMYK = 2,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Color presentation as HSL color value (hue[0°..360°], saturation[0..100%], lightness[0%..100%])
|
|
||||||
/// </summary>
|
|
||||||
HSL = 3,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Color presentation as HSV color value (hue[0°..360°], saturation[0%..100%], value[0%..100%])
|
|
||||||
/// </summary>
|
|
||||||
HSV = 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ColorPickerProperties
|
public class ColorPickerProperties
|
||||||
{
|
{
|
||||||
public ColorPickerProperties()
|
public ColorPickerProperties()
|
||||||
|
|||||||
@@ -40,14 +40,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string GetModuleName()
|
public string GetModuleName()
|
||||||
{
|
=> Name;
|
||||||
return Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||||
public bool UpgradeSettingsConfiguration()
|
public bool UpgradeSettingsConfiguration()
|
||||||
{
|
=> false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.Settings.UI.Library.Enumerations
|
||||||
|
{
|
||||||
|
public enum ColorRepresentationType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Color presentation as hexadecimal color value without the alpha-value (e.g. #0055FF)
|
||||||
|
/// </summary>
|
||||||
|
HEX = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Color presentation as RGB color value (red[0..255], green[0..255], blue[0..255])
|
||||||
|
/// </summary>
|
||||||
|
RGB = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Color presentation as CMYK color value (cyan[0%..100%], magenta[0%..100%], yellow[0%..100%], black key[0%..100%])
|
||||||
|
/// </summary>
|
||||||
|
CMYK = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Color presentation as HSL color value (hue[0°..360°], saturation[0..100%], lightness[0%..100%])
|
||||||
|
/// </summary>
|
||||||
|
HSL = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Color presentation as HSV color value (hue[0°..360°], saturation[0%..100%], value[0%..100%])
|
||||||
|
/// </summary>
|
||||||
|
HSV = 4,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Color presentation as HSB color value (hue[0°..360°], saturation[0%..100%], brightness[0%..100%])
|
||||||
|
/// </summary>
|
||||||
|
HSB = 5,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Color presentation as HSI color value (hue[0°..360°], saturation[0%..100%], value[0%..100%])
|
||||||
|
/// </summary>
|
||||||
|
HSI = 6,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Color presentation as HWB color value (hue[0°..360°], whiteness[0%..100%], blackness[0%..100%])
|
||||||
|
/// </summary>
|
||||||
|
HWB = 7,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Color presentation as natural color (hue, saturation[0%..100%], value[0%..100%])
|
||||||
|
/// </summary>
|
||||||
|
NCol = 8,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,10 @@
|
|||||||
<ComboBoxItem Content="CMYK - cmyk(100%, 50%, 75%, 0%)"/>
|
<ComboBoxItem Content="CMYK - cmyk(100%, 50%, 75%, 0%)"/>
|
||||||
<ComboBoxItem Content="HSL - hsl(100, 50%, 75%)"/>
|
<ComboBoxItem Content="HSL - hsl(100, 50%, 75%)"/>
|
||||||
<ComboBoxItem Content="HSV - hsv(100, 50%, 75%)"/>
|
<ComboBoxItem Content="HSV - hsv(100, 50%, 75%)"/>
|
||||||
|
<ComboBoxItem Content="HSB - hsb(100, 50%, 75%)"/>
|
||||||
|
<ComboBoxItem Content="HSI - hsi(100, 50%, 75%)"/>
|
||||||
|
<ComboBoxItem Content="HBW - hbw(100, 50%, 75%)"/>
|
||||||
|
<ComboBoxItem Content="NCob - 10R, 50%, 75%"/>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
@@ -13,44 +13,7 @@ namespace ColorPicker.Helpers
|
|||||||
internal static class ColorHelper
|
internal static class ColorHelper
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert a given <see cref="Color"/> color to a HSL color (hue, saturation, lightness)
|
/// Convert a given <see cref="Color"/> to a CYMK color (cyan, magenta, yellow, black key)
|
||||||
/// </summary>
|
|
||||||
/// <param name="color">The <see cref="Color"/> to convert</param>
|
|
||||||
/// <returns>The hue [0°..360°], saturation [0..1] and lightness [0..1] values of the converted color</returns>
|
|
||||||
internal static (double hue, double saturation, double lightness) ConvertToHSLColor(Color color)
|
|
||||||
{
|
|
||||||
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
|
|
||||||
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
|
|
||||||
|
|
||||||
var lightness = (max + min) / 2d;
|
|
||||||
|
|
||||||
if (lightness == 0d || min == max)
|
|
||||||
{
|
|
||||||
return (color.GetHue(), 0d, lightness);
|
|
||||||
}
|
|
||||||
else if (lightness > 0d && lightness <= 0.5d)
|
|
||||||
{
|
|
||||||
return (color.GetHue(), (max - min) / (max + min), lightness);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (color.GetHue(), (max - min) / (2d - (max + min)), lightness);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert a given <see cref="Color"/> color to a HSV color (hue, saturation, value)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="color">The <see cref="Color"/> to convert</param>
|
|
||||||
/// <returns>The hue [0°..360°], saturation [0..1] and value [0..1] of the converted color</returns>
|
|
||||||
internal static (double hue, double saturation, double value) ConvertToHSVColor(Color color)
|
|
||||||
{
|
|
||||||
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
|
|
||||||
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
|
|
||||||
|
|
||||||
return (color.GetHue(), max == 0d ? 0d : (max - min) / max, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert a given <see cref="Color"/> color to a CYMK color (cyan, magenta, yellow, black key)
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The <see cref="Color"/> to convert</param>
|
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||||
/// <returns>The cyan[0..1], magenta[0..1], yellow[0..1] and black key[0..1] of the converted color</returns>
|
/// <returns>The cyan[0..1], magenta[0..1], yellow[0..1] and black key[0..1] of the converted color</returns>
|
||||||
@@ -80,5 +43,116 @@ namespace ColorPicker.Helpers
|
|||||||
|
|
||||||
return (cyan, magenta, yellow, blackKey);
|
return (cyan, magenta, yellow, blackKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a given <see cref="Color"/> to a HSB color (hue, saturation, brightness)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||||
|
/// <returns>The hue [0°..360°], saturation [0..1] and brightness [0..1] of the converted color</returns>
|
||||||
|
internal static (double hue, double saturation, double brightness) ConvertToHSBColor(Color color)
|
||||||
|
=> (color.GetHue(), color.GetSaturation(), color.GetBrightness());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a given <see cref="Color"/> to a HSL color (hue, saturation, lightness)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||||
|
/// <returns>The hue [0°..360°], saturation [0..1] and lightness [0..1] values of the converted color</returns>
|
||||||
|
internal static (double hue, double saturation, double lightness) ConvertToHSLColor(Color color)
|
||||||
|
{
|
||||||
|
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
|
||||||
|
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
|
||||||
|
|
||||||
|
var lightness = (max + min) / 2d;
|
||||||
|
|
||||||
|
if (lightness == 0d || min == max)
|
||||||
|
{
|
||||||
|
return (color.GetHue(), 0d, lightness);
|
||||||
|
}
|
||||||
|
else if (lightness > 0d && lightness <= 0.5d)
|
||||||
|
{
|
||||||
|
return (color.GetHue(), (max - min) / (max + min), lightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (color.GetHue(), (max - min) / (2d - (max + min)), lightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a given <see cref="Color"/> to a HSV color (hue, saturation, value)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||||
|
/// <returns>The hue [0°..360°], saturation [0..1] and value [0..1] of the converted color</returns>
|
||||||
|
internal static (double hue, double saturation, double value) ConvertToHSVColor(Color color)
|
||||||
|
{
|
||||||
|
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
|
||||||
|
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
|
||||||
|
|
||||||
|
return (color.GetHue(), max == 0d ? 0d : (max - min) / max, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a given <see cref="Color"/> to a HWB color (hue, whiteness, blackness)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||||
|
/// <returns>The hue [0°..360°], whiteness [0..1] and blackness [0..1] of the converted color</returns>
|
||||||
|
internal static (double hue, double whiteness, double blackness) ConvertToHWBColor(Color color)
|
||||||
|
{
|
||||||
|
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
|
||||||
|
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
|
||||||
|
|
||||||
|
return (color.GetHue(), min, 1 - max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a given <see cref="Color"/> to a natural color (hue, whiteness, blackness)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||||
|
/// <returns>The hue, whiteness [0..1] and blackness [0..1] of the converted color</returns>
|
||||||
|
internal static (string hue, double whiteness, double blackness) ConvertToNaturalColor(Color color)
|
||||||
|
{
|
||||||
|
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
|
||||||
|
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
|
||||||
|
|
||||||
|
return (GetNaturalColorFromHue(color.GetHue()), min, 1 - max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return the natural color for the given hue value
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hue">The hue value to convert</param>
|
||||||
|
/// <returns>A natural color</returns>
|
||||||
|
private static string GetNaturalColorFromHue(double hue)
|
||||||
|
{
|
||||||
|
while (hue >= 360)
|
||||||
|
{
|
||||||
|
hue -= 360;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hue < 60)
|
||||||
|
{
|
||||||
|
return "R" + (hue / 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hue < 120)
|
||||||
|
{
|
||||||
|
return "Y" + ((hue - 60) / 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hue < 180)
|
||||||
|
{
|
||||||
|
return "G" + ((hue - 120) / 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hue < 240)
|
||||||
|
{
|
||||||
|
return "C" + ((hue - 180) / 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hue < 300)
|
||||||
|
{
|
||||||
|
return "B" + ((hue - 240) / 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "M" + ((hue - 300) / 0.6);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||||
|
|
||||||
namespace ColorPicker.Helpers
|
namespace ColorPicker.Helpers
|
||||||
{
|
{
|
||||||
@@ -24,15 +24,55 @@ namespace ColorPicker.Helpers
|
|||||||
=> colorRepresentationType switch
|
=> colorRepresentationType switch
|
||||||
{
|
{
|
||||||
ColorRepresentationType.CMYK => ColorToCYMK(color),
|
ColorRepresentationType.CMYK => ColorToCYMK(color),
|
||||||
|
ColorRepresentationType.NCol => ColorToNCol(color),
|
||||||
ColorRepresentationType.HEX => ColorToHex(color),
|
ColorRepresentationType.HEX => ColorToHex(color),
|
||||||
|
ColorRepresentationType.HSB => ColorToHSB(color),
|
||||||
ColorRepresentationType.HSL => ColorToHSL(color),
|
ColorRepresentationType.HSL => ColorToHSL(color),
|
||||||
ColorRepresentationType.HSV => ColorToHSV(color),
|
ColorRepresentationType.HSV => ColorToHSV(color),
|
||||||
|
ColorRepresentationType.HWB => ColorToHWB(color),
|
||||||
ColorRepresentationType.RGB => ColorToRGB(color),
|
ColorRepresentationType.RGB => ColorToRGB(color),
|
||||||
|
|
||||||
// Fall-back value, when "_userSettings.CopiedColorRepresentation.Value" is incorrect
|
// Fall-back value, when "_userSettings.CopiedColorRepresentation.Value" is incorrect
|
||||||
_ => ColorToHex(color),
|
_ => ColorToHex(color),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return a <see cref="string"/> representation of a CYMK color
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The <see cref="Color"/> for the CYMK color presentation</param>
|
||||||
|
/// <returns>A <see cref="string"/> representation of a CYMK color</returns>
|
||||||
|
private static string ColorToCYMK(Color color)
|
||||||
|
{
|
||||||
|
var (cyan, magenta, yellow, blackKey) = ColorHelper.ConvertToCMYKColor(color);
|
||||||
|
|
||||||
|
cyan = Math.Round(cyan * 100);
|
||||||
|
magenta = Math.Round(magenta * 100);
|
||||||
|
yellow = Math.Round(yellow * 100);
|
||||||
|
blackKey = Math.Round(blackKey * 100);
|
||||||
|
|
||||||
|
return $"cmyk({cyan.ToString(CultureInfo.InvariantCulture)}%"
|
||||||
|
+ $", {magenta.ToString(CultureInfo.InvariantCulture)}%"
|
||||||
|
+ $", {yellow.ToString(CultureInfo.InvariantCulture)}%"
|
||||||
|
+ $", {blackKey.ToString(CultureInfo.InvariantCulture)}%)";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return a <see cref="string"/> representation of a natural color
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The <see cref="Color"/> for the natural color presentation</param>
|
||||||
|
/// <returns>A <see cref="string"/> representation of a natural color</returns>
|
||||||
|
private static string ColorToNCol(Color color)
|
||||||
|
{
|
||||||
|
var (hue, whiteness, blackness) = ColorHelper.ConvertToNaturalColor(color);
|
||||||
|
|
||||||
|
whiteness = Math.Round(whiteness * 100);
|
||||||
|
blackness = Math.Round(blackness * 100);
|
||||||
|
|
||||||
|
return $"{hue}"
|
||||||
|
+ $", {whiteness.ToString(CultureInfo.InvariantCulture)}%"
|
||||||
|
+ $", {blackness.ToString(CultureInfo.InvariantCulture)}%";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a hexadecimal <see cref="string"/> representation of a RGB color
|
/// Return a hexadecimal <see cref="string"/> representation of a RGB color
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -44,19 +84,27 @@ namespace ColorPicker.Helpers
|
|||||||
+ $"{color.B.ToString("X2", CultureInfo.InvariantCulture)}";
|
+ $"{color.B.ToString("X2", CultureInfo.InvariantCulture)}";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a <see cref="string"/> representation of a RGB color
|
/// Return a <see cref="string"/> representation of a HSB color
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The see cref="Color"/> for the RGB color presentation</param>
|
/// <param name="color">The <see cref="Color"/> for the HSB color presentation</param>
|
||||||
/// <returns>A <see cref="string"/> representation of a RGB color</returns>
|
/// <returns>A <see cref="string"/> representation of a HSB color</returns>
|
||||||
private static string ColorToRGB(Color color)
|
private static string ColorToHSB(Color color)
|
||||||
=> $"rgb({color.R.ToString(CultureInfo.InvariantCulture)}"
|
{
|
||||||
+ $", {color.G.ToString(CultureInfo.InvariantCulture)}"
|
var (hue, saturation, brightnes) = ColorHelper.ConvertToHSBColor(color);
|
||||||
+ $", {color.B.ToString(CultureInfo.InvariantCulture)})";
|
|
||||||
|
hue = Math.Round(hue);
|
||||||
|
saturation = Math.Round(saturation * 100);
|
||||||
|
brightnes = Math.Round(brightnes * 100);
|
||||||
|
|
||||||
|
return $"hsb({hue.ToString(CultureInfo.InvariantCulture)}"
|
||||||
|
+ $", {saturation.ToString(CultureInfo.InvariantCulture)}%"
|
||||||
|
+ $", {brightnes.ToString(CultureInfo.InvariantCulture)}%)";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a <see cref="string"/> representation of a HSL color
|
/// Return a <see cref="string"/> representation of a HSL color
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The see cref="Color"/> for the HSL color presentation</param>
|
/// <param name="color">The <see cref="Color"/> for the HSL color presentation</param>
|
||||||
/// <returns>A <see cref="string"/> representation of a HSL color</returns>
|
/// <returns>A <see cref="string"/> representation of a HSL color</returns>
|
||||||
private static string ColorToHSL(Color color)
|
private static string ColorToHSL(Color color)
|
||||||
{
|
{
|
||||||
@@ -75,7 +123,7 @@ namespace ColorPicker.Helpers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a <see cref="string"/> representation of a HSV color
|
/// Return a <see cref="string"/> representation of a HSV color
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The see cref="Color"/> for the HSV color presentation</param>
|
/// <param name="color">The <see cref="Color"/> for the HSV color presentation</param>
|
||||||
/// <returns>A <see cref="string"/> representation of a HSV color</returns>
|
/// <returns>A <see cref="string"/> representation of a HSV color</returns>
|
||||||
private static string ColorToHSV(Color color)
|
private static string ColorToHSV(Color color)
|
||||||
{
|
{
|
||||||
@@ -92,24 +140,31 @@ namespace ColorPicker.Helpers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a <see cref="string"/> representation of a HSV color
|
/// Return a <see cref="string"/> representation of a HWB color
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The see cref="Color"/> for the HSV color presentation</param>
|
/// <param name="color">The <see cref="Color"/> for the HWB color presentation</param>
|
||||||
/// <returns>A <see cref="string"/> representation of a HSV color</returns>
|
/// <returns>A <see cref="string"/> representation of a HWB color</returns>
|
||||||
private static string ColorToCYMK(Color color)
|
private static string ColorToHWB(Color color)
|
||||||
{
|
{
|
||||||
var (cyan, magenta, yellow, blackKey) = ColorHelper.ConvertToCMYKColor(color);
|
var (hue, whiteness, blackness) = ColorHelper.ConvertToHWBColor(color);
|
||||||
|
|
||||||
cyan = Math.Round(cyan * 100);
|
hue = Math.Round(hue);
|
||||||
magenta = Math.Round(magenta * 100);
|
whiteness = Math.Round(whiteness * 100);
|
||||||
yellow = Math.Round(yellow * 100);
|
blackness = Math.Round(blackness * 100);
|
||||||
blackKey = Math.Round(blackKey * 100);
|
|
||||||
|
|
||||||
// Using InvariantCulture since this is used for color representation
|
return $"hwb({hue.ToString(CultureInfo.InvariantCulture)}"
|
||||||
return $"cmyk({cyan.ToString(CultureInfo.InvariantCulture)}%"
|
+ $", {whiteness.ToString(CultureInfo.InvariantCulture)}%"
|
||||||
+ $", {magenta.ToString(CultureInfo.InvariantCulture)}%"
|
+ $", {blackness.ToString(CultureInfo.InvariantCulture)}%)";
|
||||||
+ $", {yellow.ToString(CultureInfo.InvariantCulture)}%"
|
|
||||||
+ $", {blackKey.ToString(CultureInfo.InvariantCulture)}%)";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return a <see cref="string"/> representation of a RGB color
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The see cref="Color"/> for the RGB color presentation</param>
|
||||||
|
/// <returns>A <see cref="string"/> representation of a RGB color</returns>
|
||||||
|
private static string ColorToRGB(Color color)
|
||||||
|
=> $"rgb({color.R.ToString(CultureInfo.InvariantCulture)}"
|
||||||
|
+ $", {color.G.ToString(CultureInfo.InvariantCulture)}"
|
||||||
|
+ $", {color.B.ToString(CultureInfo.InvariantCulture)})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||||
|
|
||||||
namespace ColorPicker.Settings
|
namespace ColorPicker.Settings
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.IO;
|
|||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||||
|
|
||||||
namespace ColorPicker.Settings
|
namespace ColorPicker.Settings
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using ColorPicker.Helpers;
|
using ColorPicker.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
@@ -11,8 +11,12 @@ namespace UnitTest_ColorPickerUI.Helpers
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow(ColorRepresentationType.CMYK, "cmyk(0%, 0%, 0%, 100%)")]
|
[DataRow(ColorRepresentationType.CMYK, "cmyk(0%, 0%, 0%, 100%)")]
|
||||||
[DataRow(ColorRepresentationType.HEX, "#000000")]
|
[DataRow(ColorRepresentationType.HEX, "#000000")]
|
||||||
|
[DataRow(ColorRepresentationType.NCol, "R0, 0, 0")]
|
||||||
|
[DataRow(ColorRepresentationType.HSB, "hsb(0, 0%, 0%)")]
|
||||||
|
[DataRow(ColorRepresentationType.HSI, "hsi(0, 0%, 0%)")]
|
||||||
[DataRow(ColorRepresentationType.HSL, "hsl(0, 0%, 0%)")]
|
[DataRow(ColorRepresentationType.HSL, "hsl(0, 0%, 0%)")]
|
||||||
[DataRow(ColorRepresentationType.HSV, "hsv(0, 0%, 0%)")]
|
[DataRow(ColorRepresentationType.HSV, "hsv(0, 0%, 0%)")]
|
||||||
|
[DataRow(ColorRepresentationType.HWB, "hwb(0, 0%, 0%)")]
|
||||||
[DataRow(ColorRepresentationType.RGB, "rgb(0, 0, 0)")]
|
[DataRow(ColorRepresentationType.RGB, "rgb(0, 0, 0)")]
|
||||||
|
|
||||||
public void ColorRGBtoCMYKZeroDiv(ColorRepresentationType type, string expected)
|
public void ColorRGBtoCMYKZeroDiv(ColorRepresentationType type, string expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user