Rev 23778 | 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() |
||
23653 | craig | 26 | : ScColorMgmtEngineData("Littlecms v2", 1) |
15127 | jghali | 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)); |
||
23778 | jghali | 91 | if (descData) |
92 | descSize = cmsGetProfileInfo(hIn, cmsInfoDescription, "en", "US", descData, descSize); |
||
93 | if (descData && (descSize > 0)) |
||
15127 | jghali | 94 | { |
15135 | jghali | 95 | uint stringLen = descSize / sizeof(wchar_t); |
96 | descData[stringLen] = 0; |
||
23779 | jghali | 97 | profileInfo.description = QString::fromWCharArray(descData); |
15127 | jghali | 98 | } |
23778 | jghali | 99 | free(descData); |
15127 | jghali | 100 | } |
15143 | fschmid | 101 | #else |
22518 | craig | 102 | cmsUInt32Number descSize = cmsGetProfileInfoASCII(hIn, cmsInfoDescription, "en", "US", nullptr, 0); |
15143 | fschmid | 103 | if (descSize > 0) |
104 | { |
||
105 | char* descData = (char*) malloc(descSize + sizeof(char)); |
||
23778 | jghali | 106 | if (descData) |
107 | descSize = cmsGetProfileInfoASCII(hIn, cmsInfoDescription, "en", "US", descData, descSize); |
||
108 | if (descData && (descSize > 0)) |
||
15143 | fschmid | 109 | profileInfo.description = QString(descData); |
23778 | jghali | 110 | free(descData); |
15143 | fschmid | 111 | } |
112 | #endif |
||
15127 | jghali | 113 | if (profileInfo.description.isEmpty()) |
114 | { |
||
115 | cmsCloseProfile(hIn); |
||
116 | profileInfo.debug = QString("Color profile %1 is broken : no valid description").arg(fi.filePath()); |
||
117 | profileInfos.append(profileInfo); |
||
118 | continue; |
||
119 | } |
||
120 | profileInfo.colorSpace = translateLcmsColorSpaceType( cmsGetColorSpace(hIn) ); |
||
121 | profileInfo.deviceClass = translateLcmsProfileClass( cmsGetDeviceClass(hIn) ); |
||
122 | profileInfos.append(profileInfo); |
||
123 | cmsCloseProfile(hIn); |
||
22518 | craig | 124 | hIn = nullptr; |
15127 | jghali | 125 | } |
126 | } |
||
127 | |||
128 | return profileInfos; |
||
129 | } |
||
130 | |||
131 | ScColorProfile ScLcms2ColorMgmtEngineImpl::openProfileFromFile(ScColorMgmtEngine& engine, const QString& filePath) |
||
132 | { |
||
133 | // Search profile in profile cache first |
||
134 | ScColorProfile profile = m_profileCache->profile(filePath); |
||
135 | if (!profile.isNull()) |
||
136 | return profile; |
||
22518 | craig | 137 | cmsHPROFILE lcmsProf = nullptr; |
15127 | jghali | 138 | QFile file(filePath); |
139 | if (file.open(QFile::ReadOnly)) |
||
140 | { |
||
141 | // We do not use lcms cmsOpenProfileFromFile() to avoid limitations |
||
142 | // of I/O on 8bit filenames on Windows |
||
143 | QByteArray data = file.readAll(); |
||
144 | if (!data.isEmpty()) |
||
145 | { |
||
146 | lcmsProf = cmsOpenProfileFromMem(data.data(), data.size()); |
||
147 | if (lcmsProf) |
||
148 | { |
||
149 | ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf); |
||
150 | profData->m_profileData = data; |
||
151 | profData->m_profilePath = filePath; |
||
23665 | craig | 152 | profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData)); |
15127 | jghali | 153 | m_profileCache->addProfile(profile); |
154 | } |
||
155 | if (profile.isNull() && lcmsProf) |
||
156 | { |
||
157 | cmsCloseProfile(lcmsProf); |
||
22518 | craig | 158 | lcmsProf = nullptr; |
15127 | jghali | 159 | } |
160 | } |
||
161 | file.close(); |
||
162 | } |
||
163 | return profile; |
||
164 | } |
||
165 | |||
166 | ScColorProfile ScLcms2ColorMgmtEngineImpl::openProfileFromMem(ScColorMgmtEngine& engine, const QByteArray& data) |
||
167 | { |
||
168 | ScColorProfile profile; |
||
169 | cmsHPROFILE lcmsProf = cmsOpenProfileFromMem((const void *) data.data(), data.size()); |
||
170 | if (lcmsProf) |
||
171 | { |
||
172 | ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf); |
||
173 | QString desc = profData->productDescription(); |
||
174 | if (!desc.isEmpty()) |
||
175 | profData->m_profilePath = QString("memprofile://%1").arg(desc); |
||
176 | profData->m_profileData = data; |
||
23665 | craig | 177 | profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData)); |
15127 | jghali | 178 | } |
179 | if (profile.isNull() && lcmsProf) |
||
180 | { |
||
181 | cmsCloseProfile(lcmsProf); |
||
22518 | craig | 182 | lcmsProf = nullptr; |
15127 | jghali | 183 | } |
184 | return profile; |
||
185 | } |
||
186 | |||
187 | ScColorProfile ScLcms2ColorMgmtEngineImpl::createProfile_sRGB(ScColorMgmtEngine& engine) |
||
188 | { |
||
189 | QString internalProfilePath("memprofile://Internal sRGB profile"); |
||
190 | ScColorProfile profile = m_profileCache->profile(internalProfilePath); |
||
191 | if (!profile.isNull()) |
||
192 | return profile; |
||
193 | |||
194 | cmsHPROFILE lcmsProf = cmsCreate_sRGBProfile(); |
||
195 | if (lcmsProf) |
||
196 | { |
||
197 | ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf); |
||
198 | profData->m_profilePath = internalProfilePath; |
||
199 | profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData)); |
||
200 | m_profileCache->addProfile(profile); |
||
201 | } |
||
202 | if (profile.isNull() && lcmsProf) |
||
203 | { |
||
204 | cmsCloseProfile(lcmsProf); |
||
22518 | craig | 205 | lcmsProf = nullptr; |
15127 | jghali | 206 | } |
207 | return profile; |
||
208 | } |
||
209 | |||
210 | ScColorProfile ScLcms2ColorMgmtEngineImpl::createProfile_Lab(ScColorMgmtEngine& engine) |
||
211 | { |
||
212 | QString internalProfilePath("memprofile://Internal Lab profile"); |
||
213 | ScColorProfile profile = m_profileCache->profile(internalProfilePath); |
||
214 | if (!profile.isNull()) |
||
215 | return profile; |
||
216 | |||
22518 | craig | 217 | cmsHPROFILE lcmsProf = cmsCreateLab4Profile(nullptr); |
15127 | jghali | 218 | if (lcmsProf) |
219 | { |
||
220 | ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf); |
||
221 | profData->m_profilePath = internalProfilePath; |
||
222 | profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData)); |
||
223 | m_profileCache->addProfile(profile); |
||
224 | } |
||
225 | if (profile.isNull() && lcmsProf) |
||
226 | { |
||
227 | cmsCloseProfile(lcmsProf); |
||
22518 | craig | 228 | lcmsProf = nullptr; |
15127 | jghali | 229 | } |
230 | return profile; |
||
231 | } |
||
232 | |||
233 | ScColorTransform ScLcms2ColorMgmtEngineImpl::createTransform(ScColorMgmtEngine& engine, |
||
234 | const ScColorProfile& inputProfile , eColorFormat inputFormat, |
||
235 | const ScColorProfile& outputProfile, eColorFormat outputFormat, |
||
236 | eRenderIntent renderIntent, long transformFlags) |
||
237 | { |
||
22518 | craig | 238 | ScColorTransform transform(nullptr); |
15127 | jghali | 239 | if (inputProfile.isNull() || outputProfile.isNull()) |
240 | return transform; |
||
241 | int inputProfEngineID = inputProfile.engine().engineID(); |
||
242 | int outputProfEngineID = outputProfile.engine().engineID(); |
||
243 | if ((engine.engineID() != m_engineID) || (inputProfEngineID != m_engineID) || (outputProfEngineID != m_engineID)) |
||
244 | return transform; |
||
245 | const ScLcms2ColorProfileImpl* lcmsInputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(inputProfile.data()); |
||
246 | const ScLcms2ColorProfileImpl* lcmsOutputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(outputProfile.data()); |
||
247 | if (!lcmsInputProf || !lcmsOutputProf) |
||
248 | return transform; |
||
249 | |||
250 | transformFlags &= (~Ctf_Softproofing); |
||
251 | transformFlags &= (~Ctf_GamutCheck); |
||
252 | long strategyFlags = 0; |
||
23272 | craig | 253 | if (m_strategy.useBlackPointCompensation()) |
15127 | jghali | 254 | strategyFlags |= Ctf_BlackPointCompensation; |
23272 | craig | 255 | if (m_strategy.useBlackPreservation()) |
15127 | jghali | 256 | strategyFlags |= Ctf_BlackPreservation; |
257 | |||
258 | ScColorTransformInfo transInfo; |
||
259 | transInfo.inputProfile = inputProfile.productDescription(); |
||
260 | transInfo.outputProfile = outputProfile.productDescription(); |
||
20388 | craig | 261 | transInfo.proofingProfile.clear(); |
15127 | jghali | 262 | transInfo.inputFormat = inputFormat; |
263 | transInfo.outputFormat = outputFormat; |
||
264 | transInfo.renderIntent = renderIntent; |
||
265 | transInfo.proofingIntent = (eRenderIntent) 0; |
||
266 | transInfo.flags = transformFlags | strategyFlags; |
||
267 | |||
268 | bool nullTransform = false; |
||
269 | if (transInfo.inputProfile == transInfo.outputProfile) |
||
270 | { |
||
271 | // This is a null transform |
||
20388 | craig | 272 | transInfo.inputProfile.clear(); |
273 | transInfo.outputProfile.clear(); |
||
274 | transInfo.proofingProfile.clear(); |
||
23210 | craig | 275 | transInfo.renderIntent = Intent_Perceptual; |
276 | transInfo.proofingIntent = Intent_Perceptual; |
||
15127 | jghali | 277 | transInfo.flags = 0; |
278 | nullTransform = true; |
||
279 | } |
||
280 | |||
281 | transform = m_transformPool->findTransform(transInfo); |
||
282 | if (transform.isNull()) |
||
283 | { |
||
284 | cmsUInt32Number lcmsFlags = translateFlagsToLcmsFlags(transformFlags | strategyFlags); |
||
285 | cmsUInt32Number lcmsInputFmt = translateFormatToLcmsFormat(inputFormat); |
||
286 | cmsUInt32Number lcmsOutputFmt = translateFormatToLcmsFormat(outputFormat); |
||
287 | int lcmsIntent = translateIntentToLcmsIntent(renderIntent); |
||
288 | if (nullTransform) |
||
289 | lcmsFlags |= cmsFLAGS_NULLTRANSFORM; |
||
22518 | craig | 290 | cmsHTRANSFORM hTransform = nullptr; |
15127 | jghali | 291 | hTransform = cmsCreateTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, |
292 | lcmsOutputProf->m_profileHandle, lcmsOutputFmt, |
||
293 | lcmsIntent, lcmsFlags | cmsFLAGS_LOWRESPRECALC); |
||
294 | if (hTransform) |
||
295 | { |
||
296 | ScLcms2ColorTransformImpl* newTrans = new ScLcms2ColorTransformImpl(engine, hTransform); |
||
297 | newTrans->setTransformInfo(transInfo); |
||
23665 | craig | 298 | transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans)); |
15127 | jghali | 299 | m_transformPool->addTransform(transform, true); |
300 | } |
||
301 | } |
||
302 | return transform; |
||
303 | } |
||
304 | |||
305 | ScColorTransform ScLcms2ColorMgmtEngineImpl::createProofingTransform(ScColorMgmtEngine& engine, |
||
306 | const ScColorProfile& inputProfile , eColorFormat inputFormat, |
||
307 | const ScColorProfile& outputProfile, eColorFormat outputFormat, |
||
308 | const ScColorProfile& proofProfile , eRenderIntent renderIntent, |
||
309 | eRenderIntent proofingIntent, long transformFlags) |
||
310 | { |
||
22518 | craig | 311 | ScColorTransform transform(nullptr); |
15127 | jghali | 312 | if (inputProfile.isNull() || outputProfile.isNull()) |
313 | return transform; |
||
314 | int inputProfEngineID = inputProfile.engine().engineID(); |
||
315 | int outputProfEngineID = outputProfile.engine().engineID(); |
||
316 | int proofProfEngineID = proofProfile.engine().engineID(); |
||
317 | if ((engine.engineID() != m_engineID) || (inputProfEngineID != m_engineID) || |
||
318 | (outputProfEngineID != m_engineID) || (proofProfEngineID != m_engineID)) |
||
319 | return transform; |
||
320 | const ScLcms2ColorProfileImpl* lcmsInputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(inputProfile.data()); |
||
321 | const ScLcms2ColorProfileImpl* lcmsOutputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(outputProfile.data()); |
||
322 | const ScLcms2ColorProfileImpl* lcmsProofingProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(proofProfile.data()); |
||
323 | if (!lcmsInputProf || !lcmsOutputProf || !lcmsProofingProf) |
||
324 | return transform; |
||
325 | |||
326 | long strategyFlags = 0; |
||
23272 | craig | 327 | if (m_strategy.useBlackPointCompensation()) |
15127 | jghali | 328 | strategyFlags |= Ctf_BlackPointCompensation; |
23272 | craig | 329 | if (m_strategy.useBlackPreservation()) |
15127 | jghali | 330 | strategyFlags |= Ctf_BlackPreservation; |
331 | |||
332 | ScColorTransformInfo transInfo; |
||
333 | transInfo.inputProfile = inputProfile.productDescription(); |
||
334 | transInfo.outputProfile = outputProfile.productDescription(); |
||
335 | transInfo.proofingProfile = proofProfile.productDescription(); |
||
336 | transInfo.inputFormat = inputFormat; |
||
337 | transInfo.outputFormat = outputFormat; |
||
338 | transInfo.renderIntent = renderIntent; |
||
339 | transInfo.proofingIntent = proofingIntent; |
||
340 | transInfo.flags = transformFlags | strategyFlags; |
||
341 | |||
342 | cmsUInt32Number lcmsFlags = translateFlagsToLcmsFlags(transformFlags | strategyFlags); |
||
343 | cmsUInt32Number lcmsInputFmt = translateFormatToLcmsFormat(inputFormat); |
||
344 | cmsUInt32Number lcmsOutputFmt = translateFormatToLcmsFormat(outputFormat); |
||
345 | int lcmsIntent = translateIntentToLcmsIntent(renderIntent); |
||
346 | int lcmsPrfIntent = translateIntentToLcmsIntent(proofingIntent); |
||
347 | |||
348 | if (transInfo.inputProfile != transInfo.proofingProfile) |
||
349 | { |
||
350 | if (transInfo.proofingProfile == transInfo.outputProfile) |
||
351 | { |
||
352 | transInfo.proofingIntent = Intent_Relative_Colorimetric; |
||
353 | lcmsPrfIntent = translateIntentToLcmsIntent(Intent_Relative_Colorimetric); |
||
354 | } |
||
355 | transform = m_transformPool->findTransform(transInfo); |
||
356 | if (transform.isNull()) |
||
357 | { |
||
22518 | craig | 358 | cmsHTRANSFORM hTransform = nullptr; |
15127 | jghali | 359 | hTransform = cmsCreateProofingTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, |
360 | lcmsOutputProf->m_profileHandle, lcmsOutputFmt, |
||
361 | lcmsProofingProf->m_profileHandle, lcmsIntent, |
||
362 | lcmsPrfIntent, lcmsFlags | cmsFLAGS_SOFTPROOFING); |
||
363 | if (hTransform) |
||
364 | { |
||
365 | ScLcms2ColorTransformImpl* newTrans = new ScLcms2ColorTransformImpl(engine, hTransform); |
||
366 | newTrans->setTransformInfo(transInfo); |
||
23665 | craig | 367 | transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans)); |
15127 | jghali | 368 | m_transformPool->addTransform(transform, true); |
369 | } |
||
370 | } |
||
371 | } |
||
372 | else |
||
373 | { |
||
374 | transformFlags &= (~Ctf_Softproofing); |
||
375 | transformFlags &= (~Ctf_GamutCheck); |
||
376 | lcmsFlags = translateFlagsToLcmsFlags(transformFlags | strategyFlags); |
||
377 | transInfo.flags = transformFlags | strategyFlags; |
||
378 | transInfo.renderIntent = proofingIntent; |
||
379 | transInfo.proofingIntent = (eRenderIntent) 0; |
||
380 | if (transInfo.inputProfile == transInfo.outputProfile) |
||
381 | { |
||
382 | lcmsFlags |= cmsFLAGS_NULLTRANSFORM; |
||
20388 | craig | 383 | transInfo.inputProfile.clear(); |
384 | transInfo.outputProfile.clear(); |
||
385 | transInfo.proofingProfile.clear(); |
||
15127 | jghali | 386 | transInfo.renderIntent = (eRenderIntent) 0; |
387 | transInfo.proofingIntent = (eRenderIntent) 0; |
||
388 | transInfo.flags = 0; |
||
389 | } |
||
390 | transform = m_transformPool->findTransform(transInfo); |
||
391 | if (transform.isNull()) |
||
392 | { |
||
22518 | craig | 393 | cmsHTRANSFORM hTransform = nullptr; |
15127 | jghali | 394 | hTransform = cmsCreateTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, |
395 | lcmsOutputProf->m_profileHandle, lcmsOutputFmt, |
||
396 | lcmsPrfIntent, lcmsFlags | cmsFLAGS_LOWRESPRECALC); |
||
397 | if (hTransform) |
||
398 | { |
||
399 | ScLcms2ColorTransformImpl* newTrans = new ScLcms2ColorTransformImpl(engine, hTransform); |
||
400 | newTrans->setTransformInfo(transInfo); |
||
23665 | craig | 401 | transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans)); |
15127 | jghali | 402 | m_transformPool->addTransform(transform, true); |
403 | } |
||
404 | } |
||
405 | } |
||
406 | return transform; |
||
407 | } |
||
408 | |||
409 | cmsUInt32Number ScLcms2ColorMgmtEngineImpl::translateFlagsToLcmsFlags(long flags) |
||
410 | { |
||
411 | cmsUInt32Number lFlags = 0; |
||
412 | if (flags & Ctf_BlackPointCompensation) |
||
413 | lFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION; |
||
414 | if (flags & Ctf_BlackPreservation) |
||
415 | lFlags |= cmsFLAGS_PRESERVEBLACK; |
||
416 | if (flags & Ctf_Softproofing) |
||
417 | lFlags |= cmsFLAGS_SOFTPROOFING; |
||
418 | if (flags & Ctf_GamutCheck) |
||
419 | lFlags |= cmsFLAGS_GAMUTCHECK; |
||
420 | return lFlags; |
||
421 | } |
||
422 | |||
423 | cmsUInt32Number ScLcms2ColorMgmtEngineImpl::translateFormatToLcmsFormat(eColorFormat format) |
||
424 | { |
||
425 | cmsUInt32Number lFormat = 0; |
||
426 | if (format == Format_RGB_8) |
||
427 | lFormat = TYPE_RGB_8; |
||
428 | if (format == Format_RGB_16) |
||
429 | lFormat = TYPE_RGB_16; |
||
430 | if (format == Format_RGBA_8) |
||
431 | lFormat = TYPE_RGBA_8; |
||
432 | if (format == Format_RGBA_16) |
||
433 | lFormat = TYPE_RGBA_16; |
||
434 | if (format == Format_ARGB_8) |
||
435 | lFormat = TYPE_ARGB_8; |
||
436 | if (format == Format_ARGB_16) |
||
437 | lFormat = TYPE_ARGB_16; |
||
438 | if (format == Format_BGRA_8) |
||
439 | lFormat = TYPE_BGRA_8; |
||
440 | if (format == Format_BGRA_16) |
||
441 | lFormat = TYPE_BGRA_16; |
||
442 | if (format == Format_CMYK_8) |
||
443 | lFormat = TYPE_CMYK_8; |
||
444 | if (format == Format_CMYK_16) |
||
445 | lFormat = TYPE_CMYK_16; |
||
446 | if (format == Format_CMYKA_8) |
||
447 | lFormat = (COLORSPACE_SH(PT_CMYK)|EXTRA_SH(1)|CHANNELS_SH(4)|BYTES_SH(1)); |
||
448 | if (format == Format_CMYKA_16) |
||
449 | lFormat = (COLORSPACE_SH(PT_CMYK)|EXTRA_SH(1)|CHANNELS_SH(4)|BYTES_SH(2)); |
||
450 | if (format == Format_YMCK_8) |
||
451 | lFormat = (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1)); |
||
452 | if (format == Format_YMCK_16) |
||
453 | lFormat = (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1)|SWAPFIRST_SH(1)); |
||
454 | if (format == Format_GRAY_8) |
||
455 | lFormat = TYPE_GRAY_8; |
||
456 | if (format == Format_GRAY_16) |
||
457 | lFormat = TYPE_GRAY_16; |
||
458 | if (format == Format_LabA_8) |
||
459 | lFormat = COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1); |
||
20145 | fschmid | 460 | if (format == Format_Lab_Dbl) |
461 | lFormat = TYPE_Lab_DBL; |
||
15127 | jghali | 462 | return lFormat; |
463 | } |
||
464 | |||
465 | int ScLcms2ColorMgmtEngineImpl::translateIntentToLcmsIntent(eRenderIntent intent, eRenderIntent defIntent) |
||
466 | { |
||
467 | int lIntent = defIntent; |
||
468 | if (intent == Intent_Perceptual) |
||
469 | lIntent = INTENT_PERCEPTUAL; |
||
470 | if (intent == Intent_Relative_Colorimetric) |
||
471 | lIntent = INTENT_RELATIVE_COLORIMETRIC; |
||
472 | if (intent == Intent_Saturation) |
||
473 | lIntent = INTENT_SATURATION; |
||
474 | if (intent == Intent_Absolute_Colorimetric) |
||
475 | lIntent = INTENT_ABSOLUTE_COLORIMETRIC; |
||
476 | return lIntent; |
||
477 | } |
||
478 | |||
479 | eColorSpaceType ScLcms2ColorMgmtEngineImpl::translateLcmsColorSpaceType(cmsColorSpaceSignature signature) |
||
480 | { |
||
481 | eColorSpaceType colorSpaceType = ColorSpace_Unknown; |
||
482 | if (signature == cmsSigXYZData) |
||
483 | colorSpaceType = ColorSpace_XYZ; |
||
484 | if (signature == cmsSigLabData) |
||
485 | colorSpaceType = ColorSpace_Lab; |
||
486 | if (signature == cmsSigLuvData) |
||
487 | colorSpaceType = ColorSpace_Luv; |
||
488 | if (signature == cmsSigYCbCrData) |
||
489 | colorSpaceType = ColorSpace_YCbCr; |
||
490 | if (signature == cmsSigYxyData) |
||
491 | colorSpaceType = ColorSpace_Yxy; |
||
492 | if (signature == cmsSigRgbData) |
||
493 | colorSpaceType = ColorSpace_Rgb; |
||
494 | if (signature == cmsSigGrayData) |
||
495 | colorSpaceType = ColorSpace_Gray; |
||
496 | if (signature == cmsSigHsvData) |
||
497 | colorSpaceType = ColorSpace_Hsv; |
||
498 | if (signature == cmsSigHlsData) |
||
499 | colorSpaceType = ColorSpace_Hls; |
||
500 | if (signature == cmsSigCmykData) |
||
501 | colorSpaceType = ColorSpace_Cmyk; |
||
502 | if (signature == cmsSigCmyData) |
||
503 | colorSpaceType = ColorSpace_Cmy; |
||
504 | return colorSpaceType; |
||
505 | } |
||
506 | |||
507 | eProfileClass ScLcms2ColorMgmtEngineImpl::translateLcmsProfileClass(cmsProfileClassSignature signature) |
||
508 | { |
||
509 | eProfileClass profileClass = Class_Unknown; |
||
510 | if (signature == cmsSigInputClass) |
||
511 | profileClass = Class_Input; |
||
512 | if (signature == cmsSigDisplayClass) |
||
513 | profileClass = Class_Display; |
||
514 | if (signature == cmsSigOutputClass) |
||
515 | profileClass = Class_Output; |
||
516 | if (signature == cmsSigLinkClass) |
||
517 | profileClass = Class_Link; |
||
518 | if (signature == cmsSigAbstractClass) |
||
519 | profileClass = Class_Abstract; |
||
520 | if (signature == cmsSigColorSpaceClass) |
||
521 | profileClass = Class_ColorSpace; |
||
522 | if (signature == cmsSigNamedColorClass) |
||
523 | profileClass = Class_NamedColor; |
||
524 | return profileClass; |
||
525 | } |
||
526 | |||
527 | void ScLcms2ColorMgmtEngineImpl::cmsErrorHandler(cmsContext contextID, cmsUInt32Number /*ErrorCode*/, |
||
528 | const char *ErrorText) |
||
529 | { |
||
530 | std::string msg = std::string("Littlecms : ") + ErrorText; |
||
531 | std::cerr << ErrorText << std::endl; |
||
532 | } |