3
3
// Copyright (C) Rick Brewster, Tom Jackson, and past contributors. //
4
4
// Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
5
// See src/Resources/Files/License.txt for full licensing and attribution //
5
// See license-pdn.txt for full licensing and attribution details. //
8
6
/////////////////////////////////////////////////////////////////////////////////
11
9
using System.Threading;
13
12
namespace Pinta.Core
16
/// Defines a way to operate on a pixel, or a region of pixels, in a unary fashion.
17
/// That is, it is a simple function F that takes one parameter and returns a
18
/// result of the form: d = F(c)
21
public unsafe abstract class UnaryPixelOp
24
public abstract ColorBgra Apply(ColorBgra color);
26
public unsafe override void Apply(ColorBgra *dst, ColorBgra *src, int length)
40
public unsafe virtual void Apply(ColorBgra* ptr, int length)
53
// private unsafe void ApplyRectangle(Surface surface, Rectangle rect)
55
// for (int y = rect.Top; y < rect.Bottom; ++y)
57
// ColorBgra *ptr = surface.GetPointAddress(rect.Left, y);
58
// Apply(ptr, rect.Width);
62
// public void Apply(Surface surface, Rectangle[] roi, int startIndex, int length)
64
// Rectangle regionBounds = Utility.GetRegionBounds(roi, startIndex, length);
66
// if (regionBounds != Rectangle.Intersect(surface.Bounds, regionBounds))
68
// throw new ArgumentOutOfRangeException("roi", "Region is out of bounds");
73
// for (int x = startIndex; x < startIndex + length; ++x)
75
// ApplyRectangle(surface, roi[x]);
80
// public void Apply(Surface surface, Rectangle[] roi)
82
// Apply(surface, roi, 0, roi.Length);
85
// public void Apply(Surface surface, RectangleF[] roiF, int startIndex, int length)
87
// Rectangle regionBounds = Rectangle.Truncate(Utility.GetRegionBounds(roiF, startIndex, length));
89
// if (regionBounds != Rectangle.Intersect(surface.Bounds, regionBounds))
91
// throw new ArgumentOutOfRangeException("roiF", "Region is out of bounds");
96
// for (int x = startIndex; x < startIndex + length; ++x)
98
// ApplyRectangle(surface, Rectangle.Truncate(roiF[x]));
103
// public void Apply(Surface surface, RectangleF[] roiF)
105
// Apply(surface, roiF, 0, roiF.Length);
108
// public unsafe void Apply(Surface surface, Rectangle roi)
110
// ApplyRectangle(surface, roi);
113
// public void Apply(Surface surface, Scanline scan)
115
// Apply(surface.GetPointAddress(scan.X, scan.Y), scan.Length);
118
// public void Apply(Surface surface, Scanline[] scans)
120
// foreach (Scanline scan in scans)
122
// Apply(surface, scan);
126
// public override void Apply(Surface dst, Point dstOffset, Surface src, Point srcOffset, int scanLength)
128
// Apply(dst.GetPointAddress(dstOffset), src.GetPointAddress(srcOffset), scanLength);
131
// public void Apply(Surface dst, Surface src, Rectangle roi)
133
// for (int y = roi.Top; y < roi.Bottom; ++y)
135
// ColorBgra *dstPtr = dst.GetPointAddress(roi.Left, y);
136
// ColorBgra *srcPtr = src.GetPointAddress(roi.Left, y);
137
// Apply(dstPtr, srcPtr, roi.Width);
141
// public void Apply(Surface surface, PdnRegion roi)
143
// Apply(surface, roi.GetRegionScansReadOnlyInt());
146
public UnaryPixelOp()
15
/// Defines a way to operate on a pixel, or a region of pixels, in a unary fashion.
16
/// That is, it is a simple function F that takes one parameter and returns a
17
/// result of the form: d = F(c)
20
public unsafe abstract class UnaryPixelOp : PixelOp
22
public UnaryPixelOp ()
26
public abstract ColorBgra Apply (ColorBgra color);
28
public unsafe override void Apply (ColorBgra* dst, ColorBgra* src, int length)
40
public unsafe virtual void Apply (ColorBgra* ptr, int length)
51
private unsafe void ApplyRectangle (ImageSurface surface, Gdk.Rectangle rect)
53
for (int y = rect.Left; y < rect.Bottom; ++y) {
54
ColorBgra* ptr = surface.GetPointAddress (rect.Left, y);
55
Apply (ptr, rect.Width);
59
public void Apply (ImageSurface surface, Gdk.Rectangle[] roi, int startIndex, int length)
61
Gdk.Rectangle regionBounds = Utility.GetRegionBounds (roi, startIndex, length);
63
if (regionBounds != Gdk.Rectangle.Intersect (surface.GetBounds (), regionBounds))
64
throw new ArgumentOutOfRangeException ("roi", "Region is out of bounds");
67
for (int x = startIndex; x < startIndex + length; ++x)
68
ApplyRectangle (surface, roi[x]);
72
public void Apply (ImageSurface surface, Gdk.Rectangle[] roi)
74
Apply (surface, roi, 0, roi.Length);
77
public unsafe void Apply (ImageSurface surface, Gdk.Rectangle roi)
79
ApplyRectangle (surface, roi);
82
public override void Apply (ImageSurface dst, Gdk.Point dstOffset, ImageSurface src, Gdk.Point srcOffset, int scanLength)
84
Apply (dst.GetPointAddress (dstOffset), src.GetPointAddress (srcOffset), scanLength);
87
public void Apply (ImageSurface dst, ImageSurface src, Gdk.Rectangle roi)
89
for (int y = roi.Y; y < roi.Bottom; ++y) {
90
ColorBgra* dstPtr = dst.GetPointAddressUnchecked (roi.X, y);
91
ColorBgra* srcPtr = src.GetPointAddressUnchecked (roi.X, y);
92
Apply (dstPtr, srcPtr, roi.Width);
96
public void Apply (ImageSurface dst, ImageSurface src, Gdk.Rectangle[] rois)
98
foreach (Gdk.Rectangle roi in rois)
99
Apply (dst, src, roi);