IccNamedColorCollection Class

The colors of an ICC named color profile, in the order of the profile, and their lookup by name.

Remarks

Version 2 and 4 profiles store their colors in a namedColor2Tag (ICC.1:2022 section 10.17): a 7-bit ASCII name made of a prefix, a root name and a suffix, the media-relative colorimetry in the connection space of the profile, and optionally the device values of its data color space. Version 5 (iccMAX) profiles store them in a namedColorTag (ICC.2:2023 section 9.2.104) with a UTF-8 name and values for several tints; the collection holds the color at full tint (1.0). The spectral data of an iccMAX color are not read.

Instances are immutable and thread-safe. A name that appears several times refers to its first color.

Example

public static (byte[] Rgb, IReadOnlyList<double> Inks) SpotColor(string swatchBookPath, string name)
{
    var swatchBook = new IccProfile(new MetadataBlob(File.ReadAllBytes(swatchBookPath)));
    var colors = IccNamedColorCollection.Create(swatchBook);
    if (!colors.TryGetValue(name, out var color))
        throw new ArgumentException($"The swatch book has no color named '{name}'.", nameof(name));

    // The colorimetry of the color, converted to the device values of the display (relative colorimetric intent)
    var transform = IccNamedColorTransform.Create(swatchBook, IccProfile.Srgb);
    var rgb = new byte[transform.DestinationChannelCount];
    transform.Convert(color, rgb);

    // On the press the profile was made for, its device values (here CMYK inks) reproduce the color exactly
    return (rgb, color.DeviceValues);
}
Implements

Properties

NameDescription
CountGets the number of colors.
DeviceChannelCountGets the number of device values of each color (IccNamedColor.DeviceValues); 0 when the profile gives none.
ProfileGets the named color profile the colors were read from.

Gets the number of colors.

public int Count { get; }

Property value

int

DeviceChannelCount

IccNamedColorCollection.cs

Gets the number of device values of each color (IccNamedColor.DeviceValues); 0 when the profile gives none.

public int DeviceChannelCount { get; }

Property value

int

Gets the named color profile the colors were read from.

public IccProfile Profile { get; }

Property value

IccProfile

Indexers

NameDescription
this[int]Gets the color at an index, in the order of the profile.
this[string]Gets the color with a name (ordinal, case-sensitive comparison).

Item overloads

Gets the color at an index, in the order of the profile.

public IccNamedColor this[int index] { get; }
Parameters
index int
The index.
Property value

IccNamedColor

Exceptions
ArgumentOutOfRangeException
index is negative or not less than IccNamedColorCollection.Count.

Gets the color with a name (ordinal, case-sensitive comparison).

public IccNamedColor this[string name] { get; }
Parameters
name string
The full name of the color.
Property value

IccNamedColor

Exceptions
ArgumentNullException
name is null.
KeyNotFoundException
No color has this name.

Methods

NameDescription
Create(IccProfile)Reads the colors of a named color profile.
GetEnumerator()Returns an enumerator that iterates through the collection.
IndexOf(string)Gets the index of the first color with a name (ordinal, case-sensitive comparison).
System.Collections.IEnumerable.GetEnumerator()
TryGetValue(string, IccNamedColor?)Gets the color with a name (ordinal, case-sensitive comparison).

Create(IccProfile)

IccNamedColorCollection.cs

Reads the colors of a named color profile.

public static IccNamedColorCollection Create(IccProfile profile)

Parameters

profile IccProfile
A profile of the IccProfileClass.NamedColor class.

Returns

IccNamedColorCollection The colors.

Exceptions

ArgumentNullException
profile is null.
ArgumentException
profile is not a named color profile.
InvalidImageContentException
The profile is malformed.
UnsupportedImageFeatureException
The profile is valid but its colors cannot be read: the connection space is neither CIEXYZ nor CIELAB (a spectral iccMAX profile), or an iccMAX color has no value at full tint or stores its colorimetry as integers.

Returns an enumerator that iterates through the collection.

public IEnumerator<IccNamedColor> GetEnumerator()

Returns

IEnumerator<IccNamedColor> An enumerator that can be used to iterate through the collection.

Gets the index of the first color with a name (ordinal, case-sensitive comparison).

public int IndexOf(string name)

Parameters

name string
The full name of the color.

Returns

int The index, or -1 when no color has this name.

Exceptions

ArgumentNullException
name is null.

System.Collections.IEnumerable.GetEnumerator()

IccNamedColorCollection.cs
IEnumerator IEnumerable.GetEnumerator()

No documentation is available.

TryGetValue(string, IccNamedColor?)

IccNamedColorCollection.cs

Gets the color with a name (ordinal, case-sensitive comparison).

public bool TryGetValue(string name, out IccNamedColor? color)

Parameters

name string
The full name of the color.
color IccNamedColor?
The first color with this name, or null.

Returns

bool true when a color has this name.

Exceptions

ArgumentNullException
name is null.