[f-spot] Create an ImageLoader factory.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: svn-commits-list gnome org
- Subject: [f-spot] Create an ImageLoader factory.
- Date: Wed, 8 Jul 2009 14:23:11 +0000 (UTC)
commit d82e3981f677fa442a9da4d36df79783aba8c0da
Author: Ruben Vermeersch <ruben savanne be>
Date: Wed Jul 8 15:14:23 2009 +0100
Create an ImageLoader factory.
src/Loaders/ImageLoader.cs | 73 ++++++++++++++++++++++++++++++++++++++++++++
src/Makefile.am | 1 +
src/PhotoImageView.cs | 2 +-
3 files changed, 75 insertions(+), 1 deletions(-)
---
diff --git a/src/Loaders/ImageLoader.cs b/src/Loaders/ImageLoader.cs
new file mode 100644
index 0000000..762e66c
--- /dev/null
+++ b/src/Loaders/ImageLoader.cs
@@ -0,0 +1,73 @@
+//
+// Fspot.Loaders.ImageLoader.cs
+//
+// Copyright (c) 2009 Novell, Inc.
+//
+// Author(s)
+// Stephane Delcroix <sdelcroix novell com>
+// Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details
+//
+
+using FSpot.Utils;
+using System;
+using System.Collections.Generic;
+using Gdk;
+
+namespace FSpot.Loaders {
+ public static class ImageLoader {
+ static Dictionary<string, System.Type> name_table;
+
+ static ImageLoader ()
+ {
+ name_table = new Dictionary<string, System.Type> ();
+ name_table [".svg"] = typeof (GdkImageLoader);
+ name_table [".gif"] = typeof (GdkImageLoader);
+ name_table [".bmp"] = typeof (GdkImageLoader);
+ name_table [".jpeg"] = typeof (GdkImageLoader);
+ name_table [".jpg"] = typeof (GdkImageLoader);
+ name_table [".png"] = typeof (GdkImageLoader);
+ name_table [".cr2"] = typeof (GdkImageLoader);
+ name_table [".nef"] = typeof (GdkImageLoader);
+ name_table [".pef"] = typeof (GdkImageLoader);
+ name_table [".raw"] = typeof (GdkImageLoader);
+ name_table [".kdc"] = typeof (GdkImageLoader);
+ name_table [".arw"] = typeof (GdkImageLoader);
+ name_table [".tiff"] = typeof (GdkImageLoader);
+ name_table [".tif"] = typeof (GdkImageLoader);
+ name_table [".orf"] = typeof (GdkImageLoader);
+ name_table [".srf"] = typeof (GdkImageLoader);
+ name_table [".dng"] = typeof (GdkImageLoader);
+ name_table [".crw"] = typeof (GdkImageLoader);
+ name_table [".ppm"] = typeof (GdkImageLoader);
+ name_table [".mrw"] = typeof (GdkImageLoader);
+ name_table [".raf"] = typeof (GdkImageLoader);
+ name_table [".x3f"] = typeof (GdkImageLoader);
+
+ //as xcf pixbufloader is not part of gdk-pixbuf, check if it's there,
+ //and enable it if needed.
+ foreach (Gdk.PixbufFormat format in Gdk.Pixbuf.Formats)
+ if (format.Name == "xcf") {
+ if (format.IsDisabled)
+ format.SetDisabled (false);
+ name_table [".xcf"] = typeof (GdkImageLoader);
+ }
+ }
+
+ public static IImageLoader Create (Uri uri)
+ {
+ string path = uri.AbsolutePath;
+ string extension = System.IO.Path.GetExtension (path).ToLower ();
+ System.Type t;
+ IImageLoader loader;
+
+ if (!name_table.TryGetValue (extension, out t))
+ throw new Exception ("Loader requested for unknown file type: "+extension);
+
+ loader = (IImageLoader) System.Activator.CreateInstance (t);
+
+ return loader;
+ }
+ }
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index fa72e3b..95bcab5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -176,6 +176,7 @@ F_SPOT_CSDISTFILES = \
$(srcdir)/Histogram.cs \
$(srcdir)/Loaders/AreaPreparedEventArgs.cs \
$(srcdir)/Loaders/AreaUpdatedEventArgs.cs \
+ $(srcdir)/Loaders/ImageLoader.cs \
$(srcdir)/Loaders/IImageLoader.cs \
$(srcdir)/Loaders/GdkImageLoader.cs \
$(srcdir)/ImageLoaderThread.cs \
diff --git a/src/PhotoImageView.cs b/src/PhotoImageView.cs
index 688e9ae..a2bd364 100644
--- a/src/PhotoImageView.cs
+++ b/src/PhotoImageView.cs
@@ -203,7 +203,7 @@ namespace FSpot.Widgets {
if (loader != null)
loader.Dispose ();
- loader = new GdkImageLoader ();
+ loader = ImageLoader.Create (uri);
loader.AreaPrepared += HandlePixbufPrepared;
loader.AreaUpdated += HandlePixbufAreaUpdated;
loader.Completed += HandleDone;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]