Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TColor.cxx
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Rene Brun 12/12/94
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
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#include "TROOT.h"
13#include "TColor.h"
14#include "TObjArray.h"
15#include "TArrayI.h"
16#include "TArrayD.h"
17#include "TVirtualX.h"
18#include "TError.h"
19#include "TMathBase.h"
20#include "TApplication.h"
21#include "TColorGradient.h"
22#include "snprintf.h"
23
24#include <algorithm>
25#include <cmath>
26#include <fstream>
27#include <iostream>
28#include <sstream>
29#include <stdexcept>
30
32
33namespace {
35 static Bool_t grayScaleMode;
36 return grayScaleMode;
37 }
38 static TArrayI& TColor__Palette() {
39 static TArrayI globalPalette(0);
40 return globalPalette;
41 }
44 return globalPalettesList;
45 }
46}
47
48static Int_t gHighestColorIndex = 0; ///< Highest color index defined
49static Float_t gColorThreshold = -1.; ///< Color threshold used by GetColor
50static Int_t gDefinedColors = 0; ///< Number of defined colors.
51static Int_t gLastDefinedColors = 649; ///< Previous number of defined colors
52
53#define fgGrayscaleMode TColor__GrayScaleMode()
54#define fgPalette TColor__Palette()
55#define fgPalettesList TColor__PalettesList()
56
57using std::floor;
58
59/** \class TColor
60\ingroup Base
61\ingroup GraphicsAtt
62
63The color creation and management class.
64
65 - [Introduction](\ref C00)
66 - [Basic colors](\ref C01)
67 - [The color wheel](\ref C02)
68 - [Bright and dark colors](\ref C03)
69 - [Accessible Color Schemes](\ref C031)
70 - [Gray scale view of of canvas with colors](\ref C04)
71 - [Color palettes](\ref C05)
72 - [High quality predefined palettes](\ref C06)
73 - [Colour Vision Deficiency (CVD) friendly palettes](\ref C06a)
74 - [Non Colour Vision Deficiency (CVD) friendly palettes](\ref C06b)
75 - [Palette inversion](\ref C061)
76 - [Color transparency](\ref C07)
77
78\anchor C00
79## Introduction
80
81Colors are defined by their red, green and blue components, simply called the
82RGB components. The colors are also known by the hue, light and saturation
83components also known as the HLS components. When a new color is created the
84components of both color systems are computed.
85
86At initialization time, a table of colors is generated. An existing color can
87be retrieved by its index:
88
89~~~ {.cpp}
90 TColor *color = gROOT->GetColor(10);
91~~~
92
93Then it can be manipulated. For example its RGB components can be modified:
94
95~~~ {.cpp}
96 color->SetRGB(0.1, 0.2, 0.3);
97~~~
98
99A new color can be created the following way:
100
101~~~ {.cpp}
102 Int_t ci = 1756; // color index
103 auto color = new TColor(ci, 0.1, 0.2, 0.3);
104~~~
105
106\since **6.07/07:**
107TColor::GetFreeColorIndex() allows to make sure the new color is created with an
108unused color index:
109
110~~~ {.cpp}
111 Int_t ci = TColor::GetFreeColorIndex();
112 auto color = new TColor(ci, 0.1, 0.2, 0.3);
113~~~
114
115Two sets of colors are initialized;
116
117 - The basic colors: colors with index from 0 to 50.
118 - The color wheel: colors with indices from 300 to 1000.
119
120\anchor C01
121## Basic colors
122The following image displays the 50 basic colors.
123
124Begin_Macro(source)
125{
126 auto c = new TCanvas("c","Fill Area colors",0,0,500,200);
127 c->DrawColorTable();
128 return c;
129}
130End_Macro
131
132\anchor C02
133## The color wheel
134The wheel contains the recommended 216 colors to be used in web applications.
135
136The colors in the color wheel are created by `TColor::CreateColorWheel`.
137
138Using this color set for your text, background or graphics will give your
139application a consistent appearance across different platforms and browsers.
140
141Colors are grouped by hue, the aspect most important in human perception.
142Touching color chips have the same hue, but with different brightness and
143vividness.
144
145Colors of slightly different hues clash. If you intend to display
146colors of the same hue together, you should pick them from the same group.
147
148Each color chip is identified by a mnemonic (e.g. kYellow) and a number.
149The keywords, kRed, kBlue, kYellow, kPink, etc are defined in the header file
150Rtypes.h that is included in all ROOT other header files. It is better
151to use these keywords in user code instead of hardcoded color numbers, e.g.:
152
153~~~ {.cpp}
154 myObject.SetFillColor(kRed);
155 myObject.SetFillColor(kYellow-10);
156 myLine.SetLineColor(kMagenta+2);
157~~~
158
159Begin_Macro(source)
160{
161 auto w = new TColorWheel();
162 auto cw = new TCanvas("cw","cw",0,0,400,400);
163 w->SetCanvas(cw);
164 w->Draw();
165}
166End_Macro
167
168The complete list of predefined color names is the following:
169
170~~~ {.cpp}
171kWhite = 0, kBlack = 1, kGray = 920, kRed = 632, kGreen = 416,
172kBlue = 600, kYellow = 400, kMagenta = 616, kCyan = 432, kOrange = 800,
173kSpring = 820, kTeal = 840, kAzure = 860, kViolet = 880, kPink = 900
174~~~
175
176Note the special role of color `kWhite` (color number 0). It is the default
177background color also. For instance in a PDF or PS files (as paper is usually white)
178it is simply not painted. To have a white color behaving like the other color the
179simplest is to define an other white color not attached to the color index 0:
180
181~~~ {.cpp}
182 Int_t ci = TColor::GetFreeColorIndex();
183 TColor *color = new TColor(ci, 1., 1., 1.);
184~~~
185
186\anchor C03
187## Bright and dark colors
188Dark and bright colors are used to add 3D effects to graphical objects like
189TWbox, TPave, TPaveText, TPaveLabel, etc. and in colored lego plots.
190
191Two static functions are available that return the bright or dark color number corresponding
192to a given color index. If these variants don't already exist, they are created as needed:
193~~~ {.cpp}
194 Int_t dark = TColor::GetColorDark(color_index);
195 Int_t bright = TColor::GetColorBright(color_index);
196~~~
197
198\anchor C031
199## Accessible Color Schemes
200Choosing an appropriate color scheme is essential for making results easy to understand and
201interpret. Factors like colorblindness and converting colors to grayscale for publications
202can impact accessibility. Furthermore, results should be aesthetically pleasing. The following
203three color schemes, recommended by M. Petroff in [arXiv:2107.02270v2](https://arxiv.org/pdf/2107.02270)
204and available on [GitHub](https://github.com/mpetroff/accessible-color-cycles)
205under the MIT License, meet these criteria.
206
207These three color schemes are available as color sets with 6, 8, and 10 colors, named
208`kP[6, 8, 10]ColorName`. For example, `kP6Red` represents the red color within the P6 color scheme
209(`P` for Petroff or Preferred).
210
211Begin_Macro
212../../../tutorials/visualisation/graphics/accessiblecolorschemes.C
213End_Macro
214
215The example thstackcolorscheme.C illustrates how to use these color schemes in THStack drawings.
216It also demonstrates that they are effective in grayscale.
217
218\anchor C04
219## Grayscale view of of canvas with colors
220One can toggle between a grayscale preview and the regular colored mode using
221`TCanvas::SetGrayscale()`. Note that in grayscale mode, access via RGB
222will return grayscale values according to ITU standards (and close to b&w
223printer gray-scales), while access via HLS returns de-saturated gray-scales. The
224image below shows the ROOT color wheel in grayscale mode.
225
226Begin_Macro(source)
227{
228 auto w = new TColorWheel();
229 auto cw = new TCanvas("cw","cw",0,0,400,400);
230 cw->GetCanvas()->SetGrayscale();
231 w->SetCanvas(cw);
232 w->Draw();
233}
234End_Macro
235
236\anchor C05
237## Color palettes
238It is often very useful to represent a variable with a color map. The concept
239of "color palette" allows to do that. One color palette is active at any time.
240This "current palette" is set using:
241
242~~~ {.cpp}
243gStyle->SetPalette(...);
244~~~
245
246This function has two parameters: the number of colors in the palette and an
247array of containing the indices of colors in the palette. The following small
248example demonstrates how to define and use the color palette:
249
250Begin_Macro(source)
251{
252 auto c1 = new TCanvas("c1","c1",0,0,600,400);
253 TF2 *f1 = new TF2("f1","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
254 Int_t palette[5];
255 palette[0] = 15;
256 palette[1] = 20;
257 palette[2] = 23;
258 palette[3] = 30;
259 palette[4] = 32;
260 gStyle->SetPalette(5,palette);
261 f1->Draw("colz");
262 return c1;
263}
264End_Macro
265
266To define more a complex palette with a continuous gradient of color, one
267should use the static function `TColor::CreateGradientColorTable()`.
268The following example demonstrates how to proceed:
269
270Begin_Macro(source)
271{
272 auto c2 = new TCanvas("c2","c2",0,0,600,400);
273 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
274 const Int_t Number = 3;
275 Double_t Red[Number] = { 1.00, 0.00, 0.00};
276 Double_t Green[Number] = { 0.00, 1.00, 0.00};
277 Double_t Blue[Number] = { 1.00, 0.00, 1.00};
278 Double_t Length[Number] = { 0.00, 0.50, 1.00 };
279 Int_t nb=50;
280 TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
281 f2->SetContour(nb);
282 f2->SetLineWidth(1);
283 f2->SetLineColor(kBlack);
284 f2->Draw("surf1z");
285 return c2;
286}
287End_Macro
288
289The function `TColor::CreateGradientColorTable()` automatically
290calls `gStyle->SetPalette()`, so there is not need to add one.
291
292After a call to `TColor::CreateGradientColorTable()` it is sometimes
293useful to store the newly create palette for further use. In particular, it is
294recommended to do if one wants to switch between several user define palettes.
295To store a palette in an array it is enough to do:
296
297~~~ {.cpp}
298 Int_t MyPalette[100];
299 Double_t Red[] = {0., 0.0, 1.0, 1.0, 1.0};
300 Double_t Green[] = {0., 0.0, 0.0, 1.0, 1.0};
301 Double_t Blue[] = {0., 1.0, 0.0, 0.0, 1.0};
302 Double_t Length[] = {0., .25, .50, .75, 1.0};
303 Int_t FI = TColor::CreateGradientColorTable(5, Length, Red, Green, Blue, 100);
304 for (int i=0;i<100;i++) MyPalette[i] = FI+i;
305~~~
306
307Later on to reuse the palette `MyPalette` it will be enough to do
308
309~~~ {.cpp}
310 gStyle->SetPalette(100, MyPalette);
311~~~
312
313As only one palette is active, one need to use `TExec` to be able to
314display plots using different palettes on the same pad.
315The tutorial multipalette.C illustrates this feature.
316
317Begin_Macro(source)
318../../../tutorials/visualisation/graphics/multipalette.C
319End_Macro
320
321\since **6.26:**
322The function `TColor::CreateColorTableFromFile("filename.txt")` allows you to create a color
323palette based on an input ASCII file. In contrast to `TColor::CreateGradientColorTable()`, here
324the length (spacing) is constant and can not be tuned. There is no gradient being interpolated
325between adjacent colors. The palette will contain the exact colors stored in the file, that
326comprises one line per color in the format "r g b" as floats.
327
328\anchor C06
329## High quality predefined palettes
330\since **6.04:**
33163 high quality palettes are predefined with 255 colors each.
332
333These palettes can be accessed "by name" with `gStyle->SetPalette(num)`.
334`num` can be taken within the following enum:
335
336~~~ {.cpp}
337kDeepSea=51, kGreyScale=52, kDarkBodyRadiator=53,
338kBlueYellow= 54, kRainBow=55, kInvertedDarkBodyRadiator=56,
339kBird=57, kCubehelix=58, kGreenRedViolet=59,
340kBlueRedYellow=60, kOcean=61, kColorPrintableOnGrey=62,
341kAlpine=63, kAquamarine=64, kArmy=65,
342kAtlantic=66, kAurora=67, kAvocado=68,
343kBeach=69, kBlackBody=70, kBlueGreenYellow=71,
344kBrownCyan=72, kCMYK=73, kCandy=74,
345kCherry=75, kCoffee=76, kDarkRainBow=77,
346kDarkTerrain=78, kFall=79, kFruitPunch=80,
347kFuchsia=81, kGreyYellow=82, kGreenBrownTerrain=83,
348kGreenPink=84, kIsland=85, kLake=86,
349kLightTemperature=87, kLightTerrain=88, kMint=89,
350kNeon=90, kPastel=91, kPearl=92,
351kPigeon=93, kPlum=94, kRedBlue=95,
352kRose=96, kRust=97, kSandyTerrain=98,
353kSienna=99, kSolar=100, kSouthWest=101,
354kStarryNight=102, kSunset=103, kTemperatureMap=104,
355kThermometer=105, kValentine=106, kVisibleSpectrum=107,
356kWaterMelon=108, kCool=109, kCopper=110,
357kGistEarth=111, kViridis=112, kCividis=113
358~~~
359
360As explained in [Crameri, F., Shephard, G.E. & Heron, P.J. The misuse of colour in science communication.
361Nat Commun 11, 5444 (2020)](https://doi.org/10.1038/s41467-020-19160-7) some color maps
362can visually distord data, specially for people with colour-vision deficiencies.
363
364For instance one can immediately see the [disadvantages of the Rainbow color
365map](https://root.cern.ch/rainbow-color-map), which is misleading for colour-blinded people in a 2D plot (not so much in
366a 3D surfaces).
367
368The `kCMYK` palette, is also not great because it's dark, then lighter, then
369half-dark again. Some others, like `kAquamarine`, have almost no contrast therefore it would
370be almost impossible (for a color blind person) to see something with a such palette.
371
372Therefore the palettes are classified in two categories: those which are Colour Vision Deficiency
373friendly and those which are not.
374
375An easy way to classify the palettes is to turn them into grayscale using TCanvas::SetGrayscale().
376The grayscale version of a palette should be as proportional as possible, and monotonously
377increasing or decreasing.
378
379Unless it is symmetrical, then it is fine to have white in the
380borders and black in the centre (for example an axis that goes between
381-40 degrees and +40 degrees, the 0 has a meaning in the perceptualcolormap.C example).
382
383A full set of colour-vision deficiency friendly and perceptually uniform colour maps can be
384[downloaded](https://doi.org/10.5281/zenodo.4491293) and used with ROOT (since 6.26) via:
385`gStyle->SetPalette("filename.txt")` or `TColor::CreateColorTableFromFile("filename.txt")`.
386Remember to increase the number of contours for a smoother result, e.g.:
387`gStyle->SetNumberContours(99)` if you are drawing with "surf1z" or `gStyle->SetNumberContours(256)`
388if with "colz".
389
390\anchor C06a
391### Colour Vision Deficiency (CVD) friendly palettes
392
393<table border=0>
394<tr><td>
395Begin_Macro
396{
397 auto c = new TCanvas("c","c",0,0,300,300);
398 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
399 f2->SetContour(99); gStyle->SetPalette(kBird);
400 f2->Draw("surf2Z"); f2->SetTitle("kBird (default)");
401}
402End_Macro
403</td><td>
404Begin_Macro
405{
406 auto c = new TCanvas("c","c",0,0,300,300);
407 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
408 f2->SetContour(99); gStyle->SetPalette(kGreyScale);
409 f2->Draw("surf2Z"); f2->SetTitle("kGreyScale");
410}
411End_Macro
412</td><td>
413Begin_Macro
414{
415 auto c = new TCanvas("c","c",0,0,300,300);
416 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
417 f2->SetContour(99); gStyle->SetPalette(kDarkBodyRadiator);
418 f2->Draw("surf2Z"); f2->SetTitle("kDarkBodyRadiator");
419}
420End_Macro
421</td></tr>
422<tr><td>
423Begin_Macro
424{
425 auto c = new TCanvas("c","c",0,0,300,300);
426 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
427 f2->SetContour(99); gStyle->SetPalette(kBlueYellow);
428 f2->Draw("surf2Z"); f2->SetTitle("kBlueYellow");
429}
430End_Macro
431</td><td>
432Begin_Macro
433{
434 auto c = new TCanvas("c","c",0,0,300,300);
435 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
436 f2->SetContour(99); gStyle->SetPalette(kWaterMelon);
437 f2->Draw("surf2Z"); f2->SetTitle("kWaterMelon");
438}
439End_Macro
440</td><td>
441Begin_Macro
442{
443 auto c = new TCanvas("c","c",0,0,300,300);
444 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
445 f2->SetContour(99); gStyle->SetPalette(kInvertedDarkBodyRadiator);
446 f2->Draw("surf2Z"); f2->SetTitle("kInvertedDarkBodyRadiator");
447}
448End_Macro
449</td></tr>
450<tr><td>
451Begin_Macro
452{
453 auto c = new TCanvas("c","c",0,0,300,300);
454 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
455 f2->SetContour(99); gStyle->SetPalette(kDeepSea);
456 f2->Draw("surf2Z"); f2->SetTitle("kDeepSea");
457}
458End_Macro
459</td><td>
460Begin_Macro
461{
462 auto c = new TCanvas("c","c",0,0,300,300);
463 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
464 f2->SetContour(99); gStyle->SetPalette(kCubehelix);
465 f2->Draw("surf2Z"); f2->SetTitle("kCubehelix");
466}
467End_Macro
468</td><td>
469Begin_Macro
470{
471 auto c = new TCanvas("c","c",0,0,300,300);
472 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
473 f2->SetContour(99); gStyle->SetPalette(kGreenRedViolet);
474 f2->Draw("surf2Z"); f2->SetTitle("kGreenRedViolet");
475}
476End_Macro
477</td></tr>
478<tr><td>
479Begin_Macro
480{
481 auto c = new TCanvas("c","c",0,0,300,300);
482 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
483 f2->SetContour(99); gStyle->SetPalette(kBlueRedYellow);
484 f2->Draw("surf2Z"); f2->SetTitle("kBlueRedYellow");
485}
486End_Macro
487</td><td>
488Begin_Macro
489{
490 auto c = new TCanvas("c","c",0,0,300,300);
491 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
492 f2->SetContour(99); gStyle->SetPalette(kOcean);
493 f2->Draw("surf2Z"); f2->SetTitle("kOcean");
494}
495End_Macro
496</td><td>
497Begin_Macro
498{
499 auto c = new TCanvas("c","c",0,0,300,300);
500 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
501 f2->SetContour(99); gStyle->SetPalette(kCool);
502 f2->Draw("surf2Z"); f2->SetTitle("kCool");
503}
504End_Macro
505</td></tr>
506<tr><td>
507Begin_Macro
508{
509 auto c = new TCanvas("c","c",0,0,300,300);
510 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
511 f2->SetContour(99); gStyle->SetPalette(kAlpine);
512 f2->Draw("surf2Z"); f2->SetTitle("kAlpine");
513}
514End_Macro
515</td><td>
516Begin_Macro
517{
518 auto c = new TCanvas("c","c",0,0,300,300);
519 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
520 f2->SetContour(99); gStyle->SetPalette(kPigeon);
521 f2->Draw("surf2Z"); f2->SetTitle("kPigeon");
522}
523End_Macro
524</td><td>
525Begin_Macro
526{
527 auto c = new TCanvas("c","c",0,0,300,300);
528 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
529 f2->SetContour(99); gStyle->SetPalette(kPlum);
530 f2->Draw("surf2Z"); f2->SetTitle("kPlum");
531}
532End_Macro
533</td></tr>
534<tr><td>
535Begin_Macro
536{
537 auto c = new TCanvas("c","c",0,0,300,300);
538 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
539 f2->SetContour(99); gStyle->SetPalette(kGistEarth);
540 f2->Draw("surf2Z"); f2->SetTitle("kGistEarth");
541}
542End_Macro
543</td><td>
544Begin_Macro
545{
546 auto c = new TCanvas("c","c",0,0,300,300);
547 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
548 f2->SetContour(99); gStyle->SetPalette(kViridis);
549 f2->Draw("surf2Z"); f2->SetTitle("kViridis");
550}
551End_Macro
552</td><td>
553Begin_Macro
554{
555 auto c = new TCanvas("c","c",0,0,300,300);
556 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
557 f2->SetContour(99); gStyle->SetPalette(kAvocado);
558 f2->Draw("surf2Z"); f2->SetTitle("kAvocado");
559}
560End_Macro
561</td></tr>
562<tr><td>
563Begin_Macro
564{
565 auto c = new TCanvas("c","c",0,0,300,300);
566 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
567 f2->SetContour(99); gStyle->SetPalette(kRust);
568 f2->Draw("surf2Z"); f2->SetTitle("kRust");
569}
570End_Macro
571</td><td>
572Begin_Macro
573{
574 auto c = new TCanvas("c","c",0,0,300,300);
575 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
576 f2->SetContour(99); gStyle->SetPalette(kCopper);
577 f2->Draw("surf2Z"); f2->SetTitle("kCopper");
578}
579End_Macro
580</td><td>
581Begin_Macro
582{
583 auto c = new TCanvas("c","c",0,0,300,300);
584 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
585 f2->SetContour(99); gStyle->SetPalette(kBlueGreenYellow);
586 f2->Draw("surf2Z"); f2->SetTitle("kBlueGreenYellow");
587}
588End_Macro
589</td></tr>
590<tr><td>
591Begin_Macro
592{
593 auto c = new TCanvas("c","c",0,0,300,300);
594 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
595 f2->SetContour(99); gStyle->SetPalette(kSienna);
596 f2->Draw("surf2Z"); f2->SetTitle("kSienna");
597}
598End_Macro
599</td><td>
600Begin_Macro
601{
602 auto c = new TCanvas("c","c",0,0,300,300);
603 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
604 f2->SetContour(99); gStyle->SetPalette(kSolar);
605 f2->Draw("surf2Z"); f2->SetTitle("kSolar");
606}
607End_Macro
608</td><td>
609Begin_Macro
610{
611 auto c = new TCanvas("c","c",0,0,300,300);
612 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
613 f2->SetContour(99); gStyle->SetPalette(kCandy);
614 f2->Draw("surf2Z"); f2->SetTitle("kCandy");
615}
616End_Macro
617</td></tr>
618<tr><td>
619Begin_Macro
620{
621 auto c = new TCanvas("c","c",0,0,300,300);
622 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
623 f2->SetContour(99); gStyle->SetPalette(kCherry);
624 f2->Draw("surf2Z"); f2->SetTitle("kCherry");
625}
626End_Macro
627</td><td>
628Begin_Macro
629{
630 auto c = new TCanvas("c","c",0,0,300,300);
631 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
632 f2->SetContour(99); gStyle->SetPalette(kCoffee);
633 f2->Draw("surf2Z"); f2->SetTitle("kCoffee");
634}
635End_Macro
636</td><td>
637Begin_Macro
638{
639 auto c = new TCanvas("c","c",0,0,300,300);
640 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
641 f2->SetContour(99); gStyle->SetPalette(kSouthWest);
642 f2->Draw("surf2Z"); f2->SetTitle("kSouthWest");
643}
644End_Macro
645</td></tr>
646<tr><td>
647Begin_Macro
648{
649 auto c = new TCanvas("c","c",0,0,300,300);
650 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
651 f2->SetContour(99); gStyle->SetPalette(kStarryNight);
652 f2->Draw("surf2Z"); f2->SetTitle("kStarryNight");
653}
654End_Macro
655</td><td>
656Begin_Macro
657{
658 auto c = new TCanvas("c","c",0,0,300,300);
659 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
660 f2->SetContour(99); gStyle->SetPalette(kFall);
661 f2->Draw("surf2Z"); f2->SetTitle("kFall");
662}
663End_Macro
664</td><td>
665Begin_Macro
666{
667 auto c = new TCanvas("c","c",0,0,300,300);
668 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
669 f2->SetContour(99); gStyle->SetPalette(kFruitPunch);
670 f2->Draw("surf2Z"); f2->SetTitle("kFruitPunch");
671}
672End_Macro
673</td></tr>
674<tr><td>
675Begin_Macro
676{
677 auto c = new TCanvas("c","c",0,0,300,300);
678 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
679 f2->SetContour(99); gStyle->SetPalette(kFuchsia);
680 f2->Draw("surf2Z"); f2->SetTitle("kFuchsia");
681}
682End_Macro
683</td><td>
684Begin_Macro
685{
686 auto c = new TCanvas("c","c",0,0,300,300);
687 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
688 f2->SetContour(99); gStyle->SetPalette(kGreyYellow);
689 f2->Draw("surf2Z"); f2->SetTitle("kGreyYellow");
690}
691End_Macro
692</td><td>
693Begin_Macro
694{
695 auto c = new TCanvas("c","c",0,0,300,300);
696 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
697 f2->SetContour(99); gStyle->SetPalette(kGreenBrownTerrain);
698 f2->Draw("surf2Z"); f2->SetTitle("kGreenBrownTerrain");
699}
700End_Macro
701</td></tr>
702<tr><td>
703Begin_Macro
704{
705 auto c = new TCanvas("c","c",0,0,300,300);
706 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
707 f2->SetContour(99); gStyle->SetPalette(kSunset);
708 f2->Draw("surf2Z"); f2->SetTitle("kSunset");
709}
710End_Macro
711</td><td>
712Begin_Macro
713{
714 auto c = new TCanvas("c","c",0,0,300,300);
715 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
716 f2->SetContour(99); gStyle->SetPalette(kNeon);
717 f2->Draw("surf2Z"); f2->SetTitle("kNeon");
718}
719End_Macro
720</td><td>
721Begin_Macro
722{
723 auto c = new TCanvas("c","c",0,0,300,300);
724 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
725 f2->SetContour(99); gStyle->SetPalette(kLake);
726 f2->Draw("surf2Z"); f2->SetTitle("kLake");
727}
728End_Macro
729</td></tr>
730<tr><td>
731Begin_Macro
732{
733 auto c = new TCanvas("c","c",0,0,300,300);
734 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
735 f2->SetContour(99); gStyle->SetPalette(kValentine);
736 f2->Draw("surf2Z"); f2->SetTitle("kValentine");
737}
738End_Macro
739</td><td>
740Begin_Macro
741{
742 auto c = new TCanvas("c","c",0,0,300,300);
743 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
744 f2->SetContour(99); gStyle->SetPalette(kLightTerrain);
745 f2->Draw("surf2Z"); f2->SetTitle("kLightTerrain");
746}
747End_Macro
748</td><td>
749Begin_Macro
750{
751 auto c = new TCanvas("c","c",0,0,300,300);
752 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
753 f2->SetContour(99); gStyle->SetPalette(kCividis);
754 f2->Draw("surf2Z"); f2->SetTitle("kCividis");
755}
756End_Macro
757</td></tr>
758</table>
759
760\anchor C06b
761### Non Colour Vision Deficiency (CVD) friendly palettes
762
763<table border=0>
764<tr><td>
765Begin_Macro
766{
767 auto c = new TCanvas("c","c",0,0,300,300);
768 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
769 f2->SetContour(99); gStyle->SetPalette(kIsland);
770 f2->Draw("surf2Z"); f2->SetTitle("kIsland");
771}
772End_Macro
773</td><td>
774Begin_Macro
775{
776 auto c = new TCanvas("c","c",0,0,300,300);
777 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
778 f2->SetContour(99); gStyle->SetPalette(kRainBow);
779 f2->Draw("surf2Z"); f2->SetTitle("kRainBow");
780}
781End_Macro
782</td><td>
783Begin_Macro
784{
785 auto c = new TCanvas("c","c",0,0,300,300);
786 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
787 f2->SetContour(99); gStyle->SetPalette(kColorPrintableOnGrey);
788 f2->Draw("surf2Z"); f2->SetTitle("kColorPrintableOnGrey");
789}
790End_Macro
791</td></tr>
792<tr><td>
793Begin_Macro
794{
795 auto c = new TCanvas("c","c",0,0,300,300);
796 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
797 f2->SetContour(99); gStyle->SetPalette(kAquamarine);
798 f2->Draw("surf2Z"); f2->SetTitle("kAquamarine");
799}
800End_Macro
801</td><td>
802Begin_Macro
803{
804 auto c = new TCanvas("c","c",0,0,300,300);
805 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
806 f2->SetContour(99); gStyle->SetPalette(kArmy);
807 f2->Draw("surf2Z"); f2->SetTitle("kArmy");
808}
809End_Macro
810</td><td>
811Begin_Macro
812{
813 auto c = new TCanvas("c","c",0,0,300,300);
814 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
815 f2->SetContour(99); gStyle->SetPalette(kAtlantic);
816 f2->Draw("surf2Z"); f2->SetTitle("kAtlantic");
817}
818End_Macro
819</td></tr>
820<tr><td>
821Begin_Macro
822{
823 auto c = new TCanvas("c","c",0,0,300,300);
824 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
825 f2->SetContour(99); gStyle->SetPalette(kAurora);
826 f2->Draw("surf2Z"); f2->SetTitle("kAurora");
827}
828End_Macro
829</td><td>
830Begin_Macro
831{
832 auto c = new TCanvas("c","c",0,0,300,300);
833 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
834 f2->SetContour(99); gStyle->SetPalette(kBeach);
835 f2->Draw("surf2Z"); f2->SetTitle("kBeach");
836}
837End_Macro
838</td><td>
839Begin_Macro
840{
841 auto c = new TCanvas("c","c",0,0,300,300);
842 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
843 f2->SetContour(99); gStyle->SetPalette(kBlackBody);
844 f2->Draw("surf2Z"); f2->SetTitle("kBlackBody");
845}
846End_Macro
847</td></tr>
848<tr><td>
849Begin_Macro
850{
851 auto c = new TCanvas("c","c",0,0,300,300);
852 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
853 f2->SetContour(99); gStyle->SetPalette(kBrownCyan);
854 f2->Draw("surf2Z"); f2->SetTitle("kBrownCyan");
855}
856End_Macro
857</td><td>
858Begin_Macro
859{
860 auto c = new TCanvas("c","c",0,0,300,300);
861 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
862 f2->SetContour(99); gStyle->SetPalette(kCMYK);
863 f2->Draw("surf2Z"); f2->SetTitle("kCMYK");
864}
865End_Macro
866</td><td>
867Begin_Macro
868{
869 auto c = new TCanvas("c","c",0,0,300,300);
870 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
871 f2->SetContour(99); gStyle->SetPalette(kDarkRainBow);
872 f2->Draw("surf2Z"); f2->SetTitle("kDarkRainBow");
873}
874End_Macro
875</td></tr>
876<tr><td>
877Begin_Macro
878{
879 auto c = new TCanvas("c","c",0,0,300,300);
880 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
881 f2->SetContour(99); gStyle->SetPalette(kDarkTerrain);
882 f2->Draw("surf2Z"); f2->SetTitle("kDarkTerrain");
883}
884End_Macro
885</td><td>
886Begin_Macro
887{
888 auto c = new TCanvas("c","c",0,0,300,300);
889 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
890 f2->SetContour(99); gStyle->SetPalette(kGreenPink);
891 f2->Draw("surf2Z"); f2->SetTitle("kGreenPink");
892}
893End_Macro
894</td><td>
895Begin_Macro
896{
897 auto c = new TCanvas("c","c",0,0,300,300);
898 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
899 f2->SetContour(99); gStyle->SetPalette(kRedBlue);
900 f2->Draw("surf2Z"); f2->SetTitle("kRedBlue");
901}
902End_Macro
903</td></tr>
904<tr><td>
905Begin_Macro
906{
907 auto c = new TCanvas("c","c",0,0,300,300);
908 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
909 f2->SetContour(99); gStyle->SetPalette(kRose);
910 f2->Draw("surf2Z"); f2->SetTitle("kRose");
911}
912End_Macro
913</td><td>
914Begin_Macro
915{
916 auto c = new TCanvas("c","c",0,0,300,300);
917 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
918 f2->SetContour(99); gStyle->SetPalette(kLightTemperature);
919 f2->Draw("surf2Z"); f2->SetTitle("kLightTemperature");
920}
921End_Macro
922</td><td>
923Begin_Macro
924{
925 auto c = new TCanvas("c","c",0,0,300,300);
926 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
927 f2->SetContour(99); gStyle->SetPalette(kMint);
928 f2->Draw("surf2Z"); f2->SetTitle("kMint");
929}
930End_Macro
931</td></tr>
932<tr><td>
933Begin_Macro
934{
935 auto c = new TCanvas("c","c",0,0,300,300);
936 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
937 f2->SetContour(99); gStyle->SetPalette(kPastel);
938 f2->Draw("surf2Z"); f2->SetTitle("kPastel");
939}
940End_Macro
941</td><td>
942Begin_Macro
943{
944 auto c = new TCanvas("c","c",0,0,300,300);
945 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
946 f2->SetContour(99); gStyle->SetPalette(kPearl);
947 f2->Draw("surf2Z"); f2->SetTitle("kPearl");
948}
949End_Macro
950</td><td>
951Begin_Macro
952{
953 auto c = new TCanvas("c","c",0,0,300,300);
954 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
955 f2->SetContour(99); gStyle->SetPalette(kSandyTerrain);
956 f2->Draw("surf2Z"); f2->SetTitle("kSandyTerrain");
957}
958End_Macro
959</td></tr>
960<tr><td>
961Begin_Macro
962{
963 auto c = new TCanvas("c","c",0,0,300,300);
964 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
965 f2->SetContour(99); gStyle->SetPalette(kTemperatureMap);
966 f2->Draw("surf2Z"); f2->SetTitle("kTemperatureMap");
967}
968End_Macro
969</td><td>
970Begin_Macro
971{
972 auto c = new TCanvas("c","c",0,0,300,300);
973 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
974 f2->SetContour(99); gStyle->SetPalette(kThermometer);
975 f2->Draw("surf2Z"); f2->SetTitle("kThermometer");
976}
977End_Macro
978</td><td>
979Begin_Macro
980{
981 auto c = new TCanvas("c","c",0,0,300,300);
982 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
983 f2->SetContour(99); gStyle->SetPalette(kVisibleSpectrum);
984 f2->Draw("surf2Z"); f2->SetTitle("kVisibleSpectrum");
985}
986End_Macro
987</td></tr>
988</table>
989
990\anchor C061
991## Palette inversion
992Once a palette is defined, it is possible to invert the color order thanks to the
993method TColor::InvertPalette. The top of the palette becomes the bottom and vice versa.
994
995Begin_Macro(source)
996{
997 auto c = new TCanvas("c","c",0,0,600,400);
998 auto f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
999 f2->SetContour(99); gStyle->SetPalette(kCherry);
1000 TColor::InvertPalette();
1001 f2->Draw("surf2Z"); f2->SetTitle("kCherry inverted");
1002}
1003End_Macro
1004
1005\anchor C07
1006## Color transparency
1007To make a graphics object transparent it is enough to set its color to a
1008transparent one. The color transparency is defined via its alpha component. The
1009alpha value varies from `0.` (fully transparent) to `1.` (fully
1010opaque). To set the alpha value of an existing color it is enough to do:
1011
1012~~~ {.cpp}
1013 TColor *col26 = gROOT->GetColor(26);
1014 col26->SetAlpha(0.01);
1015~~~
1016
1017A new color can be created transparent the following way:
1018
1019~~~ {.cpp}
1020 Int_t ci = 1756;
1021 auto color = new TColor(ci, 0.1, 0.2, 0.3, "", 0.5); // alpha = 0.5
1022~~~
1023
1024An example of transparency usage with parallel coordinates can be found
1025in parallelcoordtrans.C.
1026
1027To ease the creation of a transparent color the static method
1028`GetColorTransparent(Int_t color, Float_t a)` is provided.
1029In the following example the `trans_red` color index point to
1030a red color 30% opaque (70% transparent). The alpha value of
1031the color index `kRed` is not modified.
1032
1033~~~ {.cpp}
1034 Int_t trans_red = GetColorTransparent(kRed, 0.3);
1035~~~
1036
1037This function is also used in the methods
1038`SetFillColorAlpha()`, `SetLineColorAlpha()`,
1039`SetMarkerColorAlpha()` and `SetTextColorAlpha()`.
1040In the following example the fill color of the histogram `histo`
1041is set to blue with an opacity of 35% (i.e. a transparency of 65%).
1042(The color `kBlue` itself is internally stored as fully opaque.)
1043
1044~~~ {.cpp}
1045 histo->SetFillColorAlpha(kBlue, 0.35);
1046~~~
1047
1048The transparency is available on all platforms when the flag `OpenGL.CanvasPreferGL` is set to `1`
1049in `$ROOTSYS/etc/system.rootrc`, or on Mac with the Cocoa backend. On the file output
1050it is visible with PDF, PNG, Gif, JPEG, SVG, TeX ... but not PostScript.
1051
1052Alternatively, you can call at the top of your script `gSytle->SetCanvasPreferGL();`.
1053Or if you prefer to activate GL for a single canvas `c`, then use `c->SetSupportGL(true);`.
1054
1055The following macro gives an example of transparency usage:
1056
1057Begin_Macro(source)
1058../../../tutorials/visualisation/graphics/transparency.C
1059End_Macro
1060
1061*/
1062
1063////////////////////////////////////////////////////////////////////////////////
1064/// Default constructor.
1067{
1068 fNumber = -1;
1069 fRed = fGreen = fBlue = fHue = fLight = fSaturation = -1;
1070 fAlpha = 1;
1071}
1072
1073////////////////////////////////////////////////////////////////////////////////
1074/// Normal color constructor. Initialize a color structure.
1075/// Compute the RGB and HLS color components.
1076/// The color title is set to its hexadecimal value.
1078TColor::TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char *name,
1079 Float_t a)
1080 : TNamed(name,"")
1081{
1083 // do not enter if color number already exist
1084 TColor *col = gROOT->GetColor(color);
1085 if (col) {
1086 Warning("TColor", "color %d already defined", color);
1087 fNumber = col->GetNumber();
1088 fRed = col->GetRed();
1089 fGreen = col->GetGreen();
1090 fBlue = col->GetBlue();
1091 fHue = col->GetHue();
1092 fLight = col->GetLight();
1093 fAlpha = col->GetAlpha();
1094 fSaturation = col->GetSaturation();
1095 return;
1096 }
1097
1098 fNumber = color;
1099
1101
1102 char aname[32];
1103 if (!name || !*name) {
1104 snprintf(aname,32, "Color%d", color);
1105 SetName(aname);
1106 }
1107
1108 // enter in the list of colors
1109 TObjArray *lcolors = (TObjArray*)gROOT->GetListOfColors();
1110 lcolors->AddAtAndExpand(this, color);
1111
1112 // fill color structure
1113 SetRGB(r, g, b);
1114 fAlpha = a;
1117}
1118
1119////////////////////////////////////////////////////////////////////////////////
1120/// Fast TColor constructor. It creates a color with an index just above the
1121/// current highest one. It does not name the color.
1122/// This is useful to create palettes.
1125{
1128 fRed = r;
1129 fGreen = g;
1130 fBlue = b;
1131 fAlpha = a;
1133
1134 // enter in the list of colors
1135 TObjArray *lcolors = (TObjArray*)gROOT->GetListOfColors();
1136 lcolors->AddAtAndExpand(this, fNumber);
1138}
1139
1140////////////////////////////////////////////////////////////////////////////////
1141/// Color destructor.
1144{
1145 gROOT->GetListOfColors()->Remove(this);
1146 if (gROOT->GetListOfColors()->IsEmpty()) {
1147 fgPalette.Set(0);
1148 fgPalette=0;
1149 }
1150}
1151
1152////////////////////////////////////////////////////////////////////////////////
1153/// Color copy constructor.
1155TColor::TColor(const TColor &color) : TNamed(color)
1156{
1157 color.TColor::Copy(*this);
1158}
1160TColor &TColor::operator=(const TColor &color)
1161{
1162 if (this != &color)
1163 color.TColor::Copy(*this);
1164 return *this;
1165}
1166
1167////////////////////////////////////////////////////////////////////////////////
1168/// Initialize colors used by the TCanvas based graphics (via TColor objects).
1169/// This method should be called before the ApplicationImp is created (which
1170/// initializes the GUI colors).
1173{
1174 static Bool_t initDone = kFALSE;
1175
1176 if (initDone) return;
1177 initDone = kTRUE;
1178
1179 if (gROOT->GetListOfColors()->First() == nullptr) {
1180
1181 new TColor(kWhite,1,1,1,"background");
1182 new TColor(kBlack,0,0,0,"black");
1183 new TColor(2,1,0,0,"red");
1184 new TColor(3,0,1,0,"green");
1185 new TColor(4,0,0,1,"blue");
1186 new TColor(5,1,1,0,"yellow");
1187 new TColor(6,1,0,1,"magenta");
1188 new TColor(7,0,1,1,"cyan");
1189 new TColor(10,0.999,0.999,0.999,"white");
1190 new TColor(11,0.754,0.715,0.676,"editcol");
1191
1192 // The color white above is defined as being nearly white.
1193 // Sets the associated dark color also to white.
1195 TColor *c110 = gROOT->GetColor(110);
1196 if (c110) c110->SetRGB(0.999,0.999,.999);
1197
1198 // Initialize Custom colors
1199 new TColor(20,0.8,0.78,0.67);
1200 new TColor(31,0.54,0.66,0.63);
1201 new TColor(41,0.83,0.81,0.53);
1202 new TColor(30,0.52,0.76,0.64);
1203 new TColor(32,0.51,0.62,0.55);
1204 new TColor(24,0.70,0.65,0.59);
1205 new TColor(21,0.8,0.78,0.67);
1206 new TColor(47,0.67,0.56,0.58);
1207 new TColor(35,0.46,0.54,0.57);
1208 new TColor(33,0.68,0.74,0.78);
1209 new TColor(39,0.5,0.5,0.61);
1210 new TColor(37,0.43,0.48,0.52);
1211 new TColor(38,0.49,0.6,0.82);
1212 new TColor(36,0.41,0.51,0.59);
1213 new TColor(49,0.58,0.41,0.44);
1214 new TColor(43,0.74,0.62,0.51);
1215 new TColor(22,0.76,0.75,0.66);
1216 new TColor(45,0.75,0.51,0.47);
1217 new TColor(44,0.78,0.6,0.49);
1218 new TColor(26,0.68,0.6,0.55);
1219 new TColor(28,0.53,0.4,0.34);
1220 new TColor(25,0.72,0.64,0.61);
1221 new TColor(27,0.61,0.56,0.51);
1222 new TColor(23,0.73,0.71,0.64);
1223 new TColor(42,0.87,0.73,0.53);
1224 new TColor(46,0.81,0.37,0.38);
1225 new TColor(48,0.65,0.47,0.48);
1226 new TColor(34,0.48,0.56,0.6);
1227 new TColor(40,0.67,0.65,0.75);
1228 new TColor(29,0.69,0.81,0.78);
1229
1230 // Initialize some additional greyish non saturated colors
1231 new TColor(8, 0.35,0.83,0.33);
1232 new TColor(9, 0.35,0.33,0.85);
1233 new TColor(12,.3,.3,.3,"grey12");
1234 new TColor(13,.4,.4,.4,"grey13");
1235 new TColor(14,.5,.5,.5,"grey14");
1236 new TColor(15,.6,.6,.6,"grey15");
1237 new TColor(16,.7,.7,.7,"grey16");
1238 new TColor(17,.8,.8,.8,"grey17");
1239 new TColor(18,.9,.9,.9,"grey18");
1240 new TColor(19,.95,.95,.95,"grey19");
1241 new TColor(50, 0.83,0.35,0.33);
1242
1243 // define the Petroff color schemes
1244 new TColor(kGrape, 111./255., 45./255., 168./255., "kGrape");
1245 new TColor(kBrown, 165./255., 42./255., 42./255., "kBrown");
1246 new TColor(kAsh, 178./255., 190./255., 181./255., "kAsh");
1247
1248 new TColor(kP6Blue, 87./255., 144./255., 252./255., "kP6Blue");
1249 new TColor(kP6Yellow, 248./255., 156./255., 32./255., "kP6Yellow");
1250 new TColor(kP6Red, 228./255., 37./255., 54./255., "kP6Red");
1251 new TColor(kP6Grape, 150./255., 74./255., 139./255., "kP6Grape");
1252 new TColor(kP6Gray, 156./255., 156./255., 161./255., "kP6Gray");
1253 new TColor(kP6Violet, 122./255., 33./255., 221./255., "kP6Violet");
1254
1255 new TColor(kP8Blue, 24./255., 69./255., 251./255., "kP8Blue");
1256 new TColor(kP8Orange, 1., 94./255., 2./255., "kP8Orange");
1257 new TColor(kP8Red, 201./255., 31./255., 22./255., "kP8Red");
1258 new TColor(kP8Pink, 200./255., 73./255., 169./255., "kP8Pink");
1259 new TColor(kP8Green, 173./255., 173./255., 125./255., "kP8Green");
1260 new TColor(kP8Cyan, 134./255., 200./255., 221./255., "kP8Cyan");
1261 new TColor(kP8Azure, 87./255., 141./255., 255./255., "kP8Azure");
1262 new TColor(kP8Gray, 101./255., 99./255., 100./255., "kP8Gray");
1263
1264 new TColor(kP10Blue, 63./255., 144./255., 218./255., "kP10Blue");
1265 new TColor(kP10Yellow, 1., 169./255., 14./255., "kP10Yellow");
1266 new TColor(kP10Red, 189./255., 31./255., 1./255., "kP10Red");
1267 new TColor(kP10Gray, 148./255., 164./255., 162./255., "kP10Gray");
1268 new TColor(kP10Violet, 131./255., 45./255., 182./255., "kP10Violet");
1269 new TColor(kP10Brown, 169./255., 107./255., 89./255., "kP10Brown");
1270 new TColor(kP10Orange, 231./255., 99./255., 0., "kP10Orange");
1271 new TColor(kP10Green, 185./255., 172./255., 112./255., "kP10Green");
1272 new TColor(kP10Ash, 113./255., 117./255., 129./255., "kP10Ash");
1273 new TColor(kP10Cyan, 146./255., 218./255., 221./255., "kP10Cyan");
1274
1275 // Initialize the Pretty Palette Spectrum Violet->Red
1276 // The color model used here is based on the HLS model which
1277 // is much more suitable for creating palettes than RGB.
1278 // Fixing the saturation and lightness we can scan through the
1279 // spectrum of visible light by using "hue" alone.
1280 // In Root hue takes values from 0 to 360.
1281 Int_t i;
1282 Float_t saturation = 1;
1283 Float_t lightness = 0.5;
1284 Float_t maxHue = 280;
1285 Float_t minHue = 0;
1286 Int_t maxPretty = 50;
1287 Float_t hue;
1288 Float_t r=0., g=0., b=0., h, l, s;
1289
1290 for (i=0 ; i<maxPretty-1 ; i++) {
1291 hue = maxHue-(i+1)*((maxHue-minHue)/maxPretty);
1293 new TColor(i+51, r, g, b);
1294 }
1295
1296 // Initialize special colors for x3d
1297 TColor *s0;
1298 for (i = 1; i < 8; i++) {
1299 s0 = gROOT->GetColor(i);
1300 if (s0) s0->GetRGB(r,g,b);
1301 if (i == 1) { r = 0.6; g = 0.6; b = 0.6; }
1302 if (r == 1) r = 0.9; else if (r == 0) r = 0.1;
1303 if (g == 1) g = 0.9; else if (g == 0) g = 0.1;
1304 if (b == 1) b = 0.9; else if (b == 0) b = 0.1;
1305 TColor::RGBtoHLS(r,g,b,h,l,s);
1306 TColor::HLStoRGB(h,0.6*l,s,r,g,b);
1307 new TColor(200+4*i-3,r,g,b);
1308 TColor::HLStoRGB(h,0.8*l,s,r,g,b);
1309 new TColor(200+4*i-2,r,g,b);
1310 TColor::HLStoRGB(h,1.2*l,s,r,g,b);
1311 new TColor(200+4*i-1,r,g,b);
1312 TColor::HLStoRGB(h,1.4*l,s,r,g,b);
1313 new TColor(200+4*i ,r,g,b);
1314 }
1315
1316 // Create the ROOT Color Wheel
1318 }
1319 // If fgPalette.fN !=0 SetPalette has been called already
1320 // (from rootlogon.C for instance)
1321
1322 if (!fgPalette.fN) SetPalette(1,nullptr);
1323}
1324
1325////////////////////////////////////////////////////////////////////////////////
1326/// Return color as hexadecimal string. This string can be directly passed
1327/// to, for example, TGClient::GetColorByName(). String will be reused so
1328/// copy immediately if needed.
1330const char *TColor::AsHexString() const
1331{
1332 static TString tempbuf;
1333
1334 Int_t r, g, b, a;
1335 r = Int_t(GetRed() * 255);
1336 g = Int_t(GetGreen() * 255);
1337 b = Int_t(GetBlue() * 255);
1338 a = Int_t(fAlpha * 255);
1339
1340 if (a != 255) {
1341 tempbuf.Form("#%02x%02x%02x%02x", a, r, g, b);
1342 } else {
1343 tempbuf.Form("#%02x%02x%02x", r, g, b);
1344 }
1345 return tempbuf;
1346}
1347
1348////////////////////////////////////////////////////////////////////////////////
1349/// Copy this color to obj.
1351void TColor::Copy(TObject &obj) const
1352{
1353 TNamed::Copy((TNamed&)obj);
1354 ((TColor&)obj).fRed = fRed;
1355 ((TColor&)obj).fGreen = fGreen;
1356 ((TColor&)obj).fBlue = fBlue;
1357 ((TColor&)obj).fHue = fHue;
1358 ((TColor&)obj).fLight = fLight;
1359 ((TColor&)obj).fAlpha = fAlpha;
1360 ((TColor&)obj).fSaturation = fSaturation;
1361 ((TColor&)obj).fNumber = fNumber;
1362}
1363
1364////////////////////////////////////////////////////////////////////////////////
1365/// Create the Gray scale colors in the Color Wheel
1368{
1369 if (gROOT->GetColor(kGray)) return;
1370 TColor *gray = new TColor(kGray,204./255.,204./255.,204./255.);
1371 TColor *gray1 = new TColor(kGray+1,153./255.,153./255.,153./255.);
1372 TColor *gray2 = new TColor(kGray+2,102./255.,102./255.,102./255.);
1373 TColor *gray3 = new TColor(kGray+3, 51./255., 51./255., 51./255.);
1374 gray ->SetName("kGray");
1375 gray1->SetName("kGray+1");
1376 gray2->SetName("kGray+2");
1377 gray3->SetName("kGray+3");
1378}
1379
1380////////////////////////////////////////////////////////////////////////////////
1381/// Create the "circle" colors in the color wheel.
1384{
1386 for (Int_t n=0;n<15;n++) {
1387 Int_t colorn = offset+n-10;
1388 TColor *color = gROOT->GetColor(colorn);
1389 if (!color) {
1390 color = new TColor(colorn,rgb[3*n]/255.,rgb[3*n+1]/255.,rgb[3*n+2]/255.);
1391 if (n>10) colorname.Form("%s+%d",name,n-10);
1392 else if (n<10) colorname.Form("%s-%d",name,10-n);
1393 else colorname.Form("%s",name);
1394 color->SetName(colorname);
1395 }
1396 }
1397}
1398
1399////////////////////////////////////////////////////////////////////////////////
1400/// Create the "rectangular" colors in the color wheel.
1403{
1405 for (Int_t n=0;n<20;n++) {
1406 Int_t colorn = offset+n-9;
1407 TColor *color = gROOT->GetColor(colorn);
1408 if (!color) {
1409 color = new TColor(colorn,rgb[3*n]/255.,rgb[3*n+1]/255.,rgb[3*n+2]/255.);
1410 if (n>9) colorname.Form("%s+%d",name,n-9);
1411 else if (n<9) colorname.Form("%s-%d",name,9-n);
1412 else colorname.Form("%s",name);
1413 color->SetName(colorname);
1414 }
1415 }
1416}
1417
1418////////////////////////////////////////////////////////////////////////////////
1419/// Static function steering the creation of all colors in the color wheel.
1422{
1423 UChar_t magenta[46]= {255,204,255
1424 ,255,153,255, 204,153,204
1425 ,255,102,255, 204,102,204, 153,102,153
1426 ,255, 51,255, 204, 51,204, 153, 51,153, 102, 51,102
1427 ,255, 0,255, 204, 0,204, 153, 0,153, 102, 0,102, 51, 0, 51};
1428
1429 UChar_t red[46] = {255,204,204
1430 ,255,153,153, 204,153,153
1431 ,255,102,102, 204,102,102, 153,102,102
1432 ,255, 51, 51, 204, 51, 51, 153, 51, 51, 102, 51, 51
1433 ,255, 0, 0, 204, 0, 0, 153, 0, 0, 102, 0, 0, 51, 0, 0};
1434
1435 UChar_t yellow[46] = {255,255,204
1436 ,255,255,153, 204,204,153
1437 ,255,255,102, 204,204,102, 153,153,102
1438 ,255,255, 51, 204,204, 51, 153,153, 51, 102,102, 51
1439 ,255,255, 0, 204,204, 0, 153,153, 0, 102,102, 0, 51, 51, 0};
1440
1441 UChar_t green[46] = {204,255,204
1442 ,153,255,153, 153,204,153
1443 ,102,255,102, 102,204,102, 102,153,102
1444 , 51,255, 51, 51,204, 51, 51,153, 51, 51,102, 51
1445 , 0,255, 0, 0,204, 0, 0,153, 0, 0,102, 0, 0, 51, 0};
1446
1447 UChar_t cyan[46] = {204,255,255
1448 ,153,255,255, 153,204,204
1449 ,102,255,255, 102,204,204, 102,153,153
1450 , 51,255,255, 51,204,204, 51,153,153, 51,102,102
1451 , 0,255,255, 0,204,204, 0,153,153, 0,102,102, 0, 51, 51};
1452
1453 UChar_t blue[46] = {204,204,255
1454 ,153,153,255, 153,153,204
1455 ,102,102,255, 102,102,204, 102,102,153
1456 , 51, 51,255, 51, 51,204, 51, 51,153, 51, 51,102
1457 , 0, 0,255, 0, 0,204, 0, 0,153, 0, 0,102, 0, 0, 51};
1458
1459 UChar_t pink[60] = {255, 51,153, 204, 0,102, 102, 0, 51, 153, 0, 51, 204, 51,102
1460 ,255,102,153, 255, 0,102, 255, 51,102, 204, 0, 51, 255, 0, 51
1461 ,255,153,204, 204,102,153, 153, 51,102, 153, 0,102, 204, 51,153
1462 ,255,102,204, 255, 0,153, 204, 0,153, 255, 51,204, 255, 0,153};
1463
1464 UChar_t orange[60]={255,204,153, 204,153,102, 153,102, 51, 153,102, 0, 204,153, 51
1465 ,255,204,102, 255,153, 0, 255,204, 51, 204,153, 0, 255,204, 0
1466 ,255,153, 51, 204,102, 0, 102, 51, 0, 153, 51, 0, 204,102, 51
1467 ,255,153,102, 255,102, 0, 255,102, 51, 204, 51, 0, 255, 51, 0};
1468
1469 UChar_t spring[60]={153,255, 51, 102,204, 0, 51,102, 0, 51,153, 0, 102,204, 51
1470 ,153,255,102, 102,255, 0, 102,255, 51, 51,204, 0, 51,255, 0
1471 ,204,255,153, 153,204,102, 102,153, 51, 102,153, 0, 153,204, 51
1472 ,204,255,102, 153,255, 0, 204,255, 51, 153,204, 0, 204,255, 0};
1473
1474 UChar_t teal[60] = {153,255,204, 102,204,153, 51,153,102, 0,153,102, 51,204,153
1475 ,102,255,204, 0,255,102, 51,255,204, 0,204,153, 0,255,204
1476 , 51,255,153, 0,204,102, 0,102, 51, 0,153, 51, 51,204,102
1477 ,102,255,153, 0,255,153, 51,255,102, 0,204, 51, 0,255, 51};
1478
1479 UChar_t azure[60] ={153,204,255, 102,153,204, 51,102,153, 0, 51,153, 51,102,204
1480 ,102,153,255, 0,102,255, 51,102,255, 0, 51,204, 0, 51,255
1481 , 51,153,255, 0,102,204, 0, 51,102, 0,102,153, 51,153,204
1482 ,102,204,255, 0,153,255, 51,204,255, 0,153,204, 0,204,255};
1483
1484 UChar_t violet[60]={204,153,255, 153,102,204, 102, 51,153, 102, 0,153, 153, 51,204
1485 ,204,102,255, 153, 0,255, 204, 51,255, 153, 0,204, 204, 0,255
1486 ,153, 51,255, 102, 0,204, 51, 0,102, 51, 0,153, 102, 51,204
1487 ,153,102,255, 102, 0,255, 102, 51,255, 51, 0,204, 51, 0,255};
1488
1495
1502
1504}
1505
1506////////////////////////////////////////////////////////////////////////////////
1507/// Static function returning the color number i in current palette.
1510{
1511 Int_t ncolors = fgPalette.fN;
1512 if (ncolors == 0) return 0;
1513 Int_t icol = i%ncolors;
1514 if (icol < 0) icol = 0;
1515 return fgPalette.fArray[icol];
1516}
1517
1518////////////////////////////////////////////////////////////////////////////////
1519/// Static function returning the current active palette.
1522{
1523 return fgPalette;
1524}
1525
1526////////////////////////////////////////////////////////////////////////////////
1527/// Static function returning number of colors in the color palette.
1530{
1531 return fgPalette.fN;
1532}
1533
1534////////////////////////////////////////////////////////////////////////////////
1535/// Static method returning kTRUE if some new colors have been defined after
1536/// initialisation or since the last call to this method. This allows to avoid
1537/// the colors and palette streaming in TCanvas::Streamer if not needed.
1538/// If method called once with set_always_on = 1, all next canvases will be
1539// saved with color palette - disregard if new colors created or not.
1540/// To reset such mode, just call methoid once with set_always_on = -1
1543{
1544 if (set_always_on > 0)
1545 gLastDefinedColors = -1;
1546 else if (set_always_on < 0)
1548
1549 if (gLastDefinedColors < 0)
1550 return kTRUE;
1551
1552 // After initialization gDefinedColors == 649. If it is bigger it means some new
1553 // colors have been defined
1554 Bool_t hasChanged = (gDefinedColors - gLastDefinedColors) > 50;
1556 return hasChanged;
1557}
1558
1559////////////////////////////////////////////////////////////////////////////////
1560/// Return pixel value corresponding to this color. This pixel value can
1561/// be used in the GUI classes. This call does not work in batch mode since
1562/// it needs to communicate with the graphics system.
1565{
1566 if (gVirtualX && !gROOT->IsBatch()) {
1567 if (gApplication) {
1569 gApplication->InitializeGraphics(gROOT->IsWebDisplay());
1570 }
1571 return gVirtualX->GetPixel(fNumber);
1572 }
1573
1574 return 0;
1575}
1576
1577////////////////////////////////////////////////////////////////////////////////
1578/// Static method to compute RGB from HLS. The l and s are between [0,1]
1579/// and h is between [0,360]. The returned r,g,b triplet is between [0,1].
1582 Float_t &r, Float_t &g, Float_t &b)
1583{
1584
1585 Float_t rh, rl, rs, rm1, rm2;
1586 rh = rl = rs = 0;
1587 if (hue > 0) { rh = hue; if (rh > 360) rh = 360; }
1588 if (light > 0) { rl = light; if (rl > 1) rl = 1; }
1589 if (satur > 0) { rs = satur; if (rs > 1) rs = 1; }
1590
1591 if (rl <= 0.5)
1592 rm2 = rl*(1.0f + rs);
1593 else
1594 rm2 = rl + rs - rl*rs;
1595 rm1 = 2.0f*rl - rm2;
1596
1597 if (!rs) { r = rl; g = rl; b = rl; return; }
1598 r = HLStoRGB1(rm1, rm2, rh+120.0f);
1599 g = HLStoRGB1(rm1, rm2, rh);
1600 b = HLStoRGB1(rm1, rm2, rh-120.0f);
1601}
1602
1603////////////////////////////////////////////////////////////////////////////////
1604/// Static method. Auxiliary to HLS2RGB().
1607{
1608 Float_t hue = huei;
1609 if (hue > 360) hue = hue - 360.0f;
1610 if (hue < 0) hue = hue + 360.0f;
1611 if (hue < 60 ) return rn1 + (rn2-rn1)*hue/60.0f;
1612 if (hue < 180) return rn2;
1613 if (hue < 240) return rn1 + (rn2-rn1)*(240.0f-hue)/60.0f;
1614 return rn1;
1615}
1616
1617////////////////////////////////////////////////////////////////////////////////
1618/// Static method to compute RGB from HLS. The h,l,s are between [0,255].
1619/// The returned r,g,b triplet is between [0,255].
1622{
1623 Float_t hh, ll, ss, rr, gg, bb;
1624
1625 hh = Float_t(h) * 360.0f / 255.0f;
1626 ll = Float_t(l) / 255.0f;
1627 ss = Float_t(s) / 255.0f;
1628
1629 TColor::HLStoRGB(hh, ll, ss, rr, gg, bb);
1630
1631 r = (Int_t) (rr * 255.0f);
1632 g = (Int_t) (gg * 255.0f);
1633 b = (Int_t) (bb * 255.0f);
1634}
1635
1636////////////////////////////////////////////////////////////////////////////////
1637/// Static method to compute RGB from HSV:
1638///
1639/// - The hue value runs from 0 to 360.
1640/// - The saturation is the degree of strength or purity and is from 0 to 1.
1641/// Purity is how much white is added to the color, so S=1 makes the purest
1642/// color (no white).
1643/// - Brightness value also ranges from 0 to 1, where 0 is the black.
1644///
1645/// The returned r,g,b triplet is between [0,1].
1648 Float_t &r, Float_t &g, Float_t &b)
1649{
1650 Int_t i;
1651 Float_t f, p, q, t;
1652
1653 if (satur==0) {
1654 // Achromatic (grey)
1655 r = g = b = value;
1656 return;
1657 }
1658
1659 hue /= 60.0f; // sector 0 to 5
1660 i = (Int_t)floor(hue);
1661 f = hue-i; // factorial part of hue
1662 p = value*(1-satur);
1663 q = value*(1-satur*f );
1664 t = value*(1-satur*(1-f));
1665
1666 switch (i) {
1667 case 0:
1668 r = value;
1669 g = t;
1670 b = p;
1671 break;
1672 case 1:
1673 r = q;
1674 g = value;
1675 b = p;
1676 break;
1677 case 2:
1678 r = p;
1679 g = value;
1680 b = t;
1681 break;
1682 case 3:
1683 r = p;
1684 g = q;
1685 b = value;
1686 break;
1687 case 4:
1688 r = t;
1689 g = p;
1690 b = value;
1691 break;
1692 default:
1693 r = value;
1694 g = p;
1695 b = q;
1696 break;
1697 }
1698}
1699
1700////////////////////////////////////////////////////////////////////////////////
1701/// List this color with its attributes.
1703void TColor::ls(Option_t *) const
1704{
1705 printf("Color:%d Red=%f Green=%f Blue=%f Alpha=%f Name=%s\n",
1707}
1708
1709////////////////////////////////////////////////////////////////////////////////
1710/// Dump this color with its attributes.
1712void TColor::Print(Option_t *) const
1713{
1714 ls();
1715}
1716
1717////////////////////////////////////////////////////////////////////////////////
1718/// Static method to compute HLS from RGB. The r,g,b triplet is between
1719/// [0,1], hue is between [0,360], light and satur are [0,1].
1723{
1724 Float_t r = 0, g = 0, b = 0;
1725 if (rr > 0) { r = rr; if (r > 1) r = 1; }
1726 if (gg > 0) { g = gg; if (g > 1) g = 1; }
1727 if (bb > 0) { b = bb; if (b > 1) b = 1; }
1728
1729 Float_t minval = r, maxval = r;
1730 if (g < minval) minval = g;
1731 if (b < minval) minval = b;
1732 if (g > maxval) maxval = g;
1733 if (b > maxval) maxval = b;
1734
1738 light = 0.5f * msum;
1739 if (maxval != minval) {
1740 rnorm = (maxval - r)/mdiff;
1741 gnorm = (maxval - g)/mdiff;
1742 bnorm = (maxval - b)/mdiff;
1743 } else {
1744 satur = hue = 0;
1745 return;
1746 }
1747
1748 if (light < 0.5)
1749 satur = mdiff/msum;
1750 else
1751 satur = mdiff/(2.0f - msum);
1752
1753 if (r == maxval)
1754 hue = 60.0f * (6.0f + bnorm - gnorm);
1755 else if (g == maxval)
1756 hue = 60.0f * (2.0f + rnorm - bnorm);
1757 else
1758 hue = 60.0f * (4.0f + gnorm - rnorm);
1759
1760 if (hue > 360)
1761 hue = hue - 360.0f;
1762}
1763
1764////////////////////////////////////////////////////////////////////////////////
1765/// Static method to compute HSV from RGB.
1766///
1767/// - The input values:
1768/// - r,g,b triplet is between [0,1].
1769/// - The returned values:
1770/// - The hue value runs from 0 to 360.
1771/// - The saturation is the degree of strength or purity and is from 0 to 1.
1772/// Purity is how much white is added to the color, so S=1 makes the purest
1773/// color (no white).
1774/// - Brightness value also ranges from 0 to 1, where 0 is the black.
1778{
1779 Float_t min, max, delta;
1780
1781 min = TMath::Min(TMath::Min(r, g), b);
1782 max = TMath::Max(TMath::Max(r, g), b);
1783 value = max;
1784
1785 delta = max - min;
1786
1787 if (max != 0) {
1788 satur = delta/max;
1789 } else {
1790 satur = 0;
1791 hue = -1;
1792 return;
1793 }
1794
1795 if (r == max) {
1796 hue = (g-b)/delta;
1797 } else if (g == max) {
1798 hue = 2.0f+(b-r)/delta;
1799 } else {
1800 hue = 4.0f+(r-g)/delta;
1801 }
1802
1803 hue *= 60.0f;
1804 if (hue < 0.0f) hue += 360.0f;
1805}
1806
1807////////////////////////////////////////////////////////////////////////////////
1808/// Static method to compute HLS from RGB. The r,g,b triplet is between
1809/// [0,255], hue, light and satur are between [0,255].
1812{
1813 Float_t rr, gg, bb, hue, light, satur;
1814
1815 rr = Float_t(r) / 255.0f;
1816 gg = Float_t(g) / 255.0f;
1817 bb = Float_t(b) / 255.0f;
1818
1820
1821 h = (Int_t) (hue/360.0f * 255.0f);
1822 l = (Int_t) (light * 255.0f);
1823 s = (Int_t) (satur * 255.0f);
1824}
1825
1826
1827////////////////////////////////////////////////////////////////////////////////
1828/// Set the color name and change also the name of the "dark" and "bright" associated
1829/// colors if they exist.
1831void TColor::SetName(const char* name)
1832{
1833 Int_t nd = GetColorByName(TString::Format("%s_dark",fName.Data()).Data());
1834 Int_t nb = GetColorByName(TString::Format("%s_bright",fName.Data()).Data());
1835
1836 fName = name;
1837
1838 auto colors = (TObjArray*) gROOT->GetListOfColors();
1839
1840 if (nd >= 0) {
1841 TColor *colord = (TColor*)colors->At(nd);
1842 colord->TNamed::SetName(TString::Format("%s_dark",fName.Data()).Data());
1843 }
1844
1845 if (nb >= 0) {
1846 TColor *colorb = (TColor*)colors->At(nb);
1847 colorb->TNamed::SetName(TString::Format("%s_bright",fName.Data()).Data());
1848 }
1849}
1850
1851
1852////////////////////////////////////////////////////////////////////////////////
1853/// Initialize this color and its "dark" and "bright" associated colors.
1856{
1858 fRed = r;
1859 fGreen = g;
1860 fBlue = b;
1861
1862 if (fRed < 0) return;
1863
1866
1867 Int_t nplanes = 16;
1868 if (gVirtualX) gVirtualX->GetPlanes(nplanes);
1869 if (nplanes == 0) nplanes = 16;
1870
1871 // allocate color now (can be delayed when we have a large colormap)
1872#ifndef R__WIN32
1873 if (nplanes < 15)
1874#endif
1875 Allocate();
1876
1877 // change the dark and bright associated colors if they exist
1878 Float_t dr, dg, db, lr, lg, lb;
1879
1880 // get the list of all defined colors
1881 auto colors = (TObjArray*) gROOT->GetListOfColors();
1882
1883 // set dark color
1884 Int_t nd = GetColorByName(TString::Format("%s_dark",GetName()).Data());
1885 if (nd >= 0) {
1886 HLStoRGB(fHue, 0.7f*fLight, fSaturation, dr, dg, db);
1887 TColor *colord = (TColor*)colors->At(nd);
1888 if (nplanes > 8) colord->SetRGB(dr, dg, db);
1889 else colord->SetRGB(0.3f,0.3f,0.3f);
1890 colord->SetTitle(colord->AsHexString());
1891 }
1892
1893 // set bright color
1894 Int_t nb = GetColorByName(TString::Format("%s_bright",GetName()).Data());
1895 if (nb >= 0) {
1896 HLStoRGB(fHue, 1.2f*fLight, fSaturation, lr, lg, lb);
1897 TColor *colorb = (TColor*)colors->At(nb);
1898 if (nplanes > 8) colorb->SetRGB(lr, lg, lb);
1899 else colorb->SetRGB(0.8f,0.8f,0.8f);
1900 colorb->SetTitle(colorb->AsHexString());
1901 }
1902
1904}
1905
1906////////////////////////////////////////////////////////////////////////////////
1907/// Make this color known to the graphics system.
1909void TColor::Allocate()
1910{
1911 if (gVirtualX && !gROOT->IsBatch())
1912 gVirtualX->SetRGB(fNumber, GetRed(), GetGreen(), GetBlue());
1913}
1914
1915////////////////////////////////////////////////////////////////////////////////
1916/// Static method returning color number for color specified by
1917/// hex color string of form: "#rrggbb", where rr, gg and bb are in
1918/// hex between [0,FF], e.g. "#c0c0c0". Also alpha channel is applied when
1919/// hex string includes fourth number e.g "#c0c0c0ff"
1920///
1921/// The color retrieval is done using a threshold defined by SetColorThreshold.
1922///
1923/// If specified color does not exist it will be created with as
1924/// name "#rrggbb" with rr, gg and bb in hex between [0,FF].
1926Int_t TColor::GetColor(const char *hexcolor)
1927{
1928 if (hexcolor && *hexcolor == '#') {
1929 Int_t r, g, b, a;
1930 if (strlen(hexcolor) == 9 && sscanf(hexcolor + 1, "%02x%02x%02x%02x", &r, &g, &b, &a) == 4)
1931 return GetColor(r, g, b, a / 255.);
1932 if (sscanf(hexcolor + 1, "%02x%02x%02x", &r, &g, &b) == 3)
1933 return GetColor(r, g, b);
1934 }
1935 ::Error("TColor::GetColor(const char*)", "incorrect color string");
1936 return 0;
1937}
1938
1939////////////////////////////////////////////////////////////////////////////////
1940/// Static method returning color number for color specified by
1941/// r, g and b. The r,g,b should be in the range [0,1].
1942///
1943/// The color retrieval is done using a threshold defined by SetColorThreshold.
1944///
1945/// If specified color does not exist it will be created
1946/// with as name "#rrggbb" with rr, gg and bb in hex between
1947/// [0,FF].
1950{
1951 return GetColor(Int_t(r * 255), Int_t(g * 255), Int_t(b * 255), a);
1952}
1953
1954////////////////////////////////////////////////////////////////////////////////
1955/// Static method returning color number for color specified by
1956/// system dependent pixel value. Pixel values can be obtained, e.g.,
1957/// from the GUI color picker.
1958///
1959/// The color retrieval is done using a threshold defined by SetColorThreshold.
1960
1963{
1964 Int_t r, g, b;
1965
1966 Pixel2RGB(pixel, r, g, b);
1967
1968 return GetColor(r, g, b);
1969}
1970
1971////////////////////////////////////////////////////////////////////////////////
1972/// This method specifies the color threshold used by GetColor to retrieve a color.
1973///
1974/// \param[in] t Color threshold. By default is equal to 1./31. or 1./255.
1975/// depending on the number of available color planes.
1976///
1977/// When GetColor is called, it scans the defined colors and compare them to the
1978/// requested color.
1979/// If the Red Green and Blue values passed to GetColor are Rr Gr Br
1980/// and Rd Gd Bd the values of a defined color. These two colors are considered equal
1981/// if (abs(Rr-Rd) < t & abs(Br-Bd) < t & abs(Br-Bd) < t). If this test passes,
1982/// the color defined by Rd Gd Bd is returned by GetColor.
1983///
1984/// To make sure GetColor will return a color having exactly the requested
1985/// R G B values it is enough to specify a nul :
1986/// ~~~ {.cpp}
1987/// TColor::SetColorThreshold(0.);
1988/// ~~~
1989///
1990/// To reset the color threshold to its default value it is enough to do:
1991/// ~~~ {.cpp}
1992/// TColor::SetColorThreshold(-1.);
1993/// ~~~
1998}
1999
2000////////////////////////////////////////////////////////////////////////////////
2001/// Static method returning color number for color specified by
2002/// r, g and b. The r,g,b should be in the range [0,255].
2003/// If the specified color does not exist it will be created
2004/// with as name "#rrggbb" with rr, gg and bb in hex between
2005/// [0,FF].
2006///
2007/// The color retrieval is done using a threshold defined by SetColorThreshold.
2010{
2012 if (r < 0)
2013 r = 0;
2014 else if (r > 255)
2015 r = 255;
2016 if (g < 0)
2017 g = 0;
2018 else if (g > 255)
2019 g = 255;
2020 if (b < 0)
2021 b = 0;
2022 else if (b > 255)
2023 b = 255;
2024 if (a > 1.)
2025 a = 1.;
2026 else if (a < 0.)
2027 a = 0.;
2028
2029 // Get list of all defined colors
2030 TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
2031
2032 TString name = TString::Format("#%02x%02x%02x", r, g, b);
2033 if (a != 1.)
2034 name.Append(TString::Format("%02x", Int_t(a*255)));
2035
2036 // Look for color by name
2037 if (auto color = static_cast<TColor *>(colors->FindObject(name.Data())))
2038 // We found the color by name, so we use that right away
2039 return color->GetNumber();
2040
2041 Float_t rr, gg, bb;
2042 rr = Float_t(r)/255.0f;
2043 gg = Float_t(g)/255.0f;
2044 bb = Float_t(b)/255.0f;
2045
2046 TIter next(colors);
2047
2048 Float_t thres;
2049 if (gColorThreshold >= 0) {
2051 } else {
2052 Int_t nplanes = 24;
2053 thres = 1.0f/255.0f; // 8 bits per color : 0 - 0xFF !
2054 if (gVirtualX) gVirtualX->GetPlanes(nplanes);
2055 if ((nplanes > 0) && (nplanes <= 16)) thres = 1.0f/31.0f; // 5 bits per color : 0 - 0x1F !
2056 }
2057
2058 // Loop over all defined colors
2059 while (auto color = static_cast<TColor *>(next())) {
2060 if (TMath::Abs(color->GetRed() - rr) > thres) continue;
2061 if (TMath::Abs(color->GetGreen() - gg) > thres) continue;
2062 if (TMath::Abs(color->GetBlue() - bb) > thres) continue;
2063 if (TMath::Abs(color->GetAlpha() - a) > thres) continue;
2064 // We found a matching color in the color table
2065 return color->GetNumber();
2066 }
2067
2068 // We didn't find a matching color in the color table, so we
2069 // add it. Note name is of the form "#rrggbb" where rr, etc. are
2070 // hexadecimal numbers.
2071 auto color = new TColor(colors->GetLast()+1, rr, gg, bb, name.Data(), a);
2072
2073 return color->GetNumber();
2074}
2075
2076////////////////////////////////////////////////////////////////////////////////
2077/// Static method returning color index for a color specified by name.
2078/// The list of defined colors and their names is given by TColor::ListColors.
2079/// If the specified color name does not exist -1 is returned.
2082{
2083 TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
2084 if (auto color = static_cast<TColor *>(colors->FindObject(colorname))) {
2085 return color->GetNumber();
2086 } else {
2087 return -1;
2088 }
2089}
2090
2091////////////////////////////////////////////////////////////////////////////////
2092/// Static function: Returns the bright color number corresponding to n
2093/// If the TColor object does not exist, it is created at a free color index.
2096{
2097 if (n < 0) return -1;
2098
2099 // Get list of all defined colors
2100 auto colors = (TObjArray*) gROOT->GetListOfColors();
2101 Int_t ncolors = colors->GetSize();
2102
2103 // Get existing color at index n
2104 TColor *color = nullptr;
2105 if (n < ncolors) color = (TColor*)colors->At(n);
2106 if (!color) return -1;
2107
2108 // in case color is not named, assign a unique name.
2109 if (strlen(color->GetName()) == 0)
2110 color->SetName(TString::Format("Color%d",n).Data());
2111
2112 // check if the bright color already exists, if yes return it
2113 TString nameb = TString::Format("%s_bright",color->GetName()).Data();
2114 Int_t nb = GetColorByName(nameb.Data());
2115 TColor *colorb = nullptr;
2116 if (nb >= 0) {
2117 colorb = (TColor*)colors->At(nb);
2118 return colorb->GetNumber();
2119 }
2120
2121 //Get the rgb of the new bright color corresponding to color n
2122 Float_t r,g,b;
2123 HLStoRGB(color->GetHue(), 1.2f*color->GetLight(), color->GetSaturation(), r, g, b);
2124
2125 //Build the bright color
2127 colorb = new TColor(nb,r,g,b);
2128 colorb->SetName(nameb.Data());
2129 colorb->SetTitle(colorb->AsHexString());
2130 colors->AddAtAndExpand(colorb,nb);
2131 return nb;
2132}
2133
2134////////////////////////////////////////////////////////////////////////////////
2135/// Static function: Returns the dark color number corresponding to n
2136/// If the TColor object does not exist, it is created at a free color index.
2139{
2140 if (n < 0) return -1;
2141
2142 // Get list of all defined colors
2143 auto colors = (TObjArray*) gROOT->GetListOfColors();
2144 Int_t ncolors = colors->GetSize();
2145
2146 // Get existing color at index n
2147 TColor *color = nullptr;
2148 if (n < ncolors) color = (TColor*)colors->At(n);
2149 if (!color) return -1;
2150
2151 // in case color is not named, assign a unique name.
2152 if (strlen(color->GetName()) == 0)
2153 color->SetName(TString::Format("Color%d",n).Data());
2154
2155 // check if the dark color already exists, if yes return it
2156 TString named = TString::Format("%s_dark",color->GetName()).Data();
2157 Int_t nd = GetColorByName(named.Data());
2158 TColor *colord = nullptr;
2159 if (nd >= 0) {
2160 colord = (TColor*)colors->At(nd);
2161 return colord->GetNumber();
2162 }
2163
2164 //Get the rgb of the new dark color corresponding to color n
2165 Float_t r,g,b;
2166 HLStoRGB(color->GetHue(), 0.7f*color->GetLight(), color->GetSaturation(), r, g, b);
2167
2168 //Build the dark color
2170 colord = new TColor(nd,r,g,b);
2171 colord->SetName(named.Data());
2172 colord->SetTitle(colord->AsHexString());
2173 colors->AddAtAndExpand(colord,nd);
2174 return nd;
2175}
2176
2177////////////////////////////////////////////////////////////////////////////////
2178/// Static function: Returns the transparent color number corresponding to n.
2179/// The opacity level is given by the alpha value a. If a color with the same
2180/// RGBa values already exists it is returned.
2183{
2184 if (n < 0) return -1;
2185
2186 TColor *color = gROOT->GetColor(n);
2187 if (color) {
2188 TObjArray *colors = (TObjArray *)gROOT->GetListOfColors();
2189 Int_t ncolors = colors->GetSize();
2190 TColor *col = nullptr;
2191 for (Int_t i = 0; i < ncolors; i++) {
2192 col = (TColor *)colors->At(i);
2193 if (col) {
2194 if (col->GetRed() == color->GetRed() && col->GetGreen() == color->GetGreen() &&
2195 col->GetBlue() == color->GetBlue() && col->GetAlpha() == a)
2196 return col->GetNumber();
2197 }
2198 }
2199 TColor *colort = new TColor(gROOT->GetListOfColors()->GetLast()+1,
2200 color->GetRed(), color->GetGreen(), color->GetBlue());
2201 colort->SetAlpha(a);
2202 colort->SetName(TString::Format("%s_transparent",color->GetName()).Data());
2203 return colort->GetNumber();
2204 } else {
2205 ::Error("TColor::GetColorTransparent", "color with index %d not defined", n);
2206 return -1;
2207 }
2208}
2209
2210////////////////////////////////////////////////////////////////////////////////
2211/// Static function: Returns the linear gradient color number corresponding to specified parameters.
2212/// First parameter set direction as angle in grad. Value 0 is horizontal direction, 90 - vertical
2213/// List of colors defines interpolation colors for the gradient
2214/// Optional positions can define relative color positions and must be sorted array of values between 0 and 1.
2215/// If such gradient not exists - it will be created new
2216/// Returns -1 if wrong parameters where specified
2218Int_t TColor::GetLinearGradient(Double_t angle, const std::vector<Int_t> &colors, const std::vector<Double_t> &positions)
2219{
2220 if (colors.size() < 2) {
2221 ::Error("TColor::GetLinearGradient", "number of specified colors %d not enough to create gradients", (int) colors.size());
2222 return -1;
2223 }
2224
2225 std::vector<Double_t> raw_colors(colors.size()*4);
2226 std::vector<Double_t> raw_positions(colors.size());
2227 for (unsigned indx = 0; indx < colors.size(); indx++) {
2228 TColor *color = gROOT->GetColor(colors[indx]);
2229 if (!color) {
2230 ::Error("TColor::GetLinearGradient", "Not able to get %d color", (int) colors.size());
2231 return -1;
2232 }
2233 raw_colors[indx*4] = color->GetRed();
2234 raw_colors[indx*4+1] = color->GetGreen();
2235 raw_colors[indx*4+2] = color->GetBlue();
2236 raw_colors[indx*4+3] = color->GetAlpha();
2237
2238 raw_positions[indx] = indx < positions.size() ? positions[indx] : indx / (colors.size() - 1.);
2239 }
2240
2241 Double_t _cos = std::cos(angle / 180. * 3.1415), _sin = std::sin(angle / 180. * 3.1415);
2242 Double_t x0 = (_cos >= 0. ? 0. : 1.), y0 = (_sin >= 0. ? 0. : 1.);
2244
2245 TLinearGradient::Point start(x0, y0), end(x0 + _cos/scale, y0 + _sin/scale);
2246
2247
2248 TObjArray *root_colors = (TObjArray*) gROOT->GetListOfColors();
2249
2250 TIter iter(root_colors);
2251
2252 while (auto col = static_cast<TColor *>(iter())) {
2253 if (col->IsA() != TLinearGradient::Class())
2254 continue;
2255
2256 auto grad = static_cast<TLinearGradient *>(col);
2257
2258 if (grad->GetNumberOfSteps() != colors.size())
2259 continue;
2260
2261 Bool_t match = kTRUE;
2262 for (unsigned n = 0; n < raw_colors.size(); ++n)
2263 if (TMath::Abs(raw_colors[n] - grad->GetColors()[n]) > 1e-3)
2264 match = kFALSE;
2265
2266 for (unsigned n = 0; n < raw_positions.size(); ++n)
2267 if (TMath::Abs(raw_positions[n] - grad->GetColorPositions()[n]) > 1e-2)
2268 match = kFALSE;
2269
2270 if (TMath::Abs(grad->GetStart().fX - start.fX) > 1e-2 ||
2271 TMath::Abs(grad->GetStart().fY - start.fY) > 1e-2 ||
2272 TMath::Abs(grad->GetEnd().fX - end.fX) > 1e-2 ||
2273 TMath::Abs(grad->GetEnd().fY - end.fY) > 1e-2)
2274 match = kFALSE;
2275
2276 if (match)
2277 return col->GetNumber();
2278 }
2279
2280 auto grad = new TLinearGradient(root_colors->GetLast() + 1, colors.size(), raw_positions.data(), raw_colors.data());
2281
2282 grad->SetStartEnd(start, end);
2283
2284 return grad->GetNumber();
2285}
2286
2287////////////////////////////////////////////////////////////////////////////////
2288/// Static function: Returns the radial gradient color number corresponding to specified parameters.
2289/// First parameter set direction as angle in grad. Value 0 is horizontal direction, 90 - vertical
2290/// List of colors defines interpolation colors for the gradient
2291/// Optional positions can define relative color positions and must be sorted array of values between 0 and 1.
2292/// If such gradient not exists - it will be created new
2293/// Returns -1 if wrong parameter where specified
2295Int_t TColor::GetRadialGradient(Double_t radius, const std::vector<Int_t> &colors, const std::vector<Double_t> &positions)
2296{
2297 if (colors.size() < 2) {
2298 ::Error("TColor::GetRadialGradient", "number of specified colors %d not enough to create gradients", (int) colors.size());
2299 return -1;
2300 }
2301
2302 std::vector<Double_t> raw_colors(colors.size()*4);
2303 std::vector<Double_t> raw_positions(colors.size());
2304 for (unsigned indx = 0; indx < colors.size(); indx++) {
2305 TColor *color = gROOT->GetColor(colors[indx]);
2306 if (!color) {
2307 ::Error("TColor::GetRadialGradient", "Not able to get %d color", (int) colors.size());
2308 return -1;
2309 }
2310 raw_colors[indx*4] = color->GetRed();
2311 raw_colors[indx*4+1] = color->GetGreen();
2312 raw_colors[indx*4+2] = color->GetBlue();
2313 raw_colors[indx*4+3] = color->GetAlpha();
2314
2315 raw_positions[indx] = indx < positions.size() ? positions[indx] : indx / (colors.size() - 1.);
2316 }
2317
2318 TRadialGradient::Point start(0.5, 0.5);
2319
2320 TObjArray *root_colors = (TObjArray*) gROOT->GetListOfColors();
2321
2322 TIter iter(root_colors);
2323
2324 while (auto col = static_cast<TColor *>(iter())) {
2325 if (col->IsA() != TRadialGradient::Class())
2326 continue;
2327
2328 auto grad = static_cast<TRadialGradient *>(col);
2329
2330 if (grad->GetNumberOfSteps() != colors.size())
2331 continue;
2332
2333 if (grad->GetGradientType() != TRadialGradient::kSimple)
2334 continue;
2335
2336 Bool_t match = kTRUE;
2337 for (unsigned n = 0; n < raw_colors.size(); ++n)
2338 if (TMath::Abs(raw_colors[n] - grad->GetColors()[n]) > 1e-3)
2339 match = kFALSE;
2340
2341 for (unsigned n = 0; n < raw_positions.size(); ++n)
2342 if (TMath::Abs(raw_positions[n] - grad->GetColorPositions()[n]) > 1e-2)
2343 match = kFALSE;
2344
2345 if (TMath::Abs(grad->GetStart().fX - start.fX) > 1e-2 ||
2346 TMath::Abs(grad->GetStart().fY - start.fY) > 1e-2 ||
2347 TMath::Abs(grad->GetR1() - radius) > 1e-2)
2348 match = kFALSE;
2349
2350 if (match)
2351 return col->GetNumber();
2352 }
2353
2354 auto grad = new TRadialGradient(root_colors->GetLast() + 1, colors.size(), raw_positions.data(), raw_colors.data());
2355
2356 grad->SetRadialGradient(start, radius);
2357
2358 return grad->GetNumber();
2359}
2360
2361
2362////////////////////////////////////////////////////////////////////////////////
2363/// Static function: Returns the free color index greater than the highest defined color
2364/// index. All the color indices after this index are also free. It can be used to
2365/// define a user custom color.
2366///
2367/// ~~~ {.cpp}
2368/// Int_t ci = TColor::GetFreeColorIndex();
2369/// auto color = new TColor(ci, 0.1, 0.2, 0.3);
2370/// ~~~
2375}
2376
2377////////////////////////////////////////////////////////////////////////////////
2378/// Static function: Returns the first free color greater in the list of colors.
2379/// index. It can be used to define a user custom color.
2380///
2381/// ~~~ {.cpp}
2382/// Int_t ci = TColor::GetFirstFreeColorIndex();
2383/// auto color = new TColor(ci, 0.1, 0.2, 0.3);
2384/// ~~~
2387{
2388 TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
2389 const Int_t ncolors = colors->GetSize();
2390 TColor *color = nullptr;
2391 for (Int_t i = kP10Cyan+1; i<ncolors; i++) {
2392 color = (TColor*)colors->At(i);
2393 if (!color) return i;
2394 }
2395 return -1;
2396}
2397
2398////////////////////////////////////////////////////////////////////////////////
2399/// List `nb` colors from the color index `ci`.
2400/// If `nb=0` all the colors are printed.
2401/// If showEmpty is set to kTRUE, empty color indices are also printed
2404{
2405 TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
2406 const Int_t ncolors = colors->GetSize();
2407 Int_t last = ci+nb;
2408 if (nb==0 || last>=ncolors) last = ncolors;
2409 TColor *color = 0;
2410 Int_t nc =0 ;
2411
2412 printf(" +------+-------+-------+-------+-------+--------------------+--------------------+\n");
2413 printf(" | Idx | Red | Green | Blue | Alpha | Color Name | Color Title |\n");
2414 printf(" +------+-------+-------+-------+-------+--------------------+--------------------+\n");
2415
2416 for (Int_t i = ci; i<last; i++) {
2417 color = (TColor*)colors->At(i);
2418 if (color) {
2419 printf(" | %4d | %5.3f | %5.3f | %5.3f | %5.3f | %18s | %18s |\n", i,
2420 color->GetRed(),
2421 color->GetGreen(),
2422 color->GetBlue(),
2423 color->GetAlpha(),
2424 color->GetName(),
2425 color->GetTitle());
2426 nc++;
2427 } else if (showEmpty) {
2428 printf(" | %4d | ? | ? | ? | ? | ? | ? |\n",i);
2429 }
2430 }
2431 printf(" +------+-------+-------+-------+-------+--------------------+--------------------+\n");
2432 printf(" | Number of possible colors = %4d |\n",ncolors);
2433 printf(" | Number of defined colors between %4d and %4d = %4d |\n",ci,last,nc);
2434 printf(" | Number of free indices between %4d and %4d = %4d |\n",ci,last,last-ci-nc);
2435 printf(" +--------------------------------------------------------------------------------+\n\n");
2436
2437}
2438
2439////////////////////////////////////////////////////////////////////////////////
2440/// Static method that given a color index number, returns the corresponding
2441/// pixel value. This pixel value can be used in the GUI classes. This call
2442/// does not work in batch mode since it needs to communicate with the
2443/// graphics system.
2446{
2448 TColor *color = gROOT->GetColor(ci);
2449 if (color)
2450 return color->GetPixel();
2451 else
2452 ::Warning("TColor::Number2Pixel", "color with index %d not defined", ci);
2453
2454 return 0;
2455}
2456
2457////////////////////////////////////////////////////////////////////////////////
2458/// Convert r,g,b to graphics system dependent pixel value.
2459/// The r,g,b triplet must be [0,1].
2462{
2463 if (r < 0) r = 0;
2464 if (g < 0) g = 0;
2465 if (b < 0) b = 0;
2466 if (r > 1) r = 1;
2467 if (g > 1) g = 1;
2468 if (b > 1) b = 1;
2469
2470 ColorStruct_t color;
2471 color.fRed = UShort_t(r * 65535);
2472 color.fGreen = UShort_t(g * 65535);
2473 color.fBlue = UShort_t(b * 65535);
2474 color.fMask = kDoRed | kDoGreen | kDoBlue;
2475 gVirtualX->AllocColor(gVirtualX->GetColormap(), color);
2476 return color.fPixel;
2477}
2478
2479////////////////////////////////////////////////////////////////////////////////
2480/// Convert r,g,b to graphics system dependent pixel value.
2481/// The r,g,b triplet must be [0,255].
2484{
2485 if (r < 0) r = 0;
2486 if (g < 0) g = 0;
2487 if (b < 0) b = 0;
2488 if (r > 255) r = 255;
2489 if (g > 255) g = 255;
2490 if (b > 255) b = 255;
2491
2492 ColorStruct_t color;
2493 color.fRed = UShort_t(r * 256); // 65536/256
2494 color.fGreen = UShort_t(g * 256);
2495 color.fBlue = UShort_t(b * 256);
2496 color.fMask = kDoRed | kDoGreen | kDoBlue;
2497 gVirtualX->AllocColor(gVirtualX->GetColormap(), color);
2498 return color.fPixel;
2499}
2500
2501////////////////////////////////////////////////////////////////////////////////
2502/// Convert machine dependent pixel value (obtained via RGB2Pixel or
2503/// via Number2Pixel() or via TColor::GetPixel()) to r,g,b triplet.
2504/// The r,g,b triplet will be [0,1].
2507{
2508 ColorStruct_t color;
2509 color.fPixel = pixel;
2510 gVirtualX->QueryColor(gVirtualX->GetColormap(), color);
2511 r = (Float_t)color.fRed / 65535.0f;
2512 g = (Float_t)color.fGreen / 65535.0f;
2513 b = (Float_t)color.fBlue / 65535.0f;
2514}
2515
2516////////////////////////////////////////////////////////////////////////////////
2517/// Convert machine dependent pixel value (obtained via RGB2Pixel or
2518/// via Number2Pixel() or via TColor::GetPixel()) to r,g,b triplet.
2519/// The r,g,b triplet will be [0,255].
2522{
2523 ColorStruct_t color;
2524 color.fPixel = pixel;
2525 gVirtualX->QueryColor(gVirtualX->GetColormap(), color);
2526 // color is between 0 and 65535 inclusive.
2527 // We need to move it to the 0 to 255 range (inclusive).
2528 // So we need to resample the 65536 values into 256 indices.
2529 // This would mean equal blocks of 256 high-res values per color index.
2530 r = color.fRed / 256;
2531 g = color.fGreen / 256;
2532 b = color.fBlue / 256;
2533}
2534
2535////////////////////////////////////////////////////////////////////////////////
2536/// Convert machine dependent pixel value (obtained via RGB2Pixel or
2537/// via Number2Pixel() or via TColor::GetPixel()) to a hexadecimal string.
2538/// This string can be directly passed to, for example,
2539/// TGClient::GetColorByName(). String will be reused so copy immediately
2540/// if needed.
2543{
2544 static TString tempbuf;
2545 Int_t r, g, b;
2546 Pixel2RGB(pixel, r, g, b);
2547 tempbuf.Form("#%02x%02x%02x", r, g, b);
2548 return tempbuf;
2549}
2550
2551////////////////////////////////////////////////////////////////////////////////
2552/// Save a color with index > 228 as a C++ statement(s) on output stream out.
2553/// Return kFALSE if color not saved in the output stream
2555Bool_t TColor::SaveColor(std::ostream &out, Int_t ci)
2556{
2557 if (ci <= 228)
2558 return kFALSE;
2559
2560 TColor *c = gROOT->GetColor(ci);
2561 if (!c)
2562 return kFALSE;
2563
2564 if (gROOT->ClassSaved(TColor::Class()))
2565 out << " ci = ";
2566 else
2567 out << " Int_t ci = ";
2568
2569 Float_t r, g, b, a;
2570
2571 c->GetRGB(r, g, b);
2572 a = c->GetAlpha();
2573 Int_t ri = (Int_t)(255 * r), gi = (Int_t)(255 * g), bi = (Int_t)(255 * b), ai = (Int_t)(255 * a);
2574
2575 TString cname;
2576
2577 if (ai < 255)
2578 cname.Form("#%02x%02x%02x%02x", ri, gi, bi, ai);
2579 else
2580 cname.Form("#%02x%02x%02x", ri, gi, bi);
2581
2582 out << "TColor::GetColor(\"" << cname << "\");" << std::endl;
2583
2584 return kTRUE;
2585}
2586
2587////////////////////////////////////////////////////////////////////////////////
2588/// Return whether all colors return grayscale values.
2590{
2591 return fgGrayscaleMode;
2592}
2593
2594////////////////////////////////////////////////////////////////////////////////
2595/// Set whether all colors should return grayscale values.
2597void TColor::SetGrayscale(Bool_t set /*= kTRUE*/)
2598{
2599 if (fgGrayscaleMode == set) return;
2600
2601 fgGrayscaleMode = set;
2602
2603 if (!gVirtualX || gROOT->IsBatch()) return;
2604
2606 TIter iColor(gROOT->GetListOfColors());
2607 TColor* color = nullptr;
2608 while ((color = (TColor*) iColor()))
2609 color->Allocate();
2610}
2611
2612////////////////////////////////////////////////////////////////////////////////
2613/// \brief Static function creating a color palette based on an input text file.
2614///
2615/// Every color in the file will take the same amount of space in the palette.
2616///
2617/// \see https://doi.org/10.1038/s41467-020-19160-7
2618/// \note This function is designed to load into ROOT the colour-vision
2619/// deficiency friendly and perceptually uniform colour maps specially designed
2620/// in https://doi.org/10.5281/zenodo.4491293, namely the .txt files stored
2621/// in the subfolders of ScientificColourMaps7.zip, e.g. batlow/batlow.txt
2622///
2623/// \param fileName: Name of a .txt file (ASCII) containing three floats per
2624/// line, separated by spaces, namely the r g b fractions of the color, each
2625/// value being in the range [0,1].
2626/// \param alpha the global opacity for all colors within this palette
2627/// \return a positive value on success and -1 on error.
2628/// \author Fernando Hueso-González
2630{
2631 std::ifstream f(fileName.Data());
2632 if (!f.good()) {
2633 ::Error("TColor::CreateColorPalette(const TString)", "%s does not exist or cannot be opened", fileName.Data());
2634 return -1;
2635 }
2636
2637 Int_t nLines = 0;
2638 Float_t r, g, b;
2639 std::vector<Float_t> reds, greens, blues;
2640 while (f >> r >> g >> b) {
2641 nLines++;
2642 if (r < 0. || r > 1.) {
2643 ::Error("TColor::CreateColorPalette(const TString)", "Red value %f outside [0,1] on line %d of %s ", r,
2644 nLines, fileName.Data());
2645 f.close();
2646 return -1;
2647 }
2648 if (g < 0. || g > 1.) {
2649 ::Error("TColor::CreateColorPalette(const TString)", "Green value %f outside [0,1] on line %d of %s ", g,
2650 nLines, fileName.Data());
2651 f.close();
2652 return -1;
2653 }
2654 if (b < 0. || b > 1.) {
2655 ::Error("TColor::CreateColorPalette(const TString)", "Blue value %f outside [0,1] on line %d of %s ", b,
2656 nLines, fileName.Data());
2657 f.close();
2658 return -1;
2659 }
2660 reds.emplace_back(r);
2661 greens.emplace_back(g);
2662 blues.emplace_back(b);
2663 }
2664 f.close();
2665 if (nLines < 2) {
2666 ::Error("TColor::CreateColorPalette(const TString)", "Found insufficient color lines (%d) on %s", nLines,
2667 fileName.Data());
2668 return -1;
2669 }
2670
2672 Int_t *palette = new Int_t[nLines];
2673
2674 for (Int_t i = 0; i < nLines; ++i) {
2675 new TColor(reds.at(i), greens.at(i), blues.at(i), alpha);
2677 }
2679 delete[] palette;
2680 return gHighestColorIndex + 1 - nLines;
2681}
2682
2683////////////////////////////////////////////////////////////////////////////////
2684/// Static function creating a color table with several connected linear gradients.
2685///
2686/// - Number: The number of end point colors that will form the gradients.
2687/// Must be at least 2.
2688/// - Stops: Where in the whole table the end point colors should lie.
2689/// Each entry must be on [0, 1], each entry must be greater than
2690/// the previous entry.
2691/// - Red, Green, Blue: The end point color values.
2692/// Each entry must be on [0, 1]
2693/// - NColors: Total number of colors in the table. Must be at least 1.
2694/// - alpha: the opacity factor, between 0 and 1. Default is no transparency (1).
2695/// - setPalette: activate the newly created palette (true by default). If false,
2696/// the caller is in charge of calling TColor::SetPalette using the
2697/// return value of the function (first palette color index) and
2698/// reconstructing the Int_t palette[NColors+1] array.
2699///
2700/// Returns a positive value (the index of the first color of the palette) on
2701/// success and -1 on error.
2702///
2703/// The table is constructed by tracing lines between the given points in
2704/// RGB space. Each color value may have a value between 0 and 1. The
2705/// difference between consecutive "Stops" values gives the fraction of
2706/// space in the whole table that should be used for the interval between
2707/// the corresponding color values.
2708///
2709/// Normally the first element of Stops should be 0 and the last should be 1.
2710/// If this is not true, fewer than NColors will be used in proportion with
2711/// the total interval between the first and last elements of Stops.
2712///
2713/// This definition is similar to the povray-definition of gradient
2714/// color tables.
2715///
2716/// For instance:
2717/// ~~~ {.cpp}
2718/// UInt_t Number = 3;
2719/// Double_t Red[3] = { 0.0, 1.0, 1.0 };
2720/// Double_t Green[3] = { 0.0, 0.0, 1.0 };
2721/// Double_t Blue[3] = { 1.0, 0.0, 1.0 };
2722/// Double_t Stops[3] = { 0.0, 0.4, 1.0 };
2723/// ~~~
2724/// This defines a table in which there are three color end points:
2725/// RGB = {0, 0, 1}, {1, 0, 0}, and {1, 1, 1} = blue, red, white
2726/// The first 40% of the table is used to go linearly from blue to red.
2727/// The remaining 60% of the table is used to go linearly from red to white.
2728///
2729/// If you define a very short interval such that less than one color fits
2730/// in it, no colors at all will be allocated. If this occurs for all
2731/// intervals, ROOT will revert to the default palette.
2732///
2733/// Original code by Andreas Zoglauer (zog@mpe.mpg.de)
2736 Double_t* Red, Double_t* Green,
2737 Double_t* Blue, UInt_t NColors, Float_t alpha,
2739{
2741
2742 UInt_t g, c;
2743 UInt_t nPalette = 0;
2744 Int_t *palette = new Int_t[NColors+1];
2746
2747 if(Number < 2 || NColors < 1){
2748 delete [] palette;
2749 return -1;
2750 }
2751
2752 // Check if all RGB values are between 0.0 and 1.0 and
2753 // Stops goes from 0.0 to 1.0 in increasing order.
2754 for (c = 0; c < Number; c++) {
2755 if (Red[c] < 0 || Red[c] > 1.0 ||
2756 Green[c] < 0 || Green[c] > 1.0 ||
2757 Blue[c] < 0 || Blue[c] > 1.0 ||
2758 Stops[c] < 0 || Stops[c] > 1.0) {
2759 delete [] palette;
2760 return -1;
2761 }
2762 if (c >= 1) {
2763 if (Stops[c-1] > Stops[c]) {
2764 delete [] palette;
2765 return -1;
2766 }
2767 }
2768 }
2769
2770 // Now create the colors and add them to the default palette:
2771
2772 // For each defined gradient...
2773 for (g = 1; g < Number; g++) {
2774 // create the colors...
2775 nColorsGradient = (Int_t) (floor(NColors*Stops[g]) - floor(NColors*Stops[g-1]));
2776 for (c = 0; c < nColorsGradient; c++) {
2777 new TColor( Float_t(Red[g-1] + c * (Red[g] - Red[g-1]) / nColorsGradient),
2778 Float_t(Green[g-1] + c * (Green[g] - Green[g-1])/ nColorsGradient),
2779 Float_t(Blue[g-1] + c * (Blue[g] - Blue[g-1]) / nColorsGradient),
2780 alpha);
2782 nPalette++;
2783 }
2784 }
2785
2786 if (setPalette)
2788 delete [] palette;
2789 return gHighestColorIndex + 1 - NColors;
2790}
2791
2792
2793////////////////////////////////////////////////////////////////////////////////
2794/// Static function.
2795/// The color palette is used by the histogram classes
2796/// (see TH1::Draw options).
2797/// For example TH1::Draw("col") draws a 2-D histogram with cells
2798/// represented by a box filled with a color CI function of the cell content.
2799/// if the cell content is N, the color CI used will be the color number
2800/// in colors[N],etc. If the maximum cell content is > ncolors, all
2801/// cell contents are scaled to ncolors.
2802///
2803/// `if ncolors <= 0` a default palette (see below) of 50 colors is
2804/// defined. The colors defined in this palette are OK for coloring pads, labels.
2805///
2806/// ~~~ {.cpp}
2807/// index 0->9 : grey colors from light to dark grey
2808/// index 10->19 : "brown" colors
2809/// index 20->29 : "blueish" colors
2810/// index 30->39 : "redish" colors
2811/// index 40->49 : basic colors
2812/// ~~~
2813///
2814/// `if ncolors == 1 && colors == 0`, a Rainbow Color map is created
2815/// with 50 colors. It is kept for backward compatibility. Better palettes like
2816/// kBird are recommended.
2817///
2818/// High quality predefined palettes with 255 colors are available when `colors == 0`.
2819/// The following value of `ncolors` give access to:
2820///
2821/// ~~~ {.cpp}
2822/// if ncolors = 51 and colors=0, a Deep Sea palette is used.
2823/// if ncolors = 52 and colors=0, a Grey Scale palette is used.
2824/// if ncolors = 53 and colors=0, a Dark Body Radiator palette is used.
2825/// if ncolors = 54 and colors=0, a Two-Color Hue palette is used.(dark blue through neutral gray to bright yellow)
2826/// if ncolors = 55 and colors=0, a Rain Bow palette is used.
2827/// if ncolors = 56 and colors=0, an Inverted Dark Body Radiator palette is used.
2828/// if ncolors = 57 and colors=0, a monotonically increasing L value palette is used.
2829/// if ncolors = 58 and colors=0, a Cubehelix palette is used
2830/// (Cf. Dave Green's "cubehelix" colour scheme at http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/)
2831/// if ncolors = 59 and colors=0, a Green Red Violet palette is used.
2832/// if ncolors = 60 and colors=0, a Blue Red Yellow palette is used.
2833/// if ncolors = 61 and colors=0, an Ocean palette is used.
2834/// if ncolors = 62 and colors=0, a Color Printable On Grey palette is used.
2835/// if ncolors = 63 and colors=0, an Alpine palette is used.
2836/// if ncolors = 64 and colors=0, an Aquamarine palette is used.
2837/// if ncolors = 65 and colors=0, an Army palette is used.
2838/// if ncolors = 66 and colors=0, an Atlantic palette is used.
2839/// if ncolors = 67 and colors=0, an Aurora palette is used.
2840/// if ncolors = 68 and colors=0, an Avocado palette is used.
2841/// if ncolors = 69 and colors=0, a Beach palette is used.
2842/// if ncolors = 70 and colors=0, a Black Body palette is used.
2843/// if ncolors = 71 and colors=0, a Blue Green Yellow palette is used.
2844/// if ncolors = 72 and colors=0, a Brown Cyan palette is used.
2845/// if ncolors = 73 and colors=0, a CMYK palette is used.
2846/// if ncolors = 74 and colors=0, a Candy palette is used.
2847/// if ncolors = 75 and colors=0, a Cherry palette is used.
2848/// if ncolors = 76 and colors=0, a Coffee palette is used.
2849/// if ncolors = 77 and colors=0, a Dark Rain Bow palette is used.
2850/// if ncolors = 78 and colors=0, a Dark Terrain palette is used.
2851/// if ncolors = 79 and colors=0, a Fall palette is used.
2852/// if ncolors = 80 and colors=0, a Fruit Punch palette is used.
2853/// if ncolors = 81 and colors=0, a Fuchsia palette is used.
2854/// if ncolors = 82 and colors=0, a Grey Yellow palette is used.
2855/// if ncolors = 83 and colors=0, a Green Brown Terrain palette is used.
2856/// if ncolors = 84 and colors=0, a Green Pink palette is used.
2857/// if ncolors = 85 and colors=0, an Island palette is used.
2858/// if ncolors = 86 and colors=0, a Lake palette is used.
2859/// if ncolors = 87 and colors=0, a Light Temperature palette is used.
2860/// if ncolors = 88 and colors=0, a Light Terrain palette is used.
2861/// if ncolors = 89 and colors=0, a Mint palette is used.
2862/// if ncolors = 90 and colors=0, a Neon palette is used.
2863/// if ncolors = 91 and colors=0, a Pastel palette is used.
2864/// if ncolors = 92 and colors=0, a Pearl palette is used.
2865/// if ncolors = 93 and colors=0, a Pigeon palette is used.
2866/// if ncolors = 94 and colors=0, a Plum palette is used.
2867/// if ncolors = 95 and colors=0, a Red Blue palette is used.
2868/// if ncolors = 96 and colors=0, a Rose palette is used.
2869/// if ncolors = 97 and colors=0, a Rust palette is used.
2870/// if ncolors = 98 and colors=0, a Sandy Terrain palette is used.
2871/// if ncolors = 99 and colors=0, a Sienna palette is used.
2872/// if ncolors = 100 and colors=0, a Solar palette is used.
2873/// if ncolors = 101 and colors=0, a South West palette is used.
2874/// if ncolors = 102 and colors=0, a Starry Night palette is used.
2875/// if ncolors = 103 and colors=0, a Sunset palette is used.
2876/// if ncolors = 104 and colors=0, a Temperature Map palette is used.
2877/// if ncolors = 105 and colors=0, a Thermometer palette is used.
2878/// if ncolors = 106 and colors=0, a Valentine palette is used.
2879/// if ncolors = 107 and colors=0, a Visible Spectrum palette is used.
2880/// if ncolors = 108 and colors=0, a Water Melon palette is used.
2881/// if ncolors = 109 and colors=0, a Cool palette is used.
2882/// if ncolors = 110 and colors=0, a Copper palette is used.
2883/// if ncolors = 111 and colors=0, a Gist Earth palette is used.
2884/// if ncolors = 112 and colors=0, a Viridis palette is used.
2885/// if ncolors = 113 and colors=0, a Cividis palette is used.
2886/// ~~~
2887/// These palettes can also be accessed by names:
2888/// ~~~ {.cpp}
2889/// kDeepSea=51, kGreyScale=52, kDarkBodyRadiator=53,
2890/// kBlueYellow= 54, kRainBow=55, kInvertedDarkBodyRadiator=56,
2891/// kBird=57, kCubehelix=58, kGreenRedViolet=59,
2892/// kBlueRedYellow=60, kOcean=61, kColorPrintableOnGrey=62,
2893/// kAlpine=63, kAquamarine=64, kArmy=65,
2894/// kAtlantic=66, kAurora=67, kAvocado=68,
2895/// kBeach=69, kBlackBody=70, kBlueGreenYellow=71,
2896/// kBrownCyan=72, kCMYK=73, kCandy=74,
2897/// kCherry=75, kCoffee=76, kDarkRainBow=77,
2898/// kDarkTerrain=78, kFall=79, kFruitPunch=80,
2899/// kFuchsia=81, kGreyYellow=82, kGreenBrownTerrain=83,
2900/// kGreenPink=84, kIsland=85, kLake=86,
2901/// kLightTemperature=87, kLightTerrain=88, kMint=89,
2902/// kNeon=90, kPastel=91, kPearl=92,
2903/// kPigeon=93, kPlum=94, kRedBlue=95,
2904/// kRose=96, kRust=97, kSandyTerrain=98,
2905/// kSienna=99, kSolar=100, kSouthWest=101,
2906/// kStarryNight=102, kSunset=103, kTemperatureMap=104,
2907/// kThermometer=105, kValentine=106, kVisibleSpectrum=107,
2908/// kWaterMelon=108, kCool=109, kCopper=110,
2909/// kGistEarth=111 kViridis=112, kCividis=113
2910/// ~~~
2911/// For example:
2912/// ~~~ {.cpp}
2913/// gStyle->SetPalette(kBird);
2914/// ~~~
2915/// Set the current palette as "Bird" (number 57).
2916///
2917/// The color numbers specified in the palette can be viewed by selecting
2918/// the item "colors" in the "VIEW" menu of the canvas toolbar.
2919/// The color parameters can be changed via TColor::SetRGB.
2920///
2921/// Note that when drawing a 2D histogram `h2` with the option "COL" or
2922/// "COLZ" or with any "CONT" options using the color map, the number of colors
2923/// used is defined by the number of contours `n` specified with:
2924/// `h2->SetContour(n)`
2926void TColor::SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha)
2927{
2928 Int_t i;
2929
2930 static Int_t paletteType = 0;
2931
2932 Int_t palette[50] = {19,18,17,16,15,14,13,12,11,20,
2933 21,22,23,24,25,26,27,28,29,30, 8,
2934 31,32,33,34,35,36,37,38,39,40, 9,
2935 41,42,43,44,45,47,48,49,46,50, 2,
2936 7, 6, 5, 4, 3, 2,1};
2937
2938 // set default palette (pad type)
2939 if (ncolors <= 0) {
2940 ncolors = 50;
2941 fgPalette.Set(ncolors);
2942 for (i=0;i<ncolors;i++) fgPalette.fArray[i] = palette[i];
2943 paletteType = 1;
2944 return;
2945 }
2946
2947 // set Rainbow Color map. Kept for backward compatibility.
2948 if (ncolors == 1 && colors == nullptr) {
2949 ncolors = 50;
2950 fgPalette.Set(ncolors);
2951 for (i=0;i<ncolors-1;i++) fgPalette.fArray[i] = 51+i;
2952 fgPalette.fArray[ncolors-1] = kRed; // the last color of this palette is red
2953 paletteType = 2;
2954 return;
2955 }
2956
2957 // High quality palettes (255 levels)
2958 if (colors == nullptr && ncolors>50) {
2959
2960 if (!fgPalettesList.fN) fgPalettesList.Set(63); // Right now 63 high quality palettes
2961 Int_t Idx = (Int_t)fgPalettesList.fArray[ncolors-51]; // High quality palettes indices start at 51
2962
2963 // This high quality palette has already been created. Reuse it.
2964 if (Idx > 0) {
2965 Double_t alphas = 10*(fgPalettesList.fArray[ncolors-51]-Idx);
2966 Bool_t same_alpha = TMath::Abs(alpha-alphas) < 0.0001;
2967 if (paletteType == ncolors && same_alpha) return; // The current palette is already this one.
2968 fgPalette.Set(255); // High quality palettes have 255 entries
2969 for (i=0;i<255;i++) fgPalette.fArray[i] = Idx+i;
2970 paletteType = ncolors;
2971
2972 // restore the palette transparency if needed
2973 if (alphas>0 && !same_alpha) {
2974 TColor *ca;
2975 for (i=0;i<255;i++) {
2976 ca = gROOT->GetColor(Idx+i);
2977 ca->SetAlpha(alpha);
2978 }
2979 fgPalettesList.fArray[paletteType-51] = (Double_t)Idx+alpha/10.;
2980 }
2981 return;
2982 }
2983
2985 Double_t stops[9] = { 0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000};
2986
2987 switch (ncolors) {
2988 // Deep Sea
2989 case 51:
2990 {
2991 Double_t red[9] = { 0./255., 9./255., 13./255., 17./255., 24./255., 32./255., 27./255., 25./255., 29./255.};
2992 Double_t green[9] = { 0./255., 0./255., 0./255., 2./255., 37./255., 74./255., 113./255., 160./255., 221./255.};
2993 Double_t blue[9] = { 28./255., 42./255., 59./255., 78./255., 98./255., 129./255., 154./255., 184./255., 221./255.};
2994 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
2995 }
2996 break;
2997
2998 // Grey Scale
2999 case 52:
3000 {
3001 Double_t red[9] = { 0./255., 32./255., 64./255., 96./255., 128./255., 160./255., 192./255., 224./255., 255./255.};
3002 Double_t green[9] = { 0./255., 32./255., 64./255., 96./255., 128./255., 160./255., 192./255., 224./255., 255./255.};
3003 Double_t blue[9] = { 0./255., 32./255., 64./255., 96./255., 128./255., 160./255., 192./255., 224./255., 255./255.};
3004 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3005 }
3006 break;
3007
3008 // Dark Body Radiator
3009 case 53:
3010 {
3011 Double_t red[9] = { 0./255., 45./255., 99./255., 156./255., 212./255., 230./255., 237./255., 234./255., 242./255.};
3012 Double_t green[9] = { 0./255., 0./255., 0./255., 45./255., 101./255., 168./255., 238./255., 238./255., 243./255.};
3013 Double_t blue[9] = { 0./255., 1./255., 1./255., 3./255., 9./255., 8./255., 11./255., 95./255., 230./255.};
3014 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3015 }
3016 break;
3017
3018 // Two-color hue (dark blue through neutral gray to bright yellow)
3019 case 54:
3020 {
3021 Double_t red[9] = { 0./255., 22./255., 44./255., 68./255., 93./255., 124./255., 160./255., 192./255., 237./255.};
3022 Double_t green[9] = { 0./255., 16./255., 41./255., 67./255., 93./255., 125./255., 162./255., 194./255., 241./255.};
3023 Double_t blue[9] = { 97./255., 100./255., 99./255., 99./255., 93./255., 68./255., 44./255., 26./255., 74./255.};
3024 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3025 }
3026 break;
3027
3028 // Rain Bow
3029 case 55:
3030 {
3031 Double_t red[9] = { 0./255., 5./255., 15./255., 35./255., 102./255., 196./255., 208./255., 199./255., 110./255.};
3032 Double_t green[9] = { 0./255., 48./255., 124./255., 192./255., 206./255., 226./255., 97./255., 16./255., 0./255.};
3033 Double_t blue[9] = { 99./255., 142./255., 198./255., 201./255., 90./255., 22./255., 13./255., 8./255., 2./255.};
3034 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3035 }
3036 break;
3037
3038 // Inverted Dark Body Radiator
3039 case 56:
3040 {
3041 Double_t red[9] = { 242./255., 234./255., 237./255., 230./255., 212./255., 156./255., 99./255., 45./255., 0./255.};
3042 Double_t green[9] = { 243./255., 238./255., 238./255., 168./255., 101./255., 45./255., 0./255., 0./255., 0./255.};
3043 Double_t blue[9] = { 230./255., 95./255., 11./255., 8./255., 9./255., 3./255., 1./255., 1./255., 0./255.};
3044 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3045 }
3046 break;
3047
3048 // Bird
3049 case 57:
3050 {
3051 Double_t red[9] = { 0.2082, 0.0592, 0.0780, 0.0232, 0.1802, 0.5301, 0.8186, 0.9956, 0.9764};
3052 Double_t green[9] = { 0.1664, 0.3599, 0.5041, 0.6419, 0.7178, 0.7492, 0.7328, 0.7862, 0.9832};
3053 Double_t blue[9] = { 0.5293, 0.8684, 0.8385, 0.7914, 0.6425, 0.4662, 0.3499, 0.1968, 0.0539};
3054 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3055 }
3056 break;
3057
3058 // Cubehelix
3059 case 58:
3060 {
3061 Double_t red[9] = { 0.0000, 0.0956, 0.0098, 0.2124, 0.6905, 0.9242, 0.7914, 0.7596, 1.0000};
3062 Double_t green[9] = { 0.0000, 0.1147, 0.3616, 0.5041, 0.4577, 0.4691, 0.6905, 0.9237, 1.0000};
3063 Double_t blue[9] = { 0.0000, 0.2669, 0.3121, 0.1318, 0.2236, 0.6741, 0.9882, 0.9593, 1.0000};
3064 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3065 }
3066 break;
3067
3068 // Green Red Violet
3069 case 59:
3070 {
3071 Double_t red[9] = {13./255., 23./255., 25./255., 63./255., 76./255., 104./255., 137./255., 161./255., 206./255.};
3072 Double_t green[9] = {95./255., 67./255., 37./255., 21./255., 0./255., 12./255., 35./255., 52./255., 79./255.};
3073 Double_t blue[9] = { 4./255., 3./255., 2./255., 6./255., 11./255., 22./255., 49./255., 98./255., 208./255.};
3074 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3075 }
3076 break;
3077
3078 // Blue Red Yellow
3079 case 60:
3080 {
3081 Double_t red[9] = {0./255., 61./255., 89./255., 122./255., 143./255., 160./255., 185./255., 204./255., 231./255.};
3082 Double_t green[9] = {0./255., 0./255., 0./255., 0./255., 14./255., 37./255., 72./255., 132./255., 235./255.};
3083 Double_t blue[9] = {0./255., 140./255., 224./255., 144./255., 4./255., 5./255., 6./255., 9./255., 13./255.};
3084 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3085 }
3086 break;
3087
3088 // Ocean
3089 case 61:
3090 {
3091 Double_t red[9] = { 14./255., 7./255., 2./255., 0./255., 5./255., 11./255., 55./255., 131./255., 229./255.};
3092 Double_t green[9] = {105./255., 56./255., 26./255., 1./255., 42./255., 74./255., 131./255., 171./255., 229./255.};
3093 Double_t blue[9] = { 2./255., 21./255., 35./255., 60./255., 92./255., 113./255., 160./255., 185./255., 229./255.};
3094 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3095 }
3096 break;
3097
3098 // Color Printable On Grey
3099 case 62:
3100 {
3101 Double_t red[9] = { 0./255., 0./255., 0./255., 70./255., 148./255., 231./255., 235./255., 237./255., 244./255.};
3102 Double_t green[9] = { 0./255., 0./255., 0./255., 0./255., 0./255., 69./255., 67./255., 216./255., 244./255.};
3103 Double_t blue[9] = { 0./255., 102./255., 228./255., 231./255., 177./255., 124./255., 137./255., 20./255., 244./255.};
3104 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3105 }
3106 break;
3107
3108 // Alpine
3109 case 63:
3110 {
3111 Double_t red[9] = { 50./255., 56./255., 63./255., 68./255., 93./255., 121./255., 165./255., 192./255., 241./255.};
3112 Double_t green[9] = { 66./255., 81./255., 91./255., 96./255., 111./255., 128./255., 155./255., 189./255., 241./255.};
3113 Double_t blue[9] = { 97./255., 91./255., 75./255., 65./255., 77./255., 103./255., 143./255., 167./255., 217./255.};
3114 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3115 }
3116 break;
3117
3118 // Aquamarine
3119 case 64:
3120 {
3121 Double_t red[9] = { 145./255., 166./255., 167./255., 156./255., 131./255., 114./255., 101./255., 112./255., 132./255.};
3122 Double_t green[9] = { 158./255., 178./255., 179./255., 181./255., 163./255., 154./255., 144./255., 152./255., 159./255.};
3123 Double_t blue[9] = { 190./255., 199./255., 201./255., 192./255., 176./255., 169./255., 160./255., 166./255., 190./255.};
3124 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3125 }
3126 break;
3127
3128 // Army
3129 case 65:
3130 {
3131 Double_t red[9] = { 93./255., 91./255., 99./255., 108./255., 130./255., 125./255., 132./255., 155./255., 174./255.};
3132 Double_t green[9] = { 126./255., 124./255., 128./255., 129./255., 131./255., 121./255., 119./255., 153./255., 173./255.};
3133 Double_t blue[9] = { 103./255., 94./255., 87./255., 85./255., 80./255., 85./255., 107./255., 120./255., 146./255.};
3134 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3135 }
3136 break;
3137
3138 // Atlantic
3139 case 66:
3140 {
3141 Double_t red[9] = { 24./255., 40./255., 69./255., 90./255., 104./255., 114./255., 120./255., 132./255., 103./255.};
3142 Double_t green[9] = { 29./255., 52./255., 94./255., 127./255., 150./255., 162./255., 159./255., 151./255., 101./255.};
3143 Double_t blue[9] = { 29./255., 52./255., 96./255., 132./255., 162./255., 181./255., 184./255., 186./255., 131./255.};
3144 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3145 }
3146 break;
3147
3148 // Aurora
3149 case 67:
3150 {
3151 Double_t red[9] = { 46./255., 38./255., 61./255., 92./255., 113./255., 121./255., 132./255., 150./255., 191./255.};
3152 Double_t green[9] = { 46./255., 36./255., 40./255., 69./255., 110./255., 135./255., 131./255., 92./255., 34./255.};
3153 Double_t blue[9] = { 46./255., 80./255., 74./255., 70./255., 81./255., 105./255., 165./255., 211./255., 225./255.};
3154 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3155 }
3156 break;
3157
3158 // Avocado
3159 case 68:
3160 {
3161 Double_t red[9] = { 0./255., 4./255., 12./255., 30./255., 52./255., 101./255., 142./255., 190./255., 237./255.};
3162 Double_t green[9] = { 0./255., 40./255., 86./255., 121./255., 140./255., 172./255., 187./255., 213./255., 240./255.};
3163 Double_t blue[9] = { 0./255., 9./255., 14./255., 18./255., 21./255., 23./255., 27./255., 35./255., 101./255.};
3164 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3165 }
3166 break;
3167
3168 // Beach
3169 case 69:
3170 {
3171 Double_t red[9] = { 198./255., 206./255., 206./255., 211./255., 198./255., 181./255., 161./255., 171./255., 244./255.};
3172 Double_t green[9] = { 103./255., 133./255., 150./255., 172./255., 178./255., 174./255., 163./255., 175./255., 244./255.};
3173 Double_t blue[9] = { 49./255., 54./255., 55./255., 66./255., 91./255., 130./255., 184./255., 224./255., 244./255.};
3174 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3175 }
3176 break;
3177
3178 // Black Body
3179 case 70:
3180 {
3181 Double_t red[9] = { 243./255., 243./255., 240./255., 240./255., 241./255., 239./255., 186./255., 151./255., 129./255.};
3182 Double_t green[9] = { 0./255., 46./255., 99./255., 149./255., 194./255., 220./255., 183./255., 166./255., 147./255.};
3183 Double_t blue[9] = { 6./255., 8./255., 36./255., 91./255., 169./255., 235./255., 246./255., 240./255., 233./255.};
3184 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3185 }
3186 break;
3187
3188 // Blue Green Yellow
3189 case 71:
3190 {
3191 Double_t red[9] = { 22./255., 19./255., 19./255., 25./255., 35./255., 53./255., 88./255., 139./255., 210./255.};
3192 Double_t green[9] = { 0./255., 32./255., 69./255., 108./255., 135./255., 159./255., 183./255., 198./255., 215./255.};
3193 Double_t blue[9] = { 77./255., 96./255., 110./255., 116./255., 110./255., 100./255., 90./255., 78./255., 70./255.};
3194 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3195 }
3196 break;
3197
3198 // Brown Cyan
3199 case 72:
3200 {
3201 Double_t red[9] = { 68./255., 116./255., 165./255., 182./255., 189./255., 180./255., 145./255., 111./255., 71./255.};
3202 Double_t green[9] = { 37./255., 82./255., 135./255., 178./255., 204./255., 225./255., 221./255., 202./255., 147./255.};
3203 Double_t blue[9] = { 16./255., 55./255., 105./255., 147./255., 196./255., 226./255., 232./255., 224./255., 178./255.};
3204 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3205 }
3206 break;
3207
3208 // CMYK
3209 case 73:
3210 {
3211 Double_t red[9] = { 61./255., 99./255., 136./255., 181./255., 213./255., 225./255., 198./255., 136./255., 24./255.};
3212 Double_t green[9] = { 149./255., 140./255., 96./255., 83./255., 132./255., 178./255., 190./255., 135./255., 22./255.};
3213 Double_t blue[9] = { 214./255., 203./255., 168./255., 135./255., 110./255., 100./255., 111./255., 113./255., 22./255.};
3214 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3215 }
3216 break;
3217
3218 // Candy
3219 case 74:
3220 {
3221 Double_t red[9] = { 76./255., 120./255., 156./255., 183./255., 197./255., 180./255., 162./255., 154./255., 140./255.};
3222 Double_t green[9] = { 34./255., 35./255., 42./255., 69./255., 102./255., 137./255., 164./255., 188./255., 197./255.};
3223 Double_t blue[9] = { 64./255., 69./255., 78./255., 105./255., 142./255., 177./255., 205./255., 217./255., 198./255.};
3224 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3225 }
3226 break;
3227
3228 // Cherry
3229 case 75:
3230 {
3231 Double_t red[9] = { 37./255., 102./255., 157./255., 188./255., 196./255., 214./255., 223./255., 235./255., 251./255.};
3232 Double_t green[9] = { 37./255., 29./255., 25./255., 37./255., 67./255., 91./255., 132./255., 185./255., 251./255.};
3233 Double_t blue[9] = { 37./255., 32./255., 33./255., 45./255., 66./255., 98./255., 137./255., 187./255., 251./255.};
3234 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3235 }
3236 break;
3237
3238 // Coffee
3239 case 76:
3240 {
3241 Double_t red[9] = { 79./255., 100./255., 119./255., 137./255., 153./255., 172./255., 192./255., 205./255., 250./255.};
3242 Double_t green[9] = { 63./255., 79./255., 93./255., 103./255., 115./255., 135./255., 167./255., 196./255., 250./255.};
3243 Double_t blue[9] = { 51./255., 59./255., 66./255., 61./255., 62./255., 70./255., 110./255., 160./255., 250./255.};
3244 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3245 }
3246 break;
3247
3248 // Dark Rain Bow
3249 case 77:
3250 {
3251 Double_t red[9] = { 43./255., 44./255., 50./255., 66./255., 125./255., 172./255., 178./255., 155./255., 157./255.};
3252 Double_t green[9] = { 63./255., 63./255., 85./255., 101./255., 138./255., 163./255., 122./255., 51./255., 39./255.};
3253 Double_t blue[9] = { 121./255., 101./255., 58./255., 44./255., 47./255., 55./255., 57./255., 44./255., 43./255.};
3254 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3255 }
3256 break;
3257
3258 // Dark Terrain
3259 case 78:
3260 {
3261 Double_t red[9] = { 0./255., 41./255., 62./255., 79./255., 90./255., 87./255., 99./255., 140./255., 228./255.};
3262 Double_t green[9] = { 0./255., 57./255., 81./255., 93./255., 85./255., 70./255., 71./255., 125./255., 228./255.};
3263 Double_t blue[9] = { 95./255., 91./255., 91./255., 82./255., 60./255., 43./255., 44./255., 112./255., 228./255.};
3264 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3265 }
3266 break;
3267
3268 // Fall
3269 case 79:
3270 {
3271 Double_t red[9] = { 49./255., 59./255., 72./255., 88./255., 114./255., 141./255., 176./255., 205./255., 222./255.};
3272 Double_t green[9] = { 78./255., 72./255., 66./255., 57./255., 59./255., 75./255., 106./255., 142./255., 173./255.};
3273 Double_t blue[9] = { 78./255., 55./255., 46./255., 40./255., 39./255., 39./255., 40./255., 41./255., 47./255.};
3274 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3275 }
3276 break;
3277
3278 // Fruit Punch
3279 case 80:
3280 {
3281 Double_t red[9] = { 243./255., 222./255., 201./255., 185./255., 165./255., 158./255., 166./255., 187./255., 219./255.};
3282 Double_t green[9] = { 94./255., 108./255., 132./255., 135./255., 125./255., 96./255., 68./255., 51./255., 61./255.};
3283 Double_t blue[9] = { 7./255., 9./255., 12./255., 19./255., 45./255., 89./255., 118./255., 146./255., 118./255.};
3284 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3285 }
3286 break;
3287
3288 // Fuchsia
3289 case 81:
3290 {
3291 Double_t red[9] = { 19./255., 44./255., 74./255., 105./255., 137./255., 166./255., 194./255., 206./255., 220./255.};
3292 Double_t green[9] = { 19./255., 28./255., 40./255., 55./255., 82./255., 110./255., 159./255., 181./255., 220./255.};
3293 Double_t blue[9] = { 19./255., 42./255., 68./255., 96./255., 129./255., 157./255., 188./255., 203./255., 220./255.};
3294 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3295 }
3296 break;
3297
3298 // Grey Yellow
3299 case 82:
3300 {
3301 Double_t red[9] = { 33./255., 44./255., 70./255., 99./255., 140./255., 165./255., 199./255., 211./255., 216./255.};
3302 Double_t green[9] = { 38./255., 50./255., 76./255., 105./255., 140./255., 165./255., 191./255., 189./255., 167./255.};
3303 Double_t blue[9] = { 55./255., 67./255., 97./255., 124./255., 140./255., 166./255., 163./255., 129./255., 52./255.};
3304 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3305 }
3306 break;
3307
3308 // Green Brown Terrain
3309 case 83:
3310 {
3311 Double_t red[9] = { 0./255., 33./255., 73./255., 124./255., 136./255., 152./255., 159./255., 171./255., 223./255.};
3312 Double_t green[9] = { 0./255., 43./255., 92./255., 124./255., 134./255., 126./255., 121./255., 144./255., 223./255.};
3313 Double_t blue[9] = { 0./255., 43./255., 68./255., 76./255., 73./255., 64./255., 72./255., 114./255., 223./255.};
3314 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3315 }
3316 break;
3317
3318 // Green Pink
3319 case 84:
3320 {
3321 Double_t red[9] = { 5./255., 18./255., 45./255., 124./255., 193./255., 223./255., 205./255., 128./255., 49./255.};
3322 Double_t green[9] = { 48./255., 134./255., 207./255., 230./255., 193./255., 113./255., 28./255., 0./255., 7./255.};
3323 Double_t blue[9] = { 6./255., 15./255., 41./255., 121./255., 193./255., 226./255., 208./255., 130./255., 49./255.};
3324 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3325 }
3326 break;
3327
3328 // Island
3329 case 85:
3330 {
3331 Double_t red[9] = { 180./255., 106./255., 104./255., 135./255., 164./255., 188./255., 189./255., 165./255., 144./255.};
3332 Double_t green[9] = { 72./255., 126./255., 154./255., 184./255., 198./255., 207./255., 205./255., 190./255., 179./255.};
3333 Double_t blue[9] = { 41./255., 120./255., 158./255., 188./255., 194./255., 181./255., 145./255., 100./255., 62./255.};
3334 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3335 }
3336 break;
3337
3338 // Lake
3339 case 86:
3340 {
3341 Double_t red[9] = { 57./255., 72./255., 94./255., 117./255., 136./255., 154./255., 174./255., 192./255., 215./255.};
3342 Double_t green[9] = { 0./255., 33./255., 68./255., 109./255., 140./255., 171./255., 192./255., 196./255., 209./255.};
3343 Double_t blue[9] = { 116./255., 137./255., 173./255., 201./255., 200./255., 201./255., 203./255., 190./255., 187./255.};
3344 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3345 }
3346 break;
3347
3348 // Light Temperature
3349 case 87:
3350 {
3351 Double_t red[9] = { 31./255., 71./255., 123./255., 160./255., 210./255., 222./255., 214./255., 199./255., 183./255.};
3352 Double_t green[9] = { 40./255., 117./255., 171./255., 211./255., 231./255., 220./255., 190./255., 132./255., 65./255.};
3353 Double_t blue[9] = { 234./255., 214./255., 228./255., 222./255., 210./255., 160./255., 105./255., 60./255., 34./255.};
3354 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3355 }
3356 break;
3357
3358 // Light Terrain
3359 case 88:
3360 {
3361 Double_t red[9] = { 123./255., 108./255., 109./255., 126./255., 154./255., 172./255., 188./255., 196./255., 218./255.};
3362 Double_t green[9] = { 184./255., 138./255., 130./255., 133./255., 154./255., 175./255., 188./255., 196./255., 218./255.};
3363 Double_t blue[9] = { 208./255., 130./255., 109./255., 99./255., 110./255., 122./255., 150./255., 171./255., 218./255.};
3364 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3365 }
3366 break;
3367
3368 // Mint
3369 case 89:
3370 {
3371 Double_t red[9] = { 105./255., 106./255., 122./255., 143./255., 159./255., 172./255., 176./255., 181./255., 207./255.};
3372 Double_t green[9] = { 252./255., 197./255., 194./255., 187./255., 174./255., 162./255., 153./255., 136./255., 125./255.};
3373 Double_t blue[9] = { 146./255., 133./255., 144./255., 155./255., 163./255., 167./255., 166./255., 162./255., 174./255.};
3374 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3375 }
3376 break;
3377
3378 // Neon
3379 case 90:
3380 {
3381 Double_t red[9] = { 171./255., 141./255., 145./255., 152./255., 154./255., 159./255., 163./255., 158./255., 177./255.};
3382 Double_t green[9] = { 236./255., 143./255., 100./255., 63./255., 53./255., 55./255., 44./255., 31./255., 6./255.};
3383 Double_t blue[9] = { 59./255., 48./255., 46./255., 44./255., 42./255., 54./255., 82./255., 112./255., 179./255.};
3384 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3385 }
3386 break;
3387
3388 // Pastel
3389 case 91:
3390 {
3391 Double_t red[9] = { 180./255., 190./255., 209./255., 223./255., 204./255., 228./255., 205./255., 152./255., 91./255.};
3392 Double_t green[9] = { 93./255., 125./255., 147./255., 172./255., 181./255., 224./255., 233./255., 198./255., 158./255.};
3393 Double_t blue[9] = { 236./255., 218./255., 160./255., 133./255., 114./255., 132./255., 162./255., 220./255., 218./255.};
3394 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3395 }
3396 break;
3397
3398 // Pearl
3399 case 92:
3400 {
3401 Double_t red[9] = { 225./255., 183./255., 162./255., 135./255., 115./255., 111./255., 119./255., 145./255., 211./255.};
3402 Double_t green[9] = { 205./255., 177./255., 166./255., 135./255., 124./255., 117./255., 117./255., 132./255., 172./255.};
3403 Double_t blue[9] = { 186./255., 165./255., 155./255., 135./255., 126./255., 130./255., 150./255., 178./255., 226./255.};
3404 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3405 }
3406 break;
3407
3408 // Pigeon
3409 case 93:
3410 {
3411 Double_t red[9] = { 39./255., 43./255., 59./255., 63./255., 80./255., 116./255., 153./255., 177./255., 223./255.};
3412 Double_t green[9] = { 39./255., 43./255., 59./255., 74./255., 91./255., 114./255., 139./255., 165./255., 223./255.};
3413 Double_t blue[9] = { 39./255., 50./255., 59./255., 70./255., 85./255., 115./255., 151./255., 176./255., 223./255.};
3414 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3415 }
3416 break;
3417
3418 // Plum
3419 case 94:
3420 {
3421 Double_t red[9] = { 0./255., 38./255., 60./255., 76./255., 84./255., 89./255., 101./255., 128./255., 204./255.};
3422 Double_t green[9] = { 0./255., 10./255., 15./255., 23./255., 35./255., 57./255., 83./255., 123./255., 199./255.};
3423 Double_t blue[9] = { 0./255., 11./255., 22./255., 40./255., 63./255., 86./255., 97./255., 94./255., 85./255.};
3424 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3425 }
3426 break;
3427
3428 // Red Blue
3429 case 95:
3430 {
3431 Double_t red[9] = { 94./255., 112./255., 141./255., 165./255., 167./255., 140./255., 91./255., 49./255., 27./255.};
3432 Double_t green[9] = { 27./255., 46./255., 88./255., 135./255., 166./255., 161./255., 135./255., 97./255., 58./255.};
3433 Double_t blue[9] = { 42./255., 52./255., 81./255., 106./255., 139./255., 158./255., 155./255., 137./255., 116./255.};
3434 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3435 }
3436 break;
3437
3438 // Rose
3439 case 96:
3440 {
3441 Double_t red[9] = { 30./255., 49./255., 79./255., 117./255., 135./255., 151./255., 146./255., 138./255., 147./255.};
3442 Double_t green[9] = { 63./255., 60./255., 72./255., 90./255., 94./255., 94./255., 68./255., 46./255., 16./255.};
3443 Double_t blue[9] = { 18./255., 28./255., 41./255., 56./255., 62./255., 63./255., 50./255., 36./255., 21./255.};
3444 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3445 }
3446 break;
3447
3448 // Rust
3449 case 97:
3450 {
3451 Double_t red[9] = { 0./255., 30./255., 63./255., 101./255., 143./255., 152./255., 169./255., 187./255., 230./255.};
3452 Double_t green[9] = { 0./255., 14./255., 28./255., 42./255., 58./255., 61./255., 67./255., 74./255., 91./255.};
3453 Double_t blue[9] = { 39./255., 26./255., 21./255., 18./255., 15./255., 14./255., 14./255., 13./255., 13./255.};
3454 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3455 }
3456 break;
3457
3458 // Sandy Terrain
3459 case 98:
3460 {
3461 Double_t red[9] = { 149./255., 140./255., 164./255., 179./255., 182./255., 181./255., 131./255., 87./255., 61./255.};
3462 Double_t green[9] = { 62./255., 70./255., 107./255., 136./255., 144./255., 138./255., 117./255., 87./255., 74./255.};
3463 Double_t blue[9] = { 40./255., 38./255., 45./255., 49./255., 49./255., 49./255., 38./255., 32./255., 34./255.};
3464 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3465 }
3466 break;
3467
3468 // Sienna
3469 case 99:
3470 {
3471 Double_t red[9] = { 99./255., 112./255., 148./255., 165./255., 179./255., 182./255., 183./255., 183./255., 208./255.};
3472 Double_t green[9] = { 39./255., 40./255., 57./255., 79./255., 104./255., 127./255., 148./255., 161./255., 198./255.};
3473 Double_t blue[9] = { 15./255., 16./255., 18./255., 33./255., 51./255., 79./255., 103./255., 129./255., 177./255.};
3474 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3475 }
3476 break;
3477
3478 // Solar
3479 case 100:
3480 {
3481 Double_t red[9] = { 99./255., 116./255., 154./255., 174./255., 200./255., 196./255., 201./255., 201./255., 230./255.};
3482 Double_t green[9] = { 0./255., 0./255., 8./255., 32./255., 58./255., 83./255., 119./255., 136./255., 173./255.};
3483 Double_t blue[9] = { 5./255., 6./255., 7./255., 9./255., 9./255., 14./255., 17./255., 19./255., 24./255.};
3484 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3485 }
3486 break;
3487
3488 // South West
3489 case 101:
3490 {
3491 Double_t red[9] = { 82./255., 106./255., 126./255., 141./255., 155./255., 163./255., 142./255., 107./255., 66./255.};
3492 Double_t green[9] = { 62./255., 44./255., 69./255., 107./255., 135./255., 152./255., 149./255., 132./255., 119./255.};
3493 Double_t blue[9] = { 39./255., 25./255., 31./255., 60./255., 73./255., 68./255., 49./255., 72./255., 188./255.};
3494 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3495 }
3496 break;
3497
3498 // Starry Night
3499 case 102:
3500 {
3501 Double_t red[9] = { 18./255., 29./255., 44./255., 72./255., 116./255., 158./255., 184./255., 208./255., 221./255.};
3502 Double_t green[9] = { 27./255., 46./255., 71./255., 105./255., 146./255., 177./255., 189./255., 190./255., 183./255.};
3503 Double_t blue[9] = { 39./255., 55./255., 80./255., 108./255., 130./255., 133./255., 124./255., 100./255., 76./255.};
3504 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3505 }
3506 break;
3507
3508 // Sunset
3509 case 103:
3510 {
3511 Double_t red[9] = { 0./255., 48./255., 119./255., 173./255., 212./255., 224./255., 228./255., 228./255., 245./255.};
3512 Double_t green[9] = { 0./255., 13./255., 30./255., 47./255., 79./255., 127./255., 167./255., 205./255., 245./255.};
3513 Double_t blue[9] = { 0./255., 68./255., 75./255., 43./255., 16./255., 22./255., 55./255., 128./255., 245./255.};
3514 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3515 }
3516 break;
3517
3518 // Temperature Map
3519 case 104:
3520 {
3521 Double_t red[9] = { 34./255., 70./255., 129./255., 187./255., 225./255., 226./255., 216./255., 193./255., 179./255.};
3522 Double_t green[9] = { 48./255., 91./255., 147./255., 194./255., 226./255., 229./255., 196./255., 110./255., 12./255.};
3523 Double_t blue[9] = { 234./255., 212./255., 216./255., 224./255., 206./255., 110./255., 53./255., 40./255., 29./255.};
3524 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3525 }
3526 break;
3527
3528 // Thermometer
3529 case 105:
3530 {
3531 Double_t red[9] = { 30./255., 55./255., 103./255., 147./255., 174./255., 203./255., 188./255., 151./255., 105./255.};
3532 Double_t green[9] = { 0./255., 65./255., 138./255., 182./255., 187./255., 175./255., 121./255., 53./255., 9./255.};
3533 Double_t blue[9] = { 191./255., 202./255., 212./255., 208./255., 171./255., 140./255., 97./255., 57./255., 30./255.};
3534 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3535 }
3536 break;
3537
3538 // Valentine
3539 case 106:
3540 {
3541 Double_t red[9] = { 112./255., 97./255., 113./255., 125./255., 138./255., 159./255., 178./255., 188./255., 225./255.};
3542 Double_t green[9] = { 16./255., 17./255., 24./255., 37./255., 56./255., 81./255., 110./255., 136./255., 189./255.};
3543 Double_t blue[9] = { 38./255., 35./255., 46./255., 59./255., 78./255., 103./255., 130./255., 152./255., 201./255.};
3544 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3545 }
3546 break;
3547
3548 // Visible Spectrum
3549 case 107:
3550 {
3551 Double_t red[9] = { 18./255., 72./255., 5./255., 23./255., 29./255., 201./255., 200./255., 98./255., 29./255.};
3552 Double_t green[9] = { 0./255., 0./255., 43./255., 167./255., 211./255., 117./255., 0./255., 0./255., 0./255.};
3553 Double_t blue[9] = { 51./255., 203./255., 177./255., 26./255., 10./255., 9./255., 8./255., 3./255., 0./255.};
3554 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3555 }
3556 break;
3557
3558 // Water Melon
3559 case 108:
3560 {
3561 Double_t red[9] = { 19./255., 42./255., 64./255., 88./255., 118./255., 147./255., 175./255., 187./255., 205./255.};
3562 Double_t green[9] = { 19./255., 55./255., 89./255., 125./255., 154./255., 169./255., 161./255., 129./255., 70./255.};
3563 Double_t blue[9] = { 19./255., 32./255., 47./255., 70./255., 100./255., 128./255., 145./255., 130./255., 75./255.};
3564 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3565 }
3566 break;
3567
3568 // Cool
3569 case 109:
3570 {
3571 Double_t red[9] = { 33./255., 31./255., 42./255., 68./255., 86./255., 111./255., 141./255., 172./255., 227./255.};
3572 Double_t green[9] = { 255./255., 175./255., 145./255., 106./255., 88./255., 55./255., 15./255., 0./255., 0./255.};
3573 Double_t blue[9] = { 255./255., 205./255., 202./255., 203./255., 208./255., 205./255., 203./255., 206./255., 231./255.};
3574 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3575 }
3576 break;
3577
3578 // Copper
3579 case 110:
3580 {
3581 Double_t red[9] = { 0./255., 25./255., 50./255., 79./255., 110./255., 145./255., 181./255., 201./255., 254./255.};
3582 Double_t green[9] = { 0./255., 16./255., 30./255., 46./255., 63./255., 82./255., 101./255., 124./255., 179./255.};
3583 Double_t blue[9] = { 0./255., 12./255., 21./255., 29./255., 39./255., 49./255., 61./255., 74./255., 103./255.};
3584 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3585 }
3586 break;
3587
3588 // Gist Earth
3589 case 111:
3590 {
3591 Double_t red[9] = { 0./255., 13./255., 30./255., 44./255., 72./255., 120./255., 156./255., 200./255., 247./255.};
3592 Double_t green[9] = { 0./255., 36./255., 84./255., 117./255., 141./255., 153./255., 151./255., 158./255., 247./255.};
3593 Double_t blue[9] = { 0./255., 94./255., 100./255., 82./255., 56./255., 66./255., 76./255., 131./255., 247./255.};
3594 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3595 }
3596 break;
3597
3598 // Viridis
3599 case 112:
3600 {
3601 Double_t red[9] = { 26./255., 51./255., 43./255., 33./255., 28./255., 35./255., 74./255., 144./255., 246./255.};
3602 Double_t green[9] = { 9./255., 24./255., 55./255., 87./255., 118./255., 150./255., 180./255., 200./255., 222./255.};
3603 Double_t blue[9] = { 30./255., 96./255., 112./255., 114./255., 112./255., 101./255., 72./255., 35./255., 0./255.};
3604 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3605 }
3606 break;
3607
3608 // Cividis
3609 case 113:
3610 {
3611 Double_t red[9] = { 0./255., 5./255., 65./255., 97./255., 124./255., 156./255., 189./255., 224./255., 255./255.};
3612 Double_t green[9] = { 32./255., 54./255., 77./255., 100./255., 123./255., 148./255., 175./255., 203./255., 234./255.};
3613 Double_t blue[9] = { 77./255., 110./255., 107./255., 111./255., 120./255., 119./255., 111./255., 94./255., 70./255.};
3614 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3615 }
3616 break;
3617
3618 default:
3619 ::Error("SetPalette", "Unknown palette number %d", ncolors);
3620 return;
3621 }
3622 paletteType = ncolors;
3623 if (Idx>0) fgPalettesList.fArray[paletteType-51] = (Double_t)Idx;
3624 else fgPalettesList.fArray[paletteType-51] = 0.;
3625 if (alpha > 0.) fgPalettesList.fArray[paletteType-51] += alpha/10.0f;
3626 return;
3627 }
3628
3629 // set user defined palette
3630 if (colors) {
3631 fgPalette.Set(ncolors);
3632 for (i=0;i<ncolors;i++) fgPalette.fArray[i] = colors[i];
3633 } else {
3634 fgPalette.Set(TMath::Min(50,ncolors));
3635 for (i=0;i<TMath::Min(50,ncolors);i++) fgPalette.fArray[i] = palette[i];
3636 }
3637 paletteType = 3;
3638}
3639
3640
3641////////////////////////////////////////////////////////////////////////////////
3642/// Invert the current color palette.
3643/// The top of the palette becomes the bottom and vice versa.
3646{
3647 std::reverse(fgPalette.fArray, fgPalette.fArray + fgPalette.GetSize());
3648}
3649
3650////////////////////////////////////////////////////////////////////////////////
3651/// The `color` string argument argument will be evaluated
3652/// to get the actual ROOT color number, like `kRed`.
3653/// Here is how the string is parsed:
3654///
3655/// 1. Match against single-character color codes following the matplotlib convention.
3656/// For example, to get red color (equivalent to `kRed`):
3657/// ~~~ {.cxx}
3658/// hist.SetLineColor("r")
3659/// ~~~
3660/// 2. Check if the string matches an en existing TColor name (see TColor::GetColorByName()).
3661/// For example:
3662/// ~~~ {.cxx}
3663/// hist.SetLineColor("kRed+1")
3664/// ~~~
3665///
3666/// In case no corresponding color is found, a `std::invalid_argument` exception is thrown.
3667TColorNumber::TColorNumber(std::string const &color)
3668{
3669 using Map = std::unordered_map<std::string, Int_t>;
3670 // Color dictionary to define matplotlib conventions
3671 static Map colorMap{{"r", kRed}, {"b", kBlue}, {"g", kGreen}, {"y", kYellow},
3672 {"w", kWhite}, {"k", kBlack}, {"m", kMagenta}, {"c", kCyan}};
3673 auto found = colorMap.find(color);
3674 if (found != colorMap.end()) {
3675 fNumber = found->second;
3676 return;
3677 }
3678
3679 fNumber = TColor::GetColorByName(color.c_str());
3680 if (fNumber == -1) {
3681 std::stringstream msg;
3682 msg << "\"" << color << "\" is not a valid color name";
3683 throw std::invalid_argument(msg.str());
3684 }
3685}
3686
3687////////////////////////////////////////////////////////////////////////////////
3688/// Instantiate a color from a tuple of RGB values between 0.0 and 1.0.
3689TColorNumber::TColorNumber(std::array<Float_t, 3> rgb) : fNumber{TColor::GetColor(rgb[0], rgb[1], rgb[2])} {}
const Mask_t kDoRed
Definition GuiTypes.h:319
const Mask_t kDoGreen
Definition GuiTypes.h:320
const Mask_t kDoBlue
Definition GuiTypes.h:321
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define s0(x)
Definition RSha256.hxx:90
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
bool Bool_t
Definition RtypesCore.h:63
unsigned short UShort_t
Definition RtypesCore.h:40
int Int_t
Definition RtypesCore.h:45
unsigned char UChar_t
Definition RtypesCore.h:38
unsigned long ULong_t
Definition RtypesCore.h:55
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:374
@ kP8Cyan
Definition Rtypes.h:70
@ kTeal
Definition Rtypes.h:67
@ kP8Red
Definition Rtypes.h:70
@ kGray
Definition Rtypes.h:65
@ kAsh
Definition Rtypes.h:68
@ kP6Red
Definition Rtypes.h:69
@ kP8Pink
Definition Rtypes.h:70
@ kP10Violet
Definition Rtypes.h:71
@ kP10Orange
Definition Rtypes.h:71
@ kBrown
Definition Rtypes.h:68
@ kP6Grape
Definition Rtypes.h:69
@ kPink
Definition Rtypes.h:67
@ kP8Azure
Definition Rtypes.h:70
@ kRed
Definition Rtypes.h:66
@ kGrape
Definition Rtypes.h:68
@ kP6Gray
Definition Rtypes.h:69
@ kOrange
Definition Rtypes.h:67
@ kP8Gray
Definition Rtypes.h:70
@ kP10Red
Definition Rtypes.h:71
@ kBlack
Definition Rtypes.h:65
@ kP10Brown
Definition Rtypes.h:71
@ kP10Cyan
Definition Rtypes.h:71
@ kGreen
Definition Rtypes.h:66
@ kMagenta
Definition Rtypes.h:66
@ kP10Ash
Definition Rtypes.h:71
@ kWhite
Definition Rtypes.h:65
@ kP10Green
Definition Rtypes.h:71
@ kP6Yellow
Definition Rtypes.h:69
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kP10Gray
Definition Rtypes.h:71
@ kAzure
Definition Rtypes.h:67
@ kYellow
Definition Rtypes.h:66
@ kP8Orange
Definition Rtypes.h:70
@ kP8Green
Definition Rtypes.h:70
@ kP8Blue
Definition Rtypes.h:70
@ kViolet
Definition Rtypes.h:67
@ kP6Violet
Definition Rtypes.h:69
@ kP10Yellow
Definition Rtypes.h:71
@ kSpring
Definition Rtypes.h:67
@ kP10Blue
Definition Rtypes.h:71
@ kP6Blue
Definition Rtypes.h:69
R__EXTERN TApplication * gApplication
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static Int_t gDefinedColors
Number of defined colors.
Definition TColor.cxx:50
#define fgGrayscaleMode
Definition TColor.cxx:53
static Float_t gColorThreshold
Color threshold used by GetColor.
Definition TColor.cxx:49
static Int_t gLastDefinedColors
Previous number of defined colors.
Definition TColor.cxx:51
#define fgPalette
Definition TColor.cxx:54
#define fgPalettesList
Definition TColor.cxx:55
static Int_t gHighestColorIndex
Highest color index defined.
Definition TColor.cxx:48
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void pixel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint angle
char name[80]
Definition TGX11.cxx:110
float * q
#define gROOT
Definition TROOT.h:406
#define gVirtualX
Definition TVirtualX.h:337
Color * colors
Definition X3DBuffer.c:21
#define snprintf
Definition civetweb.c:1540
const_iterator end() const
void InitializeGraphics(Bool_t only_web=kFALSE)
Initialize the graphics environment.
static void NeedGraphicsLibs()
Static method.
Array of doubles (64 bits per element).
Definition TArrayD.h:27
Array of integers (32 bits per element).
Definition TArrayI.h:27
Int_t fNumber
Color number identifier.
Definition TColor.h:148
TColorNumber(Int_t color)
Definition TColor.h:142
The color creation and management class.
Definition TColor.h:22
void Print(Option_t *option="") const override
Dump this color with its attributes.
Definition TColor.cxx:1711
static Int_t GetFirstFreeColorIndex()
Static function: Returns the first free color greater in the list of colors.
Definition TColor.cxx:2385
Float_t fSaturation
Saturation.
Definition TColor.h:31
static void SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha=1.)
Static function.
Definition TColor.cxx:2925
static Int_t GetLinearGradient(Double_t angle, const std::vector< Int_t > &colors, const std::vector< Double_t > &positions={})
Static function: Returns the linear gradient color number corresponding to specified parameters.
Definition TColor.cxx:2217
static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
Static method to compute RGB from HLS.
Definition TColor.cxx:1580
virtual void SetRGB(Float_t r, Float_t g, Float_t b)
Initialize this color and its "dark" and "bright" associated colors.
Definition TColor.cxx:1854
static void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
Definition TColor.h:83
static Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei)
Static method. Auxiliary to HLS2RGB().
Definition TColor.cxx:1605
static Int_t GetRadialGradient(Double_t r, const std::vector< Int_t > &colors, const std::vector< Double_t > &positions={})
Static function: Returns the radial gradient color number corresponding to specified parameters.
Definition TColor.cxx:2294
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Definition TColor.cxx:1508
static const TArrayI & GetPalette()
Static function returning the current active palette.
Definition TColor.cxx:1520
Float_t GetRed() const
Definition TColor.h:61
void ls(Option_t *option="") const override
List this color with its attributes.
Definition TColor.cxx:1702
static Bool_t SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition TColor.cxx:2554
Float_t fLight
Light.
Definition TColor.h:30
static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)
Convert r,g,b to graphics system dependent pixel value.
Definition TColor.cxx:2482
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2444
static void RGB2HSV(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &s, Float_t &v)
Static method to compute HSV from RGB.
Definition TColor.cxx:1775
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1925
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition TColor.cxx:1171
static void HSV2RGB(Float_t h, Float_t s, Float_t v, Float_t &r, Float_t &g, Float_t &b)
Static method to compute RGB from HSV:
Definition TColor.cxx:1646
Float_t fAlpha
Alpha (transparency)
Definition TColor.h:32
void Copy(TObject &color) const override
Copy this color to obj.
Definition TColor.cxx:1350
static void InvertPalette()
Invert the current color palette.
Definition TColor.cxx:3644
Float_t fHue
Hue.
Definition TColor.h:29
static void CreateColorWheel()
Static function steering the creation of all colors in the color wheel.
Definition TColor.cxx:1420
static Int_t GetColorByName(const char *colorname)
Static method returning color index for a color specified by name.
Definition TColor.cxx:2080
void SetName(const char *name) override
Set the color name and change also the name of the "dark" and "bright" associated colors if they exis...
Definition TColor.cxx:1830
static Int_t GetColorBright(Int_t color)
Static function: Returns the bright color number corresponding to n If the TColor object does not exi...
Definition TColor.cxx:2094
static Bool_t IsGrayscale()
Return whether all colors return grayscale values.
Definition TColor.cxx:2588
static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b)
Convert machine dependent pixel value (obtained via RGB2Pixel or via Number2Pixel() or via TColor::Ge...
Definition TColor.cxx:2520
const char * AsHexString() const
Return color as hexadecimal string.
Definition TColor.cxx:1329
static Int_t GetColorDark(Int_t color)
Static function: Returns the dark color number corresponding to n If the TColor object does not exist...
Definition TColor.cxx:2137
Float_t GetAlpha() const
Definition TColor.h:67
static Int_t CreateGradientColorTable(UInt_t Number, Double_t *Stops, Double_t *Red, Double_t *Green, Double_t *Blue, UInt_t NColors, Float_t alpha=1., Bool_t setPalette=kTRUE)
Static function creating a color table with several connected linear gradients.
Definition TColor.cxx:2734
static const char * PixelAsHexString(ULong_t pixel)
Convert machine dependent pixel value (obtained via RGB2Pixel or via Number2Pixel() or via TColor::Ge...
Definition TColor.cxx:2541
static TClass * Class()
void Allocate()
Make this color known to the graphics system.
Definition TColor.cxx:1908
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition TColor.cxx:1563
static Int_t CreateColorTableFromFile(TString fileName, Float_t alpha=1.)
Static function creating a color palette based on an input text file.
Definition TColor.cxx:2628
static void SetColorThreshold(Float_t t)
This method specifies the color threshold used by GetColor to retrieve a color.
Definition TColor.cxx:1994
static Bool_t DefinedColors(Int_t set_always_on=0)
Static method returning kTRUE if some new colors have been defined after initialisation or since the ...
Definition TColor.cxx:1541
Float_t GetLight() const
Definition TColor.h:65
Float_t GetHue() const
Definition TColor.h:64
Float_t fGreen
Fraction of Green.
Definition TColor.h:27
static void CreateColorsCircle(Int_t offset, const char *name, UChar_t *rgb)
Create the "circle" colors in the color wheel.
Definition TColor.cxx:1382
Int_t GetNumber() const
Definition TColor.h:59
Float_t GetBlue() const
Definition TColor.h:63
TColor & operator=(const TColor &color)
Definition TColor.cxx:1159
Float_t GetGreen() const
Definition TColor.h:62
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Definition TColor.cxx:1528
static Int_t GetFreeColorIndex()
Static function: Returns the free color index greater than the highest defined color index.
Definition TColor.cxx:2371
Float_t GetSaturation() const
Definition TColor.h:66
static void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
Definition TColor.h:78
static void ListColors(Int_t ci1=0, Int_t ci2=0, Bool_t showEmpty=kFALSE)
List nb colors from the color index ci.
Definition TColor.cxx:2402
TColor()
Default constructor.
Definition TColor.cxx:1065
Int_t fNumber
Color number identifier.
Definition TColor.h:24
static void CreateColorsRectangle(Int_t offset, const char *name, UChar_t *rgb)
Create the "rectangular" colors in the color wheel.
Definition TColor.cxx:1401
Float_t fBlue
Fraction of Blue.
Definition TColor.h:28
static void CreateColorsGray()
Create the Gray scale colors in the Color Wheel.
Definition TColor.cxx:1366
virtual ~TColor()
Color destructor.
Definition TColor.cxx:1142
Float_t fRed
Fraction of Red.
Definition TColor.h:26
static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
Static method to compute HLS from RGB.
Definition TColor.cxx:1720
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2181
static void SetGrayscale(Bool_t set=kTRUE)
Set whether all colors should return grayscale values.
Definition TColor.cxx:2596
static TClass * Class()
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
void Copy(TObject &named) const override
Copy this to obj.
Definition TNamed.cxx:94
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:174
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
TString fName
Definition TNamed.h:32
An array of TObjects.
Definition TObjArray.h:31
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1040
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1054
static TClass * Class()
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
ULong_t fPixel
color pixel value (index in color table)
Definition GuiTypes.h:311
UShort_t fRed
red component (0..65535)
Definition GuiTypes.h:312
UShort_t fGreen
green component (0..65535)
Definition GuiTypes.h:313
UShort_t fBlue
blue component (0..65535)
Definition GuiTypes.h:314
UShort_t fMask
mask telling which color components are valid
Definition GuiTypes.h:315
TLine l
Definition textangle.C:4