From fd1887e986ce14211054ba6caec18406a15b5697 Mon Sep 17 00:00:00 2001 From: Olivier Couet Date: Mon, 4 Apr 2022 10:15:55 +0200 Subject: [PATCH 1/2] Improve GetColorTransparent. --- core/base/src/TColor.cxx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/base/src/TColor.cxx b/core/base/src/TColor.cxx index d81b1fd56f080..96c67234a1589 100644 --- a/core/base/src/TColor.cxx +++ b/core/base/src/TColor.cxx @@ -2027,7 +2027,8 @@ Int_t TColor::GetColorDark(Int_t n) //////////////////////////////////////////////////////////////////////////////// /// Static function: Returns the transparent color number corresponding to n. -/// The transparency level is given by the alpha value a. +/// The transparency level is given by the alpha value a. If a color with the same +/// RGBa values already exists it is returned. Int_t TColor::GetColorTransparent(Int_t n, Float_t a) { @@ -2035,6 +2036,18 @@ Int_t TColor::GetColorTransparent(Int_t n, Float_t a) TColor *color = gROOT->GetColor(n); if (color) { + TObjArray *colors = (TObjArray*) gROOT->GetListOfColors(); + Int_t ncolors = colors->GetSize(); + TColor *col = 0; + for (Int_t i = 0; iAt(i); + if (col) { + if (col->GetRed() == color->GetRed() && + col->GetGreen() == color->GetGreen() && + col->GetBlue() == color->GetBlue() && + col->GetAlpha() == a) return col->GetNumber(); + } + } TColor *colort = new TColor(gROOT->GetListOfColors()->GetLast()+1, color->GetRed(), color->GetGreen(), color->GetBlue()); colort->SetAlpha(a); From e3cdc307f72e8922f8ca945c5650fad169fe17e0 Mon Sep 17 00:00:00 2001 From: Olivier Couet Date: Mon, 4 Apr 2022 14:41:27 +0200 Subject: [PATCH 2/2] Coding conventions --- core/base/src/TColor.cxx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/core/base/src/TColor.cxx b/core/base/src/TColor.cxx index 96c67234a1589..c490df20dd82b 100644 --- a/core/base/src/TColor.cxx +++ b/core/base/src/TColor.cxx @@ -2036,16 +2036,15 @@ Int_t TColor::GetColorTransparent(Int_t n, Float_t a) TColor *color = gROOT->GetColor(n); if (color) { - TObjArray *colors = (TObjArray*) gROOT->GetListOfColors(); + TObjArray *colors = (TObjArray *)gROOT->GetListOfColors(); Int_t ncolors = colors->GetSize(); TColor *col = 0; - for (Int_t i = 0; iAt(i); + for (Int_t i = 0; i < ncolors; i++) { + col = (TColor *)colors->At(i); if (col) { - if (col->GetRed() == color->GetRed() && - col->GetGreen() == color->GetGreen() && - col->GetBlue() == color->GetBlue() && - col->GetAlpha() == a) return col->GetNumber(); + if (col->GetRed() == color->GetRed() && col->GetGreen() == color->GetGreen() && + col->GetBlue() == color->GetBlue() && col->GetAlpha() == a) + return col->GetNumber(); } } TColor *colort = new TColor(gROOT->GetListOfColors()->GetLast()+1,