-
-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable & optimized memory management #475
Changes from 67 commits
72772ff
607e452
c5eb2cf
a73283f
9e4e5ab
b1a5c71
333ce3b
f675f5c
f1412d3
2451168
58330a1
58ab4e6
9290536
2615556
4e4cdd5
cf13ebf
76dc5c2
54313e8
b23b137
750af5a
7e3cb28
22206f1
80e5fe3
af23153
7a076de
967098b
3819c75
2ea9e08
29483b3
cf96e61
e666609
739cec3
7db4cdc
58d187f
77e524d
4e515a8
f390569
d6c196b
f23e849
ae52170
fa0ae3c
76633c9
2fa0994
a85cc51
7210a89
d29ef1a
6e1736d
6a40926
52c482e
be325d8
bcd33b6
62f8ba2
e64f1d5
2be566b
ba5e80f
d1872c5
65918d1
45cca93
7b62fbc
8d351f3
0684c93
eeaa270
e2694d3
9368d3e
110e3c7
88be834
48a3189
c07cbea
4d915b6
de67364
d721138
1b0a2b4
7d5cea1
c314db6
5b9b27c
55d2184
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,17 +61,14 @@ private class SolidBrushApplicator : BrushApplicator<TPixel> | |
public SolidBrushApplicator(ImageFrame<TPixel> source, TPixel color, GraphicsOptions options) | ||
: base(source, options) | ||
{ | ||
this.Colors = new Buffer<TPixel>(source.Width); | ||
for (int i = 0; i < this.Colors.Length; i++) | ||
{ | ||
this.Colors[i] = color; | ||
} | ||
this.Colors = source.MemoryManager.Allocate<TPixel>(source.Width); | ||
this.Colors.Span.Fill(color); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the colors. | ||
/// </summary> | ||
protected Buffer<TPixel> Colors { get; } | ||
protected IBuffer<TPixel> Colors { get; } | ||
|
||
/// <summary> | ||
/// Gets the color for a single pixel. | ||
|
@@ -81,7 +78,7 @@ public SolidBrushApplicator(ImageFrame<TPixel> source, TPixel color, GraphicsOpt | |
/// <returns> | ||
/// The color | ||
/// </returns> | ||
internal override TPixel this[int x, int y] => this.Colors[x]; | ||
internal override TPixel this[int x, int y] => this.Colors.Span[x]; | ||
|
||
/// <inheritdoc /> | ||
public override void Dispose() | ||
|
@@ -96,18 +93,23 @@ internal override void Apply(Span<float> scanline, int x, int y) | |
{ | ||
Span<TPixel> destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); | ||
|
||
using (var amountBuffer = new Buffer<float>(scanline.Length)) | ||
MemoryManager memoryManager = this.Target.MemoryManager; | ||
|
||
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length)) | ||
{ | ||
Span<float> amountSpan = amountBuffer.Span; | ||
|
||
for (int i = 0; i < scanline.Length; i++) | ||
{ | ||
amountBuffer[i] = scanline[i] * this.Options.BlendPercentage; | ||
amountSpan[i] = scanline[i] * this.Options.BlendPercentage; | ||
} | ||
|
||
this.Blender.Blend(destinationRow, destinationRow, this.Colors, amountBuffer); | ||
this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, amountSpan); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
// TODO: Why are we catching exceptions here silently ??? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was probably a hangover from the old |
||
throw; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,18 +46,17 @@ public override int Scan(float y, float[] buffer, int offset) | |
{ | ||
var start = new PointF(this.Bounds.Left - 1, y); | ||
var end = new PointF(this.Bounds.Right + 1, y); | ||
using (var innerBuffer = new Buffer<PointF>(buffer.Length)) | ||
{ | ||
PointF[] array = innerBuffer.Array; | ||
int count = this.Shape.FindIntersections(start, end, array, 0); | ||
|
||
for (int i = 0; i < count; i++) | ||
{ | ||
buffer[i + offset] = array[i].X; | ||
} | ||
// TODO: This is a temporal workaround because of the lack of Span<T> API-s on IPath. We should use MemoryManager.Allocate() here! | ||
PointF[] innerBuffer = new PointF[buffer.Length]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's get a PR in place against Shapes to add those API's. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do it now, or in a follow up PR pair? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do a follow up once we've done Shapes. |
||
int count = this.Shape.FindIntersections(start, end, innerBuffer, 0); | ||
|
||
return count; | ||
for (int i = 0; i < count; i++) | ||
{ | ||
buffer[i + offset] = innerBuffer[i].X; | ||
} | ||
|
||
return count; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know
Span
had aFill
method. Neat!