/*
* Geeqie
* (C) 2004 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
*
* Author: John Ellis
*
#include "thumb_standard.h"
#include "ui_fileops.h"
#include "exif.h"
+#include "metadata.h"
#include <utime.h>
static void thumb_loader_error_cb(ImageLoader *il, gpointer data);
-static void thumb_loader_setup(ThumbLoader *tl, const gchar *path);
+static void thumb_loader_setup(ThumbLoader *tl, FileData *fd);
static GdkPixbuf *get_xv_thumbnail(gchar *thumb_filename, gint max_w, gint max_h);
cache_dir = cache_get_location(CACHE_TYPE_THUMB, tl->fd->path, FALSE, &mode);
- if (cache_ensure_dir_exists(cache_dir, mode))
+ if (recursive_mkdir_if_not_exists(cache_dir, mode))
{
gchar *cache_path;
gchar *pathl;
{
if (!tl->fd->exif_orientation)
{
- ExifData *exif = exif_read_fd(tl->fd);
- gint orientation;
-
- if (exif && exif_get_integer(exif, "Exif.Image.Orientation", &orientation))
- tl->fd->exif_orientation = orientation;
- else
- tl->fd->exif_orientation = EXIF_ORIENTATION_TOP_LEFT;
- exif_free_fd(tl->fd, exif);
+ tl->fd->exif_orientation = metadata_read_int(tl->fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
}
if (tl->fd->exif_orientation != EXIF_ORIENTATION_TOP_LEFT)
DEBUG_1("thumbnail size mismatch, regenerating: %s", tl->fd->path);
tl->cache_hit = FALSE;
- thumb_loader_setup(tl, tl->fd->path);
+ thumb_loader_setup(tl, tl->fd);
- g_signal_connect (G_OBJECT(tl->il), "done", (GCallback)thumb_loader_done_cb, tl);
+ g_signal_connect(G_OBJECT(tl->il), "done", (GCallback)thumb_loader_done_cb, tl);
if (!image_loader_start(tl->il))
{
if (tl->func_error) tl->func_error(tl, tl->data);
}
-static gint thumb_loader_done_delay_cb(gpointer data)
+static gboolean thumb_loader_done_delay_cb(gpointer data)
{
ThumbLoader *tl = data;
- tl->idle_done_id = -1;
+ tl->idle_done_id = 0;
if (tl->func_done) tl->func_done(tl, tl->data);
static void thumb_loader_delay_done(ThumbLoader *tl)
{
- if (tl->idle_done_id == -1) tl->idle_done_id = g_idle_add(thumb_loader_done_delay_cb, tl);
+ if (!tl->idle_done_id) tl->idle_done_id = g_idle_add(thumb_loader_done_delay_cb, tl);
}
-static void thumb_loader_setup(ThumbLoader *tl, const gchar *path)
+static void thumb_loader_setup(ThumbLoader *tl, FileData *fd)
{
- FileData *fd = file_data_new_simple(path);
image_loader_free(tl->il);
tl->il = image_loader_new(fd);
- file_data_unref(fd);
image_loader_set_priority(tl->il, G_PRIORITY_LOW);
- if (options->thumbnails.fast)
- {
- /* this will speed up jpegs by up to 3x in some cases */
- image_loader_set_requested_size(tl->il, tl->max_w, tl->max_h);
- }
+ /* this will speed up jpegs by up to 3x in some cases */
+ image_loader_set_requested_size(tl->il, tl->max_w, tl->max_h);
- g_signal_connect (G_OBJECT(tl->il), "error", (GCallback)thumb_loader_error_cb, tl);
- if (tl->func_progress) g_signal_connect (G_OBJECT(tl->il), "percent", (GCallback)thumb_loader_percent_cb, tl);
+ g_signal_connect(G_OBJECT(tl->il), "error", (GCallback)thumb_loader_error_cb, tl);
+ if (tl->func_progress) g_signal_connect(G_OBJECT(tl->il), "percent", (GCallback)thumb_loader_percent_cb, tl);
}
void thumb_loader_set_callbacks(ThumbLoader *tl,
tl->data = data;
}
-void thumb_loader_set_cache(ThumbLoader *tl, gint enable_cache, gint local, gint retry_failed)
+void thumb_loader_set_cache(ThumbLoader *tl, gboolean enable_cache, gboolean local, gboolean retry_failed)
{
if (!tl) return;
}
tl->cache_enable = enable_cache;
-#if 0
- tl->cache_local = local;
- tl->cache_retry = retry_failed;
-#endif
}
-gint thumb_loader_start(ThumbLoader *tl, FileData *fd)
+gboolean thumb_loader_start(ThumbLoader *tl, FileData *fd)
{
gchar *cache_path = NULL;
if (cache_path)
{
- thumb_loader_setup(tl, cache_path);
+ FileData *fd = file_data_new_no_grouping(cache_path);
+ thumb_loader_setup(tl, fd);
+ file_data_unref(fd);
g_free(cache_path);
tl->cache_hit = TRUE;
}
else
{
- thumb_loader_setup(tl, tl->fd->path);
+ thumb_loader_setup(tl, tl->fd);
}
- g_signal_connect (G_OBJECT(tl->il), "done", (GCallback)thumb_loader_done_cb, tl);
+ g_signal_connect(G_OBJECT(tl->il), "done", (GCallback)thumb_loader_done_cb, tl);
if (!image_loader_start(tl->il))
{
/* try from original if cache attempt */
tl->cache_hit = FALSE;
log_printf("%s", _("Thumbnail image in cache failed to load, trying to recreate.\n"));
- thumb_loader_setup(tl, tl->fd->path);
- g_signal_connect (G_OBJECT(tl->il), "done", (GCallback)thumb_loader_done_cb, tl);
+ thumb_loader_setup(tl, tl->fd);
+ g_signal_connect(G_OBJECT(tl->il), "done", (GCallback)thumb_loader_done_cb, tl);
if (image_loader_start(tl->il)) return TRUE;
}
/* mark failed thumbnail in cache with 0 byte file */
return TRUE;
}
-#if 0
-gint thumb_loader_to_pixmap(ThumbLoader *tl, GdkPixmap **pixmap, GdkBitmap **mask)
-{
- if (!tl || !tl->pixbuf) return -1;
-
- gdk_pixbuf_render_pixmap_and_mask(tl->pixbuf, pixmap, mask, 128);
-
- return thumb_loader_get_space(tl);
-}
-#endif
-
GdkPixbuf *thumb_loader_get_pixbuf(ThumbLoader *tl)
{
GdkPixbuf *pixbuf;
return pixbuf;
}
-#if 0
-gint thumb_loader_get_space(ThumbLoader *tl)
-{
- if (!tl) return 0;
-
- if (tl->pixbuf) return (tl->max_w - gdk_pixbuf_get_width(tl->pixbuf));
-
- return tl->max_w;
-}
-#endif
-
ThumbLoader *thumb_loader_new(gint width, gint height)
{
ThumbLoader *tl;
- if (options->thumbnails.spec_standard)
+ /* non-std thumb loader is more effective for configurations with disabled caching
+ because it loads the thumbnails at the required size. loader_std loads
+ the thumbnails at the sizes appropriate for standard cache (typically 256x256 pixels)
+ and then performs one additional scaling */
+ if (options->thumbnails.spec_standard && options->thumbnails.enable_caching)
{
return (ThumbLoader *)thumb_loader_std_new(width, height);
}
tl = g_new0(ThumbLoader, 1);
- tl->standard_loader = FALSE;
- tl->fd = NULL;
+
tl->cache_enable = options->thumbnails.enable_caching;
- tl->cache_hit = FALSE;
tl->percent_done = 0.0;
tl->max_w = width;
tl->max_h = height;
- tl->il = NULL;
-
- tl->idle_done_id = -1;
-
return tl;
}
image_loader_free(tl->il);
file_data_unref(tl->fd);
- if (tl->idle_done_id != -1) g_source_remove(tl->idle_done_id);
+ if (tl->idle_done_id) g_source_remove(tl->idle_done_id);
g_free(tl);
}
-#if 0
-gint thumb_from_xpm_d(const gchar **data, gint max_w, gint max_h, GdkPixmap **pixmap, GdkBitmap **mask)
-{
- GdkPixbuf *pixbuf;
- gint w, h;
-
- pixbuf = gdk_pixbuf_new_from_xpm_data(data);
- w = gdk_pixbuf_get_width(pixbuf);
- h = gdk_pixbuf_get_height(pixbuf);
-
- if (pixbuf_scale_aspect(w, h, max_w, max_h, &w, &h))
- {
- /* scale */
- GdkPixbuf *tmp;
-
- tmp = pixbuf;
- pixbuf = gdk_pixbuf_scale_simple(tmp, w, h, GDK_INTERP_NEAREST);
- gdk_pixbuf_unref(tmp);
- }
-
- gdk_pixbuf_render_pixmap_and_mask(pixbuf, pixmap, mask, 128);
- gdk_pixbuf_unref(pixbuf);
-
- return w;
-}
-#endif
-
-
/* release thumb_pixbuf on file change - this forces reload. */
void thumb_notify_cb(FileData *fd, NotifyType type, gpointer data)
{
- if (type != NOTIFY_TYPE_INTERNAL && fd->thumb_pixbuf)
+ if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE)) && fd->thumb_pixbuf)
{
+ DEBUG_1("Notify thumb: %s %04x", fd->path, type);
g_object_unref(fd->thumb_pixbuf);
fd->thumb_pixbuf = NULL;
}
{
FILE *file;
gchar buffer[XV_BUFFER];
- guchar *data;
- gint width, height, depth;
+ guchar *data = NULL;
file = fopen(filename, "rt");
if (!file) return NULL;
- fgets(buffer, XV_BUFFER, file);
- if (strncmp(buffer, "P7 332", 6) != 0)
+ if (fgets(buffer, XV_BUFFER, file) != NULL
+ && strncmp(buffer, "P7 332", 6) == 0)
{
- fclose(file);
- return NULL;
- }
+ gint width, height, depth;
- while (fgets(buffer, XV_BUFFER, file) && buffer[0] == '#') /* do_nothing() */;
+ while (fgets(buffer, XV_BUFFER, file) && buffer[0] == '#') /* do_nothing() */;
- if (sscanf(buffer, "%d %d %d", &width, &height, &depth) != 3)
- {
- fclose(file);
- return NULL;
+ if (sscanf(buffer, "%d %d %d", &width, &height, &depth) == 3)
+ {
+ gsize size = width * height;
+
+ data = g_new(guchar, size);
+ if (data && fread(data, 1, size, file) == size)
+ {
+ *widthp = width;
+ *heightp = height;
+ }
+ }
}
- data = g_new(guchar, width * height);
- fread(data, 1, width * height, file);
-
fclose(file);
- *widthp = width;
- *heightp = height;
return data;
}
#undef XV_BUFFER