32 #include <ApplicationServices/ApplicationServices.h>
33 #include <CoreFoundation/CoreFoundation.h>
34 #include "wx/osx/core/cfstring.h"
35 #include <wx/osx/private.h>
50 HDC hdc = GetDC(NULL);
53 wxChar filename[MAX_PATH];
54 DWORD len = MAX_PATH - 1;
55 if (GetICMProfile(hdc, &len, filename))
57 profileName = filename;
58 profile = cmsOpenProfileFromFile(profileName.c_str(),
"r");
63 #elif defined __WXGTK__
64 cmsHPROFILE GetProfileFromAtom(Display* disp,
const char* prop_name)
66 Atom atom = XInternAtom(disp, prop_name, True);
69 int actual_format_return;
70 unsigned long nitems_return = 0;
71 unsigned long bytes_after_return = 0;
72 unsigned char* prop_return = 0;
74 Window w = XDefaultRootWindow(disp);
77 XGetWindowProperty(disp, w, atom, 0, INT_MAX, False,
79 &a, &actual_format_return, &nitems_return,
80 &bytes_after_return, &prop_return);
81 if (nitems_return && prop_return)
83 cmsHPROFILE profile = cmsOpenProfileFromMem(prop_return, nitems_return);
99 Display *disp = XOpenDisplay(0);
107 profile = GetProfileFromAtom(disp,
"_ICC_PROFILE");
116 #elif defined __WXMAC__
121 } ColorsyncIteratorData;
123 static bool ColorSyncIterateCallback(CFDictionaryRef dict,
void *
data)
125 ColorsyncIteratorData *iterData = (ColorsyncIteratorData *)data;
130 if (!CFDictionaryGetValueIfPresent(dict, kColorSyncDeviceClass, (
const void**)&str))
135 if (!CFEqual(str, kColorSyncDisplayDeviceClass))
139 if (!CFDictionaryGetValueIfPresent(dict, kColorSyncDeviceID, (
const void**)&uuid))
144 if (!CFEqual(uuid, iterData->dispuuid))
148 if (!CFDictionaryGetValueIfPresent(dict, kColorSyncDeviceProfileIsCurrent, (
const void**)&iscur))
150 DEBUG_INFO(
"kColorSyncDeviceProfileIsCurrent failed");
153 if (!CFBooleanGetValue(iscur))
157 if (!CFDictionaryGetValueIfPresent(dict, kColorSyncDeviceProfileURL, (
const void**)&(iterData->url)))
159 DEBUG_INFO(
"Could not get current profile URL");
162 CFRetain(iterData->url);
168 ColorsyncIteratorData
data;
169 data.dispuuid = CGDisplayCreateUUIDFromDisplayID(CGMainDisplayID());
170 if (data.dispuuid == NULL)
172 DEBUG_INFO(
"CGDisplayCreateUUIDFromDisplayID() failed.");
176 ColorSyncIterateDeviceProfiles(ColorSyncIterateCallback, (
void *)&data);
177 CFRelease(data.dispuuid);
179 CFStringRef urlstr = CFURLCopyFileSystemPath(data.url, kCFURLPOSIXPathStyle);
188 profileName = wxCFStringRef(urlstr).AsString(wxLocale::GetSystemEncoding());
189 profile = cmsOpenProfileFromFile(profileName.c_str(),
"r");
190 DEBUG_INFO(
"Found profile: " << profileName.c_str());
205 cmsCloseProfile(profile);
213 profile = cmsCreate_sRGBProfile();
218 void CorrectImage(wxImage& image,
const vigra::ImageImportInfo::ICCProfile& iccProfile,
const cmsHPROFILE& monitorProfile)
220 cmsHPROFILE inputICC = NULL;
221 if (!iccProfile.empty())
223 inputICC = cmsOpenProfileFromMem(iccProfile.data(), iccProfile.size());
226 if (inputICC != NULL)
228 if (cmsGetColorSpace(inputICC) != cmsSigRgbData)
230 cmsCloseProfile(inputICC);
235 if (inputICC == NULL)
237 inputICC = cmsCreate_sRGBProfile();
240 cmsHTRANSFORM transform = cmsCreateTransform(inputICC, TYPE_RGB_8,
241 monitorProfile, TYPE_RGB_8,
242 INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_BLACKPOINTCOMPENSATION);
244 if (transform != NULL)
246 unsigned char* imgData = image.GetData();
247 const int imgWidth = image.GetWidth();
248 const int imgHeight = image.GetHeight();
249 #pragma omp parallel for
250 for (
int y = 0; y < imgHeight; ++y)
252 cmsDoTransform(transform, imgData + 3 * y * imgWidth, imgData + 3 * y * imgWidth, imgWidth);
254 cmsDeleteTransform(transform);
256 cmsCloseProfile(inputICC);
std::string GetICCDesc(const vigra::ImageImportInfo::ICCProfile &iccProfile)
returns description of given icc profile
void GetMonitorProfile(wxString &profileName, cmsHPROFILE &profile)
void CorrectImage(wxImage &image, const vigra::ImageImportInfo::ICCProfile &iccProfile, const cmsHPROFILE &monitorProfile)
apply color correction to given image using input iccProfile and monitor profile
options wxIntPtr wxIntPtr sortData std::vector< PanoInfo > * data
void GetMonitorProfile(wxString &profileName, cmsHPROFILE &profile)
retrieve monitor profile from system