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