Browse Source

First working version

Former-commit-id: 9a29900c60ed46679ec35b19764f2716a071cdcc
Former-commit-id: 5d27440cde0a1b795322f33df43c1e23a5686158
Former-commit-id: 94ca246cfdf0d6ad960284d4dcd626632d15c300
pull/1/head
Sverre Rekvin 10 years ago
parent
commit
d6fd816ad9
  1. 26
      src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs
  2. 2
      src/ImageProcessorCore/Samplers/Rotate.cs
  3. 2
      tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

26
src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs

@ -41,10 +41,6 @@ namespace ImageProcessorCore
}
}
/// <summary>
/// Gets or sets the center point.
/// </summary>
public Point Center { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to expand the canvas to fit the rotated image.
@ -54,22 +50,12 @@ namespace ImageProcessorCore
/// <inheritdoc/>
protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle)
{
// If we are expanding we need to pad the bounds of the source rectangle.
// We can use the resizer in nearest neighbor mode to do this fairly quickly.
if (this.Expand)
{
// First find out how big the target rectangle should be.
Point centre = this.Center == Point.Empty ? Rectangle.Center(sourceRectangle) : this.Center;
Point centre = Rectangle.Center(sourceRectangle);
Matrix3x2 rotation = Point.CreateRotation(centre, -this.angle);
Rectangle rectangle = ImageMaths.GetBoundingRectangle(sourceRectangle, rotation);
ResizeOptions options = new ResizeOptions
{
Size = new Size(rectangle.Width, rectangle.Height),
Mode = ResizeMode.BoxPad
};
// Get the padded bounds and resize the image.
Rectangle bounds = ResizeHelper.CalculateTargetLocationAndBounds(source, options);
target.SetPixels(rectangle.Width, rectangle.Height, new float[rectangle.Width * rectangle.Height * 4]);
}
}
@ -78,14 +64,10 @@ namespace ImageProcessorCore
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
Point centre = Rectangle.Center(source.Bounds);
Matrix3x2 rotation = Point.CreateRotation(centre, -this.angle);
rotation = Point.CreateRotation(new Point(0,0), -this.angle);
Matrix3x2 tran =Matrix3x2.CreateTranslation(-target.Width/2, -target.Height/2);
Matrix3x2 rotation = Point.CreateRotation(new Point(0,0), -this.angle);
Matrix3x2 tran =Matrix3x2.CreateTranslation(-target.Width/2f, -target.Height/2f);
rotation = tran* rotation;
Matrix3x2 tran2 = Matrix3x2.CreateTranslation(source.Width / 2, source.Height / 2);
Matrix3x2 tran2 = Matrix3x2.CreateTranslation(source.Width / 2f, source.Height / 2f);
rotation = rotation*tran2;

2
src/ImageProcessorCore/Samplers/Rotate.cs

@ -33,7 +33,7 @@ namespace ImageProcessorCore
/// <returns>The <see cref="Image"/></returns>
public static Image Rotate(this Image source, float degrees, Point center, bool expand, ProgressEventHandler progressHandler = null)
{
RotateProcessor processor = new RotateProcessor { Angle = degrees, Center = center, Expand = expand };
RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand };
processor.OnProgress += progressHandler;
try

2
tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

@ -471,7 +471,7 @@
using (Image image = new Image(stream))
using (FileStream output = File.OpenWrite($"TestOutput/Rotate/{filename}"))
{
image.Rotate(63, this.ProgressUpdate)
image.Rotate(20, this.ProgressUpdate)
.Save(output);
}

Loading…
Cancel
Save