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