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 fUndershootAction;
34 Int_t fOvershootAction;
36 Color_t fDefaultColor; // Color for when value is not specified
37 UChar_t fDefaultRGBA[4];
38 Color_t fUnderColor; // Undershoot color
39 UChar_t fUnderRGBA[4];
40 Color_t fOverColor; // Overshoot 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);
52 RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t showdef=kTRUE);
53 virtual ~RGBAPalette();
55 void SetupColorArray() const;
56 void ClearColorArray();
58 Bool_t WithinVisibleRange(Int_t val) const;
59 const UChar_t* ColorFromValue(Int_t val) const;
60 void ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const;
61 Bool_t ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha=kTRUE) const;
63 Int_t GetMinVal() const { return fMinVal; }
64 Int_t GetMaxVal() const { return fMaxVal; }
66 void SetLimits(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 // ================================================================
73 Bool_t GetInterpolate() const { return fInterpolate; }
74 void SetInterpolate(Bool_t b);
76 Bool_t GetShowDefValue() const { return fShowDefValue; }
77 void SetShowDefValue(Bool_t v) { fShowDefValue = v; }
79 Int_t GetUndershootAction() const { return fUndershootAction; }
80 Int_t GetOvershootAction() const { return fOvershootAction; }
81 void SetUndershootAction(Int_t a) { fUndershootAction = a; }
82 void SetOvershootAction(Int_t a) { fOvershootAction = a; }
84 // ================================================================
86 Color_t GetDefaultColor() const { return fDefaultColor; }
87 Color_t* PtrDefaultColor() { return &fDefaultColor; }
88 UChar_t* GetDefaultRGBA() { return fDefaultRGBA; }
89 const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA; }
91 void SetDefaultColor(Color_t ci);
92 void SetDefaultColor(Pixel_t pix);
93 void SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
95 // ----------------------------------------------------------------
97 Color_t GetUnderColor() const { return fUnderColor; }
98 Color_t* PtrUnderColor() { return &fUnderColor; }
99 UChar_t* GetUnderRGBA() { return fUnderRGBA; }
100 const UChar_t* GetUnderRGBA() const { return fUnderRGBA; }
102 void SetUnderColor(Color_t ci);
103 void SetUnderColor(Pixel_t pix);
104 void SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
106 // ----------------------------------------------------------------
108 Color_t GetOverColor() const { return fOverColor; }
109 Color_t* PtrOverColor() { return &fOverColor; }
110 UChar_t* GetOverRGBA() { return fOverRGBA; }
111 const UChar_t* GetOverRGBA() const { return fOverRGBA; }
113 void SetOverColor(Color_t ci);
114 void SetOverColor(Pixel_t pix);
115 void SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
117 // ================================================================
119 // ?? Should we emit some *SIGNALS* ??
120 // ?? Should we have a RendererTimeStamp ??
122 ClassDef(RGBAPalette, 1);
123 }; // endclass RGBAPalette
126 /**************************************************************************/
127 // Inlines for RGBAPalette
128 /**************************************************************************/
130 inline Bool_t RGBAPalette::WithinVisibleRange(Int_t val) const
132 if ((val < fMinVal && fUndershootAction == LA_Cut) ||
133 (val > fMaxVal && fOvershootAction == LA_Cut))
139 inline const UChar_t* RGBAPalette::ColorFromValue(Int_t val) const
141 // Here we expect that LA_Cut has been checked; we further check
142 // for LA_Wrap and LA_Clip otherwise we proceed as for LA_Mark.
144 if (!fColorArray) SetupColorArray();
146 if (fUndershootAction == LA_Wrap)
147 val = (val+1-fMinVal)%fNBins + fMaxVal;
148 else if (fUndershootAction == LA_Clip)
153 else if(val > fMaxVal) {
154 if (fOvershootAction == LA_Wrap)
155 val = (val-1-fMaxVal)%fNBins + fMinVal;
156 else if (fOvershootAction == LA_Clip)
161 return fColorArray + 4 * (val - fMinVal);
164 inline void RGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const
166 const UChar_t* c = ColorFromValue(val);
167 pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2];
168 if (alpha) pix[3] = c[3];
171 inline Bool_t RGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const
175 pix[0] = fDefaultRGBA[0];
176 pix[1] = fDefaultRGBA[1];
177 pix[2] = fDefaultRGBA[2];
178 if (alpha) pix[3] = fDefaultRGBA[3];
185 if (WithinVisibleRange(val)) {
186 ColorFromValue(val, pix, alpha);