@@ -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 << 16 ) | (g << 8 ) | (b << 0 );
31+ }
2132
2233// -------------------------------------------------------------------
2334Palette::Palette (Widget &w, int datalistlength, int width,
@@ -385,7 +396,11 @@ int Palette::ReadSeqPalette(const string &fileName, bool bRedraw) {
385396 bTrueColor = gaPtr->IsTrueColor ();
386397 bprgb = gaPtr->PBitsPerRGB ();
387398 }
388-
399+
400+ unsigned long rs (gaPtr->PRedShift ());
401+ unsigned long gs (gaPtr->PGreenShift ());
402+ unsigned long bs (gaPtr->PBlueShift ());
403+
389404 if (bReadPalette) {
390405 bReadPalette = false ;
391406 rbuff.resize (iSeqPalSize);
@@ -397,10 +412,7 @@ int Palette::ReadSeqPalette(const string &fileName, bool bRedraw) {
397412 cout << " Can't open colormap file: " << fileName << endl;
398413 for (i = 0 ; i < totalColorSlots; ++i) { // make a default grayscale colormap.
399414 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 ) );
415+ ccells[i].pixel = make_pixel (rbuff[i], gbuff[i], bbuff[i], bprgb, rs, gs, bs);
404416 } else {
405417 ccells[i].pixel = i;
406418 }
@@ -489,9 +501,7 @@ int Palette::ReadSeqPalette(const string &fileName, bool bRedraw) {
489501 cout << "making a CCPal colormap" << endl;
490502 for(i = 0; i < totalColorSlots; ++i) {
491503 if(bTrueColor) {
492- ccells[i].pixel = (((rbuff[i] >> (8 - bprgb)) << 2 * bprgb)
493- | ((gbuff[i] >> (8 - bprgb)) << bprgb)
494- | ((bbuff[i] >> (8 - bprgb)) << 0) );
504+ ccells[i].pixel = make_pixel(rbuff[i], gbuff[i], bbuff[i], bprgb, rs, gs, bs);
495505 } else {
496506 ccells[i].pixel = i;
497507 }
@@ -617,22 +627,15 @@ int Palette::ReadSeqPalette(const string &fileName, bool bRedraw) {
617627
618628 pixelCache.resize (iSeqPalSize);
619629 pixelCacheDim.resize (iSeqPalSize);
620- assert ( gaPtr-> PBitsPerRGB () <= 8 );
630+
621631 Real dimValue (0.4 );
622632 if (bTrueColor) {
623- Pixel r, g, b;
624- unsigned long rs (gaPtr->PRedShift ());
625- unsigned long gs (gaPtr->PGreenShift ());
626- unsigned long bs (gaPtr->PBlueShift ());
627633 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) );
634+ pixelCache[i] = make_pixel (rbuff[i], gbuff[i], bbuff[i], bprgb, rs, gs, bs);
635+ pixelCacheDim[i] = make_pixel (static_cast <unsigned char >(rbuff[i] * dimValue),
636+ static_cast <unsigned char >(gbuff[i] * dimValue),
637+ static_cast <unsigned char >(bbuff[i] * dimValue),
638+ bprgb, rs, gs, bs);
636639 }
637640 } else {
638641 for (i = 0 ; i < iSeqPalSize; ++i) {
@@ -641,13 +644,9 @@ int Palette::ReadSeqPalette(const string &fileName, bool bRedraw) {
641644 }
642645 }
643646
644-
645647 for (i = 0 ; i < totalColorSlots; ++i) {
646648 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 ));
649+ ccells[i].pixel = make_pixel (rbuff[i], gbuff[i], bbuff[i], bprgb, rs, gs, bs);
651650 } else {
652651 ccells[i].pixel = i;
653652 }
0 commit comments