assert((greenMax & (greenMax + 1)) == 0);
assert((blueMax & (blueMax + 1)) == 0);
- updateShifts();
+ updateState();
}
PixelFormat::PixelFormat()
redMax(7), greenMax(7), blueMax(3),
redShift(0), greenShift(3), blueShift(6)
{
- updateShifts();
+ updateState();
}
bool PixelFormat::equal(const PixelFormat& other) const
blueShift = is->readU8();
is->skip(3);
- updateShifts();
+ updateState();
}
void PixelFormat::write(rdr::OutStream* os) const
return false;
}
- updateShifts();
+ updateState();
return true;
}
return bits;
}
-void PixelFormat::updateShifts(void)
+void PixelFormat::updateState(void)
{
int redBits, greenBits, blueBits;
+ int endianTest = 1;
redBits = bits(redMax);
greenBits = bits(greenMax);
redConvShift = 16 - redBits;
greenConvShift = 16 - greenBits;
blueConvShift = 16 - blueBits;
+
+ if (((*(char*)&endianTest) == 0) != bigEndian)
+ endianMismatch = true;
+ else
+ endianMismatch = false;
}
}
+#define _rfb_bswap_32(x) \
+ ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
+ (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
+
+
inline void PixelFormat::rgbFromPixel(Pixel p, ColourMap* cm, rdr::U16 *r, rdr::U16 *g, rdr::U16 *b) const
{
if (trueColour) {
+ if (endianMismatch)
+ p = _rfb_bswap_32(p);
/* We don't need to mask since we shift out unwanted bits */
*r = (p >> redShift) << redConvShift;
*g = (p >> greenShift) << greenConvShift;
inline void PixelFormat::rgbFromPixel(Pixel p, ColourMap* cm, rdr::U8 *r, rdr::U8 *g, rdr::U8 *b) const
{
if (trueColour) {
+ if (endianMismatch)
+ p = _rfb_bswap_32(p);
*r = (p >> redShift) << (redConvShift - 8);
*g = (p >> greenShift) << (greenConvShift - 8);
*b = (p >> blueShift) << (blueConvShift - 8);