97 ClassImp(TPaletteEditor);
99 ClassImp(TImagePalette);
103 const Int_t kNUM_DEFAULT_COLORS = 12;
104 static UShort_t gAlphaDefault[kNUM_DEFAULT_COLORS] = {
105 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
106 0xffff, 0xffff, 0xffff, 0xffff
109 static UShort_t gRedDefault[kNUM_DEFAULT_COLORS] = {
110 0x0000, 0x0000, 0x7000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff,
111 0x7000, 0x8000, 0xffff, 0xffff
114 static UShort_t gGreenDefault[kNUM_DEFAULT_COLORS] = {
115 0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0x0000,
116 0x0000, 0x8000, 0xffff, 0xffff
119 static UShort_t gBlueDefault[kNUM_DEFAULT_COLORS] = {
120 0x0000, 0x0000, 0x7000, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000,
121 0x0000, 0xa000, 0xffff, 0xffff
126 static UShort_t gWebBase[6] = { 0, 51, 102, 153, 204, 255 };
128 class TWebPalette :
public TImagePalette {
131 Int_t fCLUT[6][6][6];
134 TWebPalette() : TImagePalette() {
137 fPoints =
new Double_t[216];
138 fColorRed =
new UShort_t[216];
139 fColorBlue =
new UShort_t[216];
140 fColorGreen =
new UShort_t[216];
141 fColorAlpha =
new UShort_t[216];
143 for (i = 0; i < 214; i++) {
144 fPoints[i + 1] = (double)i/213;
150 for (
int r = 0; r < 6; r++) {
151 for (
int g = 0; g < 6; g++) {
152 for (
int b = 0; b < 6; b++) {
153 fColorRed[i] = gWebBase[r] << 8;
154 fColorGreen[i] = gWebBase[g] << 8;
155 fColorBlue[i] = gWebBase[b] << 8;
156 fColorAlpha[i] = 0xffff;
164 Int_t FindColor(UShort_t r, UShort_t g, UShort_t b) {
165 Int_t ri = TMath:: BinarySearch(6, (
const Short_t*)gWebBase, (Short_t)r);
166 Int_t gi = TMath:: BinarySearch(6, (
const Short_t*)gWebBase, (Short_t)g);
167 Int_t bi = TMath:: BinarySearch(6, (
const Short_t*)gWebBase, (Short_t)b);
168 return fCLUT[ri][gi][bi];
171 Int_t *GetRootColors() {
172 static Int_t *gRootColors = 0;
173 if (gRootColors)
return gRootColors;
175 gRootColors =
new Int_t[216];
178 for (
int r = 0; r < 6; r++) {
179 for (
int g = 0; g < 6; g++) {
180 for (
int b = 0; b < 6; b++) {
181 gRootColors[i] = TColor::GetColor(gWebBase[r], gWebBase[g], gWebBase[b]);
190 TImagePalette *gWebImagePalette =
new TWebPalette();
194 static Double_t gDefHistP[50] = {
195 0.00,0.02,0.04,0.06,0.08,0.10,0.12,0.14,0.16,0.18,0.20,0.22,0.24,0.26,
196 0.28,0.30,0.32,0.34,0.36,0.38,0.40,0.42,0.44,0.46,0.48,0.50,0.52,0.54,
197 0.56,0.58,0.60,0.62,0.64,0.66,0.68,0.70,0.72,0.74,0.76,0.78,0.80,0.82,
198 0.84,0.86,0.88,0.90,0.92,0.94,0.96,0.98 };
200 static UShort_t gDefHistR[50] = {
201 242,229,204,178,153,127,102,76,192,204,204,193,186,178,183,173,155,135,
202 175,132,89,137,130,173,122, 117,104,109,124,127,170,89,211,221,188,198,
203 191,170,165,147,206,211,255,0,255,255,0,0,53,0 };
205 static UShort_t gDefHistG[50] = {
206 242,229,204,178,153,127,102,76,182,198,198,191,181,165,163,153,142,102,
207 206,193,211,168,158,188,142,137,130,122,153,127,165,84,206,186,158,153,
208 130,142,119,104,94,89,0,255,0,255,0,255,53,0 };
210 static UShort_t gDefHistB[50] = {
211 242,229,204,178,153,127,102,76,172,170,170,168,163,150,155,140,130,86,
212 198,163,84,160,140,198,153,145,150,132,209,155,191,216,135,135,130,124,
213 119,147,122,112,96,84,0,255,255,0,255,0,53,0 };
215 static UShort_t gDefHistA[50] = {
216 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
217 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
218 255,255,255,255,255,255,255,255,255,255,255,255,255,255 };
220 static Int_t gDefHistRoot[50] = {
221 19,18,17,16,15,14,13,12,11,20,21,22,23,24,25,26,27,28,29,30, 8,
222 31,32,33,34,35,36,37,38,39,40, 9, 41,42,43,44,45,47,48,49,46,50, 2,
223 7, 6, 5, 4, 3, 112,1};
226 class TDefHistImagePalette :
public TImagePalette {
229 TDefHistImagePalette() : TImagePalette() {
232 fColorRed = gDefHistR;
233 fColorGreen = gDefHistG;
234 fColorBlue = gDefHistB;
235 fColorAlpha = gDefHistA;
237 for (
int i = 0; i<50; i++) {
238 fColorRed[i] = fColorRed[i] << 8;
239 fColorGreen[i] = fColorGreen[i] << 8;
240 fColorBlue[i] = fColorBlue[i] << 8;
241 fColorAlpha[i] = fColorAlpha[i] << 8;
245 Int_t *GetRootColors() {
return gDefHistRoot; }
248 TImagePalette *gHistImagePalette =
new TDefHistImagePalette();
254 TPaletteEditor::TPaletteEditor(TAttImage *attImage, UInt_t, UInt_t)
256 fAttImage = attImage;
262 void TPaletteEditor::CloseWindow()
264 fAttImage->EditorClosed();
270 TImagePalette::TImagePalette()
284 TImagePalette::TImagePalette(UInt_t numPoints)
286 fNumPoints = numPoints;
287 fPoints =
new Double_t[fNumPoints];
288 fColorRed =
new UShort_t[fNumPoints];
289 fColorGreen =
new UShort_t[fNumPoints];
290 fColorBlue =
new UShort_t[fNumPoints];
291 fColorAlpha =
new UShort_t[fNumPoints];
297 TImagePalette::TImagePalette(
const TImagePalette &palette) : TObject(palette)
299 fNumPoints = palette.fNumPoints;
301 fPoints =
new Double_t[fNumPoints];
302 memcpy(fPoints, palette.fPoints, fNumPoints *
sizeof(Double_t));
304 fColorRed =
new UShort_t[fNumPoints];
305 fColorGreen =
new UShort_t[fNumPoints];
306 fColorBlue =
new UShort_t[fNumPoints];
307 fColorAlpha =
new UShort_t[fNumPoints];
308 memcpy(fColorRed, palette.fColorRed, fNumPoints *
sizeof(UShort_t));
309 memcpy(fColorGreen, palette.fColorGreen, fNumPoints *
sizeof(UShort_t));
310 memcpy(fColorBlue, palette.fColorBlue, fNumPoints *
sizeof(UShort_t));
311 memcpy(fColorAlpha, palette.fColorAlpha, fNumPoints *
sizeof(UShort_t));
317 TImagePalette::TImagePalette(Int_t ncolors, Int_t *colors)
327 static Int_t palette[50] = {19,18,17,16,15,14,13,12,11,20,
328 21,22,23,24,25,26,27,28,29,30, 8,
329 31,32,33,34,35,36,37,38,39,40, 9,
330 41,42,43,44,45,47,48,49,46,50, 2,
331 7, 6, 5, 4, 3, 112,1};
337 fNumPoints = ncolors;
338 step = 1./fNumPoints;
339 fPoints =
new Double_t[fNumPoints];
340 fColorRed =
new UShort_t[fNumPoints];
341 fColorGreen =
new UShort_t[fNumPoints];
342 fColorBlue =
new UShort_t[fNumPoints];
343 fColorAlpha =
new UShort_t[fNumPoints];
344 for (i=0;i<ncolors;i++) {
345 col = gROOT->GetColor(palette[i]);
348 fColorRed[i] = UShort_t(col->GetRed()*255) << 8;
349 fColorGreen[i] = UShort_t(col->GetGreen()*255) << 8;
350 fColorBlue[i] = UShort_t(col->GetBlue()*255) << 8;
352 fColorAlpha[i] = 65280;
358 if (ncolors == 1 && colors == 0) {
360 fNumPoints = ncolors;
361 step = 1./fNumPoints;
362 fPoints =
new Double_t[fNumPoints];
363 fColorRed =
new UShort_t[fNumPoints];
364 fColorGreen =
new UShort_t[fNumPoints];
365 fColorBlue =
new UShort_t[fNumPoints];
366 fColorAlpha =
new UShort_t[fNumPoints];
370 fColorRed[0] = 255 << 8;
371 fColorGreen[0] = 255 << 8;
372 fColorBlue[0] = 255 << 8;
375 for (i=1;i<ncolors;i++) {
376 col = gROOT->GetColor(51+i);
379 fColorRed[i] = UShort_t(col->GetRed()*255) << 8;
380 fColorGreen[i] = UShort_t(col->GetGreen()*255) << 8;
381 fColorBlue[i] = UShort_t(col->GetBlue()*255) << 8;
383 fColorAlpha[i] = 65280;
389 if (colors == 0 && ncolors > 50) {
390 static const Int_t nRGBs = 5;
391 static Float_t stops[nRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
392 static Float_t red[nRGBs] = { 0.00, 0.09, 0.18, 0.09, 0.00 };
393 static Float_t green[nRGBs] = { 0.01, 0.02, 0.39, 0.68, 0.97 };
394 static Float_t blue[nRGBs] = { 0.17, 0.39, 0.62, 0.79, 0.97 };
396 fPoints =
new Double_t[fNumPoints];
397 fColorRed =
new UShort_t[fNumPoints];
398 fColorGreen =
new UShort_t[fNumPoints];
399 fColorBlue =
new UShort_t[fNumPoints];
400 fColorAlpha =
new UShort_t[fNumPoints];
401 for (i=0;i<(int)fNumPoints;i++) {
402 fPoints[i] = stops[i];
403 fColorRed[i] = UShort_t(red[i]*255) << 8;
404 fColorGreen[i] = UShort_t(green[i]*255) << 8;
405 fColorBlue[i] = UShort_t(blue[i]*255) << 8;
406 fColorAlpha[i] = 65280;
413 fNumPoints = ncolors;
414 step = 1./fNumPoints;
415 fPoints =
new Double_t[fNumPoints];
416 fColorRed =
new UShort_t[fNumPoints];
417 fColorGreen =
new UShort_t[fNumPoints];
418 fColorBlue =
new UShort_t[fNumPoints];
419 fColorAlpha =
new UShort_t[fNumPoints];
420 for (i=0;i<ncolors;i++) {
422 col = gROOT->GetColor(colors[i]);
424 fColorRed[i] = UShort_t(col->GetRed()*255) << 8;
425 fColorGreen[i] = UShort_t(col->GetGreen()*255) << 8;
426 fColorBlue[i] = UShort_t(col->GetBlue()*255) << 8;
427 fColorAlpha[i] = 65280;
441 TImagePalette::~TImagePalette()
445 delete [] fColorGreen;
446 delete [] fColorBlue;
447 delete [] fColorAlpha;
453 TImagePalette &TImagePalette::operator=(
const TImagePalette &palette)
455 if (
this != &palette) {
456 fNumPoints = palette.fNumPoints;
459 fPoints =
new Double_t[fNumPoints];
460 memcpy(fPoints, palette.fPoints, fNumPoints *
sizeof(Double_t));
463 fColorRed =
new UShort_t[fNumPoints];
464 memcpy(fColorRed, palette.fColorRed, fNumPoints *
sizeof(UShort_t));
466 delete [] fColorGreen;
467 fColorGreen =
new UShort_t[fNumPoints];
468 memcpy(fColorGreen, palette.fColorGreen, fNumPoints *
sizeof(UShort_t));
470 delete [] fColorBlue;
471 fColorBlue =
new UShort_t[fNumPoints];
472 memcpy(fColorBlue, palette.fColorBlue, fNumPoints *
sizeof(UShort_t));
474 delete [] fColorAlpha;
475 fColorAlpha =
new UShort_t[fNumPoints];
476 memcpy(fColorAlpha, palette.fColorAlpha, fNumPoints *
sizeof(UShort_t));
485 Int_t TImagePalette::FindColor(UShort_t r, UShort_t g, UShort_t b)
491 for (UInt_t i = 0; i < fNumPoints; i++) {
492 d = TMath::Abs(r - ((fColorRed[i] & 0xff00) >> 8)) +
493 TMath::Abs(g - ((fColorGreen[i] & 0xff00) >> 8)) +
494 TMath::Abs(b - ((fColorBlue[i] & 0xff00) >> 8));
507 Int_t *TImagePalette::GetRootColors()
509 static Int_t *gRootColors = 0;
510 if (gRootColors)
return gRootColors;
512 gRootColors =
new Int_t[fNumPoints];
514 for (UInt_t i = 0; i < fNumPoints; i++) {
515 gRootColors[i] = TColor::GetColor(fColorRed[i], fColorGreen[i], fColorBlue[i]);
524 TAttImage::TAttImage()
528 fPaletteEnabled = kTRUE;
544 TAttImage::TAttImage(EImageQuality lquality, UInt_t lcompression,
549 fImageQuality = lquality;
550 fImageCompression = (lcompression > 100) ? 100 : lcompression;
551 fConstRatio = constRatio;
553 fPaletteEnabled = kTRUE;
559 TAttImage::~TAttImage()
561 delete fPaletteEditor;
567 void TAttImage::Copy(TAttImage &attimage)
const
569 attimage.fImageQuality = fImageQuality;
570 attimage.fImageCompression = fImageCompression;
571 attimage.fConstRatio = fConstRatio;
572 attimage.fPalette = fPalette;
584 void TAttImage::ResetAttImage(Option_t *)
586 fImageQuality = kImgPoor;
587 fImageCompression = 0;
591 delete [] fPalette.fPoints;
592 delete [] fPalette.fColorRed;
593 delete [] fPalette.fColorGreen;
594 delete [] fPalette.fColorBlue;
595 delete [] fPalette.fColorAlpha;
597 fPalette.fNumPoints = kNUM_DEFAULT_COLORS;
599 fPalette.fColorRed =
new UShort_t [kNUM_DEFAULT_COLORS];
600 fPalette.fColorGreen =
new UShort_t [kNUM_DEFAULT_COLORS];
601 fPalette.fColorBlue =
new UShort_t [kNUM_DEFAULT_COLORS];
602 fPalette.fColorAlpha =
new UShort_t [kNUM_DEFAULT_COLORS];
603 fPalette.fPoints =
new Double_t [kNUM_DEFAULT_COLORS];
605 memcpy(fPalette.fColorRed, gRedDefault, kNUM_DEFAULT_COLORS *
sizeof(UShort_t));
606 memcpy(fPalette.fColorGreen, gGreenDefault, kNUM_DEFAULT_COLORS *
sizeof(UShort_t));
607 memcpy(fPalette.fColorBlue, gBlueDefault, kNUM_DEFAULT_COLORS *
sizeof(UShort_t));
608 memcpy(fPalette.fColorAlpha, gAlphaDefault, kNUM_DEFAULT_COLORS *
sizeof(UShort_t));
610 for (Int_t point = 0; point < kNUM_DEFAULT_COLORS - 2; point++)
611 fPalette.fPoints[point + 1] = (
double)point / (kNUM_DEFAULT_COLORS - 3);
612 fPalette.fPoints[0] = 0;
613 fPalette.fPoints[kNUM_DEFAULT_COLORS - 1] = 1;
620 void TAttImage::SaveImageAttributes(std::ostream &out,
const char *name,
621 EImageQuality qualdef,
622 UInt_t comprdef, Bool_t constRatiodef)
624 if (fImageQuality != qualdef) {
625 out<<
" "<<name<<
"->SetImageQuality("<<fImageQuality<<
");"<<std::endl;
627 if (fImageCompression != comprdef) {
628 out<<
" "<<name<<
"->SetImageCompression("<<fImageCompression<<
");"<<std::endl;
630 if (fConstRatio != constRatiodef) {
631 out<<
" "<<name<<
"->SetConstRatio("<<fConstRatio<<
");"<<std::endl;
641 void TAttImage::SetConstRatio(Bool_t constRatio)
643 fConstRatio = constRatio;
650 void TAttImage::SetPalette(
const TImagePalette *palette)
657 delete [] fPalette.fPoints;
658 delete [] fPalette.fColorRed;
659 delete [] fPalette.fColorGreen;
660 delete [] fPalette.fColorBlue;
661 delete [] fPalette.fColorAlpha;
663 fPalette.fNumPoints = kNUM_DEFAULT_COLORS;
665 fPalette.fColorRed =
new UShort_t [kNUM_DEFAULT_COLORS];
666 fPalette.fColorGreen =
new UShort_t [kNUM_DEFAULT_COLORS];
667 fPalette.fColorBlue =
new UShort_t [kNUM_DEFAULT_COLORS];
668 fPalette.fColorAlpha =
new UShort_t [kNUM_DEFAULT_COLORS];
669 fPalette.fPoints =
new Double_t [kNUM_DEFAULT_COLORS];
671 memcpy(fPalette.fColorRed, gRedDefault, kNUM_DEFAULT_COLORS *
sizeof(UShort_t));
672 memcpy(fPalette.fColorGreen, gGreenDefault, kNUM_DEFAULT_COLORS *
sizeof(UShort_t));
673 memcpy(fPalette.fColorBlue, gBlueDefault, kNUM_DEFAULT_COLORS *
sizeof(UShort_t));
674 memcpy(fPalette.fColorAlpha, gAlphaDefault, kNUM_DEFAULT_COLORS *
sizeof(UShort_t));
676 for (Int_t point = 0; point < kNUM_DEFAULT_COLORS - 2; point++)
677 fPalette.fPoints[point + 1] = (
double)point / (kNUM_DEFAULT_COLORS - 3);
678 fPalette.fPoints[0] = 0;
679 fPalette.fPoints[kNUM_DEFAULT_COLORS - 1] = 1;
702 TImagePalette* TImagePalette::Create(Option_t* opts)
704 TImagePalette* pPalette =
nullptr;
706 TString option(opts);
707 if (option.Contains(
"col", TString::kIgnoreCase)) {
709 pPalette =
new TImagePalette(gStyle->GetNumberOfColors());
710 Double_t step = 1./(pPalette->fNumPoints-1);
712 for (UInt_t i=0; i<pPalette->fNumPoints; ++i) {
713 TColor* pColor = gROOT->GetColor(gStyle->GetColorPalette(i));
714 pPalette->fPoints[i] = i*step;
716 pPalette->fColorRed[i] = UShort_t(pColor->GetRed()*255) << 8;
717 pPalette->fColorGreen[i] = UShort_t(pColor->GetGreen()*255) << 8;
718 pPalette->fColorBlue[i] = UShort_t(pColor->GetBlue()*255) << 8;
720 pPalette->fColorAlpha[i] = 0xff00;
722 }
else if (option.Contains(
"web", TString::kIgnoreCase)) {
723 pPalette =
new TDefHistImagePalette();
724 }
else if (option.Contains(
"hist", TString::kIgnoreCase)) {
725 pPalette =
new TWebPalette();
748 TImagePalette* TImagePalette::CreateCOLPalette(Int_t ncontours)
750 Int_t ncolors = gStyle->GetNumberOfColors();
753 if (ncontours != 0 ) {
754 minColor = (0.99*ncolors)/ncontours;
755 scale =
static_cast<Double_t
>(ncolors)/ncontours;
760 auto pPalette =
new TImagePalette(ncolors);
761 Double_t step = 1./(pPalette->fNumPoints-1);
763 for (UInt_t i=0; i<pPalette->fNumPoints; ++i) {
764 TColor* pColor = gROOT->GetColor(gStyle->GetColorPalette(minColor + i*scale));
765 pPalette->fPoints[i] = i*step;
767 pPalette->fColorRed[i] = UShort_t(pColor->GetRed()*255) << 8;
768 pPalette->fColorGreen[i] = UShort_t(pColor->GetGreen()*255) << 8;
769 pPalette->fColorBlue[i] = UShort_t(pColor->GetBlue()*255) << 8;
770 pPalette->fColorAlpha[i] = UShort_t(pColor->GetAlpha()*255) << 8;
780 void TAttImage::StartPaletteEditor()
782 if (fPaletteEditor == 0) {
785 if ((h = gROOT->GetPluginManager()->FindHandler(
"TPaletteEditor"))) {
786 if (h->LoadPlugin() == -1)
788 fPaletteEditor = (TPaletteEditor *) h->ExecPlugin(3,
this, 80, 25);