Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TAttImage.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Reiner Rohlfs 24/03/02
3
4/*************************************************************************
5 * Copyright (C) 2001-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TAttImage
13\ingroup BasicGraphics
14\ingroup GraphicsAtt
15
16TImage attributes.
17
18Image attributes are:
19
20- Image Quality (see EImageQuality for the list of qualities)
21- Compression defines the compression rate of the color data in the
22 internal image structure. Speed and memory depends
23 on this rate, but not the image display itself
24 0: no compression; 100: max compression
25- Radio Flag: kTRUE the x/y radio of the displayed image is always
26 identical to the original image kFALSE the x and y size of the displayed
27 image depends on the size of the pad
28- Palette: Defines the conversion from a pixel value to the
29 screen color
30
31This class is used (in general by secondary inheritance)
32by some other classes (image display).
33*/
34
35/** \class TImagePalette
36\ingroup BasicGraphics
37
38A class to define a conversion from pixel values to pixel color.
39
40A Palette is defined by some anchor points. Each anchor point has
41a value between 0 and 1 and a color. An image has to be normalized
42and the values between the anchor points are interpolated.
43All member variables are public and can be directly manipulated.
44In most cases the default operator will be used to create a
45TImagePalette. In this case the member arrays have to be allocated
46by an application and will be deleted in the destructor of this
47class.
48
49We provide few predefined palettes:
50
51- gHistImagePalette - palette used in TH2::Draw("col")
52- gWebImagePalette
53 The web palette is a set of 216 colors that will not dither or
54 shift on PCs or Macs. Browsers use this built-in palette when
55 they need to render colors on monitors with only 256 colors
56 (also called 8-bit color monitors).
57 The 6x6x6 web palette provides very quick color index lookup
58 and can be used for good quality conversion of images into
59 2-D histograms.
60- TImagePalette(Int_t ncolors, Int_t *colors)
61 if ncolors <= 0 a default palette (see below) of 50 colors
62 is defined.
63
64if ncolors == 1 && colors == 0, then a Rainbow Palette is created.
65
66if ncolors > 50 and colors=0, the DeepSea palette is used.
67(see TStyle::CreateGradientColorTable for more details)
68
69if ncolors > 0 and colors = 0, the default palette is used with a maximum of ncolors.
70
71The default palette defines:
72- index 0->9 : grey colors from light to dark grey
73- index 10->19 : "brown" colors
74- index 20->29 : "blueish" colors
75- index 30->39 : "redish" colors
76- index 40->49 : basic colors
77*/
78
79/** \class TPaletteEditor
80\ingroup BasicGraphics
81
82Edit the palette via a GUI.
83
84This class provides a way to edit the palette via a GUI.
85*/
86
87
88#include "TAttImage.h"
89#include "TROOT.h"
90#include "TPluginManager.h"
91#include <iostream>
92#include "TColor.h"
93#include "TMath.h"
94#include "TStyle.h"
95#include <vector>
96
97
98
99// definition of a default palette
102 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
103 0xffff, 0xffff, 0xffff, 0xffff
104};
105
107 0x0000, 0x0000, 0x7000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff,
108 0x7000, 0x8000, 0xffff, 0xffff
109};
110
112 0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0x0000,
113 0x0000, 0x8000, 0xffff, 0xffff
114};
115
117 0x0000, 0x0000, 0x7000, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000,
118 0x0000, 0xa000, 0xffff, 0xffff
119};
120
121
122//////////////////////////// Web Palette ///////////////////////////////////////
123static UShort_t gWebBase[6] = { 0, 51, 102, 153, 204, 255 };
124
126
127private:
128 Int_t fCLUT[6][6][6]; // Color LookUp Table
129
130public:
132 int i = 0;
133 fNumPoints = 216;
134 fPoints = new Double_t[216];
135 fColorRed = new UShort_t[216];
136 fColorBlue = new UShort_t[216];
137 fColorGreen = new UShort_t[216];
138 fColorAlpha = new UShort_t[216];
139
140 for (i = 0; i < 214; i++) {
141 fPoints[i + 1] = (double)i/213;
142 }
143 fPoints[0] = 0;
144 fPoints[215] = 1;
145
146 i = 0;
147 for (int r = 0; r < 6; r++) {
148 for (int g = 0; g < 6; g++) {
149 for (int b = 0; b < 6; b++) {
150 fColorRed[i] = gWebBase[r] << 8;
151 fColorGreen[i] = gWebBase[g] << 8;
152 fColorBlue[i] = gWebBase[b] << 8;
153 fColorAlpha[i] = 0xffff;
154 fCLUT[r][g][b] = i;
155 i++;
156 }
157 }
158 }
159 }
160
162 {
166 return fCLUT[ri][gi][bi];
167 }
168
170 {
171 static std::vector<Int_t> gRootColors;
172 if (!gRootColors.empty())
173 return gRootColors.data();
174
175 gRootColors.resize(216);
176
177 int i = 0;
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]);
182 i++;
183 }
184 }
185 }
186 return gRootColors.data();
187 }
188};
189
191
192
193////////////////////////////// Hist Palette ////////////////////////////////////
194static 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 };
199
200static 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 };
204
205static 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 };
209
210static 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 };
214
215static 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 };
219
220static 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};
224
225
227
228public:
230 fNumPoints = 50;
236
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;
242 }
243 }
244
245 Int_t *GetRootColors() override { return gDefHistRoot; }
246};
247
249
250
251////////////////////////////////////////////////////////////////////////////////
252/// Constructor.
253
255{
256 fAttImage = attImage;
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Closes the window and deletes itself.
261
263{
264 fAttImage->EditorClosed();
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Default constructor, sets all pointers to 0.
269
273
274////////////////////////////////////////////////////////////////////////////////
275/// Constructor for a palette with numPoints anchor points.
276/// It allocates the memory but does not set any colors.
277
287
288////////////////////////////////////////////////////////////////////////////////
289/// Copy constructor.
290
292{
293 fNumPoints = palette.fNumPoints;
294
296 memcpy(fPoints, palette.fPoints, fNumPoints * sizeof(Double_t));
297
302 memcpy(fColorRed, palette.fColorRed, fNumPoints * sizeof(UShort_t));
303 memcpy(fColorGreen, palette.fColorGreen, fNumPoints * sizeof(UShort_t));
304 memcpy(fColorBlue, palette.fColorBlue, fNumPoints * sizeof(UShort_t));
305 memcpy(fColorAlpha, palette.fColorAlpha, fNumPoints * sizeof(UShort_t));
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Creates palette in the same way as TStyle::SetPalette
310
312{
313 Int_t i;
314 static Int_t palette[50] = {19,18,17,16,15,14,13,12,11,20,
315 21,22,23,24,25,26,27,28,29,30, 8,
316 31,32,33,34,35,36,37,38,39,40, 9,
317 41,42,43,44,45,47,48,49,46,50, 2,
318 7, 6, 5, 4, 3, 112,1};
319 TColor *col = nullptr;
320 Float_t step = 0;
321 // set default palette (pad type)
322 if (ncolors <= 0) {
323 ncolors = 50;
324 fNumPoints = ncolors;
325 step = 1./fNumPoints;
331 for (i=0;i<ncolors;i++) {
332 col = gROOT->GetColor(palette[i]);
333 fPoints[i] = i*step;
334 if (col) {
335 fColorRed[i] = UShort_t(col->GetRed()*255) << 8;
336 fColorGreen[i] = UShort_t(col->GetGreen()*255) << 8;
337 fColorBlue[i] = UShort_t(col->GetBlue()*255) << 8;
338 }
339 fColorAlpha[i] = 65280;
340 }
341 return;
342 }
343
344 // set Pretty Palette Spectrum Violet->Red
345 if (ncolors == 1 && !colors) {
346 ncolors = 50;
347 fNumPoints = ncolors;
348 step = 1./fNumPoints;
354
355 // 0 point is white
356 fPoints[0] = 0;
357 fColorRed[0] = 255 << 8;
358 fColorGreen[0] = 255 << 8;
359 fColorBlue[0] = 255 << 8;
360 fColorAlpha[0] = 0;
361
362 for (i=1;i<ncolors;i++) {
363 col = gROOT->GetColor(51+i);
364 fPoints[i] = i*step;
365 if (col) {
366 fColorRed[i] = UShort_t(col->GetRed()*255) << 8;
367 fColorGreen[i] = UShort_t(col->GetGreen()*255) << 8;
368 fColorBlue[i] = UShort_t(col->GetBlue()*255) << 8;
369 }
370 fColorAlpha[i] = 65280;
371 }
372 return;
373 }
374
375 // set DeepSea palette
376 if (!colors && ncolors > 50) {
377 static const Int_t nRGBs = 5;
378 static Float_t stops[nRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
379 static Float_t red[nRGBs] = { 0.00, 0.09, 0.18, 0.09, 0.00 };
380 static Float_t green[nRGBs] = { 0.01, 0.02, 0.39, 0.68, 0.97 };
381 static Float_t blue[nRGBs] = { 0.17, 0.39, 0.62, 0.79, 0.97 };
382 fNumPoints = nRGBs;
388 for (i=0;i<(int)fNumPoints;i++) {
389 fPoints[i] = stops[i];
390 fColorRed[i] = UShort_t(red[i]*255) << 8;
391 fColorGreen[i] = UShort_t(green[i]*255) << 8;
392 fColorBlue[i] = UShort_t(blue[i]*255) << 8;
393 fColorAlpha[i] = 65280;
394 }
395 return;
396 }
397
398 // set user defined palette
399 if (colors) {
400 fNumPoints = ncolors;
401 step = 1./fNumPoints;
407 for (i=0;i<ncolors;i++) {
408 fPoints[i] = i*step;
409 col = gROOT->GetColor(colors[i]);
410 if (col) {
411 fColorRed[i] = UShort_t(col->GetRed()*255) << 8;
412 fColorGreen[i] = UShort_t(col->GetGreen()*255) << 8;
413 fColorBlue[i] = UShort_t(col->GetBlue()*255) << 8;
414 fColorAlpha[i] = 65280;
415 } else {
416 fColorRed[i] = 0;
417 fColorGreen[i] = 0;
418 fColorBlue[i] = 0;
419 fColorAlpha[i] = 0;
420 }
421 }
422 }
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// Destructor.
427
429{
430 delete [] fPoints;
431 delete [] fColorRed;
432 delete [] fColorGreen;
433 delete [] fColorBlue;
434 delete [] fColorAlpha;
435}
436
437////////////////////////////////////////////////////////////////////////////////
438/// Assignment operator.
439
441{
442 if (this != &palette) {
443 fNumPoints = palette.fNumPoints;
444
445 delete [] fPoints;
447 memcpy(fPoints, palette.fPoints, fNumPoints * sizeof(Double_t));
448
449 delete [] fColorRed;
451 memcpy(fColorRed, palette.fColorRed, fNumPoints * sizeof(UShort_t));
452
453 delete [] fColorGreen;
455 memcpy(fColorGreen, palette.fColorGreen, fNumPoints * sizeof(UShort_t));
456
457 delete [] fColorBlue;
459 memcpy(fColorBlue, palette.fColorBlue, fNumPoints * sizeof(UShort_t));
460
461 delete [] fColorAlpha;
463 memcpy(fColorAlpha, palette.fColorAlpha, fNumPoints * sizeof(UShort_t));
464 }
465
466 return *this;
467}
468
469////////////////////////////////////////////////////////////////////////////////
470/// Returns an index of the closest color
471
473{
474 Int_t ret = 0;
475 UInt_t d = 10000;
476 UInt_t min = 10000;
477
478 for (UInt_t i = 0; i < fNumPoints; i++) {
479 d = TMath::Abs(r - ((fColorRed[i] & 0xff00) >> 8)) +
480 TMath::Abs(g - ((fColorGreen[i] & 0xff00) >> 8)) +
481 TMath::Abs(b - ((fColorBlue[i] & 0xff00) >> 8));
482 if (d < min) {
483 min = d;
484 ret = i;
485 }
486 }
487 return ret;
488}
489
490////////////////////////////////////////////////////////////////////////////////
491/// Returns a list of ROOT colors. Could be used to set histogram palette.
492/// See also TStyle::SetPalette
493
495{
496 static std::vector<Int_t> gRootColors;
497 if (!gRootColors.empty())
498 return gRootColors.data();
499
500 gRootColors.resize(fNumPoints);
501
502 for (UInt_t i = 0; i < fNumPoints; i++)
503 gRootColors[i] = TColor::GetColor(fColorRed[i], fColorGreen[i], fColorBlue[i]);
504
505 return gRootColors.data();
506}
507
508////////////////////////////////////////////////////////////////////////////////
509/// TAttImage default constructor.
510/// Calls ResetAttImage to set the attributes to a default state.
511
518
519////////////////////////////////////////////////////////////////////////////////
520/// TAttImage normal constructor.
521/// Image attributes are taken from the argument list
522///
523/// \param[in] lquality must be one of EImageQuality (kImgDefault is same as
524/// kImgGood in the current implementation)
525/// \param[in] lcompression defines the compression rate of the color data in the
526/// image. Speed and memory depends on this rate, but not
527/// the image display itself
528/// 0: no compression; 100: max compression
529/// \param[in] constRatio keeps the aspect ratio of the image constant on the
530/// screen (in pixel units)
531
533 Bool_t constRatio)
534{
536
537 fImageQuality = lquality;
538 fImageCompression = (lcompression > 100) ? 100 : lcompression;
539 fConstRatio = constRatio;
540 fPaletteEditor = nullptr;
542}
543
544////////////////////////////////////////////////////////////////////////////////
545/// TAttImage destructor.
546
548{
549 delete fPaletteEditor;
550}
551
552////////////////////////////////////////////////////////////////////////////////
553/// Copy this image attributes to a new attimage.
554
555void TAttImage::Copy(TAttImage &attimage) const
556{
557 attimage.fImageQuality = fImageQuality;
559 attimage.fConstRatio = fConstRatio;
560 attimage.fPalette = fPalette;
561}
562
563////////////////////////////////////////////////////////////////////////////////
564/// Reset this image attributes to default values.
565/// Default values are:
566///
567/// - quality: kImgPoor, (no smoothing while the image is zoomed)
568/// - compression: 0 (no compression)
569/// - constRatio: kTRUE
570/// - palette: a default rainbow palette
571
573{
577
578 // set the default palette
579 delete [] fPalette.fPoints;
580 delete [] fPalette.fColorRed;
581 delete [] fPalette.fColorGreen;
582 delete [] fPalette.fColorBlue;
583 delete [] fPalette.fColorAlpha;
584
585 fPalette.fNumPoints = kNUM_DEFAULT_COLORS;
586
587 fPalette.fColorRed = new UShort_t [kNUM_DEFAULT_COLORS];
588 fPalette.fColorGreen = new UShort_t [kNUM_DEFAULT_COLORS];
589 fPalette.fColorBlue = new UShort_t [kNUM_DEFAULT_COLORS];
590 fPalette.fColorAlpha = new UShort_t [kNUM_DEFAULT_COLORS];
591 fPalette.fPoints = new Double_t [kNUM_DEFAULT_COLORS];
592
593 memcpy(fPalette.fColorRed, gRedDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
594 memcpy(fPalette.fColorGreen, gGreenDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
595 memcpy(fPalette.fColorBlue, gBlueDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
596 memcpy(fPalette.fColorAlpha, gAlphaDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
597
598 for (Int_t point = 0; point < kNUM_DEFAULT_COLORS - 2; point++)
599 fPalette.fPoints[point + 1] = (double)point / (kNUM_DEFAULT_COLORS - 3);
600 fPalette.fPoints[0] = 0;
601 fPalette.fPoints[kNUM_DEFAULT_COLORS - 1] = 1;
602}
603
604////////////////////////////////////////////////////////////////////////////////
605/// Save image attributes as C++ statement(s) on output stream, but
606/// not the palette.
607
608void TAttImage::SaveImageAttributes(std::ostream &out, const char *name,
609 EImageQuality qualdef,
610 UInt_t comprdef, Bool_t constRatiodef)
611{
612 if (fImageQuality != qualdef) {
613 out << " " << name << "->SetImageQuality(TAttImage::";
614 switch (fImageQuality) {
615 case kImgPoor: out << "kImgPoor"; break;
616 case kImgFast: out << "kImgFast"; break;
617 case kImgGood: out << "kImgGood"; break;
618 case kImgBest: out << "kImgBest"; break;
619 default: out << "kImgDefault";
620 }
621 out << ");\n";
622 }
623 if (fImageCompression != comprdef)
624 out << " " << name << "->SetImageCompression(" << fImageCompression << ");\n";
625 if (fConstRatio != constRatiodef)
626 out << " " << name << "->SetConstRatio(" << (fConstRatio ? "kTRUE" : "kFALSE") << ");\n";
627}
628
629////////////////////////////////////////////////////////////////////////////////
630/// Set (constRatio = kTRUE) or unset (constRadio = kFALSE) the ratio flag.
631/// The aspect ratio of the image on the screen is constant if the ratio
632/// flag is set. That means one image pixel is always a square on the screen
633/// independent of the pad size and of the size of the zoomed area.
634
636{
637 fConstRatio = constRatio;
638}
639
640////////////////////////////////////////////////////////////////////////////////
641/// Set a new palette for the image. If palette == 0 a default
642/// rainbow color palette is used.
643
645{
646 if (palette)
647 fPalette = *palette;
648 else {
649 // set default palette
650
651 delete [] fPalette.fPoints;
652 delete [] fPalette.fColorRed;
653 delete [] fPalette.fColorGreen;
654 delete [] fPalette.fColorBlue;
655 delete [] fPalette.fColorAlpha;
656
657 fPalette.fNumPoints = kNUM_DEFAULT_COLORS;
658
659 fPalette.fColorRed = new UShort_t [kNUM_DEFAULT_COLORS];
660 fPalette.fColorGreen = new UShort_t [kNUM_DEFAULT_COLORS];
661 fPalette.fColorBlue = new UShort_t [kNUM_DEFAULT_COLORS];
662 fPalette.fColorAlpha = new UShort_t [kNUM_DEFAULT_COLORS];
663 fPalette.fPoints = new Double_t [kNUM_DEFAULT_COLORS];
664
665 memcpy(fPalette.fColorRed, gRedDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
666 memcpy(fPalette.fColorGreen, gGreenDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
667 memcpy(fPalette.fColorBlue, gBlueDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
668 memcpy(fPalette.fColorAlpha, gAlphaDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
669
670 for (Int_t point = 0; point < kNUM_DEFAULT_COLORS - 2; point++)
671 fPalette.fPoints[point + 1] = (double)point / (kNUM_DEFAULT_COLORS - 3);
672 fPalette.fPoints[0] = 0;
673 fPalette.fPoints[kNUM_DEFAULT_COLORS - 1] = 1;
674 }
675}
676
677////////////////////////////////////////////////////////////////////////////////
678/// Factory method to creates an image palette of a specific typ
679///
680/// Create a new palette
681///
682/// This creates a new TImagePalette based on the
683/// option specified in the parameter. The supported options are:
684///
685/// - "col" - color palette similar in TStyle (i.e. use for "col" option)
686/// - "web" - color palette similar to gWebImagePalette
687/// - "hist" - color palette similar to gHistImagePalette
688///
689/// \param opts the type of palette to create
690///
691/// Ownership of the returned object transfers to the caller.
692///
693/// \retval new palette
694/// \retval nullptr - option does not exist
695
697{
698 TImagePalette* pPalette = nullptr;
699
700 TString option(opts);
701 if (option.Contains("col", TString::kIgnoreCase)) {
702 // Define the new palette using the current palette in TStyle
703 pPalette = new TImagePalette(gStyle->GetNumberOfColors());
704 Double_t step = 1./(pPalette->fNumPoints-1);
705
706 for (UInt_t i=0; i<pPalette->fNumPoints; ++i) {
707 TColor* pColor = gROOT->GetColor(gStyle->GetColorPalette(i));
708 pPalette->fPoints[i] = i*step;
709 if (pColor) {
710 pPalette->fColorRed[i] = UShort_t(pColor->GetRed()*255) << 8;
711 pPalette->fColorGreen[i] = UShort_t(pColor->GetGreen()*255) << 8;
712 pPalette->fColorBlue[i] = UShort_t(pColor->GetBlue()*255) << 8;
713 }
714 pPalette->fColorAlpha[i] = 0xff00;
715 }
716 } else if (option.Contains("web", TString::kIgnoreCase)) {
717 pPalette = new TDefHistImagePalette();
718 } else if (option.Contains("hist", TString::kIgnoreCase)) {
719 pPalette = new TWebPalette();
720 }
721
722 return pPalette;
723}
724
725////////////////////////////////////////////////////////////////////////////////
726/// Factory method to creates an image palette for histogram plotting.
727///
728/// Creates a "col" palette with correct number of contours
729///
730/// The behavior is similar to the TImagePalette::Create() method with
731/// the "col" option. The difference here is that the palette will only
732/// contain a specific number of colors. This method is used to create
733/// the palette used in the "col2" and "colz2" options. It handles the
734/// color selection for contours.
735///
736/// \param ncontours number of contours
737///
738/// Ownership of the returned object transfers to the caller.
739///
740/// \return new palette
741
743{
744 Int_t ncolors = gStyle->GetNumberOfColors();
745 Int_t minColor = 0;
746 Double_t scale = 1;
747 if (ncontours != 0 ) {
748 minColor = (0.99*ncolors)/ncontours;
749 scale = static_cast<Double_t>(ncolors)/ncontours;
750 ncolors = ncontours;
751 }
752
753 // Define the new palette using the current palette in TStyle
754 auto pPalette = new TImagePalette(ncolors);
755 Double_t step = 1./(pPalette->fNumPoints-1);
756
757 for (UInt_t i=0; i<pPalette->fNumPoints; ++i) {
758 TColor* pColor = gROOT->GetColor(gStyle->GetColorPalette(minColor + i*scale));
759 pPalette->fPoints[i] = i*step;
760 if (pColor) {
761 pPalette->fColorRed[i] = UShort_t(pColor->GetRed()*255) << 8;
762 pPalette->fColorGreen[i] = UShort_t(pColor->GetGreen()*255) << 8;
763 pPalette->fColorBlue[i] = UShort_t(pColor->GetBlue()*255) << 8;
764 pPalette->fColorAlpha[i] = UShort_t(pColor->GetAlpha()*255) << 8;
765 }
766 }
767
768 return pPalette;
769}
770
771////////////////////////////////////////////////////////////////////////////////
772/// Opens a GUI to edit the color palette.
773
775{
776 if (!fPaletteEditor)
777 if (auto h = gROOT->GetPluginManager()->FindHandler("TPaletteEditor")) {
778 if (h->LoadPlugin() == -1)
779 return;
780 fPaletteEditor = (TPaletteEditor *) h->ExecPlugin(3, this, 80, 25);
781 }
782}
ROOT::R::TRInterface & r
Definition Object.C:4
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
char * ret
Definition Rotated.cxx:221
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short).
Definition RtypesCore.h:54
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
short Short_t
Signed Short integer 2 bytes (short).
Definition RtypesCore.h:53
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
static UShort_t gBlueDefault[kNUM_DEFAULT_COLORS]
static UShort_t gWebBase[6]
static UShort_t gGreenDefault[kNUM_DEFAULT_COLORS]
static UShort_t gDefHistG[50]
static UShort_t gDefHistA[50]
static UShort_t gDefHistR[50]
const Int_t kNUM_DEFAULT_COLORS
static Double_t gDefHistP[50]
static UShort_t gAlphaDefault[kNUM_DEFAULT_COLORS]
static UShort_t gDefHistB[50]
static Int_t gDefHistRoot[50]
static UShort_t gRedDefault[kNUM_DEFAULT_COLORS]
externTImagePalette * gHistImagePalette
Definition TAttImage.h:109
externTImagePalette * gWebImagePalette
Definition TAttImage.h:110
char name[80]
Definition TGX11.cxx:148
#define gROOT
Definition TROOT.h:417
externTStyle * gStyle
Definition TStyle.h:442
Color * colors
Definition X3DBuffer.c:21
TImage attributes.
Definition TAttImage.h:59
TPaletteEditor * fPaletteEditor
! GUI to edit the color palette
Definition TAttImage.h:76
virtual void ResetAttImage(Option_t *option="")
Reset this image attributes to default values.
virtual void SetPalette(const TImagePalette *palette)
Set a new palette for the image.
Bool_t fConstRatio
keep aspect ratio of image on the screen
Definition TAttImage.h:74
virtual ~TAttImage()
TAttImage destructor.
UInt_t fImageCompression
compression [0 .. 100] 0: no compression
Definition TAttImage.h:73
EImageQuality fImageQuality
OPTION={GetMethod="GetImageQuality";SetMethod="SetImageQuality";Items=(kImgDefault="Default",...
Definition TAttImage.h:72
TAttImage()
TAttImage default constructor.
void Copy(TAttImage &attline) const
Copy this image attributes to a new attimage.
TImagePalette fPalette
color palette for value -> color conversion
Definition TAttImage.h:75
Bool_t fPaletteEnabled
! kTRUE - palette is drawn on the image
Definition TAttImage.h:77
virtual void SaveImageAttributes(std::ostream &out, const char *name, EImageQuality qualdef=kImgPoor, UInt_t comprdef=0, Bool_t constRatiodef=kTRUE)
Save image attributes as C++ statement(s) on output stream, but not the palette.
virtual void SetConstRatio(Bool_t constRatio=kTRUE)
Set (constRatio = kTRUE) or unset (constRadio = kFALSE) the ratio flag.
virtual void StartPaletteEditor()
Opens a GUI to edit the color palette.
Float_t GetRed() const
Definition TColor.h:61
static Int_t GetColor(const char *hexcolor)
Float_t GetAlpha() const
Definition TColor.h:67
Float_t GetBlue() const
Definition TColor.h:63
Float_t GetGreen() const
Definition TColor.h:62
Int_t * GetRootColors() override
Returns a list of ROOT colors.
A class to define a conversion from pixel values to pixel color.
Definition TAttImage.h:33
TImagePalette & operator=(const TImagePalette &palette)
Assignment operator.
virtual Int_t * GetRootColors()
Returns a list of ROOT colors.
UShort_t * fColorRed
[fNumPoints] red color at each anchor point
Definition TAttImage.h:38
~TImagePalette() override
Destructor.
Double_t * fPoints
[fNumPoints] value of each anchor point [0..1]
Definition TAttImage.h:37
static TImagePalette * CreateCOLPalette(Int_t nContours)
Factory method to creates an image palette for histogram plotting.
TImagePalette()
Default constructor, sets all pointers to 0.
virtual Int_t FindColor(UShort_t r, UShort_t g, UShort_t b)
Returns an index of the closest color.
UShort_t * fColorGreen
[fNumPoints] green color at each anchor point
Definition TAttImage.h:39
UShort_t * fColorBlue
[fNumPoints] blue color at each anchor point
Definition TAttImage.h:40
UInt_t fNumPoints
number of anchor points
Definition TAttImage.h:36
static TImagePalette * Create(Option_t *opts)
Factory method to creates an image palette of a specific typ.
UShort_t * fColorAlpha
[fNumPoints] alpha at each anchor point
Definition TAttImage.h:41
TObject()
TObject constructor.
Definition TObject.h:259
Edit the palette via a GUI.
Definition TAttImage.h:19
virtual void CloseWindow()
Closes the window and deletes itself.
TAttImage * fAttImage
Definition TAttImage.h:22
TPaletteEditor(TAttImage *attImage, UInt_t w, UInt_t h)
Constructor.
Basic string class.
Definition TString.h:138
@ kIgnoreCase
Definition TString.h:285
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
Int_t fCLUT[6][6][6]
Int_t FindColor(UShort_t r, UShort_t g, UShort_t b) override
Returns an index of the closest color.
Int_t * GetRootColors() override
Returns a list of ROOT colors.
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Definition TMathBase.h:329
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122