Merge pull request #7555 from TobiasSekan/MoreColorsTakeTwo

[ColorPicker] Add HSB, HSI, HWB and NCol color representation
This commit is contained in:
Clint Rutkas
2020-11-09 15:16:32 -08:00
committed by GitHub
15 changed files with 589 additions and 228 deletions

View File

@@ -13,44 +13,7 @@ namespace ColorPicker.Helpers
internal static class ColorHelper
{
/// <summary>
/// Convert a given <see cref="Color"/> 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"/> 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)
/// 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 cyan[0..1], magenta[0..1], yellow[0..1] and black key[0..1] of the converted color</returns>
@@ -80,5 +43,135 @@ namespace ColorPicker.Helpers
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 HSI color (hue, saturation, intensity)
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], saturation [0..1] and intensity [0..1] of the converted color</returns>
internal static (double hue, double saturation, double intensity) ConvertToHSIColor(Color color)
{
// special case for black
if (color.R == 0 && color.G == 0 && color.B == 0)
{
return (0d, 0d, 0d);
}
var red = color.R / 255d;
var green = color.G / 255d;
var blue = color.B / 255d;
var intensity = (red + green + blue) / 3d;
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
return (color.GetHue(), 1d - (min / intensity), intensity);
}
/// <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)
{
if (hue < 60d)
{
return $"R{Math.Round(hue / 0.6d, 0)}";
}
if (hue < 120d)
{
return $"Y{Math.Round((hue - 60d) / 0.6d, 0)}";
}
if (hue < 180d)
{
return $"G{Math.Round((hue - 120d) / 0.6d, 0)}";
}
if (hue < 240d)
{
return $"C{Math.Round((hue - 180d) / 0.6d, 0)}";
}
if (hue < 300d)
{
return $"B{Math.Round((hue - 240d) / 0.6d, 0)}";
}
return $"M{Math.Round((hue - 300d) / 0.6d, 0)}";
}
}
}

View File

@@ -5,7 +5,7 @@
using System;
using System.Drawing;
using System.Globalization;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
namespace ColorPicker.Helpers
{
@@ -25,14 +25,38 @@ namespace ColorPicker.Helpers
{
ColorRepresentationType.CMYK => ColorToCYMK(color),
ColorRepresentationType.HEX => ColorToHex(color),
ColorRepresentationType.HSB => ColorToHSB(color),
ColorRepresentationType.HSI => ColorToHSI(color),
ColorRepresentationType.HSL => ColorToHSL(color),
ColorRepresentationType.HSV => ColorToHSV(color),
ColorRepresentationType.HWB => ColorToHWB(color),
ColorRepresentationType.NCol => ColorToNCol(color),
ColorRepresentationType.RGB => ColorToRGB(color),
// Fall-back value, when "_userSettings.CopiedColorRepresentation.Value" is incorrect
_ => 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 hexadecimal <see cref="string"/> representation of a RGB color
/// </summary>
@@ -44,19 +68,45 @@ namespace ColorPicker.Helpers
+ $"{color.B.ToString("X2", CultureInfo.InvariantCulture)}";
/// <summary>
/// Return a <see cref="string"/> representation of a RGB color
/// Return a <see cref="string"/> representation of a HSB 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)})";
/// <param name="color">The <see cref="Color"/> for the HSB color presentation</param>
/// <returns>A <see cref="string"/> representation of a HSB color</returns>
private static string ColorToHSB(Color color)
{
var (hue, saturation, brightness) = ColorHelper.ConvertToHSBColor(color);
hue = Math.Round(hue);
saturation = Math.Round(saturation * 100);
brightness = Math.Round(brightness * 100);
return $"hsb({hue.ToString(CultureInfo.InvariantCulture)}"
+ $", {saturation.ToString(CultureInfo.InvariantCulture)}%"
+ $", {brightness.ToString(CultureInfo.InvariantCulture)}%)";
}
/// <summary>
/// Return a <see cref="string"/> representation of a HSI color
/// </summary>
/// <param name="color">The <see cref="Color"/> for the HSI color presentation</param>
/// <returns>A <see cref="string"/> representation of a HSI color</returns>
private static string ColorToHSI(Color color)
{
var (hue, saturation, intensity) = ColorHelper.ConvertToHSIColor(color);
hue = Math.Round(hue);
saturation = Math.Round(saturation * 100);
intensity = Math.Round(intensity * 100);
return $"hsi({hue.ToString(CultureInfo.InvariantCulture)}"
+ $", {saturation.ToString(CultureInfo.InvariantCulture)}%"
+ $", {intensity.ToString(CultureInfo.InvariantCulture)}%)";
}
/// <summary>
/// Return a <see cref="string"/> representation of a HSL color
/// </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>
private static string ColorToHSL(Color color)
{
@@ -75,7 +125,7 @@ namespace ColorPicker.Helpers
/// <summary>
/// Return a <see cref="string"/> representation of a HSV color
/// </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>
private static string ColorToHSV(Color color)
{
@@ -92,24 +142,48 @@ namespace ColorPicker.Helpers
}
/// <summary>
/// Return a <see cref="string"/> representation of a HSV color
/// Return a <see cref="string"/> representation of a HWB color
/// </summary>
/// <param name="color">The see cref="Color"/> for the HSV color presentation</param>
/// <returns>A <see cref="string"/> representation of a HSV color</returns>
private static string ColorToCYMK(Color color)
/// <param name="color">The <see cref="Color"/> for the HWB color presentation</param>
/// <returns>A <see cref="string"/> representation of a HWB color</returns>
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);
magenta = Math.Round(magenta * 100);
yellow = Math.Round(yellow * 100);
blackKey = Math.Round(blackKey * 100);
hue = Math.Round(hue);
whiteness = Math.Round(whiteness * 100);
blackness = Math.Round(blackness * 100);
// Using InvariantCulture since this is used for color representation
return $"cmyk({cyan.ToString(CultureInfo.InvariantCulture)}%"
+ $", {magenta.ToString(CultureInfo.InvariantCulture)}%"
+ $", {yellow.ToString(CultureInfo.InvariantCulture)}%"
+ $", {blackKey.ToString(CultureInfo.InvariantCulture)}%)";
return $"hwb({hue.ToString(CultureInfo.InvariantCulture)}"
+ $", {whiteness.ToString(CultureInfo.InvariantCulture)}%"
+ $", {blackness.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>
/// 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)})";
}
}

View File

@@ -2,7 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// 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
{

View File

@@ -8,6 +8,7 @@ using System.IO;
using System.IO.Abstractions;
using System.Threading;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace ColorPicker.Settings

View File

@@ -15,7 +15,6 @@ using ColorPicker.Mouse;
using ColorPicker.Settings;
using ColorPicker.Telemetry;
using ColorPicker.ViewModelContracts;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Telemetry;
namespace ColorPicker.ViewModels

View File

@@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.Globalization;
using ColorPicker.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -41,7 +42,7 @@ namespace UnitTest_ColorPickerUI.Helpers
[DataRow(315, 100, 050, 100, 000, 075)] // Red-magenta
[DataRow(330, 100, 050, 100, 000, 050)] // Blue-red
[DataRow(345, 100, 050, 100, 000, 025)] // Light blue-red
public void ColorRGBtoHSL(double hue, double saturation, double lightness, int red, int green, int blue)
public void ColorRGBtoHSLTest(double hue, double saturation, double lightness, int red, int green, int blue)
{
red = Convert.ToInt32(Math.Round(255d / 100d * red)); // [0%..100%] to [0..255]
green = Convert.ToInt32(Math.Round(255d / 100d * green)); // [0%..100%] to [0..255]
@@ -90,7 +91,7 @@ namespace UnitTest_ColorPickerUI.Helpers
[DataRow(315, 100, 100, 100, 000, 075)] // Red-magenta
[DataRow(330, 100, 100, 100, 000, 050)] // Blue-red
[DataRow(345, 100, 100, 100, 000, 025)] // Light blue-red
public void ColorRGBtoHSV(double hue, double saturation, double value, int red, int green, int blue)
public void ColorRGBtoHSVTest(double hue, double saturation, double value, int red, int green, int blue)
{
red = Convert.ToInt32(Math.Round(255d / 100d * red)); // [0%..100%] to [0..255]
green = Convert.ToInt32(Math.Round(255d / 100d * green)); // [0%..100%] to [0..255]
@@ -138,7 +139,7 @@ namespace UnitTest_ColorPickerUI.Helpers
[DataRow(000, 100, 025, 000, 255, 000, 192)] // Red-magenta
[DataRow(000, 100, 050, 000, 255, 000, 128)] // Blue-red
[DataRow(000, 100, 075, 000, 255, 000, 064)] // Light blue-red
public void ColorRGBtoCMYK(int cyan, int magenta, int yellow, int blackKey, int red, int green, int blue)
public void ColorRGBtoCMYKTest(int cyan, int magenta, int yellow, int blackKey, int red, int green, int blue)
{
var color = Color.FromArgb(255, red, green, blue);
var result = ColorHelper.ConvertToCMYKColor(color);
@@ -156,8 +157,130 @@ namespace UnitTest_ColorPickerUI.Helpers
Assert.AreEqual(result.blackKey * 100d, blackKey, 0.5d);
}
// values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples
[TestMethod]
public void ColorRGBtoCMYKZeroDiv()
[DataRow("FFFFFF", 000.0, 000.0, 100.0)] // white
[DataRow("808080", 000.0, 000.0, 050.0)] // gray
[DataRow("000000", 000.0, 000.0, 000.0)] // black
[DataRow("FF0000", 000.0, 100.0, 033.3)] // red
[DataRow("BFBF00", 060.0, 100.0, 050.0)] // yellow
[DataRow("008000", 120.0, 100.0, 016.7)] // green
[DataRow("80FFFF", 180.0, 040.0, 083.3)] // cyan
[DataRow("8080FF", 240.0, 025.0, 066.7)] // blue
[DataRow("BF40BF", 300.0, 057.1, 058.3)] // magenta
[DataRow("A0A424", 061.8, 069.9, 047.1)]
[DataRow("411BEA", 251.1, 075.6, 042.6)]
[DataRow("1EAC41", 134.9, 066.7, 034.9)]
[DataRow("F0C80E", 049.5, 091.1, 059.3)]
[DataRow("B430E5", 283.7, 068.6, 059.6)]
[DataRow("ED7651", 014.3, 044.6, 057.0)]
[DataRow("FEF888", 056.9, 036.3, 083.5)]
[DataRow("19CB97", 162.4, 080.0, 049.5)]
[DataRow("362698", 248.3, 053.3, 031.9)]
[DataRow("7E7EB8", 240.5, 013.5, 057.0)]
public void ColorRGBtoHSITest(string hexValue, double hue, double saturation, double intensity)
{
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber);
var color = Color.FromArgb(255, red, green, blue);
var result = ColorHelper.ConvertToHSIColor(color);
// hue[0<>..360<EFBFBD>]
Assert.AreEqual(result.hue, hue, 0.5d);
// saturation[0..1]
Assert.AreEqual(result.saturation * 100d, saturation, 0.5d);
// intensity[0..1]
Assert.AreEqual(result.intensity * 100d, intensity, 0.5d);
}
// values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples
// and manual convert via https://colorconv.com/hwb
[TestMethod]
[DataRow("FFFFFF", 000, 100, 000)] // white
[DataRow("808080", 000, 050, 050)] // gray
[DataRow("000000", 000, 000, 100)] // black
[DataRow("FF0000", 000, 000, 000)] // red
[DataRow("BFBF00", 060, 000, 025)] // yellow
[DataRow("008000", 120, 000, 050)] // green
[DataRow("80FFFF", 180, 050, 000)] // cyan
[DataRow("8080FF", 240, 050, 000)] // blue
[DataRow("BF40BF", 300, 025, 025)] // magenta
[DataRow("A0A424", 062, 014, 036)]
[DataRow("411BEA", 251, 011, 008)]
[DataRow("1EAC41", 135, 012, 033)]
[DataRow("F0C80E", 049, 005, 006)]
[DataRow("B430E5", 284, 019, 010)]
[DataRow("ED7651", 014, 032, 007)]
[DataRow("FEF888", 057, 053, 000)]
[DataRow("19CB97", 162, 010, 020)]
[DataRow("362698", 248, 015, 040)]
[DataRow("7E7EB8", 240, 049, 028)]
public void ColorRGBtoHWBTest(string hexValue, double hue, double whiteness, double blackness)
{
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber);
var color = Color.FromArgb(255, red, green, blue);
var result = ColorHelper.ConvertToHWBColor(color);
// hue[0<>..360<EFBFBD>]
Assert.AreEqual(result.hue, hue, 0.5d);
// whiteness[0..1]
Assert.AreEqual(result.whiteness * 100d, whiteness, 0.5d);
// blackness[0..1]
Assert.AreEqual(result.blackness * 100d, blackness, 0.5d);
}
// values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples
// and manual convert via https://colorconv.com/hwb
[TestMethod]
[DataRow("FFFFFF", "R0", 100, 000)] // white
[DataRow("808080", "R0", 050, 050)] // gray
[DataRow("000000", "R0", 000, 100)] // black
[DataRow("FF0000", "R0", 000, 000)] // red
[DataRow("BFBF00", "Y0", 000, 025)] // yellow
[DataRow("008000", "G0", 000, 050)] // green
[DataRow("80FFFF", "C0", 050, 000)] // cyan
[DataRow("8080FF", "B0", 050, 000)] // blue
[DataRow("BF40BF", "M0", 025, 025)] // magenta
[DataRow("A0A424", "Y3", 014, 036)]
[DataRow("411BEA", "B18", 011, 008)]
[DataRow("1EAC41", "G25", 012, 033)]
[DataRow("F0C80E", "R82", 005, 006)]
[DataRow("B430E5", "B73", 019, 010)]
[DataRow("ED7651", "R24", 032, 007)]
[DataRow("FEF888", "R95", 053, 000)]
[DataRow("19CB97", "G71", 010, 020)]
[DataRow("362698", "B14", 015, 040)]
[DataRow("7E7EB8", "B0", 049, 028)]
public void ColorRGBtoNColTest(string hexValue, string hue, double whiteness, double blackness)
{
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber);
var color = Color.FromArgb(255, red, green, blue);
var result = ColorHelper.ConvertToNaturalColor(color);
// hue
Assert.AreEqual(result.hue, hue);
// whiteness[0..1]
Assert.AreEqual(result.whiteness * 100d, whiteness, 0.5d);
// blackness[0..1]
Assert.AreEqual(result.blackness * 100d, blackness, 0.5d);
}
[TestMethod]
public void ColorRGBtoCMYKZeroDivTest()
{
for(var red = 0; red < 256; red++)
{

View File

@@ -1,5 +1,5 @@
using ColorPicker.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Drawing;
@@ -11,11 +11,15 @@ namespace UnitTest_ColorPickerUI.Helpers
[TestMethod]
[DataRow(ColorRepresentationType.CMYK, "cmyk(0%, 0%, 0%, 100%)")]
[DataRow(ColorRepresentationType.HEX, "#000000")]
[DataRow(ColorRepresentationType.NCol, "R0, 0%, 100%")]
[DataRow(ColorRepresentationType.HSB, "hsb(0, 0%, 0%)")]
[DataRow(ColorRepresentationType.HSI, "hsi(0, 0%, 0%)")]
[DataRow(ColorRepresentationType.HSL, "hsl(0, 0%, 0%)")]
[DataRow(ColorRepresentationType.HSV, "hsv(0, 0%, 0%)")]
[DataRow(ColorRepresentationType.HWB, "hwb(0, 0%, 100%)")]
[DataRow(ColorRepresentationType.RGB, "rgb(0, 0, 0)")]
public void ColorRGBtoCMYKZeroDiv(ColorRepresentationType type, string expected)
public void GetStringRepresentationTest(ColorRepresentationType type, string expected)
{
var result = ColorRepresentationHelper.GetStringRepresentation(Color.Black, type);
Assert.AreEqual(result, expected);