Krolyxon
Commit 50f9ad1

Branches

Refs →

nsxiv50f9ad1

Refactored remote changes

Author
Bert Münnich
Date
2013-11-14 17:06 +0100
Parent
2737fc8
Commit
50f9ad14de921295d7a1687799e30562808e940a

+66 −46

7 files changed

  1. M commands.c +1 −8
  2. M config.def.h +3 −3
  3. M image.c +40 −18
  4. M image.h +1 −1
  5. M main.c +4 −3
  6. M options.c +8 −6
  7. M sxiv.1 +9 −7
M commands.c View
@@ -474,17 +474,10 @@ bool i_toggle_antialias(arg_t a)
474474 }
475475 }
476476
477−/* a < 0: decrease gamma
478− * a == 0: reset gamma
479− * a > 0: increase gamma
480− */
481477 bool i_change_gamma(arg_t a)
482478 {
483479 if (mode == MODE_IMAGE) {
484− long val = (long) a;
485− int delta = val > 0 ? 1 : (val < 0 ? -1 : -img.gamma);
486− img_set_gamma(&img, img.gamma + delta);
487− return true;
480+ return img_change_gamma(&img, (long) a);
488481 } else {
489482 return false;
490483 }
M config.def.h View
@@ -49,8 +49,8 @@ enum {
4949 /* gamma correction: the user-visible ranges [-GAMMA_RANGE, 0] and
5050 * (0, GAMMA_RANGE] are mapped to the ranges [0, 1], and (1, GAMMA_MAX].
5151 * */
52−static const double GAMMA_MAX = 10.0;
53−static const int GAMMA_RANGE = 32;
52+static const double GAMMA_MAX = 10.0;
53+static const int GAMMA_RANGE = 32;
5454
5555 #endif
5656 #ifdef _THUMBS_CONFIG
@@ -150,7 +150,7 @@ static const keymap_t keys[] = {
150150 /* decrease/increase/reset gamma */
151151 { false, XK_braceleft, i_change_gamma, (arg_t) -1 },
152152 { false, XK_braceright, i_change_gamma, (arg_t) +1 },
153− { true, XK_G, i_change_gamma, (arg_t) 0 },
153+ { true, XK_G, i_change_gamma, (arg_t) 0 },
154154
155155 /* open current image with given program: */
156156 { true, XK_g, it_open_with, (arg_t) "gimp" },
M image.c View
@@ -39,11 +39,27 @@ enum { MIN_GIF_DELAY = 25 };
3939 float zoom_min;
4040 float zoom_max;
4141
42−int zoomdiff(float z1, float z2)
42+static int zoomdiff(float z1, float z2)
4343 {
4444 return (int) (z1 * 1000.0 - z2 * 1000.0);
4545 }
4646
47+static void img_apply_gamma(img_t *img)
48+{
49+ if (img == NULL || img->im == NULL || img->cmod == NULL)
50+ return;
51+
52+ if (img->gamma == 0) {
53+ imlib_context_set_color_modifier(NULL);
54+ } else {
55+ double range = img->gamma <= 0 ? 1.0 : GAMMA_MAX - 1.0;
56+
57+ imlib_context_set_color_modifier(img->cmod);
58+ imlib_reset_color_modifier();
59+ imlib_modify_color_modifier_gamma(1.0 + img->gamma * (range / GAMMA_RANGE));
60+ }
61+}
62+
4763 void img_init(img_t *img, win_t *win)
4864 {
4965 zoom_min = zoom_levels[0] / 100.0;
@@ -69,7 +85,7 @@ void img_init(img_t *img, win_t *win)
6985 img->multi.animate = false;
7086
7187 img->cmod = imlib_create_color_modifier();
72− img_set_gamma(img, options->gamma);
88+ img->gamma = options->gamma;
7389 }
7490
7591 void exif_auto_orientate(const fileinfo_t *file)
@@ -306,7 +322,7 @@ bool img_load(img_t *img, const fileinfo_t *file)
306322 img_load_gif(img, file);
307323 #endif
308324
309− img_set_gamma(img, img->gamma);
325+ img_apply_gamma(img);
310326
311327 img->w = imlib_image_get_width();
312328 img->h = imlib_image_get_height();
@@ -714,25 +730,31 @@ void img_toggle_antialias(img_t *img)
714730 img->dirty = true;
715731 }
716732
717−void img_set_gamma(img_t *img, int gamma)
733+bool img_change_gamma(img_t *img, int d)
718734 {
719− if (img == NULL)
720− return;
735+ /* d < 0: decrease gamma
736+ * d = 0: reset gamma
737+ * d > 0: increase gamma
738+ */
739+ int gamma;
721740
722− img->gamma = MIN(MAX(gamma, -GAMMA_RANGE), GAMMA_RANGE);
741+ if (img == NULL || img->im == NULL)
742+ return false;
723743
724− if (img->im && img->cmod) {
725− if (img->gamma == 0) {
726− imlib_context_set_color_modifier(NULL);
727− } else {
728− double range = img->gamma <= 0 ? 1.0 : GAMMA_MAX - 1.0;
729− imlib_context_set_color_modifier(img->cmod);
730− imlib_reset_color_modifier();
731− imlib_modify_color_modifier_gamma(
732− 1.0 + (double) img->gamma
733− * (range / (double) GAMMA_RANGE));
734− }
744+ if (d == 0)
745+ gamma = 0;
746+ else if (d < 0)
747+ gamma = MAX(-GAMMA_RANGE, img->gamma - 1);
748+ else
749+ gamma = MIN(+GAMMA_RANGE, img->gamma + 1);
750+
751+ if (img->gamma != gamma) {
752+ img->gamma = gamma;
753+ img_apply_gamma(img);
735754 img->dirty = true;
755+ return true;
756+ } else {
757+ return false;
736758 }
737759 }
738760
M image.h View
@@ -84,7 +84,7 @@ void img_flip(img_t*, flipdir_t);
8484
8585 void img_toggle_antialias(img_t*);
8686
87−void img_set_gamma(img_t*, int);
87+bool img_change_gamma(img_t*, int);
8888
8989 bool img_frame_navigate(img_t*, int);
9090 bool img_frame_animate(img_t*, bool);
M main.c View
@@ -345,14 +345,15 @@ void update_info(void)
345345 ow_info = false;
346346 }
347347 } else {
348− n = snprintf(rt, rlen, "%s%3d%% | ", mark, (int) (img.zoom * 100.0));
348+ n = snprintf(rt, rlen, "%s", mark);
349+ if (img.gamma != 0)
350+ n += snprintf(rt + n, rlen - n, "G%+d | ", img.gamma);
351+ n += snprintf(rt + n, rlen - n, "%3d%% | ", (int) (img.zoom * 100.0));
349352 if (img.multi.cnt > 0) {
350353 for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10);
351354 n += snprintf(rt + n, rlen - n, "%0*d/%d | ",
352355 fn, img.multi.sel + 1, img.multi.cnt);
353356 }
354− if (img.gamma != 0)
355− n += snprintf(rt + n, rlen - n, "g%d | ", img.gamma);
356357 n += snprintf(rt + n, rlen - n, "%0*d/%d", fw, sel + 1, filecnt);
357358 ow_info = info.script == NULL;
358359 }
M options.c View
@@ -33,7 +33,7 @@ const options_t *options = (const options_t*) &_options;
3333
3434 void print_usage(void)
3535 {
36− printf("usage: sxiv [-bcdFfhioqrstvZ] [-g GEOMETRY] [-G GAMMA] [-n NUM] "
36+ printf("usage: sxiv [-bcdFfhioqrstvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] "
3737 "[-N name] [-z ZOOM] FILES...\n");
3838 }
3939
@@ -45,6 +45,7 @@ void print_version(void)
4545 void parse_options(int argc, char **argv)
4646 {
4747 int opt, t, gamma;
48+ char *end;
4849
4950 _options.from_stdin = false;
5051 _options.to_stdout = false;
@@ -65,7 +66,7 @@ void parse_options(int argc, char **argv)
6566 _options.thumb_mode = false;
6667 _options.clean_cache = false;
6768
68− while ((opt = getopt(argc, argv, "bcdFfg:G:hin:N:oqrstvZz:")) != -1) {
69+ while ((opt = getopt(argc, argv, "bcdFfG:g:hin:N:oqrstvZz:")) != -1) {
6970 switch (opt) {
7071 case '?':
7172 print_usage();
@@ -85,17 +86,18 @@ void parse_options(int argc, char **argv)
8586 case 'f':
8687 _options.fullscreen = true;
8788 break;
88− case 'g':
89− _options.geometry = optarg;
90− break;
9189 case 'G':
92− if (sscanf(optarg, "%d", &gamma) <= 0) {
90+ gamma = strtol(optarg, &end, 0);
91+ if (*end != '\0') {
9392 fprintf(stderr, "sxiv: invalid argument for option -G: %s\n",
9493 optarg);
9594 exit(EXIT_FAILURE);
9695 }
9796 _options.gamma = gamma;
9897 break;
98+ case 'g':
99+ _options.geometry = optarg;
100+ break;
99101 case 'h':
100102 print_usage();
101103 exit(EXIT_SUCCESS);
M sxiv.1 View
@@ -4,12 +4,14 @@ sxiv \- Simple X Image Viewer
44 .SH SYNOPSIS
55 .B sxiv
66 .RB [ \-bcdFfhiopqrstvZ ]
7+.RB [ \-G
8+.IR GAMMA ]
79 .RB [ \-g
810 .IR GEOMETRY ]
9−.RB [ \-n
10−.IR NUM ]
1111 .RB [ \-N
1212 .IR NAME ]
13+.RB [ \-n
14+.IR NUM ]
1315 .RB [ \-z
1416 .IR ZOOM ]
1517 .IR FILE ...
@@ -44,20 +46,20 @@ size-hints to the window width/height.
4446 .B \-f
4547 Start in fullscreen mode.
4648 .TP
49+.BI "\-G " GAMMA
50+Set image gamma to GAMMA (-32..32).
51+.TP
4752 .BI "\-g " GEOMETRY
4853 Set window position and size. See section GEOMETRY SPECIFICATIONS of X(7) for
4954 more information on
5055 .IR GEOMETRY .
5156 .TP
52−.BI "\-G " GAMMA
53−Set gamma to GAMMA (-32..32).
57+.BI "\-N " NAME
58+Set the resource name of sxiv's X window to NAME.
5459 .TP
5560 .BI "\-n " NUM
5661 Start at picture number NUM.
5762 .TP
58−.BI "\-N " NAME
59−Set the resource name of sxiv's X window to NAME.
60−.TP
6163 .B \-h
6264 Print brief usage information to standard output and exit.
6365 .TP