From f64ac97a913ee2b04de841ff8d1e0fc0d9502f64 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 9 Jun 2019 00:44:46 +0100 Subject: [PATCH] Return kernel count from kernel generation functions Signed-off-by: Yuxuan Shui --- src/backend/backend_common.c | 23 +++++++++++++---------- src/backend/backend_common.h | 8 ++++++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/backend/backend_common.c b/src/backend/backend_common.c index 2e41de7..d4ee3f4 100644 --- a/src/backend/backend_common.c +++ b/src/backend/backend_common.c @@ -280,10 +280,10 @@ default_backend_render_shadow(backend_t *backend_data, int width, int height, return ret; } -static struct conv **generate_box_blur_kernel(int blur_size) { +static struct conv **generate_box_blur_kernel(int blur_size, int *kernel_count) { int r = blur_size * 2 + 1; assert(r > 0); - auto ret = ccalloc(3, struct conv *); + auto ret = ccalloc(2, struct conv *); ret[0] = cvalloc(sizeof(struct conv) + sizeof(double) * (size_t)r); ret[1] = cvalloc(sizeof(struct conv) + sizeof(double) * (size_t)r); ret[0]->w = r; @@ -294,38 +294,41 @@ static struct conv **generate_box_blur_kernel(int blur_size) { ret[0]->data[i] = 1; ret[1]->data[i] = 1; } + *kernel_count = 2; return ret; } -static struct conv **generate_gaussian_blur_kernel(int blur_size, double blur_deviation) { +static struct conv ** +generate_gaussian_blur_kernel(int blur_size, double blur_deviation, int *kernel_count) { int r = blur_size * 2 + 1; assert(r > 0); - auto ret = ccalloc(3, struct conv *); + auto ret = ccalloc(2, struct conv *); ret[0] = cvalloc(sizeof(struct conv) + sizeof(double) * (size_t)r); ret[1] = cvalloc(sizeof(struct conv) + sizeof(double) * (size_t)r); ret[0]->w = r; ret[0]->h = 1; ret[1]->w = 1; ret[1]->h = r; - for (int i = 0; i < blur_size; i++) { + for (int i = 0; i <= blur_size; i++) { ret[0]->data[i] = ret[0]->data[r - i - 1] = 1.0 / (sqrt(2.0 * M_PI) * blur_deviation) * exp(-(blur_size - i) * (blur_size - i) / (2 * blur_deviation * blur_deviation)); - ret[1]->data[i] = ret[1]->data[r - i - 1] = ret[0]->data[0]; + ret[1]->data[i] = ret[1]->data[r - i - 1] = ret[0]->data[i]; } + *kernel_count = 2; return ret; } /// Generate blur kernels for gaussian and box blur methods. Generated kernel is not /// normalized, and the center element will always be 1. -struct conv ** -generate_blur_kernel(enum blur_method method, int blur_size, double blur_deviation) { +struct conv **generate_blur_kernel(enum blur_method method, int blur_size, + double blur_deviation, int *kernel_count) { assert(blur_size >= 0); switch (method) { - case BLUR_METHOD_BOX: return generate_box_blur_kernel(blur_size); + case BLUR_METHOD_BOX: return generate_box_blur_kernel(blur_size, kernel_count); case BLUR_METHOD_GAUSSIAN: - return generate_gaussian_blur_kernel(blur_size, blur_deviation); + return generate_gaussian_blur_kernel(blur_size, blur_deviation, kernel_count); default: break; } return NULL; diff --git a/src/backend/backend_common.h b/src/backend/backend_common.h index 5800399..88a4c27 100644 --- a/src/backend/backend_common.h +++ b/src/backend/backend_common.h @@ -7,6 +7,7 @@ #include +#include "config.h" #include "region.h" typedef struct session session_t; @@ -22,8 +23,8 @@ bool build_shadow(xcb_connection_t *, xcb_drawable_t, double opacity, int width, xcb_render_picture_t solid_picture(xcb_connection_t *, xcb_drawable_t, bool argb, double a, double r, double g, double b); -xcb_image_t *make_shadow(xcb_connection_t *c, const conv *kernel, double opacity, - int width, int height); +xcb_image_t * +make_shadow(xcb_connection_t *c, const conv *kernel, double opacity, int width, int height); /// The default implementation of `is_win_transparent`, it simply looks at win::mode. So /// this is not suitable for backends that alter the content of windows @@ -38,3 +39,6 @@ default_backend_render_shadow(backend_t *backend_data, int width, int height, const conv *kernel, double r, double g, double b, double a); void init_backend_base(struct backend_base *base, session_t *ps); + +struct conv **generate_blur_kernel(enum blur_method method, int blur_size, + double blur_deviation, int *kernel_count);