3 #include "RGBAPalette.h"
11 //______________________________________________________________________
17 RGBAPalette::RGBAPalette() :
19 Reve::ReferenceCount(),
21 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
23 fInterpolate (kFALSE),
24 fShowDefValue (kTRUE),
25 fUnderflowAction (LA_Cut),
26 fOverflowAction (LA_Clip),
37 RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t showdef) :
39 Reve::ReferenceCount(),
41 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
43 fInterpolate (interp),
44 fShowDefValue (showdef),
45 fUnderflowAction (LA_Cut),
46 fOverflowAction (LA_Clip),
57 RGBAPalette::~RGBAPalette()
59 delete [] fColorArray;
62 /**************************************************************************/
64 void RGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const
66 using namespace TMath;
67 Float_t div = Max(1, fMaxVal - fMinVal);
68 Int_t nCol = gStyle->GetNumberOfColors();
71 if (val >= fMaxVal) f = nCol - 1;
72 else if (val <= fMinVal) f = 0;
73 else f = (val - fMinVal)/div*(nCol - 1);
76 Int_t bin = (Int_t) f;
77 Float_t f1 = f - bin, f2 = 1.0f - f1;
78 ColorFromIdx(f1, gStyle->GetColorPalette(bin),
79 f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
82 ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel);
86 void RGBAPalette::SetupColorArray() const
88 if(fColorArray) // !!!! should reinit anyway, maybe palette in gstyle changed
91 // !!!! probably should store original palette for editing ...
93 fColorArray = new UChar_t [4 * fNBins];
94 UChar_t* p = fColorArray;
95 for(Int_t v=fMinVal; v<=fMaxVal; ++v, p+=4)
99 void RGBAPalette::ClearColorArray()
102 delete [] fColorArray;
107 /**************************************************************************/
109 void RGBAPalette::SetLimits(Int_t low, Int_t high)
113 Bool_t changed = kFALSE;
114 if (fMaxVal < fLowLimit) { SetMax(fLowLimit); changed = kTRUE; }
115 if (fMinVal < fLowLimit) { SetMin(fLowLimit); changed = kTRUE; }
116 if (fMinVal > fHighLimit) { SetMin(fHighLimit); changed = kTRUE; }
117 if (fMaxVal > fHighLimit) { SetMax(fHighLimit); changed = kTRUE; }
122 void RGBAPalette::SetMin(Int_t min)
124 fMinVal = TMath::Min(min, fMaxVal);
125 fNBins = fMaxVal - fMinVal + 1;
129 void RGBAPalette::SetMax(Int_t max)
131 fMaxVal = TMath::Max(max, fMinVal);
132 fNBins = fMaxVal - fMinVal + 1;
136 void RGBAPalette::SetMinMax(Int_t min, Int_t max)
140 fNBins = fMaxVal - fMinVal + 1;
144 /**************************************************************************/
145 /**************************************************************************/
147 void RGBAPalette::SetInterpolate(Bool_t b)
153 /**************************************************************************/
154 /**************************************************************************/
156 void RGBAPalette::SetDefaultColor(Color_t ci)
159 ColorFromIdx(ci, fDefaultRGBA, kTRUE);
162 void RGBAPalette::SetDefaultColor(Pixel_t pix)
164 SetDefaultColor(Color_t(TColor::GetColor(pix)));
167 void RGBAPalette::SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
169 fDefaultColor = Color_t(TColor::GetColor(r, g, b));
176 /**************************************************************************/
178 void RGBAPalette::SetUnderColor(Color_t ci)
181 ColorFromIdx(ci, fUnderRGBA, kTRUE);
184 void RGBAPalette::SetUnderColor(Pixel_t pix)
186 SetUnderColor(Color_t(TColor::GetColor(pix)));
189 void RGBAPalette::SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
191 fUnderColor = Color_t(TColor::GetColor(r, g, b));
198 /**************************************************************************/
200 void RGBAPalette::SetOverColor(Color_t ci)
203 ColorFromIdx(ci, fOverRGBA, kTRUE);
206 void RGBAPalette::SetOverColor(Pixel_t pix)
208 SetOverColor(Color_t(TColor::GetColor(pix)));
211 void RGBAPalette::SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
213 fOverColor = Color_t(TColor::GetColor(r, g, b));
220 /**************************************************************************/
221 /**************************************************************************/