[f-spot/rubenv-gsoc-2009: 50/86] Initial Processing framework, the start of repeatable editing.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/rubenv-gsoc-2009: 50/86] Initial Processing framework, the start of repeatable editing.
- Date: Sun, 23 May 2010 12:36:09 +0000 (UTC)
commit cb999a008a8bfcce1a39d85ce962169bcd9eb8a2
Author: Ruben Vermeersch <ruben savanne be>
Date: Mon Aug 3 20:37:25 2009 +0200
Initial Processing framework, the start of repeatable editing.
src/Db.cs | 7 ++
src/Editors/Processing/ColorAdjustStep.cs | 26 +++++++
src/Editors/Processing/Pipeline.cs | 89 ++++++++++++++++++++++++
src/Editors/Processing/Setting.cs | 54 +++++++++++++++
src/Editors/Processing/SettingStore.cs | 104 +++++++++++++++++++++++++++++
src/Editors/Processing/Step.cs | 17 +++++
src/Makefile.am | 5 ++
7 files changed, 302 insertions(+), 0 deletions(-)
---
diff --git a/src/Db.cs b/src/Db.cs
index 0e60988..3ddb09b 100644
--- a/src/Db.cs
+++ b/src/Db.cs
@@ -7,6 +7,7 @@ using Banshee.Database;
using System.Diagnostics;
using FSpot;
using FSpot.Utils;
+using FSpot.Editors.Processing;
// A Store maps to a SQL table. We have separate stores (i.e. SQL tables) for tags, photos and imports.
@@ -139,6 +140,7 @@ public class Db : IDisposable {
ExportStore export_store;
JobStore job_store;
MetaStore meta_store;
+ SettingStore setting_store;
bool empty;
string path;
@@ -170,6 +172,10 @@ public class Db : IDisposable {
get { return meta_store; }
}
+ public SettingStore ProcessingSettings {
+ get { return setting_store; }
+ }
+
// This affects how often the database writes data back to disk, and
// therefore how likely corruption is in the event of power loss.
public bool Sync {
@@ -232,6 +238,7 @@ public class Db : IDisposable {
export_store = new ExportStore (Database, new_db);
job_store = new JobStore (Database, new_db);
photo_store = new PhotoStore (Database, new_db);
+ setting_store = new SettingStore (Database, new_db);
Database.CommitTransaction ();
diff --git a/src/Editors/Processing/ColorAdjustStep.cs b/src/Editors/Processing/ColorAdjustStep.cs
new file mode 100644
index 0000000..ea58ffe
--- /dev/null
+++ b/src/Editors/Processing/ColorAdjustStep.cs
@@ -0,0 +1,26 @@
+//
+// Fspot.Editors.Processing.ColorAdjustStep.cs
+//
+// Author(s)
+// Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details
+//
+
+using FSpot.Utils;
+using Gdk;
+
+namespace FSpot.Editors.Processing {
+ public class ColorAdjustStep : Step
+ {
+ static ColorAdjustStep ()
+ {
+ Pipeline.AddStep (150, new ColorAdjustStep ());
+ }
+
+ public void Process (Pipeline pipeline, Pixbuf input, out Pixbuf output)
+ {
+ output = input.ShallowCopy ();
+ }
+ }
+}
diff --git a/src/Editors/Processing/Pipeline.cs b/src/Editors/Processing/Pipeline.cs
new file mode 100644
index 0000000..af0e35d
--- /dev/null
+++ b/src/Editors/Processing/Pipeline.cs
@@ -0,0 +1,89 @@
+//
+// Fspot.Editors.Processing.Pipeline.cs
+//
+// Author(s)
+// Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details
+//
+
+using FSpot.Utils;
+using Gdk;
+using System;
+using System.Collections.Generic;
+
+namespace FSpot.Editors.Processing {
+ public class Pipeline
+ {
+#region Step registration
+ static SortedList<uint, Step> Steps { get; set; }
+
+ static Pipeline ()
+ {
+ Steps = new SortedList<uint, Step> ();
+ }
+
+ public static void AddStep (uint order, Step step)
+ {
+ Steps.Add (order, step);
+ }
+#endregion
+
+ public Photo Photo { get; private set; }
+
+ public Pipeline (Photo photo)
+ {
+ Photo = photo;
+ Settings = new Dictionary<string, Setting> ();
+
+ SettingStore store = Core.Database.ProcessingSettings;
+ foreach (Setting setting in store.GetAll (Photo.Id, Photo.DefaultVersionId)) {
+ Settings.Add (setting.Key, setting);
+ }
+ }
+
+#region Processing
+ public Pixbuf Input { get; set; }
+ public Pixbuf Output { get; private set; }
+
+ public void Process ()
+ {
+ Pixbuf input = Input.ShallowCopy ();
+ Pixbuf output = null;
+ foreach (Step step in Steps.Values)
+ {
+ step.Process (this, input, out output);
+ input.Dispose ();
+ input = output;
+ }
+ Output = output;
+ }
+#endregion
+
+#region Settings
+ Dictionary<string, Setting> Settings { get; set; }
+
+ public void Set (string key, bool val)
+ {
+ Set (key, val ? "1" : "0");
+ }
+
+ public void Set (string key, string val)
+ {
+ if (Settings.ContainsKey (key)) {
+ Settings [key].Value = val;
+ } else {
+ Settings.Add (key, new Setting (Photo.Id, Photo.DefaultVersionId, key, val));
+ }
+ }
+
+ public Setting Get (string key)
+ {
+ Setting setting;
+ if (!Settings.TryGetValue (key, out setting))
+ setting = new Setting (Photo.Id, Photo.DefaultVersionId, key, null);
+ return setting;
+ }
+#endregion
+ }
+}
diff --git a/src/Editors/Processing/Setting.cs b/src/Editors/Processing/Setting.cs
new file mode 100644
index 0000000..2be5791
--- /dev/null
+++ b/src/Editors/Processing/Setting.cs
@@ -0,0 +1,54 @@
+//
+// Fspot.Editors.Processing.Setting.cs
+//
+// Author(s)
+// Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details
+//
+
+using System;
+
+namespace FSpot.Editors.Processing {
+ public class Setting : DbItem
+ {
+ public uint Id { get; internal set; }
+ public uint PhotoId { get; private set; }
+ public uint VersionId { get; private set; }
+ public string Key { get; private set; }
+ public string Value { get; set; }
+
+ public Setting (uint photo, uint version, string key, string val)
+ : this (0, photo, version, key, val) { }
+
+ public Setting (uint id, uint photo, uint version, string key, string val)
+ : base (id) {
+ Id = id;
+ PhotoId = photo;
+ VersionId = version;
+ Key = key;
+ Value = val;
+ }
+
+ public bool BoolValue {
+ get {
+ return !IsBlank && (
+ String.Compare (Value, "1") == 0
+ || String.Compare (Value, "true") == 0
+ );
+ }
+ }
+
+ public int IntValue {
+ get { return IsBlank ? 0 : Convert.ToInt32 (Value); }
+ }
+
+ public double DoubleValue {
+ get { return IsBlank ? 0.0 : Convert.ToDouble (Value); }
+ }
+
+ public bool IsBlank {
+ get { return Value == null; }
+ }
+ }
+}
diff --git a/src/Editors/Processing/SettingStore.cs b/src/Editors/Processing/SettingStore.cs
new file mode 100644
index 0000000..dfe0fc1
--- /dev/null
+++ b/src/Editors/Processing/SettingStore.cs
@@ -0,0 +1,104 @@
+//
+// Fspot.Editors.Processing.SettingStore.cs
+//
+// Author(s)
+// Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details
+//
+
+using Banshee.Database;
+using Mono.Data.SqliteClient;
+using System;
+using System.Collections.Generic;
+
+namespace FSpot.Editors.Processing {
+ public class SettingStore : DbStore<Setting>
+ {
+ public SettingStore (QueuedSqliteDatabase database, bool is_new) : base (database, false)
+ {
+ if (!is_new && Database.TableExists ("processing_settings"))
+ return;
+
+ Database.ExecuteNonQuery (
+ "CREATE TABLE processing_settings (\n" +
+ " id INTEGER PRIMARY KEY NOT NULL,\n" +
+ " photo_id INTEGER NOT NULL,\n" +
+ " version_id INTEGER NOT NULL,\n" +
+ " key TEXT NOT NULL,\n" +
+ " value TEXT NOT NULL\n" +
+ ")");
+ }
+
+ public override Setting Get (uint id)
+ {
+ Setting setting = null;
+ SqliteDataReader reader = Database.Query(new DbCommand ("SELECT * FROM processing_settings WHERE id = :id", "id", id));
+
+ if (reader.Read ()) {
+ setting = new Setting (id,
+ Convert.ToUInt32 (reader ["photo_id"]),
+ Convert.ToUInt32 (reader ["version_id"]),
+ reader ["key"].ToString (),
+ reader ["value"].ToString ());
+ }
+
+ return setting;
+ }
+
+ public List<Setting> GetAll (uint photo_id, uint version_id)
+ {
+ List<Setting> settings = new List<Setting> ();
+ SqliteDataReader reader = Database.Query(new DbCommand ("SELECT * FROM processing_settings WHERE photo_id = :photo_id AND version_id = :version_id", "photo_id", photo_id, "version_id", version_id));
+
+ while (reader.Read ()) {
+ Setting setting = new Setting (
+ Convert.ToUInt32 (reader ["id"]),
+ Convert.ToUInt32 (reader ["photo_id"]),
+ Convert.ToUInt32 (reader ["version_id"]),
+ reader ["key"].ToString (),
+ reader ["value"].ToString ());
+ settings.Add (setting);
+ }
+
+ return settings;
+ }
+
+ public override void Remove (Setting setting)
+ {
+ Database.ExecuteNonQuery (new DbCommand ("DELETE FROM processing_settings WHERE id = :id", "id", setting.Id));
+ }
+
+ public void RemoveAll (uint photo_id, uint version_id)
+ {
+ Database.ExecuteNonQuery (new DbCommand ("DELETE FROM processing_settings WHERE photo_id = :photo_id AND version_id = :version_id", "photo_id", photo_id, "version_id", version_id));
+ }
+
+ public override void Commit (Setting setting)
+ {
+ if (setting.Id == 0) {
+ uint id = (uint) Database.Execute (
+ new DbCommand (
+ "INSERT INTO processing_settings (photo_id, version_id, key, value) " +
+ "VALUES (:photo_id, :version_id, :key, :value)",
+ "photo_id", setting.PhotoId,
+ "version_id", setting.VersionId,
+ "key", setting.Key,
+ "value", setting.Value
+ )
+ );
+ setting.Id = id;
+ } else {
+ Database.ExecuteNonQuery (
+ new DbCommand (
+ "UPDATE processing_settings " +
+ "SET value = :value " +
+ "WHERE id = :id ",
+ "value", setting.Value,
+ "id", setting.Id
+ )
+ );
+ }
+ }
+ }
+}
diff --git a/src/Editors/Processing/Step.cs b/src/Editors/Processing/Step.cs
new file mode 100644
index 0000000..c68bbe2
--- /dev/null
+++ b/src/Editors/Processing/Step.cs
@@ -0,0 +1,17 @@
+//
+// Fspot.Editors.Processing.Step.cs
+//
+// Author(s)
+// Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details
+//
+
+using Gdk;
+
+namespace FSpot.Editors.Processing {
+ public interface Step
+ {
+ void Process (Pipeline pipeline, Pixbuf input, out Pixbuf output);
+ }
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index c3148c8..1d23f07 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -192,6 +192,11 @@ F_SPOT_CSDISTFILES = \
$(srcdir)/Editors/SepiaEditor.cs \
$(srcdir)/Editors/SoftFocusEditor.cs \
$(srcdir)/Editors/TiltEditor.cs \
+ $(srcdir)/Editors/Processing/Pipeline.cs \
+ $(srcdir)/Editors/Processing/Setting.cs \
+ $(srcdir)/Editors/Processing/SettingStore.cs \
+ $(srcdir)/Editors/Processing/Step.cs \
+ $(srcdir)/Editors/Processing/ColorAdjustStep.cs \
$(srcdir)/ExportStore.cs \
$(srcdir)/Extensions/ExportMenuItemNode.cs \
$(srcdir)/Extensions/IExporter.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]