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
1049The transparency is available on all platforms when the flag `OpenGL.CanvasPreferGL` is set to `1`
1050in `$ROOTSYS/etc/system.rootrc`, or on Mac with the Cocoa backend. On the file output
1051it is visible with PDF, PNG, Gif, JPEG, SVG, TeX ... but not PostScript.
1052
1053Alternatively, you can call at the top of your script `gSytle->SetCanvasPreferGL();`.
1054Or if you prefer to activate GL for a single canvas `c`, then use `c->SetSupportGL(true);`.
1055
1056The following macro gives an example of transparency usage:
1057
1058Begin_Macro(source)
1059../../../tutorials/visualisation/graphics/transparency.C
1060End_Macro
1061
1062*/
1063
1064////////////////////////////////////////////////////////////////////////////////
1065/// Default constructor.
1068{
1069 fNumber = -1;
1070 fRed = fGreen = fBlue = fHue = fLight = fSaturation = -1;
1071 fAlpha = 1;
1072}
1073
1074////////////////////////////////////////////////////////////////////////////////
1075/// Normal color constructor. Initialize a color structure.
1076/// Compute the RGB and HLS color components.
1077/// The color title is set to its hexadecimal value.
1079TColor::TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char *name,
1080 Float_t a)
1081 : TNamed(name,"")
1082{
1084 // do not enter if color number already exist
1085 TColor *col = gROOT->GetColor(color);
1086 if (col) {
1087 Warning("TColor", "color %d already defined", color);
1088 fNumber = col->GetNumber();
1089 fRed = col->GetRed();
1090 fGreen = col->GetGreen();
1091 fBlue = col->GetBlue();
1092 fHue = col->GetHue();
1093 fLight = col->GetLight();
1094 fAlpha = col->GetAlpha();
1095 fSaturation = col->GetSaturation();
1096 return;
1097 }
1098
1099 fNumber = color;
1100
1102
1103 char aname[32];
1104 if (!name || !*name) {
1105 snprintf(aname,32, "Color%d", color);
1106 SetName(aname);
1107 }
1108
1109 // enter in the list of colors
1110 TObjArray *lcolors = (TObjArray*)gROOT->GetListOfColors();
1111 lcolors->AddAtAndExpand(this, color);
1112
1113 // fill color structure
1114 SetRGB(r, g, b);
1115 fAlpha = a;
1118}
1119
1120////////////////////////////////////////////////////////////////////////////////
1121/// Fast TColor constructor. It creates a color with an index just above the
1122/// current highest one. It does not name the color.
1123/// This is useful to create palettes.
1126{
1129 fRed = r;
1130 fGreen = g;
1131 fBlue = b;
1132 fAlpha = a;
1134
1135 // enter in the list of colors
1136 TObjArray *lcolors = (TObjArray*)gROOT->GetListOfColors();
1137 lcolors->AddAtAndExpand(this, fNumber);
1139}
1140
1141////////////////////////////////////////////////////////////////////////////////
1142/// Color destructor.
1145{
1146 gROOT->GetListOfColors()->Remove(this);
1147 if (gROOT->GetListOfColors()->IsEmpty()) {
1148 fgPalette.Set(0);
1149 fgPalette=0;
1150 }
1151}
1152
1153////////////////////////////////////////////////////////////////////////////////
1154/// Color copy constructor.
1156TColor::TColor(const TColor &color) : TNamed(color)
1157{
1158 color.TColor::Copy(*this);
1159}
1161TColor &TColor::operator=(const TColor &color)
1162{
1163 if (this != &color)
1164 color.TColor::Copy(*this);
1165 return *this;
1166}
1167
1168////////////////////////////////////////////////////////////////////////////////
1169/// Initialize colors used by the TCanvas based graphics (via TColor objects).
1170/// This method should be called before the ApplicationImp is created (which
1171/// initializes the GUI colors).
1174{
1175 static Bool_t initDone = kFALSE;
1176
1177 if (initDone) return;
1178 initDone = kTRUE;
1179
1180 if (gROOT->GetListOfColors()->First() == nullptr) {
1181
1182 new TColor(kWhite,1,1,1,"background");
1183 new TColor(kBlack,0,0,0,"black");
1184 new TColor(2,1,0,0,"red");
1185 new TColor(3,0,1,0,"green");
1186 new TColor(4,0,0,1,"blue");
1187 new TColor(5,1,1,0,"yellow");
1188 new TColor(6,1,0,1,"magenta");
1189 new TColor(7,0,1,1,"cyan");
1190 new TColor(10,0.999,0.999,0.999,"white");
1191 new TColor(11,0.754,0.715,0.676,"editcol");
1192
1193 // The color white above is defined as being nearly white.
1194 // Sets the associated dark color also to white.
1196 TColor *c110 = gROOT->GetColor(110);
1197 if (c110) c110->SetRGB(0.999,0.999,.999);
1198
1199 // Initialize Custom colors
1200 new TColor(20,0.8,0.78,0.67);
1201 new TColor(31,0.54,0.66,0.63);
1202 new TColor(41,0.83,0.81,0.53);
1203 new TColor(30,0.52,0.76,0.64);
1204 new TColor(32,0.51,0.62,0.55);
1205 new TColor(24,0.70,0.65,0.59);
1206 new TColor(21,0.8,0.78,0.67);
1207 new TColor(47,0.67,0.56,0.58);
1208 new TColor(35,0.46,0.54,0.57);
1209 new TColor(33,0.68,0.74,0.78);
1210 new TColor(39,0.5,0.5,0.61);
1211 new TColor(37,0.43,0.48,0.52);
1212 new TColor(38,0.49,0.6,0.82);
1213 new TColor(36,0.41,0.51,0.59);
1214 new TColor(49,0.58,0.41,0.44);
1215 new TColor(43,0.74,0.62,0.51);
1216 new TColor(22,0.76,0.75,0.66);
1217 new TColor(45,0.75,0.51,0.47);
1218 new TColor(44,0.78,0.6,0.49);
1219 new TColor(26,0.68,0.6,0.55);
1220 new TColor(28,0.53,0.4,0.34);
1221 new TColor(25,0.72,0.64,0.61);
1222 new TColor(27,0.61,0.56,0.51);
1223 new TColor(23,0.73,0.71,0.64);
1224 new TColor(42,0.87,0.73,0.53);
1225 new TColor(46,0.81,0.37,0.38);
1226 new TColor(48,0.65,0.47,0.48);
1227 new TColor(34,0.48,0.56,0.6);
1228 new TColor(40,0.67,0.65,0.75);
1229 new TColor(29,0.69,0.81,0.78);
1230
1231 // Initialize some additional greyish non saturated colors
1232 new TColor(8, 0.35,0.83,0.33);
1233 new TColor(9, 0.35,0.33,0.85);
1234 new TColor(12,.3,.3,.3,"grey12");
1235 new TColor(13,.4,.4,.4,"grey13");
1236 new TColor(14,.5,.5,.5,"grey14");
1237 new TColor(15,.6,.6,.6,"grey15");
1238 new TColor(16,.7,.7,.7,"grey16");
1239 new TColor(17,.8,.8,.8,"grey17");
1240 new TColor(18,.9,.9,.9,"grey18");
1241 new TColor(19,.95,.95,.95,"grey19");
1242 new TColor(50, 0.83,0.35,0.33);
1243
1244 // define the Petroff color schemes
1245 new TColor(kGrape, 111./255., 45./255., 168./255., "kGrape");
1246 new TColor(kBrown, 165./255., 42./255., 42./255., "kBrown");
1247 new TColor(kAsh, 178./255., 190./255., 181./255., "kAsh");
1248
1249 new TColor(kP6Blue, 87./255., 144./255., 252./255., "kP6Blue");
1250 new TColor(kP6Yellow, 248./255., 156./255., 32./255., "kP6Yellow");
1251 new TColor(kP6Red, 228./255., 37./255., 54./255., "kP6Red");
1252 new TColor(kP6Grape, 150./255., 74./255., 139./255., "kP6Grape");
1253 new TColor(kP6Gray, 156./255., 156./255., 161./255., "kP6Gray");
1254 new TColor(kP6Violet, 122./255., 33./255., 221./255., "kP6Violet");
1255
1256 new TColor(kP8Blue, 24./255., 69./255., 251./255., "kP8Blue");
1257 new TColor(kP8Orange, 1., 94./255., 2./255., "kP8Orange");
1258 new TColor(kP8Red, 201./255., 31./255., 22./255., "kP8Red");
1259 new TColor(kP8Pink, 200./255., 73./255., 169./255., "kP8Pink");
1260 new TColor(kP8Green, 173./255., 173./255., 125./255., "kP8Green");
1261 new TColor(kP8Cyan, 134./255., 200./255., 221./255., "kP8Cyan");
1262 new TColor(kP8Azure, 87./255., 141./255., 255./255., "kP8Azure");
1263 new TColor(kP8Gray, 101./255., 99./255., 100./255., "kP8Gray");
1264
1265 new TColor(kP10Blue, 63./255., 144./255., 218./255., "kP10Blue");
1266 new TColor(kP10Yellow, 1., 169./255., 14./255., "kP10Yellow");
1267 new TColor(kP10Red, 189./255., 31./255., 1./255., "kP10Red");
1268 new TColor(kP10Gray, 148./255., 164./255., 162./255., "kP10Gray");
1269 new TColor(kP10Violet, 131./255., 45./255., 182./255., "kP10Violet");
1270 new TColor(kP10Brown, 169./255., 107./255., 89./255., "kP10Brown");
1271 new TColor(kP10Orange, 231./255., 99./255., 0., "kP10Orange");
1272 new TColor(kP10Green, 185./255., 172./255., 112./255., "kP10Green");
1273 new TColor(kP10Ash, 113./255., 117./255., 129./255., "kP10Ash");
1274 new TColor(kP10Cyan, 146./255., 218./255., 221./255., "kP10Cyan");
1275
1276 // Initialize the Pretty Palette Spectrum Violet->Red
1277 // The color model used here is based on the HLS model which
1278 // is much more suitable for creating palettes than RGB.
1279 // Fixing the saturation and lightness we can scan through the
1280 // spectrum of visible light by using "hue" alone.
1281 // In Root hue takes values from 0 to 360.
1282 Int_t i;
1283 Float_t saturation = 1;
1284 Float_t lightness = 0.5;
1285 Float_t maxHue = 280;
1286 Float_t minHue = 0;
1287 Int_t maxPretty = 50;
1288 Float_t hue;
1289 Float_t r=0., g=0., b=0., h, l, s;
1290
1291 for (i=0 ; i<maxPretty-1 ; i++) {
1292 hue = maxHue-(i+1)*((maxHue-minHue)/maxPretty);
1294 new TColor(i+51, r, g, b);
1295 }
1296
1297 // Initialize special colors for x3d
1298 TColor *s0;
1299 for (i = 1; i < 8; i++) {
1300 s0 = gROOT->GetColor(i);
1301 if (s0) s0->GetRGB(r,g,b);
1302 if (i == 1) { r = 0.6; g = 0.6; b = 0.6; }
1303 if (r == 1) r = 0.9; else if (r == 0) r = 0.1;
1304 if (g == 1) g = 0.9; else if (g == 0) g = 0.1;
1305 if (b == 1) b = 0.9; else if (b == 0) b = 0.1;
1306 TColor::RGBtoHLS(r,g,b,h,l,s);
1307 TColor::HLStoRGB(h,0.6*l,s,r,g,b);
1308 new TColor(200+4*i-3,r,g,b);
1309 TColor::HLStoRGB(h,0.8*l,s,r,g,b);
1310 new TColor(200+4*i-2,r,g,b);
1311 TColor::HLStoRGB(h,1.2*l,s,r,g,b);
1312 new TColor(200+4*i-1,r,g,b);
1313 TColor::HLStoRGB(h,1.4*l,s,r,g,b);
1314 new TColor(200+4*i ,r,g,b);
1315 }
1316
1317 // Create the ROOT Color Wheel
1319 }
1320 // If fgPalette.fN !=0 SetPalette has been called already
1321 // (from rootlogon.C for instance)
1322
1323 if (!fgPalette.fN) SetPalette(1,nullptr);
1324}
1325
1326////////////////////////////////////////////////////////////////////////////////
1327/// Return color as hexadecimal string. This string can be directly passed
1328/// to, for example, TGClient::GetColorByName(). String will be reused so
1329/// copy immediately if needed.
1331const char *TColor::AsHexString() const
1332{
1333 static TString tempbuf;
1334
1335 Int_t r, g, b, a;
1336 r = Int_t(GetRed() * 255);
1337 g = Int_t(GetGreen() * 255);
1338 b = Int_t(GetBlue() * 255);
1339 a = Int_t(fAlpha * 255);
1340
1341 if (a != 255) {
1342 tempbuf.Form("#%02x%02x%02x%02x", a, r, g, b);
1343 } else {
1344 tempbuf.Form("#%02x%02x%02x", r, g, b);
1345 }
1346 return tempbuf;
1347}
1348
1349////////////////////////////////////////////////////////////////////////////////
1350/// Copy this color to obj.
1352void TColor::Copy(TObject &obj) const
1353{
1354 TNamed::Copy((TNamed&)obj);
1355 ((TColor&)obj).fRed = fRed;
1356 ((TColor&)obj).fGreen = fGreen;
1357 ((TColor&)obj).fBlue = fBlue;
1358 ((TColor&)obj).fHue = fHue;
1359 ((TColor&)obj).fLight = fLight;
1360 ((TColor&)obj).fAlpha = fAlpha;
1361 ((TColor&)obj).fSaturation = fSaturation;
1362 ((TColor&)obj).fNumber = fNumber;
1363}
1364
1365////////////////////////////////////////////////////////////////////////////////
1366/// Create the Gray scale colors in the Color Wheel
1369{
1370 if (gROOT->GetColor(kGray)) return;
1371 TColor *gray = new TColor(kGray,204./255.,204./255.,204./255.);
1372 TColor *gray1 = new TColor(kGray+1,153./255.,153./255.,153./255.);
1373 TColor *gray2 = new TColor(kGray+2,102./255.,102./255.,102./255.);
1374 TColor *gray3 = new TColor(kGray+3, 51./255., 51./255., 51./255.);
1375 gray ->SetName("kGray");
1376 gray1->SetName("kGray+1");
1377 gray2->SetName("kGray+2");
1378 gray3->SetName("kGray+3");
1379}
1380
1381////////////////////////////////////////////////////////////////////////////////
1382/// Create the "circle" colors in the color wheel.
1385{
1387 for (Int_t n=0;n<15;n++) {
1388 Int_t colorn = offset+n-10;
1389 TColor *color = gROOT->GetColor(colorn);
1390 if (!color) {
1391 color = new TColor(colorn,rgb[3*n]/255.,rgb[3*n+1]/255.,rgb[3*n+2]/255.);
1392 if (n>10) colorname.Form("%s+%d",name,n-10);
1393 else if (n<10) colorname.Form("%s-%d",name,10-n);
1394 else colorname.Form("%s",name);
1395 color->SetName(colorname);
1396 }
1397 }
1398}
1399
1400////////////////////////////////////////////////////////////////////////////////
1401/// Create the "rectangular" colors in the color wheel.
1404{
1406 for (Int_t n=0;n<20;n++) {
1407 Int_t colorn = offset+n-9;
1408 TColor *color = gROOT->GetColor(colorn);
1409 if (!color) {
1410 color = new TColor(colorn,rgb[3*n]/255.,rgb[3*n+1]/255.,rgb[3*n+2]/255.);
1411 if (n>9) colorname.Form("%s+%d",name,n-9);
1412 else if (n<9) colorname.Form("%s-%d",name,9-n);
1413 else colorname.Form("%s",name);
1414 color->SetName(colorname);
1415 }
1416 }
1417}
1418
1419////////////////////////////////////////////////////////////////////////////////
1420/// Static function steering the creation of all colors in the color wheel.
1423{
1424 UChar_t magenta[46]= {255,204,255
1425 ,255,153,255, 204,153,204
1426 ,255,102,255, 204,102,204, 153,102,153
1427 ,255, 51,255, 204, 51,204, 153, 51,153, 102, 51,102
1428 ,255, 0,255, 204, 0,204, 153, 0,153, 102, 0,102, 51, 0, 51};
1429
1430 UChar_t red[46] = {255,204,204
1431 ,255,153,153, 204,153,153
1432 ,255,102,102, 204,102,102, 153,102,102
1433 ,255, 51, 51, 204, 51, 51, 153, 51, 51, 102, 51, 51
1434 ,255, 0, 0, 204, 0, 0, 153, 0, 0, 102, 0, 0, 51, 0, 0};
1435
1436 UChar_t yellow[46] = {255,255,204
1437 ,255,255,153, 204,204,153
1438 ,255,255,102, 204,204,102, 153,153,102
1439 ,255,255, 51, 204,204, 51, 153,153, 51, 102,102, 51
1440 ,255,255, 0, 204,204, 0, 153,153, 0, 102,102, 0, 51, 51, 0};
1441
1442 UChar_t green[46] = {204,255,204
1443 ,153,255,153, 153,204,153
1444 ,102,255,102, 102,204,102, 102,153,102
1445 , 51,255, 51, 51,204, 51, 51,153, 51, 51,102, 51
1446 , 0,255, 0, 0,204, 0, 0,153, 0, 0,102, 0, 0, 51, 0};
1447
1448 UChar_t cyan[46] = {204,255,255
1449 ,153,255,255, 153,204,204
1450 ,102,255,255, 102,204,204, 102,153,153
1451 , 51,255,255, 51,204,204, 51,153,153, 51,102,102
1452 , 0,255,255, 0,204,204, 0,153,153, 0,102,102, 0, 51, 51};
1453
1454 UChar_t blue[46] = {204,204,255
1455 ,153,153,255, 153,153,204
1456 ,102,102,255, 102,102,204, 102,102,153
1457 , 51, 51,255, 51, 51,204, 51, 51,153, 51, 51,102
1458 , 0, 0,255, 0, 0,204, 0, 0,153, 0, 0,102, 0, 0, 51};
1459
1460 UChar_t pink[60] = {255, 51,153, 204, 0,102, 102, 0, 51, 153, 0, 51, 204, 51,102
1461 ,255,102,153, 255, 0,102, 255, 51,102, 204, 0, 51, 255, 0, 51
1462 ,255,153,204, 204,102,153, 153, 51,102, 153, 0,102, 204, 51,153
1463 ,255,102,204, 255, 0,153, 204, 0,153, 255, 51,204, 255, 0,153};
1464
1465 UChar_t orange[60]={255,204,153, 204,153,102, 153,102, 51, 153,102, 0, 204,153, 51
1466 ,255,204,102, 255,153, 0, 255,204, 51, 204,153, 0, 255,204, 0
1467 ,255,153, 51, 204,102, 0, 102, 51, 0, 153, 51, 0, 204,102, 51
1468 ,255,153,102, 255,102, 0, 255,102, 51, 204, 51, 0, 255, 51, 0};
1469
1470 UChar_t spring[60]={153,255, 51, 102,204, 0, 51,102, 0, 51,153, 0, 102,204, 51
1471 ,153,255,102, 102,255, 0, 102,255, 51, 51,204, 0, 51,255, 0
1472 ,204,255,153, 153,204,102, 102,153, 51, 102,153, 0, 153,204, 51
1473 ,204,255,102, 153,255, 0, 204,255, 51, 153,204, 0, 204,255, 0};
1474
1475 UChar_t teal[60] = {153,255,204, 102,204,153, 51,153,102, 0,153,102, 51,204,153
1476 ,102,255,204, 0,255,102, 51,255,204, 0,204,153, 0,255,204
1477 , 51,255,153, 0,204,102, 0,102, 51, 0,153, 51, 51,204,102
1478 ,102,255,153, 0,255,153, 51,255,102, 0,204, 51, 0,255, 51};
1479
1480 UChar_t azure[60] ={153,204,255, 102,153,204, 51,102,153, 0, 51,153, 51,102,204
1481 ,102,153,255, 0,102,255, 51,102,255, 0, 51,204, 0, 51,255
1482 , 51,153,255, 0,102,204, 0, 51,102, 0,102,153, 51,153,204
1483 ,102,204,255, 0,153,255, 51,204,255, 0,153,204, 0,204,255};
1484
1485 UChar_t violet[60]={204,153,255, 153,102,204, 102, 51,153, 102, 0,153, 153, 51,204
1486 ,204,102,255, 153, 0,255, 204, 51,255, 153, 0,204, 204, 0,255
1487 ,153, 51,255, 102, 0,204, 51, 0,102, 51, 0,153, 102, 51,204
1488 ,153,102,255, 102, 0,255, 102, 51,255, 51, 0,204, 51, 0,255};
1489
1496
1503
1505}
1506
1507////////////////////////////////////////////////////////////////////////////////
1508/// Static function returning the color number i in current palette.
1511{
1512 Int_t ncolors = fgPalette.fN;
1513 if (ncolors == 0) return 0;
1514 Int_t icol = i%ncolors;
1515 if (icol < 0) icol = 0;
1516 return fgPalette.fArray[icol];
1517}
1518
1519////////////////////////////////////////////////////////////////////////////////
1520/// Static function returning the current active palette.
1523{
1524 return fgPalette;
1525}
1526
1527////////////////////////////////////////////////////////////////////////////////
1528/// Static function returning number of colors in the color palette.
1531{
1532 return fgPalette.fN;
1533}
1534
1535////////////////////////////////////////////////////////////////////////////////
1536/// Static method returning kTRUE if some new colors have been defined after
1537/// initialisation or since the last call to this method. This allows to avoid
1538/// the colors and palette streaming in TCanvas::Streamer if not needed.
1539/// If method called once with set_always_on = 1, all next canvases will be
1540// saved with color palette - disregard if new colors created or not.
1541/// To reset such mode, just call methoid once with set_always_on = -1
1544{
1545 if (set_always_on > 0)
1546 gLastDefinedColors = -1;
1547 else if (set_always_on < 0)
1549
1550 if (gLastDefinedColors < 0)
1551 return kTRUE;
1552
1553 // After initialization gDefinedColors == 649. If it is bigger it means some new
1554 // colors have been defined
1555 Bool_t hasChanged = (gDefinedColors - gLastDefinedColors) > 50;
1557 return hasChanged;
1558}
1559
1560////////////////////////////////////////////////////////////////////////////////
1561/// Return pixel value corresponding to this color. This pixel value can
1562/// be used in the GUI classes. This call does not work in batch mode since
1563/// it needs to communicate with the graphics system.
1566{
1567 if (gVirtualX && !gROOT->IsBatch()) {
1568 if (gApplication) {
1570 gApplication->InitializeGraphics(gROOT->IsWebDisplay());
1571 }
1572 return gVirtualX->GetPixel(fNumber);
1573 }
1574
1575 return 0;
1576}
1577
1578////////////////////////////////////////////////////////////////////////////////
1579/// Static method to compute RGB from HLS. The l and s are between [0,1]
1580/// and h is between [0,360]. The returned r,g,b triplet is between [0,1].
1583 Float_t &r, Float_t &g, Float_t &b)
1584{
1585
1586 Float_t rh, rl, rs, rm1, rm2;
1587 rh = rl = rs = 0;
1588 if (hue > 0) { rh = hue; if (rh > 360) rh = 360; }
1589 if (light > 0) { rl = light; if (rl > 1) rl = 1; }
1590 if (satur > 0) { rs = satur; if (rs > 1) rs = 1; }
1591
1592 if (rl <= 0.5)
1593 rm2 = rl*(1.0f + rs);
1594 else
1595 rm2 = rl + rs - rl*rs;
1596 rm1 = 2.0f*rl - rm2;
1597
1598 if (!rs) { r = rl; g = rl; b = rl; return; }
1599 r = HLStoRGB1(rm1, rm2, rh+120.0f);
1600 g = HLStoRGB1(rm1, rm2, rh);
1601 b = HLStoRGB1(rm1, rm2, rh-120.0f);
1602}
1603
1604////////////////////////////////////////////////////////////////////////////////
1605/// Static method. Auxiliary to HLS2RGB().
1608{
1609 Float_t hue = huei;
1610 if (hue > 360) hue = hue - 360.0f;
1611 if (hue < 0) hue = hue + 360.0f;
1612 if (hue < 60 ) return rn1 + (rn2-rn1)*hue/60.0f;
1613 if (hue < 180) return rn2;
1614 if (hue < 240) return rn1 + (rn2-rn1)*(240.0f-hue)/60.0f;
1615 return rn1;
1616}
1617
1618////////////////////////////////////////////////////////////////////////////////
1619/// Static method to compute RGB from HLS. The h,l,s are between [0,255].
1620/// The returned r,g,b triplet is between [0,255].
1623{
1624 Float_t hh, ll, ss, rr, gg, bb;
1625
1626 hh = Float_t(h) * 360.0f / 255.0f;
1627 ll = Float_t(l) / 255.0f;
1628 ss = Float_t(s) / 255.0f;
1629
1630 TColor::HLStoRGB(hh, ll, ss, rr, gg, bb);
1631
1632 r = (Int_t) (rr * 255.0f);
1633 g = (Int_t) (gg * 255.0f);
1634 b = (Int_t) (bb * 255.0f);
1635}
1636
1637////////////////////////////////////////////////////////////////////////////////
1638/// Static method to compute RGB from HSV:
1639///
1640/// - The hue value runs from 0 to 360.
1641/// - The saturation is the degree of strength or purity and is from 0 to 1.
1642/// Purity is how much white is added to the color, so S=1 makes the purest
1643/// color (no white).
1644/// - Brightness value also ranges from 0 to 1, where 0 is the black.
1645///
1646/// The returned r,g,b triplet is between [0,1].
1649 Float_t &r, Float_t &g, Float_t &b)
1650{
1651 Int_t i;
1652 Float_t f, p, q, t;
1653
1654 if (satur==0) {
1655 // Achromatic (grey)
1656 r = g = b = value;
1657 return;
1658 }
1659
1660 hue /= 60.0f; // sector 0 to 5
1661 i = (Int_t)floor(hue);
1662 f = hue-i; // factorial part of hue
1663 p = value*(1-satur);
1664 q = value*(1-satur*f );
1665 t = value*(1-satur*(1-f));
1666
1667 switch (i) {
1668 case 0:
1669 r = value;
1670 g = t;
1671 b = p;
1672 break;
1673 case 1:
1674 r = q;
1675 g = value;
1676 b = p;
1677 break;
1678 case 2:
1679 r = p;
1680 g = value;
1681 b = t;
1682 break;
1683 case 3:
1684 r = p;
1685 g = q;
1686 b = value;
1687 break;
1688 case 4:
1689 r = t;
1690 g = p;
1691 b = value;
1692 break;
1693 default:
1694 r = value;
1695 g = p;
1696 b = q;
1697 break;
1698 }
1699}
1700
1701////////////////////////////////////////////////////////////////////////////////
1702/// List this color with its attributes.
1704void TColor::ls(Option_t *) const
1705{
1706 printf("Color:%d Red=%f Green=%f Blue=%f Alpha=%f Name=%s\n",
1708}
1709
1710////////////////////////////////////////////////////////////////////////////////
1711/// Dump this color with its attributes.
1713void TColor::Print(Option_t *) const
1714{
1715 ls();
1716}
1717
1718////////////////////////////////////////////////////////////////////////////////
1719/// Static method to compute HLS from RGB. The r,g,b triplet is between
1720/// [0,1], hue is between [0,360], light and satur are [0,1].
1724{
1725 Float_t r = 0, g = 0, b = 0;
1726 if (rr > 0) { r = rr; if (r > 1) r = 1; }
1727 if (gg > 0) { g = gg; if (g > 1) g = 1; }
1728 if (bb > 0) { b = bb; if (b > 1) b = 1; }
1729
1730 Float_t minval = r, maxval = r;
1731 if (g < minval) minval = g;
1732 if (b < minval) minval = b;
1733 if (g > maxval) maxval = g;
1734 if (b > maxval) maxval = b;
1735
1739 light = 0.5f * msum;
1740 if (maxval != minval) {
1741 rnorm = (maxval - r)/mdiff;
1742 gnorm = (maxval - g)/mdiff;
1743 bnorm = (maxval - b)/mdiff;
1744 } else {
1745 satur = hue = 0;
1746 return;
1747 }
1748
1749 if (light < 0.5)
1750 satur = mdiff/msum;
1751 else
1752 satur = mdiff/(2.0f - msum);
1753
1754 if (r == maxval)
1755 hue = 60.0f * (6.0f + bnorm - gnorm);
1756 else if (g == maxval)
1757 hue = 60.0f * (2.0f + rnorm - bnorm);
1758 else
1759 hue = 60.0f * (4.0f + gnorm - rnorm);
1760
1761 if (hue > 360)
1762 hue = hue - 360.0f;
1763}
1764
1765////////////////////////////////////////////////////////////////////////////////
1766/// Static method to compute HSV from RGB.
1767///
1768/// - The input values:
1769/// - r,g,b triplet is between [0,1].
1770/// - The returned values:
1771/// - The hue value runs from 0 to 360.
1772/// - The saturation is the degree of strength or purity and is from 0 to 1.
1773/// Purity is how much white is added to the color, so S=1 makes the purest
1774/// color (no white).
1775/// - Brightness value also ranges from 0 to 1, where 0 is the black.
1779{
1780 Float_t min, max, delta;
1781
1782 min = TMath::Min(TMath::Min(r, g), b);
1783 max = TMath::Max(TMath::Max(r, g), b);
1784 value = max;
1785
1786 delta = max - min;
1787
1788 if (max != 0) {
1789 satur = delta/max;
1790 } else {
1791 satur = 0;
1792 hue = -1;
1793 return;
1794 }
1795
1796 if (r == max) {
1797 hue = (g-b)/delta;
1798 } else if (g == max) {
1799 hue = 2.0f+(b-r)/delta;
1800 } else {
1801 hue = 4.0f+(r-g)/delta;
1802 }
1803
1804 hue *= 60.0f;
1805 if (hue < 0.0f) hue += 360.0f;
1806}
1807
1808////////////////////////////////////////////////////////////////////////////////
1809/// Static method to compute HLS from RGB. The r,g,b triplet is between
1810/// [0,255], hue, light and satur are between [0,255].
1813{
1814 Float_t rr, gg, bb, hue, light, satur;
1815
1816 rr = Float_t(r) / 255.0f;
1817 gg = Float_t(g) / 255.0f;
1818 bb = Float_t(b) / 255.0f;
1819
1821
1822 h = (Int_t) (hue/360.0f * 255.0f);
1823 l = (Int_t) (light * 255.0f);
1824 s = (Int_t) (satur * 255.0f);
1825}
1826
1827
1828////////////////////////////////////////////////////////////////////////////////
1829/// Set the color name and change also the name of the "dark" and "bright" associated
1830/// colors if they exist.
1832void TColor::SetName(const char* name)
1833{
1834 Int_t nd = GetColorByName(TString::Format("%s_dark",fName.Data()).Data());
1835 Int_t nb = GetColorByName(TString::Format("%s_bright",fName.Data()).Data());
1836
1837 fName = name;
1838
1839 auto colors = (TObjArray*) gROOT->GetListOfColors();
1840
1841 if (nd >= 0) {
1842 TColor *colord = (TColor*)colors->At(nd);
1843 colord->TNamed::SetName(TString::Format("%s_dark",fName.Data()).Data());
1844 }
1845
1846 if (nb >= 0) {
1847 TColor *colorb = (TColor*)colors->At(nb);
1848 colorb->TNamed::SetName(TString::Format("%s_bright",fName.Data()).Data());
1849 }
1850}
1851
1852
1853////////////////////////////////////////////////////////////////////////////////
1854/// Initialize this color and its "dark" and "bright" associated colors.
1857{
1859 fRed = r;
1860 fGreen = g;
1861 fBlue = b;
1862
1863 if (fRed < 0) return;
1864
1867
1868 Int_t nplanes = 16;
1869 if (gVirtualX) gVirtualX->GetPlanes(nplanes);
1870 if (nplanes == 0) nplanes = 16;
1871
1872 // allocate color now (can be delayed when we have a large colormap)
1873#ifndef R__WIN32
1874 if (nplanes < 15)
1875#endif
1876 Allocate();
1877
1878 // change the dark and bright associated colors if they exist
1879 Float_t dr, dg, db, lr, lg, lb;
1880
1881 // get the list of all defined colors
1882 auto colors = (TObjArray*) gROOT->GetListOfColors();
1883
1884 // set dark color
1885 Int_t nd = GetColorByName(TString::Format("%s_dark",GetName()).Data());
1886 if (nd >= 0) {
1887 HLStoRGB(fHue, 0.7f*fLight, fSaturation, dr, dg, db);
1888 TColor *colord = (TColor*)colors->At(nd);
1889 if (nplanes > 8) colord->SetRGB(dr, dg, db);
1890 else colord->SetRGB(0.3f,0.3f,0.3f);
1891 colord->SetTitle(colord->AsHexString());
1892 }
1893
1894 // set bright color
1895 Int_t nb = GetColorByName(TString::Format("%s_bright",GetName()).Data());
1896 if (nb >= 0) {
1897 HLStoRGB(fHue, 1.2f*fLight, fSaturation, lr, lg, lb);
1898 TColor *colorb = (TColor*)colors->At(nb);
1899 if (nplanes > 8) colorb->SetRGB(lr, lg, lb);
1900 else colorb->SetRGB(0.8f,0.8f,0.8f);
1901 colorb->SetTitle(colorb->AsHexString());
1902 }
1903
1905}
1906
1907////////////////////////////////////////////////////////////////////////////////
1908/// Make this color known to the graphics system.
1910void TColor::Allocate()
1911{
1912 if (gVirtualX && !gROOT->IsBatch())
1913 gVirtualX->SetRGB(fNumber, GetRed(), GetGreen(), GetBlue());
1914}
1915
1916////////////////////////////////////////////////////////////////////////////////
1917/// Static method returning color number for color specified by
1918/// hex color string of form: "#rrggbb", where rr, gg and bb are in
1919/// hex between [0,FF], e.g. "#c0c0c0". Also alpha channel is applied when
1920/// hex string includes fourth number e.g "#c0c0c0ff"
1921///
1922/// The color retrieval is done using a threshold defined by SetColorThreshold.
1923///
1924/// If specified color does not exist it will be created with as
1925/// name "#rrggbb" with rr, gg and bb in hex between [0,FF].
1927Int_t TColor::GetColor(const char *hexcolor)
1928{
1929 if (hexcolor && *hexcolor == '#') {
1930 Int_t r, g, b, a;
1931 if (strlen(hexcolor) == 9 && sscanf(hexcolor + 1, "%02x%02x%02x%02x", &r, &g, &b, &a) == 4)
1932 return GetColor(r, g, b, a / 255.);
1933 if (sscanf(hexcolor + 1, "%02x%02x%02x", &r, &g, &b) == 3)
1934 return GetColor(r, g, b);
1935 }
1936 ::Error("TColor::GetColor(const char*)", "incorrect color string");
1937 return 0;
1938}
1939
1940////////////////////////////////////////////////////////////////////////////////
1941/// Static method returning color number for color specified by
1942/// r, g and b. The r,g,b should be in the range [0,1].
1943///
1944/// The color retrieval is done using a threshold defined by SetColorThreshold.
1945///
1946/// If specified color does not exist it will be created
1947/// with as name "#rrggbb" with rr, gg and bb in hex between
1948/// [0,FF].
1951{
1952 return GetColor(Int_t(r * 255), Int_t(g * 255), Int_t(b * 255), a);
1953}
1954
1955////////////////////////////////////////////////////////////////////////////////
1956/// Static method returning color number for color specified by
1957/// system dependent pixel value. Pixel values can be obtained, e.g.,
1958/// from the GUI color picker.
1959///
1960/// The color retrieval is done using a threshold defined by SetColorThreshold.
1961
1964{
1965 Int_t r, g, b;
1966
1967 Pixel2RGB(pixel, r, g, b);
1968
1969 return GetColor(r, g, b);
1970}
1971
1972////////////////////////////////////////////////////////////////////////////////
1973/// This method specifies the color threshold used by GetColor to retrieve a color.
1974///
1975/// \param[in] t Color threshold. By default is equal to 1./31. or 1./255.
1976/// depending on the number of available color planes.
1977///
1978/// When GetColor is called, it scans the defined colors and compare them to the
1979/// requested color.
1980/// If the Red Green and Blue values passed to GetColor are Rr Gr Br
1981/// and Rd Gd Bd the values of a defined color. These two colors are considered equal
1982/// if (abs(Rr-Rd) < t & abs(Br-Bd) < t & abs(Br-Bd) < t). If this test passes,
1983/// the color defined by Rd Gd Bd is returned by GetColor.
1984///
1985/// To make sure GetColor will return a color having exactly the requested
1986/// R G B values it is enough to specify a nul :
1987/// ~~~ {.cpp}
1988/// TColor::SetColorThreshold(0.);
1989/// ~~~
1990///
1991/// To reset the color threshold to its default value it is enough to do:
1992/// ~~~ {.cpp}
1993/// TColor::SetColorThreshold(-1.);
1994/// ~~~
1999}
2000
2001////////////////////////////////////////////////////////////////////////////////
2002/// Static method returning color number for color specified by
2003/// r, g and b. The r,g,b should be in the range [0,255].
2004/// If the specified color does not exist it will be created
2005/// with as name "#rrggbb" with rr, gg and bb in hex between
2006/// [0,FF].
2007///
2008/// The color retrieval is done using a threshold defined by SetColorThreshold.
2011{
2013 if (r < 0)
2014 r = 0;
2015 else if (r > 255)
2016 r = 255;
2017 if (g < 0)
2018 g = 0;
2019 else if (g > 255)
2020 g = 255;
2021 if (b < 0)
2022 b = 0;
2023 else if (b > 255)
2024 b = 255;
2025 if (a > 1.)
2026 a = 1.;
2027 else if (a < 0.)
2028 a = 0.;
2029
2030 // Get list of all defined colors
2031 TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
2032
2033 TString name = TString::Format("#%02x%02x%02x", r, g, b);
2034 if (a != 1.)
2035 name.Append(TString::Format("%02x", Int_t(a*255)));
2036
2037 // Look for color by name
2038 if (auto color = static_cast<TColor *>(colors->FindObject(name.Data())))
2039 // We found the color by name, so we use that right away
2040 return color->GetNumber();
2041
2042 Float_t rr, gg, bb;
2043 rr = Float_t(r)/255.0f;
2044 gg = Float_t(g)/255.0f;
2045 bb = Float_t(b)/255.0f;
2046
2047 TIter next(colors);
2048
2049 Float_t thres;
2050 if (gColorThreshold >= 0) {
2052 } else {
2053 Int_t nplanes = 24;
2054 thres = 1.0f/255.0f; // 8 bits per color : 0 - 0xFF !
2055 if (gVirtualX) gVirtualX->GetPlanes(nplanes);
2056 if ((nplanes > 0) && (nplanes <= 16)) thres = 1.0f/31.0f; // 5 bits per color : 0 - 0x1F !
2057 }
2058
2059 // Loop over all defined colors
2060 while (auto color = static_cast<TColor *>(next())) {
2061 if (TMath::Abs(color->GetRed() - rr) > thres) continue;
2062 if (TMath::Abs(color->GetGreen() - gg) > thres) continue;
2063 if (TMath::Abs(color->GetBlue() - bb) > thres) continue;
2064 if (TMath::Abs(color->GetAlpha() - a) > thres) continue;
2065 // We found a matching color in the color table
2066 return color->GetNumber();
2067 }
2068
2069 // We didn't find a matching color in the color table, so we
2070 // add it. Note name is of the form "#rrggbb" where rr, etc. are
2071 // hexadecimal numbers.
2072 auto color = new TColor(colors->GetLast()+1, rr, gg, bb, name.Data(), a);
2073
2074 return color->GetNumber();
2075}
2076
2077////////////////////////////////////////////////////////////////////////////////
2078/// Static method returning color index for a color specified by name.
2079/// The list of defined colors and their names is given by TColor::ListColors.
2080/// If the specified color name does not exist -1 is returned.
2083{
2084 TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
2085 if (auto color = static_cast<TColor *>(colors->FindObject(colorname))) {
2086 return color->GetNumber();
2087 } else {
2088 return -1;
2089 }
2090}
2091
2092////////////////////////////////////////////////////////////////////////////////
2093/// Static function: Returns the bright color number corresponding to n
2094/// If the TColor object does not exist, it is created at a free color index.
2097{
2098 if (n < 0) return -1;
2099
2100 // Get list of all defined colors
2101 auto colors = (TObjArray*) gROOT->GetListOfColors();
2102 Int_t ncolors = colors->GetSize();
2103
2104 // Get existing color at index n
2105 TColor *color = nullptr;
2106 if (n < ncolors) color = (TColor*)colors->At(n);
2107 if (!color) return -1;
2108
2109 // in case color is not named, assign a unique name.
2110 if (strlen(color->GetName()) == 0)
2111 color->SetName(TString::Format("Color%d",n).Data());
2112
2113 // check if the bright color already exists, if yes return it
2114 TString nameb = TString::Format("%s_bright",color->GetName()).Data();
2115 Int_t nb = GetColorByName(nameb.Data());
2116 TColor *colorb = nullptr;
2117 if (nb >= 0) {
2118 colorb = (TColor*)colors->At(nb);
2119 return colorb->GetNumber();
2120 }
2121
2122 //Get the rgb of the new bright color corresponding to color n
2123 Float_t r,g,b;
2124 HLStoRGB(color->GetHue(), 1.2f*color->GetLight(), color->GetSaturation(), r, g, b);
2125
2126 //Build the bright color
2128 colorb = new TColor(nb,r,g,b);
2129 colorb->SetName(nameb.Data());
2130 colorb->SetTitle(colorb->AsHexString());
2131 colors->AddAtAndExpand(colorb,nb);
2132 return nb;
2133}
2134
2135////////////////////////////////////////////////////////////////////////////////
2136/// Static function: Returns the dark color number corresponding to n
2137/// If the TColor object does not exist, it is created at a free color index.
2140{
2141 if (n < 0) return -1;
2142
2143 // Get list of all defined colors
2144 auto colors = (TObjArray*) gROOT->GetListOfColors();
2145 Int_t ncolors = colors->GetSize();
2146
2147 // Get existing color at index n
2148 TColor *color = nullptr;
2149 if (n < ncolors) color = (TColor*)colors->At(n);
2150 if (!color) return -1;
2151
2152 // in case color is not named, assign a unique name.
2153 if (strlen(color->GetName()) == 0)
2154 color->SetName(TString::Format("Color%d",n).Data());
2155
2156 // check if the dark color already exists, if yes return it
2157 TString named = TString::Format("%s_dark",color->GetName()).Data();
2158 Int_t nd = GetColorByName(named.Data());
2159 TColor *colord = nullptr;
2160 if (nd >= 0) {
2161 colord = (TColor*)colors->At(nd);
2162 return colord->GetNumber();
2163 }
2164
2165 //Get the rgb of the new dark color corresponding to color n
2166 Float_t r,g,b;
2167 HLStoRGB(color->GetHue(), 0.7f*color->GetLight(), color->GetSaturation(), r, g, b);
2168
2169 //Build the dark color
2171 colord = new TColor(nd,r,g,b);
2172 colord->SetName(named.Data());
2173 colord->SetTitle(colord->AsHexString());
2174 colors->AddAtAndExpand(colord,nd);
2175 return nd;
2176}
2177
2178////////////////////////////////////////////////////////////////////////////////
2179/// Static function: Returns the transparent color number corresponding to n.
2180/// The opacity level is given by the alpha value a. If a color with the same
2181/// RGBa values already exists it is returned.
2184{
2185 if (n < 0) return -1;
2186
2187 TColor *color = gROOT->GetColor(n);
2188 if (color) {
2189 TObjArray *colors = (TObjArray *)gROOT->GetListOfColors();
2190 Int_t ncolors = colors->GetSize();
2191 TColor *col = nullptr;
2192 for (Int_t i = 0; i < ncolors; i++) {
2193 col = (TColor *)colors->At(i);
2194 if (col) {
2195 if (col->GetRed() == color->GetRed() && col->GetGreen() == color->GetGreen() &&
2196 col->GetBlue() == color->GetBlue() && col->GetAlpha() == a)
2197 return col->GetNumber();
2198 }
2199 }
2200 TColor *colort = new TColor(gROOT->GetListOfColors()->GetLast()+1,
2201 color->GetRed(), color->GetGreen(), color->GetBlue());
2202 colort->SetAlpha(a);
2203 colort->SetName(TString::Format("%s_transparent",color->GetName()).Data());
2204 return colort->GetNumber();
2205 } else {
2206 ::Error("TColor::GetColorTransparent", "color with index %d not defined", n);
2207 return -1;
2208 }
2209}
2210
2211////////////////////////////////////////////////////////////////////////////////
2212/// Static function: Returns the linear gradient color number corresponding to specified parameters.
2213/// First parameter set direction as angle in grad. Value 0 is horizontal direction, 90 - vertical
2214/// List of colors defines interpolation colors for the gradient
2215/// Optional positions can define relative color positions and must be sorted array of values between 0 and 1.
2216/// If such gradient not exists - it will be created new
2217/// Returns -1 if wrong parameters where specified
2219Int_t TColor::GetLinearGradient(Double_t angle, const std::vector<Int_t> &colors, const std::vector<Double_t> &positions)
2220{
2221 if (colors.size() < 2) {
2222 ::Error("TColor::GetLinearGradient", "number of specified colors %d not enough to create gradients", (int) colors.size());
2223 return -1;
2224 }
2225
2226 std::vector<Double_t> raw_colors(colors.size()*4);
2227 std::vector<Double_t> raw_positions(colors.size());
2228 for (unsigned indx = 0; indx < colors.size(); indx++) {
2229 TColor *color = gROOT->GetColor(colors[indx]);
2230 if (!color) {
2231 ::Error("TColor::GetLinearGradient", "Not able to get %d color", (int) colors.size());
2232 return -1;
2233 }
2234 raw_colors[indx*4] = color->GetRed();
2235 raw_colors[indx*4+1] = color->GetGreen();
2236 raw_colors[indx*4+2] = color->GetBlue();
2237 raw_colors[indx*4+3] = color->GetAlpha();
2238
2239 raw_positions[indx] = indx < positions.size() ? positions[indx] : indx / (colors.size() - 1.);
2240 }
2241
2242 Double_t _cos = std::cos(angle / 180. * 3.1415), _sin = std::sin(angle / 180. * 3.1415);
2243 Double_t x0 = (_cos >= 0. ? 0. : 1.), y0 = (_sin >= 0. ? 0. : 1.);
2245
2246 TLinearGradient::Point start(x0, y0), end(x0 + _cos/scale, y0 + _sin/scale);
2247
2248
2249 TObjArray *root_colors = (TObjArray*) gROOT->GetListOfColors();
2250
2251 TIter iter(root_colors);
2252
2253 while (auto col = static_cast<TColor *>(iter())) {
2254 if (col->IsA() != TLinearGradient::Class())
2255 continue;
2256
2257 auto grad = static_cast<TLinearGradient *>(col);
2258
2259 if (grad->GetNumberOfSteps() != colors.size())
2260 continue;
2261
2262 Bool_t match = kTRUE;
2263 for (unsigned n = 0; n < raw_colors.size(); ++n)
2264 if (TMath::Abs(raw_colors[n] - grad->GetColors()[n]) > 1e-3)
2265 match = kFALSE;
2266
2267 for (unsigned n = 0; n < raw_positions.size(); ++n)
2268 if (TMath::Abs(raw_positions[n] - grad->GetColorPositions()[n]) > 1e-2)
2269 match = kFALSE;
2270
2271 if (TMath::Abs(grad->GetStart().fX - start.fX) > 1e-2 ||
2272 TMath::Abs(grad->GetStart().fY - start.fY) > 1e-2 ||
2273 TMath::Abs(grad->GetEnd().fX - end.fX) > 1e-2 ||
2274 TMath::Abs(grad->GetEnd().fY - end.fY) > 1e-2)
2275 match = kFALSE;
2276
2277 if (match)
2278 return col->GetNumber();
2279 }
2280
2281 auto grad = new TLinearGradient(root_colors->GetLast() + 1, colors.size(), raw_positions.data(), raw_colors.data());
2282
2283 grad->SetStartEnd(start, end);
2284
2285 return grad->GetNumber();
2286}
2287
2288////////////////////////////////////////////////////////////////////////////////
2289/// Static function: Returns the radial gradient color number corresponding to specified parameters.
2290/// First parameter set direction as angle in grad. Value 0 is horizontal direction, 90 - vertical
2291/// List of colors defines interpolation colors for the gradient
2292/// Optional positions can define relative color positions and must be sorted array of values between 0 and 1.
2293/// If such gradient not exists - it will be created new
2294/// Returns -1 if wrong parameter where specified
2296Int_t TColor::GetRadialGradient(Double_t radius, const std::vector<Int_t> &colors, const std::vector<Double_t> &positions)
2297{
2298 if (colors.size() < 2) {
2299 ::Error("TColor::GetRadialGradient", "number of specified colors %d not enough to create gradients", (int) colors.size());
2300 return -1;
2301 }
2302
2303 std::vector<Double_t> raw_colors(colors.size()*4);
2304 std::vector<Double_t> raw_positions(colors.size());
2305 for (unsigned indx = 0; indx < colors.size(); indx++) {
2306 TColor *color = gROOT->GetColor(colors[indx]);
2307 if (!color) {
2308 ::Error("TColor::GetRadialGradient", "Not able to get %d color", (int) colors.size());
2309 return -1;
2310 }
2311 raw_colors[indx*4] = color->GetRed();
2312 raw_colors[indx*4+1] = color->GetGreen();
2313 raw_colors[indx*4+2] = color->GetBlue();
2314 raw_colors[indx*4+3] = color->GetAlpha();
2315
2316 raw_positions[indx] = indx < positions.size() ? positions[indx] : indx / (colors.size() - 1.);
2317 }
2318
2319 TRadialGradient::Point start(0.5, 0.5);
2320
2321 TObjArray *root_colors = (TObjArray*) gROOT->GetListOfColors();
2322
2323 TIter iter(root_colors);
2324
2325 while (auto col = static_cast<TColor *>(iter())) {
2326 if (col->IsA() != TRadialGradient::Class())
2327 continue;
2328
2329 auto grad = static_cast<TRadialGradient *>(col);
2330
2331 if (grad->GetNumberOfSteps() != colors.size())
2332 continue;
2333
2334 if (grad->GetGradientType() != TRadialGradient::kSimple)
2335 continue;
2336
2337 Bool_t match = kTRUE;
2338 for (unsigned n = 0; n < raw_colors.size(); ++n)
2339 if (TMath::Abs(raw_colors[n] - grad->GetColors()[n]) > 1e-3)
2340 match = kFALSE;
2341
2342 for (unsigned n = 0; n < raw_positions.size(); ++n)
2343 if (TMath::Abs(raw_positions[n] - grad->GetColorPositions()[n]) > 1e-2)
2344 match = kFALSE;
2345
2346 if (TMath::Abs(grad->GetStart().fX - start.fX) > 1e-2 ||
2347 TMath::Abs(grad->GetStart().fY - start.fY) > 1e-2 ||
2348 TMath::Abs(grad->GetR1() - radius) > 1e-2)
2349 match = kFALSE;
2350
2351 if (match)
2352 return col->GetNumber();
2353 }
2354
2355 auto grad = new TRadialGradient(root_colors->GetLast() + 1, colors.size(), raw_positions.data(), raw_colors.data());
2356
2357 grad->SetRadialGradient(start, radius);
2358
2359 return grad->GetNumber();
2360}
2361
2362
2363////////////////////////////////////////////////////////////////////////////////
2364/// Static function: Returns the free color index greater than the highest defined color
2365/// index. All the color indices after this index are also free. It can be used to
2366/// define a user custom color.
2367///
2368/// ~~~ {.cpp}
2369/// Int_t ci = TColor::GetFreeColorIndex();
2370/// auto color = new TColor(ci, 0.1, 0.2, 0.3);
2371/// ~~~
2376}
2377
2378////////////////////////////////////////////////////////////////////////////////
2379/// Static function: Returns the first free color greater in the list of colors.
2380/// index. It can be used to define a user custom color.
2381///
2382/// ~~~ {.cpp}
2383/// Int_t ci = TColor::GetFirstFreeColorIndex();
2384/// auto color = new TColor(ci, 0.1, 0.2, 0.3);
2385/// ~~~
2388{
2389 TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
2390 const Int_t ncolors = colors->GetSize();
2391 TColor *color = nullptr;
2392 for (Int_t i = kP10Cyan+1; i<ncolors; i++) {
2393 color = (TColor*)colors->At(i);
2394 if (!color) return i;
2395 }
2396 return -1;
2397}
2398
2399////////////////////////////////////////////////////////////////////////////////
2400/// List `nb` colors from the color index `ci`.
2401/// If `nb=0` all the colors are printed.
2402/// If showEmpty is set to kTRUE, empty color indices are also printed
2405{
2406 TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
2407 const Int_t ncolors = colors->GetSize();
2408 Int_t last = ci+nb;
2409 if (nb==0 || last>=ncolors) last = ncolors;
2410 TColor *color = nullptr;
2411 Int_t nc =0 ;
2412
2413 printf(" +------+-------+-------+-------+-------+--------------------+--------------------+\n");
2414 printf(" | Idx | Red | Green | Blue | Alpha | Color Name | Color Title |\n");
2415 printf(" +------+-------+-------+-------+-------+--------------------+--------------------+\n");
2416
2417 for (Int_t i = ci; i<last; i++) {
2418 color = (TColor*)colors->At(i);
2419 if (color) {
2420 printf(" | %4d | %5.3f | %5.3f | %5.3f | %5.3f | %18s | %18s |\n", i,
2421 color->GetRed(),
2422 color->GetGreen(),
2423 color->GetBlue(),
2424 color->GetAlpha(),
2425 color->GetName(),
2426 color->GetTitle());
2427 nc++;
2428 } else if (showEmpty) {
2429 printf(" | %4d | ? | ? | ? | ? | ? | ? |\n",i);
2430 }
2431 }
2432 printf(" +------+-------+-------+-------+-------+--------------------+--------------------+\n");
2433 printf(" | Number of possible colors = %4d |\n",ncolors);
2434 printf(" | Number of defined colors between %4d and %4d = %4d |\n",ci,last,nc);
2435 printf(" | Number of free indices between %4d and %4d = %4d |\n",ci,last,last-ci-nc);
2436 printf(" +--------------------------------------------------------------------------------+\n\n");
2437
2438}
2439
2440////////////////////////////////////////////////////////////////////////////////
2441/// Static method that given a color index number, returns the corresponding
2442/// pixel value. This pixel value can be used in the GUI classes. This call
2443/// does not work in batch mode since it needs to communicate with the
2444/// graphics system.
2447{
2449 TColor *color = gROOT->GetColor(ci);
2450 if (color)
2451 return color->GetPixel();
2452 else
2453 ::Warning("TColor::Number2Pixel", "color with index %d not defined", ci);
2454
2455 return 0;
2456}
2457
2458////////////////////////////////////////////////////////////////////////////////
2459/// Convert r,g,b to graphics system dependent pixel value.
2460/// The r,g,b triplet must be [0,1].
2463{
2464 if (r < 0) r = 0;
2465 if (g < 0) g = 0;
2466 if (b < 0) b = 0;
2467 if (r > 1) r = 1;
2468 if (g > 1) g = 1;
2469 if (b > 1) b = 1;
2470
2471 ColorStruct_t color;
2472 color.fRed = UShort_t(r * 65535);
2473 color.fGreen = UShort_t(g * 65535);
2474 color.fBlue = UShort_t(b * 65535);
2475 color.fMask = kDoRed | kDoGreen | kDoBlue;
2476 gVirtualX->AllocColor(gVirtualX->GetColormap(), color);
2477 return color.fPixel;
2478}
2479
2480////////////////////////////////////////////////////////////////////////////////
2481/// Convert r,g,b to graphics system dependent pixel value.
2482/// The r,g,b triplet must be [0,255].
2485{
2486 if (r < 0) r = 0;
2487 if (g < 0) g = 0;
2488 if (b < 0) b = 0;
2489 if (r > 255) r = 255;
2490 if (g > 255) g = 255;
2491 if (b > 255) b = 255;
2492
2493 ColorStruct_t color;
2494 color.fRed = UShort_t(r * 256); // 65536/256
2495 color.fGreen = UShort_t(g * 256);
2496 color.fBlue = UShort_t(b * 256);
2497 color.fMask = kDoRed | kDoGreen | kDoBlue;
2498 gVirtualX->AllocColor(gVirtualX->GetColormap(), color);
2499 return color.fPixel;
2500}
2501
2502////////////////////////////////////////////////////////////////////////////////
2503/// Convert machine dependent pixel value (obtained via RGB2Pixel or
2504/// via Number2Pixel() or via TColor::GetPixel()) to r,g,b triplet.
2505/// The r,g,b triplet will be [0,1].
2508{
2509 ColorStruct_t color;
2510 color.fPixel = pixel;
2511 gVirtualX->QueryColor(gVirtualX->GetColormap(), color);
2512 r = (Float_t)color.fRed / 65535.0f;
2513 g = (Float_t)color.fGreen / 65535.0f;
2514 b = (Float_t)color.fBlue / 65535.0f;
2515}
2516
2517////////////////////////////////////////////////////////////////////////////////
2518/// Convert machine dependent pixel value (obtained via RGB2Pixel or
2519/// via Number2Pixel() or via TColor::GetPixel()) to r,g,b triplet.
2520/// The r,g,b triplet will be [0,255].
2523{
2524 ColorStruct_t color;
2525 color.fPixel = pixel;
2526 gVirtualX->QueryColor(gVirtualX->GetColormap(), color);
2527 // color is between 0 and 65535 inclusive.
2528 // We need to move it to the 0 to 255 range (inclusive).
2529 // So we need to resample the 65536 values into 256 indices.
2530 // This would mean equal blocks of 256 high-res values per color index.
2531 r = color.fRed / 256;
2532 g = color.fGreen / 256;
2533 b = color.fBlue / 256;
2534}
2535
2536////////////////////////////////////////////////////////////////////////////////
2537/// Convert machine dependent pixel value (obtained via RGB2Pixel or
2538/// via Number2Pixel() or via TColor::GetPixel()) to a hexadecimal string.
2539/// This string can be directly passed to, for example,
2540/// TGClient::GetColorByName(). String will be reused so copy immediately
2541/// if needed.
2544{
2545 static TString tempbuf;
2546 Int_t r, g, b;
2547 Pixel2RGB(pixel, r, g, b);
2548 tempbuf.Form("#%02x%02x%02x", r, g, b);
2549 return tempbuf;
2550}
2551
2552////////////////////////////////////////////////////////////////////////////////
2553/// Convert color in C++ statement which can be used in SetColor directives
2554/// Produced statement either includes TColor::GetColor() invocation or just plain color index as integer
2555/// Method should be used is SavePrimitive methods for color storage
2558{
2559 TColor *c = ci <= 228 ? nullptr : gROOT->GetColor(ci);
2560 if (!c)
2561 return TString::Format("%d", ci);
2562
2563 Float_t r, g, b, a;
2564
2565 c->GetRGB(r, g, b);
2566 a = c->GetAlpha();
2567 Int_t ri = (Int_t)(255 * r), gi = (Int_t)(255 * g), bi = (Int_t)(255 * b), ai = (Int_t)(255 * a);
2568
2569 if (ai < 255)
2570 return TString::Format("TColor::GetColor(\"#%02x%02x%02x%02x\")", ri, gi, bi, ai);
2571
2572 return TString::Format("TColor::GetColor(\"#%02x%02x%02x\")", ri, gi, bi);
2573}
2574
2575////////////////////////////////////////////////////////////////////////////////
2576/// Save a color with index > 228 as a C++ statement(s) on output stream out.
2577/// Return kFALSE if color not saved in the output stream
2578/// Consider use of SavePrimitiveColor() method instead
2580Bool_t TColor::SaveColor(std::ostream &out, Int_t ci)
2581{
2582 if ((ci <= 228) || !gROOT->GetColor(ci))
2583 return kFALSE;
2584
2585 if (gROOT->ClassSaved(TColor::Class()))
2586 out << " ci = ";
2587 else
2588 out << " Int_t ci = ";
2589
2590 out << SavePrimitiveColor(ci) << ";\n";
2591
2592 return kTRUE;
2593}
2594
2595////////////////////////////////////////////////////////////////////////////////
2596/// Return whether all colors return grayscale values.
2598{
2599 return fgGrayscaleMode;
2600}
2601
2602////////////////////////////////////////////////////////////////////////////////
2603/// Set whether all colors should return grayscale values.
2605void TColor::SetGrayscale(Bool_t set /*= kTRUE*/)
2606{
2607 if (fgGrayscaleMode == set) return;
2608
2609 fgGrayscaleMode = set;
2610
2611 if (!gVirtualX || gROOT->IsBatch()) return;
2612
2614 TIter iColor(gROOT->GetListOfColors());
2615 TColor* color = nullptr;
2616 while ((color = (TColor*) iColor()))
2617 color->Allocate();
2618}
2619
2620////////////////////////////////////////////////////////////////////////////////
2621/// \brief Static function creating a color palette based on an input text file.
2622///
2623/// Every color in the file will take the same amount of space in the palette.
2624///
2625/// \see https://doi.org/10.1038/s41467-020-19160-7
2626/// \note This function is designed to load into ROOT the colour-vision
2627/// deficiency friendly and perceptually uniform colour maps specially designed
2628/// in https://doi.org/10.5281/zenodo.4491293, namely the .txt files stored
2629/// in the subfolders of ScientificColourMaps7.zip, e.g. batlow/batlow.txt
2630///
2631/// \param fileName: Name of a .txt file (ASCII) containing three floats per
2632/// line, separated by spaces, namely the r g b fractions of the color, each
2633/// value being in the range [0,1].
2634/// \param alpha the global opacity for all colors within this palette
2635/// \return a positive value on success and -1 on error.
2636/// \author Fernando Hueso-González
2638{
2639 std::ifstream f(fileName.Data());
2640 if (!f.good()) {
2641 ::Error("TColor::CreateColorPalette(const TString)", "%s does not exist or cannot be opened", fileName.Data());
2642 return -1;
2643 }
2644
2645 Int_t nLines = 0;
2646 Float_t r, g, b;
2647 std::vector<Float_t> reds, greens, blues;
2648 while (f >> r >> g >> b) {
2649 nLines++;
2650 if (r < 0. || r > 1.) {
2651 ::Error("TColor::CreateColorPalette(const TString)", "Red value %f outside [0,1] on line %d of %s ", r,
2652 nLines, fileName.Data());
2653 f.close();
2654 return -1;
2655 }
2656 if (g < 0. || g > 1.) {
2657 ::Error("TColor::CreateColorPalette(const TString)", "Green value %f outside [0,1] on line %d of %s ", g,
2658 nLines, fileName.Data());
2659 f.close();
2660 return -1;
2661 }
2662 if (b < 0. || b > 1.) {
2663 ::Error("TColor::CreateColorPalette(const TString)", "Blue value %f outside [0,1] on line %d of %s ", b,
2664 nLines, fileName.Data());
2665 f.close();
2666 return -1;
2667 }
2668 reds.emplace_back(r);
2669 greens.emplace_back(g);
2670 blues.emplace_back(b);
2671 }
2672 f.close();
2673 if (nLines < 2) {
2674 ::Error("TColor::CreateColorPalette(const TString)", "Found insufficient color lines (%d) on %s", nLines,
2675 fileName.Data());
2676 return -1;
2677 }
2678
2680 Int_t *palette = new Int_t[nLines];
2681
2682 for (Int_t i = 0; i < nLines; ++i) {
2683 new TColor(reds.at(i), greens.at(i), blues.at(i), alpha);
2685 }
2687 delete[] palette;
2688 return gHighestColorIndex + 1 - nLines;
2689}
2690
2691////////////////////////////////////////////////////////////////////////////////
2692/// Static function creating a color table with several connected linear gradients.
2693///
2694/// - Number: The number of end point colors that will form the gradients.
2695/// Must be at least 2.
2696/// - Stops: Where in the whole table the end point colors should lie.
2697/// Each entry must be on [0, 1], each entry must be greater than
2698/// the previous entry.
2699/// - Red, Green, Blue: The end point color values.
2700/// Each entry must be on [0, 1]
2701/// - NColors: Total number of colors in the table. Must be at least 1.
2702/// - alpha: the opacity factor, between 0 and 1. Default is no transparency (1).
2703/// - setPalette: activate the newly created palette (true by default). If false,
2704/// the caller is in charge of calling TColor::SetPalette using the
2705/// return value of the function (first palette color index) and
2706/// reconstructing the Int_t palette[NColors+1] array.
2707///
2708/// Returns a positive value (the index of the first color of the palette) on
2709/// success and -1 on error.
2710///
2711/// The table is constructed by tracing lines between the given points in
2712/// RGB space. Each color value may have a value between 0 and 1. The
2713/// difference between consecutive "Stops" values gives the fraction of
2714/// space in the whole table that should be used for the interval between
2715/// the corresponding color values.
2716///
2717/// Normally the first element of Stops should be 0 and the last should be 1.
2718/// If this is not true, fewer than NColors will be used in proportion with
2719/// the total interval between the first and last elements of Stops.
2720///
2721/// This definition is similar to the povray-definition of gradient
2722/// color tables.
2723///
2724/// For instance:
2725/// ~~~ {.cpp}
2726/// UInt_t Number = 3;
2727/// Double_t Red[3] = { 0.0, 1.0, 1.0 };
2728/// Double_t Green[3] = { 0.0, 0.0, 1.0 };
2729/// Double_t Blue[3] = { 1.0, 0.0, 1.0 };
2730/// Double_t Stops[3] = { 0.0, 0.4, 1.0 };
2731/// ~~~
2732/// This defines a table in which there are three color end points:
2733/// RGB = {0, 0, 1}, {1, 0, 0}, and {1, 1, 1} = blue, red, white
2734/// The first 40% of the table is used to go linearly from blue to red.
2735/// The remaining 60% of the table is used to go linearly from red to white.
2736///
2737/// If you define a very short interval such that less than one color fits
2738/// in it, no colors at all will be allocated. If this occurs for all
2739/// intervals, ROOT will revert to the default palette.
2740///
2741/// Original code by Andreas Zoglauer (zog@mpe.mpg.de)
2744 Double_t* Red, Double_t* Green,
2745 Double_t* Blue, UInt_t NColors, Float_t alpha,
2747{
2749
2750 UInt_t g, c;
2751 UInt_t nPalette = 0;
2752 Int_t *palette = new Int_t[NColors+1];
2754
2755 if(Number < 2 || NColors < 1){
2756 delete [] palette;
2757 return -1;
2758 }
2759
2760 // Check if all RGB values are between 0.0 and 1.0 and
2761 // Stops goes from 0.0 to 1.0 in increasing order.
2762 for (c = 0; c < Number; c++) {
2763 if (Red[c] < 0 || Red[c] > 1.0 ||
2764 Green[c] < 0 || Green[c] > 1.0 ||
2765 Blue[c] < 0 || Blue[c] > 1.0 ||
2766 Stops[c] < 0 || Stops[c] > 1.0) {
2767 delete [] palette;
2768 return -1;
2769 }
2770 if (c >= 1) {
2771 if (Stops[c-1] > Stops[c]) {
2772 delete [] palette;
2773 return -1;
2774 }
2775 }
2776 }
2777
2778 // Now create the colors and add them to the default palette:
2779
2780 // For each defined gradient...
2781 for (g = 1; g < Number; g++) {
2782 // create the colors...
2783 nColorsGradient = (Int_t) (floor(NColors*Stops[g]) - floor(NColors*Stops[g-1]));
2784 for (c = 0; c < nColorsGradient; c++) {
2785 new TColor( Float_t(Red[g-1] + c * (Red[g] - Red[g-1]) / nColorsGradient),
2786 Float_t(Green[g-1] + c * (Green[g] - Green[g-1])/ nColorsGradient),
2787 Float_t(Blue[g-1] + c * (Blue[g] - Blue[g-1]) / nColorsGradient),
2788 alpha);
2790 nPalette++;
2791 }
2792 }
2793
2794 if (setPalette)
2796 delete [] palette;
2797 return gHighestColorIndex + 1 - NColors;
2798}
2799
2800
2801////////////////////////////////////////////////////////////////////////////////
2802/// Static function.
2803/// The color palette is used by the histogram classes
2804/// (see TH1::Draw options).
2805/// For example TH1::Draw("col") draws a 2-D histogram with cells
2806/// represented by a box filled with a color CI function of the cell content.
2807/// if the cell content is N, the color CI used will be the color number
2808/// in colors[N],etc. If the maximum cell content is > ncolors, all
2809/// cell contents are scaled to ncolors.
2810///
2811/// `if ncolors <= 0` a default palette (see below) of 50 colors is
2812/// defined. The colors defined in this palette are OK for coloring pads, labels.
2813///
2814/// ~~~ {.cpp}
2815/// index 0->9 : grey colors from light to dark grey
2816/// index 10->19 : "brown" colors
2817/// index 20->29 : "blueish" colors
2818/// index 30->39 : "redish" colors
2819/// index 40->49 : basic colors
2820/// ~~~
2821///
2822/// `if ncolors == 1 && colors == 0`, a Rainbow Color map is created
2823/// with 50 colors. It is kept for backward compatibility. Better palettes like
2824/// kBird are recommended.
2825///
2826/// High quality predefined palettes with 255 colors are available when `colors == 0`.
2827/// The following value of `ncolors` give access to:
2828///
2829/// ~~~ {.cpp}
2830/// if ncolors = 51 and colors=0, a Deep Sea palette is used.
2831/// if ncolors = 52 and colors=0, a Grey Scale palette is used.
2832/// if ncolors = 53 and colors=0, a Dark Body Radiator palette is used.
2833/// if ncolors = 54 and colors=0, a Two-Color Hue palette is used.(dark blue through neutral gray to bright yellow)
2834/// if ncolors = 55 and colors=0, a Rain Bow palette is used.
2835/// if ncolors = 56 and colors=0, an Inverted Dark Body Radiator palette is used.
2836/// if ncolors = 57 and colors=0, a monotonically increasing L value palette is used.
2837/// if ncolors = 58 and colors=0, a Cubehelix palette is used
2838/// (Cf. Dave Green's "cubehelix" colour scheme at http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/)
2839/// if ncolors = 59 and colors=0, a Green Red Violet palette is used.
2840/// if ncolors = 60 and colors=0, a Blue Red Yellow palette is used.
2841/// if ncolors = 61 and colors=0, an Ocean palette is used.
2842/// if ncolors = 62 and colors=0, a Color Printable On Grey palette is used.
2843/// if ncolors = 63 and colors=0, an Alpine palette is used.
2844/// if ncolors = 64 and colors=0, an Aquamarine palette is used.
2845/// if ncolors = 65 and colors=0, an Army palette is used.
2846/// if ncolors = 66 and colors=0, an Atlantic palette is used.
2847/// if ncolors = 67 and colors=0, an Aurora palette is used.
2848/// if ncolors = 68 and colors=0, an Avocado palette is used.
2849/// if ncolors = 69 and colors=0, a Beach palette is used.
2850/// if ncolors = 70 and colors=0, a Black Body palette is used.
2851/// if ncolors = 71 and colors=0, a Blue Green Yellow palette is used.
2852/// if ncolors = 72 and colors=0, a Brown Cyan palette is used.
2853/// if ncolors = 73 and colors=0, a CMYK palette is used.
2854/// if ncolors = 74 and colors=0, a Candy palette is used.
2855/// if ncolors = 75 and colors=0, a Cherry palette is used.
2856/// if ncolors = 76 and colors=0, a Coffee palette is used.
2857/// if ncolors = 77 and colors=0, a Dark Rain Bow palette is used.
2858/// if ncolors = 78 and colors=0, a Dark Terrain palette is used.
2859/// if ncolors = 79 and colors=0, a Fall palette is used.
2860/// if ncolors = 80 and colors=0, a Fruit Punch palette is used.
2861/// if ncolors = 81 and colors=0, a Fuchsia palette is used.
2862/// if ncolors = 82 and colors=0, a Grey Yellow palette is used.
2863/// if ncolors = 83 and colors=0, a Green Brown Terrain palette is used.
2864/// if ncolors = 84 and colors=0, a Green Pink palette is used.
2865/// if ncolors = 85 and colors=0, an Island palette is used.
2866/// if ncolors = 86 and colors=0, a Lake palette is used.
2867/// if ncolors = 87 and colors=0, a Light Temperature palette is used.
2868/// if ncolors = 88 and colors=0, a Light Terrain palette is used.
2869/// if ncolors = 89 and colors=0, a Mint palette is used.
2870/// if ncolors = 90 and colors=0, a Neon palette is used.
2871/// if ncolors = 91 and colors=0, a Pastel palette is used.
2872/// if ncolors = 92 and colors=0, a Pearl palette is used.
2873/// if ncolors = 93 and colors=0, a Pigeon palette is used.
2874/// if ncolors = 94 and colors=0, a Plum palette is used.
2875/// if ncolors = 95 and colors=0, a Red Blue palette is used.
2876/// if ncolors = 96 and colors=0, a Rose palette is used.
2877/// if ncolors = 97 and colors=0, a Rust palette is used.
2878/// if ncolors = 98 and colors=0, a Sandy Terrain palette is used.
2879/// if ncolors = 99 and colors=0, a Sienna palette is used.
2880/// if ncolors = 100 and colors=0, a Solar palette is used.
2881/// if ncolors = 101 and colors=0, a South West palette is used.
2882/// if ncolors = 102 and colors=0, a Starry Night palette is used.
2883/// if ncolors = 103 and colors=0, a Sunset palette is used.
2884/// if ncolors = 104 and colors=0, a Temperature Map palette is used.
2885/// if ncolors = 105 and colors=0, a Thermometer palette is used.
2886/// if ncolors = 106 and colors=0, a Valentine palette is used.
2887/// if ncolors = 107 and colors=0, a Visible Spectrum palette is used.
2888/// if ncolors = 108 and colors=0, a Water Melon palette is used.
2889/// if ncolors = 109 and colors=0, a Cool palette is used.
2890/// if ncolors = 110 and colors=0, a Copper palette is used.
2891/// if ncolors = 111 and colors=0, a Gist Earth palette is used.
2892/// if ncolors = 112 and colors=0, a Viridis palette is used.
2893/// if ncolors = 113 and colors=0, a Cividis palette is used.
2894/// ~~~
2895/// These palettes can also be accessed by names:
2896/// ~~~ {.cpp}
2897/// kDeepSea=51, kGreyScale=52, kDarkBodyRadiator=53,
2898/// kBlueYellow= 54, kRainBow=55, kInvertedDarkBodyRadiator=56,
2899/// kBird=57, kCubehelix=58, kGreenRedViolet=59,
2900/// kBlueRedYellow=60, kOcean=61, kColorPrintableOnGrey=62,
2901/// kAlpine=63, kAquamarine=64, kArmy=65,
2902/// kAtlantic=66, kAurora=67, kAvocado=68,
2903/// kBeach=69, kBlackBody=70, kBlueGreenYellow=71,
2904/// kBrownCyan=72, kCMYK=73, kCandy=74,
2905/// kCherry=75, kCoffee=76, kDarkRainBow=77,
2906/// kDarkTerrain=78, kFall=79, kFruitPunch=80,
2907/// kFuchsia=81, kGreyYellow=82, kGreenBrownTerrain=83,
2908/// kGreenPink=84, kIsland=85, kLake=86,
2909/// kLightTemperature=87, kLightTerrain=88, kMint=89,
2910/// kNeon=90, kPastel=91, kPearl=92,
2911/// kPigeon=93, kPlum=94, kRedBlue=95,
2912/// kRose=96, kRust=97, kSandyTerrain=98,
2913/// kSienna=99, kSolar=100, kSouthWest=101,
2914/// kStarryNight=102, kSunset=103, kTemperatureMap=104,
2915/// kThermometer=105, kValentine=106, kVisibleSpectrum=107,
2916/// kWaterMelon=108, kCool=109, kCopper=110,
2917/// kGistEarth=111 kViridis=112, kCividis=113
2918/// ~~~
2919/// For example:
2920/// ~~~ {.cpp}
2921/// gStyle->SetPalette(kBird);
2922/// ~~~
2923/// Set the current palette as "Bird" (number 57).
2924///
2925/// The color numbers specified in the palette can be viewed by selecting
2926/// the item "colors" in the "VIEW" menu of the canvas toolbar.
2927/// The color parameters can be changed via TColor::SetRGB.
2928///
2929/// Note that when drawing a 2D histogram `h2` with the option "COL" or
2930/// "COLZ" or with any "CONT" options using the color map, the number of colors
2931/// used is defined by the number of contours `n` specified with:
2932/// `h2->SetContour(n)`
2934void TColor::SetPalette(Int_t ncolors, Int_t *colors, Float_t alpha)
2935{
2936 Int_t i;
2937
2938 Int_t palette[50] = {19,18,17,16,15,14,13,12,11,20,
2939 21,22,23,24,25,26,27,28,29,30, 8,
2940 31,32,33,34,35,36,37,38,39,40, 9,
2941 41,42,43,44,45,47,48,49,46,50, 2,
2942 7, 6, 5, 4, 3, 2,1};
2943
2944 // set default palette (pad type)
2945 if (ncolors <= 0) {
2946 ncolors = 50;
2947 fgPalette.Set(ncolors);
2948 for (i=0;i<ncolors;i++) fgPalette.fArray[i] = palette[i];
2949 gPaletteType = 1;
2950 return;
2951 }
2952
2953 // set Rainbow Color map. Kept for backward compatibility.
2954 if (ncolors == 1 && colors == nullptr) {
2955 ncolors = 50;
2956 fgPalette.Set(ncolors);
2957 for (i=0;i<ncolors-1;i++) fgPalette.fArray[i] = 51+i;
2958 fgPalette.fArray[ncolors-1] = kRed; // the last color of this palette is red
2959 gPaletteType = 2;
2960 return;
2961 }
2962
2963 // High quality palettes (255 levels)
2964 if (colors == nullptr && ncolors>50) {
2965
2966 if (!fgPalettesList.fN) fgPalettesList.Set(63); // Right now 63 high quality palettes
2967 Int_t Idx = (Int_t)fgPalettesList.fArray[ncolors-51]; // High quality palettes indices start at 51
2968
2969 // This high quality palette has already been created. Reuse it.
2970 if (Idx > 0) {
2971 Double_t alphas = 10*(fgPalettesList.fArray[ncolors-51]-Idx);
2972 Bool_t same_alpha = TMath::Abs(alpha-alphas) < 0.0001;
2973 if (gPaletteType == ncolors && same_alpha) return; // The current palette is already this one.
2974 fgPalette.Set(255); // High quality palettes have 255 entries
2975 for (i=0;i<255;i++) fgPalette.fArray[i] = Idx+i;
2976 gPaletteType = ncolors;
2977
2978 // restore the palette transparency if needed
2979 if (alphas>0 && !same_alpha) {
2980 TColor *ca;
2981 for (i=0;i<255;i++) {
2982 ca = gROOT->GetColor(Idx+i);
2983 ca->SetAlpha(alpha);
2984 }
2985 fgPalettesList.fArray[gPaletteType-51] = (Double_t)Idx+alpha/10.;
2986 }
2987 return;
2988 }
2989
2991 Double_t stops[9] = { 0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000};
2992
2993 switch (ncolors) {
2994 // Deep Sea
2995 case 51:
2996 {
2997 Double_t red[9] = { 0./255., 9./255., 13./255., 17./255., 24./255., 32./255., 27./255., 25./255., 29./255.};
2998 Double_t green[9] = { 0./255., 0./255., 0./255., 2./255., 37./255., 74./255., 113./255., 160./255., 221./255.};
2999 Double_t blue[9] = { 28./255., 42./255., 59./255., 78./255., 98./255., 129./255., 154./255., 184./255., 221./255.};
3000 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3001 }
3002 break;
3003
3004 // Grey Scale
3005 case 52:
3006 {
3007 Double_t red[9] = { 0./255., 32./255., 64./255., 96./255., 128./255., 160./255., 192./255., 224./255., 255./255.};
3008 Double_t green[9] = { 0./255., 32./255., 64./255., 96./255., 128./255., 160./255., 192./255., 224./255., 255./255.};
3009 Double_t blue[9] = { 0./255., 32./255., 64./255., 96./255., 128./255., 160./255., 192./255., 224./255., 255./255.};
3010 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3011 }
3012 break;
3013
3014 // Dark Body Radiator
3015 case 53:
3016 {
3017 Double_t red[9] = { 0./255., 45./255., 99./255., 156./255., 212./255., 230./255., 237./255., 234./255., 242./255.};
3018 Double_t green[9] = { 0./255., 0./255., 0./255., 45./255., 101./255., 168./255., 238./255., 238./255., 243./255.};
3019 Double_t blue[9] = { 0./255., 1./255., 1./255., 3./255., 9./255., 8./255., 11./255., 95./255., 230./255.};
3020 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3021 }
3022 break;
3023
3024 // Two-color hue (dark blue through neutral gray to bright yellow)
3025 case 54:
3026 {
3027 Double_t red[9] = { 0./255., 22./255., 44./255., 68./255., 93./255., 124./255., 160./255., 192./255., 237./255.};
3028 Double_t green[9] = { 0./255., 16./255., 41./255., 67./255., 93./255., 125./255., 162./255., 194./255., 241./255.};
3029 Double_t blue[9] = { 97./255., 100./255., 99./255., 99./255., 93./255., 68./255., 44./255., 26./255., 74./255.};
3030 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3031 }
3032 break;
3033
3034 // Rain Bow
3035 case 55:
3036 {
3037 Double_t red[9] = { 0./255., 5./255., 15./255., 35./255., 102./255., 196./255., 208./255., 199./255., 110./255.};
3038 Double_t green[9] = { 0./255., 48./255., 124./255., 192./255., 206./255., 226./255., 97./255., 16./255., 0./255.};
3039 Double_t blue[9] = { 99./255., 142./255., 198./255., 201./255., 90./255., 22./255., 13./255., 8./255., 2./255.};
3040 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3041 }
3042 break;
3043
3044 // Inverted Dark Body Radiator
3045 case 56:
3046 {
3047 Double_t red[9] = { 242./255., 234./255., 237./255., 230./255., 212./255., 156./255., 99./255., 45./255., 0./255.};
3048 Double_t green[9] = { 243./255., 238./255., 238./255., 168./255., 101./255., 45./255., 0./255., 0./255., 0./255.};
3049 Double_t blue[9] = { 230./255., 95./255., 11./255., 8./255., 9./255., 3./255., 1./255., 1./255., 0./255.};
3050 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3051 }
3052 break;
3053
3054 // Bird
3055 case 57:
3056 {
3057 Double_t red[9] = { 0.2082, 0.0592, 0.0780, 0.0232, 0.1802, 0.5301, 0.8186, 0.9956, 0.9764};
3058 Double_t green[9] = { 0.1664, 0.3599, 0.5041, 0.6419, 0.7178, 0.7492, 0.7328, 0.7862, 0.9832};
3059 Double_t blue[9] = { 0.5293, 0.8684, 0.8385, 0.7914, 0.6425, 0.4662, 0.3499, 0.1968, 0.0539};
3060 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3061 }
3062 break;
3063
3064 // Cubehelix
3065 case 58:
3066 {
3067 Double_t red[9] = { 0.0000, 0.0956, 0.0098, 0.2124, 0.6905, 0.9242, 0.7914, 0.7596, 1.0000};
3068 Double_t green[9] = { 0.0000, 0.1147, 0.3616, 0.5041, 0.4577, 0.4691, 0.6905, 0.9237, 1.0000};
3069 Double_t blue[9] = { 0.0000, 0.2669, 0.3121, 0.1318, 0.2236, 0.6741, 0.9882, 0.9593, 1.0000};
3070 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3071 }
3072 break;
3073
3074 // Green Red Violet
3075 case 59:
3076 {
3077 Double_t red[9] = {13./255., 23./255., 25./255., 63./255., 76./255., 104./255., 137./255., 161./255., 206./255.};
3078 Double_t green[9] = {95./255., 67./255., 37./255., 21./255., 0./255., 12./255., 35./255., 52./255., 79./255.};
3079 Double_t blue[9] = { 4./255., 3./255., 2./255., 6./255., 11./255., 22./255., 49./255., 98./255., 208./255.};
3080 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3081 }
3082 break;
3083
3084 // Blue Red Yellow
3085 case 60:
3086 {
3087 Double_t red[9] = {0./255., 61./255., 89./255., 122./255., 143./255., 160./255., 185./255., 204./255., 231./255.};
3088 Double_t green[9] = {0./255., 0./255., 0./255., 0./255., 14./255., 37./255., 72./255., 132./255., 235./255.};
3089 Double_t blue[9] = {0./255., 140./255., 224./255., 144./255., 4./255., 5./255., 6./255., 9./255., 13./255.};
3090 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3091 }
3092 break;
3093
3094 // Ocean
3095 case 61:
3096 {
3097 Double_t red[9] = { 14./255., 7./255., 2./255., 0./255., 5./255., 11./255., 55./255., 131./255., 229./255.};
3098 Double_t green[9] = {105./255., 56./255., 26./255., 1./255., 42./255., 74./255., 131./255., 171./255., 229./255.};
3099 Double_t blue[9] = { 2./255., 21./255., 35./255., 60./255., 92./255., 113./255., 160./255., 185./255., 229./255.};
3100 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3101 }
3102 break;
3103
3104 // Color Printable On Grey
3105 case 62:
3106 {
3107 Double_t red[9] = { 0./255., 0./255., 0./255., 70./255., 148./255., 231./255., 235./255., 237./255., 244./255.};
3108 Double_t green[9] = { 0./255., 0./255., 0./255., 0./255., 0./255., 69./255., 67./255., 216./255., 244./255.};
3109 Double_t blue[9] = { 0./255., 102./255., 228./255., 231./255., 177./255., 124./255., 137./255., 20./255., 244./255.};
3110 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3111 }
3112 break;
3113
3114 // Alpine
3115 case 63:
3116 {
3117 Double_t red[9] = { 50./255., 56./255., 63./255., 68./255., 93./255., 121./255., 165./255., 192./255., 241./255.};
3118 Double_t green[9] = { 66./255., 81./255., 91./255., 96./255., 111./255., 128./255., 155./255., 189./255., 241./255.};
3119 Double_t blue[9] = { 97./255., 91./255., 75./255., 65./255., 77./255., 103./255., 143./255., 167./255., 217./255.};
3120 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3121 }
3122 break;
3123
3124 // Aquamarine
3125 case 64:
3126 {
3127 Double_t red[9] = { 145./255., 166./255., 167./255., 156./255., 131./255., 114./255., 101./255., 112./255., 132./255.};
3128 Double_t green[9] = { 158./255., 178./255., 179./255., 181./255., 163./255., 154./255., 144./255., 152./255., 159./255.};
3129 Double_t blue[9] = { 190./255., 199./255., 201./255., 192./255., 176./255., 169./255., 160./255., 166./255., 190./255.};
3130 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3131 }
3132 break;
3133
3134 // Army
3135 case 65:
3136 {
3137 Double_t red[9] = { 93./255., 91./255., 99./255., 108./255., 130./255., 125./255., 132./255., 155./255., 174./255.};
3138 Double_t green[9] = { 126./255., 124./255., 128./255., 129./255., 131./255., 121./255., 119./255., 153./255., 173./255.};
3139 Double_t blue[9] = { 103./255., 94./255., 87./255., 85./255., 80./255., 85./255., 107./255., 120./255., 146./255.};
3140 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3141 }
3142 break;
3143
3144 // Atlantic
3145 case 66:
3146 {
3147 Double_t red[9] = { 24./255., 40./255., 69./255., 90./255., 104./255., 114./255., 120./255., 132./255., 103./255.};
3148 Double_t green[9] = { 29./255., 52./255., 94./255., 127./255., 150./255., 162./255., 159./255., 151./255., 101./255.};
3149 Double_t blue[9] = { 29./255., 52./255., 96./255., 132./255., 162./255., 181./255., 184./255., 186./255., 131./255.};
3150 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3151 }
3152 break;
3153
3154 // Aurora
3155 case 67:
3156 {
3157 Double_t red[9] = { 46./255., 38./255., 61./255., 92./255., 113./255., 121./255., 132./255., 150./255., 191./255.};
3158 Double_t green[9] = { 46./255., 36./255., 40./255., 69./255., 110./255., 135./255., 131./255., 92./255., 34./255.};
3159 Double_t blue[9] = { 46./255., 80./255., 74./255., 70./255., 81./255., 105./255., 165./255., 211./255., 225./255.};
3160 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3161 }
3162 break;
3163
3164 // Avocado
3165 case 68:
3166 {
3167 Double_t red[9] = { 0./255., 4./255., 12./255., 30./255., 52./255., 101./255., 142./255., 190./255., 237./255.};
3168 Double_t green[9] = { 0./255., 40./255., 86./255., 121./255., 140./255., 172./255., 187./255., 213./255., 240./255.};
3169 Double_t blue[9] = { 0./255., 9./255., 14./255., 18./255., 21./255., 23./255., 27./255., 35./255., 101./255.};
3170 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3171 }
3172 break;
3173
3174 // Beach
3175 case 69:
3176 {
3177 Double_t red[9] = { 198./255., 206./255., 206./255., 211./255., 198./255., 181./255., 161./255., 171./255., 244./255.};
3178 Double_t green[9] = { 103./255., 133./255., 150./255., 172./255., 178./255., 174./255., 163./255., 175./255., 244./255.};
3179 Double_t blue[9] = { 49./255., 54./255., 55./255., 66./255., 91./255., 130./255., 184./255., 224./255., 244./255.};
3180 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3181 }
3182 break;
3183
3184 // Black Body
3185 case 70:
3186 {
3187 Double_t red[9] = { 243./255., 243./255., 240./255., 240./255., 241./255., 239./255., 186./255., 151./255., 129./255.};
3188 Double_t green[9] = { 0./255., 46./255., 99./255., 149./255., 194./255., 220./255., 183./255., 166./255., 147./255.};
3189 Double_t blue[9] = { 6./255., 8./255., 36./255., 91./255., 169./255., 235./255., 246./255., 240./255., 233./255.};
3190 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3191 }
3192 break;
3193
3194 // Blue Green Yellow
3195 case 71:
3196 {
3197 Double_t red[9] = { 22./255., 19./255., 19./255., 25./255., 35./255., 53./255., 88./255., 139./255., 210./255.};
3198 Double_t green[9] = { 0./255., 32./255., 69./255., 108./255., 135./255., 159./255., 183./255., 198./255., 215./255.};
3199 Double_t blue[9] = { 77./255., 96./255., 110./255., 116./255., 110./255., 100./255., 90./255., 78./255., 70./255.};
3200 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3201 }
3202 break;
3203
3204 // Brown Cyan
3205 case 72:
3206 {
3207 Double_t red[9] = { 68./255., 116./255., 165./255., 182./255., 189./255., 180./255., 145./255., 111./255., 71./255.};
3208 Double_t green[9] = { 37./255., 82./255., 135./255., 178./255., 204./255., 225./255., 221./255., 202./255., 147./255.};
3209 Double_t blue[9] = { 16./255., 55./255., 105./255., 147./255., 196./255., 226./255., 232./255., 224./255., 178./255.};
3210 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3211 }
3212 break;
3213
3214 // CMYK
3215 case 73:
3216 {
3217 Double_t red[9] = { 61./255., 99./255., 136./255., 181./255., 213./255., 225./255., 198./255., 136./255., 24./255.};
3218 Double_t green[9] = { 149./255., 140./255., 96./255., 83./255., 132./255., 178./255., 190./255., 135./255., 22./255.};
3219 Double_t blue[9] = { 214./255., 203./255., 168./255., 135./255., 110./255., 100./255., 111./255., 113./255., 22./255.};
3220 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3221 }
3222 break;
3223
3224 // Candy
3225 case 74:
3226 {
3227 Double_t red[9] = { 76./255., 120./255., 156./255., 183./255., 197./255., 180./255., 162./255., 154./255., 140./255.};
3228 Double_t green[9] = { 34./255., 35./255., 42./255., 69./255., 102./255., 137./255., 164./255., 188./255., 197./255.};
3229 Double_t blue[9] = { 64./255., 69./255., 78./255., 105./255., 142./255., 177./255., 205./255., 217./255., 198./255.};
3230 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3231 }
3232 break;
3233
3234 // Cherry
3235 case 75:
3236 {
3237 Double_t red[9] = { 37./255., 102./255., 157./255., 188./255., 196./255., 214./255., 223./255., 235./255., 251./255.};
3238 Double_t green[9] = { 37./255., 29./255., 25./255., 37./255., 67./255., 91./255., 132./255., 185./255., 251./255.};
3239 Double_t blue[9] = { 37./255., 32./255., 33./255., 45./255., 66./255., 98./255., 137./255., 187./255., 251./255.};
3240 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3241 }
3242 break;
3243
3244 // Coffee
3245 case 76:
3246 {
3247 Double_t red[9] = { 79./255., 100./255., 119./255., 137./255., 153./255., 172./255., 192./255., 205./255., 250./255.};
3248 Double_t green[9] = { 63./255., 79./255., 93./255., 103./255., 115./255., 135./255., 167./255., 196./255., 250./255.};
3249 Double_t blue[9] = { 51./255., 59./255., 66./255., 61./255., 62./255., 70./255., 110./255., 160./255., 250./255.};
3250 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3251 }
3252 break;
3253
3254 // Dark Rain Bow
3255 case 77:
3256 {
3257 Double_t red[9] = { 43./255., 44./255., 50./255., 66./255., 125./255., 172./255., 178./255., 155./255., 157./255.};
3258 Double_t green[9] = { 63./255., 63./255., 85./255., 101./255., 138./255., 163./255., 122./255., 51./255., 39./255.};
3259 Double_t blue[9] = { 121./255., 101./255., 58./255., 44./255., 47./255., 55./255., 57./255., 44./255., 43./255.};
3260 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3261 }
3262 break;
3263
3264 // Dark Terrain
3265 case 78:
3266 {
3267 Double_t red[9] = { 0./255., 41./255., 62./255., 79./255., 90./255., 87./255., 99./255., 140./255., 228./255.};
3268 Double_t green[9] = { 0./255., 57./255., 81./255., 93./255., 85./255., 70./255., 71./255., 125./255., 228./255.};
3269 Double_t blue[9] = { 95./255., 91./255., 91./255., 82./255., 60./255., 43./255., 44./255., 112./255., 228./255.};
3270 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3271 }
3272 break;
3273
3274 // Fall
3275 case 79:
3276 {
3277 Double_t red[9] = { 49./255., 59./255., 72./255., 88./255., 114./255., 141./255., 176./255., 205./255., 222./255.};
3278 Double_t green[9] = { 78./255., 72./255., 66./255., 57./255., 59./255., 75./255., 106./255., 142./255., 173./255.};
3279 Double_t blue[9] = { 78./255., 55./255., 46./255., 40./255., 39./255., 39./255., 40./255., 41./255., 47./255.};
3280 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3281 }
3282 break;
3283
3284 // Fruit Punch
3285 case 80:
3286 {
3287 Double_t red[9] = { 243./255., 222./255., 201./255., 185./255., 165./255., 158./255., 166./255., 187./255., 219./255.};
3288 Double_t green[9] = { 94./255., 108./255., 132./255., 135./255., 125./255., 96./255., 68./255., 51./255., 61./255.};
3289 Double_t blue[9] = { 7./255., 9./255., 12./255., 19./255., 45./255., 89./255., 118./255., 146./255., 118./255.};
3290 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3291 }
3292 break;
3293
3294 // Fuchsia
3295 case 81:
3296 {
3297 Double_t red[9] = { 19./255., 44./255., 74./255., 105./255., 137./255., 166./255., 194./255., 206./255., 220./255.};
3298 Double_t green[9] = { 19./255., 28./255., 40./255., 55./255., 82./255., 110./255., 159./255., 181./255., 220./255.};
3299 Double_t blue[9] = { 19./255., 42./255., 68./255., 96./255., 129./255., 157./255., 188./255., 203./255., 220./255.};
3300 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3301 }
3302 break;
3303
3304 // Grey Yellow
3305 case 82:
3306 {
3307 Double_t red[9] = { 33./255., 44./255., 70./255., 99./255., 140./255., 165./255., 199./255., 211./255., 216./255.};
3308 Double_t green[9] = { 38./255., 50./255., 76./255., 105./255., 140./255., 165./255., 191./255., 189./255., 167./255.};
3309 Double_t blue[9] = { 55./255., 67./255., 97./255., 124./255., 140./255., 166./255., 163./255., 129./255., 52./255.};
3310 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3311 }
3312 break;
3313
3314 // Green Brown Terrain
3315 case 83:
3316 {
3317 Double_t red[9] = { 0./255., 33./255., 73./255., 124./255., 136./255., 152./255., 159./255., 171./255., 223./255.};
3318 Double_t green[9] = { 0./255., 43./255., 92./255., 124./255., 134./255., 126./255., 121./255., 144./255., 223./255.};
3319 Double_t blue[9] = { 0./255., 43./255., 68./255., 76./255., 73./255., 64./255., 72./255., 114./255., 223./255.};
3320 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3321 }
3322 break;
3323
3324 // Green Pink
3325 case 84:
3326 {
3327 Double_t red[9] = { 5./255., 18./255., 45./255., 124./255., 193./255., 223./255., 205./255., 128./255., 49./255.};
3328 Double_t green[9] = { 48./255., 134./255., 207./255., 230./255., 193./255., 113./255., 28./255., 0./255., 7./255.};
3329 Double_t blue[9] = { 6./255., 15./255., 41./255., 121./255., 193./255., 226./255., 208./255., 130./255., 49./255.};
3330 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3331 }
3332 break;
3333
3334 // Island
3335 case 85:
3336 {
3337 Double_t red[9] = { 180./255., 106./255., 104./255., 135./255., 164./255., 188./255., 189./255., 165./255., 144./255.};
3338 Double_t green[9] = { 72./255., 126./255., 154./255., 184./255., 198./255., 207./255., 205./255., 190./255., 179./255.};
3339 Double_t blue[9] = { 41./255., 120./255., 158./255., 188./255., 194./255., 181./255., 145./255., 100./255., 62./255.};
3340 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3341 }
3342 break;
3343
3344 // Lake
3345 case 86:
3346 {
3347 Double_t red[9] = { 57./255., 72./255., 94./255., 117./255., 136./255., 154./255., 174./255., 192./255., 215./255.};
3348 Double_t green[9] = { 0./255., 33./255., 68./255., 109./255., 140./255., 171./255., 192./255., 196./255., 209./255.};
3349 Double_t blue[9] = { 116./255., 137./255., 173./255., 201./255., 200./255., 201./255., 203./255., 190./255., 187./255.};
3350 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3351 }
3352 break;
3353
3354 // Light Temperature
3355 case 87:
3356 {
3357 Double_t red[9] = { 31./255., 71./255., 123./255., 160./255., 210./255., 222./255., 214./255., 199./255., 183./255.};
3358 Double_t green[9] = { 40./255., 117./255., 171./255., 211./255., 231./255., 220./255., 190./255., 132./255., 65./255.};
3359 Double_t blue[9] = { 234./255., 214./255., 228./255., 222./255., 210./255., 160./255., 105./255., 60./255., 34./255.};
3360 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3361 }
3362 break;
3363
3364 // Light Terrain
3365 case 88:
3366 {
3367 Double_t red[9] = { 123./255., 108./255., 109./255., 126./255., 154./255., 172./255., 188./255., 196./255., 218./255.};
3368 Double_t green[9] = { 184./255., 138./255., 130./255., 133./255., 154./255., 175./255., 188./255., 196./255., 218./255.};
3369 Double_t blue[9] = { 208./255., 130./255., 109./255., 99./255., 110./255., 122./255., 150./255., 171./255., 218./255.};
3370 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3371 }
3372 break;
3373
3374 // Mint
3375 case 89:
3376 {
3377 Double_t red[9] = { 105./255., 106./255., 122./255., 143./255., 159./255., 172./255., 176./255., 181./255., 207./255.};
3378 Double_t green[9] = { 252./255., 197./255., 194./255., 187./255., 174./255., 162./255., 153./255., 136./255., 125./255.};
3379 Double_t blue[9] = { 146./255., 133./255., 144./255., 155./255., 163./255., 167./255., 166./255., 162./255., 174./255.};
3380 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3381 }
3382 break;
3383
3384 // Neon
3385 case 90:
3386 {
3387 Double_t red[9] = { 171./255., 141./255., 145./255., 152./255., 154./255., 159./255., 163./255., 158./255., 177./255.};
3388 Double_t green[9] = { 236./255., 143./255., 100./255., 63./255., 53./255., 55./255., 44./255., 31./255., 6./255.};
3389 Double_t blue[9] = { 59./255., 48./255., 46./255., 44./255., 42./255., 54./255., 82./255., 112./255., 179./255.};
3390 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3391 }
3392 break;
3393
3394 // Pastel
3395 case 91:
3396 {
3397 Double_t red[9] = { 180./255., 190./255., 209./255., 223./255., 204./255., 228./255., 205./255., 152./255., 91./255.};
3398 Double_t green[9] = { 93./255., 125./255., 147./255., 172./255., 181./255., 224./255., 233./255., 198./255., 158./255.};
3399 Double_t blue[9] = { 236./255., 218./255., 160./255., 133./255., 114./255., 132./255., 162./255., 220./255., 218./255.};
3400 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3401 }
3402 break;
3403
3404 // Pearl
3405 case 92:
3406 {
3407 Double_t red[9] = { 225./255., 183./255., 162./255., 135./255., 115./255., 111./255., 119./255., 145./255., 211./255.};
3408 Double_t green[9] = { 205./255., 177./255., 166./255., 135./255., 124./255., 117./255., 117./255., 132./255., 172./255.};
3409 Double_t blue[9] = { 186./255., 165./255., 155./255., 135./255., 126./255., 130./255., 150./255., 178./255., 226./255.};
3410 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3411 }
3412 break;
3413
3414 // Pigeon
3415 case 93:
3416 {
3417 Double_t red[9] = { 39./255., 43./255., 59./255., 63./255., 80./255., 116./255., 153./255., 177./255., 223./255.};
3418 Double_t green[9] = { 39./255., 43./255., 59./255., 74./255., 91./255., 114./255., 139./255., 165./255., 223./255.};
3419 Double_t blue[9] = { 39./255., 50./255., 59./255., 70./255., 85./255., 115./255., 151./255., 176./255., 223./255.};
3420 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3421 }
3422 break;
3423
3424 // Plum
3425 case 94:
3426 {
3427 Double_t red[9] = { 0./255., 38./255., 60./255., 76./255., 84./255., 89./255., 101./255., 128./255., 204./255.};
3428 Double_t green[9] = { 0./255., 10./255., 15./255., 23./255., 35./255., 57./255., 83./255., 123./255., 199./255.};
3429 Double_t blue[9] = { 0./255., 11./255., 22./255., 40./255., 63./255., 86./255., 97./255., 94./255., 85./255.};
3430 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3431 }
3432 break;
3433
3434 // Red Blue
3435 case 95:
3436 {
3437 Double_t red[9] = { 94./255., 112./255., 141./255., 165./255., 167./255., 140./255., 91./255., 49./255., 27./255.};
3438 Double_t green[9] = { 27./255., 46./255., 88./255., 135./255., 166./255., 161./255., 135./255., 97./255., 58./255.};
3439 Double_t blue[9] = { 42./255., 52./255., 81./255., 106./255., 139./255., 158./255., 155./255., 137./255., 116./255.};
3440 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3441 }
3442 break;
3443
3444 // Rose
3445 case 96:
3446 {
3447 Double_t red[9] = { 30./255., 49./255., 79./255., 117./255., 135./255., 151./255., 146./255., 138./255., 147./255.};
3448 Double_t green[9] = { 63./255., 60./255., 72./255., 90./255., 94./255., 94./255., 68./255., 46./255., 16./255.};
3449 Double_t blue[9] = { 18./255., 28./255., 41./255., 56./255., 62./255., 63./255., 50./255., 36./255., 21./255.};
3450 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3451 }
3452 break;
3453
3454 // Rust
3455 case 97:
3456 {
3457 Double_t red[9] = { 0./255., 30./255., 63./255., 101./255., 143./255., 152./255., 169./255., 187./255., 230./255.};
3458 Double_t green[9] = { 0./255., 14./255., 28./255., 42./255., 58./255., 61./255., 67./255., 74./255., 91./255.};
3459 Double_t blue[9] = { 39./255., 26./255., 21./255., 18./255., 15./255., 14./255., 14./255., 13./255., 13./255.};
3460 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3461 }
3462 break;
3463
3464 // Sandy Terrain
3465 case 98:
3466 {
3467 Double_t red[9] = { 149./255., 140./255., 164./255., 179./255., 182./255., 181./255., 131./255., 87./255., 61./255.};
3468 Double_t green[9] = { 62./255., 70./255., 107./255., 136./255., 144./255., 138./255., 117./255., 87./255., 74./255.};
3469 Double_t blue[9] = { 40./255., 38./255., 45./255., 49./255., 49./255., 49./255., 38./255., 32./255., 34./255.};
3470 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3471 }
3472 break;
3473
3474 // Sienna
3475 case 99:
3476 {
3477 Double_t red[9] = { 99./255., 112./255., 148./255., 165./255., 179./255., 182./255., 183./255., 183./255., 208./255.};
3478 Double_t green[9] = { 39./255., 40./255., 57./255., 79./255., 104./255., 127./255., 148./255., 161./255., 198./255.};
3479 Double_t blue[9] = { 15./255., 16./255., 18./255., 33./255., 51./255., 79./255., 103./255., 129./255., 177./255.};
3480 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3481 }
3482 break;
3483
3484 // Solar
3485 case 100:
3486 {
3487 Double_t red[9] = { 99./255., 116./255., 154./255., 174./255., 200./255., 196./255., 201./255., 201./255., 230./255.};
3488 Double_t green[9] = { 0./255., 0./255., 8./255., 32./255., 58./255., 83./255., 119./255., 136./255., 173./255.};
3489 Double_t blue[9] = { 5./255., 6./255., 7./255., 9./255., 9./255., 14./255., 17./255., 19./255., 24./255.};
3490 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3491 }
3492 break;
3493
3494 // South West
3495 case 101:
3496 {
3497 Double_t red[9] = { 82./255., 106./255., 126./255., 141./255., 155./255., 163./255., 142./255., 107./255., 66./255.};
3498 Double_t green[9] = { 62./255., 44./255., 69./255., 107./255., 135./255., 152./255., 149./255., 132./255., 119./255.};
3499 Double_t blue[9] = { 39./255., 25./255., 31./255., 60./255., 73./255., 68./255., 49./255., 72./255., 188./255.};
3500 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3501 }
3502 break;
3503
3504 // Starry Night
3505 case 102:
3506 {
3507 Double_t red[9] = { 18./255., 29./255., 44./255., 72./255., 116./255., 158./255., 184./255., 208./255., 221./255.};
3508 Double_t green[9] = { 27./255., 46./255., 71./255., 105./255., 146./255., 177./255., 189./255., 190./255., 183./255.};
3509 Double_t blue[9] = { 39./255., 55./255., 80./255., 108./255., 130./255., 133./255., 124./255., 100./255., 76./255.};
3510 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3511 }
3512 break;
3513
3514 // Sunset
3515 case 103:
3516 {
3517 Double_t red[9] = { 0./255., 48./255., 119./255., 173./255., 212./255., 224./255., 228./255., 228./255., 245./255.};
3518 Double_t green[9] = { 0./255., 13./255., 30./255., 47./255., 79./255., 127./255., 167./255., 205./255., 245./255.};
3519 Double_t blue[9] = { 0./255., 68./255., 75./255., 43./255., 16./255., 22./255., 55./255., 128./255., 245./255.};
3520 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3521 }
3522 break;
3523
3524 // Temperature Map
3525 case 104:
3526 {
3527 Double_t red[9] = { 34./255., 70./255., 129./255., 187./255., 225./255., 226./255., 216./255., 193./255., 179./255.};
3528 Double_t green[9] = { 48./255., 91./255., 147./255., 194./255., 226./255., 229./255., 196./255., 110./255., 12./255.};
3529 Double_t blue[9] = { 234./255., 212./255., 216./255., 224./255., 206./255., 110./255., 53./255., 40./255., 29./255.};
3530 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3531 }
3532 break;
3533
3534 // Thermometer
3535 case 105:
3536 {
3537 Double_t red[9] = { 30./255., 55./255., 103./255., 147./255., 174./255., 203./255., 188./255., 151./255., 105./255.};
3538 Double_t green[9] = { 0./255., 65./255., 138./255., 182./255., 187./255., 175./255., 121./255., 53./255., 9./255.};
3539 Double_t blue[9] = { 191./255., 202./255., 212./255., 208./255., 171./255., 140./255., 97./255., 57./255., 30./255.};
3540 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3541 }
3542 break;
3543
3544 // Valentine
3545 case 106:
3546 {
3547 Double_t red[9] = { 112./255., 97./255., 113./255., 125./255., 138./255., 159./255., 178./255., 188./255., 225./255.};
3548 Double_t green[9] = { 16./255., 17./255., 24./255., 37./255., 56./255., 81./255., 110./255., 136./255., 189./255.};
3549 Double_t blue[9] = { 38./255., 35./255., 46./255., 59./255., 78./255., 103./255., 130./255., 152./255., 201./255.};
3550 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3551 }
3552 break;
3553
3554 // Visible Spectrum
3555 case 107:
3556 {
3557 Double_t red[9] = { 18./255., 72./255., 5./255., 23./255., 29./255., 201./255., 200./255., 98./255., 29./255.};
3558 Double_t green[9] = { 0./255., 0./255., 43./255., 167./255., 211./255., 117./255., 0./255., 0./255., 0./255.};
3559 Double_t blue[9] = { 51./255., 203./255., 177./255., 26./255., 10./255., 9./255., 8./255., 3./255., 0./255.};
3560 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3561 }
3562 break;
3563
3564 // Water Melon
3565 case 108:
3566 {
3567 Double_t red[9] = { 19./255., 42./255., 64./255., 88./255., 118./255., 147./255., 175./255., 187./255., 205./255.};
3568 Double_t green[9] = { 19./255., 55./255., 89./255., 125./255., 154./255., 169./255., 161./255., 129./255., 70./255.};
3569 Double_t blue[9] = { 19./255., 32./255., 47./255., 70./255., 100./255., 128./255., 145./255., 130./255., 75./255.};
3570 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3571 }
3572 break;
3573
3574 // Cool
3575 case 109:
3576 {
3577 Double_t red[9] = { 33./255., 31./255., 42./255., 68./255., 86./255., 111./255., 141./255., 172./255., 227./255.};
3578 Double_t green[9] = { 255./255., 175./255., 145./255., 106./255., 88./255., 55./255., 15./255., 0./255., 0./255.};
3579 Double_t blue[9] = { 255./255., 205./255., 202./255., 203./255., 208./255., 205./255., 203./255., 206./255., 231./255.};
3580 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3581 }
3582 break;
3583
3584 // Copper
3585 case 110:
3586 {
3587 Double_t red[9] = { 0./255., 25./255., 50./255., 79./255., 110./255., 145./255., 181./255., 201./255., 254./255.};
3588 Double_t green[9] = { 0./255., 16./255., 30./255., 46./255., 63./255., 82./255., 101./255., 124./255., 179./255.};
3589 Double_t blue[9] = { 0./255., 12./255., 21./255., 29./255., 39./255., 49./255., 61./255., 74./255., 103./255.};
3590 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3591 }
3592 break;
3593
3594 // Gist Earth
3595 case 111:
3596 {
3597 Double_t red[9] = { 0./255., 13./255., 30./255., 44./255., 72./255., 120./255., 156./255., 200./255., 247./255.};
3598 Double_t green[9] = { 0./255., 36./255., 84./255., 117./255., 141./255., 153./255., 151./255., 158./255., 247./255.};
3599 Double_t blue[9] = { 0./255., 94./255., 100./255., 82./255., 56./255., 66./255., 76./255., 131./255., 247./255.};
3600 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3601 }
3602 break;
3603
3604 // Viridis
3605 case 112:
3606 {
3607 Double_t red[9] = { 26./255., 51./255., 43./255., 33./255., 28./255., 35./255., 74./255., 144./255., 246./255.};
3608 Double_t green[9] = { 9./255., 24./255., 55./255., 87./255., 118./255., 150./255., 180./255., 200./255., 222./255.};
3609 Double_t blue[9] = { 30./255., 96./255., 112./255., 114./255., 112./255., 101./255., 72./255., 35./255., 0./255.};
3610 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3611 }
3612 break;
3613
3614 // Cividis
3615 case 113:
3616 {
3617 Double_t red[9] = { 0./255., 5./255., 65./255., 97./255., 124./255., 156./255., 189./255., 224./255., 255./255.};
3618 Double_t green[9] = { 32./255., 54./255., 77./255., 100./255., 123./255., 148./255., 175./255., 203./255., 234./255.};
3619 Double_t blue[9] = { 77./255., 110./255., 107./255., 111./255., 120./255., 119./255., 111./255., 94./255., 70./255.};
3620 Idx = TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha);
3621 }
3622 break;
3623
3624 default:
3625 ::Error("SetPalette", "Unknown palette number %d", ncolors);
3626 return;
3627 }
3628 gPaletteType = ncolors;
3629 if (Idx>0) fgPalettesList.fArray[gPaletteType-51] = (Double_t)Idx;
3630 else fgPalettesList.fArray[gPaletteType-51] = 0.;
3631 if (alpha > 0.) fgPalettesList.fArray[gPaletteType-51] += alpha/10.0f;
3632 return;
3633 }
3634
3635 // set user defined palette
3636 if (colors) {
3637 fgPalette.Set(ncolors);
3638 for (i=0;i<ncolors;i++) fgPalette.fArray[i] = colors[i];
3639 } else {
3640 fgPalette.Set(TMath::Min(50,ncolors));
3641 for (i=0;i<TMath::Min(50,ncolors);i++) fgPalette.fArray[i] = palette[i];
3642 }
3643 gPaletteType = 3;
3644}
3645
3646////////////////////////////////////////////////////////////////////////////////
3647/// Store current palette in the output macro
3649void TColor::SaveColorsPalette(std::ostream &out)
3650{
3651 if ((gPaletteType == 1) || (gPaletteType == 2))
3652 out << " TColor::SetPalette(" << (gPaletteType - 1) << ", nullptr);\n";
3653 else if ((gPaletteType == 3) && (fgPalette.fN <= 50)) {
3654 out << " TColor::SetPalette(" << fgPalette.fN << ", (Int_t []) ";
3655 for (int i = 0; i < fgPalette.fN; i++)
3656 out << (i == 0 ? "{ " : ", ") << TColor::SavePrimitiveColor(fgPalette.fArray[i]);
3657 out << " });\n";
3658 } else if (gPaletteType > 50) {
3659 out << " TColor::SetPalette(" << gPaletteType << ", nullptr";
3660
3661 Int_t Idx = (Int_t)fgPalettesList.fArray[gPaletteType - 51];
3662 Double_t alphas = 10 * (fgPalettesList.fArray[gPaletteType - 51] - Idx);
3663
3664 if (alphas < 1)
3665 out << ", " << alphas;
3666 out << ");\n";
3667 }
3668}
3669
3670////////////////////////////////////////////////////////////////////////////////
3671/// Invert the current color palette.
3672/// The top of the palette becomes the bottom and vice versa.
3675{
3676 std::reverse(fgPalette.fArray, fgPalette.fArray + fgPalette.GetSize());
3677}
3678
3679////////////////////////////////////////////////////////////////////////////////
3680/// The `color` string argument argument will be evaluated
3681/// to get the actual ROOT color number, like `kRed`.
3682/// Here is how the string is parsed:
3683///
3684/// 1. Match against single-character color codes following the matplotlib convention.
3685/// For example, to get red color (equivalent to `kRed`):
3686/// ~~~ {.cxx}
3687/// hist.SetLineColor("r")
3688/// ~~~
3689/// 2. Check if the string matches an en existing TColor name (see TColor::GetColorByName()).
3690/// For example:
3691/// ~~~ {.cxx}
3692/// hist.SetLineColor("kRed+1")
3693/// ~~~
3694///
3695/// In case no corresponding color is found, a `std::invalid_argument` exception is thrown.
3696TColorNumber::TColorNumber(std::string const &color)
3697{
3698 using Map = std::unordered_map<std::string, Int_t>;
3699 // Color dictionary to define matplotlib conventions
3700 static Map colorMap{{"r", kRed}, {"b", kBlue}, {"g", kGreen}, {"y", kYellow},
3701 {"w", kWhite}, {"k", kBlack}, {"m", kMagenta}, {"c", kCyan}};
3702 auto found = colorMap.find(color);
3703 if (found != colorMap.end()) {
3704 fNumber = found->second;
3705 return;
3706 }
3707
3708 fNumber = TColor::GetColorByName(color.c_str());
3709 if (fNumber == -1) {
3710 std::stringstream msg;
3711 msg << "\"" << color << "\" is not a valid color name";
3712 throw std::invalid_argument(msg.str());
3713 }
3714}
3715
3716////////////////////////////////////////////////////////////////////////////////
3717/// Instantiate a color from a tuple of RGB values between 0.0 and 1.0.
3718TColorNumber::TColorNumber(std::array<Float_t, 3> rgb) : fNumber{TColor::GetColor(rgb[0], rgb[1], rgb[2])} {}
const Mask_t kDoRed
Definition GuiTypes.h:319
const Mask_t kDoGreen
Definition GuiTypes.h:320
const Mask_t kDoBlue
Definition GuiTypes.h:321
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define s0(x)
Definition RSha256.hxx:90
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short)
Definition RtypesCore.h:54
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:52
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
@ 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:110
float * q
#define gROOT
Definition TROOT.h:411
#define gVirtualX
Definition TVirtualX.h:337
Color * colors
Definition X3DBuffer.c:21
#define snprintf
Definition civetweb.c:1579
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:150
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:1712
static Int_t GetFirstFreeColorIndex()
Static function: Returns the first free color greater in the list of colors.
Definition TColor.cxx:2386
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:2933
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:2218
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:1581
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:1855
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:1606
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:2295
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Definition TColor.cxx:1509
static const TArrayI & GetPalette()
Static function returning the current active palette.
Definition TColor.cxx:1521
Float_t GetRed() const
Definition TColor.h:61
void ls(Option_t *option="") const override
List this color with its attributes.
Definition TColor.cxx:1703
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:2579
static void SaveColorsPalette(std::ostream &out)
Store current palette in the output macro.
Definition TColor.cxx:3648
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:2483
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2445
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:1776
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:1926
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition TColor.cxx:1172
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:1647
Float_t fAlpha
Alpha (transparency)
Definition TColor.h:32
void Copy(TObject &color) const override
Copy this color to obj.
Definition TColor.cxx:1351
static void InvertPalette()
Invert the current color palette.
Definition TColor.cxx:3673
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:1421
static Int_t GetColorByName(const char *colorname)
Static method returning color index for a color specified by name.
Definition TColor.cxx:2081
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:1831
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:2095
static Bool_t IsGrayscale()
Return whether all colors return grayscale values.
Definition TColor.cxx:2596
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:2521
const char * AsHexString() const
Return color as hexadecimal string.
Definition TColor.cxx:1330
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:2138
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:2742
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:2542
static TClass * Class()
void Allocate()
Make this color known to the graphics system.
Definition TColor.cxx:1909
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition TColor.cxx:1564
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:2636
static void SetColorThreshold(Float_t t)
This method specifies the color threshold used by GetColor to retrieve a color.
Definition TColor.cxx:1995
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:2556
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:1542
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:1383
Int_t GetNumber() const
Definition TColor.h:59
Float_t GetBlue() const
Definition TColor.h:63
TColor & operator=(const TColor &color)
Definition TColor.cxx:1160
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:1529
static Int_t GetFreeColorIndex()
Static function: Returns the free color index greater than the highest defined color index.
Definition TColor.cxx:2372
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:2403
TColor()
Default constructor.
Definition TColor.cxx:1066
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:1402
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:1367
virtual ~TColor()
Color destructor.
Definition TColor.cxx:1143
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:1721
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2182
static void SetGrayscale(Bool_t set=kTRUE)
Set whether all colors should return grayscale values.
Definition TColor.cxx:2604
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:41
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
static TClass * Class()
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
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:2384
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:251
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:199
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:124
ULong_t fPixel
color pixel value (index in color table)
Definition GuiTypes.h:311
UShort_t fRed
red component (0..65535)
Definition GuiTypes.h:312
UShort_t fGreen
green component (0..65535)
Definition GuiTypes.h:313
UShort_t fBlue
blue component (0..65535)
Definition GuiTypes.h:314
UShort_t fMask
mask telling which color components are valid
Definition GuiTypes.h:315
TLine l
Definition textangle.C:4