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

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

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase Created 5 years 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
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_flate.cpp ('k') | core/src/fxcodec/codec/fx_codec_jpeg.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "codec_int.h" 7 #include "codec_int.h"
8 #include "core/include/fxcodec/fx_codec.h" 8 #include "core/include/fxcodec/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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 int32_t nDstComponents, 95 int32_t nDstComponents,
96 int intent, 96 int intent,
97 FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT, 97 FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT,
98 FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT) { 98 FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT) {
99 cmsHPROFILE srcProfile = NULL; 99 cmsHPROFILE srcProfile = NULL;
100 cmsHPROFILE dstProfile = NULL; 100 cmsHPROFILE dstProfile = NULL;
101 cmsHTRANSFORM hTransform = NULL; 101 cmsHTRANSFORM hTransform = NULL;
102 CLcmsCmm* pCmm = NULL; 102 CLcmsCmm* pCmm = NULL;
103 nSrcComponents = 0; 103 nSrcComponents = 0;
104 srcProfile = cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize); 104 srcProfile = cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize);
105 if (srcProfile == NULL) { 105 if (!srcProfile) {
106 return NULL; 106 return NULL;
107 } 107 }
108 if (pDstProfileData == NULL && dwDstProfileSize == 0 && nDstComponents == 3) { 108 if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) {
109 dstProfile = cmsCreate_sRGBProfile(); 109 dstProfile = cmsCreate_sRGBProfile();
110 } else { 110 } else {
111 dstProfile = 111 dstProfile =
112 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize); 112 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize);
113 } 113 }
114 if (dstProfile == NULL) { 114 if (!dstProfile) {
115 cmsCloseProfile(srcProfile); 115 cmsCloseProfile(srcProfile);
116 return NULL; 116 return NULL;
117 } 117 }
118 int srcFormat; 118 int srcFormat;
119 FX_BOOL bLab = FALSE; 119 FX_BOOL bLab = FALSE;
120 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); 120 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile);
121 nSrcComponents = GetCSComponents(srcCS); 121 nSrcComponents = GetCSComponents(srcCS);
122 if (srcCS == cmsSigLabData) { 122 if (srcCS == cmsSigLabData) {
123 srcFormat = 123 srcFormat =
124 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0); 124 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0);
(...skipping 21 matching lines...) Expand all
146 TYPE_BGR_8, intent, 0); 146 TYPE_BGR_8, intent, 0);
147 break; 147 break;
148 case cmsSigCmykData: 148 case cmsSigCmykData:
149 hTransform = cmsCreateTransform( 149 hTransform = cmsCreateTransform(
150 srcProfile, srcFormat, dstProfile, 150 srcProfile, srcFormat, dstProfile,
151 T_DOSWAP(dwDstFormat) ? TYPE_KYMC_8 : TYPE_CMYK_8, intent, 0); 151 T_DOSWAP(dwDstFormat) ? TYPE_KYMC_8 : TYPE_CMYK_8, intent, 0);
152 break; 152 break;
153 default: 153 default:
154 break; 154 break;
155 } 155 }
156 if (hTransform == NULL) { 156 if (!hTransform) {
157 cmsCloseProfile(srcProfile); 157 cmsCloseProfile(srcProfile);
158 cmsCloseProfile(dstProfile); 158 cmsCloseProfile(dstProfile);
159 return NULL; 159 return NULL;
160 } 160 }
161 pCmm = new CLcmsCmm; 161 pCmm = new CLcmsCmm;
162 pCmm->m_nSrcComponents = nSrcComponents; 162 pCmm->m_nSrcComponents = nSrcComponents;
163 pCmm->m_nDstComponents = nDstComponents; 163 pCmm->m_nDstComponents = nDstComponents;
164 pCmm->m_hTransform = hTransform; 164 pCmm->m_hTransform = hTransform;
165 pCmm->m_bLab = bLab; 165 pCmm->m_bLab = bLab;
166 cmsCloseProfile(srcProfile); 166 cmsCloseProfile(srcProfile);
167 cmsCloseProfile(dstProfile); 167 cmsCloseProfile(dstProfile);
168 return pCmm; 168 return pCmm;
169 } 169 }
170 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, 170 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData,
171 FX_DWORD dwProfileSize, 171 FX_DWORD dwProfileSize,
172 int32_t& nComponents, 172 int32_t& nComponents,
173 int32_t intent, 173 int32_t intent,
174 FX_DWORD dwSrcFormat) { 174 FX_DWORD dwSrcFormat) {
175 return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, NULL, 175 return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, NULL,
176 0, 3, intent, dwSrcFormat); 176 0, 3, intent, dwSrcFormat);
177 } 177 }
178 void IccLib_DestroyTransform(void* pTransform) { 178 void IccLib_DestroyTransform(void* pTransform) {
179 if (pTransform == NULL) { 179 if (!pTransform) {
180 return; 180 return;
181 } 181 }
182 cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform); 182 cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform);
183 delete (CLcmsCmm*)pTransform; 183 delete (CLcmsCmm*)pTransform;
184 } 184 }
185 void IccLib_Translate(void* pTransform, 185 void IccLib_Translate(void* pTransform,
186 FX_DWORD nSrcComponents, 186 FX_DWORD nSrcComponents,
187 FX_FLOAT* pSrcValues, 187 FX_FLOAT* pSrcValues,
188 FX_FLOAT* pDestValues) { 188 FX_FLOAT* pDestValues) {
189 if (pTransform == NULL) { 189 if (!pTransform) {
190 return; 190 return;
191 } 191 }
192 CLcmsCmm* p = (CLcmsCmm*)pTransform; 192 CLcmsCmm* p = (CLcmsCmm*)pTransform;
193 uint8_t output[4]; 193 uint8_t output[4];
194 if (p->m_bLab) { 194 if (p->m_bLab) {
195 CFX_FixedBufGrow<double, 16> inputs(nSrcComponents); 195 CFX_FixedBufGrow<double, 16> inputs(nSrcComponents);
196 double* input = inputs; 196 double* input = inputs;
197 for (FX_DWORD i = 0; i < nSrcComponents; i++) { 197 for (FX_DWORD i = 0; i < nSrcComponents; i++) {
198 input[i] = pSrcValues[i]; 198 input[i] = pSrcValues[i];
199 } 199 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 int32_t pixels) { 235 int32_t pixels) {
236 cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, (void*)pSrc, pDest, 236 cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, (void*)pSrc, pDest,
237 pixels); 237 pixels);
238 } 238 }
239 void* CreateProfile_Gray(double gamma) { 239 void* CreateProfile_Gray(double gamma) {
240 cmsCIExyY* D50 = (cmsCIExyY*)cmsD50_xyY(); 240 cmsCIExyY* D50 = (cmsCIExyY*)cmsD50_xyY();
241 if (!cmsWhitePointFromTemp(D50, 6504)) { 241 if (!cmsWhitePointFromTemp(D50, 6504)) {
242 return NULL; 242 return NULL;
243 } 243 }
244 cmsToneCurve* curve = cmsBuildGamma(NULL, gamma); 244 cmsToneCurve* curve = cmsBuildGamma(NULL, gamma);
245 if (curve == NULL) { 245 if (!curve) {
246 return NULL; 246 return NULL;
247 } 247 }
248 void* profile = cmsCreateGrayProfile(D50, curve); 248 void* profile = cmsCreateGrayProfile(D50, curve);
249 cmsFreeToneCurve(curve); 249 cmsFreeToneCurve(curve);
250 return profile; 250 return profile;
251 } 251 }
252 ICodec_IccModule::IccCS GetProfileCSFromHandle(void* pProfile) { 252 ICodec_IccModule::IccCS GetProfileCSFromHandle(void* pProfile) {
253 if (pProfile == NULL) { 253 if (!pProfile) {
254 return ICodec_IccModule::IccCS_Unknown; 254 return ICodec_IccModule::IccCS_Unknown;
255 } 255 }
256 switch (cmsGetColorSpace(pProfile)) { 256 switch (cmsGetColorSpace(pProfile)) {
257 case cmsSigXYZData: 257 case cmsSigXYZData:
258 return ICodec_IccModule::IccCS_XYZ; 258 return ICodec_IccModule::IccCS_XYZ;
259 case cmsSigLabData: 259 case cmsSigLabData:
260 return ICodec_IccModule::IccCS_Lab; 260 return ICodec_IccModule::IccCS_Lab;
261 case cmsSigLuvData: 261 case cmsSigLuvData:
262 return ICodec_IccModule::IccCS_Luv; 262 return ICodec_IccModule::IccCS_Luv;
263 case cmsSigYCbCrData: 263 case cmsSigYCbCrData:
(...skipping 15 matching lines...) Expand all
279 default: 279 default:
280 return ICodec_IccModule::IccCS_Unknown; 280 return ICodec_IccModule::IccCS_Unknown;
281 } 281 }
282 } 282 }
283 ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS( 283 ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS(
284 const uint8_t* pProfileData, 284 const uint8_t* pProfileData,
285 FX_DWORD dwProfileSize) { 285 FX_DWORD dwProfileSize) {
286 ICodec_IccModule::IccCS cs; 286 ICodec_IccModule::IccCS cs;
287 cmsHPROFILE hProfile = 287 cmsHPROFILE hProfile =
288 cmsOpenProfileFromMem((void*)pProfileData, dwProfileSize); 288 cmsOpenProfileFromMem((void*)pProfileData, dwProfileSize);
289 if (hProfile == NULL) { 289 if (!hProfile) {
290 return IccCS_Unknown; 290 return IccCS_Unknown;
291 } 291 }
292 cs = GetProfileCSFromHandle(hProfile); 292 cs = GetProfileCSFromHandle(hProfile);
293 if (hProfile) { 293 if (hProfile) {
294 cmsCloseProfile(hProfile); 294 cmsCloseProfile(hProfile);
295 } 295 }
296 return cs; 296 return cs;
297 } 297 }
298 ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS(IFX_FileRead* pFile) { 298 ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS(IFX_FileRead* pFile) {
299 if (pFile == NULL) { 299 if (!pFile) {
300 return IccCS_Unknown; 300 return IccCS_Unknown;
301 } 301 }
302 ICodec_IccModule::IccCS cs; 302 ICodec_IccModule::IccCS cs;
303 FX_DWORD dwSize = (FX_DWORD)pFile->GetSize(); 303 FX_DWORD dwSize = (FX_DWORD)pFile->GetSize();
304 uint8_t* pBuf = FX_Alloc(uint8_t, dwSize); 304 uint8_t* pBuf = FX_Alloc(uint8_t, dwSize);
305 pFile->ReadBlock(pBuf, 0, dwSize); 305 pFile->ReadBlock(pBuf, 0, dwSize);
306 cs = GetProfileCS(pBuf, dwSize); 306 cs = GetProfileCS(pBuf, dwSize);
307 FX_Free(pBuf); 307 FX_Free(pBuf);
308 return cs; 308 return cs;
309 } 309 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 ICodec_IccModule::IccParam* pOutputParam, 469 ICodec_IccModule::IccParam* pOutputParam,
470 ICodec_IccModule::IccParam* pProofParam, 470 ICodec_IccModule::IccParam* pProofParam,
471 FX_DWORD dwIntent, 471 FX_DWORD dwIntent,
472 FX_DWORD dwFlag, 472 FX_DWORD dwFlag,
473 FX_DWORD dwPrfIntent, 473 FX_DWORD dwPrfIntent,
474 FX_DWORD dwPrfFlag) { 474 FX_DWORD dwPrfFlag) {
475 CLcmsCmm* pCmm = NULL; 475 CLcmsCmm* pCmm = NULL;
476 ASSERT(pInputParam && pOutputParam); 476 ASSERT(pInputParam && pOutputParam);
477 CFX_ByteStringKey key; 477 CFX_ByteStringKey key;
478 void* pInputProfile = CreateProfile(pInputParam, Icc_CLASS_INPUT, &key); 478 void* pInputProfile = CreateProfile(pInputParam, Icc_CLASS_INPUT, &key);
479 if (pInputProfile == NULL) { 479 if (!pInputProfile) {
480 return NULL; 480 return NULL;
481 } 481 }
482 void* pOutputProfile = CreateProfile(pOutputParam, Icc_CLASS_OUTPUT, &key); 482 void* pOutputProfile = CreateProfile(pOutputParam, Icc_CLASS_OUTPUT, &key);
483 if (pOutputProfile == NULL) { 483 if (!pOutputProfile) {
484 return NULL; 484 return NULL;
485 } 485 }
486 FX_DWORD dwInputProfileType = 486 FX_DWORD dwInputProfileType =
487 TransferProfileType(pInputProfile, pInputParam->dwFormat); 487 TransferProfileType(pInputProfile, pInputParam->dwFormat);
488 FX_DWORD dwOutputProfileType = 488 FX_DWORD dwOutputProfileType =
489 TransferProfileType(pOutputProfile, pOutputParam->dwFormat); 489 TransferProfileType(pOutputProfile, pOutputParam->dwFormat);
490 if (dwInputProfileType == 0 || dwOutputProfileType == 0) { 490 if (dwInputProfileType == 0 || dwOutputProfileType == 0) {
491 return NULL; 491 return NULL;
492 } 492 }
493 void* pProofProfile = NULL; 493 void* pProofProfile = NULL;
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 uint8_t c1 = FXSYS_round(c * 255); 1971 uint8_t c1 = FXSYS_round(c * 255);
1972 uint8_t m1 = FXSYS_round(m * 255); 1972 uint8_t m1 = FXSYS_round(m * 255);
1973 uint8_t y1 = FXSYS_round(y * 255); 1973 uint8_t y1 = FXSYS_round(y * 255);
1974 uint8_t k1 = FXSYS_round(k * 255); 1974 uint8_t k1 = FXSYS_round(k * 255);
1975 uint8_t r, g, b; 1975 uint8_t r, g, b;
1976 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); 1976 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b);
1977 R = 1.0f * r / 255; 1977 R = 1.0f * r / 255;
1978 G = 1.0f * g / 255; 1978 G = 1.0f * g / 255;
1979 B = 1.0f * b / 255; 1979 B = 1.0f * b / 255;
1980 } 1980 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_flate.cpp ('k') | core/src/fxcodec/codec/fx_codec_jpeg.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698