Apply gamma value on thumbnails too; fixes issue #193

This commit is contained in:
Bert Münnich 2015-01-05 20:53:04 +01:00
parent 47af0dd7b5
commit 47e6cd0669
5 changed files with 27 additions and 40 deletions

View File

@ -1,4 +1,4 @@
VERSION := git-20150104 VERSION := git-20150105
PREFIX := /usr/local PREFIX := /usr/local
MANPREFIX := $(PREFIX)/share/man MANPREFIX := $(PREFIX)/share/man

View File

@ -260,6 +260,17 @@ bool cg_navigate_marked(arg_t a)
} }
} }
bool cg_change_gamma(arg_t a)
{
if (img_change_gamma(&img, (long) a * (prefix > 0 ? prefix : 1))) {
if (mode == MODE_THUMB)
tns.dirty = true;
return true;
} else {
return false;
}
}
bool ci_navigate(arg_t a) bool ci_navigate(arg_t a)
{ {
long n = (long) a; long n = (long) a;
@ -419,11 +430,6 @@ bool ci_flip(arg_t a)
return true; return true;
} }
bool ci_change_gamma(arg_t a)
{
return img_change_gamma(&img, (long) a);
}
bool ci_toggle_antialias(arg_t a) bool ci_toggle_antialias(arg_t a)
{ {
img_toggle_antialias(&img); img_toggle_antialias(&img);

View File

@ -13,6 +13,7 @@ G_CMD(toggle_image_mark)
G_CMD(reverse_marks) G_CMD(reverse_marks)
G_CMD(unmark_all) G_CMD(unmark_all)
G_CMD(navigate_marked) G_CMD(navigate_marked)
G_CMD(change_gamma)
I_CMD(navigate) I_CMD(navigate)
I_CMD(alternate) I_CMD(alternate)
@ -25,7 +26,6 @@ I_CMD(set_zoom)
I_CMD(fit_to_win) I_CMD(fit_to_win)
I_CMD(rotate) I_CMD(rotate)
I_CMD(flip) I_CMD(flip)
I_CMD(change_gamma)
I_CMD(toggle_antialias) I_CMD(toggle_antialias)
I_CMD(toggle_alpha) I_CMD(toggle_alpha)
I_CMD(slideshow) I_CMD(slideshow)

View File

@ -88,6 +88,9 @@ static const keymap_t keys[] = {
{ ControlMask, XK_m, g_unmark_all, (arg_t) None }, { ControlMask, XK_m, g_unmark_all, (arg_t) None },
{ 0, XK_N, g_navigate_marked, (arg_t) +1 }, { 0, XK_N, g_navigate_marked, (arg_t) +1 },
{ 0, XK_P, g_navigate_marked, (arg_t) -1 }, { 0, XK_P, g_navigate_marked, (arg_t) -1 },
{ 0, XK_braceleft, g_change_gamma, (arg_t) -1 },
{ 0, XK_braceright, g_change_gamma, (arg_t) +1 },
{ ControlMask, XK_g, g_change_gamma, (arg_t) 0 },
{ 0, XK_h, t_move_sel, (arg_t) DIR_LEFT }, { 0, XK_h, t_move_sel, (arg_t) DIR_LEFT },
{ 0, XK_Left, t_move_sel, (arg_t) DIR_LEFT }, { 0, XK_Left, t_move_sel, (arg_t) DIR_LEFT },
@ -133,9 +136,6 @@ static const keymap_t keys[] = {
{ 0, XK_question, i_rotate, (arg_t) DEGREE_180 }, { 0, XK_question, i_rotate, (arg_t) DEGREE_180 },
{ 0, XK_bar, i_flip, (arg_t) FLIP_HORIZONTAL }, { 0, XK_bar, i_flip, (arg_t) FLIP_HORIZONTAL },
{ 0, XK_underscore, i_flip, (arg_t) FLIP_VERTICAL }, { 0, XK_underscore, i_flip, (arg_t) FLIP_VERTICAL },
{ 0, XK_braceleft, i_change_gamma, (arg_t) -1 },
{ 0, XK_braceright, i_change_gamma, (arg_t) +1 },
{ ControlMask, XK_g, i_change_gamma, (arg_t) 0 },
{ 0, XK_a, i_toggle_antialias, (arg_t) None }, { 0, XK_a, i_toggle_antialias, (arg_t) None },
{ 0, XK_A, i_toggle_alpha, (arg_t) None }, { 0, XK_A, i_toggle_alpha, (arg_t) None },
{ 0, XK_s, i_slideshow, (arg_t) None }, { 0, XK_s, i_slideshow, (arg_t) None },

41
image.c
View File

@ -46,22 +46,6 @@ static int zoomdiff(float z1, float z2)
return (int) (z1 * 1000.0 - z2 * 1000.0); 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) void img_init(img_t *img, win_t *win)
{ {
zoom_min = zoom_levels[0] / 100.0; zoom_min = zoom_levels[0] / 100.0;
@ -89,8 +73,9 @@ void img_init(img_t *img, win_t *win)
img->multi.length = 0; img->multi.length = 0;
img->cmod = imlib_create_color_modifier(); img->cmod = imlib_create_color_modifier();
imlib_context_set_color_modifier(img->cmod);
img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE); img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE);
img->ss.on = options->slideshow > 0; img->ss.on = options->slideshow > 0;
img->ss.delay = options->slideshow > 0 ? options->slideshow : SLIDESHOW_DELAY; img->ss.delay = options->slideshow > 0 ? options->slideshow : SLIDESHOW_DELAY;
} }
@ -339,8 +324,6 @@ bool img_load(img_t *img, const fileinfo_t *file)
img_load_gif(img, file); img_load_gif(img, file);
#endif #endif
} }
img_apply_gamma(img);
img->w = imlib_image_get_width(); img->w = imlib_image_get_width();
img->h = imlib_image_get_height(); img->h = imlib_image_get_height();
img->checkpan = true; img->checkpan = true;
@ -371,9 +354,6 @@ void img_close(img_t *img, bool decache)
imlib_free_image(); imlib_free_image();
img->im = NULL; img->im = NULL;
} }
if (img->cmod)
imlib_context_set_color_modifier(NULL);
} }
void img_check_pan(img_t *img, bool moved) void img_check_pan(img_t *img, bool moved)
@ -529,10 +509,8 @@ void img_render(img_t *img)
imlib_blend_image_onto_image(img->im, 0, sx, sy, sw, sh, 0, 0, dw, dh); imlib_blend_image_onto_image(img->im, 0, sx, sy, sw, sh, 0, 0, dw, dh);
imlib_context_set_color_modifier(NULL); imlib_context_set_color_modifier(NULL);
imlib_render_image_on_drawable(dx, dy); imlib_render_image_on_drawable(dx, dy);
imlib_free_image(); imlib_free_image();
if (img->gamma != 0) imlib_context_set_color_modifier(img->cmod);
imlib_context_set_color_modifier(img->cmod);
} else { } else {
imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh); imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh);
} }
@ -771,20 +749,23 @@ bool img_change_gamma(img_t *img, int d)
* d > 0: increase gamma * d > 0: increase gamma
*/ */
int gamma; int gamma;
double range;
if (img == NULL || img->im == NULL) if (img == NULL)
return false; return false;
if (d == 0) if (d == 0)
gamma = 0; gamma = 0;
else if (d < 0)
gamma = MAX(-GAMMA_RANGE, img->gamma - 1);
else else
gamma = MIN(+GAMMA_RANGE, img->gamma + 1); gamma = MIN(MAX(img->gamma + d, -GAMMA_RANGE), GAMMA_RANGE);
if (img->gamma != gamma) { if (img->gamma != gamma) {
imlib_reset_color_modifier();
if (gamma != 0) {
range = gamma <= 0 ? 1.0 : GAMMA_MAX - 1.0;
imlib_modify_color_modifier_gamma(1.0 + gamma * (range / GAMMA_RANGE));
}
img->gamma = gamma; img->gamma = gamma;
img_apply_gamma(img);
img->dirty = true; img->dirty = true;
return true; return true;
} else { } else {