From 94fddc09c064555721dc521e3e94ed6f610653b9 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Wed, 6 Feb 2013 08:53:59 +0100 Subject: Fix bug in renderEllipticGradient() For odd 'widths' and 'heigths' the texture would not be filled completely: Given a 'width' of 5 we would render only 4 instances of x (-2, 1, 0, 1) instead of the needed 5. This results in a texture which looks a bit cut off to the bottom right side. --- src/FbTk/TextureRender.cc | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/FbTk/TextureRender.cc b/src/FbTk/TextureRender.cc index df7a550..68b98df 100644 --- a/src/FbTk/TextureRender.cc +++ b/src/FbTk/TextureRender.cc @@ -570,31 +570,34 @@ void renderEllipticGradient(bool interlaced, const FbTk::Color* from, const FbTk::Color* to, FbTk::ImageControl& imgctrl) { - size_t i; - int x; - int y; + const double r = to->red(); + const double g = to->green(); + const double b = to->blue(); + const double dr = r - from->red(); + const double dg = g - from->green(); + const double db = b - from->blue(); - double r = to->red(); - double g = to->green(); - double b = to->blue(); + const double w2 = width / 2.0; + const double h2 = height / 2.0; - double dr = r - from->red(); - double dg = g - from->green(); - double db = b - from->blue(); - - int w2 = width/2; - int h2 = height/2; + const double sw = 1.0 / (w2 * w2); + const double sh = 1.0 / (h2 * h2); + size_t i; + int x; + int y; + double _x; + double _y; double d; - for (i = 0, y = -h2; y < h2; ++y) { - for (x = -w2; x < w2; ++x, ++i) { + for (i = 0, y = 0; y < height; ++y) { + for (x = 0; x < width; ++x, ++i) { - d = ((double)(x*x) / (double)(w2*w2)) - + ((double)(y*y) / (double)(h2*h2)); + _x = x - w2; + _y = y - h2; - d *= 0.5; + d = ((_x * _x * sw) + (_y * _y * sh)) / 2.0; rgba[i].r = (unsigned char)(r - (d * dr)); rgba[i].g = (unsigned char)(g - (d * dg)); -- cgit v0.11.2