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

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

Issue 493163003: Use number of components from ICC profile and alternateCS (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 3 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 "../../../include/fxcodec/fx_codec.h" 7 #include "../../../include/fxcodec/fx_codec.h"
8 #include "codec_int.h" 8 #include "codec_int.h"
9 #include "../lcms2/include/fx_lcms2.h" 9 #include "../lcms2/include/fx_lcms2.h"
10 #define N_COMPONENT_LAB 3
jun_fang 2014/08/25 18:56:51 It's better to use const variables rather than mac
Bo Xu 2014/08/25 20:28:18 Done.
11 #define N_COMPONENT_GRAY 1
12 #define N_COMPONENT_RGB 3
13 #define N_COMPONENT_CMYK 4
14 #define N_COMPONENT_DEFAULT 3
15
10 FX_BOOL MD5ComputeID( FX_LPCVOID buf, FX_DWORD dwSize, FX_BYTE ID[16] ) 16 FX_BOOL MD5ComputeID( FX_LPCVOID buf, FX_DWORD dwSize, FX_BYTE ID[16] )
11 { 17 {
12 return cmsMD5computeIDExt(buf, dwSize, ID); 18 return cmsMD5computeIDExt(buf, dwSize, ID);
13 } 19 }
14 struct CLcmsCmm : public CFX_Object { 20 struct CLcmsCmm : public CFX_Object {
15 cmsHTRANSFORM m_hTransform; 21 cmsHTRANSFORM m_hTransform;
16 int m_nSrcComponents; 22 int m_nSrcComponents;
17 int m_nDstComponents; 23 int m_nDstComponents;
18 FX_BOOL m_bLab; 24 FX_BOOL m_bLab;
19 }; 25 };
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 58 }
53 break; 59 break;
54 default: 60 default:
55 if (nComponents != 3) { 61 if (nComponents != 3) {
56 return FALSE; 62 return FALSE;
57 } 63 }
58 break; 64 break;
59 } 65 }
60 return TRUE; 66 return TRUE;
61 } 67 }
62 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, unsigned int dwSrcProfileSize, int nSrcComponents, 68 FX_INT32 GetCSComponents(cmsColorSpaceSignature cs)
63 const unsigned char* pDstProfileData, unsigned int dwDstProfileSize, int nDstComponents, 69 {
jun_fang 2014/08/25 18:56:51 FX_DWORD components = N_COMPONENT_DEFAULT;
Bo Xu 2014/08/25 20:28:18 Done.
70 switch (cs) {
71 case cmsSigLabData:
72 return N_COMPONENT_LAB;
jun_fang 2014/08/25 18:56:51 use |components = N_COMPONENT_LAB| to replace the
73 break;
74 case cmsSigGrayData:
75 return N_COMPONENT_GRAY;
76 break;
77 case cmsSigRgbData:
78 return N_COMPONENT_RGB;
79 break;
80 case cmsSigCmykData:
81 return N_COMPONENT_CMYK;
82 break;
83 default:
84 return N_COMPONENT_DEFAULT;
85 break;
86 }
jun_fang 2014/08/25 18:56:51 return components;
87 }
88 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, FX_DWORD dwSr cProfileSize, FX_INT32* nSrcComponents,
89 const unsigned char* pDstProfileData, FX_DWORD dwDs tProfileSize, FX_INT32 nDstComponents,
64 int intent, FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAU LT, FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT) 90 int intent, FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAU LT, FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT)
65 { 91 {
66 cmsHPROFILE srcProfile = NULL; 92 cmsHPROFILE srcProfile = NULL;
67 cmsHPROFILE dstProfile = NULL; 93 cmsHPROFILE dstProfile = NULL;
68 cmsHTRANSFORM hTransform = NULL; 94 cmsHTRANSFORM hTransform = NULL;
69 CLcmsCmm* pCmm = NULL; 95 CLcmsCmm* pCmm = NULL;
96 *nSrcComponents = 0;
jun_fang 2014/08/25 18:56:51 Need to check whether nSrcComponents is NULL.
Bo Xu 2014/08/25 20:28:18 I have changed nSrcComponents from pointer to refe
70 srcProfile = cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize) ; 97 srcProfile = cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize) ;
71 if (srcProfile == NULL) { 98 if (srcProfile == NULL) {
72 return NULL; 99 return NULL;
73 } 100 }
74 if(pDstProfileData == NULL && dwDstProfileSize == 0 && nDstComponents == 3) { 101 if(pDstProfileData == NULL && dwDstProfileSize == 0 && nDstComponents == 3) {
75 dstProfile = cmsCreate_sRGBProfile(); 102 dstProfile = cmsCreate_sRGBProfile();
76 } else { 103 } else {
77 dstProfile = cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileS ize); 104 dstProfile = cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileS ize);
78 } 105 }
79 if (dstProfile == NULL) { 106 if (dstProfile == NULL) {
80 cmsCloseProfile(srcProfile); 107 cmsCloseProfile(srcProfile);
81 return NULL; 108 return NULL;
82 } 109 }
83 int srcFormat; 110 int srcFormat;
84 FX_BOOL bLab = FALSE; 111 FX_BOOL bLab = FALSE;
85 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); 112 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile);
86 if (!CheckComponents(srcCS, nSrcComponents, FALSE)) { 113 *nSrcComponents = GetCSComponents(srcCS);
87 cmsCloseProfile(srcProfile);
88 cmsCloseProfile(dstProfile);
89 return NULL;
90 }
91 if (srcCS == cmsSigLabData) { 114 if (srcCS == cmsSigLabData) {
92 srcFormat = COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_ SH(0); 115 srcFormat = COLORSPACE_SH(PT_Lab) | CHANNELS_SH(*nSrcComponents) | BYTES _SH(0);
93 bLab = TRUE; 116 bLab = TRUE;
94 } else { 117 } else {
95 srcFormat = COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_ SH(1); 118 srcFormat = COLORSPACE_SH(PT_ANY) | CHANNELS_SH(*nSrcComponents) | BYTES _SH(1);
96 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { 119 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) {
97 srcFormat |= DOSWAP_SH(1); 120 srcFormat |= DOSWAP_SH(1);
98 } 121 }
99 } 122 }
100 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); 123 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile);
101 if (!CheckComponents(dstCS, nDstComponents, TRUE)) { 124 if (!CheckComponents(dstCS, nDstComponents, TRUE)) {
102 cmsCloseProfile(srcProfile); 125 cmsCloseProfile(srcProfile);
103 cmsCloseProfile(dstProfile); 126 cmsCloseProfile(dstProfile);
104 return NULL; 127 return NULL;
105 } 128 }
(...skipping 14 matching lines...) Expand all
120 } 143 }
121 if (hTransform == NULL) { 144 if (hTransform == NULL) {
122 cmsCloseProfile(srcProfile); 145 cmsCloseProfile(srcProfile);
123 cmsCloseProfile(dstProfile); 146 cmsCloseProfile(dstProfile);
124 return NULL; 147 return NULL;
125 } 148 }
126 pCmm = FX_NEW CLcmsCmm; 149 pCmm = FX_NEW CLcmsCmm;
127 if (pCmm == NULL) { 150 if (pCmm == NULL) {
128 return NULL; 151 return NULL;
129 } 152 }
130 pCmm->m_nSrcComponents = nSrcComponents; 153 pCmm->m_nSrcComponents = *nSrcComponents;
131 pCmm->m_nDstComponents = nDstComponents; 154 pCmm->m_nDstComponents = nDstComponents;
132 pCmm->m_hTransform = hTransform; 155 pCmm->m_hTransform = hTransform;
133 pCmm->m_bLab = bLab; 156 pCmm->m_bLab = bLab;
134 cmsCloseProfile(srcProfile); 157 cmsCloseProfile(srcProfile);
135 cmsCloseProfile(dstProfile); 158 cmsCloseProfile(dstProfile);
136 return pCmm; 159 return pCmm;
137 } 160 }
138 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, unsigned in t dwProfileSize, int nComponents, int intent, FX_DWORD dwSrcFormat) 161 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, FX_DWORD dw ProfileSize, FX_INT32* nComponents, FX_INT32 intent, FX_DWORD dwSrcFormat)
139 { 162 {
140 return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, NULL , 0, 3, intent, dwSrcFormat); 163 return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, NULL , 0, 3, intent, dwSrcFormat);
141 } 164 }
142 void IccLib_DestroyTransform(void* pTransform) 165 void IccLib_DestroyTransform(void* pTransform)
143 { 166 {
144 if (pTransform == NULL) { 167 if (pTransform == NULL) {
145 return; 168 return;
146 } 169 }
147 cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform); 170 cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform);
148 delete (CLcmsCmm*)pTransform; 171 delete (CLcmsCmm*)pTransform;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 pDestValues[2] = output[0] / 255.0f; 208 pDestValues[2] = output[0] / 255.0f;
186 break; 209 break;
187 case 4: 210 case 4:
188 pDestValues[0] = output[0] / 255.0f; 211 pDestValues[0] = output[0] / 255.0f;
189 pDestValues[1] = output[1] / 255.0f; 212 pDestValues[1] = output[1] / 255.0f;
190 pDestValues[2] = output[2] / 255.0f; 213 pDestValues[2] = output[2] / 255.0f;
191 pDestValues[3] = output[3] / 255.0f; 214 pDestValues[3] = output[3] / 255.0f;
192 break; 215 break;
193 } 216 }
194 } 217 }
195 void IccLib_TranslateImage(void* pTransform, unsigned char* pDest, const unsigne d char* pSrc, int pixels) 218 void IccLib_TranslateImage(void* pTransform, unsigned char* pDest, const unsigne d char* pSrc, FX_INT32 pixels)
196 { 219 {
197 cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, (void*)pSrc, pDest, pi xels); 220 cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, (void*)pSrc, pDest, pi xels);
198 } 221 }
199 FX_LPVOID CreateProfile_Gray(double gamma) 222 FX_LPVOID CreateProfile_Gray(double gamma)
200 { 223 {
201 cmsCIExyY* D50 = (cmsCIExyY*)cmsD50_xyY(); 224 cmsCIExyY* D50 = (cmsCIExyY*)cmsD50_xyY();
202 if (!cmsWhitePointFromTemp(D50, 6504)) { 225 if (!cmsWhitePointFromTemp(D50, 6504)) {
203 return NULL; 226 return NULL;
204 } 227 }
205 cmsToneCurve* curve = cmsBuildGamma(NULL, gamma); 228 cmsToneCurve* curve = cmsBuildGamma(NULL, gamma);
(...skipping 29 matching lines...) Expand all
235 case cmsSigHlsData: 258 case cmsSigHlsData:
236 return ICodec_IccModule::IccCS_Hls; 259 return ICodec_IccModule::IccCS_Hls;
237 case cmsSigCmykData: 260 case cmsSigCmykData:
238 return ICodec_IccModule::IccCS_Cmyk; 261 return ICodec_IccModule::IccCS_Cmyk;
239 case cmsSigCmyData: 262 case cmsSigCmyData:
240 return ICodec_IccModule::IccCS_Cmy; 263 return ICodec_IccModule::IccCS_Cmy;
241 default: 264 default:
242 return ICodec_IccModule::IccCS_Unknown; 265 return ICodec_IccModule::IccCS_Unknown;
243 } 266 }
244 } 267 }
245 ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS(FX_LPCBYTE pProfileData, unsigned int dwProfileSize) 268 ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS(FX_LPCBYTE pProfileData, FX_DWORD dwProfileSize)
246 { 269 {
247 ICodec_IccModule::IccCS cs; 270 ICodec_IccModule::IccCS cs;
248 cmsHPROFILE hProfile = cmsOpenProfileFromMem((void*)pProfileData, dwProfileS ize); 271 cmsHPROFILE hProfile = cmsOpenProfileFromMem((void*)pProfileData, dwProfileS ize);
249 if (hProfile == NULL) { 272 if (hProfile == NULL) {
250 return IccCS_Unknown; 273 return IccCS_Unknown;
251 } 274 }
252 cs = GetProfileCSFromHandle(hProfile); 275 cs = GetProfileCSFromHandle(hProfile);
253 if (hProfile) { 276 if (hProfile) {
254 cmsCloseProfile(hProfile); 277 cmsCloseProfile(hProfile);
255 } 278 }
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } 533 }
511 pos = m_MapTranform.GetStartPosition(); 534 pos = m_MapTranform.GetStartPosition();
512 CFX_IccTransformCache* pTransformCache; 535 CFX_IccTransformCache* pTransformCache;
513 while (pos) { 536 while (pos) {
514 m_MapTranform.GetNextAssoc(pos, key, (FX_LPVOID&)pTransformCache); 537 m_MapTranform.GetNextAssoc(pos, key, (FX_LPVOID&)pTransformCache);
515 if (pTransformCache) { 538 if (pTransformCache) {
516 delete pTransformCache; 539 delete pTransformCache;
517 } 540 }
518 } 541 }
519 } 542 }
520 void* CCodec_IccModule::CreateTransform_sRGB(FX_LPCBYTE pProfileData, unsigned i nt dwProfileSize, int nComponents, int intent, FX_DWORD dwSrcFormat) 543 void* CCodec_IccModule::CreateTransform_sRGB(FX_LPCBYTE pProfileData, FX_DWORD d wProfileSize, FX_INT32* nComponents, FX_INT32 intent, FX_DWORD dwSrcFormat)
521 { 544 {
522 return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents, intent, dwSrcFormat); 545 return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents, intent, dwSrcFormat);
523 } 546 }
524 void* CCodec_IccModule::CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, unsigne d int dwSrcProfileSize, int nSrcComponents, 547 void* CCodec_IccModule::CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, FX_DWOR D dwSrcProfileSize, FX_INT32* nSrcComponents,
525 FX_LPCBYTE pDstProfileData, unsigned int dwDstProfileSize, int intent, 548 FX_LPCBYTE pDstProfileData, FX_DWORD dwDstProfileSize, FX_INT32 intent,
526 FX_DWORD dwSrcFormat , FX_DWORD dwDstFormat) 549 FX_DWORD dwSrcFormat , FX_DWORD dwDstFormat)
527 { 550 {
528 return IccLib_CreateTransform(pSrcProfileData, dwSrcProfileSize, nSrcCompone nts, 551 return IccLib_CreateTransform(pSrcProfileData, dwSrcProfileSize, nSrcCompone nts,
529 pDstProfileData, dwDstProfileSize, 4, intent, dwSrcFormat, dwDstFormat); 552 pDstProfileData, dwDstProfileSize, 4, intent, dwSrcFormat, dwDstFormat);
530 } 553 }
531 void CCodec_IccModule::DestroyTransform(void* pTransform) 554 void CCodec_IccModule::DestroyTransform(void* pTransform)
532 { 555 {
533 IccLib_DestroyTransform(pTransform); 556 IccLib_DestroyTransform(pTransform);
534 } 557 }
535 void CCodec_IccModule::Translate(void* pTransform, FX_FLOAT* pSrcValues, FX_FLOA T* pDestValues) 558 void CCodec_IccModule::Translate(void* pTransform, FX_FLOAT* pSrcValues, FX_FLOA T* pDestValues)
536 { 559 {
537 IccLib_Translate(pTransform, m_nComponents, pSrcValues, pDestValues); 560 IccLib_Translate(pTransform, m_nComponents, pSrcValues, pDestValues);
538 } 561 }
539 void CCodec_IccModule::TranslateScanline(void* pTransform, FX_LPBYTE pDest, FX_L PCBYTE pSrc, int pixels) 562 void CCodec_IccModule::TranslateScanline(void* pTransform, FX_LPBYTE pDest, FX_L PCBYTE pSrc, FX_INT32 pixels)
540 { 563 {
541 IccLib_TranslateImage(pTransform, pDest, pSrc, pixels); 564 IccLib_TranslateImage(pTransform, pDest, pSrc, pixels);
542 } 565 }
543 const FX_BYTE g_CMYKSamples[81 * 81 * 3] = { 566 const FX_BYTE g_CMYKSamples[81 * 81 * 3] = {
544 255, 255, 255, 225, 226, 228, 199, 200, 202, 173, 174, 178, 147, 149, 152, 1 23, 125, 128, 99, 99, 102, 69, 70, 71, 34, 30, 31, 567 255, 255, 255, 225, 226, 228, 199, 200, 202, 173, 174, 178, 147, 149, 152, 1 23, 125, 128, 99, 99, 102, 69, 70, 71, 34, 30, 31,
545 255, 253, 229, 226, 224, 203, 200, 199, 182, 173, 173, 158, 149, 148, 135, 1 25, 124, 113, 99, 99, 90, 70, 69, 63, 33, 29, 24, 568 255, 253, 229, 226, 224, 203, 200, 199, 182, 173, 173, 158, 149, 148, 135, 1 25, 124, 113, 99, 99, 90, 70, 69, 63, 33, 29, 24,
546 255, 251, 204, 228, 223, 182, 201, 198, 163, 174, 172, 142, 150, 147, 122, 1 25, 123, 101, 99, 98, 80, 70, 68, 54, 32, 28, 16, 569 255, 251, 204, 228, 223, 182, 201, 198, 163, 174, 172, 142, 150, 147, 122, 1 25, 123, 101, 99, 98, 80, 70, 68, 54, 32, 28, 16,
547 255, 249, 179, 230, 222, 160, 203, 197, 144, 174, 170, 124, 150, 145, 105, 1 25, 122, 88, 99, 97, 69, 70, 68, 46, 31, 28, 6, 570 255, 249, 179, 230, 222, 160, 203, 197, 144, 174, 170, 124, 150, 145, 105, 1 25, 122, 88, 99, 97, 69, 70, 68, 46, 31, 28, 6,
548 255, 247, 154, 229, 220, 138, 203, 195, 122, 176, 169, 107, 150, 145, 91, 12 5, 121, 74, 100, 96, 57, 70, 67, 35, 29, 26, 0, 571 255, 247, 154, 229, 220, 138, 203, 195, 122, 176, 169, 107, 150, 145, 91, 12 5, 121, 74, 100, 96, 57, 70, 67, 35, 29, 26, 0,
549 255, 246, 128, 231, 217, 114, 205, 194, 101, 176, 167, 88, 150, 144, 75, 125 , 120, 60, 100, 96, 44, 70, 66, 24, 28, 26, 0, 572 255, 246, 128, 231, 217, 114, 205, 194, 101, 176, 167, 88, 150, 144, 75, 125 , 120, 60, 100, 96, 44, 70, 66, 24, 28, 26, 0,
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 FX_BYTE c1 = FXSYS_round(c * 255); 1374 FX_BYTE c1 = FXSYS_round(c * 255);
1352 FX_BYTE m1 = FXSYS_round(m * 255); 1375 FX_BYTE m1 = FXSYS_round(m * 255);
1353 FX_BYTE y1 = FXSYS_round(y * 255); 1376 FX_BYTE y1 = FXSYS_round(y * 255);
1354 FX_BYTE k1 = FXSYS_round(k * 255); 1377 FX_BYTE k1 = FXSYS_round(k * 255);
1355 FX_BYTE r, g, b; 1378 FX_BYTE r, g, b;
1356 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); 1379 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b);
1357 R = 1.0f * r / 255; 1380 R = 1.0f * r / 255;
1358 G = 1.0f * g / 255; 1381 G = 1.0f * g / 255;
1359 B = 1.0f * b / 255; 1382 B = 1.0f * b / 255;
1360 } 1383 }
OLDNEW
« core/src/fpdfapi/fpdf_page/pageint.h ('K') | « core/src/fxcodec/codec/codec_int.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698