From 4ee616c528e84a21dc187074025e6474ae4c9971 Mon Sep 17 00:00:00 2001 From: Johannes Winkelmann Date: Tue, 30 Aug 2005 19:13:01 +0000 Subject: [PATCH] 16-bit color adjustments: save 6 divisions per graph by using precalculated values git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@247 7f574dfc-610e-0410-a909-a81674777703 --- src/conky.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/conky.c b/src/conky.c index 9d5c6ac7..11bc5aa9 100644 --- a/src/conky.c +++ b/src/conky.c @@ -527,6 +527,10 @@ inline void graph_append(struct special_t *graph, double f) short colour_depth = 0; void set_up_gradient(); +/* precalculated: 31/255, and 63/255 */ +#define CONST_8_TO_5_BITS 0.12156862745098 +#define CONST_8_TO_6_BITS 0.247058823529412 + /* adjust color values depending on color depth*/ static unsigned int adjust_colors(unsigned int color) { @@ -538,9 +542,9 @@ static unsigned int adjust_colors(unsigned int color) r = (color & 0xff0000) >> 16; g = (color & 0xff00) >> 8; b = color & 0xff; - color = (int)(r / 0xff * 0x1f) << 11; - color |= (int)(g / 0xff * 0x3f) << 5; - color |= (int)(b / 0xff * 0x1f); + color = (int)(r * CONST_8_TO_5_BITS) << 11; + color |= (int)(g * CONST_8_TO_6_BITS) << 5; + color |= (int)(b * CONST_8_TO_5_BITS); } return color; }