5
// Krzysztof Marecki <marecki.krzysztof@gmail.com>
7
// Copyright (c) 2010 Krzysztof Marecki
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
using Pinta.Gui.Widgets;
33
public class EdgeDetectEffect : ColorDifferenceEffect
35
private double[][] weights;
37
public override string Icon {
38
get { return "Menu.Effects.Stylize.EdgeDetect.png"; }
41
public override string Text {
42
get { return Mono.Unix.Catalog.GetString ("Edge Detect"); }
45
public override bool IsConfigurable {
49
public EdgeDetectData Data { get { return EffectData as EdgeDetectData; } }
51
public EdgeDetectEffect ()
53
EffectData = new EdgeDetectData ();
56
public override bool LaunchConfiguration ()
58
return EffectHelper.LaunchSimpleEffectDialog (this);
61
public unsafe override void RenderEffect (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
64
base.RenderColorDifferenceEffect (weights, src, dest, rois);
67
private void SetWeights ()
69
weights = new double[3][];
70
for (int i = 0; i < this.weights.Length; ++i) {
71
this.weights[i] = new double[3];
74
// adjust and convert angle to radians
75
double r = (double)Data.Angle * 2.0 * Math.PI / 360.0;
77
// angle delta for each weight
78
double dr = Math.PI / 4.0;
80
// for r = 0 this builds an edge detect filter pointing straight left
82
this.weights[0][0] = Math.Cos(r + dr);
83
this.weights[0][1] = Math.Cos(r + 2.0 * dr);
84
this.weights[0][2] = Math.Cos(r + 3.0 * dr);
86
this.weights[1][0] = Math.Cos(r);
87
this.weights[1][1] = 0;
88
this.weights[1][2] = Math.Cos(r + 4.0 * dr);
90
this.weights[2][0] = Math.Cos(r - dr);
91
this.weights[2][1] = Math.Cos(r - 2.0 * dr);
92
this.weights[2][2] = Math.Cos(r - 3.0 * dr);
96
public class EdgeDetectData : EffectData
98
public double Angle = 45;