[f-spot] New BWEditor extension
- From: Stephane Delcroix <sdelcroix src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [f-spot] New BWEditor extension
- Date: Thu, 17 Sep 2009 11:07:19 +0000 (UTC)
commit 04375b12ba722abe97fdb177492181adaa7bad64
Author: Stephane Delcroix <stephane delcroix org>
Date: Wed Sep 16 16:32:20 2009 +0200
New BWEditor extension
This extension allow converting images to BW with control ov er the channels and curve.
extensions/Editors/BWEditor/BWEditor.addin.xml | 15 +++
extensions/Editors/BWEditor/BWEditor.cs | 126 ++++++++++++++++++++++++
extensions/Editors/BWEditor/Makefile | 30 ++++++
3 files changed, 171 insertions(+), 0 deletions(-)
---
diff --git a/extensions/Editors/BWEditor/BWEditor.addin.xml b/extensions/Editors/BWEditor/BWEditor.addin.xml
new file mode 100644
index 0000000..e3d6791
--- /dev/null
+++ b/extensions/Editors/BWEditor/BWEditor.addin.xml
@@ -0,0 +1,15 @@
+<Addin namespace="FSpot"
+ id="BWEditor"
+ version="0.6.0.0"
+ name="BWEditor"
+ description="Convert to B/W with control. Require Mono 2.2."
+ author="Stephane Delcroix"
+ url="http://f-spot.org/Extensions"
+ category="Editors">
+ <Dependencies>
+ <Addin id="Core" version="0.6"/>
+ </Dependencies>
+ <Extension path = "/FSpot/Editors">
+ <Editor editor_type = "BWEditor.BWEditor"/>
+ </Extension>
+</Addin>
diff --git a/extensions/Editors/BWEditor/BWEditor.cs b/extensions/Editors/BWEditor/BWEditor.cs
new file mode 100644
index 0000000..bd4dcda
--- /dev/null
+++ b/extensions/Editors/BWEditor/BWEditor.cs
@@ -0,0 +1,126 @@
+/*
+ * BWEditor.cs
+ *
+ * Author(s)
+ * Stephane Delcroix (stephane delcroix org)
+ *
+ * Copyright (c) 2009 Novell, Inc.
+ *
+ * This is open source software. See COPYING for details.
+ */
+
+using System;
+using FSpot;
+using FSpot.Editors;
+using Gtk;
+using Gdk;
+using Mono.Unix;
+using Mono.Simd;
+
+namespace BWEditor {
+ class BWEditor : Editor {
+ public BWEditor () : base (Catalog.GetString ("Convert to B/W"), null) {
+ CanHandleMultiple = false;
+ HasSettings = true;
+ ApplyLabel = Catalog.GetString ("Apply");
+ }
+
+ static bool enhanced_support = EnhancedSimdSupport ();
+ static bool EnhancedSimdSupport () { //require sse3
+ return SimdRuntime.IsMethodAccelerated (typeof (VectorOperations), "HorizontalAdd", new Type[] {typeof (Vector4f), typeof (Vector4f)})
+ && SimdRuntime.IsMethodAccelerated (typeof (Vector4f), "op_Multiply");
+ }
+
+ protected override Pixbuf Process (Pixbuf input, Cms.Profile input_profile)
+ {
+ uint timer = FSpot.Utils.Log.DebugTimerStart ();
+ if (input.BitsPerSample != 8) {
+ FSpot.Utils.Log.Warning ("unsupported pixbuf format");
+ return (Pixbuf)input.Clone ();
+ }
+ Pixbuf output = new Pixbuf (input.Colorspace, input.HasAlpha, input.BitsPerSample, input.Width, input.Height);
+ Vector4f multiply = new Vector4f ((float)(r.Value/100.0), (float)(g.Value/100.0), (float)(b.Value/100.0), 0);
+ Normalize (ref multiply);
+
+ bool has_alpha = input.HasAlpha;
+ int chan = input.NChannels;
+ int rowstride_in = input.Rowstride;
+ int rowstride_out = output.Rowstride;
+ Vector4f v_in;
+ Vector4f v_out = new Vector4f (0);
+ float[] fcurve = new float [256];
+ c.GetVector (fcurve.Length, fcurve);
+ byte[] curve = new byte [fcurve.Length];
+ for (int i = 0; i < fcurve.Length; i++)
+ curve[i] = (byte)fcurve[i];
+ unsafe {
+ byte *pix_in = (byte *)input.Pixels;
+ byte *pix_out = (byte *)output.Pixels;
+ for (int i=0; i < input.Height; i++)
+ for (int j=0; j<input.Width; j++) {
+ v_in = new Vector4f (pix_in[i*rowstride_in + j*chan],
+ pix_in[i*rowstride_in + j*chan + 1],
+ pix_in[i*rowstride_in + j*chan + 2],
+ 0);
+ Desaturate (ref v_in, ref multiply, ref v_out);
+ pix_out[i*rowstride_out + j*chan] = curve [unchecked ((byte)v_out.X)];
+ pix_out[i*rowstride_out + j*chan + 1] = curve [unchecked ((byte)v_out.Y)];
+ pix_out[i*rowstride_out + j*chan + 2] = curve [unchecked ((byte)v_out.Z)];
+ if (has_alpha)
+ pix_out[i*rowstride_out + j*chan + 3] = pix_in[i*rowstride_in + j*chan + 3];
+ }
+ }
+ FSpot.Utils.Log.DebugTimerPrint (timer, "Processing took {0}");
+ return output;
+ }
+
+ static void Desaturate (ref Vector4f input, ref Vector4f chan_multiplier, ref Vector4f output)
+ {
+ Vector4f temp = input * chan_multiplier; //(r1,g1,b1,0) = (r,g,b,a) * (rx, gx, bx, 0)
+ temp = temp.HorizontalAdd (temp); //(r1+g1, b1+0, r1+g1, b1+0)
+ output = temp.HorizontalAdd (temp); //(r1+g1+b1+0, r1+g1+b1+0, ..., ...)
+ }
+
+ static void Normalize (ref Vector4f v)
+ {
+ float sum = v.X + v.Y + v.Z;
+ v /= new Vector4f (sum);
+ }
+
+ HScale r, g, b;
+ Curve c;
+
+ public override Widget ConfigurationWidget ()
+ {
+ VBox h = new VBox ();
+ r = new HScale (0, 100, 1);
+ r.ModifyBg (StateType.Selected, new Color (0xff, 0, 0));
+ r.Value = 80;
+ r.ValueChanged += SettingsChanged;
+ h.Add (r);
+ g = new HScale (0, 100, 1);
+ g.ModifyBg (StateType.Selected, new Color (0, 0xff, 0));
+ g.Value = 10;
+ g.ValueChanged += SettingsChanged;
+ h.Add (g);
+ b = new HScale (0, 100, 1);
+ b.ModifyBg (StateType.Selected, new Color (0, 0, 0xff));
+ b.Value = 10;
+ b.ValueChanged += SettingsChanged;
+ h.Add (b);
+ c = new Curve ();
+ c.CurveType = CurveType.Spline;
+ c.SetRange (0, 255, 0, 255);
+ h.Add (c);
+ Button btn = new Button (Gtk.Stock.Refresh);
+ btn.Clicked += delegate {UpdatePreview ();};
+ h.Add (btn);
+ return h;
+ }
+
+ void SettingsChanged (object sender, EventArgs e)
+ {
+ UpdatePreview ();
+ }
+ }
+}
diff --git a/extensions/Editors/BWEditor/Makefile b/extensions/Editors/BWEditor/Makefile
new file mode 100644
index 0000000..629472b
--- /dev/null
+++ b/extensions/Editors/BWEditor/Makefile
@@ -0,0 +1,30 @@
+all: BWEditor.dll
+
+PACKAGES = \
+ -pkg:f-spot \
+ -pkg:gtk-sharp-2.0
+
+ASSEMBLIES = \
+ -r:Mono.Posix \
+ -r:Mono.Simd
+
+RESOURCES = \
+ -resource:BWEditor.addin.xml
+
+SOURCES = \
+ BWEditor.cs
+
+install: all
+ cp *.dll ~/.config/f-spot/addins/
+
+mpack: BWEditor.dll
+ mautil p BWEditor.dll
+
+BWEditor.dll: $(SOURCES) BWEditor.addin.xml
+ gmcs -target:library -unsafe $(SOURCES) $(PACKAGES) $(ASSEMBLIES) $(RESOURCES)
+
+clean:
+ rm -f *.dll *~ *.bak .mpack
+
+PHONY:
+ install clean all mpack
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]