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