Rev 23778 | Rev 23780 | 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) |
||
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 | |||
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); |
||
23668 | craig | 51 | return (cmsIsCLUT(m_profileHandle, defaultIntent, LCMS_USED_AS_INPUT) && |
52 | cmsIsCLUT(m_profileHandle, defaultIntent, LCMS_USED_AS_OUTPUT)); |
||
23489 | jghali | 53 | } |
54 | |||
15127 | jghali | 55 | QString ScLcms2ColorProfileImpl::productDescription() const |
56 | { |
||
57 | if (m_productDescription.isEmpty()) |
||
58 | { |
||
59 | if (m_profileHandle) |
||
60 | { |
||
15143 | fschmid | 61 | #ifdef _WIN32 |
22518 | craig | 62 | cmsUInt32Number descSize = cmsGetProfileInfo(m_profileHandle, cmsInfoDescription, "en", "US", nullptr, 0); |
15127 | jghali | 63 | if (descSize > 0) |
64 | { |
||
65 | wchar_t* descData = (wchar_t*) malloc(descSize + sizeof(wchar_t)); |
||
23778 | jghali | 66 | if (descData) |
67 | descSize = cmsGetProfileInfo(m_profileHandle, cmsInfoDescription, "en", "US", descData, descSize); |
||
68 | if (descData && (descSize > 0)) |
||
15127 | jghali | 69 | { |
15135 | jghali | 70 | uint stringLen = descSize / sizeof(wchar_t); |
71 | descData[stringLen] = 0; |
||
23779 | jghali | 72 | m_productDescription = QString::fromWCharArray(descData); |
15127 | jghali | 73 | } |
23778 | jghali | 74 | free(descData); |
15127 | jghali | 75 | } |
15143 | fschmid | 76 | #else |
22518 | craig | 77 | cmsUInt32Number descSize = cmsGetProfileInfoASCII(m_profileHandle, cmsInfoDescription, "en", "US", nullptr, 0); |
15143 | fschmid | 78 | if (descSize > 0) |
79 | { |
||
80 | char* descData = (char*) malloc(descSize + sizeof(char)); |
||
23778 | jghali | 81 | if (descData) |
82 | descSize = cmsGetProfileInfoASCII(m_profileHandle, cmsInfoDescription, "en", "US", descData, descSize); |
||
83 | if (descData && (descSize > 0)) |
||
15143 | fschmid | 84 | m_productDescription = QString(descData); |
23778 | jghali | 85 | free(descData); |
15143 | fschmid | 86 | } |
87 | #endif |
||
15127 | jghali | 88 | } |
89 | } |
||
90 | return m_productDescription; |
||
91 | } |
||
92 | |||
22599 | craig | 93 | void ScLcms2ColorProfileImpl::closeProfile() |
15127 | jghali | 94 | { |
95 | if (m_profileHandle) |
||
96 | { |
||
97 | cmsCloseProfile(m_profileHandle); |
||
22518 | craig | 98 | m_profileHandle = nullptr; |
15127 | jghali | 99 | } |
22518 | craig | 100 | } |
23515 | jghali | 101 | |
102 | bool ScLcms2ColorProfileImpl::save(QByteArray& profileData) const |
||
103 | { |
||
104 | if (!m_profileHandle) |
||
105 | return false; |
||
106 | profileData.clear(); |
||
107 | |||
108 | // First retrieve profile size |
||
109 | cmsUInt32Number bytesNeeded = 0; |
||
110 | bool done = cmsSaveProfileToMem(m_profileHandle, 0, &bytesNeeded); |
||
111 | if (!done) |
||
112 | return false; |
||
113 | |||
114 | // Allocate array for profile data |
||
115 | profileData.resize(bytesNeeded); |
||
116 | if (profileData.size() != bytesNeeded) |
||
117 | return false; |
||
118 | done = cmsSaveProfileToMem(m_profileHandle, profileData.data(), &bytesNeeded); |
||
119 | |||
120 | return done; |
||
23668 | craig | 121 | } |