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