From 62d52b597d6a9cf4ed7ef0782fad8ca5eca24aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Mon, 29 Nov 2021 21:09:33 +0300 Subject: config: blur setting for thumbnails/images --- src/config.c | 14 ++++++++++++++ src/site.c | 9 ++++----- src/tests/config.c | 7 +++++-- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index e9dd609..1bc531f 100644 --- a/src/config.c +++ b/src/config.c @@ -75,6 +75,18 @@ site_config_images_keyvalue_handler(struct parcini_line *parsed, res = parcini_value_handle(&parsed->value, PARCINI_VALUE_BOOLEAN, &iconfig->smart_resize) ? CONFIG_KEY_OK : CONFIG_KEY_BADVALUE; } + if (!strcmp(parsed->key, "blur")) { + long int temp; + res = parcini_value_handle(&parsed->value, PARCINI_VALUE_INTEGER, + &temp) ? CONFIG_KEY_OK : CONFIG_KEY_BADVALUE; + if (res == CONFIG_KEY_OK) { + if (temp < -100 || temp > 100) { + res = CONFIG_KEY_BADVALUE; + } else { + iconfig->blur = (double)temp/100; + } + } + } return res; } @@ -227,6 +239,7 @@ site_config_init(void) .max_width = 3000, .max_height = 2000, .smart_resize = true, + .blur = 0, }; config->thumbnails = (struct image_config) { .strip = true, @@ -234,6 +247,7 @@ site_config_init(void) .max_width = 400, .max_height = 270, .smart_resize = true, + .blur = 0.25, }; } diff --git a/src/site.c b/src/site.c index a47d16e..2d3922b 100644 --- a/src/site.c +++ b/src/site.c @@ -111,7 +111,8 @@ optimize_image(MagickWand *wand, const char *dst, nx = ny * ratio; } } - TRYWAND(wand, MagickResizeImage(wand, nx, ny, GaussianFilter, 0)); + TRYWAND(wand, MagickResizeImage(wand, nx, ny, GaussianFilter, + conf->blur)); } TRYWAND(wand, MagickWriteImage(wand, dst)); setdatetime(dst, srcmtim); @@ -214,8 +215,8 @@ albums_walk(struct bstnode *node, void *data) struct stat dstat; if (!nmkdir(album->slug, &dstat, site->dry_run)) return false; + hashmap_insert(site->album_dirs, album->slug, (char *)album->slug); if (!site->dry_run) { - hashmap_insert(site->album_dirs, album->slug, (char *)album->slug); if (!render_set_album_vars(&site->render, album)) return false; } @@ -390,9 +391,7 @@ site_init(struct site *site) site->rel_content_dir = strlen(site->root_dir) + 1; InitializeMagick(NULL); site->wand = NewMagickWand(); - if (!site->dry_run) { - site->album_dirs = hashmap_new(); - } + site->album_dirs = hashmap_new(); site->render.dry_run = site->dry_run; return true; diff --git a/src/tests/config.c b/src/tests/config.c index 8d86a2f..64a4da8 100644 --- a/src/tests/config.c +++ b/src/tests/config.c @@ -1,8 +1,9 @@ #include +#include -#include "tests/tests.h" -#include "config.h" #include "log.h" +#include "config.h" +#include "tests/tests.h" #define TESTS_DIR "tests" #define TEST_ALBUM "tests/album.ini" @@ -20,11 +21,13 @@ test_site_config_read_ini(void) asserteq(config->images.max_width, 3000); asserteq(config->images.max_height, 2000); asserteq(config->images.smart_resize, true); + asserteq(fabs(config->images.blur - 0.0) < 0.0001, true); asserteq(config->thumbnails.strip, true); asserteq(config->thumbnails.quality, 75); asserteq(config->thumbnails.max_width, 400); asserteq(config->thumbnails.max_height, 270); asserteq(config->thumbnails.smart_resize, true); + asserteq(fabs(config->thumbnails.blur - 0.1) < 0.0001, true); site_config_destroy(config); } -- cgit v1.2.3