From d72088e0b2e958a9dc6a05cc9d29207e4d280c6b Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Wed, 3 May 2017 11:30:12 +0100 Subject: [PATCH] Fix #123: Limit image expansion in Fit To Window https://github.com/BestImageViewer/geeqie/issues/123 Additional option in Preferences/Image to limit the expansion of an image in Fit To Window mode. Stops small images being over-magnified. --- doc/docbook/GuideOptionsImage.xml | 2 +- src/image.c | 1 + src/options.c | 1 + src/options.h | 1 + src/pixbuf-renderer.c | 30 +++++++++++++++++++++++++++++- src/pixbuf-renderer.h | 1 + src/preferences.c | 11 +++++++++-- src/rcfile.c | 2 ++ 8 files changed, 45 insertions(+), 4 deletions(-) diff --git a/doc/docbook/GuideOptionsImage.xml b/doc/docbook/GuideOptionsImage.xml index e64016e2..7cac9ae6 100644 --- a/doc/docbook/GuideOptionsImage.xml +++ b/doc/docbook/GuideOptionsImage.xml @@ -79,7 +79,7 @@ Enable this to allow Geeqie to increase the image size for images that are smaller than the current view area when the zoom is set to Fit image to window - . + . The value in the adjoining spin box sets the maximum size permitted in percent i.e. 100% is full-size. diff --git a/src/image.c b/src/image.c index 7fad282d..76724db1 100644 --- a/src/image.c +++ b/src/image.c @@ -1743,6 +1743,7 @@ static void image_options_set(ImageWindow *imd) "window_limit_value", options->image.max_window_size, "autofit_limit", options->image.limit_autofit_size, "autofit_limit_value", options->image.max_autofit_size, + "enlargement_limit_value", options->image.max_enlargement_size, NULL); diff --git a/src/options.c b/src/options.c index 34563485..5477dffc 100644 --- a/src/options.c +++ b/src/options.c @@ -93,6 +93,7 @@ ConfOptions *init_options(ConfOptions *options) options->image.limit_autofit_size = FALSE; options->image.limit_window_size = TRUE; options->image.max_autofit_size = 100; + options->image.max_enlargement_size = 900; options->image.max_window_size = 90; options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE; options->image.tile_cache_max = 10; diff --git a/src/options.h b/src/options.h index 15ac65bd..39054423 100644 --- a/src/options.h +++ b/src/options.h @@ -74,6 +74,7 @@ struct _ConfOptions gint max_window_size; gboolean limit_autofit_size; gint max_autofit_size; + gint max_enlargement_size; gint tile_cache_max; /* in megabytes */ gint image_cache_max; /* in megabytes */ diff --git a/src/pixbuf-renderer.c b/src/pixbuf-renderer.c index f736ccc6..411d91e0 100644 --- a/src/pixbuf-renderer.c +++ b/src/pixbuf-renderer.c @@ -105,7 +105,8 @@ enum { PROP_WINDOW_LIMIT, PROP_WINDOW_LIMIT_VALUE, PROP_AUTOFIT_LIMIT, - PROP_AUTOFIT_LIMIT_VALUE + PROP_AUTOFIT_LIMIT_VALUE, + PROP_ENLARGEMENT_LIMIT_VALUE }; typedef enum { @@ -329,6 +330,16 @@ static void pixbuf_renderer_class_init(PixbufRendererClass *class) 100, G_PARAM_READABLE | G_PARAM_WRITABLE)); + g_object_class_install_property(gobject_class, + PROP_ENLARGEMENT_LIMIT_VALUE, + g_param_spec_uint("enlargement_limit_value", + "Size increase limit of image when autofitting", + NULL, + 100, + 999, + 500, + G_PARAM_READABLE | G_PARAM_WRITABLE)); + signals[SIGNAL_ZOOM] = g_signal_new("zoom", @@ -530,6 +541,9 @@ static void pixbuf_renderer_set_property(GObject *object, guint prop_id, case PROP_AUTOFIT_LIMIT_VALUE: pr->autofit_limit_size = g_value_get_uint(value); break; + case PROP_ENLARGEMENT_LIMIT_VALUE: + pr->enlargement_limit_size = g_value_get_uint(value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -593,6 +607,9 @@ static void pixbuf_renderer_get_property(GObject *object, guint prop_id, case PROP_AUTOFIT_LIMIT_VALUE: g_value_set_uint(value, pr->autofit_limit_size); break; + case PROP_ENLARGEMENT_LIMIT_VALUE: + g_value_set_uint(value, pr->enlargement_limit_size); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -1665,6 +1682,17 @@ static gboolean pr_zoom_clamp(PixbufRenderer *pr, gdouble zoom, scale = scale * factor; } + if (pr->zoom_expand) + { + gdouble factor = (gdouble)pr->enlargement_limit_size / 100; + if (scale > factor) + { + w = w * factor / scale; + h = h * factor / scale; + scale = factor; + } + } + if (w < 1) w = 1; if (h < 1) h = 1; } diff --git a/src/pixbuf-renderer.h b/src/pixbuf-renderer.h index 783110ab..c399e1fd 100644 --- a/src/pixbuf-renderer.h +++ b/src/pixbuf-renderer.h @@ -158,6 +158,7 @@ struct _PixbufRenderer gboolean autofit_limit; gint autofit_limit_size; + gint enlargement_limit_size; GdkColor color; diff --git a/src/preferences.c b/src/preferences.c index 57f3e7b7..36750f2e 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -236,6 +236,7 @@ static void config_window_apply(void) options->image.max_window_size = c_options->image.max_window_size; options->image.limit_autofit_size = c_options->image.limit_autofit_size; options->image.max_autofit_size = c_options->image.max_autofit_size; + options->image.max_enlargement_size = c_options->image.max_enlargement_size; options->image.use_clutter_renderer = c_options->image.use_clutter_renderer; options->progressive_key_scrolling = c_options->progressive_key_scrolling; options->keyboard_scroll_step = c_options->keyboard_scroll_step; @@ -1478,6 +1479,7 @@ static void config_tab_image(GtkWidget *notebook) GtkWidget *group; GtkWidget *button; GtkWidget *ct_button; + GtkWidget *enlargement_button; GtkWidget *table; GtkWidget *spin; @@ -1496,11 +1498,16 @@ static void config_tab_image(GtkWidget *notebook) pref_checkbox_new_int(group, _("Two pass rendering (apply HQ zoom and color correction in second pass)"), options->image.zoom_2pass, &c_options->image.zoom_2pass); - pref_checkbox_new_int(group, _("Allow enlargement of image for zoom to fit"), + hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); + enlargement_button = pref_checkbox_new_int(hbox, _("Allow enlargement of image for zoom to fit (max. size in %)"), options->image.zoom_to_fit_allow_expand, &c_options->image.zoom_to_fit_allow_expand); + spin = pref_spin_new_int(hbox, NULL, NULL, + 100, 999, 1, + options->image.max_enlargement_size, &c_options->image.max_enlargement_size); + pref_checkbox_link_sensitivity(enlargement_button, spin); hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); - ct_button = pref_checkbox_new_int(hbox, _("Limit image size when autofitting (%):"), + ct_button = pref_checkbox_new_int(hbox, _("Limit image size when autofitting (% of window):"), options->image.limit_autofit_size, &c_options->image.limit_autofit_size); spin = pref_spin_new_int(hbox, NULL, NULL, 10, 150, 1, diff --git a/src/rcfile.c b/src/rcfile.c index 5da858af..e6663f9b 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -358,6 +358,7 @@ static void write_global_attributes(GString *outstr, gint indent) WRITE_NL(); WRITE_INT(*options, image.max_window_size); WRITE_NL(); WRITE_BOOL(*options, image.limit_autofit_size); WRITE_NL(); WRITE_INT(*options, image.max_autofit_size); + WRITE_NL(); WRITE_INT(*options, image.max_enlargement_size); WRITE_NL(); WRITE_UINT(*options, image.scroll_reset_method); WRITE_NL(); WRITE_INT(*options, image.tile_cache_max); WRITE_NL(); WRITE_INT(*options, image.image_cache_max); @@ -632,6 +633,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar ** if (READ_INT(*options, image.max_window_size)) continue; if (READ_BOOL(*options, image.limit_autofit_size)) continue; if (READ_INT(*options, image.max_autofit_size)) continue; + if (READ_INT(*options, image.max_enlargement_size)) continue; if (READ_UINT_CLAMP(*options, image.scroll_reset_method, 0, PR_SCROLL_RESET_COUNT - 1)) continue; if (READ_INT(*options, image.tile_cache_max)) continue; if (READ_INT(*options, image.image_cache_max)) continue; -- 2.20.1