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