mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
// <copyright file="Crop.cs" company="James Jackson-South">
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
|
|
namespace ImageProcessorCore.Samplers
|
|
{
|
|
using System.Threading.Tasks;
|
|
|
|
/// <summary>
|
|
/// Provides methods to allow the cropping of an image.
|
|
/// </summary>
|
|
public class Crop : ImageSampler
|
|
{
|
|
/// <inheritdoc/>
|
|
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
|
|
{
|
|
int targetY = targetRectangle.Y;
|
|
int targetBottom = targetRectangle.Bottom;
|
|
int startX = targetRectangle.X;
|
|
int endX = targetRectangle.Right;
|
|
int sourceX = sourceRectangle.X;
|
|
int sourceY = sourceRectangle.Y;
|
|
|
|
Parallel.For(
|
|
startY,
|
|
endY,
|
|
y =>
|
|
{
|
|
if (y >= targetY && y < targetBottom)
|
|
{
|
|
for (int x = startX; x < endX; x++)
|
|
{
|
|
target[x, y] = source[x + sourceX, y + sourceY];
|
|
}
|
|
|
|
this.OnRowProcessed();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|