VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.ColorManagement Namespace / ColorTransformsOptimizer Class
Members Object Syntax Example Hierarchy Requirements SeeAlso
In This Topic
ColorTransformsOptimizer Class
In This Topic
Contains static methods for creating optimized versions of color transforms.
Object Model
ColorTransformsOptimizer
Syntax
'Declaration

Public MustInherit NotInheritable Class ColorTransformsOptimizer

public static class ColorTransformsOptimizer

Example

Here is an example that shows how to get composite color transform from source and destination ICC profiles and optimize it.


''' <summary>
''' Creates a composite color transform from specified source and destination RGB profiles
''' and returns optimized thread-unsafe color transform.
''' </summary>
Public Shared Function GetOptimizedRgbTransform(sourceRgbProfileFilename As String, destRgbProfileFilename As String) As Vintasoft.Imaging.ColorManagement.ColorTransform
    ' create ICC profiles
    Using sourceIccProfile As New Vintasoft.Imaging.ColorManagement.Icc.IccProfile(sourceRgbProfileFilename)
        Using destIccProfile As New Vintasoft.Imaging.ColorManagement.Icc.IccProfile(destRgbProfileFilename)
            ' check device color space of the source profile
            If sourceIccProfile.DeviceColorSpace <> Vintasoft.Imaging.ColorSpaceType.sRGB Then
                Throw New System.ArgumentException("Source profile is not RGB profile.")
            End If
            ' check device color space of the destination profile
            If destIccProfile.DeviceColorSpace <> Vintasoft.Imaging.ColorSpaceType.sRGB Then
                Throw New System.ArgumentException("Destination profile is not RGB profile.")
            End If

            ' get transforms from device color space to PCS
            Dim deviceToPcsTransform As Vintasoft.Imaging.ColorManagement.ColorTransform = sourceIccProfile.GetDeviceToPcsTransform()
            ' get transforms from PCS to device color space
            Dim pcsToDeviceTransform As Vintasoft.Imaging.ColorManagement.ColorTransform = destIccProfile.GetPcsToDeviceTransform()
            ' composite color transform
            Dim composition As Vintasoft.Imaging.ColorManagement.ColorTransform
            If sourceIccProfile.PcsColorSpace = destIccProfile.PcsColorSpace Then
                ' create simple composite color transform
                composition = Vintasoft.Imaging.ColorManagement.SimpleCompositeColorTransform.Create(deviceToPcsTransform, pcsToDeviceTransform)
            Else
                If sourceIccProfile.PcsColorSpace = Vintasoft.Imaging.ColorSpaceType.PCSXYZ Then
                    ' create simple composite color transform with intermediate PCSXYZ->PCSLab conversion
                    composition = Vintasoft.Imaging.ColorManagement.SimpleCompositeColorTransform.Create(deviceToPcsTransform, Vintasoft.Imaging.ColorManagement.ColorTransforms.PcsXyzToPcsLabD50, pcsToDeviceTransform)
                Else
                    ' create simple composite color transform with intermediate PCSLab->PCSXYZ conversion
                    composition = Vintasoft.Imaging.ColorManagement.SimpleCompositeColorTransform.Create(deviceToPcsTransform, Vintasoft.Imaging.ColorManagement.ColorTransforms.PcsLabToPcsXyzD50, pcsToDeviceTransform)
                End If
            End If
            ' return optimized color transform
            Return Vintasoft.Imaging.ColorManagement.ColorTransformsOptimizer.GetOptimizedTransform(composition, False)
        End Using
    End Using
End Function


/// <summary>
/// Creates a composite color transform from specified source and destination RGB profiles
/// and returns optimized thread-unsafe color transform.
/// </summary>
public static Vintasoft.Imaging.ColorManagement.ColorTransform GetOptimizedRgbTransform(
    string sourceRgbProfileFilename, string destRgbProfileFilename)
{
    // create ICC profiles
    using (Vintasoft.Imaging.ColorManagement.Icc.IccProfile sourceIccProfile =
        new Vintasoft.Imaging.ColorManagement.Icc.IccProfile(sourceRgbProfileFilename))
    using (Vintasoft.Imaging.ColorManagement.Icc.IccProfile destIccProfile =
        new Vintasoft.Imaging.ColorManagement.Icc.IccProfile(destRgbProfileFilename))
    {
        // check device color space of the source profile
        if (sourceIccProfile.DeviceColorSpace != Vintasoft.Imaging.ColorSpaceType.sRGB)
        {
            throw new System.ArgumentException("Source profile is not RGB profile.");
        }
        // check device color space of the destination profile
        if (destIccProfile.DeviceColorSpace != Vintasoft.Imaging.ColorSpaceType.sRGB)
        {
            throw new System.ArgumentException("Destination profile is not RGB profile.");
        }

        // get transforms from device color space to PCS
        Vintasoft.Imaging.ColorManagement.ColorTransform deviceToPcsTransform = sourceIccProfile.GetDeviceToPcsTransform();
        // get transforms from PCS to device color space
        Vintasoft.Imaging.ColorManagement.ColorTransform pcsToDeviceTransform = destIccProfile.GetPcsToDeviceTransform();
        // composite color transform
        Vintasoft.Imaging.ColorManagement.ColorTransform composition;
        if (sourceIccProfile.PcsColorSpace == destIccProfile.PcsColorSpace)
        {
            // create simple composite color transform
            composition = Vintasoft.Imaging.ColorManagement.SimpleCompositeColorTransform.Create(
                deviceToPcsTransform,
                pcsToDeviceTransform);
        }
        else
        {
            if (sourceIccProfile.PcsColorSpace == Vintasoft.Imaging.ColorSpaceType.PCSXYZ)
            {
                // create simple composite color transform with intermediate PCSXYZ->PCSLab conversion
                composition = Vintasoft.Imaging.ColorManagement.SimpleCompositeColorTransform.Create(
                    deviceToPcsTransform,
                    Vintasoft.Imaging.ColorManagement.ColorTransforms.PcsXyzToPcsLabD50,
                    pcsToDeviceTransform);
            }
            else
            {
                // create simple composite color transform with intermediate PCSLab->PCSXYZ conversion
                composition = Vintasoft.Imaging.ColorManagement.SimpleCompositeColorTransform.Create(
                    deviceToPcsTransform,
                    Vintasoft.Imaging.ColorManagement.ColorTransforms.PcsLabToPcsXyzD50,
                    pcsToDeviceTransform);
            }
        }
        // return optimized color transform
        return Vintasoft.Imaging.ColorManagement.ColorTransformsOptimizer.GetOptimizedTransform(composition, false);
    }
}

Inheritance Hierarchy

System.Object
   Vintasoft.Imaging.ColorManagement.ColorTransformsOptimizer

Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also