Refactored remote changes
This commit is contained in:
parent
2737fc8b81
commit
50f9ad14de
|
@ -474,17 +474,10 @@ bool i_toggle_antialias(arg_t a)
|
|||
}
|
||||
}
|
||||
|
||||
/* a < 0: decrease gamma
|
||||
* a == 0: reset gamma
|
||||
* a > 0: increase gamma
|
||||
*/
|
||||
bool i_change_gamma(arg_t a)
|
||||
{
|
||||
if (mode == MODE_IMAGE) {
|
||||
long val = (long) a;
|
||||
int delta = val > 0 ? 1 : (val < 0 ? -1 : -img.gamma);
|
||||
img_set_gamma(&img, img.gamma + delta);
|
||||
return true;
|
||||
return img_change_gamma(&img, (long) a);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ enum {
|
|||
/* gamma correction: the user-visible ranges [-GAMMA_RANGE, 0] and
|
||||
* (0, GAMMA_RANGE] are mapped to the ranges [0, 1], and (1, GAMMA_MAX].
|
||||
* */
|
||||
static const double GAMMA_MAX = 10.0;
|
||||
static const int GAMMA_RANGE = 32;
|
||||
static const double GAMMA_MAX = 10.0;
|
||||
static const int GAMMA_RANGE = 32;
|
||||
|
||||
#endif
|
||||
#ifdef _THUMBS_CONFIG
|
||||
|
@ -150,7 +150,7 @@ static const keymap_t keys[] = {
|
|||
/* decrease/increase/reset gamma */
|
||||
{ false, XK_braceleft, i_change_gamma, (arg_t) -1 },
|
||||
{ false, XK_braceright, i_change_gamma, (arg_t) +1 },
|
||||
{ true, XK_G, i_change_gamma, (arg_t) 0 },
|
||||
{ true, XK_G, i_change_gamma, (arg_t) 0 },
|
||||
|
||||
/* open current image with given program: */
|
||||
{ true, XK_g, it_open_with, (arg_t) "gimp" },
|
||||
|
|
58
image.c
58
image.c
|
@ -39,11 +39,27 @@ enum { MIN_GIF_DELAY = 25 };
|
|||
float zoom_min;
|
||||
float zoom_max;
|
||||
|
||||
int zoomdiff(float z1, float z2)
|
||||
static int zoomdiff(float z1, float z2)
|
||||
{
|
||||
return (int) (z1 * 1000.0 - z2 * 1000.0);
|
||||
}
|
||||
|
||||
static void img_apply_gamma(img_t *img)
|
||||
{
|
||||
if (img == NULL || img->im == NULL || img->cmod == NULL)
|
||||
return;
|
||||
|
||||
if (img->gamma == 0) {
|
||||
imlib_context_set_color_modifier(NULL);
|
||||
} else {
|
||||
double range = img->gamma <= 0 ? 1.0 : GAMMA_MAX - 1.0;
|
||||
|
||||
imlib_context_set_color_modifier(img->cmod);
|
||||
imlib_reset_color_modifier();
|
||||
imlib_modify_color_modifier_gamma(1.0 + img->gamma * (range / GAMMA_RANGE));
|
||||
}
|
||||
}
|
||||
|
||||
void img_init(img_t *img, win_t *win)
|
||||
{
|
||||
zoom_min = zoom_levels[0] / 100.0;
|
||||
|
@ -69,7 +85,7 @@ void img_init(img_t *img, win_t *win)
|
|||
img->multi.animate = false;
|
||||
|
||||
img->cmod = imlib_create_color_modifier();
|
||||
img_set_gamma(img, options->gamma);
|
||||
img->gamma = options->gamma;
|
||||
}
|
||||
|
||||
void exif_auto_orientate(const fileinfo_t *file)
|
||||
|
@ -306,7 +322,7 @@ bool img_load(img_t *img, const fileinfo_t *file)
|
|||
img_load_gif(img, file);
|
||||
#endif
|
||||
|
||||
img_set_gamma(img, img->gamma);
|
||||
img_apply_gamma(img);
|
||||
|
||||
img->w = imlib_image_get_width();
|
||||
img->h = imlib_image_get_height();
|
||||
|
@ -714,25 +730,31 @@ void img_toggle_antialias(img_t *img)
|
|||
img->dirty = true;
|
||||
}
|
||||
|
||||
void img_set_gamma(img_t *img, int gamma)
|
||||
bool img_change_gamma(img_t *img, int d)
|
||||
{
|
||||
if (img == NULL)
|
||||
return;
|
||||
/* d < 0: decrease gamma
|
||||
* d = 0: reset gamma
|
||||
* d > 0: increase gamma
|
||||
*/
|
||||
int gamma;
|
||||
|
||||
img->gamma = MIN(MAX(gamma, -GAMMA_RANGE), GAMMA_RANGE);
|
||||
if (img == NULL || img->im == NULL)
|
||||
return false;
|
||||
|
||||
if (img->im && img->cmod) {
|
||||
if (img->gamma == 0) {
|
||||
imlib_context_set_color_modifier(NULL);
|
||||
} else {
|
||||
double range = img->gamma <= 0 ? 1.0 : GAMMA_MAX - 1.0;
|
||||
imlib_context_set_color_modifier(img->cmod);
|
||||
imlib_reset_color_modifier();
|
||||
imlib_modify_color_modifier_gamma(
|
||||
1.0 + (double) img->gamma
|
||||
* (range / (double) GAMMA_RANGE));
|
||||
}
|
||||
if (d == 0)
|
||||
gamma = 0;
|
||||
else if (d < 0)
|
||||
gamma = MAX(-GAMMA_RANGE, img->gamma - 1);
|
||||
else
|
||||
gamma = MIN(+GAMMA_RANGE, img->gamma + 1);
|
||||
|
||||
if (img->gamma != gamma) {
|
||||
img->gamma = gamma;
|
||||
img_apply_gamma(img);
|
||||
img->dirty = true;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
image.h
2
image.h
|
@ -84,7 +84,7 @@ void img_flip(img_t*, flipdir_t);
|
|||
|
||||
void img_toggle_antialias(img_t*);
|
||||
|
||||
void img_set_gamma(img_t*, int);
|
||||
bool img_change_gamma(img_t*, int);
|
||||
|
||||
bool img_frame_navigate(img_t*, int);
|
||||
bool img_frame_animate(img_t*, bool);
|
||||
|
|
7
main.c
7
main.c
|
@ -345,14 +345,15 @@ void update_info(void)
|
|||
ow_info = false;
|
||||
}
|
||||
} else {
|
||||
n = snprintf(rt, rlen, "%s%3d%% | ", mark, (int) (img.zoom * 100.0));
|
||||
n = snprintf(rt, rlen, "%s", mark);
|
||||
if (img.gamma != 0)
|
||||
n += snprintf(rt + n, rlen - n, "G%+d | ", img.gamma);
|
||||
n += snprintf(rt + n, rlen - n, "%3d%% | ", (int) (img.zoom * 100.0));
|
||||
if (img.multi.cnt > 0) {
|
||||
for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10);
|
||||
n += snprintf(rt + n, rlen - n, "%0*d/%d | ",
|
||||
fn, img.multi.sel + 1, img.multi.cnt);
|
||||
}
|
||||
if (img.gamma != 0)
|
||||
n += snprintf(rt + n, rlen - n, "g%d | ", img.gamma);
|
||||
n += snprintf(rt + n, rlen - n, "%0*d/%d", fw, sel + 1, filecnt);
|
||||
ow_info = info.script == NULL;
|
||||
}
|
||||
|
|
14
options.c
14
options.c
|
@ -33,7 +33,7 @@ const options_t *options = (const options_t*) &_options;
|
|||
|
||||
void print_usage(void)
|
||||
{
|
||||
printf("usage: sxiv [-bcdFfhioqrstvZ] [-g GEOMETRY] [-G GAMMA] [-n NUM] "
|
||||
printf("usage: sxiv [-bcdFfhioqrstvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] "
|
||||
"[-N name] [-z ZOOM] FILES...\n");
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ void print_version(void)
|
|||
void parse_options(int argc, char **argv)
|
||||
{
|
||||
int opt, t, gamma;
|
||||
char *end;
|
||||
|
||||
_options.from_stdin = false;
|
||||
_options.to_stdout = false;
|
||||
|
@ -65,7 +66,7 @@ void parse_options(int argc, char **argv)
|
|||
_options.thumb_mode = false;
|
||||
_options.clean_cache = false;
|
||||
|
||||
while ((opt = getopt(argc, argv, "bcdFfg:G:hin:N:oqrstvZz:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "bcdFfG:g:hin:N:oqrstvZz:")) != -1) {
|
||||
switch (opt) {
|
||||
case '?':
|
||||
print_usage();
|
||||
|
@ -85,17 +86,18 @@ void parse_options(int argc, char **argv)
|
|||
case 'f':
|
||||
_options.fullscreen = true;
|
||||
break;
|
||||
case 'g':
|
||||
_options.geometry = optarg;
|
||||
break;
|
||||
case 'G':
|
||||
if (sscanf(optarg, "%d", &gamma) <= 0) {
|
||||
gamma = strtol(optarg, &end, 0);
|
||||
if (*end != '\0') {
|
||||
fprintf(stderr, "sxiv: invalid argument for option -G: %s\n",
|
||||
optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
_options.gamma = gamma;
|
||||
break;
|
||||
case 'g':
|
||||
_options.geometry = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
print_usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
|
|
16
sxiv.1
16
sxiv.1
|
@ -4,12 +4,14 @@ sxiv \- Simple X Image Viewer
|
|||
.SH SYNOPSIS
|
||||
.B sxiv
|
||||
.RB [ \-bcdFfhiopqrstvZ ]
|
||||
.RB [ \-G
|
||||
.IR GAMMA ]
|
||||
.RB [ \-g
|
||||
.IR GEOMETRY ]
|
||||
.RB [ \-n
|
||||
.IR NUM ]
|
||||
.RB [ \-N
|
||||
.IR NAME ]
|
||||
.RB [ \-n
|
||||
.IR NUM ]
|
||||
.RB [ \-z
|
||||
.IR ZOOM ]
|
||||
.IR FILE ...
|
||||
|
@ -44,20 +46,20 @@ size-hints to the window width/height.
|
|||
.B \-f
|
||||
Start in fullscreen mode.
|
||||
.TP
|
||||
.BI "\-G " GAMMA
|
||||
Set image gamma to GAMMA (-32..32).
|
||||
.TP
|
||||
.BI "\-g " GEOMETRY
|
||||
Set window position and size. See section GEOMETRY SPECIFICATIONS of X(7) for
|
||||
more information on
|
||||
.IR GEOMETRY .
|
||||
.TP
|
||||
.BI "\-G " GAMMA
|
||||
Set gamma to GAMMA (-32..32).
|
||||
.BI "\-N " NAME
|
||||
Set the resource name of sxiv's X window to NAME.
|
||||
.TP
|
||||
.BI "\-n " NUM
|
||||
Start at picture number NUM.
|
||||
.TP
|
||||
.BI "\-N " NAME
|
||||
Set the resource name of sxiv's X window to NAME.
|
||||
.TP
|
||||
.B \-h
|
||||
Print brief usage information to standard output and exit.
|
||||
.TP
|
||||
|
|
Loading…
Reference in a new issue