IccNamedColorTransform Class

The conversion of the colors of an ICC named color profile to the device values of another profile, through a sequence of profiles. Instances are immutable and thread-safe: create a transform once and reuse it.

public sealed class IccNamedColorTransform

Remarks

The first profile of the sequence is the named color profile; its colors enter the sequence in the profile connection space, from their media-relative colorimetry (IccNamedColor.ConnectionSpaceColor). The other profiles follow the rules of IccColorTransform.Create: abstract profiles in the connection space, then a device profile that converts the colors to its device values, optionally followed by device link profiles or by other pairs of device profiles.

The rendering intent selects the conversion of the destination profiles; with IccRenderingIntent.AbsoluteColorimetric, the colors are first rescaled from the media white point of the named color profile. Named colors are measured colors, not the range of a device: IccColorTransformOptions.BlackPointCompensation does not apply to them, as in LittleCMS.

To print a named color on the device the named color profile was made for, use its IccNamedColor.DeviceValues, when the profile gives them, instead of converting its colorimetry.

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);
}

Properties

NameDescription
ColorsGets the colors of the named color profile.
DestinationChannelCountGets the number of samples per converted color: 1 (grayscale), 3 (RGB) or 4 (CMYK).

Gets the colors of the named color profile.

public IccNamedColorCollection Colors { get; }

DestinationChannelCount

IccNamedColorTransform.cs

Gets the number of samples per converted color: 1 (grayscale), 3 (RGB) or 4 (CMYK).

public int DestinationChannelCount { get; }

Property value

int

Methods

NameDescription
Convert(IccNamedColor, Span<byte>)Converts a named color to 8-bit samples.
Convert(IccNamedColor, Span<float>)Converts a named color to floating-point samples, in [0, 1] unless the transform does not clip them.
Convert(IccNamedColor, Span<ushort>)Converts a named color to 16-bit samples.
Create(IccProfile, IccProfile, IccColorTransformOptions?)Creates the conversion of the colors of a named color profile to the device values of a profile.
Create(IReadOnlyList<IccProfile>, IccColorTransformOptions?)Creates the conversion of the colors of a named color profile through a sequence of profiles: the named color profile first, then the profiles in the order the colors go through them.

Convert overloads

Convert(IccNamedColor, Span<byte>)

IccNamedColorTransform.cs

Converts a named color to 8-bit samples.

public void Convert(IccNamedColor color, Span<byte> destination)
Parameters
color IccNamedColor
The color, usually one of IccNamedColorTransform.Colors.
destination Span<byte>
The converted samples: exactly IccNamedColorTransform.DestinationChannelCount samples.
Exceptions
ArgumentNullException
color is null.
ArgumentException
The length of destination is not IccNamedColorTransform.DestinationChannelCount.

Convert(IccNamedColor, Span<float>)

IccNamedColorTransform.cs

Converts a named color to floating-point samples, in [0, 1] unless the transform does not clip them.

public void Convert(IccNamedColor color, Span<float> destination)
Parameters
color IccNamedColor
The color, usually one of IccNamedColorTransform.Colors.
destination Span<float>
The converted samples: exactly IccNamedColorTransform.DestinationChannelCount samples.
Exceptions
ArgumentNullException
color is null.
ArgumentException
The length of destination is not IccNamedColorTransform.DestinationChannelCount.

Convert(IccNamedColor, Span<ushort>)

IccNamedColorTransform.cs

Converts a named color to 16-bit samples.

public void Convert(IccNamedColor color, Span<ushort> destination)
Parameters
color IccNamedColor
The color, usually one of IccNamedColorTransform.Colors.
destination Span<ushort>
The converted samples: exactly IccNamedColorTransform.DestinationChannelCount samples.
Exceptions
ArgumentNullException
color is null.
ArgumentException
The length of destination is not IccNamedColorTransform.DestinationChannelCount.

Create overloads

Create(IccProfile, IccProfile, IccColorTransformOptions?)

IccNamedColorTransform.cs

Creates the conversion of the colors of a named color profile to the device values of a profile.

public static IccNamedColorTransform Create(IccProfile namedColorProfile, IccProfile destination, IccColorTransformOptions? options = null)
Parameters
namedColorProfile IccProfile
The named color profile.
destination IccProfile
The profile describing the converted samples.
options IccColorTransformOptions?
The options, or null for IccColorTransformOptions.Default.
Returns

IccNamedColorTransform The transform.

Exceptions
ArgumentNullException
namedColorProfile or destination is null.
ArgumentException
namedColorProfile is not a named color profile.
InvalidImageContentException
A profile is malformed.
UnsupportedImageFeatureException
A profile is valid but not supported, or cannot be used as a destination.

Create(IReadOnlyList<IccProfile>, IccColorTransformOptions?)

IccNamedColorTransform.cs

Creates the conversion of the colors of a named color profile through a sequence of profiles: the named color profile first, then the profiles in the order the colors go through them.

public static IccNamedColorTransform Create(IReadOnlyList<IccProfile> profiles, IccColorTransformOptions? options = null)
Parameters
profiles IReadOnlyList<IccProfile>
The named color profile, then at least one profile; the last one describes the converted samples.
options IccColorTransformOptions?
The options, or null for IccColorTransformOptions.Default.
Returns

IccNamedColorTransform The transform.

Exceptions
ArgumentNullException
profiles or one of its profiles is null.
ArgumentException
profiles has fewer than two profiles, or its first profile is not a named color profile.
InvalidImageContentException
A profile is malformed.
UnsupportedImageFeatureException
A profile is valid but not supported, or the sequence does not connect; or IccColorTransformOptions.ClipFloatingPointSamples is false and the conversion goes through a lookup table or a gamut mapping.