Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include <array>
18#include <vector>
19
20class TArrayI;
21
22class TColor : public TNamed {
23protected:
24 Int_t fNumber; ///< Color number identifier
25private:
26 Float_t fRed; ///< Fraction of Red
27 Float_t fGreen; ///< Fraction of Green
28 Float_t fBlue; ///< Fraction of Blue
29 Float_t fHue; ///< Hue
30 Float_t fLight; ///< Light
31 Float_t fSaturation; ///< Saturation
32 Float_t fAlpha; ///< Alpha (transparency)
33
34 void Allocate();
36
37public:
38 TColor();
39 TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char *name="", Float_t a = 1);
41 TColor(const TColor &color);
42 TColor &operator=(const TColor &color);
43 virtual ~TColor();
44 const char *AsHexString() const;
45 void Copy(TObject &color) const override;
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 CreateColorTableFromFile(TString fileName, Float_t alpha=1.);
52 Double_t* Red, Double_t* Green, Double_t* Blue, UInt_t NColors, Float_t alpha=1., Bool_t setPalette=kTRUE);
53 static Int_t GetColorPalette(Int_t i);
54 static Int_t GetNumberOfColors();
55 virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
56 { r=GetRed(); g=GetGreen(); b=GetBlue(); }
57 virtual void GetHLS(Float_t &h, Float_t &l, Float_t &s) const
58 { h=GetHue(); l=GetLight(); s=GetSaturation(); }
59 Int_t GetNumber() const { return fNumber; }
60 ULong_t GetPixel() const;
61 Float_t GetRed() const { return IsGrayscale() ? GetGrayscale() : fRed; }
62 Float_t GetGreen() const { return IsGrayscale() ? GetGrayscale() : fGreen; }
63 Float_t GetBlue() const { return IsGrayscale() ? GetGrayscale() : fBlue; }
64 Float_t GetHue() const { return fHue; }
65 Float_t GetLight() const { return fLight; }
66 Float_t GetSaturation() const { return IsGrayscale() ? 0 : fSaturation; }
67 Float_t GetAlpha() const { return fAlpha; }
68 virtual Float_t GetGrayscale() const { /*ITU*/ return 0.299f*fRed + 0.587f*fGreen + 0.114f*fBlue; }
69 void ls(Option_t *option="") const override;
70 void Print(Option_t *option="") const override;
71 virtual void SetAlpha(Float_t a) { fAlpha = a; }
72 virtual void SetRGB(Float_t r, Float_t g, Float_t b);
73 void SetName(const char* name) override;
74
75 static void InitializeColors();
76 static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b);
77 static void HLS2RGB(Int_t h, Int_t l, Int_t s, Int_t &r, Int_t &g, Int_t &b);
79 { TColor::HLS2RGB(h, l, s, r, g, b); } // backward compatible
80 static void HSV2RGB(Float_t h, Float_t s, Float_t v, Float_t &r, Float_t &g, Float_t &b);
81 static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s);
82 static void RGB2HLS(Int_t r, Int_t g, Int_t b, Int_t &h, Int_t &l, Int_t &s);
84 { TColor::RGB2HLS(r, g, b, h, l, s); } // backward compatible
85 static void RGB2HSV(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &s, Float_t &v);
86 static Int_t GetColor(const char *hexcolor);
87 static Int_t GetColor(Float_t r, Float_t g, Float_t b, Float_t a = 1.);
88 static Int_t GetColor(Int_t r, Int_t g, Int_t b, Float_t a = 1.);
90 static Int_t GetColorBright(Int_t color);
91 static Int_t GetColorDark(Int_t color);
93 static Int_t GetColorByName(const char *colorname);
94 static Int_t GetFreeColorIndex();
96 static const TArrayI& GetPalette();
97 static Int_t GetLinearGradient(Double_t angle, const std::vector<Int_t> &colors, const std::vector<Double_t> &positions = {});
98 static Int_t GetRadialGradient(Double_t r, const std::vector<Int_t> &colors, const std::vector<Double_t> &positions = {});
100 static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b);
102 static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b);
103 static void Pixel2RGB(ULong_t pixel, Float_t &r, Float_t &g, Float_t &b);
104 static const char *PixelAsHexString(ULong_t pixel);
105 static Bool_t SaveColor(std::ostream &out, Int_t ci);
106 static void SetColorThreshold(Float_t t);
108 static void InvertPalette();
109 static Bool_t IsGrayscale();
110 static void ListColors(Int_t ci1=0, Int_t ci2 = 0, Bool_t showEmpty = kFALSE);
111 static void SetGrayscale(Bool_t set = kTRUE);
112 static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.);
113
114 ClassDefOverride(TColor,2) //Color defined by RGB or HLS
115};
116
139
141public:
142 TColorNumber(Int_t color) : fNumber{color} {}
143 TColorNumber(std::string const &color);
144 TColorNumber(std::array<Float_t, 3> rgb);
145 Int_t number() const { return fNumber; }
146
147private:
148 Int_t fNumber; ///< Color number identifier
149};
150
151#endif
152
#define b(i)
Definition RSha256.hxx:100
#define g(i)
Definition RSha256.hxx:105
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned char UChar_t
Definition RtypesCore.h:38
unsigned long ULong_t
Definition RtypesCore.h:55
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
EColorPalette
Definition TColor.h:117
@ kFall
Definition TColor.h:126
@ kStarryNight
Definition TColor.h:134
@ kAtlantic
Definition TColor.h:122
@ kIsland
Definition TColor.h:128
@ kBlackBody
Definition TColor.h:123
@ kFruitPunch
Definition TColor.h:126
@ kArmy
Definition TColor.h:121
@ kAurora
Definition TColor.h:122
@ kBrownCyan
Definition TColor.h:124
@ kBeach
Definition TColor.h:123
@ kAquamarine
Definition TColor.h:121
@ kPastel
Definition TColor.h:130
@ kCubehelix
Definition TColor.h:119
@ kAvocado
Definition TColor.h:122
@ kGreenRedViolet
Definition TColor.h:119
@ kAlpine
Definition TColor.h:121
@ kVisibleSpectrum
Definition TColor.h:135
@ kCMYK
Definition TColor.h:124
@ kInvertedDarkBodyRadiator
Definition TColor.h:118
@ kWaterMelon
Definition TColor.h:136
@ kOcean
Definition TColor.h:120
@ kDarkBodyRadiator
Definition TColor.h:117
@ kDarkTerrain
Definition TColor.h:126
@ kLightTemperature
Definition TColor.h:129
@ kRust
Definition TColor.h:132
@ kCopper
Definition TColor.h:136
@ kTemperatureMap
Definition TColor.h:134
@ kSolar
Definition TColor.h:133
@ kRedBlue
Definition TColor.h:131
@ kDeepSea
Definition TColor.h:117
@ kRainBow
Definition TColor.h:118
@ kSouthWest
Definition TColor.h:133
@ kPlum
Definition TColor.h:131
@ kGreenBrownTerrain
Definition TColor.h:127
@ kGreyYellow
Definition TColor.h:127
@ kGreyScale
Definition TColor.h:117
@ kRose
Definition TColor.h:132
@ kRainbow
Definition TColor.h:138
@ kSunset
Definition TColor.h:134
@ kCoffee
Definition TColor.h:125
@ kGreenPink
Definition TColor.h:128
@ kColorPrintableOnGrey
Definition TColor.h:120
@ kSienna
Definition TColor.h:133
@ kBlueYellow
Definition TColor.h:118
@ kBlueRedYellow
Definition TColor.h:120
@ kValentine
Definition TColor.h:135
@ kDarkRainbow
Definition TColor.h:138
@ kSandyTerrain
Definition TColor.h:132
@ kDarkRainBow
Definition TColor.h:125
@ kViridis
Definition TColor.h:137
@ kCandy
Definition TColor.h:124
@ kCherry
Definition TColor.h:125
@ kNeon
Definition TColor.h:130
@ kBird
Definition TColor.h:119
@ kFuchsia
Definition TColor.h:127
@ kBlueGreenYellow
Definition TColor.h:123
@ kPearl
Definition TColor.h:130
@ kPigeon
Definition TColor.h:131
@ kCividis
Definition TColor.h:137
@ kCool
Definition TColor.h:136
@ kLake
Definition TColor.h:128
@ kMint
Definition TColor.h:129
@ kGistEarth
Definition TColor.h:137
@ kThermometer
Definition TColor.h:135
@ kLightTerrain
Definition TColor.h:129
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void pixel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint angle
char name[80]
Definition TGX11.cxx:110
Color * colors
Definition X3DBuffer.c:21
Array of integers (32 bits per element).
Definition TArrayI.h:27
Int_t number() const
Definition TColor.h:145
Int_t fNumber
Color number identifier.
Definition TColor.h:148
TColorNumber(Int_t color)
Definition TColor.h:142
The color creation and management class.
Definition TColor.h:22
void Print(Option_t *option="") const override
Dump this color with its attributes.
Definition TColor.cxx:1711
static Int_t GetFirstFreeColorIndex()
Static function: Returns the first free color greater in the list of colors.
Definition TColor.cxx:2382
Float_t fSaturation
Saturation.
Definition TColor.h:31
static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.)
Static function.
Definition TColor.cxx:2929
static Int_t GetLinearGradient(Double_t angle, const std::vector< Int_t > &colors, const std::vector< Double_t > &positions={})
Static function: Returns the linear gradient color number corresponding to specified parameters.
Definition TColor.cxx:2214
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:1580
virtual void SetRGB(Float_t r, Float_t g, Float_t b)
Initialize this color and its "dark" and "bright" associated colors.
Definition TColor.cxx:1854
static void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
Definition TColor.h:83
static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei)
Static method. Auxiliary to HLS2RGB().
Definition TColor.cxx:1605
virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
Definition TColor.h:55
static Int_t GetRadialGradient(Double_t r, const std::vector< Int_t > &colors, const std::vector< Double_t > &positions={})
Static function: Returns the radial gradient color number corresponding to specified parameters.
Definition TColor.cxx:2291
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Definition TColor.cxx:1508
static const TArrayI & GetPalette()
Static function returning the current active palette.
Definition TColor.cxx:1520
Float_t GetRed() const
Definition TColor.h:61
void ls(Option_t *option="") const override
List this color with its attributes.
Definition TColor.cxx:1702
static Bool_t 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:2551
Float_t fLight
Light.
Definition TColor.h:30
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:2479
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2441
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:1775
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:1924
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition TColor.cxx:1171
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:1646
Float_t fAlpha
Alpha (transparency)
Definition TColor.h:32
void Copy(TObject &color) const override
Copy this color to obj.
Definition TColor.cxx:1350
static void InvertPalette()
Invert the current color palette.
Definition TColor.cxx:3648
Float_t fHue
Hue.
Definition TColor.h:29
static void CreateColorWheel()
Static function steering the creation of all colors in the color wheel.
Definition TColor.cxx:1420
virtual void GetHLS(Float_t &h, Float_t &l, Float_t &s) const
Definition TColor.h:57
static Int_t GetColorByName(const char *colorname)
Static method returning color index for a color specified by name.
Definition TColor.cxx:2077
void SetName(const char *name) override
Set the color name and change also the name of the "dark" and "bright" associated colors if they exis...
Definition TColor.cxx:1830
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:2091
static Bool_t IsGrayscale()
Return whether all colors return grayscale values.
Definition TColor.cxx:2592
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:2517
const char * AsHexString() const
Return color as hexadecimal string.
Definition TColor.cxx:1329
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:2134
Float_t GetAlpha() const
Definition TColor.h:67
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., Bool_t setPalette=kTRUE)
Static function creating a color table with several connected linear gradients.
Definition TColor.cxx:2738
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:2538
void Allocate()
Make this color known to the graphics system.
Definition TColor.cxx:1908
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition TColor.cxx:1563
static Int_t CreateColorTableFromFile(TString fileName, Float_t alpha=1.)
Static function creating a color palette based on an input text file.
Definition TColor.cxx:2632
static void SetColorThreshold(Float_t t)
This method specifies the color threshold used by GetColor to retrieve a color.
Definition TColor.cxx:1991
static Bool_t DefinedColors(Int_t set_always_on=0)
Static method returning kTRUE if some new colors have been defined after initialisation or since the ...
Definition TColor.cxx:1541
Float_t GetLight() const
Definition TColor.h:65
Float_t GetHue() const
Definition TColor.h:64
Float_t fGreen
Fraction of Green.
Definition TColor.h:27
static void CreateColorsCircle(Int_t offset, const char *name, UChar_t *rgb)
Create the "circle" colors in the color wheel.
Definition TColor.cxx:1382
Int_t GetNumber() const
Definition TColor.h:59
Float_t GetBlue() const
Definition TColor.h:63
TColor & operator=(const TColor &color)
Definition TColor.cxx:1159
Float_t GetGreen() const
Definition TColor.h:62
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Definition TColor.cxx:1528
static Int_t GetFreeColorIndex()
Static function: Returns the free color index greater than the highest defined color index.
Definition TColor.cxx:2368
Float_t GetSaturation() const
Definition TColor.h:66
static void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
Definition TColor.h:78
static void ListColors(Int_t ci1=0, Int_t ci2=0, Bool_t showEmpty=kFALSE)
List nb colors from the color index ci.
Definition TColor.cxx:2399
TColor()
Default constructor.
Definition TColor.cxx:1065
Int_t fNumber
Color number identifier.
Definition TColor.h:24
static void CreateColorsRectangle(Int_t offset, const char *name, UChar_t *rgb)
Create the "rectangular" colors in the color wheel.
Definition TColor.cxx:1401
Float_t fBlue
Fraction of Blue.
Definition TColor.h:28
static void CreateColorsGray()
Create the Gray scale colors in the Color Wheel.
Definition TColor.cxx:1366
virtual void SetAlpha(Float_t a)
Definition TColor.h:71
virtual Float_t GetGrayscale() const
Definition TColor.h:68
virtual ~TColor()
Color destructor.
Definition TColor.cxx:1142
Float_t fRed
Fraction of Red.
Definition TColor.h:26
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:1720
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2178
static void SetGrayscale(Bool_t set=kTRUE)
Set whether all colors should return grayscale values.
Definition TColor.cxx:2600
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
TLine l
Definition textangle.C:4