From 1da726047a455a79b81cff64d7c2c0174aee7763 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 9 Jun 2019 01:01:53 +0100 Subject: [PATCH] new backend: don't assume center of blur kernel is 1 Also fill the center of parsed kernel with 1. This shouldn't change the behavior of the old backends since they will modify the center of the kernels. Signed-off-by: Yuxuan Shui --- src/backend/gl/gl_common.c | 7 ++----- src/backend/xrender/xrender.c | 12 ++++++++---- src/config.c | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/backend/gl/gl_common.c b/src/backend/gl/gl_common.c index 10092a9..02913e1 100644 --- a/src/backend/gl/gl_common.c +++ b/src/backend/gl/gl_common.c @@ -18,6 +18,7 @@ #include "utils.h" #include "backend/gl/gl_common.h" +#include "backend/backend_common.h" #define GLSL(version, ...) "#version " #version "\n" #__VA_ARGS__ #define QUOTE(...) #__VA_ARGS__ @@ -713,11 +714,7 @@ static bool gl_init_blur(struct gl_data *gd, conv *const *const kernels, int nke for (int j = 0; j < height; ++j) { for (int k = 0; k < width; ++k) { double val; - if (height / 2 == j && width / 2 == k) { - val = 1; - } else { - val = kern->data[j * width + k]; - } + val = kern->data[j * width + k]; if (val == 0) { continue; } diff --git a/src/backend/xrender/xrender.c b/src/backend/xrender/xrender.c index defe0d3..57fcd9a 100644 --- a/src/backend/xrender/xrender.c +++ b/src/backend/xrender/xrender.c @@ -183,9 +183,10 @@ static bool blur(backend_t *backend_data, double opacity, const region_t *reg_bl // be applied on source picture, to get the nearby pixels outside the // window. // TODO cache converted blur_kerns - xcb_render_set_picture_filter( - c, src_pict, to_u16_checked(strlen(filter)), filter, - to_u32_checked(xd->x_blur_kernel[i]->size), xd->x_blur_kernel[i]->kernel); + xcb_render_set_picture_filter(c, src_pict, to_u16_checked(strlen(filter)), + filter, + to_u32_checked(xd->x_blur_kernel[i]->size), + xd->x_blur_kernel[i]->kernel); if (i < xd->x_blur_kernel_count - 1 || i == 0) { // This is not the last pass, or this is the first pass @@ -552,7 +553,10 @@ backend_t *backend_xrender_init(session_t *ps) { xd->x_blur_kernel = ccalloc(ps->o.blur_kernel_count, struct x_convolution_kernel *); for (int i = 0; i < ps->o.blur_kernel_count; i++) { - x_create_convolution_kernel(ps->o.blur_kerns[i], 1, &xd->x_blur_kernel[i]); + int center = ps->o.blur_kerns[i]->h * ps->o.blur_kerns[i]->w / 2; + x_create_convolution_kernel(ps->o.blur_kerns[i], + ps->o.blur_kerns[i]->data[center], + &xd->x_blur_kernel[i]); } xd->x_blur_kernel_count = ps->o.blur_kernel_count; return &xd->base; diff --git a/src/config.c b/src/config.c index 1f46df9..536c1b3 100644 --- a/src/config.c +++ b/src/config.c @@ -139,7 +139,7 @@ conv *parse_blur_kern(const char *src, const char **endptr, bool *hasneg) { for (int i = 0; i < width * height; ++i) { // Ignore the center element if (i == skip) { - matrix->data[i] = 0; + matrix->data[i] = 1; continue; } if (src == (pc = parse_readnum(src, &val))) {