mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-18 12:00:31 +01:00
wrlib: changed Gamma Correction calculation to use single-precision float
The original code was using double precision floating point to perform the color corrections for the creation of the standard colormap. This precision is not necessary because color coding is 16 bits anyway, and on some architecture the double precision comes with a cost. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
9ab2203456
commit
b64d9e6be0
@@ -70,6 +70,7 @@ AC_CACHE_CHECK([if sinf+cosf are defined in math.h], [wm_cv_libm_sinf],
|
||||
a = atan2f(a, b);
|
||||
b = cosf(a);
|
||||
a = sinf(b);
|
||||
a = powf(a, b);
|
||||
return (int)a;])],
|
||||
[wm_cv_libm_sinf="`echo "$wm_arg" | sed -e 's,^.*% *,,' `" ; break])
|
||||
done
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
#include "scale.h"
|
||||
|
||||
|
||||
#ifndef HAVE_FLOAT_MATHFUNC
|
||||
#define powf(x, y) ((float) pow((double)(x), (double)(y)))
|
||||
#endif
|
||||
|
||||
static Bool bestContext(Display * dpy, int screen_number, RContext * context);
|
||||
|
||||
static const RContextAttributes DEFAULT_CONTEXT_ATTRIBS = {
|
||||
@@ -248,13 +252,13 @@ static Bool allocatePseudoColor(RContext *ctx)
|
||||
|
||||
if ((ctx->attribs->flags & RC_GammaCorrection) && ctx->attribs->rgamma > 0
|
||||
&& ctx->attribs->ggamma > 0 && ctx->attribs->bgamma > 0) {
|
||||
double rg, gg, bg;
|
||||
double tmp;
|
||||
float rg, gg, bg;
|
||||
float tmp;
|
||||
|
||||
/* do gamma correction */
|
||||
rg = 1.0 / ctx->attribs->rgamma;
|
||||
gg = 1.0 / ctx->attribs->ggamma;
|
||||
bg = 1.0 / ctx->attribs->bgamma;
|
||||
rg = 1.0F / ctx->attribs->rgamma;
|
||||
gg = 1.0F / ctx->attribs->ggamma;
|
||||
bg = 1.0F / ctx->attribs->bgamma;
|
||||
for (r = 0; r < cpc; r++) {
|
||||
for (g = 0; g < cpc; g++) {
|
||||
for (b = 0; b < cpc; b++) {
|
||||
@@ -263,14 +267,14 @@ static Bool allocatePseudoColor(RContext *ctx)
|
||||
colors[i].blue = (b * 0xffff) / (cpc - 1);
|
||||
colors[i].flags = DoRed | DoGreen | DoBlue;
|
||||
|
||||
tmp = (double)colors[i].red / 65536.0;
|
||||
colors[i].red = (unsigned short)(65536.0 * pow(tmp, rg));
|
||||
tmp = (float) colors[i].red / 65536.0F;
|
||||
colors[i].red = (unsigned short)(65536.0F * powf(tmp, rg));
|
||||
|
||||
tmp = (double)colors[i].green / 65536.0;
|
||||
colors[i].green = (unsigned short)(65536.0 * pow(tmp, gg));
|
||||
tmp = (float) colors[i].green / 65536.0F;
|
||||
colors[i].green = (unsigned short)(65536.0F * powf(tmp, gg));
|
||||
|
||||
tmp = (double)colors[i].blue / 65536.0;
|
||||
colors[i].blue = (unsigned short)(65536.0 * pow(tmp, bg));
|
||||
tmp = (float) colors[i].blue / 65536.0F;
|
||||
colors[i].blue = (unsigned short)(65536.0F * powf(tmp, bg));
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user