CMYK To RGB With Color Management

Color Management Color Conversion

Converts a color specified in CMYK color space to RGB color space.

Сode Snippet

public static class ColorExtension
{
    public static T To<T>(
        this Color color,
        ColorProfile destinationProfile = null,
        ColorManagementEngine engine = ColorManagementEngine.LittleCms,
        ColorProfile targetDeviceProfile = null,
        ColorTransformationIntent transformationIntent = ColorTransformationIntent.Perceptual)
        where T : Color, new() => ColorExtension.ConvertColor<T>(color, destinationProfile, engine, targetDeviceProfile, transformationIntent);

    internal static T ConvertColor<T>(
        Color color,
        ColorProfile destinationProfile,
        ColorManagementEngine engine = ColorManagementEngine.LittleCms,
        ColorProfile targetDeviceProfile = null,
        ColorTransformationIntent transformationIntent = ColorTransformationIntent.Perceptual)
        where T : Color, new()
    {
        if (destinationProfile == null)
        {
            Type colorType = typeof(T);
            if (colorType != typeof(LabColor) && colorType != typeof(Lab16Color))
            {
                throw new ArgumentException("Destination profile should be specified for converting to non-absolute color space (LabColor or Lab16Color)", "destinationProfile");
            }
        }

        using (var cc = new Aurigma.GraphicsMill.Transforms.ColorConverter())
        {
            cc.DestinationProfile = destinationProfile;
            cc.TargetDeviceProfile = targetDeviceProfile;
            cc.ColorManagementEngine = engine;
            cc.TransformationIntent = transformationIntent;

            T tempColor = new T();

            cc.DestinationPixelFormat = tempColor.PixelFormat;

            return (T)cc.ConvertColor(color, color.Profile);
        }
    }

    internal static T ConvertColor<T>(
        Color color,
        string destinationProfile,
        ColorManagementEngine engine = ColorManagementEngine.LittleCms,
        ColorProfile targetDeviceProfile = null,
        ColorTransformationIntent transformationIntent = ColorTransformationIntent.Perceptual)
        where T : Color, new()
    {
        return ConvertColor<T>(color, new ColorProfile(destinationProfile), engine, targetDeviceProfile, transformationIntent);
    }
}

public class ConvertCmykToRgbWithColorManagement
{
    public static void Run()
    {
        CmykColor cmykColor = new CmykColor(20, 42, 211, 40)
        {
            Profile = new ColorProfile("ISOcoated_v2_eci.icc"),
        };

        RgbColor rgbColor = cmykColor.To<RgbColor>(ColorProfile.FromSrgb());

        Console.WriteLine("With color management: {0} to {1}", cmykColor, rgbColor);
    }
}

Input

ISOcoated_v2_eci.icc

Download

Output

ConvertCmykToRgbWithColorManagement.txt

With color management: CmykColor [C=20, M=42, Y=211, K=40, A=255] to RgbColor [R=208, G=180, B=62, A=255]

For AI-assisted development: Download Graphics Mill Code Samples XML Catalog