Fix #123: Limit image expansion in Fit To Window
authorColin Clark <colin.clark@cclark.uk>
Wed, 3 May 2017 10:30:12 +0000 (11:30 +0100)
committerColin Clark <colin.clark@cclark.uk>
Wed, 3 May 2017 10:30:12 +0000 (11:30 +0100)
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
src/image.c
src/options.c
src/options.h
src/pixbuf-renderer.c
src/pixbuf-renderer.h
src/preferences.c
src/rcfile.c

index e64016e..7cac9ae 100644 (file)
@@ -79,7 +79,7 @@
           <para>\r
             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\r
             <emphasis>Fit image to window</emphasis>\r
-            .\r
+            . The value in the adjoining spin box sets the maximum size permitted in percent i.e. 100% is full-size.\r
           </para>\r
         </listitem>\r
       </varlistentry>\r
index 7fad282..76724db 100644 (file)
@@ -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);
 
index 3456348..5477dff 100644 (file)
@@ -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;
index 15ac65b..3905442 100644 (file)
@@ -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 */
index f736ccc..411d91e 100644 (file)
@@ -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;
                        }
index 783110a..c399e1f 100644 (file)
@@ -158,6 +158,7 @@ struct _PixbufRenderer
 
        gboolean autofit_limit;
        gint autofit_limit_size;
+       gint enlargement_limit_size;
 
        GdkColor color;
 
index 57f3e7b..36750f2 100644 (file)
@@ -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,
index 5da858a..e6663f9 100644 (file)
@@ -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;