5
// Krzysztof Marecki <marecki.krzysztof@gmail.com>
7
// Copyright (c) 2010 Jonathan Pobst
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
28
using System.Collections.Generic;
29
using System.ComponentModel;
35
public class CurvesEffect : BaseEffect
37
private SortedList<int, int>[] control_points;
38
private ColorTransferMode mode;
40
public override string Icon {
41
get { return "Menu.Adjustments.Curves.png"; }
44
public override string Text {
45
get { return Mono.Unix.Catalog.GetString ("Curves"); }
48
public override bool IsConfigurable {
52
public override bool LaunchConfiguration ()
54
CurvesDialog dialog = new CurvesDialog ();
55
dialog.Icon = PintaCore.Resources.GetIcon (Icon);
56
int response = dialog.Run ();
58
if (response == (int)Gtk.ResponseType.Ok) {
60
control_points = dialog.ControlPoints;
71
public override void RenderEffect (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
73
UnaryPixelOp op = MakeUop ();
75
op.Apply (dest, src, rois);
78
private UnaryPixelOp MakeUop()
81
byte[][] transferCurves;
85
case ColorTransferMode.Rgb:
86
UnaryPixelOps.ChannelCurve cc = new UnaryPixelOps.ChannelCurve();
87
transferCurves = new byte[][] { cc.CurveR, cc.CurveG, cc.CurveB };
92
case ColorTransferMode.Luminosity:
93
UnaryPixelOps.LuminosityCurve lc = new UnaryPixelOps.LuminosityCurve();
94
transferCurves = new byte[][] { lc.Curve };
100
throw new InvalidEnumArgumentException();
104
int channels = transferCurves.Length;
106
for (int channel = 0; channel < channels; channel++) {
107
SortedList<int, int> channelControlPoints = control_points[channel];
108
IList<int> xa = channelControlPoints.Keys;
109
IList<int> ya = channelControlPoints.Values;
110
SplineInterpolator interpolator = new SplineInterpolator();
111
int length = channelControlPoints.Count;
113
for (int i = 0; i < length; i++) {
114
interpolator.Add(xa[i], ya[i]);
117
for (int i = 0; i < entries; i++) {
118
transferCurves[channel][i] = Utility.ClampToByte(interpolator.Interpolate(i));