Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: core/fxcodec/codec/fx_codec_icc.cpp

Issue 2032613003: Get rid of NULLs in core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: s/NULL/nullptr/ Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fxcodec/codec/codec_int.h" 7 #include "core/fxcodec/codec/codec_int.h"
8 #include "core/fxcodec/include/fx_codec.h" 8 #include "core/fxcodec/include/fx_codec.h"
9 #include "third_party/lcms2-2.6/include/lcms2.h" 9 #include "third_party/lcms2-2.6/include/lcms2.h"
10 10
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, 92 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData,
93 uint32_t dwSrcProfileSize, 93 uint32_t dwSrcProfileSize,
94 uint32_t& nSrcComponents, 94 uint32_t& nSrcComponents,
95 const unsigned char* pDstProfileData, 95 const unsigned char* pDstProfileData,
96 uint32_t dwDstProfileSize, 96 uint32_t dwDstProfileSize,
97 int32_t nDstComponents, 97 int32_t nDstComponents,
98 int intent, 98 int intent,
99 uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT, 99 uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT,
100 uint32_t dwDstFormat = Icc_FORMAT_DEFAULT) { 100 uint32_t dwDstFormat = Icc_FORMAT_DEFAULT) {
101 cmsHPROFILE srcProfile = NULL; 101 cmsHPROFILE srcProfile = nullptr;
Tom Sepez 2016/06/02 20:09:49 nit:combine with 106.
Lei Zhang 2016/06/07 07:33:23 Done.
102 cmsHPROFILE dstProfile = NULL; 102 cmsHPROFILE dstProfile = nullptr;
103 cmsHTRANSFORM hTransform = NULL; 103 cmsHTRANSFORM hTransform = nullptr;
104 CLcmsCmm* pCmm = NULL; 104 CLcmsCmm* pCmm = nullptr;
105 nSrcComponents = 0; 105 nSrcComponents = 0;
106 srcProfile = cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize); 106 srcProfile = cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize);
107 if (!srcProfile) { 107 if (!srcProfile) {
108 return NULL; 108 return nullptr;
109 } 109 }
110 if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) { 110 if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) {
111 dstProfile = cmsCreate_sRGBProfile(); 111 dstProfile = cmsCreate_sRGBProfile();
112 } else { 112 } else {
113 dstProfile = 113 dstProfile =
114 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize); 114 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize);
115 } 115 }
116 if (!dstProfile) { 116 if (!dstProfile) {
117 cmsCloseProfile(srcProfile); 117 cmsCloseProfile(srcProfile);
118 return NULL; 118 return nullptr;
119 } 119 }
120 int srcFormat; 120 int srcFormat;
121 FX_BOOL bLab = FALSE; 121 FX_BOOL bLab = FALSE;
122 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); 122 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile);
123 nSrcComponents = GetCSComponents(srcCS); 123 nSrcComponents = GetCSComponents(srcCS);
124 if (srcCS == cmsSigLabData) { 124 if (srcCS == cmsSigLabData) {
125 srcFormat = 125 srcFormat =
126 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0); 126 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0);
127 bLab = TRUE; 127 bLab = TRUE;
128 } else { 128 } else {
129 srcFormat = 129 srcFormat =
130 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1); 130 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1);
131 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { 131 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) {
132 srcFormat |= DOSWAP_SH(1); 132 srcFormat |= DOSWAP_SH(1);
133 } 133 }
134 } 134 }
135 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); 135 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile);
136 if (!CheckComponents(dstCS, nDstComponents, TRUE)) { 136 if (!CheckComponents(dstCS, nDstComponents, TRUE)) {
137 cmsCloseProfile(srcProfile); 137 cmsCloseProfile(srcProfile);
138 cmsCloseProfile(dstProfile); 138 cmsCloseProfile(dstProfile);
139 return NULL; 139 return nullptr;
140 } 140 }
141 switch (dstCS) { 141 switch (dstCS) {
142 case cmsSigGrayData: 142 case cmsSigGrayData:
143 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, 143 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile,
144 TYPE_GRAY_8, intent, 0); 144 TYPE_GRAY_8, intent, 0);
145 break; 145 break;
146 case cmsSigRgbData: 146 case cmsSigRgbData:
147 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, 147 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile,
148 TYPE_BGR_8, intent, 0); 148 TYPE_BGR_8, intent, 0);
149 break; 149 break;
150 case cmsSigCmykData: 150 case cmsSigCmykData:
151 hTransform = cmsCreateTransform( 151 hTransform = cmsCreateTransform(
152 srcProfile, srcFormat, dstProfile, 152 srcProfile, srcFormat, dstProfile,
153 T_DOSWAP(dwDstFormat) ? TYPE_KYMC_8 : TYPE_CMYK_8, intent, 0); 153 T_DOSWAP(dwDstFormat) ? TYPE_KYMC_8 : TYPE_CMYK_8, intent, 0);
154 break; 154 break;
155 default: 155 default:
156 break; 156 break;
157 } 157 }
158 if (!hTransform) { 158 if (!hTransform) {
159 cmsCloseProfile(srcProfile); 159 cmsCloseProfile(srcProfile);
160 cmsCloseProfile(dstProfile); 160 cmsCloseProfile(dstProfile);
161 return NULL; 161 return nullptr;
162 } 162 }
163 pCmm = new CLcmsCmm; 163 pCmm = new CLcmsCmm;
164 pCmm->m_nSrcComponents = nSrcComponents; 164 pCmm->m_nSrcComponents = nSrcComponents;
165 pCmm->m_nDstComponents = nDstComponents; 165 pCmm->m_nDstComponents = nDstComponents;
166 pCmm->m_hTransform = hTransform; 166 pCmm->m_hTransform = hTransform;
167 pCmm->m_bLab = bLab; 167 pCmm->m_bLab = bLab;
168 cmsCloseProfile(srcProfile); 168 cmsCloseProfile(srcProfile);
169 cmsCloseProfile(dstProfile); 169 cmsCloseProfile(dstProfile);
170 return pCmm; 170 return pCmm;
171 } 171 }
172 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, 172 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData,
173 uint32_t dwProfileSize, 173 uint32_t dwProfileSize,
174 uint32_t& nComponents, 174 uint32_t& nComponents,
175 int32_t intent, 175 int32_t intent,
176 uint32_t dwSrcFormat) { 176 uint32_t dwSrcFormat) {
177 return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, NULL, 177 return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents,
178 0, 3, intent, dwSrcFormat); 178 nullptr, 0, 3, intent, dwSrcFormat);
179 } 179 }
180 void IccLib_DestroyTransform(void* pTransform) { 180 void IccLib_DestroyTransform(void* pTransform) {
181 if (!pTransform) { 181 if (!pTransform) {
182 return; 182 return;
183 } 183 }
184 cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform); 184 cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform);
185 delete (CLcmsCmm*)pTransform; 185 delete (CLcmsCmm*)pTransform;
186 } 186 }
187 void IccLib_Translate(void* pTransform, 187 void IccLib_Translate(void* pTransform,
188 uint32_t nSrcComponents, 188 uint32_t nSrcComponents,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 void IccLib_TranslateImage(void* pTransform, 234 void IccLib_TranslateImage(void* pTransform,
235 unsigned char* pDest, 235 unsigned char* pDest,
236 const unsigned char* pSrc, 236 const unsigned char* pSrc,
237 int32_t pixels) { 237 int32_t pixels) {
238 cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, (void*)pSrc, pDest, 238 cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, (void*)pSrc, pDest,
239 pixels); 239 pixels);
240 } 240 }
241 void* CreateProfile_Gray(double gamma) { 241 void* CreateProfile_Gray(double gamma) {
242 cmsCIExyY* D50 = (cmsCIExyY*)cmsD50_xyY(); 242 cmsCIExyY* D50 = (cmsCIExyY*)cmsD50_xyY();
243 if (!cmsWhitePointFromTemp(D50, 6504)) { 243 if (!cmsWhitePointFromTemp(D50, 6504)) {
244 return NULL; 244 return nullptr;
245 } 245 }
246 cmsToneCurve* curve = cmsBuildGamma(NULL, gamma); 246 cmsToneCurve* curve = cmsBuildGamma(nullptr, gamma);
247 if (!curve) { 247 if (!curve) {
248 return NULL; 248 return nullptr;
249 } 249 }
250 void* profile = cmsCreateGrayProfile(D50, curve); 250 void* profile = cmsCreateGrayProfile(D50, curve);
251 cmsFreeToneCurve(curve); 251 cmsFreeToneCurve(curve);
252 return profile; 252 return profile;
253 } 253 }
254 CCodec_IccModule::IccCS GetProfileCSFromHandle(void* pProfile) { 254 CCodec_IccModule::IccCS GetProfileCSFromHandle(void* pProfile) {
255 if (!pProfile) { 255 if (!pProfile) {
256 return CCodec_IccModule::IccCS_Unknown; 256 return CCodec_IccModule::IccCS_Unknown;
257 } 257 }
258 switch (cmsGetColorSpace(pProfile)) { 258 switch (cmsGetColorSpace(pProfile)) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 public: 358 public:
359 CFX_IccProfileCache(); 359 CFX_IccProfileCache();
360 ~CFX_IccProfileCache(); 360 ~CFX_IccProfileCache();
361 void* m_pProfile; 361 void* m_pProfile;
362 uint32_t m_dwRate; 362 uint32_t m_dwRate;
363 363
364 protected: 364 protected:
365 void Purge(); 365 void Purge();
366 }; 366 };
367 CFX_IccProfileCache::CFX_IccProfileCache() { 367 CFX_IccProfileCache::CFX_IccProfileCache() {
368 m_pProfile = NULL; 368 m_pProfile = nullptr;
369 m_dwRate = 1; 369 m_dwRate = 1;
370 } 370 }
371 CFX_IccProfileCache::~CFX_IccProfileCache() { 371 CFX_IccProfileCache::~CFX_IccProfileCache() {
372 if (m_pProfile) { 372 if (m_pProfile) {
373 cmsCloseProfile(m_pProfile); 373 cmsCloseProfile(m_pProfile);
374 } 374 }
375 } 375 }
376 void CFX_IccProfileCache::Purge() {} 376 void CFX_IccProfileCache::Purge() {}
377 class CFX_IccTransformCache { 377 class CFX_IccTransformCache {
378 public: 378 public:
379 CFX_IccTransformCache(CLcmsCmm* pCmm = NULL); 379 CFX_IccTransformCache(CLcmsCmm* pCmm = nullptr);
380 ~CFX_IccTransformCache(); 380 ~CFX_IccTransformCache();
381 void* m_pIccTransform; 381 void* m_pIccTransform;
382 uint32_t m_dwRate; 382 uint32_t m_dwRate;
383 CLcmsCmm* m_pCmm; 383 CLcmsCmm* m_pCmm;
384 384
385 protected: 385 protected:
386 void Purge(); 386 void Purge();
387 }; 387 };
388 CFX_IccTransformCache::CFX_IccTransformCache(CLcmsCmm* pCmm) { 388 CFX_IccTransformCache::CFX_IccTransformCache(CLcmsCmm* pCmm) {
389 m_pIccTransform = NULL; 389 m_pIccTransform = nullptr;
390 m_dwRate = 1; 390 m_dwRate = 1;
391 m_pCmm = pCmm; 391 m_pCmm = pCmm;
392 } 392 }
393 CFX_IccTransformCache::~CFX_IccTransformCache() { 393 CFX_IccTransformCache::~CFX_IccTransformCache() {
394 if (m_pIccTransform) { 394 if (m_pIccTransform) {
395 cmsDeleteTransform(m_pIccTransform); 395 cmsDeleteTransform(m_pIccTransform);
396 } 396 }
397 FX_Free(m_pCmm); 397 FX_Free(m_pCmm);
398 } 398 }
399 void CFX_IccTransformCache::Purge() {} 399 void CFX_IccTransformCache::Purge() {}
400 class CFX_ByteStringKey : public CFX_BinaryBuf { 400 class CFX_ByteStringKey : public CFX_BinaryBuf {
401 public: 401 public:
402 CFX_ByteStringKey() : CFX_BinaryBuf() {} 402 CFX_ByteStringKey() : CFX_BinaryBuf() {}
403 CFX_ByteStringKey& operator<<(uint32_t i); 403 CFX_ByteStringKey& operator<<(uint32_t i);
404 }; 404 };
405 CFX_ByteStringKey& CFX_ByteStringKey::operator<<(uint32_t i) { 405 CFX_ByteStringKey& CFX_ByteStringKey::operator<<(uint32_t i) {
406 AppendBlock(&i, sizeof(uint32_t)); 406 AppendBlock(&i, sizeof(uint32_t));
407 return *this; 407 return *this;
408 } 408 }
409 void* CCodec_IccModule::CreateProfile(CCodec_IccModule::IccParam* pIccParam, 409 void* CCodec_IccModule::CreateProfile(CCodec_IccModule::IccParam* pIccParam,
410 Icc_CLASS ic, 410 Icc_CLASS ic,
411 CFX_BinaryBuf* pTransformKey) { 411 CFX_BinaryBuf* pTransformKey) {
412 CFX_IccProfileCache* pCache = NULL; 412 CFX_IccProfileCache* pCache = nullptr;
413 CFX_ByteStringKey key; 413 CFX_ByteStringKey key;
414 CFX_ByteString text; 414 CFX_ByteString text;
415 key << pIccParam->ColorSpace << (pIccParam->dwProfileType | ic << 8); 415 key << pIccParam->ColorSpace << (pIccParam->dwProfileType | ic << 8);
416 uint8_t ID[16]; 416 uint8_t ID[16];
417 switch (pIccParam->dwProfileType) { 417 switch (pIccParam->dwProfileType) {
418 case Icc_PARAMTYPE_NONE: 418 case Icc_PARAMTYPE_NONE:
419 return NULL; 419 return nullptr;
420 case Icc_PARAMTYPE_BUFFER: 420 case Icc_PARAMTYPE_BUFFER:
421 MD5ComputeID(pIccParam->pProfileData, pIccParam->dwProfileSize, ID); 421 MD5ComputeID(pIccParam->pProfileData, pIccParam->dwProfileSize, ID);
422 break; 422 break;
423 case Icc_PARAMTYPE_PARAM: 423 case Icc_PARAMTYPE_PARAM:
424 FXSYS_memset(ID, 0, 16); 424 FXSYS_memset(ID, 0, 16);
425 switch (pIccParam->ColorSpace) { 425 switch (pIccParam->ColorSpace) {
426 case IccCS_Gray: 426 case IccCS_Gray:
427 text.Format("%lf", pIccParam->Gamma); 427 text.Format("%lf", pIccParam->Gamma);
428 break; 428 break;
429 default: 429 default:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 return pCache->m_pProfile; 469 return pCache->m_pProfile;
470 } 470 }
471 void* CCodec_IccModule::CreateTransform( 471 void* CCodec_IccModule::CreateTransform(
472 CCodec_IccModule::IccParam* pInputParam, 472 CCodec_IccModule::IccParam* pInputParam,
473 CCodec_IccModule::IccParam* pOutputParam, 473 CCodec_IccModule::IccParam* pOutputParam,
474 CCodec_IccModule::IccParam* pProofParam, 474 CCodec_IccModule::IccParam* pProofParam,
475 uint32_t dwIntent, 475 uint32_t dwIntent,
476 uint32_t dwFlag, 476 uint32_t dwFlag,
477 uint32_t dwPrfIntent, 477 uint32_t dwPrfIntent,
478 uint32_t dwPrfFlag) { 478 uint32_t dwPrfFlag) {
479 CLcmsCmm* pCmm = NULL; 479 CLcmsCmm* pCmm = nullptr;
480 ASSERT(pInputParam && pOutputParam); 480 ASSERT(pInputParam && pOutputParam);
481 CFX_ByteStringKey key; 481 CFX_ByteStringKey key;
482 void* pInputProfile = CreateProfile(pInputParam, Icc_CLASS_INPUT, &key); 482 void* pInputProfile = CreateProfile(pInputParam, Icc_CLASS_INPUT, &key);
483 if (!pInputProfile) { 483 if (!pInputProfile) {
484 return NULL; 484 return nullptr;
485 } 485 }
486 void* pOutputProfile = CreateProfile(pOutputParam, Icc_CLASS_OUTPUT, &key); 486 void* pOutputProfile = CreateProfile(pOutputParam, Icc_CLASS_OUTPUT, &key);
487 if (!pOutputProfile) { 487 if (!pOutputProfile) {
488 return NULL; 488 return nullptr;
489 } 489 }
490 uint32_t dwInputProfileType = 490 uint32_t dwInputProfileType =
491 TransferProfileType(pInputProfile, pInputParam->dwFormat); 491 TransferProfileType(pInputProfile, pInputParam->dwFormat);
492 uint32_t dwOutputProfileType = 492 uint32_t dwOutputProfileType =
493 TransferProfileType(pOutputProfile, pOutputParam->dwFormat); 493 TransferProfileType(pOutputProfile, pOutputParam->dwFormat);
494 if (dwInputProfileType == 0 || dwOutputProfileType == 0) { 494 if (dwInputProfileType == 0 || dwOutputProfileType == 0) {
495 return NULL; 495 return nullptr;
496 } 496 }
497 void* pProofProfile = NULL; 497 void* pProofProfile = nullptr;
498 if (pProofParam) { 498 if (pProofParam) {
499 pProofProfile = CreateProfile(pProofParam, Icc_CLASS_PROOF, &key); 499 pProofProfile = CreateProfile(pProofParam, Icc_CLASS_PROOF, &key);
500 } 500 }
501 key << dwInputProfileType << dwOutputProfileType << dwIntent << dwFlag 501 key << dwInputProfileType << dwOutputProfileType << dwIntent << dwFlag
502 << (pProofProfile != NULL) << dwPrfIntent << dwPrfFlag; 502 << !!pProofProfile << dwPrfIntent << dwPrfFlag;
503 CFX_ByteString TransformKey(key.GetBuffer(), key.GetSize()); 503 CFX_ByteString TransformKey(key.GetBuffer(), key.GetSize());
504 CFX_IccTransformCache* pTransformCache; 504 CFX_IccTransformCache* pTransformCache;
505 auto it = m_MapTranform.find(TransformKey); 505 auto it = m_MapTranform.find(TransformKey);
506 if (it == m_MapTranform.end()) { 506 if (it == m_MapTranform.end()) {
507 pCmm = FX_Alloc(CLcmsCmm, 1); 507 pCmm = FX_Alloc(CLcmsCmm, 1);
508 pCmm->m_nSrcComponents = T_CHANNELS(dwInputProfileType); 508 pCmm->m_nSrcComponents = T_CHANNELS(dwInputProfileType);
509 pCmm->m_nDstComponents = T_CHANNELS(dwOutputProfileType); 509 pCmm->m_nDstComponents = T_CHANNELS(dwOutputProfileType);
510 pCmm->m_bLab = T_COLORSPACE(pInputParam->dwFormat) == PT_Lab; 510 pCmm->m_bLab = T_COLORSPACE(pInputParam->dwFormat) == PT_Lab;
511 pTransformCache = new CFX_IccTransformCache(pCmm); 511 pTransformCache = new CFX_IccTransformCache(pCmm);
512 if (pProofProfile) { 512 if (pProofProfile) {
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 uint8_t c1 = FXSYS_round(c * 255); 1977 uint8_t c1 = FXSYS_round(c * 255);
1978 uint8_t m1 = FXSYS_round(m * 255); 1978 uint8_t m1 = FXSYS_round(m * 255);
1979 uint8_t y1 = FXSYS_round(y * 255); 1979 uint8_t y1 = FXSYS_round(y * 255);
1980 uint8_t k1 = FXSYS_round(k * 255); 1980 uint8_t k1 = FXSYS_round(k * 255);
1981 uint8_t r, g, b; 1981 uint8_t r, g, b;
1982 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); 1982 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b);
1983 R = 1.0f * r / 255; 1983 R = 1.0f * r / 255;
1984 G = 1.0f * g / 255; 1984 G = 1.0f * g / 255;
1985 B = 1.0f * b / 255; 1985 B = 1.0f * b / 255;
1986 } 1986 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698