2014-03-25 3 views
2

나는이 문제로 여러 날 어려움을 겪었으므로 설명을 찾을 수 없습니다!프로파일을 모니터하기 위해 ProPhoto RGB에서 색상 변환

배경 :

나는 색상 VC9 + MFC와 Windows에서 사진 편집 응용 프로그램을 관리 생성 및 사진 포함 된 색상 프로파일의 픽셀을 변환하는 WCS (윈도우 컬러 시스템) 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); 

답변

0

나는 Windows 7 SP1 x64에서 당신과 똑같은 문제가있었습니다. TranslateColors 기능이 디자인에 의해 손상되었거나 그런 식으로 사용되지 않는 것으로 보입니다. MSDN에 더 많은 WCS 샘플을 쓸 수 있기 때문에 Microsoft의 잘못이라고 생각합니다.

하지만 대신 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); 

희망이 있습니다.

+0

지금 LittleCMS를 사용하고 있습니다. 훨씬 나아 졌어. –

관련 문제