[Color Picker] Feature/lab color representation (#12935)

* Created logic to convrt RGB to CIELAB (with intermediate step to CIEXYZ)

* Added CIELAB to the available color representation types

* Created tests for the color conversion from RGB to LAB (and for RGB to XYZ)

* Update ColorPickerViewModel to keep the L*a*b* format the same

* Improved variable names & comment

* Remove url from color converting website to avoid unnecessary license issues

* Removed typo of the wrong variable

* Added expected words into dictionary

* Added links to explain used formulas

* Added CIE XYZ color space

* Added 'SRGB' to the dictionary

* Updated the range for the X and Z value in the CIE XYZ color space comments

* Fixed XYZ to LAB calculations

* Changed output format for CIELAb

Changed L*a*b*(L,a,b) to CIELab(L,a,b)

* Changed output in tests

* Fixed tests

* Added extra accuracy

* Add decimal places to cielab and ciexyz formats

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
Ruben Fricke
2021-09-24 17:54:44 +02:00
committed by GitHub
parent 88e24263cf
commit 3358fd9b02
8 changed files with 259 additions and 1 deletions

View File

@@ -55,5 +55,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Enumerations
/// Color presentation as natural color (hue, whiteness[0%..100%], blackness[0%..100%])
/// </summary>
NCol = 8,
/// <summary>
/// Color presentation as CIELAB color space, also referred to as CIELAB(L[0..100], A[-128..127], B[-128..127])
/// </summary>
CIELAB = 9,
/// <summary>
/// Color presentation as CIEXYZ color space (X[0..95], Y[0..100], Z[0..109]
/// </summary>
CIEXYZ = 10,
}
}

View File

@@ -53,6 +53,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{ ColorRepresentationType.HWB, "HWB - hwb(100, 50%, 75%)" },
{ ColorRepresentationType.NCol, "NCol - R10, 50%, 75%" },
{ ColorRepresentationType.RGB, "RGB - rgb(100, 50, 75)" },
{ ColorRepresentationType.CIELAB, "CIE LAB - CIELab(76, 21, 80)" },
{ ColorRepresentationType.CIEXYZ, "CIE XYZ - xyz(56, 50, 7)" },
};
GeneralSettingsConfig = settingsRepository.SettingsConfig;
@@ -218,6 +220,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
var hsiFormatName = ColorRepresentationType.HSI.ToString();
var hwbFormatName = ColorRepresentationType.HWB.ToString();
var ncolFormatName = ColorRepresentationType.NCol.ToString();
var cielabFormatName = ColorRepresentationType.CIELAB.ToString();
var ciexyzFormatName = ColorRepresentationType.CIEXYZ.ToString();
formatsUnordered.Add(new ColorFormatModel(hexFormatName, "#EF68FF", visibleFormats.ContainsKey(hexFormatName) && visibleFormats[hexFormatName]));
formatsUnordered.Add(new ColorFormatModel(rgbFormatName, "rgb(239, 104, 255)", visibleFormats.ContainsKey(rgbFormatName) && visibleFormats[rgbFormatName]));
@@ -228,6 +232,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
formatsUnordered.Add(new ColorFormatModel(hsiFormatName, "hsi(100, 50%, 75%)", visibleFormats.ContainsKey(hsiFormatName) && visibleFormats[hsiFormatName]));
formatsUnordered.Add(new ColorFormatModel(hwbFormatName, "hwb(100, 50%, 75%)", visibleFormats.ContainsKey(hwbFormatName) && visibleFormats[hwbFormatName]));
formatsUnordered.Add(new ColorFormatModel(ncolFormatName, "R10, 50%, 75%", visibleFormats.ContainsKey(ncolFormatName) && visibleFormats[ncolFormatName]));
formatsUnordered.Add(new ColorFormatModel(cielabFormatName, "CIELab(66, 72, -52)", visibleFormats.ContainsKey(cielabFormatName) && visibleFormats[cielabFormatName]));
formatsUnordered.Add(new ColorFormatModel(ciexyzFormatName, "xyz(59, 35, 98)", visibleFormats.ContainsKey(ciexyzFormatName) && visibleFormats[ciexyzFormatName]));
foreach (var storedColorFormat in _colorPickerSettings.Properties.VisibleColorFormats)
{