summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-01-09 01:27:29 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-01-09 01:27:29 +0100
commit91a89808f1f9a19c6703706f1859c870b9884d05 (patch)
tree13483c15d505c2ebe2b5a02c8ba5f5b847e5c43e
parentacacdcd8521c29f1a2c893d4bf97445cb22a9e75 (diff)
Store original pixbufs so that preloaded images can be properly resized.
load_pixbuf() will now load the original pixbuf, then draw the pre-resized pixbuf (if any) while keeping the original loaded. This way the image will be properly resized when needed. Added mutex calls to preload_clear().
-rw-r--r--preload.c31
-rw-r--r--preload.h3
-rw-r--r--window_main.c10
3 files changed, 34 insertions, 10 deletions
diff --git a/preload.c b/preload.c
index 281bdf6..3bd2e24 100644
--- a/preload.c
+++ b/preload.c
@@ -24,7 +24,10 @@ static void preload_hash_table_free(gpointer data) {
pt = data;
- g_object_unref(pt->pb);
+ if(pt->pb)
+ g_object_unref(pt->pb);
+
+ g_object_unref(pt->pb_orig);
g_free(data);
}
@@ -169,7 +172,27 @@ void preload_start_thread(GtkWidget *thumbview, gint win_width, gint win_height)
}
void preload_clear() {
+ g_mutex_lock(preload_hashtable_mutex);
g_hash_table_remove_all(hashtable);
+ g_mutex_unlock(preload_hashtable_mutex);
+}
+
+void preload_clear_sized() {
+ GHashTableIter iter;
+ struct preload_hash_table_value_t *data;
+
+ g_mutex_lock(preload_hashtable_mutex);
+
+ g_hash_table_iter_init(&iter, hashtable);
+
+ while(g_hash_table_iter_next(&iter, NULL, (gpointer)&data)) {
+ if(data->pb) {
+ g_object_unref(data->pb);
+ data->pb = NULL;
+ }
+ }
+
+ g_mutex_unlock(preload_hashtable_mutex);
}
static void preload_add(const gchar *filename, gpointer data) {
@@ -218,15 +241,15 @@ inline static void add_pixbuf(const gchar *filename, gpointer _data) {
value = g_malloc(sizeof(struct preload_hash_table_value_t));
+ value->pb_orig = orig;
+
if(pb) {
value->pb = pb;
value->width = width;
value->height = height;
value->ratio = ratio;
-
- g_object_unref(orig);
} else {
- value->pb = orig;
+ value->pb = NULL;
value->width = 0;
value->height = 0;
value->ratio = 0;
diff --git a/preload.h b/preload.h
index dbadbeb..b5edc24 100644
--- a/preload.h
+++ b/preload.h
@@ -6,7 +6,7 @@
#include <gtk/gtk.h>
struct preload_hash_table_value_t {
- GdkPixbuf *pb;
+ GdkPixbuf *pb, *pb_orig;
gint width, height;
gdouble ratio;
};
@@ -15,6 +15,7 @@ void preload_init();
void preload_free();
void preload_start_thread(GtkWidget*, gint, gint);
void preload_clear();
+void preload_clear_sized();
gpointer preload_get(const gchar*);
extern guint preload_max;
diff --git a/window_main.c b/window_main.c
index 41f53ad..a4e84f1 100644
--- a/window_main.c
+++ b/window_main.c
@@ -147,7 +147,7 @@ static void set_image_pixbuf() {
void on_window_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data) {
if(orig_pixbuf && (allocation->width != last_width || allocation->height != last_height)) {
- preload_clear();
+ preload_clear_sized();
set_image_pixbuf();
last_width = allocation->width;
last_height = allocation->height;
@@ -160,7 +160,7 @@ static gboolean hpane_resize_idle_func(gpointer data) {
pos = gtk_paned_get_position(GTK_PANED(data));
if(pos != hpane_last_pos) {
- preload_clear();
+ preload_clear_sized();
set_image_pixbuf();
hpane_last_pos = pos;
return TRUE; /* Ensure that we'll keep checking until we're done resizing. */
@@ -203,7 +203,7 @@ static void load_pixbuf(const gchar *filepath) {
pt = preload_get(filepath);
if(pt)
- orig_pixbuf = gdk_pixbuf_copy(pt->pb);
+ orig_pixbuf = gdk_pixbuf_copy(pt->pb_orig);
else
orig_pixbuf = NULL;
@@ -243,11 +243,11 @@ static void load_pixbuf(const gchar *filepath) {
walls_set_window_title();
}
- if(pt) {
+ if(pt && pt->pb) {
window = gtk_widget_get_window(layout);
gdk_drawable_get_size(window, &win_width, &win_height);
- set_image_pixbuf_resized(orig_pixbuf, win_width, win_height, pt->width, pt->height, pt->ratio);
+ set_image_pixbuf_resized(pt->pb, win_width, win_height, pt->width, pt->height, pt->ratio);
} else
set_image_pixbuf();
}