Table of Contents

Struct CmykColor

Namespace
Egami.Colors
Assembly
Egami.dll

A CMYK color: ink amounts 0 to 1, 0 being no ink, by the plain formula (K = 1 − max(R, G, B), C = (1 − R − K) / (1 − K)) on encoded sRGB. Real inks need a print profile: From(Rgba8, ColorProfile, ColorTransformOptions?) converts through one.

public readonly record struct CmykColor : IColorValue<CmykColor>, IEquatable<CmykColor>
Implements
Inherited Members

Examples

// Color values in the models apps ask for, from and to pixels, and between each other.
Rgba8 orange = new(240, 128, 32, 255);
HslColor hsl = HslColor.From(orange);                          // hue 28°, saturation 0.87, lightness 0.53
LabColor lab = ColorConvert.Convert<HslColor, LabColor>(hsl);  // through XYZ
OklchColor oklch = OklchColor.From(orange);
YCbCrColor jpeg = YCbCrColor.From(orange);                     // BT.601 full range, as JPEG
YCbCrColor video = YCbCrColor.From(orange, YuvMatrix.Bt709, YuvRange.Limited);

// Color difference: CIEDE2000 on Lab, distance on Oklab.
double deltaE = lab.DeltaE2000(LabColor.From(new Rgba8(235, 130, 40, 255)));

// Whole rows at once, from any pixel type and encoding.
Rgba8[] pixels = [orange, new(10, 20, 30, 255)];
OklabColor[] row = new OklabColor[pixels.Length];
ColorConvert.FromPixels<Rgba8, OklabColor>(pixels, row);
ColorConvert.FromPixels<Rgba8, OklabColor>(pixels, row, ColorProfile.DisplayP3);   // the same pixels read as Display P3

Constructors

CmykColor(float, float, float, float)

A CMYK color: ink amounts 0 to 1, 0 being no ink, by the plain formula (K = 1 − max(R, G, B), C = (1 − R − K) / (1 − K)) on encoded sRGB. Real inks need a print profile: From(Rgba8, ColorProfile, ColorTransformOptions?) converts through one.

public CmykColor(float C, float M, float Y, float K)

Parameters

C float

Cyan.

M float

Magenta.

Y float

Yellow.

K float

Black.

Examples

// Color values in the models apps ask for, from and to pixels, and between each other.
Rgba8 orange = new(240, 128, 32, 255);
HslColor hsl = HslColor.From(orange);                          // hue 28°, saturation 0.87, lightness 0.53
LabColor lab = ColorConvert.Convert<HslColor, LabColor>(hsl);  // through XYZ
OklchColor oklch = OklchColor.From(orange);
YCbCrColor jpeg = YCbCrColor.From(orange);                     // BT.601 full range, as JPEG
YCbCrColor video = YCbCrColor.From(orange, YuvMatrix.Bt709, YuvRange.Limited);

// Color difference: CIEDE2000 on Lab, distance on Oklab.
double deltaE = lab.DeltaE2000(LabColor.From(new Rgba8(235, 130, 40, 255)));

// Whole rows at once, from any pixel type and encoding.
Rgba8[] pixels = [orange, new(10, 20, 30, 255)];
OklabColor[] row = new OklabColor[pixels.Length];
ColorConvert.FromPixels<Rgba8, OklabColor>(pixels, row);
ColorConvert.FromPixels<Rgba8, OklabColor>(pixels, row, ColorProfile.DisplayP3);   // the same pixels read as Display P3

Properties

C

Cyan.

public float C { get; init; }

Property Value

float

K

Black.

public float K { get; init; }

Property Value

float

M

Magenta.

public float M { get; init; }

Property Value

float

Y

Yellow.

public float Y { get; init; }

Property Value

float

Methods

From(Rgba8)

Returns the value of an sRGB pixel; alpha is ignored.

public static CmykColor From(Rgba8 color)

Parameters

color Rgba8

The pixel.

Returns

CmykColor

The value.

From(Rgba8, ColorProfile, ColorTransformOptions?)

Returns the inks a print profile uses for an sRGB pixel.

public static CmykColor From(Rgba8 color, ColorProfile cmyk, ColorTransformOptions? options = null)

Parameters

color Rgba8

The pixel.

cmyk ColorProfile

The CMYK profile.

options ColorTransformOptions

The intent and black point compensation, or null for the defaults.

Returns

CmykColor

The inks.

Examples

// The inks a press would use for a color, and the color it would print, through the press's CMYK profile: here the
// built-in FOGRA39 (coated offset paper); ColorProfile.FromIcc reads any other.
ColorProfile print = ColorProfile.Fogra39;
CmykColor inks = CmykColor.From(new Rgba8(200, 60, 30, 255), print, new ColorTransformOptions { Intent = RenderingIntent.RelativeColorimetric });
Rgba8 proof = inks.ToRgba8(print);

Exceptions

ArgumentException

cmyk is not a CMYK profile.

From(RgbaF32)

Returns the value of an sRGB pixel, whose channels may be outside 0..1; alpha is ignored.

public static CmykColor From(RgbaF32 color)

Parameters

color RgbaF32

The pixel.

Returns

CmykColor

The value.

FromXyz(XyzColor)

Returns the value for an XYZ color (D65, white Y = 1).

public static CmykColor FromXyz(XyzColor xyz)

Parameters

xyz XyzColor

The color.

Returns

CmykColor

The value; components may fall outside their usual range for colors outside sRGB.

IsCloseTo(CmykColor, float)

Returns whether every component of the two values differs by at most tolerance.

public bool IsCloseTo(CmykColor other, float tolerance = 0.0001)

Parameters

other CmykColor

The other value.

tolerance float

The largest difference allowed in a component.

Returns

bool

true if they are that close.

ToRgba8()

Returns the color as an opaque sRGB pixel, each channel clamped into range.

public Rgba8 ToRgba8()

Returns

Rgba8

The pixel.

ToRgba8(ColorProfile, ColorTransformOptions?)

Returns the sRGB pixel a print profile gives these inks.

public Rgba8 ToRgba8(ColorProfile cmyk, ColorTransformOptions? options = null)

Parameters

cmyk ColorProfile

The CMYK profile.

options ColorTransformOptions

The intent and black point compensation, or null for the defaults.

Returns

Rgba8

The pixel.

Examples

// The inks a press would use for a color, and the color it would print, through the press's CMYK profile: here the
// built-in FOGRA39 (coated offset paper); ColorProfile.FromIcc reads any other.
ColorProfile print = ColorProfile.Fogra39;
CmykColor inks = CmykColor.From(new Rgba8(200, 60, 30, 255), print, new ColorTransformOptions { Intent = RenderingIntent.RelativeColorimetric });
Rgba8 proof = inks.ToRgba8(print);

Exceptions

ArgumentException

cmyk is not a CMYK profile.

ToRgbaF32()

Returns the color as an opaque sRGB pixel, unclamped, so colors outside sRGB keep channels outside 0..1.

public RgbaF32 ToRgbaF32()

Returns

RgbaF32

The pixel.

ToXyz()

Returns the color as XYZ (D65, white Y = 1).

public XyzColor ToXyz()

Returns

XyzColor

The color.