Coverage Report

Created: 2026-06-13 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libcdr/src/lib/CDRCollector.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/*
3
 * This file is part of the libcdr project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#include "CDRCollector.h"
11
12
#include <math.h>
13
#include <stack>
14
#include <string.h>
15
#include <lcms2.h>
16
#include "CDRColorProfiles.h"
17
#include "libcdr_utils.h"
18
19
libcdr::CDRParserState::CDRParserState()
20
41.0k
  : m_bmps(), m_patterns(), m_vects(), m_pages(), m_documentPalette(), m_texts(),
21
41.0k
    m_styles(), m_fillStyles(), m_lineStyles(),
22
41.0k
    m_colorTransformCMYK2RGB(nullptr), m_colorTransformLab2RGB(nullptr), m_colorTransformRGB2RGB(nullptr)
23
41.0k
{
24
41.0k
  cmsHPROFILE tmpRGBProfile = cmsCreate_sRGBProfile();
25
41.0k
  m_colorTransformRGB2RGB = cmsCreateTransform(tmpRGBProfile, TYPE_RGB_8, tmpRGBProfile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0);
26
41.0k
  cmsHPROFILE tmpCMYKProfile = cmsOpenProfileFromMem(CMYK_icc, sizeof(CMYK_icc)/sizeof(CMYK_icc[0]));
27
41.0k
  m_colorTransformCMYK2RGB = cmsCreateTransform(tmpCMYKProfile, TYPE_CMYK_DBL, tmpRGBProfile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0);
28
41.0k
  cmsHPROFILE tmpLabProfile = cmsCreateLab4Profile(nullptr);
29
41.0k
  m_colorTransformLab2RGB = cmsCreateTransform(tmpLabProfile, TYPE_Lab_DBL, tmpRGBProfile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0);
30
41.0k
  cmsCloseProfile(tmpLabProfile);
31
41.0k
  cmsCloseProfile(tmpCMYKProfile);
32
41.0k
  cmsCloseProfile(tmpRGBProfile);
33
41.0k
}
34
35
libcdr::CDRParserState::~CDRParserState()
36
41.0k
{
37
41.0k
  if (m_colorTransformCMYK2RGB)
38
41.0k
    cmsDeleteTransform(m_colorTransformCMYK2RGB);
39
41.0k
  if (m_colorTransformLab2RGB)
40
41.0k
    cmsDeleteTransform(m_colorTransformLab2RGB);
41
41.0k
  if (m_colorTransformRGB2RGB)
42
41.0k
    cmsDeleteTransform(m_colorTransformRGB2RGB);
43
41.0k
}
44
45
void libcdr::CDRParserState::setColorTransform(const std::vector<unsigned char> &profile)
46
3.78k
{
47
3.78k
  if (profile.empty())
48
0
    return;
49
3.78k
  cmsHPROFILE tmpProfile = cmsOpenProfileFromMem(&profile[0], cmsUInt32Number(profile.size()));
50
3.78k
  if (!tmpProfile)
51
3.75k
    return;
52
27
  cmsHPROFILE tmpRGBProfile = cmsCreate_sRGBProfile();
53
27
  cmsColorSpaceSignature signature = cmsGetColorSpace(tmpProfile);
54
27
  switch (signature)
55
27
  {
56
0
  case cmsSigCmykData:
57
0
  {
58
0
    if (m_colorTransformCMYK2RGB)
59
0
      cmsDeleteTransform(m_colorTransformCMYK2RGB);
60
0
    m_colorTransformCMYK2RGB = cmsCreateTransform(tmpProfile, TYPE_CMYK_DBL, tmpRGBProfile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0);
61
0
  }
62
0
  break;
63
18
  case cmsSigRgbData:
64
18
  {
65
18
    if (m_colorTransformRGB2RGB)
66
18
      cmsDeleteTransform(m_colorTransformRGB2RGB);
67
18
    m_colorTransformRGB2RGB = cmsCreateTransform(tmpProfile, TYPE_RGB_8, tmpRGBProfile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0);
68
18
  }
69
18
  break;
70
9
  default:
71
9
    break;
72
27
  }
73
27
  cmsCloseProfile(tmpProfile);
74
27
  cmsCloseProfile(tmpRGBProfile);
75
27
}
76
77
void libcdr::CDRParserState::setColorTransform(librevenge::RVNGInputStream *input)
78
31
{
79
31
  if (!input)
80
0
    return;
81
31
  unsigned long numBytesRead = 0;
82
31
  const unsigned char *tmpProfile = input->read((unsigned long)-1, numBytesRead);
83
31
  if (!numBytesRead)
84
0
    return;
85
31
  std::vector<unsigned char> profile(numBytesRead);
86
31
  memcpy(&profile[0], tmpProfile, numBytesRead);
87
31
  setColorTransform(profile);
88
31
}
89
90
unsigned libcdr::CDRParserState::getBMPColor(const CDRColor &color)
91
1.90M
{
92
1.90M
  switch (color.m_colorModel)
93
1.90M
  {
94
304k
  case 0:
95
304k
    return _getRGBColor(libcdr::CDRColor(0, color.m_colorValue));
96
13.7k
  case 1:
97
13.7k
    return _getRGBColor(libcdr::CDRColor(5, color.m_colorValue));
98
1.67k
  case 2:
99
1.67k
    return _getRGBColor(libcdr::CDRColor(4, color.m_colorValue));
100
75.3k
  case 3:
101
75.3k
    return _getRGBColor(libcdr::CDRColor(3, color.m_colorValue));
102
3.94k
  case 4:
103
3.94k
    return _getRGBColor(libcdr::CDRColor(6, color.m_colorValue));
104
11.7k
  case 5:
105
11.7k
    return _getRGBColor(libcdr::CDRColor(9, color.m_colorValue));
106
670
  case 6:
107
670
    return _getRGBColor(libcdr::CDRColor(8, color.m_colorValue));
108
22.9k
  case 7:
109
22.9k
    return _getRGBColor(libcdr::CDRColor(7, color.m_colorValue));
110
359
  case 8:
111
359
    return color.m_colorValue;
112
10.3k
  case 9:
113
10.3k
    return color.m_colorValue;
114
1.42M
  case 10:
115
1.42M
    return _getRGBColor(libcdr::CDRColor(5, color.m_colorValue));
116
15.7k
  case 11:
117
15.7k
    return _getRGBColor(libcdr::CDRColor(18, color.m_colorValue));
118
17.7k
  default:
119
17.7k
    return color.m_colorValue;
120
1.90M
  }
121
1.90M
}
122
123
unsigned libcdr::CDRParserState::_getRGBColor(const CDRColor &color)
124
3.61M
{
125
3.61M
  unsigned char red = 0;
126
3.61M
  unsigned char green = 0;
127
3.61M
  unsigned char blue = 0;
128
3.61M
  unsigned short colorModel(color.m_colorModel);
129
3.61M
  unsigned colorValue(color.m_colorValue);
130
3.61M
  if (colorModel == 0x19) // Spot colour not handled in the parser
131
8.14k
  {
132
8.14k
    unsigned short colourIndex = colorValue & 0xffff;
133
8.14k
    std::map<unsigned, CDRColor>::const_iterator iter = m_documentPalette.find(colourIndex);
134
8.14k
    if (iter != m_documentPalette.end())
135
709
    {
136
709
      colorModel = iter->second.m_colorModel;
137
709
      colorValue = iter->second.m_colorValue;
138
709
    }
139
    // todo handle tint
140
8.14k
  }
141
3.61M
  unsigned char col0 = colorValue & 0xff;
142
3.61M
  unsigned char col1 = (colorValue >> 8) & 0xff;
143
3.61M
  unsigned char col2 = (colorValue >> 16) & 0xff;
144
3.61M
  unsigned char col3 = (unsigned char)((colorValue >> 24) & 0xff);
145
3.61M
  switch (colorModel)
146
3.61M
  {
147
1.40M
  case 0x00: // Pantone palette in CDR1
148
1.40M
  {
149
1.40M
    static const unsigned char WaldoColorType0_R[] =
150
1.40M
    {
151
1.40M
      0x00, 0xff, 0xde, 0xa1, 0xc5, 0x7d, 0x0c, 0x00, 0x00, 0x08, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
152
1.40M
      0x00, 0x00, 0x00, 0x00, 0xe5, 0xdc, 0xba, 0xa6, 0x82, 0xaf, 0xa9, 0x85, 0x78, 0x60, 0x44, 0xcf,
153
1.40M
      0xca, 0xbe, 0xb0, 0x91, 0xaa, 0x91, 0x75, 0x5b, 0x4d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
154
1.40M
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
155
1.40M
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
156
1.40M
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157
1.40M
      0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xc5, 0xa4, 0x6a, 0xff, 0xff, 0xff, 0xff, 0xd9, 0xa2,
158
1.40M
      0x8e, 0xff, 0xff, 0xff, 0xff, 0xc2, 0xa1, 0x73, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x9a, 0x84, 0xff,
159
1.40M
      0xff, 0xff, 0xff, 0xc8, 0x84, 0x52, 0xff, 0xff, 0xff, 0xff, 0xce, 0x93, 0x5a, 0xff, 0xff, 0xf2,
160
1.40M
      0xcb, 0xc5, 0x90, 0x5b, 0xff, 0xff, 0xff, 0xff, 0xcb, 0x95, 0x7f, 0xff, 0xff, 0xf5, 0xed, 0xb2,
161
1.40M
      0x7a, 0x4d, 0xff, 0xff, 0xff, 0xe6, 0xc2, 0x9b, 0x43, 0xff, 0xff, 0xff, 0xff, 0xb8, 0x72, 0x48,
162
1.40M
      0xff, 0xff, 0xff, 0xc6, 0x8e, 0x58, 0xff, 0xff, 0xec, 0xcc, 0xa3, 0x74, 0x49, 0xff, 0xff, 0xdf,
163
1.40M
      0xd6, 0x9a, 0x61, 0x44, 0xff, 0xeb, 0xca, 0xaa, 0x8d, 0x71, 0x59, 0xff, 0xe9, 0xd5, 0xaf, 0x7c,
164
1.40M
      0x53, 0x43, 0xff, 0xe7, 0xdb, 0xb8, 0xa1, 0x67, 0x44, 0xff, 0xda, 0xbc, 0x7c, 0x65, 0x40, 0xff,
165
1.40M
      0xe8, 0xd3, 0xb8, 0x7d, 0x57, 0x3c, 0xff, 0xe4, 0xd0, 0xa6, 0x6c, 0x4a, 0xff, 0xef, 0xc6, 0xab,
166
1.40M
      0x80, 0x68, 0x3f, 0xff, 0xde, 0xd0, 0x8d, 0x7c, 0x66, 0x44, 0xf9, 0xe4, 0xab, 0x63, 0x4e, 0x37,
167
1.40M
      0xe6, 0xd2, 0x91, 0x64, 0x45, 0x3b, 0x35, 0xda, 0xb1, 0x6f, 0x48, 0x36, 0x2f, 0x21, 0xc2, 0xab,
168
1.40M
      0x8c, 0x3e, 0x25, 0x22, 0x1c, 0xc2, 0xa8, 0x7c, 0x06, 0x00, 0x0a, 0xc9, 0xa7, 0x5f, 0x25, 0x00,
169
1.40M
      0x00, 0x00, 0xc4, 0x94, 0x75, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x6c, 0x40, 0x0f, 0x00, 0x00, 0x00,
170
1.40M
      0xcc, 0x7f, 0x56, 0x00, 0x00, 0x00, 0x9e, 0x72, 0x2e, 0x00, 0x00, 0x00, 0x00, 0xdb, 0xc7, 0x72,
171
1.40M
      0x00, 0x00, 0x00, 0x00, 0xb7, 0x89, 0x6b, 0x17, 0x10, 0x00, 0x16, 0xcc, 0xc0, 0x74, 0x17, 0x15,
172
1.40M
      0x12, 0xa1, 0x82, 0x59, 0x2a, 0x1b, 0x24, 0x11, 0xc8, 0xbc, 0x8d, 0x3b, 0x30, 0x2a, 0x2d, 0xc8,
173
1.40M
      0xbc, 0x92, 0x2b, 0x31, 0x2a, 0x27, 0xd6, 0xb7, 0x8f, 0x5e, 0x4a, 0x46, 0x3f, 0xe5, 0xda, 0xc0,
174
1.40M
      0x89, 0x76, 0x62, 0x45, 0xf6, 0xe8, 0xcc, 0xb0, 0x98, 0x7f, 0x51, 0xf7, 0xe6, 0xd1, 0xc4, 0xac,
175
1.40M
      0x98, 0x6e, 0xf9, 0xf4, 0xed, 0xec, 0xbb, 0x9f, 0x74, 0xfd, 0xf6, 0xf1, 0xe9, 0xbf, 0xa1, 0x8e,
176
1.40M
      0xd3, 0xb2, 0x96, 0x82, 0x5e, 0x33, 0xd6, 0xb5, 0xaa, 0x7c, 0x54, 0x43, 0x11, 0xc8, 0xac, 0x89,
177
1.40M
      0x65, 0x4b, 0x39, 0x13, 0xc8, 0xbc, 0x8d, 0x7f, 0x5d, 0x3a, 0x07, 0xcc, 0xb2, 0x8f, 0x78, 0x51,
178
1.40M
      0x28, 0x0f, 0xcc, 0xc3, 0x9a, 0x78, 0x3f, 0x26, 0x21, 0xd4, 0xbd, 0x8b, 0x69, 0x47, 0x2e, 0x22,
179
1.40M
      0x3a, 0x4f, 0x59, 0xa0, 0xad, 0xc8, 0xdd, 0x54, 0x7f, 0xa8, 0xe2, 0xea, 0xf7, 0xf7, 0x59, 0x6d,
180
1.40M
      0x83, 0xc2, 0xd6, 0xdb, 0xea, 0x4d, 0x9f, 0xc2, 0xe9, 0xe6, 0xf0, 0xf3, 0x3b, 0x5a, 0x68, 0xa5,
181
1.40M
      0xb1, 0xcc, 0xd6, 0x4f, 0x91, 0xc8, 0xdb, 0xef, 0xeb, 0xf5, 0x4e, 0x60, 0x70, 0xc5, 0xe8, 0xef,
182
1.40M
      0xf4, 0x3f, 0x59, 0x72, 0xc7, 0xd5, 0xe4, 0xf0, 0x42, 0x53, 0x60, 0xbc, 0xd2, 0xe9, 0xec, 0x48,
183
1.40M
      0x68, 0x80, 0xc2, 0xd3, 0xeb, 0xf7, 0x3b, 0x55, 0x62, 0xa6, 0xbc, 0xd5, 0xe7, 0x3c, 0x4e, 0x5b,
184
1.40M
      0x94, 0xba, 0xd2, 0xe2, 0x21, 0x2d, 0x3e, 0x8b, 0xad, 0xb9, 0xcc, 0x18, 0x0f, 0x0f, 0x65, 0x8c,
185
1.40M
      0xa9, 0xc3, 0x00, 0x09, 0x1f, 0x59, 0x81, 0x9f, 0xc3, 0x19, 0x18, 0x21, 0x69, 0x95, 0xa5, 0xb7,
186
1.40M
      0x1d, 0x27, 0x39, 0x74, 0x92, 0xc4, 0xe1, 0x1b, 0x16, 0x2b, 0x67, 0x93, 0xb6, 0xd1, 0x39, 0x4e,
187
1.40M
      0x56, 0xa6, 0xc8, 0xd5, 0xdd, 0x5a, 0x90, 0xa5, 0xd0, 0xdd, 0xe7, 0xe9, 0xff, 0xff, 0xff, 0xff,
188
1.40M
      0xce, 0x7c, 0x46, 0xff, 0xff, 0xf5, 0xf7, 0xc2, 0x86, 0x57, 0xff, 0xff, 0xff, 0xe6, 0xc2, 0x7d,
189
1.40M
      0x4d, 0xff, 0xff, 0xff, 0xde, 0xc6, 0x78, 0x4f, 0xca, 0xbc, 0x80, 0x59, 0x4c, 0x38, 0x2f, 0xbf,
190
1.40M
      0xae, 0x8a, 0x47, 0x3d, 0x35, 0x28, 0xcf, 0xa8, 0x6c, 0x51, 0x20, 0x1e, 0x9c, 0x8e, 0x6c, 0x33,
191
1.40M
      0x26, 0x1d, 0x17, 0xbc, 0x7c, 0x56, 0x21, 0x13, 0x00, 0x00, 0x9e, 0x72, 0x00, 0x0d, 0x00, 0x00,
192
1.40M
      0x00, 0xae, 0x7e, 0x50, 0x00, 0x00, 0x00, 0x00, 0xac, 0x7c, 0x5e, 0x00, 0x0a, 0x0c, 0x0d, 0x86,
193
1.40M
      0x70, 0x29, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x7c, 0x5c, 0x34, 0x30, 0x24, 0x11, 0xff, 0xfb, 0xf8,
194
1.40M
      0xe9, 0xab, 0x85, 0x59, 0x4f, 0x77, 0x8a, 0xbb, 0xbf, 0xca, 0xd6, 0x45, 0x7e, 0xa1, 0xbe, 0xc9,
195
1.40M
      0xc9, 0xd3, 0x4d, 0x6a, 0x92, 0xae, 0xbc, 0xc8, 0xd1, 0x43, 0x71, 0x92, 0xc6, 0xd5, 0xdb, 0xdd,
196
1.40M
      0x3f, 0x63, 0x8c, 0xba, 0xc0, 0xce, 0xd9, 0x2d, 0x44, 0x69, 0x90, 0xac, 0xc2, 0xd7, 0x1e, 0x3a,
197
1.40M
      0x42, 0x73, 0x9b, 0xb7, 0xcc, 0x06, 0x1b, 0x4d, 0x75, 0x9a, 0xb0, 0xc3, 0x00, 0x1a, 0x51, 0x89,
198
1.40M
      0xa2, 0xbc, 0xd1, 0x00, 0x18, 0x37, 0x77, 0x94, 0xad, 0xc8, 0x28, 0x4c, 0x6a, 0x7b, 0xa1, 0xaf,
199
1.40M
      0xc1, 0x17, 0x3a, 0x57, 0x90, 0xac, 0xc0, 0xd6, 0x34, 0x4a, 0x5d, 0x9e, 0xb1, 0xc9, 0xd8, 0x3f,
200
1.40M
      0x5d, 0x7e, 0xb1, 0xc8, 0xd5, 0xdd, 0x49, 0x71, 0xa5, 0xc4, 0xca, 0xd3, 0xda,
201
1.40M
    };
202
203
1.40M
    static const unsigned char WaldoColorType0_G[] =
204
1.40M
    {
205
1.40M
      0x00, 0xee, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x75, 0xa3, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
206
1.40M
      0x00, 0x00, 0x00, 0x00, 0xde, 0xd9, 0xad, 0x96, 0x78, 0x9b, 0x98, 0x7a, 0x6e, 0x58, 0x3c, 0xc9,
207
1.40M
      0xc6, 0xb5, 0xa6, 0x8e, 0x9b, 0x8d, 0x74, 0x5a, 0x4d, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208
1.40M
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209
1.40M
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
210
1.40M
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211
1.40M
      0x00, 0x00, 0x00, 0xff, 0xf6, 0xfb, 0xf4, 0xb0, 0x93, 0x60, 0xf3, 0xf4, 0xef, 0xed, 0xbd, 0x8b,
212
1.40M
      0x7e, 0xee, 0xef, 0xea, 0xd9, 0xa1, 0x85, 0x69, 0xed, 0xee, 0xe2, 0xd2, 0x98, 0x7f, 0x72, 0xe9,
213
1.40M
      0xea, 0xe0, 0xc7, 0x99, 0x6d, 0x4d, 0xe0, 0xd6, 0xc5, 0xac, 0x8b, 0x6c, 0x4e, 0xd5, 0xce, 0xb5,
214
1.40M
      0x83, 0x7e, 0x6f, 0x51, 0xd7, 0xca, 0xa7, 0x98, 0x7d, 0x65, 0x58, 0xe4, 0xd4, 0x9a, 0x7f, 0x58,
215
1.40M
      0x47, 0x35, 0xcb, 0xb0, 0x93, 0x75, 0x62, 0x54, 0x29, 0xc1, 0x9e, 0x85, 0x6d, 0x58, 0x3d, 0x29,
216
1.40M
      0xbd, 0x8e, 0x70, 0x42, 0x38, 0x2a, 0xc5, 0x8e, 0x76, 0x30, 0x22, 0x10, 0x10, 0xb2, 0x98, 0x59,
217
1.40M
      0x26, 0x24, 0x13, 0x18, 0xc3, 0xaa, 0x35, 0x17, 0x00, 0x18, 0x1d, 0xc0, 0x7d, 0x56, 0x07, 0x15,
218
1.40M
      0x0b, 0x10, 0xa8, 0x6d, 0x33, 0x10, 0x18, 0x15, 0x09, 0xce, 0x74, 0x1a, 0x00, 0x00, 0x00, 0x7a,
219
1.40M
      0x5d, 0x31, 0x00, 0x00, 0x00, 0x10, 0xba, 0x6c, 0x34, 0x00, 0x00, 0x00, 0xa1, 0x60, 0x3c, 0x00,
220
1.40M
      0x00, 0x00, 0x00, 0xd0, 0x95, 0x67, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x93, 0x35, 0x00, 0x00, 0x00,
221
1.40M
      0xb9, 0x9b, 0x45, 0x0a, 0x0f, 0x17, 0x1d, 0xc4, 0x8a, 0x2b, 0x12, 0x05, 0x0a, 0x05, 0xa6, 0x89,
222
1.40M
      0x6f, 0x1d, 0x07, 0x0c, 0x0d, 0xc9, 0xab, 0x89, 0x10, 0x0e, 0x0c, 0xd5, 0xb8, 0x74, 0x3f, 0x17,
223
1.40M
      0x00, 0x0e, 0xd5, 0xb0, 0x92, 0x00, 0x2a, 0x28, 0x1c, 0xb0, 0x97, 0x7f, 0x59, 0x40, 0x2f, 0x29,
224
1.40M
      0xea, 0xcd, 0xa9, 0x67, 0x42, 0x2f, 0xd7, 0xb7, 0x8a, 0x72, 0x62, 0x44, 0x29, 0xff, 0xf5, 0xd6,
225
1.40M
      0x96, 0x78, 0x6b, 0x4b, 0xdf, 0xd0, 0xb9, 0x84, 0x5f, 0x4f, 0x37, 0xf5, 0xf0, 0xe2, 0x85, 0x6e,
226
1.40M
      0x58, 0xe8, 0xce, 0xaa, 0x91, 0x6d, 0x5c, 0x41, 0xee, 0xf4, 0xee, 0xb2, 0x95, 0x6f, 0x4a, 0xf6,
227
1.40M
      0xff, 0xf5, 0xcb, 0x8b, 0x67, 0x47, 0xf0, 0xe3, 0xd4, 0xa2, 0x7d, 0x6c, 0x5c, 0xf4, 0xf1, 0xe7,
228
1.40M
      0xca, 0xa6, 0x80, 0x52, 0xff, 0xff, 0xe7, 0xde, 0xbd, 0x93, 0x57, 0xf6, 0xf1, 0xe0, 0xd6, 0xae,
229
1.40M
      0x96, 0x6b, 0xfa, 0xfa, 0xfa, 0xff, 0xbf, 0x99, 0x73, 0xf3, 0xf9, 0xf2, 0xf2, 0xba, 0x9b, 0x86,
230
1.40M
      0xc9, 0xa3, 0x8d, 0x7a, 0x58, 0x31, 0xca, 0xa6, 0x9c, 0x73, 0x4a, 0x3e, 0x0f, 0xc0, 0xa3, 0x86,
231
1.40M
      0x67, 0x4d, 0x3b, 0x13, 0xc3, 0xb7, 0x8b, 0x7d, 0x5b, 0x3a, 0x0b, 0xc7, 0xac, 0x8f, 0x78, 0x55,
232
1.40M
      0x2e, 0x10, 0xb0, 0xa4, 0x7b, 0x60, 0x2d, 0x1a, 0x1b, 0xd2, 0xbb, 0x8e, 0x6a, 0x48, 0x2e, 0x24,
233
1.40M
      0x31, 0x46, 0x4e, 0x8f, 0x9d, 0xba, 0xd8, 0x4b, 0x70, 0x8f, 0xd3, 0xe1, 0xef, 0xee, 0x45, 0x4f,
234
1.40M
      0x5a, 0xa0, 0xba, 0xc5, 0xd9, 0x35, 0x61, 0x6d, 0xa8, 0xb4, 0xcf, 0xd5, 0x29, 0x3d, 0x3e, 0x7f,
235
1.40M
      0x92, 0xab, 0xc4, 0x30, 0x41, 0x3f, 0x92, 0xab, 0xb2, 0xcf, 0x2b, 0x27, 0x22, 0x70, 0x9b, 0xb5,
236
1.40M
      0xca, 0x29, 0x33, 0x3c, 0x80, 0x98, 0xb1, 0xcd, 0x1f, 0x21, 0x29, 0x6c, 0x83, 0xa6, 0xb8, 0x26,
237
1.40M
      0x2f, 0x2e, 0x6a, 0x8b, 0xa5, 0xc7, 0x1d, 0x29, 0x29, 0x72, 0x8d, 0xaa, 0xc7, 0x20, 0x20, 0x1c,
238
1.40M
      0x62, 0x86, 0xa2, 0xc5, 0x1e, 0x23, 0x37, 0x80, 0x9e, 0xaf, 0xc8, 0x23, 0x2d, 0x33, 0x7b, 0x9b,
239
1.40M
      0xb1, 0xcd, 0x1b, 0x31, 0x47, 0x7a, 0x9c, 0xab, 0xcf, 0x2b, 0x3e, 0x4e, 0x86, 0xa6, 0xb1, 0xc5,
240
1.40M
      0x30, 0x50, 0x6c, 0xa1, 0xb4, 0xdd, 0xf6, 0x38, 0x4f, 0x6c, 0xa6, 0xc7, 0xd9, 0xe8, 0x41, 0x62,
241
1.40M
      0x77, 0xbe, 0xd8, 0xde, 0xe4, 0x56, 0x91, 0xae, 0xda, 0xe3, 0xec, 0xef, 0xd1, 0xcd, 0xb6, 0x9c,
242
1.40M
      0x85, 0x5a, 0x34, 0xcc, 0xa9, 0x85, 0x78, 0x63, 0x4e, 0x31, 0xb6, 0xa5, 0x83, 0x60, 0x56, 0x3b,
243
1.40M
      0x27, 0xa7, 0x88, 0x63, 0x2c, 0x2d, 0x19, 0x18, 0x61, 0x39, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x6b,
244
1.40M
      0x3d, 0x20, 0x00, 0x00, 0x00, 0x00, 0x99, 0x4e, 0x0f, 0x00, 0x00, 0x12, 0x79, 0x74, 0x22, 0x00,
245
1.40M
      0x00, 0x00, 0x00, 0xd5, 0xac, 0x9a, 0x76, 0x52, 0x39, 0x25, 0xd7, 0xb4, 0x92, 0x76, 0x68, 0x47,
246
1.40M
      0x35, 0xe9, 0xe3, 0xc3, 0x94, 0x78, 0x51, 0x32, 0xdf, 0xd0, 0xb9, 0x91, 0x71, 0x5b, 0x37, 0xd6,
247
1.40M
      0xcd, 0xa8, 0x8a, 0x6e, 0x57, 0x2e, 0xe9, 0xe5, 0xd4, 0xa5, 0x80, 0x5c, 0x38, 0xff, 0xfe, 0xfa,
248
1.40M
      0xec, 0xa2, 0x81, 0x56, 0x42, 0x69, 0x7c, 0xab, 0xb0, 0xc4, 0xd1, 0x2a, 0x59, 0x7a, 0x96, 0xa9,
249
1.40M
      0xac, 0xba, 0x2b, 0x3e, 0x6e, 0x84, 0x95, 0xac, 0xb7, 0x2d, 0x43, 0x60, 0x94, 0xa4, 0xc2, 0xcc,
250
1.40M
      0x18, 0x2e, 0x56, 0x89, 0x9a, 0xb1, 0xc8, 0x1b, 0x29, 0x48, 0x72, 0x8d, 0xaa, 0xc7, 0x00, 0x20,
251
1.40M
      0x1c, 0x5c, 0x84, 0xa4, 0xc3, 0x1c, 0x33, 0x5f, 0x80, 0x9e, 0xaf, 0xc8, 0x25, 0x47, 0x74, 0x9f,
252
1.40M
      0xb4, 0xca, 0xdc, 0x1b, 0x39, 0x53, 0x87, 0xa0, 0xb4, 0xd0, 0x38, 0x64, 0x83, 0x8f, 0xad, 0xb9,
253
1.40M
      0xcc, 0x27, 0x50, 0x69, 0x9d, 0xb1, 0xcc, 0xde, 0x3d, 0x57, 0x6c, 0xa1, 0xb0, 0xcb, 0xd9, 0x45,
254
1.40M
      0x66, 0x87, 0xb2, 0xcc, 0xd9, 0xde, 0x4a, 0x74, 0xa0, 0xc0, 0xc7, 0xd0, 0xd7,
255
1.40M
    };
256
257
1.40M
    static const unsigned char WaldoColorType0_B[] =
258
1.40M
    {
259
1.40M
      0x00, 0x00, 0x16, 0x6a, 0x8e, 0x89, 0x87, 0xad, 0x6e, 0x02, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00,
260
1.40M
      0x00, 0x00, 0x00, 0x00, 0xc5, 0xc7, 0xa4, 0x8d, 0x72, 0x8f, 0x8d, 0x74, 0x6b, 0x57, 0x3e, 0xb5,
261
1.40M
      0xba, 0xb2, 0xa6, 0x92, 0x98, 0x90, 0x7e, 0x68, 0x5c, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262
1.40M
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263
1.40M
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264
1.40M
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265
1.40M
      0x00, 0x00, 0x00, 0xff, 0x81, 0x6b, 0x00, 0x0a, 0x00, 0x00, 0x7a, 0x6b, 0x5e, 0x2f, 0x11, 0x00,
266
1.40M
      0x00, 0x7a, 0x6a, 0x57, 0x00, 0x00, 0x0d, 0x0f, 0x7a, 0x76, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x7a,
267
1.40M
      0x78, 0x1a, 0x00, 0x00, 0x00, 0x05, 0x72, 0x5f, 0x1a, 0x00, 0x00, 0x00, 0x09, 0x61, 0x4c, 0x2b,
268
1.40M
      0x00, 0x00, 0x00, 0x01, 0x88, 0x74, 0x19, 0x00, 0x00, 0x00, 0x00, 0xa3, 0x83, 0x4c, 0x2e, 0x2a,
269
1.40M
      0x02, 0x06, 0x8b, 0x73, 0x51, 0x00, 0x00, 0x05, 0x0d, 0x98, 0x7c, 0x5d, 0x0d, 0x02, 0x07, 0x04,
270
1.40M
      0xab, 0x83, 0x61, 0x30, 0x25, 0x23, 0xba, 0x9e, 0x8e, 0x4f, 0x3a, 0x19, 0x10, 0xb1, 0xa9, 0x78,
271
1.40M
      0x54, 0x47, 0x33, 0x2e, 0xbd, 0xb1, 0x6a, 0x43, 0x34, 0x39, 0x1f, 0xc3, 0xa2, 0x86, 0x55, 0x49,
272
1.40M
      0x34, 0x30, 0xb9, 0x9c, 0x81, 0x63, 0x5b, 0x44, 0x30, 0xdf, 0xb1, 0x88, 0x56, 0x49, 0x31, 0xc5,
273
1.40M
      0xac, 0x98, 0x81, 0x5e, 0x46, 0x36, 0xd4, 0xb2, 0x9e, 0x7b, 0x59, 0x40, 0xd8, 0xc6, 0xa5, 0x89,
274
1.40M
      0x71, 0x5d, 0x3c, 0xed, 0xc5, 0xc2, 0x8a, 0x7c, 0x6e, 0x4d, 0xee, 0xff, 0xbe, 0x74, 0x58, 0x47,
275
1.40M
      0xd3, 0xc6, 0xa5, 0x7f, 0x56, 0x4e, 0x4a, 0xde, 0xd0, 0xb1, 0x8a, 0x70, 0x5e, 0x4d, 0xcc, 0xc4,
276
1.40M
      0xba, 0x88, 0x65, 0x57, 0x45, 0xdc, 0xdd, 0xc4, 0x6a, 0x4f, 0x44, 0xf0, 0xdf, 0xe2, 0xb6, 0x69,
277
1.40M
      0x67, 0x44, 0xe5, 0xdc, 0xc7, 0xb4, 0x7f, 0x6c, 0x48, 0xc9, 0xb8, 0xb3, 0xa0, 0x85, 0x5d, 0x4d,
278
1.40M
      0xe4, 0xe1, 0xc7, 0x95, 0x61, 0x4e, 0xd2, 0xc1, 0xa1, 0x91, 0x81, 0x5f, 0x3c, 0xe4, 0xdf, 0xc1,
279
1.40M
      0x96, 0x7d, 0x71, 0x55, 0xc2, 0xb0, 0xa1, 0x79, 0x5e, 0x50, 0x3f, 0xc2, 0xbe, 0xa3, 0x5c, 0x54,
280
1.40M
      0x4b, 0xb1, 0x9d, 0x80, 0x67, 0x52, 0x4a, 0x3d, 0xa5, 0xa2, 0x88, 0x53, 0x40, 0x36, 0x1f, 0xa6,
281
1.40M
      0xa0, 0x8f, 0x4c, 0x40, 0x39, 0x30, 0x94, 0x6f, 0x4e, 0x23, 0x22, 0x18, 0x12, 0x91, 0x73, 0x52,
282
1.40M
      0x03, 0x00, 0x00, 0x0a, 0x74, 0x6c, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x66, 0x57, 0x22, 0x00, 0x00,
283
1.40M
      0x00, 0x00, 0x7e, 0x62, 0x37, 0x0d, 0x00, 0x00, 0x00, 0x78, 0x4f, 0x20, 0x00, 0x00, 0x00, 0x03,
284
1.40M
      0xaf, 0x90, 0x80, 0x6d, 0x54, 0x2e, 0xb5, 0x9a, 0x97, 0x71, 0x48, 0x44, 0x0a, 0xa6, 0x96, 0x7d,
285
1.40M
      0x64, 0x4b, 0x3b, 0x17, 0xbb, 0xb8, 0x92, 0x82, 0x60, 0x48, 0x1c, 0xbb, 0xb0, 0x99, 0x82, 0x67,
286
1.40M
      0x48, 0x20, 0xa6, 0x9d, 0x7f, 0x6a, 0x3d, 0x25, 0x22, 0xc6, 0xb8, 0x91, 0x6d, 0x50, 0x3b, 0x22,
287
1.40M
      0x16, 0x3a, 0x2d, 0x72, 0x86, 0x95, 0xad, 0x25, 0x19, 0x2f, 0x60, 0x71, 0x83, 0x98, 0x35, 0x2b,
288
1.40M
      0x35, 0x75, 0x8a, 0x8e, 0xa3, 0x22, 0x2e, 0x21, 0x72, 0x80, 0x99, 0x9e, 0x2d, 0x3b, 0x3b, 0x6f,
289
1.40M
      0x86, 0x97, 0xaf, 0x20, 0x20, 0x31, 0x79, 0x8d, 0x98, 0xb0, 0x33, 0x32, 0x37, 0x7d, 0x9e, 0xb1,
290
1.40M
      0xb6, 0x1b, 0x31, 0x38, 0x7e, 0x90, 0xa5, 0xb9, 0x31, 0x38, 0x44, 0x83, 0x90, 0xa9, 0xb8, 0x4a,
291
1.40M
      0x6f, 0x83, 0xa9, 0xb4, 0xc2, 0xcf, 0x3e, 0x61, 0x6f, 0x9a, 0xa6, 0xb9, 0xce, 0x56, 0x77, 0x8b,
292
1.40M
      0xa8, 0xc1, 0xcd, 0xe1, 0x3c, 0x4e, 0x6b, 0x99, 0xb5, 0xc2, 0xd0, 0x4c, 0x67, 0x7c, 0xab, 0xbc,
293
1.40M
      0xc6, 0xdc, 0x39, 0x51, 0x69, 0x96, 0xac, 0xb3, 0xcd, 0x00, 0x00, 0x27, 0x6d, 0x90, 0x9a, 0xaa,
294
1.40M
      0x27, 0x46, 0x5d, 0x85, 0x99, 0xbe, 0xd7, 0x2d, 0x3b, 0x55, 0x84, 0x9e, 0xb2, 0xc1, 0x00, 0x00,
295
1.40M
      0x00, 0x64, 0x85, 0x87, 0x9a, 0x00, 0x00, 0x00, 0x5b, 0x65, 0x73, 0x8d, 0x70, 0x64, 0x15, 0x00,
296
1.40M
      0x00, 0x00, 0x00, 0x8f, 0x63, 0x32, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x7b, 0x4f, 0x00, 0x00, 0x00,
297
1.40M
      0x00, 0xa5, 0x8f, 0x75, 0x1a, 0x37, 0x15, 0x18, 0xff, 0xff, 0xbe, 0x89, 0x74, 0x58, 0x4e, 0xff,
298
1.40M
      0xff, 0xdb, 0x80, 0x70, 0x63, 0x52, 0xff, 0xff, 0xc0, 0xa0, 0x5f, 0x4c, 0xcc, 0xcc, 0xcf, 0x8e,
299
1.40M
      0x6f, 0x57, 0x45, 0xda, 0xd1, 0xc9, 0xc1, 0x8a, 0x5d, 0x40, 0xca, 0xb6, 0xa1, 0x8b, 0x7c, 0x5b,
300
1.40M
      0x48, 0xc3, 0xb7, 0x9e, 0x7c, 0x6c, 0x4f, 0x38, 0xb7, 0xa6, 0x96, 0x76, 0x60, 0x51, 0x32, 0xb0,
301
1.40M
      0xa6, 0x89, 0x6e, 0x5c, 0x49, 0x26, 0xa7, 0x95, 0x81, 0x62, 0x57, 0x44, 0x23, 0x78, 0x4f, 0x20,
302
1.40M
      0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x3e, 0x7e, 0x84, 0x9b, 0xa9, 0x00, 0x43, 0x62, 0x75, 0x8c,
303
1.40M
      0x91, 0x9c, 0x32, 0x3e, 0x66, 0x74, 0x80, 0x99, 0x9e, 0x3a, 0x55, 0x6d, 0x9a, 0xa7, 0xb9, 0xc3,
304
1.40M
      0x4a, 0x6f, 0x91, 0xad, 0xb3, 0xc2, 0xcd, 0x3e, 0x52, 0x70, 0x8b, 0x9f, 0xb3, 0xc6, 0x4b, 0x77,
305
1.40M
      0x8b, 0xac, 0xc1, 0xcd, 0xe1, 0x50, 0x65, 0x85, 0x9c, 0xb8, 0xc5, 0xd4, 0x3e, 0x5b, 0x83, 0xa3,
306
1.40M
      0xb4, 0xc2, 0xd0, 0x31, 0x4c, 0x63, 0x8c, 0xa0, 0xb0, 0xc7, 0x40, 0x5c, 0x77, 0x82, 0x9f, 0xa8,
307
1.40M
      0xb7, 0x21, 0x4d, 0x63, 0x91, 0xa2, 0xb5, 0xc8, 0x29, 0x35, 0x3d, 0x75, 0x7e, 0xa2, 0xae, 0x11,
308
1.40M
      0x00, 0x46, 0x73, 0x91, 0xa2, 0xad, 0x2a, 0x3d, 0x69, 0x7d, 0x85, 0x8f, 0xa3,
309
1.40M
    };
310
311
1.40M
    auto pantoneIndex = (unsigned short)(((int)col1 << 8) | (int)col0);
312
1.40M
    double pantoneSaturation = (double)(((unsigned short)col3 << 8) | (unsigned short)col2) / 100.0;
313
1.40M
    typedef struct
314
1.40M
    {
315
1.40M
      unsigned char r;
316
1.40M
      unsigned char g;
317
1.40M
      unsigned char b;
318
1.40M
    } RGBColor;
319
1.40M
    RGBColor pureColor = { 0, 0, 0 };
320
1.40M
    if (pantoneIndex < sizeof(WaldoColorType0_R)/sizeof(WaldoColorType0_R[0])
321
1.23M
        && pantoneIndex < sizeof(WaldoColorType0_G)/sizeof(WaldoColorType0_G[0])
322
1.23M
        && pantoneIndex < sizeof(WaldoColorType0_B)/sizeof(WaldoColorType0_B[0]))
323
1.23M
    {
324
1.23M
      pureColor.r = WaldoColorType0_R[pantoneIndex];
325
1.23M
      pureColor.g = WaldoColorType0_G[pantoneIndex];
326
1.23M
      pureColor.b = WaldoColorType0_B[pantoneIndex];
327
1.23M
    }
328
1.40M
    auto tmpRed = (unsigned)cdr_round(255.0*(1-pantoneSaturation) + (double)pureColor.r*pantoneSaturation);
329
1.40M
    auto tmpGreen = (unsigned)cdr_round(255.0*(1-pantoneSaturation) + (double)pureColor.g*pantoneSaturation);
330
1.40M
    auto tmpBlue = (unsigned)cdr_round(255.0*(1-pantoneSaturation) + (double)pureColor.b*pantoneSaturation);
331
1.40M
    red = (tmpRed < 255 ? (unsigned char)tmpRed : 255);
332
1.40M
    green = (tmpGreen < 255 ? (unsigned char)tmpGreen : 255);
333
1.40M
    blue = (tmpBlue < 255 ? (unsigned char)tmpBlue : 255);
334
1.40M
    break;
335
0
  }
336
  // CMYK 100
337
28.7k
  case 0x01:
338
74.9k
  case 0x02:
339
75.7k
  case 0x15:
340
75.7k
  {
341
75.7k
    double cmyk[4] =
342
75.7k
    {
343
75.7k
      (double)col0,
344
75.7k
      (double)col1,
345
75.7k
      (double)col2,
346
75.7k
      (double)col3
347
75.7k
    };
348
75.7k
    unsigned char rgb[3] = { 0, 0, 0 };
349
75.7k
    cmsDoTransform(m_colorTransformCMYK2RGB, cmyk, rgb, 1);
350
75.7k
    red = rgb[0];
351
75.7k
    green = rgb[1];
352
75.7k
    blue = rgb[2];
353
75.7k
    break;
354
74.9k
  }
355
  // CMYK 255
356
81.3k
  case 0x03:
357
82.2k
  case 0x11:
358
82.2k
  {
359
82.2k
    double cmyk[4] =
360
82.2k
    {
361
82.2k
      (double)col0*100.0/255.0,
362
82.2k
      (double)col1*100.0/255.0,
363
82.2k
      (double)col2*100.0/255.0,
364
82.2k
      (double)col3*100.0/255.0
365
82.2k
    };
366
82.2k
    unsigned char rgb[3] = { 0, 0, 0 };
367
82.2k
    cmsDoTransform(m_colorTransformCMYK2RGB, cmyk, rgb, 1);
368
82.2k
    red = rgb[0];
369
82.2k
    green = rgb[1];
370
82.2k
    blue = rgb[2];
371
82.2k
    break;
372
81.3k
  }
373
  // CMY
374
5.27k
  case 0x04:
375
5.27k
  {
376
5.27k
    red = 255 - col0;
377
5.27k
    green = 255 - col1;
378
5.27k
    blue = 255 - col2;
379
5.27k
    break;
380
81.3k
  }
381
  // RGB
382
1.45M
  case 0x05:
383
1.45M
  {
384
1.45M
    unsigned char input[3] = { col2, col1, col0 };
385
1.45M
    unsigned char output[3] = { 0, 0, 0 };
386
1.45M
    cmsDoTransform(m_colorTransformRGB2RGB, input, output, 1);
387
1.45M
    red = output[0];
388
1.45M
    green = output[1];
389
1.45M
    blue = output[2];
390
1.45M
    break;
391
81.3k
  }
392
  // HSB
393
7.02k
  case 0x06:
394
7.02k
  {
395
7.02k
    auto hue = (unsigned short)(((int)col1<<8) | col0);
396
7.02k
    double saturation = (double)col2/255.0;
397
7.02k
    double brightness = (double)col3/255.0;
398
399
342k
    while (hue > 360)
400
335k
      hue -= 360;
401
402
7.02k
    double satRed, satGreen, satBlue;
403
404
7.02k
    if (hue < 120)
405
3.30k
    {
406
3.30k
      satRed = (double)(120 - hue) / 60.0;
407
3.30k
      satGreen = (double)hue / 60.0;
408
3.30k
      satBlue = 0;
409
3.30k
    }
410
3.72k
    else if (hue < 240)
411
2.71k
    {
412
2.71k
      satRed = 0;
413
2.71k
      satGreen = (double)(240 - hue) / 60.0;
414
2.71k
      satBlue = (double)(hue - 120) / 60.0;
415
2.71k
    }
416
1.00k
    else
417
1.00k
    {
418
1.00k
      satRed = (double)(hue - 240) / 60.0;
419
1.00k
      satGreen = 0.0;
420
1.00k
      satBlue = (double)(360 - hue) / 60.0;
421
1.00k
    }
422
7.02k
    red = (unsigned char)cdr_round(255*(1 - saturation + saturation * (satRed > 1 ? 1 : satRed)) * brightness);
423
7.02k
    green = (unsigned char)cdr_round(255*(1 - saturation + saturation * (satGreen > 1 ? 1 : satGreen)) * brightness);
424
7.02k
    blue = (unsigned char)cdr_round(255*(1 - saturation + saturation * (satBlue > 1 ? 1 : satBlue)) * brightness);
425
7.02k
    break;
426
81.3k
  }
427
  // HLS
428
26.6k
  case 0x07:
429
26.6k
  {
430
26.6k
    auto hue = (unsigned short)(((int)col1<<8) | col0);
431
26.6k
    double lightness = (double)col2/255.0;
432
26.6k
    double saturation = (double)col3/255.0;
433
434
543k
    while (hue > 360)
435
517k
      hue -= 360;
436
437
26.6k
    double satRed, satGreen, satBlue;
438
439
26.6k
    if (hue < 120)
440
22.8k
    {
441
22.8k
      satRed = (double)(120 - hue) / 60.0;
442
22.8k
      satGreen = (double)hue/60.0;
443
22.8k
      satBlue = 0.0;
444
22.8k
    }
445
3.88k
    else if (hue < 240)
446
2.26k
    {
447
2.26k
      satRed = 0;
448
2.26k
      satGreen = (double)(240 - hue) / 60.0;
449
2.26k
      satBlue = (double)(hue - 120) / 60.0;
450
2.26k
    }
451
1.62k
    else
452
1.62k
    {
453
1.62k
      satRed = (double)(hue - 240) / 60.0;
454
1.62k
      satGreen = 0;
455
1.62k
      satBlue = (double)(360 - hue) / 60.0;
456
1.62k
    }
457
458
26.6k
    double tmpRed = 2*saturation*(satRed > 1 ? 1 : satRed) + 1 - saturation;
459
26.6k
    double tmpGreen = 2*saturation*(satGreen > 1 ? 1 : satGreen) + 1 - saturation;
460
26.6k
    double tmpBlue = 2*saturation*(satBlue > 1 ? 1 : satBlue) + 1 - saturation;
461
462
26.6k
    if (lightness < 0.5)
463
25.1k
    {
464
25.1k
      red = (unsigned char)cdr_round(255.0*lightness*tmpRed);
465
25.1k
      green = (unsigned char)cdr_round(255.0*lightness*tmpGreen);
466
25.1k
      blue = (unsigned char)cdr_round(255.0*lightness*tmpBlue);
467
25.1k
    }
468
1.58k
    else
469
1.58k
    {
470
1.58k
      red = (unsigned char)cdr_round(255*((1 - lightness) * tmpRed + 2 * lightness - 1));
471
1.58k
      green = (unsigned char)cdr_round(255*((1 - lightness) * tmpGreen + 2 * lightness - 1));
472
1.58k
      blue = (unsigned char)cdr_round(255*((1 - lightness) * tmpBlue + 2 * lightness - 1));
473
1.58k
    }
474
26.6k
    break;
475
81.3k
  }
476
  // BW
477
5.79k
  case 0x08:
478
5.79k
  {
479
5.79k
    red = col0 ? 0 : 0xff;
480
5.79k
    green = col0 ? 0 : 0xff;
481
5.79k
    blue = col0 ? 0 : 0xff;
482
5.79k
    break;
483
81.3k
  }
484
  // Grayscale
485
14.0k
  case 0x09:
486
14.0k
  {
487
14.0k
    red = col0;
488
14.0k
    green = col0;
489
14.0k
    blue = col0;
490
14.0k
    break;
491
81.3k
  }
492
  // YIQ255
493
2.07k
  case 0x0b:
494
2.07k
  {
495
2.07k
    auto y = (double)col0;
496
2.07k
    auto i = (double)col1;
497
2.07k
    auto q = (double)col2;
498
499
2.07k
    y -= 100.0;
500
2.07k
    if (y < 0.0)
501
1.36k
      y /= 100.0;
502
702
    else
503
702
      y /= 155.0;
504
2.07k
    y *= 0.5;
505
2.07k
    y += 0.5;
506
507
2.07k
    i -= 100.0;
508
2.07k
    if (i <= 0.0)
509
1.24k
      i /= 100.0;
510
821
    else
511
821
      i /= 155;
512
2.07k
    i *= 0.5957;
513
514
2.07k
    q -= 100.0;
515
2.07k
    if (q <= 0)
516
1.42k
      q /= 100.0;
517
647
    else
518
647
      q /= 155;
519
2.07k
    q *= 0.5226;
520
521
2.07k
    double RR = y + 0.9563*i + 0.6210*q;
522
2.07k
    double GG = y - 0.2127*i - 0.6474*q;
523
2.07k
    double BB = y - 1.1070*i + 1.7046*q;
524
2.07k
    if (RR > 1.0)
525
134
      RR = 1.0;
526
2.07k
    if (RR < 0.0)
527
1.16k
      RR = 0.0;
528
2.07k
    if (GG > 1.0)
529
60
      GG = 1.0;
530
2.07k
    if (GG < 0.0)
531
188
      GG = 0.0;
532
2.07k
    if (BB > 1.0)
533
63
      BB = 1.0;
534
2.07k
    if (BB < 0.0)
535
1.10k
      BB = 0.0;
536
2.07k
    red = (unsigned char)cdr_round(255*RR);
537
2.07k
    green = (unsigned char)cdr_round(255*GG);
538
2.07k
    blue = (unsigned char)cdr_round(255*BB);
539
2.07k
    break;
540
81.3k
  }
541
  // Lab
542
1.02k
  case 0x0c:
543
1.02k
  {
544
1.02k
    cmsCIELab Lab;
545
1.02k
    Lab.L = (double)col0*100.0/255.0;
546
1.02k
    Lab.a = (double)(signed char)col1;
547
1.02k
    Lab.b = (double)(signed char)col2;
548
1.02k
    unsigned char rgb[3] = { 0, 0, 0 };
549
1.02k
    cmsDoTransform(m_colorTransformLab2RGB, &Lab, rgb, 1);
550
1.02k
    red = rgb[0];
551
1.02k
    green = rgb[1];
552
1.02k
    blue = rgb[2];
553
1.02k
    break;
554
81.3k
  }
555
  // Lab
556
47.3k
  case 0x12:
557
47.3k
  {
558
47.3k
    cmsCIELab Lab;
559
47.3k
    Lab.L = (double)col0*100.0/255.0;
560
47.3k
    Lab.a = (double)((signed char)(col1 - 0x80));
561
47.3k
    Lab.b = (double)((signed char)(col2 - 0x80));
562
47.3k
    unsigned char rgb[3] = { 0, 0, 0 };
563
47.3k
    cmsDoTransform(m_colorTransformLab2RGB, &Lab, rgb, 1);
564
47.3k
    red = rgb[0];
565
47.3k
    green = rgb[1];
566
47.3k
    blue = rgb[2];
567
47.3k
    break;
568
81.3k
  }
569
  // Registration colour
570
1.96k
  case 0x14:
571
1.96k
  {
572
1.96k
    red = (unsigned char)cdr_round(255.0 * col0 / 100.0);
573
1.96k
    green = (unsigned char)cdr_round(255.0 * col0 / 100.0);
574
1.96k
    blue = (unsigned char)cdr_round(255.0 * col0 / 100.0);
575
1.96k
    break;
576
81.3k
  }
577
578
481k
  default:
579
481k
    break;
580
3.61M
  }
581
3.61M
  return (unsigned)((red << 16) | (green << 8) | blue);
582
3.61M
}
583
584
librevenge::RVNGString libcdr::CDRParserState::getRGBColorString(const libcdr::CDRColor &color)
585
1.73M
{
586
1.73M
  librevenge::RVNGString tempString;
587
1.73M
  tempString.sprintf("#%.6x", _getRGBColor(color));
588
1.73M
  return tempString;
589
1.73M
}
590
591
void libcdr::CDRParserState::getRecursedStyle(CDRStyle &style, unsigned styleId)
592
31.9k
{
593
31.9k
  std::map<unsigned, CDRStyle>::const_iterator iter = m_styles.find(styleId);
594
31.9k
  if (iter == m_styles.end())
595
28.9k
    return;
596
597
3.01k
  std::stack<CDRStyle> styleStack;
598
3.01k
  styleStack.push(iter->second);
599
3.01k
  if (iter->second.m_parentId)
600
2.59k
  {
601
2.59k
    std::map<unsigned, CDRStyle>::const_iterator iter2 = m_styles.find(iter->second.m_parentId);
602
4.54k
    while (iter2 != m_styles.end())
603
1.95k
    {
604
1.95k
      styleStack.push(iter2->second);
605
1.95k
      if (iter2->second.m_parentId)
606
47
        iter2 = m_styles.find(iter2->second.m_parentId);
607
1.90k
      else
608
1.90k
        iter2 = m_styles.end();
609
1.95k
    }
610
2.59k
  }
611
7.97k
  while (!styleStack.empty())
612
4.96k
  {
613
4.96k
    style.overrideStyle(styleStack.top());
614
4.96k
    styleStack.pop();
615
4.96k
  }
616
3.01k
}
617
618
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */