diff options
author | Kristian Høgsberg <krh@redhat.com> | 2008-11-17 22:23:55 -0500 |
---|---|---|
committer | Kristian Høgsberg <krh@redhat.com> | 2008-11-17 22:23:55 -0500 |
commit | 873302649a3374dfae65aae932a6a12f81c09940 (patch) | |
tree | d651563214ea2938f557cd71b9ac8b0c45b7cfe0 | |
parent | 8c304f6d9ace435817506b18b228b62787b1ce15 (diff) |
Optimize blur a bit more.
-rw-r--r-- | cairo-util.c | 19 | ||||
-rw-r--r-- | window.c | 5 |
2 files changed, 15 insertions, 9 deletions
diff --git a/cairo-util.c b/cairo-util.c index 94c7b03..3fd5176 100644 --- a/cairo-util.c +++ b/cairo-util.c @@ -100,6 +100,8 @@ buffer_create_from_cairo_surface(int fd, cairo_surface_t *surface) return buffer; } +#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) + void blur_surface(cairo_surface_t *surface, int margin) { @@ -107,10 +109,11 @@ blur_surface(cairo_surface_t *surface, int margin) int32_t width, height, stride, x, y, z, w; uint8_t *src, *dst; uint32_t *s, *d, a, p; - int i, j, k, size = 17, half; - uint8_t kernel[100]; + int i, j, k, size, half; + uint8_t kernel[10]; double f; + size = ARRAY_LENGTH(kernel); width = cairo_image_surface_get_width(surface); height = cairo_image_surface_get_height(surface); stride = cairo_image_surface_get_stride(surface); @@ -131,9 +134,11 @@ blur_surface(cairo_surface_t *surface, int margin) s = (uint32_t *) (src + i * stride); d = (uint32_t *) (dst + i * stride); for (j = 0; j < width; j++) { - if (margin < j && j < width - margin && - margin < i && i < height - margin) + if (margin < j && j < width - margin) { + d[j] = s[j]; continue; + } + x = 0; y = 0; z = 0; @@ -156,9 +161,11 @@ blur_surface(cairo_surface_t *surface, int margin) s = (uint32_t *) (dst + i * stride); d = (uint32_t *) (src + i * stride); for (j = 0; j < width; j++) { - if (margin <= j && j < width - margin && - margin <= i && i < height - margin) + if (margin <= i && i < height - margin) { + d[j] = s[j]; continue; + } + x = 0; y = 0; z = 0; @@ -88,7 +88,7 @@ draw_window(void *data) cairo_set_source_rgba(cr, 0, 0, 0, 0.5); rounded_rect(cr, 0, 0, window->width, window->height, radius); cairo_fill(cr); - blur_surface(surface, 16 + radius); + blur_surface(surface, 24 + radius); cairo_translate(cr, -5, -3); cairo_set_line_width (cr, border); @@ -148,7 +148,6 @@ draw_window(void *data) cairo_set_source_rgb(cr, 1, 1, 1); cairo_fill(cr); cairo_destroy(cr); - if (window->buffer != NULL) buffer_destroy(window->buffer, window->fd); buffer = buffer_create_from_cairo_surface(window->fd, surface); @@ -381,7 +380,7 @@ int main(int argc, char *argv[]) wl_display_set_event_handler(display, event_handler, window); - g_timeout_add(20, draw, window); + g_timeout_add(50, draw, window); g_main_loop_run(loop); |