3 #ifndef REVE_RGBAPalette_H
4 #define REVE_RGBAPalette_H
12 class RGBAPalette : public TObject, public ReferenceCount
14 friend class RGBAPaletteEditor;
15 friend class RGBAPaletteSubEditor;
18 enum LimitAction_e { LA_Cut, LA_Mark, LA_Clip, LA_Wrap };
21 RGBAPalette(const RGBAPalette&); // Not implemented
22 RGBAPalette& operator=(const RGBAPalette&); // Not implemented
25 Int_t fLowLimit; // Low limit for Min/Max values (used by editor)
26 Int_t fHighLimit; // High limit for Min/Max values (used by editor)
33 Int_t fUnderflowAction;
34 Int_t fOverflowAction;
36 Color_t fDefaultColor; // Color for when value is not specified
37 UChar_t fDefaultRGBA[4];
38 Color_t fUnderColor; // Underflow color
39 UChar_t fUnderRGBA[4];
40 Color_t fOverColor; // Overflow color
43 mutable UChar_t* fColorArray; //[4*fNBins]
45 void SetupColor(Int_t val, UChar_t* pix) const;
47 static RGBAPalette* fgDefaultPalette;
51 RGBAPalette(Int_t min, Int_t max, Bool_t interp=kFALSE, Bool_t showdef=kTRUE);
52 virtual ~RGBAPalette();
54 void SetupColorArray() const;
55 void ClearColorArray();
57 Bool_t WithinVisibleRange(Int_t val) const;
58 const UChar_t* ColorFromValue(Int_t val) const;
59 void ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const;
60 Bool_t ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha=kTRUE) const;
62 Int_t GetMinVal() const { return fMinVal; }
63 Int_t GetMaxVal() const { return fMaxVal; }
65 void SetLimits(Int_t low, Int_t high);
66 void SetLimitsScaleMinMax(Int_t low, Int_t high);
67 void SetMinMax(Int_t min, Int_t max);
68 void SetMin(Int_t min);
69 void SetMax(Int_t max);
71 Int_t GetLowLimit() const { return fLowLimit; }
72 Int_t GetHighLimit() const { return fHighLimit; }
74 // ================================================================
76 Bool_t GetInterpolate() const { return fInterpolate; }
77 void SetInterpolate(Bool_t b);
79 Bool_t GetShowDefValue() const { return fShowDefValue; }
80 void SetShowDefValue(Bool_t v) { fShowDefValue = v; }
82 Int_t GetUnderflowAction() const { return fUnderflowAction; }
83 Int_t GetOverflowAction() const { return fOverflowAction; }
84 void SetUnderflowAction(Int_t a) { fUnderflowAction = a; }
85 void SetOverflowAction(Int_t a) { fOverflowAction = a; }
87 // ================================================================
89 Color_t GetDefaultColor() const { return fDefaultColor; }
90 Color_t* PtrDefaultColor() { return &fDefaultColor; }
91 UChar_t* GetDefaultRGBA() { return fDefaultRGBA; }
92 const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA; }
94 void SetDefaultColor(Color_t ci);
95 void SetDefaultColor(Pixel_t pix);
96 void SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
98 // ----------------------------------------------------------------
100 Color_t GetUnderColor() const { return fUnderColor; }
101 Color_t* PtrUnderColor() { return &fUnderColor; }
102 UChar_t* GetUnderRGBA() { return fUnderRGBA; }
103 const UChar_t* GetUnderRGBA() const { return fUnderRGBA; }
105 void SetUnderColor(Color_t ci);
106 void SetUnderColor(Pixel_t pix);
107 void SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
109 // ----------------------------------------------------------------
111 Color_t GetOverColor() const { return fOverColor; }
112 Color_t* PtrOverColor() { return &fOverColor; }
113 UChar_t* GetOverRGBA() { return fOverRGBA; }
114 const UChar_t* GetOverRGBA() const { return fOverRGBA; }
116 void SetOverColor(Color_t ci);
117 void SetOverColor(Pixel_t pix);
118 void SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
120 // ================================================================
122 // ?? Should we emit some *SIGNALS* ??
123 // ?? Should we have a RendererTimeStamp ??
125 ClassDef(RGBAPalette, 1); // A generic mapping from value to RGBA color.
126 }; // endclass RGBAPalette
129 /**************************************************************************/
130 // Inlines for RGBAPalette
131 /**************************************************************************/
133 inline Bool_t RGBAPalette::WithinVisibleRange(Int_t val) const
135 if ((val < fMinVal && fUnderflowAction == LA_Cut) ||
136 (val > fMaxVal && fOverflowAction == LA_Cut))
142 inline const UChar_t* RGBAPalette::ColorFromValue(Int_t val) const
144 // Here we expect that LA_Cut has been checked; we further check
145 // for LA_Wrap and LA_Clip otherwise we proceed as for LA_Mark.
147 if (!fColorArray) SetupColorArray();
149 if (fUnderflowAction == LA_Wrap)
150 val = (val+1-fMinVal)%fNBins + fMaxVal;
151 else if (fUnderflowAction == LA_Clip)
156 else if(val > fMaxVal) {
157 if (fOverflowAction == LA_Wrap)
158 val = (val-1-fMaxVal)%fNBins + fMinVal;
159 else if (fOverflowAction == LA_Clip)
164 return fColorArray + 4 * (val - fMinVal);
167 inline void RGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const
169 const UChar_t* c = ColorFromValue(val);
170 pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2];
171 if (alpha) pix[3] = c[3];
174 inline Bool_t RGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const
178 pix[0] = fDefaultRGBA[0];
179 pix[1] = fDefaultRGBA[1];
180 pix[2] = fDefaultRGBA[2];
181 if (alpha) pix[3] = fDefaultRGBA[3];
188 if (WithinVisibleRange(val)) {
189 ColorFromValue(val, pix, alpha);