Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TColor.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Rene Brun 12/12/94
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TColor
13 #define ROOT_TColor
14 
15 #include "TNamed.h"
16 #include "TArrayI.h"
17 
18 
19 class TColor : public TNamed {
20 protected:
21  Int_t fNumber; ///< Color number identifier
22 private:
23  Float_t fRed; ///< Fraction of Red
24  Float_t fGreen; ///< Fraction of Green
25  Float_t fBlue; ///< Fraction of Blue
26  Float_t fHue; ///< Hue
27  Float_t fLight; ///< Light
28  Float_t fSaturation; ///< Saturation
29  Float_t fAlpha; ///< Alpha (transparency)
30 
31  void Allocate();
32  static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei);
33 
34 public:
35  TColor();
36  TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char *name="", Float_t a = 1);
37  TColor(Float_t r, Float_t g, Float_t b, Float_t a = 1);
38  TColor(const TColor &color);
39  TColor &operator=(const TColor &color);
40  virtual ~TColor();
41  const char *AsHexString() const;
42  void Copy(TObject &color) const;
43  static void CreateColorWheel();
44  static void CreateColorsGray();
45  static void CreateColorsCircle(Int_t offset, const char *name, UChar_t *rgb);
46  static void CreateColorsRectangle(Int_t offset, const char *name, UChar_t *rgb);
47  static Int_t CreateGradientColorTable(UInt_t Number, Double_t* Stops,
48  Double_t* Red, Double_t* Green, Double_t* Blue, UInt_t NColors, Float_t alpha=1.);
49  static Int_t GetColorPalette(Int_t i);
50  static Int_t GetNumberOfColors();
51  virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
52  { r=GetRed(); g=GetGreen(); b=GetBlue(); }
53  virtual void GetHLS(Float_t &h, Float_t &l, Float_t &s) const
54  { h=GetHue(); l=GetLight(); s=GetSaturation(); }
55  Int_t GetNumber() const { return fNumber; }
56  ULong_t GetPixel() const;
57  Float_t GetRed() const { return IsGrayscale() ? GetGrayscale() : fRed; }
58  Float_t GetGreen() const { return IsGrayscale() ? GetGrayscale() : fGreen; }
59  Float_t GetBlue() const { return IsGrayscale() ? GetGrayscale() : fBlue; }
60  Float_t GetHue() const { return fHue; }
61  Float_t GetLight() const { return fLight; }
62  Float_t GetSaturation() const { return IsGrayscale() ? 0 : fSaturation; }
63  Float_t GetAlpha() const { return fAlpha; }
64  virtual Float_t GetGrayscale() const { /*ITU*/ return 0.299f*fRed + 0.587f*fGreen + 0.114f*fBlue; }
65  virtual void ls(Option_t *option="") const;
66  virtual void Print(Option_t *option="") const;
67  virtual void SetAlpha(Float_t a) { fAlpha = a; }
68  virtual void SetRGB(Float_t r, Float_t g, Float_t b);
69 
70  static void InitializeColors();
71  static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b);
72  static void HLS2RGB(Int_t h, Int_t l, Int_t s, Int_t &r, Int_t &g, Int_t &b);
73  static void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
74  { TColor::HLS2RGB(h, l, s, r, g, b); } // backward compatible
75  static void HSV2RGB(Float_t h, Float_t s, Float_t v, Float_t &r, Float_t &g, Float_t &b);
76  static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s);
77  static void RGB2HLS(Int_t r, Int_t g, Int_t b, Int_t &h, Int_t &l, Int_t &s);
78  static void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
79  { TColor::RGB2HLS(r, g, b, h, l, s); } // backward compatible
80  static void RGB2HSV(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &s, Float_t &v);
81  static Int_t GetColor(const char *hexcolor);
82  static Int_t GetColor(Float_t r, Float_t g, Float_t b);
83  static Int_t GetColor(Int_t r, Int_t g, Int_t b);
84  static Int_t GetColor(ULong_t pixel);
85  static Int_t GetColorBright(Int_t color);
86  static Int_t GetColorDark(Int_t color);
87  static Int_t GetColorTransparent(Int_t color, Float_t a);
88  static Int_t GetFreeColorIndex();
89  static const TArrayI& GetPalette();
90  static ULong_t Number2Pixel(Int_t ci);
91  static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b);
92  static ULong_t RGB2Pixel(Float_t r, Float_t g, Float_t b);
93  static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b);
94  static void Pixel2RGB(ULong_t pixel, Float_t &r, Float_t &g, Float_t &b);
95  static const char *PixelAsHexString(ULong_t pixel);
96  static void SaveColor(std::ostream &out, Int_t ci);
97  static void SetColorThreshold(Float_t t);
98  static Bool_t DefinedColors();
99  static void InvertPalette();
100  static Bool_t IsGrayscale();
101  static void SetGrayscale(Bool_t set = kTRUE);
102  static void SetPalette(Int_t ncolors, Int_t *colors,Float_t alpha=1.);
103 
104  ClassDef(TColor,2) //Color defined by RGB or HLS
105 };
106 
107  enum EColorPalette {kDeepSea=51, kGreyScale=52, kDarkBodyRadiator=53,
108  kBlueYellow= 54, kRainBow=55, kInvertedDarkBodyRadiator=56,
109  kBird=57, kCubehelix=58, kGreenRedViolet=59,
110  kBlueRedYellow=60, kOcean=61, kColorPrintableOnGrey=62,
111  kAlpine=63, kAquamarine=64, kArmy=65,
112  kAtlantic=66, kAurora=67, kAvocado=68,
113  kBeach=69, kBlackBody=70, kBlueGreenYellow=71,
114  kBrownCyan=72, kCMYK=73, kCandy=74,
115  kCherry=75, kCoffee=76, kDarkRainBow=77,
116  kDarkTerrain=78, kFall=79, kFruitPunch=80,
117  kFuchsia=81, kGreyYellow=82, kGreenBrownTerrain=83,
118  kGreenPink=84, kIsland=85, kLake=86,
119  kLightTemperature=87, kLightTerrain=88, kMint=89,
120  kNeon=90, kPastel=91, kPearl=92,
121  kPigeon=93, kPlum=94, kRedBlue=95,
122  kRose=96, kRust=97, kSandyTerrain=98,
123  kSienna=99, kSolar=100, kSouthWest=101,
124  kStarryNight=102, kSunset=103, kTemperatureMap=104,
125  kThermometer=105, kValentine=106, kVisibleSpectrum=107,
126  kWaterMelon=108, kCool=109, kCopper=110,
127  kGistEarth=111, kViridis=112, kCividis=113};
128 #endif
129