Browse Source

Use Size

af/merge-core
James Jackson-South 8 years ago
parent
commit
74ee173fc0
  1. 4
      src/ImageSharp/DefaultInternalImageProcessorContext.cs
  2. 4
      src/ImageSharp/IImageProcessingContext{TPixel}.cs
  3. 6
      src/ImageSharp/Processing/Transforms/Resize.cs
  4. 2
      src/ImageSharp/Processing/Transforms/Rotate.cs
  5. 2
      src/ImageSharp/Processing/Transforms/Skew.cs
  6. 4
      src/ImageSharp/Processing/Transforms/Transform.cs
  7. 4
      tests/ImageSharp.Tests/FakeImageOperationsProvider.cs
  8. 30
      tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs

4
src/ImageSharp/DefaultInternalImageProcessorContext.cs

@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp
} }
/// <inheritdoc/> /// <inheritdoc/>
public Rectangle Bounds() => this.destination?.Bounds() ?? this.source.Bounds(); public Size GetCurrentSize() => this.destination?.Size() ?? this.source.Size();
/// <inheritdoc/> /// <inheritdoc/>
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle) public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle)
@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp
/// <inheritdoc/> /// <inheritdoc/>
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor) public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor)
{ {
return this.ApplyProcessor(processor, this.Bounds()); return this.ApplyProcessor(processor, this.source.Bounds());
} }
} }
} }

4
src/ImageSharp/IImageProcessingContext{TPixel}.cs

@ -22,10 +22,10 @@ namespace SixLabors.ImageSharp
MemoryManager MemoryManager { get; } MemoryManager MemoryManager { get; }
/// <summary> /// <summary>
/// Gets the image bounds at the current point in the processing pipeline. /// Gets the image dimensions at the current point in the processing pipeline.
/// </summary> /// </summary>
/// <returns>The <see cref="Rectangle"/></returns> /// <returns>The <see cref="Rectangle"/></returns>
Rectangle Bounds(); Size GetCurrentSize();
/// <summary> /// <summary>
/// Adds the processor to the current set of image operations to be applied. /// Adds the processor to the current set of image operations to be applied.

6
src/ImageSharp/Processing/Transforms/Resize.cs

@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp
/// <remarks>Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image</remarks> /// <remarks>Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image</remarks>
public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, ResizeOptions options) public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, ResizeOptions options)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new ResizeProcessor<TPixel>(options, source.Bounds().Size)); => source.ApplyProcessor(new ResizeProcessor<TPixel>(options, source.GetCurrentSize()));
/// <summary> /// <summary>
/// Resizes an image to the given <see cref="Size"/>. /// Resizes an image to the given <see cref="Size"/>.
@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp
Rectangle targetRectangle, Rectangle targetRectangle,
bool compand) bool compand)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new ResizeProcessor<TPixel>(sampler, width, height, source.Bounds().Size, targetRectangle, compand), sourceRectangle); => source.ApplyProcessor(new ResizeProcessor<TPixel>(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand), sourceRectangle);
/// <summary> /// <summary>
/// Resizes an image to the given width and height with the given sampler and source rectangle. /// Resizes an image to the given width and height with the given sampler and source rectangle.
@ -171,6 +171,6 @@ namespace SixLabors.ImageSharp
Rectangle targetRectangle, Rectangle targetRectangle,
bool compand) bool compand)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new ResizeProcessor<TPixel>(sampler, width, height, source.Bounds().Size, targetRectangle, compand)); => source.ApplyProcessor(new ResizeProcessor<TPixel>(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand));
} }
} }

2
src/ImageSharp/Processing/Transforms/Rotate.cs

@ -44,6 +44,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> Rotate<TPixel>(this IImageProcessingContext<TPixel> source, float degrees, IResampler sampler) public static IImageProcessingContext<TPixel> Rotate<TPixel>(this IImageProcessingContext<TPixel> source, float degrees, IResampler sampler)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new RotateProcessor<TPixel>(degrees, sampler, source.Bounds().Size)); => source.ApplyProcessor(new RotateProcessor<TPixel>(degrees, sampler, source.GetCurrentSize()));
} }
} }

2
src/ImageSharp/Processing/Transforms/Skew.cs

@ -35,6 +35,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> Skew<TPixel>(this IImageProcessingContext<TPixel> source, float degreesX, float degreesY, IResampler sampler) public static IImageProcessingContext<TPixel> Skew<TPixel>(this IImageProcessingContext<TPixel> source, float degreesX, float degreesY, IResampler sampler)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new SkewProcessor<TPixel>(degreesX, degreesY, sampler, source.Bounds().Size)); => source.ApplyProcessor(new SkewProcessor<TPixel>(degreesX, degreesY, sampler, source.GetCurrentSize()));
} }
} }

4
src/ImageSharp/Processing/Transforms/Transform.cs

@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, Matrix3x2 matrix, IResampler sampler) public static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, Matrix3x2 matrix, IResampler sampler)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Transform(source, matrix, sampler, source.Bounds()); => source.ApplyProcessor(new AffineTransformProcessor<TPixel>(matrix, sampler, source.GetCurrentSize()));
/// <summary> /// <summary>
/// Transforms an image by the given matrix using the specified sampling algorithm /// Transforms an image by the given matrix using the specified sampling algorithm
@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
internal static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix, IResampler sampler) internal static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix, IResampler sampler)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Transform(source, matrix, sampler, source.Bounds()); => source.ApplyProcessor(new ProjectiveTransformProcessor<TPixel>(matrix, sampler, source.GetCurrentSize()));
/// <summary> /// <summary>
/// Applies a projective transform to the image by the given matrix using the specified sampling algorithm. /// Applies a projective transform to the image by the given matrix using the specified sampling algorithm.

4
tests/ImageSharp.Tests/FakeImageOperationsProvider.cs

@ -61,9 +61,9 @@ namespace SixLabors.ImageSharp.Tests
return this.Source; return this.Source;
} }
public Rectangle Bounds() public Size GetCurrentSize()
{ {
return this.Source.Bounds(); return this.Source.Size();
} }
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle) public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle)

30
tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Tests
public class ImageProcessingContextTests public class ImageProcessingContextTests
{ {
[Fact] [Fact]
public void MutatedBoundsAreAccuratePerOperation() public void MutatedSizeIsAccuratePerOperation()
{ {
var x500 = new Size(500, 500); var x500 = new Size(500, 500);
var x400 = new Size(400, 400); var x400 = new Size(400, 400);
@ -19,16 +19,16 @@ namespace SixLabors.ImageSharp.Tests
using (var image = new Image<Rgba32>(500, 500)) using (var image = new Image<Rgba32>(500, 500))
{ {
image.Mutate(x => image.Mutate(x =>
x.AssertBounds(x500) x.AssertSize(x500)
.Resize(x400).AssertBounds(x400) .Resize(x400).AssertSize(x400)
.Resize(x300).AssertBounds(x300) .Resize(x300).AssertSize(x300)
.Resize(x200).AssertBounds(x200) .Resize(x200).AssertSize(x200)
.Resize(x100).AssertBounds(x100)); .Resize(x100).AssertSize(x100));
} }
} }
[Fact] [Fact]
public void ClonedBoundsAreAccuratePerOperation() public void ClonedSizeIsAccuratePerOperation()
{ {
var x500 = new Size(500, 500); var x500 = new Size(500, 500);
var x400 = new Size(400, 400); var x400 = new Size(400, 400);
@ -38,20 +38,20 @@ namespace SixLabors.ImageSharp.Tests
using (var image = new Image<Rgba32>(500, 500)) using (var image = new Image<Rgba32>(500, 500))
{ {
image.Clone(x => image.Clone(x =>
x.AssertBounds(x500) x.AssertSize(x500)
.Resize(x400).AssertBounds(x400) .Resize(x400).AssertSize(x400)
.Resize(x300).AssertBounds(x300) .Resize(x300).AssertSize(x300)
.Resize(x200).AssertBounds(x200) .Resize(x200).AssertSize(x200)
.Resize(x100).AssertBounds(x100)); .Resize(x100).AssertSize(x100));
} }
} }
} }
public static class BoundsAssertationExtensions public static class SizeAssertationExtensions
{ {
public static IImageProcessingContext<Rgba32> AssertBounds(this IImageProcessingContext<Rgba32> context, Size size) public static IImageProcessingContext<Rgba32> AssertSize(this IImageProcessingContext<Rgba32> context, Size size)
{ {
Assert.Equal(size, context.Bounds().Size); Assert.Equal(size, context.GetCurrentSize());
return context; return context;
} }
} }

Loading…
Cancel
Save