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

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

Issue 1258093002: FX Bool considered harmful, part 3 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 4 months 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 | « core/src/fxcodec/codec/fx_codec_flate.cpp ('k') | core/src/fxcodec/codec/fx_codec_jbig.cpp » ('j') | 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 "../../../../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 } 47 }
48 if (!bDst && nComponents > 2) { 48 if (!bDst && nComponents > 2) {
49 return FALSE; 49 return false;
50 } 50 }
51 break; 51 break;
52 case cmsSigRgbData: 52 case cmsSigRgbData:
53 if (bDst && nComponents != 3) { 53 if (bDst && nComponents != 3) {
54 return FALSE; 54 return false;
55 } 55 }
56 break; 56 break;
57 case cmsSigCmykData: 57 case cmsSigCmykData:
58 if (bDst && nComponents != 4) { 58 if (bDst && nComponents != 4) {
59 return FALSE; 59 return false;
60 } 60 }
61 break; 61 break;
62 default: 62 default:
63 if (nComponents != 3) { 63 if (nComponents != 3) {
64 return FALSE; 64 return false;
65 } 65 }
66 break; 66 break;
67 } 67 }
68 return TRUE; 68 return true;
69 } 69 }
70 int32_t GetCSComponents(cmsColorSpaceSignature cs) 70 int32_t GetCSComponents(cmsColorSpaceSignature cs)
71 { 71 {
72 FX_DWORD components; 72 FX_DWORD components;
73 switch (cs) { 73 switch (cs) {
74 case cmsSigLabData: 74 case cmsSigLabData:
75 components = N_COMPONENT_LAB; 75 components = N_COMPONENT_LAB;
76 break; 76 break;
77 case cmsSigGrayData: 77 case cmsSigGrayData:
78 components = N_COMPONENT_GRAY; 78 components = N_COMPONENT_GRAY;
(...skipping 26 matching lines...) Expand all
105 if(pDstProfileData == NULL && dwDstProfileSize == 0 && nDstComponents == 3) { 105 if(pDstProfileData == NULL && dwDstProfileSize == 0 && nDstComponents == 3) {
106 dstProfile = cmsCreate_sRGBProfile(); 106 dstProfile = cmsCreate_sRGBProfile();
107 } else { 107 } else {
108 dstProfile = cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileS ize); 108 dstProfile = cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileS ize);
109 } 109 }
110 if (dstProfile == NULL) { 110 if (dstProfile == NULL) {
111 cmsCloseProfile(srcProfile); 111 cmsCloseProfile(srcProfile);
112 return NULL; 112 return NULL;
113 } 113 }
114 int srcFormat; 114 int srcFormat;
115 FX_BOOL bLab = FALSE; 115 bool bLab = false;
116 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); 116 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile);
117 nSrcComponents = GetCSComponents(srcCS); 117 nSrcComponents = GetCSComponents(srcCS);
118 if (srcCS == cmsSigLabData) { 118 if (srcCS == cmsSigLabData) {
119 srcFormat = COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_ SH(0); 119 srcFormat = COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_ SH(0);
120 bLab = TRUE; 120 bLab = true;
121 } else { 121 } else {
122 srcFormat = COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_ SH(1); 122 srcFormat = COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_ SH(1);
123 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { 123 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) {
124 srcFormat |= DOSWAP_SH(1); 124 srcFormat |= DOSWAP_SH(1);
125 } 125 }
126 } 126 }
127 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); 127 cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile);
128 if (!CheckComponents(dstCS, nDstComponents, TRUE)) { 128 if (!CheckComponents(dstCS, nDstComponents, true)) {
129 cmsCloseProfile(srcProfile); 129 cmsCloseProfile(srcProfile);
130 cmsCloseProfile(dstProfile); 130 cmsCloseProfile(dstProfile);
131 return NULL; 131 return NULL;
132 } 132 }
133 switch(dstCS) { 133 switch(dstCS) {
134 case cmsSigGrayData: 134 case cmsSigGrayData:
135 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, T YPE_GRAY_8, intent, 0); 135 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, T YPE_GRAY_8, intent, 0);
136 break; 136 break;
137 case cmsSigRgbData: 137 case cmsSigRgbData:
138 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, T YPE_BGR_8, intent, 0); 138 hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, T YPE_BGR_8, intent, 0);
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 uint8_t c1 = FXSYS_round(c * 255); 1358 uint8_t c1 = FXSYS_round(c * 255);
1359 uint8_t m1 = FXSYS_round(m * 255); 1359 uint8_t m1 = FXSYS_round(m * 255);
1360 uint8_t y1 = FXSYS_round(y * 255); 1360 uint8_t y1 = FXSYS_round(y * 255);
1361 uint8_t k1 = FXSYS_round(k * 255); 1361 uint8_t k1 = FXSYS_round(k * 255);
1362 uint8_t r, g, b; 1362 uint8_t r, g, b;
1363 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); 1363 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b);
1364 R = 1.0f * r / 255; 1364 R = 1.0f * r / 255;
1365 G = 1.0f * g / 255; 1365 G = 1.0f * g / 255;
1366 B = 1.0f * b / 255; 1366 B = 1.0f * b / 255;
1367 } 1367 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_flate.cpp ('k') | core/src/fxcodec/codec/fx_codec_jbig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698