summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2011-10-14 13:04:48 (GMT)
committerSøren Sandmann Pedersen <ssp@redhat.com>2011-10-15 14:50:20 (GMT)
commitec7c9c2b6865b48b8bd14e4509538f8fcbe93463 (patch)
tree69cd0c78bf0257f7890f1775d87783be4228564d
parent2d0da8ab8d8fef60ed1bbb9d6b75f66577c3f85d (diff)
downloadpixman-ec7c9c2b6865b48b8bd14e4509538f8fcbe93463.tar.gz
pixman-ec7c9c2b6865b48b8bd14e4509538f8fcbe93463.tar.xz
Simplify gradient_walker_reset()
The code that searches for the closest color stop to the given position is duplicated across the various repeat modes. Replace the switch with two if/else constructions, and put the search code between them.
-rw-r--r--pixman/pixman-gradient-walker.c93
1 files changed, 31 insertions, 62 deletions
diff --git a/pixman/pixman-gradient-walker.c b/pixman/pixman-gradient-walker.c
index 3848247..048039e 100644
--- a/pixman/pixman-gradient-walker.c
+++ b/pixman/pixman-gradient-walker.c
@@ -56,57 +56,40 @@ gradient_walker_reset (pixman_gradient_walker_t *walker,
int n, count = walker->num_stops;
pixman_gradient_stop_t *stops = walker->stops;
- switch (walker->repeat)
+ if (walker->repeat == PIXMAN_REPEAT_NORMAL)
{
- case PIXMAN_REPEAT_NORMAL:
- x = (int32_t)pos & 0xFFFF;
- for (n = 0; n < count; n++)
- {
- if (x < stops[n].x)
- break;
- }
-
- left_x = stops[n - 1].x;
- left_c = &stops[n - 1].color;
-
- 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;
- }
-
- left_x = stops[n - 1].x;
- left_c = &stops[n - 1].color;
-
- right_x = stops[n].x;
- right_c = &stops[n].color;
- break;
-
- case PIXMAN_REPEAT_REFLECT:
- x = (int32_t)pos & 0xFFFF;
+ x = (int32_t)pos & 0xffff;
+ }
+ else if (walker->repeat == 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;
- }
-
- left_x = stops[n - 1].x;
- left_c = &stops[n - 1].color;
-
- right_x = stops[n].x;
- right_c = &stops[n].color;
-
+ }
+ else
+ {
+ x = pos;
+ }
+
+ for (n = 0; n < count; n++)
+ {
+ if (x < stops[n].x)
+ break;
+ }
+
+ left_x = stops[n - 1].x;
+ left_c = &stops[n - 1].color;
+
+ right_x = stops[n].x;
+ right_c = &stops[n].color;
+
+ if (walker->repeat == PIXMAN_REPEAT_NORMAL)
+ {
+ left_x += (pos - x);
+ right_x += (pos - x);
+ }
+ else if (walker->repeat == PIXMAN_REPEAT_REFLECT)
+ {
if ((int32_t)pos & 0x10000)
{
pixman_color_t *tmp_c;
@@ -124,20 +107,6 @@ gradient_walker_reset (pixman_gradient_walker_t *walker,
}
left_x += (pos - x);
right_x += (pos - x);
- break;
-
- default: /* REPEAT_NONE */
- for (n = 0; n < count; n++)
- {
- if (pos < stops[n].x)
- break;
- }
-
- left_x = stops[n - 1].x;
- left_c = &stops[n - 1].color;
-
- right_x = stops[n].x;
- right_c = &stops[n].color;
}
walker->left_x = left_x;