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

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

Issue 2485363002: Revert of Clean up fx_codec_icc.cpp (Closed)
Patch Set: Created 4 years, 1 month 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
11 struct CLcmsCmm { 17 struct CLcmsCmm {
12 cmsHTRANSFORM m_hTransform; 18 cmsHTRANSFORM m_hTransform;
13 int m_nSrcComponents; 19 int m_nSrcComponents;
14 int m_nDstComponents; 20 int m_nDstComponents;
15 bool m_bLab; 21 bool m_bLab;
16 }; 22 };
17 bool CheckComponents(cmsColorSpaceSignature cs, int nComponents, bool bDst) { 23 bool CheckComponents(cmsColorSpaceSignature cs, int nComponents, bool bDst) {
18 if (nComponents <= 0 || nComponents > 15) { 24 if (nComponents <= 0 || nComponents > 15) {
19 return false; 25 return false;
20 } 26 }
(...skipping 23 matching lines...) Expand all
44 break; 50 break;
45 default: 51 default:
46 if (nComponents != 3) { 52 if (nComponents != 3) {
47 return false; 53 return false;
48 } 54 }
49 break; 55 break;
50 } 56 }
51 return true; 57 return true;
52 } 58 }
53 59
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
54 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, 82 void* IccLib_CreateTransform(const unsigned char* pSrcProfileData,
55 uint32_t dwSrcProfileSize, 83 uint32_t dwSrcProfileSize,
56 uint32_t& nSrcComponents, 84 uint32_t& nSrcComponents,
57 const unsigned char* pDstProfileData, 85 const unsigned char* pDstProfileData,
58 uint32_t dwDstProfileSize, 86 uint32_t dwDstProfileSize,
59 int32_t nDstComponents, 87 int32_t nDstComponents,
60 int intent, 88 int intent,
61 uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT, 89 uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT,
62 uint32_t dwDstFormat = Icc_FORMAT_DEFAULT) { 90 uint32_t dwDstFormat = Icc_FORMAT_DEFAULT) {
63 nSrcComponents = 0; 91 nSrcComponents = 0;
64 cmsHPROFILE srcProfile = 92 cmsHPROFILE srcProfile =
65 cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize); 93 cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize);
66 if (!srcProfile) 94 if (!srcProfile)
67 return nullptr; 95 return nullptr;
68 96
69 cmsHPROFILE dstProfile; 97 cmsHPROFILE dstProfile;
70 if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) { 98 if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) {
71 dstProfile = cmsCreate_sRGBProfile(); 99 dstProfile = cmsCreate_sRGBProfile();
72 } else { 100 } else {
73 dstProfile = 101 dstProfile =
74 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize); 102 cmsOpenProfileFromMem((void*)pDstProfileData, dwDstProfileSize);
75 } 103 }
76 if (!dstProfile) { 104 if (!dstProfile) {
77 cmsCloseProfile(srcProfile); 105 cmsCloseProfile(srcProfile);
78 return nullptr; 106 return nullptr;
79 } 107 }
80 int srcFormat; 108 int srcFormat;
81 bool bLab = false; 109 bool bLab = false;
82 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); 110 cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile);
83 nSrcComponents = cmsChannelsOf(srcCS); 111 nSrcComponents = GetCSComponents(srcCS);
84 if (srcCS == cmsSigLabData) { 112 if (srcCS == cmsSigLabData) {
85 srcFormat = 113 srcFormat =
86 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0); 114 COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0);
87 bLab = true; 115 bLab = true;
88 } else { 116 } else {
89 srcFormat = 117 srcFormat =
90 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1); 118 COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1);
91 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { 119 if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) {
92 srcFormat |= DOSWAP_SH(1); 120 srcFormat |= DOSWAP_SH(1);
93 } 121 }
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 ASSERT(k1 == FXSYS_round(k * 255)); 1679 ASSERT(k1 == FXSYS_round(k * 255));
1652 1680
1653 uint8_t r, g, b; 1681 uint8_t r, g, b;
1654 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); 1682 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b);
1655 // Multiply by a constant rather than dividing because division is much 1683 // Multiply by a constant rather than dividing because division is much
1656 // more expensive. 1684 // more expensive.
1657 R = r * (1.0f / 255); 1685 R = r * (1.0f / 255);
1658 G = g * (1.0f / 255); 1686 G = g * (1.0f / 255);
1659 B = b * (1.0f / 255); 1687 B = b * (1.0f / 255);
1660 } 1688 }
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