File indexing completed on 2025-09-17 09:15:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TColor
0013 #define ROOT_TColor
0014
0015 #include "TNamed.h"
0016
0017 #include <array>
0018 #include <vector>
0019
0020 class TArrayI;
0021
0022 class TColor : public TNamed {
0023 protected:
0024 Int_t fNumber;
0025 private:
0026 Float_t fRed;
0027 Float_t fGreen;
0028 Float_t fBlue;
0029 Float_t fHue;
0030 Float_t fLight;
0031 Float_t fSaturation;
0032 Float_t fAlpha;
0033
0034 void Allocate();
0035 static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei);
0036
0037 public:
0038 TColor();
0039 TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char *name="", Float_t a = 1);
0040 TColor(Float_t r, Float_t g, Float_t b, Float_t a = 1);
0041 TColor(const TColor &color);
0042 TColor &operator=(const TColor &color);
0043 virtual ~TColor();
0044 const char *AsHexString() const;
0045 void Copy(TObject &color) const override;
0046 static void CreateColorWheel();
0047 static void CreateColorsGray();
0048 static void CreateColorsCircle(Int_t offset, const char *name, UChar_t *rgb);
0049 static void CreateColorsRectangle(Int_t offset, const char *name, UChar_t *rgb);
0050 static Int_t CreateColorTableFromFile(TString fileName, Float_t alpha=1.);
0051 static Int_t CreateGradientColorTable(UInt_t Number, Double_t* Stops,
0052 Double_t* Red, Double_t* Green, Double_t* Blue, UInt_t NColors, Float_t alpha=1., Bool_t setPalette=kTRUE);
0053 static Int_t GetColorPalette(Int_t i);
0054 static Int_t GetNumberOfColors();
0055 virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
0056 { r=GetRed(); g=GetGreen(); b=GetBlue(); }
0057 virtual void GetHLS(Float_t &h, Float_t &l, Float_t &s) const
0058 { h=GetHue(); l=GetLight(); s=GetSaturation(); }
0059 Int_t GetNumber() const { return fNumber; }
0060 ULong_t GetPixel() const;
0061 Float_t GetRed() const { return IsGrayscale() ? GetGrayscale() : fRed; }
0062 Float_t GetGreen() const { return IsGrayscale() ? GetGrayscale() : fGreen; }
0063 Float_t GetBlue() const { return IsGrayscale() ? GetGrayscale() : fBlue; }
0064 Float_t GetHue() const { return fHue; }
0065 Float_t GetLight() const { return fLight; }
0066 Float_t GetSaturation() const { return IsGrayscale() ? 0 : fSaturation; }
0067 Float_t GetAlpha() const { return fAlpha; }
0068 virtual Float_t GetGrayscale() const { return 0.299f*fRed + 0.587f*fGreen + 0.114f*fBlue; }
0069 void ls(Option_t *option="") const override;
0070 void Print(Option_t *option="") const override;
0071 virtual void SetAlpha(Float_t a) { fAlpha = a; }
0072 virtual void SetRGB(Float_t r, Float_t g, Float_t b);
0073 void SetName(const char* name) override;
0074
0075 static void InitializeColors();
0076 static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b);
0077 static void HLS2RGB(Int_t h, Int_t l, Int_t s, Int_t &r, Int_t &g, Int_t &b);
0078 static void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
0079 { TColor::HLS2RGB(h, l, s, r, g, b); }
0080 static void HSV2RGB(Float_t h, Float_t s, Float_t v, Float_t &r, Float_t &g, Float_t &b);
0081 static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s);
0082 static void RGB2HLS(Int_t r, Int_t g, Int_t b, Int_t &h, Int_t &l, Int_t &s);
0083 static void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
0084 { TColor::RGB2HLS(r, g, b, h, l, s); }
0085 static void RGB2HSV(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &s, Float_t &v);
0086 static Int_t GetColor(const char *hexcolor);
0087 static Int_t GetColor(Float_t r, Float_t g, Float_t b, Float_t a = 1.);
0088 static Int_t GetColor(Int_t r, Int_t g, Int_t b, Float_t a = 1.);
0089 static Int_t GetColor(ULong_t pixel);
0090 static Int_t GetColorBright(Int_t color);
0091 static Int_t GetColorDark(Int_t color);
0092 static Int_t GetColorTransparent(Int_t color, Float_t a);
0093 static Int_t GetColorByName(const char *colorname);
0094 static Int_t GetFreeColorIndex();
0095 static Int_t GetFirstFreeColorIndex();
0096 static const TArrayI& GetPalette();
0097 static Int_t GetLinearGradient(Double_t angle, const std::vector<Int_t> &colors, const std::vector<Double_t> &positions = {});
0098 static Int_t GetRadialGradient(Double_t r, const std::vector<Int_t> &colors, const std::vector<Double_t> &positions = {});
0099 static ULong_t Number2Pixel(Int_t ci);
0100 static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b);
0101 static ULong_t RGB2Pixel(Float_t r, Float_t g, Float_t b);
0102 static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b);
0103 static void Pixel2RGB(ULong_t pixel, Float_t &r, Float_t &g, Float_t &b);
0104 static const char *PixelAsHexString(ULong_t pixel);
0105 static TString SavePrimitiveColor(Int_t ci);
0106 static Bool_t SaveColor(std::ostream &out, Int_t ci);
0107 static void SaveColorsPalette(std::ostream &out);
0108 static void SetColorThreshold(Float_t t);
0109 static Bool_t DefinedColors(Int_t set_always_on = 0);
0110 static void InvertPalette();
0111 static Bool_t IsGrayscale();
0112 static void ListColors(Int_t ci1=0, Int_t ci2 = 0, Bool_t showEmpty = kFALSE);
0113 static void SetGrayscale(Bool_t set = kTRUE);
0114 static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.);
0115
0116 ClassDefOverride(TColor,2)
0117 };
0118
0119 enum EColorPalette {kDeepSea=51, kGreyScale=52, kDarkBodyRadiator=53,
0120 kBlueYellow= 54, kRainBow=55, kInvertedDarkBodyRadiator=56,
0121 kBird=57, kCubehelix=58, kGreenRedViolet=59,
0122 kBlueRedYellow=60, kOcean=61, kColorPrintableOnGrey=62,
0123 kAlpine=63, kAquamarine=64, kArmy=65,
0124 kAtlantic=66, kAurora=67, kAvocado=68,
0125 kBeach=69, kBlackBody=70, kBlueGreenYellow=71,
0126 kBrownCyan=72, kCMYK=73, kCandy=74,
0127 kCherry=75, kCoffee=76, kDarkRainBow=77,
0128 kDarkTerrain=78, kFall=79, kFruitPunch=80,
0129 kFuchsia=81, kGreyYellow=82, kGreenBrownTerrain=83,
0130 kGreenPink=84, kIsland=85, kLake=86,
0131 kLightTemperature=87, kLightTerrain=88, kMint=89,
0132 kNeon=90, kPastel=91, kPearl=92,
0133 kPigeon=93, kPlum=94, kRedBlue=95,
0134 kRose=96, kRust=97, kSandyTerrain=98,
0135 kSienna=99, kSolar=100, kSouthWest=101,
0136 kStarryNight=102, kSunset=103, kTemperatureMap=104,
0137 kThermometer=105, kValentine=106, kVisibleSpectrum=107,
0138 kWaterMelon=108, kCool=109, kCopper=110,
0139 kGistEarth=111, kViridis=112, kCividis=113,
0140 kRainbow=kRainBow, kDarkRainbow=kDarkRainBow};
0141
0142 class TColorNumber {
0143 public:
0144 TColorNumber(Int_t color) : fNumber{color} {}
0145 TColorNumber(std::string const &color);
0146 TColorNumber(std::array<Float_t, 3> rgb);
0147 Int_t number() const { return fNumber; }
0148
0149 private:
0150 Int_t fNumber;
0151 };
0152
0153 #endif
0154