Rev 3490 | Rev 4535 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
2886 | fschmid | 7 | /*************************************************************************** |
8 | sccolor.cpp - description |
||
9 | ------------------- |
||
10 | begin : Sun Sep 9 2001 |
||
11 | copyright : (C) 2001 by Franz Schmid |
||
12 | email : Franz.Schmid@altmuehlnet.de |
||
13 | ***************************************************************************/ |
||
14 | |||
15 | /*************************************************************************** |
||
16 | * * |
||
17 | * This program is free software; you can redistribute it and/or modify * |
||
18 | * it under the terms of the GNU General Public License as published by * |
||
19 | * the Free Software Foundation; either version 2 of the License, or * |
||
20 | * (at your option) any later version. * |
||
21 | * * |
||
22 | ***************************************************************************/ |
||
23 | |||
24 | #include <qcolor.h> |
||
25 | #include <qstring.h> |
||
26 | |||
27 | #include "sccolor.h" |
||
28 | |||
29 | #include "scconfig.h" |
||
30 | |||
31 | #ifdef HAVE_CMS |
||
32 | #include CMS_INC |
||
33 | extern cmsHTRANSFORM stdTransG; |
||
34 | extern cmsHTRANSFORM stdProofG; |
||
35 | extern cmsHTRANSFORM stdTransCMYKG; |
||
36 | extern cmsHTRANSFORM stdProofCMYKG; |
||
37 | extern cmsHTRANSFORM stdTransRGBG; |
||
3046 | fschmid | 38 | extern cmsHTRANSFORM stdProofGCG; |
39 | extern cmsHTRANSFORM stdProofCMYKGCG; |
||
2886 | fschmid | 40 | extern bool SoftProofing; |
41 | extern bool CMSuse; |
||
42 | #endif |
||
43 | extern bool CMSavail; |
||
44 | bool ScColor::UseProf = true; |
||
45 | |||
46 | ScColor::ScColor() |
||
47 | { |
||
3490 | avox | 48 | // setColor(0, 0, 0, 0); |
49 | Model = colorModelCMYK; |
||
50 | C = M = Y = K = 0; |
||
51 | R = G = B = 255; |
||
52 | RGB = Qt::white; |
||
53 | |||
2886 | fschmid | 54 | Spot = false; |
3041 | fschmid | 55 | outOfGamutFlag = false; |
3060 | fschmid | 56 | Regist = false; |
2886 | fschmid | 57 | } |
58 | |||
59 | ScColor::ScColor(int c, int m, int y, int k) |
||
60 | { |
||
61 | setColor(c, m, y, k); |
||
62 | Spot = false; |
||
3041 | fschmid | 63 | outOfGamutFlag = false; |
3060 | fschmid | 64 | Regist = false; |
2886 | fschmid | 65 | } |
66 | |||
67 | ScColor::ScColor(int r, int g, int b) |
||
68 | { |
||
69 | setColorRGB(r, g, b); |
||
70 | Spot = false; |
||
3041 | fschmid | 71 | outOfGamutFlag = false; |
3060 | fschmid | 72 | Regist = false; |
2886 | fschmid | 73 | } |
74 | |||
75 | void ScColor::setColor(int c, int m, int y, int k) |
||
76 | { |
||
77 | C = c; |
||
78 | M = m; |
||
79 | Y = y; |
||
80 | K = k; |
||
81 | Model = colorModelCMYK; |
||
82 | RecalcRGB(); |
||
83 | } |
||
84 | |||
85 | void ScColor::setColorRGB(int r, int g, int b) |
||
86 | { |
||
87 | R = r; |
||
88 | G = g; |
||
89 | B = b; |
||
90 | Model = colorModelRGB; |
||
91 | RecalcRGB(); |
||
92 | } |
||
93 | |||
94 | void ScColor::setColorModel (colorModel cm) |
||
95 | { |
||
96 | Model = cm; |
||
97 | RecalcRGB(); |
||
98 | } |
||
99 | |||
100 | colorModel ScColor::getColorModel () |
||
101 | { |
||
102 | return Model; |
||
103 | } |
||
104 | |||
105 | void ScColor::fromQColor(QColor color) |
||
106 | { |
||
107 | int r, g, b; |
||
108 | color.rgb(&r, &g, &b); |
||
109 | setColorRGB(r, g, b); |
||
110 | } |
||
111 | |||
112 | QColor ScColor::getRGBColor() |
||
113 | { |
||
114 | return RGB; |
||
115 | } |
||
116 | |||
117 | void ScColor::getShadeColorCMYK(int *c, int *m, int *y, int *k, int level) |
||
118 | { |
||
119 | if (Model == colorModelRGB) |
||
120 | { |
||
121 | int r, g, b; |
||
122 | ScColor tmpR; |
||
123 | getShadeColorRGB(&r, &g, &b, level); |
||
124 | tmpR.setColorRGB(r, g, b); |
||
125 | tmpR.getCMYK(c, m, y, k); |
||
126 | } |
||
127 | else |
||
128 | { |
||
129 | *c = C * level / 100; |
||
130 | *m = M * level / 100; |
||
131 | *y = Y * level / 100; |
||
132 | *k = K * level / 100; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | void ScColor::getShadeColorRGB(int *r, int *g, int *b, int level) |
||
137 | { |
||
138 | int h, s, v, snew; |
||
139 | |||
140 | if (Model == colorModelCMYK) |
||
141 | { |
||
142 | int c, m, y, k; |
||
143 | getShadeColorCMYK(&c, &m, &y, &k, level); |
||
144 | ScColor tmpC(c, m, y, k); |
||
145 | tmpC.getRGB(r, g, b); |
||
146 | } |
||
147 | else |
||
148 | { |
||
149 | QColor tmpR(R, G, B); |
||
150 | tmpR.hsv(&h, &s, &v); |
||
151 | |||
152 | if (R == G && G == B) |
||
153 | { |
||
154 | snew = 255 - ((255 - v) * level / 100); |
||
155 | tmpR.setHsv(h, s, snew); |
||
156 | } |
||
157 | else |
||
158 | { |
||
159 | snew = s * level / 100; |
||
160 | tmpR.setHsv(h, snew, v); |
||
161 | } |
||
162 | |||
163 | tmpR.getRgb(r, g, b); |
||
164 | } |
||
165 | } |
||
166 | |||
167 | QColor ScColor::getShadeColorProof(int level) |
||
168 | { |
||
169 | QColor tmp; |
||
170 | ScColor tmp2; |
||
171 | int r, g, b, c, m ,y, k; |
||
172 | |||
173 | if (Model == colorModelRGB) |
||
174 | { |
||
175 | getShadeColorRGB(&r, &g, &b, level); |
||
176 | tmp2.setColorRGB(r, g, b); |
||
177 | } |
||
178 | else |
||
179 | { |
||
180 | getShadeColorCMYK(&c, &m, &y, &k, level); |
||
181 | tmp2.setColor(c, m, y, k); |
||
182 | } |
||
183 | |||
184 | return tmp2.getRGBColor(); |
||
185 | } |
||
186 | |||
187 | void ScColor::getRawRGBColor(int *r, int *g, int *b) |
||
188 | { |
||
189 | *r = 255-QMIN(255, C+K); |
||
190 | *g = 255-QMIN(255, M+K); |
||
191 | *b = 255-QMIN(255, Y+K); |
||
192 | } |
||
193 | |||
3046 | fschmid | 194 | QColor ScColor::getRawRGBColor() |
195 | { |
||
196 | return QColor(255-QMIN(255, C+K), 255-QMIN(255, M+K), 255-QMIN(255, Y+K)); |
||
197 | } |
||
198 | |||
2886 | fschmid | 199 | void ScColor::getRGB(int *r, int *g, int *b) |
200 | { |
||
201 | *r = R; |
||
202 | *g = G; |
||
203 | *b = B; |
||
204 | } |
||
205 | |||
206 | void ScColor::getCMYK(int *c, int *m, int *y, int *k) |
||
207 | { |
||
208 | *c = C; |
||
209 | *m = M; |
||
210 | *y = Y; |
||
211 | *k = K; |
||
212 | } |
||
213 | |||
214 | void ScColor::applyGCR() |
||
215 | { |
||
216 | #ifdef HAVE_CMS |
||
217 | if (!(CMSuse && CMSavail)) |
||
218 | { |
||
219 | #endif |
||
220 | int k = QMIN(QMIN(C, M), Y); |
||
221 | C = C - k; |
||
222 | M = M - k; |
||
223 | Y = Y - k; |
||
224 | K = QMIN((K + k), 255); |
||
225 | #ifdef HAVE_CMS |
||
226 | } |
||
227 | #endif |
||
228 | } |
||
229 | |||
230 | QString ScColor::name() |
||
231 | { |
||
232 | QString tmp, name="#"; |
||
233 | switch (Model) |
||
234 | { |
||
235 | case colorModelCMYK: |
||
236 | tmp.setNum(C, 16); |
||
237 | if (tmp.length() < 2) |
||
238 | tmp.insert(0, "0"); |
||
239 | name += tmp; |
||
240 | tmp.setNum(M, 16); |
||
241 | if (tmp.length() < 2) |
||
242 | tmp.insert(0, "0"); |
||
243 | name += tmp; |
||
244 | tmp.setNum(Y, 16); |
||
245 | if (tmp.length() < 2) |
||
246 | tmp.insert(0, "0"); |
||
247 | name += tmp; |
||
248 | tmp.setNum(K, 16); |
||
249 | if (tmp.length() < 2) |
||
250 | tmp.insert(0, "0"); |
||
251 | name += tmp; |
||
252 | return name; |
||
253 | break; |
||
254 | case colorModelRGB: |
||
255 | tmp.setNum(R, 16); |
||
256 | if (tmp.length() < 2) |
||
257 | tmp.insert(0, "0"); |
||
258 | name += tmp; |
||
259 | tmp.setNum(G, 16); |
||
260 | if (tmp.length() < 2) |
||
261 | tmp.insert(0, "0"); |
||
262 | name += tmp; |
||
263 | tmp.setNum(B, 16); |
||
264 | if (tmp.length() < 2) |
||
265 | tmp.insert(0, "0"); |
||
266 | name += tmp; |
||
267 | return name; |
||
268 | } |
||
269 | return ""; |
||
270 | } |
||
271 | |||
272 | void ScColor::setNamedColor(QString name) |
||
273 | { |
||
274 | bool ok; |
||
275 | if (name.length () == 9) |
||
276 | { |
||
277 | int c = name.mid(1,2).toInt(&ok, 16); |
||
278 | int m = name.mid(3,2).toInt(&ok, 16); |
||
279 | int y = name.mid(5,2).toInt(&ok, 16); |
||
280 | int k = name.mid(7,2).toInt(&ok, 16); |
||
281 | setColor(c, m, y, k); |
||
282 | } |
||
283 | else if (name.length () == 7) |
||
284 | { |
||
285 | int r = name.mid(1,2).toInt(&ok, 16); |
||
286 | int g = name.mid(3,2).toInt(&ok, 16); |
||
287 | int b = name.mid(5,2).toInt(&ok, 16); |
||
288 | setColorRGB(r, g, b); |
||
289 | } |
||
290 | } |
||
291 | |||
3041 | fschmid | 292 | bool ScColor::isOutOfGamut() |
293 | { |
||
294 | return outOfGamutFlag; |
||
295 | } |
||
296 | |||
3046 | fschmid | 297 | void ScColor::checkGamut() |
298 | { |
||
299 | outOfGamutFlag = false; |
||
3057 | fschmid | 300 | if (Spot) |
301 | return; |
||
3046 | fschmid | 302 | #ifdef HAVE_CMS |
303 | WORD inC[4]; |
||
304 | WORD outC[4]; |
||
305 | if (CMSuse && CMSavail) |
||
306 | { |
||
307 | bool alert = true; |
||
308 | cmsHTRANSFORM xformProof; |
||
309 | if (Model == colorModelRGB) |
||
310 | { |
||
311 | inC[0] = R*257; |
||
312 | inC[1] = G*257; |
||
313 | inC[2] = B*257; |
||
314 | xformProof = stdProofGCG; |
||
315 | if ((R == 0) && (B == 0) && (G == 255)) |
||
316 | alert = false; |
||
3052 | fschmid | 317 | if ((R == G && G == B)) |
318 | alert = false; |
||
3046 | fschmid | 319 | } |
320 | else |
||
321 | { |
||
322 | inC[0] = C*257; |
||
323 | inC[1] = M*257; |
||
324 | inC[2] = Y*257; |
||
325 | inC[3] = K*257; |
||
326 | xformProof = stdProofCMYKGCG; |
||
3051 | fschmid | 327 | if ((M == 0) && (K == 0) && (C == 255) && (Y == 255)) |
3046 | fschmid | 328 | alert = false; |
3052 | fschmid | 329 | if ((M == 0) && (C == 0) && (Y == 0)) |
330 | alert = false; |
||
331 | if ((M == C) && (C == Y) && (Y == K)) |
||
332 | alert = false; |
||
3046 | fschmid | 333 | } |
3052 | fschmid | 334 | if (alert) |
335 | { |
||
336 | cmsDoTransform(xformProof, inC, outC, 1); |
||
337 | if ((alert) && ((outC[0]/257 == 0) && (outC[1]/257 == 255) & (outC[2]/257 == 0))) |
||
338 | outOfGamutFlag = true; |
||
339 | } |
||
3046 | fschmid | 340 | } |
341 | #endif |
||
342 | } |
||
343 | |||
2886 | fschmid | 344 | void ScColor::RecalcRGB() |
345 | { |
||
3041 | fschmid | 346 | outOfGamutFlag = false; |
3163 | fschmid | 347 | bool alert = true; |
2886 | fschmid | 348 | #ifdef HAVE_CMS |
349 | WORD inC[4]; |
||
350 | WORD outC[4]; |
||
3163 | fschmid | 351 | if ((CMSuse && CMSavail) && (!Spot)) |
2886 | fschmid | 352 | { |
3163 | fschmid | 353 | if (Model == colorModelRGB) |
2886 | fschmid | 354 | { |
3163 | fschmid | 355 | // allow RGB greys to go got to CMYK greys without transform |
356 | if (R == G && G == B) |
||
2886 | fschmid | 357 | { |
3163 | fschmid | 358 | C = M = Y = 0; |
359 | K = 255 - R; |
||
360 | } |
||
361 | else |
||
362 | { |
||
2886 | fschmid | 363 | inC[0] = R * 257; |
364 | inC[1] = G * 257; |
||
365 | inC[2] = B * 257; |
||
3163 | fschmid | 366 | if (SoftProofing) |
367 | { |
||
368 | if ((R == 0) && (B == 0) && (G == 255)) |
||
369 | alert = false; |
||
370 | cmsDoTransform(stdProofG, inC, outC, 1); |
||
371 | R = outC[0] / 257; |
||
372 | G = outC[1] / 257; |
||
373 | B = outC[2] / 257; |
||
374 | if ((alert) && (R == 0) && (B == 0) && (G == 255)) |
||
375 | outOfGamutFlag = true; |
||
376 | K = QMIN(QMIN(255 - R, 255 - G), 255 - B); |
||
377 | C = 255 - R - K; |
||
378 | M = 255 - G - K; |
||
379 | Y = 255 - B - K; |
||
380 | } |
||
381 | else |
||
382 | { |
||
383 | cmsDoTransform(stdTransCMYKG, inC, outC, 1); |
||
384 | C = outC[0] / 257; |
||
385 | M = outC[1] / 257; |
||
386 | Y = outC[2] / 257; |
||
387 | K = outC[3] / 257; |
||
388 | } |
||
2886 | fschmid | 389 | } |
390 | } |
||
3163 | fschmid | 391 | else |
2886 | fschmid | 392 | { |
393 | inC[0] = C * 257; |
||
394 | inC[1] = M * 257; |
||
395 | inC[2] = Y * 257; |
||
396 | inC[3] = K * 257; |
||
3163 | fschmid | 397 | if (SoftProofing) |
398 | { |
||
399 | if ((M == 0) && (K == 0) && (C == 255) && (Y == 255)) |
||
400 | alert = false; |
||
401 | if ((M == 0) && (C == 0) && (Y == 0)) |
||
402 | alert = false; |
||
403 | if ((M == C) && (C == Y) && (Y == K)) |
||
404 | alert = false; |
||
405 | cmsDoTransform(stdProofCMYKG, inC, outC, 1); |
||
406 | if ((alert) && (R == 0) && (B == 0) && (G == 255)) |
||
407 | outOfGamutFlag = true; |
||
408 | } |
||
409 | else |
||
410 | cmsDoTransform(stdTransRGBG, inC, outC, 1); |
||
2886 | fschmid | 411 | R = outC[0] / 257; |
412 | G = outC[1] / 257; |
||
413 | B = outC[2] / 257; |
||
414 | } |
||
415 | } |
||
3163 | fschmid | 416 | else |
2886 | fschmid | 417 | { |
3163 | fschmid | 418 | #endif |
2886 | fschmid | 419 | if (Model == colorModelRGB) |
420 | { |
||
3163 | fschmid | 421 | K = QMIN(QMIN(255 - R, 255 - G), 255 - B); |
422 | C = 255 - R - K; |
||
423 | M = 255 - G - K; |
||
424 | Y = 255 - B - K; |
||
2886 | fschmid | 425 | } |
426 | else |
||
427 | { |
||
3163 | fschmid | 428 | R = 255 - QMIN(255, C + K); |
429 | G = 255 - QMIN(255, M + K); |
||
430 | B = 255 - QMIN(255, Y + K); |
||
2886 | fschmid | 431 | } |
3163 | fschmid | 432 | #ifdef HAVE_CMS |
2886 | fschmid | 433 | } |
434 | #endif |
||
3163 | fschmid | 435 | RGB = QColor(R, G, B); |
2886 | fschmid | 436 | } |
3051 | fschmid | 437 | |
3060 | fschmid | 438 | bool ScColor::isRegistrationColor() |
439 | { |
||
440 | return Regist; |
||
441 | } |
||
442 | |||
443 | void ScColor::setRegistrationColor(bool s) |
||
444 | { |
||
445 | Regist = s; |
||
446 | } |
||
447 | |||
3051 | fschmid | 448 | bool ScColor::isSpotColor() |
449 | { |
||
450 | return Spot; |
||
451 | } |
||
452 | |||
453 | void ScColor::setSpotColor(bool s) |
||
454 | { |
||
455 | Spot = s; |
||
456 | } |