[f-spot] Do all orientation parsing using TagLib#.



commit bde6b719b74318356856ad4689c9e6022b509717
Author: Ruben Vermeersch <ruben savanne be>
Date:   Fri Jul 2 23:31:53 2010 +0200

    Do all orientation parsing using TagLib#.
    
    Plenty of files will break. We'll fix them.

 src/Imaging/Ciff.cs      |   14 ------------
 src/Imaging/ImageFile.cs |   51 ++++++++++++---------------------------------
 src/Imaging/RafFile.cs   |   17 +--------------
 src/Imaging/Tiff.cs      |    9 --------
 src/Imaging/X3fFile.cs   |    6 -----
 5 files changed, 15 insertions(+), 82 deletions(-)
---
diff --git a/src/Imaging/Ciff.cs b/src/Imaging/Ciff.cs
index 30c626b..c793132 100644
--- a/src/Imaging/Ciff.cs
+++ b/src/Imaging/Ciff.cs
@@ -391,20 +391,6 @@ namespace FSpot.Imaging.Ciff {
 			return new ImageDirectory (stream, start, end, little);
 		}
 
-		public override ImageOrientation GetOrientation ()
-		{
-			var orientation = ImageOrientation.TopLeft;
-			ImageDirectory props = Root.ReadDirectory (Tag.ImageProps);
-		       	byte [] data = props.ReadEntry (Tag.ImageSpec);
-			
-			if (data != null)
-				orientation = new ImageSpec (data, little).Orientation;
-			else 
-				Log.Debug ("NO ORIENTATION");
-
-			return orientation;
-		}
-
 		public override System.IO.Stream PixbufStream ()
 		{
 			byte [] data = GetEmbeddedJpeg ();
diff --git a/src/Imaging/ImageFile.cs b/src/Imaging/ImageFile.cs
index d8793ed..2739aa7 100644
--- a/src/Imaging/ImageFile.cs
+++ b/src/Imaging/ImageFile.cs
@@ -30,13 +30,13 @@ namespace FSpot.Imaging {
 		static ImageFile ()
 		{
 			name_table = new Hashtable ();
-			name_table [".svg"] = typeof (TagLibFile);
-			name_table [".gif"] = typeof (TagLibFile);
-			name_table [".bmp"] = typeof (TagLibFile);
-			name_table [".pcx"] = typeof (TagLibFile);
-			name_table [".jpeg"] = typeof (TagLibFile);
-			name_table [".jpg"] = typeof (TagLibFile);
-			name_table [".png"] = typeof (TagLibFile);
+			name_table [".svg"] = typeof (BaseImageFile);
+			name_table [".gif"] = typeof (BaseImageFile);
+			name_table [".bmp"] = typeof (BaseImageFile);
+			name_table [".pcx"] = typeof (BaseImageFile);
+			name_table [".jpeg"] = typeof (BaseImageFile);
+			name_table [".jpg"] = typeof (BaseImageFile);
+			name_table [".png"] = typeof (BaseImageFile);
 			name_table [".cr2"] = typeof (FSpot.Imaging.Tiff.Cr2File);
 			name_table [".nef"] = typeof (FSpot.Imaging.Tiff.NefFile);
 			name_table [".pef"] = typeof (FSpot.Imaging.Tiff.NefFile);
@@ -161,13 +161,18 @@ namespace FSpot.Imaging {
 		ImageOrientation Orientation { get; }
     }
 
-    public abstract class BaseImageFile : IImageFile {
+    public class BaseImageFile : IImageFile {
+        ImageOrientation orientation = ImageOrientation.TopLeft;
 
 		protected SafeUri uri;
 
 		public BaseImageFile (SafeUri uri)
 		{
 			this.uri = uri;
+
+            using (var metadata_file = Metadata.Parse (uri)) {
+                orientation = metadata_file.ImageTag.Orientation;
+            }
 		}
 
 		~BaseImageFile ()
@@ -190,7 +195,7 @@ namespace FSpot.Imaging {
 		}
 
 		public ImageOrientation Orientation {
-			get { return GetOrientation (); }
+			get { return orientation; }
 		}
 
 		protected Gdk.Pixbuf TransformAndDispose (Gdk.Pixbuf orig)
@@ -229,11 +234,6 @@ namespace FSpot.Imaging {
 			}
 		}
 
-		public virtual ImageOrientation GetOrientation ()
-		{
-			return ImageOrientation.TopLeft;
-		}
-
 		// FIXME this need to have an intent just like the loading stuff.
 		public virtual Cms.Profile GetProfile ()
 		{
@@ -250,27 +250,4 @@ namespace FSpot.Imaging {
 		{
 		}
     }
-
-    public class TagLibFile : BaseImageFile {
-        private TagLib.Image.File metadata_file;
-
-        public TagLibFile (SafeUri uri) : base (uri)
-        {
-            metadata_file = Metadata.Parse (uri);
-        }
-
-        ~TagLibFile () {
-            metadata_file.Dispose ();
-        }
-
-        public override Cms.Profile GetProfile ()
-        {
-            return null;
-        }
-
-        public override ImageOrientation GetOrientation ()
-        {
-            return metadata_file.ImageTag.Orientation;
-        }
-    }
 }
diff --git a/src/Imaging/RafFile.cs b/src/Imaging/RafFile.cs
index 55b5e2a..837618e 100644
--- a/src/Imaging/RafFile.cs
+++ b/src/Imaging/RafFile.cs
@@ -34,21 +34,6 @@ namespace FSpot.Imaging.Raf {
 				return exif_data;
 			}
 		}
-		
-		public override ImageOrientation GetOrientation (){
-			var orientation = ImageOrientation.TopLeft;
-
-			Exif.ExifEntry e = this.ExifData.GetContents (Exif.Ifd.Zero).Lookup (Exif.Tag.Orientation);
-			if (e != null) {
-				ushort [] value = e.GetDataUShort ();
-				orientation = (ImageOrientation) value [0];
-			}
-
-			if (orientation < ImageOrientation.TopLeft || orientation > ImageOrientation.LeftBottom)
-				orientation = ImageOrientation.TopLeft;
-
-			return orientation;
-		}
 
 		public override System.IO.Stream PixbufStream ()
 		{
@@ -68,7 +53,7 @@ namespace FSpot.Imaging.Raf {
 		public override Gdk.Pixbuf Load (int width, int height)
 		{
 			Gdk.Pixbuf full = this.Load ();
-			Gdk.Pixbuf rotated = FSpot.Utils.PixbufUtils.TransformOrientation (full, this.GetOrientation());
+			Gdk.Pixbuf rotated = FSpot.Utils.PixbufUtils.TransformOrientation (full, Orientation);
 			Gdk.Pixbuf scaled  = PixbufUtils.ScaleToMaxSize (rotated, width, height);
 			full.Dispose ();
 			return scaled;
diff --git a/src/Imaging/Tiff.cs b/src/Imaging/Tiff.cs
index 74f63ae..bd6ab18 100644
--- a/src/Imaging/Tiff.cs
+++ b/src/Imaging/Tiff.cs
@@ -1855,15 +1855,6 @@ namespace FSpot.Imaging.Tiff {
 			Header.SelectDirectory (Header.Directory, sink);
 		}
 
-		public override ImageOrientation GetOrientation ()
-		{
-			ShortEntry e = (ShortEntry)(this.Header.Directory.Lookup (TagId.Orientation));
-			if (e != null) 
-				return (ImageOrientation)(e.ShortValue[0]);
-			else
-				return ImageOrientation.TopLeft;
-		}
-
 		public System.IO.Stream LookupJpegSubstream (ImageDirectory directory)
 		{
 			uint offset = directory.Lookup (TagId.JPEGInterchangeFormat).ValueAsLong [0];
diff --git a/src/Imaging/X3fFile.cs b/src/Imaging/X3fFile.cs
index 06b0fbb..641657d 100644
--- a/src/Imaging/X3fFile.cs
+++ b/src/Imaging/X3fFile.cs
@@ -101,11 +101,5 @@ namespace FSpot.Imaging.X3f {
 			MetadataStore.AddLiteral (sink, "tiff:ImageWidth", Info.Width.ToString ());
 			MetadataStore.AddLiteral (sink, "tiff:ImageLength", Info.Height.ToString ());
 		}
-
-		public override ImageOrientation GetOrientation ()
-		{
-			return Info.Orientation;
-		}
-
 	}
 }



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