clang -cc1 -cc1 -triple x86_64-apple-macosx14.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name IccEncoding.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=osx -analyzer-checker=security.insecureAPI.decodeValueOfObjCType -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -target-sdk-version=14.0 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debugger-tuning=lldb -target-linker-version 1015.7 -fprofile-instrument=clang -fcoverage-mapping -fcoverage-compilation-dir=/Users/xss/DemoIccMAX-hoyt-master/build/IccProfLib -resource-dir /usr/local/Cellar/llvm/17.0.3/lib/clang/17 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -D IccProfLib2_EXPORTS -I /Users/xss/DemoIccMAX-hoyt-master/build/Cmake/../../IccProfLib -I /Developer/Headers/FlatCarbon -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks -internal-isystem /usr/local/Cellar/llvm/17.0.3/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/local/include -internal-isystem /usr/local/Cellar/llvm/17.0.3/lib/clang/17/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/Users/xss/DemoIccMAX-hoyt-master/build/IccProfLib -ferror-limit 19 -fsanitize=address -fsanitize-system-ignorelist=/usr/local/Cellar/llvm/17.0.3/lib/clang/17/share/asan_ignorelist.txt -fno-sanitize-memory-param-retval -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -analyzer-output=html -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/l9/sd9kj1px4yq2wc5_lkwhlt6w0000gn/T/scan-build-2023-10-28-102616-57860-1 -x c++ /Users/xss/DemoIccMAX-hoyt-master/IccProfLib/IccEncoding.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | #include "IccEncoding.h" |
72 | #include "IccProfile.h" |
73 | #include "IccTag.h" |
74 | #include "IccTagMPE.h" |
75 | #include "IccMpeBasic.h" |
76 | #include "IccCAM.h" |
77 | #include "IccUtil.h" |
78 | #include <string> |
79 | #include <time.h> |
80 | #include <cstring> |
81 | |
82 | class CIccDefaultEncProfileCacheHandler : public IIccEncProfileCacheHandler |
83 | { |
84 | public: |
85 | CIccDefaultEncProfileCacheHandler() {} |
86 | |
87 | virtual CIccProfile *GetEncodingProfile(const icUChar *szColorSpaceName) |
88 | { |
89 | std::string file = "ISO22028-Encoded-"; |
90 | file += (char*)szColorSpaceName; |
91 | file += ".icc"; |
92 | |
93 | return OpenIccProfile(file.c_str()); |
94 | } |
95 | }; |
96 | |
97 | static IIccEncProfileCacheHandler* g_pEncProfileCacheHandler = NULL; |
98 | |
99 | IIccEncProfileCacheHandler *IIccEncProfileCacheHandler::GetHandler() |
100 | { |
101 | if (!g_pEncProfileCacheHandler) { |
102 | g_pEncProfileCacheHandler = new CIccDefaultEncProfileCacheHandler(); |
103 | } |
104 | return g_pEncProfileCacheHandler; |
105 | } |
106 | |
107 | void IIccEncProfileCacheHandler::SetEncCacheHandler(IIccEncProfileCacheHandler *pHandler) |
108 | { |
109 | if (pHandler) { |
110 | if (g_pEncProfileCacheHandler) { |
111 | delete g_pEncProfileCacheHandler; |
112 | } |
113 | g_pEncProfileCacheHandler = pHandler; |
114 | } |
115 | } |
116 | |
117 | class CIccDefaultEncProfileConverter : public IIccEncProfileConverter |
118 | { |
119 | public: |
120 | CIccDefaultEncProfileConverter() {} |
121 | |
122 | virtual icStatusEncConvert ConvertFromParams(CIccProfilePtr &newIcc, CIccTagStruct *pParams, icHeader *pHeader); |
123 | }; |
124 | |
125 | static icFloatNumber icGetParamFloatNum(CIccTagStruct *pParams, icColorEncodingParamsMemberSignature sig, icFloatNumber defaultValue=0) |
126 | { |
127 | CIccTagFloat32 *pTag = (CIccTagFloat32*)pParams->FindElemOfType(sig, icSigFloat32ArrayType); |
128 | |
129 | if (!pTag || pTag->GetSize()<1) |
130 | return defaultValue; |
131 | |
132 | return (*pTag)[0]; |
133 | } |
134 | |
135 | static void icYxy2XYZVector(icFloatNumber*XYZ, icFloatNumber Y, icFloatNumber *xy, icUInt8Number idxOffset=1) |
136 | { |
137 | XYZ[0] = Y*xy[0] / xy[1]; |
138 | XYZ[idxOffset] = Y; |
139 | XYZ[idxOffset<<1] = Y*(1.0f-xy[0]-xy[1]) / xy[1]; |
140 | } |
141 | |
142 | icStatusEncConvert CIccDefaultEncProfileConverter::ConvertFromParams(CIccProfilePtr &newIcc, CIccTagStruct *pParams, icHeader *pHeader) |
143 | { |
144 | newIcc = NULL; |
145 | |
146 | if (!pParams || pParams->GetTagStructType()!= icSigColorEncodingParamsSruct || !pHeader) |
| 12 | | Assuming the condition is false | |
|
| |
147 | return icEncConvertBadParams; |
148 | |
149 | CIccTagFloat32 *pWhitePt = (CIccTagFloat32*)pParams->FindElemOfType(icSigCeptWhitePointChromaticityMbr, icSigFloat32ArrayType); |
150 | CIccTagFloat32 *pMediaWhitePt = (CIccTagFloat32*)pParams->FindElemOfType(icSigCeptMediumWhitePointChromaticityMbr, icSigFloat32ArrayType); |
151 | |
152 | if (!pWhitePt || pWhitePt->GetNumValues()<2) { |
| 14 | | Assuming 'pWhitePt' is non-null | |
|
| 15 | | Assuming the condition is false | |
|
| |
153 | return icEncConvertBadParams; |
154 | } |
155 | |
156 | if (!pMediaWhitePt) |
| 17 | | Assuming 'pMediaWhitePt' is non-null | |
|
157 | pMediaWhitePt = pWhitePt; |
158 | |
159 | if (!pMediaWhitePt || pMediaWhitePt->GetNumValues()<2) { |
| 18 | | Assuming the condition is false | |
|
| |
160 | return icEncConvertBadParams; |
161 | } |
162 | |
163 | CIccProfile *pIcc = new CIccProfile; |
| |
164 | pIcc->m_Header = *pHeader; |
165 | |
166 | struct tm *newtime; |
167 | time_t long_time; |
168 | |
169 | time( &long_time ); |
170 | newtime = gmtime( &long_time ); |
171 | |
172 | pIcc->m_Header.date.year = newtime->tm_year+1900; |
173 | pIcc->m_Header.date.month = newtime->tm_mon+1; |
174 | pIcc->m_Header.date.day = newtime->tm_mday; |
175 | pIcc->m_Header.date.hours = newtime->tm_hour; |
176 | pIcc->m_Header.date.minutes = newtime->tm_min; |
177 | pIcc->m_Header.date.seconds = newtime->tm_sec; |
178 | |
179 | float XYZWhite[3]; |
180 | icYxy2XYZVector(XYZWhite, 1.0f, &(*pWhitePt)[0], 1); |
181 | |
182 | pIcc->m_Header.pcs = icSigXYZPcsData; |
183 | pIcc->m_Header.deviceClass = icSigDisplayClass; |
184 | pIcc->m_Header.illuminant.X = icDtoF(XYZWhite[0]); |
185 | pIcc->m_Header.illuminant.Y = icDtoF(XYZWhite[1]); |
186 | pIcc->m_Header.illuminant.Z = icDtoF(XYZWhite[2]); |
187 | |
188 | |
189 | CIccTagXYZ *pXYZ = new CIccTagXYZ(); |
190 | float XYZMedia[3]; |
191 | icYxy2XYZVector(XYZMedia, 1.0f, &(*pMediaWhitePt)[0], 1); |
192 | if (!pXYZ->SetSize(1)) |
| 21 | | Assuming the condition is true | |
|
| |
193 | return icEncConvertMemoryError; |
| 23 | | Potential leak of memory pointed to by 'pIcc' |
|
194 | |
195 | (*pXYZ)[0].X = icDtoF(XYZMedia[0]); |
196 | (*pXYZ)[0].Y = icDtoF(XYZMedia[1]); |
197 | (*pXYZ)[0].Z = icDtoF(XYZMedia[2]); |
198 | pIcc->AttachTag(icSigMediaWhitePointTag, pXYZ); |
199 | |
200 | |
201 | CIccTagMultiProcessElement *pMpeTag = (CIccTagMultiProcessElement*)CIccTag::Create(icSigMultiProcessElementType); |
202 | if (!pMpeTag) { |
203 | delete pIcc; |
204 | return icEncConvertMemoryError; |
205 | } |
206 | |
207 | pMpeTag->SetChannels(3, 3); |
208 | |
209 | CIccMpeMatrix *pMtx; |
210 | CIccTagFloat32 *pLumMtx = (CIccTagFloat32*)pParams->FindElemOfType(icSigCeptLumaChromaMatrixMbr, icSigFloat32ArrayType); |
211 | icFloatNumber lumMtx[9]; |
212 | bool bHaveLumMtx = false; |
213 | if (pLumMtx) { |
214 | if (pLumMtx->GetSize()<9) { |
215 | delete pMpeTag; |
216 | delete pIcc; |
217 | return icEncConvertBadParams; |
218 | } |
219 | pMtx = (CIccMpeMatrix*)CIccMultiProcessElement::Create(icSigMatrixElemType); |
220 | if (!pMtx) { |
221 | delete pMpeTag; |
222 | delete pIcc; |
223 | return icEncConvertMemoryError; |
224 | } |
225 | if (!pMtx->SetSize(3, 3)) |
226 | return icEncConvertMemoryError; |
227 | |
228 | pLumMtx->GetValues(pMtx->GetMatrix(), 0, 9); |
229 | pLumMtx->GetValues(&lumMtx[0], 0, 9); |
230 | pMpeTag->Attach(pMtx); |
231 | delete pLumMtx; |
232 | bHaveLumMtx = true; |
233 | } |
234 | |
235 | CIccTagSegmentedCurve *pSegCurve = (CIccTagSegmentedCurve*)pParams->FindElemOfType(icSigCeptTransferFunctionMbr, icSigSegmentedCurveType); |
236 | if (pSegCurve && pSegCurve->GetCurve()) { |
237 | CIccSegmentedCurve *pCurve = pSegCurve->GetCurve(); |
238 | CIccMpeCurveSet *pCurves = (CIccMpeCurveSet*)CIccMultiProcessElement::Create(icSigCurveSetElemType); |
239 | if (!pCurves) { |
240 | delete pMpeTag; |
241 | delete pIcc; |
242 | return icEncConvertMemoryError; |
243 | } |
244 | pCurves->SetSize(3); |
245 | pCurves->SetCurve(0, pCurve->NewCopy()); |
246 | pCurves->SetCurve(1, pCurve->NewCopy()); |
247 | pCurves->SetCurve(2, pCurve->NewCopy()); |
248 | pMpeTag->Attach(pCurves); |
249 | } |
250 | pMtx = (CIccMpeMatrix*)CIccMultiProcessElement::Create(icSigMatrixElemType); |
251 | if (!pMtx) { |
252 | delete pMpeTag; |
253 | delete pIcc; |
254 | return icEncConvertMemoryError; |
255 | } |
256 | |
257 | CIccTagFloat32 *pxy; |
258 | if (!pMtx->SetSize(3,3)) { |
259 | delete pMtx; |
260 | delete pMpeTag; |
261 | delete pIcc; |
262 | return icEncConvertMemoryError; |
263 | } |
264 | icFloatNumber *mtx=pMtx->GetMatrix(); |
265 | |
266 | pxy = (CIccTagFloat32*)pParams->FindElemOfType(icSigCeptRedPrimaryXYZMbr, icSigFloat32ArrayType); |
267 | if (!pxy || pxy->GetSize()<2) { |
268 | delete pMpeTag; |
269 | delete pIcc; |
270 | return icEncConvertMemoryError; |
271 | } |
272 | mtx[0]=(*pxy)[0] * XYZMedia[0]; |
273 | mtx[3]=(*pxy)[1] * XYZMedia[1]; |
274 | mtx[6]=(1.0f - (*pxy)[0] - (*pxy)[1]) * XYZMedia[2]; |
275 | |
276 | pxy = (CIccTagFloat32*)pParams->FindElemOfType(icSigCeptGreenPrimaryXYZMbr, icSigFloat32ArrayType); |
277 | if (!pxy || pxy->GetSize()<2) { |
278 | delete pMpeTag; |
279 | delete pIcc; |
280 | return icEncConvertMemoryError; |
281 | } |
282 | mtx[1]=(*pxy)[0] * XYZMedia[0]; |
283 | mtx[4]=(*pxy)[1] * XYZMedia[1]; |
284 | mtx[7]=(1.0f - (*pxy)[0] - (*pxy)[1]) * XYZMedia[2]; |
285 | |
286 | pxy = (CIccTagFloat32*)pParams->FindElemOfType(icSigCeptBluePrimaryXYZMbr, icSigFloat32ArrayType); |
287 | if (!pxy || pxy->GetSize()<2) { |
288 | delete pMpeTag; |
289 | delete pIcc; |
290 | return icEncConvertMemoryError; |
291 | } |
292 | mtx[2]=(*pxy)[0] * XYZMedia[0]; |
293 | mtx[5]=(*pxy)[1] * XYZMedia[1]; |
294 | mtx[8]=(1.0f - (*pxy)[0] - (*pxy)[1]) * XYZMedia[2]; |
295 | |
296 | CIccMpeMatrix *pMtx2 = (CIccMpeMatrix*)pMtx->NewCopy(); |
297 | pMpeTag->Attach(pMtx); |
298 | |
299 | pIcc->AttachTag(icSigAToB3Tag, pMpeTag); |
300 | |
301 | if (!icMatrixInvert3x3(pMtx2->GetMatrix())) { |
302 | delete pMtx2; |
303 | delete pIcc; |
304 | return icEncConvertBadParams; |
305 | } |
306 | |
307 | |
308 | pMpeTag = (CIccTagMultiProcessElement*)CIccTag::Create(icSigMultiProcessElementType); |
309 | if (!pMpeTag) { |
310 | delete pMtx2; |
311 | delete pIcc; |
312 | return icEncConvertMemoryError; |
313 | } |
314 | |
315 | pMpeTag->SetChannels(3, 3); |
316 | |
317 | pMpeTag->Attach(pMtx2); |
318 | |
319 | pSegCurve = (CIccTagSegmentedCurve*)pParams->FindElemOfType(icSigCeptInverseTransferFunctionMbr, icSigSegmentedCurveType); |
320 | if (pSegCurve && pSegCurve->GetCurve()) { |
321 | CIccSegmentedCurve *pCurve = pSegCurve->GetCurve(); |
322 | CIccMpeCurveSet *pCurves = (CIccMpeCurveSet*)CIccMultiProcessElement::Create(icSigCurveSetElemType); |
323 | if (!pCurves || !pCurves->SetSize(3)) { |
324 | delete pMpeTag; |
325 | delete pIcc; |
326 | return icEncConvertMemoryError; |
327 | } |
328 | pCurves->SetCurve(0, pCurve->NewCopy()); |
329 | pCurves->SetCurve(1, pCurve->NewCopy()); |
330 | pCurves->SetCurve(2, pCurve->NewCopy()); |
331 | pMpeTag->Attach(pCurves); |
332 | } |
333 | |
334 | if (bHaveLumMtx) { |
335 | if (!icMatrixInvert3x3(&lumMtx[0])) { |
336 | delete pMpeTag; |
337 | delete pIcc; |
338 | return icEncConvertBadParams; |
339 | } |
340 | |
341 | pMtx = (CIccMpeMatrix*)CIccMultiProcessElement::Create(icSigMatrixElemType); |
342 | if (!pMtx) { |
343 | delete pMpeTag; |
344 | delete pIcc; |
345 | return icEncConvertMemoryError; |
346 | } |
347 | pMpeTag->Attach(pMtx); |
348 | } |
349 | pIcc->AttachTag(icSigBToA3Tag, pMpeTag); |
350 | |
351 | |
352 | if (pIcc->m_Header.illuminant.X!=icDtoF(icD50XYZ[0]) || |
353 | pIcc->m_Header.illuminant.Y!=icDtoF(icD50XYZ[1]) || |
354 | pIcc->m_Header.illuminant.Z!=icDtoF(icD50XYZ[2])) { |
355 | |
356 | |
357 | CIccTagSpectralViewingConditions *pCond = (CIccTagSpectralViewingConditions*)CIccTag::Create(icSigSpectralViewingConditionsType); |
358 | if (!pCond) { |
359 | delete pIcc; |
360 | return icEncConvertMemoryError; |
361 | } |
362 | |
363 | icFloatNumber illXYZ[3]; |
364 | icFloatNumber Lw = pParams->GetElemNumberValue(icSigCeptWhitePointLuminanceMbr, 100); |
365 | pCond->setIlluminant(XYZWhite); |
366 | |
367 | illXYZ[0] = pCond->m_illuminantXYZ.X = Lw * XYZWhite[0]; |
368 | illXYZ[1] = pCond->m_illuminantXYZ.Y = Lw * XYZWhite[1]; |
369 | illXYZ[2] = pCond->m_illuminantXYZ.Z = Lw * XYZWhite[2]; |
370 | |
371 | icFloatNumber La = pParams->GetElemNumberValue(icSigCeptAmbientWhitePointLuminanceMbr, Lw/5.0f); |
372 | CIccTagFloat32 *pSurround = (CIccTagFloat32*)pParams->FindElemOfType(icSigCeptAmbientWhitePointChromaticityMbr, icSigFloat32ArrayType); |
373 | if (pSurround && pSurround->GetSize()>=2) { |
374 | icFloatNumber XYZSurround[3]; |
375 | icYxy2XYZVector(XYZSurround, 1, &(*pSurround)[0], 1); |
376 | pCond->m_surroundXYZ.X = La * XYZSurround[0]; |
377 | pCond->m_surroundXYZ.Y = La * XYZSurround[1]; |
378 | pCond->m_surroundXYZ.Z = La * XYZSurround[2]; |
379 | } |
380 | else { |
381 | pCond->m_surroundXYZ.X = La * XYZWhite[0]; |
382 | pCond->m_surroundXYZ.Y = La * XYZWhite[1]; |
383 | pCond->m_surroundXYZ.Z = La * XYZWhite[2]; |
384 | } |
385 | |
386 | pIcc->AttachTag(icSigSpectralViewingConditionsTag, pCond); |
387 | |
388 | icFloatNumber Lsw=pParams->GetElemNumberValue(icSigCeptViewingSurroundMbr, Lw/5.0f - 0.001f); |
389 | CIccCamConverter *pCstmConvert = new CIccCamConverter(); |
390 | if (!pCstmConvert) { |
391 | delete pIcc; |
392 | return icEncConvertMemoryError; |
393 | } |
394 | pCstmConvert->SetParameter_WhitePoint(&illXYZ[0]); |
395 | pCstmConvert->SetParameter_La(La); |
396 | pCstmConvert->SetParameter_Yb(Lw); |
397 | |
398 | icFloatNumber SWr = Lsw / Lw; |
399 | |
400 | if (SWr>0.2) { |
401 | pCstmConvert->SetParameter_C(0.69f); |
402 | pCstmConvert->SetParameter_Nc(1.0f); |
403 | pCstmConvert->SetParameter_F(1.0f); |
404 | } |
405 | else if (SWr>0.0) { |
406 | pCstmConvert->SetParameter_C(0.59f); |
407 | pCstmConvert->SetParameter_Nc(0.95f); |
408 | pCstmConvert->SetParameter_F(0.9f); |
409 | } |
410 | else { |
411 | pCstmConvert->SetParameter_C(0.525f); |
412 | pCstmConvert->SetParameter_Nc(0.8f); |
413 | pCstmConvert->SetParameter_F(0.8f); |
414 | } |
415 | |
416 | CIccCamConverter *pCstmConvert2 = new CIccCamConverter(); |
417 | if (!pCstmConvert2) { |
418 | delete pCstmConvert; |
419 | delete pIcc; |
420 | return icEncConvertMemoryError; |
421 | } |
422 | *pCstmConvert2 = *pCstmConvert; |
423 | |
424 | |
425 | CIccCamConverter *pStdConvert = new CIccCamConverter(); |
426 | if (!pStdConvert) { |
427 | delete pCstmConvert; |
428 | delete pCstmConvert2; |
429 | delete pIcc; |
430 | return icEncConvertMemoryError; |
431 | } |
432 | CIccCamConverter *pStdConvert2 = new CIccCamConverter(); |
433 | if (!pStdConvert2) { |
434 | delete pCstmConvert; |
435 | delete pCstmConvert2; |
436 | delete pStdConvert; |
437 | delete pIcc; |
438 | return icEncConvertMemoryError; |
439 | } |
440 | |
441 | CIccMpeCAM *pCam; |
442 | pMpeTag = (CIccTagMultiProcessElement*)CIccTag::Create(icSigMultiProcessElementType); |
443 | if (!pMpeTag) { |
444 | delete pCstmConvert; |
445 | delete pStdConvert; |
446 | delete pCstmConvert2; |
447 | delete pStdConvert2; |
448 | delete pIcc; |
449 | return icEncConvertMemoryError; |
450 | } |
451 | pMpeTag->SetChannels(3, 3); |
452 | |
453 | pCam = (CIccMpeCAM*)CIccMultiProcessElement::Create(icSigXYZToJabElemType); |
454 | if (!pCam) { |
455 | delete pCstmConvert; |
456 | delete pStdConvert; |
457 | delete pCstmConvert2; |
458 | delete pStdConvert2; |
459 | delete pIcc; |
460 | return icEncConvertMemoryError; |
461 | } |
462 | pCam->SetCAM(pCstmConvert); |
463 | pMpeTag->Attach(pCam); |
464 | |
465 | pCam = (CIccMpeCAM*)CIccMultiProcessElement::Create(icSigJabToXYZElemType); |
466 | if (!pCam) { |
467 | delete pStdConvert; |
468 | delete pCstmConvert2; |
469 | delete pStdConvert2; |
470 | delete pIcc; |
471 | return icEncConvertMemoryError; |
472 | } |
473 | pCam->SetCAM(pStdConvert); |
474 | pMpeTag->Attach(pCam); |
475 | pIcc->AttachTag(icSigCustomToStandardPccTag, pMpeTag); |
476 | |
477 | pMpeTag = (CIccTagMultiProcessElement*)CIccTag::Create(icSigMultiProcessElementType); |
478 | if (!pMpeTag) { |
479 | delete pIcc; |
480 | return icEncConvertMemoryError; |
481 | } |
482 | pMpeTag->SetChannels(3,3); |
483 | |
484 | pCam = (CIccMpeCAM*)CIccMultiProcessElement::Create(icSigXYZToJabElemType); |
485 | if (!pCam) { |
486 | delete pCstmConvert2; |
487 | delete pStdConvert2; |
488 | delete pIcc; |
489 | return icEncConvertMemoryError; |
490 | } |
491 | pCam->SetCAM(pStdConvert2); |
492 | pMpeTag->Attach(pCam); |
493 | |
494 | pCam = (CIccMpeCAM*)CIccMultiProcessElement::Create(icSigJabToXYZElemType); |
495 | if (!pCam) { |
496 | delete pCstmConvert2; |
497 | delete pIcc; |
498 | return icEncConvertMemoryError; |
499 | } |
500 | pCam->SetCAM(pCstmConvert2); |
501 | pMpeTag->Attach(pCam); |
502 | pIcc->AttachTag(icSigStandardToCustomPccTag, pMpeTag); |
503 | } |
504 | |
505 | #if 1 && defined(_DEBUG) |
506 | SaveIccProfile("WEncConv.icc", pIcc); |
507 | #endif |
508 | |
509 | newIcc = pIcc; |
510 | return icEncConvertOk; |
511 | } |
512 | |
513 | static IIccEncProfileConverter* g_pEncProfileConverter = NULL; |
514 | |
515 | IIccEncProfileConverter *IIccEncProfileConverter::GetHandler() |
516 | { |
517 | if (!g_pEncProfileConverter) { |
518 | g_pEncProfileConverter = new CIccDefaultEncProfileConverter(); |
519 | } |
520 | return g_pEncProfileConverter; |
521 | } |
522 | |
523 | void IIccEncProfileConverter::SetEncProfileConverter(IIccEncProfileConverter *pConverter) |
524 | { |
525 | if (pConverter) { |
526 | if (g_pEncProfileConverter) { |
527 | delete g_pEncProfileConverter; |
528 | } |
529 | g_pEncProfileConverter = pConverter; |
530 | } |
531 | } |
532 | |
533 | |
534 | icStatusEncConvert icConvertEncodingProfile(CIccProfilePtr &newIcc, CIccProfile *pEncodeIcc) |
535 | { |
536 | newIcc = NULL; |
537 | |
538 | if (!pEncodeIcc || pEncodeIcc->m_Header.deviceClass!=icSigColorEncodingClass) |
| 1 | Assuming 'pEncodeIcc' is non-null | |
|
| 2 | | Assuming field 'deviceClass' is equal to icSigColorEncodingClass | |
|
| |
539 | return icEncConvertBadProfile; |
540 | |
541 | CIccTag *pTag; |
542 | CIccTagStruct *pParams=NULL; |
543 | pTag = pEncodeIcc->FindTagOfType(icSigReferenceNameTag, icSigUtf8TextType); |
544 | if (pTag) { |
| 4 | | Assuming 'pTag' is non-null | |
|
| |
545 | CIccTagUtf8Text *pText = (CIccTagUtf8Text*)pTag; |
546 | const icUChar *szRefName = pText->GetText(); |
547 | if (!strcmp((const char*)szRefName, "ISO 22028-1")) { |
| |
548 | pTag = pEncodeIcc->FindTagOfType(icSigColorEncodingParamsTag, icSigTagStructType); |
549 | if (pTag) |
| 7 | | Assuming 'pTag' is non-null | |
|
| |
550 | pParams = (CIccTagStruct*)pTag->NewCopy(); |
551 | } |
552 | else { |
553 | CIccTag *pNameTag = pEncodeIcc->FindTagOfType(icSigColorSpaceNameTag, icSigUtf8TextType); |
554 | if (pNameTag) { |
555 | pText = (CIccTagUtf8Text *)pNameTag; |
556 | const icUChar *szName = pText->GetText(); |
557 | |
558 | CIccProfile *pBaseIcc = IIccEncProfileCacheHandler::GetHandler()->GetEncodingProfile(szName); |
559 | if (!pBaseIcc) { |
560 | return icEncConvertNoBaseProfile; |
561 | } |
562 | |
563 | pTag = pBaseIcc->FindTagOfType(icSigColorEncodingParamsTag, icSigTagStructType); |
564 | if (!pTag) { |
565 | delete pBaseIcc; |
566 | return icEncConvertBadBaseProfile; |
567 | } |
568 | pParams = (CIccTagStruct*)pTag->NewCopy(); |
569 | delete pBaseIcc; |
570 | |
571 | |
572 | CIccTag *pOverridesTag = pEncodeIcc->FindTagOfType(icSigColorEncodingParamsTag, icSigTagStructType); |
573 | if (pOverridesTag) { |
574 | CIccTagStruct *pStruct = (CIccTagStruct*)pOverridesTag; |
575 | TagEntryList *pTags = pStruct->GetElemList(); |
576 | if (pTags) { |
577 | TagEntryList::iterator entry; |
578 | for (entry=pTags->begin(); entry!=pTags->end(); entry++) { |
579 | if (entry->pTag) { |
580 | pStruct->DeleteElem(entry->TagInfo.sig); |
581 | pStruct->AttachElem(entry->TagInfo.sig, entry->pTag->NewCopy()); |
582 | } |
583 | } |
584 | } |
585 | } |
586 | } |
587 | } |
588 | } |
589 | |
590 | if (!pParams) { |
| 9 | | Assuming 'pParams' is non-null | |
|
| |
591 | return icEncConvertBadProfile; |
592 | } |
593 | |
594 | |
595 | icStatusEncConvert stat = IIccEncProfileConverter::GetHandler()->ConvertFromParams(newIcc, pParams, &pEncodeIcc->m_Header); |
| 11 | | Calling 'CIccDefaultEncProfileConverter::ConvertFromParams' | |
|
596 | |
597 | delete pParams; |
598 | |
599 | return stat; |
600 | } |