Krolyxon
Commit 88a480c

Branches

Refs →

nsxiv88a480c

allow disabling anti-aliasing via cli flag

simply running nsxiv with `--anti-alias` will enable anti-aliasing, and
running it with `--anti-alias=no` will disable it.

the cli flag will overwrite the config.h default.
Author
NRK
Date
2022-08-17 20:54 +0600
Committer
NRK · 2022-09-10 19:43 +0600
Parent
7e3e600
Commit
88a480c9388d698f123bf892f33197d7bd1cfb9b

+52 −30

5 files changed

  1. M config.def.h +8 −5
  2. M etc/nsxiv.1 +5 −0
  3. M image.c +1 −1
  4. M nsxiv.h +1 −0
  5. M options.c +37 −24
M config.def.h View
@@ -42,11 +42,6 @@ static const int GAMMA_RANGE = 32;
4242 /* command i_scroll pans image 1/PAN_FRACTION of screen width/height */
4343 static const int PAN_FRACTION = 5;
4444
45−/* if false, pixelate images at zoom level != 100%,
46− * toggled with 'a' key binding
47− */
48−static const bool ANTI_ALIAS = true;
49−
5045 /* if true, use a checkerboard background for alpha layer,
5146 * toggled with 'A' key binding
5247 */
@@ -64,6 +59,14 @@ static const int CACHE_SIZE_MEM_PERCENTAGE = 3; /* use 3% of total memo
6459 static const int CACHE_SIZE_LIMIT = 256 * 1024 * 1024; /* but not above 256MiB */
6560 static const int CACHE_SIZE_FALLBACK = 32 * 1024 * 1024; /* fallback to 32MiB if we can't determine total memory */
6661
62+#endif
63+#ifdef INCLUDE_OPTIONS_CONFIG
64+
65+/* if false, pixelate images at zoom level != 100%,
66+ * toggled with 'a' key binding (overwritten via `--anti-alias` option)
67+ */
68+static const bool ANTI_ALIAS = true;
69+
6770 #endif
6871 #ifdef INCLUDE_THUMBS_CONFIG
6972
M etc/nsxiv.1 View
@@ -114,6 +114,11 @@ Set zoom level to ZOOM percent.
114114 .B "\-0, \-\-null"
115115 Use NULL-separator. With this option, output of \-o and file-list sent to the
116116 key-handler and the input of \-i will be separated by a NULL character.
117+.TP
118+.BI "\-\-anti\-alias" [=no]
119+Enables anti-aliasing, when given
120+.I no
121+as an argument, disables it instead.
117122 .SH KEYBOARD COMMANDS
118123 .SS General
119124 The following keyboard commands are available in both image and thumbnail modes:
M image.c View
@@ -80,7 +80,7 @@ void img_init(img_t *img, win_t *win)
8080 img->zoom = MIN(img->zoom, ZOOM_MAX);
8181 img->checkpan = false;
8282 img->dirty = false;
83− img->aa = ANTI_ALIAS;
83+ img->aa = options->aa;
8484 img->alpha = ALPHA_LAYER;
8585 img->multi.cap = img->multi.cnt = 0;
8686 img->multi.animate = options->animate;
M nsxiv.h View
@@ -237,6 +237,7 @@ struct opt {
237237 scalemode_t scalemode;
238238 float zoom;
239239 bool animate;
240+ bool aa;
240241 int gamma;
241242 int slideshow;
242243 int framerate;
M options.c View
@@ -19,8 +19,11 @@
1919
2020 #include "nsxiv.h"
2121 #include "version.h"
22+#define INCLUDE_OPTIONS_CONFIG
23+#include "config.h"
2224
2325 #include <assert.h>
26+#include <limits.h>
2427 #include <stdio.h>
2528 #include <stdlib.h>
2629 #include <string.h>
@@ -63,31 +66,35 @@ static void print_version(void)
6366
6467 void parse_options(int argc, char **argv)
6568 {
69+ enum { /* ensure these can't be represented in a single byte */
70+ OPT_AA = UCHAR_MAX + 1
71+ };
6672 static const struct optparse_long longopts[] = {
67− { "framerate", 'A', OPTPARSE_REQUIRED },
68− { "animate", 'a', OPTPARSE_NONE },
69− { "no-bar", 'b', OPTPARSE_NONE },
70− { "clean-cache", 'c', OPTPARSE_NONE },
71− { "embed", 'e', OPTPARSE_REQUIRED },
72− { "fullscreen", 'f', OPTPARSE_NONE },
73− { "gamma", 'G', OPTPARSE_REQUIRED },
74− { "geometry", 'g', OPTPARSE_REQUIRED },
75− { "help", 'h', OPTPARSE_NONE },
76− { "stdin", 'i', OPTPARSE_NONE },
77− { "class", 'N', OPTPARSE_REQUIRED },
78− { "start-at", 'n', OPTPARSE_REQUIRED },
79− { "stdout", 'o', OPTPARSE_NONE },
80− { "private", 'p', OPTPARSE_NONE },
81− { "quiet", 'q', OPTPARSE_NONE },
82− { "recursive", 'r', OPTPARSE_NONE },
83− { "ss-delay", 'S', OPTPARSE_REQUIRED },
84− { "scale-mode", 's', OPTPARSE_REQUIRED },
85− { NULL, 'T', OPTPARSE_REQUIRED },
86− { "thumbnail", 't', OPTPARSE_NONE },
87− { "version", 'v', OPTPARSE_NONE },
88− { "zoom-100", 'Z', OPTPARSE_NONE },
89− { "zoom", 'z', OPTPARSE_REQUIRED },
90− { "null", '0', OPTPARSE_NONE },
73+ { "framerate", 'A', OPTPARSE_REQUIRED },
74+ { "animate", 'a', OPTPARSE_NONE },
75+ { "no-bar", 'b', OPTPARSE_NONE },
76+ { "clean-cache", 'c', OPTPARSE_NONE },
77+ { "embed", 'e', OPTPARSE_REQUIRED },
78+ { "fullscreen", 'f', OPTPARSE_NONE },
79+ { "gamma", 'G', OPTPARSE_REQUIRED },
80+ { "geometry", 'g', OPTPARSE_REQUIRED },
81+ { "help", 'h', OPTPARSE_NONE },
82+ { "stdin", 'i', OPTPARSE_NONE },
83+ { "class", 'N', OPTPARSE_REQUIRED },
84+ { "start-at", 'n', OPTPARSE_REQUIRED },
85+ { "stdout", 'o', OPTPARSE_NONE },
86+ { "private", 'p', OPTPARSE_NONE },
87+ { "quiet", 'q', OPTPARSE_NONE },
88+ { "recursive", 'r', OPTPARSE_NONE },
89+ { "ss-delay", 'S', OPTPARSE_REQUIRED },
90+ { "scale-mode", 's', OPTPARSE_REQUIRED },
91+ { NULL, 'T', OPTPARSE_REQUIRED },
92+ { "thumbnail", 't', OPTPARSE_NONE },
93+ { "version", 'v', OPTPARSE_NONE },
94+ { "zoom-100", 'Z', OPTPARSE_NONE },
95+ { "zoom", 'z', OPTPARSE_REQUIRED },
96+ { "null", '0', OPTPARSE_NONE },
97+ { "anti-alias", OPT_AA, OPTPARSE_OPTIONAL },
9198 { 0 }, /* end */
9299 };
93100
@@ -106,6 +113,7 @@ void parse_options(int argc, char **argv)
106113
107114 _options.scalemode = SCALE_DOWN;
108115 _options.zoom = 1.0;
116+ _options.aa = ANTI_ALIAS;
109117 _options.animate = false;
110118 _options.gamma = 0;
111119 _options.slideshow = 0;
@@ -233,6 +241,11 @@ void parse_options(int argc, char **argv)
233241 case '0':
234242 _options.using_null = true;
235243 break;
244+ case OPT_AA:
245+ if (op.optarg != NULL && !STREQ(op.optarg, "no"))
246+ error(EXIT_FAILURE, 0, "Invalid argument for option --anti-alias: %s", op.optarg);
247+ _options.aa = op.optarg == NULL;
248+ break;
236249 }
237250 }
238251