我一直在为这个问题苦苦挣扎很多天,找不到任何解释!
背景:
我正在使用 VC9+MFC 在 Windows 上创建一个色彩管理的照片编辑应用程序,并使用WCS(Windows 颜色系统)API 将像素从照片嵌入的颜色配置文件转换为显示器的配置文件。
我的显示器已使用“Windows 显示校准”进行校准,并创建了一个名为“CalibratedDisplayProfile-x.icc”的配置文件。
问题:
当我将像素从“ProPhoto RGB”转换为显示器的配置文件时,黑暗区域的颜色发生变化,色调变为绿色。如果目标配置文件是 sRGB,则在中间调/高光中不会发生这种情况。这是屏幕截图。
测试:
为了简化问题,我写了一些测试代码来翻译一个单一的颜色,但测试结果真的让我很困惑。源颜色 "c0" 是RGB(0,0,65535),但输出颜色 "c1" 是RGB(0,0,0)!!并且功能“CheckColor”失败并出现错误“Invalid Arguments”......
这怎么可能发生?难道我做错了什么?
您可以在此处下载这两个配置文件:颜色配置文件
非常感谢!
CString strProfilePath = _T("C:\\Windows\\System32\\spool\\drivers\\color\\");
CString strSrcProfile = strProfilePath + _T("ProPhoto.icm");
CString strDstProfile = strProfilePath + _T("CalibratedDisplayProfile-2.icc");
PROFILE pf = {0};
pf.dwType = PROFILE_FILENAME;
pf.pProfileData = (PVOID)strSrcProfile.GetBuffer();
pf.cbDataSize = (strSrcProfile.GetLength() + 1) * sizeof(TCHAR);
HPROFILE hSrcProfile = ::OpenColorProfile( &pf, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
pf.pProfileData = (PVOID)strDstProfile.GetBuffer();
pf.cbDataSize = (strDstProfile.GetLength() + 1) * sizeof(TCHAR);
HPROFILE hDstProfile = ::OpenColorProfile( &pf, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
HPROFILE hProfiles[2];
hProfiles[0] = hSrcProfile;
hProfiles[1] = hDstProfile;
DWORD dwIndents[2] = { INTENT_RELATIVE_COLORIMETRIC, INTENT_RELATIVE_COLORIMETRIC };
HTRANSFORM hTransform = ::CreateMultiProfileTransform( hProfiles, 2, dwIndents, 2, BEST_MODE, INDEX_DONT_CARE );
COLOR c0, c1;
c0.rgb.red = 0;
c0.rgb.green = 0;
c0.rgb.blue = 0xffff;
::TranslateColors( hTransform, &c0, 1, COLOR_RGB, &c1, COLOR_RGB );
BYTE btResult = 0;
::CheckColors( hTransform, &c0, 1, COLOR_RGB, &btResult );
::DeleteColorTransform( hTransform );
::CloseColorProfile( hSrcProfile );
::CloseColorProfile( hDstProfile );