ImageEn

Color Management System


ImageEn includes a Color Management System (CMS) which enables the rendering of images with their original colors.


To render the CMS for an image use:
ImageEnView1.IEBitmap.ColorProfileMode := iecpRender;
To apply the CMS colors to the image use:
ImageEnView1.IEBitmap.ColorProfileMode := iecpApply;
When the CMS is enabled loading/display of images with a color profile will be slower.

To use LCMS instead of Windows CMS, set the following define within ie.inc and then recompile your packages:
{$define IEIncludeCMS}
When undefined, only the Windows CMS is used. Note that Windows CMS is quicker than LCMS.

Understanding ICC Profiles

There are three main ImageEn ICC Profiles:

 InputICCProfile: The Color Profile of the Image

This is the profile contained in the image file (that was provided by the image source, e.g. a digital camera or scanner). It is filled when loading the image. ColorProfileMode specifies how it is used:
ColorProfileMode Effect
iecpApply Profile is applied to the image while loading (i.e the image is modified). To determine if an input profile has been applied, use: ImageEnView.IO.Params.InputICCProfile.IsApplied
iecpRender Profile is copied to ColorProfile and used to render the image (without modifying the image)
iecpIgnore Profile is stored but not used

If InputICCProfile has not been applied (i.e. ColorProfileMode is iecpRender or iecpIgnore), it is saved to the image when saving to a compatible format (JPEG, TIFF or PSD).

 DefaultICCProfile: The Fallback Color Profile

If an image does not contain a color profile (i.e. InputICCProfile), then this property allows you to specify an alternative profile to apply (ColorProfileMode = iecpApply) or render (ColorProfileMode = iecpRender) to the image.

 OutputICCProfile: The Output Color Profile

Defines the color profile for our usage of the image (e.g. a monitor or printer). This property defaults to sRGB, which is suitable for display, printing and saving.

Note:

TIEBitmap.ColorProfile is a copy of InputICCProfile that is used for rendering (i.e. when ColorProfileMode = iecpRender)
ICC profiles can be read from JPEG (RGB and CMYK), TIFF, PNG and PSD files (for PNG, only rendering is supported). They are written to JPEG, TIFF and PSD files
For the output profile (OutputICCProfile) ImageEn defaults to an embedded sRGB profile (suitable for display, printing and saving)

Demo

Demo  Demos\Display\ColorProfiles\ColorProfiles.dpr

Examples

// Apply color profile on rendering (image is not modified, it only renders with the color profile)
ImageEnView1.IEBitmap.ColorProfileMode := iecpRender;
ImageEnView1.IO.NativePixelFormat := True;  // This means "Do not convert to RGB"
ImageEnView1.IO.LoadFromFile('cmyk-jpeg.jpg');


// Apply color profile to the image (image colors are changed, i.e. image is modified)
ImageEnView1.IEBitmap.ColorProfileMode := iecpApply;
ImageEnView1.IO.NativePixelFormat := False; // This means "Convert to RGB"
ImageEnView1.IO.LoadFromFile('cmyk-jpeg.jpg');


// Do not apply color profile (image is not modified, and is rendered without the color profile)
ImageEnView1.IEBitmap.ColorProfileMode := iecpIgnore;
ImageEnView1.IO.NativePixelFormat := False; // This means "Convert to RGB"
ImageEnView1.IO.LoadFromFile('cmyk-jpeg.jpg');


// Load a color profile to apply to the image if one is not available
ImageEnView1.IO.Params.DefaultICCProfile.LoadFromFile('C:\Windows\System32\spool\drivers\color\AdobeRGB1998.icc');
ImageEnView1.IEBitmap.ColorProfileMode := iecpApply;
ImageEnView1.IO.LoadFromFile('C:\input.tif');


// Load a TIFF containing a CMYK profile, save to JPEG maintaining the profile
ImageEnView1.IEBitmap.ColorProfileMode := iecpIgnore;   // or iecpRender
ImageEnView.IO.LoadFromFile('D:\Img with ICC Profile.tif');
ImageEnView1.IO.Params.JPEG_ColorSpace := ioJPEG_CMYK;
ImageEnView1.IO.SaveToFile('D:\Img with ICC Profile.jpeg');


// Render image with a custom color profile
ImageEnView1.IEBitmap.ColorProfile.LoadFromFile( 'D:\ColorProfile.icc' );
ImageEnView1.IEBitmap.ColorProfileMode := iecpRender;
ImageEnView1.Update();


// Save a JPEG with the ICC profile, sRGB2014.icc
ImageEnView1.IO.LoadFromFile( 'D:\201849018_A1.jpg' );
ImageEnView1.IO.Params.InputICCProfile.LoadFromFile('D:\sRGB2014.icc');
ImageEnView1.IO.SaveToFile( 'D:\Test_SRGB.jpg' );


// Apply InputICCProfile (VibranceMetallic_8400.icc) color profile to an image and output as OutputICCProfile (Defaults to sRGB)
// Note: This permanently changes the colors of the image
ImageEnView1.IO.LoadFromFile('C:\Wedding.jpg');
ImageEnView1.IO.Params.InputICCProfile.LoadFromFile('C:\VibranceMetallic_8400.icc');
ImageEnView1.IO.Params.InputICCProfile.ConvertBitmap( ImageEnView1.IEBitmap );
ImageEnView1.Update();  // Show changes to bitmap in viewer

  


// Load the color profile of the current monitor
icc := TIEICC.Create();
icc.LoadFromFile( IEGlobalSettings().CurrentMonitorProfile );
// Do something with icc
icc.Free();


// Display the description of the ICC profile in the image
if ierICC in ImageEnView1.IO.Params.ContainsInfo() then
  ShowMessage( 'ICC Profile: ' + ImageEnView1.IO.Params.InputICCProfile.Description )
else
  ShowMessage( 'ICC Profile: None' );


// If the image has a valid color profile (for rendering) then display its information
if ImageEnView1.IEBitmap.ColorProfile.IsValid then
begin
  lblICCDescription     .Caption := 'Description:' + string( ImageEnView1.IEBitmap.ColorProfile.Description );
  lblICCCopyright       .Caption := 'Copyright:' + string( ImageEnView1.IEBitmap.ColorProfile.Copyright );
  lblICCInputColorSpace .Caption := 'Input Color Space:' + string( ImageEnView1.IEBitmap.ColorProfile.InputColorSpace );
  lblICCOutputColorSpace.Caption := 'Output Color Space:' + string( ImageEnView1.IEBitmap.ColorProfile.OutputColorSpace );
end;


// Save the color profile that is embedded in the image
if ierICC in ImageEnView1.IO.Params.ContainsInfo() then
  ImageEnView1.IO.Params.InputICCProfile.SaveToFile( ChangeFileExt( Filename, '.icc' ))
else
  ShowMessage( 'Image has no color profile' );

See Also

TIEICC
InputICCProfile
DefaultICCProfile
OutputICCProfile
ColorProfile
ColorProfileMode
CurrentMonitorProfile
ConvertColorFunction

Compatibility Information

Prior to v15.1.0, Color profile support in ImageEn was handled by IEGlobalSettings().EnableCMS and IEGlobalSettings().ApplyColorProfileOnRendering. These properties should no longer be used.

IEGlobalSettings().EnableCMS (which defaulted to False) is still included for compatibility. Enabling EnableCMS will force ColorProfileMode := iecpApply. Rather than setting EnableCMS, you should use ImageEnView1.IEBitmap.ColorProfileMode := iecpApply; (before loading your image).
IEGlobalSettings().ApplyColorProfileOnRendering (which defaulted to True) has been removed. Rather than enabling ApplyColorProfileOnRendering, you should use ImageEnView1.IEBitmap.ColorProfileMode := iecpRender; or ImageEnView1.IEBitmap.ColorProfileMode := iecpIgnore;

Code that was:
IEGlobalSettings().EnableCMS := False;
IEGlobalSettings().ApplyColorProfileOnRendering := True;

Should now be:
ImageEnView1.IEBitmap.ColorProfileMode := iecpRender;

Code that was:
IEGlobalSettings().EnableCMS := True;
IEGlobalSettings().ApplyColorProfileOnRendering := False;  // or True

Should now be:
ImageEnView1.IEBitmap.ColorProfileMode := iecpApply;

Code that was:
IEGlobalSettings().EnableCMS := False;
IEGlobalSettings().ApplyColorProfileOnRendering := False;

Should now be:
ImageEnView1.IEBitmap.ColorProfileMode := iecpIgnore;