Rev 23825 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
15127 | jghali | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | |||
8 | #include "sclcms2colorprofileimpl.h" |
||
9 | #include "sclcms2colormgmtengineimpl.h" |
||
15143 | fschmid | 10 | #include <cstdlib> |
15127 | jghali | 11 | |
12 | ScLcms2ColorProfileImpl::ScLcms2ColorProfileImpl(ScColorMgmtEngine& engine, cmsHPROFILE lcmsProfile) |
||
23668 | craig | 13 | : ScColorProfileImplBase(engine), m_profileHandle(lcmsProfile) |
15127 | jghali | 14 | { |
15 | |||
16 | } |
||
17 | |||
18 | ScLcms2ColorProfileImpl::~ScLcms2ColorProfileImpl() |
||
19 | { |
||
20 | closeProfile(); |
||
21 | } |
||
22 | |||
23 | bool ScLcms2ColorProfileImpl::isNull() const |
||
24 | { |
||
22518 | craig | 25 | return (m_profileHandle == nullptr); |
15127 | jghali | 26 | } |
27 | |||
28 | eColorSpaceType ScLcms2ColorProfileImpl::colorSpace() const |
||
29 | { |
||
30 | if (m_profileHandle) |
||
31 | return ScLcms2ColorMgmtEngineImpl::translateLcmsColorSpaceType( cmsGetColorSpace(m_profileHandle) ); |
||
32 | return ColorSpace_Unknown; |
||
33 | } |
||
34 | |||
23825 | jghali | 35 | eColorSpaceType ScLcms2ColorProfileImpl::connectionSpace() const |
36 | { |
||
37 | if (m_profileHandle) |
||
38 | return ScLcms2ColorMgmtEngineImpl::translateLcmsColorSpaceType( cmsGetPCS(m_profileHandle) ); |
||
39 | return ColorSpace_Unknown; |
||
40 | } |
||
41 | |||
15127 | jghali | 42 | eProfileClass ScLcms2ColorProfileImpl::deviceClass() const |
43 | { |
||
44 | if (m_profileHandle) |
||
45 | return ScLcms2ColorMgmtEngineImpl::translateLcmsProfileClass( cmsGetDeviceClass(m_profileHandle) ); |
||
46 | return Class_Unknown; |
||
47 | } |
||
48 | |||
23825 | jghali | 49 | int ScLcms2ColorProfileImpl::channelsOfColorSpace() const |
50 | { |
||
51 | if (m_profileHandle) |
||
52 | { |
||
53 | eColorSpaceType colorspace = ScLcms2ColorMgmtEngineImpl::translateLcmsColorSpaceType( cmsGetColorSpace(m_profileHandle) ); |
||
54 | return ScLcms2ColorMgmtEngineImpl::channelsOfColorspace(colorspace); |
||
55 | } |
||
56 | return 0; |
||
57 | } |
||
58 | |||
59 | int ScLcms2ColorProfileImpl::channelsOfConnectionSpace() const |
||
60 | { |
||
61 | if (m_profileHandle) |
||
62 | { |
||
63 | eColorSpaceType colorspace = ScLcms2ColorMgmtEngineImpl::translateLcmsColorSpaceType( cmsGetPCS(m_profileHandle) ); |
||
64 | return ScLcms2ColorMgmtEngineImpl::channelsOfColorspace(colorspace); |
||
65 | } |
||
66 | return 0; |
||
67 | } |
||
68 | |||
23489 | jghali | 69 | bool ScLcms2ColorProfileImpl::isSuitableForOutput() const |
70 | { |
||
71 | if (!m_profileHandle) |
||
72 | return false; |
||
73 | |||
74 | if (cmsIsMatrixShaper(m_profileHandle)) |
||
75 | return true; |
||
76 | |||
77 | cmsUInt32Number defaultIntent = cmsGetHeaderRenderingIntent(m_profileHandle); |
||
23668 | craig | 78 | return (cmsIsCLUT(m_profileHandle, defaultIntent, LCMS_USED_AS_INPUT) && |
79 | cmsIsCLUT(m_profileHandle, defaultIntent, LCMS_USED_AS_OUTPUT)); |
||
23489 | jghali | 80 | } |
81 | |||
15127 | jghali | 82 | QString ScLcms2ColorProfileImpl::productDescription() const |
83 | { |
||
24730 | jghali | 84 | if (!m_productDescription.isEmpty()) |
85 | return m_productDescription; |
||
86 | |||
87 | if (m_profileHandle == nullptr) |
||
88 | return QString(); |
||
89 | |||
90 | #ifdef _WIN32 |
||
91 | cmsUInt32Number descSize = cmsGetProfileInfo(m_profileHandle, cmsInfoDescription, "en", "US", nullptr, 0); |
||
92 | if (descSize > 0) |
||
15127 | jghali | 93 | { |
24730 | jghali | 94 | wchar_t* descData = (wchar_t*) malloc(descSize + sizeof(wchar_t)); |
95 | if (descData) |
||
96 | descSize = cmsGetProfileInfo(m_profileHandle, cmsInfoDescription, "en", "US", descData, descSize); |
||
97 | if (descData && (descSize > 0)) |
||
15127 | jghali | 98 | { |
24730 | jghali | 99 | uint stringLen = descSize / sizeof(wchar_t); |
100 | descData[stringLen] = 0; |
||
101 | m_productDescription = QString::fromWCharArray(descData); |
||
102 | } |
||
103 | free(descData); |
||
104 | } |
||
15143 | fschmid | 105 | #else |
24730 | jghali | 106 | cmsUInt32Number descSize = cmsGetProfileInfoASCII(m_profileHandle, cmsInfoDescription, "en", "US", nullptr, 0); |
107 | if (descSize > 0) |
||
108 | { |
||
109 | char* descData = (char*) malloc(descSize + sizeof(char)); |
||
110 | if (descData) |
||
111 | descSize = cmsGetProfileInfoASCII(m_profileHandle, cmsInfoDescription, "en", "US", descData, descSize); |
||
112 | if (descData && (descSize > 0)) |
||
113 | m_productDescription = QString(descData); |
||
114 | free(descData); |
||
115 | } |
||
15143 | fschmid | 116 | #endif |
24730 | jghali | 117 | |
15127 | jghali | 118 | return m_productDescription; |
119 | } |
||
120 | |||
22599 | craig | 121 | void ScLcms2ColorProfileImpl::closeProfile() |
15127 | jghali | 122 | { |
123 | if (m_profileHandle) |
||
124 | { |
||
125 | cmsCloseProfile(m_profileHandle); |
||
22518 | craig | 126 | m_profileHandle = nullptr; |
15127 | jghali | 127 | } |
22518 | craig | 128 | } |
23515 | jghali | 129 | |
130 | bool ScLcms2ColorProfileImpl::save(QByteArray& profileData) const |
||
131 | { |
||
132 | if (!m_profileHandle) |
||
133 | return false; |
||
134 | profileData.clear(); |
||
135 | |||
136 | // First retrieve profile size |
||
137 | cmsUInt32Number bytesNeeded = 0; |
||
24730 | jghali | 138 | bool done = cmsSaveProfileToMem(m_profileHandle, nullptr, &bytesNeeded); |
23515 | jghali | 139 | if (!done) |
140 | return false; |
||
141 | |||
142 | // Allocate array for profile data |
||
143 | profileData.resize(bytesNeeded); |
||
23780 | jghali | 144 | if (profileData.size() != static_cast<int>(bytesNeeded)) |
23515 | jghali | 145 | return false; |
146 | done = cmsSaveProfileToMem(m_profileHandle, profileData.data(), &bytesNeeded); |
||
147 | |||
148 | return done; |
||
23668 | craig | 149 | } |