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 fUnderflowAction (LA_Cut),
25 fOverflowAction (LA_Clip),
36 RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t showdef) :
38 Reve::ReferenceCount(),
40 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0), fNBins(0),
42 fInterpolate (interp),
43 fShowDefValue (showdef),
44 fUnderflowAction (LA_Cut),
45 fOverflowAction (LA_Clip),
56 RGBAPalette::~RGBAPalette()
58 delete [] fColorArray;
61 /**************************************************************************/
63 void RGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const
65 using namespace TMath;
66 Float_t div = Max(1, fMaxVal - fMinVal);
67 Int_t nCol = gStyle->GetNumberOfColors();
70 if (val >= fMaxVal) f = nCol - 1;
71 else if (val <= fMinVal) f = 0;
72 else f = (val - fMinVal)/div*(nCol - 1);
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)),
81 ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel);
85 void RGBAPalette::SetupColorArray() const
87 if(fColorArray) // !!!! should reinit anyway, maybe palette in gstyle changed
90 // !!!! probably should store original palette for editing ...
92 fColorArray = new UChar_t [4 * fNBins];
93 UChar_t* p = fColorArray;
94 for(Int_t v=fMinVal; v<=fMaxVal; ++v, p+=4)
98 void RGBAPalette::ClearColorArray()
101 delete [] fColorArray;
106 /**************************************************************************/
108 void RGBAPalette::SetLimits(Int_t low, Int_t 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; }
121 void RGBAPalette::SetMin(Int_t min)
123 fMinVal = TMath::Min(min, fMaxVal);
124 fNBins = fMaxVal - fMinVal + 1;
128 void RGBAPalette::SetMax(Int_t max)
130 fMaxVal = TMath::Max(max, fMinVal);
131 fNBins = fMaxVal - fMinVal + 1;
135 void RGBAPalette::SetMinMax(Int_t min, Int_t max)
139 fNBins = fMaxVal - fMinVal + 1;
143 /**************************************************************************/
144 /**************************************************************************/
146 void RGBAPalette::SetInterpolate(Bool_t b)
152 /**************************************************************************/
153 /**************************************************************************/
155 void RGBAPalette::SetDefaultColor(Color_t ci)
158 ColorFromIdx(ci, fDefaultRGBA, kTRUE);
161 void RGBAPalette::SetDefaultColor(Pixel_t pix)
163 SetDefaultColor(Color_t(TColor::GetColor(pix)));
166 void RGBAPalette::SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
168 fDefaultColor = Color_t(TColor::GetColor(r, g, b));
175 /**************************************************************************/
177 void RGBAPalette::SetUnderColor(Color_t ci)
180 ColorFromIdx(ci, fUnderRGBA, kTRUE);
183 void RGBAPalette::SetUnderColor(Pixel_t pix)
185 SetUnderColor(Color_t(TColor::GetColor(pix)));
188 void RGBAPalette::SetUnderColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
190 fUnderColor = Color_t(TColor::GetColor(r, g, b));
197 /**************************************************************************/
199 void RGBAPalette::SetOverColor(Color_t ci)
202 ColorFromIdx(ci, fOverRGBA, kTRUE);
205 void RGBAPalette::SetOverColor(Pixel_t pix)
207 SetOverColor(Color_t(TColor::GetColor(pix)));
210 void RGBAPalette::SetOverColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
212 fOverColor = Color_t(TColor::GetColor(r, g, b));
219 /**************************************************************************/
220 /**************************************************************************/