Logo ROOT  
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 #include "TNamed.h"
16 
17 class TArrayI;
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);
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);
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);
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);
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);
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 
114  kBrownCyan=72, kCMYK=73, kCandy=74,
120  kNeon=90, kPastel=91, kPearl=92,
121  kPigeon=93, kPlum=94, kRedBlue=95,
123  kSienna=99, kSolar=100, kSouthWest=101,
126  kWaterMelon=108, kCool=109, kCopper=110,
127  kGistEarth=111, kViridis=112, kCividis=113};
128 #endif
129 
TColor::GetSaturation
Float_t GetSaturation() const
Definition: TColor.h:62
TColor::HLStoRGB
static void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
Definition: TColor.h:73
TColor::fGreen
Float_t fGreen
Fraction of Green.
Definition: TColor.h:24
l
auto * l
Definition: textangle.C:4
kLightTerrain
@ kLightTerrain
Definition: TColor.h:119
kCopper
@ kCopper
Definition: TColor.h:126
kVisibleSpectrum
@ kVisibleSpectrum
Definition: TColor.h:125
kGreenBrownTerrain
@ kGreenBrownTerrain
Definition: TColor.h:117
TColor::ls
virtual void ls(Option_t *option="") const
List this color with its attributes.
Definition: TColor.cxx:1573
TColor::GetLight
Float_t GetLight() const
Definition: TColor.h:61
TColor::RGB2HSV
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:1649
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
kAvocado
@ kAvocado
Definition: TColor.h:112
TColor::HLStoRGB1
static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei)
Static method. Auxiliary to HLS2RGB().
Definition: TColor.cxx:1476
kDarkRainBow
@ kDarkRainBow
Definition: TColor.h:115
kDeepSea
@ kDeepSea
Definition: TColor.h:107
kCherry
@ kCherry
Definition: TColor.h:115
kPigeon
@ kPigeon
Definition: TColor.h:121
kMint
@ kMint
Definition: TColor.h:119
kSunset
@ kSunset
Definition: TColor.h:124
kArmy
@ kArmy
Definition: TColor.h:111
kPlum
@ kPlum
Definition: TColor.h:121
TColor::GetPixel
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition: TColor.cxx:1434
r
ROOT::R::TRInterface & r
Definition: Object.C:4
kAurora
@ kAurora
Definition: TColor.h:112
TNamed.h
TColor::SetGrayscale
static void SetGrayscale(Bool_t set=kTRUE)
Set whether all colors should return grayscale values.
Definition: TColor.cxx:2164
colors
Color * colors
Definition: X3DBuffer.c:21
TColor::GetFreeColorIndex
static Int_t GetFreeColorIndex()
Static function: Returns a free color index which can be used to define a user custom color.
Definition: TColor.cxx:2002
TColor::CreateColorsCircle
static void CreateColorsCircle(Int_t offset, const char *name, UChar_t *rgb)
Create the "circle" colors in the color wheel.
Definition: TColor.cxx:1262
TColor::Allocate
void Allocate()
Make this color known to the graphics system.
Definition: TColor.cxx:1749
kGreenRedViolet
@ kGreenRedViolet
Definition: TColor.h:109
TColor::DefinedColors
static Bool_t DefinedColors()
Static function returning kTRUE if some new colors have been defined after initialisation or since th...
Definition: TColor.cxx:1420
kCMYK
@ kCMYK
Definition: TColor.h:114
kBird
@ kBird
Definition: TColor.h:109
TColor::SetRGB
virtual void SetRGB(Float_t r, Float_t g, Float_t b)
Initialize this color and its associated colors.
Definition: TColor.cxx:1702
Float_t
float Float_t
Definition: RtypesCore.h:57
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
Int_t
int Int_t
Definition: RtypesCore.h:45
TColor::fHue
Float_t fHue
Hue.
Definition: TColor.h:26
TColor::fLight
Float_t fLight
Light.
Definition: TColor.h:27
kRose
@ kRose
Definition: TColor.h:122
TColor::fRed
Float_t fRed
Fraction of Red.
Definition: TColor.h:23
TColor::PixelAsHexString
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:2106
TColor::Number2Pixel
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:2013
TColor::GetColorPalette
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Definition: TColor.cxx:1390
TColor::SaveColor
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:2118
kBlueYellow
@ kBlueYellow
Definition: TColor.h:108
TColor::CreateColorsRectangle
static void CreateColorsRectangle(Int_t offset, const char *name, UChar_t *rgb)
Create the "rectangular" colors in the color wheel.
Definition: TColor.cxx:1282
kPastel
@ kPastel
Definition: TColor.h:120
kCandy
@ kCandy
Definition: TColor.h:114
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TColor::GetBlue
Float_t GetBlue() const
Definition: TColor.h:59
v
@ v
Definition: rootcling_impl.cxx:3635
kAquamarine
@ kAquamarine
Definition: TColor.h:111
b
#define b(i)
Definition: RSha256.hxx:118
TColor::GetAlpha
Float_t GetAlpha() const
Definition: TColor.h:63
TColor::InvertPalette
static void InvertPalette()
Invert the current color palette.
Definition: TColor.cxx:3133
kTemperatureMap
@ kTemperatureMap
Definition: TColor.h:124
TColor::operator=
TColor & operator=(const TColor &color)
Definition: TColor.cxx:1072
TColor::RGBtoHLS
static void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
Definition: TColor.h:78
TColor::TColor
TColor()
Default constructor.
Definition: TColor.cxx:983
kSouthWest
@ kSouthWest
Definition: TColor.h:123
kBeach
@ kBeach
Definition: TColor.h:113
TColor::~TColor
virtual ~TColor()
Color destructor.
Definition: TColor.cxx:1058
kFruitPunch
@ kFruitPunch
Definition: TColor.h:116
kBrownCyan
@ kBrownCyan
Definition: TColor.h:114
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TColor::GetGrayscale
virtual Float_t GetGrayscale() const
Definition: TColor.h:64
kAtlantic
@ kAtlantic
Definition: TColor.h:112
TColor::Pixel2RGB
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:2089
kSandyTerrain
@ kSandyTerrain
Definition: TColor.h:122
TColor::IsGrayscale
static Bool_t IsGrayscale()
Return whether all colors return grayscale values.
Definition: TColor.cxx:2156
TColor
Definition: TColor.h:19
TColor::GetRGB
virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
Definition: TColor.h:51
TColor::fBlue
Float_t fBlue
Fraction of Blue.
Definition: TColor.h:25
kDarkTerrain
@ kDarkTerrain
Definition: TColor.h:116
h
#define h(i)
Definition: RSha256.hxx:124
kRainBow
@ kRainBow
Definition: TColor.h:108
kDarkBodyRadiator
@ kDarkBodyRadiator
Definition: TColor.h:107
a
auto * a
Definition: textangle.C:12
kBlackBody
@ kBlackBody
Definition: TColor.h:113
kLightTemperature
@ kLightTemperature
Definition: TColor.h:119
TNamed
Definition: TNamed.h:29
kRedBlue
@ kRedBlue
Definition: TColor.h:121
kFuchsia
@ kFuchsia
Definition: TColor.h:117
TColor::GetColorBright
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:1913
TColor::Print
virtual void Print(Option_t *option="") const
Dump this color with its attributes.
Definition: TColor.cxx:1582
kViridis
@ kViridis
Definition: TColor.h:127
TColor::GetRed
Float_t GetRed() const
Definition: TColor.h:57
TColor::CreateColorsGray
static void CreateColorsGray()
Create the Gray scale colors in the Color Wheel.
Definition: TColor.cxx:1246
kGreenPink
@ kGreenPink
Definition: TColor.h:118
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TColor::GetColor
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:1766
kStarryNight
@ kStarryNight
Definition: TColor.h:124
TColor::GetHLS
virtual void GetHLS(Float_t &h, Float_t &l, Float_t &s) const
Definition: TColor.h:53
kBlueGreenYellow
@ kBlueGreenYellow
Definition: TColor.h:113
kSolar
@ kSolar
Definition: TColor.h:123
kGreyScale
@ kGreyScale
Definition: TColor.h:107
TColor::SetAlpha
virtual void SetAlpha(Float_t a)
Definition: TColor.h:67
unsigned int
kPearl
@ kPearl
Definition: TColor.h:120
kThermometer
@ kThermometer
Definition: TColor.h:125
kLake
@ kLake
Definition: TColor.h:118
EColorPalette
EColorPalette
Definition: TColor.h:107
TColor::CreateColorWheel
static void CreateColorWheel()
Static function steering the creation of all colors in the color wheel.
Definition: TColor.cxx:1302
Double_t
double Double_t
Definition: RtypesCore.h:59
kOcean
@ kOcean
Definition: TColor.h:110
kGistEarth
@ kGistEarth
Definition: TColor.h:127
TColor::CreateGradientColorTable
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:2225
kWaterMelon
@ kWaterMelon
Definition: TColor.h:126
UChar_t
unsigned char UChar_t
Definition: RtypesCore.h:38
kRust
@ kRust
Definition: TColor.h:122
TColor::GetColorTransparent
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1976
TObject
Definition: TObject.h:37
TColor::fNumber
Int_t fNumber
Color number identifier.
Definition: TColor.h:21
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
kColorPrintableOnGrey
@ kColorPrintableOnGrey
Definition: TColor.h:110
TColor::Copy
void Copy(TObject &color) const
Copy this color to obj.
Definition: TColor.cxx:1230
TColor::GetColorDark
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:1945
name
char name[80]
Definition: TGX11.cxx:110
kNeon
@ kNeon
Definition: TColor.h:120
TColor::fSaturation
Float_t fSaturation
Saturation.
Definition: TColor.h:28
kCoffee
@ kCoffee
Definition: TColor.h:115
TColor::HSV2RGB
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:1517
kSienna
@ kSienna
Definition: TColor.h:123
TColor::RGB2Pixel
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:2051
kFall
@ kFall
Definition: TColor.h:116
kCubehelix
@ kCubehelix
Definition: TColor.h:109
TColor::SetPalette
static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.)
Static function.
Definition: TColor.cxx:2414
TColor::RGB2HLS
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:1591
TColor::GetNumberOfColors
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Definition: TColor.cxx:1410
kCividis
@ kCividis
Definition: TColor.h:127
kCool
@ kCool
Definition: TColor.h:126
kIsland
@ kIsland
Definition: TColor.h:118
TColor::InitializeColors
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition: TColor.cxx:1083
TColor::GetGreen
Float_t GetGreen() const
Definition: TColor.h:58
kBlueRedYellow
@ kBlueRedYellow
Definition: TColor.h:110
TColor::HLS2RGB
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:1451
kAlpine
@ kAlpine
Definition: TColor.h:111
TColor::GetHue
Float_t GetHue() const
Definition: TColor.h:60
TColor::fAlpha
Float_t fAlpha
Alpha (transparency)
Definition: TColor.h:29
TArrayI
Definition: TArrayI.h:27
kInvertedDarkBodyRadiator
@ kInvertedDarkBodyRadiator
Definition: TColor.h:108
TColor::AsHexString
const char * AsHexString() const
Return color as hexadecimal string.
Definition: TColor.cxx:1209
int
kGreyYellow
@ kGreyYellow
Definition: TColor.h:117
TColor::SetColorThreshold
static void SetColorThreshold(Float_t t)
This method specifies the color threshold used by GetColor to retrieve a color.
Definition: TColor.cxx:1838
TColor::GetPalette
static const TArrayI & GetPalette()
Static function returning the current active palette.
Definition: TColor.cxx:1402
TColor::GetNumber
Int_t GetNumber() const
Definition: TColor.h:55
g
#define g(i)
Definition: RSha256.hxx:123
kValentine
@ kValentine
Definition: TColor.h:125