OLD | NEW |
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 const FX_DWORD N_COMPONENT_LAB = 3; |
| 11 const FX_DWORD N_COMPONENT_GRAY = 1; |
| 12 const FX_DWORD N_COMPONENT_RGB = 3; |
| 13 const FX_DWORD N_COMPONENT_CMYK = 4; |
| 14 const FX_DWORD 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 Loading... |
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 { |
| 70 FX_DWORD components; |
| 71 switch (cs) { |
| 72 case cmsSigLabData: |
| 73 components = N_COMPONENT_LAB; |
| 74 break; |
| 75 case cmsSigGrayData: |
| 76 components = N_COMPONENT_GRAY; |
| 77 break; |
| 78 case cmsSigRgbData: |
| 79 components = N_COMPONENT_RGB; |
| 80 break; |
| 81 case cmsSigCmykData: |
| 82 components = N_COMPONENT_CMYK; |
| 83 break; |
| 84 default: |
| 85 components = N_COMPONENT_DEFAULT; |
| 86 break; |
| 87 } |
| 88 return components; |
| 89 } |
| 90 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, FX_DWORD dwSr
cProfileSize, FX_INT32& nSrcComponents, |
| 91 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) | 92 int intent, FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAU
LT, FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT) |
65 { | 93 { |
66 cmsHPROFILE srcProfile = NULL; | 94 cmsHPROFILE srcProfile = NULL; |
67 cmsHPROFILE dstProfile = NULL; | 95 cmsHPROFILE dstProfile = NULL; |
68 cmsHTRANSFORM hTransform = NULL; | 96 cmsHTRANSFORM hTransform = NULL; |
69 CLcmsCmm* pCmm = NULL; | 97 CLcmsCmm* pCmm = NULL; |
| 98 nSrcComponents = 0; |
70 srcProfile = cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize)
; | 99 srcProfile = cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize)
; |
71 if (srcProfile == NULL) { | 100 if (srcProfile == NULL) { |
72 return NULL; | 101 return NULL; |
73 } | 102 } |
74 if(pDstProfileData == NULL && dwDstProfileSize == 0 && nDstComponents == 3)
{ | 103 if(pDstProfileData == NULL && dwDstProfileSize == 0 && nDstComponents == 3)
{ |
75 dstProfile = cmsCreate_sRGBProfile(); | 104 dstProfile = cmsCreate_sRGBProfile(); |
76 } else { | 105 } else { |
77 dstProfile = cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileS
ize); | 106 dstProfile = cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileS
ize); |
78 } | 107 } |
79 if (dstProfile == NULL) { | 108 if (dstProfile == NULL) { |
80 cmsCloseProfile(srcProfile); | 109 cmsCloseProfile(srcProfile); |
81 return NULL; | 110 return NULL; |
82 } | 111 } |
83 int srcFormat; | 112 int srcFormat; |
84 FX_BOOL bLab = FALSE; | 113 FX_BOOL bLab = FALSE; |
85 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); | 114 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); |
86 if (!CheckComponents(srcCS, nSrcComponents, FALSE)) { | 115 nSrcComponents = GetCSComponents(srcCS); |
87 cmsCloseProfile(srcProfile); | |
88 cmsCloseProfile(dstProfile); | |
89 return NULL; | |
90 } | |
91 if (srcCS == cmsSigLabData) { | 116 if (srcCS == cmsSigLabData) { |
92 srcFormat = COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_
SH(0); | 117 srcFormat = COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_
SH(0); |
93 bLab = TRUE; | 118 bLab = TRUE; |
94 } else { | 119 } else { |
95 srcFormat = COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_
SH(1); | 120 srcFormat = COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_
SH(1); |
96 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { | 121 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { |
97 srcFormat |= DOSWAP_SH(1); | 122 srcFormat |= DOSWAP_SH(1); |
98 } | 123 } |
99 } | 124 } |
100 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); | 125 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); |
(...skipping 27 matching lines...) Expand all Loading... |
128 return NULL; | 153 return NULL; |
129 } | 154 } |
130 pCmm->m_nSrcComponents = nSrcComponents; | 155 pCmm->m_nSrcComponents = nSrcComponents; |
131 pCmm->m_nDstComponents = nDstComponents; | 156 pCmm->m_nDstComponents = nDstComponents; |
132 pCmm->m_hTransform = hTransform; | 157 pCmm->m_hTransform = hTransform; |
133 pCmm->m_bLab = bLab; | 158 pCmm->m_bLab = bLab; |
134 cmsCloseProfile(srcProfile); | 159 cmsCloseProfile(srcProfile); |
135 cmsCloseProfile(dstProfile); | 160 cmsCloseProfile(dstProfile); |
136 return pCmm; | 161 return pCmm; |
137 } | 162 } |
138 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, unsigned in
t dwProfileSize, int nComponents, int intent, FX_DWORD dwSrcFormat) | 163 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, FX_DWORD dw
ProfileSize, FX_INT32& nComponents, FX_INT32 intent, FX_DWORD dwSrcFormat) |
139 { | 164 { |
140 return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, NULL
, 0, 3, intent, dwSrcFormat); | 165 return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, NULL
, 0, 3, intent, dwSrcFormat); |
141 } | 166 } |
142 void IccLib_DestroyTransform(void* pTransform) | 167 void IccLib_DestroyTransform(void* pTransform) |
143 { | 168 { |
144 if (pTransform == NULL) { | 169 if (pTransform == NULL) { |
145 return; | 170 return; |
146 } | 171 } |
147 cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform); | 172 cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform); |
148 delete (CLcmsCmm*)pTransform; | 173 delete (CLcmsCmm*)pTransform; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 pDestValues[2] = output[0] / 255.0f; | 210 pDestValues[2] = output[0] / 255.0f; |
186 break; | 211 break; |
187 case 4: | 212 case 4: |
188 pDestValues[0] = output[0] / 255.0f; | 213 pDestValues[0] = output[0] / 255.0f; |
189 pDestValues[1] = output[1] / 255.0f; | 214 pDestValues[1] = output[1] / 255.0f; |
190 pDestValues[2] = output[2] / 255.0f; | 215 pDestValues[2] = output[2] / 255.0f; |
191 pDestValues[3] = output[3] / 255.0f; | 216 pDestValues[3] = output[3] / 255.0f; |
192 break; | 217 break; |
193 } | 218 } |
194 } | 219 } |
195 void IccLib_TranslateImage(void* pTransform, unsigned char* pDest, const unsigne
d char* pSrc, int pixels) | 220 void IccLib_TranslateImage(void* pTransform, unsigned char* pDest, const unsigne
d char* pSrc, FX_INT32 pixels) |
196 { | 221 { |
197 cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, (void*)pSrc, pDest, pi
xels); | 222 cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, (void*)pSrc, pDest, pi
xels); |
198 } | 223 } |
199 FX_LPVOID CreateProfile_Gray(double gamma) | 224 FX_LPVOID CreateProfile_Gray(double gamma) |
200 { | 225 { |
201 cmsCIExyY* D50 = (cmsCIExyY*)cmsD50_xyY(); | 226 cmsCIExyY* D50 = (cmsCIExyY*)cmsD50_xyY(); |
202 if (!cmsWhitePointFromTemp(D50, 6504)) { | 227 if (!cmsWhitePointFromTemp(D50, 6504)) { |
203 return NULL; | 228 return NULL; |
204 } | 229 } |
205 cmsToneCurve* curve = cmsBuildGamma(NULL, gamma); | 230 cmsToneCurve* curve = cmsBuildGamma(NULL, gamma); |
(...skipping 29 matching lines...) Expand all Loading... |
235 case cmsSigHlsData: | 260 case cmsSigHlsData: |
236 return ICodec_IccModule::IccCS_Hls; | 261 return ICodec_IccModule::IccCS_Hls; |
237 case cmsSigCmykData: | 262 case cmsSigCmykData: |
238 return ICodec_IccModule::IccCS_Cmyk; | 263 return ICodec_IccModule::IccCS_Cmyk; |
239 case cmsSigCmyData: | 264 case cmsSigCmyData: |
240 return ICodec_IccModule::IccCS_Cmy; | 265 return ICodec_IccModule::IccCS_Cmy; |
241 default: | 266 default: |
242 return ICodec_IccModule::IccCS_Unknown; | 267 return ICodec_IccModule::IccCS_Unknown; |
243 } | 268 } |
244 } | 269 } |
245 ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS(FX_LPCBYTE pProfileData,
unsigned int dwProfileSize) | 270 ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS(FX_LPCBYTE pProfileData,
FX_DWORD dwProfileSize) |
246 { | 271 { |
247 ICodec_IccModule::IccCS cs; | 272 ICodec_IccModule::IccCS cs; |
248 cmsHPROFILE hProfile = cmsOpenProfileFromMem((void*)pProfileData, dwProfileS
ize); | 273 cmsHPROFILE hProfile = cmsOpenProfileFromMem((void*)pProfileData, dwProfileS
ize); |
249 if (hProfile == NULL) { | 274 if (hProfile == NULL) { |
250 return IccCS_Unknown; | 275 return IccCS_Unknown; |
251 } | 276 } |
252 cs = GetProfileCSFromHandle(hProfile); | 277 cs = GetProfileCSFromHandle(hProfile); |
253 if (hProfile) { | 278 if (hProfile) { |
254 cmsCloseProfile(hProfile); | 279 cmsCloseProfile(hProfile); |
255 } | 280 } |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 } | 535 } |
511 pos = m_MapTranform.GetStartPosition(); | 536 pos = m_MapTranform.GetStartPosition(); |
512 CFX_IccTransformCache* pTransformCache; | 537 CFX_IccTransformCache* pTransformCache; |
513 while (pos) { | 538 while (pos) { |
514 m_MapTranform.GetNextAssoc(pos, key, (FX_LPVOID&)pTransformCache); | 539 m_MapTranform.GetNextAssoc(pos, key, (FX_LPVOID&)pTransformCache); |
515 if (pTransformCache) { | 540 if (pTransformCache) { |
516 delete pTransformCache; | 541 delete pTransformCache; |
517 } | 542 } |
518 } | 543 } |
519 } | 544 } |
520 void* CCodec_IccModule::CreateTransform_sRGB(FX_LPCBYTE pProfileData, unsigned i
nt dwProfileSize, int nComponents, int intent, FX_DWORD dwSrcFormat) | 545 void* CCodec_IccModule::CreateTransform_sRGB(FX_LPCBYTE pProfileData, FX_DWORD d
wProfileSize, FX_INT32& nComponents, FX_INT32 intent, FX_DWORD dwSrcFormat) |
521 { | 546 { |
522 return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents,
intent, dwSrcFormat); | 547 return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents,
intent, dwSrcFormat); |
523 } | 548 } |
524 void* CCodec_IccModule::CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, unsigne
d int dwSrcProfileSize, int nSrcComponents, | 549 void* CCodec_IccModule::CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, FX_DWOR
D dwSrcProfileSize, FX_INT32& nSrcComponents, |
525 FX_LPCBYTE pDstProfileData, unsigned int dwDstProfileSize, int intent, | 550 FX_LPCBYTE pDstProfileData, FX_DWORD dwDstProfileSize, FX_INT32 intent, |
526 FX_DWORD dwSrcFormat , FX_DWORD dwDstFormat) | 551 FX_DWORD dwSrcFormat , FX_DWORD dwDstFormat) |
527 { | 552 { |
528 return IccLib_CreateTransform(pSrcProfileData, dwSrcProfileSize, nSrcCompone
nts, | 553 return IccLib_CreateTransform(pSrcProfileData, dwSrcProfileSize, nSrcCompone
nts, |
529 pDstProfileData, dwDstProfileSize, 4, intent,
dwSrcFormat, dwDstFormat); | 554 pDstProfileData, dwDstProfileSize, 4, intent,
dwSrcFormat, dwDstFormat); |
530 } | 555 } |
531 void CCodec_IccModule::DestroyTransform(void* pTransform) | 556 void CCodec_IccModule::DestroyTransform(void* pTransform) |
532 { | 557 { |
533 IccLib_DestroyTransform(pTransform); | 558 IccLib_DestroyTransform(pTransform); |
534 } | 559 } |
535 void CCodec_IccModule::Translate(void* pTransform, FX_FLOAT* pSrcValues, FX_FLOA
T* pDestValues) | 560 void CCodec_IccModule::Translate(void* pTransform, FX_FLOAT* pSrcValues, FX_FLOA
T* pDestValues) |
536 { | 561 { |
537 IccLib_Translate(pTransform, m_nComponents, pSrcValues, pDestValues); | 562 IccLib_Translate(pTransform, m_nComponents, pSrcValues, pDestValues); |
538 } | 563 } |
539 void CCodec_IccModule::TranslateScanline(void* pTransform, FX_LPBYTE pDest, FX_L
PCBYTE pSrc, int pixels) | 564 void CCodec_IccModule::TranslateScanline(void* pTransform, FX_LPBYTE pDest, FX_L
PCBYTE pSrc, FX_INT32 pixels) |
540 { | 565 { |
541 IccLib_TranslateImage(pTransform, pDest, pSrc, pixels); | 566 IccLib_TranslateImage(pTransform, pDest, pSrc, pixels); |
542 } | 567 } |
543 const FX_BYTE g_CMYKSamples[81 * 81 * 3] = { | 568 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, | 569 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, | 570 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, | 571 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, | 572 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, | 573 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, | 574 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 Loading... |
1351 FX_BYTE c1 = FXSYS_round(c * 255); | 1376 FX_BYTE c1 = FXSYS_round(c * 255); |
1352 FX_BYTE m1 = FXSYS_round(m * 255); | 1377 FX_BYTE m1 = FXSYS_round(m * 255); |
1353 FX_BYTE y1 = FXSYS_round(y * 255); | 1378 FX_BYTE y1 = FXSYS_round(y * 255); |
1354 FX_BYTE k1 = FXSYS_round(k * 255); | 1379 FX_BYTE k1 = FXSYS_round(k * 255); |
1355 FX_BYTE r, g, b; | 1380 FX_BYTE r, g, b; |
1356 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); | 1381 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); |
1357 R = 1.0f * r / 255; | 1382 R = 1.0f * r / 255; |
1358 G = 1.0f * g / 255; | 1383 G = 1.0f * g / 255; |
1359 B = 1.0f * b / 255; | 1384 B = 1.0f * b / 255; |
1360 } | 1385 } |
OLD | NEW |