[f-spot/rubenv-gsoc-2009: 61/86] Properly handle Original.



commit 978d82242e8aabcde4ac854a02db2fd6983a95ed
Author: Ruben Vermeersch <ruben savanne be>
Date:   Tue Aug 11 01:47:01 2009 +0200

    Properly handle Original.

 src/Editors/Editor.cs           |   17 ++++++---
 src/Editors/RepeatableEditor.cs |   75 ++++++++++++++++++++++++--------------
 2 files changed, 58 insertions(+), 34 deletions(-)
---
diff --git a/src/Editors/Editor.cs b/src/Editors/Editor.cs
index c9be5ed..58f69d4 100644
--- a/src/Editors/Editor.cs
+++ b/src/Editors/Editor.cs
@@ -211,14 +211,12 @@ namespace FSpot.Editors {
 		void RenderPreview ()
 		{
 			if (Original == null) {
-				Original = GetOriginal ();
+				Original = State.PhotoImageView.Pixbuf;
 			}
 
 			Pixbuf old_preview = null;
 			if (Preview == null) {
-				int width, height;
-				CalcPreviewSize (Original, out width, out height);
-				Preview = Original.ScaleSimple (width, height, InterpType.Nearest);
+				Preview = GetPreviewInput ();
 			} else {
 				// We're updating a previous preview
 				old_preview = State.PhotoImageView.Pixbuf;
@@ -236,9 +234,16 @@ namespace FSpot.Editors {
 				});
 		}
 
-		protected virtual Pixbuf GetOriginal ()
+		protected Pixbuf ScalePreviewInput (Pixbuf input)
 		{
-			return State.PhotoImageView.Pixbuf;
+			int width, height;
+			CalcPreviewSize (input, out width, out height);
+			return input.ScaleSimple (width, height, InterpType.Nearest);
+		}
+
+		protected virtual Pixbuf GetPreviewInput ()
+		{
+			return ScalePreviewInput (Original);
 		}
 
 		protected void CalcPreviewSize (Pixbuf input, out int width, out int height) {
diff --git a/src/Editors/RepeatableEditor.cs b/src/Editors/RepeatableEditor.cs
index 4946967..3ee08dd 100644
--- a/src/Editors/RepeatableEditor.cs
+++ b/src/Editors/RepeatableEditor.cs
@@ -41,7 +41,23 @@ namespace FSpot.Editors {
 
 		sealed protected override void LoadPhoto (Photo photo, out Pixbuf photo_pixbuf, out Cms.Profile photo_profile)
 		{
-			base.LoadPhoto (photo, out photo_pixbuf, out photo_profile);
+			// Figure out the original version to process
+			PhotoVersion version = photo.DefaultVersion;
+			uint parent_version = version.Type == PhotoVersionType.Processable ? version.ParentVersionId : version.VersionId;
+			Uri uri = photo.VersionUri (parent_version);
+
+			if (parent_version == photo.DefaultVersionId) {
+				base.LoadPhoto (photo, out photo_pixbuf, out photo_profile);
+			} else {
+				using (ImageFile img = ImageFile.Create (uri)) {
+					using (IImageLoader loader = ImageLoader.Create (uri)) {
+						loader.Load (ImageLoaderItem.Full);
+						photo_pixbuf = loader.Full;
+					}
+					photo_profile = img.GetProfile ();
+				}
+			}
+
 			Pipeline = new Pipeline (photo);
 			SetupPipeline ();
 		}
@@ -76,7 +92,7 @@ namespace FSpot.Editors {
 			return new RepeatableEditorState ();
 		}
 
-		sealed protected override Pixbuf GetOriginal ()
+		sealed protected override Pixbuf GetPreviewInput ()
 		{
 			// Figure out the original version to process
 			Photo photo = State.Items [0] as Photo;
@@ -87,40 +103,43 @@ namespace FSpot.Editors {
 			// Load the large size blocking
 			IImageLoader loader = ImageLoader.Create (uri);
 			loader.Load (ImageLoaderItem.Large);
+			Pixbuf large = loader.Large;
 
 			// Load the full size in the background
-			loader.Load (ImageLoaderItem.Full, delegate (object sender, ItemsCompletedEventArgs args) {
-				if (!args.Items.Contains (ImageLoaderItem.Full))
-					return;
-
-				Pixbuf old_original = Original;
-				Pixbuf full = loader.Full;
-				if (full == null) {
-					loader.Dispose ();
-					return;
-				}
+			loader.Load (ImageLoaderItem.Full, HandleFullPreviewLoaded);
 
-				if (!StateInitialized) {
-					full.Dispose ();
-					loader.Dispose ();
-					return;
-				}
+			if (large == null)
+				return ScalePreviewInput (Original);
+			else
+				return ScalePreviewInput (large);
+		}
+
+		private void HandleFullPreviewLoaded (object sender, ItemsCompletedEventArgs args)
+		{
+			IImageLoader loader = sender as IImageLoader;
 
-				Original = full;
-				if (old_original != null)
-					old_original.Dispose ();
+			if (!args.Items.Contains (ImageLoaderItem.Full))
+				return;
 
-				int width, height;
-				CalcPreviewSize (Original, out width, out height);
-				Pixbuf old_preview = Preview;
-				Preview = Original.ScaleSimple (width, height, InterpType.Nearest);
-				if (old_preview != null)
-					old_preview.Dispose ();
+			Pixbuf full = loader.Full;
+			if (full == null) {
+				loader.Dispose ();
+				return;
+			}
 
+			if (!StateInitialized) {
+				full.Dispose ();
 				loader.Dispose ();
-			});
+				return;
+			}
+
+			Pixbuf old_preview = Preview;
+			Preview = ScalePreviewInput (full);
+			if (old_preview != null)
+				old_preview.Dispose ();
 
-			return loader.Large;
+			full.Dispose ();
+			loader.Dispose ();
 		}
 	}
 }



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