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