[f-spot/rubenv-gsoc-2009: 22/86] Detect RAW files using a marker interface: IRawFile.



commit b6e1a50c95faa759392cd2370bd8f7b5cf66cbef
Author: Ruben Vermeersch <ruben savanne be>
Date:   Mon Jul 27 17:22:29 2009 +0200

    Detect RAW files using a marker interface: IRawFile.

 extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs |    3 +-
 extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs       |    7 ++--
 src/Imaging/Ciff.cs                               |    3 +-
 src/Imaging/IRawFile.cs                           |   16 ++++++++
 src/Imaging/ImageFile.cs                          |   39 ++++++++-------------
 src/Imaging/MrwFile.cs                            |    3 +-
 src/Imaging/RafFile.cs                            |    3 +-
 src/Imaging/Tiff.cs                               |    7 ++--
 src/Makefile.am                                   |    1 +
 9 files changed, 48 insertions(+), 34 deletions(-)
---
diff --git a/extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs b/extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs
index a8c2bcf..98a5a39 100644
--- a/extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs
+++ b/extensions/Tools/DevelopInUFraw/DevelopInUFRaw.cs
@@ -14,6 +14,7 @@ using Mono.Unix;
 
 using FSpot;
 using FSpot.Utils;
+using FSpot.Imaging;
 using FSpot.Extensions;
 using FSpot.UI.Dialog;
 
@@ -91,7 +92,7 @@ namespace DevelopInUFRawExtension
 			LoadPreference (UFRAW_BATCH_ARGUMENTS_KEY);
 
 			PhotoVersion raw = p.GetVersion (Photo.OriginalVersionId) as PhotoVersion;
-			if (!ImageFile.IsRaw (raw.Uri.AbsolutePath)) {
+			if (!ImageFile.IsRaw (raw.Uri)) {
 				Log.Warning ("The original version of this image is not a (supported) RAW file");
 				return;
 			}
diff --git a/extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs b/extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs
index 4077fb1..7673e00 100644
--- a/extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs
+++ b/extensions/Tools/RawPlusJpeg/RawPlusJpeg.cs
@@ -44,12 +44,13 @@ namespace RawPlusJpegExtension
 			for (int i = 0; i < photos.Length; i++) {
 				Photo p = photos [i];
 
-				if (!ImageFile.IsRaw (p.Name) && !ImageFile.IsJpeg (p.Name))
+				ImageFile img = ImageFile.Create (p.DefaultVersionUri);
+				if (!ImageFile.IsRaw (img) && !ImageFile.IsJpeg (img))
 					continue;
 
-				if (ImageFile.IsJpeg (p.Name))
+				if (ImageFile.IsJpeg (img))
 					jpeg = p;
-				if (ImageFile.IsRaw (p.Name))
+				if (ImageFile.IsRaw (img))
 					raw = p;
 
 				if (raw != null && jpeg != null && SamePlaceAndName (raw, jpeg))
diff --git a/src/Imaging/Ciff.cs b/src/Imaging/Ciff.cs
index 34c6071..f1b6f68 100644
--- a/src/Imaging/Ciff.cs
+++ b/src/Imaging/Ciff.cs
@@ -1,5 +1,6 @@
 using System;
 using FSpot.Utils;
+using FSpot.Imaging;
 
 namespace FSpot.Ciff {
 	public enum Tag {
@@ -312,7 +313,7 @@ namespace FSpot.Ciff {
 		}
 	}
 	
-	public class CiffFile : FSpot.ImageFile , SemWeb.StatementSource {
+	public class CiffFile : FSpot.ImageFile , SemWeb.StatementSource, IRawFile {
 		public ImageDirectory root;
 		private uint version;
 		bool little;
diff --git a/src/Imaging/IRawFile.cs b/src/Imaging/IRawFile.cs
new file mode 100644
index 0000000..4883cdd
--- /dev/null
+++ b/src/Imaging/IRawFile.cs
@@ -0,0 +1,16 @@
+//
+// Fspot.Imaging.IRawFile.cs
+//
+// Copyright (c) 2009 Novell, Inc.
+//
+// Author(s)
+//	Ruben Vermeersch  <ruben savanne be>
+//
+// This is free software. See COPYING for details
+//
+
+namespace FSpot.Imaging {
+	public interface IRawFile {
+
+	}
+}
diff --git a/src/Imaging/ImageFile.cs b/src/Imaging/ImageFile.cs
index c974c9f..cd34063 100644
--- a/src/Imaging/ImageFile.cs
+++ b/src/Imaging/ImageFile.cs
@@ -3,6 +3,7 @@ using System.IO;
 using System.Collections;
 
 using FSpot.Utils;
+using FSpot.Imaging;
 using Mono.Unix;
 using Mono.Unix.Native;
 using Gdk;
@@ -265,34 +266,24 @@ namespace FSpot {
 		{
 		}
 
-		public static bool IsRaw (string name)
+		public static bool IsJpeg (ImageFile image)
 		{
-			string [] raw_extensions = {
-				".arw",
-				".crw",
-				".cr2",
-				".dng",
-				".mrw",
-				".nef",
-				".orf", 
-				".pef", 
-				".raw",
-				".raf",
-				".rw2",
-			};
-			foreach (string ext in raw_extensions)
-				if (ext == System.IO.Path.GetExtension (name).ToLower ())
-					return true;
-			return false;
+			return image is JpegFile;
 		}
 
-		public static bool IsJpeg (string name)
+		public static bool IsJpeg (Uri uri)
 		{
-			string [] jpg_extensions = {".jpg", ".jpeg"};
-			foreach (string ext in jpg_extensions)
-				if (ext == System.IO.Path.GetExtension (name).ToLower ())
-					return true;
-			return false;
+			return IsJpeg (ImageFile.Create (uri));
+		}
+
+		public static bool IsRaw (ImageFile image)
+		{
+			return image is IRawFile;
+		}
+
+		public static bool IsRaw (Uri uri)
+		{
+			return IsRaw (ImageFile.Create (uri));
 		}
 	} 
 }
diff --git a/src/Imaging/MrwFile.cs b/src/Imaging/MrwFile.cs
index b4693df..7bd3c6b 100644
--- a/src/Imaging/MrwFile.cs
+++ b/src/Imaging/MrwFile.cs
@@ -1,4 +1,5 @@
 using FSpot.Tiff;
+using FSpot.Imaging;
 
 namespace FSpot.Mrw {
 	// Minolta raw format
@@ -169,7 +170,7 @@ namespace FSpot.Mrw {
 		
 	}
 	
-	public class MrwFile : ImageFile, SemWeb.StatementSource {
+	public class MrwFile : ImageFile, SemWeb.StatementSource, IRawFile {
 		MrmBlock mrm;
 		FSpot.Tiff.Header header;
 
diff --git a/src/Imaging/RafFile.cs b/src/Imaging/RafFile.cs
index 5bcb3dd..29f333b 100644
--- a/src/Imaging/RafFile.cs
+++ b/src/Imaging/RafFile.cs
@@ -1,4 +1,5 @@
 using FSpot.Utils;
+using FSpot.Imaging;
 
 namespace FSpot.Raf {
 	// This is reverse engineered from looking at the sample files I have
@@ -21,7 +22,7 @@ namespace FSpot.Raf {
 		}
 	}
 	
-	public class RafFile : ImageFile, SemWeb.StatementSource {
+	public class RafFile : ImageFile, SemWeb.StatementSource, IRawFile {
 
                 // false seems a safe default
                 public bool Distinct {
diff --git a/src/Imaging/Tiff.cs b/src/Imaging/Tiff.cs
index 083e13e..fed6d56 100644
--- a/src/Imaging/Tiff.cs
+++ b/src/Imaging/Tiff.cs
@@ -1,6 +1,7 @@
 //#define DEBUG_LOADER
 using FSpot;
 using FSpot.Utils;
+using FSpot.Imaging;
 using SemWeb;
 using System;
 using System.IO;
@@ -2129,7 +2130,7 @@ namespace FSpot.Tiff {
 		}
 	}
 
-	public class DngFile : TiffFile {
+	public class DngFile : TiffFile, IRawFile {
 		public DngFile (string path) : base (path) 
 		{
 		}
@@ -2213,7 +2214,7 @@ namespace FSpot.Tiff {
 		}
 	}	
 	
-	public class NefFile : TiffFile, IThumbnailContainer {
+	public class NefFile : TiffFile, IThumbnailContainer, IRawFile {
 		public NefFile (string path) : base (path) 
 		{
 		}
@@ -2277,7 +2278,7 @@ namespace FSpot.Tiff {
 	}
 		
 
-	public class Cr2File : TiffFile, IThumbnailContainer {
+	public class Cr2File : TiffFile, IThumbnailContainer, IRawFile {
 		public Cr2File (string path) : base (path) 
 		{
 		}
diff --git a/src/Makefile.am b/src/Makefile.am
index 4469b99..f0f26fc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -205,6 +205,7 @@ F_SPOT_CSDISTFILES =				\
 	$(srcdir)/Imaging/Exif.cs		\
 	$(srcdir)/Imaging/ImageFile.cs		\
 	$(srcdir)/Imaging/IptcFile.cs		\
+	$(srcdir)/Imaging/IRawFile.cs		\
 	$(srcdir)/Imaging/JpegFile.cs		\
 	$(srcdir)/Imaging/JpegHeader.cs		\
 	$(srcdir)/Imaging/JpegUtils.cs		\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]