diff options
author | Andrea Canciani <ranma42@gmail.com> | 2011-08-09 13:15:53 +0200 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2011-08-09 13:15:53 +0200 |
commit | 5068a94f929c0e461e79420bc2e243c9135d708d (patch) | |
tree | b4e11bb06754a3f647e42be4f046c508c5dd9971 | |
parent | 59b5d18e52d9dfe5c85384f019f5e62df368c992 (diff) |
-rw-r--r-- | pixman/pixman-gradient-walker.c | 117 | ||||
-rw-r--r-- | pixman/pixman-repeat.c | 96 |
2 files changed, 99 insertions, 114 deletions
diff --git a/pixman/pixman-gradient-walker.c b/pixman/pixman-gradient-walker.c index ec5285e..6ee8d39 100644 --- a/pixman/pixman-gradient-walker.c +++ b/pixman/pixman-gradient-walker.c @@ -74,119 +74,9 @@ _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker, static const pixman_color_t transparent_black = { 0, 0, 0, 0 }; - switch (walker->spread) - { - case PIXMAN_REPEAT_NORMAL: - x = (int32_t)pos & 0xFFFF; - for (n = 0; n < count; n++) - if (x < stops[n].x) - break; - if (n == 0) - { - left_x = stops[count - 1].x - 0x10000; - left_c = &stops[count - 1].color; - } - else - { - left_x = stops[n - 1].x; - left_c = &stops[n - 1].color; - } - - if (n == count) - { - right_x = stops[0].x + 0x10000; - right_c = &stops[0].color; - } - else - { - right_x = stops[n].x; - right_c = &stops[n].color; - } - left_x += (pos - x); - right_x += (pos - x); - break; - - case PIXMAN_REPEAT_PAD: - for (n = 0; n < count; n++) - if (pos < stops[n].x) - break; - - if (n == 0) - { - left_x = INT32_MIN; - left_c = &stops[0].color; - } - else - { - left_x = stops[n - 1].x; - left_c = &stops[n - 1].color; - } - - if (n == count) - { - right_x = INT32_MAX; - right_c = &stops[n - 1].color; - } - else - { - right_x = stops[n].x; - right_c = &stops[n].color; - } - break; - - case PIXMAN_REPEAT_REFLECT: - x = (int32_t)pos & 0xFFFF; - if ((int32_t)pos & 0x10000) - x = 0x10000 - x; - for (n = 0; n < count; n++) - if (x < stops[n].x) - break; - - if (n == 0) - { - left_x = -stops[0].x; - left_c = &stops[0].color; - } - else - { - left_x = stops[n - 1].x; - left_c = &stops[n - 1].color; - } - - if (n == count) - { - right_x = 0x20000 - stops[n - 1].x; - right_c = &stops[n - 1].color; - } - else - { - right_x = stops[n].x; - right_c = &stops[n].color; - } - - if ((int32_t)pos & 0x10000) - { - const pixman_color_t *tmp_c; - int32_t tmp_x; - - tmp_x = 0x10000 - right_x; - right_x = 0x10000 - left_x; - left_x = tmp_x; - - tmp_c = right_c; - right_c = left_c; - left_c = tmp_c; - - x = 0x10000 - x; - } - left_x += (pos - x); - right_x += (pos - x); - break; - - default: /* REPEAT_NONE */ - for (n = 0; n < count; n++) - if (pos < stops[n].x) - break; + for (n = 0; n < count; n++) + if (pos < stops[n].x) + break; if (n == 0) { @@ -207,7 +97,6 @@ _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker, left_c = &stops[n - 1].color; right_c = &stops[n].color; } - } walker->left_x = left_x; walker->right_x = right_x; diff --git a/pixman/pixman-repeat.c b/pixman/pixman-repeat.c new file mode 100644 index 0000000..8cf7245 --- /dev/null +++ b/pixman/pixman-repeat.c @@ -0,0 +1,96 @@ +/* + * + * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. + * 2005 Lars Knoll & Zack Rusin, Trolltech + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include "pixman-private.h" + +static force_inline double +_pixman_clamp01 (double x) +{ + if (x < 0.0) + return 0.0; + else if (x > 1.0) + return 1.0; + else + return x; +} + +static force_inline double +_pixman_clamp01nan (double x) +{ + if (x < 0.0 || x > 1.0) + return PIXMAN_NAN; + else + return x; +} + +static force_inline double +_pixman_frac (double x) +{ + return x; +} + +static force_inline double +_pixman_tent (double x) +{ + return fabs (pixman_frac (x*0.5 + 0.5)*2.0 - 1.0); +} + +#define REPEAT_TEMPLATE(name, op) \ + static void \ + _repeat_##name (double *buffer, int width) \ + { \ + for (i = 0; i < width; i++) \ + { \ + if (buffer[i] != PIXMAN_NAN) \ + buffer[i] = op (buffer[i]); \ + } \ + } \ + + +REPEAT_TEMPLATE(none, _pixman_clamp01nan) +REPEAT_TEMPLATE(normal, _pixman_frac) +REPEAT_TEMPLATE(reflect, _pixman_tent) +REPEAT_TEMPLATE(pad, _pixman_clamp01) + +static const repeat_function_t _repeat_function[] { + _repeat_none, + _repeat_normal, + _repeat_reflect, + _repeat_pad +} + +uint32_t * +repeat_function_get_scanline_narrow (uint32_t *buffer, + int width, + const uint32_t *mask, + const gradient_t *gradient) +{ + _repeat_function[gradient->common.repeat] ((double *) buffer, width); + + return buffer; +} |