-
Notifications
You must be signed in to change notification settings - Fork 265
/
SoftenPortraitEffect.cs
129 lines (104 loc) · 4.6 KB
/
SoftenPortraitEffect.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/////////////////////////////////////////////////////////////////////////////////
// Paint.NET //
// Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors. //
// Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
// See license-pdn.txt for full licensing and attribution details. //
// //
// Ported to Pinta by: Krzystzof Marecki //
/////////////////////////////////////////////////////////////////////////////////
// This effect was graciously provided by David Issel, aka BoltBait. His original
// copyright and license (MIT License) are reproduced below.
/*
PortraitEffect.cs
Copyright (c) 2007 David Issel
Contact Info: BoltBait@hotmail.com http://www.BoltBait.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
using System;
using Cairo;
using Pinta.Gui.Widgets;
using Pinta.Effects;
using Pinta.Core;
using Mono.Unix;
namespace Pinta.Effects
{
//[System.ComponentModel.Composition.Export (typeof (BaseEffect))]
public class SoftenPortraitEffect : BaseEffect
{
private GaussianBlurEffect blurEffect;
private BrightnessContrastEffect bacAdjustment;
private UnaryPixelOps.Desaturate desaturateOp;
private UserBlendOps.OverlayBlendOp overlayOp;
public override string Icon {
get { return "Menu.Effects.Photo.SoftenPortrait.png"; }
}
public override string Text {
get { return Catalog.GetString ("Soften Portrait"); }
}
public override bool IsConfigurable {
get { return true; }
}
public override string EffectMenuCategory {
get { return Catalog.GetString ("Photo"); }
}
public SoftenPortraitData Data { get { return EffectData as SoftenPortraitData; } }
public SoftenPortraitEffect ()
{
EffectData = new SoftenPortraitData ();
blurEffect = new GaussianBlurEffect ();
bacAdjustment = new BrightnessContrastEffect ();
desaturateOp = new UnaryPixelOps.Desaturate ();
overlayOp = new UserBlendOps.OverlayBlendOp ();
}
public override bool LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
}
public unsafe override void RenderEffect (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
{
int warmth = Data.Warmth;
float redAdjust = 1.0f + (warmth / 100.0f);
float blueAdjust = 1.0f - (warmth / 100.0f);
this.blurEffect.RenderEffect(src, dest, rois);
this.bacAdjustment.RenderEffect(src, dest, rois);
foreach (Gdk.Rectangle roi in rois) {
for (int y = roi.Top; y < roi.Bottom; ++y) {
ColorBgra* srcPtr = src.GetPointAddress(roi.X, y);
ColorBgra* dstPtr = dest.GetPointAddress(roi.X, y);
for (int x = roi.Left; x < roi.Right; ++x) {
ColorBgra srcGrey = this.desaturateOp.Apply(*srcPtr);
srcGrey.R = Utility.ClampToByte((int)((float)srcGrey.R * redAdjust));
srcGrey.B = Utility.ClampToByte((int)((float)srcGrey.B * blueAdjust));
ColorBgra mypixel = this.overlayOp.Apply(srcGrey, *dstPtr);
*dstPtr = mypixel;
++srcPtr;
++dstPtr;
}
}
}
}
}
public class SoftenPortraitData : EffectData
{
[MinimumValue (0), MaximumValue (10)]
public int Softness = 5;
[MinimumValue (-20), MaximumValue (20)]
public int Lighting = 0;
[MinimumValue (0), MaximumValue (20)]
public int Warmth = 10;
}
}