3 #include "RGBAPalette.h"
10 //______________________________________________________________________
16 RGBAPalette::RGBAPalette() :
18 Reve::ReferenceCount(),
20 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
22 fInterpolate (kFALSE),
23 fShowDefValue (kTRUE),
24 fUndershootAction (LA_Cut),
25 fOvershootAction (LA_Clip),
36 RGBAPalette::RGBAPalette(Int_t min, Int_t max) :
38 Reve::ReferenceCount(),
40 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
42 fInterpolate (kFALSE),
43 fShowDefValue (kTRUE),
44 fUndershootAction (LA_Cut),
45 fOvershootAction (LA_Clip),
56 RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t showdef) :
58 Reve::ReferenceCount(),
60 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
62 fInterpolate (interp),
63 fShowDefValue (showdef),
64 fUndershootAction (LA_Cut),
65 fOvershootAction (LA_Clip),
76 RGBAPalette::~RGBAPalette()
78 delete [] fColorArray;
81 /**************************************************************************/
83 void RGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const
85 using namespace TMath;
86 Float_t div = Max(1, fMaxVal - fMinVal);
87 Int_t nCol = gStyle->GetNumberOfColors();
90 if (val >= fMaxVal) f = nCol - 1;
91 else if (val <= fMinVal) f = 0;
92 else f = (val - fMinVal)/div*(nCol - 1);
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)),
101 ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel);
105 void RGBAPalette::SetupColorArray() const
107 if(fColorArray) // !!!! should reinit anyway, maybe palette in gstyle changed
110 // !!!! probably should store original palette for editing ...
112 fColorArray = new UChar_t [4 * fNBins];
113 UChar_t* p = fColorArray;
114 for(Int_t v=fMinVal; v<=fMaxVal; ++v, p+=4)
118 void RGBAPalette::ClearColorArray()
121 delete [] fColorArray;
126 /**************************************************************************/
128 void RGBAPalette::SetLimits(Int_t low, Int_t high)
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; }
141 void RGBAPalette::SetMin(Int_t min)
143 fMinVal = TMath::Min(min, fMaxVal);
144 fNBins = fMaxVal - fMinVal + 1;
148 void RGBAPalette::SetMax(Int_t max)
150 fMaxVal = TMath::Max(max, fMinVal);
151 fNBins = fMaxVal - fMinVal + 1;
155 void RGBAPalette::SetMinMax(Int_t min, Int_t max)
159 fNBins = fMaxVal - fMinVal + 1;
163 /**************************************************************************/
164 /**************************************************************************/
166 void RGBAPalette::SetInterpolate(Bool_t b)
172 /**************************************************************************/
173 /**************************************************************************/
175 void RGBAPalette::SetDefaultColor(Color_t ci)
178 ColorFromIdx(ci, fDefaultRGBA, kTRUE);
181 void RGBAPalette::SetDefaultColor(Pixel_t pix)
183 SetDefaultColor(Color_t(TColor::GetColor(pix)));
186 void RGBAPalette::SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
188 fDefaultColor = Color_t(TColor::GetColor(r, g, b));
195 /**************************************************************************/
197 void RGBAPalette::SetUnderColor(Color_t ci)
200 ColorFromIdx(ci, fUnderRGBA, kTRUE);
203 void RGBAPalette::SetUnderColor(Pixel_t pix)
205 SetUnderColor(Color_t(TColor::GetColor(pix)));
208 void RGBAPalette::SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
210 fUnderColor = Color_t(TColor::GetColor(r, g, b));
217 /**************************************************************************/
219 void RGBAPalette::SetOverColor(Color_t ci)
222 ColorFromIdx(ci, fOverRGBA, kTRUE);
225 void RGBAPalette::SetOverColor(Pixel_t pix)
227 SetOverColor(Color_t(TColor::GetColor(pix)));
230 void RGBAPalette::SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
232 fOverColor = Color_t(TColor::GetColor(r, g, b));
239 /**************************************************************************/
240 /**************************************************************************/