### Add Unicolour.Experimental Package Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README_UnicolourExperimental_nuget.md Install the Unicolour.Experimental package using the .NET CLI. ```bash dotnet add package Wacton.Unicolour.Experimental ``` -------------------------------- ### Add Unicolour.Datasets NuGet Package Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README_UnicolourDatasets_nuget.md Install the Unicolour.Datasets package using the .NET CLI. ```bash dotnet add package Wacton.Unicolour.Datasets ``` -------------------------------- ### Install Unicolour Package Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Add the Unicolour NuGet package to your .NET project using the dotnet CLI. ```bash dotnet add package Wacton.Unicolour ``` -------------------------------- ### Install ReportGenerator Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Tests/_NOTES.md Installs the dotnet-reportgenerator-globaltool globally if it's not already installed. This tool is used for generating code coverage reports. ```bash dotnet tool install -g dotnet-reportgenerator-globaltool ``` -------------------------------- ### Configure Unicolour with Custom Wide-Gamut RGB and D50 XYZ Source: https://github.com/waacton/unicolour/blob/main/docs/README.md This example demonstrates creating a Unicolour instance with a custom wide-gamut RGB configuration and a specific XYZ illuminant (D50 with 10° observer) using Von Kries chromatic adaptation. It's suitable for advanced color space definitions. ```csharp var rgbConfig = new RgbConfiguration( chromaticityR: new(0.7347, 0.2653), chromaticityG: new(0.1152, 0.8264), chromaticityB: new(0.1566, 0.0177), whitePoint: Illuminant.D50.GetWhitePoint(Observer.Degree2), fromLinear: value => Math.Pow(value, 1 / 2.19921875), toLinear: value => Math.Pow(value, 2.19921875) ); var xyzConfig = new XyzConfiguration(Illuminant.C, Observer.Degree10, ChromaticAdaptation.VonKries); var config = new Configuration(rgbConfig, xyzConfig); var colour = new Unicolour(config, ColourSpace.Rgb255, 202, 97, 143); ``` -------------------------------- ### Reference Predefined Unicolour Datasets Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README_UnicolourDatasets_nuget.md Access predefined colours and colourmaps from various datasets. Examples include CSS named colours, xkcd colours, and colourmaps like Viridis and Turbo. ```csharp var pink = Css.DeepPink; var green = Xkcd.NastyGreen; var mapped = Colourmaps.Viridis.Map(0.5); var palette = Colourmaps.Turbo.Palette(10); ``` -------------------------------- ### Create and Convert WXY Colour Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/docs/wxy-colour-space.md Demonstrates creating a WXY colour and converting it to RGB and Oklab colour spaces. Ensure the Unicolour library is included. ```csharp var yellow = new Unicolour(ColourSpace.Wxy, 570, 0.75, 0.9); Console.WriteLine(yellow.Rgb); // 0.97 0.99 0.19 Console.WriteLine(yellow.Oklab); // 0.96 -0.07 +0.19 ``` -------------------------------- ### Convert between RGB configurations Source: https://github.com/waacton/unicolour/blob/main/README.md Demonstrates converting a pure sRGB green color to Display P3 and then to Rec. 2020 configurations. Ensure the Configuration objects are correctly initialized for each target color space. ```csharp /* pure sRGB green */ var srgbConfig = new Configuration(RgbConfiguration.StandardRgb); var srgbColour = new Unicolour(srgbConfig, ColourSpace.Rgb, 0, 1, 0); Console.WriteLine(srgbColour.Rgb); // 0.00 1.00 0.00 /* Convert to Display P3 */ var displayP3Config = new Configuration(RgbConfiguration.DisplayP3); var displayP3Colour = srgbColour.ConvertToConfiguration(displayP3Config); Console.WriteLine(displayP3Colour.Rgb); // 0.46 0.99 0.30 /* Convert to Rec. 2020 */ var rec2020Config = new Configuration(RgbConfiguration.Rec2020); var rec2020Colour = displayP3Colour.ConvertToConfiguration(rec2020Config); Console.WriteLine(rec2020Colour.Rgb); // 0.57 0.96 0.27 ``` -------------------------------- ### Import Unicolour.Experimental Namespace Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README_UnicolourExperimental_nuget.md Import the necessary namespace to use the experimental features. ```csharp using Wacton.Unicolour.Experimental; ``` -------------------------------- ### Get Wavelength Attributes Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Ascertain the dominant wavelength and excitation purity of a color using the spectral locus. These attributes can be used in conjunction with the WXY color space to create a color. Wavelengths from 360 nm to 700 nm are supported. ```csharp var chromaticity = new Chromaticity(0.1, 0.8); var hyperGreen = new Unicolour(chromaticity); var dominantWavelength = hyperGreen.DominantWavelength; var excitationPurity = hyperGreen.ExcitationPurity; var laserRed = new Unicolour(ColourSpace.Wxy, 670, 1.0, 0.5); ``` -------------------------------- ### Convert Unicolour to Different Configurations Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README_Unicolour_nuget.md Demonstrates how to convert a Unicolour object to different RGB configurations like Display P3 and Rec. 2020. Ensure the target configuration is correctly specified. ```cs /* pure sRGB green */ var srgbConfig = new Configuration(RgbConfiguration.StandardRgb); var srgbColour = new Unicolour(srgbConfig, ColourSpace.Rgb, 0, 1, 0); Console.WriteLine(srgbColour.Rgb); // 0.00 1.00 0.00 /* Convert sRGB to Display P3 */ var displayP3Config = new Configuration(RgbConfiguration.DisplayP3); var displayP3Colour = srgbColour.ConvertToConfiguration(displayP3Config); Console.WriteLine(displayP3Colour.Rgb); // 0.46 0.99 0.30 /* Convert Display P3 to Rec. 2020 */ var rec2020Config = new Configuration(RgbConfiguration.Rec2020); var rec2020Colour = displayP3Colour.ConvertToConfiguration(rec2020Config); Console.WriteLine(rec2020Colour.Rgb); // 0.57 0.96 0.27 ``` -------------------------------- ### Create Unicolour with Custom Wide-Gamut RGB and D5 XYZ Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Initialize a Unicolour object with custom-defined wide-gamut RGB and Illuminant C XYZ configurations, including Von Kries adaptation. ```csharp var rgbConfig = new RgbConfiguration( chromaticityR: new(0.7347, 0.2653), chromaticityG: new(0.1152, 0.8264), chromaticityB: new(0.1566, 0.0177), whitePoint: Illuminant.D50.GetWhitePoint(Observer.Degree2), fromLinear: value => Math.Pow(value, 1 / 2.19921875), toLinear: value => Math.Pow(value, 2.19921875) ); var xyzConfig = new XyzConfiguration(Illuminant.C, Observer.Degree10, ChromaticAdaptation.VonKries); var config = new Configuration(rgbConfig, xyzConfig); var color = new Unicolour(config, ColourSpace.Rgb255, 202, 97, 143); ``` -------------------------------- ### Configure Colour Spaces with Sensible Defaults Source: https://github.com/waacton/unicolour/blob/main/docs/README.md Utilize Unicolour's sensible defaults for RGB models (sRGB) and white points (D65, 2° observer), ensuring consistency. These defaults can be overridden using the `Configuration` parameter for custom applications. ```csharp var defaultConfig = new Configuration(RgbConfiguration.StandardRgb, XyzConfiguration.D65); var colour = new Unicolour(defaultConfig, ColourSpace.Rgb255, 192, 255, 238); ``` -------------------------------- ### Convert Between RGB Configurations Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Demonstrates converting a color between different RGB color space configurations like sRGB, Display P3, and Rec. 2020. Ensure the Unicolour library is referenced. ```csharp /* pure sRGB green */ var srgbConfig = new Configuration(RgbConfiguration.StandardRgb); var srgbColor = new Unicolour(srgbConfig, ColourSpace.Rgb, 0, 1, 0); Console.WriteLine(srgbColour.Rgb); // 0.00 1.00 0.00 /* Display P3 */ var displayP3Config = new Configuration(RgbConfiguration.DisplayP3); var displayP3Color = srgbColour.ConvertToConfiguration(displayP3Config); Console.WriteLine(displayP3Colour.Rgb); // 0.46 0.99 0.30 /* Rec. 2020 */ var rec2020Config = new Configuration(RgbConfiguration.Rec2020); var rec2020Color = displayP3Colour.ConvertToConfiguration(rec2020Config); Console.WriteLine(rec2020Colour.Rgb); // 0.57 0.96 0.27 ``` -------------------------------- ### Create and Convert Unicolour Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Demonstrates creating Unicolour objects from hex codes and RGB values, and accessing their representations in different color spaces like HSL and Hex. ```csharp var cyan = new Unicolour("#00FFFF"); Console.WriteLine(cyan.Hsl); // 180.0° 100.0% 50.0% var yellow = new Unicolour(ColourSpace.Rgb255, 255, 255, 0); Console.WriteLine(yellow.Hex); // #FFFF00 ``` -------------------------------- ### Mix Colors in Different Color Spaces Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Demonstrates mixing two colors (red and blue) using different color spaces (HSL) and hue spans (Decreasing, Increasing). Also shows how to generate a palette of evenly distributed mixes. ```csharp var red = new Unicolour(ColourSpace.Rgb, 1.0, 0.0, 0.0, alpha: 1.0); var blue = new Unicolour(ColourSpace.Hsb, 240, 1.0, 1.0, alpha: 1.0); var magenta = red.Mix(blue, ColourSpace.Hsl, 0.5, HueSpan.Decreasing); var green = red.Mix(blue, ColourSpace.Hsl, 0.5, HueSpan.Increasing); var palette = red.Palette(blue, ColourSpace.Hsl, 10, HueSpan.Longer); ``` -------------------------------- ### Use Default Configuration Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Utilize the default Unicolour configuration, which uses sRGB as the default RGB model and D65 illuminant as the default white point. This configuration can be overridden. ```csharp var defaultConfig = new Configuration(RgbConfiguration.StandardRgb, XyzConfiguration.D65); var color = new Unicolour(defaultConfig, ColourSpace.Rgb255, 192, 255, 238); ``` -------------------------------- ### Initialize Unicolour with Hex String Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Create a Unicolour instance using a hexadecimal color string. The library automatically detects the color space. ```csharp Unicolour pink = new("#FF1493"); Console.WriteLine(pink.Oklab); // 0.65 +0.26 -0.01 ``` -------------------------------- ### Create Colour from Spectral Power Distribution (SPD) Source: https://github.com/waacton/unicolour/blob/main/docs/README.md Create a colour by defining a spectral power distribution. Wavelengths should be in 1 nm or 5 nm intervals; omitted wavelengths are assumed to have zero spectral power. ```csharp /* [575 nm] -> 0.5 · [580 nm] -> 1.0 · [585 nm] -> 0.5 */ var spd = new Spd(start: 575, interval: 5, coefficients: [0.5, 1.0, 0.5]); var intenseYellow = new Unicolour(spd); ``` -------------------------------- ### Create Unicolour with Predefined Rec. 2020 RGB and D50 XYZ Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Use this snippet to initialize a Unicolour object with standard Rec. 2020 RGB and Illuminant D50 XYZ configurations. ```csharp Configuration config = new(RgbConfiguration.Rec2020, XyzConfiguration.D50); Unicolour color = new(config, ColourSpace.Rgb255, 204, 64, 132); ``` -------------------------------- ### Import Unicolour.Datasets Namespace Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README_UnicolourDatasets_nuget.md Import the necessary namespace to use the datasets in your C# code. ```csharp using Wacton.Unicolour.Datasets; ``` -------------------------------- ### Compare Colors using Delta E Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Illustrates calculating the color difference between two Unicolour objects using the CIEDE2000 delta E metric. ```csharp var white = new Unicolour(ColourSpace.Oklab, 1.0, 0.0, 0.0); var black = new Unicolour(ColourSpace.Oklab, 0.0, 0.0, 0.0); var difference = white.Difference(black, DeltaE.Ciede2000); Console.WriteLine(difference); // 100.0000 ``` -------------------------------- ### Convert RGB to Oklch Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Demonstrates converting an RGB color to the Oklch color space. This is useful for understanding color differences in a perceptually uniform space. ```csharp Unicolour color = new(ColourSpace.Rgb255, 192, 255, 238); var (l, c, h) = color.Oklch; ``` -------------------------------- ### Blend Colors using Source-Over Operator Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Shows how to blend two colors (blue and red) using different blend modes like Normal and Screen, simulating layered elements with alpha compositing. ```csharp var blue = new Unicolour(ColourSpace.Rgb, 240, 1.0, 1.0, alpha: 0.5); var red = new Unicolour(ColourSpace.Rgb, 1.0, 0.0, 0.0); var purple = blue.Blend(red, BlendMode.Normal); var pink = blue.Blend(red, BlendMode.Screen); ``` -------------------------------- ### Create Unicolour from Spectral Power Distribution Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README.md Create a Unicolour object from a spectral power distribution (SPD). Wavelengths should be provided in 1 nm or 5 nm intervals. ```csharp /* [575 nm] -> 0.5 [580 nm] -> 1.0 [585 nm] -> 0.5 */ var spd = new Spd(start: 575, interval: 5, coefficients: [0.5, 1.0, 0.5]); var intenseYellow = new Unicolour(spd); ``` -------------------------------- ### Configure Unicolour with Custom RGB and XYZ Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README_Unicolour_nuget.md Manually define custom RGB and XYZ configurations, including chromaticity coordinates, white points, and adaptation methods. This is useful for non-standard color spaces or specific color science requirements. ```cs var rgbConfig = new RgbConfiguration( chromaticityR: new(0.7347, 0.2653), chromaticityG: new(0.1152, 0.8264), chromaticityB: new(0.1566, 0.0177), whitePoint: Illuminant.D50.GetWhitePoint(Observer.Degree2), fromLinear: value => Math.Pow(value, 1 / 2.19921875), toLinear: value => Math.Pow(value, 2.19921875) ); var xyzConfig = new XyzConfiguration(Illuminant.C, Observer.Degree10, Adaptation.VonKries); var config = new Configuration(rgbConfig, xyzConfig); var colour = new Unicolour(config, ColourSpace.Rgb255, 202, 97, 143); ``` -------------------------------- ### Compare Colors using Contrast and Delta E Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Demonstrates comparing two colors (red and blue) using contrast and difference metrics. The difference calculation supports various Delta E standards, including CIE76. ```csharp var red = new Unicolour(ColourSpace.Rgb, 1.0, 0.0, 0.0); var blue = new Unicolour(ColourSpace.Hsb, 240, 1.0, 1.0); var contrast = red.Contrast(blue); var difference = red.Difference(blue, DeltaE.Cie76); ``` -------------------------------- ### Run Tests and Collect Coverage Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Tests/_NOTES.md Executes tests, outputs artifacts including JUnit results and XPlat code coverage data. Ensure the test adapter path is correctly set and results directory is specified. ```bash dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=..\artifacts\{assembly}-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage" --results-directory:".\artifacts" ``` -------------------------------- ### Create Unicolour Instance with RGB Values Source: https://github.com/waacton/unicolour/blob/main/docs/README_us.md Instantiate a Unicolour object by specifying the color space and its corresponding RGB values (0-255 range). ```csharp Unicolour color = new(ColourSpace.Rgb255, 192, 255, 238); ``` -------------------------------- ### Approximate Pigments from Colour Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README_UnicolourExperimental_nuget.md Generate a reflectance curve for a given colour to approximate a single-constant pigment, enabling Kubelka-Munk pigment mixing. ```csharp var redPigment = PigmentGenerator.From(new Unicolour("#FF0000")); var bluePigment = PigmentGenerator.From(new Unicolour("#0000FF")); var magenta = new Unicolour([redPigment, bluePigment], [0.5, 0.5]); ``` -------------------------------- ### Generate Colour Wheel and Harmonies Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/README_UnicolourExperimental_nuget.md Create a colour wheel from pigments or a hued colour space and generate various colour harmonies like analogous, complementary, and triadic. ```csharp /* populate pigment k and s with measurement data */ var quinaRed = new Pigment(380, 1, k: [], s: []); var bismuthYellow = new Pigment(380, 1, k: [], s: []); var ceruleanBlue = new Pigment(380, 1, k: [], s: []); var titaniumWhite = new Pigment(380, 1, k: [], s: []); var boneBlack = new Pigment(380, 1, k: [], s: []); var colourWheel = usePigments ? ColourWheel.From(quinaRed, bismuthYellow, ceruleanBlue, titaniumWhite, boneBlack) : ColourWheel.From(ColourSpace.Oklch, reference: new Unicolour("ff0000")); var orange = colourWheel.Pure(hue: 60); var lightGreen = colourWheel.Tint(hue: 180, weight: 1); var darkPurple = colourWheel.Shade(hue: 300, weight: 1); var greyRed = colourWheel.Tone(hue: 0, weight: 1); var orangePalette = colourWheel.Harmony(hue: 60, Harmony.Analogous); ``` -------------------------------- ### C# Gamut Mapping with Purity Reduction Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/docs/wxy-colour-space.md This snippet demonstrates how to map an out-of-gamut WXY colour to an in-gamut colour by iteratively reducing its purity until it falls within the sRGB gamut. Adjust the 'decrement' value for greater accuracy. ```csharp const double decrement = 0.05; // reduce for greater accuracy var (w, x, y) = (530, 0.5, 0.7); var colour = new Unicolour(ColourSpace.Wxy, w, x, y); while (!colour.IsInRgbGamut) { x -= decrement; colour = new Unicolour(ColourSpace.Wxy, w, x, y); } Console.WriteLine(colour.Wxy); // 530.0nm 30.0% 0.7000 Console.WriteLine(colour.Hex); // #0FF993 ``` -------------------------------- ### Convert RGB to WXY Source: https://github.com/waacton/unicolour/blob/main/Unicolour.Readme/docs/wxy-colour-space.md Shows how to convert an RGB colour, specifically sRGB green, into its WXY representation including dominant wavelength and excitation purity. Assumes standard illuminant D65 (2° observer). ```csharp var green = new Unicolour(ColourSpace.Rgb, 0, 1, 0); Console.WriteLine(green.Wxy); // 549.1nm 73.4% 0.7152 ```