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 <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-06-09 01:01:53 +01:00
parent f64ac97a91
commit 1da726047a
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 11 additions and 10 deletions

View File

@ -18,6 +18,7 @@
#include "utils.h" #include "utils.h"
#include "backend/gl/gl_common.h" #include "backend/gl/gl_common.h"
#include "backend/backend_common.h"
#define GLSL(version, ...) "#version " #version "\n" #__VA_ARGS__ #define GLSL(version, ...) "#version " #version "\n" #__VA_ARGS__
#define QUOTE(...) #__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 j = 0; j < height; ++j) {
for (int k = 0; k < width; ++k) { for (int k = 0; k < width; ++k) {
double val; double val;
if (height / 2 == j && width / 2 == k) { val = kern->data[j * width + k];
val = 1;
} else {
val = kern->data[j * width + k];
}
if (val == 0) { if (val == 0) {
continue; continue;
} }

View File

@ -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 // be applied on source picture, to get the nearby pixels outside the
// window. // window.
// TODO cache converted blur_kerns // TODO cache converted blur_kerns
xcb_render_set_picture_filter( xcb_render_set_picture_filter(c, src_pict, to_u16_checked(strlen(filter)),
c, src_pict, to_u16_checked(strlen(filter)), filter, filter,
to_u32_checked(xd->x_blur_kernel[i]->size), xd->x_blur_kernel[i]->kernel); 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) { if (i < xd->x_blur_kernel_count - 1 || i == 0) {
// This is not the last pass, or this is the first pass // 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 *); 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++) { 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; xd->x_blur_kernel_count = ps->o.blur_kernel_count;
return &xd->base; return &xd->base;

View File

@ -139,7 +139,7 @@ conv *parse_blur_kern(const char *src, const char **endptr, bool *hasneg) {
for (int i = 0; i < width * height; ++i) { for (int i = 0; i < width * height; ++i) {
// Ignore the center element // Ignore the center element
if (i == skip) { if (i == skip) {
matrix->data[i] = 0; matrix->data[i] = 1;
continue; continue;
} }
if (src == (pc = parse_readnum(src, &val))) { if (src == (pc = parse_readnum(src, &val))) {