diff options
Diffstat (limited to 'src/FbTk/TextureRender.cc')
-rw-r--r-- | src/FbTk/TextureRender.cc | 79 |
1 files changed, 41 insertions, 38 deletions
diff --git a/src/FbTk/TextureRender.cc b/src/FbTk/TextureRender.cc index 7abc436..df7a550 100644 --- a/src/FbTk/TextureRender.cc +++ b/src/FbTk/TextureRender.cc | |||
@@ -109,7 +109,7 @@ struct Vec2 { | |||
109 | // negative: 'other' is counterclockwise of this | 109 | // negative: 'other' is counterclockwise of this |
110 | // 0: same line | 110 | // 0: same line |
111 | int cross(int other_x, int other_y) const { | 111 | int cross(int other_x, int other_y) const { |
112 | return (x * other_y) - (other_x * y); | 112 | return (x * other_y) - (y * other_x); |
113 | } | 113 | } |
114 | }; | 114 | }; |
115 | 115 | ||
@@ -165,13 +165,13 @@ typedef void (*prepareFunc)(size_t, FbTk::RGBA*, const FbTk::Color*, const FbTk: | |||
165 | void prepareLinearTable(size_t size, FbTk::RGBA* rgba, | 165 | void prepareLinearTable(size_t size, FbTk::RGBA* rgba, |
166 | const FbTk::Color* from, const FbTk::Color* to, double scale) { | 166 | const FbTk::Color* from, const FbTk::Color* to, double scale) { |
167 | 167 | ||
168 | const double delta_r = (double)(to->red() - from->red()) / (double)size; | 168 | const double r = from->red(); |
169 | const double delta_g = (double)(to->green() - from->green()) / (double)size; | 169 | const double g = from->green(); |
170 | const double delta_b = (double)(to->blue() - from->blue()) / (double)size; | 170 | const double b = from->blue(); |
171 | 171 | ||
172 | double r = from->red(); | 172 | const double delta_r = (to->red() - r) / (double)size; |
173 | double g = from->green(); | 173 | const double delta_g = (to->green() - g) / (double)size; |
174 | double b = from->blue(); | 174 | const double delta_b = (to->blue() - b) / (double)size; |
175 | 175 | ||
176 | size_t i; | 176 | size_t i; |
177 | for (i = 0; i < size; ++i) { | 177 | for (i = 0; i < size; ++i) { |
@@ -184,19 +184,20 @@ void prepareLinearTable(size_t size, FbTk::RGBA* rgba, | |||
184 | void prepareSquareTable(size_t size, FbTk::RGBA* rgba, | 184 | void prepareSquareTable(size_t size, FbTk::RGBA* rgba, |
185 | const FbTk::Color* from, const FbTk::Color* to, double scale) { | 185 | const FbTk::Color* from, const FbTk::Color* to, double scale) { |
186 | 186 | ||
187 | const double delta_r = (double)(to->red() - from->red()); | ||
188 | const double delta_g = (double)(to->green() - from->green()); | ||
189 | const double delta_b = (double)(to->blue() - from->blue()); | ||
190 | 187 | ||
191 | double r = from->red(); | 188 | const double r = from->red(); |
192 | double g = from->green(); | 189 | const double g = from->green(); |
193 | double b = from->blue(); | 190 | const double b = from->blue(); |
191 | |||
192 | const double delta_r = (to->red() - r); | ||
193 | const double delta_g = (to->green() - g); | ||
194 | const double delta_b = (to->blue() - b); | ||
194 | 195 | ||
195 | double s; | 196 | double s; |
196 | size_t i; | 197 | size_t i; |
197 | for (i = 0; i < size; ++i) { | 198 | for (i = 0; i < size; ++i) { |
198 | s = 1.0 - ((double)(i + 1) / (double)size); | 199 | s = 1.0 - ((double)(i + 1) / (double)size); |
199 | s *=s; | 200 | s *= s; |
200 | rgba[i].r = static_cast<unsigned char>(scale * (r + (s * delta_r))); | 201 | rgba[i].r = static_cast<unsigned char>(scale * (r + (s * delta_r))); |
201 | rgba[i].g = static_cast<unsigned char>(scale * (g + (s * delta_g))); | 202 | rgba[i].g = static_cast<unsigned char>(scale * (g + (s * delta_g))); |
202 | rgba[i].b = static_cast<unsigned char>(scale * (b + (s * delta_b))); | 203 | rgba[i].b = static_cast<unsigned char>(scale * (b + (s * delta_b))); |
@@ -407,7 +408,7 @@ void renderPyramidGradient(bool interlaced, | |||
407 | 408 | ||
408 | // we need 2 gradients but use only 'one' buffer | 409 | // we need 2 gradients but use only 'one' buffer |
409 | FbTk::RGBA* x_gradient = (FbTk::RGBA*)&getGradientBuffer(s * sizeof(FbTk::RGBA))[0]; | 410 | FbTk::RGBA* x_gradient = (FbTk::RGBA*)&getGradientBuffer(s * sizeof(FbTk::RGBA))[0]; |
410 | FbTk::RGBA* y_gradient = &x_gradient[width]; | 411 | FbTk::RGBA* y_gradient = x_gradient + width; |
411 | 412 | ||
412 | prepareMirrorTable(prepareLinearTable, width, x_gradient, from, to, 0.5); | 413 | prepareMirrorTable(prepareLinearTable, width, x_gradient, from, to, 0.5); |
413 | prepareMirrorTable(prepareLinearTable, height, y_gradient, from, to, 0.5); | 414 | prepareMirrorTable(prepareLinearTable, height, y_gradient, from, to, 0.5); |
@@ -430,15 +431,15 @@ void renderPyramidGradient(bool interlaced, | |||
430 | 431 | ||
431 | 432 | ||
432 | /* | 433 | /* |
433 | * ................. | 434 | ................. |
434 | * ............. | 435 | ............. |
435 | * ......... | 436 | ......... |
436 | * .... '.' - x_gradient | 437 | .... '.' - x_gradient |
437 | * . ' ' - y_gradient | 438 | . ' ' - y_gradient |
438 | * .... | 439 | .... |
439 | * ......... | 440 | ......... |
440 | * ............. | 441 | ............. |
441 | * ................. | 442 | ................. |
442 | */ | 443 | */ |
443 | void renderRectangleGradient(bool interlaced, | 444 | void renderRectangleGradient(bool interlaced, |
444 | unsigned int width, unsigned int height, | 445 | unsigned int width, unsigned int height, |
@@ -450,13 +451,13 @@ void renderRectangleGradient(bool interlaced, | |||
450 | 451 | ||
451 | // we need 2 gradients but use only 'one' buffer | 452 | // we need 2 gradients but use only 'one' buffer |
452 | FbTk::RGBA* x_gradient = (FbTk::RGBA*)&getGradientBuffer(s * sizeof(FbTk::RGBA))[0]; | 453 | FbTk::RGBA* x_gradient = (FbTk::RGBA*)&getGradientBuffer(s * sizeof(FbTk::RGBA))[0]; |
453 | FbTk::RGBA* y_gradient = &x_gradient[width]; | 454 | FbTk::RGBA* y_gradient = x_gradient + width; |
454 | 455 | ||
455 | prepareMirrorTable(prepareLinearTable, width, x_gradient, from, to, 1.0); | 456 | prepareMirrorTable(prepareLinearTable, width, x_gradient, from, to, 1.0); |
456 | prepareMirrorTable(prepareLinearTable, height, y_gradient, from, to, 1.0); | 457 | prepareMirrorTable(prepareLinearTable, height, y_gradient, from, to, 1.0); |
457 | 458 | ||
458 | // diagonal vectors | 459 | // diagonal vectors |
459 | const Vec2 a = { static_cast<int>(width) - 1, static_cast<int>(height - 1) }; | 460 | const Vec2 a = { static_cast<int>(width) - 1, static_cast<int>(height) - 1 }; |
460 | const Vec2 b = { a.x, -a.y }; | 461 | const Vec2 b = { a.x, -a.y }; |
461 | 462 | ||
462 | int x; | 463 | int x; |
@@ -468,8 +469,8 @@ void renderRectangleGradient(bool interlaced, | |||
468 | 469 | ||
469 | // check, if the point (x, y) is left or right of the vectors | 470 | // check, if the point (x, y) is left or right of the vectors |
470 | // 'a' and 'b'. if the point is on the same side for both 'a' and | 471 | // 'a' and 'b'. if the point is on the same side for both 'a' and |
471 | // 'b' (a.cross() is equal to b.cross()) then use the x_gradient, | 472 | // 'b' (sign(a.cross()) is equal to sign(b.cross())) then use the |
472 | // otherwise use y_gradient | 473 | // y_gradient, otherwise use x_gradient |
473 | 474 | ||
474 | if (sign(a.cross(x, y)) * sign(b.cross(x, b.y + y)) < 0) { | 475 | if (sign(a.cross(x, y)) * sign(b.cross(x, b.y + y)) < 0) { |
475 | rgba[i] = x_gradient[x]; | 476 | rgba[i] = x_gradient[x]; |
@@ -510,8 +511,8 @@ void renderPipeCrossGradient(bool interlaced, | |||
510 | 511 | ||
511 | // check, if the point (x, y) is left or right of the vectors | 512 | // check, if the point (x, y) is left or right of the vectors |
512 | // 'a' and 'b'. if the point is on the same side for both 'a' and | 513 | // 'a' and 'b'. if the point is on the same side for both 'a' and |
513 | // 'b' (a.cross() is equal to b.cross()) then use the x_gradient, | 514 | // 'b' (sign(a.cross()) is equal to sign(b.cross())) then use the |
514 | // otherwise use y_gradient | 515 | // x_gradient, otherwise use y_gradient |
515 | 516 | ||
516 | if (sign(a.cross(x, y)) * sign(b.cross(x, b.y + y)) > 0) { | 517 | if (sign(a.cross(x, y)) * sign(b.cross(x, b.y + y)) > 0) { |
517 | rgba[i] = x_gradient[x]; | 518 | rgba[i] = x_gradient[x]; |
@@ -573,18 +574,19 @@ void renderEllipticGradient(bool interlaced, | |||
573 | int x; | 574 | int x; |
574 | int y; | 575 | int y; |
575 | 576 | ||
576 | double dr = (double)to->red() - (double)from->red() ; | ||
577 | double dg = (double)to->green()- (double)from->green() ; | ||
578 | double db = (double)to->blue() - (double)from->blue() ; | ||
579 | |||
580 | int w2 = width/2; | ||
581 | int h2 = height/2; | ||
582 | 577 | ||
583 | double d; | ||
584 | double r = to->red(); | 578 | double r = to->red(); |
585 | double g = to->green(); | 579 | double g = to->green(); |
586 | double b = to->blue(); | 580 | double b = to->blue(); |
587 | 581 | ||
582 | double dr = r - from->red(); | ||
583 | double dg = g - from->green(); | ||
584 | double db = b - from->blue(); | ||
585 | |||
586 | int w2 = width/2; | ||
587 | int h2 = height/2; | ||
588 | |||
589 | double d; | ||
588 | 590 | ||
589 | for (i = 0, y = -h2; y < h2; ++y) { | 591 | for (i = 0, y = -h2; y < h2; ++y) { |
590 | for (x = -w2; x < w2; ++x, ++i) { | 592 | for (x = -w2; x < w2; ++x, ++i) { |
@@ -829,8 +831,9 @@ Pixmap TextureRender::renderGradient(const FbTk::Texture &texture) { | |||
829 | } | 831 | } |
830 | } | 832 | } |
831 | 833 | ||
832 | if (inverted) | 834 | if (inverted) { |
833 | invertRGB(width, height, rgba); | 835 | invertRGB(width, height, rgba); |
836 | } | ||
834 | 837 | ||
835 | return renderPixmap(); | 838 | return renderPixmap(); |
836 | 839 | ||