2

私はこの問題に何日も苦労してきましたが、説明が見つかりません!

バックグラウンド:

VC9 + MFCを使用してWindowsでカラー管理された写真編集アプリを作成し、WCS(Windowsカラーシステム)APIを使用して、写真に埋め込まれたカラープロファイルからモニターのプロファイルにピクセルを変換しています。

私のモニターは「Windows Display Calibration」で調整され、「CalibratedDisplayProfile-x.icc」という名前のプロファイルが作成されました。

問題:

「ProPhoto RGB」からモニターのプロファイルにピクセルを変換すると、暗い領域の色がシフトし、色合いが緑色になります。ターゲット プロファイルが sRGB の場合、これはミッドトーン/ハイライトでは発生しません。ここにスクリーンショットがあります。

正解とエラーの画像

テスト:

問題を単純化するために、単一の色を変換するためのテスト コードをいくつか書きましたが、テスト結果は本当に混乱を招きます。ソースカラー "c0" はRGB(0,0,65535)ですが、出力カラー "c1" はRGB(0,0,0)です!! 関数「CheckColor」は「引数が無効です」というエラーで失敗します...

これはどのように起こりますか?私は何か間違ったことをしていますか?

ここから 2 つのプロファイルをダウンロードできます:カラー プロファイル

どうもありがとう!

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

1 に答える 1

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

お役に立てれば。

于 2016-03-31T11:07:36.937 に答える