config: add scaling-filter option
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Before: this patch, lanczos3 was always used (unless the PNG was >= 1024px, in which case we used pixman's "fast" filter). Now, the default is 'box'. This filter is much faster than lanczos3 (and lanczos2 and cubic, though not by as much), while still looking just as good (in most cases at least). The check for too large icons remains, but has been slightly modified: If the icon is >=1024px, we switch to the fast filter, regardless of which filter the user has selected. If the icon is >=256px (but less than 1024), *and* if the user selected a "slow" filter (we consider cubic, linear and lanczos* to be slow), then warn and use the box filter instead. Closes #553
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+205 added−25 removed
- other:+205 added−25 removed
Provenance
- Commit
3866f60- Tree
4492f1c- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
40964b5
10 files changed+205 added−25 removed
modified:completions/fish/fuzzel.fish+1 added
68 unmodified lines69 complete -c fuzzel -x -l render-workers -d "number of render worker threads"70 complete -c fuzzel -x -l match-workers -d "number of match worker threads"71 complete -c fuzzel -x -l delayed-filter-ms -d "time in milliseconds to delay refiltering when there are lots of matches"72 complete -c fuzzel -x -l delayed-filter-limit -d "switch to delayed refiltering when there are more matches than this"73+complete -c fuzzel -x -l scaling-filter -a "none nearest bilinear box linear cubic lanczos2 lanczos3 lanczos3-stretched" -d "filter to use when down scaling PNGs"74 complete -c fuzzel -s d -l dmenu -d "dmenu compatibility mode; entries are read from stdin, newline separated"75 complete -c fuzzel -l dmenu0 -d "dmenu compatibility mode; entries are read from stdin, NUL separated"76 complete -c fuzzel -l index -d "print selected entry's index instead of its text (dmenu mode only)"77 complete -c fuzzel -x -l with-nth -d "display the N:th column (tab separated) of each input line (dmenu only)"8 unmodified linesmodified:completions/zsh/_fuzzel+2 added-1 removed
69 unmodified lines70 '(-R --no-run-if-empty)'{-R,--no-run-if-empty}'[exit immediately without showing the UI if stdin is empty (dmenu mode only)]' \71 '--log-level[log level (warning)]:loglevel:(info warning error none)' \72 '--log-colorize[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \73 '--log-no-syslog[disable syslog logging]' \74- '--print-timing-info[print timing information, to help debug performance issues]'74+ '--print-timing-info[print timing information, to help debug performance issues]' \75+ '--scaling-filter[filter to use when down scaling PNGs]:scaling-filter:(none nearest bilinear box linear cubic lanczos2 lanczos3 lanczos3-stretched)'76 77 case "${state}" in78 fonts)79 if command -v fc-list > /dev/null; then16 unmodified linesmodified:doc/fuzzel.1.scd+17 added
397 unmodified lines398 When there are more matches than this, switch from immediate399 refiltering to delayed refiltering (see400 *--delayed-filter-ms*). Default: _20000_.401 402+*--scaling-filter*=_FILTER_403+ Scaling filter to use when down scaling PNGs. One of *none*,404+ *nearest*, *bilinear*, *box*, *linear*, *cubic*, *lanczos2*,405+ *lanczos3* and *lanczos3-stretched*.406+ 407+ *none*, *nearest* and *bilinear* are the fastest options, but also408+ have the worst looking results.409+ 410+ *cubic*, *lanczos2*, *lanczos3* and *lanczos3-stretched* are the411+ slowest options, with the best looking results.412+ 413+ *box*, and to some degree, *linear*, are in the middle,414+ performance wise, while in most cases still being just as, or415+ close to, as good as *cubic* and the lanczos filters.416+ 417+ Default: _box_418+419 *-d*,*--dmenu*420 dmenu compatibility mode. In this mode, the list entries are read421 from stdin (newline separated). The selected entry is printed to422 stdout. If the input string does not match any of the entries, the135 unmodified linesmodified:doc/fuzzel.ini.5.scd+17 added
365 unmodified lines366 When there are more matches than this, switch from immediate367 refiltering to delayed refiltering (see368 *delayed-filter-ms*). Default: _20000_.369 370+*scaling-filter*371+ Scaling filter to use when down scaling PNGs. One of *none*,372+ *nearest*, *bilinear*, *box*, *linear*, *cubic*, *lanczos2*,373+ *lanczos3* and *lanczos3-stretched*.374+ 375+ *none*, *nearest* and *bilinear* are the fastest options, but also376+ have the worst looking results.377+ 378+ *cubic*, *lanczos2*, *lanczos3* and *lanczos3-stretched* are the379+ slowest options, with the best looking results.380+ 381+ *box*, and to some degree, *linear*, are in the middle,382+ performance wise, while in most cases still being just as, or383+ close to, as good as *cubic* and the lanczos filters.384+ 385+ Default: _box_386+387 *cache*388 Specify the default cache location. If unset,389 *$XDG_CACHE_HOME/fuzzel* will be used. Set to */dev/null* to390 disable caching. Default: _not set_.239 unmodified linesmodified:CHANGELOG.md+6 added-2 removed
39 unmodified lines40 `gamma-correct-blending=yes` in `fuzzel.ini`. Note that41 gamma-correct blending **is not supported in cairo enabled builds of42 fuzzel**, due to the lack of 16-bit image buffers in cairo43 ([#546][546]).44+* `scaling-filter` option (and the corresponding `--scaling-filter`45+ command line option). This option defines which scaling filter46+ fuzzel uses when down scaling PNGs ([#553][553]).47 48 [504]: https://codeberg.org/dnkl/fuzzel/pulls/50449 [512]: https://codeberg.org/dnkl/fuzzel/pulls/51250 [546]: https://codeberg.org/dnkl/fuzzel/issues/54651+[553]: https://codeberg.org/dnkl/fuzzel/issues/55352 53 54 ### Changed55 4 unmodified lines60 * fcft >= 3.3.1 is now required.61 * In application mode (not dmenu), fuzzel now ignores icon theme62 directories whose `Context` field is not `Application` or63 `Apps`. This is for performance reasons ([#553][553])64+* Default down scaling filter changed from `lanczos3` to `box`65+ ([#553][553]).66 61-[553]: https://codeberg.org/dnkl/fuzzel/issues/55367 63-68 ### Deprecated69 ### Removed70 ### Fixed71 924 unmodified linesmodified:config.c+13 added
982 unmodified lines983 conf->image_size_ratio = ratio;984 return true;985 }986 987+ else if (strcmp(key, "scaling-filter") == 0) {988+ _Static_assert(sizeof(conf->png_scaling_filter) == sizeof(int),989+ "enum is not 32-bit");990+991+ return value_to_enum(992+ ctx,993+ (const char *[]){"none", "nearest", "bilinear", "box", "linear",994+ "cubic", "lanczos2", "lanczos3",995+ "lanczos3-stretched", NULL},996+ (int *)&conf->png_scaling_filter);997+ }998+999 else if (strcmp(key, "layer") == 0) {1000 if (strcasecmp(value, "top") == 0) {1001 conf->layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;1002 return true;672 unmodified lines1675 .size = 1u,1676 .radius = 10u,1677 },1678 .image_size_ratio = 0.5,1679+ .png_scaling_filter = SCALING_FILTER_BOX,1680 .line_height = {-1, 0.0},1681 .letter_spacing = {0},1682 .layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,1683 .keyboard_focus = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE,85 unmodified linesmodified:config.h+14 added
95 unmodified lines96 int lineno;97 };98 DEFINE_LIST(struct config_key_binding);99 100+enum scaling_filter {101+ SCALING_FILTER_NONE,102+ SCALING_FILTER_NEAREST,103+ SCALING_FILTER_BILINEAR,104+ SCALING_FILTER_BOX,105+ SCALING_FILTER_LINEAR,106+ SCALING_FILTER_CUBIC,107+ SCALING_FILTER_LANCZOS2,108+ SCALING_FILTER_LANCZOS3,109+ SCALING_FILTER_LANCZOS3_STRETCHED,110+};111+112 struct config {113 char *output;114 char32_t *prompt;115 char32_t *placeholder;90 unmodified lines206 } border;207 208 float image_size_ratio;209 210+ enum scaling_filter png_scaling_filter;211+212 struct pt_or_px line_height;213 struct pt_or_px letter_spacing;214 215 enum zwlr_layer_shell_v1_layer layer;17 unmodified linesmodified:fuzzel.ini+1 added
28 unmodified lines29 # horizontal-pad=4030 # vertical-pad=831 # inner-pad=032 33+# scaling-filter=box34 # image-size-ratio=0.535 36 # gamma-correct-blending=no37 # line-height=<use font metrics>82 unmodified linesmodified:main.c+32 added
419 unmodified lines420 " --delayed-filter-ms=TIME_MS time in ms before refiltering after a keystroke\n"421 " (300)\n"422 " --delayed-filter-limit=N used delayed refiltering when the number of\n"423 " matches exceeds this number (10000)\n"424+ " --scaling-filter=FILTER filter to use when down scaling PNGs\n"425 " -d,--dmenu dmenu compatibility mode\n"426 " --dmenu0 like --dmenu, but input is NUL separated\n"427 " instead of newline separated\n"428 " --index print selected entry's index instead of of the \n"372 unmodified lines801 #define OPT_DMENU_WITH_NTH 298802 #define OPT_DMENU_ACCEPT_NTH 299803 #define OPT_GAMMA_CORRECT 300804 #define OPT_PRINT_TIMINGS 301805+ #define OPT_SCALING_FILTER 302806 807 static const struct option longopts[] = {808 {"config", required_argument, 0, OPT_CONFIG},809 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},56 unmodified lines866 {"no-sort", no_argument, 0, OPT_NO_SORT},867 {"counter", no_argument, 0, OPT_COUNTER},868 {"delayed-filter-ms", required_argument, 0, OPT_DELAYED_FILTER_MS},869 {"delayed-filter-limit", required_argument, 0, OPT_DELAYED_FILTER_LIMIT},870+ {"scaling-filter", required_argument, 0, OPT_SCALING_FILTER},871 872 /* dmenu mode */873 {"dmenu", no_argument, 0, 'd'},874 {"dmenu0", no_argument, 0, OPT_DMENU_NULL},75 unmodified lines950 bool delayed_filter_limit_set:1;951 bool placeholder_color_set:1;952 bool counter_set:1;953 bool print_timing_info_set:1;954+ bool scaling_filter_set:1;955 } cmdline_overrides = {{0}};956 957 setlocale(LC_CTYPE, "");958 setlocale(LC_MESSAGES, "");782 unmodified lines1741 }1742 cmdline_overrides.delayed_filter_limit_set = true;1743 break;1744 1745+ case OPT_SCALING_FILTER:1746+ if (strcmp(optarg, "none") == 0)1747+ cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_NONE;1748+ else if (strcmp(optarg, "nearest") == 0)1749+ cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_NEAREST;1750+ else if (strcmp(optarg, "bilinear") == 0)1751+ cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_BILINEAR;1752+ else if (strcmp(optarg, "box") == 0)1753+ cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_BOX;1754+ else if (strcmp(optarg, "linear") == 0)1755+ cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_LINEAR;1756+ else if (strcmp(optarg, "cubic") == 0)1757+ cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_CUBIC;1758+ else if (strcmp(optarg, "lanczos2") == 0)1759+ cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_LANCZOS2;1760+ else if (strcmp(optarg, "lanczos3") == 0)1761+ cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_LANCZOS3;1762+ else if (strcmp(optarg, "lanczos3-stretched") == 0)1763+ cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_LANCZOS3_STRETCHED;1764+ else {1765+ fprintf(stderr, "%s: invalid scaling-filter", optarg);1766+ return EXIT_FAILURE;1767+ }1768+ cmdline_overrides.scaling_filter_set = true;1769+ break;1770+1771 case OPT_PRINT_TIMINGS:1772 cmdline_overrides.conf.print_timing_info = true;1773 cmdline_overrides.print_timing_info_set = true;1774 break;195 unmodified lines1970 conf.cache_path = xstrdup(cmdline_overrides.conf.cache_path);1971 }1972 if (cmdline_overrides.print_timing_info_set)1973 conf.print_timing_info = cmdline_overrides.conf.print_timing_info;1974+ if (cmdline_overrides.scaling_filter_set)1975+ conf.png_scaling_filter = cmdline_overrides.conf.png_scaling_filter;1976 1977 if (conf.dmenu.enabled) {1978 /* We don't have any meta data in dmenu mode */1979 conf.match_fields = MATCH_NAME;208 unmodified linesmodified:render.c+102 added-22 removed
913 unmodified lines914 915 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)916 static void917 render_png_libpng(struct icon *icon, int x, int y, int size,918- pixman_image_t *pix, cairo_t *cairo)918+ pixman_image_t *pix, cairo_t *cairo,919+ enum scaling_filter scaling_filter)920 {921 #if defined(FUZZEL_ENABLE_CAIRO)922 cairo_surface_flush(cairo_get_target(cairo));923 #endif13 unmodified lines937 pixman_transform_from_pixman_f_transform(938 &scale_transform, &_scale_transform);939 pixman_image_set_transform(png, &scale_transform);940 940- if (height >= 1000) {941+ const int largest_side = max(width, height);942+943+ if (largest_side >= 1024) {944 if (!icon->png_size_warned) {945 LOG_WARN(946 "%s: PNG is too large (%dx%d); "944- "downscaling using a less precise filter",947+ "downscaling using a less precise filter (fast)",948 icon->path, width, height);949 icon->png_size_warned = true;950 }951+952 pixman_image_set_filter(png, PIXMAN_FILTER_FAST, NULL, 0);949- } else {950- int param_count = 0;951- pixman_kernel_t kernel = PIXMAN_KERNEL_LANCZOS3;952- pixman_fixed_t *params = pixman_filter_create_separable_convolution(953- ¶m_count,954- pixman_double_to_fixed(1. / scale),955- pixman_double_to_fixed(1. / scale),956- kernel, kernel,957- kernel, kernel,958- pixman_int_to_fixed(1),959- pixman_int_to_fixed(1));953+ }954 961- if (params != NULL || param_count == 0) {962- pixman_image_set_filter(963- png, PIXMAN_FILTER_SEPARABLE_CONVOLUTION,964- params, param_count);955+ else {956+957+ bool slow_scaling_filter = false;958+959+ switch (scaling_filter) {960+ case SCALING_FILTER_NONE:961+ case SCALING_FILTER_NEAREST:962+ case SCALING_FILTER_BILINEAR:963+ case SCALING_FILTER_BOX:964+ slow_scaling_filter = false;965+ break;966+967+ case SCALING_FILTER_CUBIC:968+ case SCALING_FILTER_LANCZOS3:969+ case SCALING_FILTER_LINEAR:970+ case SCALING_FILTER_LANCZOS2:971+ case SCALING_FILTER_LANCZOS3_STRETCHED:972+ slow_scaling_filter = true;973+ break;974 }975 976+ if (slow_scaling_filter && largest_side >= 256) {977+ if (!icon->png_size_warned) {978+ LOG_WARN(979+ "%s: PNG is too large (%dx%d); "980+ "downscaling using a less precise filter (box)",981+ icon->path, width, height);982+ icon->png_size_warned = true;983+ }984+985+ scaling_filter = SCALING_FILTER_BOX;986+ }987+988+ switch (scaling_filter) {989+ case SCALING_FILTER_NONE:990+ break;991+992+ /*993+ * "simple" filters994+ */995+996+ case SCALING_FILTER_NEAREST:997+ pixman_image_set_filter(png, PIXMAN_FILTER_NEAREST, NULL, 0);998+ break;999+1000+ case SCALING_FILTER_BILINEAR:1001+ pixman_image_set_filter(png, PIXMAN_FILTER_BILINEAR, NULL, 0);1002+ break;1003+1004+ /*1005+ * Separable convolution filters1006+ */1007+ case SCALING_FILTER_CUBIC:1008+ case SCALING_FILTER_LANCZOS3:1009+ case SCALING_FILTER_BOX:1010+ case SCALING_FILTER_LINEAR:1011+ case SCALING_FILTER_LANCZOS2:1012+ case SCALING_FILTER_LANCZOS3_STRETCHED: {1013+1014+ pixman_kernel_t kernel;1015+1016+ switch (scaling_filter) {1017+ case SCALING_FILTER_CUBIC: kernel = PIXMAN_KERNEL_CUBIC; break;1018+ case SCALING_FILTER_LANCZOS3: kernel = PIXMAN_KERNEL_LANCZOS3; break;1019+ case SCALING_FILTER_BOX: kernel = PIXMAN_KERNEL_BOX; break;1020+ case SCALING_FILTER_LINEAR: kernel = PIXMAN_KERNEL_LINEAR; break;1021+ case SCALING_FILTER_LANCZOS2: kernel = PIXMAN_KERNEL_LANCZOS2; break;1022+ case SCALING_FILTER_LANCZOS3_STRETCHED: kernel = PIXMAN_KERNEL_LANCZOS3_STRETCHED; break;1023+ default: assert(false); kernel = PIXMAN_KERNEL_CUBIC; break;1024+ }1025+1026+ int param_count = 0;1027+ pixman_fixed_t *params = pixman_filter_create_separable_convolution(1028+ ¶m_count,1029+ pixman_double_to_fixed(1. / scale),1030+ pixman_double_to_fixed(1. / scale),1031+ kernel, kernel,1032+ kernel, kernel,1033+ pixman_int_to_fixed(1),1034+ pixman_int_to_fixed(1));1035+1036+ if (params != NULL || param_count == 0) {1037+ pixman_image_set_filter(1038+ png, PIXMAN_FILTER_SEPARABLE_CONVOLUTION,1039+ params, param_count);1040+ }1041+967- free(params);1042+ free(params);1043+ break;1044+ }1045+ }1046 }1047 1048 width *= scale;1049 height *= scale;25 unmodified lines1075 #endif /* FUZZEL_ENABLE_PNG_LIBPNG */1076 1077 static void1078 render_png(struct icon *icon, int x, int y, int size, pixman_image_t *pix,1001- cairo_t *cairo, bool gamma_correct, bool print_timing_info)1079+ cairo_t *cairo, bool gamma_correct, bool print_timing_info,1080+ enum scaling_filter scaling_filter)1081 {1082 assert(icon->type == ICON_PNG);1083 1084 if (icon->png == NULL) {18 unmodified lines1103 struct timeval start, stop, diff;1104 gettimeofday(&start, NULL);1105 1106 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)1028- render_png_libpng(icon, x, y, size, pix, cairo);1107+ render_png_libpng(icon, x, y, size, pix, cairo, scaling_filter);1108 #endif1109 1110 if (print_timing_info) {1111 gettimeofday(&stop, NULL);108 unmodified lines1220 break;1221 1222 case ICON_PNG:1223 render_png(icon, img_x, img_y, size, pix, cairo,1145- render->gamma_correct, render->conf->print_timing_info);1224+ render->gamma_correct, render->conf->print_timing_info,1225+ render->conf->png_scaling_filter);1226 break;1227 1228 case ICON_SVG:1229 render_svg(icon, img_x, img_y, size, pix, cairo,435 unmodified lines