]>
Commit | Line | Data |
---|---|---|
8373e543 | 1 | // $Header$ |
2 | ||
3 | #include "RGBAPalette.h" | |
4 | ||
5 | #include <TColor.h> | |
6 | #include <TStyle.h> | |
7 | ||
8 | using namespace Reve; | |
9 | ||
10 | //______________________________________________________________________ | |
11 | // RGBAPalette | |
12 | // | |
13 | ||
14 | ClassImp(RGBAPalette) | |
15 | ||
16 | RGBAPalette::RGBAPalette() : | |
17 | TObject(), | |
18 | Reve::ReferenceCount(), | |
3c67f72c | 19 | |
20 | fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0), | |
21 | ||
bc5158df | 22 | fInterpolate (kFALSE), |
23 | fShowDefValue (kTRUE), | |
24 | fUndershootAction (LA_Cut), | |
25 | fOvershootAction (LA_Clip), | |
26 | ||
3c67f72c | 27 | fDefaultColor(0), |
bc5158df | 28 | fUnderColor (1), |
29 | fOverColor (2), | |
8373e543 | 30 | fColorArray (0) |
31 | { | |
32 | SetLimits(0, 1000); | |
33 | SetMinMax(0, 100); | |
34 | } | |
35 | ||
36 | RGBAPalette::RGBAPalette(Int_t min, Int_t max) : | |
37 | TObject(), | |
38 | Reve::ReferenceCount(), | |
3c67f72c | 39 | |
40 | fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0), | |
bc5158df | 41 | |
42 | fInterpolate (kFALSE), | |
43 | fShowDefValue (kTRUE), | |
44 | fUndershootAction (LA_Cut), | |
45 | fOvershootAction (LA_Clip), | |
3c67f72c | 46 | |
3c67f72c | 47 | fDefaultColor(0), |
bc5158df | 48 | fUnderColor (1), |
49 | fOverColor (2), | |
8373e543 | 50 | fColorArray (0) |
51 | { | |
52 | SetLimits(0, 1000); | |
53 | SetMinMax(min, max); | |
54 | } | |
55 | ||
bc5158df | 56 | RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t showdef) : |
8373e543 | 57 | TObject(), |
58 | Reve::ReferenceCount(), | |
3c67f72c | 59 | |
60 | fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0), | |
61 | ||
bc5158df | 62 | fInterpolate (interp), |
63 | fShowDefValue (showdef), | |
64 | fUndershootAction (LA_Cut), | |
65 | fOvershootAction (LA_Clip), | |
66 | ||
3c67f72c | 67 | fDefaultColor(0), |
bc5158df | 68 | fUnderColor (1), |
69 | fOverColor (2), | |
8373e543 | 70 | fColorArray (0) |
71 | { | |
72 | SetLimits(0, 1023); | |
73 | SetMinMax(min, max); | |
74 | } | |
75 | ||
76 | RGBAPalette::~RGBAPalette() | |
77 | { | |
78 | delete [] fColorArray; | |
79 | } | |
80 | ||
81 | /**************************************************************************/ | |
82 | ||
83 | void RGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const | |
84 | { | |
85 | using namespace TMath; | |
86 | Float_t div = Max(1, fMaxVal - fMinVal); | |
87 | Int_t nCol = gStyle->GetNumberOfColors(); | |
88 | ||
89 | Float_t f; | |
90 | if (val >= fMaxVal) f = nCol - 1; | |
91 | else if (val <= fMinVal) f = 0; | |
92 | else f = (val - fMinVal)/div*(nCol - 1); | |
93 | ||
94 | if (fInterpolate) { | |
95 | Int_t bin = (Int_t) f; | |
96 | Float_t f1 = f - bin, f2 = 1.0f - f1; | |
97 | ColorFromIdx(f1, gStyle->GetColorPalette(bin), | |
98 | f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)), | |
99 | pixel); | |
100 | } else { | |
101 | ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel); | |
102 | } | |
103 | } | |
104 | ||
105 | void RGBAPalette::SetupColorArray() const | |
106 | { | |
107 | if(fColorArray) // !!!! should reinit anyway, maybe palette in gstyle changed | |
108 | return; | |
109 | ||
110 | // !!!! probably should store original palette for editing ... | |
111 | ||
112 | fColorArray = new UChar_t [4 * fNBins]; | |
113 | UChar_t* p = fColorArray; | |
114 | for(Int_t v=fMinVal; v<=fMaxVal; ++v, p+=4) | |
115 | SetupColor(v, p); | |
116 | } | |
117 | ||
118 | void RGBAPalette::ClearColorArray() | |
119 | { | |
120 | if(fColorArray) { | |
121 | delete [] fColorArray; | |
122 | fColorArray = 0; | |
123 | } | |
124 | } | |
125 | ||
126 | /**************************************************************************/ | |
127 | ||
128 | void RGBAPalette::SetLimits(Int_t low, Int_t high) | |
129 | { | |
130 | fLowLimit = low; | |
131 | fHighLimit = high; | |
bc5158df | 132 | Bool_t changed = kFALSE; |
133 | if (fMaxVal < fLowLimit) { SetMax(fLowLimit); changed = kTRUE; } | |
134 | if (fMinVal < fLowLimit) { SetMin(fLowLimit); changed = kTRUE; } | |
135 | if (fMinVal > fHighLimit) { SetMin(fHighLimit); changed = kTRUE; } | |
136 | if (fMaxVal > fHighLimit) { SetMax(fHighLimit); changed = kTRUE; } | |
137 | if (changed) | |
138 | ClearColorArray(); | |
8373e543 | 139 | } |
140 | ||
141 | void RGBAPalette::SetMin(Int_t min) | |
142 | { | |
143 | fMinVal = TMath::Min(min, fMaxVal); | |
144 | fNBins = fMaxVal - fMinVal + 1; | |
145 | ClearColorArray(); | |
146 | } | |
147 | ||
148 | void RGBAPalette::SetMax(Int_t max) | |
149 | { | |
150 | fMaxVal = TMath::Max(max, fMinVal); | |
151 | fNBins = fMaxVal - fMinVal + 1; | |
152 | ClearColorArray(); | |
153 | } | |
154 | ||
155 | void RGBAPalette::SetMinMax(Int_t min, Int_t max) | |
156 | { | |
157 | fMinVal = min; | |
158 | fMaxVal = max; | |
159 | fNBins = fMaxVal - fMinVal + 1; | |
160 | ClearColorArray(); | |
161 | } | |
162 | ||
bc5158df | 163 | /**************************************************************************/ |
164 | /**************************************************************************/ | |
165 | ||
8373e543 | 166 | void RGBAPalette::SetInterpolate(Bool_t b) |
167 | { | |
168 | fInterpolate = b; | |
169 | ClearColorArray(); | |
170 | } | |
171 | ||
bc5158df | 172 | /**************************************************************************/ |
8373e543 | 173 | /**************************************************************************/ |
174 | ||
175 | void RGBAPalette::SetDefaultColor(Color_t ci) | |
176 | { | |
177 | fDefaultColor = ci; | |
178 | ColorFromIdx(ci, fDefaultRGBA, kTRUE); | |
179 | } | |
180 | ||
181 | void RGBAPalette::SetDefaultColor(Pixel_t pix) | |
182 | { | |
183 | SetDefaultColor(Color_t(TColor::GetColor(pix))); | |
184 | } | |
185 | ||
186 | void RGBAPalette::SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a) | |
187 | { | |
188 | fDefaultColor = Color_t(TColor::GetColor(r, g, b)); | |
189 | fDefaultRGBA[0] = r; | |
190 | fDefaultRGBA[1] = g; | |
191 | fDefaultRGBA[2] = b; | |
192 | fDefaultRGBA[3] = a; | |
193 | } | |
bc5158df | 194 | |
195 | /**************************************************************************/ | |
196 | ||
197 | void RGBAPalette::SetUnderColor(Color_t ci) | |
198 | { | |
199 | fUnderColor = ci; | |
200 | ColorFromIdx(ci, fUnderRGBA, kTRUE); | |
201 | } | |
202 | ||
203 | void RGBAPalette::SetUnderColor(Pixel_t pix) | |
204 | { | |
205 | SetUnderColor(Color_t(TColor::GetColor(pix))); | |
206 | } | |
207 | ||
208 | void RGBAPalette::SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a) | |
209 | { | |
210 | fUnderColor = Color_t(TColor::GetColor(r, g, b)); | |
211 | fUnderRGBA[0] = r; | |
212 | fUnderRGBA[1] = g; | |
213 | fUnderRGBA[2] = b; | |
214 | fUnderRGBA[3] = a; | |
215 | } | |
216 | ||
217 | /**************************************************************************/ | |
218 | ||
219 | void RGBAPalette::SetOverColor(Color_t ci) | |
220 | { | |
221 | fOverColor = ci; | |
222 | ColorFromIdx(ci, fOverRGBA, kTRUE); | |
223 | } | |
224 | ||
225 | void RGBAPalette::SetOverColor(Pixel_t pix) | |
226 | { | |
227 | SetOverColor(Color_t(TColor::GetColor(pix))); | |
228 | } | |
229 | ||
230 | void RGBAPalette::SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a) | |
231 | { | |
232 | fOverColor = Color_t(TColor::GetColor(r, g, b)); | |
233 | fOverRGBA[0] = r; | |
234 | fOverRGBA[1] = g; | |
235 | fOverRGBA[2] = b; | |
236 | fOverRGBA[3] = a; | |
237 | } | |
238 | ||
239 | /**************************************************************************/ | |
240 | /**************************************************************************/ |