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

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

Issue 2522933002: pdfium: Fix inconsistent number of color components of ICC profile (Closed)
Patch Set: . Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 bool m_bLab; 15 bool m_bLab;
22 }; 16 };
23 bool CheckComponents(cmsColorSpaceSignature cs, int nComponents, bool bDst) { 17 bool CheckComponents(cmsColorSpaceSignature cs, int nComponents, bool bDst) {
24 if (nComponents <= 0 || nComponents > 15) { 18 if (nComponents <= 0 || nComponents > 15) {
25 return false; 19 return false;
26 } 20 }
(...skipping 23 matching lines...) Expand all
50 break; 44 break;
51 default: 45 default:
52 if (nComponents != 3) { 46 if (nComponents != 3) {
53 return false; 47 return false;
54 } 48 }
55 break; 49 break;
56 } 50 }
57 return true; 51 return true;
58 } 52 }
59 53
60 uint32_t GetCSComponents(cmsColorSpaceSignature cs) {
61 uint32_t components;
62 switch (cs) {
63 case cmsSigLabData:
64 components = N_COMPONENT_LAB;
65 break;
66 case cmsSigGrayData:
67 components = N_COMPONENT_GRAY;
68 break;
69 case cmsSigRgbData:
70 components = N_COMPONENT_RGB;
71 break;
72 case cmsSigCmykData:
73 components = N_COMPONENT_CMYK;
74 break;
75 default:
76 components = N_COMPONENT_DEFAULT;
77 break;
78 }
79 return components;
80 }
81
82 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, 54 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData,
83 uint32_t dwSrcProfileSize, 55 uint32_t dwSrcProfileSize,
84 uint32_t& nSrcComponents, 56 uint32_t& nSrcComponents,
85 const unsigned char* pDstProfileData, 57 const unsigned char* pDstProfileData,
86 uint32_t dwDstProfileSize, 58 uint32_t dwDstProfileSize,
87 int32_t nDstComponents, 59 int32_t nDstComponents,
88 int intent, 60 int intent,
89 uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT, 61 uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT,
90 uint32_t dwDstFormat = Icc_FORMAT_DEFAULT) { 62 uint32_t dwDstFormat = Icc_FORMAT_DEFAULT) {
91 nSrcComponents = 0; 63 nSrcComponents = 0;
92 cmsHPROFILE srcProfile = 64 cmsHPROFILE srcProfile =
93 cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize); 65 cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize);
94 if (!srcProfile) 66 if (!srcProfile)
95 return nullptr; 67 return nullptr;
96 68
97 cmsHPROFILE dstProfile; 69 cmsHPROFILE dstProfile;
98 if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) { 70 if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) {
99 dstProfile = cmsCreate_sRGBProfile(); 71 dstProfile = cmsCreate_sRGBProfile();
100 } else { 72 } else {
101 dstProfile = 73 dstProfile =
102 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize); 74 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize);
103 } 75 }
104 if (!dstProfile) { 76 if (!dstProfile) {
105 cmsCloseProfile(srcProfile); 77 cmsCloseProfile(srcProfile);
106 return nullptr; 78 return nullptr;
107 } 79 }
108 int srcFormat; 80 int srcFormat;
109 bool bLab = false; 81 bool bLab = false;
110 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); 82 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile);
111 nSrcComponents = GetCSComponents(srcCS); 83
84 nSrcComponents = cmsChannelsOf(srcCS);
85 // According to PDF spec, number of components must be 1, 3, or 4.
86 if (nSrcComponents != 1 && nSrcComponents != 3 && nSrcComponents != 4) {
87 cmsCloseProfile(srcProfile);
88 cmsCloseProfile(dstProfile);
89 return nullptr;
90 }
91
112 if (srcCS == cmsSigLabData) { 92 if (srcCS == cmsSigLabData) {
113 srcFormat = 93 srcFormat =
114 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0); 94 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0);
115 bLab = true; 95 bLab = true;
116 } else { 96 } else {
117 srcFormat = 97 srcFormat =
118 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1); 98 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1);
119 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { 99 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) {
120 srcFormat |= DOSWAP_SH(1); 100 srcFormat |= DOSWAP_SH(1);
121 } 101 }
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 ASSERT(k1 == FXSYS_round(k * 255)); 1659 ASSERT(k1 == FXSYS_round(k * 255));
1680 1660
1681 uint8_t r, g, b; 1661 uint8_t r, g, b;
1682 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); 1662 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b);
1683 // Multiply by a constant rather than dividing because division is much 1663 // Multiply by a constant rather than dividing because division is much
1684 // more expensive. 1664 // more expensive.
1685 R = r * (1.0f / 255); 1665 R = r * (1.0f / 255);
1686 G = g * (1.0f / 255); 1666 G = g * (1.0f / 255);
1687 B = b * (1.0f / 255); 1667 B = b * (1.0f / 255);
1688 } 1668 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698