Last active
September 15, 2017 06:57
-
-
Save kanryu/2eac2851fd1eb48f93af9f4f170eb83c to your computer and use it in GitHub Desktop.
Convert from CMYK to sRGB with ICC Profile(for Windows)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this gist based on https://ja.pastebin.ca/3870898