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