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