Rev 23210 | Rev 23653 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
15127 | jghali | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | |||
8 | #include <iostream> |
||
9 | #include <string> |
||
15143 | fschmid | 10 | #include <cstdlib> |
15127 | jghali | 11 | #include <QDir> |
12 | #include <QFile> |
||
13 | |||
14 | #include "sclcms2colormgmtengineimpl.h" |
||
15 | #include "sclcms2colorprofileimpl.h" |
||
16 | #include "sclcms2colortransformimpl.h" |
||
17 | |||
18 | #ifndef cmsFLAGS_PRESERVEBLACK |
||
19 | #define cmsFLAGS_PRESERVEBLACK 0x8000 |
||
20 | #endif |
||
21 | |||
22 | QSharedPointer<ScColorProfileCache> ScLcms2ColorMgmtEngineImpl::m_profileCache; |
||
23 | QSharedPointer<ScColorTransformPool> ScLcms2ColorMgmtEngineImpl::m_transformPool; |
||
24 | |||
25 | ScLcms2ColorMgmtEngineImpl::ScLcms2ColorMgmtEngineImpl() |
||
26 | : ScColorMgmtEngineData("Littlecms v2", 1) |
||
27 | { |
||
28 | if (!m_profileCache) |
||
29 | m_profileCache = QSharedPointer<ScColorProfileCache>(new ScColorProfileCache()); |
||
30 | if (!m_transformPool) |
||
31 | m_transformPool = QSharedPointer<ScColorTransformPool>(new ScColorTransformPool(0)); |
||
32 | cmsUInt16Number alarmCodes[cmsMAXCHANNELS] = { 0 }; |
||
33 | alarmCodes[1] = 0xFFFF; |
||
34 | cmsSetAlarmCodes(alarmCodes); |
||
35 | cmsSetLogErrorHandler(&cmsErrorHandler); |
||
36 | } |
||
37 | |||
38 | void ScLcms2ColorMgmtEngineImpl::setStrategy(const ScColorMgmtStrategy& strategy) |
||
39 | { |
||
40 | m_strategy = strategy; |
||
41 | } |
||
42 | |||
43 | QList<ScColorProfileInfo> ScLcms2ColorMgmtEngineImpl::getAvailableProfileInfo(const QString& directory, bool recursive) |
||
44 | { |
||
45 | QList<ScColorProfileInfo> profileInfos; |
||
46 | |||
47 | QDir d(directory, "*", QDir::Name, QDir::Files | QDir::Readable | QDir::Dirs | QDir::NoSymLinks); |
||
48 | if ((!d.exists()) || (d.count() == 0)) |
||
49 | return profileInfos; |
||
50 | |||
22518 | craig | 51 | cmsHPROFILE hIn = nullptr; |
15127 | jghali | 52 | |
53 | for (uint dc = 0; dc < d.count(); ++dc) |
||
54 | { |
||
55 | QString file = d[dc]; |
||
56 | if (file == "." || file == "..") |
||
57 | continue; |
||
58 | QFileInfo fi(directory + "/" + file); |
||
59 | if (fi.isDir() && !recursive) |
||
60 | continue; |
||
22599 | craig | 61 | if (fi.isDir() && !file.startsWith('.')) |
15127 | jghali | 62 | { |
63 | QList<ScColorProfileInfo> profileInfos2 = getAvailableProfileInfo(fi.filePath()+"/", true); |
||
64 | profileInfos.append(profileInfos2); |
||
65 | continue; |
||
66 | } |
||
67 | |||
68 | ScColorProfileInfo profileInfo; |
||
69 | profileInfo.file = fi.filePath(); |
||
70 | |||
71 | QFile f(fi.filePath()); |
||
72 | QByteArray bb(40, ' '); |
||
73 | if (!f.open(QIODevice::ReadOnly)) { |
||
74 | profileInfo.debug = QString("couldn't open %1 as color profile").arg(fi.filePath()); |
||
75 | profileInfos.append(profileInfo); |
||
76 | continue; |
||
77 | } |
||
78 | int len = f.read(bb.data(), 40); |
||
79 | f.close(); |
||
80 | if (len == 40 && bb[36] == 'a' && bb[37] == 'c' && bb[38] == 's' && bb[39] == 'p') |
||
81 | { |
||
82 | const QByteArray profilePath( QString(directory + "/" + file).toLocal8Bit() ); |
||
83 | hIn = cmsOpenProfileFromFile(profilePath.data(), "r"); |
||
22518 | craig | 84 | if (hIn == nullptr) |
15127 | jghali | 85 | continue; |
15143 | fschmid | 86 | #ifdef _WIN32 |
22518 | craig | 87 | cmsUInt32Number descSize = cmsGetProfileInfo(hIn, cmsInfoDescription, "en", "US", nullptr, 0); |
15127 | jghali | 88 | if (descSize > 0) |
89 | { |
||
90 | wchar_t* descData = (wchar_t*) malloc(descSize + sizeof(wchar_t)); |
||
91 | descSize = cmsGetProfileInfo(hIn, cmsInfoDescription, "en", "US", descData, descSize); |
||
92 | if (descSize > 0) |
||
93 | { |
||
15135 | jghali | 94 | uint stringLen = descSize / sizeof(wchar_t); |
95 | descData[stringLen] = 0; |
||
15127 | jghali | 96 | if (sizeof(wchar_t) == sizeof(QChar)) { |
15135 | jghali | 97 | profileInfo.description = QString::fromUtf16((ushort *) descData); |
15127 | jghali | 98 | } else { |
15135 | jghali | 99 | profileInfo.description = QString::fromUcs4((uint *) descData); |
15127 | jghali | 100 | } |
101 | free(descData); |
||
102 | } |
||
103 | } |
||
15143 | fschmid | 104 | #else |
22518 | craig | 105 | cmsUInt32Number descSize = cmsGetProfileInfoASCII(hIn, cmsInfoDescription, "en", "US", nullptr, 0); |
15143 | fschmid | 106 | if (descSize > 0) |
107 | { |
||
108 | char* descData = (char*) malloc(descSize + sizeof(char)); |
||
109 | descSize = cmsGetProfileInfoASCII(hIn, cmsInfoDescription, "en", "US", descData, descSize); |
||
110 | if (descSize > 0) |
||
111 | { |
||
112 | profileInfo.description = QString(descData); |
||
113 | free(descData); |
||
114 | } |
||
115 | } |
||
116 | #endif |
||
15127 | jghali | 117 | if (profileInfo.description.isEmpty()) |
118 | { |
||
119 | cmsCloseProfile(hIn); |
||
120 | profileInfo.debug = QString("Color profile %1 is broken : no valid description").arg(fi.filePath()); |
||
121 | profileInfos.append(profileInfo); |
||
122 | continue; |
||
123 | } |
||
124 | profileInfo.colorSpace = translateLcmsColorSpaceType( cmsGetColorSpace(hIn) ); |
||
125 | profileInfo.deviceClass = translateLcmsProfileClass( cmsGetDeviceClass(hIn) ); |
||
126 | profileInfos.append(profileInfo); |
||
127 | cmsCloseProfile(hIn); |
||
22518 | craig | 128 | hIn = nullptr; |
15127 | jghali | 129 | } |
130 | } |
||
131 | |||
132 | return profileInfos; |
||
133 | } |
||
134 | |||
135 | ScColorProfile ScLcms2ColorMgmtEngineImpl::openProfileFromFile(ScColorMgmtEngine& engine, const QString& filePath) |
||
136 | { |
||
137 | // Search profile in profile cache first |
||
138 | ScColorProfile profile = m_profileCache->profile(filePath); |
||
139 | if (!profile.isNull()) |
||
140 | return profile; |
||
22518 | craig | 141 | cmsHPROFILE lcmsProf = nullptr; |
15127 | jghali | 142 | QFile file(filePath); |
143 | if (file.open(QFile::ReadOnly)) |
||
144 | { |
||
145 | // We do not use lcms cmsOpenProfileFromFile() to avoid limitations |
||
146 | // of I/O on 8bit filenames on Windows |
||
147 | QByteArray data = file.readAll(); |
||
148 | if (!data.isEmpty()) |
||
149 | { |
||
150 | lcmsProf = cmsOpenProfileFromMem(data.data(), data.size()); |
||
151 | if (lcmsProf) |
||
152 | { |
||
153 | ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf); |
||
154 | profData->m_profileData = data; |
||
155 | profData->m_profilePath = filePath; |
||
156 | profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData)); |
||
157 | m_profileCache->addProfile(profile); |
||
158 | } |
||
159 | if (profile.isNull() && lcmsProf) |
||
160 | { |
||
161 | cmsCloseProfile(lcmsProf); |
||
22518 | craig | 162 | lcmsProf = nullptr; |
15127 | jghali | 163 | } |
164 | } |
||
165 | file.close(); |
||
166 | } |
||
167 | return profile; |
||
168 | } |
||
169 | |||
170 | ScColorProfile ScLcms2ColorMgmtEngineImpl::openProfileFromMem(ScColorMgmtEngine& engine, const QByteArray& data) |
||
171 | { |
||
172 | ScColorProfile profile; |
||
173 | cmsHPROFILE lcmsProf = cmsOpenProfileFromMem((const void *) data.data(), data.size()); |
||
174 | if (lcmsProf) |
||
175 | { |
||
176 | ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf); |
||
177 | QString desc = profData->productDescription(); |
||
178 | if (!desc.isEmpty()) |
||
179 | profData->m_profilePath = QString("memprofile://%1").arg(desc); |
||
180 | profData->m_profileData = data; |
||
181 | profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData)); |
||
182 | } |
||
183 | if (profile.isNull() && lcmsProf) |
||
184 | { |
||
185 | cmsCloseProfile(lcmsProf); |
||
22518 | craig | 186 | lcmsProf = nullptr; |
15127 | jghali | 187 | } |
188 | return profile; |
||
189 | } |
||
190 | |||
191 | ScColorProfile ScLcms2ColorMgmtEngineImpl::createProfile_sRGB(ScColorMgmtEngine& engine) |
||
192 | { |
||
193 | QString internalProfilePath("memprofile://Internal sRGB profile"); |
||
194 | ScColorProfile profile = m_profileCache->profile(internalProfilePath); |
||
195 | if (!profile.isNull()) |
||
196 | return profile; |
||
197 | |||
198 | cmsHPROFILE lcmsProf = cmsCreate_sRGBProfile(); |
||
199 | if (lcmsProf) |
||
200 | { |
||
201 | ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf); |
||
202 | profData->m_profilePath = internalProfilePath; |
||
203 | profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData)); |
||
204 | m_profileCache->addProfile(profile); |
||
205 | } |
||
206 | if (profile.isNull() && lcmsProf) |
||
207 | { |
||
208 | cmsCloseProfile(lcmsProf); |
||
22518 | craig | 209 | lcmsProf = nullptr; |
15127 | jghali | 210 | } |
211 | return profile; |
||
212 | } |
||
213 | |||
214 | ScColorProfile ScLcms2ColorMgmtEngineImpl::createProfile_Lab(ScColorMgmtEngine& engine) |
||
215 | { |
||
216 | QString internalProfilePath("memprofile://Internal Lab profile"); |
||
217 | ScColorProfile profile = m_profileCache->profile(internalProfilePath); |
||
218 | if (!profile.isNull()) |
||
219 | return profile; |
||
220 | |||
22518 | craig | 221 | cmsHPROFILE lcmsProf = cmsCreateLab4Profile(nullptr); |
15127 | jghali | 222 | if (lcmsProf) |
223 | { |
||
224 | ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf); |
||
225 | profData->m_profilePath = internalProfilePath; |
||
226 | profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData)); |
||
227 | m_profileCache->addProfile(profile); |
||
228 | } |
||
229 | if (profile.isNull() && lcmsProf) |
||
230 | { |
||
231 | cmsCloseProfile(lcmsProf); |
||
22518 | craig | 232 | lcmsProf = nullptr; |
15127 | jghali | 233 | } |
234 | return profile; |
||
235 | } |
||
236 | |||
237 | ScColorTransform ScLcms2ColorMgmtEngineImpl::createTransform(ScColorMgmtEngine& engine, |
||
238 | const ScColorProfile& inputProfile , eColorFormat inputFormat, |
||
239 | const ScColorProfile& outputProfile, eColorFormat outputFormat, |
||
240 | eRenderIntent renderIntent, long transformFlags) |
||
241 | { |
||
22518 | craig | 242 | ScColorTransform transform(nullptr); |
15127 | jghali | 243 | if (inputProfile.isNull() || outputProfile.isNull()) |
244 | return transform; |
||
245 | int inputProfEngineID = inputProfile.engine().engineID(); |
||
246 | int outputProfEngineID = outputProfile.engine().engineID(); |
||
247 | if ((engine.engineID() != m_engineID) || (inputProfEngineID != m_engineID) || (outputProfEngineID != m_engineID)) |
||
248 | return transform; |
||
249 | const ScLcms2ColorProfileImpl* lcmsInputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(inputProfile.data()); |
||
250 | const ScLcms2ColorProfileImpl* lcmsOutputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(outputProfile.data()); |
||
251 | if (!lcmsInputProf || !lcmsOutputProf) |
||
252 | return transform; |
||
253 | |||
254 | transformFlags &= (~Ctf_Softproofing); |
||
255 | transformFlags &= (~Ctf_GamutCheck); |
||
256 | long strategyFlags = 0; |
||
23272 | craig | 257 | if (m_strategy.useBlackPointCompensation()) |
15127 | jghali | 258 | strategyFlags |= Ctf_BlackPointCompensation; |
23272 | craig | 259 | if (m_strategy.useBlackPreservation()) |
15127 | jghali | 260 | strategyFlags |= Ctf_BlackPreservation; |
261 | |||
262 | ScColorTransformInfo transInfo; |
||
263 | transInfo.inputProfile = inputProfile.productDescription(); |
||
264 | transInfo.outputProfile = outputProfile.productDescription(); |
||
20388 | craig | 265 | transInfo.proofingProfile.clear(); |
15127 | jghali | 266 | transInfo.inputFormat = inputFormat; |
267 | transInfo.outputFormat = outputFormat; |
||
268 | transInfo.renderIntent = renderIntent; |
||
269 | transInfo.proofingIntent = (eRenderIntent) 0; |
||
270 | transInfo.flags = transformFlags | strategyFlags; |
||
271 | |||
272 | bool nullTransform = false; |
||
273 | if (transInfo.inputProfile == transInfo.outputProfile) |
||
274 | { |
||
275 | // This is a null transform |
||
20388 | craig | 276 | transInfo.inputProfile.clear(); |
277 | transInfo.outputProfile.clear(); |
||
278 | transInfo.proofingProfile.clear(); |
||
23210 | craig | 279 | transInfo.renderIntent = Intent_Perceptual; |
280 | transInfo.proofingIntent = Intent_Perceptual; |
||
15127 | jghali | 281 | transInfo.flags = 0; |
282 | nullTransform = true; |
||
283 | } |
||
284 | |||
285 | transform = m_transformPool->findTransform(transInfo); |
||
286 | if (transform.isNull()) |
||
287 | { |
||
288 | cmsUInt32Number lcmsFlags = translateFlagsToLcmsFlags(transformFlags | strategyFlags); |
||
289 | cmsUInt32Number lcmsInputFmt = translateFormatToLcmsFormat(inputFormat); |
||
290 | cmsUInt32Number lcmsOutputFmt = translateFormatToLcmsFormat(outputFormat); |
||
291 | int lcmsIntent = translateIntentToLcmsIntent(renderIntent); |
||
292 | if (nullTransform) |
||
293 | lcmsFlags |= cmsFLAGS_NULLTRANSFORM; |
||
22518 | craig | 294 | cmsHTRANSFORM hTransform = nullptr; |
15127 | jghali | 295 | hTransform = cmsCreateTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, |
296 | lcmsOutputProf->m_profileHandle, lcmsOutputFmt, |
||
297 | lcmsIntent, lcmsFlags | cmsFLAGS_LOWRESPRECALC); |
||
298 | if (hTransform) |
||
299 | { |
||
300 | ScLcms2ColorTransformImpl* newTrans = new ScLcms2ColorTransformImpl(engine, hTransform); |
||
301 | newTrans->setTransformInfo(transInfo); |
||
302 | transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans)); |
||
303 | m_transformPool->addTransform(transform, true); |
||
304 | } |
||
305 | } |
||
306 | return transform; |
||
307 | } |
||
308 | |||
309 | ScColorTransform ScLcms2ColorMgmtEngineImpl::createProofingTransform(ScColorMgmtEngine& engine, |
||
310 | const ScColorProfile& inputProfile , eColorFormat inputFormat, |
||
311 | const ScColorProfile& outputProfile, eColorFormat outputFormat, |
||
312 | const ScColorProfile& proofProfile , eRenderIntent renderIntent, |
||
313 | eRenderIntent proofingIntent, long transformFlags) |
||
314 | { |
||
22518 | craig | 315 | ScColorTransform transform(nullptr); |
15127 | jghali | 316 | if (inputProfile.isNull() || outputProfile.isNull()) |
317 | return transform; |
||
318 | int inputProfEngineID = inputProfile.engine().engineID(); |
||
319 | int outputProfEngineID = outputProfile.engine().engineID(); |
||
320 | int proofProfEngineID = proofProfile.engine().engineID(); |
||
321 | if ((engine.engineID() != m_engineID) || (inputProfEngineID != m_engineID) || |
||
322 | (outputProfEngineID != m_engineID) || (proofProfEngineID != m_engineID)) |
||
323 | return transform; |
||
324 | const ScLcms2ColorProfileImpl* lcmsInputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(inputProfile.data()); |
||
325 | const ScLcms2ColorProfileImpl* lcmsOutputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(outputProfile.data()); |
||
326 | const ScLcms2ColorProfileImpl* lcmsProofingProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(proofProfile.data()); |
||
327 | if (!lcmsInputProf || !lcmsOutputProf || !lcmsProofingProf) |
||
328 | return transform; |
||
329 | |||
330 | long strategyFlags = 0; |
||
23272 | craig | 331 | if (m_strategy.useBlackPointCompensation()) |
15127 | jghali | 332 | strategyFlags |= Ctf_BlackPointCompensation; |
23272 | craig | 333 | if (m_strategy.useBlackPreservation()) |
15127 | jghali | 334 | strategyFlags |= Ctf_BlackPreservation; |
335 | |||
336 | ScColorTransformInfo transInfo; |
||
337 | transInfo.inputProfile = inputProfile.productDescription(); |
||
338 | transInfo.outputProfile = outputProfile.productDescription(); |
||
339 | transInfo.proofingProfile = proofProfile.productDescription(); |
||
340 | transInfo.inputFormat = inputFormat; |
||
341 | transInfo.outputFormat = outputFormat; |
||
342 | transInfo.renderIntent = renderIntent; |
||
343 | transInfo.proofingIntent = proofingIntent; |
||
344 | transInfo.flags = transformFlags | strategyFlags; |
||
345 | |||
346 | cmsUInt32Number lcmsFlags = translateFlagsToLcmsFlags(transformFlags | strategyFlags); |
||
347 | cmsUInt32Number lcmsInputFmt = translateFormatToLcmsFormat(inputFormat); |
||
348 | cmsUInt32Number lcmsOutputFmt = translateFormatToLcmsFormat(outputFormat); |
||
349 | int lcmsIntent = translateIntentToLcmsIntent(renderIntent); |
||
350 | int lcmsPrfIntent = translateIntentToLcmsIntent(proofingIntent); |
||
351 | |||
352 | if (transInfo.inputProfile != transInfo.proofingProfile) |
||
353 | { |
||
354 | if (transInfo.proofingProfile == transInfo.outputProfile) |
||
355 | { |
||
356 | transInfo.proofingIntent = Intent_Relative_Colorimetric; |
||
357 | lcmsPrfIntent = translateIntentToLcmsIntent(Intent_Relative_Colorimetric); |
||
358 | } |
||
359 | transform = m_transformPool->findTransform(transInfo); |
||
360 | if (transform.isNull()) |
||
361 | { |
||
22518 | craig | 362 | cmsHTRANSFORM hTransform = nullptr; |
15127 | jghali | 363 | hTransform = cmsCreateProofingTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, |
364 | lcmsOutputProf->m_profileHandle, lcmsOutputFmt, |
||
365 | lcmsProofingProf->m_profileHandle, lcmsIntent, |
||
366 | lcmsPrfIntent, lcmsFlags | cmsFLAGS_SOFTPROOFING); |
||
367 | if (hTransform) |
||
368 | { |
||
369 | ScLcms2ColorTransformImpl* newTrans = new ScLcms2ColorTransformImpl(engine, hTransform); |
||
370 | newTrans->setTransformInfo(transInfo); |
||
371 | transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans)); |
||
372 | m_transformPool->addTransform(transform, true); |
||
373 | } |
||
374 | } |
||
375 | } |
||
376 | else |
||
377 | { |
||
378 | transformFlags &= (~Ctf_Softproofing); |
||
379 | transformFlags &= (~Ctf_GamutCheck); |
||
380 | lcmsFlags = translateFlagsToLcmsFlags(transformFlags | strategyFlags); |
||
381 | transInfo.flags = transformFlags | strategyFlags; |
||
382 | transInfo.renderIntent = proofingIntent; |
||
383 | transInfo.proofingIntent = (eRenderIntent) 0; |
||
384 | if (transInfo.inputProfile == transInfo.outputProfile) |
||
385 | { |
||
386 | lcmsFlags |= cmsFLAGS_NULLTRANSFORM; |
||
20388 | craig | 387 | transInfo.inputProfile.clear(); |
388 | transInfo.outputProfile.clear(); |
||
389 | transInfo.proofingProfile.clear(); |
||
15127 | jghali | 390 | transInfo.renderIntent = (eRenderIntent) 0; |
391 | transInfo.proofingIntent = (eRenderIntent) 0; |
||
392 | transInfo.flags = 0; |
||
393 | } |
||
394 | transform = m_transformPool->findTransform(transInfo); |
||
395 | if (transform.isNull()) |
||
396 | { |
||
22518 | craig | 397 | cmsHTRANSFORM hTransform = nullptr; |
15127 | jghali | 398 | hTransform = cmsCreateTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, |
399 | lcmsOutputProf->m_profileHandle, lcmsOutputFmt, |
||
400 | lcmsPrfIntent, lcmsFlags | cmsFLAGS_LOWRESPRECALC); |
||
401 | if (hTransform) |
||
402 | { |
||
403 | ScLcms2ColorTransformImpl* newTrans = new ScLcms2ColorTransformImpl(engine, hTransform); |
||
404 | newTrans->setTransformInfo(transInfo); |
||
405 | transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans)); |
||
406 | m_transformPool->addTransform(transform, true); |
||
407 | } |
||
408 | } |
||
409 | } |
||
410 | return transform; |
||
411 | } |
||
412 | |||
413 | cmsUInt32Number ScLcms2ColorMgmtEngineImpl::translateFlagsToLcmsFlags(long flags) |
||
414 | { |
||
415 | cmsUInt32Number lFlags = 0; |
||
416 | if (flags & Ctf_BlackPointCompensation) |
||
417 | lFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION; |
||
418 | if (flags & Ctf_BlackPreservation) |
||
419 | lFlags |= cmsFLAGS_PRESERVEBLACK; |
||
420 | if (flags & Ctf_Softproofing) |
||
421 | lFlags |= cmsFLAGS_SOFTPROOFING; |
||
422 | if (flags & Ctf_GamutCheck) |
||
423 | lFlags |= cmsFLAGS_GAMUTCHECK; |
||
424 | return lFlags; |
||
425 | } |
||
426 | |||
427 | cmsUInt32Number ScLcms2ColorMgmtEngineImpl::translateFormatToLcmsFormat(eColorFormat format) |
||
428 | { |
||
429 | cmsUInt32Number lFormat = 0; |
||
430 | if (format == Format_RGB_8) |
||
431 | lFormat = TYPE_RGB_8; |
||
432 | if (format == Format_RGB_16) |
||
433 | lFormat = TYPE_RGB_16; |
||
434 | if (format == Format_RGBA_8) |
||
435 | lFormat = TYPE_RGBA_8; |
||
436 | if (format == Format_RGBA_16) |
||
437 | lFormat = TYPE_RGBA_16; |
||
438 | if (format == Format_ARGB_8) |
||
439 | lFormat = TYPE_ARGB_8; |
||
440 | if (format == Format_ARGB_16) |
||
441 | lFormat = TYPE_ARGB_16; |
||
442 | if (format == Format_BGRA_8) |
||
443 | lFormat = TYPE_BGRA_8; |
||
444 | if (format == Format_BGRA_16) |
||
445 | lFormat = TYPE_BGRA_16; |
||
446 | if (format == Format_CMYK_8) |
||
447 | lFormat = TYPE_CMYK_8; |
||
448 | if (format == Format_CMYK_16) |
||
449 | lFormat = TYPE_CMYK_16; |
||
450 | if (format == Format_CMYKA_8) |
||
451 | lFormat = (COLORSPACE_SH(PT_CMYK)|EXTRA_SH(1)|CHANNELS_SH(4)|BYTES_SH(1)); |
||
452 | if (format == Format_CMYKA_16) |
||
453 | lFormat = (COLORSPACE_SH(PT_CMYK)|EXTRA_SH(1)|CHANNELS_SH(4)|BYTES_SH(2)); |
||
454 | if (format == Format_YMCK_8) |
||
455 | lFormat = (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1)); |
||
456 | if (format == Format_YMCK_16) |
||
457 | lFormat = (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1)|SWAPFIRST_SH(1)); |
||
458 | if (format == Format_GRAY_8) |
||
459 | lFormat = TYPE_GRAY_8; |
||
460 | if (format == Format_GRAY_16) |
||
461 | lFormat = TYPE_GRAY_16; |
||
462 | if (format == Format_LabA_8) |
||
463 | lFormat = COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1); |
||
20145 | fschmid | 464 | if (format == Format_Lab_Dbl) |
465 | lFormat = TYPE_Lab_DBL; |
||
15127 | jghali | 466 | return lFormat; |
467 | } |
||
468 | |||
469 | int ScLcms2ColorMgmtEngineImpl::translateIntentToLcmsIntent(eRenderIntent intent, eRenderIntent defIntent) |
||
470 | { |
||
471 | int lIntent = defIntent; |
||
472 | if (intent == Intent_Perceptual) |
||
473 | lIntent = INTENT_PERCEPTUAL; |
||
474 | if (intent == Intent_Relative_Colorimetric) |
||
475 | lIntent = INTENT_RELATIVE_COLORIMETRIC; |
||
476 | if (intent == Intent_Saturation) |
||
477 | lIntent = INTENT_SATURATION; |
||
478 | if (intent == Intent_Absolute_Colorimetric) |
||
479 | lIntent = INTENT_ABSOLUTE_COLORIMETRIC; |
||
480 | return lIntent; |
||
481 | } |
||
482 | |||
483 | eColorSpaceType ScLcms2ColorMgmtEngineImpl::translateLcmsColorSpaceType(cmsColorSpaceSignature signature) |
||
484 | { |
||
485 | eColorSpaceType colorSpaceType = ColorSpace_Unknown; |
||
486 | if (signature == cmsSigXYZData) |
||
487 | colorSpaceType = ColorSpace_XYZ; |
||
488 | if (signature == cmsSigLabData) |
||
489 | colorSpaceType = ColorSpace_Lab; |
||
490 | if (signature == cmsSigLuvData) |
||
491 | colorSpaceType = ColorSpace_Luv; |
||
492 | if (signature == cmsSigYCbCrData) |
||
493 | colorSpaceType = ColorSpace_YCbCr; |
||
494 | if (signature == cmsSigYxyData) |
||
495 | colorSpaceType = ColorSpace_Yxy; |
||
496 | if (signature == cmsSigRgbData) |
||
497 | colorSpaceType = ColorSpace_Rgb; |
||
498 | if (signature == cmsSigGrayData) |
||
499 | colorSpaceType = ColorSpace_Gray; |
||
500 | if (signature == cmsSigHsvData) |
||
501 | colorSpaceType = ColorSpace_Hsv; |
||
502 | if (signature == cmsSigHlsData) |
||
503 | colorSpaceType = ColorSpace_Hls; |
||
504 | if (signature == cmsSigCmykData) |
||
505 | colorSpaceType = ColorSpace_Cmyk; |
||
506 | if (signature == cmsSigCmyData) |
||
507 | colorSpaceType = ColorSpace_Cmy; |
||
508 | return colorSpaceType; |
||
509 | } |
||
510 | |||
511 | eProfileClass ScLcms2ColorMgmtEngineImpl::translateLcmsProfileClass(cmsProfileClassSignature signature) |
||
512 | { |
||
513 | eProfileClass profileClass = Class_Unknown; |
||
514 | if (signature == cmsSigInputClass) |
||
515 | profileClass = Class_Input; |
||
516 | if (signature == cmsSigDisplayClass) |
||
517 | profileClass = Class_Display; |
||
518 | if (signature == cmsSigOutputClass) |
||
519 | profileClass = Class_Output; |
||
520 | if (signature == cmsSigLinkClass) |
||
521 | profileClass = Class_Link; |
||
522 | if (signature == cmsSigAbstractClass) |
||
523 | profileClass = Class_Abstract; |
||
524 | if (signature == cmsSigColorSpaceClass) |
||
525 | profileClass = Class_ColorSpace; |
||
526 | if (signature == cmsSigNamedColorClass) |
||
527 | profileClass = Class_NamedColor; |
||
528 | return profileClass; |
||
529 | } |
||
530 | |||
531 | void ScLcms2ColorMgmtEngineImpl::cmsErrorHandler(cmsContext contextID, cmsUInt32Number /*ErrorCode*/, |
||
532 | const char *ErrorText) |
||
533 | { |
||
534 | std::string msg = std::string("Littlecms : ") + ErrorText; |
||
535 | std::cerr << ErrorText << std::endl; |
||
536 | } |