Skip to content

Commit 864a71d

Browse files
committed
Fix Pallette
By default, Nidia GPUs uses a 11 bits lookup table. In the past we had to change its setup to use 8 bits. But the hack seems broken now on Ubuntu 20.04. In this commit, we try to fix the issue in the Amrvis source code. (Unfortunately, I don't fully understand how X11 works...)
1 parent a3ce67a commit 864a71d

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

Palette.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ using namespace amrex;
1818

1919
Colormap Palette::systemColmap;
2020

21+
static Pixel make_pixel (unsigned char r, unsigned char g, unsigned char b,
22+
unsigned long bprgb, unsigned long rs, unsigned long gs,
23+
unsigned long bs)
24+
{
25+
if (bprgb < 8) {
26+
r >>= (8 - bprgb);
27+
g >>= (8 - bprgb);
28+
b >>= (8 - bprgb);
29+
}
30+
return (r << rs) | (g << gs) | (b << bs);
31+
}
2132

2233
// -------------------------------------------------------------------
2334
Palette::Palette(Widget &w, int datalistlength, int width,
@@ -397,10 +408,7 @@ int Palette::ReadSeqPalette(const string &fileName, bool bRedraw) {
397408
cout << "Can't open colormap file: " << fileName << endl;
398409
for(i = 0; i < totalColorSlots; ++i) { // make a default grayscale colormap.
399410
if(bTrueColor) {
400-
// FIXME: not 24 bit!
401-
ccells[i].pixel = (((rbuff[i] >> (8 - bprgb)) << 2 * bprgb)
402-
| ((gbuff[i] >> (8 - bprgb)) << bprgb)
403-
| ((bbuff[i] >> (8 - bprgb)) << 0) );
411+
ccells[i].pixel = make_pixel(rbuff[i], gbuff[i], bbuff[i], bprgb, 2*bprgb, bprgb, 0);
404412
} else {
405413
ccells[i].pixel = i;
406414
}
@@ -489,9 +497,7 @@ int Palette::ReadSeqPalette(const string &fileName, bool bRedraw) {
489497
cout << "making a CCPal colormap" << endl;
490498
for(i = 0; i < totalColorSlots; ++i) {
491499
if(bTrueColor) {
492-
ccells[i].pixel = (((rbuff[i] >> (8 - bprgb)) << 2 * bprgb)
493-
| ((gbuff[i] >> (8 - bprgb)) << bprgb)
494-
| ((bbuff[i] >> (8 - bprgb)) << 0) );
500+
ccells[i].pixel = make_pixel(rbuff[i], gbuff[i], bbuff[i], bprgb, 2*bprgb, bprgb, 0);
495501
} else {
496502
ccells[i].pixel = i;
497503
}
@@ -617,22 +623,18 @@ int Palette::ReadSeqPalette(const string &fileName, bool bRedraw) {
617623

618624
pixelCache.resize(iSeqPalSize);
619625
pixelCacheDim.resize(iSeqPalSize);
620-
assert( gaPtr->PBitsPerRGB() <= 8 );
626+
621627
Real dimValue(0.4);
622628
if(bTrueColor) {
623-
Pixel r, g, b;
624629
unsigned long rs(gaPtr->PRedShift());
625630
unsigned long gs(gaPtr->PGreenShift());
626631
unsigned long bs(gaPtr->PBlueShift());
627632
for(i = 0; i < iSeqPalSize; ++i) {
628-
r = rbuff[i] >> (8 - bprgb);
629-
g = gbuff[i] >> (8 - bprgb);
630-
b = bbuff[i] >> (8 - bprgb);
631-
pixelCache[i] = ( (r << rs) | (g << gs) | (b << bs) );
632-
r = static_cast<unsigned char>(rbuff[i] * dimValue) >> (8 - bprgb);
633-
g = static_cast<unsigned char>(gbuff[i] * dimValue) >> (8 - bprgb);
634-
b = static_cast<unsigned char>(bbuff[i] * dimValue) >> (8 - bprgb);
635-
pixelCacheDim[i] = ( (r << rs) | (g << gs) | (b << bs) );
633+
pixelCache[i] = make_pixel(rbuff[i], gbuff[i], bbuff[i], bprgb, rs, gs, bs);
634+
pixelCacheDim[i] = make_pixel(static_cast<unsigned char>(rbuff[i] * dimValue),
635+
static_cast<unsigned char>(gbuff[i] * dimValue),
636+
static_cast<unsigned char>(bbuff[i] * dimValue),
637+
bprgb, rs, gs, bs);
636638
}
637639
} else {
638640
for(i = 0; i < iSeqPalSize; ++i) {
@@ -641,13 +643,9 @@ int Palette::ReadSeqPalette(const string &fileName, bool bRedraw) {
641643
}
642644
}
643645

644-
645646
for(i = 0; i < totalColorSlots; ++i) {
646647
if(bTrueColor) {
647-
// FIXME: not 24 bit!
648-
ccells[i].pixel = (((rbuff[i] >> (8 - bprgb)) << 2 * bprgb)
649-
| ((gbuff[i] >> (8 - bprgb)) << bprgb)
650-
| ((bbuff[i] >> (8 - bprgb)) << 0));
648+
ccells[i].pixel = make_pixel(rbuff[i], gbuff[i], bbuff[i], bprgb, 2*bprgb, bprgb, 0);
651649
} else {
652650
ccells[i].pixel = i;
653651
}

amrvis.defaults

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ windowheight 750
2525
windowwidth 900
2626
filetype newplt
2727
datasetinitialcolor true
28-
lowblack
2928
cliptoppalette

0 commit comments

Comments
 (0)