summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2021-03-22 20:42:00 +0100
committerFridrich Štrba <fridrich.strba@bluewin.ch>2021-03-22 20:42:00 +0100
commitd41d8f66957b3e2667e4781bffc1856627957fee (patch)
treecc42855f05166bb22b677eefa7038d6f65da33c2
parent3a811cc153c6bc79a017f163ac03d51b3f66506d (diff)
Parse and use fallback colours if they exist
Change-Id: I970bfbe0c00032ad196dd06bf27d32e341afc3f6
-rw-r--r--src/lib/CDRParser.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 045a1b9..c71cae5 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -109,7 +109,8 @@ static int parseColourString(const char *colourString, libcdr::CDRColor &colour,
bool bRes = false;
boost::optional<unsigned> colourModel, colourPalette;
- std::vector<char> rest;
+ std::vector<std::string> fallbackColours;
+ std::string rest;
std::vector<unsigned> val;
if (colourString)
@@ -123,6 +124,7 @@ static int parseColourString(const char *colourString, libcdr::CDRColor &colour,
("HLS", 7)
("GRAY255", 9)
("YIQ255", 11)
+ ("LAB", 12)
("PANTONEHX", 14)
("LAB255", 18)
("REGCOLOR", 20)
@@ -151,18 +153,23 @@ static int parseColourString(const char *colourString, libcdr::CDRColor &colour,
>> (cpalette | omit[+iso8859_1::alnum]) >> lit(',')
>> *(uint_ >> lit(','))
>> omit[(repeat(8)[iso8859_1::xdigit] >> '-' >> repeat(3)[repeat(4)[iso8859_1::xdigit] >> '-'] >> repeat(12)[iso8859_1::xdigit])]
- >> -(lit(',') >> *iso8859_1::char_)
+ >> -(lit(",~,") >> omit[+(iso8859_1::char_ - lit(','))] >> lit(',') >> omit[uint_] >> lit(',')
+ >> repeat[+(iso8859_1::char_ - lit(",~,")) >> lit(",~,")] >> omit[*iso8859_1::char_])
),
// End grammar
iso8859_1::space,
- colourModel, colourPalette, val, rest)
+ colourModel, colourPalette, val, fallbackColours)
&& it == end;
}
- rest.push_back(0);
if (!bRes)
return -1;
+ // If fallback colours exist, use the first of them, since we are more likely
+ // to get them right then the paletted spot colours
+ if (!fallbackColours.empty())
+ return parseColourString(fallbackColours.begin()->c_str(), colour, opacity);
+
if (colourModel)
colour.m_colorModel = get(colourModel);
@@ -201,10 +208,10 @@ static int parseColourString(const char *colourString, libcdr::CDRColor &colour,
}
else
{
- CDR_DEBUG_MSG(("parseColourString --> bRes %i, size %lu, colorModel %u, colorValue 0x%.8x\n", bRes, val.size(), colour.m_colorModel, colour.m_colorValue));
+ CDR_DEBUG_MSG(("parseColourString --> bRes %i, size %lu, colorModel %u, colorValue 0x%.8x bkp: %lu\n", bRes, val.size(), colour.m_colorModel, colour.m_colorValue, fallbackColours.size()));
return 0;
}
- CDR_DEBUG_MSG(("parseColourString --> bRes %i, size %lu, colorModel %u, colorValue 0x%.8x\n", bRes, val.size(), colour.m_colorModel, colour.m_colorValue));
+ CDR_DEBUG_MSG(("parseColourString --> bRes %i, size %lu, colorModel %u, colorValue 0x%.8x blp: %lu\n", bRes, val.size(), colour.m_colorModel, colour.m_colorValue, fallbackColours.size()));
return 1;
}