lib Library API Documentation

koColor.h

00001 /* This file is part of the KDE project
00002   Copyright (c) 1999 Matthias Elter (me@kde.org)
00003   Copyright (c) 2001-2002 Igor Jansen (rm@kde.org)
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef __ko_color_h__
00022 #define __ko_color_h__
00023 
00024 #include <qcolor.h>
00025 
00026 class KoColor
00027 {
00028 public:
00029   enum cSpace{ csIndexed, csRGB, csHSV, csCMYK, csLab };
00030 
00031   KoColor();
00032   KoColor(int a, int b, int c,  cSpace m = csRGB);
00033   KoColor(int c, int m, int y,  int k);
00034   KoColor(const QString &name);
00035   KoColor(const QColor &c);
00036 
00037   cSpace native() const {return mNative; }
00038 
00039   int R() const;
00040   int G() const;
00041   int B() const;
00042   int H() const;
00043   int S() const;
00044   int V() const;
00045   int L() const;
00046   int a() const;
00047   int b() const;
00048   int C() const;
00049   int M() const;
00050   int Y() const;
00051   int K() const;
00052 
00053   void rgb(int *R, int *G, int *B) const;
00054   void hsv(int *H, int *S, int *V) const;
00055   void lab(int *L, int *a, int *b) const;
00056   void cmyk(int *C, int *M, int *Y, int *K) const;
00057   QString name() const;
00058   QColor color() const;
00059 
00060   void setRGB(int R, int G, int B);
00061   void setHSV(int H, int S, int V);
00062   void setLab(int L, int a, int b);
00063   void setCMYK(int C, int M, int Y, int K);
00064   void setNamedColor(const QString &name);
00065   void setColor(const QColor &c);
00066   
00067   static void RGBtoHSV(int R, int G, int B, int *H, int *S, int *V);
00068   static void RGBtoLAB(int R, int G, int B, int *L, int *a, int *b);
00069   static void RGBtoCMYK(int R, int G, int B, int *C, int *M, int *Y, int *K);
00070 
00071   static void HSVtoRGB(int H, int S, int V, int *R, int *G, int *B);
00072   static void HSVtoLAB(int H, int S, int V, int *L, int *a, int *b);
00073   static void HSVtoCMYK(int H, int S, int V, int *C, int *M, int *Y, int*K);
00074 
00075   static void LABtoRGB(int L, int a, int b, int *R, int *G, int *B);
00076   static void LABtoHSV(int L, int a, int b, int *H, int *S, int *V);
00077   static void LABtoCMYK(int L, int a, int b, int *C, int *M, int *Y, int*K);
00078 
00079   static void CMYKtoRGB(int C, int M, int Y, int K, int *R, int *G, int *B);
00080   static void CMYKtoHSV(int C, int M, int Y, int K, int *H, int *S, int *V);
00081   static void CMYKtoLAB(int C, int M, int Y, int K, int *L, int *a, int *b);
00082 
00083   static const KoColor black();
00084   static const KoColor white();
00085   static const KoColor gray();
00086   static const KoColor lightGray();
00087   static const KoColor darkGray();
00088   static const KoColor red();
00089   static const KoColor darkRed();
00090   static const KoColor green();
00091   static const KoColor darkGreen();
00092   static const KoColor blue();
00093   static const KoColor darkBlue();
00094   static const KoColor cyan();
00095   static const KoColor darkCyan();
00096   static const KoColor magenta();
00097   static const KoColor darkMagenta();
00098   static const KoColor yellow();
00099   static const KoColor darkYellow();
00100 
00101 protected:
00102   int hex2int(QChar c);
00103 
00104   void calcRGB() const;
00105   void calcHSV() const;
00106   void calcCMYK() const;
00107   void calcLAB() const;
00108 
00109   void rgbChanged() const;
00110   void hsvChanged() const;
00111   void cmykChanged() const;
00112   void labChanged() const;
00113 
00114 private:
00115   /*
00116    * Mutable to make it possible for const objects to transform the native cModel
00117    * in functions like KoColor::rgb(...) to the requested.
00118    */
00119   mutable int mR, mG, mB;        // RGB
00120   mutable int mC, mM, mY, mK;    // CMYK
00121   mutable int mH, mS, mV;        // HSV
00122   mutable int mL, ma, mb;        // LAB
00123 
00124   mutable bool mRGBvalid;
00125   mutable bool mHSVvalid;
00126   mutable bool mCMYKvalid;
00127   mutable bool mLABvalid;
00128 
00129   cSpace mNative; 
00130 };
00131 
00132 inline const KoColor KoColor::white()
00133 {
00134   return KoColor(255, 255, 255, csRGB);
00135 }
00136 
00137 inline const KoColor KoColor::black()
00138 {
00139   return KoColor(0, 0, 0, csRGB);
00140 }
00141 
00142 inline const KoColor KoColor::gray()
00143 {
00144   return KoColor(160, 160, 164, csRGB);
00145 }
00146 
00147 inline const KoColor KoColor::lightGray()
00148 {
00149   return KoColor(192, 192, 192, csRGB);
00150 }
00151 
00152 inline const KoColor KoColor::darkGray()
00153 {
00154   return KoColor(128, 128, 128, csRGB);
00155 }
00156 
00157 inline const KoColor KoColor::red()
00158 {
00159   return KoColor(255, 0, 0, csRGB);
00160 }
00161 
00162 inline const KoColor KoColor::darkRed()
00163 {
00164   return KoColor(128, 0, 0, csRGB);
00165 }
00166 
00167 inline const KoColor KoColor::green()
00168 {
00169   return KoColor(0, 255, 0, csRGB);
00170 }
00171 
00172 inline const KoColor KoColor::darkGreen()
00173 {
00174   return KoColor(0, 128, 0, csRGB);
00175 }
00176 
00177 inline const KoColor KoColor::blue()
00178 {
00179   return KoColor(0, 0, 255, csRGB);
00180 }
00181 
00182 inline const KoColor KoColor::darkBlue()
00183 {
00184   return KoColor(0, 0, 128, csRGB);
00185 }
00186 
00187 inline const KoColor KoColor::cyan()
00188 {
00189   return KoColor(0, 255, 255, csRGB);
00190 }
00191 
00192 inline const KoColor KoColor::darkCyan()
00193 {
00194   return KoColor(0, 128, 128, csRGB);
00195 }
00196 
00197 inline const KoColor KoColor::magenta()
00198 {
00199   return KoColor(255, 0, 255, csRGB);
00200 }
00201 
00202 inline const KoColor KoColor::darkMagenta()
00203 {
00204   return KoColor(128, 0, 128, csRGB);
00205 }
00206 
00207 inline const KoColor KoColor::yellow()
00208 {
00209   return KoColor(255, 255, 0, csRGB);
00210 }
00211 
00212 inline const KoColor KoColor::darkYellow()
00213 {
00214   return KoColor(128, 128, 0, csRGB);
00215 }
00216 
00217 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 11 11:47:40 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003