[f-spot/rubenv-gsoc-2009: 15/86] Abort RAW loading when no longer needed.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/rubenv-gsoc-2009: 15/86] Abort RAW loading when no longer needed.
- Date: Sun, 23 May 2010 12:33:12 +0000 (UTC)
commit f227222730fb552e98c63513740c6d52a2286015
Author: Ruben Vermeersch <ruben savanne be>
Date: Mon Jul 20 12:57:30 2009 +0200
Abort RAW loading when no longer needed.
lib/libfspotraw/fspot-librawloader.cpp | 43 ++++++++++++++++++++++++++++---
lib/libfspotraw/fspot-librawloader.h | 2 +
src/Loaders/LibrawImageLoader.cs | 15 +++++++++--
3 files changed, 52 insertions(+), 8 deletions(-)
---
diff --git a/lib/libfspotraw/fspot-librawloader.cpp b/lib/libfspotraw/fspot-librawloader.cpp
index 3139dcd..01f8acd 100644
--- a/lib/libfspotraw/fspot-librawloader.cpp
+++ b/lib/libfspotraw/fspot-librawloader.cpp
@@ -22,7 +22,8 @@ enum {
enum {
PROP_0,
PROP_FILENAME,
- PROP_PROGRESS
+ PROP_PROGRESS,
+ PROP_ABORTED
};
static guint signals[LAST_SIGNAL] = { 0 };
@@ -50,9 +51,9 @@ struct _FSpotLibrawLoaderPriv
{
LibRaw *raw_proc;
gchar *filename;
- double progress;
gboolean opened;
+ gboolean aborted;
};
static void
@@ -97,6 +98,15 @@ fspot_librawloader_class_init (FSpotLibrawLoaderClass *klass)
PROP_PROGRESS,
pspec);
+ pspec = g_param_spec_boolean ("aborted",
+ "Whether the loading has been aborted.",
+ "When switched to true, loading is stopped.",
+ FALSE,
+ (GParamFlags) G_PARAM_READWRITE);
+ g_object_class_install_property (gobject_class,
+ PROP_ABORTED,
+ pspec);
+
g_type_class_add_private (klass, sizeof (FSpotLibrawLoaderPriv));
}
@@ -107,7 +117,7 @@ fspot_librawloader_init (FSpotLibrawLoader *self)
self->priv->raw_proc = new LibRaw;
self->priv->opened = false;
- self->priv->progress = 0;
+ self->priv->aborted = false;
self->priv->raw_proc->set_progress_handler (libraw_progress_callback, self);
}
@@ -127,6 +137,10 @@ fspot_librawloader_set_property (GObject *object,
self->priv->filename = g_value_dup_string (value);
break;
+ case PROP_ABORTED:
+ fspot_librawloader_set_aborted (self, g_value_get_boolean (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -147,6 +161,9 @@ fspot_librawloader_get_property (GObject *object,
g_value_set_string (value, self->priv->filename);
break;
+ case PROP_ABORTED:
+ g_value_set_boolean (value, self->priv->aborted);
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -212,7 +229,9 @@ fspot_librawloader_load_full (FSpotLibrawLoader *self)
self->priv->raw_proc->unpack ();
self->priv->raw_proc->dcraw_process ();
image = self->priv->raw_proc->dcraw_make_mem_image (&result);
- g_assert (result == 0 && image != NULL);
+ if (result != 0 || image == NULL) {
+ return NULL;
+ }
g_assert (image->type == LIBRAW_IMAGE_BITMAP);
pixbuf = gdk_pixbuf_new_from_data (image->data,
@@ -256,5 +275,19 @@ libraw_progress_callback (void *user_data, enum LibRaw_progress p, int iteration
{
FSpotLibrawLoader *self = FSPOT_LIBRAWLOADER (user_data);
g_signal_emit (self, signals[PROGRESS_UPDATED], 0, iteration, expected);
- return 0;
+ return self->priv->aborted;
+}
+
+gboolean
+fspot_librawloader_get_aborted (FSpotLibrawLoader *self)
+{
+ g_return_val_if_fail (FSPOT_IS_LIBRAWLOADER (self), false);
+ return self->priv->aborted;
+}
+
+void
+fspot_librawloader_set_aborted (FSpotLibrawLoader *self, gboolean aborted)
+{
+ g_return_if_fail (FSPOT_IS_LIBRAWLOADER (self));
+ self->priv->aborted = aborted;
}
diff --git a/lib/libfspotraw/fspot-librawloader.h b/lib/libfspotraw/fspot-librawloader.h
index 27bb548..e978a81 100644
--- a/lib/libfspotraw/fspot-librawloader.h
+++ b/lib/libfspotraw/fspot-librawloader.h
@@ -45,6 +45,8 @@ GType fspot_librawloader_get_type (void);
GdkPixbuf * fspot_librawloader_load_thumbnail (FSpotLibrawLoader *self);
GdkPixbuf * fspot_librawloader_load_full (FSpotLibrawLoader *self);
FSpotLibrawLoader * fspot_librawloader_new (const gchar *filename);
+gboolean fspot_librawloader_get_aborted (FSpotLibrawLoader *self);
+void fspot_librawloader_set_aborted (FSpotLibrawLoader *self, gboolean aborted);
G_END_DECLS
diff --git a/src/Loaders/LibrawImageLoader.cs b/src/Loaders/LibrawImageLoader.cs
index 68744fe..b900958 100644
--- a/src/Loaders/LibrawImageLoader.cs
+++ b/src/Loaders/LibrawImageLoader.cs
@@ -59,6 +59,10 @@ namespace FSpot.Loaders {
Log.Debug ("Loading RAW: {0}/{1}", args.Done, args.Total);
};
full = loader.LoadFull ();
+ if (full == null) {
+ return;
+ }
+
PixbufOrientation = PixbufOrientation.TopLeft;
GLib.Idle.Add (delegate {
EventHandler<AreaPreparedEventArgs> prep = AreaPrepared;
@@ -84,9 +88,14 @@ namespace FSpot.Loaders {
public void Dispose ()
{
- // TODO: Abort the NativeLibrawLoader
- thumb.Dispose ();
- full.Dispose ();
+ if (loader != null) {
+ loader.Aborted = true;
+ loader = null;
+ }
+ if (thumb != null)
+ thumb.Dispose ();
+ if (full != null)
+ full.Dispose ();
}
public Pixbuf Pixbuf {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]