[Scummvm-devel] colorToRGB() implementation

yotam barnoy yotambarnoy at gmail.com
Wed Mar 17 07:35:34 CET 2010


Hey guys

I came across our implementation of pixelFormat.colorToRGB() and
colorToRGBA() implementation and it seems incorrect to me. Currently it's

inline void colorToRGB(uint32 color, uint8 &r, uint8 &g, uint8 &b) const {
 r = ((color >> rShift) << rLoss) & 0xFF;
g = ((color >> gShift) << gLoss) & 0xFF;
 b = ((color >> bShift) << bLoss) & 0xFF;

The problem is, you can't ever restore the intended r,g,b values from the
original 16-bit color. For example in R5G5B5  mode, 0x7FFF, which is
supposed to be the brightest white, will only become 248,248,248 instead of
255,255,255. What we really need to do is

r = (((color >> rShift) & rMask) * 255) / rMax();

in order to translate the values correctly. rMax() should probably be saved
in the struct for speed.

The same criticism applies to the conversion in colormasks.h.

Feedback?

Yotam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scummvm.org/pipermail/scummvm-devel/attachments/20100317/2e33e72a/attachment.html>


More information about the Scummvm-devel mailing list