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 "../../../../third_party/lcms2-2.6/include/lcms2.h" | 7 #include "../../../../third_party/lcms2-2.6/include/lcms2.h" |
8 #include "../../../include/fxcodec/fx_codec.h" | 8 #include "../../../include/fxcodec/fx_codec.h" |
9 #include "codec_int.h" | 9 #include "codec_int.h" |
10 | 10 |
11 const FX_DWORD N_COMPONENT_LAB = 3; | 11 const FX_DWORD N_COMPONENT_LAB = 3; |
12 const FX_DWORD N_COMPONENT_GRAY = 1; | 12 const FX_DWORD N_COMPONENT_GRAY = 1; |
13 const FX_DWORD N_COMPONENT_RGB = 3; | 13 const FX_DWORD N_COMPONENT_RGB = 3; |
14 const FX_DWORD N_COMPONENT_CMYK = 4; | 14 const FX_DWORD N_COMPONENT_CMYK = 4; |
15 const FX_DWORD N_COMPONENT_DEFAULT = 3; | 15 const FX_DWORD N_COMPONENT_DEFAULT = 3; |
16 | 16 |
17 FX_BOOL MD5ComputeID( const void* buf, FX_DWORD dwSize, uint8_t ID[16] ) | 17 bool MD5ComputeID( const void* buf, FX_DWORD dwSize, uint8_t ID[16] ) |
18 { | 18 { |
19 return cmsMD5computeIDExt(buf, dwSize, ID); | 19 return cmsMD5computeIDExt(buf, dwSize, ID); |
20 } | 20 } |
21 struct CLcmsCmm { | 21 struct CLcmsCmm { |
22 cmsHTRANSFORM m_hTransform; | 22 cmsHTRANSFORM m_hTransform; |
23 int m_nSrcComponents; | 23 int m_nSrcComponents; |
24 int m_nDstComponents; | 24 int m_nDstComponents; |
25 FX_BOOL» » m_bLab; | 25 bool» » m_bLab; |
26 }; | 26 }; |
27 extern "C" { | 27 extern "C" { |
28 int ourHandler(int ErrorCode, const char *ErrorText) | 28 int ourHandler(int ErrorCode, const char *ErrorText) |
29 { | 29 { |
30 return TRUE; | 30 return true; |
31 } | 31 } |
32 }; | 32 }; |
33 FX_BOOL CheckComponents(cmsColorSpaceSignature cs, int nComponents, FX_BOOL bDst
) | 33 bool CheckComponents(cmsColorSpaceSignature cs, int nComponents, bool bDst) |
34 { | 34 { |
35 if (nComponents <= 0 || nComponents > 15) { | 35 if (nComponents <= 0 || nComponents > 15) { |
36 return FALSE; | 36 return false; |
37 } | 37 } |
38 switch(cs) { | 38 switch(cs) { |
39 case cmsSigLabData: | 39 case cmsSigLabData: |
40 if (nComponents < 3) { | 40 if (nComponents < 3) { |
41 return FALSE; | 41 return false; |
42 } | 42 } |
43 break; | 43 break; |
44 case cmsSigGrayData: | 44 case cmsSigGrayData: |
45 if (bDst && nComponents != 1) { | 45 if (bDst && nComponents != 1) { |
46 return FALSE; | 46 return false; |
47 } else if (!bDst && nComponents > 2) { | 47 } else if (!bDst && nComponents > 2) { |
48 return FALSE; | 48 return false; |
49 } | 49 } |
50 break; | 50 break; |
51 case cmsSigRgbData: | 51 case cmsSigRgbData: |
52 if (bDst && nComponents != 3) { | 52 if (bDst && nComponents != 3) { |
53 return FALSE; | 53 return false; |
54 } | 54 } |
55 break; | 55 break; |
56 case cmsSigCmykData: | 56 case cmsSigCmykData: |
57 if (bDst && nComponents != 4) { | 57 if (bDst && nComponents != 4) { |
58 return FALSE; | 58 return false; |
59 } | 59 } |
60 break; | 60 break; |
61 default: | 61 default: |
62 if (nComponents != 3) { | 62 if (nComponents != 3) { |
63 return FALSE; | 63 return false; |
64 } | 64 } |
65 break; | 65 break; |
66 } | 66 } |
67 return TRUE; | 67 return true; |
68 } | 68 } |
69 int32_t GetCSComponents(cmsColorSpaceSignature cs) | 69 int32_t GetCSComponents(cmsColorSpaceSignature cs) |
70 { | 70 { |
71 FX_DWORD components; | 71 FX_DWORD components; |
72 switch (cs) { | 72 switch (cs) { |
73 case cmsSigLabData: | 73 case cmsSigLabData: |
74 components = N_COMPONENT_LAB; | 74 components = N_COMPONENT_LAB; |
75 break; | 75 break; |
76 case cmsSigGrayData: | 76 case cmsSigGrayData: |
77 components = N_COMPONENT_GRAY; | 77 components = N_COMPONENT_GRAY; |
(...skipping 26 matching lines...) Expand all Loading... |
104 if(pDstProfileData == NULL && dwDstProfileSize == 0 && nDstComponents == 3)
{ | 104 if(pDstProfileData == NULL && dwDstProfileSize == 0 && nDstComponents == 3)
{ |
105 dstProfile = cmsCreate_sRGBProfile(); | 105 dstProfile = cmsCreate_sRGBProfile(); |
106 } else { | 106 } else { |
107 dstProfile = cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileS
ize); | 107 dstProfile = cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileS
ize); |
108 } | 108 } |
109 if (dstProfile == NULL) { | 109 if (dstProfile == NULL) { |
110 cmsCloseProfile(srcProfile); | 110 cmsCloseProfile(srcProfile); |
111 return NULL; | 111 return NULL; |
112 } | 112 } |
113 int srcFormat; | 113 int srcFormat; |
114 FX_BOOL bLab = FALSE; | 114 bool bLab = false; |
115 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); | 115 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); |
116 nSrcComponents = GetCSComponents(srcCS); | 116 nSrcComponents = GetCSComponents(srcCS); |
117 if (srcCS == cmsSigLabData) { | 117 if (srcCS == cmsSigLabData) { |
118 srcFormat = COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_
SH(0); | 118 srcFormat = COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_
SH(0); |
119 bLab = TRUE; | 119 bLab = true; |
120 } else { | 120 } else { |
121 srcFormat = COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_
SH(1); | 121 srcFormat = COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_
SH(1); |
122 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { | 122 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { |
123 srcFormat |= DOSWAP_SH(1); | 123 srcFormat |= DOSWAP_SH(1); |
124 } | 124 } |
125 } | 125 } |
126 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); | 126 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); |
127 if (!CheckComponents(dstCS, nDstComponents, TRUE)) { | 127 if (!CheckComponents(dstCS, nDstComponents, true)) { |
128 cmsCloseProfile(srcProfile); | 128 cmsCloseProfile(srcProfile); |
129 cmsCloseProfile(dstProfile); | 129 cmsCloseProfile(dstProfile); |
130 return NULL; | 130 return NULL; |
131 } | 131 } |
132 switch(dstCS) { | 132 switch(dstCS) { |
133 case cmsSigGrayData: | 133 case cmsSigGrayData: |
134 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, T
YPE_GRAY_8, intent, 0); | 134 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, T
YPE_GRAY_8, intent, 0); |
135 break; | 135 break; |
136 case cmsSigRgbData: | 136 case cmsSigRgbData: |
137 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, T
YPE_BGR_8, intent, 0); | 137 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, T
YPE_BGR_8, intent, 0); |
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 uint8_t c1 = FXSYS_round(c * 255); | 1357 uint8_t c1 = FXSYS_round(c * 255); |
1358 uint8_t m1 = FXSYS_round(m * 255); | 1358 uint8_t m1 = FXSYS_round(m * 255); |
1359 uint8_t y1 = FXSYS_round(y * 255); | 1359 uint8_t y1 = FXSYS_round(y * 255); |
1360 uint8_t k1 = FXSYS_round(k * 255); | 1360 uint8_t k1 = FXSYS_round(k * 255); |
1361 uint8_t r, g, b; | 1361 uint8_t r, g, b; |
1362 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); | 1362 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); |
1363 R = 1.0f * r / 255; | 1363 R = 1.0f * r / 255; |
1364 G = 1.0f * g / 255; | 1364 G = 1.0f * g / 255; |
1365 B = 1.0f * b / 255; | 1365 B = 1.0f * b / 255; |
1366 } | 1366 } |
OLD | NEW |