From 612b5e2e50dfa779ae9b29952cdb854283fd7ebd Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Fri, 14 Jul 2017 21:42:32 +0100 Subject: [PATCH] Renameing classes + simplifying Image --- samples/AvatarWithRoundedCorner/Program.cs | 2 +- src/ImageSharp.Drawing/DrawImage.cs | 12 +- src/ImageSharp.Drawing/FillRegion.cs | 18 +- src/ImageSharp.Drawing/Paths/DrawBeziers.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawLines.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawPath.cs | 12 +- .../Paths/DrawPathCollection.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawPolygon.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawRectangle.cs | 12 +- .../Paths/FillPathBuilder.cs | 8 +- .../Paths/FillPathCollection.cs | 8 +- src/ImageSharp.Drawing/Paths/FillPaths.cs | 8 +- src/ImageSharp.Drawing/Paths/FillPolygon.cs | 8 +- src/ImageSharp.Drawing/Paths/FillRectangle.cs | 8 +- .../Processors/DrawImageProcessor.cs | 4 +- src/ImageSharp.Drawing/Text/DrawText.Path.cs | 16 +- src/ImageSharp.Drawing/Text/DrawText.cs | 16 +- src/ImageSharp/ApplyProcessors.cs | 32 +-- src/ImageSharp/Configuration.cs | 2 +- ...DefaultInternalImageProcessorApplicator.cs | 72 +++++++ ...cs => IImageProcessorApplicatorFactory.cs} | 11 +- ...s => IImageProcessorApplicator{TPixel}.cs} | 22 +- src/ImageSharp/Image/IImageBase.cs | 10 - src/ImageSharp/Image/ImageBase{TPixel}.cs | 30 +-- src/ImageSharp/Image/ImageExtensions.cs | 153 +++++++++++++ src/ImageSharp/Image/ImageFrame{TPixel}.cs | 44 ++-- .../Image/ImageProcessingExtensions.cs | 32 --- src/ImageSharp/Image/Image{TPixel}.cs | 204 ++++-------------- src/ImageSharp/ImageOperations.cs | 62 ------ .../PackedPixelConverterHelper.cs | 9 +- .../Binarization/BinaryThreshold.cs | 4 +- .../Processing/Binarization/Dither.cs | 12 +- .../Processing/ColorMatrix/BlackWhite.cs | 4 +- .../Processing/ColorMatrix/ColorBlindness.cs | 4 +- .../Processing/ColorMatrix/Grayscale.cs | 8 +- src/ImageSharp/Processing/ColorMatrix/Hue.cs | 4 +- .../Processing/ColorMatrix/Kodachrome.cs | 4 +- .../Processing/ColorMatrix/Lomograph.cs | 8 +- .../Processing/ColorMatrix/Polaroid.cs | 8 +- .../Processing/ColorMatrix/Saturation.cs | 4 +- .../Processing/ColorMatrix/Sepia.cs | 4 +- .../Processing/Convolution/BoxBlur.cs | 6 +- .../Processing/Convolution/DetectEdges.cs | 14 +- .../Processing/Convolution/GaussianBlur.cs | 6 +- .../Processing/Convolution/GaussianSharpen.cs | 6 +- src/ImageSharp/Processing/Delegate.cs | 2 +- src/ImageSharp/Processing/Effects/Alpha.cs | 4 +- .../Processing/Effects/BackgroundColor.cs | 8 +- .../Processing/Effects/Brightness.cs | 6 +- src/ImageSharp/Processing/Effects/Contrast.cs | 4 +- src/ImageSharp/Processing/Effects/Invert.cs | 4 +- .../Processing/Effects/OilPainting.cs | 8 +- src/ImageSharp/Processing/Effects/Pixelate.cs | 6 +- src/ImageSharp/Processing/Overlays/Glow.cs | 24 +-- .../Processing/Overlays/Vignette.cs | 24 +-- .../Convolution/Convolution2PassProcessor.cs | 2 +- .../EdgeDetectorCompassProcessor.cs | 4 +- .../Processors/Overlays/GlowProcessor.cs | 2 +- .../Processors/Overlays/VignetteProcessor.cs | 4 +- .../Transforms/EntropyCropProcessor.cs | 2 +- .../Processors/Transforms/RotateProcessor.cs | 3 +- .../Processors/Transforms/SkewProcessor.cs | 3 +- .../Processing/Transforms/AutoOrient.cs | 2 +- src/ImageSharp/Processing/Transforms/Crop.cs | 4 +- .../Processing/Transforms/EntropyCrop.cs | 2 +- src/ImageSharp/Processing/Transforms/Flip.cs | 2 +- src/ImageSharp/Processing/Transforms/Pad.cs | 2 +- .../Processing/Transforms/Resize.cs | 18 +- .../Processing/Transforms/Rotate.cs | 6 +- .../Processing/Transforms/RotateFlip.cs | 2 +- src/ImageSharp/Processing/Transforms/Skew.cs | 4 +- src/ImageSharp/Quantizers/Quantize.cs | 4 +- .../Quantizers/Quantizer{TPixel}.cs | 2 +- tests/ImageSharp.Benchmarks/Samplers/Glow.cs | 4 +- .../BaseImageOperationsExtensionTest.cs | 3 +- .../FakeImageOperationsProvider.cs | 30 ++- .../Formats/GeneralFormatTests.cs | 6 +- tests/ImageSharp.Tests/ImageOperationTests.cs | 4 +- .../Binarization/BinaryThresholdTest.cs | 2 +- .../Processors/Binarization/DitherTest.cs | 4 +- .../Processors/ColorMatrix/BlackWhiteTest.cs | 2 +- .../ColorMatrix/ColorBlindnessTest.cs | 2 +- .../Processors/ColorMatrix/GrayscaleTest.cs | 2 +- .../Processors/ColorMatrix/HueTest.cs | 2 +- .../Processors/ColorMatrix/KodachromeTest.cs | 2 +- .../Processors/ColorMatrix/LomographTest.cs | 2 +- .../Processors/ColorMatrix/PolaroidTest.cs | 2 +- .../Processors/ColorMatrix/SaturationTest.cs | 2 +- .../Processors/ColorMatrix/SepiaTest.cs | 2 +- .../Processors/Convolution/BoxBlurTest.cs | 2 +- .../Processors/Convolution/DetectEdgesTest.cs | 2 +- .../Convolution/GaussianBlurTest.cs | 2 +- .../Convolution/GaussianSharpenTest.cs | 2 +- .../Processors/Effects/AlphaTest.cs | 2 +- .../Processors/Effects/BackgroundColorTest.cs | 2 +- .../Processors/Effects/BrightnessTest.cs | 2 +- .../Processors/Effects/ContrastTest.cs | 2 +- .../Processors/Effects/InvertTest.cs | 2 +- .../Processors/Effects/OilPaintTest.cs | 2 +- .../Processors/Effects/PixelateTest.cs | 2 +- .../Processors/Overlays/GlowTest.cs | 2 +- .../Processors/Overlays/VignetteTest.cs | 2 +- tests/ImageSharp.Tests/TestFile.cs | 2 +- .../TestUtilities/Factories/GenericFactory.cs | 2 +- .../TestUtilities/Factories/ImageFactory.cs | 2 +- .../ImageProviders/TestImageProvider.cs | 2 +- .../ImageProviders/TestPatternProvider.cs | 2 +- 107 files changed, 633 insertions(+), 591 deletions(-) create mode 100644 src/ImageSharp/DefaultInternalImageProcessorApplicator.cs rename src/ImageSharp/{IImageOperationsProvider.cs => IImageProcessorApplicatorFactory.cs} (61%) rename src/ImageSharp/{IImageOperations{TPixel}.cs => IImageProcessorApplicator{TPixel}.cs} (54%) create mode 100644 src/ImageSharp/Image/ImageExtensions.cs delete mode 100644 src/ImageSharp/Image/ImageProcessingExtensions.cs delete mode 100644 src/ImageSharp/ImageOperations.cs diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index 0cd484737..f635ed203 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -36,7 +36,7 @@ namespace AvatarWithRoundedCorner } // lets create our custom image mutating pipeline - private static IImageOperations ConvertToAvatar(this IImageOperations operations, Size size, float cornerRadius) + private static IImageProcessorApplicator ConvertToAvatar(this IImageProcessorApplicator operations, Size size, float cornerRadius) { return operations.Resize(new ImageSharp.Processing.ResizeOptions { diff --git a/src/ImageSharp.Drawing/DrawImage.cs b/src/ImageSharp.Drawing/DrawImage.cs index bd51e4ac0..a7b1faa15 100644 --- a/src/ImageSharp.Drawing/DrawImage.cs +++ b/src/ImageSharp.Drawing/DrawImage.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The location to draw the blended image. /// The options. /// The . - public static IImageOperations DrawImage(this IImageOperations source, Image image, Size size, Point location, GraphicsOptions options) + public static IImageProcessorApplicator DrawImage(this IImageProcessorApplicator source, Image image, Size size, Point location, GraphicsOptions options) where TPixel : struct, IPixel { if (size == default(Size)) @@ -49,7 +49,7 @@ namespace ImageSharp /// The image to blend with the currently processing image. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static IImageOperations Blend(this IImageOperations source, Image image, float percent) + public static IImageProcessorApplicator Blend(this IImageProcessorApplicator source, Image image, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -66,7 +66,7 @@ namespace ImageSharp /// The blending mode. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static IImageOperations Blend(this IImageOperations source, Image image, PixelBlenderMode blender, float percent) + public static IImageProcessorApplicator Blend(this IImageProcessorApplicator source, Image image, PixelBlenderMode blender, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -83,7 +83,7 @@ namespace ImageSharp /// The image to blend with the currently processing image. /// The options, including the blending type and belnding amount. /// The . - public static IImageOperations Blend(this IImageOperations source, Image image, GraphicsOptions options) + public static IImageProcessorApplicator Blend(this IImageProcessorApplicator source, Image image, GraphicsOptions options) where TPixel : struct, IPixel { return DrawImage(source, image, default(Size), default(Point), options); @@ -99,7 +99,7 @@ namespace ImageSharp /// The size to draw the blended image. /// The location to draw the blended image. /// The . - public static IImageOperations DrawImage(this IImageOperations source, Image image, float percent, Size size, Point location) + public static IImageProcessorApplicator DrawImage(this IImageProcessorApplicator source, Image image, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -118,7 +118,7 @@ namespace ImageSharp /// The size to draw the blended image. /// The location to draw the blended image. /// The . - public static IImageOperations DrawImage(this IImageOperations source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) + public static IImageProcessorApplicator DrawImage(this IImageProcessorApplicator source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; diff --git a/src/ImageSharp.Drawing/FillRegion.cs b/src/ImageSharp.Drawing/FillRegion.cs index d8bb78e90..ff86c7240 100644 --- a/src/ImageSharp.Drawing/FillRegion.cs +++ b/src/ImageSharp.Drawing/FillRegion.cs @@ -23,10 +23,10 @@ namespace ImageSharp /// The details how to fill the region of interest. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, GraphicsOptions options) where TPixel : struct, IPixel { - return source.Apply(new FillProcessor(brush, options)); + return source.ApplyProcessor(new FillProcessor(brush, options)); } /// @@ -36,7 +36,7 @@ namespace ImageSharp /// The image this method extends. /// The details how to fill the region of interest. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush) where TPixel : struct, IPixel { return source.Fill(brush, GraphicsOptions.Default); @@ -49,7 +49,7 @@ namespace ImageSharp /// The image this method extends. /// The color. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color)); @@ -64,10 +64,10 @@ namespace ImageSharp /// The region. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, Region region, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Region region, GraphicsOptions options) where TPixel : struct, IPixel { - return source.Apply(new FillRegionProcessor(brush, region, options)); + return source.ApplyProcessor(new FillRegionProcessor(brush, region, options)); } /// @@ -78,7 +78,7 @@ namespace ImageSharp /// The brush. /// The region. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, Region region) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Region region) where TPixel : struct, IPixel { return source.Fill(brush, region, GraphicsOptions.Default); @@ -93,7 +93,7 @@ namespace ImageSharp /// The region. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, Region region, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Region region, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region, options); @@ -107,7 +107,7 @@ namespace ImageSharp /// The color. /// The region. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, Region region) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Region region) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region); diff --git a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs index d332f1d05..b83edb7a2 100644 --- a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs +++ b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, TPixel color, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points, options); @@ -89,7 +89,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options); @@ -103,7 +103,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, IPen pen, PointF[] points) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawLines.cs b/src/ImageSharp.Drawing/Paths/DrawLines.cs index db1e46af8..553ec2ca5 100644 --- a/src/ImageSharp.Drawing/Paths/DrawLines.cs +++ b/src/ImageSharp.Drawing/Paths/DrawLines.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawLines(this IImageOperations source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawLines(this IImageOperations source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawLines(this IImageOperations source, TPixel color, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The .> - public static IImageOperations DrawLines(this IImageOperations source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points, options); @@ -89,7 +89,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawLines(this IImageOperations source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points)), options); @@ -103,7 +103,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static IImageOperations DrawLines(this IImageOperations source, IPen pen, PointF[] points) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawPath.cs b/src/ImageSharp.Drawing/Paths/DrawPath.cs index 57ce2032a..68ba89ff1 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPath.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPath.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(pen.StrokeFill, new ShapePath(path, pen), options); @@ -39,7 +39,7 @@ namespace ImageSharp /// The pen. /// The path. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, IPath path) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPath path) where TPixel : struct, IPixel { return source.Draw(pen, path, GraphicsOptions.Default); @@ -55,7 +55,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path, options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The thickness. /// The path. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPath path) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path); @@ -86,7 +86,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path, options); @@ -101,7 +101,7 @@ namespace ImageSharp /// The thickness. /// The path. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPath path) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path); diff --git a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs index f909e98da..086ce9723 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath path in paths) @@ -44,7 +44,7 @@ namespace ImageSharp /// The pen. /// The paths. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, IPathCollection paths) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(pen, paths, GraphicsOptions.Default); @@ -60,7 +60,7 @@ namespace ImageSharp /// The shapes. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths, options); @@ -75,7 +75,7 @@ namespace ImageSharp /// The thickness. /// The paths. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPathCollection paths) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths); @@ -91,7 +91,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths, options); @@ -106,7 +106,7 @@ namespace ImageSharp /// The thickness. /// The paths. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPathCollection paths) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths); diff --git a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs index b787afcd5..12b687415 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, TPixel color, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points, options); @@ -88,7 +88,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, IPen pen, PointF[] points) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); @@ -103,7 +103,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); diff --git a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs index 544ca2fe9..a9832a628 100644 --- a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -39,7 +39,7 @@ namespace ImageSharp /// The pen. /// The shape. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, RectangleF shape) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(pen, shape, GraphicsOptions.Default); @@ -55,7 +55,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape, options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The thickness. /// The shape. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, RectangleF shape) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape); @@ -86,7 +86,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape, options); @@ -101,7 +101,7 @@ namespace ImageSharp /// The thickness. /// The shape. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, RectangleF shape) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape); diff --git a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs index eae34f034..38d3ad10f 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The shape. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, Action path, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Action path, GraphicsOptions options) where TPixel : struct, IPixel { var pb = new PathBuilder(); @@ -42,7 +42,7 @@ namespace ImageSharp /// The brush. /// The path. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, Action path) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Action path) where TPixel : struct, IPixel { return source.Fill(brush, path, GraphicsOptions.Default); @@ -57,7 +57,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, Action path, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Action path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -71,7 +71,7 @@ namespace ImageSharp /// The color. /// The path. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, Action path) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Action path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs index 662245dc3..eec3fa795 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shapes. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath s in paths) @@ -43,7 +43,7 @@ namespace ImageSharp /// The brush. /// The paths. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPathCollection paths) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(brush, paths, GraphicsOptions.Default); @@ -58,7 +58,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths, options); @@ -72,7 +72,7 @@ namespace ImageSharp /// The color. /// The paths. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, IPathCollection paths) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths); diff --git a/src/ImageSharp.Drawing/Paths/FillPaths.cs b/src/ImageSharp.Drawing/Paths/FillPaths.cs index 07342d47b..7cd6dbe54 100644 --- a/src/ImageSharp.Drawing/Paths/FillPaths.cs +++ b/src/ImageSharp.Drawing/Paths/FillPaths.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shape. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), options); @@ -38,7 +38,7 @@ namespace ImageSharp /// The brush. /// The path. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPath path) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); @@ -53,7 +53,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -67,7 +67,7 @@ namespace ImageSharp /// The color. /// The path. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, IPath path) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPath path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPolygon.cs b/src/ImageSharp.Drawing/Paths/FillPolygon.cs index 7feac5b0a..6b6cef8ac 100644 --- a/src/ImageSharp.Drawing/Paths/FillPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/FillPolygon.cs @@ -27,7 +27,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations FillPolygon(this IImageOperations source, IBrush brush, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, IBrush brush, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); @@ -41,7 +41,7 @@ namespace ImageSharp /// The brush. /// The points. /// The . - public static IImageOperations FillPolygon(this IImageOperations source, IBrush brush, PointF[] points) + public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, IBrush brush, PointF[] points) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points))); @@ -56,7 +56,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations FillPolygon(this IImageOperations source, TPixel color, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, TPixel color, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The color. /// The points. /// The . - public static IImageOperations FillPolygon(this IImageOperations source, TPixel color, PointF[] points) + public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, TPixel color, PointF[] points) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/FillRectangle.cs b/src/ImageSharp.Drawing/Paths/FillRectangle.cs index 52512ca1c..9e475137a 100644 --- a/src/ImageSharp.Drawing/Paths/FillRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/FillRectangle.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -38,7 +38,7 @@ namespace ImageSharp /// The brush. /// The shape. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, RectangleF shape) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height)); @@ -53,7 +53,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape, options); @@ -67,7 +67,7 @@ namespace ImageSharp /// The color. /// The shape. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, RectangleF shape) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape); diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index 7154396dd..c5b92b408 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -68,13 +68,13 @@ namespace ImageSharp.Drawing.Processors try { - if (targetImage.Bounds.Size != this.Size) + if (targetImage.Size() != this.Size) { targetImage = disposableImage = this.Image.Clone(x => x.Resize(this.Size.Width, this.Size.Height)); } // Align start/end positions. - Rectangle bounds = this.Image.Bounds; + Rectangle bounds = this.Image.Bounds(); int minX = Math.Max(this.Location.X, sourceRectangle.X); int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Width); maxX = Math.Min(this.Location.X + this.Size.Width, maxX); diff --git a/src/ImageSharp.Drawing/Text/DrawText.Path.cs b/src/ImageSharp.Drawing/Text/DrawText.Path.cs index 459d5de0d..c109047b2 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.Path.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.Path.cs @@ -31,7 +31,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, IPath path) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, color, path, TextGraphicsOptions.Default); @@ -50,7 +50,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, path, options); @@ -68,7 +68,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPath path) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, path, TextGraphicsOptions.Default); @@ -87,7 +87,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, path, options); @@ -105,7 +105,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, IPath path) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, path, TextGraphicsOptions.Default); @@ -124,7 +124,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, path, options); @@ -143,7 +143,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, IPath path) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default); @@ -163,7 +163,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Text/DrawText.cs index 989322a73..338d06058 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.cs @@ -34,7 +34,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, PointF location) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, color, location, TextGraphicsOptions.Default); @@ -53,7 +53,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, location, options); @@ -71,7 +71,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, PointF location) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); @@ -90,7 +90,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, location, options); @@ -108,7 +108,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, PointF location) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); @@ -127,7 +127,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, location, options); @@ -146,7 +146,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, PointF location) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); @@ -166,7 +166,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index fd91349f5..78a5fc079 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -22,14 +22,15 @@ namespace ImageSharp /// The pixel format. /// The image to rotate, flip, or both. /// The operations to perform on the source. - public static void Mutate(this Image source, Action> operations) + public static void Mutate(this Image source, Action> operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); + Guard.NotNull(source, nameof(source)); - // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(source); + IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, true); operations(operationsRunner); + operationsRunner.Apply(); } /// @@ -42,10 +43,11 @@ namespace ImageSharp where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); + Guard.NotNull(source, nameof(source)); - // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(source); + IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, true); operationsRunner.ApplyProcessors(operations); + operationsRunner.Apply(); } /// @@ -55,16 +57,15 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The operations to perform on the source. /// Anew Image which has teh data from the but with the applied. - public static Image Clone(this Image source, Action> operations) + public static Image Clone(this Image source, Action> operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); - var generated = new Image(source); + Guard.NotNull(source, nameof(source)); - // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(generated); + IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, false); operations(operationsRunner); - return generated; + return operationsRunner.Apply(); } /// @@ -78,12 +79,11 @@ namespace ImageSharp where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); - var generated = new Image(source); + Guard.NotNull(source, nameof(source)); - // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(generated); + IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, false); operationsRunner.ApplyProcessors(operations); - return generated; + return operationsRunner.Apply(); } /// @@ -93,10 +93,10 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The operations to perform on the source. /// returns the current optinoatins class to allow chaining of oprations. - public static IImageOperations ApplyProcessors(this IImageOperations source, params IImageProcessor[] operations) + public static IImageProcessorApplicator ApplyProcessors(this IImageProcessorApplicator source, params IImageProcessor[] operations) where TPixel : struct, IPixel { - foreach (var p in operations) + foreach (IImageProcessor p in operations) { source = source.ApplyProcessor(p); } diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 834019633..b86819430 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -111,7 +111,7 @@ namespace ImageSharp /// /// Gets or sets the image operations providers. /// - internal IImageOperationsProvider ImageOperationsProvider { get; set; } = new DefaultImageOperationsProvider(); + internal IImageProcessorApplicatorFactory ImageOperationsProvider { get; set; } = new DefaultImageOperationsProvider(); /// /// Registers a new format provider. diff --git a/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs b/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs new file mode 100644 index 000000000..4dda4f070 --- /dev/null +++ b/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs @@ -0,0 +1,72 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Collections.Generic; + using ImageSharp.PixelFormats; + using ImageSharp.Processing; + using SixLabors.Primitives; + + /// + /// The static collection of all the default image formats + /// + /// The pixel format + internal class DefaultInternalImageProcessorApplicator : IInternalImageProcessorApplicator + where TPixel : struct, IPixel + { + private readonly bool mutate; + private readonly Image source; + private Image destination; + + /// + /// Initializes a new instance of the class. + /// + /// The image. + /// The mutate. + public DefaultInternalImageProcessorApplicator(Image source, bool mutate) + { + this.mutate = mutate; + this.source = source; + if (this.mutate) + { + this.destination = source; + } + } + + /// + public Image Apply() + { + if (!this.mutate && this.destination == null) + { + // ensure we have cloned it if we are not mutating as we might have failed to register any Processors + this.destination = this.source.Clone(); + } + + return this.destination; + } + + /// + public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + { + if (!this.mutate && this.destination == null) + { + // TODO check if the processor implements a special interface and if it does then allow it to take + // over and crereate the clone on behalf ImageOperations class. + this.destination = this.source.Clone(); + } + + processor.Apply(this.destination, rectangle); + return this; + } + + /// + public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor) + { + return this.ApplyProcessor(processor, this.source.Bounds()); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/IImageOperationsProvider.cs b/src/ImageSharp/IImageProcessorApplicatorFactory.cs similarity index 61% rename from src/ImageSharp/IImageOperationsProvider.cs rename to src/ImageSharp/IImageProcessorApplicatorFactory.cs index 475c63265..b79353ef5 100644 --- a/src/ImageSharp/IImageOperationsProvider.cs +++ b/src/ImageSharp/IImageProcessorApplicatorFactory.cs @@ -11,28 +11,29 @@ namespace ImageSharp /// /// Represents an interface that will create IImageOperations /// - internal interface IImageOperationsProvider + internal interface IImageProcessorApplicatorFactory { /// /// Called during Mutate operations to generate the imageoperations provider. /// /// The pixel format /// The source image. + /// A flag to determin with the image operations is allowed to mutate the source image or not. /// A new IImageOPeration - IImageOperations CreateMutator(Image source) + IInternalImageProcessorApplicator CreateImageOperations(Image source, bool mutate) where TPixel : struct, IPixel; } /// /// The default implmentation of IImageOperationsProvider /// - internal class DefaultImageOperationsProvider : IImageOperationsProvider + internal class DefaultImageOperationsProvider : IImageProcessorApplicatorFactory { /// - public IImageOperations CreateMutator(Image source) + public IInternalImageProcessorApplicator CreateImageOperations(Image source, bool mutate) where TPixel : struct, IPixel { - return new ImageOperations(source); + return new DefaultInternalImageProcessorApplicator(source, mutate); } } } diff --git a/src/ImageSharp/IImageOperations{TPixel}.cs b/src/ImageSharp/IImageProcessorApplicator{TPixel}.cs similarity index 54% rename from src/ImageSharp/IImageOperations{TPixel}.cs rename to src/ImageSharp/IImageProcessorApplicator{TPixel}.cs index 349cef7f3..861c5b010 100644 --- a/src/ImageSharp/IImageOperations{TPixel}.cs +++ b/src/ImageSharp/IImageProcessorApplicator{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -15,7 +15,7 @@ namespace ImageSharp /// An interface to queue up image operations. /// /// The pixel format - public interface IImageOperations + public interface IImageProcessorApplicator where TPixel : struct, IPixel { /// @@ -24,13 +24,27 @@ namespace ImageSharp /// The processor to apply /// The area to apply it to /// returns the current optinoatins class to allow chaining of oprations. - IImageOperations ApplyProcessor(IImageProcessor processor, Rectangle rectangle); + IImageProcessorApplicator ApplyProcessor(IImageProcessor processor, Rectangle rectangle); /// /// Adds the processor to the current setr of image operations to be applied. /// /// The processor to apply /// returns the current optinoatins class to allow chaining of oprations. - IImageOperations ApplyProcessor(IImageProcessor processor); + IImageProcessorApplicator ApplyProcessor(IImageProcessor processor); + } + + /// + /// An internal interface to queue up image operations and have a method to apply them to and return a result + /// + /// The pixel format + public interface IInternalImageProcessorApplicator : IImageProcessorApplicator + where TPixel : struct, IPixel + { + /// + /// Adds the processors to the current image + /// + /// returns the current image or a new image depending on withere this is alloed to mutate the source image. + Image Apply(); } } \ No newline at end of file diff --git a/src/ImageSharp/Image/IImageBase.cs b/src/ImageSharp/Image/IImageBase.cs index 0e087aa4a..9e0c10606 100644 --- a/src/ImageSharp/Image/IImageBase.cs +++ b/src/ImageSharp/Image/IImageBase.cs @@ -12,11 +12,6 @@ namespace ImageSharp /// public interface IImageBase { - /// - /// Gets the representing the bounds of the image. - /// - Rectangle Bounds { get; } - /// /// Gets the width in pixels. /// @@ -27,11 +22,6 @@ namespace ImageSharp /// int Height { get; } - /// - /// Gets the pixel ratio made up of the width and height. - /// - double PixelRatio { get; } - /// /// Gets the configuration providing initialization code which allows extending the library. /// diff --git a/src/ImageSharp/Image/ImageBase{TPixel}.cs b/src/ImageSharp/Image/ImageBase{TPixel}.cs index d4a7af9ca..95d537518 100644 --- a/src/ImageSharp/Image/ImageBase{TPixel}.cs +++ b/src/ImageSharp/Image/ImageBase{TPixel}.cs @@ -19,7 +19,6 @@ namespace ImageSharp /// images in different pixel formats. /// /// The pixel format. - [DebuggerDisplay("Image: {Width}x{Height}")] public abstract class ImageBase : IImageBase where TPixel : struct, IPixel { @@ -105,12 +104,8 @@ namespace ImageSharp // Rent then copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here. this.RentPixels(); - using (PixelAccessor sourcePixels = other.Lock()) - using (PixelAccessor target = this.Lock()) - { - // Check we can do this without crashing - sourcePixels.CopyTo(target); - } + + other.Pixels.CopyTo(this.Pixels); } /// @@ -122,12 +117,6 @@ namespace ImageSharp /// public int Height { get; private set; } - /// - public double PixelRatio => (double)this.Width / this.Height; - - /// - public Rectangle Bounds => new Rectangle(0, 0, this.Width, this.Height); - /// /// Gets the configuration providing initialization code which allows extending the library. /// @@ -194,6 +183,15 @@ namespace ImageSharp return this.Pixels.Slice((y * this.Width) + x, this.Width - x); } + /// + /// Clones the image + /// + /// A new items which is a clone of the original. + public ImageBase Clone() + { + return this.CloneInternal(); + } + /// public void Dispose() { @@ -246,6 +244,12 @@ namespace ImageSharp this.PixelBuffer = newPixels; } + /// + /// Clones the image + /// + /// A new items which is a clone of the original. + protected abstract ImageBase CloneInternal(); + /// /// Copies the properties from the other . /// diff --git a/src/ImageSharp/Image/ImageExtensions.cs b/src/ImageSharp/Image/ImageExtensions.cs new file mode 100644 index 000000000..9c2575a86 --- /dev/null +++ b/src/ImageSharp/Image/ImageExtensions.cs @@ -0,0 +1,153 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Text; + using ImageSharp.Formats; + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + + /// + /// Extension methods over Image{TPixel} + /// + public static partial class ImageExtensions + { + /// + /// Gets the bounds of the image. + /// + /// The Pixel format. + /// The source image + /// Returns the bounds of the image + public static Rectangle Bounds(this ImageBase source) + where TPixel : struct, IPixel + => new Rectangle(0, 0, source.Width, source.Height); + + /// + /// Gets the size of the image. + /// + /// The Pixel format. + /// The source image + /// Returns the bounds of the image + public static Size Size(this ImageBase source) + where TPixel : struct, IPixel + => new Size(source.Width, source.Height); + +#if !NETSTANDARD1_1 + /// + /// Saves the image to the given stream using the currently loaded image format. + /// + /// The Pixel format. + /// The source image + /// The file path to save the image to. + /// Thrown if the stream is null. + public static void Save(this Image source, string filePath) + where TPixel : struct, IPixel + { + Guard.NotNullOrEmpty(filePath, nameof(filePath)); + + string ext = Path.GetExtension(filePath).Trim('.'); + IImageFormat format = source.Configuration.FindFormatByFileExtensions(ext); + if (format == null) + { + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine($"Can't find a format that is associated with the file extention '{ext}'. Registered formats with there extensions include:"); + foreach (IImageFormat fmt in source.Configuration.ImageFormats) + { + stringBuilder.AppendLine($" - {fmt.Name} : {string.Join(", ", fmt.FileExtensions)}"); + } + + throw new NotSupportedException(stringBuilder.ToString()); + } + + IImageEncoder encoder = source.Configuration.FindEncoder(format); + + if (encoder == null) + { + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine($"Can't find encoder for file extention '{ext}' using image format '{format.Name}'. Registered encoders include:"); + foreach (KeyValuePair enc in source.Configuration.ImageEncoders) + { + stringBuilder.AppendLine($" - {enc.Key} : {enc.Value.GetType().Name}"); + } + + throw new NotSupportedException(stringBuilder.ToString()); + } + + source.Save(filePath, encoder); + } + + /// + /// Saves the image to the given stream using the currently loaded image format. + /// + /// The Pixel format. + /// The source image + /// The file path to save the image to. + /// The encoder to save the image with. + /// Thrown if the encoder is null. + public static void Save(this Image source, string filePath, IImageEncoder encoder) + where TPixel : struct, IPixel + { + Guard.NotNull(encoder, nameof(encoder)); + using (Stream fs = source.Configuration.FileSystem.Create(filePath)) + { + source.Save(fs, encoder); + } + } +#endif + + /// + /// Saves the image to the given stream using the currently loaded image format. + /// + /// The Pixel format. + /// The source image + /// The stream to save the image to. + /// The format to save the image to. + /// Thrown if the stream is null. + public static void Save(this Image source, Stream stream, IImageFormat format) + where TPixel : struct, IPixel + { + Guard.NotNull(format, nameof(format)); + IImageEncoder encoder = source.Configuration.FindEncoder(format); + + if (encoder == null) + { + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine("Can't find encoder for provided mime type. Available encoded:"); + + foreach (KeyValuePair val in source.Configuration.ImageEncoders) + { + stringBuilder.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}"); + } + + throw new NotSupportedException(stringBuilder.ToString()); + } + + source.Save(stream, encoder); + } + + /// + /// Returns a Base64 encoded string from the given image. + /// + /// + /// The Pixel format. + /// The source image + /// The format. + /// The + public static string ToBase64String(this Image source, IImageFormat format) + where TPixel : struct, IPixel + { + using (var stream = new MemoryStream()) + { + source.Save(stream, format); + stream.Flush(); + return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(stream.ToArray())}"; + } + } + } +} diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs index 04b9902c6..c8cad1648 100644 --- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs @@ -14,39 +14,49 @@ namespace ImageSharp /// Represents a single frame in a animation. /// /// The pixel format. - public class ImageFrame : ImageBase, IImageFrame + public sealed class ImageFrame : ImageBase, IImageFrame where TPixel : struct, IPixel { /// /// Initializes a new instance of the class. /// - /// The width of the image in pixels. - /// The height of the image in pixels. /// /// The configuration providing initialization code which allows extending the library. /// - public ImageFrame(int width, int height, Configuration configuration = null) + /// The width of the image in pixels. + /// The height of the image in pixels. + public ImageFrame(Configuration configuration, int width, int height) : base(configuration, width, height) { } + /// + /// Initializes a new instance of the class. + /// + /// The width of the image in pixels. + /// The height of the image in pixels. + public ImageFrame(int width, int height) + : this(null, width, height) + { + } + /// /// Initializes a new instance of the class. /// /// The image to create the frame from. - public ImageFrame(ImageFrame image) + internal ImageFrame(ImageBase image) : base(image) { - this.CopyProperties(image); } /// /// Initializes a new instance of the class. /// /// The image to create the frame from. - public ImageFrame(ImageBase image) + private ImageFrame(ImageFrame image) : base(image) { + this.CopyProperties(image); } /// @@ -63,15 +73,19 @@ namespace ImageSharp /// /// Returns a copy of the image frame in the given pixel format. /// - /// A function that allows for the correction of vector scaling between unknown color formats. /// The pixel format. /// The - public ImageFrame To(Func scaleFunc = null) + public ImageFrame CloneAs() where TPixel2 : struct, IPixel { - scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); + if (typeof(TPixel2) == typeof(TPixel)) + { + return this.Clone() as ImageFrame; + } - ImageFrame target = new ImageFrame(this.Width, this.Height, this.Configuration); + Func scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(); + + var target = new ImageFrame(this.Configuration, this.Width, this.Height); target.CopyProperties(this); using (PixelAccessor pixels = this.Lock()) @@ -99,11 +113,17 @@ namespace ImageSharp /// Clones the current instance. /// /// The - internal virtual ImageFrame Clone() + public new ImageFrame Clone() { return new ImageFrame(this); } + /// + protected override ImageBase CloneInternal() + { + return this.Clone(); + } + /// /// Copies the properties from the other . /// diff --git a/src/ImageSharp/Image/ImageProcessingExtensions.cs b/src/ImageSharp/Image/ImageProcessingExtensions.cs deleted file mode 100644 index 44fcba7cf..000000000 --- a/src/ImageSharp/Image/ImageProcessingExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Applies the processor to the image. - /// This method does not resize the target image. - /// - /// The pixel format. - /// The image this method extends. - /// The processor to apply to the image. - /// The . - public static IImageOperations Apply(this IImageOperations source, IImageProcessor processor) - where TPixel : struct, IPixel - { - source.ApplyProcessor(processor); - return source; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index 0dcb36905..ae89b777c 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -22,8 +22,7 @@ namespace ImageSharp /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. /// /// The pixel format. - [DebuggerDisplay("Image: {Width}x{Height}")] - public class Image : ImageBase, IImage + public sealed class Image : ImageBase, IImage where TPixel : struct, IPixel { /// @@ -51,20 +50,36 @@ namespace ImageSharp { } + /// + /// Initializes a new instance of the class + /// with the height and the width of the image. + /// + /// + /// The configuration providing initialization code which allows extending the library. + /// + /// The width of the image in pixels. + /// The height of the image in pixels. + /// The images metadata. + internal Image(Configuration configuration, int width, int height, ImageMetaData metadata) + : base(configuration, width, height) + { + this.MetaData = metadata ?? new ImageMetaData(); + } + /// /// Initializes a new instance of the class /// by making a copy from another image. /// /// The other image, where the clone should be made from. /// is null. - public Image(Image other) + private Image(Image other) : base(other) { foreach (ImageFrame frame in other.Frames) { if (frame != null) { - this.Frames.Add(new ImageFrame(frame)); + this.Frames.Add(frame.Clone()); } } @@ -77,101 +92,22 @@ namespace ImageSharp /// /// The other image, where the clone should be made from. /// is null. - public Image(ImageBase other) + private Image(ImageBase other) : base(other) { } - /// - /// Initializes a new instance of the class - /// with the height and the width of the image. - /// - /// - /// The configuration providing initialization code which allows extending the library. - /// - /// The width of the image in pixels. - /// The height of the image in pixels. - /// The images metadata. - internal Image(Configuration configuration, int width, int height, ImageMetaData metadata) - : base(configuration, width, height) - { - this.MetaData = metadata ?? new ImageMetaData(); - } - /// /// Gets the meta data of the image. /// public ImageMetaData MetaData { get; private set; } = new ImageMetaData(); /// - /// Gets the width of the image in inches. It is calculated as the width of the image - /// in pixels multiplied with the density. When the density is equals or less than zero - /// the default value is used. - /// - /// The width of the image in inches. - public double InchWidth => this.Width / this.MetaData.HorizontalResolution; - - /// - /// Gets the height of the image in inches. It is calculated as the height of the image - /// in pixels multiplied with the density. When the density is equals or less than zero - /// the default value is used. - /// - /// The height of the image in inches. - public double InchHeight => this.Height / this.MetaData.VerticalResolution; - - /// - /// Gets a value indicating whether this image is animated. - /// - /// - /// True if this image is animated; otherwise, false. - /// - public bool IsAnimated => this.Frames.Count > 0; - - /// - /// Gets the other frames for the animation. + /// Gets the other frames associated with this image. /// /// The list of frame images. public IList> Frames { get; } = new List>(); - /// - /// Applies the processor to the image. - /// - /// The processor to apply to the image. - /// The structure that specifies the portion of the image object to draw. - public virtual void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) - { - // we want to put this on on here as it gives us a really go place to test/verify processor settings - processor.Apply(this, rectangle); - } - - /// - /// Saves the image to the given stream using the currently loaded image format. - /// - /// The stream to save the image to. - /// The format to save the image to. - /// Thrown if the stream is null. - /// The - public Image Save(Stream stream, IImageFormat format) - { - Guard.NotNull(format, nameof(format)); - IImageEncoder encoder = this.Configuration.FindEncoder(format); - - if (encoder == null) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine("Can't find encoder for provided mime type. Available encoded:"); - - foreach (KeyValuePair val in this.Configuration.ImageEncoders) - { - stringBuilder.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}"); - } - - throw new NotSupportedException(stringBuilder.ToString()); - } - - return this.Save(stream, encoder); - } - /// /// Saves the image to the given stream using the given image encoder. /// @@ -191,70 +127,11 @@ namespace ImageSharp return this; } -#if !NETSTANDARD1_1 - /// - /// Saves the image to the given stream using the currently loaded image format. - /// - /// The file path to save the image to. - /// Thrown if the stream is null. - /// The - public Image Save(string filePath) - { - Guard.NotNullOrEmpty(filePath, nameof(filePath)); - - string ext = Path.GetExtension(filePath).Trim('.'); - var format = this.Configuration.FindFormatByFileExtensions(ext); - if (format == null) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine($"Can't find a format that is associated with the file extention '{ext}'. Registered formats with there extensions include:"); - foreach (IImageFormat fmt in this.Configuration.ImageFormats) - { - stringBuilder.AppendLine($" - {fmt.Name} : {string.Join(", ", fmt.FileExtensions)}"); - } - - throw new NotSupportedException(stringBuilder.ToString()); - } - - IImageEncoder encoder = this.Configuration.FindEncoder(format); - - if (encoder == null) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine($"Can't find encoder for file extention '{ext}' using image format '{format.Name}'. Registered encoders include:"); - foreach (KeyValuePair enc in this.Configuration.ImageEncoders) - { - stringBuilder.AppendLine($" - {enc.Key} : {enc.Value.GetType().Name}"); - } - - throw new NotSupportedException(stringBuilder.ToString()); - } - - return this.Save(filePath, encoder); - } - - /// - /// Saves the image to the given stream using the currently loaded image format. - /// - /// The file path to save the image to. - /// The encoder to save the image with. - /// Thrown if the encoder is null. - /// The - public Image Save(string filePath, IImageEncoder encoder) - { - Guard.NotNull(encoder, nameof(encoder)); - using (Stream fs = this.Configuration.FileSystem.Create(filePath)) - { - return this.Save(fs, encoder); - } - } -#endif - /// /// Clones the current image /// /// Returns a new image with all the same metadata as the original. - public Image Clone() + public new Image Clone() { return new Image(this); } @@ -265,32 +142,21 @@ namespace ImageSharp return $"Image<{typeof(TPixel).Name}>: {this.Width}x{this.Height}"; } - /// - /// Returns a Base64 encoded string from the given image. - /// - /// - /// The format. - /// The - public string ToBase64String(IImageFormat format) - { - using (var stream = new MemoryStream()) - { - this.Save(stream, format); - stream.Flush(); - return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(stream.ToArray())}"; - } - } - /// /// Returns a copy of the image in the given pixel format. /// - /// A function that allows for the correction of vector scaling between unknown color formats. /// The pixel format. /// The - public Image To(Func scaleFunc = null) + public Image CloneAs() where TPixel2 : struct, IPixel { - scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); + if (typeof(TPixel2) == typeof(TPixel)) + { + // short circuit when same pixel types + return this.Clone() as Image; + } + + Func scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(); var target = new Image(this.Configuration, this.Width, this.Height); target.CopyProperties(this); @@ -315,7 +181,7 @@ namespace ImageSharp for (int i = 0; i < this.Frames.Count; i++) { - target.Frames.Add(this.Frames[i].To()); + target.Frames.Add(this.Frames[i].CloneAs()); } return target; @@ -325,7 +191,7 @@ namespace ImageSharp /// Creates a new from this instance /// /// The - internal virtual ImageFrame ToFrame() + internal ImageFrame ToFrame() { return new ImageFrame(this); } @@ -342,6 +208,12 @@ namespace ImageSharp base.Dispose(disposing); } + /// + protected override ImageBase CloneInternal() + { + return this.Clone(); + } + /// /// Copies the properties from the other . /// diff --git a/src/ImageSharp/ImageOperations.cs b/src/ImageSharp/ImageOperations.cs deleted file mode 100644 index dde3153d1..000000000 --- a/src/ImageSharp/ImageOperations.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System.Collections.Generic; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; - - /// - /// The static collection of all the default image formats - /// - /// The pixel format - internal class ImageOperations : IImageOperations - where TPixel : struct, IPixel - { - private readonly Image image; - - /// - /// Initializes a new instance of the class. - /// - /// The image. - public ImageOperations(Image image) - { - this.image = image; - } - - /// - public IImageOperations ApplyProcessor(IImageProcessor processor, Rectangle rectangle) - { - // TODO : make this queue, and allow special processors managage the cloing operation for 'generate' - // to allow things like resize to not need to retain an extra copy of image data in memory, and to - // prevent an pixel copy operation - this.image.ApplyProcessor(processor, rectangle); - return this; - } - - /// - public IImageOperations ApplyProcessor(IImageProcessor processor) - { - return this.ApplyProcessor(processor, this.image.Bounds); - } - - /// - /// Applies a bluck colelctino of pressorce at once - /// - /// Processors to apply - /// this - public IImageOperations ApplyProcessors(IEnumerable> processors) - { - foreach (var processor in processors) - { - return this.ApplyProcessor(processor); - } - - return this; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs b/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs index 29ef5675e..2a25ffc16 100644 --- a/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs +++ b/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs @@ -21,18 +21,11 @@ namespace ImageSharp.PixelFormats /// /// Returns the correct scaling function for the given types The compute scale function. /// - /// The scale function. /// The source pixel format. /// The target pixel format. /// The - public static Func ComputeScaleFunction(Func scaleFunc) + public static Func ComputeScaleFunction() { - // Custom type with a custom function. - if (scaleFunc != null) - { - return scaleFunc; - } - Type source = typeof(TPixel); Type target = typeof(TPixel2); diff --git a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs index a4ee73af4..796b4f597 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs +++ b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static IImageOperations BinaryThreshold(this IImageOperations source, float threshold) + public static IImageProcessorApplicator BinaryThreshold(this IImageProcessorApplicator source, float threshold) where TPixel : struct, IPixel { source.ApplyProcessor(new BinaryThresholdProcessor(threshold)); @@ -41,7 +41,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations BinaryThreshold(this IImageOperations source, float threshold, Rectangle rectangle) + public static IImageProcessorApplicator BinaryThreshold(this IImageProcessorApplicator source, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle); diff --git a/src/ImageSharp/Processing/Binarization/Dither.cs b/src/ImageSharp/Processing/Binarization/Dither.cs index fc5193c33..177279cea 100644 --- a/src/ImageSharp/Processing/Binarization/Dither.cs +++ b/src/ImageSharp/Processing/Binarization/Dither.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The ordered ditherer. /// The . - public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, 0)); @@ -39,7 +39,7 @@ namespace ImageSharp /// The ordered ditherer. /// The component index to test the threshold against. Must range from 0 to 3. /// The . - public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, int index) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither, int index) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, index)); @@ -56,7 +56,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, Rectangle rectangle) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, 0), rectangle); @@ -74,7 +74,7 @@ namespace ImageSharp /// /// The component index to test the threshold against. Must range from 0 to 3. /// The . - public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, Rectangle rectangle, int index) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither, Rectangle rectangle, int index) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, index), rectangle); @@ -89,7 +89,7 @@ namespace ImageSharp /// The diffusion algorithm to apply. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static IImageOperations Dither(this IImageOperations source, IErrorDiffuser diffuser, float threshold) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IErrorDiffuser diffuser, float threshold) where TPixel : struct, IPixel { source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold)); @@ -107,7 +107,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Dither(this IImageOperations source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs index 5710991dc..3d15d1cbc 100644 --- a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs +++ b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations BlackWhite(this IImageOperations source) + public static IImageProcessorApplicator BlackWhite(this IImageProcessorApplicator source) where TPixel : struct, IPixel { source.ApplyProcessor(new BlackWhiteProcessor()); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations BlackWhite(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator BlackWhite(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BlackWhiteProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs index 4d83ba9a2..8a055c33c 100644 --- a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs +++ b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The image this method extends. /// The type of color blindness simulator to apply. /// The . - public static IImageOperations ColorBlindness(this IImageOperations source, ColorBlindness colorBlindness) + public static IImageProcessorApplicator ColorBlindness(this IImageProcessorApplicator source, ColorBlindness colorBlindness) where TPixel : struct, IPixel { source.ApplyProcessor(GetProcessor(colorBlindness)); @@ -42,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations ColorBlindness(this IImageOperations source, ColorBlindness colorBlindness, Rectangle rectangle) + public static IImageProcessorApplicator ColorBlindness(this IImageProcessorApplicator source, ColorBlindness colorBlindness, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(GetProcessor(colorBlindness), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs index 6cdc3343d..7b00ae0d8 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs @@ -22,7 +22,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Grayscale(this IImageOperations source) + public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Grayscale(source, GrayscaleMode.Bt709); @@ -35,7 +35,7 @@ namespace ImageSharp /// The image this method extends. /// The formula to apply to perform the operation. /// The . - public static IImageOperations Grayscale(this IImageOperations source, GrayscaleMode mode) + public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source, GrayscaleMode mode) where TPixel : struct, IPixel { IImageProcessor processor = mode == GrayscaleMode.Bt709 @@ -55,7 +55,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Grayscale(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return Grayscale(source, GrayscaleMode.Bt709, rectangle); @@ -71,7 +71,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Grayscale(this IImageOperations source, GrayscaleMode mode, Rectangle rectangle) + public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source, GrayscaleMode mode, Rectangle rectangle) where TPixel : struct, IPixel { IImageProcessor processor = mode == GrayscaleMode.Bt709 diff --git a/src/ImageSharp/Processing/ColorMatrix/Hue.cs b/src/ImageSharp/Processing/ColorMatrix/Hue.cs index 86a533621..cd2adaadb 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Hue.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Hue.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The image this method extends. /// The angle in degrees to adjust the image. /// The . - public static IImageOperations Hue(this IImageOperations source, float degrees) + public static IImageProcessorApplicator Hue(this IImageProcessorApplicator source, float degrees) where TPixel : struct, IPixel { source.ApplyProcessor(new HueProcessor(degrees)); @@ -42,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Hue(this IImageOperations source, float degrees, Rectangle rectangle) + public static IImageProcessorApplicator Hue(this IImageProcessorApplicator source, float degrees, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new HueProcessor(degrees), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs index 2f331d647..b16f241c0 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Kodachrome(this IImageOperations source) + public static IImageProcessorApplicator Kodachrome(this IImageProcessorApplicator source) where TPixel : struct, IPixel { source.ApplyProcessor(new KodachromeProcessor()); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Kodachrome(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Kodachrome(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new KodachromeProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs index e2c8f3674..0a2f80cc4 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Lomograph(this IImageOperations source) + public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Lomograph(source, GraphicsOptions.Default); @@ -39,7 +39,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Lomograph(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return Lomograph(source, rectangle, GraphicsOptions.Default); @@ -52,7 +52,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static IImageOperations Lomograph(this IImageOperations source, GraphicsOptions options) + public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new LomographProcessor(options)); @@ -69,7 +69,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations Lomograph(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new LomographProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs index bfbf6477b..e579a3251 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Polaroid(this IImageOperations source) + public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Polaroid(source, GraphicsOptions.Default); @@ -39,7 +39,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Polaroid(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return Polaroid(source, rectangle, GraphicsOptions.Default); @@ -52,7 +52,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static IImageOperations Polaroid(this IImageOperations source, GraphicsOptions options) + public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new PolaroidProcessor(options)); @@ -69,7 +69,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations Polaroid(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new PolaroidProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs index 5a2650527..768eb97c5 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The image this method extends. /// The new saturation of the image. Must be between -100 and 100. /// The . - public static IImageOperations Saturation(this IImageOperations source, int amount) + public static IImageProcessorApplicator Saturation(this IImageProcessorApplicator source, int amount) where TPixel : struct, IPixel { source.ApplyProcessor(new SaturationProcessor(amount)); @@ -42,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Saturation(this IImageOperations source, int amount, Rectangle rectangle) + public static IImageProcessorApplicator Saturation(this IImageProcessorApplicator source, int amount, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new SaturationProcessor(amount), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs index f4dbb26c1..5cf64a020 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Sepia(this IImageOperations source) + public static IImageProcessorApplicator Sepia(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new SepiaProcessor()); @@ -37,7 +37,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Sepia(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Sepia(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new SepiaProcessor(), rectangle); } diff --git a/src/ImageSharp/Processing/Convolution/BoxBlur.cs b/src/ImageSharp/Processing/Convolution/BoxBlur.cs index cc0931215..c25de3571 100644 --- a/src/ImageSharp/Processing/Convolution/BoxBlur.cs +++ b/src/ImageSharp/Processing/Convolution/BoxBlur.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations BoxBlur(this IImageOperations source) + public static IImageProcessorApplicator BoxBlur(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(7)); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The 'radius' value representing the size of the area to sample. /// The . - public static IImageOperations BoxBlur(this IImageOperations source, int radius) + public static IImageProcessorApplicator BoxBlur(this IImageProcessorApplicator source, int radius) where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(radius)); @@ -48,7 +48,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations BoxBlur(this IImageOperations source, int radius, Rectangle rectangle) + public static IImageProcessorApplicator BoxBlur(this IImageProcessorApplicator source, int radius, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); } diff --git a/src/ImageSharp/Processing/Convolution/DetectEdges.cs b/src/ImageSharp/Processing/Convolution/DetectEdges.cs index 18006752f..7ececcfe2 100644 --- a/src/ImageSharp/Processing/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Processing/Convolution/DetectEdges.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations DetectEdges(this IImageOperations source) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return DetectEdges(source, new SobelProcessor { Grayscale = true }); @@ -41,7 +41,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations DetectEdges(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); @@ -54,7 +54,7 @@ namespace ImageSharp /// The image this method extends. /// The filter for detecting edges. /// The . - public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, EdgeDetection filter) where TPixel : struct, IPixel => DetectEdges(source, GetProcessor(filter, true)); @@ -66,7 +66,7 @@ namespace ImageSharp /// The filter for detecting edges. /// Whether to convert the image to Grayscale first. Defaults to true. /// The . - public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter, bool grayscale) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, EdgeDetection filter, bool grayscale) where TPixel : struct, IPixel => DetectEdges(source, GetProcessor(filter, grayscale)); @@ -81,7 +81,7 @@ namespace ImageSharp /// /// Whether to convert the image to Grayscale first. Defaults to true. /// The . - public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) where TPixel : struct, IPixel => DetectEdges(source, rectangle, GetProcessor(filter, grayscale)); @@ -92,7 +92,7 @@ namespace ImageSharp /// The image this method extends. /// The filter for detecting edges. /// The . - public static IImageOperations DetectEdges(this IImageOperations source, IEdgeDetectorProcessor filter) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, IEdgeDetectorProcessor filter) where TPixel : struct, IPixel { return source.ApplyProcessor(filter); @@ -108,7 +108,7 @@ namespace ImageSharp /// /// The filter for detecting edges. /// The . - public static IImageOperations DetectEdges(this IImageOperations source, Rectangle rectangle, IEdgeDetectorProcessor filter) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, Rectangle rectangle, IEdgeDetectorProcessor filter) where TPixel : struct, IPixel { source.ApplyProcessor(filter, rectangle); diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs index 953a576fc..4b1682818 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations GaussianBlur(this IImageOperations source) + public static IImageProcessorApplicator GaussianBlur(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(3f)); @@ -35,7 +35,7 @@ namespace ImageSharp /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// The . - public static IImageOperations GaussianBlur(this IImageOperations source, float sigma) + public static IImageProcessorApplicator GaussianBlur(this IImageProcessorApplicator source, float sigma) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(sigma)); @@ -49,7 +49,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations GaussianBlur(this IImageOperations source, float sigma, Rectangle rectangle) + public static IImageProcessorApplicator GaussianBlur(this IImageProcessorApplicator source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(sigma), rectangle); } diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs index 1d0cce222..8c8ac6ed2 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations GaussianSharpen(this IImageOperations source) + public static IImageProcessorApplicator GaussianSharpen(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianSharpenProcessor(3f)); @@ -35,7 +35,7 @@ namespace ImageSharp /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// The . - public static IImageOperations GaussianSharpen(this IImageOperations source, float sigma) + public static IImageProcessorApplicator GaussianSharpen(this IImageProcessorApplicator source, float sigma) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianSharpenProcessor(sigma)); @@ -49,7 +49,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations GaussianSharpen(this IImageOperations source, float sigma, Rectangle rectangle) + public static IImageProcessorApplicator GaussianSharpen(this IImageProcessorApplicator source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianSharpenProcessor(sigma), rectangle); } diff --git a/src/ImageSharp/Processing/Delegate.cs b/src/ImageSharp/Processing/Delegate.cs index 52ec736f5..a5647d69e 100644 --- a/src/ImageSharp/Processing/Delegate.cs +++ b/src/ImageSharp/Processing/Delegate.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The operations to perform on the source. /// returns the current optinoatins class to allow chaining of oprations. - public static IImageOperations Run(this IImageOperations source, Action> operation) + public static IImageProcessorApplicator Run(this IImageProcessorApplicator source, Action> operation) where TPixel : struct, IPixel => source.ApplyProcessor(new DelegateProcessor(operation)); } diff --git a/src/ImageSharp/Processing/Effects/Alpha.cs b/src/ImageSharp/Processing/Effects/Alpha.cs index 4978caf86..b49a697da 100644 --- a/src/ImageSharp/Processing/Effects/Alpha.cs +++ b/src/ImageSharp/Processing/Effects/Alpha.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The new opacity of the image. Must be between 0 and 1. /// The . - public static IImageOperations Alpha(this IImageOperations source, float percent) + public static IImageProcessorApplicator Alpha(this IImageProcessorApplicator source, float percent) where TPixel : struct, IPixel => source.ApplyProcessor(new AlphaProcessor(percent)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Alpha(this IImageOperations source, float percent, Rectangle rectangle) + public static IImageProcessorApplicator Alpha(this IImageProcessorApplicator source, float percent, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new AlphaProcessor(percent), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/BackgroundColor.cs b/src/ImageSharp/Processing/Effects/BackgroundColor.cs index 276bfa2a7..c4754c8e6 100644 --- a/src/ImageSharp/Processing/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Processing/Effects/BackgroundColor.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The color to set as the background. /// The options effecting pixel blending. /// The . - public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color, GraphicsOptions options) + public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new BackgroundColorProcessor(color, options)); @@ -40,7 +40,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); @@ -51,7 +51,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the background. /// The . - public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color) + public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color) where TPixel : struct, IPixel { return BackgroundColor(source, color, GraphicsOptions.Default); @@ -67,7 +67,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color, Rectangle rectangle) + public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color, Rectangle rectangle) where TPixel : struct, IPixel { return BackgroundColor(source, color, rectangle, GraphicsOptions.Default); diff --git a/src/ImageSharp/Processing/Effects/Brightness.cs b/src/ImageSharp/Processing/Effects/Brightness.cs index 9bc27e75d..59a02d456 100644 --- a/src/ImageSharp/Processing/Effects/Brightness.cs +++ b/src/ImageSharp/Processing/Effects/Brightness.cs @@ -24,8 +24,8 @@ namespace ImageSharp /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. /// The . - public static IImageOperations Brightness(this IImageOperations source, int amount) - where TPixel : struct, IPixel + public static IImageProcessorApplicator Brightness(this IImageProcessorApplicator source, int amount) + where TPixel : struct, IPixel => source.ApplyProcessor(new BrightnessProcessor(amount)); /// @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Brightness(this IImageOperations source, int amount, Rectangle rectangle) + public static IImageProcessorApplicator Brightness(this IImageProcessorApplicator source, int amount, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/Contrast.cs b/src/ImageSharp/Processing/Effects/Contrast.cs index 52eb0d5ec..e94605a75 100644 --- a/src/ImageSharp/Processing/Effects/Contrast.cs +++ b/src/ImageSharp/Processing/Effects/Contrast.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The new contrast of the image. Must be between -100 and 100. /// The . - public static IImageOperations Contrast(this IImageOperations source, int amount) + public static IImageProcessorApplicator Contrast(this IImageProcessorApplicator source, int amount) where TPixel : struct, IPixel => source.ApplyProcessor(new ContrastProcessor(amount)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Contrast(this IImageOperations source, int amount, Rectangle rectangle) + public static IImageProcessorApplicator Contrast(this IImageProcessorApplicator source, int amount, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new ContrastProcessor(amount), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/Invert.cs b/src/ImageSharp/Processing/Effects/Invert.cs index 4f8c6a886..5e0ceab75 100644 --- a/src/ImageSharp/Processing/Effects/Invert.cs +++ b/src/ImageSharp/Processing/Effects/Invert.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Invert(this IImageOperations source) + public static IImageProcessorApplicator Invert(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new InvertProcessor()); @@ -36,7 +36,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Invert(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Invert(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new InvertProcessor(), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/OilPainting.cs b/src/ImageSharp/Processing/Effects/OilPainting.cs index 23d552885..e6a8c8373 100644 --- a/src/ImageSharp/Processing/Effects/OilPainting.cs +++ b/src/ImageSharp/Processing/Effects/OilPainting.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations OilPaint(this IImageOperations source) + public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return OilPaint(source, 10, 15); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations OilPaint(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return OilPaint(source, 10, 15, rectangle); @@ -54,7 +54,7 @@ namespace ImageSharp /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. /// The . - public static IImageOperations OilPaint(this IImageOperations source, int levels, int brushSize) + public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source, int levels, int brushSize) where TPixel : struct, IPixel => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize)); @@ -69,7 +69,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations OilPaint(this IImageOperations source, int levels, int brushSize, Rectangle rectangle) + public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source, int levels, int brushSize, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/Pixelate.cs b/src/ImageSharp/Processing/Effects/Pixelate.cs index b9403b765..c1e631838 100644 --- a/src/ImageSharp/Processing/Effects/Pixelate.cs +++ b/src/ImageSharp/Processing/Effects/Pixelate.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Pixelate(this IImageOperations source) + public static IImageProcessorApplicator Pixelate(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new PixelateProcessor(4)); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The size of the pixels. /// The . - public static IImageOperations Pixelate(this IImageOperations source, int size) + public static IImageProcessorApplicator Pixelate(this IImageProcessorApplicator source, int size) where TPixel : struct, IPixel => source.ApplyProcessor(new PixelateProcessor(size)); @@ -48,7 +48,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Pixelate(this IImageOperations source, int size, Rectangle rectangle) + public static IImageProcessorApplicator Pixelate(this IImageProcessorApplicator source, int size, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new PixelateProcessor(size), rectangle); } diff --git a/src/ImageSharp/Processing/Overlays/Glow.cs b/src/ImageSharp/Processing/Overlays/Glow.cs index 4c58a27d4..30ff66692 100644 --- a/src/ImageSharp/Processing/Overlays/Glow.cs +++ b/src/ImageSharp/Processing/Overlays/Glow.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Glow(this IImageOperations source) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Glow(source, GraphicsOptions.Default); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the glow. /// The . - public static IImageOperations Glow(this IImageOperations source, TPixel color) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color) where TPixel : struct, IPixel { return Glow(source, color, GraphicsOptions.Default); @@ -47,7 +47,7 @@ namespace ImageSharp /// The image this method extends. /// The the radius. /// The . - public static IImageOperations Glow(this IImageOperations source, float radius) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, float radius) where TPixel : struct, IPixel { return Glow(source, radius, GraphicsOptions.Default); @@ -62,7 +62,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Glow(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel => source.Glow(rectangle, GraphicsOptions.Default); @@ -77,7 +77,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Glow(this IImageOperations source, TPixel color, float radius, Rectangle rectangle) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, float radius, Rectangle rectangle) where TPixel : struct, IPixel => source.Glow(color, ValueSize.Absolute(radius), rectangle, GraphicsOptions.Default); @@ -88,7 +88,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), options); @@ -100,7 +100,7 @@ namespace ImageSharp /// The color to set as the glow. /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, TPixel color, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(color, ValueSize.PercentageOfWidth(0.5f), options); @@ -112,7 +112,7 @@ namespace ImageSharp /// The the radius. /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, float radius, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, float radius, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(NamedColors.Black, ValueSize.Absolute(radius), options); @@ -126,7 +126,7 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), rectangle, options); @@ -142,7 +142,7 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(color, ValueSize.Absolute(radius), rectangle, options); @@ -158,7 +158,7 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - private static IImageOperations Glow(this IImageOperations source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) + private static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new GlowProcessor(color, radius, options), rectangle); @@ -171,7 +171,7 @@ namespace ImageSharp /// The the radius. /// The options effecting things like blending. /// The . - private static IImageOperations Glow(this IImageOperations source, TPixel color, ValueSize radius, GraphicsOptions options) + private static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, ValueSize radius, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new GlowProcessor(color, radius, options)); } diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/Vignette.cs index 175d3ea3a..81cd773b2 100644 --- a/src/ImageSharp/Processing/Overlays/Vignette.cs +++ b/src/ImageSharp/Processing/Overlays/Vignette.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Vignette(this IImageOperations source) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Vignette(source, GraphicsOptions.Default); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the vignette. /// The . - public static IImageOperations Vignette(this IImageOperations source, TPixel color) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color) where TPixel : struct, IPixel { return Vignette(source, color, GraphicsOptions.Default); @@ -48,7 +48,7 @@ namespace ImageSharp /// The the x-radius. /// The the y-radius. /// The . - public static IImageOperations Vignette(this IImageOperations source, float radiusX, float radiusY) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, float radiusX, float radiusY) where TPixel : struct, IPixel { return Vignette(source, radiusX, radiusY, GraphicsOptions.Default); @@ -63,7 +63,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Vignette(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return Vignette(source, rectangle, GraphicsOptions.Default); @@ -81,7 +81,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Vignette(this IImageOperations source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) where TPixel : struct, IPixel => source.Vignette(color, radiusX, radiusY, rectangle, GraphicsOptions.Default); @@ -92,7 +92,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); @@ -104,7 +104,7 @@ namespace ImageSharp /// The color to set as the vignette. /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, TPixel color, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); @@ -117,7 +117,7 @@ namespace ImageSharp /// The the y-radius. /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, float radiusX, float radiusY, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, float radiusX, float radiusY, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(NamedColors.Black, radiusX, radiusY, options); @@ -131,7 +131,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle, options); @@ -148,15 +148,15 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(color, radiusX, radiusY, rectangle, options); - private static IImageOperations VignetteInternal(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) + private static IImageProcessorApplicator VignetteInternal(this IImageProcessorApplicator source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options), rectangle); - private static IImageOperations VignetteInternal(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) + private static IImageProcessorApplicator VignetteInternal(this IImageProcessorApplicator source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options)); } diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs index ceb985b0b..e5813f0d5 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs @@ -50,7 +50,7 @@ namespace ImageSharp.Processing.Processors using (var firstPassPixels = new PixelAccessor(width, height)) using (PixelAccessor sourcePixels = source.Lock()) { - this.ApplyConvolution(firstPassPixels, sourcePixels, source.Bounds, this.KernelX); + this.ApplyConvolution(firstPassPixels, sourcePixels, source.Bounds(), this.KernelX); this.ApplyConvolution(sourcePixels, firstPassPixels, sourceRectangle, this.KernelY); } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs index 367c288fc..cc21c3e19 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs @@ -89,7 +89,7 @@ namespace ImageSharp.Processing.Processors int maxY = Math.Min(source.Height, endY); // we need a clean copy for each pass to start from - using (ImageBase cleanCopy = new Image(source)) + using (ImageBase cleanCopy = source.Clone()) { new ConvolutionProcessor(kernels[0]).Apply(source, sourceRectangle); @@ -116,7 +116,7 @@ namespace ImageSharp.Processing.Processors // ReSharper disable once ForCanBeConvertedToForeach for (int i = 1; i < kernels.Length; i++) { - using (ImageBase pass = new Image(cleanCopy)) + using (ImageBase pass = cleanCopy.Clone()) { new ConvolutionProcessor(kernels[i]).Apply(pass, sourceRectangle); diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 5da6a96dc..2b9c88f2d 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -62,7 +62,7 @@ namespace ImageSharp.Processing.Processors TPixel glowColor = this.GlowColor; Vector2 centre = Rectangle.Center(sourceRectangle); - var finalRadius = this.Radius.Calculate(source.Bounds.Size); + var finalRadius = this.Radius.Calculate(source.Size()); float maxDistance = finalRadius > 0 ? MathF.Min(finalRadius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index 07c45f4f0..de50dd84b 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -81,8 +81,8 @@ namespace ImageSharp.Processing.Processors TPixel vignetteColor = this.VignetteColor; Vector2 centre = Rectangle.Center(sourceRectangle); - var finalradiusX = this.RadiusX.Calculate(source.Bounds.Size); - var finalradiusY = this.RadiusY.Calculate(source.Bounds.Size); + var finalradiusX = this.RadiusX.Calculate(source.Size()); + var finalradiusY = this.RadiusY.Calculate(source.Size()); float rX = finalradiusX > 0 ? MathF.Min(finalradiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; float rY = finalradiusY > 0 ? MathF.Min(finalradiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; float maxDistance = MathF.Sqrt((rX * rX) + (rY * rY)); diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs index a52065ea9..648e86d3c 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs @@ -39,7 +39,7 @@ namespace ImageSharp.Processing.Processors /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - using (ImageBase temp = new Image(source)) + using (ImageBase temp = source.Clone()) { // Detect the edges. new SobelProcessor().Apply(temp, sourceRectangle); diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index e6b1d180f..45d04626e 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -45,6 +45,7 @@ namespace ImageSharp.Processing.Processors int height = this.CanvasRectangle.Height; int width = this.CanvasRectangle.Width; Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); + Rectangle sourceBounds = source.Bounds(); using (var targetPixels = new PixelAccessor(width, height)) { @@ -60,7 +61,7 @@ namespace ImageSharp.Processing.Processors { var transformedPoint = Point.Rotate(new Point(x, y), matrix); - if (source.Bounds.Contains(transformedPoint.X, transformedPoint.Y)) + if (sourceBounds.Contains(transformedPoint.X, transformedPoint.Y)) { targetRow[x] = source[transformedPoint.X, transformedPoint.Y]; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs index 9766caa69..757f3fa0b 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs @@ -45,6 +45,7 @@ namespace ImageSharp.Processing.Processors int height = this.CanvasRectangle.Height; int width = this.CanvasRectangle.Width; Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); + Rectangle sourceBounds = source.Bounds(); using (var targetPixels = new PixelAccessor(width, height)) { @@ -60,7 +61,7 @@ namespace ImageSharp.Processing.Processors { var transformedPoint = Point.Skew(new Point(x, y), matrix); - if (source.Bounds.Contains(transformedPoint.X, transformedPoint.Y)) + if (sourceBounds.Contains(transformedPoint.X, transformedPoint.Y)) { targetRow[x] = source[transformedPoint.X, transformedPoint.Y]; } diff --git a/src/ImageSharp/Processing/Transforms/AutoOrient.cs b/src/ImageSharp/Processing/Transforms/AutoOrient.cs index 6f7d1b665..f741e41b1 100644 --- a/src/ImageSharp/Processing/Transforms/AutoOrient.cs +++ b/src/ImageSharp/Processing/Transforms/AutoOrient.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image to auto rotate. /// The - public static IImageOperations AutoOrient(this IImageOperations source) + public static IImageProcessorApplicator AutoOrient(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new Processing.Processors.AutoRotateProcessor()); } diff --git a/src/ImageSharp/Processing/Transforms/Crop.cs b/src/ImageSharp/Processing/Transforms/Crop.cs index c518ac5ac..aad80fa0f 100644 --- a/src/ImageSharp/Processing/Transforms/Crop.cs +++ b/src/ImageSharp/Processing/Transforms/Crop.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The target image width. /// The target image height. /// The - public static IImageOperations Crop(this IImageOperations source, int width, int height) + public static IImageProcessorApplicator Crop(this IImageProcessorApplicator source, int width, int height) where TPixel : struct, IPixel => Crop(source, new Rectangle(0, 0, width, height)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to retain. /// /// The - public static IImageOperations Crop(this IImageOperations source, Rectangle cropRectangle) + public static IImageProcessorApplicator Crop(this IImageProcessorApplicator source, Rectangle cropRectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new CropProcessor(cropRectangle)); } diff --git a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs index 00f404321..a0704619c 100644 --- a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs +++ b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The image to crop. /// The threshold for entropic density. /// The - public static IImageOperations EntropyCrop(this IImageOperations source, float threshold = .5f) + public static IImageProcessorApplicator EntropyCrop(this IImageProcessorApplicator source, float threshold = .5f) where TPixel : struct, IPixel => source.ApplyProcessor(new EntropyCropProcessor(threshold)); } diff --git a/src/ImageSharp/Processing/Transforms/Flip.cs b/src/ImageSharp/Processing/Transforms/Flip.cs index 6cde1257c..2f20c3bd8 100644 --- a/src/ImageSharp/Processing/Transforms/Flip.cs +++ b/src/ImageSharp/Processing/Transforms/Flip.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The to perform the flip. /// The - public static IImageOperations Flip(this IImageOperations source, FlipType flipType) + public static IImageProcessorApplicator Flip(this IImageProcessorApplicator source, FlipType flipType) where TPixel : struct, IPixel => source.ApplyProcessor(new FlipProcessor(flipType)); } diff --git a/src/ImageSharp/Processing/Transforms/Pad.cs b/src/ImageSharp/Processing/Transforms/Pad.cs index fb064f5ce..90a9e281b 100644 --- a/src/ImageSharp/Processing/Transforms/Pad.cs +++ b/src/ImageSharp/Processing/Transforms/Pad.cs @@ -26,7 +26,7 @@ namespace ImageSharp /// The new width. /// The new height. /// The . - public static IImageOperations Pad(this IImageOperations source, int width, int height) + public static IImageProcessorApplicator Pad(this IImageProcessorApplicator source, int width, int height) where TPixel : struct, IPixel { ResizeOptions options = new ResizeOptions diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs index 6ccea5f42..4c04991c0 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/Resize.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The resize options. /// The /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, ResizeOptions options) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, ResizeOptions options) where TPixel : struct, IPixel { return source.Run(img => @@ -56,7 +56,7 @@ namespace ImageSharp /// The target image size. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, Size size) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, Size size) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), false); @@ -71,7 +71,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, Size size, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, Size size, bool compand) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), compand); @@ -86,7 +86,7 @@ namespace ImageSharp /// The target image height. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), false); @@ -102,7 +102,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, bool compand) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), compand); @@ -118,7 +118,7 @@ namespace ImageSharp /// The to perform the resampling. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler) where TPixel : struct, IPixel { return Resize(source, width, height, sampler, false); @@ -135,7 +135,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler, bool compand) where TPixel : struct, IPixel { return Resize(source, width, height, sampler, new Rectangle(0, 0, width, height), compand); @@ -159,7 +159,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { return source.Run(img => @@ -199,7 +199,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler, Rectangle targetRectangle, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { return source.Run(img => diff --git a/src/ImageSharp/Processing/Transforms/Rotate.cs b/src/ImageSharp/Processing/Transforms/Rotate.cs index 92349dba3..08ac44dad 100644 --- a/src/ImageSharp/Processing/Transforms/Rotate.cs +++ b/src/ImageSharp/Processing/Transforms/Rotate.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image to rotate. /// The angle in degrees to perform the rotation. /// The - public static IImageOperations Rotate(this IImageOperations source, float degrees) + public static IImageProcessorApplicator Rotate(this IImageProcessorApplicator source, float degrees) where TPixel : struct, IPixel { return Rotate(source, degrees, true); @@ -37,7 +37,7 @@ namespace ImageSharp /// The image to rotate. /// The to perform the rotation. /// The - public static IImageOperations Rotate(this IImageOperations source, RotateType rotateType) + public static IImageProcessorApplicator Rotate(this IImageProcessorApplicator source, RotateType rotateType) where TPixel : struct, IPixel => Rotate(source, (float)rotateType, false); @@ -49,7 +49,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation. /// Whether to expand the image to fit the rotated result. /// The - public static IImageOperations Rotate(this IImageOperations source, float degrees, bool expand) + public static IImageProcessorApplicator Rotate(this IImageProcessorApplicator source, float degrees, bool expand) where TPixel : struct, IPixel => source.ApplyProcessor(new RotateProcessor { Angle = degrees, Expand = expand }); } diff --git a/src/ImageSharp/Processing/Transforms/RotateFlip.cs b/src/ImageSharp/Processing/Transforms/RotateFlip.cs index fda11d833..2c321358e 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlip.cs +++ b/src/ImageSharp/Processing/Transforms/RotateFlip.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The to perform the rotation. /// The to perform the flip. /// The - public static IImageOperations RotateFlip(this IImageOperations source, RotateType rotateType, FlipType flipType) + public static IImageProcessorApplicator RotateFlip(this IImageProcessorApplicator source, RotateType rotateType, FlipType flipType) where TPixel : struct, IPixel { return source.Rotate(rotateType).Flip(flipType); diff --git a/src/ImageSharp/Processing/Transforms/Skew.cs b/src/ImageSharp/Processing/Transforms/Skew.cs index f38606eda..8fde7270d 100644 --- a/src/ImageSharp/Processing/Transforms/Skew.cs +++ b/src/ImageSharp/Processing/Transforms/Skew.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation along the x-axis. /// The angle in degrees to perform the rotation along the y-axis. /// The - public static IImageOperations Skew(this IImageOperations source, float degreesX, float degreesY) + public static IImageProcessorApplicator Skew(this IImageProcessorApplicator source, float degreesX, float degreesY) where TPixel : struct, IPixel { return Skew(source, degreesX, degreesY, true); @@ -39,7 +39,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation along the y-axis. /// Whether to expand the image to fit the skewed result. /// The - public static IImageOperations Skew(this IImageOperations source, float degreesX, float degreesY, bool expand) + public static IImageProcessorApplicator Skew(this IImageProcessorApplicator source, float degreesX, float degreesY, bool expand) where TPixel : struct, IPixel => source.ApplyProcessor(new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }); } diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index 2b5130f8c..54c57b508 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The quantization mode to apply to perform the operation. /// The maximum number of colors to return. Defaults to 256. /// The . - public static IImageOperations Quantize(this IImageOperations source, Quantization mode = Quantization.Octree, int maxColors = 256) + public static IImageProcessorApplicator Quantize(this IImageProcessorApplicator source, Quantization mode = Quantization.Octree, int maxColors = 256) where TPixel : struct, IPixel { IQuantizer quantizer; @@ -54,7 +54,7 @@ namespace ImageSharp /// The quantizer to apply to perform the operation. /// The maximum number of colors to return. /// The . - public static IImageOperations Quantize(this IImageOperations source, IQuantizer quantizer, int maxColors) + public static IImageProcessorApplicator Quantize(this IImageProcessorApplicator source, IQuantizer quantizer, int maxColors) where TPixel : struct, IPixel { return source.Run(img => diff --git a/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs b/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs index 2e3ea7a54..d8a2de148 100644 --- a/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs @@ -70,7 +70,7 @@ namespace ImageSharp.Quantizers if (this.Dither) { // We clone the image as we don't want to alter the original. - using (var clone = new Image(image)) + using (ImageBase clone = image.Clone()) { this.SecondPass(clone, quantizedPixels, width, height); } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 53cdb1b93..88851bd0c 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -35,7 +35,7 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.ApplyProcessor(bulk, image.Bounds); + bulk.Apply(image, image.Bounds()); return new CoreSize(image.Width, image.Height); } } @@ -45,7 +45,7 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.ApplyProcessor(parallel, image.Bounds); + parallel.Apply(image, image.Bounds()); return new CoreSize(image.Width, image.Height); } } diff --git a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs index 398db976e..997215ce2 100644 --- a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs @@ -17,7 +17,7 @@ namespace ImageSharp.Tests { this.options = new GraphicsOptions(false) { }; this.rect = new Rectangle(91, 123, 324, 56); // make this random? - this.operations = new FakeImageOperationsProvider.FakeImageOperations(null); + this.operations = new FakeImageOperationsProvider.FakeImageOperations(null, false); } public T Verify(int index = 0) @@ -28,6 +28,7 @@ namespace ImageSharp.Tests return Assert.IsType(operation.Processor); } + public T Verify(Rectangle rect, int index = 0) { Assert.InRange(index, 0, this.operations.applied.Count - 1); diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index b9a1d80a2..70e55b426 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -8,7 +8,7 @@ using ImageSharp.Processing; using SixLabors.Primitives; - public class FakeImageOperationsProvider : IImageOperationsProvider + public class FakeImageOperationsProvider : IImageProcessorApplicatorFactory { private List ImageOperators = new List(); @@ -29,27 +29,41 @@ .SelectMany(x => x.applied); } - public IImageOperations CreateMutator(Image source) where TPixel : struct, IPixel + public IInternalImageProcessorApplicator CreateImageOperations(Image source, bool mutate) where TPixel : struct, IPixel { - var op = new FakeImageOperations(source); + var op = new FakeImageOperations(source, mutate); this.ImageOperators.Add(op); return op; } - public class FakeImageOperations : IImageOperations + public class FakeImageOperations : IInternalImageProcessorApplicator where TPixel : struct, IPixel { public Image source; public List applied = new List(); + public bool mutate; - public FakeImageOperations(Image source) + public FakeImageOperations(Image source, bool mutate) { - this.source = source; + this.mutate = mutate; + if (mutate) + { + this.source = source; + } + else + { + this.source = source.Clone(); + } + } + + public Image Apply() + { + return source; } - public IImageOperations ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { applied.Add(new AppliedOpperation { @@ -59,7 +73,7 @@ return this; } - public IImageOperations ApplyProcessor(IImageProcessor processor) + public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor) { applied.Add(new AppliedOpperation { diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 1f669ba24..be6ce1343 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -64,7 +64,7 @@ namespace ImageSharp.Tests { using (Image srcImage = Image.Load(file.Bytes, out var mimeType)) { - using (Image image = new Image(srcImage)) + using (Image image = srcImage.Clone()) { using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}")) { @@ -74,7 +74,7 @@ namespace ImageSharp.Tests } } - using (Image image = new Image(srcImage)) + using (Image image = srcImage.Clone()) { using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}")) { @@ -83,7 +83,7 @@ namespace ImageSharp.Tests } } - using (Image image = new Image(srcImage)) + using (Image image = srcImage.Clone()) { using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}")) { diff --git a/tests/ImageSharp.Tests/ImageOperationTests.cs b/tests/ImageSharp.Tests/ImageOperationTests.cs index a84b0fcb0..f7352a8ea 100644 --- a/tests/ImageSharp.Tests/ImageOperationTests.cs +++ b/tests/ImageSharp.Tests/ImageOperationTests.cs @@ -92,9 +92,9 @@ namespace ImageSharp.Tests } [Fact] - public void ApplyProcessors_ListOfProcessors_AppliesALlProcessorsToOperation() + public void ApplyProcessors_ListOfProcessors_AppliesAllProcessorsToOperation() { - var operations = new FakeImageOperationsProvider.FakeImageOperations(null); + var operations = new FakeImageOperationsProvider.FakeImageOperations(null, false); operations.ApplyProcessors(this.processor); Assert.Contains(this.processor, operations.applied.Select(x => x.Processor)); } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs index 3e8c99e35..209d50661 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -37,7 +37,7 @@ namespace ImageSharp.Tests.Processing.Processors.Binarization { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs index 0a4ccaeb1..edaede58d 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs @@ -49,7 +49,7 @@ namespace ImageSharp.Tests.Processing.Processors.Binarization where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); @@ -78,7 +78,7 @@ namespace ImageSharp.Tests.Processing.Processors.Binarization where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs index 5b4953d60..dcc61a629 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs index 6d2df4c9b..59f389cfd 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs @@ -43,7 +43,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs index 3fba626c2..7fdc07005 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs @@ -48,7 +48,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); image.Mutate(x => x.Grayscale(value, bounds)); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs index 1019e2def..30beb61d0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs index 9e7c2c02f..be2464d1d 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs index d44f7005f..170999594 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs @@ -31,7 +31,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs index 29ae45be4..367ce04c7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs index df0af2bb6..ba0cc344e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs index 82bd4b26e..5879a8bb7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs index 71b5ee69b..3daa8c933 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index 7a5dbc1fc..72a3e9023 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs index 5bb372e54..9ccc4e453 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs index 71eae5b09..dab576c2b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs index c29267b10..a7626f386 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs index 2e2768115..70c2844de 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs index abd9951ab..57b7cd8d9 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs index c9d322a97..a5423ba93 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs index 839b1bb99..2816cb925 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs index 17598c648..0a26cee69 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs index e24b359e3..92703ca07 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs @@ -52,7 +52,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs index cab607973..3f69ba148 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs @@ -53,7 +53,7 @@ namespace ImageSharp.Tests.Processing.Processors.Overlays where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs index 6f856c686..c65b254c0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs @@ -53,7 +53,7 @@ namespace ImageSharp.Tests.Processing.Processors.Overlays where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index f634eb3f4..2b505a2e4 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -129,7 +129,7 @@ namespace ImageSharp.Tests /// public Image CreateImage() { - return new Image(this.image); + return this.image.Clone(); } /// diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs index 4a0950788..bfa70a2a5 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs @@ -28,7 +28,7 @@ namespace ImageSharp.Tests public virtual Image CreateImage(Image other) { - return new Image(other); + return other.Clone(); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs index 20af430a5..052a4c774 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Tests public override Image CreateImage(Image other) { - return new Image(other); + return other.Clone(); } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index e939d78bb..ae10bf9af 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -85,7 +85,7 @@ namespace ImageSharp.Tests /// /// Returns an instance to the test case with the necessary traits. /// - public Image GetImage(Action> operationsToApply) + public Image GetImage(Action> operationsToApply) { var img = GetImage(); img.Mutate(operationsToApply); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index 96d38fc40..f25beb726 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -49,7 +49,7 @@ namespace ImageSharp.Tests } } - return new Image(testImages[this.SourceFileOrDescription]); + return testImages[this.SourceFileOrDescription].Clone(); } ///