[f-spot] reduce the file opening operations by one



commit b61e2dd246882d745c2ef4bc782d3d1b9586abb6
Author: Stephane Delcroix <stephane delcroix org>
Date:   Thu Jun 18 14:10:11 2009 +0200

    reduce the file opening operations by one
    
    this feeds the jpegheader while someone requests for the complete stream. It also delays the orientation loading after requesting the pibuf so we benefits from the said fast-path

 src/AsyncPixbufLoader.cs |    2 +-
 src/Imaging/ImageFile.cs |    4 ++++
 src/Imaging/JpegFile.cs  |   14 ++++++++++++++
 3 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/src/AsyncPixbufLoader.cs b/src/AsyncPixbufLoader.cs
index 08627c1..0a08913 100644
--- a/src/AsyncPixbufLoader.cs
+++ b/src/AsyncPixbufLoader.cs
@@ -113,7 +113,6 @@ namespace FSpot {
 			damage = Gdk.Rectangle.Zero;
 
 			using (ImageFile img = ImageFile.Create (uri)) {
-				orientation = Accelerometer.GetViewOrientation (img.Orientation);
 			
 				try {
 					PixbufOrientation thumb_orientation = Accelerometer.GetViewOrientation (PixbufOrientation.TopLeft);
@@ -134,6 +133,7 @@ namespace FSpot {
 				}
 
 				System.IO.Stream nstream = img.PixbufStream ();
+				orientation = Accelerometer.GetViewOrientation (img.Orientation);
 				if (nstream == null) {
 					FileLoad (img);
 					return;
diff --git a/src/Imaging/ImageFile.cs b/src/Imaging/ImageFile.cs
index d9095ef..6080c82 100644
--- a/src/Imaging/ImageFile.cs
+++ b/src/Imaging/ImageFile.cs
@@ -29,6 +29,8 @@ namespace FSpot {
 		protected Stream Open ()
 		{
 			Log.DebugFormat ("open uri = {0}", uri.ToString ());
+//			if (uri.IsFile)
+//				return new FileStream (uri.LocalPath, FileMode.Open);
 			return new GLib.GioStream (GLib.FileFactory.NewForUri (uri).Read (null));
 		}
 
@@ -104,6 +106,7 @@ namespace FSpot {
 			return rotated;
 		}
 		
+		[Obsolete ("Use an Async way to load the pixbuf")]
 		public virtual Gdk.Pixbuf Load ()
 		{
 			using (Stream stream = PixbufStream ()) {
@@ -112,6 +115,7 @@ namespace FSpot {
 			}
 		}
 		
+		[Obsolete ("Use an Async way to load the pixbuf")]
 		public virtual Gdk.Pixbuf Load (int max_width, int max_height)
 		{
 			System.IO.Stream stream = PixbufStream ();
diff --git a/src/Imaging/JpegFile.cs b/src/Imaging/JpegFile.cs
index f54fadf..79775ff 100644
--- a/src/Imaging/JpegFile.cs
+++ b/src/Imaging/JpegFile.cs
@@ -54,6 +54,20 @@ namespace FSpot {
 			}
 		}
 
+		public override Stream PixbufStream ()
+		{
+			if (header != null)
+				return Open ();
+
+			Stream s = Open ();
+			if (s.CanSeek) {
+				header = new JpegHeader (s, true);
+				s.Position = 0;
+			} else
+				Console.WriteLine ("{0} can not seek :(", s);
+			return s;
+		}
+
 		public void Select (SemWeb.StatementSink sink)
 		{
 			Header.Select (sink);



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