nsxiv50f9ad1
Refactored remote changes
+66 −46
7 files changed
- M commands.c +1 −8
- M config.def.h +3 −3
- M image.c +40 −18
- M image.h +1 −1
- M main.c +4 −3
- M options.c +8 −6
- M sxiv.1 +9 −7
| @@ -474,17 +474,10 @@ bool i_toggle_antialias(arg_t a) | |||
| 474 | 474 | } | |
| 475 | 475 | } | |
| 476 | 476 | ||
| 477 | − | /* a < 0: decrease gamma | |
| 478 | − | * a == 0: reset gamma | |
| 479 | − | * a > 0: increase gamma | |
| 480 | − | */ | |
| 481 | 477 | bool i_change_gamma(arg_t a) | |
| 482 | 478 | { | |
| 483 | 479 | 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); | |
| 488 | 481 | } else { | |
| 489 | 482 | return false; | |
| 490 | 483 | } | |
| @@ -49,8 +49,8 @@ enum { | |||
| 49 | 49 | /* gamma correction: the user-visible ranges [-GAMMA_RANGE, 0] and | |
| 50 | 50 | * (0, GAMMA_RANGE] are mapped to the ranges [0, 1], and (1, GAMMA_MAX]. | |
| 51 | 51 | * */ | |
| 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; | |
| 54 | 54 | ||
| 55 | 55 | #endif | |
| 56 | 56 | #ifdef _THUMBS_CONFIG | |
| @@ -150,7 +150,7 @@ static const keymap_t keys[] = { | |||
| 150 | 150 | /* decrease/increase/reset gamma */ | |
| 151 | 151 | { false, XK_braceleft, i_change_gamma, (arg_t) -1 }, | |
| 152 | 152 | { 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 }, | |
| 154 | 154 | ||
| 155 | 155 | /* open current image with given program: */ | |
| 156 | 156 | { true, XK_g, it_open_with, (arg_t) "gimp" }, | |
| @@ -39,11 +39,27 @@ enum { MIN_GIF_DELAY = 25 }; | |||
| 39 | 39 | float zoom_min; | |
| 40 | 40 | float zoom_max; | |
| 41 | 41 | ||
| 42 | − | int zoomdiff(float z1, float z2) | |
| 42 | + | static int zoomdiff(float z1, float z2) | |
| 43 | 43 | { | |
| 44 | 44 | return (int) (z1 * 1000.0 - z2 * 1000.0); | |
| 45 | 45 | } | |
| 46 | 46 | ||
| 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 | + | ||
| 47 | 63 | void img_init(img_t *img, win_t *win) | |
| 48 | 64 | { | |
| 49 | 65 | zoom_min = zoom_levels[0] / 100.0; | |
| @@ -69,7 +85,7 @@ void img_init(img_t *img, win_t *win) | |||
| 69 | 85 | img->multi.animate = false; | |
| 70 | 86 | ||
| 71 | 87 | img->cmod = imlib_create_color_modifier(); | |
| 72 | − | img_set_gamma(img, options->gamma); | |
| 88 | + | img->gamma = options->gamma; | |
| 73 | 89 | } | |
| 74 | 90 | ||
| 75 | 91 | void exif_auto_orientate(const fileinfo_t *file) | |
| @@ -306,7 +322,7 @@ bool img_load(img_t *img, const fileinfo_t *file) | |||
| 306 | 322 | img_load_gif(img, file); | |
| 307 | 323 | #endif | |
| 308 | 324 | ||
| 309 | − | img_set_gamma(img, img->gamma); | |
| 325 | + | img_apply_gamma(img); | |
| 310 | 326 | ||
| 311 | 327 | img->w = imlib_image_get_width(); | |
| 312 | 328 | img->h = imlib_image_get_height(); | |
| @@ -714,25 +730,31 @@ void img_toggle_antialias(img_t *img) | |||
| 714 | 730 | img->dirty = true; | |
| 715 | 731 | } | |
| 716 | 732 | ||
| 717 | − | void img_set_gamma(img_t *img, int gamma) | |
| 733 | + | bool img_change_gamma(img_t *img, int d) | |
| 718 | 734 | { | |
| 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; | |
| 721 | 740 | ||
| 722 | − | img->gamma = MIN(MAX(gamma, -GAMMA_RANGE), GAMMA_RANGE); | |
| 741 | + | if (img == NULL || img->im == NULL) | |
| 742 | + | return false; | |
| 723 | 743 | ||
| 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); | |
| 735 | 754 | img->dirty = true; | |
| 755 | + | return true; | |
| 756 | + | } else { | |
| 757 | + | return false; | |
| 736 | 758 | } | |
| 737 | 759 | } | |
| 738 | 760 | ||
| @@ -84,7 +84,7 @@ void img_flip(img_t*, flipdir_t); | |||
| 84 | 84 | ||
| 85 | 85 | void img_toggle_antialias(img_t*); | |
| 86 | 86 | ||
| 87 | − | void img_set_gamma(img_t*, int); | |
| 87 | + | bool img_change_gamma(img_t*, int); | |
| 88 | 88 | ||
| 89 | 89 | bool img_frame_navigate(img_t*, int); | |
| 90 | 90 | bool img_frame_animate(img_t*, bool); | |
| @@ -345,14 +345,15 @@ void update_info(void) | |||
| 345 | 345 | ow_info = false; | |
| 346 | 346 | } | |
| 347 | 347 | } 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)); | |
| 349 | 352 | if (img.multi.cnt > 0) { | |
| 350 | 353 | for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10); | |
| 351 | 354 | n += snprintf(rt + n, rlen - n, "%0*d/%d | ", | |
| 352 | 355 | fn, img.multi.sel + 1, img.multi.cnt); | |
| 353 | 356 | } | |
| 354 | − | if (img.gamma != 0) | |
| 355 | − | n += snprintf(rt + n, rlen - n, "g%d | ", img.gamma); | |
| 356 | 357 | n += snprintf(rt + n, rlen - n, "%0*d/%d", fw, sel + 1, filecnt); | |
| 357 | 358 | ow_info = info.script == NULL; | |
| 358 | 359 | } | |
| @@ -33,7 +33,7 @@ const options_t *options = (const options_t*) &_options; | |||
| 33 | 33 | ||
| 34 | 34 | void print_usage(void) | |
| 35 | 35 | { | |
| 36 | − | printf("usage: sxiv [-bcdFfhioqrstvZ] [-g GEOMETRY] [-G GAMMA] [-n NUM] " | |
| 36 | + | printf("usage: sxiv [-bcdFfhioqrstvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] " | |
| 37 | 37 | "[-N name] [-z ZOOM] FILES...\n"); | |
| 38 | 38 | } | |
| 39 | 39 | ||
| @@ -45,6 +45,7 @@ void print_version(void) | |||
| 45 | 45 | void parse_options(int argc, char **argv) | |
| 46 | 46 | { | |
| 47 | 47 | int opt, t, gamma; | |
| 48 | + | char *end; | |
| 48 | 49 | ||
| 49 | 50 | _options.from_stdin = false; | |
| 50 | 51 | _options.to_stdout = false; | |
| @@ -65,7 +66,7 @@ void parse_options(int argc, char **argv) | |||
| 65 | 66 | _options.thumb_mode = false; | |
| 66 | 67 | _options.clean_cache = false; | |
| 67 | 68 | ||
| 68 | − | while ((opt = getopt(argc, argv, "bcdFfg:G:hin:N:oqrstvZz:")) != -1) { | |
| 69 | + | while ((opt = getopt(argc, argv, "bcdFfG:g:hin:N:oqrstvZz:")) != -1) { | |
| 69 | 70 | switch (opt) { | |
| 70 | 71 | case '?': | |
| 71 | 72 | print_usage(); | |
| @@ -85,17 +86,18 @@ void parse_options(int argc, char **argv) | |||
| 85 | 86 | case 'f': | |
| 86 | 87 | _options.fullscreen = true; | |
| 87 | 88 | break; | |
| 88 | − | case 'g': | |
| 89 | − | _options.geometry = optarg; | |
| 90 | − | break; | |
| 91 | 89 | case 'G': | |
| 92 | − | if (sscanf(optarg, "%d", &gamma) <= 0) { | |
| 90 | + | gamma = strtol(optarg, &end, 0); | |
| 91 | + | if (*end != '\0') { | |
| 93 | 92 | fprintf(stderr, "sxiv: invalid argument for option -G: %s\n", | |
| 94 | 93 | optarg); | |
| 95 | 94 | exit(EXIT_FAILURE); | |
| 96 | 95 | } | |
| 97 | 96 | _options.gamma = gamma; | |
| 98 | 97 | break; | |
| 98 | + | case 'g': | |
| 99 | + | _options.geometry = optarg; | |
| 100 | + | break; | |
| 99 | 101 | case 'h': | |
| 100 | 102 | print_usage(); | |
| 101 | 103 | exit(EXIT_SUCCESS); | |
| @@ -4,12 +4,14 @@ sxiv \- Simple X Image Viewer | |||
| 4 | 4 | .SH SYNOPSIS | |
| 5 | 5 | .B sxiv | |
| 6 | 6 | .RB [ \-bcdFfhiopqrstvZ ] | |
| 7 | + | .RB [ \-G | |
| 8 | + | .IR GAMMA ] | |
| 7 | 9 | .RB [ \-g | |
| 8 | 10 | .IR GEOMETRY ] | |
| 9 | − | .RB [ \-n | |
| 10 | − | .IR NUM ] | |
| 11 | 11 | .RB [ \-N | |
| 12 | 12 | .IR NAME ] | |
| 13 | + | .RB [ \-n | |
| 14 | + | .IR NUM ] | |
| 13 | 15 | .RB [ \-z | |
| 14 | 16 | .IR ZOOM ] | |
| 15 | 17 | .IR FILE ... | |
| @@ -44,20 +46,20 @@ size-hints to the window width/height. | |||
| 44 | 46 | .B \-f | |
| 45 | 47 | Start in fullscreen mode. | |
| 46 | 48 | .TP | |
| 49 | + | .BI "\-G " GAMMA | |
| 50 | + | Set image gamma to GAMMA (-32..32). | |
| 51 | + | .TP | |
| 47 | 52 | .BI "\-g " GEOMETRY | |
| 48 | 53 | Set window position and size. See section GEOMETRY SPECIFICATIONS of X(7) for | |
| 49 | 54 | more information on | |
| 50 | 55 | .IR GEOMETRY . | |
| 51 | 56 | .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. | |
| 54 | 59 | .TP | |
| 55 | 60 | .BI "\-n " NUM | |
| 56 | 61 | Start at picture number NUM. | |
| 57 | 62 | .TP | |
| 58 | − | .BI "\-N " NAME | |
| 59 | − | Set the resource name of sxiv's X window to NAME. | |
| 60 | − | .TP | |
| 61 | 63 | .B \-h | |
| 62 | 64 | Print brief usage information to standard output and exit. | |
| 63 | 65 | .TP | |