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