Replace floating point math with bit shifts

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5000 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shadow303
2003-10-12 22:23:06 +00:00
parent bbb6f2d463
commit a74c4d3064
+12 -36
View File
@@ -26,30 +26,6 @@
#include "ColorUtils.h"
#include <stdlib.h>
/*!
\brief An approximation of 31/255, which is needed for converting from 32-bit
colors to 16-bit and 15-bit.
*/
#define RATIO_8_TO_5_BIT .121568627451
/*!
\brief An approximation of 63/255, which is needed for converting from 32-bit
colors to 16-bit.
*/
#define RATIO_8_TO_6_BIT .247058823529
/*!
\brief An approximation of 255/31, which is needed for converting from 16-bit
and 15-bit colors to 32-bit.
*/
#define RATIO_5_TO_8_BIT 8.22580645161
/*!
\brief An approximation of 255/63, which is needed for converting from 16-bit
colors to 32-bit.
*/
#define RATIO_6_TO_8_BIT 4.04761904762
/*!
\brief Function for easy assignment of values to rgb_color objects
\param col Pointer to an rgb_color
@@ -92,9 +68,9 @@ void SetRGBColor15(rgb_color *col,uint16 color)
g16= (color >> 5) & 31;
b16= color & 31;
col->red=uint8(r16 * RATIO_5_TO_8_BIT);
col->green=uint8(g16 * RATIO_5_TO_8_BIT);
col->blue=uint8(b16 * RATIO_5_TO_8_BIT);
col->red=uint8(r16 << 3);
col->green=uint8(g16 << 3);
col->blue=uint8(b16 << 3);
}
/*!
@@ -118,9 +94,9 @@ void SetRGBColor16(rgb_color *col,uint16 color)
g16= (color >> 5) & 63;
b16= color & 31;
col->red=uint8(r16 * RATIO_5_TO_8_BIT);
col->green=uint8(g16 * RATIO_6_TO_8_BIT);
col->blue=uint8(b16 * RATIO_5_TO_8_BIT);
col->red=uint8(r16 << 3);
col->green=uint8(g16 << 2);
col->blue=uint8(b16 << 3);
}
/*!
@@ -193,9 +169,9 @@ uint16 FindClosestColor15(rgb_color color)
uint16 r16,g16,b16;
uint16 color16=0;
r16=uint16(color.red * RATIO_8_TO_5_BIT);
g16=uint16(color.green * RATIO_8_TO_5_BIT);
b16=uint16(color.blue * RATIO_8_TO_5_BIT);
r16=uint16(color.red >> 3);
g16=uint16(color.green >> 3);
b16=uint16(color.blue >> 3);
// start with alpha value
color16=(color.alpha>127)?0x8000:0;
@@ -219,9 +195,9 @@ uint16 FindClosestColor16(rgb_color color)
uint16 r16,g16,b16;
uint16 color16=0;
r16=uint16(color.red * RATIO_8_TO_5_BIT);
g16=uint16(color.green * RATIO_8_TO_6_BIT);
b16=uint16(color.blue * RATIO_8_TO_5_BIT);
r16=uint16(color.red >> 3);
g16=uint16(color.green >> 2);
b16=uint16(color.blue >> 3);
color16 |= r16 << 11;
color16 |= g16 << 5;