1
/* This file is part of the KDE project
2
Copyright (c) 1999 Matthias Elter (me@kde.org)
3
Copyright (c) 2001-2002 Igor Jansen (rm@kde.org)
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
Boston, MA 02111-1307, USA.
21
#ifndef __ko_color_h__
22
#define __ko_color_h__
29
enum cSpace{ csIndexed, csRGB, csHSV, csCMYK, csLab };
32
KoColor(int a, int b, int c, cSpace m = csRGB);
33
KoColor(int c, int m, int y, int k);
34
KoColor(const QString &name);
35
KoColor(const QColor &c);
37
cSpace native() const {return mNative; }
53
void rgb(int *R, int *G, int *B) const;
54
void hsv(int *H, int *S, int *V) const;
55
void lab(int *L, int *a, int *b) const;
56
void cmyk(int *C, int *M, int *Y, int *K) const;
60
void setRGB(int R, int G, int B);
61
void setHSV(int H, int S, int V);
62
void setLab(int L, int a, int b);
63
void setCMYK(int C, int M, int Y, int K);
64
void setNamedColor(const QString &name);
65
void setColor(const QColor &c);
67
static void RGBtoHSV(int R, int G, int B, int *H, int *S, int *V);
68
static void RGBtoLAB(int R, int G, int B, int *L, int *a, int *b);
69
static void RGBtoCMYK(int R, int G, int B, int *C, int *M, int *Y, int *K);
71
static void HSVtoRGB(int H, int S, int V, int *R, int *G, int *B);
72
static void HSVtoLAB(int H, int S, int V, int *L, int *a, int *b);
73
static void HSVtoCMYK(int H, int S, int V, int *C, int *M, int *Y, int*K);
75
static void LABtoRGB(int L, int a, int b, int *R, int *G, int *B);
76
static void LABtoHSV(int L, int a, int b, int *H, int *S, int *V);
77
static void LABtoCMYK(int L, int a, int b, int *C, int *M, int *Y, int*K);
79
static void CMYKtoRGB(int C, int M, int Y, int K, int *R, int *G, int *B);
80
static void CMYKtoHSV(int C, int M, int Y, int K, int *H, int *S, int *V);
81
static void CMYKtoLAB(int C, int M, int Y, int K, int *L, int *a, int *b);
83
static const KoColor black();
84
static const KoColor white();
85
static const KoColor gray();
86
static const KoColor lightGray();
87
static const KoColor darkGray();
88
static const KoColor red();
89
static const KoColor darkRed();
90
static const KoColor green();
91
static const KoColor darkGreen();
92
static const KoColor blue();
93
static const KoColor darkBlue();
94
static const KoColor cyan();
95
static const KoColor darkCyan();
96
static const KoColor magenta();
97
static const KoColor darkMagenta();
98
static const KoColor yellow();
99
static const KoColor darkYellow();
102
int hex2int(QChar c);
104
void calcRGB() const;
105
void calcHSV() const;
106
void calcCMYK() const;
107
void calcLAB() const;
109
void rgbChanged() const;
110
void hsvChanged() const;
111
void cmykChanged() const;
112
void labChanged() const;
116
* Mutable to make it possible for const objects to transform the native cModel
117
* in functions like KoColor::rgb(...) to the requested.
119
mutable int mR, mG, mB; // RGB
120
mutable int mC, mM, mY, mK; // CMYK
121
mutable int mH, mS, mV; // HSV
122
mutable int mL, ma, mb; // LAB
124
mutable bool mRGBvalid;
125
mutable bool mHSVvalid;
126
mutable bool mCMYKvalid;
127
mutable bool mLABvalid;
132
inline const KoColor KoColor::white()
134
return KoColor(255, 255, 255, csRGB);
137
inline const KoColor KoColor::black()
139
return KoColor(0, 0, 0, csRGB);
142
inline const KoColor KoColor::gray()
144
return KoColor(160, 160, 164, csRGB);
147
inline const KoColor KoColor::lightGray()
149
return KoColor(192, 192, 192, csRGB);
152
inline const KoColor KoColor::darkGray()
154
return KoColor(128, 128, 128, csRGB);
157
inline const KoColor KoColor::red()
159
return KoColor(255, 0, 0, csRGB);
162
inline const KoColor KoColor::darkRed()
164
return KoColor(128, 0, 0, csRGB);
167
inline const KoColor KoColor::green()
169
return KoColor(0, 255, 0, csRGB);
172
inline const KoColor KoColor::darkGreen()
174
return KoColor(0, 128, 0, csRGB);
177
inline const KoColor KoColor::blue()
179
return KoColor(0, 0, 255, csRGB);
182
inline const KoColor KoColor::darkBlue()
184
return KoColor(0, 0, 128, csRGB);
187
inline const KoColor KoColor::cyan()
189
return KoColor(0, 255, 255, csRGB);
192
inline const KoColor KoColor::darkCyan()
194
return KoColor(0, 128, 128, csRGB);
197
inline const KoColor KoColor::magenta()
199
return KoColor(255, 0, 255, csRGB);
202
inline const KoColor KoColor::darkMagenta()
204
return KoColor(128, 0, 128, csRGB);
207
inline const KoColor KoColor::yellow()
209
return KoColor(255, 255, 0, csRGB);
212
inline const KoColor KoColor::darkYellow()
214
return KoColor(128, 128, 0, csRGB);