@@ -18,6 +18,17 @@ using namespace amrex;
1818
1919Colormap 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// -------------------------------------------------------------------
2334Palette::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 }
0 commit comments