[f-spot/rubenv-gsoc-2009: 54/86] Convert ColorEditor to be a RepeatableEditor.



commit 8e17bcf959ec02a2b701c6b5efeb02f2e1b62586
Author: Ruben Vermeersch <ruben savanne be>
Date:   Tue Aug 4 19:58:50 2009 +0200

    Convert ColorEditor to be a RepeatableEditor.

 src/Editors/ColorEditor.cs                |   40 +++++++++++++++-------------
 src/Editors/Editor.cs                     |    2 +-
 src/Editors/Processing/ColorAdjustStep.cs |   28 +++++++++++++++----
 src/Editors/Processing/Pipeline.cs        |   41 +++++++++++++++++++++++++++-
 src/Editors/RepeatableEditor.cs           |   17 +++++++++---
 5 files changed, 96 insertions(+), 32 deletions(-)
---
diff --git a/src/Editors/ColorEditor.cs b/src/Editors/ColorEditor.cs
index 876cbe6..290e73b 100644
--- a/src/Editors/ColorEditor.cs
+++ b/src/Editors/ColorEditor.cs
@@ -16,7 +16,7 @@ using Mono.Unix;
 using System;
 
 namespace FSpot.Editors {
-	class ColorEditor : Editor {
+	class ColorEditor : RepeatableEditor {
 		private Glade.XML xml;
 
 		[Glade.Widget] private Gtk.HScale exposure_scale;
@@ -45,26 +45,33 @@ namespace FSpot.Editors {
 			xml = new Glade.XML (null, "f-spot.glade", "color_editor_prefs", "f-spot");
 			xml.Autoconnect (this);
 			AttachInterface ();
-			return xml.GetWidget ("color_editor_prefs");;
+			return xml.GetWidget ("color_editor_prefs");
 		}
 
 		private void AttachInterface () {
-			exposure_spinbutton.Adjustment = exposure_scale.Adjustment;
 			temp_spinbutton.Adjustment = temp_scale.Adjustment;
 			temptint_spinbutton.Adjustment = temptint_scale.Adjustment;
+			exposure_spinbutton.Adjustment = exposure_scale.Adjustment;
 			brightness_spinbutton.Adjustment = brightness_scale.Adjustment;
 			contrast_spinbutton.Adjustment = contrast_scale.Adjustment;
 			hue_spinbutton.Adjustment = hue_scale.Adjustment;
 			sat_spinbutton.Adjustment = sat_scale.Adjustment;
 
+			temp_scale.Adjustment.Value = Pipeline.Get ("ColorAdjust", "Temperature", "5000").IntValue;
+			temptint_scale.Adjustment.Value = Pipeline.Get ("ColorAdjust", "Tint", "0").IntValue;
+			exposure_scale.Adjustment.Value = Pipeline.Get ("ColorAdjust", "Exposure", "0.0").DoubleValue;
+			brightness_scale.Adjustment.Value = Pipeline.Get ("ColorAdjust", "Brightness", "0.0").DoubleValue;
+			contrast_scale.Adjustment.Value = Pipeline.Get ("ColorAdjust", "Contrast", "0.0").DoubleValue;
+			hue_scale.Adjustment.Value = Pipeline.Get ("ColorAdjust", "Hue", "0.0").DoubleValue;
+			sat_scale.Adjustment.Value = Pipeline.Get ("ColorAdjust", "Saturation", "0.0").DoubleValue;
+
 			temp_spinbutton.Adjustment.ChangeValue ();
 			temptint_spinbutton.Adjustment.ChangeValue ();
+			exposure_spinbutton.Adjustment.ChangeValue ();
 			brightness_spinbutton.Adjustment.ChangeValue ();
 			contrast_spinbutton.Adjustment.ChangeValue ();
 			hue_spinbutton.Adjustment.ChangeValue ();
 			sat_spinbutton.Adjustment.ChangeValue ();
-			hue_spinbutton.Adjustment.ChangeValue ();
-			sat_spinbutton.Adjustment.ChangeValue ();
 
 			exposure_scale.ValueChanged += RangeChanged;
 			temp_scale.ValueChanged += RangeChanged;
@@ -79,20 +86,15 @@ namespace FSpot.Editors {
 			UpdatePreview ();
 		}
 
-		protected override Pixbuf Process (Pixbuf input, Cms.Profile input_profile) {
-			Cms.ColorCIEXYZ src_wp;
-			Cms.ColorCIEXYZ dest_wp;
-
-			src_wp = Cms.ColorCIExyY.WhitePointFromTemperature (5000).ToXYZ ();
-			dest_wp = Cms.ColorCIExyY.WhitePointFromTemperature ((int)temp_scale.Value).ToXYZ ();
-			Cms.ColorCIELab dest_lab = dest_wp.ToLab (src_wp);
-			dest_lab.a += temptint_scale.Value;
-			dest_wp = dest_lab.ToXYZ (src_wp);
-
-			FullColorAdjustment adjust = new FullColorAdjustment (input, input_profile,
-					exposure_scale.Value, brightness_scale.Value, contrast_scale.Value,
-					hue_scale.Value, sat_scale.Value, src_wp, dest_wp);
-			return adjust.Adjust ();
+		protected override void SetupPipeline ()
+		{
+			Pipeline.Set ("ColorAdjust", "Temperature", (int) temp_scale.Value);
+			Pipeline.Set ("ColorAdjust", "Tint", (int) temptint_scale.Value);
+			Pipeline.Set ("ColorAdjust", "Exposure", (double) exposure_scale.Value);
+			Pipeline.Set ("ColorAdjust", "Brightness", (double) brightness_scale.Value);
+			Pipeline.Set ("ColorAdjust", "Contrast", (double) contrast_scale.Value);
+			Pipeline.Set ("ColorAdjust", "Hue", (double) hue_scale.Value);
+			Pipeline.Set ("ColorAdjust", "Saturation", (double) sat_scale.Value);
 		}
 	}
 }
diff --git a/src/Editors/Editor.cs b/src/Editors/Editor.cs
index d57f514..304f0ea 100644
--- a/src/Editors/Editor.cs
+++ b/src/Editors/Editor.cs
@@ -237,7 +237,7 @@ namespace FSpot.Editors {
 		public delegate void InitializedHandler ();
 		public event InitializedHandler Initialized;
 
-		public void Initialize (EditorState state) {
+		public virtual void Initialize (EditorState state) {
 			State = state;
 
 			if (Initialized != null)
diff --git a/src/Editors/Processing/ColorAdjustStep.cs b/src/Editors/Processing/ColorAdjustStep.cs
index 5ddeff2..79f94d3 100644
--- a/src/Editors/Processing/ColorAdjustStep.cs
+++ b/src/Editors/Processing/ColorAdjustStep.cs
@@ -7,24 +7,40 @@
 // This is free software. See COPYING for details
 //
 
+using FSpot.ColorAdjustment;
 using FSpot.Utils;
 using Gdk;
 
 namespace FSpot.Editors.Processing {
 	public class ColorAdjustStep : Step
 	{
-		static ColorAdjustStep ()
-		{
-			Pipeline.AddStep (150, new ColorAdjustStep ());
-		}
-
 		public string Name {
 			get { return "ColorAdjust"; }
 		}
 
 		public void Process (Pipeline pipeline, Pixbuf input, out Pixbuf output)
 		{
-			output = input.ShallowCopy ();
+			Cms.ColorCIEXYZ src_wp;
+			Cms.ColorCIEXYZ dest_wp;
+
+			int temp = pipeline.Get (this, "Temperature").IntValue;
+			int tint = pipeline.Get (this, "Tint").IntValue;
+			Cms.Profile input_profile = pipeline.InputProfile;
+			double exposure = pipeline.Get (this, "Exposure").DoubleValue;
+			double brightness = pipeline.Get (this, "Brightness").DoubleValue;
+			double contrast = pipeline.Get (this, "Contrast").DoubleValue;
+			double hue = pipeline.Get (this, "Hue").DoubleValue;
+			double saturation = pipeline.Get (this, "Saturation").DoubleValue;
+
+			src_wp = Cms.ColorCIExyY.WhitePointFromTemperature (5000).ToXYZ ();
+			dest_wp = Cms.ColorCIExyY.WhitePointFromTemperature (temp).ToXYZ ();
+			Cms.ColorCIELab dest_lab = dest_wp.ToLab (src_wp);
+			dest_lab.a += tint;
+			dest_wp = dest_lab.ToXYZ (src_wp);
+
+			FullColorAdjustment adjust = new FullColorAdjustment (input, input_profile,
+					exposure, brightness, contrast, hue, saturation, src_wp, dest_wp);
+			output = adjust.Adjust ();
 		}
 	}
 }
diff --git a/src/Editors/Processing/Pipeline.cs b/src/Editors/Processing/Pipeline.cs
index 2438516..aea09f6 100644
--- a/src/Editors/Processing/Pipeline.cs
+++ b/src/Editors/Processing/Pipeline.cs
@@ -21,6 +21,7 @@ namespace FSpot.Editors.Processing {
 		static Pipeline ()
 		{
 			Steps = new SortedList<uint, Step> ();
+			AddStep (150, new ColorAdjustStep ());
 		}
 
 		public static void AddStep (uint order, Step step)
@@ -84,7 +85,17 @@ namespace FSpot.Editors.Processing {
 
 		public void Set (Step step, string key, string val)
 		{
-			key = step.Name + ":" + key;
+			Set (step.Name, key, val);
+		}
+
+		public void Set (string step, string key, object val)
+		{
+			Set (step, key, val.ToString ());
+		}
+
+		public void Set (string step, string key, string val)
+		{
+			key = step + ":" + key;
 			if (Settings.ContainsKey (key)) {
 				Settings [key].Value = val;
 			} else {
@@ -94,13 +105,26 @@ namespace FSpot.Editors.Processing {
 
 		public Setting Get (Step step, string key)
 		{
-			key = step.Name + ":" + key;
+			return Get (step.Name, key);
+		}
+
+		public Setting Get (string step, string key)
+		{
+			key = step + ":" + key;
 			Setting setting;
 			if (!Settings.TryGetValue (key, out setting))
 				setting = new Setting (Photo.Id, Photo.DefaultVersionId, key, null);
 			return setting;
 		}
 
+		public Setting Get (string step, string key, string def)
+		{
+			Setting setting = Get (step, key);
+			if (setting.IsBlank)
+				setting.Value = def;
+			return setting;
+		}
+
 		public void Save ()
 		{
 			foreach (Setting setting in Settings.Values) {
@@ -108,5 +132,18 @@ namespace FSpot.Editors.Processing {
 			}
 		}
 #endregion
+
+		public void Dump ()
+		{
+			Log.Debug ("Dumping pipeline {0}", this);
+			Log.Debug ("   Steps:");
+			foreach (KeyValuePair<uint, Step> kvp in Steps) {
+				Log.Debug ("      {0} - {1}", kvp.Key, kvp.Value.Name);
+			}
+			Log.Debug ("   Settings:");
+			foreach (KeyValuePair<string, Setting> kvp in Settings) {
+				Log.Debug ("      {0} - {1}", kvp.Key, kvp.Value.Value);
+			}
+		}
 	}
 }
diff --git a/src/Editors/RepeatableEditor.cs b/src/Editors/RepeatableEditor.cs
index d078c47..ac6b711 100644
--- a/src/Editors/RepeatableEditor.cs
+++ b/src/Editors/RepeatableEditor.cs
@@ -18,17 +18,21 @@ namespace FSpot.Editors {
 		public RepeatableEditor (string label, string icon_name)
 				: base (label, icon_name)
 		{
-
 		}
 
-		// When this is called, the pipeline should be filled with the
-		// appropriate values, chosen in the configuration widget.
-		protected abstract void SetupPipeline ();
+		sealed public override void Initialize (EditorState state)
+		{
+			base.Initialize (state);
+
+			if (State.Items.Length > 0)
+				Pipeline = new Pipeline (State.Items [0] as Photo);
+		}
 
 		sealed protected override Pixbuf Process (Pixbuf input, Cms.Profile input_profile)
 		{
 			Pipeline.Input = input;
 			Pipeline.InputProfile = input_profile;
+			SetupPipeline ();
 			Pipeline.Process ();
 			return Pipeline.Output.ShallowCopy ();
 		}
@@ -39,5 +43,10 @@ namespace FSpot.Editors {
 			Pipeline = new Pipeline (photo);
 			SetupPipeline ();
 		}
+
+		// When this is called, the pipeline should be filled with the
+		// appropriate values, chosen in the configuration widget.
+		protected abstract void SetupPipeline ();
+
 	}
 }



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