Class ColorProfile
What a raster's numbers mean: the color model, the primaries and white point, and the transfer function. Immutable; the built-ins cover the common encodings, and Create(ColorPrimaries, TransferFunction, string?) makes any other RGB encoding.
public sealed class ColorProfile
- Inheritance
-
ColorProfile
- Inherited Members
Examples
// A ColorProfile says what a raster's numbers mean. The built-ins cover the common encodings...
ColorProfile web = ColorProfile.Srgb;
ColorProfile wide = ColorProfile.DisplayP3;
ColorProfile hdr = ColorProfile.Rec2100Pq;
// ...and Create makes any other RGB encoding from primaries and a transfer function.
ColorProfile camera = ColorProfile.Create(ColorPrimaries.AdobeRgb, TransferFunction.Gamma(2.2), "Camera RGB");
Console.WriteLine($"{camera.Name}: {camera.Model}, HDR {camera.IsHdr}, same as Adobe RGB: {camera.IsEquivalentTo(ColorProfile.AdobeRgb)}");
Properties
AdobeRgb
Gets Adobe RGB (1998): its primaries, D65, a 563/256 (about 2.2) power curve.
public static ColorProfile AdobeRgb { get; }
Property Value
ChannelCount
Gets the number of channels: 3 for RGB, 1 for gray, 4 for CMYK, 2 to 15 for an n-colour profile.
public int ChannelCount { get; }
Property Value
ColorantNames
Gets the names of an output profile's inks, from its colorant table (clrt), in channel order; null
when the profile has none.
public IReadOnlyList<string>? ColorantNames { get; }
Property Value
DisplayP3
Gets Display P3: the P3 primaries, D65, the sRGB curve, as Apple devices and CSS Color 4 use it.
public static ColorProfile DisplayP3 { get; }
Property Value
Fogra39
Gets FOGRA39L: offset printing on coated paper (ISO 12647-2, paper types 1 and 2), Europe's usual press condition, built for a 300% total ink limit. The profile is colord's, built by ArgyllCMS from Fogra's measurements, as the CTAN colorprofiles package ships it (ICC version 2.2, free of known copyright restrictions); ToIcc() returns its bytes unchanged. It is read on first use. CMYK files without a profile still convert by the plain formula, not through this one.
public static ColorProfile Fogra39 { get; }
Property Value
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);
GrayLinear
Gets linear gray with D65 white.
public static ColorProfile GrayLinear { get; }
Property Value
GraySrgb
Gets gray with the sRGB curve and D65 white: what a gray file without color information means.
public static ColorProfile GraySrgb { get; }
Property Value
Icc
Gets the ICC profile this encoding was read from, or null.
public IccData? Icc { get; }
Property Value
IsHdr
Gets a value indicating whether the encoding is HDR (a PQ or HLG curve).
public bool IsHdr { get; }
Property Value
LinearSrgb
Gets linear sRGB: BT.709 primaries, D65, no curve.
public static ColorProfile LinearSrgb { get; }
Property Value
Model
Gets the color model.
public ColorModel Model { get; }
Property Value
Name
Gets a short name for the encoding, such as "sRGB" or the description of an ICC profile.
public string Name { get; }
Property Value
Primaries
Gets the primaries of an RGB encoding, or null for gray, CMYK, and ICC profiles that convert through tables rather than a matrix.
public ColorPrimaries? Primaries { get; }
Property Value
ProPhotoRgb
Gets ProPhoto RGB (ROMM RGB): its primaries, D50, a 1.8 power with a linear segment below 1/32.
public static ColorProfile ProPhotoRgb { get; }
Property Value
Rec2020
Gets Rec. 2020: BT.2020 primaries, D65, the BT.709/BT.2020 curve.
public static ColorProfile Rec2020 { get; }
Property Value
Rec2100Hlg
Gets Rec. 2100 HLG: BT.2020 primaries, D65, the HLG curve (HDR).
public static ColorProfile Rec2100Hlg { get; }
Property Value
Rec2100Pq
Gets Rec. 2100 PQ: BT.2020 primaries, D65, the PQ curve (HDR).
public static ColorProfile Rec2100Pq { get; }
Property Value
Srgb
Gets sRGB (IEC 61966-2-1): BT.709 primaries, D65, the sRGB curve. What a file without color information means.
public static ColorProfile Srgb { get; }
Property Value
Transfer
Gets the transfer function of an RGB or gray encoding, or null for CMYK, ICC profiles that convert through tables, and ICC profiles whose three curves differ.
public TransferFunction? Transfer { get; }
Property Value
White
Gets the white point.
public Chromaticity White { get; }
Property Value
Methods
Create(ColorPrimaries, TransferFunction, string?)
Returns an RGB encoding from primaries and a transfer function.
public static ColorProfile Create(ColorPrimaries primaries, TransferFunction transfer, string? name = null)
Parameters
primariesColorPrimariesThe primaries, with the white point.
transferTransferFunctionThe transfer function.
namestringA name, or null for a generated one.
Returns
- ColorProfile
The encoding.
Exceptions
- ArgumentNullException
primariesortransferis null.- ArgumentException
The primaries cannot form a color space (IsValid is false).
CreateGray(TransferFunction, Chromaticity?, string?)
Returns a gray encoding from a transfer function and a white point.
public static ColorProfile CreateGray(TransferFunction transfer, Chromaticity? white = null, string? name = null)
Parameters
transferTransferFunctionThe transfer function.
whiteChromaticity?The white point, or null for D65.
namestringA name, or null for a generated one.
Returns
- ColorProfile
The encoding.
Exceptions
- ArgumentNullException
transferis null.
FromCodePoints(ColorCodePoints)
Returns the RGB encoding that H.273 code points name, or null when Egami does not implement the primaries or the transfer they name, or when the matrix code is not RGB (0).
public static ColorProfile? FromCodePoints(ColorCodePoints codePoints)
Parameters
codePointsColorCodePointsThe code points.
Returns
- ColorProfile
The encoding, a built-in one where it matches, or null.
FromIcc(IccData)
Returns the encoding an ICC profile describes. A matrix-shaper profile gets its primaries (un-adapted from D50 by its
chad tag or its white point) and its curve, so IsEquivalentTo(ColorProfile) recognizes sRGB, Display P3 and the
other built-ins written as ICC; a version 4.4 cicp tag naming a known encoding wins over the rest, as it does for
HDR profiles. Profiles that convert through tables, and CMYK, keep only the model and white.
public static ColorProfile FromIcc(IccData icc)
Parameters
iccIccDataThe parsed profile.
Returns
- ColorProfile
The encoding, with Icc set.
Exceptions
- ArgumentNullException
iccis null.- CorruptDataException
The profile is damaged where conversion needs it.
- UnsupportedFormatException
The profile is not an RGB, gray or CMYK input, display, output or color space profile.
FromIcc(ReadOnlySpan<byte>)
Reads an ICC profile: FromIcc(IccData) of Parse(ReadOnlySpan<byte>, SafetyLimits?).
public static ColorProfile FromIcc(ReadOnlySpan<byte> profile)
Parameters
profileReadOnlySpan<byte>The profile's bytes.
Returns
- ColorProfile
The encoding.
Exceptions
- CorruptDataException
The profile is damaged where conversion needs it.
- UnsupportedFormatException
The profile is not an RGB, gray or CMYK input, display, output or color space profile.
IsEquivalentTo(ColorProfile)
Returns whether two encodings mean the same colors: the same model, primaries and white within 1e-4, and curves that agree within 1e-4 (so an ICC profile written for sRGB is equivalent to Srgb).
public bool IsEquivalentTo(ColorProfile other)
Parameters
otherColorProfileThe other encoding.
Returns
ToCodePoints()
Returns the H.273 code points of this encoding, or null when its primaries or curve have none (Adobe RGB, ProPhoto, gray, CMYK, parametric and sampled curves).
public ColorCodePoints? ToCodePoints()
Returns
- ColorCodePoints?
The code points, or null.
ToIcc()
Returns an ICC profile for this encoding: the bytes it was read from, or a small version 4 profile written for it (4.3 with
parametric curves for SDR encodings, 4.4 with a cicp tag for PQ and HLG), which Little CMS, browsers and image
tools read.
public byte[] ToIcc()
Returns
- byte[]
A new array holding the profile.
Examples
// Any RGB or gray encoding as a small ICC profile, for files and other software.
byte[] p3 = ColorProfile.DisplayP3.ToIcc();
bool same = ColorProfile.FromIcc(p3).IsEquivalentTo(ColorProfile.DisplayP3);
ToIccV2()
Returns a version 2 ICC profile for this encoding, for readers that do not read version 4 ones (older image editors, viewers and print drivers): the bytes it was read from when they are a version 2 profile, else a small version 2.4 matrix-shaper (or gray curve) profile written for it, with curv curves (a gamma or a 1024-entry table) and its own white as the media white point. PQ and HLG get the rolled-off tables ToIcc() writes, without the cicp tag version 2 lacks.
public byte[] ToIccV2()
Returns
- byte[]
A new array holding the profile.
Examples
// A version 2 profile, for software that reads only those: older image editors, viewers and print drivers.
byte[] p3 = ColorProfile.DisplayP3.ToIccV2();
Version version = IccData.Parse(p3).Version;
Exceptions
- InvalidOperationException
The encoding is not RGB or gray with one curve, which a version 2 matrix-shaper cannot hold.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.