To reproduce:
Load a cmyk tiff, containing a color profile, using the default options. Save it as another file. Open the new file in PS or FreeImage - the origin profile is still there, though the image is now rgb (converted when loading). PS (and any color management lib) reports an error.
The problem is Metadata contains color profile as well, even if we don't have data in a FIICCPROFILE.
To solve this:
In TIFF Load (notice, metadata is read now befor setting the icc):
// copy TIFF metadata (must be done after FreeImage_Allocate) ReadMetadata(tif, dib); // copy ICC profile data (must be done after FreeImage_Allocate) FreeImage_CreateICCProfile(dib, iccBuf, iccSize); if (photometric == PHOTOMETRIC_SEPARATED ) { if(asCMYK) FreeImage_GetICCProfile(dib)->flags |= FIICC_COLOR_IS_CMYK; else FreeImage_SetMetadata(FIMD_EXIF_MAIN, dib, "InterColorProfile", NULL); }
In JPEG, in section else if((cinfo.out_color_space == JCS_CMYK) && ((flags & JPEG_CMYK) == JPEG_CMYK))
add FreeImage_SetMetadata(FIMD_EXIF_MAIN, dib, "InterColorProfile", NULL);
About the PSD, I am not sure, it should be fixed as well.
Lastly, FreeImage_DestroyICCProfile (in BtimapAccess.cpp) must also have FreeImage_SetMetadata(FIMD_EXIF_MAIN, dib, "InterColorProfile", NULL);
Anonymous
Ok TIFF should be
ReadMetadata (tiff_read_exif_profile(tiff, dib) specifically) messes the icc profile data, so it should be after profile creation!
Hi Mihail,
I've fixed the TIFF plugin and also the FreeImage_DestroyICCProfile function.
However I'm not sure about the JPEG plugin fix. Can you attach the modified JPEG plugin ?
Hervé
My code is based on an very old CVS version, here is the section with more context:
The section is where we convert CMYK to RGB. In that case the profile will be incorrect. In my original post the section I mention is wrong.
OK, JPEG plugin fixed in the CVS
Fixed in release 3.18.0