From fd0420b73ec7749e597847ab30d054619247f11c Mon Sep 17 00:00:00 2001 From: Wacton Date: Sun, 5 Nov 2023 16:19:45 +0000 Subject: [PATCH] Update package details --- README.md | 170 +++++++++++++++++++------------------ Unicolour/Unicolour.csproj | 10 +-- 2 files changed, 92 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 4114f3e3..5c3ddb6f 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Unicolour can be used to calculate colour difference via: - ΔE76 (CIE76) - ΔE94 (CIE94) - ΔE00 (CIEDE2000) +- ΔECMC (CMC l:c) - ΔEITP - ΔEz - ΔEHyAB @@ -76,37 +77,37 @@ These [can be overridden](#advanced-configuration-) using the `Configuration` pa This library was initially written for personal projects since existing libraries had complex APIs or missing features. The goal of this library is to be accurate, intuitive, and easy to use. -Although performance is not a priority, conversions are only calculated once — when first evaluated (either on access or as part of an intermediate conversion step) the result is stored for future use. -It is also [extensively tested](Unicolour.Tests), including verification of roundtrip conversions and validation using known colour values. +Although performance is not a priority, conversions are only calculated once; when first evaluated (either on access or as part of an intermediate conversion step) the result is stored for future use. +It is also [extensively tested](Unicolour.Tests), including verification of roundtrip conversions, validation using known colour values, and 100% line coverage and branch coverage. Targets [.NET Standard 2.0](https://docs.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0) for use in .NET 5.0+, .NET Core 2.0+ and .NET Framework 4.6.1+ applications. ## Quickstart ⚡ -| Colour space | Construction | Access | Interpolation | -|-----------------------------------------|-----------------------------|----------------|-------------------| -| RGB (Hex) | `Unicolour.FromHex()` | `.Hex` | `.MixRgb()` | -| RGB (0-255) | `Unicolour.FromRgb255()` | `.Rgb.Byte255` | `.MixRgb()` | -| RGB | `Unicolour.FromRgb()` | `.Rgb` | `.MixRgb()` | -| Linear RGB | `Unicolour.FromRgbLinear()` | `.RgbLinear` | `.MixRgbLinear()` | -| HSB/HSV | `Unicolour.FromHsb()` | `.Hsb` | `.MixHsb()` | -| HSL | `Unicolour.FromHsl()` | `.Hsl` | `.MixHsl()` | -| HWB | `Unicolour.FromHwb()` | `.Hwb` | `.MixHwb()` | -| CIEXYZ | `Unicolour.FromXyz()` | `.Xyz` | `.MixXyz()` | -| CIExyY | `Unicolour.FromXyy()` | `.Xyy` | `.MixXyy()` | -| CIELAB | `Unicolour.FromLab()` | `.Lab` | `.MixLab()` | -| CIELChab | `Unicolour.FromLchab()` | `.Lchab` | `.MixLchab()` | -| CIELUV | `Unicolour.FromLuv()` | `.Luv` | `.MixLuv()` | -| CIELChuv | `Unicolour.FromLchuv()` | `.Lchuv` | `.MixLchuv()` | -| HSLuv | `Unicolour.FromHsluv()` | `.Hsluv` | `.MixHsluv()` | -| HPLuv | `Unicolour.FromHpluv()` | `.Hpluv` | `.MixHpluv()` | -| ICTCP | `Unicolour.FromIctcp()` | `.Ictcp` | `.MixIctcp()` | -| Jzazbz | `Unicolour.FromJzazbz()` | `.Jzazbz` | `.MixJzazbz()` | -| JzCzhz | `Unicolour.FromJzczhz()` | `.Jzczhz` | `.MixJzczhz()` | -| Oklab | `Unicolour.FromOklab()` | `.Oklab` | `.MixOklab()` | -| Oklch | `Unicolour.FromOklch()` | `.Oklch` | `.MixOklch()` | -| CIECAM02 | `Unicolour.FromCam02()` | `.Cam02` | `.MixCam02()` | -| CAM16 | `Unicolour.FromCam16()` | `.Cam16` | `.MixCam16()` | -| HCT | `Unicolour.FromHct()` | `.Hct` | `.MixHct()` | +| Colour space | Enum | Create | Get | +|-----------------------------------------|-------------------------|---------------------------------------------|----------------| +| RGB (Hex) | - | `new Unicolour(hex)` | `.Hex` | +| RGB (0-255) | `ColourSpace.Rgb255` | `new Unicolour(ColourSpace.Rgb255, ...)` | `.Rgb.Byte255` | +| RGB | `ColourSpace.Rgb` | `new Unicolour(ColourSpace.Rgb, ...)` | `.Rgb` | +| Linear RGB | `ColourSpace.RgbLinear` | `new Unicolour(ColourSpace.RgbLinear, ...)` | `.RgbLinear` | +| HSB/HSV | `ColourSpace.Hsb` | `new Unicolour(ColourSpace.Hsb, ...)` | `.Hsb` | +| HSL | `ColourSpace.Hsl` | `new Unicolour(ColourSpace.Hsl, ...)` | `.Hsl` | +| HWB | `ColourSpace.Hwb` | `new Unicolour(ColourSpace.Hwb, ...)` | `.Hwb` | +| CIEXYZ | `ColourSpace.Xyz` | `new Unicolour(ColourSpace.Xyz, ...)` | `.Xyz` | +| CIExyY | `ColourSpace.Xyy` | `new Unicolour(ColourSpace.Xyy, ...)` | `.Xyy` | +| CIELAB | `ColourSpace.Lab` | `new Unicolour(ColourSpace.Lab, ...)` | `.Lab` | +| CIELChab | `ColourSpace.Lchab` | `new Unicolour(ColourSpace.Lchab, ...)` | `.Lchab` | +| CIELUV | `ColourSpace.Luv` | `new Unicolour(ColourSpace.Luv, ...)` | `.Luv` | +| CIELChuv | `ColourSpace.Lchuv` | `new Unicolour(ColourSpace.Lchuv, ...)` | `.Lchuv` | +| HSLuv | `ColourSpace.Hsluv` | `new Unicolour(ColourSpace.Hsluv, ...)` | `.Hsluv` | +| HPLuv | `ColourSpace.Hpluv` | `new Unicolour(ColourSpace.Hpluv, ...)` | `.Hpluv` | +| ICTCP | `ColourSpace.Ictcp` | `new Unicolour(ColourSpace.Ictcp, ...)` | `.Ictcp` | +| Jzazbz | `ColourSpace.Jzazbz` | `new Unicolour(ColourSpace.Jzazbz, ...)` | `.Jzazbz` | +| JzCzhz | `ColourSpace.Jzczhz` | `new Unicolour(ColourSpace.Jzczhz, ...)` | `.Jzczhz` | +| Oklab | `ColourSpace.Oklab` | `new Unicolour(ColourSpace.Oklab, ...)` | `.Oklab` | +| Oklch | `ColourSpace.Oklch` | `new Unicolour(ColourSpace.Oklch, ...)` | `.Oklch` | +| CIECAM02 | `ColourSpace.Cam02` | `new Unicolour(ColourSpace.Cam02, ...)` | `.Cam02` | +| CAM16 | `ColourSpace.Cam16` | `new Unicolour(ColourSpace.Cam16, ...)` | `.Cam16` | +| HCT | `ColourSpace.Hct` | `new Unicolour(ColourSpace.Hct, ...)` | `.Hct` | ## How to use 🌈 1. Install the package from [NuGet](https://www.nuget.org/packages/Wacton.Unicolour/) @@ -121,29 +122,29 @@ using Wacton.Unicolour; 3. Create a `Unicolour` ```c# -var unicolour = Unicolour.FromHex("#FF1493"); -var unicolour = Unicolour.FromRgb255(255, 20, 147); -var unicolour = Unicolour.FromRgb(1.00, 0.08, 0.58); -var unicolour = Unicolour.FromRgbLinear(1.00, 0.01, 0.29); -var unicolour = Unicolour.FromHsb(327.6, 0.922, 1.000); -var unicolour = Unicolour.FromHsl(327.6, 1.000, 0.539); -var unicolour = Unicolour.FromHwb(327.6, 0.078, 0.000); -var unicolour = Unicolour.FromXyz(0.4676, 0.2387, 0.2974); -var unicolour = Unicolour.FromXyy(0.4658, 0.2378, 0.2387); -var unicolour = Unicolour.FromLab(55.96, 84.54, -5.7); -var unicolour = Unicolour.FromLchab(55.96, 84.73, 356.1); -var unicolour = Unicolour.FromLuv(55.96, 131.47, -24.35); -var unicolour = Unicolour.FromLchuv(55.96, 133.71, 349.5); -var unicolour = Unicolour.FromHsluv(349.5, 100.0, 56.0); -var unicolour = Unicolour.FromHpluv(349.5, 303.2, 56.0); -var unicolour = Unicolour.FromIctcp(0.38, 0.12, 0.19); -var unicolour = Unicolour.FromJzazbz(0.106, 0.107, 0.005); -var unicolour = Unicolour.FromJzczhz(0.106, 0.107, 2.6); -var unicolour = Unicolour.FromOklab(0.65, 0.26, -0.01); -var unicolour = Unicolour.FromOklch(0.65, 0.26, 356.9); -var unicolour = Unicolour.FromCam02(62.86, 40.81, -1.18); -var unicolour = Unicolour.FromCam16(62.47, 42.60, -1.36); -var unicolour = Unicolour.FromHct(358.2, 100.38, 55.96); +var unicolour = new Unicolour("#FF1493"); +var unicolour = new Unicolour(ColourSpace.Rgb255, 255, 20, 147); +var unicolour = new Unicolour(ColourSpace.Rgb, 1.00, 0.08, 0.58); +var unicolour = new Unicolour(ColourSpace.RgbLinear, 1.00, 0.01, 0.29); +var unicolour = new Unicolour(ColourSpace.Hsb, 327.6, 0.922, 1.000); +var unicolour = new Unicolour(ColourSpace.Hsl, 327.6, 1.000, 0.539); +var unicolour = new Unicolour(ColourSpace.Hwb, 327.6, 0.078, 0.000); +var unicolour = new Unicolour(ColourSpace.Xyz, 0.4676, 0.2387, 0.2974); +var unicolour = new Unicolour(ColourSpace.Xyy, 0.4658, 0.2378, 0.2387); +var unicolour = new Unicolour(ColourSpace.Lab, 55.96, 84.54, -5.7); +var unicolour = new Unicolour(ColourSpace.Lchab, 55.96, 84.73, 356.1); +var unicolour = new Unicolour(ColourSpace.Luv, 55.96, 131.47, -24.35); +var unicolour = new Unicolour(ColourSpace.Lchuv, 55.96, 133.71, 349.5); +var unicolour = new Unicolour(ColourSpace.Hsluv, 349.5, 100.0, 56.0); +var unicolour = new Unicolour(ColourSpace.Hpluv, 349.5, 303.2, 56.0); +var unicolour = new Unicolour(ColourSpace.Ictcp, 0.38, 0.12, 0.19); +var unicolour = new Unicolour(ColourSpace.Jzazbz, 0.106, 0.107, 0.005); +var unicolour = new Unicolour(ColourSpace.Jzczhz, 0.106, 0.107, 2.6); +var unicolour = new Unicolour(ColourSpace.Oklab, 0.65, 0.26, -0.01); +var unicolour = new Unicolour(ColourSpace.Oklch, 0.65, 0.26, 356.9); +var unicolour = new Unicolour(ColourSpace.Cam02, 62.86, 40.81, -1.18); +var unicolour = new Unicolour(ColourSpace.Cam16, 62.47, 42.60, -1.36); +var unicolour = new Unicolour(ColourSpace.Hct, 358.2, 100.38, 55.96); ``` 4. Get colour space representations @@ -181,41 +182,44 @@ var inGamut = unicolour.IsInDisplayGamut; 6. Mix colours (interpolate between them) ```c# -var mixed = unicolour1.MixRgb(unicolour2, 0.5); -var mixed = unicolour1.MixRgbLinear(unicolour2, 0.5); -var mixed = unicolour1.MixHsb(unicolour2, 0.5); -var mixed = unicolour1.MixHsl(unicolour2, 0.5); -var mixed = unicolour1.MixHwb(unicolour2, 0.5); -var mixed = unicolour1.MixXyz(unicolour2, 0.5); -var mixed = unicolour1.MixXyy(unicolour2, 0.5); -var mixed = unicolour1.MixLab(unicolour2, 0.5); -var mixed = unicolour1.MixLchab(unicolour2, 0.5); -var mixed = unicolour1.MixLuv(unicolour2, 0.5); -var mixed = unicolour1.MixLchuv(unicolour2, 0.5); -var mixed = unicolour1.MixHsluv(unicolour2, 0.5); -var mixed = unicolour1.MixHpluv(unicolour2, 0.5); -var mixed = unicolour1.MixIctcp(unicolour2, 0.5); -var mixed = unicolour1.MixJzazbz(unicolour2, 0.5); -var mixed = unicolour1.MixJzczhz(unicolour2, 0.5); -var mixed = unicolour1.MixOklab(unicolour2, 0.5); -var mixed = unicolour1.MixOklch(unicolour2, 0.5); -var mixed = unicolour1.MixCam02(unicolour2, 0.5); -var mixed = unicolour1.MixCam16(unicolour2, 0.5); -var mixed = unicolour1.MixHct(unicolour2, 0.5); +var mixed = unicolour1.Mix(ColourSpace.Rgb, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.RgbLinear, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Hsb, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Hsl, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Hwb, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Xyz, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Xyy, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Lab, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Lchab, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Luv, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Lchuv, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Hsluv, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Hpluv, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Ictcp, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Jzazbz, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Jzczhz, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Oklab, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Oklch, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Cam02, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Cam16, unicolour2); +var mixed = unicolour1.Mix(ColourSpace.Hct, unicolour2); ``` 7. Compare colours ```c# var contrast = unicolour1.Contrast(unicolour2); -var difference = unicolour1.DeltaE76(unicolour2); -var difference = unicolour1.DeltaE94(unicolour2); -var difference = unicolour1.DeltaE00(unicolour2); -var difference = unicolour1.DeltaEItp(unicolour2); -var difference = unicolour1.DeltaEz(unicolour2); -var difference = unicolour1.DeltaEHyab(unicolour2); -var difference = unicolour1.DeltaEOk(unicolour2); -var difference = unicolour1.DeltaECam02(unicolour2); -var difference = unicolour1.DeltaECam16(unicolour2); +var difference = unicolour1.Difference(DeltaE.Cie76, unicolour2); +var difference = unicolour1.Difference(DeltaE.Cie94, unicolour2); +var difference = unicolour1.Difference(DeltaE.Cie94Textiles, unicolour2); +var difference = unicolour1.Difference(DeltaE.Ciede2000, unicolour2); +var difference = unicolour1.Difference(DeltaE.CmcAcceptability, unicolour2); +var difference = unicolour1.Difference(DeltaE.CmcPerceptibility, unicolour2); +var difference = unicolour1.Difference(DeltaE.Itp, unicolour2); +var difference = unicolour1.Difference(DeltaE.Z, unicolour2); +var difference = unicolour1.Difference(DeltaE.Hyab, unicolour2); +var difference = unicolour1.Difference(DeltaE.Ok, unicolour2); +var difference = unicolour1.Difference(DeltaE.Cam02, unicolour2); +var difference = unicolour1.Difference(DeltaE.Cam16, unicolour2); ``` 8. Map colour to display gamut @@ -261,7 +265,7 @@ and the white point of the XYZ colour space (e.g. D50 reference white used by IC ```c# // built-in configuration for Rec. 2020 RGB + D65 XYZ var config = new Configuration(RgbConfiguration.Rec2020, XyzConfiguration.D65); -var unicolour = Unicolour.FromRgb255(config, 255, 20, 147); +var unicolour = new Unicolour(ColourSpace.Rgb255, config, 255, 20, 147); ``` ```c# @@ -281,7 +285,7 @@ var xyzConfig = new XyzConfiguration( ); var config = new Configuration(rgbConfig, xyzConfig); -var unicolour = Unicolour.FromRgb255(config, 255, 20, 147); +var unicolour = new Unicolour(ColourSpace.Rgb255, config, 255, 20, 147); ``` Configuration is also available for CAM02 & CAM16 viewing conditions, @@ -293,7 +297,7 @@ A `Unicolour` can be converted to a different configuration, which enables conve ```c# // pure sRGB green var srgbConfig = new Configuration(RgbConfiguration.StandardRgb); -var unicolourSrgb = Unicolour.FromRgb(srgbConfig, 0, 1, 0); +var unicolourSrgb = new Unicolour(ColourSpace.Rgb, srgbConfig, 0, 1, 0); Console.WriteLine(unicolourSrgb.Rgb); // 0.00 1.00 0.00 // pure sRGB green -> Display P3 diff --git a/Unicolour/Unicolour.csproj b/Unicolour/Unicolour.csproj index c4c98062..50ffb70d 100644 --- a/Unicolour/Unicolour.csproj +++ b/Unicolour/Unicolour.csproj @@ -7,17 +7,17 @@ Wacton.Unicolour $(AssemblyName) William Acton - Colour conversion, interpolation, and comparison for .NET + 🌈 Colour / Color conversion, interpolation, and comparison for .NET William Acton - https://gitlab.com/Wacton/Unicolour - https://gitlab.com/Wacton/Unicolour + https://github.com/waacton/Unicolour + https://github.com/waacton/Unicolour 10 netstandard2.0 True Resources\Unicolour.png 3.0.0 - colour color RGB HSB HSV HSL HWB XYZ xyY LAB LUV LCH LCHab LCHuv HSLuv HPLuv ICtCp JzAzBz JzCzHz Oklab Oklch CAM02 CAM16 HCT converter colour-converter colour-conversion color-converter color-conversion colour-space colour-spaces color-space color-spaces interpolation colour-interpolation color-interpolation colour-mixing color-mixing comparison colour-comparison color-comparison contrast luminance deltaE chromaticity display-p3 rec-2020 temperature cct duv cvd colour-vision-deficiency color-vision-deficiency colour-blindness color-blindness protanopia deuteranopia tritanopia achromatopsia - TODO: + colour color RGB HSB HSV HSL HWB XYZ xyY LAB LUV LCH LCHab LCHuv HSLuv HPLuv ICtCp JzAzBz JzCzHz Oklab Oklch CAM02 CAM16 HCT converter colour-converter colour-conversion color-converter color-conversion colour-space colour-spaces color-space color-spaces interpolation colour-interpolation color-interpolation colour-mixing color-mixing comparison colour-comparison color-comparison contrast luminance deltaE chromaticity display-p3 rec-2020 gamut-mapping temperature cct duv cvd colour-vision-deficiency color-vision-deficiency colour-blindness color-blindness protanopia deuteranopia tritanopia achromatopsia + Add gamut mapping, support premultiplied alpha interpolation, and improve API Resources\Unicolour.ico LICENSE