Logo ROOT   6.08/07
Reference Guide
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 #ifndef ROOT_TNamed
16 #include "TNamed.h"
17 #endif
18 #ifndef ROOT_TArrayI
19 #include "TArrayI.h"
20 #endif
21 
22 
23 class TColor : public TNamed {
24 protected:
25  Int_t fNumber; ///< Color number identifier
26 private:
27  Float_t fRed; ///< Fraction of Red
28  Float_t fGreen; ///< Fraction of Green
29  Float_t fBlue; ///< Fraction of Blue
30  Float_t fHue; ///< Hue
31  Float_t fLight; ///< Light
32  Float_t fSaturation; ///< Saturation
33  Float_t fAlpha; ///< Alpha (transparency)
34 
35  void Allocate();
36  static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei);
37 
38 public:
39  TColor();
40  TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char *name="", Float_t a = 1);
42  TColor(const TColor &color);
43  virtual ~TColor();
44  const char *AsHexString() const;
45  void Copy(TObject &color) const;
46  static void CreateColorWheel();
47  static void CreateColorsGray();
48  static void CreateColorsCircle(Int_t offset, const char *name, UChar_t *rgb);
49  static void CreateColorsRectangle(Int_t offset, const char *name, UChar_t *rgb);
50  static Int_t CreateGradientColorTable(UInt_t Number, Double_t* Stops,
51  Double_t* Red, Double_t* Green, Double_t* Blue, UInt_t NColors, Float_t alpha=1.);
52  static Int_t GetColorPalette(Int_t i);
53  static Int_t GetNumberOfColors();
54  virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
55  { r=GetRed(); g=GetGreen(); b=GetBlue(); }
56  virtual void GetHLS(Float_t &h, Float_t &l, Float_t &s) const
57  { h=GetHue(); l=GetLight(); s=GetSaturation(); }
58  Int_t GetNumber() const { return fNumber; }
59  ULong_t GetPixel() const;
60  Float_t GetRed() const { return IsGrayscale() ? GetGrayscale() : fRed; }
61  Float_t GetGreen() const { return IsGrayscale() ? GetGrayscale() : fGreen; }
62  Float_t GetBlue() const { return IsGrayscale() ? GetGrayscale() : fBlue; }
63  Float_t GetHue() const { return fHue; }
64  Float_t GetLight() const { return fLight; }
65  Float_t GetSaturation() const { return IsGrayscale() ? 0 : fSaturation; }
66  Float_t GetAlpha() const { return fAlpha; }
67  virtual Float_t GetGrayscale() const { /*ITU*/ return 0.299f*fRed + 0.587f*fGreen + 0.114f*fBlue; }
68  virtual void ls(Option_t *option="") const;
69  virtual void Print(Option_t *option="") const;
70  virtual void SetAlpha(Float_t a) { fAlpha = a; }
71  virtual void SetRGB(Float_t r, Float_t g, Float_t b);
72 
73  static void InitializeColors();
74  static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b);
75  static void HLS2RGB(Int_t h, Int_t l, Int_t s, Int_t &r, Int_t &g, Int_t &b);
76  static void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
77  { TColor::HLS2RGB(h, l, s, r, g, b); } // backward compatible
78  static void HSV2RGB(Float_t h, Float_t s, Float_t v, Float_t &r, Float_t &g, Float_t &b);
79  static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s);
80  static void RGB2HLS(Int_t r, Int_t g, Int_t b, Int_t &h, Int_t &l, Int_t &s);
81  static void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
82  { TColor::RGB2HLS(r, g, b, h, l, s); } // backward compatible
83  static void RGB2HSV(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &s, Float_t &v);
84  static Int_t GetColor(const char *hexcolor);
85  static Int_t GetColor(Float_t r, Float_t g, Float_t b);
86  static Int_t GetColor(Int_t r, Int_t g, Int_t b);
87  static Int_t GetColor(ULong_t pixel);
88  static Int_t GetColorBright(Int_t color);
89  static Int_t GetColorDark(Int_t color);
90  static Int_t GetColorTransparent(Int_t color, Float_t a);
91  static Int_t GetFreeColorIndex();
92  static ULong_t Number2Pixel(Int_t ci);
93  static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b);
94  static ULong_t RGB2Pixel(Float_t r, Float_t g, Float_t b);
95  static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b);
96  static void Pixel2RGB(ULong_t pixel, Float_t &r, Float_t &g, Float_t &b);
97  static const char *PixelAsHexString(ULong_t pixel);
98  static void SaveColor(std::ostream &out, Int_t ci);
99  static Bool_t IsGrayscale();
100  static void SetGrayscale(Bool_t set = kTRUE);
101  static void SetPalette(Int_t ncolors, Int_t *colors,Float_t alpha=1.);
102 
103  ClassDef(TColor,2) //Color defined by RGB or HLS
104 };
105 
113  kBrownCyan=72, kCMYK=73, kCandy=74,
119  kNeon=90, kPastel=91, kPearl=92,
120  kPigeon=93, kPlum=94, kRedBlue=95,
122  kSienna=99, kSolar=100, kSouthWest=101,
125  kWaterMelon=108, kCool=109, kCopper=110,
126  kGistEarth=111, kViridis=112};
127 #endif
128 
static void HSV2RGB(Float_t h, Float_t s, Float_t v, Float_t &r, Float_t &g, Float_t &b)
Static method to compute RGB from HSV:
Definition: TColor.cxx:1460
Float_t fBlue
Fraction of Blue.
Definition: TColor.h:29
virtual void SetAlpha(Float_t a)
Definition: TColor.h:70
static Bool_t IsGrayscale()
Return whether all colors return grayscale values.
Definition: TColor.cxx:2059
Float_t GetRed() const
Definition: TColor.h:60
Float_t fHue
Hue.
Definition: TColor.h:30
virtual Float_t GetGrayscale() const
Definition: TColor.h:67
float Float_t
Definition: RtypesCore.h:53
Definition: TColor.h:121
const char Option_t
Definition: RtypesCore.h:62
static Int_t GetColorDark(Int_t color)
Static function: Returns the dark color number corresponding to n If the TColor object does not exist...
Definition: TColor.cxx:1848
Float_t GetAlpha() const
Definition: TColor.h:66
EColorPalette
Definition: TColor.h:106
TH1 * h
Definition: legend2.C:5
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2021
static Int_t GetFreeColorIndex()
Static function: Returns a free color index which can be used to define a user custom color...
Definition: TColor.cxx:1905
static void RGB2HSV(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &s, Float_t &v)
Static method to compute HSV from RGB.
Definition: TColor.cxx:1592
Definition: TColor.h:119
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Definition: TColor.cxx:1367
Definition: TColor.h:117
Float_t GetLight() const
Definition: TColor.h:64
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
static void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
Definition: TColor.h:76
virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
Definition: TColor.h:54
Float_t GetBlue() const
Definition: TColor.h:62
Float_t fAlpha
Alpha (transparency)
Definition: TColor.h:33
static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.)
Static function.
Definition: TColor.cxx:2316
static const char * PixelAsHexString(ULong_t pixel)
Convert machine dependent pixel value (obtained via RGB2Pixel or via Number2Pixel() or via TColor::Ge...
Definition: TColor.cxx:2009
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Definition: TColor.cxx:1355
#define ClassDef(name, id)
Definition: Rtypes.h:254
Float_t GetGreen() const
Definition: TColor.h:61
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Definition: TColor.h:115
Definition: TColor.h:121
Float_t fLight
Light.
Definition: TColor.h:31
Float_t fGreen
Fraction of Green.
Definition: TColor.h:28
virtual void GetHLS(Float_t &h, Float_t &l, Float_t &s) const
Definition: TColor.h:56
static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)
Convert r,g,b to graphics system dependent pixel value.
Definition: TColor.cxx:1954
virtual void Print(Option_t *option="") const
Dump this color with its attributes.
Definition: TColor.cxx:1525
virtual ~TColor()
Color destructor.
Definition: TColor.cxx:1029
Definition: TColor.h:120
static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
Static method to compute HLS from RGB.
Definition: TColor.cxx:1534
void Copy(TObject &color) const
Copy this color to obj.
Definition: TColor.cxx:1195
static void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
Definition: TColor.h:81
static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
Static method to compute RGB from HLS.
Definition: TColor.cxx:1394
static Int_t GetColorBright(Int_t color)
Static function: Returns the bright color number corresponding to n If the TColor object does not exi...
Definition: TColor.cxx:1816
Float_t GetSaturation() const
Definition: TColor.h:65
TRandom2 r(17)
SVector< double, 2 > v
Definition: Dict.h:5
Float_t fSaturation
Saturation.
Definition: TColor.h:32
static void CreateColorsRectangle(Int_t offset, const char *name, UChar_t *rgb)
Create the "rectangular" colors in the color wheel.
Definition: TColor.cxx:1247
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition: TColor.cxx:1377
unsigned int UInt_t
Definition: RtypesCore.h:42
Definition: TColor.h:118
TLine * l
Definition: textangle.C:4
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb"...
Definition: TColor.cxx:1706
Definition: TColor.h:125
TColor()
Default constructor.
Definition: TColor.cxx:957
Definition: TColor.h:109
Definition: TColor.h:113
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1879
Int_t fNumber
Color number identifier.
Definition: TColor.h:25
static void CreateColorWheel()
Static function steering the creation of all colors in the color wheel.
Definition: TColor.cxx:1267
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:1916
Color * colors
Definition: X3DBuffer.c:19
Definition: TColor.h:113
double Double_t
Definition: RtypesCore.h:55
unsigned long ULong_t
Definition: RtypesCore.h:51
static void CreateColorsGray()
Create the Gray scale colors in the Color Wheel.
Definition: TColor.cxx:1211
virtual void SetRGB(Float_t r, Float_t g, Float_t b)
Initialize this color and its associated colors.
Definition: TColor.cxx:1645
Definition: TColor.h:119
The color creation and management class.
Definition: TColor.h:23
Definition: TColor.h:112
Definition: TColor.h:122
Float_t fRed
Fraction of Red.
Definition: TColor.h:27
Mother of all ROOT objects.
Definition: TObject.h:37
Definition: TColor.h:110
static void SetGrayscale(Bool_t set=kTRUE)
Set whether all colors should return grayscale values.
Definition: TColor.cxx:2067
static void CreateColorsCircle(Int_t offset, const char *name, UChar_t *rgb)
Create the "circle" colors in the color wheel.
Definition: TColor.cxx:1227
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Int_t GetNumber() const
Definition: TColor.h:58
virtual void ls(Option_t *option="") const
List this color with its attributes.
Definition: TColor.cxx:1516
Definition: TColor.h:108
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition: TColor.cxx:1048
unsigned char UChar_t
Definition: RtypesCore.h:34
void Allocate()
Make this color known to the graphics system.
Definition: TColor.cxx:1691
const char * AsHexString() const
Return color as hexadecimal string.
Definition: TColor.cxx:1174
const Bool_t kTRUE
Definition: Rtypes.h:91
static Int_t CreateGradientColorTable(UInt_t Number, Double_t *Stops, Double_t *Red, Double_t *Green, Double_t *Blue, UInt_t NColors, Float_t alpha=1.)
Static function creating a color table with several connected linear gradients.
Definition: TColor.cxx:2128
static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei)
Static method. Auxiliary to HLS2RGB().
Definition: TColor.cxx:1419
char name[80]
Definition: TGX11.cxx:109
static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b)
Convert machine dependent pixel value (obtained via RGB2Pixel or via Number2Pixel() or via TColor::Ge...
Definition: TColor.cxx:1992
Float_t GetHue() const
Definition: TColor.h:63