Skip to content

Instantly share code, notes, and snippets.

@kanryu
Last active September 15, 2017 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanryu/2eac2851fd1eb48f93af9f4f170eb83c to your computer and use it in GitHub Desktop.
Save kanryu/2eac2851fd1eb48f93af9f4f170eb83c to your computer and use it in GitHub Desktop.
Convert from CMYK to sRGB with ICC Profile(for Windows)
#include <Windows.h>
#include <Icm.h>
BOOL convertCMYKtoRGB(void *cmyk, void *rgb, DWORD w, DWORD h)
{
HPROFILE hProfiles[2] = { 0 };
PROFILE p = { 0 };
std::wstring woppath = L"RSWOP.icm";
p.dwType = PROFILE_FILENAME;
p.pProfileData = (PVOID)woppath.c_str();
p.cbDataSize = (woppath.size()+1)*sizeof(wchar_t);
if ((hProfiles[0] = OpenColorProfile(&p, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING)) == NULL)
return FALSE;
std::wstring sRGBpath = L"sRGB Color Space Profile.icm";
p.pProfileData = (PVOID)sRGBpath.c_str();
p.cbDataSize = (sRGBpath.size()+1)*sizeof(wchar_t);
if ((hProfiles[1] = OpenColorProfile(&p, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING)) == NULL)
{
CloseColorProfile(hProfiles[0]);
return FALSE;
}
HTRANSFORM hTransform;
DWORD intents[1] = { INTENT_PERCEPTUAL };
if ((hTransform = CreateMultiProfileTransform(hProfiles, 2, intents, 1, BEST_MODE, INDEX_DONT_CARE)) == NULL)
{
CloseColorProfile(hProfiles[0]);
CloseColorProfile(hProfiles[1]);
return FALSE;
}
BOOL result = ::TranslateBitmapBits(hTransform, cmyk, BM_KYMCQUADS, w, h, w * 4, rgb, BM_xRGBQUADS, w * 4, NULL, 0);
// or rgb, BM_BGRTRIPLETS, w * 3
DeleteColorTransform(hTransform);
CloseColorProfile(hProfiles[0]);
CloseColorProfile(hProfiles[1]);
return result;
}
@kanryu
Copy link
Author

kanryu commented Sep 15, 2017

this gist based on https://ja.pastebin.ca/3870898

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment