ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TColor //
18 // //
19 // Color defined by RGB or HLS. //
20 // At initialization time, a table of colors is generated. This linked //
21 // list can be accessed from the ROOT object //
22 // (see TROOT::GetListOfColors()). When a color is defined in the range //
23 // of [1,50], two "companion" colors are also defined: //
24 // - the dark version (color_index + 100) //
25 // - the bright version (color_index + 150) //
26 // The dark and bright color are used to give 3-D effects when drawing //
27 // various boxes (see TWbox, TPave, TPaveText, TPaveLabel,etc). //
28 // //
29 // This is the list of currently supported basic colors (here dark and //
30 // bright colors are not shown). //
31 //Begin_Html
32 /*
33 <img src="gif/colors.gif">
34 */
35 //End_Html
36 // //
37 //////////////////////////////////////////////////////////////////////////
38 
39 #ifndef ROOT_TNamed
40 #include "TNamed.h"
41 #endif
42 #ifndef ROOT_TArrayI
43 #include "TArrayI.h"
44 #endif
45 
46 
47 class TColor : public TNamed {
48 protected:
49  Int_t fNumber; //Color number identifier
50 private:
51  Float_t fRed; //Fraction of Red
52  Float_t fGreen; //Fraction of Green
53  Float_t fBlue; //Fraction of Blue
54  Float_t fHue; //Hue
55  Float_t fLight; //Light
56  Float_t fSaturation; //Saturation
57  Float_t fAlpha; //Alpha (transparency)
58  // static Bool_t fgGrayscaleMode;//if set, GetColor will return grayscale
59  // static TArrayI fgPalette; //Color palette
60 
61  void Allocate();
62  static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei);
63 
64 public:
65  TColor();
66  TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char *name="", Float_t a = 1);
67  TColor(const TColor &color);
68  virtual ~TColor();
69  const char *AsHexString() const;
70  void Copy(TObject &color) const;
71  static void CreateColorWheel();
72  static void CreateColorsGray();
73  static void CreateColorsCircle(Int_t offset, const char *name, UChar_t *rgb);
74  static void CreateColorsRectangle(Int_t offset, const char *name, UChar_t *rgb);
75  static Int_t CreateGradientColorTable(UInt_t Number, Double_t* Stops,
76  Double_t* Red, Double_t* Green, Double_t* Blue, UInt_t NColors, Float_t alpha=1.);
77  static Int_t GetColorPalette(Int_t i);
78  static Int_t GetNumberOfColors();
79  virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
80  { r=GetRed(); g=GetGreen(); b=GetBlue(); }
81  virtual void GetHLS(Float_t &h, Float_t &l, Float_t &s) const
82  { h=GetHue(); l=GetLight(); s=GetSaturation(); }
83  Int_t GetNumber() const { return fNumber; }
84  ULong_t GetPixel() const;
85  Float_t GetRed() const { return IsGrayscale() ? GetGrayscale() : fRed; }
86  Float_t GetGreen() const { return IsGrayscale() ? GetGrayscale() : fGreen; }
87  Float_t GetBlue() const { return IsGrayscale() ? GetGrayscale() : fBlue; }
88  Float_t GetHue() const { return fHue; }
89  Float_t GetLight() const { return fLight; }
90  Float_t GetSaturation() const { return IsGrayscale() ? 0 : fSaturation; }
91  Float_t GetAlpha() const { return fAlpha; }
92  virtual Float_t GetGrayscale() const { /*ITU*/ return 0.299f*fRed + 0.587f*fGreen + 0.114f*fBlue; }
93  virtual void ls(Option_t *option="") const;
94  virtual void Print(Option_t *option="") const;
95  virtual void SetAlpha(Float_t a) { fAlpha = a; }
96  virtual void SetRGB(Float_t r, Float_t g, Float_t b);
97 
98  static void InitializeColors();
99  static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b);
100  static void HLS2RGB(Int_t h, Int_t l, Int_t s, Int_t &r, Int_t &g, Int_t &b);
102  { TColor::HLS2RGB(h, l, s, r, g, b); } // backward compatible
103  static void HSV2RGB(Float_t h, Float_t s, Float_t v, Float_t &r, Float_t &g, Float_t &b);
104  static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s);
105  static void RGB2HLS(Int_t r, Int_t g, Int_t b, Int_t &h, Int_t &l, Int_t &s);
107  { TColor::RGB2HLS(r, g, b, h, l, s); } // backward compatible
108  static void RGB2HSV(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &s, Float_t &v);
109  static Int_t GetColor(const char *hexcolor);
110  static Int_t GetColor(Float_t r, Float_t g, Float_t b);
111  static Int_t GetColor(Int_t r, Int_t g, Int_t b);
112  static Int_t GetColor(ULong_t pixel);
113  static Int_t GetColorBright(Int_t color);
114  static Int_t GetColorDark(Int_t color);
115  static Int_t GetColorTransparent(Int_t color, Float_t a);
116  static ULong_t Number2Pixel(Int_t ci);
117  static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b);
118  static ULong_t RGB2Pixel(Float_t r, Float_t g, Float_t b);
119  static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b);
120  static void Pixel2RGB(ULong_t pixel, Float_t &r, Float_t &g, Float_t &b);
121  static const char *PixelAsHexString(ULong_t pixel);
122  static void SaveColor(std::ostream &out, Int_t ci);
123  static Bool_t IsGrayscale();
124  static void SetGrayscale(Bool_t set = kTRUE);
125  static void SetPalette(Int_t ncolors, Int_t *colors,Float_t alpha=1.);
126 
127  ClassDef(TColor,2) //Color defined by RGB or HLS
128 };
129 
137  kBrownCyan=72, kCMYK=73, kCandy=74,
143  kNeon=90, kPastel=91, kPearl=92,
144  kPigeon=93, kPlum=94, kRedBlue=95,
146  kSienna=99, kSolar=100, kSouthWest=101,
149  kWaterMelon=108, kCool=109, kCopper=110,
150  kGistEarth=111, kViridis=112};
151 #endif
152 
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:777
Float_t fBlue
Definition: TColor.h:53
virtual void SetAlpha(Float_t a)
Definition: TColor.h:95
static Bool_t IsGrayscale()
Return whether all colors return grayscale values.
Definition: TColor.cxx:1362
Float_t fHue
Definition: TColor.h:54
float Float_t
Definition: RtypesCore.h:53
Definition: TColor.h:145
const char Option_t
Definition: RtypesCore.h:62
tuple offset
Definition: tree.py:93
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:1165
EColorPalette
Definition: TColor.h:130
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:1324
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:909
Definition: TColor.h:143
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Definition: TColor.cxx:684
Definition: TColor.h:141
virtual void ls(Option_t *option="") const
List this color with its attributes.
Definition: TColor.cxx:833
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:101
Float_t GetGreen() const
Definition: TColor.h:86
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition: TColor.cxx:694
Float_t fAlpha
Definition: TColor.h:57
static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.)
Static function.
Definition: TColor.cxx:1642
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:1312
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Definition: TColor.cxx:672
#define ClassDef(name, id)
Definition: Rtypes.h:254
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Definition: TColor.h:139
Float_t GetBlue() const
Definition: TColor.h:87
Definition: TColor.h:145
Float_t fLight
Definition: TColor.h:55
Float_t GetLight() const
Definition: TColor.h:89
Float_t fGreen
Definition: TColor.h:52
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:1257
char * out
Definition: TBase64.cxx:29
virtual void Print(Option_t *option="") const
Dump this color with its attributes.
Definition: TColor.cxx:842
virtual ~TColor()
Color destructor.
Definition: TColor.cxx:346
Definition: TColor.h:144
Float_t GetSaturation() const
Definition: TColor.h:90
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:851
static void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
Definition: TColor.h:106
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:711
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:1133
ROOT::R::TRInterface & r
Definition: Object.C:4
SVector< double, 2 > v
Definition: Dict.h:5
Float_t fSaturation
Definition: TColor.h:56
static void CreateColorsRectangle(Int_t offset, const char *name, UChar_t *rgb)
Create the "rectangular" colors in the color wheel.
Definition: TColor.cxx:564
virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
Definition: TColor.h:79
const char * AsHexString() const
Return color as hexadecimal string.
Definition: TColor.cxx:491
unsigned int UInt_t
Definition: RtypesCore.h:42
Definition: TColor.h:142
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:1023
Definition: TColor.h:149
TColor()
Default constructor.
Definition: TColor.cxx:295
Definition: TColor.h:133
Definition: TColor.h:137
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1196
Int_t fNumber
Definition: TColor.h:49
static void CreateColorWheel()
Static function steering the creation of all colors in the color wheel.
Definition: TColor.cxx:584
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:1219
Color * colors
Definition: X3DBuffer.c:19
virtual void GetHLS(Float_t &h, Float_t &l, Float_t &s) const
Definition: TColor.h:81
Definition: TColor.h:137
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:528
virtual void SetRGB(Float_t r, Float_t g, Float_t b)
Initialize this color and its associated colors.
Definition: TColor.cxx:962
Definition: TColor.h:143
The color creation and management class.
Definition: TColor.h:47
Definition: TColor.h:136
Float_t GetRed() const
Definition: TColor.h:85
Definition: TColor.h:146
Float_t fRed
Definition: TColor.h:51
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
Definition: TColor.h:134
static void SetGrayscale(Bool_t set=kTRUE)
Set whether all colors should return grayscale values.
Definition: TColor.cxx:1370
static void CreateColorsCircle(Int_t offset, const char *name, UChar_t *rgb)
Create the "circle" colors in the color wheel.
Definition: TColor.cxx:544
Float_t GetAlpha() const
Definition: TColor.h:91
virtual Float_t GetGrayscale() const
Definition: TColor.h:92
Definition: TColor.h:132
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition: TColor.cxx:365
unsigned char UChar_t
Definition: RtypesCore.h:34
Float_t GetHue() const
Definition: TColor.h:88
void Allocate()
Make this color known to the graphics system.
Definition: TColor.cxx:1008
const Bool_t kTRUE
Definition: Rtypes.h:91
void Copy(TObject &color) const
Copy this color to obj.
Definition: TColor.cxx:512
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:1431
static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei)
Static method. Auxiliary to HLS2RGB().
Definition: TColor.cxx:736
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:1295
Int_t GetNumber() const
Definition: TColor.h:83