"Apply" ICC profile to sRGB image in PNG format without embedding it
Posted: 2018-12-10T13:17:24-07:00
Input:
- PNG image with sRGB color space, no ICC profile embedded
- ICC profile file
Expected output:
- PNG image with sRGB color space, no ICC profile embedded but image colors should be "translated" with input ICC profile
- the output has to be in PNG format, no quality loss is acceptable (i.e. JPG)
In other words I want IM temporarily act as an image viewer, and "flatten" image with ICC profile to sRGB
So far I was only able to embed ICC profile (Delphi code):
It is displayed incorrectly in IrfanView, while GIMP asks to do a conversion to sRGB since profile is still embedded:
I've tried calling MagickRemoveImageProfile after MagickProfileImage, but it simply removed ICC profile and output file is color exact to input.
Do I need to add sRGB profile first to image, and then do conversion ? If so, what MagickWand method has to be called ?
Any help appreciated, C, PHP - it doesn't matter I will understand your code. IM 7.0.8-Q16
- PNG image with sRGB color space, no ICC profile embedded
- ICC profile file
Expected output:
- PNG image with sRGB color space, no ICC profile embedded but image colors should be "translated" with input ICC profile
- the output has to be in PNG format, no quality loss is acceptable (i.e. JPG)
In other words I want IM temporarily act as an image viewer, and "flatten" image with ICC profile to sRGB
So far I was only able to embed ICC profile (Delphi code):
Code: Select all
function ApplyICCProfile(AInputFileName, AOutputFileName, AICCProfilePath: String): Boolean;
var
msProfile: TMemoryStream;
wand: PMagickWand;
begin
Result := False;
MagickWandGenesis;
try
wand := NewMagickWand;
try
if MagickReadImage(wand, PUTF8Char(UTF8Encode(AInputFileName))) = MagickTrue then
begin
msProfile := TMemoryStream.Create();
try
msProfile.LoadFromFile(AICCProfilePath);
MagickProfileImage(wand, 'ICC', msProfile.Memory, msProfile.Size);
Result := (MagickWriteImage(wand, PUTF8Char(UTF8Encode(AOutputFileName))) = MagickTrue);
finally
msProfile.Free;
end;
end;
finally
DestroyMagickWand(wand);
end;
finally
MagickWandTerminus;
end;
end;
I've tried calling MagickRemoveImageProfile after MagickProfileImage, but it simply removed ICC profile and output file is color exact to input.
Do I need to add sRGB profile first to image, and then do conversion ? If so, what MagickWand method has to be called ?
Any help appreciated, C, PHP - it doesn't matter I will understand your code. IM 7.0.8-Q16