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