krita
kis_profile.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <cfloat>
00023 #include <cmath>
00024 #include <config.h>
00025 #include LCMS_HEADER
00026
00027 #include <qimage.h>
00028 #include <qtextstream.h>
00029 #include <qfile.h>
00030
00031 #include <kdebug.h>
00032
00033 #include "kis_profile.h"
00034 #include "kis_global.h"
00035
00036 #include "ksharedptr.h"
00037
00038 #include <X11/Xlib.h>
00039 #include <X11/Xatom.h>
00040 #include <fixx11h.h>
00041
00042 KisProfile::KisProfile(QByteArray rawData)
00043 : m_rawData(rawData),
00044 m_filename( QString() ),
00045 m_valid( false ),
00046 m_suitableForOutput(false)
00047 {
00048 m_profile = cmsOpenProfileFromMem(rawData.data(), (DWORD)rawData.size());
00049 init();
00050 }
00051
00052 KisProfile::KisProfile(const QString& file)
00053 : m_filename(file),
00054 m_valid( false ),
00055 m_suitableForOutput( false )
00056 {
00057 }
00058
00059 KisProfile::KisProfile(const cmsHPROFILE profile)
00060 : m_profile(profile),
00061 m_filename( QString() ),
00062 m_valid( true )
00063 {
00064 size_t bytesNeeded=0;
00065
00066
00067 _cmsSaveProfileToMem(m_profile, 0, &bytesNeeded);
00068 if(m_rawData.resize(bytesNeeded))
00069 {
00070 _cmsSaveProfileToMem(m_profile, m_rawData.data(), &bytesNeeded);
00071 cmsHPROFILE newprofile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD) bytesNeeded);
00072 cmsCloseProfile(m_profile);
00073 m_profile = newprofile;
00074 }
00075 else
00076 m_rawData.resize(0);
00077
00078 init();
00079 }
00080
00081 KisProfile::~KisProfile()
00082 {
00083 cmsCloseProfile(m_profile);
00084 }
00085
00086
00087 bool KisProfile::load()
00088 {
00089 QFile file(m_filename);
00090 file.open(IO_ReadOnly);
00091 m_rawData = file.readAll();
00092 m_profile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD)m_rawData.size());
00093 file.close();
00094
00095 if (m_profile == 0) {
00096 kdWarning() << "Failed to load profile from " << m_filename << endl;
00097 }
00098
00099 return init();
00100
00101 }
00102
00103 bool KisProfile::init()
00104 {
00105 if (m_profile) {
00106 m_colorSpaceSignature = cmsGetColorSpace(m_profile);
00107 m_deviceClass = cmsGetDeviceClass(m_profile);
00108 m_productName = cmsTakeProductName(m_profile);
00109 m_productDescription = cmsTakeProductDesc(m_profile);
00110 m_productInfo = cmsTakeProductInfo(m_profile);
00111 m_valid = true;
00112
00113
00114
00115
00116
00117
00118
00119 cmsCIEXYZTRIPLE Primaries;
00120
00121 if (cmsTakeColorants(&Primaries, m_profile))
00122 {
00123 m_suitableForOutput = true;
00124 }
00125
00126 #if 0
00127
00128
00129
00130 cmsCloseProfile(m_profile);
00131 m_profile = 0;
00132
00133 #endif
00134 return true;
00135 }
00136 return false;
00137 }
00138
00139 cmsHPROFILE KisProfile::profile()
00140 {
00141 #if 0
00142 if (m_profile = 0) {
00143 QFile file(m_filename);
00144 file.open(IO_ReadOnly);
00145 m_rawData = file.readAll();
00146 m_profile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD)m_rawData.size());
00147 file.close();
00148 }
00149 #endif
00150 return m_profile;
00151 }
00152
00153 bool KisProfile::save()
00154 {
00155 return false;
00156 }
00157
00158 KisAnnotationSP KisProfile::annotation() const
00159 {
00160
00161
00162 if (!m_rawData.isEmpty())
00163 return new KisAnnotation("icc", productName(), m_rawData);
00164 else
00165 return 0;
00166 }
00167
00168 KisProfile * KisProfile::getScreenProfile (int screen)
00169 {
00170
00171 #ifdef Q_WS_X11
00172
00173 Atom type;
00174 int format;
00175 unsigned long nitems;
00176 unsigned long bytes_after;
00177 Q_UINT8 * str;
00178
00179 static Atom icc_atom = XInternAtom( qt_xdisplay(), "_ICC_PROFILE", False );
00180
00181 if ( XGetWindowProperty ( qt_xdisplay(),
00182 qt_xrootwin( screen ),
00183 icc_atom,
00184 0,
00185 INT_MAX,
00186 False,
00187 XA_CARDINAL,
00188 &type,
00189 &format,
00190 &nitems,
00191 &bytes_after,
00192 (unsigned char **) &str)
00193 ) {
00194
00195 QByteArray bytes (nitems);
00196 bytes.assign((char*)str, (Q_UINT32)nitems);
00197
00198 return new KisProfile(bytes);
00199 } else {
00200 return NULL;
00201 }
00202 #else
00203 return NULL;
00204
00205 #endif
00206 }
00207
00208
|