static void blur_rows (guchar *dst_buffer, guchar *tmp_buffer, int buffer_width, int buffer_height, int d) { int i; for (i = 0; i < buffer_height; i++) { guchar *row = dst_buffer + i * buffer_width; /* We want to produce a symmetric blur that spreads a pixel * equally far to the left and right. If d is odd that happens * naturally, but for d even, we approximate by using a blur * on either side and then a centered blur of size d + 1. * (technique also from the SVG specification) */ if (d % 2 == 1) { blur_xspan (row, tmp_buffer, buffer_width, d, 0); blur_xspan (row, tmp_buffer, buffer_width, d, 0); blur_xspan (row, tmp_buffer, buffer_width, d, 0); } else { blur_xspan (row, tmp_buffer, buffer_width, d, 1); blur_xspan (row, tmp_buffer, buffer_width, d, -1); blur_xspan (row, tmp_buffer, buffer_width, d + 1, 0); } } }
static void blur_rows (cairo_region_t *convolve_region, int x_offset, int y_offset, guchar *buffer, int buffer_width, int buffer_height, int d) { int i, j; int n_rectangles; guchar *tmp_buffer; tmp_buffer = g_malloc (buffer_width); n_rectangles = cairo_region_num_rectangles (convolve_region); for (i = 0; i < n_rectangles; i++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (convolve_region, i, &rect); for (j = y_offset + rect.y; j < y_offset + rect.y + rect.height; j++) { guchar *row = buffer + j * buffer_width; int x0 = x_offset + rect.x; int x1 = x0 + rect.width; /* We want to produce a symmetric blur that spreads a pixel * equally far to the left and right. If d is odd that happens * naturally, but for d even, we approximate by using a blur * on either side and then a centered blur of size d + 1. * (techique also from the SVG specification) */ if (d % 2 == 1) { blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, 0); blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, 0); blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, 0); } else { blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, 1); blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d, -1); blur_xspan (row, tmp_buffer, buffer_width, x0, x1, d + 1, 0); } } } g_free (tmp_buffer); }