/*
- * Geeqie
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
*
* Author: John Ellis
*
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
#include "main.h"
#include "image-load.h"
#include "image_load_gdk.h"
il->can_destroy = TRUE;
#ifdef HAVE_GTHREAD
+#if GLIB_CHECK_VERSION(2,32,0)
+ il->data_mutex = g_new(GMutex, 1);
+ g_mutex_init(il->data_mutex);
+ il->can_destroy_cond = g_new(GCond, 1);
+ g_cond_init(il->can_destroy_cond);
+#else
il->data_mutex = g_mutex_new();
il->can_destroy_cond = g_cond_new();
+#endif
#endif
DEBUG_1("new image loader %p, bufsize=%" G_GSIZE_FORMAT " idle_loop=%u", il, il->read_buffer_size, il->idle_read_loop_count);
}
{
DEBUG_2("pending signals detected");
}
-
+
while (il->area_param_list)
{
DEBUG_1("pending area_ready signals detected");
}
if (il->pixbuf) g_object_unref(il->pixbuf);
-
+
if (il->error) g_error_free(il->error);
file_data_unref(il->fd);
#ifdef HAVE_GTHREAD
+#if GLIB_CHECK_VERSION(2,32,0)
+ g_mutex_clear(il->data_mutex);
+ g_free(il->data_mutex);
+ g_cond_clear(il->can_destroy_cond);
+ g_free(il->can_destroy_cond);
+#else
g_mutex_free(il->data_mutex);
g_cond_free(il->can_destroy_cond);
#endif
+#endif
}
void image_loader_free(ImageLoader *il)
if (!fd) return NULL;
il = (ImageLoader *) g_object_new(TYPE_IMAGE_LOADER, NULL);
-
+
il->fd = file_data_ref(fd);
-
+
return il;
}
g_mutex_unlock(il->data_mutex);
g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, x, y, w, h);
-
+
return FALSE;
}
return NULL;
}
}
-
+
ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
par->il = il;
par->x = x;
par->y = y;
par->w = w;
par->h = h;
-
+
*list = g_list_prepend(*list, par);
return par;
}
static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
{
ImageLoaderAreaParam *par = image_loader_queue_area_ready(il, &il->area_param_list, x, y, w, h);
-
+
if (par)
{
g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
static void image_loader_sync_pixbuf(ImageLoader *il)
{
GdkPixbuf *pb;
-
+
g_mutex_lock(il->data_mutex);
-
+
if (!il->loader)
{
g_mutex_unlock(il->data_mutex);
image_loader_queue_delayed_area_ready(il, x, y, w, h);
else
image_loader_emit_area_ready(il, x, y, w, h);
-
+
if (il->stopping) il->backend.abort(il->loader);
g_mutex_unlock(il->data_mutex);
GdkPixbuf *pb;
guchar *pix;
size_t h, rs;
-
+
/* a workaround for
http://bugzilla.gnome.org/show_bug.cgi?id=547669
http://bugzilla.gnome.org/show_bug.cgi?id=589334
g_free(format);
return;
}
-
+
g_free(format);
pb = il->backend.get_pixbuf(loader);
-
+
h = gdk_pixbuf_get_height(pb);
rs = gdk_pixbuf_get_rowstride(pb);
pix = gdk_pixbuf_get_pixels(pb);
-
+
memset(pix, 0, rs * h); /*this should be faster than pixbuf_fill */
}
#ifdef HAVE_TIFF
if (il->bytes_total >= 10 &&
(memcmp(il->mapped_file, "MM\0*", 4) == 0 ||
+ memcmp(il->mapped_file, "MM\0+\0\x08\0\0", 8) == 0 ||
+ memcmp(il->mapped_file, "II+\0\x08\0\0\0", 8) == 0 ||
memcmp(il->mapped_file, "II*\0", 4) == 0))
{
DEBUG_1("Using custom tiff loader");
static gboolean image_loader_begin(ImageLoader *il)
{
gssize b;
-
+
if (il->pixbuf) return FALSE;
b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
if (b < 1) return FALSE;
image_loader_setup_loader(il);
-
+
g_assert(il->bytes_read == 0);
if (il->backend.load) {
b = il->bytes_total;
exif_free_fd(il->fd, exif);
}
-
+
if (!il->mapped_file)
{
/* normal file */
gint load_fd;
-
+
pathl = path_from_utf8(il->fd->path);
load_fd = open(pathl, O_RDONLY | O_NONBLOCK);
g_free(pathl);
close(load_fd);
return FALSE;
}
-
+
il->mapped_file = mmap(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0);
close(load_fd);
if (il->mapped_file == MAP_FAILED)
}
il->preview = FALSE;
}
-
+
return TRUE;
}
static void image_loader_stop_source(ImageLoader *il)
{
if (!il) return;
-
+
if (il->mapped_file)
{
if (il->preview)
g_source_remove(il->idle_id);
il->idle_id = 0;
}
-
+
if (il->thread)
{
/* stop loader in the other thread */
image_loader_stop_loader(il);
image_loader_stop_source(il);
-
+
}
void image_loader_delay_area_ready(ImageLoader *il, gboolean enable)
{
ImageLoaderAreaParam *par = work->data;
work = work->next;
-
+
g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h);
g_free(par);
}
{
ret = image_loader_continue(il);
}
-
+
if (!ret)
{
image_loader_stop_source(il);
}
-
+
return ret;
}
static gboolean image_loader_start_idle(ImageLoader *il)
{
gboolean ret;
-
+
if (!il) return FALSE;
if (!il->fd) return FALSE;
if (!image_loader_setup_source(il)) return FALSE;
-
+
ret = image_loader_begin(il);
if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
ImageLoader *il = data;
gboolean cont;
gboolean err;
-
+
if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
{
/* low prio, wait untill high prio tasks finishes */
/* high prio */
image_loader_thread_enter_high();
}
-
+
err = !image_loader_begin(il);
-
+
if (err)
{
/*
*/
image_loader_emit_error(il);
}
-
+
cont = !err;
-
+
while (cont && !image_loader_get_is_done(il) && !image_loader_get_stopping(il))
{
if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
if (!il->fd) return FALSE;
il->thread = TRUE;
-
+
if (!image_loader_setup_source(il)) return FALSE;
if (!image_loader_thread_pool)
{
image_loader_thread_pool = g_thread_pool_new(image_loader_thread_run, NULL, -1, FALSE, NULL);
+#if GLIB_CHECK_VERSION(2,32,0)
+ if (!image_loader_prio_cond) image_loader_prio_cond = g_new(GCond, 1);
+ g_cond_init(image_loader_prio_cond);
+ if (!image_loader_prio_mutex) image_loader_prio_mutex = g_new(GMutex, 1);
+ g_mutex_init(image_loader_prio_mutex);
+#else
image_loader_prio_cond = g_cond_new();
image_loader_prio_mutex = g_mutex_new();
+#endif
}
il->can_destroy = FALSE; /* ImageLoader can't be freed until image_loader_thread_run finishes */
g_thread_pool_push(image_loader_thread_pool, il, NULL);
DEBUG_1("Thread pool num threads: %d", g_thread_pool_get_num_threads(image_loader_thread_pool));
-
+
return TRUE;
}
#endif /* HAVE_GTHREAD */
{
GdkPixbuf *ret;
if (!il) return NULL;
-
+
g_mutex_lock(il->data_mutex);
ret = il->pixbuf;
g_mutex_unlock(il->data_mutex);
{
gdouble ret;
if (!il) return 0.0;
-
+
g_mutex_lock(il->data_mutex);
if (il->bytes_total == 0)
{