Bug Summary

File:IccProfLib/IccEncoding.cpp
Warning:line 479, column 14
Potential leak of memory pointed to by 'pStdConvert2'

Annotated Source Code

Press '?' to see keyboard shortcuts

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/*
2File: IccEncoding.cpp
3
4Contains: Implementation of Encoding profile class utilities
5
6Version: V1
7
8Copyright: see ICC Software License
9*/
10
11/*
12* The ICC Software License, Version 0.2
13*
14*
15* Copyright (c) 2003-2013 The International Color Consortium. All rights
16* reserved.
17*
18* Redistribution and use in source and binary forms, with or without
19* modification, are permitted provided that the following conditions
20* are met:
21*
22* 1. Redistributions of source code must retain the above copyright
23* notice, this list of conditions and the following disclaimer.
24*
25* 2. Redistributions in binary form must reproduce the above copyright
26* notice, this list of conditions and the following disclaimer in
27* the documentation and/or other materials provided with the
28* distribution.
29*
30* 3. In the absence of prior written permission, the names "ICC" and "The
31* International Color Consortium" must not be used to imply that the
32* ICC organization endorses or promotes products derived from this
33* software.
34*
35*
36* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39* DISCLAIMED. IN NO EVENT SHALL THE INTERNATIONAL COLOR CONSORTIUM OR
40* ITS CONTRIBUTING MEMBERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47* SUCH DAMAGE.
48* ====================================================================
49*
50* This software consists of voluntary contributions made by many
51* individuals on behalf of the The International Color Consortium.
52*
53*
54* Membership in the ICC is encouraged when this software is used for
55* commercial purposes.
56*
57*
58* For more information on The International Color Consortium, please
59* see <http://www.color.org/>.
60*
61*
62*/
63
64//////////////////////////////////////////////////////////////////////
65// HISTORY:
66//
67// -Initial implementation by Max Derhak 1-27-2013
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
82class CIccDefaultEncProfileCacheHandler : public IIccEncProfileCacheHandler
83{
84public:
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
97static IIccEncProfileCacheHandler* g_pEncProfileCacheHandler = NULL__null;
98
99IIccEncProfileCacheHandler *IIccEncProfileCacheHandler::GetHandler()
100{
101 if (!g_pEncProfileCacheHandler) {
102 g_pEncProfileCacheHandler = new CIccDefaultEncProfileCacheHandler();
103 }
104 return g_pEncProfileCacheHandler;
105}
106
107void IIccEncProfileCacheHandler::SetEncCacheHandler(IIccEncProfileCacheHandler *pHandler)
108{
109 if (pHandler) {
110 if (g_pEncProfileCacheHandler) {
111 delete g_pEncProfileCacheHandler;
112 }
113 g_pEncProfileCacheHandler = pHandler;
114 }
115}
116
117class CIccDefaultEncProfileConverter : public IIccEncProfileConverter
118{
119public:
120 CIccDefaultEncProfileConverter() {}
121
122 virtual icStatusEncConvert ConvertFromParams(CIccProfilePtr &newIcc, CIccTagStruct *pParams, icHeader *pHeader);
123};
124
125static 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
135static 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
142icStatusEncConvert CIccDefaultEncProfileConverter::ConvertFromParams(CIccProfilePtr &newIcc, CIccTagStruct *pParams, icHeader *pHeader)
143{
144 newIcc = NULL__null;
145
146 if (!pParams
18.1
'pParams' is non-null
|| pParams->GetTagStructType()!= icSigColorEncodingParamsSruct || !pHeader
19.1
'pHeader' is non-null
)
19
Assuming the condition is false
20
Taking false branch
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) {
21
Assuming 'pWhitePt' is non-null
22
Assuming the condition is false
23
Taking false branch
153 return icEncConvertBadParams;
154 }
155
156 if (!pMediaWhitePt)
24
Assuming 'pMediaWhitePt' is non-null
157 pMediaWhitePt = pWhitePt;
158
159 if (!pMediaWhitePt
24.1
'pMediaWhitePt' is non-null
|| pMediaWhitePt->GetNumValues()<2) {
25
Assuming the condition is false
26
Taking false branch
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 ); /* Get time as long integer. */
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 //Fill header from pParams
182 pIcc->m_Header.pcs = icSigXYZPcsDataicSigXYZData;
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 //Fill Media White Point tag
189 CIccTagXYZ *pXYZ = new CIccTagXYZ();
190 float XYZMedia[3];
191 icYxy2XYZVector(XYZMedia, 1.0f, &(*pMediaWhitePt)[0], 1);
192 if (!pXYZ->SetSize(1))
27
Assuming the condition is false
28
Taking false branch
193 return icEncConvertMemoryError;
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 //Create A2B tag from pParams
201 CIccTagMultiProcessElement *pMpeTag = (CIccTagMultiProcessElement*)CIccTag::Create(icSigMultiProcessElementType);
202 if (!pMpeTag) {
29
Assuming 'pMpeTag' is non-null
30
Taking false branch
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) {
31
Assuming 'pLumMtx' is null
32
Taking false branch
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()) {
33
Assuming 'pSegCurve' is null
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) {
34
Assuming 'pMtx' is non-null
35
Taking false branch
252 delete pMpeTag;
253 delete pIcc;
254 return icEncConvertMemoryError;
255 }
256
257 CIccTagFloat32 *pxy;
258 if (!pMtx->SetSize(3,3)) {
36
Assuming the condition is false
37
Taking false branch
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) {
38
Assuming 'pxy' is non-null
39
Assuming the condition is false
40
Taking false branch
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) {
41
Assuming 'pxy' is non-null
42
Assuming the condition is false
43
Taking false branch
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) {
44
Assuming 'pxy' is non-null
45
Assuming the condition is false
46
Taking false branch
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())) {
47
Assuming the condition is false
48
Taking false branch
302 delete pMtx2;
303 delete pIcc;
304 return icEncConvertBadParams;
305 }
306
307 //Create B2A tag from pParams
308 pMpeTag = (CIccTagMultiProcessElement*)CIccTag::Create(icSigMultiProcessElementType);
309 if (!pMpeTag) {
49
Assuming 'pMpeTag' is non-null
50
Taking false branch
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()) {
51
Assuming 'pSegCurve' is null
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
51.1
'bHaveLumMtx' is false
) {
52
Taking false branch
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 //Add ProfileConnectionConditions (if needed)
352 if (pIcc->m_Header.illuminant.X!=icDtoF(icD50XYZ[0]) ||
53
Assuming the condition is true
353 pIcc->m_Header.illuminant.Y!=icDtoF(icD50XYZ[1]) ||
354 pIcc->m_Header.illuminant.Z!=icDtoF(icD50XYZ[2])) {
355
356 //Set Spectral Viewing Conditions
357 CIccTagSpectralViewingConditions *pCond = (CIccTagSpectralViewingConditions*)CIccTag::Create(icSigSpectralViewingConditionsType);
358 if (!pCond) {
54
Assuming 'pCond' is non-null
55
Taking false branch
359 delete pIcc;
360 return icEncConvertMemoryError;
361 }
362
363 icFloatNumber illXYZ[3];
364 icFloatNumber Lw = pParams->GetElemNumberValue(icSigCeptWhitePointLuminanceMbr, 100);
365 pCond->setIlluminant(XYZWhite);
366 //pCond->m_stdIlluminant = icIlluminantCustom;
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) {
56
Assuming 'pSurround' is null
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
56.1
'pCstmConvert' is non-null
) {
57
Taking false branch
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) { //Average Surround
58
Assuming the condition is true
59
Taking true branch
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) { //Dim Surround
406 pCstmConvert->SetParameter_C(0.59f);
407 pCstmConvert->SetParameter_Nc(0.95f);
408 pCstmConvert->SetParameter_F(0.9f);
409 }
410 else { //Dark Surround
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
59.1
'pCstmConvert2' is non-null
) {
60
Taking false branch
418 delete pCstmConvert;
419 delete pIcc;
420 return icEncConvertMemoryError;
421 }
422 *pCstmConvert2 = *pCstmConvert;
423
424 //By default New CIccCamConverter objects are initialized with default PCS conditions
425 CIccCamConverter *pStdConvert = new CIccCamConverter();
426 if (!pStdConvert
60.1
'pStdConvert' is non-null
) {
61
Taking false branch
427 delete pCstmConvert;
428 delete pCstmConvert2;
429 delete pIcc;
430 return icEncConvertMemoryError;
431 }
432 CIccCamConverter *pStdConvert2 = new CIccCamConverter();
62
Memory is allocated
433 if (!pStdConvert2
62.1
'pStdConvert2' is non-null
) {
63
Taking false branch
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) {
64
Assuming 'pMpeTag' is non-null
65
Taking false branch
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) {
66
Assuming 'pCam' is non-null
67
Taking false branch
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) {
68
Assuming 'pCam' is non-null
69
Taking false branch
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) {
70
Assuming 'pMpeTag' is null
71
Taking true branch
479 delete pIcc;
72
Potential leak of memory pointed to by 'pStdConvert2'
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
513static IIccEncProfileConverter* g_pEncProfileConverter = NULL__null;
514
515IIccEncProfileConverter *IIccEncProfileConverter::GetHandler()
516{
517 if (!g_pEncProfileConverter) {
518 g_pEncProfileConverter = new CIccDefaultEncProfileConverter();
519 }
520 return g_pEncProfileConverter;
521}
522
523void 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
534icStatusEncConvert icConvertEncodingProfile(CIccProfilePtr &newIcc, CIccProfile *pEncodeIcc)
535{
536 newIcc = NULL__null;
537
538 if (!pEncodeIcc || pEncodeIcc->m_Header.deviceClass!=icSigColorEncodingClass)
1
Assuming 'pEncodeIcc' is non-null
2
Assuming field 'deviceClass' is equal to icSigColorEncodingClass
3
Taking false branch
539 return icEncConvertBadProfile;
540
541 CIccTag *pTag;
542 CIccTagStruct *pParams=NULL__null;
543 pTag = pEncodeIcc->FindTagOfType(icSigReferenceNameTag, icSigUtf8TextType);
544 if (pTag) {
4
Assuming 'pTag' is non-null
5
Taking true branch
545 CIccTagUtf8Text *pText = (CIccTagUtf8Text*)pTag;
546 const icUChar *szRefName = pText->GetText();
547 if (!strcmp((const char*)szRefName, "ISO 22028-1")) {
6
Assuming the condition is false
7
Taking false branch
548 pTag = pEncodeIcc->FindTagOfType(icSigColorEncodingParamsTag, icSigTagStructType);
549 if (pTag)
550 pParams = (CIccTagStruct*)pTag->NewCopy();
551 }
552 else {
553 CIccTag *pNameTag = pEncodeIcc->FindTagOfType(icSigColorSpaceNameTag, icSigUtf8TextType);
554 if (pNameTag) {
8
Assuming 'pNameTag' is non-null
9
Taking true branch
555 pText = (CIccTagUtf8Text *)pNameTag;
556 const icUChar *szName = pText->GetText();
557
558 CIccProfile *pBaseIcc = IIccEncProfileCacheHandler::GetHandler()->GetEncodingProfile(szName);
559 if (!pBaseIcc) {
10
Assuming 'pBaseIcc' is non-null
11
Taking false branch
560 return icEncConvertNoBaseProfile;
561 }
562
563 pTag = pBaseIcc->FindTagOfType(icSigColorEncodingParamsTag, icSigTagStructType);
564 if (!pTag) {
12
Assuming 'pTag' is non-null
13
Taking false branch
565 delete pBaseIcc;
566 return icEncConvertBadBaseProfile;
567 }
568 pParams = (CIccTagStruct*)pTag->NewCopy();
569 delete pBaseIcc;
570
571 //Now Copy Overrides into pParams (if they exist in pEncodeIcc
572 CIccTag *pOverridesTag = pEncodeIcc->FindTagOfType(icSigColorEncodingParamsTag, icSigTagStructType);
573 if (pOverridesTag) {
14
Assuming 'pOverridesTag' is null
15
Taking false branch
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) {
16
Assuming 'pParams' is non-null
17
Taking false branch
591 return icEncConvertBadProfile;
592 }
593
594 //Create and initialize new profile from pEncodeIcc and pParams
595 icStatusEncConvert stat = IIccEncProfileConverter::GetHandler()->ConvertFromParams(newIcc, pParams, &pEncodeIcc->m_Header);
18
Calling 'CIccDefaultEncProfileConverter::ConvertFromParams'
596
597 delete pParams;
598
599 return stat;
600}