From 47e6cd066902ec6e6295c6ae55245f8f4e53a56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Mon, 5 Jan 2015 20:53:04 +0100 Subject: Apply gamma value on thumbnails too; fixes issue #193 --- Makefile | 2 +- commands.c | 16 +++++++++++----- commands.lst | 2 +- config.def.h | 6 +++--- image.c | 41 +++++++++++------------------------------ 5 files changed, 27 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index f0b22d3..2fc53b8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := git-20150104 +VERSION := git-20150105 PREFIX := /usr/local MANPREFIX := $(PREFIX)/share/man diff --git a/commands.c b/commands.c index a7a028d..d916a09 100644 --- a/commands.c +++ b/commands.c @@ -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) { long n = (long) a; @@ -419,11 +430,6 @@ bool ci_flip(arg_t a) return true; } -bool ci_change_gamma(arg_t a) -{ - return img_change_gamma(&img, (long) a); -} - bool ci_toggle_antialias(arg_t a) { img_toggle_antialias(&img); diff --git a/commands.lst b/commands.lst index a1b14e6..a658dd4 100644 --- a/commands.lst +++ b/commands.lst @@ -13,6 +13,7 @@ G_CMD(toggle_image_mark) G_CMD(reverse_marks) G_CMD(unmark_all) G_CMD(navigate_marked) +G_CMD(change_gamma) I_CMD(navigate) I_CMD(alternate) @@ -25,7 +26,6 @@ I_CMD(set_zoom) I_CMD(fit_to_win) I_CMD(rotate) I_CMD(flip) -I_CMD(change_gamma) I_CMD(toggle_antialias) I_CMD(toggle_alpha) I_CMD(slideshow) diff --git a/config.def.h b/config.def.h index cb230c8..f3fd9d3 100644 --- a/config.def.h +++ b/config.def.h @@ -88,6 +88,9 @@ static const keymap_t keys[] = { { ControlMask, XK_m, g_unmark_all, (arg_t) None }, { 0, XK_N, 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_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_bar, i_flip, (arg_t) FLIP_HORIZONTAL }, { 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_alpha, (arg_t) None }, { 0, XK_s, i_slideshow, (arg_t) None }, diff --git a/image.c b/image.c index 240054f..fe2c6e8 100644 --- a/image.c +++ b/image.c @@ -46,22 +46,6 @@ 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; @@ -89,8 +73,9 @@ void img_init(img_t *img, win_t *win) img->multi.length = 0; img->cmod = imlib_create_color_modifier(); + imlib_context_set_color_modifier(img->cmod); img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE); - + img->ss.on = options->slideshow > 0; 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); #endif } - img_apply_gamma(img); - img->w = imlib_image_get_width(); img->h = imlib_image_get_height(); img->checkpan = true; @@ -371,9 +354,6 @@ void img_close(img_t *img, bool decache) imlib_free_image(); img->im = NULL; } - - if (img->cmod) - imlib_context_set_color_modifier(NULL); } 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_context_set_color_modifier(NULL); imlib_render_image_on_drawable(dx, dy); - imlib_free_image(); - if (img->gamma != 0) - imlib_context_set_color_modifier(img->cmod); + imlib_context_set_color_modifier(img->cmod); } else { 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 */ int gamma; + double range; - if (img == NULL || img->im == NULL) + if (img == NULL) return false; if (d == 0) gamma = 0; - else if (d < 0) - gamma = MAX(-GAMMA_RANGE, img->gamma - 1); else - gamma = MIN(+GAMMA_RANGE, img->gamma + 1); + gamma = MIN(MAX(img->gamma + d, -GAMMA_RANGE), GAMMA_RANGE); 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_apply_gamma(img); img->dirty = true; return true; } else { -- cgit v1.2.3