Browse Source

Transforms

af/merge-core
James Jackson-South 8 years ago
parent
commit
fe64365532
  1. 7
      src/ImageSharp/Image/ImageFrameCollection.cs
  2. 2
      src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs
  3. 2
      src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs
  4. 2
      src/ImageSharp/Processing/Processors/CloningImageProcessor.cs
  5. 2
      src/ImageSharp/Processing/Transforms/AnchorPosition.cs
  6. 8
      src/ImageSharp/Processing/Transforms/AutoOrientExtensions.cs
  7. 6
      src/ImageSharp/Processing/Transforms/BicubicResampler.cs
  8. 4
      src/ImageSharp/Processing/Transforms/BoxResampler.cs
  9. 4
      src/ImageSharp/Processing/Transforms/CatmullRomResampler.cs
  10. 13
      src/ImageSharp/Processing/Transforms/CropExtensions.cs
  11. 26
      src/ImageSharp/Processing/Transforms/EntropyCrop.cs
  12. 35
      src/ImageSharp/Processing/Transforms/EntropyCropExtensions.cs
  13. 12
      src/ImageSharp/Processing/Transforms/FlipExtensions.cs
  14. 4
      src/ImageSharp/Processing/Transforms/FlipType.cs
  15. 4
      src/ImageSharp/Processing/Transforms/HermiteResampler.cs
  16. 4
      src/ImageSharp/Processing/Transforms/IResampler.cs
  17. 4
      src/ImageSharp/Processing/Transforms/Lanczos2Resampler.cs
  18. 4
      src/ImageSharp/Processing/Transforms/Lanczos3Resampler.cs
  19. 4
      src/ImageSharp/Processing/Transforms/Lanczos5Resampler.cs
  20. 4
      src/ImageSharp/Processing/Transforms/Lanczos8Resampler.cs
  21. 4
      src/ImageSharp/Processing/Transforms/MitchellNetravaliResampler.cs
  22. 4
      src/ImageSharp/Processing/Transforms/NearestNeighborResampler.cs
  23. 4
      src/ImageSharp/Processing/Transforms/OrientationType.cs
  24. 9
      src/ImageSharp/Processing/Transforms/PadExtensions.cs
  25. 6
      src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs
  26. 40
      src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs
  27. 6
      src/ImageSharp/Processing/Transforms/Processors/CenteredAffineTransformProcessor.cs
  28. 2
      src/ImageSharp/Processing/Transforms/Processors/CenteredProjectiveTransformProcessor.cs
  29. 53
      src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs
  30. 43
      src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs
  31. 8
      src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs
  32. 4
      src/ImageSharp/Processing/Transforms/Processors/InterpolatedTransformProcessorBase.cs
  33. 4
      src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs
  34. 36
      src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs
  35. 3
      src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs
  36. 2
      src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs
  37. 3
      src/ImageSharp/Processing/Transforms/Processors/TransformProcessorBase.cs
  38. 2
      src/ImageSharp/Processing/Transforms/Resamplers.cs
  39. 29
      src/ImageSharp/Processing/Transforms/ResizeExtensions.cs
  40. 2
      src/ImageSharp/Processing/Transforms/ResizeHelper.cs
  41. 2
      src/ImageSharp/Processing/Transforms/ResizeMode.cs
  42. 4
      src/ImageSharp/Processing/Transforms/ResizeOptions.cs
  43. 4
      src/ImageSharp/Processing/Transforms/RobidouxResampler.cs
  44. 4
      src/ImageSharp/Processing/Transforms/RobidouxSharpResampler.cs
  45. 15
      src/ImageSharp/Processing/Transforms/RotateExtensions.cs
  46. 14
      src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs
  47. 4
      src/ImageSharp/Processing/Transforms/RotateType.cs
  48. 13
      src/ImageSharp/Processing/Transforms/SkewExtensions.cs
  49. 4
      src/ImageSharp/Processing/Transforms/SplineResampler.cs
  50. 13
      src/ImageSharp/Processing/Transforms/TransformExtensions.cs
  51. 2
      src/ImageSharp/Processing/Transforms/TransformHelpers.cs
  52. 4
      src/ImageSharp/Processing/Transforms/TriangleResampler.cs
  53. 2
      src/ImageSharp/Processing/Transforms/WelchResampler.cs
  54. 3
      tests/ImageSharp.Benchmarks/Samplers/Crop.cs
  55. 1
      tests/ImageSharp.Benchmarks/Samplers/Resize.cs
  56. 1
      tests/ImageSharp.Tests/ComplexIntegrationTests.cs
  57. 2
      tests/ImageSharp.Tests/Drawing/DrawImageTest.cs
  58. 1
      tests/ImageSharp.Tests/Drawing/FillPatternTests.cs
  59. 1
      tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
  60. 1
      tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs
  61. 1
      tests/ImageSharp.Tests/Image/ImageRotationTests.cs
  62. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs
  63. 1
      tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs
  64. 1
      tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs
  65. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs
  66. 1
      tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs
  67. 3
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs
  68. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  69. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs
  70. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs
  71. 1
      tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs
  72. 4
      tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs
  73. 4
      tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs
  74. 19
      tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs
  75. 18
      tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs
  76. 5
      tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs
  77. 3
      tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs
  78. 5
      tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs
  79. 9
      tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs
  80. 3
      tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs
  81. 3
      tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs
  82. 2
      tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs
  83. 1
      tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs

7
src/ImageSharp/Image/ImageFrameCollection.cs

@ -10,7 +10,7 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp
{ {
/// <summary> /// <summary>
/// Encapsulates an imaged collection of frames. /// Encapsulates a collection of frames that make up an image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the pixel.</typeparam> /// <typeparam name="TPixel">The type of the pixel.</typeparam>
internal sealed class ImageFrameCollection<TPixel> : IImageFrameCollection<TPixel> internal sealed class ImageFrameCollection<TPixel> : IImageFrameCollection<TPixel>
@ -51,10 +51,7 @@ namespace SixLabors.ImageSharp
public ImageFrame<TPixel> RootFrame => this.frames.Count > 0 ? this.frames[0] : null; public ImageFrame<TPixel> RootFrame => this.frames.Count > 0 ? this.frames[0] : null;
/// <inheritdoc/> /// <inheritdoc/>
public ImageFrame<TPixel> this[int index] public ImageFrame<TPixel> this[int index] => this.frames[index];
{
get => this.frames[index];
}
/// <inheritdoc/> /// <inheritdoc/>
public int IndexOf(ImageFrame<TPixel> frame) => this.frames.IndexOf(frame); public int IndexOf(ImageFrame<TPixel> frame) => this.frames.IndexOf(frame);

2
src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors
/// Initializes a new instance of the <see cref="GaussianBlurProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="GaussianBlurProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param> /// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
public GaussianBlurProcessor(float sigma = 3f) public GaussianBlurProcessor(float sigma = 3F)
{ {
this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1; this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1;
this.Sigma = sigma; this.Sigma = sigma;

2
src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors
/// <param name="sigma"> /// <param name="sigma">
/// The 'sigma' value representing the weight of the sharpening. /// The 'sigma' value representing the weight of the sharpening.
/// </param> /// </param>
public GaussianSharpenProcessor(float sigma = 3f) public GaussianSharpenProcessor(float sigma = 3F)
{ {
this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1; this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1;
this.Sigma = sigma; this.Sigma = sigma;

2
src/ImageSharp/Processing/Processors/CloningImageProcessor.cs

@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
#else #else
catch (Exception ex) catch (Exception ex)
{ {
throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); throw new ImageProcessingException($"An error occurred when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex);
#endif #endif
} }
} }

2
src/ImageSharp/Processing/Transforms/Options/AnchorPosition.cs → src/ImageSharp/Processing/Transforms/AnchorPosition.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Enumerated anchor positions to apply to resized images. /// Enumerated anchor positions to apply to resized images.

8
src/ImageSharp/Processing/Transforms/AutoOrient.cs → src/ImageSharp/Processing/Transforms/AutoOrientExtensions.cs

@ -2,14 +2,14 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Transforms.Processors;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of auto-orientation operations to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class AutoOrientExtensions
{ {
/// <summary> /// <summary>
/// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image. /// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image.

6
src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs → src/ImageSharp/Processing/Transforms/BicubicResampler.cs

@ -1,12 +1,12 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the bicubic kernel algorithm W(x) as described on /// The function implements the bicubic kernel algorithm W(x) as described on
/// <see href="https://en.wikipedia.org/wiki/Bicubic_interpolation#Bicubic_convolution_algorithm">Wikipedia</see> /// <see href="https://en.wikipedia.org/wiki/Bicubic_interpolation#Bicubic_convolution_algorithm">Wikipedia</see>
/// A commonly used algorithm within imageprocessing that preserves sharpness better than triangle interpolation. /// A commonly used algorithm within image processing that preserves sharpness better than triangle interpolation.
/// </summary> /// </summary>
public class BicubicResampler : IResampler public class BicubicResampler : IResampler
{ {
@ -38,4 +38,4 @@ namespace SixLabors.ImageSharp.Processing
return result; return result;
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs → src/ImageSharp/Processing/Transforms/BoxResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the box algorithm. Similar to nearest neighbor when upscaling. /// The function implements the box algorithm. Similar to nearest neighbor when upscaling.
@ -23,4 +23,4 @@ namespace SixLabors.ImageSharp.Processing
return 0; return 0;
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs → src/ImageSharp/Processing/Transforms/CatmullRomResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The Catmull-Rom filter is a well known standard Cubic Filter often used as a interpolation function. /// The Catmull-Rom filter is a well known standard Cubic Filter often used as a interpolation function.
@ -23,4 +23,4 @@ namespace SixLabors.ImageSharp.Processing
return ImageMaths.GetBcValue(x, B, C); return ImageMaths.GetBcValue(x, B, C);
} }
} }
} }

13
src/ImageSharp/Processing/Transforms/Crop.cs → src/ImageSharp/Processing/Transforms/CropExtensions.cs

@ -1,17 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of cropping operations to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class CropExtensions
{ {
/// <summary> /// <summary>
/// Crops an image to the given width and height. /// Crops an image to the given width and height.
@ -23,7 +22,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> Crop<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height) public static IImageProcessingContext<TPixel> Crop<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Crop(source, new Rectangle(0, 0, width, height)); => Crop(source, new Rectangle(0, 0, width, height));
/// <summary> /// <summary>
/// Crops an image to the given rectangle. /// Crops an image to the given rectangle.
@ -36,6 +35,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> Crop<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle cropRectangle) public static IImageProcessingContext<TPixel> Crop<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle cropRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new CropProcessor<TPixel>(cropRectangle)); => source.ApplyProcessor(new CropProcessor<TPixel>(cropRectangle));
} }
} }

26
src/ImageSharp/Processing/Transforms/EntropyCrop.cs

@ -1,26 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
namespace SixLabors.ImageSharp
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Crops an image to the area of greatest entropy.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to crop.</param>
/// <param name="threshold">The threshold for entropic density.</param>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> EntropyCrop<TPixel>(this IImageProcessingContext<TPixel> source, float threshold = .5f)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new EntropyCropProcessor<TPixel>(threshold));
}
}

35
src/ImageSharp/Processing/Transforms/EntropyCropExtensions.cs

@ -0,0 +1,35 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Transforms.Processors;
namespace SixLabors.ImageSharp.Processing.Transforms
{
/// <summary>
/// Adds extensions that allow the application of entropy cropping operations to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static class EntropyCropExtensions
{
/// <summary>
/// Crops an image to the area of greatest entropy using a threshold for entropic density of <value>.5F</value>.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to crop.</param>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> EntropyCrop<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new EntropyCropProcessor<TPixel>());
/// <summary>
/// Crops an image to the area of greatest entropy.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to crop.</param>
/// <param name="threshold">The threshold for entropic density.</param>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> EntropyCrop<TPixel>(this IImageProcessingContext<TPixel> source, float threshold)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new EntropyCropProcessor<TPixel>(threshold));
}
}

12
src/ImageSharp/Processing/Transforms/Flip.cs → src/ImageSharp/Processing/Transforms/FlipExtensions.cs

@ -1,17 +1,15 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.ImageSharp.Processing.Processors;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of flipping operations to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class FlipExtensions
{ {
/// <summary> /// <summary>
/// Flips an image by the given instructions. /// Flips an image by the given instructions.
@ -22,6 +20,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> Flip<TPixel>(this IImageProcessingContext<TPixel> source, FlipType flipType) public static IImageProcessingContext<TPixel> Flip<TPixel>(this IImageProcessingContext<TPixel> source, FlipType flipType)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new FlipProcessor<TPixel>(flipType)); => source.ApplyProcessor(new FlipProcessor<TPixel>(flipType));
} }
} }

4
src/ImageSharp/Processing/Transforms/Options/FlipType.cs → src/ImageSharp/Processing/Transforms/FlipType.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Provides enumeration over how a image should be flipped. /// Provides enumeration over how a image should be flipped.
@ -23,4 +23,4 @@ namespace SixLabors.ImageSharp.Processing
/// </summary> /// </summary>
Vertical, Vertical,
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs → src/ImageSharp/Processing/Transforms/HermiteResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The Hermite filter is type of smoothed triangular interpolation Filter, /// The Hermite filter is type of smoothed triangular interpolation Filter,
@ -22,4 +22,4 @@ namespace SixLabors.ImageSharp.Processing
return ImageMaths.GetBcValue(x, B, C); return ImageMaths.GetBcValue(x, B, C);
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs → src/ImageSharp/Processing/Transforms/IResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Encapsulates an interpolation algorithm for resampling images. /// Encapsulates an interpolation algorithm for resampling images.
@ -22,4 +22,4 @@ namespace SixLabors.ImageSharp.Processing
/// </returns> /// </returns>
float GetValue(float x); float GetValue(float x);
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs → src/ImageSharp/Processing/Transforms/Lanczos2Resampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the Lanczos kernel algorithm as described on /// The function implements the Lanczos kernel algorithm as described on
@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing
return 0F; return 0F;
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs → src/ImageSharp/Processing/Transforms/Lanczos3Resampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the Lanczos kernel algorithm as described on /// The function implements the Lanczos kernel algorithm as described on
@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing
return 0F; return 0F;
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs → src/ImageSharp/Processing/Transforms/Lanczos5Resampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the Lanczos kernel algorithm as described on /// The function implements the Lanczos kernel algorithm as described on
@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing
return 0F; return 0F;
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs → src/ImageSharp/Processing/Transforms/Lanczos8Resampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the Lanczos kernel algorithm as described on /// The function implements the Lanczos kernel algorithm as described on
@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing
return 0F; return 0F;
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs → src/ImageSharp/Processing/Transforms/MitchellNetravaliResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the mitchell algorithm as described on /// The function implements the mitchell algorithm as described on
@ -21,4 +21,4 @@ namespace SixLabors.ImageSharp.Processing
return ImageMaths.GetBcValue(x, B, C); return ImageMaths.GetBcValue(x, B, C);
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs → src/ImageSharp/Processing/Transforms/NearestNeighborResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the nearest neighbor algorithm. This uses an unscaled filter /// The function implements the nearest neighbor algorithm. This uses an unscaled filter
@ -18,4 +18,4 @@ namespace SixLabors.ImageSharp.Processing
return x; return x;
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Options/Orientation.cs → src/ImageSharp/Processing/Transforms/OrientationType.cs

@ -1,12 +1,12 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Enumerates the available orientation values supplied by EXIF metadata. /// Enumerates the available orientation values supplied by EXIF metadata.
/// </summary> /// </summary>
internal enum Orientation : ushort internal enum OrientationType : ushort
{ {
/// <summary> /// <summary>
/// Unknown rotation. /// Unknown rotation.

9
src/ImageSharp/Processing/Transforms/Pad.cs → src/ImageSharp/Processing/Transforms/PadExtensions.cs

@ -2,15 +2,14 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of padding operations to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class PadExtensions
{ {
/// <summary> /// <summary>
/// Evenly pads an image to fit the new dimensions. /// Evenly pads an image to fit the new dimensions.
@ -30,7 +29,7 @@ namespace SixLabors.ImageSharp
Sampler = Resamplers.NearestNeighbor Sampler = Resamplers.NearestNeighbor
}; };
return Resize(source, options); return source.Resize(options);
} }
} }
} }

6
src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs

@ -12,7 +12,7 @@ using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// Provides the base methods to perform affine transforms on an image. /// Provides the base methods to perform affine transforms on an image.
@ -208,8 +208,6 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// The <see cref="Matrix3x2"/>. /// The <see cref="Matrix3x2"/>.
/// </returns> /// </returns>
protected virtual Matrix3x2 GetProcessingMatrix(Rectangle sourceRectangle, Rectangle destinationRectangle) protected virtual Matrix3x2 GetProcessingMatrix(Rectangle sourceRectangle, Rectangle destinationRectangle)
{ => this.TransformMatrix;
return this.TransformMatrix;
}
} }
} }

40
src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs

@ -6,7 +6,7 @@ using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image. /// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image.
@ -18,42 +18,42 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <inheritdoc/> /// <inheritdoc/>
protected override void BeforeImageApply(Image<TPixel> source, Rectangle sourceRectangle) protected override void BeforeImageApply(Image<TPixel> source, Rectangle sourceRectangle)
{ {
Orientation orientation = GetExifOrientation(source); OrientationType orientation = GetExifOrientation(source);
Size size = sourceRectangle.Size; Size size = sourceRectangle.Size;
switch (orientation) switch (orientation)
{ {
case Orientation.TopRight: case OrientationType.TopRight:
new FlipProcessor<TPixel>(FlipType.Horizontal).Apply(source, sourceRectangle); new FlipProcessor<TPixel>(FlipType.Horizontal).Apply(source, sourceRectangle);
break; break;
case Orientation.BottomRight: case OrientationType.BottomRight:
new RotateProcessor<TPixel>((int)RotateType.Rotate180, size).Apply(source, sourceRectangle); new RotateProcessor<TPixel>((int)RotateType.Rotate180, size).Apply(source, sourceRectangle);
break; break;
case Orientation.BottomLeft: case OrientationType.BottomLeft:
new FlipProcessor<TPixel>(FlipType.Vertical).Apply(source, sourceRectangle); new FlipProcessor<TPixel>(FlipType.Vertical).Apply(source, sourceRectangle);
break; break;
case Orientation.LeftTop: case OrientationType.LeftTop:
new RotateProcessor<TPixel>((int)RotateType.Rotate90, size).Apply(source, sourceRectangle); new RotateProcessor<TPixel>((int)RotateType.Rotate90, size).Apply(source, sourceRectangle);
new FlipProcessor<TPixel>(FlipType.Horizontal).Apply(source, sourceRectangle); new FlipProcessor<TPixel>(FlipType.Horizontal).Apply(source, sourceRectangle);
break; break;
case Orientation.RightTop: case OrientationType.RightTop:
new RotateProcessor<TPixel>((int)RotateType.Rotate90, size).Apply(source, sourceRectangle); new RotateProcessor<TPixel>((int)RotateType.Rotate90, size).Apply(source, sourceRectangle);
break; break;
case Orientation.RightBottom: case OrientationType.RightBottom:
new FlipProcessor<TPixel>(FlipType.Vertical).Apply(source, sourceRectangle); new FlipProcessor<TPixel>(FlipType.Vertical).Apply(source, sourceRectangle);
new RotateProcessor<TPixel>((int)RotateType.Rotate270, size).Apply(source, sourceRectangle); new RotateProcessor<TPixel>((int)RotateType.Rotate270, size).Apply(source, sourceRectangle);
break; break;
case Orientation.LeftBottom: case OrientationType.LeftBottom:
new RotateProcessor<TPixel>((int)RotateType.Rotate270, size).Apply(source, sourceRectangle); new RotateProcessor<TPixel>((int)RotateType.Rotate270, size).Apply(source, sourceRectangle);
break; break;
case Orientation.Unknown: case OrientationType.Unknown:
case Orientation.TopLeft: case OrientationType.TopLeft:
default: default:
break; break;
} }
@ -62,39 +62,39 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> sourceBase, Rectangle sourceRectangle, Configuration config) protected override void OnFrameApply(ImageFrame<TPixel> sourceBase, Rectangle sourceRectangle, Configuration config)
{ {
// all processing happens at the image level within BeforeImageApply(); // All processing happens at the image level within BeforeImageApply();
} }
/// <summary> /// <summary>
/// Returns the current EXIF orientation /// Returns the current EXIF orientation
/// </summary> /// </summary>
/// <param name="source">The image to auto rotate.</param> /// <param name="source">The image to auto rotate.</param>
/// <returns>The <see cref="Orientation"/></returns> /// <returns>The <see cref="OrientationType"/></returns>
private static Orientation GetExifOrientation(Image<TPixel> source) private static OrientationType GetExifOrientation(Image<TPixel> source)
{ {
if (source.MetaData.ExifProfile == null) if (source.MetaData.ExifProfile == null)
{ {
return Orientation.Unknown; return OrientationType.Unknown;
} }
ExifValue value = source.MetaData.ExifProfile.GetValue(ExifTag.Orientation); ExifValue value = source.MetaData.ExifProfile.GetValue(ExifTag.Orientation);
if (value == null) if (value == null)
{ {
return Orientation.Unknown; return OrientationType.Unknown;
} }
Orientation orientation; OrientationType orientation;
if (value.DataType == ExifDataType.Short) if (value.DataType == ExifDataType.Short)
{ {
orientation = (Orientation)value.Value; orientation = (OrientationType)value.Value;
} }
else else
{ {
orientation = (Orientation)Convert.ToUInt16(value.Value); orientation = (OrientationType)Convert.ToUInt16(value.Value);
source.MetaData.ExifProfile.RemoveValue(ExifTag.Orientation); source.MetaData.ExifProfile.RemoveValue(ExifTag.Orientation);
} }
source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft); source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)OrientationType.TopLeft);
return orientation; return orientation;
} }

6
src/ImageSharp/Processing/Transforms/Processors/CenteredAffineTransformProcessor.cs

@ -5,7 +5,7 @@ using System.Numerics;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// A base class that provides methods to allow the automatic centering of affine transforms /// A base class that provides methods to allow the automatic centering of affine transforms
@ -27,9 +27,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <inheritdoc/> /// <inheritdoc/>
protected override Matrix3x2 GetProcessingMatrix(Rectangle sourceRectangle, Rectangle destinationRectangle) protected override Matrix3x2 GetProcessingMatrix(Rectangle sourceRectangle, Rectangle destinationRectangle)
{ => TransformHelpers.GetCenteredTransformMatrix(sourceRectangle, destinationRectangle, this.TransformMatrix);
return TransformHelpers.GetCenteredTransformMatrix(sourceRectangle, destinationRectangle, this.TransformMatrix);
}
private static Size GetTransformedDimensions(Size sourceDimensions, Matrix3x2 matrix) private static Size GetTransformedDimensions(Size sourceDimensions, Matrix3x2 matrix)
{ {

2
src/ImageSharp/Processing/Transforms/Processors/CenteredProjectiveTransformProcessor.cs

@ -5,7 +5,7 @@ using System.Numerics;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// A base class that provides methods to allow the automatic centering of non-affine transforms /// A base class that provides methods to allow the automatic centering of non-affine transforms

53
src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs

@ -2,20 +2,21 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
// TODO: Convert this into a cloning processor inheriting TransformProcessor once Anton's memory PR is merged namespace SixLabors.ImageSharp.Processing.Transforms.Processors
namespace SixLabors.ImageSharp.Processing.Processors
{ {
/// <summary> /// <summary>
/// Provides methods to allow the cropping of an image. /// Provides methods to allow the cropping of an image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class CropProcessor<TPixel> : ImageProcessor<TPixel> internal class CropProcessor<TPixel> : TransformProcessorBase<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
@ -33,10 +34,23 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Rectangle CropRectangle { get; } public Rectangle CropRectangle { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override Image<TPixel> CreateDestination(Image<TPixel> source, Rectangle sourceRectangle)
{ {
if (this.CropRectangle == sourceRectangle) // We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select(x => new ImageFrame<TPixel>(source.GetMemoryManager(), this.CropRectangle.Width, this.CropRectangle.Height, x.MetaData.Clone()));
// Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames);
}
/// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source, ImageFrame<TPixel> destination, Rectangle sourceRectangle, Configuration configuration)
{
// Handle resize dimensions identical to the original
if (source.Width == destination.Width && source.Height == destination.Height && sourceRectangle == this.CropRectangle)
{ {
// the cloned will be blank here copy all the pixel data over
source.GetPixelSpan().CopyTo(destination.GetPixelSpan());
return; return;
} }
@ -45,25 +59,16 @@ namespace SixLabors.ImageSharp.Processing.Processors
int minX = Math.Max(this.CropRectangle.X, sourceRectangle.X); int minX = Math.Max(this.CropRectangle.X, sourceRectangle.X);
int maxX = Math.Min(this.CropRectangle.Right, sourceRectangle.Right); int maxX = Math.Min(this.CropRectangle.Right, sourceRectangle.Right);
using (Buffer2D<TPixel> targetPixels = configuration.MemoryManager.Allocate2D<TPixel>(this.CropRectangle.Size)) Parallel.For(
{ minY,
Parallel.For( maxY,
minY, configuration.ParallelOptions,
maxY, y =>
configuration.ParallelOptions, {
y => Span<TPixel> sourceRow = source.GetPixelRowSpan(y).Slice(minX);
{ Span<TPixel> targetRow = destination.GetPixelRowSpan(y - minY);
Span<TPixel> sourceRow = source.GetPixelRowSpan(y).Slice(minX); SpanHelper.Copy(sourceRow, targetRow, maxX - minX);
Span<TPixel> targetRow = targetPixels.GetRowSpan(y - minY); });
SpanHelper.Copy(sourceRow, targetRow, maxX - minX);
});
Buffer2D<TPixel>.SwapContents(source.PixelBuffer, targetPixels);
}
} }
/// <inheritdoc/>
protected override void AfterImageApply(Image<TPixel> source, Rectangle sourceRectangle)
=> TransformHelpers.UpdateDimensionalMetData(source);
} }
} }

43
src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs

@ -1,22 +1,29 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Binarization.Processors; using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.ImageSharp.Processing.Convolution.Processors; using SixLabors.ImageSharp.Processing.Convolution.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// Provides methods to allow the cropping of an image to preserve areas of highest /// Provides methods to allow the cropping of an image to preserve areas of highest entropy.
/// entropy.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class EntropyCropProcessor<TPixel> : ImageProcessor<TPixel> internal class EntropyCropProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary>
/// Initializes a new instance of the <see cref="EntropyCropProcessor{TPixel}"/> class.
/// </summary>
public EntropyCropProcessor()
: this(.5F)
{
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="EntropyCropProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="EntropyCropProcessor{TPixel}"/> class.
/// </summary> /// </summary>
@ -26,20 +33,25 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// </exception> /// </exception>
public EntropyCropProcessor(float threshold) public EntropyCropProcessor(float threshold)
{ {
Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold)); Guard.MustBeBetweenOrEqualTo(threshold, 0, 1F, nameof(threshold));
this.Threshold = threshold; this.Threshold = threshold;
} }
/// <summary> /// <summary>
/// Gets the threshold value. /// Gets the entropy threshold value.
/// </summary> /// </summary>
public float Threshold { get; } public float Threshold { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void BeforeImageApply(Image<TPixel> source, Rectangle sourceRectangle)
{ {
using (ImageFrame<TPixel> temp = source.Clone()) Rectangle rectangle;
// All frames have be the same size so we only need to calculate the correct dimensions for the first frame
using (ImageFrame<TPixel> temp = source.Frames.RootFrame.Clone())
{ {
Configuration configuration = source.GetConfiguration();
// Detect the edges. // Detect the edges.
new SobelProcessor<TPixel>(false).Apply(temp, sourceRectangle, configuration); new SobelProcessor<TPixel>(false).Apply(temp, sourceRectangle, configuration);
@ -47,15 +59,16 @@ namespace SixLabors.ImageSharp.Processing.Processors
new BinaryThresholdProcessor<TPixel>(this.Threshold).Apply(temp, sourceRectangle, configuration); new BinaryThresholdProcessor<TPixel>(this.Threshold).Apply(temp, sourceRectangle, configuration);
// Search for the first white pixels // Search for the first white pixels
Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0); rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0);
}
if (rectangle == sourceRectangle) new CropProcessor<TPixel>(rectangle).Apply(source, sourceRectangle);
{ }
return;
}
new CropProcessor<TPixel>(rectangle).Apply(source, sourceRectangle, configuration); /// <inheritdoc/>
} protected override void OnFrameApply(ImageFrame<TPixel> sourceBase, Rectangle sourceRectangle, Configuration config)
{
// All processing happens at the image level within BeforeImageApply();
} }
} }
} }

8
src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs

@ -9,7 +9,7 @@ using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// Provides methods that allow the flipping of an image around its center point. /// Provides methods that allow the flipping of an image around its center point.
@ -48,8 +48,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
} }
/// <summary> /// <summary>
/// Swaps the image at the X-axis, which goes horizontally through the middle /// Swaps the image at the X-axis, which goes horizontally through the middle at half the height of the image.
/// at half the height of the image.
/// </summary> /// </summary>
/// <param name="source">The source image to apply the process to.</param> /// <param name="source">The source image to apply the process to.</param>
/// <param name="configuration">The configuration.</param> /// <param name="configuration">The configuration.</param>
@ -81,8 +80,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
} }
/// <summary> /// <summary>
/// Swaps the image at the Y-axis, which goes vertically through the middle /// Swaps the image at the Y-axis, which goes vertically through the middle at half of the width of the image.
/// at half of the width of the image.
/// </summary> /// </summary>
/// <param name="source">The source image to apply the process to.</param> /// <param name="source">The source image to apply the process to.</param>
/// <param name="configuration">The configuration.</param> /// <param name="configuration">The configuration.</param>

4
src/ImageSharp/Processing/Transforms/Processors/InterpolatedTransformProcessorBase.cs

@ -5,7 +5,7 @@ using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// The base class for performing interpolated affine and non-affine transforms. /// The base class for performing interpolated affine and non-affine transforms.
@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <summary> /// <summary>
/// Calculated the weights for the given point. /// Calculated the weights for the given point.
/// This method uses more samples than the upscaled version to ensure edge pixels are correctly rendered. /// This method uses more samples than the upscaled version to ensure edge pixels are correctly rendered.
/// Additionally the weights are nomalized. /// Additionally the weights are normalized.
/// </summary> /// </summary>
/// <param name="min">The minimum sampling offset</param> /// <param name="min">The minimum sampling offset</param>
/// <param name="max">The maximum sampling offset</param> /// <param name="max">The maximum sampling offset</param>

4
src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs

@ -12,11 +12,11 @@ using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors // TODO: Doesn't work yet! Implement tests + Finish implementation + Document Matrix4x4 behavior
namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// Provides the base methods to perform non-affine transforms on an image. /// Provides the base methods to perform non-affine transforms on an image.
/// TODO: Doesn't work yet! Implement tests + Finish implementation + Document Matrix4x4 behavior
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class ProjectiveTransformProcessor<TPixel> : InterpolatedTransformProcessorBase<TPixel> internal class ProjectiveTransformProcessor<TPixel> : InterpolatedTransformProcessorBase<TPixel>

36
src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs

@ -10,9 +10,10 @@ using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// Provides methods that allow the resizing of images using various algorithms. /// Provides methods that allow the resizing of images using various algorithms.
@ -212,38 +213,39 @@ namespace SixLabors.ImageSharp.Processing.Processors
protected override Image<TPixel> CreateDestination(Image<TPixel> source, Rectangle sourceRectangle) protected override Image<TPixel> CreateDestination(Image<TPixel> source, Rectangle sourceRectangle)
{ {
// We will always be creating the clone even for mutate because we may need to resize the canvas // We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select(x => new ImageFrame<TPixel>(source.GetMemoryManager(), this.Width, this.Height, x.MetaData.Clone())); // this will create places holders IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select(x => new ImageFrame<TPixel>(source.GetMemoryManager(), this.Width, this.Height, x.MetaData.Clone()));
// Use the overload to prevent an extra frame being added // Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames); return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames);
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void BeforeFrameApply(ImageFrame<TPixel> source, ImageFrame<TPixel> destination, Rectangle sourceRectangle, Configuration configuration) protected override void BeforeImageApply(Image<TPixel> source, Image<TPixel> destination, Rectangle sourceRectangle)
{ {
if (!(this.Sampler is NearestNeighborResampler)) if (!(this.Sampler is NearestNeighborResampler))
{ {
// TODO: Optimization opportunity: if we could assume that all frames are of the same size, we can move this into 'BeforeImageApply()` // Since all image frame dimensions have to be the same we can calculate this for all frames.
MemoryManager memoryManager = source.GetMemoryManager();
this.horizontalWeights = this.PrecomputeWeights( this.horizontalWeights = this.PrecomputeWeights(
source.MemoryManager, memoryManager,
this.ResizeRectangle.Width, this.ResizeRectangle.Width,
sourceRectangle.Width); sourceRectangle.Width);
this.verticalWeights = this.PrecomputeWeights( this.verticalWeights = this.PrecomputeWeights(
source.MemoryManager, memoryManager,
this.ResizeRectangle.Height, this.ResizeRectangle.Height,
sourceRectangle.Height); sourceRectangle.Height);
} }
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source, ImageFrame<TPixel> cloned, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, ImageFrame<TPixel> destination, Rectangle sourceRectangle, Configuration configuration)
{ {
// Jump out, we'll deal with that later. // Handle resize dimensions identical to the original
if (source.Width == cloned.Width && source.Height == cloned.Height && sourceRectangle == this.ResizeRectangle) if (source.Width == destination.Width && source.Height == destination.Height && sourceRectangle == this.ResizeRectangle)
{ {
// the cloned will be blank here copy all the pixel data over // the cloned will be blank here copy all the pixel data over
source.GetPixelSpan().CopyTo(cloned.GetPixelSpan()); source.GetPixelSpan().CopyTo(destination.GetPixelSpan());
return; return;
} }
@ -275,7 +277,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
{ {
// Y coordinates of source points // Y coordinates of source points
Span<TPixel> sourceRow = source.GetPixelRowSpan((int)(((y - startY) * heightFactor) + sourceY)); Span<TPixel> sourceRow = source.GetPixelRowSpan((int)(((y - startY) * heightFactor) + sourceY));
Span<TPixel> targetRow = cloned.GetPixelRowSpan(y); Span<TPixel> targetRow = destination.GetPixelRowSpan(y);
for (int x = minX; x < maxX; x++) for (int x = minX; x < maxX; x++)
{ {
@ -336,18 +338,18 @@ namespace SixLabors.ImageSharp.Processing.Processors
{ {
// Ensure offsets are normalized for cropping and padding. // Ensure offsets are normalized for cropping and padding.
WeightsWindow window = this.verticalWeights.Weights[y - startY]; WeightsWindow window = this.verticalWeights.Weights[y - startY];
Span<TPixel> targetRow = cloned.GetPixelRowSpan(y); Span<TPixel> targetRow = destination.GetPixelRowSpan(y);
if (this.Compand) if (this.Compand)
{ {
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
// Destination color components // Destination color components
Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); Vector4 destinationVector = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY);
destination = destination.Compress(); destinationVector = destinationVector.Compress();
ref TPixel pixel = ref targetRow[x]; ref TPixel pixel = ref targetRow[x];
pixel.PackFromVector4(destination); pixel.PackFromVector4(destinationVector);
} }
} }
else else
@ -355,10 +357,10 @@ namespace SixLabors.ImageSharp.Processing.Processors
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
// Destination color components // Destination color components
Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); Vector4 destinationVector = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY);
ref TPixel pixel = ref targetRow[x]; ref TPixel pixel = ref targetRow[x];
pixel.PackFromVector4(destination); pixel.PackFromVector4(destinationVector);
} }
} }
}); });

3
src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs

@ -3,13 +3,14 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// Provides methods that allow the rotating of images. /// Provides methods that allow the rotating of images.

2
src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs

@ -4,7 +4,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// Provides methods that allow the skewing of images. /// Provides methods that allow the skewing of images.

3
src/ImageSharp/Processing/Transforms/Processors/TransformProcessorBase.cs

@ -2,9 +2,10 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
/// <summary> /// <summary>
/// The base class for all transform processors. Any processor that changes the dimensions of the image should inherit from this. /// The base class for all transform processors. Any processor that changes the dimensions of the image should inherit from this.

2
src/ImageSharp/Processing/Transforms/Resamplers/Resamplers.cs → src/ImageSharp/Processing/Transforms/Resamplers.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Contains reusable static instances of known resampling algorithms /// Contains reusable static instances of known resampling algorithms

29
src/ImageSharp/Processing/Transforms/Resize.cs → src/ImageSharp/Processing/Transforms/ResizeExtensions.cs

@ -2,16 +2,15 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of resize operations to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class ResizeExtensions
{ {
/// <summary> /// <summary>
/// Resizes an image in accordance with the given <see cref="ResizeOptions"/>. /// Resizes an image in accordance with the given <see cref="ResizeOptions"/>.
@ -23,7 +22,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.GetCurrentSize())); => 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"/>.
@ -35,7 +34,7 @@ namespace SixLabors.ImageSharp
/// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks> /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, Size size) public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, Size size)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Resize(source, size.Width, size.Height, Resamplers.Bicubic, false); => Resize(source, size.Width, size.Height, Resamplers.Bicubic, false);
/// <summary> /// <summary>
/// Resizes an image to the given <see cref="Size"/>. /// Resizes an image to the given <see cref="Size"/>.
@ -48,7 +47,7 @@ namespace SixLabors.ImageSharp
/// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks> /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, Size size, bool compand) public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, Size size, bool compand)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Resize(source, size.Width, size.Height, Resamplers.Bicubic, compand); => Resize(source, size.Width, size.Height, Resamplers.Bicubic, compand);
/// <summary> /// <summary>
/// Resizes an image to the given width and height. /// Resizes an image to the given width and height.
@ -61,7 +60,7 @@ namespace SixLabors.ImageSharp
/// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks> /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height) public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Resize(source, width, height, Resamplers.Bicubic, false); => Resize(source, width, height, Resamplers.Bicubic, false);
/// <summary> /// <summary>
/// Resizes an image to the given width and height. /// Resizes an image to the given width and height.
@ -75,7 +74,7 @@ namespace SixLabors.ImageSharp
/// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks> /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height, bool compand) public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height, bool compand)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Resize(source, width, height, Resamplers.Bicubic, compand); => Resize(source, width, height, Resamplers.Bicubic, compand);
/// <summary> /// <summary>
/// Resizes an image to the given width and height with the given sampler. /// Resizes an image to the given width and height with the given sampler.
@ -89,7 +88,7 @@ namespace SixLabors.ImageSharp
/// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks> /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height, IResampler sampler) public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height, IResampler sampler)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Resize(source, width, height, sampler, false); => Resize(source, width, height, sampler, false);
/// <summary> /// <summary>
/// Resizes an image to the given width and height with the given sampler. /// Resizes an image to the given width and height with the given sampler.
@ -103,7 +102,7 @@ namespace SixLabors.ImageSharp
/// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks> /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, Size size, IResampler sampler, bool compand) public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, Size size, IResampler sampler, bool compand)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Resize(source, size.Width, size.Height, sampler, new Rectangle(0, 0, size.Width, size.Height), compand); => Resize(source, size.Width, size.Height, sampler, new Rectangle(0, 0, size.Width, size.Height), compand);
/// <summary> /// <summary>
/// Resizes an image to the given width and height with the given sampler. /// Resizes an image to the given width and height with the given sampler.
@ -118,7 +117,7 @@ namespace SixLabors.ImageSharp
/// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks> /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height, IResampler sampler, bool compand) public static IImageProcessingContext<TPixel> Resize<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height, IResampler sampler, bool compand)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Resize(source, width, height, sampler, new Rectangle(0, 0, width, height), compand); => Resize(source, width, height, sampler, new Rectangle(0, 0, width, height), compand);
/// <summary> /// <summary>
/// Resizes an image to the given width and height with the given sampler and /// Resizes an image to the given width and height with the given sampler and
@ -147,7 +146,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.GetCurrentSize(), 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 +170,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.GetCurrentSize(), targetRectangle, compand)); => source.ApplyProcessor(new ResizeProcessor<TPixel>(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand));
} }
} }

2
src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs → src/ImageSharp/Processing/Transforms/ResizeHelper.cs

@ -5,7 +5,7 @@ using System;
using System.Linq; using System.Linq;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Provides methods to help calculate the target rectangle when resizing using the /// Provides methods to help calculate the target rectangle when resizing using the

2
src/ImageSharp/Processing/Transforms/Options/ResizeMode.cs → src/ImageSharp/Processing/Transforms/ResizeMode.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Enumerated resize modes to apply to resized images. /// Enumerated resize modes to apply to resized images.

4
src/ImageSharp/Processing/Transforms/Options/ResizeOptions.cs → src/ImageSharp/Processing/Transforms/ResizeOptions.cs

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The resize options for resizing images against certain modes. /// The resize options for resizing images against certain modes.
@ -43,4 +43,4 @@ namespace SixLabors.ImageSharp.Processing
/// </summary> /// </summary>
public bool Compand { get; set; } = false; public bool Compand { get; set; } = false;
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs → src/ImageSharp/Processing/Transforms/RobidouxResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the Robidoux algorithm. /// The function implements the Robidoux algorithm.
@ -21,4 +21,4 @@ namespace SixLabors.ImageSharp.Processing
return ImageMaths.GetBcValue(x, B, C); return ImageMaths.GetBcValue(x, B, C);
} }
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs → src/ImageSharp/Processing/Transforms/RobidouxSharpResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the Robidoux Sharp algorithm. /// The function implements the Robidoux Sharp algorithm.
@ -21,4 +21,4 @@ namespace SixLabors.ImageSharp.Processing
return ImageMaths.GetBcValue(x, B, C); return ImageMaths.GetBcValue(x, B, C);
} }
} }
} }

15
src/ImageSharp/Processing/Transforms/Rotate.cs → src/ImageSharp/Processing/Transforms/RotateExtensions.cs

@ -2,15 +2,14 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.ImageSharp.Processing.Processors;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of rotate operations to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class RotateExtensions
{ {
/// <summary> /// <summary>
/// Rotates and flips an image by the given instructions. /// Rotates and flips an image by the given instructions.
@ -21,7 +20,7 @@ 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, RotateType rotateType) public static IImageProcessingContext<TPixel> Rotate<TPixel>(this IImageProcessingContext<TPixel> source, RotateType rotateType)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Rotate(source, (float)rotateType); => Rotate(source, (float)rotateType);
/// <summary> /// <summary>
/// Rotates an image by the given angle in degrees. /// Rotates an image by the given angle in degrees.
@ -32,7 +31,7 @@ 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) public static IImageProcessingContext<TPixel> Rotate<TPixel>(this IImageProcessingContext<TPixel> source, float degrees)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Rotate(source, degrees, Resamplers.Bicubic); => Rotate(source, degrees, Resamplers.Bicubic);
/// <summary> /// <summary>
/// Rotates an image by the given angle in degrees using the specified sampling algorithm. /// Rotates an image by the given angle in degrees using the specified sampling algorithm.
@ -44,6 +43,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.GetCurrentSize())); => source.ApplyProcessor(new RotateProcessor<TPixel>(degrees, sampler, source.GetCurrentSize()));
} }
} }

14
src/ImageSharp/Processing/Transforms/RotateFlip.cs → src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs

@ -1,16 +1,14 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of rotate-flip operations to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class RotateFlipExtensions
{ {
/// <summary> /// <summary>
/// Rotates and flips an image by the given instructions. /// Rotates and flips an image by the given instructions.
@ -22,8 +20,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> RotateFlip<TPixel>(this IImageProcessingContext<TPixel> source, RotateType rotateType, FlipType flipType) public static IImageProcessingContext<TPixel> RotateFlip<TPixel>(this IImageProcessingContext<TPixel> source, RotateType rotateType, FlipType flipType)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.Rotate(rotateType).Flip(flipType);
return source.Rotate(rotateType).Flip(flipType);
}
} }
} }

4
src/ImageSharp/Processing/Transforms/Options/RotateType.cs → src/ImageSharp/Processing/Transforms/RotateType.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Provides enumeration over how the image should be rotated. /// Provides enumeration over how the image should be rotated.
@ -28,4 +28,4 @@ namespace SixLabors.ImageSharp.Processing
/// </summary> /// </summary>
Rotate270 = 270 Rotate270 = 270
} }
} }

13
src/ImageSharp/Processing/Transforms/Skew.cs → src/ImageSharp/Processing/Transforms/SkewExtensions.cs

@ -2,15 +2,14 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.ImageSharp.Processing.Processors;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of skew operations to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class SkewExtensions
{ {
/// <summary> /// <summary>
/// Skews an image by the given angles in degrees. /// Skews an image by the given angles in degrees.
@ -22,7 +21,7 @@ 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) public static IImageProcessingContext<TPixel> Skew<TPixel>(this IImageProcessingContext<TPixel> source, float degreesX, float degreesY)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Skew(source, degreesX, degreesY, Resamplers.Bicubic); => Skew(source, degreesX, degreesY, Resamplers.Bicubic);
/// <summary> /// <summary>
/// Skews an image by the given angles in degrees using the specified sampling algorithm. /// Skews an image by the given angles in degrees using the specified sampling algorithm.
@ -35,6 +34,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.GetCurrentSize())); => source.ApplyProcessor(new SkewProcessor<TPixel>(degreesX, degreesY, sampler, source.GetCurrentSize()));
} }
} }

4
src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs → src/ImageSharp/Processing/Transforms/SplineResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the spline algorithm. /// The function implements the spline algorithm.
@ -21,4 +21,4 @@ namespace SixLabors.ImageSharp.Processing
return ImageMaths.GetBcValue(x, B, C); return ImageMaths.GetBcValue(x, B, C);
} }
} }
} }

13
src/ImageSharp/Processing/Transforms/Transform.cs → src/ImageSharp/Processing/Transforms/TransformExtensions.cs

@ -3,16 +3,15 @@
using System.Numerics; using System.Numerics;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of composable transform operations to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class TransformExtensions
{ {
/// <summary> /// <summary>
/// Transforms an image by the given matrix. /// Transforms an image by the given matrix.
@ -77,9 +76,7 @@ namespace SixLabors.ImageSharp
IResampler sampler, IResampler sampler,
Size destinationSize) Size destinationSize)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new AffineTransformProcessor<TPixel>(matrix, sampler, destinationSize));
return source.ApplyProcessor(new AffineTransformProcessor<TPixel>(matrix, sampler, destinationSize));
}
/// <summary> /// <summary>
/// Transforms an image by the given matrix. /// Transforms an image by the given matrix.

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

@ -7,7 +7,7 @@ using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// Contains helper methods for working with affine and non-affine transforms /// Contains helper methods for working with affine and non-affine transforms

4
src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs → src/ImageSharp/Processing/Transforms/TriangleResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the triangle (bilinear) algorithm. /// The function implements the triangle (bilinear) algorithm.
@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing
return 0F; return 0F;
} }
} }
} }

2
src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs → src/ImageSharp/Processing/Transforms/WelchResampler.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Transforms
{ {
/// <summary> /// <summary>
/// The function implements the welch algorithm. /// The function implements the welch algorithm.

3
tests/ImageSharp.Benchmarks/Samplers/Crop.cs

@ -9,9 +9,8 @@ namespace SixLabors.ImageSharp.Benchmarks
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
using CoreSize = SixLabors.Primitives.Size; using CoreSize = SixLabors.Primitives.Size;

1
tests/ImageSharp.Benchmarks/Samplers/Resize.cs

@ -12,6 +12,7 @@ namespace SixLabors.ImageSharp.Benchmarks
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
using CoreSize = SixLabors.Primitives.Size; using CoreSize = SixLabors.Primitives.Size;

1
tests/ImageSharp.Tests/ComplexIntegrationTests.cs

@ -3,6 +3,7 @@
using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.Primitives; using SixLabors.Primitives;
using Xunit; using Xunit;

2
tests/ImageSharp.Tests/Drawing/DrawImageTest.cs

@ -11,6 +11,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
using SixLabors.ImageSharp.Processing.Transforms;
public class DrawImageTest : FileTestBase public class DrawImageTest : FileTestBase
{ {
private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32; private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32;

1
tests/ImageSharp.Tests/Drawing/FillPatternTests.cs

@ -13,6 +13,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
{ {
using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
public class FillPatternBrushTests : FileTestBase public class FillPatternBrushTests : FileTestBase
{ {

1
tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs

@ -11,6 +11,7 @@ using SixLabors.ImageSharp.Formats.Png;
namespace SixLabors.ImageSharp.Tests.Formats.Png namespace SixLabors.ImageSharp.Tests.Formats.Png
{ {
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
public class PngSmokeTests public class PngSmokeTests
{ {

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

@ -8,6 +8,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
public class ImageProcessingContextTests public class ImageProcessingContextTests
{ {

1
tests/ImageSharp.Tests/Image/ImageRotationTests.cs

@ -8,6 +8,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
public class ImageRotationTests public class ImageRotationTests
{ {

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs

@ -9,6 +9,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
public class AutoOrientTests : FileTestBase public class AutoOrientTests : FileTestBase
{ {
public static readonly string[] FlipFiles = { TestImages.Bmp.F }; public static readonly string[] FlipFiles = { TestImages.Bmp.F };

1
tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs

@ -7,6 +7,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
public class CropTest : FileTestBase public class CropTest : FileTestBase
{ {

1
tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs

@ -7,6 +7,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
public class EntropyCropTest : FileTestBase public class EntropyCropTest : FileTestBase
{ {

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs

@ -7,6 +7,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
public class FlipTests : FileTestBase public class FlipTests : FileTestBase
{ {
public static readonly string[] FlipFiles = { TestImages.Bmp.F }; public static readonly string[] FlipFiles = { TestImages.Bmp.F };

1
tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs

@ -7,6 +7,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
public class PadTest : FileTestBase public class PadTest : FileTestBase
{ {

3
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs

@ -12,6 +12,9 @@ using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.Processing.Transforms.Processors;
public class ResizeProfilingBenchmarks : MeasureFixture public class ResizeProfilingBenchmarks : MeasureFixture
{ {
public ResizeProfilingBenchmarks(ITestOutputHelper output) public ResizeProfilingBenchmarks(ITestOutputHelper output)

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

@ -13,6 +13,8 @@ using Xunit;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
public class ResizeTests : FileTestBase public class ResizeTests : FileTestBase
{ {
public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial }; public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial };

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs

@ -7,6 +7,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
public class RotateFlipTests : FileTestBase public class RotateFlipTests : FileTestBase
{ {
public static readonly string[] FlipFiles = { TestImages.Bmp.F }; public static readonly string[] FlipFiles = { TestImages.Bmp.F };

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs

@ -11,6 +11,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
using System; using System;
using System.Reflection; using System.Reflection;
using SixLabors.ImageSharp.Processing.Transforms;
public class RotateTests : FileTestBase public class RotateTests : FileTestBase
{ {
public static readonly TheoryData<float> RotateAngles public static readonly TheoryData<float> RotateAngles

1
tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs

@ -11,6 +11,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
using System.Reflection; using System.Reflection;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
public class SkewTest : FileTestBase public class SkewTest : FileTestBase
{ {

4
tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs

@ -11,6 +11,8 @@ using SixLabors.ImageSharp.Helpers;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
public class AffineTransformTests public class AffineTransformTests
{ {
private readonly ITestOutputHelper Output; private readonly ITestOutputHelper Output;
@ -236,7 +238,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
private static void VerifyAllPixelsAreWhiteOrTransparent<TPixel>(Image<TPixel> image) private static void VerifyAllPixelsAreWhiteOrTransparent<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel[] data = new TPixel[image.Width * image.Height]; var data = new TPixel[image.Width * image.Height];
image.Frames.RootFrame.SavePixelData(data); image.Frames.RootFrame.SavePixelData(data);
var rgba = default(Rgba32); var rgba = default(Rgba32);
var white = new Rgb24(255, 255, 255); var white = new Rgb24(255, 255, 255);

4
tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs

@ -1,11 +1,13 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Processing.Processors;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.Processing.Transforms.Processors;
public class AutoOrientTests : BaseImageOperationsExtensionTest public class AutoOrientTests : BaseImageOperationsExtensionTest
{ {
[Fact] [Fact]

19
tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs

@ -1,9 +1,8 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
using Xunit; using Xunit;
@ -14,10 +13,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
[Theory] [Theory]
[InlineData(10, 10)] [InlineData(10, 10)]
[InlineData(12, 123)] [InlineData(12, 123)]
public void Crop_Width_height_CropProcessorWithRectangleSet(int width, int height) public void CropWidthHeightCropProcessorWithRectangleSet(int width, int height)
{ {
this.operations.Crop(width, height); this.operations.Crop(width, height);
var processor = this.Verify<CropProcessor<Rgba32>>(); CropProcessor<Rgba32> processor = this.Verify<CropProcessor<Rgba32>>();
Assert.Equal(new Rectangle(0, 0, width, height), processor.CropRectangle); Assert.Equal(new Rectangle(0, 0, width, height), processor.CropRectangle);
} }
@ -25,13 +24,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
[Theory] [Theory]
[InlineData(10, 10, 2, 6)] [InlineData(10, 10, 2, 6)]
[InlineData(12, 123, 6, 2)] [InlineData(12, 123, 6, 2)]
public void Crop_Rectangle_CropProcessorWithRectangleSet(int x, int y, int width, int height) public void CropRectangleCropProcessorWithRectangleSet(int x, int y, int width, int height)
{ {
var rect = new Rectangle(x, y, width, height); var cropRectangle = new Rectangle(x, y, width, height);
this.operations.Crop(rect); this.operations.Crop(cropRectangle);
var processor = this.Verify<CropProcessor<Rgba32>>(); CropProcessor<Rgba32> processor = this.Verify<CropProcessor<Rgba32>>();
Assert.Equal(rect, processor.CropRectangle); Assert.Equal(cropRectangle, processor.CropRectangle);
} }
} }
} }

18
tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs

@ -1,25 +1,23 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
public class EntropyCropTest : BaseImageOperationsExtensionTest public class EntropyCropTest : BaseImageOperationsExtensionTest
{ {
[Theory] [Theory]
[InlineData(0.5f)] [InlineData(0.5F)]
[InlineData(.2f)] [InlineData(.2F)]
public void EntropyCrop_threasholdFloat_EntropyCropProcessorWithThreshold(float threashold) public void EntropyCropThresholdFloatEntropyCropProcessorWithThreshold(float threshold)
{ {
this.operations.EntropyCrop(threashold); this.operations.EntropyCrop(threshold);
var processor = this.Verify<EntropyCropProcessor<Rgba32>>(); EntropyCropProcessor<Rgba32> processor = this.Verify<EntropyCropProcessor<Rgba32>>();
Assert.Equal(threashold, processor.Threshold); Assert.Equal(threshold, processor.Threshold);
} }
} }
} }

5
tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs

@ -9,6 +9,9 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.Processing.Transforms.Processors;
public class FlipTests : BaseImageOperationsExtensionTest public class FlipTests : BaseImageOperationsExtensionTest
{ {
@ -19,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
public void Flip_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(FlipType flip) public void Flip_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(FlipType flip)
{ {
this.operations.Flip(flip); this.operations.Flip(flip);
var flipProcessor = this.Verify<FlipProcessor<Rgba32>>(); FlipProcessor<Rgba32> flipProcessor = this.Verify<FlipProcessor<Rgba32>>();
Assert.Equal(flip, flipProcessor.FlipType); Assert.Equal(flip, flipProcessor.FlipType);
} }

3
tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs

@ -8,7 +8,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.Processing.Transforms.Processors;
public class PadTest : BaseImageOperationsExtensionTest public class PadTest : BaseImageOperationsExtensionTest
{ {

5
tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs

@ -1,14 +1,13 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Processing.Processors;
public class ResizeTests : BaseImageOperationsExtensionTest public class ResizeTests : BaseImageOperationsExtensionTest
{ {
[Fact] [Fact]

9
tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs

@ -1,17 +1,14 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Transforms.Processors;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
public class RotateFlipTests : BaseImageOperationsExtensionTest public class RotateFlipTests : BaseImageOperationsExtensionTest
{ {
[Theory] [Theory]
[InlineData(RotateType.None, FlipType.None, 0)] [InlineData(RotateType.None, FlipType.None, 0)]
[InlineData(RotateType.Rotate90, FlipType.None, 90)] [InlineData(RotateType.Rotate90, FlipType.None, 90)]
@ -25,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
[InlineData(RotateType.Rotate90, FlipType.Vertical, 90)] [InlineData(RotateType.Rotate90, FlipType.Vertical, 90)]
[InlineData(RotateType.Rotate180, FlipType.Vertical, 180)] [InlineData(RotateType.Rotate180, FlipType.Vertical, 180)]
[InlineData(RotateType.Rotate270, FlipType.Vertical, 270)] [InlineData(RotateType.Rotate270, FlipType.Vertical, 270)]
public void Rotate_degreesFloat_RotateProcessorWithAnglesSetrue(RotateType angle, FlipType flip, float expectedAngle) public void RotateDegreesFloatRotateProcessorWithAnglesSet(RotateType angle, FlipType flip, float expectedAngle)
{ {
this.operations.RotateFlip(angle, flip); this.operations.RotateFlip(angle, flip);
RotateProcessor<Rgba32> rotateProcessor = this.Verify<RotateProcessor<Rgba32>>(0); RotateProcessor<Rgba32> rotateProcessor = this.Verify<RotateProcessor<Rgba32>>(0);

3
tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs

@ -7,6 +7,9 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.Processing.Transforms.Processors;
public class RotateTests : BaseImageOperationsExtensionTest public class RotateTests : BaseImageOperationsExtensionTest
{ {
[Theory] [Theory]

3
tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs

@ -6,6 +6,9 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.Processing.Transforms.Processors;
public class SkewTest : BaseImageOperationsExtensionTest public class SkewTest : BaseImageOperationsExtensionTest
{ {
[Fact] [Fact]

2
tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs

@ -7,6 +7,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Processing.Transforms;
public class TransformsHelpersTest public class TransformsHelpersTest
{ {
[Fact] [Fact]

1
tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs

@ -14,6 +14,7 @@ namespace SixLabors.ImageSharp.Tests
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Transforms;
public class ImageComparerTests public class ImageComparerTests
{ {

Loading…
Cancel
Save