Rev 23489 | Rev 23668 | Go to most recent revision | 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) |
||
13 | : ScColorProfileImplBase(engine), m_profileHandle(lcmsProfile) |
||
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 | |||
35 | eProfileClass ScLcms2ColorProfileImpl::deviceClass() const |
||
36 | { |
||
37 | if (m_profileHandle) |
||
38 | return ScLcms2ColorMgmtEngineImpl::translateLcmsProfileClass( cmsGetDeviceClass(m_profileHandle) ); |
||
39 | return Class_Unknown; |
||
40 | } |
||
41 | |||
23489 | jghali | 42 | bool ScLcms2ColorProfileImpl::isSuitableForOutput() const |
43 | { |
||
44 | if (!m_profileHandle) |
||
45 | return false; |
||
46 | |||
47 | if (cmsIsMatrixShaper(m_profileHandle)) |
||
48 | return true; |
||
49 | |||
50 | cmsUInt32Number defaultIntent = cmsGetHeaderRenderingIntent(m_profileHandle); |
||
51 | if (cmsIsCLUT(m_profileHandle, defaultIntent, LCMS_USED_AS_INPUT) && |
||
52 | cmsIsCLUT(m_profileHandle, defaultIntent, LCMS_USED_AS_OUTPUT)) |
||
53 | { |
||
54 | return true; |
||
55 | } |
||
56 | return false; |
||
57 | } |
||
58 | |||
15127 | jghali | 59 | QString ScLcms2ColorProfileImpl::productDescription() const |
60 | { |
||
61 | if (m_productDescription.isEmpty()) |
||
62 | { |
||
63 | if (m_profileHandle) |
||
64 | { |
||
15143 | fschmid | 65 | #ifdef _WIN32 |
22518 | craig | 66 | cmsUInt32Number descSize = cmsGetProfileInfo(m_profileHandle, cmsInfoDescription, "en", "US", nullptr, 0); |
15127 | jghali | 67 | if (descSize > 0) |
68 | { |
||
69 | wchar_t* descData = (wchar_t*) malloc(descSize + sizeof(wchar_t)); |
||
70 | descSize = cmsGetProfileInfo(m_profileHandle, cmsInfoDescription, "en", "US", descData, descSize); |
||
71 | if (descSize > 0) |
||
72 | { |
||
15135 | jghali | 73 | uint stringLen = descSize / sizeof(wchar_t); |
74 | descData[stringLen] = 0; |
||
15127 | jghali | 75 | if (sizeof(wchar_t) == sizeof(QChar)) { |
15135 | jghali | 76 | m_productDescription = QString::fromUtf16((ushort *) descData); |
15127 | jghali | 77 | } else { |
15135 | jghali | 78 | m_productDescription = QString::fromUcs4((uint *) descData); |
15127 | jghali | 79 | } |
80 | free(descData); |
||
81 | } |
||
82 | } |
||
15143 | fschmid | 83 | #else |
22518 | craig | 84 | cmsUInt32Number descSize = cmsGetProfileInfoASCII(m_profileHandle, cmsInfoDescription, "en", "US", nullptr, 0); |
15143 | fschmid | 85 | if (descSize > 0) |
86 | { |
||
87 | char* descData = (char*) malloc(descSize + sizeof(char)); |
||
88 | descSize = cmsGetProfileInfoASCII(m_profileHandle, cmsInfoDescription, "en", "US", descData, descSize); |
||
89 | if (descSize > 0) |
||
90 | { |
||
91 | m_productDescription = QString(descData); |
||
92 | free(descData); |
||
93 | } |
||
94 | } |
||
95 | #endif |
||
15127 | jghali | 96 | } |
97 | } |
||
98 | return m_productDescription; |
||
99 | } |
||
100 | |||
22599 | craig | 101 | void ScLcms2ColorProfileImpl::closeProfile() |
15127 | jghali | 102 | { |
103 | if (m_profileHandle) |
||
104 | { |
||
105 | cmsCloseProfile(m_profileHandle); |
||
22518 | craig | 106 | m_profileHandle = nullptr; |
15127 | jghali | 107 | } |
22518 | craig | 108 | } |
23515 | jghali | 109 | |
110 | bool ScLcms2ColorProfileImpl::save(QByteArray& profileData) const |
||
111 | { |
||
112 | if (!m_profileHandle) |
||
113 | return false; |
||
114 | profileData.clear(); |
||
115 | |||
116 | // First retrieve profile size |
||
117 | cmsUInt32Number bytesNeeded = 0; |
||
118 | bool done = cmsSaveProfileToMem(m_profileHandle, 0, &bytesNeeded); |
||
119 | if (!done) |
||
120 | return false; |
||
121 | |||
122 | // Allocate array for profile data |
||
123 | profileData.resize(bytesNeeded); |
||
124 | if (profileData.size() != bytesNeeded) |
||
125 | return false; |
||
126 | done = cmsSaveProfileToMem(m_profileHandle, profileData.data(), &bytesNeeded); |
||
127 | |||
128 | return done; |
||
129 | } |