]>
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); | |
66 | void SetMinMax(Int_t min, Int_t max); | |
67 | void SetMin(Int_t min); | |
68 | void SetMax(Int_t max); | |
bc5158df | 69 | |
70 | // ================================================================ | |
71 | ||
72 | Bool_t GetInterpolate() const { return fInterpolate; } | |
8373e543 | 73 | void SetInterpolate(Bool_t b); |
bc5158df | 74 | |
75 | Bool_t GetShowDefValue() const { return fShowDefValue; } | |
76 | void SetShowDefValue(Bool_t v) { fShowDefValue = v; } | |
77 | ||
a290e33f | 78 | Int_t GetUnderflowAction() const { return fUnderflowAction; } |
79 | Int_t GetOverflowAction() const { return fOverflowAction; } | |
80 | void SetUnderflowAction(Int_t a) { fUnderflowAction = a; } | |
81 | void SetOverflowAction(Int_t a) { fOverflowAction = a; } | |
bc5158df | 82 | |
83 | // ================================================================ | |
8373e543 | 84 | |
85 | Color_t GetDefaultColor() const { return fDefaultColor; } | |
86 | Color_t* PtrDefaultColor() { return &fDefaultColor; } | |
87 | UChar_t* GetDefaultRGBA() { return fDefaultRGBA; } | |
88 | const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA; } | |
89 | ||
90 | void SetDefaultColor(Color_t ci); | |
91 | void SetDefaultColor(Pixel_t pix); | |
92 | void SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255); | |
93 | ||
bc5158df | 94 | // ---------------------------------------------------------------- |
95 | ||
96 | Color_t GetUnderColor() const { return fUnderColor; } | |
97 | Color_t* PtrUnderColor() { return &fUnderColor; } | |
98 | UChar_t* GetUnderRGBA() { return fUnderRGBA; } | |
99 | const UChar_t* GetUnderRGBA() const { return fUnderRGBA; } | |
100 | ||
101 | void SetUnderColor(Color_t ci); | |
102 | void SetUnderColor(Pixel_t pix); | |
103 | void SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255); | |
104 | ||
105 | // ---------------------------------------------------------------- | |
106 | ||
107 | Color_t GetOverColor() const { return fOverColor; } | |
108 | Color_t* PtrOverColor() { return &fOverColor; } | |
109 | UChar_t* GetOverRGBA() { return fOverRGBA; } | |
110 | const UChar_t* GetOverRGBA() const { return fOverRGBA; } | |
111 | ||
112 | void SetOverColor(Color_t ci); | |
113 | void SetOverColor(Pixel_t pix); | |
114 | void SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255); | |
115 | ||
116 | // ================================================================ | |
117 | ||
8373e543 | 118 | // ?? Should we emit some *SIGNALS* ?? |
119 | // ?? Should we have a RendererTimeStamp ?? | |
120 | ||
121 | ClassDef(RGBAPalette, 1); | |
122 | }; // endclass RGBAPalette | |
123 | ||
124 | ||
bc5158df | 125 | /**************************************************************************/ |
126 | // Inlines for RGBAPalette | |
127 | /**************************************************************************/ | |
128 | ||
129 | inline Bool_t RGBAPalette::WithinVisibleRange(Int_t val) const | |
8373e543 | 130 | { |
a290e33f | 131 | if ((val < fMinVal && fUnderflowAction == LA_Cut) || |
132 | (val > fMaxVal && fOverflowAction == LA_Cut)) | |
bc5158df | 133 | return kFALSE; |
134 | else | |
135 | return kTRUE; | |
136 | } | |
137 | ||
138 | inline const UChar_t* RGBAPalette::ColorFromValue(Int_t val) const | |
139 | { | |
140 | // Here we expect that LA_Cut has been checked; we further check | |
141 | // for LA_Wrap and LA_Clip otherwise we proceed as for LA_Mark. | |
142 | ||
143 | if (!fColorArray) SetupColorArray(); | |
144 | if (val < fMinVal) { | |
a290e33f | 145 | if (fUnderflowAction == LA_Wrap) |
bc5158df | 146 | val = (val+1-fMinVal)%fNBins + fMaxVal; |
a290e33f | 147 | else if (fUnderflowAction == LA_Clip) |
bc5158df | 148 | val = fMinVal; |
149 | else | |
150 | return fUnderRGBA; | |
151 | } | |
152 | else if(val > fMaxVal) { | |
a290e33f | 153 | if (fOverflowAction == LA_Wrap) |
bc5158df | 154 | val = (val-1-fMaxVal)%fNBins + fMinVal; |
a290e33f | 155 | else if (fOverflowAction == LA_Clip) |
bc5158df | 156 | val = fMaxVal; |
157 | else | |
158 | return fOverRGBA; | |
159 | } | |
8373e543 | 160 | return fColorArray + 4 * (val - fMinVal); |
161 | } | |
162 | ||
bc5158df | 163 | inline void RGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const |
8373e543 | 164 | { |
bc5158df | 165 | const UChar_t* c = ColorFromValue(val); |
8373e543 | 166 | pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2]; |
167 | if (alpha) pix[3] = c[3]; | |
168 | } | |
169 | ||
bc5158df | 170 | inline Bool_t RGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const |
8373e543 | 171 | { |
bc5158df | 172 | if (val == defVal) { |
173 | if (fShowDefValue) { | |
174 | pix[0] = fDefaultRGBA[0]; | |
175 | pix[1] = fDefaultRGBA[1]; | |
176 | pix[2] = fDefaultRGBA[2]; | |
177 | if (alpha) pix[3] = fDefaultRGBA[3]; | |
178 | return kTRUE; | |
179 | } else { | |
180 | return kFALSE; | |
181 | } | |
182 | } | |
183 | ||
184 | if (WithinVisibleRange(val)) { | |
185 | ColorFromValue(val, pix, alpha); | |
8373e543 | 186 | return kTRUE; |
bc5158df | 187 | } else { |
188 | return kFALSE; | |
189 | } | |
8373e543 | 190 | } |
191 | ||
192 | } | |
193 | ||
194 | #endif |