[Xfce4-commits] <ristretto:master> Improve cache-size and image-quality calculations
Stephan Arts
stephan at xfce.org
Wed Aug 12 12:22:20 CEST 2009
Updating branch refs/heads/master
to 2182434ce9cc1ec909e0eafdd141ad8921b21981 (commit)
from 95ea5978a9d91f3cb1bef5300d097d97674d38d8 (commit)
commit 2182434ce9cc1ec909e0eafdd141ad8921b21981
Author: Stephan Arts <stephan at xfce.org>
Date: Mon May 25 11:18:18 2009 +0200
Improve cache-size and image-quality calculations
ChangeLog | 9 +++++++-
src/image.c | 2 +-
src/image_cache.c | 18 +++++++---------
src/preferences_dialog.c | 48 +++++++++++++++++++++++++++++++++------------
src/settings.c | 4 +-
5 files changed, 54 insertions(+), 27 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f7170d7..b271d0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,11 @@
-2009-05-25 Stephan Arts <stephan.xfce.org>
+2009-05-25 Stephan Arts <stephan at xfce.org>
+
+ * src/image_cache.c
+ src/preferences_dialog.c
+ src/settings.c
+ src/image.c: Improve cache-size and image-quality calculations
+
+2009-05-25 Stephan Arts <stephan at xfce.org>
* src/main_window.c
src/preferences_dialog.c: Implement preferences for the 'open' toolbar
diff --git a/src/image.c b/src/image.c
index b175bbd..77b3ed5 100644
--- a/src/image.c
+++ b/src/image.c
@@ -569,7 +569,7 @@ cb_rstto_image_size_prepared (GdkPixbufLoader *loader, gint width, gint height,
if (image->priv->max_size > 0)
{
- gdouble ratio = (gdouble)(image->priv->max_size*1000000)/(gdouble)(width * height);
+ gdouble ratio = (gdouble)(image->priv->max_size)/(gdouble)(width * height);
if (ratio < 1)
gdk_pixbuf_loader_set_size (loader, width*ratio, height*ratio);
}
diff --git a/src/image_cache.c b/src/image_cache.c
index d25a143..ce6a1fc 100644
--- a/src/image_cache.c
+++ b/src/image_cache.c
@@ -91,18 +91,16 @@ rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolea
{
gboolean retval = FALSE;
RsttoSettings *settings = rstto_settings_new();
- GValue val = {0, }, val_cache_size = {0, };
+ gboolean cache_enabled;
guint size = 0;
guint cache_size = 0;
RsttoImage *c_image;
GList *iter = NULL;
- g_value_init (&val, G_TYPE_BOOLEAN);
- g_value_init (&val_cache_size, G_TYPE_UINT);
- g_object_get_property (G_OBJECT (settings), "enable-cache", &val);
- g_object_get_property (G_OBJECT (settings), "cache-size", &val_cache_size);
-
- cache_size = g_value_get_uint(&val_cache_size)*1000000;
+ g_object_get (G_OBJECT (settings),
+ "enable-cache", &cache_enabled,
+ "cache-size", &cache_size,
+ NULL);
if (cache->cache_list)
{
@@ -123,8 +121,9 @@ rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolea
/**
* Check if we are keeping a cache
*/
- if (g_value_get_boolean (&val) == FALSE)
+ if (cache_enabled == FALSE)
{
+ g_debug ("cache disable");
while (g_list_length (cache->cache_list) > 1)
{
c_image = g_list_last (cache->cache_list)->data;
@@ -141,7 +140,7 @@ rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolea
for (iter = cache->cache_list->next; iter != NULL; iter = g_list_next (iter))
{
c_image = iter->data;
- if (size > cache_size)
+ if (size > (cache_size*1000000))
{
rstto_image_unload (c_image);
cache->cache_list = g_list_remove (cache->cache_list, c_image);
@@ -161,7 +160,6 @@ rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolea
}
}
g_object_unref (settings);
- g_value_unset (&val);
return retval;
}
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 9b36639..b58ef26 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -283,21 +283,21 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
gtk_box_pack_start (GTK_BOX (dialog->priv->display_tab.image_quality_hbox),
dialog->priv->display_tab.image_quality_combo, FALSE, FALSE, 0);
/* set current value */
- switch (uint_image_quality)
+ switch (uint_image_quality-(uint_image_quality%1000000))
{
case 0:
gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), 0);
break;
- case 1:
+ case 1000000:
gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), 1);
break;
- case 2:
+ case 2000000:
gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), 2);
break;
- case 4:
+ case 4000000:
gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), 4);
break;
- case 8:
+ case 8000000:
gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), 8);
break;
default:
@@ -547,17 +547,39 @@ cb_rstto_preferences_dialog_cache_spin_button_value_changed (GtkSpinButton *butt
static void
cb_rstto_preferences_dialog_image_quality_combo_box_changed (GtkComboBox *combo_box,
gpointer user_data)
+
{
+ /* FIXME */
RsttoPreferencesDialog *dialog = RSTTO_PREFERENCES_DIALOG (user_data);
+ switch (gtk_combo_box_get_active (combo_box))
+ {
+ case 0: /* unlimited */
+ g_object_set (G_OBJECT (dialog->priv->settings),
+ "image-quality", 0,
+ NULL);
+ break;
+ case 1: /* 1 MegaPixel */
+ g_object_set (G_OBJECT (dialog->priv->settings),
+ "image-quality", 1000000,
+ NULL);
+ break;
+ case 2: /* 2 MegaPixel */
+ g_object_set (G_OBJECT (dialog->priv->settings),
+ "image-quality", 2000000,
+ NULL);
+ break;
+ case 3: /* 4 MegaPixel */
+ g_object_set (G_OBJECT (dialog->priv->settings),
+ "image-quality", 4000000,
+ NULL);
+ break;
+ case 4: /* 8 MegaPixel */
+ g_object_set (G_OBJECT (dialog->priv->settings),
+ "image-quality", 8000000,
+ NULL);
+ break;
- GValue value = {0, };
- g_value_init (&value, G_TYPE_UINT);
-
- g_value_set_uint (&value, (guint)gtk_combo_box_get_active (combo_box));
-
- g_object_set_property (G_OBJECT (dialog->priv->settings), "image-quality", &value);
-
- g_value_unset (&value);
+ }
}
static void
diff --git a/src/settings.c b/src/settings.c
index e1efa65..d8b5083 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -251,8 +251,8 @@ rstto_settings_class_init (GObjectClass *object_class)
"",
"",
0,
- 50,
- 2,
+ 50000000,
+ 2000000,
G_PARAM_READWRITE);
g_object_class_install_property (object_class,
PROP_IMAGE_QUALITY,
More information about the Xfce4-commits
mailing list