~paolorotolo/pinta/fix-for-1093971

« back to all changes in this revision

Viewing changes to Pinta/ConfigurableEffects/EdgeDetectEffect.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields, Jo Shields, Iain Lane
  • Date: 2010-07-06 07:09:12 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100706070912-da3ughgbrph20vav
Tags: 0.4+dfsg-1
[ Jo Shields ]
* New upstream release
* +DFSG release of Pinta 0.4. Deleted files:
  + ./Pinta.Gui.Widgets/bin/Debug/Pinta.Gui.Widgets.dll
* debian/rules:
  + Switch to entirely minimal DH7 rules file, since the Automake
    wrapper for xbuild handles things we were having to do by hand
* debian/pinta.sh,
  debian/pinta.desktop,
  debian/pinta.xpm,
  debian/pinta.install:
  + Upstream now takes care of providing an icon and a .desktop file,
    and DH7 takes care of putting everything where it should be, so
    all these files have been deleted
* debian/copyright:
  + Updated (thanks to Maia Kozheva <sikon@ubuntu.com>)

[ Iain Lane ]
* [a8be0d2] Remove BD on libglade2.0-cil-dev; no longer necessary
* [41bfc27] debian/watch: Mangle version for +dfsg
* [9c1ad07] Standards-Version → 3.9.0, no changes required
* [0232079] Work around buggy upstream make clean target, fixing
  double build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// EdgeDetectEffect.cs
3
 
//  
4
 
// Author:
5
 
//       Krzysztof Marecki <marecki.krzysztof@gmail.com>
6
 
// 
7
 
// Copyright (c) 2010 Krzysztof Marecki
8
 
// 
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:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
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
25
 
// THE SOFTWARE.
26
 
using System;
27
 
using Cairo;
28
 
 
29
 
using Pinta.Gui.Widgets;
30
 
 
31
 
namespace Pinta.Core
32
 
{
33
 
        public class EdgeDetectEffect : ColorDifferenceEffect
34
 
        {
35
 
                private double[][] weights;
36
 
                
37
 
                public override string Icon {
38
 
                        get { return "Menu.Effects.Stylize.EdgeDetect.png"; }
39
 
                }
40
 
 
41
 
                public override string Text {
42
 
                        get { return Mono.Unix.Catalog.GetString ("Edge Detect"); }
43
 
                }
44
 
 
45
 
                public override bool IsConfigurable {
46
 
                        get { return true; }
47
 
                }
48
 
 
49
 
                public EdgeDetectData Data { get { return EffectData as EdgeDetectData; } }
50
 
                
51
 
                public EdgeDetectEffect ()
52
 
                {
53
 
                        EffectData = new EdgeDetectData ();
54
 
                }
55
 
                
56
 
                public override bool LaunchConfiguration ()
57
 
                {
58
 
                        return EffectHelper.LaunchSimpleEffectDialog (this);
59
 
                }
60
 
                
61
 
                public unsafe override void RenderEffect (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
62
 
                {
63
 
                        SetWeights ();
64
 
                        base.RenderColorDifferenceEffect (weights, src, dest, rois);
65
 
                }
66
 
                
67
 
                private void SetWeights ()
68
 
                {
69
 
                        weights = new double[3][];
70
 
            for (int i = 0; i < this.weights.Length; ++i) {
71
 
                this.weights[i] = new double[3];
72
 
            }
73
 
 
74
 
            // adjust and convert angle to radians
75
 
            double r = (double)Data.Angle * 2.0 * Math.PI / 360.0;
76
 
 
77
 
            // angle delta for each weight
78
 
            double dr = Math.PI / 4.0;
79
 
 
80
 
            // for r = 0 this builds an edge detect filter pointing straight left
81
 
 
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);
85
 
 
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);
89
 
 
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);
93
 
                }
94
 
        }
95
 
        
96
 
        public class EdgeDetectData : EffectData
97
 
        {
98
 
                public double Angle = 45;
99
 
        }
100
 
}