From 873302649a3374dfae65aae932a6a12f81c09940 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Mon, 17 Nov 2008 22:23:55 -0500 Subject: [PATCH] Optimize blur a bit more. --- cairo-util.c | 19 +++++++++++++------ 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; diff --git a/window.c b/window.c index 951c4b0..634952d 100644 --- a/window.c +++ b/window.c @@ -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); -- 2.7.4