]>
Commit | Line | Data |
---|---|---|
8373e543 | 1 | // $Header$ |
2 | ||
3 | #ifndef REVE_RGBAPalette_H | |
4 | #define REVE_RGBAPalette_H | |
5 | ||
6 | #include <Reve/Reve.h> | |
7 | ||
8 | #include <TObject.h> | |
9 | ||
10 | namespace Reve { | |
11 | ||
12 | class RGBAPalette : public TObject, public ReferenceCount | |
13 | { | |
14 | friend class RGBAPaletteEditor; | |
15 | friend class RGBAPaletteSubEditor; | |
16 | ||
bc5158df | 17 | public: |
18 | enum LimitAction_e { LA_Cut, LA_Mark, LA_Clip, LA_Wrap }; | |
19 | ||
8373e543 | 20 | private: |
21 | RGBAPalette(const RGBAPalette&); // Not implemented | |
22 | RGBAPalette& operator=(const RGBAPalette&); // Not implemented | |
23 | ||
24 | protected: | |
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) | |
27 | Int_t fMinVal; | |
28 | Int_t fMaxVal; | |
29 | Int_t fNBins; | |
bc5158df | 30 | |
a290e33f | 31 | Bool_t fInterpolate; |
32 | Bool_t fShowDefValue; | |
33 | Int_t fUnderflowAction; | |
34 | Int_t fOverflowAction; | |
bc5158df | 35 | |
36 | Color_t fDefaultColor; // Color for when value is not specified | |
8373e543 | 37 | UChar_t fDefaultRGBA[4]; |
a290e33f | 38 | Color_t fUnderColor; // Underflow color |
bc5158df | 39 | UChar_t fUnderRGBA[4]; |
a290e33f | 40 | Color_t fOverColor; // Overflow color |
bc5158df | 41 | UChar_t fOverRGBA[4]; |
8373e543 | 42 | |
43 | mutable UChar_t* fColorArray; //[4*fNBins] | |
44 | ||
45 | void SetupColor(Int_t val, UChar_t* pix) const; | |
46 | ||
47 | static RGBAPalette* fgDefaultPalette; | |
48 | ||
49 | public: | |
50 | RGBAPalette(); | |
e0fa60e9 | 51 | RGBAPalette(Int_t min, Int_t max, Bool_t interp=kFALSE, Bool_t showdef=kTRUE); |
8373e543 | 52 | virtual ~RGBAPalette(); |
53 | ||
54 | void SetupColorArray() const; | |
55 | void ClearColorArray(); | |
56 | ||
8373e543 | 57 | Bool_t WithinVisibleRange(Int_t val) const; |
bc5158df | 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; | |
8373e543 | 61 | |
bc5158df | 62 | Int_t GetMinVal() const { return fMinVal; } |
63 | Int_t GetMaxVal() const { return fMaxVal; } | |
8373e543 | 64 | |
65 | void SetLimits(Int_t low, Int_t high); | |
32e219c2 | 66 | void SetLimitsScaleMinMax(Int_t low, Int_t high); |
8373e543 | 67 | void SetMinMax(Int_t min, Int_t max); |
68 | void SetMin(Int_t min); | |
69 | void SetMax(Int_t max); | |
bc5158df | 70 | |
fa90d41f | 71 | Int_t GetLowLimit() const { return fLowLimit; } |
72 | Int_t GetHighLimit() const { return fHighLimit; } | |
73 | ||
bc5158df | 74 | // ================================================================ |
75 | ||
76 | Bool_t GetInterpolate() const { return fInterpolate; } | |
8373e543 | 77 | void SetInterpolate(Bool_t b); |
bc5158df | 78 | |
79 | Bool_t GetShowDefValue() const { return fShowDefValue; } | |
80 | void SetShowDefValue(Bool_t v) { fShowDefValue = v; } | |
81 | ||
a290e33f | 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; } | |
bc5158df | 86 | |
87 | // ================================================================ | |
8373e543 | 88 | |
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; } | |
93 | ||
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); | |
97 | ||
bc5158df | 98 | // ---------------------------------------------------------------- |
99 | ||
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; } | |
104 | ||
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); | |
108 | ||
109 | // ---------------------------------------------------------------- | |
110 | ||
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; } | |
115 | ||
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); | |
119 | ||
120 | // ================================================================ | |
121 | ||
8373e543 | 122 | // ?? Should we emit some *SIGNALS* ?? |
123 | // ?? Should we have a RendererTimeStamp ?? | |
124 | ||
e9ef1a49 | 125 | ClassDef(RGBAPalette, 1); // A generic mapping from value to RGBA color. |
8373e543 | 126 | }; // endclass RGBAPalette |
127 | ||
128 | ||
bc5158df | 129 | /**************************************************************************/ |
130 | // Inlines for RGBAPalette | |
131 | /**************************************************************************/ | |
132 | ||
133 | inline Bool_t RGBAPalette::WithinVisibleRange(Int_t val) const | |
8373e543 | 134 | { |
a290e33f | 135 | if ((val < fMinVal && fUnderflowAction == LA_Cut) || |
136 | (val > fMaxVal && fOverflowAction == LA_Cut)) | |
bc5158df | 137 | return kFALSE; |
138 | else | |
139 | return kTRUE; | |
140 | } | |
141 | ||
142 | inline const UChar_t* RGBAPalette::ColorFromValue(Int_t val) const | |
143 | { | |
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. | |
146 | ||
147 | if (!fColorArray) SetupColorArray(); | |
148 | if (val < fMinVal) { | |
a290e33f | 149 | if (fUnderflowAction == LA_Wrap) |
bc5158df | 150 | val = (val+1-fMinVal)%fNBins + fMaxVal; |
a290e33f | 151 | else if (fUnderflowAction == LA_Clip) |
bc5158df | 152 | val = fMinVal; |
153 | else | |
154 | return fUnderRGBA; | |
155 | } | |
156 | else if(val > fMaxVal) { | |
a290e33f | 157 | if (fOverflowAction == LA_Wrap) |
bc5158df | 158 | val = (val-1-fMaxVal)%fNBins + fMinVal; |
a290e33f | 159 | else if (fOverflowAction == LA_Clip) |
bc5158df | 160 | val = fMaxVal; |
161 | else | |
162 | return fOverRGBA; | |
163 | } | |
8373e543 | 164 | return fColorArray + 4 * (val - fMinVal); |
165 | } | |
166 | ||
bc5158df | 167 | inline void RGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const |
8373e543 | 168 | { |
bc5158df | 169 | const UChar_t* c = ColorFromValue(val); |
8373e543 | 170 | pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2]; |
171 | if (alpha) pix[3] = c[3]; | |
172 | } | |
173 | ||
bc5158df | 174 | inline Bool_t RGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const |
8373e543 | 175 | { |
bc5158df | 176 | if (val == defVal) { |
177 | if (fShowDefValue) { | |
178 | pix[0] = fDefaultRGBA[0]; | |
179 | pix[1] = fDefaultRGBA[1]; | |
180 | pix[2] = fDefaultRGBA[2]; | |
181 | if (alpha) pix[3] = fDefaultRGBA[3]; | |
182 | return kTRUE; | |
183 | } else { | |
184 | return kFALSE; | |
185 | } | |
186 | } | |
187 | ||
188 | if (WithinVisibleRange(val)) { | |
189 | ColorFromValue(val, pix, alpha); | |
8373e543 | 190 | return kTRUE; |
bc5158df | 191 | } else { |
192 | return kFALSE; | |
193 | } | |
8373e543 | 194 | } |
195 | ||
196 | } | |
197 | ||
198 | #endif |