summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2020-02-18 14:17:45 +0100
committerFridrich Štrba <fridrich.strba@bluewin.ch>2020-02-18 14:17:45 +0100
commit9c123d71095d284fad32296b1d35b744878d33b1 (patch)
treeffee4564e0492ca9f2e94057e9515f0d588e3e89
parenta44d6bc1e586e3035431bdf68a53cf0b3f5c7579 (diff)
Extract palette resolution into a separate function
Change-Id: Ifd7e8c42c1ff2cd0986a467a27335af6b441b2f8
-rw-r--r--src/lib/CDRParser.cpp900
-rw-r--r--src/lib/CDRParser.h1
-rw-r--r--src/lib/CDRTypes.h8
3 files changed, 458 insertions, 451 deletions
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 8d6ddba..eb43b39 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -734,476 +734,57 @@ double libcdr::CDRParser::readRectCoord(librevenge::RVNGInputStream *input)
libcdr::CDRColor libcdr::CDRParser::readColor(librevenge::RVNGInputStream *input)
{
- unsigned short colorModel = 0;
- unsigned colorValue = 0;
+ libcdr::CDRColor tmpColor;
+
if (m_version >= 500)
{
- colorModel = readU16(input);
- if (colorModel == 0x01 && m_version >= 1300)
- colorModel = 0x19;
- if (colorModel == 0x19 || colorModel == 0x1e)
- {
- unsigned char r = 0;
- unsigned char g = 0;
- unsigned char b = 0;
- unsigned char c = 0;
- unsigned char m = 0;
- unsigned char y = 0;
- unsigned char k = 100;
- unsigned short paletteID = 0;
- /* A bug in CorelDraw x7 creates a corrupted file. If we meet colorModel of 0x1e,
- * it is actually colorModel 0x19 and paletteId 0x1e */
- if (colorModel == 0x1e)
- {
- colorModel = 0x19;
- paletteID = 0x1e;
- }
- else
- {
- paletteID = readU16(input);
- input->seek(4, librevenge::RVNG_SEEK_CUR);
- }
- unsigned short ix = readU16(input);
- unsigned short tint = readU16(input);
- switch (paletteID)
- {
- case 0x03:
- if (ix > 0
- && ix <= sizeof(palette_19_03_C)/sizeof(palette_19_03_C[0])
- && ix <= sizeof(palette_19_03_M)/sizeof(palette_19_03_M[0])
- && ix <= sizeof(palette_19_03_Y)/sizeof(palette_19_03_Y[0])
- && ix <= sizeof(palette_19_03_K)/sizeof(palette_19_03_K[0]))
- {
- c = palette_19_03_C[ix-1];
- m = palette_19_03_M[ix-1];
- y = palette_19_03_Y[ix-1];
- k = palette_19_03_K[ix-1];
- }
- break;
- case 0x08:
- if (ix > 0
- && ix <= sizeof(palette_19_08_C)/sizeof(palette_19_08_C[0])
- && ix <= sizeof(palette_19_08_M)/sizeof(palette_19_08_M[0])
- && ix <= sizeof(palette_19_08_Y)/sizeof(palette_19_08_Y[0])
- && ix <= sizeof(palette_19_08_K)/sizeof(palette_19_08_K[0]))
- {
- c = palette_19_08_C[ix-1];
- m = palette_19_08_M[ix-1];
- y = palette_19_08_Y[ix-1];
- k = palette_19_08_K[ix-1];
- }
- break;
- case 0x09:
- if (ix > 0
- && ix <= sizeof(palette_19_09_L)/sizeof(palette_19_09_L[0])
- && ix <= sizeof(palette_19_09_A)/sizeof(palette_19_09_A[0])
- && ix <= sizeof(palette_19_09_B)/sizeof(palette_19_09_B[0]))
- {
- colorValue = palette_19_09_B[ix-1];
- colorValue <<= 8;
- colorValue |= palette_19_09_A[ix-1];
- colorValue <<= 8;
- colorValue |= palette_19_09_L[ix-1];
- }
- break;
- case 0x0a:
- if (ix > 0
- && ix <= sizeof(palette_19_0A_C)/sizeof(palette_19_0A_C[0])
- && ix <= sizeof(palette_19_0A_M)/sizeof(palette_19_0A_M[0])
- && ix <= sizeof(palette_19_0A_Y)/sizeof(palette_19_0A_Y[0])
- && ix <= sizeof(palette_19_0A_K)/sizeof(palette_19_0A_K[0]))
- {
- c = palette_19_0A_C[ix-1];
- m = palette_19_0A_M[ix-1];
- y = palette_19_0A_Y[ix-1];
- k = palette_19_0A_K[ix-1];
- }
- break;
- case 0x0b:
- if (ix > 0
- && ix <= sizeof(palette_19_0B_C)/sizeof(palette_19_0B_C[0])
- && ix <= sizeof(palette_19_0B_M)/sizeof(palette_19_0B_M[0])
- && ix <= sizeof(palette_19_0B_Y)/sizeof(palette_19_0B_Y[0])
- && ix <= sizeof(palette_19_0B_K)/sizeof(palette_19_0B_K[0]))
- {
- c = palette_19_0B_C[ix-1];
- m = palette_19_0B_M[ix-1];
- y = palette_19_0B_Y[ix-1];
- k = palette_19_0B_K[ix-1];
- }
- break;
- case 0x11:
- if (ix > 0
- && ix <= sizeof(palette_19_11_C)/sizeof(palette_19_11_C[0])
- && ix <= sizeof(palette_19_11_M)/sizeof(palette_19_11_M[0])
- && ix <= sizeof(palette_19_11_Y)/sizeof(palette_19_11_Y[0])
- && ix <= sizeof(palette_19_11_K)/sizeof(palette_19_11_K[0]))
- {
- c = palette_19_11_C[ix-1];
- m = palette_19_11_M[ix-1];
- y = palette_19_11_Y[ix-1];
- k = palette_19_11_K[ix-1];
- }
- break;
- case 0x12:
- if (ix > 0
- && ix <= sizeof(palette_19_12_C)/sizeof(palette_19_12_C[0])
- && ix <= sizeof(palette_19_12_M)/sizeof(palette_19_12_M[0])
- && ix <= sizeof(palette_19_12_Y)/sizeof(palette_19_12_Y[0])
- && ix <= sizeof(palette_19_12_K)/sizeof(palette_19_12_K[0]))
- {
- c = palette_19_12_C[ix-1];
- m = palette_19_12_M[ix-1];
- y = palette_19_12_Y[ix-1];
- k = palette_19_12_K[ix-1];
- }
- break;
- case 0x14:
- if (ix > 0
- && ix <= sizeof(palette_19_14_C)/sizeof(palette_19_14_C[0])
- && ix <= sizeof(palette_19_14_M)/sizeof(palette_19_14_M[0])
- && ix <= sizeof(palette_19_14_Y)/sizeof(palette_19_14_Y[0])
- && ix <= sizeof(palette_19_14_K)/sizeof(palette_19_14_K[0]))
- {
- c = palette_19_14_C[ix-1];
- m = palette_19_14_M[ix-1];
- y = palette_19_14_Y[ix-1];
- k = palette_19_14_K[ix-1];
- }
- break;
- case 0x15:
- if (ix > 0
- && ix <= sizeof(palette_19_15_C)/sizeof(palette_19_15_C[0])
- && ix <= sizeof(palette_19_15_M)/sizeof(palette_19_15_M[0])
- && ix <= sizeof(palette_19_15_Y)/sizeof(palette_19_15_Y[0])
- && ix <= sizeof(palette_19_15_K)/sizeof(palette_19_15_K[0]))
- {
- c = palette_19_15_C[ix-1];
- m = palette_19_15_M[ix-1];
- y = palette_19_15_Y[ix-1];
- k = palette_19_15_K[ix-1];
- }
- break;
- case 0x16:
- if (ix > 0
- && ix <= sizeof(palette_19_16_C)/sizeof(palette_19_16_C[0])
- && ix <= sizeof(palette_19_16_M)/sizeof(palette_19_16_M[0])
- && ix <= sizeof(palette_19_16_Y)/sizeof(palette_19_16_Y[0])
- && ix <= sizeof(palette_19_16_K)/sizeof(palette_19_16_K[0]))
- {
- c = palette_19_16_C[ix-1];
- m = palette_19_16_M[ix-1];
- y = palette_19_16_Y[ix-1];
- k = palette_19_16_K[ix-1];
- }
- break;
- case 0x17:
- if (ix > 0
- && ix <= sizeof(palette_19_17_C)/sizeof(palette_19_17_C[0])
- && ix <= sizeof(palette_19_17_M)/sizeof(palette_19_17_M[0])
- && ix <= sizeof(palette_19_17_Y)/sizeof(palette_19_17_Y[0])
- && ix <= sizeof(palette_19_17_K)/sizeof(palette_19_17_K[0]))
- {
- c = palette_19_17_C[ix-1];
- m = palette_19_17_M[ix-1];
- y = palette_19_17_Y[ix-1];
- k = palette_19_17_K[ix-1];
- }
- break;
- case 0x1a:
- if (ix < sizeof(palette_19_1A_C)/sizeof(palette_19_1A_C[0])
- && ix < sizeof(palette_19_1A_M)/sizeof(palette_19_1A_M[0])
- && ix < sizeof(palette_19_1A_Y)/sizeof(palette_19_1A_Y[0])
- && ix < sizeof(palette_19_1A_K)/sizeof(palette_19_1A_K[0]))
- {
- c = palette_19_1A_C[ix];
- m = palette_19_1A_M[ix];
- y = palette_19_1A_Y[ix];
- k = palette_19_1A_K[ix];
- }
- break;
- case 0x1b:
- if (ix < sizeof(palette_19_1B_C)/sizeof(palette_19_1B_C[0])
- && ix < sizeof(palette_19_1B_M)/sizeof(palette_19_1B_M[0])
- && ix < sizeof(palette_19_1B_Y)/sizeof(palette_19_1B_Y[0])
- && ix < sizeof(palette_19_1B_K)/sizeof(palette_19_1B_K[0]))
- {
- c = palette_19_1B_C[ix];
- m = palette_19_1B_M[ix];
- y = palette_19_1B_Y[ix];
- k = palette_19_1B_K[ix];
- }
- break;
- case 0x1c:
- if (ix < sizeof(palette_19_1C_C)/sizeof(palette_19_1C_C[0])
- && ix < sizeof(palette_19_1C_M)/sizeof(palette_19_1C_M[0])
- && ix < sizeof(palette_19_1C_Y)/sizeof(palette_19_1C_Y[0])
- && ix < sizeof(palette_19_1C_K)/sizeof(palette_19_1C_K[0]))
- {
- c = palette_19_1C_C[ix];
- m = palette_19_1C_M[ix];
- y = palette_19_1C_Y[ix];
- k = palette_19_1C_K[ix];
- }
- break;
- case 0x1d:
- if (ix < sizeof(palette_19_1D_C)/sizeof(palette_19_1D_C[0])
- && ix < sizeof(palette_19_1D_M)/sizeof(palette_19_1D_M[0])
- && ix < sizeof(palette_19_1D_Y)/sizeof(palette_19_1D_Y[0])
- && ix < sizeof(palette_19_1D_K)/sizeof(palette_19_1D_K[0]))
- {
- c = palette_19_1D_C[ix];
- m = palette_19_1D_M[ix];
- y = palette_19_1D_Y[ix];
- k = palette_19_1D_K[ix];
- }
- break;
- case 0x1e:
- if (ix > 0
- && ix <= sizeof(palette_19_1E_R)/sizeof(palette_19_1E_R[0])
- && ix <= sizeof(palette_19_1E_G)/sizeof(palette_19_1E_G[0])
- && ix <= sizeof(palette_19_1E_B)/sizeof(palette_19_1E_B[0]))
- {
- r = palette_19_1E_R[ix-1];
- g = palette_19_1E_G[ix-1];
- b = palette_19_1E_B[ix-1];
- }
- break;
- case 0x1f:
- if (ix > 0
- && ix <= sizeof(palette_19_1F_R)/sizeof(palette_19_1F_R[0])
- && ix <= sizeof(palette_19_1F_G)/sizeof(palette_19_1F_G[0])
- && ix <= sizeof(palette_19_1F_B)/sizeof(palette_19_1F_B[0]))
- {
- r = palette_19_1F_R[ix-1];
- g = palette_19_1F_G[ix-1];
- b = palette_19_1F_B[ix-1];
- }
- break;
- case 0x20:
- if (ix > 0
- && ix <= sizeof(palette_19_20_R)/sizeof(palette_19_20_R[0])
- && ix <= sizeof(palette_19_20_G)/sizeof(palette_19_20_G[0])
- && ix <= sizeof(palette_19_20_B)/sizeof(palette_19_20_B[0]))
- {
- r = palette_19_20_R[ix-1];
- g = palette_19_20_G[ix-1];
- b = palette_19_20_B[ix-1];
- }
- break;
- case 0x23:
- if (ix > 0
- && ix <= sizeof(palette_19_23_C)/sizeof(palette_19_23_C[0])
- && ix <= sizeof(palette_19_23_M)/sizeof(palette_19_23_M[0])
- && ix <= sizeof(palette_19_23_Y)/sizeof(palette_19_23_Y[0])
- && ix <= sizeof(palette_19_23_K)/sizeof(palette_19_23_K[0]))
- {
- c = palette_19_23_C[ix-1];
- m = palette_19_23_M[ix-1];
- y = palette_19_23_Y[ix-1];
- k = palette_19_23_K[ix-1];
- }
- break;
- case 0x24:
- if (ix > 0
- && ix <= sizeof(palette_19_24_C)/sizeof(palette_19_24_C[0])
- && ix <= sizeof(palette_19_24_M)/sizeof(palette_19_24_M[0])
- && ix <= sizeof(palette_19_24_Y)/sizeof(palette_19_24_Y[0])
- && ix <= sizeof(palette_19_24_K)/sizeof(palette_19_24_K[0]))
- {
- c = palette_19_24_C[ix-1];
- m = palette_19_24_M[ix-1];
- y = palette_19_24_Y[ix-1];
- k = palette_19_24_K[ix-1];
- }
- break;
- case 0x25:
- if (ix > 0
- && ix <= sizeof(palette_19_25_C)/sizeof(palette_19_25_C[0])
- && ix <= sizeof(palette_19_25_M)/sizeof(palette_19_25_M[0])
- && ix <= sizeof(palette_19_25_Y)/sizeof(palette_19_25_Y[0])
- && ix <= sizeof(palette_19_25_K)/sizeof(palette_19_25_K[0]))
- {
- c = palette_19_25_C[ix-1];
- m = palette_19_25_M[ix-1];
- y = palette_19_25_Y[ix-1];
- k = palette_19_25_K[ix-1];
- }
- break;
- default:
- colorValue = (tint << 16) | ix;
- break;
- }
-
- switch (paletteID)
- {
- case 0x03:
- case 0x08:
- case 0x0a:
- case 0x0b:
- case 0x11:
- case 0x12:
- case 0x14:
- case 0x15:
- case 0x16:
- case 0x17:
- case 0x1a:
- case 0x1b:
- case 0x1c:
- case 0x1d:
- case 0x23:
- case 0x24:
- case 0x25:
- {
- colorModel = 0x02; // CMYK100
- unsigned cyan = (unsigned)tint * (unsigned)c / 100;
- unsigned magenta = (unsigned)tint * (unsigned)m / 100;
- unsigned yellow = (unsigned)tint * (unsigned)y / 100;
- unsigned black = (unsigned)tint * (unsigned)k / 100;
- colorValue = (black & 0xff);
- colorValue <<= 8;
- colorValue |= (yellow & 0xff);
- colorValue <<= 8;
- colorValue |= (magenta & 0xff);
- colorValue <<= 8;
- colorValue |= (cyan & 0xff);
- break;
- }
- case 0x1e:
- case 0x1f:
- case 0x20:
- {
- colorModel = 0x05; // RGB
- unsigned red = (unsigned)tint * (unsigned)r + 255 * (100 - tint);
- unsigned green = (unsigned)tint * (unsigned)g + 255 * (100 - tint);
- unsigned blue = (unsigned)tint * (unsigned)b + 255 * (100 - tint);
- red /= 100;
- green /= 100;
- blue /= 100;
- colorValue = (red & 0xff);
- colorValue <<= 8;
- colorValue |= (green & 0xff);
- colorValue <<= 8;
- colorValue |= (blue & 0xff);
- break;
- }
- case 0x09:
- colorModel = 0x12; // L*a*b
- break;
- default:
- break;
- }
- }
- else if (colorModel == 0x0e)
+ tmpColor.m_colorModel = readU16(input);
+ if (tmpColor.m_colorModel == 0x01 && m_version >= 1300)
+ tmpColor.m_colorModel = 0x19;
+ /* A bug in CorelDraw x7 creates a corrupted file. If we meet colorModel of 0x1e,
+ * it is actually colorModel 0x19 and paletteId 0x1e */
+ if (tmpColor.m_colorModel == 0x1e)
{
- unsigned short paletteID = readU16(input);
- input->seek(4, librevenge::RVNG_SEEK_CUR);
- unsigned short ix = readU16(input);
- unsigned short tint = readU16(input);
- switch (paletteID)
- {
- case 0x0c:
- if (ix > 0
- && ix <= sizeof(palette_0E_0C_L)/sizeof(palette_0E_0C_L[0])
- && ix <= sizeof(palette_0E_0C_A)/sizeof(palette_0E_0C_A[0])
- && ix <= sizeof(palette_0E_0C_B)/sizeof(palette_0E_0C_B[0]))
- {
- colorValue = palette_0E_0C_B[ix-1];
- colorValue <<= 8;
- colorValue |= palette_0E_0C_A[ix-1];
- colorValue <<= 8;
- colorValue |= palette_0E_0C_L[ix-1];
- }
- break;
- case 0x18:
- if (ix > 0
- && ix <= sizeof(palette_0E_18_L)/sizeof(palette_0E_18_L[0])
- && ix <= sizeof(palette_0E_18_A)/sizeof(palette_0E_18_A[0])
- && ix <= sizeof(palette_0E_18_B)/sizeof(palette_0E_18_B[0]))
- {
- colorValue = palette_0E_18_B[ix-1];
- colorValue <<= 8;
- colorValue |= palette_0E_18_A[ix-1];
- colorValue <<= 8;
- colorValue |= palette_0E_18_L[ix-1];
- }
- break;
- case 0x21:
- if (ix > 0
- && ix <= sizeof(palette_0E_21_L)/sizeof(palette_0E_21_L[0])
- && ix <= sizeof(palette_0E_21_A)/sizeof(palette_0E_21_A[0])
- && ix <= sizeof(palette_0E_21_B)/sizeof(palette_0E_21_B[0]))
- {
- colorValue = palette_0E_21_B[ix-1];
- colorValue <<= 8;
- colorValue |= palette_0E_21_A[ix-1];
- colorValue <<= 8;
- colorValue |= palette_0E_21_L[ix-1];
- }
- break;
- case 0x22:
- if (ix > 0
- && ix <= sizeof(palette_0E_22_L)/sizeof(palette_0E_22_L[0])
- && ix <= sizeof(palette_0E_22_A)/sizeof(palette_0E_22_A[0])
- && ix <= sizeof(palette_0E_22_B)/sizeof(palette_0E_22_B[0]))
- {
- colorValue = palette_0E_22_B[ix-1];
- colorValue <<= 8;
- colorValue |= palette_0E_22_A[ix-1];
- colorValue <<= 8;
- colorValue |= palette_0E_22_L[ix-1];
- }
- break;
- default:
- colorValue = tint;
- colorValue <<= 16;
- colorValue |= ix;
- break;
- }
-
- switch (paletteID)
- {
- case 0x0c:
- case 0x18:
- case 0x21:
- case 0x22:
- colorModel = 0x12; // L*a*b
- break;
- default:
- break;
- }
+ tmpColor.m_colorModel = 0x19;
+ tmpColor.m_colorPalette = 0x1e;
}
else
{
- input->seek(6, librevenge::RVNG_SEEK_CUR);
- colorValue = readU32(input);
+ tmpColor.m_colorPalette = readU16(input);
+ input->seek(4, librevenge::RVNG_SEEK_CUR);
}
+ tmpColor.m_colorValue = readU32(input);
+
}
else if (m_version >= 400)
{
- colorModel = readU16(input);
+ tmpColor.m_colorModel = readU16(input);
unsigned short c = readU16(input);
unsigned short m = readU16(input);
unsigned short y = readU16(input);
unsigned short k = readU16(input);
- colorValue = (k & 0xff);
- colorValue <<= 8;
- colorValue |= (y & 0xff);
- colorValue <<= 8;
- colorValue |= (m & 0xff);
- colorValue <<= 8;
- colorValue |= (c & 0xff);
+ tmpColor.m_colorValue = (k & 0xff);
+ tmpColor.m_colorValue <<= 8;
+ tmpColor.m_colorValue |= (y & 0xff);
+ tmpColor.m_colorValue <<= 8;
+ tmpColor.m_colorValue |= (m & 0xff);
+ tmpColor.m_colorValue <<= 8;
+ tmpColor.m_colorValue |= (c & 0xff);
input->seek(2, librevenge::RVNG_SEEK_CUR);
}
else
{
- colorModel = readU8(input);
- colorValue = readU32(input);
+ tmpColor.m_colorModel = readU8(input);
+ tmpColor.m_colorValue = readU32(input);
}
- CDR_DEBUG_MSG(("CDRParser::readColor --> colorModel 0x%x -- colorValue 0x%x\n", colorModel, colorValue));
+ CDR_DEBUG_MSG(("CDRParser::readColor --> colorModel 0x%x -- colorPalette 0x%x -- colorValue 0x%x\n", tmpColor.m_colorModel, tmpColor.m_colorPalette, tmpColor.m_colorValue));
- return libcdr::CDRColor(colorModel, colorValue);
+ _resolveColorPalette(tmpColor);
+
+ CDR_DEBUG_MSG(("CDRParser::readColor resolved --> colorModel 0x%x -- colorPalette 0x%x -- colorValue 0x%x\n", tmpColor.m_colorModel, tmpColor.m_colorPalette, tmpColor.m_colorValue));
+
+ return tmpColor;
}
void libcdr::CDRParser::readRectangle(librevenge::RVNGInputStream *input)
@@ -3552,4 +3133,425 @@ void libcdr::CDRParser::_skipX3Optional(librevenge::RVNGInputStream *input)
}
}
+void libcdr::CDRParser::_resolveColorPalette(libcdr::CDRColor &color)
+{
+ unsigned char r = 0;
+ unsigned char g = 0;
+ unsigned char b = 0;
+ unsigned char c = 0;
+ unsigned char m = 0;
+ unsigned char y = 0;
+ unsigned char k = 100;
+
+ unsigned short ix = color.m_colorValue & 0xffff;
+ unsigned short tint = (color.m_colorValue >> 16) & 0xffff;
+
+ if (color.m_colorModel == 0x19)
+ {
+ switch (color.m_colorPalette)
+ {
+ case 0x03:
+ if (ix > 0
+ && ix <= sizeof(palette_19_03_C)/sizeof(palette_19_03_C[0])
+ && ix <= sizeof(palette_19_03_M)/sizeof(palette_19_03_M[0])
+ && ix <= sizeof(palette_19_03_Y)/sizeof(palette_19_03_Y[0])
+ && ix <= sizeof(palette_19_03_K)/sizeof(palette_19_03_K[0]))
+ {
+ c = palette_19_03_C[ix-1];
+ m = palette_19_03_M[ix-1];
+ y = palette_19_03_Y[ix-1];
+ k = palette_19_03_K[ix-1];
+ }
+ break;
+ case 0x08:
+ if (ix > 0
+ && ix <= sizeof(palette_19_08_C)/sizeof(palette_19_08_C[0])
+ && ix <= sizeof(palette_19_08_M)/sizeof(palette_19_08_M[0])
+ && ix <= sizeof(palette_19_08_Y)/sizeof(palette_19_08_Y[0])
+ && ix <= sizeof(palette_19_08_K)/sizeof(palette_19_08_K[0]))
+ {
+ c = palette_19_08_C[ix-1];
+ m = palette_19_08_M[ix-1];
+ y = palette_19_08_Y[ix-1];
+ k = palette_19_08_K[ix-1];
+ }
+ break;
+ case 0x09:
+ if (ix > 0
+ && ix <= sizeof(palette_19_09_L)/sizeof(palette_19_09_L[0])
+ && ix <= sizeof(palette_19_09_A)/sizeof(palette_19_09_A[0])
+ && ix <= sizeof(palette_19_09_B)/sizeof(palette_19_09_B[0]))
+ {
+ color.m_colorValue = palette_19_09_B[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_19_09_A[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_19_09_L[ix-1];
+ }
+ break;
+ case 0x0a:
+ if (ix > 0
+ && ix <= sizeof(palette_19_0A_C)/sizeof(palette_19_0A_C[0])
+ && ix <= sizeof(palette_19_0A_M)/sizeof(palette_19_0A_M[0])
+ && ix <= sizeof(palette_19_0A_Y)/sizeof(palette_19_0A_Y[0])
+ && ix <= sizeof(palette_19_0A_K)/sizeof(palette_19_0A_K[0]))
+ {
+ c = palette_19_0A_C[ix-1];
+ m = palette_19_0A_M[ix-1];
+ y = palette_19_0A_Y[ix-1];
+ k = palette_19_0A_K[ix-1];
+ }
+ break;
+ case 0x0b:
+ if (ix > 0
+ && ix <= sizeof(palette_19_0B_C)/sizeof(palette_19_0B_C[0])
+ && ix <= sizeof(palette_19_0B_M)/sizeof(palette_19_0B_M[0])
+ && ix <= sizeof(palette_19_0B_Y)/sizeof(palette_19_0B_Y[0])
+ && ix <= sizeof(palette_19_0B_K)/sizeof(palette_19_0B_K[0]))
+ {
+ c = palette_19_0B_C[ix-1];
+ m = palette_19_0B_M[ix-1];
+ y = palette_19_0B_Y[ix-1];
+ k = palette_19_0B_K[ix-1];
+ }
+ break;
+ case 0x11:
+ if (ix > 0
+ && ix <= sizeof(palette_19_11_C)/sizeof(palette_19_11_C[0])
+ && ix <= sizeof(palette_19_11_M)/sizeof(palette_19_11_M[0])
+ && ix <= sizeof(palette_19_11_Y)/sizeof(palette_19_11_Y[0])
+ && ix <= sizeof(palette_19_11_K)/sizeof(palette_19_11_K[0]))
+ {
+ c = palette_19_11_C[ix-1];
+ m = palette_19_11_M[ix-1];
+ y = palette_19_11_Y[ix-1];
+ k = palette_19_11_K[ix-1];
+ }
+ break;
+ case 0x12:
+ if (ix > 0
+ && ix <= sizeof(palette_19_12_C)/sizeof(palette_19_12_C[0])
+ && ix <= sizeof(palette_19_12_M)/sizeof(palette_19_12_M[0])
+ && ix <= sizeof(palette_19_12_Y)/sizeof(palette_19_12_Y[0])
+ && ix <= sizeof(palette_19_12_K)/sizeof(palette_19_12_K[0]))
+ {
+ c = palette_19_12_C[ix-1];
+ m = palette_19_12_M[ix-1];
+ y = palette_19_12_Y[ix-1];
+ k = palette_19_12_K[ix-1];
+ }
+ break;
+ case 0x14:
+ if (ix > 0
+ && ix <= sizeof(palette_19_14_C)/sizeof(palette_19_14_C[0])
+ && ix <= sizeof(palette_19_14_M)/sizeof(palette_19_14_M[0])
+ && ix <= sizeof(palette_19_14_Y)/sizeof(palette_19_14_Y[0])
+ && ix <= sizeof(palette_19_14_K)/sizeof(palette_19_14_K[0]))
+ {
+ c = palette_19_14_C[ix-1];
+ m = palette_19_14_M[ix-1];
+ y = palette_19_14_Y[ix-1];
+ k = palette_19_14_K[ix-1];
+ }
+ break;
+ case 0x15:
+ if (ix > 0
+ && ix <= sizeof(palette_19_15_C)/sizeof(palette_19_15_C[0])
+ && ix <= sizeof(palette_19_15_M)/sizeof(palette_19_15_M[0])
+ && ix <= sizeof(palette_19_15_Y)/sizeof(palette_19_15_Y[0])
+ && ix <= sizeof(palette_19_15_K)/sizeof(palette_19_15_K[0]))
+ {
+ c = palette_19_15_C[ix-1];
+ m = palette_19_15_M[ix-1];
+ y = palette_19_15_Y[ix-1];
+ k = palette_19_15_K[ix-1];
+ }
+ break;
+ case 0x16:
+ if (ix > 0
+ && ix <= sizeof(palette_19_16_C)/sizeof(palette_19_16_C[0])
+ && ix <= sizeof(palette_19_16_M)/sizeof(palette_19_16_M[0])
+ && ix <= sizeof(palette_19_16_Y)/sizeof(palette_19_16_Y[0])
+ && ix <= sizeof(palette_19_16_K)/sizeof(palette_19_16_K[0]))
+ {
+ c = palette_19_16_C[ix-1];
+ m = palette_19_16_M[ix-1];
+ y = palette_19_16_Y[ix-1];
+ k = palette_19_16_K[ix-1];
+ }
+ break;
+ case 0x17:
+ if (ix > 0
+ && ix <= sizeof(palette_19_17_C)/sizeof(palette_19_17_C[0])
+ && ix <= sizeof(palette_19_17_M)/sizeof(palette_19_17_M[0])
+ && ix <= sizeof(palette_19_17_Y)/sizeof(palette_19_17_Y[0])
+ && ix <= sizeof(palette_19_17_K)/sizeof(palette_19_17_K[0]))
+ {
+ c = palette_19_17_C[ix-1];
+ m = palette_19_17_M[ix-1];
+ y = palette_19_17_Y[ix-1];
+ k = palette_19_17_K[ix-1];
+ }
+ break;
+ case 0x1a:
+ if (ix < sizeof(palette_19_1A_C)/sizeof(palette_19_1A_C[0])
+ && ix < sizeof(palette_19_1A_M)/sizeof(palette_19_1A_M[0])
+ && ix < sizeof(palette_19_1A_Y)/sizeof(palette_19_1A_Y[0])
+ && ix < sizeof(palette_19_1A_K)/sizeof(palette_19_1A_K[0]))
+ {
+ c = palette_19_1A_C[ix];
+ m = palette_19_1A_M[ix];
+ y = palette_19_1A_Y[ix];
+ k = palette_19_1A_K[ix];
+ }
+ break;
+ case 0x1b:
+ if (ix < sizeof(palette_19_1B_C)/sizeof(palette_19_1B_C[0])
+ && ix < sizeof(palette_19_1B_M)/sizeof(palette_19_1B_M[0])
+ && ix < sizeof(palette_19_1B_Y)/sizeof(palette_19_1B_Y[0])
+ && ix < sizeof(palette_19_1B_K)/sizeof(palette_19_1B_K[0]))
+ {
+ c = palette_19_1B_C[ix];
+ m = palette_19_1B_M[ix];
+ y = palette_19_1B_Y[ix];
+ k = palette_19_1B_K[ix];
+ }
+ break;
+ case 0x1c:
+ if (ix < sizeof(palette_19_1C_C)/sizeof(palette_19_1C_C[0])
+ && ix < sizeof(palette_19_1C_M)/sizeof(palette_19_1C_M[0])
+ && ix < sizeof(palette_19_1C_Y)/sizeof(palette_19_1C_Y[0])
+ && ix < sizeof(palette_19_1C_K)/sizeof(palette_19_1C_K[0]))
+ {
+ c = palette_19_1C_C[ix];
+ m = palette_19_1C_M[ix];
+ y = palette_19_1C_Y[ix];
+ k = palette_19_1C_K[ix];
+ }
+ break;
+ case 0x1d:
+ if (ix < sizeof(palette_19_1D_C)/sizeof(palette_19_1D_C[0])
+ && ix < sizeof(palette_19_1D_M)/sizeof(palette_19_1D_M[0])
+ && ix < sizeof(palette_19_1D_Y)/sizeof(palette_19_1D_Y[0])
+ && ix < sizeof(palette_19_1D_K)/sizeof(palette_19_1D_K[0]))
+ {
+ c = palette_19_1D_C[ix];
+ m = palette_19_1D_M[ix];
+ y = palette_19_1D_Y[ix];
+ k = palette_19_1D_K[ix];
+ }
+ break;
+ case 0x1e:
+ if (ix > 0
+ && ix <= sizeof(palette_19_1E_R)/sizeof(palette_19_1E_R[0])
+ && ix <= sizeof(palette_19_1E_G)/sizeof(palette_19_1E_G[0])
+ && ix <= sizeof(palette_19_1E_B)/sizeof(palette_19_1E_B[0]))
+ {
+ r = palette_19_1E_R[ix-1];
+ g = palette_19_1E_G[ix-1];
+ b = palette_19_1E_B[ix-1];
+ }
+ break;
+ case 0x1f:
+ if (ix > 0
+ && ix <= sizeof(palette_19_1F_R)/sizeof(palette_19_1F_R[0])
+ && ix <= sizeof(palette_19_1F_G)/sizeof(palette_19_1F_G[0])
+ && ix <= sizeof(palette_19_1F_B)/sizeof(palette_19_1F_B[0]))
+ {
+ r = palette_19_1F_R[ix-1];
+ g = palette_19_1F_G[ix-1];
+ b = palette_19_1F_B[ix-1];
+ }
+ break;
+ case 0x20:
+ if (ix > 0
+ && ix <= sizeof(palette_19_20_R)/sizeof(palette_19_20_R[0])
+ && ix <= sizeof(palette_19_20_G)/sizeof(palette_19_20_G[0])
+ && ix <= sizeof(palette_19_20_B)/sizeof(palette_19_20_B[0]))
+ {
+ r = palette_19_20_R[ix-1];
+ g = palette_19_20_G[ix-1];
+ b = palette_19_20_B[ix-1];
+ }
+ break;
+ case 0x23:
+ if (ix > 0
+ && ix <= sizeof(palette_19_23_C)/sizeof(palette_19_23_C[0])
+ && ix <= sizeof(palette_19_23_M)/sizeof(palette_19_23_M[0])
+ && ix <= sizeof(palette_19_23_Y)/sizeof(palette_19_23_Y[0])
+ && ix <= sizeof(palette_19_23_K)/sizeof(palette_19_23_K[0]))
+ {
+ c = palette_19_23_C[ix-1];
+ m = palette_19_23_M[ix-1];
+ y = palette_19_23_Y[ix-1];
+ k = palette_19_23_K[ix-1];
+ }
+ break;
+ case 0x24:
+ if (ix > 0
+ && ix <= sizeof(palette_19_24_C)/sizeof(palette_19_24_C[0])
+ && ix <= sizeof(palette_19_24_M)/sizeof(palette_19_24_M[0])
+ && ix <= sizeof(palette_19_24_Y)/sizeof(palette_19_24_Y[0])
+ && ix <= sizeof(palette_19_24_K)/sizeof(palette_19_24_K[0]))
+ {
+ c = palette_19_24_C[ix-1];
+ m = palette_19_24_M[ix-1];
+ y = palette_19_24_Y[ix-1];
+ k = palette_19_24_K[ix-1];
+ }
+ break;
+ case 0x25:
+ if (ix > 0
+ && ix <= sizeof(palette_19_25_C)/sizeof(palette_19_25_C[0])
+ && ix <= sizeof(palette_19_25_M)/sizeof(palette_19_25_M[0])
+ && ix <= sizeof(palette_19_25_Y)/sizeof(palette_19_25_Y[0])
+ && ix <= sizeof(palette_19_25_K)/sizeof(palette_19_25_K[0]))
+ {
+ c = palette_19_25_C[ix-1];
+ m = palette_19_25_M[ix-1];
+ y = palette_19_25_Y[ix-1];
+ k = palette_19_25_K[ix-1];
+ }
+ break;
+ default:
+ break;
+ }
+
+ switch (color.m_colorPalette)
+ {
+ case 0x03:
+ case 0x08:
+ case 0x0a:
+ case 0x0b:
+ case 0x11:
+ case 0x12:
+ case 0x14:
+ case 0x15:
+ case 0x16:
+ case 0x17:
+ case 0x1a:
+ case 0x1b:
+ case 0x1c:
+ case 0x1d:
+ case 0x23:
+ case 0x24:
+ case 0x25:
+ {
+ color.m_colorModel = 0x02; // CMYK100
+ unsigned cyan = (unsigned)tint * (unsigned)c / 100;
+ unsigned magenta = (unsigned)tint * (unsigned)m / 100;
+ unsigned yellow = (unsigned)tint * (unsigned)y / 100;
+ unsigned black = (unsigned)tint * (unsigned)k / 100;
+ color.m_colorValue = (black & 0xff);
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= (yellow & 0xff);
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= (magenta & 0xff);
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= (cyan & 0xff);
+ color.m_colorPalette = 0;
+ break;
+ }
+ case 0x1e:
+ case 0x1f:
+ case 0x20:
+ {
+ color.m_colorModel = 0x05; // RGB
+ unsigned red = (unsigned)tint * (unsigned)r + 255 * (100 - tint);
+ unsigned green = (unsigned)tint * (unsigned)g + 255 * (100 - tint);
+ unsigned blue = (unsigned)tint * (unsigned)b + 255 * (100 - tint);
+ red /= 100;
+ green /= 100;
+ blue /= 100;
+ color.m_colorValue = (red & 0xff);
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= (green & 0xff);
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= (blue & 0xff);
+ color.m_colorPalette = 0;
+ break;
+ }
+ case 0x09:
+ color.m_colorModel = 0x12; // L*a*b
+ color.m_colorPalette = 0;
+ break;
+ default:
+ break;
+ }
+ }
+ else if (color.m_colorModel == 0x0e)
+ {
+ switch (color.m_colorPalette)
+ {
+ case 0x0c:
+ if (ix > 0
+ && ix <= sizeof(palette_0E_0C_L)/sizeof(palette_0E_0C_L[0])
+ && ix <= sizeof(palette_0E_0C_A)/sizeof(palette_0E_0C_A[0])
+ && ix <= sizeof(palette_0E_0C_B)/sizeof(palette_0E_0C_B[0]))
+ {
+ color.m_colorValue = palette_0E_0C_B[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_0E_0C_A[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_0E_0C_L[ix-1];
+ }
+ break;
+ case 0x18:
+ if (ix > 0
+ && ix <= sizeof(palette_0E_18_L)/sizeof(palette_0E_18_L[0])
+ && ix <= sizeof(palette_0E_18_A)/sizeof(palette_0E_18_A[0])
+ && ix <= sizeof(palette_0E_18_B)/sizeof(palette_0E_18_B[0]))
+ {
+ color.m_colorValue = palette_0E_18_B[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_0E_18_A[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_0E_18_L[ix-1];
+ }
+ break;
+ case 0x21:
+ if (ix > 0
+ && ix <= sizeof(palette_0E_21_L)/sizeof(palette_0E_21_L[0])
+ && ix <= sizeof(palette_0E_21_A)/sizeof(palette_0E_21_A[0])
+ && ix <= sizeof(palette_0E_21_B)/sizeof(palette_0E_21_B[0]))
+ {
+ color.m_colorValue = palette_0E_21_B[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_0E_21_A[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_0E_21_L[ix-1];
+ }
+ break;
+ case 0x22:
+ if (ix > 0
+ && ix <= sizeof(palette_0E_22_L)/sizeof(palette_0E_22_L[0])
+ && ix <= sizeof(palette_0E_22_A)/sizeof(palette_0E_22_A[0])
+ && ix <= sizeof(palette_0E_22_B)/sizeof(palette_0E_22_B[0]))
+ {
+ color.m_colorValue = palette_0E_22_B[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_0E_22_A[ix-1];
+ color.m_colorValue <<= 8;
+ color.m_colorValue |= palette_0E_22_L[ix-1];
+ }
+ break;
+ default:
+ break;
+ }
+
+ switch (color.m_colorPalette)
+ {
+ case 0x0c:
+ case 0x18:
+ case 0x21:
+ case 0x22:
+ color.m_colorModel = 0x12; // L*a*b
+ color.m_colorPalette = 0;
+ break;
+ default:
+ break;
+ }
+ }
+}
+
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/CDRParser.h b/src/lib/CDRParser.h
index 76c46e0..75acc0e 100644
--- a/src/lib/CDRParser.h
+++ b/src/lib/CDRParser.h
@@ -95,6 +95,7 @@ private:
bool _redirectX6Chunk(librevenge::RVNGInputStream **input, unsigned &length);
void _readX6StyleString(librevenge::RVNGInputStream *input, unsigned length, CDRStyle &style);
void _skipX3Optional(librevenge::RVNGInputStream *input);
+ void _resolveColorPalette(CDRColor &color);
const std::vector<std::unique_ptr<librevenge::RVNGInputStream>> &m_externalStreams;
diff --git a/src/lib/CDRTypes.h b/src/lib/CDRTypes.h
index f3010e0..9144592 100644
--- a/src/lib/CDRTypes.h
+++ b/src/lib/CDRTypes.h
@@ -53,10 +53,14 @@ struct CDRBox
struct CDRColor
{
unsigned short m_colorModel;
+ unsigned short m_colorPalette;
unsigned m_colorValue;
- CDRColor() : m_colorModel(0), m_colorValue(0) {}
+ CDRColor(unsigned short colorModel, unsigned short colorPalette, unsigned colorValue)
+ : m_colorModel(colorModel), m_colorPalette(colorPalette), m_colorValue(colorValue) {}
+ CDRColor()
+ : m_colorModel(0), m_colorPalette(0), m_colorValue(0) {}
CDRColor(unsigned short colorModel, unsigned colorValue)
- : m_colorModel(colorModel), m_colorValue(colorValue) {}
+ : m_colorModel(colorModel), m_colorPalette(0), m_colorValue(colorValue) {}
};
struct CDRGradientStop