Hugin trunk 0.1
Loading...
Searching...
No Matches
wxcms.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2
10/* This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This software is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this software. If not, see
22 * <http://www.gnu.org/licenses/>.
23 *
24 */
25
26#include "wxcms.h"
27#include "hugin_utils/utils.h"
28#include "hugin_config.h"
29#if defined __WXGTK__ && defined HAVE_X11
30#include <X11/Xlib.h>
31#endif
32#ifdef __WXMAC__
33#include <ApplicationServices/ApplicationServices.h>
34#include <CoreFoundation/CoreFoundation.h>
35#include "wx/osx/core/cfstring.h"
36#include <wx/osx/private.h>
37#endif
38
39namespace HuginBase
40{
41 namespace Color
42 {
43 namespace detail
44 {
45#ifdef __WXMSW__
46 // retrieve monitor profile from Windows
47 // TODO: support for multi-monitor setups
49 {
50 // look up monitor profile in system
51 HDC hdc = GetDC(NULL);
52 if (hdc)
53 {
54 wxChar filename[MAX_PATH];
55 DWORD len = MAX_PATH - 1;
56 if (GetICMProfile(hdc, &len, filename))
57 {
58 profileName = filename;
60 };
62 };
63 };
64#elif defined __WXGTK__ && defined HAVE_X11
66 {
68 if (atom)
69 {
71 unsigned long nitems_return = 0;
72 unsigned long bytes_after_return = 0;
73 unsigned char* prop_return = 0;
74 Atom a;
76 if (w)
77 {
83 {
86 if (profile != NULL)
87 {
88 return profile;
89 };
90 };
91 };
92 };
93 return NULL;
94 }
95
96 // retrieve monitor profile from X system
97 // TODO: support for multi-monitor setups
99 {
101 if (disp)
102 {
103 // when using libXcm we should also use
104 // profile = GetProfileFromAtom(disp, "_ICC_DEVICE_PROFILE");
105 // profile = GetProfileFromAtom(disp, XCM_ICC_COLOUR_SERVER_TARGET_PROFILE_IN_X_BASE)
106 // but in this case we need to update the code to take X11/Xcm/Xcm.h XcolorRegion
107 // into account
108 profile = GetProfileFromAtom(disp, "_ICC_PROFILE");
109 if (profile != NULL)
110 {
112 }
113 XSync(disp, False);
115 };
116 };
117#elif defined __WXMAC__
118 // retrieve monitor profile for Mac
119 typedef struct {
123
124 static bool ColorSyncIterateCallback(CFDictionaryRef dict, void *data)
125 {
130
132 {
133 DEBUG_INFO("kColorSyncDeviceClass failed");
134 return true;
135 }
137 {
138 return true;
139 }
141 {
142 DEBUG_INFO("kColorSyncDeviceID failed");
143 return true;
144 }
145 if (!CFEqual(uuid, iterData->dispuuid))
146 {
147 return true;
148 }
150 {
151 DEBUG_INFO("kColorSyncDeviceProfileIsCurrent failed");
152 return true;
153 }
155 {
156 return true;
157 }
159 {
160 DEBUG_INFO("Could not get current profile URL");
161 return true;
162 }
163 CFRetain(iterData->url);
164 return false;
165 }
166
168 {
171 if (data.dispuuid == NULL)
172 {
173 DEBUG_INFO("CGDisplayCreateUUIDFromDisplayID() failed.");
174 return;
175 }
176 data.url = NULL;
178 CFRelease(data.dispuuid);
179
181 CFRelease(data.url);
182 if (urlstr == NULL)
183 {
184 DEBUG_INFO("Failed to get URL in CFString");
185 }
186 else
187 {
189 profileName = wxCFStringRef(urlstr).AsString();
191 DEBUG_INFO("Found profile: " << profileName.c_str());
192 };
193 };
194#else
195 // general case, does nothing
199#endif
200 }
201
203 {
204 if (profile != NULL)
205 {
207 }
208 profileName.Clear();
209 profile = NULL;
211 // check if monitor profile could be successful loaded, if not switch back to default sRGB profile
212 if (profile == NULL)
213 {
215 profileName.Clear();
216 };
217 };
218
219 void CorrectImage(wxImage& image, const vigra::ImageImportInfo::ICCProfile& iccProfile, const cmsHPROFILE& monitorProfile)
220 {
222 if (!iccProfile.empty())
223 {
224 inputICC = cmsOpenProfileFromMem(iccProfile.data(), iccProfile.size());
225 };
226 // check type of input profile
227 if (inputICC != NULL)
228 {
230 {
232 inputICC = NULL;
233 };
234 };
235 // if there is no icc profile in file fall back to sRGB
236 if (inputICC == NULL)
237 {
239 };
240 // now build transform
244 // check that we could get a valid transform
245 if (transform != NULL)
246 {
247 unsigned char* imgData = image.GetData();
248 const int imgWidth = image.GetWidth();
249 const int imgHeight = image.GetHeight();
250#pragma omp parallel for
251 for (int y = 0; y < imgHeight; ++y)
252 {
253 cmsDoTransform(transform, imgData + 3 * y * imgWidth, imgData + 3 * y * imgWidth, imgWidth);
254 };
255 cmsDeleteTransform(transform);
256 };
258 };
259
260 }; // namespace Color
261}; // namespace HuginBase
#define DEBUG_INFO(msg)
Definition utils.h:69
void GetMonitorProfile(wxString &profileName, cmsHPROFILE &profile)
Definition wxcms.cpp:196
void CorrectImage(wxImage &image, const vigra::ImageImportInfo::ICCProfile &iccProfile, const cmsHPROFILE &monitorProfile)
apply color correction to given image using input iccProfile and monitor profile
Definition wxcms.cpp:219
void GetMonitorProfile(wxString &profileName, cmsHPROFILE &profile)
retrieve monitor profile from system
Definition wxcms.cpp:202
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:40
std::string GetICCDesc(const vigra::ImageImportInfo::ICCProfile &iccProfile)
returns description of given icc profile
Definition utils.cpp:912
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41