gpt4 book ai didi

c++ - 从 ProPhoto RGB 到显示器配置文件的颜色转换

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:54:13 25 4
gpt4 key购买 nike

我已经为这个问题苦苦挣扎了很多天,找不到任何解释!

背景:

我正在使用 VC9+MFC 在 Windows 上创建一个颜色管理照片编辑应用程序,并使用WCS(Windows 颜色系统)API 从照片嵌入的颜色转换像素配置文件到监视器的配置文件。

我的显示器已使用“Windows 显示校准”进行校准,并创建了一个名为“CalibratedDisplayProfile-x.icc”的配置文件。

问题:

当我将像素从“ProPhoto RGB”转换为显示器的配置文件时,黑暗区域的颜色发生变化,色调变为绿色。如果目标配置文件是 sRGB,则中间调/高光不会发生这种情况。这是屏幕截图。

correct & error images

测试:

为了简化问题,我写了一些翻译单一颜色的测试代码,但测试结果确实让我很困惑。源颜色“c0”是RGB(0,0,65535),但输出颜色“c1”是RGB(0,0,0)!!函数“CheckColor”失败并出现错误“无效参数”...

怎么会这样?我做错了什么吗?

您可以在此处下载两个配置文件:Color Profiles

非常感谢!

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 );

最佳答案

我在 Windows 7 SP1 x64 上遇到了与您完全相同的问题。似乎TranslateColors功能要么被设计破坏,要么不应该以这种方式使用。我认为这是微软的错,因为他们可以在 MSDN 上编写更多 WCS 示例。

但我设法使用 TranslateBitmapBits 解决了问题代替功能。这是一个示例:

bool translateColors(BYTE* srcRgbColors, BYTE* dstRgbColors, DWORD nBytes)
{
BOOL bResult = FALSE;

HPROFILE hSrcProfile = nullptr;
HPROFILE hDstProfile = nullptr;
HTRANSFORM hColorTransform = nullptr;

/* open source sRGB profile */
wchar_t* srcProfilePath = L"sRGB Color Space Profile.icm";

tagPROFILE targetProfile;
targetProfile.dwType = PROFILE_FILENAME;
targetProfile.pProfileData = srcProfilePath;
targetProfile.cbDataSize = sizeof(wchar_t) * (wcslen(srcProfilePath) + 1);

hSrcProfile = OpenColorProfile(&targetProfile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING);
if (nullptr == hSrcProfile) goto EXIT;

/* open destination monitor profile */
wchar_t* dstProfilePath = L"ActiveMonitorProfile.icm";

tagPROFILE destinationProfile;
destinationProfile.dwType = PROFILE_FILENAME;
destinationProfile.pProfileData = dstProfilePath;
destinationProfile.cbDataSize = sizeof(wchar_t) * (wcslen(dstProfilePath) + 1);

hDstProfile = OpenColorProfile(&destinationProfile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING);
if (nullptr == hDstProfile) goto EXIT;

/* create color transform */

DWORD dwIntent = (DWORD)-1;
HPROFILE hProfileList[2] = { hSrcProfile, hDstProfile };

hColorTransform = CreateMultiProfileTransform(
hProfileList,
2,
&dwIntent,
1,
NORMAL_MODE,
INDEX_DONT_CARE
);

if (nullptr == hColorTransform) goto EXIT;

/* transform colors */
DWORD dwWidth = nBytes / 3; // 3 channels per pixel, 8 bits per channel, RGB format

bResult = TranslateBitmapBits(
hColorTransform,
srcRgbColors,
BM_RGBTRIPLETS,
dwWidth, // bitmap width
1, // bitmap height
0,
dstRgbColors,
BM_RGBTRIPLETS,
0,
nullptr,
0
);

EXIT:
/* free resources */
if (nullptr != hColorTransform) {
DeleteColorTransform(hColorTransform);
}

if (nullptr != hSrcProfile) {
CloseColorProfile(hSrcProfile);
}

if (nullptr != hDstProfile) {
CloseColorProfile(hDstProfile);
}

return bResult == FALSE ? false : true;
}

/* example usage */
BYTE srcBitmapData[3];
srcBitmapData[0] = 0x1c;
srcBitmapData[1] = 0x1a;
srcBitmapData[2] = 0x1a;

BYTE dstOutputBitmapData[3];
bool bResult = traslateColors(srcBitmapData, dstOutputBitmapData, 3);

希望这对您有所帮助。

关于c++ - 从 ProPhoto RGB 到显示器配置文件的颜色转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22626380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com