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