[f-spot] Split ImageFile into factory and abstract types.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot] Split ImageFile into factory and abstract types.
- Date: Thu, 8 Jul 2010 16:53:08 +0000 (UTC)
commit 012634b53803c6a09005a46cf2222e6e83cd2412
Author: Ruben Vermeersch <ruben savanne be>
Date: Fri Jul 2 22:10:44 2010 +0200
Split ImageFile into factory and abstract types.
.../Exporters/PicasaWebExport/PicasaWebExport.cs | 2 +-
src/Core/Photo.cs | 2 +-
src/Editors/Editor.cs | 2 +-
src/Filters/ResizeFilter.cs | 2 +-
src/Filters/SharpFilter.cs | 2 +-
src/Imaging/Ciff.cs | 2 +-
src/Imaging/DCRawFile.cs | 2 +-
src/Imaging/ImageFile.cs | 49 ++++++++++------
src/Imaging/IptcFile.cs | 10 +---
src/Imaging/MrwFile.cs | 2 +-
src/Imaging/PnmFile.cs | 2 +-
src/Imaging/RafFile.cs | 2 +-
src/Imaging/SvgFile.cs | 59 --------------------
src/Imaging/Tiff.cs | 2 +-
src/Loaders/GdkImageLoader.cs | 2 +-
src/Makefile.am | 1 -
src/PhotoLoader.cs | 4 +-
src/PixbufUtils.cs | 4 +-
src/PrintOperation.cs | 2 +-
src/UI.Dialog/EditTagIconDialog.cs | 2 +-
src/Widgets/ImageInfo.cs | 2 +-
src/Widgets/InfoBox.cs | 14 ++---
src/Widgets/MetadataDisplay.cs | 2 +-
src/Widgets/SlideShow.cs | 2 +-
24 files changed, 59 insertions(+), 116 deletions(-)
---
diff --git a/extensions/Exporters/PicasaWebExport/PicasaWebExport.cs b/extensions/Exporters/PicasaWebExport/PicasaWebExport.cs
index be0fdfb..a27a6b7 100644
--- a/extensions/Exporters/PicasaWebExport/PicasaWebExport.cs
+++ b/extensions/Exporters/PicasaWebExport/PicasaWebExport.cs
@@ -288,7 +288,7 @@ namespace FSpotGoogleExport {
if (show_captcha) {
try {
- using (ImageFile img = ImageFile.Create(new SafeUri(captcha_exception.CaptchaUrl, true))) {
+ using (var img = ImageFile.Create(new SafeUri(captcha_exception.CaptchaUrl, true))) {
captcha_image.Pixbuf = img.Load();
token = captcha_exception.Token;
}
diff --git a/src/Core/Photo.cs b/src/Core/Photo.cs
index 104615c..1de4979 100644
--- a/src/Core/Photo.cs
+++ b/src/Core/Photo.cs
@@ -218,7 +218,7 @@ namespace FSpot
public uint SaveVersion (Gdk.Pixbuf buffer, bool create_version)
{
uint version = DefaultVersionId;
- using (ImageFile img = ImageFile.Create (DefaultVersion.Uri)) {
+ using (var img = ImageFile.Create (DefaultVersion.Uri)) {
// Always create a version if the source is not a jpeg for now.
create_version = create_version || ImageFile.IsJpeg (DefaultVersion.Uri);
diff --git a/src/Editors/Editor.cs b/src/Editors/Editor.cs
index 6f4dc43..a84a5e9 100644
--- a/src/Editors/Editor.cs
+++ b/src/Editors/Editor.cs
@@ -99,7 +99,7 @@ namespace FSpot.Editors {
protected void LoadPhoto (Photo photo, out Pixbuf photo_pixbuf, out Cms.Profile photo_profile) {
// FIXME: We might get this value from the PhotoImageView.
- using (ImageFile img = ImageFile.Create (photo.DefaultVersion.Uri)) {
+ using (var img = ImageFile.Create (photo.DefaultVersion.Uri)) {
photo_pixbuf = img.Load ();
photo_profile = img.GetProfile ();
}
diff --git a/src/Filters/ResizeFilter.cs b/src/Filters/ResizeFilter.cs
index 050c977..6bb16b7 100644
--- a/src/Filters/ResizeFilter.cs
+++ b/src/Filters/ResizeFilter.cs
@@ -43,7 +43,7 @@ namespace FSpot.Filters {
string source = req.Current.LocalPath;
var dest_uri = req.TempUri (System.IO.Path.GetExtension (source));
- using (ImageFile img = ImageFile.Create (req.Current)) {
+ using (var img = ImageFile.Create (req.Current)) {
using (Pixbuf pixbuf = img.Load ()) {
if (pixbuf.Width < size && pixbuf.Height < size)
diff --git a/src/Filters/SharpFilter.cs b/src/Filters/SharpFilter.cs
index 1c0ecc3..e1093e0 100644
--- a/src/Filters/SharpFilter.cs
+++ b/src/Filters/SharpFilter.cs
@@ -33,7 +33,7 @@ namespace FSpot.Filters {
{
var dest_uri = req.TempUri (req.Current.GetExtension ());
- using (ImageFile img = ImageFile.Create (req.Current)) {
+ using (var img = ImageFile.Create (req.Current)) {
using (Pixbuf in_pixbuf = img.Load ()) {
using (Pixbuf out_pixbuf = PixbufUtils.UnsharpMask (in_pixbuf, radius, amount, threshold)) {
PixbufUtils.CreateDerivedVersion (req.Current, dest_uri, 95, out_pixbuf);
diff --git a/src/Imaging/Ciff.cs b/src/Imaging/Ciff.cs
index 3935c4f..30c626b 100644
--- a/src/Imaging/Ciff.cs
+++ b/src/Imaging/Ciff.cs
@@ -304,7 +304,7 @@ namespace FSpot.Imaging.Ciff {
}
}
- public class CiffFile : ImageFile , SemWeb.StatementSource {
+ public class CiffFile : BaseImageFile , SemWeb.StatementSource {
public ImageDirectory root;
bool little;
System.IO.Stream stream;
diff --git a/src/Imaging/DCRawFile.cs b/src/Imaging/DCRawFile.cs
index 6b6d4ff..fd8e5b9 100644
--- a/src/Imaging/DCRawFile.cs
+++ b/src/Imaging/DCRawFile.cs
@@ -72,7 +72,7 @@ namespace FSpot.Imaging {
}
}
- public class DCRawFile : ImageFile {
+ public class DCRawFile : BaseImageFile {
const string dcraw_command = "dcraw";
public DCRawFile (SafeUri uri) : base (uri)
diff --git a/src/Imaging/ImageFile.cs b/src/Imaging/ImageFile.cs
index 137f65d..fbecf60 100644
--- a/src/Imaging/ImageFile.cs
+++ b/src/Imaging/ImageFile.cs
@@ -20,7 +20,7 @@ namespace FSpot.Imaging {
}
}
- public class ImageFile : IDisposable {
+ public static class ImageFile {
#region Factory functionality
@@ -30,10 +30,10 @@ namespace FSpot.Imaging {
static ImageFile ()
{
name_table = new Hashtable ();
- name_table [".svg"] = typeof (FSpot.Imaging.Svg.SvgFile);
- name_table [".gif"] = typeof (ImageFile);
- name_table [".bmp"] = typeof (ImageFile);
- name_table [".pcx"] = typeof (ImageFile);
+ name_table [".svg"] = typeof (NoMetadataFile);
+ name_table [".gif"] = typeof (NoMetadataFile);
+ name_table [".bmp"] = typeof (NoMetadataFile);
+ name_table [".pcx"] = typeof (NoMetadataFile);
name_table [".jpeg"] = typeof (TagLibFile);
name_table [".jpg"] = typeof (TagLibFile);
name_table [".png"] = typeof (TagLibFile);
@@ -109,17 +109,13 @@ namespace FSpot.Imaging {
return t;
}
- public static ImageFile Create (SafeUri uri)
+ public static IImageFile Create (SafeUri uri)
{
- System.Type t = GetLoaderType (uri);
- ImageFile img;
+ var t = GetLoaderType (uri);
+ if (t == null)
+ throw new Exception (String.Format ("Unsupported image: {0}", uri));
- if (t != null)
- img = (ImageFile) System.Activator.CreateInstance (t, new object[] { uri });
- else
- img = new ImageFile (uri);
-
- return img;
+ return (IImageFile) System.Activator.CreateInstance (t, new object[] { uri });
}
public static bool IsRaw (SafeUri uri)
@@ -155,15 +151,26 @@ namespace FSpot.Imaging {
}
#endregion
+ }
+
+ public interface IImageFile : IDisposable {
+ Gdk.Pixbuf Load ();
+ Cms.Profile GetProfile ();
+ Gdk.Pixbuf Load (int max_width, int max_height);
+ Stream PixbufStream ();
+ ImageOrientation Orientation { get; }
+ }
+
+ public abstract class BaseImageFile : IImageFile {
protected SafeUri uri;
- public ImageFile (SafeUri uri)
+ public BaseImageFile (SafeUri uri)
{
this.uri = uri;
}
- ~ImageFile ()
+ ~BaseImageFile ()
{
Dispose ();
}
@@ -242,9 +249,15 @@ namespace FSpot.Imaging {
protected virtual void Close ()
{
}
- }
+ }
+
+ public class NoMetadataFile : BaseImageFile {
+ public NoMetadataFile (SafeUri uri) : base (uri)
+ {
+ }
+ }
- public class TagLibFile : ImageFile {
+ public class TagLibFile : BaseImageFile {
private TagLib.Image.File metadata_file;
public TagLibFile (SafeUri uri) : base (uri)
diff --git a/src/Imaging/IptcFile.cs b/src/Imaging/IptcFile.cs
index b53dd75..a265cd3 100644
--- a/src/Imaging/IptcFile.cs
+++ b/src/Imaging/IptcFile.cs
@@ -317,11 +317,7 @@ namespace FSpot.Imaging.Iptc {
public string XmpObject
{
get {
- //DataSetInfo info = (DataSetInfo) DataSetInfo.IDTable [this.ID];
- //if (info != null && info.Format == Format.String) {
- return System.Text.Encoding.UTF8.GetString (this.Data);
- //}
- //return null;
+ return System.Text.Encoding.UTF8.GetString (this.Data);
}
}
}
@@ -394,11 +390,7 @@ namespace FSpot.Imaging.Iptc {
try {
data.Load (stream);
} catch (System.Exception) {
- //System.Console.WriteLine (e.ToString ());
}
- //DataSetInfo info = DataSetInfo.FindInfo (data.ID);
- //System.Console.WriteLine ("{0}:{1} - {2} {3}", data.RecordNumber, data.DataSetNumber,
- // data.ID.ToString (), info.Description);
sets.Add (data);
}
}
diff --git a/src/Imaging/MrwFile.cs b/src/Imaging/MrwFile.cs
index d069ee3..71b47f8 100644
--- a/src/Imaging/MrwFile.cs
+++ b/src/Imaging/MrwFile.cs
@@ -169,7 +169,7 @@ namespace FSpot.Imaging.Mrw {
}
- public class MrwFile : ImageFile, SemWeb.StatementSource {
+ public class MrwFile : BaseImageFile, SemWeb.StatementSource {
MrmBlock mrm;
FSpot.Imaging.Tiff.Header header;
diff --git a/src/Imaging/PnmFile.cs b/src/Imaging/PnmFile.cs
index 231e7a0..a35f206 100644
--- a/src/Imaging/PnmFile.cs
+++ b/src/Imaging/PnmFile.cs
@@ -5,7 +5,7 @@ using System.IO;
using Hyena;
namespace FSpot.Imaging.Pnm {
- public class PnmFile : ImageFile, StatementSource {
+ public class PnmFile : BaseImageFile, StatementSource {
// false seems a safe default
public bool Distinct {
diff --git a/src/Imaging/RafFile.cs b/src/Imaging/RafFile.cs
index 262d1a6..55b5e2a 100644
--- a/src/Imaging/RafFile.cs
+++ b/src/Imaging/RafFile.cs
@@ -14,7 +14,7 @@ namespace FSpot.Imaging.Raf {
// ALL the sample files I have begin with "FUJIFILMCCD-RAW "
- public class RafFile : ImageFile, SemWeb.StatementSource {
+ public class RafFile : BaseImageFile, SemWeb.StatementSource {
// false seems a safe default
public bool Distinct {
diff --git a/src/Imaging/Tiff.cs b/src/Imaging/Tiff.cs
index cda5e80..74f63ae 100644
--- a/src/Imaging/Tiff.cs
+++ b/src/Imaging/Tiff.cs
@@ -1831,7 +1831,7 @@ namespace FSpot.Imaging.Tiff {
}
- public class TiffFile : ImageFile, SemWeb.StatementSource {
+ public class TiffFile : BaseImageFile, SemWeb.StatementSource {
public Header Header;
// false seems a safe default
diff --git a/src/Loaders/GdkImageLoader.cs b/src/Loaders/GdkImageLoader.cs
index 475a3b3..f904148 100644
--- a/src/Loaders/GdkImageLoader.cs
+++ b/src/Loaders/GdkImageLoader.cs
@@ -48,7 +48,7 @@ namespace FSpot.Loaders {
upd (this, new AreaUpdatedEventArgs (new Rectangle (0, 0, thumb.Width, thumb.Height)));
}
- using (ImageFile image_file = ImageFile.Create (uri)) {
+ using (var image_file = ImageFile.Create (uri)) {
image_stream = image_file.PixbufStream ();
pixbuf_orientation = image_file.Orientation;
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 0d31418..b3b7b3f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -95,7 +95,6 @@ SOURCES = \
Imaging/PixelBuffer.cs \
Imaging/PnmFile.cs \
Imaging/RafFile.cs \
- Imaging/SvgFile.cs \
Imaging/X3fFile.cs \
Imaging/XmpFile.cs \
Imaging/Tiff.cs \
diff --git a/src/PhotoLoader.cs b/src/PhotoLoader.cs
index 38b9cad..7a51e9d 100644
--- a/src/PhotoLoader.cs
+++ b/src/PhotoLoader.cs
@@ -21,7 +21,7 @@ namespace FSpot {
static public Gdk.Pixbuf Load (IBrowsableItem item)
{
- using (ImageFile img = ImageFile.Create (item.DefaultVersion.Uri)) {
+ using (var img = ImageFile.Create (item.DefaultVersion.Uri)) {
Gdk.Pixbuf pixbuf = img.Load ();
return pixbuf;
}
@@ -29,7 +29,7 @@ namespace FSpot {
static public Gdk.Pixbuf LoadAtMaxSize (IBrowsableItem item, int width, int height)
{
- using (ImageFile img = ImageFile.Create (item.DefaultVersion.Uri)) {
+ using (var img = ImageFile.Create (item.DefaultVersion.Uri)) {
Gdk.Pixbuf pixbuf = img.Load (width, height);
return pixbuf;
}
diff --git a/src/PixbufUtils.cs b/src/PixbufUtils.cs
index d056758..7814450 100644
--- a/src/PixbufUtils.cs
+++ b/src/PixbufUtils.cs
@@ -429,7 +429,7 @@ public static class PixbufUtils {
public static ImageOrientation GetOrientation (SafeUri uri)
{
- using (ImageFile img = ImageFile.Create (uri)) {
+ using (var img = ImageFile.Create (uri)) {
return img.Orientation;
}
}
@@ -470,7 +470,7 @@ public static class PixbufUtils {
}
// Else make a derived copy with metadata copied
- using (ImageFile img = ImageFile.Create (source)) {
+ using (var img = ImageFile.Create (source)) {
using (var pixbuf = img.Load ()) {
CreateDerivedVersion (source, destination, jpeg_quality, pixbuf);
}
diff --git a/src/PrintOperation.cs b/src/PrintOperation.cs
index 7c3045b..0f8a2d0 100644
--- a/src/PrintOperation.cs
+++ b/src/PrintOperation.cs
@@ -111,7 +111,7 @@ namespace FSpot
DrawCropMarks (cr, x*w, y*h, w*.1);
if (x == ppx || y == ppy || p_index >= selected_photos.Length)
continue;
- using (ImageFile img = new ImageFile (selected_photos[p_index].DefaultVersion.Uri))
+ using (var img = ImageFile.Create (selected_photos[p_index].DefaultVersion.Uri))
{
Gdk.Pixbuf pixbuf;
try {
diff --git a/src/UI.Dialog/EditTagIconDialog.cs b/src/UI.Dialog/EditTagIconDialog.cs
index e58d206..059d60d 100644
--- a/src/UI.Dialog/EditTagIconDialog.cs
+++ b/src/UI.Dialog/EditTagIconDialog.cs
@@ -157,7 +157,7 @@ namespace FSpot.UI.Dialog
void CreateTagIconFromExternalPhoto ()
{
try {
- using (ImageFile img = ImageFile.Create (new SafeUri(external_photo_chooser.Uri, true))) {
+ using (var img = ImageFile.Create (new SafeUri(external_photo_chooser.Uri, true))) {
using (Gdk.Pixbuf external_image = img.Load ()) {
PreviewPixbuf = PixbufUtils.TagIconFromPixbuf (external_image);
}
diff --git a/src/Widgets/ImageInfo.cs b/src/Widgets/ImageInfo.cs
index 12a7a81..1944c22 100644
--- a/src/Widgets/ImageInfo.cs
+++ b/src/Widgets/ImageInfo.cs
@@ -21,7 +21,7 @@ namespace FSpot.Widgets {
public ImageInfo (SafeUri uri)
{
- using (ImageFile img = ImageFile.Create (uri)) {
+ using (var img = ImageFile.Create (uri)) {
Pixbuf pixbuf = img.Load ();
SetPixbuf (pixbuf);
pixbuf.Dispose ();
diff --git a/src/Widgets/InfoBox.cs b/src/Widgets/InfoBox.cs
index a01bc23..833cfd0 100644
--- a/src/Widgets/InfoBox.cs
+++ b/src/Widgets/InfoBox.cs
@@ -306,7 +306,7 @@ namespace FSpot.Widgets
MemoryStore store;
- public ImageInfo (ImageFile img)
+ public ImageInfo (IImageFile img)
{
// FIXME We use the memory store to hold the anonymous statements
// as they are added so that we can query for them later to
@@ -471,12 +471,10 @@ namespace FSpot.Widgets
name_value_label.Visible = show_name;
try {
- //using (new Timer ("building info")) {
- using (ImageFile img = ImageFile.Create (photo.DefaultVersion.Uri))
- {
- info = new ImageInfo (img);
- }
- //}
+ using (var img = ImageFile.Create (photo.DefaultVersion.Uri))
+ {
+ info = new ImageInfo (img);
+ }
} catch (System.Exception e) {
Hyena.Log.Debug (e.StackTrace);
info = new ImageInfo (null);
@@ -681,7 +679,7 @@ namespace FSpot.Widgets
try {
if (hint == null)
- using (ImageFile img = ImageFile.Create (photo.DefaultVersion.Uri))
+ using (var img = ImageFile.Create (photo.DefaultVersion.Uri))
hint = img.Load (256, 256);
histogram_image.Pixbuf = histogram.Generate (hint, max);
diff --git a/src/Widgets/MetadataDisplay.cs b/src/Widgets/MetadataDisplay.cs
index c23b3e9..7c877ca 100644
--- a/src/Widgets/MetadataDisplay.cs
+++ b/src/Widgets/MetadataDisplay.cs
@@ -331,7 +331,7 @@ namespace FSpot.Widgets {
if (photo != null) {
MetadataStore store = new MetadataStore ();
try {
- using (ImageFile img = ImageFile.Create (photo.DefaultVersion.Uri)) {
+ using (var img = ImageFile.Create (photo.DefaultVersion.Uri)) {
if (img is SemWeb.StatementSource) {
StatementSource source = (StatementSource)img;
source.Select (store);
diff --git a/src/Widgets/SlideShow.cs b/src/Widgets/SlideShow.cs
index 851053d..1290a21 100644
--- a/src/Widgets/SlideShow.cs
+++ b/src/Widgets/SlideShow.cs
@@ -114,7 +114,7 @@ namespace FSpot.Widgets
if (item == null || item.Current == null)
return;
- using (ImageFile img = ImageFile.Create (item.Current.DefaultVersion.Uri)) {
+ using (var img = ImageFile.Create (item.Current.DefaultVersion.Uri)) {
try {
using (var pb = img.Load ()) {
double scale = Math.Min ((double)Allocation.Width/(double)pb.Width, (double)Allocation.Height/(double)pb.Height);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]