Krita Source Code Documentation
Loading...
Searching...
No Matches
KoColorSet::Private Class Reference

#include <KoColorSet_p.h>

Public Member Functions

KisSwatchGroupSP global ()
 
bool init ()
 
bool loadAcb ()
 
bool loadAco ()
 
bool loadAct ()
 
bool loadAse ()
 
bool loadCss ()
 
bool loadGpl ()
 
bool loadKpl ()
 
bool loadPsp ()
 
bool loadRiff ()
 
bool loadSbz ()
 
bool loadXml ()
 
 Private (KoColorSet *a_colorSet)
 
bool saveGpl (QIODevice *dev) const
 
bool saveKpl (QIODevice *dev) const
 

Public Attributes

KoColorSet * colorSet {0}
 
int columns
 
QString comment
 
QByteArray data
 
bool isLocked {false}
 
KoColorSet::PaletteType paletteType {UNKNOWN}
 
QList< KisSwatchGroupSP > swatchGroups
 
KUndo2Stack undoStack
 

Private Member Functions

KoColorSet::PaletteType detectFormat (const QString &fileName, const QByteArray &ba)
 
const KoColorProfile * loadColorProfile (QScopedPointer< KoStore > &store, const QString &path, const QString &modelId, const QString &colorDepthId)
 
bool loadKplColorset (QScopedPointer< KoStore > &store)
 
void loadKplGroup (const QDomDocument &doc, const QDomElement &parentElement, KisSwatchGroupSP group, QString version)
 
bool loadKplProfiles (QScopedPointer< KoStore > &store)
 
bool loadSbzSwatchbook (QScopedPointer< KoStore > &store)
 
bool loadScribusXmlPalette (KoColorSet *set, QXmlStreamReader *xml)
 
quint8 readByte (QIODevice *io)
 
float readFloat (QIODevice *io)
 
qint32 readInt (QIODevice *io)
 
quint16 readShort (QIODevice *io)
 
QString readUnicodeString (QIODevice *io, bool sizeIsInt=false)
 
void saveKplGroup (QDomDocument &doc, QDomElement &groupEle, const KisSwatchGroupSP group, QSet< const KoColorSpace * > &colorSetSet) const
 
void scribusParseColor (KoColorSet *set, QXmlStreamReader *xml)
 

Friends

struct AddGroupCommand
 
struct AddSwatchCommand
 
struct ChangeGroupNameCommand
 
struct ClearCommand
 
struct MoveGroupCommand
 
struct RemoveGroupCommand
 
struct RemoveSwatchCommand
 
struct SetColumnCountCommand
 
struct SetCommentCommand
 
struct SetPaletteTypeCommand
 

Detailed Description

Definition at line 27 of file KoColorSet_p.h.

Constructor & Destructor Documentation

◆ Private()

KoColorSet::Private::Private ( KoColorSet * a_colorSet)

Definition at line 1041 of file KoColorSet.cpp.

1042 : colorSet(a_colorSet)
1043{
1046 group->setName(KoColorSet::GLOBAL_GROUP_NAME);
1047 swatchGroups.clear();
1048 swatchGroups.append(group);
1049}
void setUndoLimit(int limit)
The KisSwatchGroup class stores a matrix of color swatches swatches can accessed using (x,...
KUndo2Stack undoStack
KoColorSet * colorSet
QList< KisSwatchGroupSP > swatchGroups
static const QString GLOBAL_GROUP_NAME
Definition KoColorSet.h:33

References KoColorSet::GLOBAL_GROUP_NAME, KUndo2QStack::setUndoLimit(), swatchGroups, and undoStack.

Member Function Documentation

◆ detectFormat()

KoColorSet::PaletteType KoColorSet::Private::detectFormat ( const QString & fileName,
const QByteArray & ba )
private

Definition at line 1051 of file KoColorSet.cpp.

1052{
1053 QFileInfo fi(fileName);
1054
1055 // .pal
1056 if (ba.startsWith("RIFF") && ba.indexOf("PAL data", 8)) {
1057 return KoColorSet::RIFF_PAL;
1058 }
1059 // .gpl
1060 else if (ba.startsWith("GIMP Palette")) {
1061 return KoColorSet::GPL;
1062 }
1063 // .pal
1064 else if (ba.startsWith("JASC-PAL")) {
1065 return KoColorSet::PSP_PAL;
1066 }
1067 else if (ba.contains("krita/x-colorset") || ba.contains("application/x-krita-palette")) {
1068 return KoColorSet::KPL;
1069 }
1070 else if (fi.suffix().toLower() == "aco") {
1071 return KoColorSet::ACO;
1072 }
1073 else if (fi.suffix().toLower() == "act") {
1074 return KoColorSet::ACT;
1075 }
1076 else if (fi.suffix().toLower() == "xml") {
1077 return KoColorSet::XML;
1078 }
1079 else if (fi.suffix().toLower() == "sbz") {
1080 return KoColorSet::SBZ;
1081 }
1082 else if (fi.suffix().toLower() == "ase" || ba.startsWith("ASEF")) {
1083 return KoColorSet::ASE;
1084 }
1085 else if (fi.suffix().toLower() == "acb" || ba.startsWith("8BCB")) {
1086 return KoColorSet::ACB;
1087 }
1088 else if (fi.suffix().toLower() == "css") {
1089 return KoColorSet::CSS;
1090 }
1091 return KoColorSet::UNKNOWN;
1092}

References KoColorSet::ACB, KoColorSet::ACO, KoColorSet::ACT, KoColorSet::ASE, KoColorSet::CSS, KoColorSet::GPL, KoColorSet::KPL, KoColorSet::PSP_PAL, KoColorSet::RIFF_PAL, KoColorSet::SBZ, KoColorSet::UNKNOWN, and KoColorSet::XML.

◆ global()

KisSwatchGroupSP KoColorSet::Private::global ( )
inline

Definition at line 34 of file KoColorSet_p.h.

34 {
35 Q_ASSERT(swatchGroups.size() > 0 && swatchGroups.first()->name() == GLOBAL_GROUP_NAME);
36 return swatchGroups.first();
37 }

References KoColorSet::GLOBAL_GROUP_NAME, and swatchGroups.

◆ init()

bool KoColorSet::Private::init ( )

Definition at line 1270 of file KoColorSet.cpp.

1271{
1272 // just in case this is a reload (eg by KoEditColorSetDialog),
1273 swatchGroups.clear();
1274 KisSwatchGroupSP globalGroup(new KisSwatchGroup);
1275 globalGroup->setName(KoColorSet::GLOBAL_GROUP_NAME);
1276 swatchGroups.append(globalGroup);
1277 undoStack.clear();
1278
1279 if (colorSet->filename().isNull()) {
1280 warnPigment << "Cannot load palette" << colorSet->name() << "there is no filename set";
1281 return false;
1282 }
1283 if (data.isNull()) {
1284 QFile file(colorSet->filename());
1285 if (file.size() == 0) {
1286 warnPigment << "Cannot load palette" << colorSet->name() << "there is no data available";
1287 return false;
1288 }
1289 if (!file.open(QIODevice::ReadOnly)) {
1290 warnPigment << "Cannot load palette" << colorSet->name() << ":" << file.errorString();
1291 return false;
1292 }
1293 data = file.readAll();
1294 file.close();
1295 }
1296
1297 bool res = false;
1299 switch(paletteType) {
1300 case GPL:
1301 res = loadGpl();
1302 break;
1303 case ACT:
1304 res = loadAct();
1305 break;
1306 case RIFF_PAL:
1307 res = loadRiff();
1308 break;
1309 case PSP_PAL:
1310 res = loadPsp();
1311 break;
1312 case ACO:
1313 res = loadAco();
1314 break;
1315 case XML:
1316 res = loadXml();
1317 break;
1318 case KPL:
1319 res = loadKpl();
1320 break;
1321 case SBZ:
1322 res = loadSbz();
1323 break;
1324 case ASE:
1325 res = loadAse();
1326 break;
1327 case ACB:
1328 res = loadAcb();
1329 break;
1330 case CSS:
1331 res = loadCss();
1332 break;
1333 default:
1334 res = false;
1335 }
1336 if (paletteType != KPL) {
1337 int rowCount = global()->colorCount() / global()->columnCount();
1338 if (global()->colorCount() % global()->columnCount() > 0) {
1339 rowCount ++;
1340 }
1341 global()->setRowCount(rowCount);
1342 }
1343 colorSet->setValid(res);
1345
1346 data.clear();
1347 undoStack.clear();
1348
1349 return res;
1350}
#define warnPigment
KoColorSet::PaletteType detectFormat(const QString &fileName, const QByteArray &ba)
KoColorSet::PaletteType paletteType
KisSwatchGroupSP global()
int rowCount() const
void updateThumbnail() override
updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something e...
int columnCount() const
quint32 colorCount() const
void setValid(bool valid)
QString filename
QString name

References KoColorSet::ACB, KoColorSet::ACO, KoColorSet::ACT, KoColorSet::ASE, KUndo2QStack::clear(), KoColorSet::colorCount(), KoColorSet::columnCount(), KoColorSet::CSS, KoColorSet::GLOBAL_GROUP_NAME, KoColorSet::GPL, KoColorSet::KPL, KoColorSet::paletteType(), KoColorSet::PSP_PAL, KoColorSet::RIFF_PAL, KoColorSet::rowCount(), KoColorSet::SBZ, KoColorSet::undoStack(), warnPigment, and KoColorSet::XML.

◆ loadAcb()

bool KoColorSet::Private::loadAcb ( )

Definition at line 2314 of file KoColorSet.cpp.

2315{
2316
2317 QFileInfo info(colorSet->filename());
2318
2319 QBuffer buf(&data);
2320 buf.open(QBuffer::ReadOnly);
2321
2322 QByteArray signature; // should be "8BCB";
2323 signature = buf.read(4);
2324 quint16 version = readShort(&buf);
2325 quint16 bookID = readShort(&buf);
2326 Q_UNUSED(bookID);
2327
2328 if (signature != "8BCB" && version!= 1) {
2329 return false;
2330 }
2331
2333 for (int i = 0; i< 4; i++) {
2334
2335 QString metadataString = readUnicodeString(&buf, true);
2336 if (metadataString.startsWith("\"")) {
2337 metadataString = metadataString.remove(0, 1);
2338 }
2339 if (metadataString.endsWith("\"")) {
2340 metadataString.chop(1);
2341 }
2342 if (metadataString.startsWith("$$$/")) {
2343 if (metadataString.contains("=")) {
2344 metadataString = metadataString.split("=").last();
2345 } else {
2346 metadataString = QString();
2347 }
2348 }
2349 metadata.append(metadataString);
2350 }
2351 QString title = metadata.at(0);
2352 colorSet->setName(title);
2353 QString prefix = metadata.at(1);
2354 QString postfix = metadata.at(2);
2355 QString description = metadata.at(3);
2356 colorSet->setComment(description);
2357
2358 quint16 numColors = readShort(&buf);
2359 quint16 numColumns = readShort(&buf);
2360 numColumns = numColumns > 0 ? numColumns : 8; // overwrite with sane default in case of 0
2361 colorSet->setColumnCount(numColumns);
2362 quint16 numKeyColorPage = readShort(&buf);
2363 Q_UNUSED(numKeyColorPage);
2364 quint16 colorType = readShort(&buf);
2365
2367 if (colorType == 2) {
2368 QString profileName = "U.S. Web Coated (SWOP) v2";
2370 } else if (colorType == 7) {
2372 }
2373
2374 for (quint16 i = 0; i < numColors; i++) {
2375 KisSwatch swatch;
2377 name << prefix;
2378 name << readUnicodeString(&buf, true);
2379 name << postfix;
2380 swatch.setName(name.join(" ").trimmed());
2381 QByteArray key; // should be "8BCB";
2382 key = buf.read(6);
2383 swatch.setId(QString::fromLatin1(key));
2384 swatch.setSpotColor(true);
2385 quint8 c1 = readByte(&buf);
2386 quint8 c2 = readByte(&buf);
2387 quint8 c3 = readByte(&buf);
2388 KoColor c(cs);
2389 if (colorType == 0) {
2390 c.data()[0] = c3;
2391 c.data()[1] = c2;
2392 c.data()[2] = c1;
2393 } else if (colorType == 2) {
2394 quint8 c4 = readByte(&buf);
2395 c.data()[0] = c1;
2396 c.data()[1] = c2;
2397 c.data()[2] = c3;
2398 c.data()[3] = c4;
2399 } else if (colorType == 7) {
2400 c.data()[0] = c1;
2401 c.data()[1] = c2;
2402 c.data()[2] = c3;
2403 }
2404 c.setOpacity(1.0);
2405 swatch.setColor(c);
2406 colorSet->addSwatch(swatch);
2407 }
2408
2409 return true;
2410}
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID CMYKAColorModelID("CMYKA", ki18n("CMYK/Alpha"))
const KoID LABAColorModelID("LABA", ki18n("L*a*b*/Alpha"))
void setSpotColor(bool spotColor)
Definition KisSwatch.cpp:38
void setColor(const KoColor &color)
Definition KisSwatch.cpp:32
void setId(const QString &id)
Definition KisSwatch.cpp:26
void setName(const QString &name)
Definition KisSwatch.cpp:20
quint8 readByte(QIODevice *io)
quint16 readShort(QIODevice *io)
QString readUnicodeString(QIODevice *io, bool sizeIsInt=false)
void setColumnCount(int columns)
void addSwatch(const KisSwatch &swatch, const QString &groupName=GLOBAL_GROUP_NAME, int column=-1, int row=-1)
Add a color to the palette.
void setComment(QString comment)
QString id() const
Definition KoID.cpp:63
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
const KoColorSpace * rgb8(const QString &profileName=QString())
void setName(const QString &name)
QMap< QString, QVariant > metadata
KoResourceSignature signature() const

References CMYKAColorModelID, KoColorSpaceRegistry::colorSpace(), KoColor::data(), KoID::id(), KoColorSpaceRegistry::instance(), Integer8BitsColorDepthID, LABAColorModelID, KoResource::metadata, KoResource::name, KoColorSpaceRegistry::rgb8(), KisSwatch::setColor(), KisSwatch::setId(), KisSwatch::setName(), KoColor::setOpacity(), KisSwatch::setSpotColor(), KoResource::signature(), and KoResource::version.

◆ loadAco()

bool KoColorSet::Private::loadAco ( )

Definition at line 1810 of file KoColorSet.cpp.

1811{
1812 QFileInfo info(colorSet->filename());
1813 colorSet->setName(info.completeBaseName());
1814
1815 QBuffer buf(&data);
1816 buf.open(QBuffer::ReadOnly);
1817
1818 quint16 version = readShort(&buf);
1819 quint16 numColors = readShort(&buf);
1820 KisSwatch swatch;
1821
1822 if (version == 1 && buf.size() > 4+numColors*10) {
1823 buf.seek(4+numColors*10);
1824 version = readShort(&buf);
1825 numColors = readShort(&buf);
1826 }
1827
1828 const quint16 quint16_MAX = 65535;
1829
1831
1832 for (int i = 0; i < numColors && !buf.atEnd(); ++i) {
1833
1834 quint16 colorSpace = readShort(&buf);
1835 quint16 ch1 = readShort(&buf);
1836 quint16 ch2 = readShort(&buf);
1837 quint16 ch3 = readShort(&buf);
1838 quint16 ch4 = readShort(&buf);
1839
1840 bool skip = false;
1841 if (colorSpace == 0) { // RGB
1843 KoColor c(KoColorSpaceRegistry::instance()->rgb16(srgb));
1844 reinterpret_cast<quint16*>(c.data())[0] = ch3;
1845 reinterpret_cast<quint16*>(c.data())[1] = ch2;
1846 reinterpret_cast<quint16*>(c.data())[2] = ch1;
1847 c.setOpacity(OPACITY_OPAQUE_U8);
1848 swatch.setColor(c);
1849 }
1850 else if (colorSpace == 1) { // HSB
1851 QColor qc;
1852 qc.setHsvF(ch1 / 65536.0, ch2 / 65536.0, ch3 / 65536.0);
1853 KoColor c(qc, KoColorSpaceRegistry::instance()->rgb16());
1854 c.setOpacity(OPACITY_OPAQUE_U8);
1855 swatch.setColor(c);
1856 }
1857 else if (colorSpace == 2) { // CMYK
1859 reinterpret_cast<quint16*>(c.data())[0] = quint16_MAX - ch1;
1860 reinterpret_cast<quint16*>(c.data())[1] = quint16_MAX - ch2;
1861 reinterpret_cast<quint16*>(c.data())[2] = quint16_MAX - ch3;
1862 reinterpret_cast<quint16*>(c.data())[3] = quint16_MAX - ch4;
1863 c.setOpacity(OPACITY_OPAQUE_U8);
1864 swatch.setColor(c);
1865 }
1866 else if (colorSpace == 7) { // LAB
1868 reinterpret_cast<quint16*>(c.data())[0] = ch3;
1869 reinterpret_cast<quint16*>(c.data())[1] = ch2;
1870 reinterpret_cast<quint16*>(c.data())[2] = ch1;
1872 swatch.setColor(c);
1873 }
1874 else if (colorSpace == 8) { // GRAY
1876 reinterpret_cast<quint16*>(c.data())[0] = ch1 * (quint16_MAX / 10000);
1878 swatch.setColor(c);
1879 }
1880 else {
1881 warnPigment << "Unsupported colorspace in palette" << colorSet->filename() << "(" << colorSpace << ")";
1882 skip = true;
1883 }
1884
1885 if (version == 2) {
1886 QString name = readUnicodeString(&buf, true);
1887 swatch.setName(name);
1888 }
1889 if (!skip) {
1890 group->addSwatch(swatch);
1891 }
1892 }
1893 return true;
1894}
const KoID GrayAColorModelID("GRAYA", ki18n("Grayscale/Alpha"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
const quint8 OPACITY_OPAQUE_U8
KisSwatchGroupSP getGlobalGroup() const
getGlobalGroup
virtual const KoColorProfile * profile() const =0
void setOpacity(quint8 alpha)
Definition KoColor.cpp:333
quint8 * data()
Definition KoColor.h:144
const quint16 quint16_MAX
Definition kis_global.h:25

References CMYKAColorModelID, KoColor::data(), GrayAColorModelID, KoID::id(), KoColorSpaceRegistry::instance(), Integer16BitsColorDepthID, KoResource::name, OPACITY_OPAQUE_U8, KoColorSpace::profile(), quint16_MAX, KoColorSpaceRegistry::rgb8(), KisSwatch::setColor(), KisSwatch::setName(), KoColor::setOpacity(), KoResource::version, and warnPigment.

◆ loadAct()

bool KoColorSet::Private::loadAct ( )

Definition at line 1448 of file KoColorSet.cpp.

1449{
1450 QFileInfo info(colorSet->filename());
1451 colorSet->setName(info.completeBaseName());
1452 KisSwatch swatch;
1453 int numOfTriplets = int(data.size() / 3);
1454 for (int i = 0; i < numOfTriplets * 3; i += 3) {
1455 quint8 r = data[i];
1456 quint8 g = data[i+1];
1457 quint8 b = data[i+2];
1458 swatch.setColor(KoColor(QColor(r, g, b), KoColorSpaceRegistry::instance()->rgb8()));
1459 global()->addSwatch(swatch);
1460 }
1461 return true;
1462}

References KoColorSpaceRegistry::instance(), and KisSwatch::setColor().

◆ loadAse()

bool KoColorSet::Private::loadAse ( )

Definition at line 2209 of file KoColorSet.cpp.

2210{
2211 QFileInfo info(colorSet->filename());
2212 colorSet->setName(info.completeBaseName());
2213
2214 QBuffer buf(&data);
2215 buf.open(QBuffer::ReadOnly);
2216
2217 QByteArray signature; // should be "ASEF";
2218 signature = buf.read(4);
2219 quint16 version = readShort(&buf);
2220 quint16 version2 = readShort(&buf);
2221
2222 if (signature != "ASEF" && version!= 1 && version2 != 0) {
2223 qWarning() << "incorrect header:" << signature << version << version2;
2224 return false;
2225 }
2226 qint32 numBlocks = readInt(&buf);
2227
2228 QByteArray groupStart("\xC0\x01");
2229 QByteArray groupEnd("\xC0\x02");
2230 QByteArray swatchSig("\x00\x01");
2231
2232 bool inGroup = false;
2233 QString groupName;
2234 for (qint32 i = 0; i < numBlocks; i++) {
2235 QByteArray blockType;
2236 blockType = buf.read(2);
2237 qint32 blockSize = readInt(&buf);
2238 qint64 pos = buf.pos();
2239
2240 if (blockType == groupStart) {
2241 groupName = readUnicodeString(&buf);
2242 colorSet->addGroup(groupName);
2243 inGroup = true;
2244 }
2245 else if (blockType == groupEnd) {
2246 int colorCount = colorSet->getGroup(groupName)->colorCount();
2247 int columns = colorSet->columnCount();
2248 int rows = colorCount/columns;
2249 if (colorCount % columns > 0) {
2250 rows += 1;
2251 }
2252 colorSet->getGroup(groupName)->setRowCount(rows);
2253 inGroup = false;
2254 }
2255 else /* if (blockType == swatchSig)*/ {
2256 KisSwatch swatch;
2257 swatch.setName(readUnicodeString(&buf).trimmed());
2258 QByteArray colorModel;
2259 QDomDocument doc;
2260 colorModel = buf.read(4);
2261 if (colorModel == "RGB ") {
2262 QDomElement elt = doc.createElement("sRGB");
2263
2264 elt.setAttribute("r", readFloat(&buf));
2265 elt.setAttribute("g", readFloat(&buf));
2266 elt.setAttribute("b", readFloat(&buf));
2267
2268 KoColor color = KoColor::fromXML(elt, "U8");
2269 swatch.setColor(color);
2270 } else if (colorModel == "CMYK") {
2271 QDomElement elt = doc.createElement("CMYK");
2272
2273 elt.setAttribute("c", readFloat(&buf));
2274 elt.setAttribute("m", readFloat(&buf));
2275 elt.setAttribute("y", readFloat(&buf));
2276 elt.setAttribute("k", readFloat(&buf));
2277 //try to select the default PS icc profile if possible.
2278 elt.setAttribute("space", "U.S. Web Coated (SWOP) v2");
2279
2280 KoColor color = KoColor::fromXML(elt, "U8");
2281 swatch.setColor(color);
2282 } else if (colorModel == "LAB ") {
2283 QDomElement elt = doc.createElement("Lab");
2284
2285 elt.setAttribute("L", readFloat(&buf)*100.0);
2286 elt.setAttribute("a", readFloat(&buf));
2287 elt.setAttribute("b", readFloat(&buf));
2288
2289 KoColor color = KoColor::fromXML(elt, "U16");
2290 swatch.setColor(color);
2291 } else if (colorModel == "GRAY") {
2292 QDomElement elt = doc.createElement("Gray");
2293
2294 elt.setAttribute("g", readFloat(&buf));
2295
2296 KoColor color = KoColor::fromXML(elt, "U8");
2297 swatch.setColor(color);
2298 }
2299 qint16 type = readShort(&buf);
2300 if (type == 1) { //0 is global, 2 is regular;
2301 swatch.setSpotColor(true);
2302 }
2303 if (inGroup) {
2304 colorSet->addSwatch(swatch, groupName);
2305 } else {
2306 colorSet->addSwatch(swatch);
2307 }
2308 }
2309 buf.seek(pos + qint64(blockSize));
2310 }
2311 return true;
2312}
float readFloat(QIODevice *io)
qint32 readInt(QIODevice *io)
KisSwatchGroupSP getGroup(const QString &name) const
getGroup
void addGroup(const QString &groupName, int columnCount=KisSwatchGroup::DEFAULT_COLUMN_COUNT, int rowCount=KisSwatchGroup::DEFAULT_ROW_COUNT)
addGroup Adds a new group.
static KoColor fromXML(const QDomElement &elt, const QString &channelDepthId)
Definition KoColor.cpp:350
QString trimmed(const QString &string)

References KoColorSet::colorCount(), KoColor::fromXML(), KisSwatch::setColor(), KisSwatch::setName(), KisSwatch::setSpotColor(), KoResource::signature(), and KoResource::version.

◆ loadColorProfile()

const KoColorProfile * KoColorSet::Private::loadColorProfile ( QScopedPointer< KoStore > & store,
const QString & path,
const QString & modelId,
const QString & colorDepthId )
private

Definition at line 1688 of file KoColorSet.cpp.

1692{
1693 if (!store->open(path)) {
1694 return nullptr;
1695 }
1696
1697 QByteArray bytes = store->read(store->size());
1698 store->close();
1699
1701 ->createColorProfile(modelId, colorDepthId, bytes);
1702 if (!profile || !profile->valid()) {
1703 return nullptr;
1704 }
1705
1706 return profile;
1707}
virtual bool valid() const =0
const KoColorProfile * createColorProfile(const QString &colorModelId, const QString &colorDepthId, const QByteArray &rawData)

References KoColorSpaceRegistry::createColorProfile(), KoColorSpaceRegistry::instance(), and KoColorProfile::valid().

◆ loadCss()

bool KoColorSet::Private::loadCss ( )

Definition at line 1528 of file KoColorSet.cpp.

1529{
1530 QFileInfo info(colorSet->filename());
1531 colorSet->setName(info.completeBaseName());
1532
1533 QString text = readAllLinesSafe(&data).join("").replace("\t", "").replace(" ", "");
1534
1535 QRegularExpression re("/\\*.*?\\*/");
1536
1537 text.remove(re); // Remove comments
1538
1539 KisSwatch swatch;
1540
1541 // Regex to detect a color in the palette
1542 QRegularExpression palette("(.*?){(?:[^:;]+:[^;]+;)*?color:(.*?)(?:;.*?)*?}");
1543
1544 QRegularExpressionMatchIterator colors = palette.globalMatch(text);
1545
1546 if (!colors.hasNext()) {
1547 warnPigment << "No color found in CSS palette : " << colorSet->filename();
1548 return false;
1549 }
1550
1551 while (colors.hasNext()) {
1552 QRegularExpressionMatch match = colors.next();
1553 QString colorInfo = match.captured();
1554 QString colorName = match.captured(1);
1555 QString colorValue = match.captured(2);
1556
1557 if (!colorInfo.startsWith(".") || colorValue.isEmpty()) {
1558 warnPigment << "Illegal CSS palette syntax : " << colorInfo;
1559 return false;
1560 }
1561
1562 QColor qColor;
1563
1564 colorName.remove(".");
1565 swatch.setName(colorName);
1566
1567 if (colorValue.startsWith("rgb")) {
1568 QStringList color;
1569
1570 if (colorValue.startsWith("rgba")) {
1571 colorValue.remove("rgba(").remove(")");
1572 color = colorValue.split(",");
1573
1574 if (color.size() != 4) {
1575 warnPigment << "Invalid RGBA color definition : " << colorInfo;
1576 return false;
1577 }
1578
1579 int alpha = color[3].toFloat() * 255;
1580
1581 if (alpha < 0 || alpha > 255) {
1582 warnPigment << "Invalid alpha parameter : " << colorInfo;
1583 return false;
1584 }
1585 }
1586 else {
1587 colorValue.remove("rgb(").remove(")");
1588
1589 color = colorValue.split(",");
1590
1591 if (color.size() != 3) {
1592 warnPigment << "Invalid RGB color definition : " << colorInfo;
1593 return false;
1594 }
1595 }
1596
1597 int rgb[3];
1598
1599 for (int i = 0; i < 3; i++) {
1600 if (color[i].endsWith("%")) {
1601 color[i].replace("%", "");
1602 rgb[i] = color[i].toFloat() / 100 * 255 ;
1603 }
1604 else {
1605 rgb[i] = color[i].toInt();
1606 };
1607 }
1608
1609 qColor = QColor(rgb[0], rgb[1], rgb[2]);
1610 }
1611 else if (colorValue.startsWith("hsl")) {
1612 QStringList color;
1613
1614 if (colorValue.startsWith("hsla")) {
1615 colorValue.remove("hsla(").remove(")").replace("%", "");
1616 color = colorValue.split(",");
1617 if (color.size() != 4) {
1618 warnPigment << "Invalid HSLA color definition : " << colorInfo;
1619 return false;
1620 }
1621
1622 float alpha = color[3].toFloat();
1623
1624 if (alpha < 0.0 || alpha > 1.0) {
1625 warnPigment << "Invalid alpha parameter : " << colorInfo;
1626 return false;
1627 }
1628
1629 }
1630 else {
1631 colorValue.remove("hsl(").remove(")").replace("%", "");
1632 color = colorValue.split(",");
1633 if (color.size() != 3) {
1634 warnPigment << "Invalid HSL color definition : " << colorInfo;
1635 return false;
1636 }
1637 }
1638
1639 float hue = color[0].toFloat() / 359;
1640 float saturation = color[1].toFloat() / 100;
1641 float lightness = color[2].toFloat() / 100;
1642
1643 if (hue < 0.0 || hue > 1.0) {
1644 warnPigment << "Invalid hue parameter : " << colorInfo;
1645 return false;
1646 }
1647
1648 if (saturation < 0.0 || saturation > 1.0) {
1649 warnPigment << "Invalid saturation parameter : " << colorInfo;
1650 return false;
1651 }
1652
1653 if (lightness < 0.0 || lightness > 1.0) {
1654 warnPigment << "Invalid lightness parameter : " << colorInfo;
1655 return false;
1656 }
1657
1658 qColor = QColor::fromHslF(hue, saturation, lightness);
1659
1660 }
1661 else if (colorValue.startsWith("#")) {
1662 if (colorValue.size() == 9) {
1663 // Convert the CSS format #RRGGBBAA to #RRGGBB
1664 // Due to QColor's 8 digits format being #AARRGGBB and that we do not load the alpha channel
1665 colorValue.truncate(7);
1666 }
1667
1668 qColor = QColor(colorValue);
1669 }
1670 else {
1671 warnPigment << "Unknown color declaration : " << colorInfo;
1672 return false;
1673 }
1674
1675 if (!qColor.isValid()) {
1676 warnPigment << "Invalid color definition : " << colorInfo;
1677 return false;
1678 }
1679
1680 swatch.setColor(KoColor(qColor, KoColorSpaceRegistry::instance()->rgb8()));
1681
1682 global()->addSwatch(swatch);
1683 }
1684
1685 return true;
1686}

References KoColorSpaceRegistry::instance(), KisSwatch::setColor(), KisSwatch::setName(), and warnPigment.

◆ loadGpl()

bool KoColorSet::Private::loadGpl ( )

Definition at line 1380 of file KoColorSet.cpp.

1381{
1382 if (data.isEmpty() || data.isNull() || data.length() < 12) {
1383 warnPigment << "Illegal Gimp palette file: " << colorSet->filename();
1384 return false;
1385 }
1386
1387 QStringList lines = readAllLinesSafe(&data);
1388
1389 if (!lines[0].startsWith("GIMP Palette")) {
1390 warnPigment << "Illegal Gimp palette file: " << colorSet->filename();
1391 return false;
1392 }
1393
1394 bool isGplVersion1 = true;
1395 quint32 index = 1;
1396
1397 // Read name, if one exists
1398 // If it exists, then that also means that this is not a "version 1" palette
1399 if (lines.size() >= 2 && lines[index].startsWith("Name: ")) {
1400 isGplVersion1 = false;
1401 colorSet->setName(lines[index].split(":")[1].trimmed());
1402 index += 1;
1403 }
1404 else {
1405 colorSet->setName(QFileInfo(colorSet->filename()).baseName());
1406 }
1407
1408 // If the palette isn't version 1, load and set the column count if it's defined
1409 if (!isGplVersion1 && lines.size() >= 3) {
1410 if (lines[index].startsWith("Columns: ")) {
1411 int columns = lines[index].split(":")[1].trimmed().toInt();
1413 warnPigment << "Refusing to set unreasonable number of columns (" << columns << ") in GIMP Palette file " << colorSet->filename() << " - using maximum number of allowed columns instead";
1415 }
1416 global()->setColumnCount(columns);
1417 index += 1;
1418 }
1419 }
1420
1421 qint32 r, g, b;
1422 KisSwatch swatch;
1423 for (qint32 i = index; i < lines.size(); i++) {
1424 if (lines[i].startsWith('#')) {
1425 comment += lines[i].mid(1).trimmed() + ' ';
1426 } else if (!lines[i].isEmpty()) {
1427 QStringList a = lines[i].replace('\t', ' ').split(' ', Qt::SkipEmptyParts);
1428
1429 if (a.count() < 3) {
1430 continue;
1431 }
1432
1433 r = qBound(0, a.takeFirst().toInt(), 255);
1434 g = qBound(0, a.takeFirst().toInt(), 255);
1435 b = qBound(0, a.takeFirst().toInt(), 255);
1436
1437 swatch.setColor(KoColor(QColor(r, g, b), KoColorSpaceRegistry::instance()->rgb8()));
1438
1439 QString name = a.join(" ");
1440 swatch.setName(name.isEmpty() || name == "Untitled" ? i18n("Untitled") : name);
1441
1442 global()->addSwatch(swatch);
1443 }
1444 }
1445 return true;
1446}
const int MAXIMUM_ALLOWED_COLUMNS
QList< KoSubpath * > split(const KoPathShape &path)

References KoColorSet::comment(), KoColorSpaceRegistry::instance(), MAXIMUM_ALLOWED_COLUMNS, KoResource::name, KisSwatch::setColor(), KisSwatch::setName(), and warnPigment.

◆ loadKpl()

bool KoColorSet::Private::loadKpl ( )

Definition at line 1785 of file KoColorSet.cpp.

1786{
1787 QBuffer buf(&data);
1788 buf.open(QBuffer::ReadOnly);
1789
1790 QScopedPointer<KoStore> store(
1792 "application/x-krita-palette",
1793 KoStore::Zip));
1794 if (!store || store->bad()) {
1795 return false;
1796 }
1797
1798 if (store->hasFile("profiles.xml") && !loadKplProfiles(store)) {
1799 return false;
1800 }
1801
1802 if (!loadKplColorset(store)) {
1803 return false;
1804 }
1805
1806 buf.close();
1807 return true;
1808}
bool loadKplColorset(QScopedPointer< KoStore > &store)
bool loadKplProfiles(QScopedPointer< KoStore > &store)
@ Read
Definition KoStore.h:29
@ Zip
Definition KoStore.h:30
static KoStore * createStore(const QString &fileName, Mode mode, const QByteArray &appIdentification=QByteArray(), Backend backend=Auto, bool writeMimetype=true)
Definition KoStore.cpp:39

References KoStore::createStore(), KoStore::Read, and KoStore::Zip.

◆ loadKplColorset()

bool KoColorSet::Private::loadKplColorset ( QScopedPointer< KoStore > & store)
private

Definition at line 1743 of file KoColorSet.cpp.

1744{
1745 if (!store->open("colorset.xml")) {
1746 return false;
1747 }
1748
1749 QByteArray bytes = store->read(store->size());
1750 store->close();
1751
1752 QDomDocument doc;
1753 if (!doc.setContent(bytes)) {
1754 return false;
1755 }
1756
1757 QDomElement root = doc.documentElement();
1758 colorSet->setName(root.attribute(KPL_PALETTE_NAME_ATTR));
1759 QString version = root.attribute(KPL_VERSION_ATTR);
1760 comment = root.attribute(KPL_PALETTE_COMMENT_ATTR);
1761
1762 int desiredColumnCount = root.attribute(KPL_PALETTE_COLUMN_COUNT_ATTR).toInt();
1763 if (desiredColumnCount > MAXIMUM_ALLOWED_COLUMNS) {
1764 warnPigment << "Refusing to set unreasonable number of columns (" << desiredColumnCount
1765 << ") in KPL palette file " << colorSet->filename()
1766 << " - setting maximum allowed column count instead.";
1768 } else {
1769 colorSet->setColumnCount(desiredColumnCount);
1770 }
1771
1773
1774 for (QDomElement g = root.firstChildElement(KPL_GROUP_TAG);
1775 !g.isNull();
1776 g = g.nextSiblingElement(KPL_GROUP_TAG)) {
1777 QString groupName = g.attribute(KPL_GROUP_NAME_ATTR);
1778 colorSet->addGroup(groupName);
1779 loadKplGroup(doc, g, colorSet->getGroup(groupName), version);
1780 }
1781
1782 return true;
1783}
void loadKplGroup(const QDomDocument &doc, const QDomElement &parentElement, KisSwatchGroupSP group, QString version)
static const QString KPL_PALETTE_COMMENT_ATTR
Definition KoColorSet.h:38
static const QString KPL_PALETTE_NAME_ATTR
Definition KoColorSet.h:37
static const QString KPL_PALETTE_COLUMN_COUNT_ATTR
Definition KoColorSet.h:36
static const QString KPL_GROUP_TAG
Definition KoColorSet.h:53
static const QString KPL_GROUP_NAME_ATTR
Definition KoColorSet.h:43
static const QString KPL_VERSION_ATTR
Definition KoColorSet.h:34

References KoColorSet::comment(), KoColorSet::KPL_GROUP_NAME_ATTR, KoColorSet::KPL_GROUP_TAG, KoColorSet::KPL_PALETTE_COLUMN_COUNT_ATTR, KoColorSet::KPL_PALETTE_COMMENT_ATTR, KoColorSet::KPL_PALETTE_NAME_ATTR, KoColorSet::KPL_VERSION_ATTR, MAXIMUM_ALLOWED_COLUMNS, KoResource::version, and warnPigment.

◆ loadKplGroup()

void KoColorSet::Private::loadKplGroup ( const QDomDocument & doc,
const QDomElement & parentElement,
KisSwatchGroupSP group,
QString version )
private

Definition at line 2547 of file KoColorSet.cpp.

2548{
2549 Q_UNUSED(doc);
2550 if (!parentEle.attribute(KPL_GROUP_ROW_COUNT_ATTR).isNull()) {
2551 group->setRowCount(parentEle.attribute(KPL_GROUP_ROW_COUNT_ATTR).toInt());
2552 }
2553 group->setColumnCount(colorSet->columnCount());
2554
2555 for (QDomElement swatchEle = parentEle.firstChildElement(KPL_SWATCH_TAG);
2556 !swatchEle.isNull();
2557 swatchEle = swatchEle.nextSiblingElement(KPL_SWATCH_TAG)) {
2558 QString colorDepthId = swatchEle.attribute(KPL_SWATCH_BITDEPTH_ATTR, Integer8BitsColorDepthID.id());
2559 KisSwatch swatch;
2560
2561 if (version == "1.0" && swatchEle.firstChildElement().tagName() == "Lab") {
2562 // previous version of krita had the values wrong, and scaled everything between 0 to 1,
2563 // but lab requires L = 0-100 and AB = -128-127.
2564 // TODO: write unittest for this.
2565 QDomElement el = swatchEle.firstChildElement();
2566 double L = KisDomUtils::toDouble(el.attribute("L"));
2567 el.setAttribute("L", L*100.0);
2568 double ab = KisDomUtils::toDouble(el.attribute("a"));
2569 if (ab <= .5) {
2570 ab = (0.5 - ab) * 2 * -128.0;
2571 } else {
2572 ab = (ab - 0.5) * 2 * 127.0;
2573 }
2574 el.setAttribute("a", ab);
2575
2576 ab = KisDomUtils::toDouble(el.attribute("b"));
2577 if (ab <= .5) {
2578 ab = (0.5 - ab) * 2 * -128.0;
2579 } else {
2580 ab = (ab - 0.5) * 2 * 127.0;
2581 }
2582 el.setAttribute("b", ab);
2583 swatch.setColor(KoColor::fromXML(el, colorDepthId));
2584 } else {
2585 swatch.setColor(KoColor::fromXML(swatchEle.firstChildElement(), colorDepthId));
2586 }
2587 swatch.setName(swatchEle.attribute(KPL_SWATCH_NAME_ATTR));
2588 swatch.setId(swatchEle.attribute(KPL_SWATCH_ID_ATTR));
2589 swatch.setSpotColor(swatchEle.attribute(KPL_SWATCH_SPOT_ATTR, "false") == "true" ? true : false);
2590 QDomElement positionEle = swatchEle.firstChildElement(KPL_SWATCH_POS_TAG);
2591 if (!positionEle.isNull()) {
2592 int rowNumber = positionEle.attribute(KPL_SWATCH_ROW_ATTR).toInt();
2593 int columnNumber = positionEle.attribute(KPL_SWATCH_COL_ATTR).toInt();
2594 if (columnNumber < 0 ||
2595 columnNumber >= colorSet->columnCount() ||
2596 rowNumber < 0
2597 ) {
2598 warnPigment << "Swatch" << swatch.name()
2599 << "of palette" << colorSet->name()
2600 << "has invalid position.";
2601 continue;
2602 }
2603 group->setSwatch(swatch, columnNumber, rowNumber);
2604 } else {
2605 group->addSwatch(swatch);
2606 }
2607 }
2608
2609 if (parentEle.attribute(KPL_GROUP_ROW_COUNT_ATTR).isNull()
2610 && group->colorCount() > 0
2611 && group->columnCount() > 0
2612 && (group->colorCount() / (group->columnCount()) + 1) < 20) {
2613 group->setRowCount((group->colorCount() / group->columnCount()) + 1);
2614 }
2615
2616}
QString name() const
Definition KisSwatch.h:24
static const QString KPL_SWATCH_TAG
Definition KoColorSet.h:52
static const QString KPL_SWATCH_ROW_ATTR
Definition KoColorSet.h:44
static const QString KPL_SWATCH_COL_ATTR
Definition KoColorSet.h:45
static const QString KPL_SWATCH_POS_TAG
Definition KoColorSet.h:51
static const QString KPL_GROUP_ROW_COUNT_ATTR
Definition KoColorSet.h:35
static const QString KPL_SWATCH_BITDEPTH_ATTR
Definition KoColorSet.h:49
static const QString KPL_SWATCH_SPOT_ATTR
Definition KoColorSet.h:47
static const QString KPL_SWATCH_NAME_ATTR
Definition KoColorSet.h:46
static const QString KPL_SWATCH_ID_ATTR
Definition KoColorSet.h:48
double toDouble(const QString &str, bool *ok=nullptr)

References KoColor::fromXML(), KoID::id(), Integer8BitsColorDepthID, KoColorSet::KPL_GROUP_ROW_COUNT_ATTR, KoColorSet::KPL_SWATCH_BITDEPTH_ATTR, KoColorSet::KPL_SWATCH_COL_ATTR, KoColorSet::KPL_SWATCH_ID_ATTR, KoColorSet::KPL_SWATCH_NAME_ATTR, KoColorSet::KPL_SWATCH_POS_TAG, KoColorSet::KPL_SWATCH_ROW_ATTR, KoColorSet::KPL_SWATCH_SPOT_ATTR, KoColorSet::KPL_SWATCH_TAG, KisSwatch::name(), KisSwatch::setColor(), KisSwatch::setId(), KisSwatch::setName(), KisSwatch::setSpotColor(), KisDomUtils::toDouble(), KoResource::version, and warnPigment.

◆ loadKplProfiles()

bool KoColorSet::Private::loadKplProfiles ( QScopedPointer< KoStore > & store)
private

Definition at line 1709 of file KoColorSet.cpp.

1710{
1711 if (!store->open("profiles.xml")) {
1712 return false;
1713 }
1714
1715 QByteArray bytes = store->read(store->size());
1716 store->close();
1717
1718 QDomDocument doc;
1719 if(!doc.setContent(bytes)) {
1720 return false;
1721 }
1722
1723 QDomElement root = doc.documentElement();
1724 for (QDomElement c = root.firstChildElement(KPL_PALETTE_PROFILE_TAG);
1725 !c.isNull();
1726 c = c.nextSiblingElement(KPL_PALETTE_PROFILE_TAG)) {
1727 QString name = c.attribute(KPL_PALETTE_NAME_ATTR);
1728 QString filename = c.attribute(KPL_PALETTE_FILENAME_ATTR);
1729 QString colorModelId = c.attribute(KPL_COLOR_MODEL_ID_ATTR);
1730 QString colorDepthId = c.attribute(KPL_COLOR_DEPTH_ID_ATTR);
1731
1733 continue;
1734 }
1735
1736 loadColorProfile(store, filename, colorModelId, colorDepthId);
1737 // TODO: What should happen if this fails?
1738 }
1739
1740 return true;
1741}
const KoColorProfile * loadColorProfile(QScopedPointer< KoStore > &store, const QString &path, const QString &modelId, const QString &colorDepthId)
static const QString KPL_COLOR_DEPTH_ID_ATTR
Definition KoColorSet.h:42
static const QString KPL_COLOR_MODEL_ID_ATTR
Definition KoColorSet.h:41
static const QString KPL_PALETTE_PROFILE_TAG
Definition KoColorSet.h:50
static const QString KPL_PALETTE_FILENAME_ATTR
Definition KoColorSet.h:39
const KoColorProfile * profileByName(const QString &name) const

References KoResource::filename, KoColorSpaceRegistry::instance(), KoColorSet::KPL_COLOR_DEPTH_ID_ATTR, KoColorSet::KPL_COLOR_MODEL_ID_ATTR, KoColorSet::KPL_PALETTE_FILENAME_ATTR, KoColorSet::KPL_PALETTE_NAME_ATTR, KoColorSet::KPL_PALETTE_PROFILE_TAG, KoResource::name, and KoColorSpaceRegistry::profileByName().

◆ loadPsp()

bool KoColorSet::Private::loadPsp ( )

Definition at line 1488 of file KoColorSet.cpp.

1489{
1490 QFileInfo info(colorSet->filename());
1491 colorSet->setName(info.completeBaseName());
1492 KisSwatch swatch;
1493 qint32 r, g, b;
1494
1495 QStringList l = readAllLinesSafe(&data);
1496 if (l.size() < 4) return false;
1497 if (l[0] != "JASC-PAL") return false;
1498 if (l[1] != "0100") return false;
1499
1500 int entries = l[2].toInt();
1501 if (entries < 0 || l.size() < entries + 3) return false;
1502
1504
1505 for (int i = 0; i < entries; ++i) {
1506
1507 QStringList a = l[i + 3].replace('\t', ' ').split(' ', Qt::SkipEmptyParts);
1508
1509 if (a.count() != 3) {
1510 continue;
1511 }
1512
1513 r = qBound(0, a[0].toInt(), 255);
1514 g = qBound(0, a[1].toInt(), 255);
1515 b = qBound(0, a[2].toInt(), 255);
1516
1517 swatch.setColor(KoColor(QColor(r, g, b),
1519
1520 QString name = a.join(" ");
1521 swatch.setName(name.isEmpty() ? i18n("Untitled") : name);
1522
1523 global->addSwatch(swatch);
1524 }
1525 return true;
1526}
int toInt(const QString &str, bool *ok=nullptr)

References KoColorSpaceRegistry::instance(), KoResource::name, KisSwatch::setColor(), and KisSwatch::setName().

◆ loadRiff()

bool KoColorSet::Private::loadRiff ( )

Definition at line 1464 of file KoColorSet.cpp.

1465{
1466 // https://worms2d.info/Palette_file
1467 QFileInfo info(colorSet->filename());
1468 colorSet->setName(info.completeBaseName());
1469 KisSwatch swatch;
1470
1471 RiffHeader header;
1472 memcpy(&header, data.constData(), sizeof(RiffHeader));
1473 header.colorcount = qFromBigEndian(header.colorcount);
1474
1475 for (int i = sizeof(RiffHeader);
1476 (i < (int)(sizeof(RiffHeader) + (header.colorcount * 4)) && i < data.size());
1477 i += 4) {
1478 quint8 r = data[i];
1479 quint8 g = data[i+1];
1480 quint8 b = data[i+2];
1481 swatch.setColor(KoColor(QColor(r, g, b), KoColorSpaceRegistry::instance()->rgb8()));
1482 colorSet->getGlobalGroup()->addSwatch(swatch);
1483 }
1484 return true;
1485}
quint16 colorcount

References RiffHeader::colorcount, KoColorSpaceRegistry::instance(), KoColorSpaceRegistry::rgb8(), and KisSwatch::setColor().

◆ loadSbz()

bool KoColorSet::Private::loadSbz ( )

Definition at line 2188 of file KoColorSet.cpp.

2188 {
2189 QBuffer buf(&data);
2190 buf.open(QBuffer::ReadOnly);
2191
2192 // &buf is a subclass of QIODevice
2193 QScopedPointer<KoStore> store(
2195 "application/x-swatchbook",
2196 KoStore::Zip));
2197 if (!store || store->bad()) {
2198 return false;
2199 }
2200
2201 if (store->hasFile("swatchbook.xml") && !loadSbzSwatchbook(store)) {
2202 return false;
2203 }
2204
2205 buf.close();
2206 return true;
2207}
bool loadSbzSwatchbook(QScopedPointer< KoStore > &store)

References KoStore::createStore(), KoStore::Read, and KoStore::Zip.

◆ loadSbzSwatchbook()

bool KoColorSet::Private::loadSbzSwatchbook ( QScopedPointer< KoStore > & store)
private

Definition at line 1896 of file KoColorSet.cpp.

1897{
1898 if (!store->open("swatchbook.xml")) {
1899 return false;
1900 }
1901
1902 QByteArray bytes = store->read(store->size());
1903 store->close();
1904
1905 dbgPigment << "XML palette: " << colorSet->filename() << ", SwatchBooker format";
1906
1907 QDomDocument doc;
1908#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
1909 int errorLine, errorColumn;
1910 QString errorMessage;
1911 if (!doc.setContent(bytes, &errorMessage, &errorLine, &errorColumn)) {
1912 warnPigment << "Illegal XML palette:" << colorSet->filename();
1913 warnPigment << "Error (line" << errorLine
1914 << ", column" << errorColumn
1915 << "):" << errorMessage;
1916#else
1917 QDomDocument::ParseResult result = doc.setContent(bytes);
1918 if (!result) {
1919 warnPigment << "Illegal XML palette:" << colorSet->filename();
1920 warnPigment << "Error (line" << result.errorLine
1921 << ", column" << result.errorColumn
1922 << "):" << result.errorMessage;
1923#endif
1924 return false;
1925 }
1926
1927 QDomElement root = doc.documentElement(); // SwatchBook
1928
1929 // Start reading properties...
1930 QDomElement metadata = root.firstChildElement("metadata");
1931 if (metadata.isNull()) {
1932 warnPigment << "Palette metadata not found";
1933 return false;
1934 }
1935
1936 QDomElement title = metadata.firstChildElement("dc:title");
1937 QString colorName = title.text();
1938 colorName = colorName.isEmpty() ? i18n("Untitled") : colorName;
1939 colorSet->setName(colorName);
1940 dbgPigment << "Processed name of palette:" << colorSet->name();
1941 // End reading properties
1942
1943 // Also read the swatch book...
1944 QDomElement book = root.firstChildElement("book");
1945 if (book.isNull()) {
1946 warnPigment << "Palette book (swatch composition) not found (line" << root.lineNumber()
1947 << ", column" << root.columnNumber()
1948 << ")";
1949 return false;
1950 }
1951
1952 // Which has lots of "swatch"es (todo: support groups)
1953 QDomElement swatch = book.firstChildElement();
1954 if (swatch.isNull()) {
1955 warnPigment << "Swatches/groups definition not found (line" << book.lineNumber()
1956 << ", column" << book.columnNumber()
1957 << ")";
1958 return false;
1959 }
1960
1961 // Now read colors...
1962 QDomElement materials = root.firstChildElement("materials");
1963 if (materials.isNull()) {
1964 warnPigment << "Materials (color definitions) not found";
1965 return false;
1966 }
1967
1968 // This one has lots of "color" elements
1969 if (materials.firstChildElement("color").isNull()) {
1970 warnPigment << "Color definitions not found (line" << materials.lineNumber()
1971 << ", column" << materials.columnNumber()
1972 << ")";
1973 return false;
1974 }
1975
1976 // We'll store colors here, and as we process swatches
1977 // we'll add them to the palette
1978 QHash<QString, KisSwatch> materialsBook;
1979 QHash<QString, const KoColorSpace*> fileColorSpaces;
1980
1981 // Color processing
1982 store->enterDirectory("profiles"); // Color profiles (icc files) live here
1983 for (QDomElement colorElement = materials.firstChildElement("color");
1984 !colorElement.isNull();
1985 colorElement = colorElement.nextSiblingElement("color")) {
1986 KisSwatch currentEntry;
1987 // Set if color is spot
1988 currentEntry.setSpotColor(colorElement.attribute("usage") == "spot");
1989
1990 // <metadata> inside contains id and name
1991 // one or more <values> define the color
1992 QDomElement currentColorMetadata = colorElement.firstChildElement("metadata");
1993 // Get color name
1994 QDomElement colorTitle = currentColorMetadata.firstChildElement("dc:title");
1995 QDomElement colorId = currentColorMetadata.firstChildElement("dc:identifier");
1996 // Is there an id? (we need that at the very least for identifying a color)
1997 if (colorId.text().isEmpty()) {
1998 warnPigment << "Unidentified color (line" << colorId.lineNumber()
1999 << ", column" << colorId.columnNumber()
2000 << ")";
2001 return false;
2002 }
2003
2004 if (materialsBook.contains(colorId.text())) {
2005 warnPigment << "Duplicated color definition (line" << colorId.lineNumber()
2006 << ", column" << colorId.columnNumber()
2007 << ")";
2008 return false;
2009 }
2010
2011 // Get a valid color name
2012 currentEntry.setId(colorId.text());
2013 currentEntry.setName(colorTitle.text().isEmpty() ? colorId.text() : colorTitle.text());
2014
2015 // Get a valid color definition
2016 if (colorElement.firstChildElement("values").isNull()) {
2017 warnPigment << "Color definitions not found (line" << colorElement.lineNumber()
2018 << ", column" << colorElement.columnNumber()
2019 << ")";
2020 return false;
2021 }
2022
2023 bool status;
2024 bool firstDefinition = false;
2026 const QString colorDepthId = Float32BitsColorDepthID.id();
2027 // Priority: Lab, otherwise the first definition found
2028 for (QDomElement colorValueE = colorElement.firstChildElement("values");
2029 !colorValueE.isNull();
2030 colorValueE = colorValueE.nextSiblingElement("values")) {
2031 QString model = colorValueE.attribute("model");
2032
2033 QString modelId;
2034 const KoColorProfile *profile = nullptr;
2035 if (model == "Lab") {
2036 modelId = LABAColorModelID.id();
2037 } else if (model == "sRGB") {
2038 modelId = RGBAColorModelID.id();
2039 profile = colorSpaceRegistry->rgb8()->profile();
2040 } else if (model == "XYZ") {
2041 modelId = XYZAColorModelID.id();
2042 } else if (model == "CMYK") {
2043 modelId = CMYKAColorModelID.id();
2044 } else if (model == "GRAY") {
2045 modelId = GrayAColorModelID.id();
2046 } else if (model == "RGB") {
2047 modelId = RGBAColorModelID.id();
2048 } else {
2049 warnPigment << "Color space not implemented:" << model
2050 << "(line" << colorValueE.lineNumber()
2051 << ", column "<< colorValueE.columnNumber()
2052 << ")";
2053 continue;
2054 }
2055
2056 const KoColorSpace *colorSpace = colorSpaceRegistry->colorSpace(modelId, colorDepthId, profile);
2057
2058 // The 'space' attribute is the name of the icc file
2059 // sitting in the 'profiles' directory in the zip.
2060 QString space = colorValueE.attribute("space");
2061 if (!space.isEmpty()) {
2062 if (fileColorSpaces.contains(space)) {
2063 colorSpace = fileColorSpaces.value(space);
2064 } else {
2065 // Try loading the profile and add it to the registry
2066 profile = loadColorProfile(store, space, modelId, colorDepthId);
2067 if (profile) {
2068 colorSpace = colorSpaceRegistry->colorSpace(modelId, colorDepthId, profile);
2069 fileColorSpaces.insert(space, colorSpace);
2070 }
2071 }
2072 }
2073
2074 KoColor c(colorSpace);
2075
2076 // sRGB,RGB,HSV,HSL,CMY,CMYK,nCLR: 0 -> 1
2077 // YIQ: Y 0 -> 1 : IQ -0.5 -> 0.5
2078 // Lab: L 0 -> 100 : ab -128 -> 127
2079 // XYZ: 0 -> ~100
2080 QVector<float> channels;
2081 for (const QString &str : colorValueE.text().split(" ")) {
2082 float channelValue = str.toFloat(&status);
2083 if (!status) {
2084 warnPigment << "Invalid float definition (line" << colorValueE.lineNumber()
2085 << ", column" << colorValueE.columnNumber()
2086 << ")";
2087
2088 channelValue = 0;
2089 }
2090
2091 channels.append(channelValue);
2092 }
2093 channels.append(OPACITY_OPAQUE_F); // Alpha channel
2094 colorSpace->fromNormalisedChannelsValue(c.data(), channels);
2095
2096 currentEntry.setColor(c);
2097 firstDefinition = true;
2098
2099 if (model == "Lab") {
2100 break; // Immediately add this one
2101 }
2102 }
2103
2104 if (firstDefinition) {
2105 materialsBook.insert(currentEntry.id(), currentEntry);
2106 } else {
2107 warnPigment << "No supported color spaces for the current color (line" << colorElement.lineNumber()
2108 << ", column "<< colorElement.columnNumber()
2109 << ")";
2110 return false;
2111 }
2112 }
2113
2114 store->leaveDirectory(); // Return to root
2115 // End colors
2116 // Now decide which ones will go into the palette
2117
2119 for(; !swatch.isNull(); swatch = swatch.nextSiblingElement()) {
2120 QString type = swatch.tagName();
2121 if (type.isEmpty() || type.isNull()) {
2122 warnPigment << "Invalid swatch/group definition (no id) (line" << swatch.lineNumber()
2123 << ", column" << swatch.columnNumber()
2124 << ")";
2125 return false;
2126 } else if (type == "swatch") {
2127 QString id = swatch.attribute("material");
2128 if (id.isEmpty() || id.isNull()) {
2129 warnPigment << "Invalid swatch definition (no material id) (line" << swatch.lineNumber()
2130 << ", column" << swatch.columnNumber()
2131 << ")";
2132 return false;
2133 }
2134
2135 if (materialsBook.contains(id)) {
2136 global->addSwatch(materialsBook.value(id));
2137 } else {
2138 warnPigment << "Invalid swatch definition (material not found) (line" << swatch.lineNumber()
2139 << ", column" << swatch.columnNumber()
2140 << ")";
2141 return false;
2142 }
2143 } else if (type == "group") {
2144 QDomElement groupMetadata = swatch.firstChildElement("metadata");
2145 if (groupMetadata.isNull()) {
2146 warnPigment << "Invalid group definition (missing metadata) (line" << groupMetadata.lineNumber()
2147 << ", column" << groupMetadata.columnNumber()
2148 << ")";
2149 return false;
2150 }
2151 QDomElement groupTitle = metadata.firstChildElement("dc:title");
2152 if (groupTitle.isNull()) {
2153 warnPigment << "Invalid group definition (missing title) (line" << groupTitle.lineNumber()
2154 << ", column" << groupTitle.columnNumber()
2155 << ")";
2156 return false;
2157 }
2158 QString currentGroupName = groupTitle.text();
2159 colorSet->addGroup(currentGroupName);
2160
2161 for (QDomElement groupSwatch = swatch.firstChildElement("swatch");
2162 !groupSwatch.isNull();
2163 groupSwatch = groupSwatch.nextSiblingElement("swatch")) {
2164 QString id = groupSwatch.attribute("material");
2165 if (id.isEmpty() || id.isNull()) {
2166 warnPigment << "Invalid swatch definition (no material id) (line" << groupSwatch.lineNumber()
2167 << ", column" << groupSwatch.columnNumber()
2168 << ")";
2169 return false;
2170 }
2171
2172 if (materialsBook.contains(id)) {
2173 colorSet->getGroup(currentGroupName)->addSwatch(materialsBook.value(id));
2174 } else {
2175 warnPigment << "Invalid swatch definition (material not found) (line" << groupSwatch.lineNumber()
2176 << ", column" << groupSwatch.columnNumber()
2177 << ")";
2178 return false;
2179 }
2180 }
2181 }
2182 }
2183 // End palette
2184
2185 return true;
2186}
#define dbgPigment
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID XYZAColorModelID("XYZA", ki18n("XYZ/Alpha"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
const qreal OPACITY_OPAQUE_F
QString id() const
Definition KisSwatch.h:27
virtual void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const =0

References CMYKAColorModelID, KoColorSpaceRegistry::colorSpace(), KoColor::data(), dbgPigment, Float32BitsColorDepthID, KoColorSpace::fromNormalisedChannelsValue(), GrayAColorModelID, KoID::id(), KisSwatch::id(), KoColorSpaceRegistry::instance(), LABAColorModelID, KoResource::metadata, OPACITY_OPAQUE_F, KoColorSpace::profile(), KoColorSpaceRegistry::rgb8(), RGBAColorModelID, KisSwatch::setColor(), KisSwatch::setId(), KisSwatch::setName(), KisSwatch::setSpotColor(), warnPigment, and XYZAColorModelID.

◆ loadScribusXmlPalette()

bool KoColorSet::Private::loadScribusXmlPalette ( KoColorSet * set,
QXmlStreamReader * xml )
private

Definition at line 1187 of file KoColorSet.cpp.

1188{
1189
1190 //1. Get name
1191 QXmlStreamAttributes paletteProperties = xml->attributes();
1192 auto paletteName = paletteProperties.value("Name");
1193 dbgPigment << "Processed name of palette:" << paletteName;
1194 set->setName(paletteName.toString());
1195
1196 //2. Inside the SCRIBUSCOLORS, there are lots of colors. Retrieve them
1197
1198 while(xml->readNextStartElement()) {
1199 auto currentElement = xml->name();
1200 if (currentElement.compare(QString("COLOR"), Qt::CaseInsensitive) == 0) {
1201 scribusParseColor(set, xml);
1202 }
1203 else {
1204 xml->skipCurrentElement();
1205 }
1206 }
1207
1208 if(xml->hasError()) {
1209 return false;
1210 }
1211
1212 return true;
1213}
void scribusParseColor(KoColorSet *set, QXmlStreamReader *xml)

References dbgPigment, and KoResource::setName().

◆ loadXml()

bool KoColorSet::Private::loadXml ( )

Definition at line 2412 of file KoColorSet.cpp.

2412 {
2413 bool res = false;
2414
2415 QXmlStreamReader *xml = new QXmlStreamReader(data);
2416
2417 if (xml->readNextStartElement()) {
2418 auto paletteId = xml->name();
2419 if (paletteId.compare(QString("SCRIBUSCOLORS"), Qt::CaseInsensitive) == 0) { // Scribus
2420 dbgPigment << "XML palette: " << colorSet->filename() << ", Scribus format";
2421 res = loadScribusXmlPalette(colorSet, xml);
2422 }
2423 else {
2424 // Unknown XML format
2425 xml->raiseError("Unknown XML palette format. Expected SCRIBUSCOLORS, found " + paletteId);
2426 }
2427 }
2428
2429 // If there is any error (it should be returned through the stream)
2430 if (xml->hasError() || !res) {
2431 warnPigment << "Illegal XML palette:" << colorSet->filename();
2432 warnPigment << "Error (line"<< xml->lineNumber() << ", column" << xml->columnNumber() << "):" << xml->errorString();
2433 return false;
2434 }
2435 else {
2436 dbgPigment << "XML palette parsed successfully:" << colorSet->filename();
2437 return true;
2438 }
2439}
bool loadScribusXmlPalette(KoColorSet *set, QXmlStreamReader *xml)

References dbgPigment, and warnPigment.

◆ readByte()

quint8 KoColorSet::Private::readByte ( QIODevice * io)
private

Definition at line 1215 of file KoColorSet.cpp.

1216{
1217 quint8 val;
1218 quint64 read = io->read((char*)&val, 1);
1219 if (read != 1) return false;
1220 return val;
1221}

◆ readFloat()

float KoColorSet::Private::readFloat ( QIODevice * io)
private

Definition at line 1238 of file KoColorSet.cpp.

1239{
1240 float val;
1241 quint64 read = io->read((char*)&val, 4);
1242 if (read != 4) return false;
1243 return qFromBigEndian(val);
1244}

◆ readInt()

qint32 KoColorSet::Private::readInt ( QIODevice * io)
private

Definition at line 1230 of file KoColorSet.cpp.

1231{
1232 qint32 val;
1233 quint64 read = io->read((char*)&val, 4);
1234 if (read != 4) return false;
1235 return qFromBigEndian(val);
1236}

◆ readShort()

quint16 KoColorSet::Private::readShort ( QIODevice * io)
private

Definition at line 1223 of file KoColorSet.cpp.

1223 {
1224 quint16 val;
1225 quint64 read = io->read((char*)&val, 2);
1226 if (read != 2) return false;
1227 return qFromBigEndian(val);
1228}

◆ readUnicodeString()

QString KoColorSet::Private::readUnicodeString ( QIODevice * io,
bool sizeIsInt = false )
private

Definition at line 1246 of file KoColorSet.cpp.

1247{
1248 QString unicode;
1249 qint32 size = 0;
1250 if (sizeIsInt) {
1251 size = readInt(io);
1252 } else {
1253 size = readShort(io)-1;
1254 }
1255 if (size>0) {
1256 QByteArray ba = io->read(size*2);
1257 if (ba.size() == int(size)*2) {
1258 QTextCodec *Utf16Codec = QTextCodec::codecForName("UTF-16BE");
1259 unicode = Utf16Codec->toUnicode(ba);
1260 } else {
1261 warnPigment << "Unicode name block is the wrong size" << colorSet->filename();
1262 }
1263 }
1264 if (!sizeIsInt) {
1265 readShort(io); // when the size is quint16, the string is 00 terminated;
1266 }
1267 return unicode.trimmed();
1268}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References warnPigment.

◆ saveGpl()

bool KoColorSet::Private::saveGpl ( QIODevice * dev) const

Definition at line 1352 of file KoColorSet.cpp.

1353{
1354 Q_ASSERT(dev->isOpen());
1355 Q_ASSERT(dev->isWritable());
1356
1357 QTextStream stream(dev);
1359 stream << "GIMP Palette\nName: " << colorSet->name() << "\nColumns: " << colorSet->columnCount() << "\n#\n";
1360
1362 for (int y = 0; y < global->rowCount(); y++) {
1363 for (int x = 0; x < colorSet->columnCount(); x++) {
1364 if (!global->checkSwatchExists(x, y)) {
1365 continue;
1366 }
1367 const KisSwatch& entry = global->getSwatch(x, y);
1368 QColor c = entry.color().toQColor();
1369 stream << c.red() << " " << c.green() << " " << c.blue() << "\t";
1370 if (entry.name().isEmpty())
1371 stream << "Untitled\n";
1372 else
1373 stream << entry.name() << "\n";
1374 }
1375 }
1376
1377 return true;
1378}
KoColor color() const
Definition KisSwatch.h:30
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198
void setUtf8OnStream(QTextStream &stream)

References KisSwatch::color(), KisSwatch::name(), KisPortingUtils::setUtf8OnStream(), and KoColor::toQColor().

◆ saveKpl()

bool KoColorSet::Private::saveKpl ( QIODevice * dev) const

Definition at line 2441 of file KoColorSet.cpp.

2442{
2443 QScopedPointer<KoStore> store(KoStore::createStore(dev, KoStore::Write, "application/x-krita-palette", KoStore::Zip));
2444 if (!store || store->bad()) {
2445 qWarning() << "saveKpl could not create store";
2446 return false;
2447 }
2448
2449 QSet<const KoColorSpace *> colorSpaces;
2450
2451 {
2452 QDomDocument doc;
2453 QDomElement root = doc.createElement(KPL_PALETTE_TAG);
2454 root.setAttribute(KPL_VERSION_ATTR, "2.0");
2455 root.setAttribute(KPL_PALETTE_NAME_ATTR, colorSet->name());
2456 root.setAttribute(KPL_PALETTE_COMMENT_ATTR, comment);
2457 root.setAttribute(KPL_PALETTE_COLUMN_COUNT_ATTR, colorSet->columnCount());
2458 root.setAttribute(KPL_GROUP_ROW_COUNT_ATTR, colorSet->getGlobalGroup()->rowCount());
2459
2461
2462 for (const KisSwatchGroupSP &group : swatchGroups) {
2463 if (group->name() == KoColorSet::GLOBAL_GROUP_NAME) { continue; }
2464 QDomElement gl = doc.createElement(KPL_GROUP_TAG);
2465 gl.setAttribute(KPL_GROUP_NAME_ATTR, group->name());
2466 root.appendChild(gl);
2467 saveKplGroup(doc, gl, group, colorSpaces);
2468 }
2469
2470 doc.appendChild(root);
2471 if (!store->open("colorset.xml")) { return false; }
2472 QByteArray ba = doc.toByteArray();
2473 if (store->write(ba) != ba.size()) { return false; }
2474 if (!store->close()) { return false; }
2475 }
2476
2477 QDomDocument doc;
2478 QDomElement profileElement = doc.createElement("Profiles");
2479
2480 for (const KoColorSpace *colorSpace : colorSpaces) {
2481 QString fn = QFileInfo(colorSpace->profile()->fileName()).fileName();
2482 if (!store->open(fn)) { qWarning() << "Could not open the store for profiles directory"; return false; }
2483 QByteArray profileRawData = colorSpace->profile()->rawData();
2484 if (!store->write(profileRawData)) { qWarning() << "Could not write the profiles data into the store"; return false; }
2485 if (!store->close()) { qWarning() << "Could not close the store for profiles directory"; return false; }
2486 QDomElement el = doc.createElement(KPL_PALETTE_PROFILE_TAG);
2487 el.setAttribute(KPL_PALETTE_FILENAME_ATTR, fn);
2488 el.setAttribute(KPL_PALETTE_NAME_ATTR, colorSpace->profile()->name());
2489 el.setAttribute(KPL_COLOR_MODEL_ID_ATTR, colorSpace->colorModelId().id());
2490 el.setAttribute(KPL_COLOR_DEPTH_ID_ATTR, colorSpace->colorDepthId().id());
2491 profileElement.appendChild(el);
2492
2493 }
2494 doc.appendChild(profileElement);
2495
2496 if (!store->open("profiles.xml")) { qWarning() << "Could not open profiles.xml"; return false; }
2497 QByteArray ba = doc.toByteArray();
2498
2499 int bytesWritten = store->write(ba);
2500 if (bytesWritten != ba.size()) { qWarning() << "Bytes written is wrong" << ba.size(); return false; }
2501
2502 if (!store->close()) { qWarning() << "Could not close the store"; return false; }
2503
2504 bool r = store->finalize();
2505 if (!r) { qWarning() << "Could not finalize the store"; }
2506 return r;
2507}
void saveKplGroup(QDomDocument &doc, QDomElement &groupEle, const KisSwatchGroupSP group, QSet< const KoColorSpace * > &colorSetSet) const
static const QString KPL_PALETTE_TAG
Definition KoColorSet.h:54
@ Write
Definition KoStore.h:29

References KoColorSet::comment(), KoStore::createStore(), KoColorSet::GLOBAL_GROUP_NAME, KoColorSet::KPL_COLOR_DEPTH_ID_ATTR, KoColorSet::KPL_COLOR_MODEL_ID_ATTR, KoColorSet::KPL_GROUP_NAME_ATTR, KoColorSet::KPL_GROUP_ROW_COUNT_ATTR, KoColorSet::KPL_GROUP_TAG, KoColorSet::KPL_PALETTE_COLUMN_COUNT_ATTR, KoColorSet::KPL_PALETTE_COMMENT_ATTR, KoColorSet::KPL_PALETTE_FILENAME_ATTR, KoColorSet::KPL_PALETTE_NAME_ATTR, KoColorSet::KPL_PALETTE_PROFILE_TAG, KoColorSet::KPL_PALETTE_TAG, KoColorSet::KPL_VERSION_ATTR, KoStore::Write, and KoStore::Zip.

◆ saveKplGroup()

void KoColorSet::Private::saveKplGroup ( QDomDocument & doc,
QDomElement & groupEle,
const KisSwatchGroupSP group,
QSet< const KoColorSpace * > & colorSetSet ) const
private

Definition at line 2509 of file KoColorSet.cpp.

2513{
2514 groupEle.setAttribute(KPL_GROUP_ROW_COUNT_ATTR, QString::number(group->rowCount()));
2515
2516 for (const KisSwatchGroup::SwatchInfo &info : group->infoList()) {
2517 const KoColorProfile *profile = info.swatch.color().colorSpace()->profile();
2518 // Only save non-builtin profiles.=
2519 if (!profile->fileName().isEmpty()) {
2520 bool alreadyIncluded = false;
2521 Q_FOREACH(const KoColorSpace* colorSpace, colorSetSet) {
2522 if (colorSpace->profile()->fileName() == profile->fileName()) {
2523 alreadyIncluded = true;
2524 break;
2525 }
2526 }
2527 if(!alreadyIncluded) {
2528 colorSetSet.insert(info.swatch.color().colorSpace());
2529 }
2530 }
2531 QDomElement swatchEle = doc.createElement(KPL_SWATCH_TAG);
2532 swatchEle.setAttribute(KPL_SWATCH_NAME_ATTR, info.swatch.name());
2533 swatchEle.setAttribute(KPL_SWATCH_ID_ATTR, info.swatch.id());
2534 swatchEle.setAttribute(KPL_SWATCH_SPOT_ATTR, info.swatch.spotColor() ? "true" : "false");
2535 swatchEle.setAttribute(KPL_SWATCH_BITDEPTH_ATTR, info.swatch.color().colorSpace()->colorDepthId().id());
2536 info.swatch.color().toXML(doc, swatchEle);
2537
2538 QDomElement positionEle = doc.createElement(KPL_SWATCH_POS_TAG);
2539 positionEle.setAttribute(KPL_SWATCH_ROW_ATTR, info.row);
2540 positionEle.setAttribute(KPL_SWATCH_COL_ATTR, info.column);
2541 swatchEle.appendChild(positionEle);
2542
2543 groupEle.appendChild(swatchEle);
2544 }
2545}

References KoColorProfile::fileName, KoColorSet::KPL_GROUP_ROW_COUNT_ATTR, KoColorSet::KPL_SWATCH_BITDEPTH_ATTR, KoColorSet::KPL_SWATCH_COL_ATTR, KoColorSet::KPL_SWATCH_ID_ATTR, KoColorSet::KPL_SWATCH_NAME_ATTR, KoColorSet::KPL_SWATCH_POS_TAG, KoColorSet::KPL_SWATCH_ROW_ATTR, KoColorSet::KPL_SWATCH_SPOT_ATTR, KoColorSet::KPL_SWATCH_TAG, and KoColorSpace::profile().

◆ scribusParseColor()

void KoColorSet::Private::scribusParseColor ( KoColorSet * set,
QXmlStreamReader * xml )
private

Definition at line 1094 of file KoColorSet.cpp.

1095{
1096 KisSwatch colorEntry;
1097 // It's a color, retrieve it
1098 QXmlStreamAttributes colorProperties = xml->attributes();
1099 auto colorName = colorProperties.value("NAME");
1100 colorEntry.setName(colorName.isEmpty() || colorName.isNull() ? i18n("Untitled") : colorName.toString());
1101
1102 // RGB or CMYK?
1103 if (colorProperties.hasAttribute("RGB")) {
1104 dbgPigment << "Color " << colorProperties.value("NAME") << ", RGB " << colorProperties.value("RGB");
1105
1107 auto colorValue = colorProperties.value("RGB");
1108
1109 if (colorValue.length() != 7 && colorValue.at(0) != '#') { // Color is a hexadecimal number
1110 xml->raiseError("Invalid rgb8 color (malformed): " + colorValue);
1111 return;
1112 } else {
1113 bool rgbOk;
1114 quint32 rgb = colorValue.mid(1).toUInt(&rgbOk, 16);
1115 if (!rgbOk) {
1116 xml->raiseError("Invalid rgb8 color (unable to convert): " + colorValue);
1117 return;
1118 }
1119
1120 quint8 r = rgb >> 16 & 0xff;
1121 quint8 g = rgb >> 8 & 0xff;
1122 quint8 b = rgb & 0xff;
1123
1124 dbgPigment << "Color parsed: "<< r << g << b;
1125
1126 currentColor.data()[0] = r;
1127 currentColor.data()[1] = g;
1128 currentColor.data()[2] = b;
1130 colorEntry.setColor(currentColor);
1131
1132 set->addSwatch(colorEntry);
1133
1134 while(xml->readNextStartElement()) {
1135 //ignore - these are all unknown or the /> element tag
1136 xml->skipCurrentElement();
1137 }
1138 return;
1139 }
1140 }
1141 else if (colorProperties.hasAttribute("CMYK")) {
1142 dbgPigment << "Color " << colorProperties.value("NAME") << ", CMYK " << colorProperties.value("CMYK");
1143
1145 auto colorValue = colorProperties.value("CMYK");
1146
1147 if (colorValue.length() != 9 && colorValue.at(0) != '#') { // Color is a hexadecimal number
1148 xml->raiseError("Invalid cmyk color (malformed): " % colorValue);
1149 return;
1150 }
1151 else {
1152 bool cmykOk;
1153 quint32 cmyk = colorValue.mid(1).toUInt(&cmykOk, 16); // cmyk uses the full 32 bits
1154 if (!cmykOk) {
1155 xml->raiseError("Invalid cmyk color (unable to convert): " % colorValue);
1156 return;
1157 }
1158
1159 quint8 c = cmyk >> 24 & 0xff;
1160 quint8 m = cmyk >> 16 & 0xff;
1161 quint8 y = cmyk >> 8 & 0xff;
1162 quint8 k = cmyk & 0xff;
1163
1164 dbgPigment << "Color parsed: "<< c << m << y << k;
1165
1166 currentColor.data()[0] = c;
1167 currentColor.data()[1] = m;
1168 currentColor.data()[2] = y;
1169 currentColor.data()[3] = k;
1171 colorEntry.setColor(currentColor);
1172
1173 set->addSwatch(colorEntry);
1174
1175 while(xml->readNextStartElement()) {
1176 //ignore - these are all unknown or the /> element tag
1177 xml->skipCurrentElement();
1178 }
1179 return;
1180 }
1181 }
1182 else {
1183 xml->raiseError("Unknown color space for color " + colorEntry.name());
1184 }
1185}
KoColor currentColor(ResourceProvider *provider, ColorRole role)
QString toString(const QString &value)

References KoColorSet::addSwatch(), CMYKAColorModelID, KoColor::data(), dbgPigment, KoID::id(), KoColorSpaceRegistry::instance(), Integer8BitsColorDepthID, KisSwatch::name(), OPACITY_OPAQUE_U8, KisSwatch::setColor(), KisSwatch::setName(), and KoColor::setOpacity().

Friends And Related Symbol Documentation

◆ AddGroupCommand

friend struct AddGroupCommand
friend

Definition at line 73 of file KoColorSet_p.h.

◆ AddSwatchCommand

friend struct AddSwatchCommand
friend

Definition at line 70 of file KoColorSet_p.h.

◆ ChangeGroupNameCommand

friend struct ChangeGroupNameCommand
friend

Definition at line 72 of file KoColorSet_p.h.

◆ ClearCommand

friend struct ClearCommand
friend

Definition at line 75 of file KoColorSet_p.h.

◆ MoveGroupCommand

friend struct MoveGroupCommand
friend

Definition at line 79 of file KoColorSet_p.h.

◆ RemoveGroupCommand

friend struct RemoveGroupCommand
friend

Definition at line 74 of file KoColorSet_p.h.

◆ RemoveSwatchCommand

friend struct RemoveSwatchCommand
friend

Definition at line 71 of file KoColorSet_p.h.

◆ SetColumnCountCommand

friend struct SetColumnCountCommand
friend

Definition at line 76 of file KoColorSet_p.h.

◆ SetCommentCommand

friend struct SetCommentCommand
friend

Definition at line 77 of file KoColorSet_p.h.

◆ SetPaletteTypeCommand

friend struct SetPaletteTypeCommand
friend

Definition at line 78 of file KoColorSet_p.h.

Member Data Documentation

◆ colorSet

KoColorSet* KoColorSet::Private::colorSet {0}

Definition at line 59 of file KoColorSet_p.h.

59{0};

◆ columns

int KoColorSet::Private::columns

Definition at line 66 of file KoColorSet_p.h.

◆ comment

QString KoColorSet::Private::comment

Definition at line 62 of file KoColorSet_p.h.

◆ data

QByteArray KoColorSet::Private::data

Definition at line 61 of file KoColorSet_p.h.

◆ isLocked

bool KoColorSet::Private::isLocked {false}

Definition at line 65 of file KoColorSet_p.h.

65{false};

◆ paletteType

KoColorSet::PaletteType KoColorSet::Private::paletteType {UNKNOWN}

Definition at line 60 of file KoColorSet_p.h.

60{UNKNOWN};

◆ swatchGroups

QList<KisSwatchGroupSP> KoColorSet::Private::swatchGroups

Definition at line 63 of file KoColorSet_p.h.

◆ undoStack

KUndo2Stack KoColorSet::Private::undoStack

Definition at line 64 of file KoColorSet_p.h.


The documentation for this class was generated from the following files: