1901{
1902 if (!store->open("swatchbook.xml")) {
1903 return false;
1904 }
1905
1906 QByteArray bytes = store->read(store->size());
1907 store->close();
1908
1910
1911 QDomDocument doc;
1912 int errorLine, errorColumn;
1913 QString errorMessage;
1914 if (!doc.setContent(bytes, &errorMessage, &errorLine, &errorColumn)) {
1917 << ", column" << errorColumn
1918 << "):" << errorMessage;
1919 return false;
1920 }
1921
1922 QDomElement root = doc.documentElement();
1923
1924
1925 QDomElement
metadata = root.firstChildElement(
"metadata");
1928 return false;
1929 }
1930
1931 QDomElement title =
metadata.firstChildElement(
"dc:title");
1932 QString colorName = title.text();
1933 colorName = colorName.isEmpty() ? i18n("Untitled") : colorName;
1936
1937
1938
1939 QDomElement book = root.firstChildElement("book");
1940 if (book.isNull()) {
1941 warnPigment <<
"Palette book (swatch composition) not found (line" << root.lineNumber()
1942 << ", column" << root.columnNumber()
1943 << ")";
1944 return false;
1945 }
1946
1947
1948 QDomElement swatch = book.firstChildElement();
1949 if (swatch.isNull()) {
1950 warnPigment <<
"Swatches/groups definition not found (line" << book.lineNumber()
1951 << ", column" << book.columnNumber()
1952 << ")";
1953 return false;
1954 }
1955
1956
1957 QDomElement materials = root.firstChildElement("materials");
1958 if (materials.isNull()) {
1959 warnPigment <<
"Materials (color definitions) not found";
1960 return false;
1961 }
1962
1963
1964 if (materials.firstChildElement("color").isNull()) {
1965 warnPigment <<
"Color definitions not found (line" << materials.lineNumber()
1966 << ", column" << materials.columnNumber()
1967 << ")";
1968 return false;
1969 }
1970
1971
1972
1973 QHash<QString, KisSwatch> materialsBook;
1974 QHash<QString, const KoColorSpace*> fileColorSpaces;
1975
1976
1977 store->enterDirectory("profiles");
1978 for (QDomElement colorElement = materials.firstChildElement("color");
1979 !colorElement.isNull();
1980 colorElement = colorElement.nextSiblingElement("color")) {
1982
1983 currentEntry.
setSpotColor(colorElement.attribute(
"usage") ==
"spot");
1984
1985
1986
1987 QDomElement currentColorMetadata = colorElement.firstChildElement("metadata");
1988
1989 QDomElement colorTitle = currentColorMetadata.firstChildElement("dc:title");
1990 QDomElement colorId = currentColorMetadata.firstChildElement("dc:identifier");
1991
1992 if (colorId.text().isEmpty()) {
1993 warnPigment <<
"Unidentified color (line" << colorId.lineNumber()
1994 << ", column" << colorId.columnNumber()
1995 << ")";
1996 return false;
1997 }
1998
1999 if (materialsBook.contains(colorId.text())) {
2000 warnPigment <<
"Duplicated color definition (line" << colorId.lineNumber()
2001 << ", column" << colorId.columnNumber()
2002 << ")";
2003 return false;
2004 }
2005
2006
2007 currentEntry.
setId(colorId.text());
2008 currentEntry.
setName(colorTitle.text().isEmpty() ? colorId.text() : colorTitle.text());
2009
2010
2011 if (colorElement.firstChildElement("values").isNull()) {
2012 warnPigment <<
"Color definitions not found (line" << colorElement.lineNumber()
2013 << ", column" << colorElement.columnNumber()
2014 << ")";
2015 return false;
2016 }
2017
2018 bool status;
2019 bool firstDefinition = false;
2022
2023 for (QDomElement colorValueE = colorElement.firstChildElement("values");
2024 !colorValueE.isNull();
2025 colorValueE = colorValueE.nextSiblingElement("values")) {
2026 QString model = colorValueE.attribute("model");
2027
2028 QString modelId;
2030 if (model == "Lab") {
2032 } else if (model == "sRGB") {
2035 } else if (model == "XYZ") {
2037 } else if (model == "CMYK") {
2039 } else if (model == "GRAY") {
2041 } else if (model == "RGB") {
2043 } else {
2044 warnPigment <<
"Color space not implemented:" << model
2045 << "(line" << colorValueE.lineNumber()
2046 << ", column "<< colorValueE.columnNumber()
2047 << ")";
2048 continue;
2049 }
2050
2052
2053
2054
2055 QString space = colorValueE.attribute("space");
2056 if (!space.isEmpty()) {
2057 if (fileColorSpaces.contains(space)) {
2058 colorSpace = fileColorSpaces.value(space);
2059 } else {
2060
2062 if (profile) {
2063 colorSpace = colorSpaceRegistry->
colorSpace(modelId, colorDepthId, profile);
2064 fileColorSpaces.insert(space, colorSpace);
2065 }
2066 }
2067 }
2068
2070
2071
2072
2073
2074
2076 for (
const QString &str : colorValueE.text().
split(
" ")) {
2077 float channelValue = str.toFloat(&status);
2078 if (!status) {
2079 warnPigment <<
"Invalid float definition (line" << colorValueE.lineNumber()
2080 << ", column" << colorValueE.columnNumber()
2081 << ")";
2082
2083 channelValue = 0;
2084 }
2085
2086 channels.append(channelValue);
2087 }
2090
2092 firstDefinition = true;
2093
2094 if (model == "Lab") {
2095 break;
2096 }
2097 }
2098
2099 if (firstDefinition) {
2100 materialsBook.insert(currentEntry.
id(), currentEntry);
2101 } else {
2102 warnPigment <<
"No supported color spaces for the current color (line" << colorElement.lineNumber()
2103 << ", column "<< colorElement.columnNumber()
2104 << ")";
2105 return false;
2106 }
2107 }
2108
2109 store->leaveDirectory();
2110
2111
2112
2114 for(; !swatch.isNull(); swatch = swatch.nextSiblingElement()) {
2115 QString type = swatch.tagName();
2116 if (type.isEmpty() || type.isNull()) {
2117 warnPigment <<
"Invalid swatch/group definition (no id) (line" << swatch.lineNumber()
2118 << ", column" << swatch.columnNumber()
2119 << ")";
2120 return false;
2121 } else if (type == "swatch") {
2122 QString id = swatch.attribute("material");
2123 if (id.isEmpty() || id.isNull()) {
2124 warnPigment <<
"Invalid swatch definition (no material id) (line" << swatch.lineNumber()
2125 << ", column" << swatch.columnNumber()
2126 << ")";
2127 return false;
2128 }
2129
2130 if (materialsBook.contains(id)) {
2131 global->addSwatch(materialsBook.value(
id));
2132 } else {
2133 warnPigment <<
"Invalid swatch definition (material not found) (line" << swatch.lineNumber()
2134 << ", column" << swatch.columnNumber()
2135 << ")";
2136 return false;
2137 }
2138 } else if (type == "group") {
2139 QDomElement groupMetadata = swatch.firstChildElement("metadata");
2140 if (groupMetadata.isNull()) {
2141 warnPigment <<
"Invalid group definition (missing metadata) (line" << groupMetadata.lineNumber()
2142 << ", column" << groupMetadata.columnNumber()
2143 << ")";
2144 return false;
2145 }
2146 QDomElement groupTitle =
metadata.firstChildElement(
"dc:title");
2147 if (groupTitle.isNull()) {
2148 warnPigment <<
"Invalid group definition (missing title) (line" << groupTitle.lineNumber()
2149 << ", column" << groupTitle.columnNumber()
2150 << ")";
2151 return false;
2152 }
2153 QString currentGroupName = groupTitle.text();
2155
2156 for (QDomElement groupSwatch = swatch.firstChildElement("swatch");
2157 !groupSwatch.isNull();
2158 groupSwatch = groupSwatch.nextSiblingElement("swatch")) {
2159 QString id = groupSwatch.attribute("material");
2160 if (id.isEmpty() || id.isNull()) {
2161 warnPigment <<
"Invalid swatch definition (no material id) (line" << groupSwatch.lineNumber()
2162 << ", column" << groupSwatch.columnNumber()
2163 << ")";
2164 return false;
2165 }
2166
2167 if (materialsBook.contains(id)) {
2169 } else {
2170 warnPigment <<
"Invalid swatch definition (material not found) (line" << groupSwatch.lineNumber()
2171 << ", column" << groupSwatch.columnNumber()
2172 << ")";
2173 return false;
2174 }
2175 }
2176 }
2177 }
2178
2179
2180 return true;
2181}
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