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 "core/fxcodec/codec/codec_int.h" | 7 #include "core/fxcodec/codec/codec_int.h" |
8 #include "core/fxcodec/fx_codec.h" | 8 #include "core/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 |
11 const uint32_t N_COMPONENT_LAB = 3; | 11 const uint32_t N_COMPONENT_LAB = 3; |
12 const uint32_t N_COMPONENT_GRAY = 1; | 12 const uint32_t N_COMPONENT_GRAY = 1; |
13 const uint32_t N_COMPONENT_RGB = 3; | 13 const uint32_t N_COMPONENT_RGB = 3; |
14 const uint32_t N_COMPONENT_CMYK = 4; | 14 const uint32_t N_COMPONENT_CMYK = 4; |
15 const uint32_t N_COMPONENT_DEFAULT = 3; | 15 const uint32_t N_COMPONENT_DEFAULT = 3; |
16 | 16 |
17 struct CLcmsCmm { | 17 struct CLcmsCmm { |
18 cmsHTRANSFORM m_hTransform; | 18 cmsHTRANSFORM m_hTransform; |
19 int m_nSrcComponents; | 19 int m_nSrcComponents; |
20 int m_nDstComponents; | 20 int m_nDstComponents; |
21 FX_BOOL m_bLab; | 21 bool m_bLab; |
22 }; | 22 }; |
23 FX_BOOL CheckComponents(cmsColorSpaceSignature cs, | 23 bool CheckComponents(cmsColorSpaceSignature cs, int nComponents, bool bDst) { |
24 int nComponents, | |
25 FX_BOOL bDst) { | |
26 if (nComponents <= 0 || nComponents > 15) { | 24 if (nComponents <= 0 || nComponents > 15) { |
27 return FALSE; | 25 return false; |
28 } | 26 } |
29 switch (cs) { | 27 switch (cs) { |
30 case cmsSigLabData: | 28 case cmsSigLabData: |
31 if (nComponents < 3) { | 29 if (nComponents < 3) { |
32 return FALSE; | 30 return false; |
33 } | 31 } |
34 break; | 32 break; |
35 case cmsSigGrayData: | 33 case cmsSigGrayData: |
36 if (bDst && nComponents != 1) { | 34 if (bDst && nComponents != 1) { |
37 return FALSE; | 35 return false; |
38 } | 36 } |
39 if (!bDst && nComponents > 2) { | 37 if (!bDst && nComponents > 2) { |
40 return FALSE; | 38 return false; |
41 } | 39 } |
42 break; | 40 break; |
43 case cmsSigRgbData: | 41 case cmsSigRgbData: |
44 if (bDst && nComponents != 3) { | 42 if (bDst && nComponents != 3) { |
45 return FALSE; | 43 return false; |
46 } | 44 } |
47 break; | 45 break; |
48 case cmsSigCmykData: | 46 case cmsSigCmykData: |
49 if (bDst && nComponents != 4) { | 47 if (bDst && nComponents != 4) { |
50 return FALSE; | 48 return false; |
51 } | 49 } |
52 break; | 50 break; |
53 default: | 51 default: |
54 if (nComponents != 3) { | 52 if (nComponents != 3) { |
55 return FALSE; | 53 return false; |
56 } | 54 } |
57 break; | 55 break; |
58 } | 56 } |
59 return TRUE; | 57 return true; |
60 } | 58 } |
61 | 59 |
62 uint32_t GetCSComponents(cmsColorSpaceSignature cs) { | 60 uint32_t GetCSComponents(cmsColorSpaceSignature cs) { |
63 uint32_t components; | 61 uint32_t components; |
64 switch (cs) { | 62 switch (cs) { |
65 case cmsSigLabData: | 63 case cmsSigLabData: |
66 components = N_COMPONENT_LAB; | 64 components = N_COMPONENT_LAB; |
67 break; | 65 break; |
68 case cmsSigGrayData: | 66 case cmsSigGrayData: |
69 components = N_COMPONENT_GRAY; | 67 components = N_COMPONENT_GRAY; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 dstProfile = cmsCreate_sRGBProfile(); | 99 dstProfile = cmsCreate_sRGBProfile(); |
102 } else { | 100 } else { |
103 dstProfile = | 101 dstProfile = |
104 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize); | 102 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize); |
105 } | 103 } |
106 if (!dstProfile) { | 104 if (!dstProfile) { |
107 cmsCloseProfile(srcProfile); | 105 cmsCloseProfile(srcProfile); |
108 return nullptr; | 106 return nullptr; |
109 } | 107 } |
110 int srcFormat; | 108 int srcFormat; |
111 FX_BOOL bLab = FALSE; | 109 bool bLab = false; |
112 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); | 110 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); |
113 nSrcComponents = GetCSComponents(srcCS); | 111 nSrcComponents = GetCSComponents(srcCS); |
114 if (srcCS == cmsSigLabData) { | 112 if (srcCS == cmsSigLabData) { |
115 srcFormat = | 113 srcFormat = |
116 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0); | 114 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0); |
117 bLab = TRUE; | 115 bLab = true; |
118 } else { | 116 } else { |
119 srcFormat = | 117 srcFormat = |
120 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1); | 118 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1); |
121 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { | 119 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { |
122 srcFormat |= DOSWAP_SH(1); | 120 srcFormat |= DOSWAP_SH(1); |
123 } | 121 } |
124 } | 122 } |
125 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); | 123 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); |
126 if (!CheckComponents(dstCS, nDstComponents, TRUE)) { | 124 if (!CheckComponents(dstCS, nDstComponents, true)) { |
127 cmsCloseProfile(srcProfile); | 125 cmsCloseProfile(srcProfile); |
128 cmsCloseProfile(dstProfile); | 126 cmsCloseProfile(dstProfile); |
129 return nullptr; | 127 return nullptr; |
130 } | 128 } |
131 | 129 |
132 cmsHTRANSFORM hTransform = nullptr; | 130 cmsHTRANSFORM hTransform = nullptr; |
133 switch (dstCS) { | 131 switch (dstCS) { |
134 case cmsSigGrayData: | 132 case cmsSigGrayData: |
135 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, | 133 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, |
136 TYPE_GRAY_8, intent, 0); | 134 TYPE_GRAY_8, intent, 0); |
(...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 ASSERT(k1 == FXSYS_round(k * 255)); | 1679 ASSERT(k1 == FXSYS_round(k * 255)); |
1682 | 1680 |
1683 uint8_t r, g, b; | 1681 uint8_t r, g, b; |
1684 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); | 1682 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); |
1685 // Multiply by a constant rather than dividing because division is much | 1683 // Multiply by a constant rather than dividing because division is much |
1686 // more expensive. | 1684 // more expensive. |
1687 R = r * (1.0f / 255); | 1685 R = r * (1.0f / 255); |
1688 G = g * (1.0f / 255); | 1686 G = g * (1.0f / 255); |
1689 B = b * (1.0f / 255); | 1687 B = b * (1.0f / 255); |
1690 } | 1688 } |
OLD | NEW |