Skip to content

Commit

Permalink
Merge pull request #350 from SixLabors/js/issue-348
Browse files Browse the repository at this point in the history
RecolorBrush  - Limit access to target dimensions
  • Loading branch information
JimBobSquarePants authored Jan 8, 2025
2 parents 888d8b8 + 51173a8 commit 435aae4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ImageSharp.Drawing.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATE", "ISSUE_TEMPLATE", "{FBE8C1AD-5AEC-4514-9B64-091D8E145865}"
ProjectSection(SolutionItems) = preProject
.github\ISSUE_TEMPLATE\config.yml = .github\ISSUE_TEMPLATE\config.yml
.github\ISSUE_TEMPLATE\oss-bug-report.md = .github\ISSUE_TEMPLATE\oss-bug-report.md
.github\ISSUE_TEMPLATE\oss-bug-report.yml = .github\ISSUE_TEMPLATE\oss-bug-report.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}"
Expand Down
11 changes: 9 additions & 2 deletions src/ImageSharp.Drawing/Processing/RecolorBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,15 @@ public RecolorBrushApplicator(
/// <inheritdoc />
public override void Apply(Span<float> scanline, int x, int y)
{
Span<float> amounts = this.blenderBuffers.AmountSpan.Slice(0, scanline.Length);
Span<TPixel> overlays = this.blenderBuffers.OverlaySpan.Slice(0, scanline.Length);
if (x < 0 || y < 0 || x >= this.Target.Width || y >= this.Target.Height)
{
return;
}

// Limit the scanline to the bounds of the image relative to x.
scanline = scanline[..Math.Min(this.Target.Width - x, scanline.Length)];
Span<float> amounts = this.blenderBuffers.AmountSpan[..scanline.Length];
Span<TPixel> overlays = this.blenderBuffers.OverlaySpan[..scanline.Length];

for (int i = 0; i < scanline.Length; i++)
{
Expand Down

0 comments on commit 435aae4

Please sign in to comment.