1897{
1898 if (!store->open("swatchbook.xml")) {
1899 return false;
1900 }
1901
1902 QByteArray bytes = store->read(store->size());
1903 store->close();
1904
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)) {
1914 << ", column" << errorColumn
1915 << "):" << errorMessage;
1916#else
1917 QDomDocument::ParseResult result = doc.setContent(bytes);
1918 if (!result) {
1921 << ", column" << result.errorColumn
1922 << "):" << result.errorMessage;
1923#endif
1924 return false;
1925 }
1926
1927 QDomElement root = doc.documentElement();
1928
1929
1930 QDomElement
metadata = root.firstChildElement(
"metadata");
1933 return false;
1934 }
1935
1936 QDomElement title =
metadata.firstChildElement(
"dc:title");
1937 QString colorName = title.text();
1938 colorName = colorName.isEmpty() ? i18n("Untitled") : colorName;
1941
1942
1943
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
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
1962 QDomElement materials = root.firstChildElement("materials");
1963 if (materials.isNull()) {
1964 warnPigment <<
"Materials (color definitions) not found";
1965 return false;
1966 }
1967
1968
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
1977
1978 QHash<QString, KisSwatch> materialsBook;
1979 QHash<QString, const KoColorSpace*> fileColorSpaces;
1980
1981
1982 store->enterDirectory("profiles");
1983 for (QDomElement colorElement = materials.firstChildElement("color");
1984 !colorElement.isNull();
1985 colorElement = colorElement.nextSiblingElement("color")) {
1987
1988 currentEntry.
setSpotColor(colorElement.attribute(
"usage") ==
"spot");
1989
1990
1991
1992 QDomElement currentColorMetadata = colorElement.firstChildElement("metadata");
1993
1994 QDomElement colorTitle = currentColorMetadata.firstChildElement("dc:title");
1995 QDomElement colorId = currentColorMetadata.firstChildElement("dc:identifier");
1996
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
2012 currentEntry.
setId(colorId.text());
2013 currentEntry.
setName(colorTitle.text().isEmpty() ? colorId.text() : colorTitle.text());
2014
2015
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;
2027
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;
2035 if (model == "Lab") {
2037 } else if (model == "sRGB") {
2040 } else if (model == "XYZ") {
2042 } else if (model == "CMYK") {
2044 } else if (model == "GRAY") {
2046 } else if (model == "RGB") {
2048 } else {
2049 warnPigment <<
"Color space not implemented:" << model
2050 << "(line" << colorValueE.lineNumber()
2051 << ", column "<< colorValueE.columnNumber()
2052 << ")";
2053 continue;
2054 }
2055
2057
2058
2059
2060 QString space = colorValueE.attribute("space");
2061 if (!space.isEmpty()) {
2062 if (fileColorSpaces.contains(space)) {
2063 colorSpace = fileColorSpaces.value(space);
2064 } else {
2065
2067 if (profile) {
2068 colorSpace = colorSpaceRegistry->
colorSpace(modelId, colorDepthId, profile);
2069 fileColorSpaces.insert(space, colorSpace);
2070 }
2071 }
2072 }
2073
2075
2076
2077
2078
2079
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 }
2095
2097 firstDefinition = true;
2098
2099 if (model == "Lab") {
2100 break;
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();
2115
2116
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();
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)) {
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
2184
2185 return true;
2186}
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
virtual void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const =0