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