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; | |
12 const uint32_t N_COMPONENT_GRAY = 1; | |
13 const uint32_t N_COMPONENT_RGB = 3; | |
14 const uint32_t N_COMPONENT_CMYK = 4; | |
15 const uint32_t N_COMPONENT_DEFAULT = 3; | |
16 | |
17 struct CLcmsCmm { | 11 struct CLcmsCmm { |
18 cmsHTRANSFORM m_hTransform; | 12 cmsHTRANSFORM m_hTransform; |
19 int m_nSrcComponents; | 13 int m_nSrcComponents; |
20 int m_nDstComponents; | 14 int m_nDstComponents; |
21 FX_BOOL m_bLab; | 15 FX_BOOL m_bLab; |
22 }; | 16 }; |
23 FX_BOOL CheckComponents(cmsColorSpaceSignature cs, | 17 FX_BOOL CheckComponents(cmsColorSpaceSignature cs, |
24 int nComponents, | 18 int nComponents, |
25 FX_BOOL bDst) { | 19 FX_BOOL bDst) { |
26 if (nComponents <= 0 || nComponents > 15) { | 20 if (nComponents <= 0 || nComponents > 15) { |
(...skipping 25 matching lines...) Expand all Loading... |
52 break; | 46 break; |
53 default: | 47 default: |
54 if (nComponents != 3) { | 48 if (nComponents != 3) { |
55 return FALSE; | 49 return FALSE; |
56 } | 50 } |
57 break; | 51 break; |
58 } | 52 } |
59 return TRUE; | 53 return TRUE; |
60 } | 54 } |
61 | 55 |
62 uint32_t GetCSComponents(cmsColorSpaceSignature cs) { | |
63 uint32_t components; | |
64 switch (cs) { | |
65 case cmsSigLabData: | |
66 components = N_COMPONENT_LAB; | |
67 break; | |
68 case cmsSigGrayData: | |
69 components = N_COMPONENT_GRAY; | |
70 break; | |
71 case cmsSigRgbData: | |
72 components = N_COMPONENT_RGB; | |
73 break; | |
74 case cmsSigCmykData: | |
75 components = N_COMPONENT_CMYK; | |
76 break; | |
77 default: | |
78 components = N_COMPONENT_DEFAULT; | |
79 break; | |
80 } | |
81 return components; | |
82 } | |
83 | |
84 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, | 56 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, |
85 uint32_t dwSrcProfileSize, | 57 uint32_t dwSrcProfileSize, |
86 uint32_t& nSrcComponents, | 58 uint32_t& nSrcComponents, |
87 const unsigned char* pDstProfileData, | 59 const unsigned char* pDstProfileData, |
88 uint32_t dwDstProfileSize, | 60 uint32_t dwDstProfileSize, |
89 int32_t nDstComponents, | 61 int32_t nDstComponents, |
90 int intent, | 62 int intent, |
91 uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT, | 63 uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT, |
92 uint32_t dwDstFormat = Icc_FORMAT_DEFAULT) { | 64 uint32_t dwDstFormat = Icc_FORMAT_DEFAULT) { |
93 nSrcComponents = 0; | 65 nSrcComponents = 0; |
94 cmsHPROFILE srcProfile = | 66 cmsHPROFILE srcProfile = |
95 cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize); | 67 cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize); |
96 if (!srcProfile) | 68 if (!srcProfile) |
97 return nullptr; | 69 return nullptr; |
98 | 70 |
99 cmsHPROFILE dstProfile; | 71 cmsHPROFILE dstProfile; |
100 if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) { | 72 if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) { |
101 dstProfile = cmsCreate_sRGBProfile(); | 73 dstProfile = cmsCreate_sRGBProfile(); |
102 } else { | 74 } else { |
103 dstProfile = | 75 dstProfile = |
104 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize); | 76 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize); |
105 } | 77 } |
106 if (!dstProfile) { | 78 if (!dstProfile) { |
107 cmsCloseProfile(srcProfile); | 79 cmsCloseProfile(srcProfile); |
108 return nullptr; | 80 return nullptr; |
109 } | 81 } |
110 int srcFormat; | 82 int srcFormat; |
111 FX_BOOL bLab = FALSE; | 83 FX_BOOL bLab = FALSE; |
112 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); | 84 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); |
113 nSrcComponents = GetCSComponents(srcCS); | 85 |
| 86 nSrcComponents = cmsChannelsOf(srcCS); |
| 87 // According to PDF spec, number of components must be 1, 3, or 4. |
| 88 if (nSrcComponents != 1 && nSrcComponents != 3 && nSrcComponents != 4) { |
| 89 cmsCloseProfile(srcProfile); |
| 90 cmsCloseProfile(dstProfile); |
| 91 return nullptr; |
| 92 } |
| 93 |
114 if (srcCS == cmsSigLabData) { | 94 if (srcCS == cmsSigLabData) { |
115 srcFormat = | 95 srcFormat = |
116 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0); | 96 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0); |
117 bLab = TRUE; | 97 bLab = TRUE; |
118 } else { | 98 } else { |
119 srcFormat = | 99 srcFormat = |
120 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1); | 100 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1); |
121 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { | 101 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { |
122 srcFormat |= DOSWAP_SH(1); | 102 srcFormat |= DOSWAP_SH(1); |
123 } | 103 } |
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 ASSERT(k1 == FXSYS_round(k * 255)); | 1661 ASSERT(k1 == FXSYS_round(k * 255)); |
1682 | 1662 |
1683 uint8_t r, g, b; | 1663 uint8_t r, g, b; |
1684 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); | 1664 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); |
1685 // Multiply by a constant rather than dividing because division is much | 1665 // Multiply by a constant rather than dividing because division is much |
1686 // more expensive. | 1666 // more expensive. |
1687 R = r * (1.0f / 255); | 1667 R = r * (1.0f / 255); |
1688 G = g * (1.0f / 255); | 1668 G = g * (1.0f / 255); |
1689 B = b * (1.0f / 255); | 1669 B = b * (1.0f / 255); |
1690 } | 1670 } |
OLD | NEW |