From 20f467a0e76cc10361d8821535abd9f8bbfe905c Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Thu, 15 Oct 2026 14:01:26 +0200 Subject: [PATCH 1/3] [asimage] fix bug in rainbow palette selection Target array has only 12 elements, but rainbow palette has only 10 points These 10 points should be copied from offset 1, first and last point will be overwritten --- graf2d/asimage/src/TASPaletteEditor.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/graf2d/asimage/src/TASPaletteEditor.cxx b/graf2d/asimage/src/TASPaletteEditor.cxx index 77d667eb83ba5..66d56154522f4 100644 --- a/graf2d/asimage/src/TASPaletteEditor.cxx +++ b/graf2d/asimage/src/TASPaletteEditor.cxx @@ -61,15 +61,15 @@ static const char *gFileTypes[] = { nullptr, nullptr }; -static UShort_t gRedRainbow[12] = { +static UShort_t gRedRainbow[10] = { 0x0000, 0x7000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0x7000, 0x8000, 0xffff }; -static UShort_t gGreenRainbow[12] = { +static UShort_t gGreenRainbow[10] = { 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x8000, 0xffff }; -static UShort_t gBlueRainbow[12] = { +static UShort_t gBlueRainbow[10] = { 0x0000, 0x7000, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0xffff }; @@ -687,9 +687,9 @@ void TASPaletteEditor::NewPalette(Long_t id) switch (id) { case 0: // rainbow - memcpy(newPalette->fColorRed + 1, gRedRainbow, 12 * sizeof(UShort_t)); - memcpy(newPalette->fColorGreen + 1, gGreenRainbow, 12 * sizeof(UShort_t)); - memcpy(newPalette->fColorBlue + 1, gBlueRainbow, 12 * sizeof(UShort_t)); + memcpy(newPalette->fColorRed + 1, gRedRainbow, 10 * sizeof(UShort_t)); + memcpy(newPalette->fColorGreen + 1, gGreenRainbow, 10 * sizeof(UShort_t)); + memcpy(newPalette->fColorBlue + 1, gBlueRainbow, 10 * sizeof(UShort_t)); break; case 1: // gray From 3427f9cfb1b268ccbeff69cf74e9c34b12fa7b3b Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Fri, 16 Oct 2026 17:11:48 +0200 Subject: [PATCH 2/3] [asimage] provide size constant for rainbow palette Use it in assign methods Co-authored-by: ferdymercury --- graf2d/asimage/src/TASPaletteEditor.cxx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/graf2d/asimage/src/TASPaletteEditor.cxx b/graf2d/asimage/src/TASPaletteEditor.cxx index 66d56154522f4..79964a9d2566e 100644 --- a/graf2d/asimage/src/TASPaletteEditor.cxx +++ b/graf2d/asimage/src/TASPaletteEditor.cxx @@ -61,15 +61,17 @@ static const char *gFileTypes[] = { nullptr, nullptr }; -static UShort_t gRedRainbow[10] = { +constexpr size_t kNRainbowElems = 10; + +static UShort_t gRedRainbow[kNRainbowElems] = { 0x0000, 0x7000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0x7000, 0x8000, 0xffff }; -static UShort_t gGreenRainbow[10] = { +static UShort_t gGreenRainbow[kNRainbowElems] = { 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x8000, 0xffff }; -static UShort_t gBlueRainbow[10] = { +static UShort_t gBlueRainbow[kNRainbowElems] = { 0x0000, 0x7000, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0xffff }; @@ -687,9 +689,9 @@ void TASPaletteEditor::NewPalette(Long_t id) switch (id) { case 0: // rainbow - memcpy(newPalette->fColorRed + 1, gRedRainbow, 10 * sizeof(UShort_t)); - memcpy(newPalette->fColorGreen + 1, gGreenRainbow, 10 * sizeof(UShort_t)); - memcpy(newPalette->fColorBlue + 1, gBlueRainbow, 10 * sizeof(UShort_t)); + memcpy(newPalette->fColorRed + 1, gRedRainbow, kNRainbowElems * sizeof(UShort_t)); + memcpy(newPalette->fColorGreen + 1, gGreenRainbow, kNRainbowElems * sizeof(UShort_t)); + memcpy(newPalette->fColorBlue + 1, gBlueRainbow, kNRainbowElems * sizeof(UShort_t)); break; case 1: // gray From bc637f085c294c1cd2aa8f47ae55fa2c1a7bbd2d Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Mon, 19 Oct 2026 11:06:18 +0200 Subject: [PATCH 3/3] [asimage] use new constant in NewPalette New kNRainbowElems constant specify number of elements in array, palette should reserve 2 more points --- graf2d/asimage/src/TASPaletteEditor.cxx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/graf2d/asimage/src/TASPaletteEditor.cxx b/graf2d/asimage/src/TASPaletteEditor.cxx index 79964a9d2566e..eaf2c23c7de89 100644 --- a/graf2d/asimage/src/TASPaletteEditor.cxx +++ b/graf2d/asimage/src/TASPaletteEditor.cxx @@ -674,13 +674,11 @@ void TASPaletteEditor::NewPalette(Long_t id) if (id == 5) // empty entry return; - TImagePalette *newPalette; - Double_t delta = fPalette->fPoints[fPalette->fNumPoints-2] - fPalette->fPoints[1]; - UInt_t numPt; - numPt = id == 0 ? 12 : 13; - newPalette = new TImagePalette(numPt); + UInt_t numPt = id == 0 ? kNRainbowElems + 2 : 13; + TImagePalette *newPalette = new TImagePalette(numPt); + Int_t pt; for (pt = 1; pt < Int_t(numPt - 1); pt++) { newPalette->fPoints[pt] = fPalette->fPoints[1] + (pt - 1) * delta / (numPt - 3);