library: libCore #include "TColor.h"

# TColor

class description - source file - inheritance tree (.pdf)

## class TColor : public TNamed

| Inheritance Chart:

`TObject`

<-

`TNamed`

<-

`TColor`

        private:

                    void Allocate()
          static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei)

        public:

                             TColor()
                             TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char* name = "", Float_t a = 1)
                             TColor(const TColor& color)
                     virtual ~TColor()
                 const char* AsHexString() const
              static TClass* Class()
                virtual void Copy(TObject& color) const
                     Float_t GetAlpha() const
                     Float_t GetBlue() const
                static Int_t GetColor(const char* hexcolor)
                static Int_t GetColor(Float_t r, Float_t g, Float_t b)
                static Int_t GetColor(Int_t r, Int_t g, Int_t b)
                static Int_t GetColor(ULong_t pixel)
                     Float_t GetGreen() const
                virtual void GetHLS(Float_t& h, Float_t& l, Float_t& s) const
                     Float_t GetHue() const
                     Float_t GetLight() const
                       Int_t GetNumber() const
                     ULong_t GetPixel() const
                     Float_t GetRed() const
                virtual void GetRGB(Float_t& r, Float_t& g, Float_t& b) const
                     Float_t GetSaturation() const
                 static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t& r, Float_t& g, Float_t& b)
                 static void HLS2RGB(Int_t h, Int_t l, Int_t s, Int_t& r, Int_t& g, Int_t& b)
                 static void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t& r, Float_t& g, Float_t& b)
             virtual TClass* IsA() const
                virtual void ls(Option_t* option = "") const
              static ULong_t Number2Pixel(Int_t ci)
                     TColor& operator=(const TColor&)
                 static void Pixel2RGB(ULong_t pixel, Int_t& r, Int_t& g, Int_t& b)
                 static void Pixel2RGB(ULong_t pixel, Float_t& r, Float_t& g, Float_t& b)
          static const char* PixelAsHexString(ULong_t pixel) const
                virtual void Print(Option_t* option = "") const
                 static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t& h, Float_t& l, Float_t& s)
                 static void RGB2HLS(Int_t r, Int_t g, Int_t b, Int_t& h, Int_t& l, Int_t& s)
              static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)
              static ULong_t RGB2Pixel(Float_t r, Float_t g, Float_t b)
                 static void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t& h, Float_t& l, Float_t& s)
                 static void SaveColor(ofstream& out, Int_t ci)
                virtual void SetRGB(Float_t r, Float_t g, Float_t b)
                virtual void ShowMembers(TMemberInspector& insp, char* parent)
                virtual void Streamer(TBuffer& b)
                        void StreamerNVirtual(TBuffer& b)

### Data Members

        private:

            Int_t fNumber      Color number identifier
          Float_t fRed         Fraction of Red
          Float_t fGreen       Fraction of Green
          Float_t fBlue        Fraction of Blue
          Float_t fHue         Hue
          Float_t fLight       Light
          Float_t fSaturation  Saturation
          Float_t fAlpha       Alpha (transparency)

## Class Description

     TColor

     Color defined by RGB or HLS.
     At initialization time, a table of colors is generated. This linked
     list can be accessed from the ROOT object
     (see TROOT::GetListOfColors()). When a color is defined in the range
     of [1,50], two "companion" colors are also defined:
        - the dark version (color_index + 100)
        - the bright version (color_index + 150)
     The dark and bright color are used to give 3-D effects when drawing
     various boxes (see TWbox, TPave, TPaveText, TPaveLabel,etc).

     This is the list of currently supported basic colors (here dark and
     bright colors are not shown).

/* */

TColor(): TNamed()

     Default ctor.

TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char *name, Float_t a) : TNamed(name,"")

     Normal color constructor. Initialize a color structure.
     Compute the RGB and HLS parameters

~TColor()

     Color destructor.

TColor(const TColor &color) : TNamed(color)

     Color copy ctor.

const char* AsHexString() const

     Return color as hexidecimal string. This string can be directly passed
     to, for example, TGClient::GetColorByName(). String will be reused so
     copy immediately if needed.

void Copy(TObject &obj) const

     Copy this color to obj.

ULong_t GetPixel() const

     Return pixel value corresponding to this color. This pixel value can
     be used in the GUI classes. This call does not work in batch mode since
     it needs to communicate with the graphics system.

void HLS2RGB(Float_t hue, Float_t light, Float_t satur, Float_t &r, Float_t &g, Float_t &b)

     Static method to compute RGB from HLS. The l and s are between [0,1]
     and h is between [0,360]. The returned r,g,b triplet is between [0,1].

Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei)

     Static method. Auxiliary to HLS2RGB().

void HLS2RGB(Int_t h, Int_t l, Int_t s, Int_t &r, Int_t &g, Int_t &b)

     Static method to compute RGB from HLS. The h,l,s are between [0,255].
     The returned r,g,b triplet is between [0,255].

void ls(Option_t *) const

     List this color with its attributes.

void Print(Option_t *) const

     Dump this color with its attributes.

void RGB2HLS(Float_t rr, Float_t gg, Float_t bb, Float_t &hue, Float_t &light, Float_t &satur)

     Static method to compute HLS from RGB. The r,g,b triplet is between
     [0,1], hue is between [0,360], light and satur are [0,1].

void RGB2HLS(Int_t r, Int_t g, Int_t b, Int_t &h, Int_t &l, Int_t &s)

     Static method to compute HLS from RGB. The r,g,b triplet is between
     [0,255], hue, light and satur are between [0,255].

void SetRGB(Float_t r, Float_t g, Float_t b)

     Initialize this color and its associated colors.

void Allocate()

     Make this color known to the graphics system.

Int_t GetColor(const char *hexcolor)

     Static method returning color number for color specified by
     hex color string of form: #rrggbb, where rr, gg and bb are in
     hex between [0,FF], e.g. "#c0c0c0".
     If specified color does not exist it will be created with as
     name "#rrggbb" with rr, gg and bb in hex between [0,FF].

Int_t GetColor(Float_t r, Float_t g, Float_t b)

     Static method returning color number for color specified by
     r, g and b. The r,g,b should be in the range [0,1].
     If specified color does not exist it will be created
     with as name "#rrggbb" with rr, gg and bb in hex between
     [0,FF].

Int_t GetColor(ULong_t pixel)

     Static method returning color number for color specified by
     system dependent pixel value. Pixel values can be obtained, e.g.,
     from the GUI color picker.

Int_t GetColor(Int_t r, Int_t g, Int_t b)

     Static method returning color number for color specified by
     r, g and b. The r,g,b should be in the range [0,255].
     If the specified color does not exist it will be created
     with as name "#rrggbb" with rr, gg and bb in hex between
     [0,FF].

ULong_t Number2Pixel(Int_t ci)

     Static method that given a color index number, returns the corresponding
     pixel value. This pixel value can be used in the GUI classes. This call
     does not work in batch mode since it needs to communicate with the
     graphics system.

ULong_t RGB2Pixel(Float_t r, Float_t g, Float_t b)

     Convert r,g,b to graphics system dependent pixel value.
     The r,g,b triplet must be [0,1].

ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)

     Convert r,g,b to graphics system dependent pixel value.
     The r,g,b triplet must be [0,255].

void Pixel2RGB(ULong_t pixel, Float_t &r, Float_t &g, Float_t &b)

     Convert machine dependent pixel value (obtained via RGB2Pixel or
     via Number2Pixel() or via TColor::GetPixel()) to r,g,b triplet.
     The r,g,b triplet will be [0,1].

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::GetPixel()) to r,g,b triplet.
     The r,g,b triplet will be [0,255].

const char* PixelAsHexString(ULong_t pixel)

     Convert machine dependent pixel value (obtained via RGB2Pixel or
     via Number2Pixel() or via TColor::GetPixel()) to a hexidecimal string.
     This string can be directly passed to, for example,
     TGClient::GetColorByName(). String will be reused so copy immediately
     if needed.

void SaveColor(ofstream &out, Int_t ci)

     Save a color with index > 228 as a C++ statement(s) on output stream out.

### Inline Functions

                   void GetRGB(Float_t& r, Float_t& g, Float_t& b) const
                   void GetHLS(Float_t& h, Float_t& l, Float_t& s) const
                  Int_t GetNumber() const
                Float_t GetRed() const
                Float_t GetGreen() const
                Float_t GetBlue() const
                Float_t GetHue() const
                Float_t GetLight() const
                Float_t GetSaturation() const
                Float_t GetAlpha() const
                   void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t& r, Float_t& g, Float_t& b)
                   void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t& h, Float_t& l, Float_t& s)
                TClass* Class()
                TClass* IsA() const
                   void ShowMembers(TMemberInspector& insp, char* parent)
                   void Streamer(TBuffer& b)
                   void StreamerNVirtual(TBuffer& b)
                TColor& operator=(const TColor&)

Author: Rene Brun 12/12/94
Last update: root/base:$Name: $:$Id: TColor.cxx,v 1.21 2004/12/07 15:34:27 brun Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *