From 0f989add083cd53c85b57d1e2431b2090d708133 Mon Sep 17 00:00:00 2001 From: Sebastian Frysztak Date: Wed, 15 Feb 2017 12:01:08 +0100 Subject: [PATCH] Pass blur strength from command line arguments --- blur.c | 6 ++---- blur.h | 3 +-- i3lock.c | 12 +++++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/blur.c b/blur.c index 04c9429..f78f8cb 100644 --- a/blur.c +++ b/blur.c @@ -24,9 +24,9 @@ #include #include "blur.h" -/* Performs a simple 2D Gaussian blur of radius @radius on surface @surface. */ +/* Performs a simple 2D Gaussian blur of standard devation @sigma surface @surface. */ void -blur_image_surface (cairo_surface_t *surface, int radius) +blur_image_surface (cairo_surface_t *surface, int sigma) { cairo_surface_t *tmp; int width, height; @@ -73,8 +73,6 @@ blur_image_surface (cairo_surface_t *surface, int radius) // [1]: http://www.peterkovesi.com/papers/FastGaussianSmoothing.pdf // [2]: https://en.wikipedia.org/wiki/Gaussian_blur#Mathematics - float sigma = 5; - int n = lrintf((sigma*sigma)/(SIGMA_AV*SIGMA_AV)); if (n < 3) n = 3; diff --git a/blur.h b/blur.h index c1fabc0..dfc1c3d 100644 --- a/blur.h +++ b/blur.h @@ -8,8 +8,7 @@ #define SIGMA_AV 2 #define HALF_KERNEL KERNEL_SIZE / 2 -void blur_image_surface (cairo_surface_t *surface, int radius); - +void blur_image_surface(cairo_surface_t *surface, int sigma); void blur_impl_horizontal_pass_sse2(uint32_t *src, uint32_t *dst, int width, int height); void blur_impl_horizontal_pass_generic(uint32_t *src, uint32_t *dst, int width, int height); diff --git a/i3lock.c b/i3lock.c index c6a6a45..9b50cde 100644 --- a/i3lock.c +++ b/i3lock.c @@ -79,7 +79,7 @@ char date_format[32] = "%A, %m %Y\0"; /* opts for blurring */ bool blur = false; bool step_blur = false; -int blur_radius = 5; +int blur_sigma = 5; uint32_t last_resolution[2]; xcb_window_t win; @@ -866,7 +866,7 @@ int main(int argc, char *argv[]) { {"timestr", required_argument, NULL, 0}, {"datestr", required_argument, NULL, 0}, - {"blur", no_argument, NULL, 'B'}, + {"blur", required_argument, NULL, 'B'}, {"ignore-empty-password", no_argument, NULL, 'e'}, {"inactivity-timeout", required_argument, NULL, 'I'}, @@ -878,7 +878,7 @@ int main(int argc, char *argv[]) { if ((username = pw->pw_name) == NULL) errx(EXIT_FAILURE, "pw->pw_name is NULL.\n"); - char *optstring = "hvnbdc:p:ui:teI:frsS:kB"; + char *optstring = "hvnbdc:p:ui:teI:frsS:kB:"; while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) { switch (o) { case 'v': @@ -950,6 +950,7 @@ int main(int argc, char *argv[]) { break; case 'B': blur = true; + blur_sigma = atoi(optarg); break; case 0: if (strcmp(longopts[optind].name, "debug") == 0) @@ -1084,7 +1085,8 @@ int main(int argc, char *argv[]) { break; default: errx(EXIT_FAILURE, "Syntax: i3lock-color [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]" - " [-i image.png] [-t] [-e] [-I timeout] [-f] [-r|s] [-S screen_number] [-k] [--fuckton-of-color-args=rrggbbaa]"); + " [-i image.png] [-t] [-e] [-I timeout] [-f] [-r|s] [-S screen_number] [-k]" + " [-B blur_strength] [--fuckton-of-color-args=rrggbbaa]"); } } @@ -1207,7 +1209,7 @@ int main(int argc, char *argv[]) { cairo_destroy(ctx); cairo_surface_destroy(xcb_img); } - blur_image_surface(img, 10000); + blur_image_surface(img, blur_sigma); } /* Pixmap on which the image is rendered to (if any) */