diff --git a/README.md b/README.md index 3c343ad135..078219183e 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; // Individual pixels -using (Image image = new Image(400, 400)) +using (var image = new Image(400, 400)) { image[200, 200] = Rgba32.White; } diff --git a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs index 812744b895..f4a6458206 100644 --- a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs +++ b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs @@ -5,7 +5,6 @@ using System; using System.Buffers; using SixLabors.ImageSharp.Memory; -using SixLabors.Memory; using SixLabors.Primitives; using SixLabors.Shapes; diff --git a/src/ImageSharp.Drawing/Processing/Brushes.cs b/src/ImageSharp.Drawing/Processing/Brushes.cs index bd73e1f1b6..bd10e90c68 100644 --- a/src/ImageSharp.Drawing/Processing/Brushes.cs +++ b/src/ImageSharp.Drawing/Processing/Brushes.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing { /// diff --git a/src/ImageSharp.Drawing/Processing/ColorStop.cs b/src/ImageSharp.Drawing/Processing/ColorStop.cs index aee559469f..21c82b63ff 100644 --- a/src/ImageSharp.Drawing/Processing/ColorStop.cs +++ b/src/ImageSharp.Drawing/Processing/ColorStop.cs @@ -3,8 +3,6 @@ using System.Diagnostics; -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing { /// diff --git a/src/ImageSharp.Drawing/Processing/DrawingHelpers.cs b/src/ImageSharp.Drawing/Processing/DrawingHelpers.cs index b4ce0c5cba..25a8204f2a 100644 --- a/src/ImageSharp.Drawing/Processing/DrawingHelpers.cs +++ b/src/ImageSharp.Drawing/Processing/DrawingHelpers.cs @@ -14,9 +14,9 @@ namespace SixLabors.ImageSharp.Processing public static DenseMatrix ToPixelMatrix(this DenseMatrix colorMatrix, Configuration configuration) where TPixel : struct, IPixel { - DenseMatrix result = new DenseMatrix(colorMatrix.Columns, colorMatrix.Rows); + var result = new DenseMatrix(colorMatrix.Columns, colorMatrix.Rows); Color.ToPixel(configuration, colorMatrix.Span, result.Span); return result; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawBezierExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawBezierExtensions.cs index 85addd5f2c..7660e72255 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawBezierExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawBezierExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using SixLabors.Shapes; diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawLineExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawLineExtensions.cs index b7b419be61..98e8fdc594 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawLineExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawLineExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using SixLabors.Shapes; diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs index 79b4fd0a80..a68b69a444 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.Shapes; namespace SixLabors.ImageSharp.Processing diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs index efafdde5ab..dfe30f6a3c 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.Shapes; diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs index 324e05e87b..86d8e9e2e2 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using SixLabors.Shapes; diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs index d0a6c8ccd2..da78ab2ecc 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using SixLabors.Shapes; diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs index 163a676bbe..05cd3a1ae6 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.Fonts; -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Text; using SixLabors.Primitives; diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs index ca7eab93f9..5de9c6d4ed 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.PixelFormats; + using SixLabors.Shapes; namespace SixLabors.ImageSharp.Processing diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs index d750ff455b..776e1f7e4e 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.Shapes; namespace SixLabors.ImageSharp.Processing diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPolygonExtensions.cs index 8150c7381e..9262c8baad 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/FillPolygonExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/FillPolygonExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using SixLabors.Shapes; diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillRectangleExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillRectangleExtensions.cs index ad512015e2..cfe37deb2c 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/FillRectangleExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/FillRectangleExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using SixLabors.Shapes; diff --git a/src/ImageSharp.Drawing/Processing/IPen.cs b/src/ImageSharp.Drawing/Processing/IPen.cs index af7517905d..0efcfc108c 100644 --- a/src/ImageSharp.Drawing/Processing/IPen.cs +++ b/src/ImageSharp.Drawing/Processing/IPen.cs @@ -3,8 +3,6 @@ using System; -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing { /// diff --git a/src/ImageSharp.Drawing/Processing/ImageBrush.cs b/src/ImageSharp.Drawing/Processing/ImageBrush.cs index 33f7b831ab..8485ddfd09 100644 --- a/src/ImageSharp.Drawing/Processing/ImageBrush.cs +++ b/src/ImageSharp.Drawing/Processing/ImageBrush.cs @@ -7,7 +7,6 @@ using System.Buffers; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing diff --git a/src/ImageSharp.Drawing/Processing/Pen.cs b/src/ImageSharp.Drawing/Processing/Pen.cs index c9d60a50e2..ebad687d5a 100644 --- a/src/ImageSharp.Drawing/Processing/Pen.cs +++ b/src/ImageSharp.Drawing/Processing/Pen.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing { diff --git a/src/ImageSharp.Drawing/Processing/Pens.cs b/src/ImageSharp.Drawing/Processing/Pens.cs index 4b8f478c92..e60b5b6c7c 100644 --- a/src/ImageSharp.Drawing/Processing/Pens.cs +++ b/src/ImageSharp.Drawing/Processing/Pens.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing { /// diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs index 889b7b5674..7ec359220e 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs @@ -1,12 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Buffers; -using System.Threading.Tasks; - -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Processors.Drawing diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs index 0f72a4692f..81880308cf 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs @@ -1,10 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Threading.Tasks; - using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Memory; namespace SixLabors.ImageSharp.Processing.Processors.Drawing { diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs index 1b207d4cd4..000fa260ab 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs @@ -3,7 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.Memory; namespace SixLabors.ImageSharp.Processing.Processors.Drawing { diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs index d5778c865f..347d243ae7 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing } float yPlusOne = y + 1; - for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction) + for (float subPixel = y; subPixel < yPlusOne; subPixel += subpixelFraction) { int pointsFound = region.Scan(subPixel + offset, buffer, configuration); if (pointsFound == 0) @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing QuickSort.Sort(buffer.Slice(0, pointsFound)); - for (int point = 0; point < pointsFound; point += 2) + for (int point = 0; point < pointsFound && point < buffer.Length - 1; point += 2) { // points will be paired up float scanStart = buffer[point] - minX; @@ -192,4 +192,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing return this.definition.Options.IsOpaqueColorWithoutBlending(solidBrush.Color); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs index 9fb52d6bc3..b3c336c885 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs @@ -135,21 +135,22 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text private readonly PathBuilder builder; - private Point currentRenderPosition = default; - private (GlyphRendererParameters glyph, PointF subPixelOffset) currentGlyphRenderParams = default; - private readonly int offset = 0; - private PointF currentPoint = default(PointF); + private Point currentRenderPosition; + private (GlyphRendererParameters glyph, PointF subPixelOffset) currentGlyphRenderParams; + private readonly int offset; + private PointF currentPoint; private readonly Dictionary<(GlyphRendererParameters glyph, PointF subPixelOffset), GlyphRenderData> glyphData = new Dictionary<(GlyphRendererParameters glyph, PointF subPixelOffset), GlyphRenderData>(); - private readonly bool renderOutline = false; - private readonly bool renderFill = false; - private bool rasterizationRequired = false; + private readonly bool renderOutline; + private readonly bool renderFill; + private bool rasterizationRequired; public CachingGlyphRenderer(MemoryAllocator memoryAllocator, int size, IPen pen, bool renderFill) { this.MemoryAllocator = memoryAllocator; + this.currentRenderPosition = default; this.Pen = pen; this.renderFill = renderFill; this.renderOutline = pen != null; @@ -191,7 +192,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text subPixelOffset.X = MathF.Round(subPixelOffset.X * AccuracyMultiple) / AccuracyMultiple; subPixelOffset.Y = MathF.Round(subPixelOffset.Y * AccuracyMultiple) / AccuracyMultiple; - // we have offset our rendering origion a little bit down to prevent edge cropping, move the draw origin up to compensate + // we have offset our rendering origin a little bit down to prevent edge cropping, move the draw origin up to compensate this.currentRenderPosition = new Point(this.currentRenderPosition.X - this.offset, this.currentRenderPosition.Y - this.offset); this.currentGlyphRenderParams = (parameters, subPixelOffset); @@ -205,7 +206,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text // we check to see if we have a render cache and if we do then we render else this.builder.Clear(); - // ensure all glyphs render around [zero, zero] so offset negative root positions so when we draw the glyph we can offet it back + // ensure all glyphs render around [zero, zero] so offset negative root positions so when we draw the glyph we can offset it back this.builder.SetOrigin(new PointF(-(int)bounds.X + this.offset, -(int)bounds.Y + this.offset)); this.rasterizationRequired = true; @@ -244,7 +245,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text { GlyphRenderData renderData = default; - // has the glyoh been rendedered already???? + // has the glyph been rendered already? if (this.rasterizationRequired) { IPath path = this.builder.Build(); @@ -303,7 +304,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text float offset = 0.5f; if (this.Options.Antialias) { - offset = 0f; // we are antialising skip offsetting as real antalising should take care of offset. + offset = 0f; // we are antialiasing skip offsetting as real antialiasing should take care of offset. subpixelCount = this.Options.AntialiasSubpixelDepth; if (subpixelCount < 4) { @@ -326,7 +327,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text bool scanlineDirty = false; float yPlusOne = y + 1; - for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction) + for (float subPixel = y; subPixel < yPlusOne; subPixel += subpixelFraction) { var start = new PointF(path.Bounds.Left - 1, subPixel); var end = new PointF(path.Bounds.Right + 1, subPixel); @@ -443,4 +444,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index e0d7a4b184..4b1d4222cb 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Advanced /// /// Returns a reference to the 0th element of the Pixel buffer, /// allowing direct manipulation of pixel data through unsafe operations. - /// The pixel buffer is a contigous memory area containing Width*Height TPixel elements layed out in row-major order. + /// The pixel buffer is a contiguous memory area containing Width*Height TPixel elements laid out in row-major order. /// /// The Pixel format. /// The source image @@ -153,42 +153,6 @@ namespace SixLabors.ImageSharp.Advanced internal static MemoryAllocator GetMemoryAllocator(this IConfigurable source) => GetConfiguration(source).MemoryAllocator; - /// - /// Gets the span to the backing buffer. - /// - /// The type of the pixel. - /// The source. - /// The span returned from Pixel source - private static Span GetSpan(IPixelSource source) - where TPixel : struct, IPixel - => source.PixelBuffer.GetSpan(); - - /// - /// Gets the span to the backing buffer at the given row. - /// - /// The type of the pixel. - /// The source. - /// The row. - /// - /// The span returned from Pixel source - /// - private static Span GetSpan(IPixelSource source, int row) - where TPixel : struct, IPixel - => GetSpan(source.PixelBuffer, row); - - /// - /// Gets the span to the backing buffer at the given row. - /// - /// The type of the pixel. - /// The source. - /// The row. - /// - /// The span returned from Pixel source. - /// - private static Span GetSpan(Buffer2D source, int row) - where TPixel : struct, IPixel - => source.GetSpan().Slice(row * source.Width, source.Width); - /// /// Gets the configuration. /// diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index 82df7304e5..084f2403e5 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -1,12 +1,15 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.ImageSharp.Processing.Processors.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Transforms; +using SixLabors.Primitives; namespace SixLabors.ImageSharp.Advanced { @@ -15,8 +18,10 @@ namespace SixLabors.ImageSharp.Advanced /// compiled on demand by a JIT compiler. This means there are a few limitations with respect to generics, /// these are caused because not every possible generic instantiation can be determined up front at compile time. /// The Aot Compiler is designed to overcome the limitations of this compiler. + /// None of the methods in this class should ever be called, the code only has to exist at compile-time to be picked up by the AoT compiler. + /// (Very similar to the LinkerIncludes.cs technique used in Xamarin.Android projects.) /// - public static class AotCompilerTools + internal static class AotCompilerTools { static AotCompilerTools() { @@ -25,21 +30,59 @@ namespace SixLabors.ImageSharp.Advanced System.Runtime.CompilerServices.Unsafe.SizeOf(); System.Runtime.CompilerServices.Unsafe.SizeOf(); System.Runtime.CompilerServices.Unsafe.SizeOf(); + System.Runtime.CompilerServices.Unsafe.SizeOf(); System.Runtime.CompilerServices.Unsafe.SizeOf(); System.Runtime.CompilerServices.Unsafe.SizeOf(); } + /// + /// This is the method that seeds the AoT compiler. + /// None of these seed methods needs to actually be called to seed the compiler. + /// The calls just need to be present when the code is compiled, and each implementation will be built. + /// + private static void SeedEverything() + { + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + Seed(); + } + /// /// Seeds the compiler using the given pixel format. /// /// The pixel format. - public static void Seed() + private static void Seed() where TPixel : struct, IPixel { // This is we actually call all the individual methods you need to seed. AotCompileOctreeQuantizer(); AotCompileWuQuantizer(); AotCompileDithering(); + AotCompilePixelOperations(); + AotCompileResizeOperations(); System.Runtime.CompilerServices.Unsafe.SizeOf(); @@ -51,39 +94,11 @@ namespace SixLabors.ImageSharp.Advanced // TODO: Do the discovery work to figure out what works and what doesn't. } - /// - /// Seeds the compiler using the given pixel formats. - /// - /// The first pixel format. - /// The second pixel format. - public static void Seed() - where TPixel : struct, IPixel - where TPixel2 : struct, IPixel - { - Seed(); - Seed(); - } - - /// - /// Seeds the compiler using the given pixel formats. - /// - /// The first pixel format. - /// The second pixel format. - /// The third pixel format. - public static void Seed() - where TPixel : struct, IPixel - where TPixel2 : struct, IPixel - where TPixel3 : struct, IPixel - { - Seed(); - Seed(); - } - /// /// This method doesn't actually do anything but serves an important purpose... - /// If you are running ImageSharp on iOS and try to call SaveAsGif, it will throw an excepion: + /// If you are running ImageSharp on iOS and try to call SaveAsGif, it will throw an exception: /// "Attempting to JIT compile method... OctreeFrameQuantizer.ConstructPalette... while running in aot-only mode." - /// The reason this happens is the SaveAsGif method makes haevy use of generics, which are too confusing for the AoT + /// The reason this happens is the SaveAsGif method makes heavy use of generics, which are too confusing for the AoT /// compiler used on Xamarin.iOS. It spins up the JIT compiler to try and figure it out, but that is an illegal op on /// iOS so it bombs out. /// If you are getting the above error, you need to call this method, which will pre-seed the AoT compiler with the @@ -118,7 +133,7 @@ namespace SixLabors.ImageSharp.Advanced { var test = new FloydSteinbergDiffuser(); TPixel pixel = default; - test.Dither(new ImageFrame(Configuration.Default, 1, 1), pixel, pixel, 0, 0, 0, 0, 0, 0); + test.Dither(new ImageFrame(Configuration.Default, 1, 1), pixel, pixel, 0, 0, 0, 0, 0, 0); } /// @@ -146,5 +161,28 @@ namespace SixLabors.ImageSharp.Advanced { } } + + /// + /// This method pre-seeds the PixelOperations engine for the AoT compiler on iOS. + /// + /// The pixel format. + private static void AotCompilePixelOperations() + where TPixel : struct, IPixel + { + var pixelOp = new PixelOperations(); + pixelOp.GetPixelBlender(PixelColorBlendingMode.Normal, PixelAlphaCompositionMode.Clear); + } + + /// + /// This method pre-seeds the ResizeProcessor for the AoT compiler on iOS. + /// + /// The pixel format. + private static void AotCompileResizeOperations() + where TPixel : struct, IPixel + { + var resizeProcessor = new ResizeProcessor(new ResizeOptions(), default); + var genericResizeProcessor = new ResizeProcessor((ResizeProcessor)resizeProcessor.CreatePixelSpecificProcessor()); + genericResizeProcessor.AotCreateDestination(new Image(0, 0), default); + } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Color/Color.cs b/src/ImageSharp/Color/Color.cs index 2547e6d873..4bdbe088ca 100644 --- a/src/ImageSharp/Color/Color.cs +++ b/src/ImageSharp/Color/Color.cs @@ -2,8 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Buffers.Binary; -using System.Globalization; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs index bfabbb21d5..273c9be912 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// The public CieLab ToCieLab(in CieLch color) { - // Conversion (perserving white point) + // Conversion (preserving white point) CieLab unadapted = CieLchToCieLabConverter.Convert(color); return this.Adapt(unadapted); @@ -446,4 +446,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs index 316b35f37a..b790712c50 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// The public CieLuv ToCieLuv(in CieLchuv color) { - // Conversion (perserving white point) + // Conversion (preserving white point) CieLuv unadapted = CieLchuvToCieLuvConverter.Convert(color); // Adaptation @@ -438,4 +438,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs index e28f3f1a4a..8871d04656 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs @@ -14,9 +14,9 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation /// /// Initializes a new instance of the struct. /// - /// The chomaticity coordinates of the red channel. - /// The chomaticity coordinates of the green channel. - /// The chomaticity coordinates of the blue channel. + /// The chromaticity coordinates of the red channel. + /// The chromaticity coordinates of the green channel. + /// The chromaticity coordinates of the blue channel. public RgbPrimariesChromaticityCoordinates(CieXyChromaticityCoordinates r, CieXyChromaticityCoordinates g, CieXyChromaticityCoordinates b) { this.R = r; @@ -25,17 +25,17 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation } /// - /// Gets the chomaticity coordinates of the red channel. + /// Gets the chromaticity coordinates of the red channel. /// public CieXyChromaticityCoordinates R { get; } /// - /// Gets the chomaticity coordinates of the green channel. + /// Gets the chromaticity coordinates of the green channel. /// public CieXyChromaticityCoordinates G { get; } /// - /// Gets the chomaticity coordinates of the blue channel. + /// Gets the chromaticity coordinates of the blue channel. /// public CieXyChromaticityCoordinates B { get; } @@ -88,4 +88,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation /// public override int GetHashCode() => HashCode.Combine(this.R, this.G, this.B); } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs b/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs index ca6e1fe6ed..fa13700787 100644 --- a/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs +++ b/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs @@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp { /// /// The exception that is thrown when the library tries to load - /// an image which has an unkown format. + /// an image which has an unknown format. /// public sealed class UnknownImageFormatException : ImageFormatException { diff --git a/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs b/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs index 6bb5adc060..64532af274 100644 --- a/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs +++ b/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Threading.Tasks; @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp /// public static ParallelOptions GetParallelOptions(this Configuration configuration) { - return new ParallelOptions() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism }; + return new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism }; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Common/Extensions/StreamExtensions.cs b/src/ImageSharp/Common/Extensions/StreamExtensions.cs index 505ecccdda..6af09b220a 100644 --- a/src/ImageSharp/Common/Extensions/StreamExtensions.cs +++ b/src/ImageSharp/Common/Extensions/StreamExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp } else { - byte[] foo = new byte[count]; + var foo = new byte[count]; while (count > 0) { int bytesRead = stream.Read(foo, 0, count); diff --git a/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs new file mode 100644 index 0000000000..0c22aa68ff --- /dev/null +++ b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs @@ -0,0 +1,105 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp +{ + /// + /// Extension methods for . + /// TODO: One day rewrite all this to use SIMD intrinsics. There's a lot of scope for improvement. + /// + internal static class Buffer2DUtils + { + /// + /// Computes the sum of vectors in weighted by the kernel weight values. + /// + /// The pixel format. + /// The 1D convolution kernel. + /// The source frame. + /// The target row. + /// The current row. + /// The current column. + /// The minimum working area row. + /// The maximum working area row. + /// The minimum working area column. + /// The maximum working area column. + public static void Convolve4( + Span kernel, + Buffer2D sourcePixels, + Span targetRow, + int row, + int column, + int minRow, + int maxRow, + int minColumn, + int maxColumn) + where TPixel : struct, IPixel + { + ComplexVector4 vector = default; + int kernelLength = kernel.Length; + int radiusY = kernelLength >> 1; + int sourceOffsetColumnBase = column + minColumn; + ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel); + + for (int i = 0; i < kernelLength; i++) + { + int offsetY = (row + i - radiusY).Clamp(minRow, maxRow); + int offsetX = sourceOffsetColumnBase.Clamp(minColumn, maxColumn); + Span sourceRowSpan = sourcePixels.GetRowSpan(offsetY); + var currentColor = sourceRowSpan[offsetX].ToVector4(); + + vector.Sum(Unsafe.Add(ref baseRef, i) * currentColor); + } + + targetRow[column] = vector; + } + + /// + /// Computes the sum of vectors in weighted by the kernel weight values. + /// + /// The 1D convolution kernel. + /// The source frame. + /// The target row. + /// The current row. + /// The current column. + /// The minimum working area row. + /// The maximum working area row. + /// The minimum working area column. + /// The maximum working area column. + public static void Convolve4( + Span kernel, + Buffer2D sourceValues, + Span targetRow, + int row, + int column, + int minRow, + int maxRow, + int minColumn, + int maxColumn) + { + ComplexVector4 vector = default; + int kernelLength = kernel.Length; + int radiusX = kernelLength >> 1; + int sourceOffsetColumnBase = column + minColumn; + + int offsetY = row.Clamp(minRow, maxRow); + ref ComplexVector4 sourceRef = ref MemoryMarshal.GetReference(sourceValues.GetRowSpan(offsetY)); + ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel); + + for (int x = 0; x < kernelLength; x++) + { + int offsetX = (sourceOffsetColumnBase + x - radiusX).Clamp(minColumn, maxColumn); + vector.Sum(Unsafe.Add(ref baseRef, x) * Unsafe.Add(ref sourceRef, offsetX)); + } + + targetRow[column] = vector; + } + } +} diff --git a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs index 427b240057..c5c9ddebe1 100644 --- a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs +++ b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -45,8 +45,6 @@ namespace SixLabors.ImageSharp int maxColumn) where TPixel : struct, IPixel { - Vector4 vector = default; - Convolve2DImpl( in matrixY, in matrixX, @@ -57,7 +55,7 @@ namespace SixLabors.ImageSharp maxRow, minColumn, maxColumn, - ref vector); + out Vector4 vector); ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); vector.W = target.W; @@ -95,8 +93,6 @@ namespace SixLabors.ImageSharp int maxColumn) where TPixel : struct, IPixel { - Vector4 vector = default; - Convolve2DImpl( in matrixY, in matrixX, @@ -107,7 +103,7 @@ namespace SixLabors.ImageSharp maxRow, minColumn, maxColumn, - ref vector); + out Vector4 vector); ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); Vector4Utils.UnPremultiply(ref vector); @@ -125,7 +121,7 @@ namespace SixLabors.ImageSharp int maxRow, int minColumn, int maxColumn, - ref Vector4 vector) + out Vector4 vector) where TPixel : struct, IPixel { Vector4 vectorY = default; @@ -281,4 +277,4 @@ namespace SixLabors.ImageSharp } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index e86da78e30..a39d10b6b8 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -51,28 +51,6 @@ namespace SixLabors.ImageSharp } } - /// - /// Ensures that the enumeration is not null or empty. - /// - /// The type of objects in the - /// The target enumeration, which should be checked against being null or empty. - /// Name of the parameter. - /// is null. - /// is empty. - [MethodImpl(InliningOptions.ShortMethod)] - public static void NotNullOrEmpty(ICollection value, string parameterName) - { - if (value is null) - { - ThrowArgumentNullException(parameterName); - } - - if (value.Count == 0) - { - ThrowArgumentException("Must not be empty.", parameterName); - } - } - /// /// Ensures that the specified value is less than a maximum value. /// @@ -253,7 +231,7 @@ namespace SixLabors.ImageSharp { if (destination.Length < source.Length) { - ThrowArgumentException($"Destination span is too short!", destinationParamName); + ThrowArgumentException("Destination span is too short!", destinationParamName); } } @@ -273,7 +251,7 @@ namespace SixLabors.ImageSharp { if (destination.Length < source.Length) { - ThrowArgumentException($"Destination span is too short!", destinationParamName); + ThrowArgumentException("Destination span is too short!", destinationParamName); } } diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs index 85c9f00748..5aa0b21ec1 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs @@ -1,8 +1,7 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; -using System.Diagnostics; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -139,8 +138,8 @@ namespace SixLabors.ImageSharp ref Octet.OfByte destBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = source.Length / 8; - Vector magick = new Vector(32768.0f); - Vector scale = new Vector(255f) / new Vector(256f); + var magick = new Vector(32768.0f); + var scale = new Vector(255f) / new Vector(256f); // need to copy to a temporary struct, because // SimdUtils.Octet.OfUInt32 temp = Unsafe.As, SimdUtils.Octet.OfUInt32>(ref x) @@ -188,8 +187,8 @@ namespace SixLabors.ImageSharp ref Octet.OfByte destBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = source.Length / 8; - Vector magick = new Vector(32768.0f); - Vector scale = new Vector(255f) / new Vector(256f); + var magick = new Vector(32768.0f); + var scale = new Vector(255f) / new Vector(256f); // need to copy to a temporary struct, because // SimdUtils.Octet.OfUInt32 temp = Unsafe.As, SimdUtils.Octet.OfUInt32>(ref x) @@ -212,4 +211,4 @@ namespace SixLabors.ImageSharp } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs index 83216aaa72..7baa788e41 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -172,7 +172,7 @@ namespace SixLabors.ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector ConvertToUInt32(Vector vf) { - Vector maxBytes = new Vector(255f); + var maxBytes = new Vector(255f); vf *= maxBytes; vf += new Vector(0.5f); vf = Vector.Min(Vector.Max(vf, Vector.Zero), maxBytes); @@ -190,4 +190,4 @@ namespace SixLabors.ImageSharp } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.cs b/src/ImageSharp/Common/Helpers/SimdUtils.cs index 867e7b9de1..4c34e28bc8 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -7,9 +7,6 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tuples; - namespace SixLabors.ImageSharp { /// @@ -46,7 +43,7 @@ namespace SixLabors.ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Vector FastRound(this Vector v) { - Vector magic0 = new Vector(int.MinValue); // 0x80000000 + var magic0 = new Vector(int.MinValue); // 0x80000000 Vector sgn0 = Vector.AsVectorSingle(magic0); Vector and0 = Vector.BitwiseAnd(sgn0, v); Vector or0 = Vector.BitwiseOr(and0, new Vector(8388608.0f)); @@ -182,4 +179,4 @@ namespace SixLabors.ImageSharp $"length should be divisible by {shouldBeDivisibleBy}!"); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs b/src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs index 2c2d045a57..1e7299720d 100644 --- a/src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs +++ b/src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.ParallelUtils int verticalStep = DivideCeil(rectangle.Height, numOfSteps); - var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = numOfSteps }; + var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps }; Parallel.For( 0, @@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.ParallelUtils int verticalStep = DivideCeil(rectangle.Height, numOfSteps); - var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = numOfSteps }; + var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps }; Parallel.For( 0, @@ -158,4 +158,4 @@ namespace SixLabors.ImageSharp.ParallelUtils $"{nameof(rectangle)}.{nameof(rectangle.Height)}"); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Bmp/BmpCompression.cs b/src/ImageSharp/Formats/Bmp/BmpCompression.cs index 27a0e121b6..81a76e28d1 100644 --- a/src/ImageSharp/Formats/Bmp/BmpCompression.cs +++ b/src/ImageSharp/Formats/Bmp/BmpCompression.cs @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp /// rather than four or eight bits in size. /// /// Note: Because compression value of 4 is ambiguous for BI_RGB for windows and RLE24 for OS/2, the enum value is remapped - /// to a different value. + /// to a different value, to be clearly separate from valid windows values. /// RLE24 = 100, } diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 906fc53fef..b7733e0269 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -446,7 +446,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp #if NETCOREAPP2_1 Span cmd = stackalloc byte[2]; #else - byte[] cmd = new byte[2]; + var cmd = new byte[2]; #endif int count = 0; @@ -485,7 +485,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp int max = cmd[1]; int bytesToRead = (max + 1) / 2; - byte[] run = new byte[bytesToRead]; + var run = new byte[bytesToRead]; this.stream.Read(run, 0, run.Length); @@ -557,7 +557,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp #if NETCOREAPP2_1 Span cmd = stackalloc byte[2]; #else - byte[] cmd = new byte[2]; + var cmd = new byte[2]; #endif int count = 0; @@ -595,7 +595,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp // Take this number of bytes from the stream as uncompressed data. int length = cmd[1]; - byte[] run = new byte[length]; + var run = new byte[length]; this.stream.Read(run, 0, run.Length); @@ -640,7 +640,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp #if NETCOREAPP2_1 Span cmd = stackalloc byte[2]; #else - byte[] cmd = new byte[2]; + var cmd = new byte[2]; #endif int uncompressedPixels = 0; @@ -678,7 +678,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp // Take this number of bytes from the stream as uncompressed data. int length = cmd[1]; - byte[] run = new byte[length * 3]; + var run = new byte[length * 3]; this.stream.Read(run, 0, run.Length); @@ -1214,7 +1214,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp #if NETCOREAPP2_1 Span buffer = stackalloc byte[BmpInfoHeader.MaxHeaderSize]; #else - byte[] buffer = new byte[BmpInfoHeader.MaxHeaderSize]; + var buffer = new byte[BmpInfoHeader.MaxHeaderSize]; #endif // Read the header size. @@ -1252,7 +1252,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp // color masks for each color channel follow the info header. if (this.infoHeader.Compression == BmpCompression.BitFields) { - byte[] bitfieldsBuffer = new byte[12]; + var bitfieldsBuffer = new byte[12]; this.stream.Read(bitfieldsBuffer, 0, 12); Span data = bitfieldsBuffer.AsSpan(); this.infoHeader.RedMask = BinaryPrimitives.ReadInt32LittleEndian(data.Slice(0, 4)); @@ -1261,7 +1261,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp } else if (this.infoHeader.Compression == BmpCompression.BI_ALPHABITFIELDS) { - byte[] bitfieldsBuffer = new byte[16]; + var bitfieldsBuffer = new byte[16]; this.stream.Read(bitfieldsBuffer, 0, 16); Span data = bitfieldsBuffer.AsSpan(); this.infoHeader.RedMask = BinaryPrimitives.ReadInt32LittleEndian(data.Slice(0, 4)); @@ -1340,7 +1340,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp #if NETCOREAPP2_1 Span buffer = stackalloc byte[BmpFileHeader.Size]; #else - byte[] buffer = new byte[BmpFileHeader.Size]; + var buffer = new byte[BmpFileHeader.Size]; #endif this.stream.Read(buffer, 0, BmpFileHeader.Size); diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 4e6ec45021..a5e1ee5dbc 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp #if NETCOREAPP2_1 Span buffer = stackalloc byte[infoHeaderSize]; #else - byte[] buffer = new byte[infoHeaderSize]; + var buffer = new byte[infoHeaderSize]; #endif fileHeader.WriteTo(buffer); diff --git a/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs b/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs index 661275fc90..16421cfb0c 100644 --- a/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs +++ b/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp return MemoryMarshal.Cast(data)[0]; } - public unsafe void WriteTo(Span buffer) + public void WriteTo(Span buffer) { ref BmpFileHeader dest = ref Unsafe.As(ref MemoryMarshal.GetReference(buffer)); diff --git a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs index 4d7f781001..9ede660705 100644 --- a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs +++ b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs @@ -447,7 +447,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp /// Writes a complete Bitmap V4 header to a buffer. /// /// The buffer to write to. - public unsafe void WriteV4Header(Span buffer) + public void WriteV4Header(Span buffer) { ref BmpInfoHeader dest = ref Unsafe.As(ref MemoryMarshal.GetReference(buffer)); diff --git a/src/ImageSharp/Formats/Gif/GifConstants.cs b/src/ImageSharp/Formats/Gif/GifConstants.cs index 288c3dfa19..c9d631da0e 100644 --- a/src/ImageSharp/Formats/Gif/GifConstants.cs +++ b/src/ImageSharp/Formats/Gif/GifConstants.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; @@ -7,7 +7,7 @@ using System.Text; namespace SixLabors.ImageSharp.Formats.Gif { /// - /// Constants that define specific points within a gif. + /// Constants that define specific points within a Gif. /// internal static class GifConstants { @@ -67,14 +67,9 @@ namespace SixLabors.ImageSharp.Formats.Gif public const byte CommentLabel = 0xFE; /// - /// The name of the property inside the image properties for the comments. + /// The maximum length of a comment data sub-block is 255. /// - public const string Comments = "Comments"; - - /// - /// The maximum comment length. - /// - public const int MaxCommentLength = 1024 * 8; + public const int MaxCommentSubBlockLength = 255; /// /// The image descriptor label ,. @@ -102,18 +97,18 @@ namespace SixLabors.ImageSharp.Formats.Gif public const byte EndIntroducer = 0x3B; /// - /// Gets the default encoding to use when reading comments. + /// The character encoding to use when reading and writing comments - (ASCII 7bit). /// - public static readonly Encoding DefaultEncoding = Encoding.ASCII; + public static readonly Encoding Encoding = Encoding.ASCII; /// - /// The list of mimetypes that equate to a gif. + /// The collection of mimetypes that equate to a Gif. /// public static readonly IEnumerable MimeTypes = new[] { "image/gif" }; /// - /// The list of file extensions that equate to a gif. + /// The collection of file extensions that equate to a Gif. /// public static readonly IEnumerable FileExtensions = new[] { "gif" }; } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs index 1addcd0abf..7691ec1aa5 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoder.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs @@ -1,8 +1,7 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.IO; -using System.Text; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.PixelFormats; @@ -18,11 +17,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// public bool IgnoreMetadata { get; set; } = false; - /// - /// Gets or sets the encoding that should be used when reading comments. - /// - public Encoding TextEncoding { get; set; } = GifConstants.DefaultEncoding; - /// /// Gets or sets the decoding mode for multi-frame images /// diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index e16ecb42e3..c11e93a93a 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -77,7 +77,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// The decoder options. public GifDecoderCore(Configuration configuration, IGifDecoderOptions options) { - this.TextEncoding = options.TextEncoding ?? GifConstants.DefaultEncoding; this.IgnoreMetadata = options.IgnoreMetadata; this.DecodingMode = options.DecodingMode; this.configuration = configuration ?? Configuration.Default; @@ -88,11 +87,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// public bool IgnoreMetadata { get; internal set; } - /// - /// Gets the text encoding - /// - public Encoding TextEncoding { get; } - /// /// Gets the decoding mode for multi-frame images /// @@ -317,11 +311,12 @@ namespace SixLabors.ImageSharp.Formats.Gif { int length; + var stringBuilder = new StringBuilder(); while ((length = this.stream.ReadByte()) != 0) { - if (length > GifConstants.MaxCommentLength) + if (length > GifConstants.MaxCommentSubBlockLength) { - throw new ImageFormatException($"Gif comment length '{length}' exceeds max '{GifConstants.MaxCommentLength}'"); + throw new ImageFormatException($"Gif comment length '{length}' exceeds max '{GifConstants.MaxCommentSubBlockLength}' of a comment data block"); } if (this.IgnoreMetadata) @@ -333,10 +328,15 @@ namespace SixLabors.ImageSharp.Formats.Gif using (IManagedByteBuffer commentsBuffer = this.MemoryAllocator.AllocateManagedByteBuffer(length)) { this.stream.Read(commentsBuffer.Array, 0, length); - string comments = this.TextEncoding.GetString(commentsBuffer.Array, 0, length); - this.metadata.Properties.Add(new ImageProperty(GifConstants.Comments, comments)); + string commentPart = GifConstants.Encoding.GetString(commentsBuffer.Array, 0, length); + stringBuilder.Append(commentPart); } } + + if (stringBuilder.Length > 0) + { + this.gifMetadata.Comments.Add(stringBuilder.ToString()); + } } /// @@ -632,4 +632,4 @@ namespace SixLabors.ImageSharp.Formats.Gif } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index 4210b08765..fef311596e 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -1,8 +1,7 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.IO; -using System.Text; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Quantization; @@ -14,11 +13,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// public sealed class GifEncoder : IImageEncoder, IGifEncoderOptions { - /// - /// Gets or sets the encoding that should be used when writing comments. - /// - public Encoding TextEncoding { get; set; } = GifConstants.DefaultEncoding; - /// /// Gets or sets the quantizer for reducing the color count. /// Defaults to the @@ -38,4 +32,4 @@ namespace SixLabors.ImageSharp.Formats.Gif encoder.Encode(image, stream); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 36e27866e9..912e6c04d8 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -37,11 +37,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// private readonly byte[] buffer = new byte[20]; - /// - /// The text encoding used to write comments. - /// - private readonly Encoding textEncoding; - /// /// The quantizer used to generate the color palette. /// @@ -57,11 +52,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// private int bitDepth; - /// - /// Gif specific metadata. - /// - private GifMetadata gifMetadata; - /// /// Initializes a new instance of the class. /// @@ -70,7 +60,6 @@ namespace SixLabors.ImageSharp.Formats.Gif public GifEncoderCore(MemoryAllocator memoryAllocator, IGifEncoderOptions options) { this.memoryAllocator = memoryAllocator; - this.textEncoding = options.TextEncoding ?? GifConstants.DefaultEncoding; this.quantizer = options.Quantizer; this.colorTableMode = options.ColorTableMode; } @@ -90,12 +79,12 @@ namespace SixLabors.ImageSharp.Formats.Gif this.configuration = image.GetConfiguration(); ImageMetadata metadata = image.Metadata; - this.gifMetadata = metadata.GetFormatMetadata(GifFormat.Instance); - this.colorTableMode = this.colorTableMode ?? this.gifMetadata.ColorTableMode; + GifMetadata gifMetadata = metadata.GetFormatMetadata(GifFormat.Instance); + this.colorTableMode = this.colorTableMode ?? gifMetadata.ColorTableMode; bool useGlobalTable = this.colorTableMode == GifColorTableMode.Global; // Quantize the image returning a palette. - IQuantizedFrame quantized = null; + IQuantizedFrame quantized; using (IFrameQuantizer frameQuantizer = this.quantizer.CreateFrameQuantizer(image.GetConfiguration())) { quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame); @@ -117,12 +106,12 @@ namespace SixLabors.ImageSharp.Formats.Gif } // Write the comments. - this.WriteComments(metadata, stream); + this.WriteComments(gifMetadata, stream); // Write application extension to allow additional frames. if (image.Frames.Count > 1) { - this.WriteApplicationExtension(stream, this.gifMetadata.RepeatCount); + this.WriteApplicationExtension(stream, gifMetadata.RepeatCount); } if (useGlobalTable) @@ -158,10 +147,10 @@ namespace SixLabors.ImageSharp.Formats.Gif } else { - using (IFrameQuantizer palleteFrameQuantizer = + using (IFrameQuantizer paletteFrameQuantizer = new PaletteFrameQuantizer(this.quantizer.Diffuser, quantized.Palette)) { - using (IQuantizedFrame paletteQuantized = palleteFrameQuantizer.QuantizeFrame(frame)) + using (IQuantizedFrame paletteQuantized = paletteFrameQuantizer.QuantizeFrame(frame)) { this.WriteImageData(paletteQuantized, stream); } @@ -333,25 +322,51 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// The metadata to be extract the comment data. /// The stream to write to. - private void WriteComments(ImageMetadata metadata, Stream stream) + private void WriteComments(GifMetadata metadata, Stream stream) { - if (!metadata.TryGetProperty(GifConstants.Comments, out ImageProperty property) - || string.IsNullOrEmpty(property.Value)) + if (metadata.Comments.Count == 0) { return; } - byte[] comments = this.textEncoding.GetBytes(property.Value); + foreach (string comment in metadata.Comments) + { + this.buffer[0] = GifConstants.ExtensionIntroducer; + this.buffer[1] = GifConstants.CommentLabel; + stream.Write(this.buffer, 0, 2); + + // Comment will be stored in chunks of 255 bytes, if it exceeds this size. + ReadOnlySpan commentSpan = comment.AsSpan(); + int idx = 0; + for (; idx <= comment.Length - GifConstants.MaxCommentSubBlockLength; idx += GifConstants.MaxCommentSubBlockLength) + { + WriteCommentSubBlock(stream, commentSpan, idx, GifConstants.MaxCommentSubBlockLength); + } - int count = Math.Min(comments.Length, 255); + // Write the length bytes, if any, to another sub block. + if (idx < comment.Length) + { + int remaining = comment.Length - idx; + WriteCommentSubBlock(stream, commentSpan, idx, remaining); + } - this.buffer[0] = GifConstants.ExtensionIntroducer; - this.buffer[1] = GifConstants.CommentLabel; - this.buffer[2] = (byte)count; + stream.WriteByte(GifConstants.Terminator); + } + } - stream.Write(this.buffer, 0, 3); - stream.Write(comments, 0, count); - stream.WriteByte(GifConstants.Terminator); + /// + /// Writes a comment sub-block to the stream. + /// + /// The stream to write to. + /// Comment as a Span. + /// Current start index. + /// The length of the string to write. Should not exceed 255 bytes. + private static void WriteCommentSubBlock(Stream stream, ReadOnlySpan commentSpan, int idx, int length) + { + string subComment = commentSpan.Slice(idx, length).ToString(); + byte[] subCommentBytes = GifConstants.Encoding.GetBytes(subComment); + stream.WriteByte((byte)length); + stream.Write(subCommentBytes, 0, length); } /// @@ -458,4 +473,4 @@ namespace SixLabors.ImageSharp.Formats.Gif } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Gif/GifFrameMetaData.cs b/src/ImageSharp/Formats/Gif/GifFrameMetaData.cs index 613825ad63..dfc96af5a6 100644 --- a/src/ImageSharp/Formats/Gif/GifFrameMetaData.cs +++ b/src/ImageSharp/Formats/Gif/GifFrameMetaData.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.Gif @@ -51,4 +51,4 @@ namespace SixLabors.ImageSharp.Formats.Gif /// public IDeepCloneable DeepClone() => new GifFrameMetadata(this); } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Gif/GifMetaData.cs b/src/ImageSharp/Formats/Gif/GifMetaData.cs index 0b6566fbfe..b00db6752b 100644 --- a/src/ImageSharp/Formats/Gif/GifMetaData.cs +++ b/src/ImageSharp/Formats/Gif/GifMetaData.cs @@ -1,6 +1,8 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.Collections.Generic; + namespace SixLabors.ImageSharp.Formats.Gif { /// @@ -24,6 +26,11 @@ namespace SixLabors.ImageSharp.Formats.Gif this.RepeatCount = other.RepeatCount; this.ColorTableMode = other.ColorTableMode; this.GlobalColorTableLength = other.GlobalColorTableLength; + + for (int i = 0; i < other.Comments.Count; i++) + { + this.Comments.Add(other.Comments[i]); + } } /// @@ -44,7 +51,13 @@ namespace SixLabors.ImageSharp.Formats.Gif /// public int GlobalColorTableLength { get; set; } + /// + /// Gets or sets the the collection of comments about the graphics, credits, descriptions or any + /// other type of non-control and non-graphic data. + /// + public IList Comments { get; set; } = new List(); + /// public IDeepCloneable DeepClone() => new GifMetadata(this); } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs index 871b511a0d..050ab170b2 100644 --- a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs +++ b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs @@ -1,7 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Text; using SixLabors.ImageSharp.Metadata; namespace SixLabors.ImageSharp.Formats.Gif @@ -16,11 +15,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// bool IgnoreMetadata { get; } - /// - /// Gets the text encoding that should be used when reading comments. - /// - Encoding TextEncoding { get; } - /// /// Gets the decoding mode for multi-frame images. /// diff --git a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs index 4b3c28a92c..5936d30cba 100644 --- a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs +++ b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs @@ -1,7 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Text; using SixLabors.ImageSharp.Processing.Processors.Quantization; namespace SixLabors.ImageSharp.Formats.Gif @@ -11,11 +10,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// internal interface IGifEncoderOptions { - /// - /// Gets the text encoding used to write comments. - /// - Encoding TextEncoding { get; } - /// /// Gets the quantizer used to generate the color palette. /// @@ -26,4 +20,4 @@ namespace SixLabors.ImageSharp.Formats.Gif /// GifColorTableMode? ColorTableMode { get; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index 07594e81a1..af390e9545 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp.Formats.Gif #if NETCOREAPP2_1 Span buffer = stackalloc byte[255]; #else - byte[] buffer = new byte[255]; + var buffer = new byte[255]; #endif while (xyz < length) @@ -253,4 +253,4 @@ namespace SixLabors.ImageSharp.Formats.Gif this.pixelStack.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index b4c80a3da1..d809106143 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -249,9 +249,9 @@ namespace SixLabors.ImageSharp.Formats.Gif /// Compress the packets to the stream. /// /// The span of indexed pixels. - /// The initial bits. + /// The initial bits. /// The stream to write to. - private void Compress(ReadOnlySpan indexedPixels, int intialBits, Stream stream) + private void Compress(ReadOnlySpan indexedPixels, int initialBits, Stream stream) { int fcode; int c; @@ -260,14 +260,14 @@ namespace SixLabors.ImageSharp.Formats.Gif int hshift; // Set up the globals: globalInitialBits - initial number of bits - this.globalInitialBits = intialBits; + this.globalInitialBits = initialBits; // Set up the necessary values this.clearFlag = false; this.bitCount = this.globalInitialBits; this.maxCode = GetMaxcode(this.bitCount); - this.clearCode = 1 << (intialBits - 1); + this.clearCode = 1 << (initialBits - 1); this.eofCode = this.clearCode + 1; this.freeEntry = this.clearCode + 2; @@ -450,4 +450,4 @@ namespace SixLabors.ImageSharp.Formats.Gif this.codeTable?.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs b/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs index 49a52edf6a..8af5b81c20 100644 --- a/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs +++ b/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Formats.Gif // Application Data ---- buffer[12] = 3; // Application block length (always 3) - buffer[13] = 1; // Data sub-block indentity (always 1) + buffer[13] = 1; // Data sub-block identity (always 1) // 0 means loop indefinitely. Count is set as play n + 1 times. BinaryPrimitives.WriteUInt16LittleEndian(buffer.Slice(14, 2), this.RepeatCount); diff --git a/src/ImageSharp/Formats/IImageFormatDetector.cs b/src/ImageSharp/Formats/IImageFormatDetector.cs index da3730d207..becd8200cf 100644 --- a/src/ImageSharp/Formats/IImageFormatDetector.cs +++ b/src/ImageSharp/Formats/IImageFormatDetector.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats /// Detect mimetype /// /// The containing the file header. - /// returns the mime type of detected othersie returns null + /// returns the mime type of detected otherwise returns null IImageFormat DetectFormat(ReadOnlySpan header); } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs index 60fec25d29..0b69e3f8ba 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs @@ -194,7 +194,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components /// public short[] ToArray() { - short[] result = new short[Size]; + var result = new short[Size]; this.CopyTo(result); return result; } @@ -297,4 +297,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components return result; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs index a9e9903a9d..23b51f0926 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -95,9 +95,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components /// public void NormalizeColorsInplace(float maximum) { - Vector4 CMin4 = new Vector4(0F); - Vector4 CMax4 = new Vector4(maximum); - Vector4 COff4 = new Vector4(MathF.Ceiling(maximum / 2)); + var CMin4 = new Vector4(0F); + var CMax4 = new Vector4(maximum); + var COff4 = new Vector4(MathF.Ceiling(maximum / 2)); this.V0L = Vector4.Clamp(this.V0L + COff4, CMin4, CMax4); this.V0R = Vector4.Clamp(this.V0R + COff4, CMin4, CMax4); @@ -123,8 +123,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components [MethodImpl(InliningOptions.ShortMethod)] public void NormalizeColorsAndRoundInplaceAvx2(float maximum) { - Vector off = new Vector(MathF.Ceiling(maximum / 2)); - Vector max = new Vector(maximum); + var off = new Vector(MathF.Ceiling(maximum / 2)); + var max = new Vector(maximum); ref Vector row0 = ref Unsafe.As>(ref this.V0L); row0 = NormalizeAndRound(row0, off, max); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt index d6c42a802a..176591972a 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt @@ -1,4 +1,4 @@ -<# +<# // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. #> @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components char srcCoord = coordz[j % 4]; char srcSide = (j / 4) % 2 == 0 ? 'L' : 'R'; - string expression = $"d.V{j}{destSide}.{destCoord} = V{i}{srcSide}.{srcCoord};\r\n"; + var expression = $"d.V{j}{destSide}.{destCoord} = V{i}{srcSide}.{srcCoord};\r\n"; Write(expression); } } @@ -60,9 +60,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components /// public void NormalizeColorsInplace(float maximum) { - Vector4 CMin4 = new Vector4(0F); - Vector4 CMax4 = new Vector4(maximum); - Vector4 COff4 = new Vector4(MathF.Ceiling(maximum / 2)); + var CMin4 = new Vector4(0F); + var CMax4 = new Vector4(maximum); + var COff4 = new Vector4(MathF.Ceiling(maximum / 2)); <# @@ -86,8 +86,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components [MethodImpl(InliningOptions.ShortMethod)] public void NormalizeColorsAndRoundInplaceAvx2(float maximum) { - Vector off = new Vector(MathF.Ceiling(maximum / 2)); - Vector max = new Vector(maximum); + var off = new Vector(MathF.Ceiling(maximum / 2)); + var max = new Vector(maximum); <# for (int i = 0; i < 8; i++) @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components { char destCoord = coordz[i % 4]; char destSide = (i / 4) % 2 == 0 ? 'L' : 'R'; - + if(j > 0 && i == 0){ WriteLine(""); } @@ -125,9 +125,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components char srcCoord = coordz[j % 4]; char srcSide = (j / 4) % 2 == 0 ? 'L' : 'R'; - string expression = $"this.V{j}{destSide}.{destCoord} = Unsafe.Add(ref selfRef, {j*8+i});\r\n"; + var expression = $"this.V{j}{destSide}.{destCoord} = Unsafe.Add(ref selfRef, {j*8+i});\r\n"; Write(expression); - + } } PopIndent(); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs index c85bd725c9..f11b0f8fa7 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -210,7 +210,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components } /// - /// Convert salars to byte-s and copy to dest, + /// Convert scalars to byte-s and copy to dest, /// /// Pointer to block /// Destination @@ -257,7 +257,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components { fixed (Vector4* ptr = &this.V0L) { - float* fp = (float*)ptr; + var fp = (float*)ptr; for (int i = 0; i < Size; i++) { dest[i] = (int)fp[i]; @@ -267,7 +267,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components public float[] ToArray() { - float[] result = new float[Size]; + var result = new float[Size]; this.CopyTo(result); return result; } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs index a57535b71c..f106d67ad0 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs @@ -25,11 +25,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters var v = new Vector4(0, 0, 0, 1F); - var scale = new Vector4( - 1 / this.MaximumValue, - 1 / this.MaximumValue, - 1 / this.MaximumValue, - 1F); + var maximum = 1 / this.MaximumValue; + var scale = new Vector4(maximum, maximum, maximum, 1F); for (int i = 0; i < result.Length; i++) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs index 15bb2cf4b4..68ab6f9121 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs @@ -19,11 +19,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters public override void ConvertToRgba(in ComponentValues values, Span result) { - var scale = new Vector4( - 1 / this.MaximumValue, - 1 / this.MaximumValue, - 1 / this.MaximumValue, - 1F); + var maximum = 1 / this.MaximumValue; + var scale = new Vector4(maximum, maximum, maximum, 1F); ref float sBase = ref MemoryMarshal.GetReference(values.Component0); ref Vector4 dBase = ref MemoryMarshal.GetReference(result); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs index 2f68e312dc..7a92a4ed4e 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs @@ -24,11 +24,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters var v = new Vector4(0, 0, 0, 1); - var scale = new Vector4( - 1 / this.MaximumValue, - 1 / this.MaximumValue, - 1 / this.MaximumValue, - 1F); + var maximum = 1 / this.MaximumValue; + var scale = new Vector4(maximum, maximum, maximum, 1F); for (int i = 0; i < result.Length; i++) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs index cd8a3bb06c..f1d773708c 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs @@ -25,11 +25,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters var v = new Vector4(0, 0, 0, 1F); - var scale = new Vector4( - 1 / this.MaximumValue, - 1 / this.MaximumValue, - 1 / this.MaximumValue, - 1F); + var maximum = 1 / this.MaximumValue; + var scale = new Vector4(maximum, maximum, maximum, 1F); for (int i = 0; i < result.Length; i++) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs index c50812e253..fbb2b52727 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs @@ -124,7 +124,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } } - private unsafe void ParseBaselineDataInterleaved() + private void ParseBaselineDataInterleaved() { // Interleaved int mcu = 0; @@ -196,7 +196,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } } - private unsafe void ParseBaselineDataNonInterleaved() + private void ParseBaselineDataNonInterleaved() { JpegComponent component = this.components[this.frame.ComponentOrder[0]]; ref HuffmanScanBuffer buffer = ref this.scanBuffer; @@ -209,7 +209,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder dcHuffmanTable.Configure(); acHuffmanTable.Configure(); - int mcu = 0; for (int j = 0; j < h; j++) { Span blockSpan = component.SpectralBlocks.GetRowSpan(j); @@ -228,9 +227,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref dcHuffmanTable, ref acHuffmanTable); - // Every data block is an MCU, so countdown the restart interval - mcu++; - this.HandleRestart(); } } @@ -366,7 +362,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } } - private unsafe void ParseProgressiveDataNonInterleaved() + private void ParseProgressiveDataNonInterleaved() { JpegComponent component = this.components[this.frame.ComponentOrder[0]]; ref HuffmanScanBuffer buffer = ref this.scanBuffer; @@ -379,7 +375,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; dcHuffmanTable.Configure(); - int mcu = 0; for (int j = 0; j < h; j++) { Span blockSpan = component.SpectralBlocks.GetRowSpan(j); @@ -397,8 +392,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref Unsafe.Add(ref blockRef, i), ref dcHuffmanTable); - // Every data block is an MCU, so countdown the restart interval - mcu++; this.HandleRestart(); } } @@ -408,7 +401,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref HuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; acHuffmanTable.Configure(); - int mcu = 0; for (int j = 0; j < h; j++) { Span blockSpan = component.SpectralBlocks.GetRowSpan(j); @@ -425,8 +417,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref Unsafe.Add(ref blockRef, i), ref acHuffmanTable); - // Every data block is an MCU, so countdown the restart interval - mcu++; this.HandleRestart(); } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs index ace8d7215b..2f393fadae 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Generic; using SixLabors.Primitives; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs index 301079b6ae..883a085b5a 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs @@ -4,7 +4,6 @@ using System; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder diff --git a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs index c795ccc8b5..3d1e22a99d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs @@ -7,7 +7,6 @@ using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Memory; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Formats.Jpeg.Components diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index bf7c8f9c88..c15fe5e274 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -538,7 +538,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg return; } - byte[] profile = new byte[remaining]; + var profile = new byte[remaining]; this.InputStream.Read(profile, 0, remaining); if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker)) @@ -571,14 +571,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg return; } - byte[] identifier = new byte[Icclength]; + var identifier = new byte[Icclength]; this.InputStream.Read(identifier, 0, Icclength); remaining -= Icclength; // We have read it by this point if (ProfileResolver.IsProfile(identifier, ProfileResolver.IccMarker)) { this.isIcc = true; - byte[] profile = new byte[remaining]; + var profile = new byte[remaining]; this.InputStream.Read(profile, 0, remaining); if (this.iccData is null) diff --git a/src/ImageSharp/Formats/Png/Adam7.cs b/src/ImageSharp/Formats/Png/Adam7.cs index 4e6485b55f..b392332d7a 100644 --- a/src/ImageSharp/Formats/Png/Adam7.cs +++ b/src/ImageSharp/Formats/Png/Adam7.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -31,6 +31,34 @@ namespace SixLabors.ImageSharp.Formats.Png /// public static readonly int[] RowIncrement = { 8, 8, 8, 4, 4, 2, 2 }; + /// + /// Gets the width of the block. + /// + /// The width. + /// The pass. + /// + /// The + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int ComputeBlockWidth(int width, int pass) + { + return (width + ColumnIncrement[pass] - 1 - FirstColumn[pass]) / ColumnIncrement[pass]; + } + + /// + /// Gets the height of the block. + /// + /// The height. + /// The pass. + /// + /// The + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int ComputeBlockHeight(int height, int pass) + { + return (height + RowIncrement[pass] - 1 - FirstRow[pass]) / RowIncrement[pass]; + } + /// /// Returns the correct number of columns for each interlaced pass. /// @@ -53,4 +81,4 @@ namespace SixLabors.ImageSharp.Formats.Png } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs index 6af5f0b648..e6fc1b6ae6 100644 --- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -25,12 +25,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline); // Sub(x) + Raw(x-bpp) - int x = 1; - for (; x <= bytesPerPixel /* Note the <= because x starts at 1 */; ++x) - { - ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); - } - + int x = bytesPerPixel + 1; + Unsafe.Add(ref scanBaseRef, x); for (; x < scanline.Length; ++x) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); diff --git a/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs b/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs index 5b650ac2a0..44cb837a6a 100644 --- a/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs +++ b/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Text; @@ -14,10 +14,5 @@ namespace SixLabors.ImageSharp.Formats.Png /// Gets a value indicating whether the metadata should be ignored when the image is being decoded. /// bool IgnoreMetadata { get; } - - /// - /// Gets the encoding that should be used when reading text chunks. - /// - Encoding TextEncoding { get; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs index 7e5a9fa6b8..87fd2582a5 100644 --- a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs +++ b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Processing.Processors.Quantization; @@ -6,7 +6,7 @@ using SixLabors.ImageSharp.Processing.Processors.Quantization; namespace SixLabors.ImageSharp.Formats.Png { /// - /// The options available for manipulating the encoder pipeline + /// The options available for manipulating the encoder pipeline. /// internal interface IPngEncoderOptions { @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Png PngBitDepth? BitDepth { get; } /// - /// Gets the color type + /// Gets the color type. /// PngColorType? ColorType { get; } @@ -33,7 +33,12 @@ namespace SixLabors.ImageSharp.Formats.Png int CompressionLevel { get; } /// - /// Gets the gamma value, that will be written the the image. + /// Gets the threshold of characters in text metadata, when compression should be used. + /// + int TextCompressionThreshold { get; } + + /// + /// Gets the gamma value, that will be written the image. /// /// The gamma value of the image. float? Gamma { get; } @@ -47,5 +52,10 @@ namespace SixLabors.ImageSharp.Formats.Png /// Gets the transparency threshold. /// byte Threshold { get; } + + /// + /// Gets a value indicating whether this instance should write an Adam7 interlaced image. + /// + PngInterlaceMode? InterlaceMethod { get; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/PngChunkType.cs b/src/ImageSharp/Formats/Png/PngChunkType.cs index 1b251a5748..e41b49066a 100644 --- a/src/ImageSharp/Formats/Png/PngChunkType.cs +++ b/src/ImageSharp/Formats/Png/PngChunkType.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Formats.Png @@ -55,6 +55,19 @@ namespace SixLabors.ImageSharp.Formats.Png /// Text = 0x74455874U, + /// + /// Textual information that the encoder wishes to record with the image. The zTXt and tEXt chunks are semantically equivalent, + /// but the zTXt chunk is recommended for storing large blocks of text. Each zTXt chunk contains a (uncompressed) keyword and + /// a compressed text string. + /// + CompressedText = 0x7A545874U, + + /// + /// The iTXt chunk contains International textual data. It contains a keyword, an optional language tag, an optional translated keyword + /// and the actual text string, which can be compressed or uncompressed. + /// + InternationalText = 0x69545874U, + /// /// The tRNS chunk specifies that the image uses simple transparency: /// either alpha values associated with palette entries (for indexed-color images) @@ -62,4 +75,4 @@ namespace SixLabors.ImageSharp.Formats.Png /// Transparency = 0x74524E53U } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/PngConstants.cs b/src/ImageSharp/Formats/Png/PngConstants.cs index e1f978e1ac..632460ec43 100644 --- a/src/ImageSharp/Formats/Png/PngConstants.cs +++ b/src/ImageSharp/Formats/Png/PngConstants.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; @@ -7,25 +7,38 @@ using System.Text; namespace SixLabors.ImageSharp.Formats.Png { /// - /// Defines png constants defined in the specification. + /// Defines Png constants defined in the specification. /// internal static class PngConstants { /// - /// The default encoding for text metadata. + /// The character encoding to use when reading and writing textual data keywords and text - (Latin-1 ISO-8859-1). /// - public static readonly Encoding DefaultEncoding = Encoding.ASCII; + public static readonly Encoding Encoding = Encoding.GetEncoding("ISO-8859-1"); /// - /// The list of mimetypes that equate to a png. + /// The character encoding to use when reading and writing language tags within iTXt chunks - (ASCII 7bit). + /// + public static readonly Encoding LanguageEncoding = Encoding.ASCII; + + /// + /// The character encoding to use when reading and writing translated textual data keywords and text - (UTF8). + /// + public static readonly Encoding TranslatedEncoding = Encoding.UTF8; + + /// + /// The list of mimetypes that equate to a Png. /// public static readonly IEnumerable MimeTypes = new[] { "image/png" }; /// - /// The list of file extensions that equate to a png. + /// The list of file extensions that equate to a Png. /// public static readonly IEnumerable FileExtensions = new[] { "png" }; + /// + /// The header bytes identifying a Png. + /// public static readonly byte[] HeaderBytes = { 0x89, // Set the high bit. @@ -39,14 +52,14 @@ namespace SixLabors.ImageSharp.Formats.Png }; /// - /// The header bytes as a big endian coded ulong. + /// The header bytes as a big-endian coded ulong. /// public const ulong HeaderValue = 0x89504E470D0A1A0AUL; /// /// The dictionary of available color types. /// - public static readonly Dictionary ColorTypes = new Dictionary() + public static readonly Dictionary ColorTypes = new Dictionary { [PngColorType.Grayscale] = new byte[] { 1, 2, 4, 8, 16 }, [PngColorType.Rgb] = new byte[] { 8, 16 }, @@ -54,5 +67,15 @@ namespace SixLabors.ImageSharp.Formats.Png [PngColorType.GrayscaleWithAlpha] = new byte[] { 8, 16 }, [PngColorType.RgbWithAlpha] = new byte[] { 8, 16 } }; + + /// + /// The maximum length of keyword in a text chunk is 79 bytes. + /// + public const int MaxTextKeywordLength = 79; + + /// + /// The minimum length of a keyword in a text chunk is 1 byte. + /// + public const int MinTextKeywordLength = 1; } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs index 040da94737..19e5e848d0 100644 --- a/src/ImageSharp/Formats/Png/PngDecoder.cs +++ b/src/ImageSharp/Formats/Png/PngDecoder.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.IO; @@ -34,11 +34,6 @@ namespace SixLabors.ImageSharp.Formats.Png /// public bool IgnoreMetadata { get; set; } - /// - /// Gets or sets the encoding that should be used when reading text chunks. - /// - public Encoding TextEncoding { get; set; } = PngConstants.DefaultEncoding; - /// /// Decodes the image from the specified stream to the . /// @@ -63,4 +58,4 @@ namespace SixLabors.ImageSharp.Formats.Png /// public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream); } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 5e9d1440ac..9bc5a5079d 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -1,8 +1,9 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Buffers.Binary; +using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -30,7 +31,7 @@ namespace SixLabors.ImageSharp.Formats.Png private readonly byte[] buffer = new byte[4]; /// - /// Reusable crc for validating chunks. + /// Reusable CRC for validating chunks. /// private readonly Crc32 crc = new Crc32(); @@ -39,11 +40,6 @@ namespace SixLabors.ImageSharp.Formats.Png /// private readonly Configuration configuration; - /// - /// Gets the encoding to use - /// - private readonly Encoding textEncoding; - /// /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded. /// @@ -70,22 +66,22 @@ namespace SixLabors.ImageSharp.Formats.Png private int bytesPerPixel; /// - /// The number of bytes per sample + /// The number of bytes per sample. /// private int bytesPerSample; /// - /// The number of bytes per scanline + /// The number of bytes per scanline. /// private int bytesPerScanline; /// - /// The palette containing color information for indexed png's + /// The palette containing color information for indexed png's. /// private byte[] palette; /// - /// The palette containing alpha channel color information for indexed png's + /// The palette containing alpha channel color information for indexed png's. /// private byte[] paletteAlpha; @@ -95,37 +91,32 @@ namespace SixLabors.ImageSharp.Formats.Png private bool isEndChunkReached; /// - /// Previous scanline processed + /// Previous scanline processed. /// private IManagedByteBuffer previousScanline; /// - /// The current scanline that is being processed + /// The current scanline that is being processed. /// private IManagedByteBuffer scanline; /// - /// The index of the current scanline being processed + /// The index of the current scanline being processed. /// private int currentRow = Adam7.FirstRow[0]; - /// - /// The current pass for an interlaced PNG - /// - private int pass; - /// /// The current number of bytes read in the current scanline /// private int currentRowBytesRead; /// - /// Gets or sets the png color type + /// Gets or sets the png color type. /// private PngColorType pngColorType; /// - /// The next chunk of data to return + /// The next chunk of data to return. /// private PngChunk? nextChunk; @@ -138,7 +129,6 @@ namespace SixLabors.ImageSharp.Formats.Png { this.configuration = configuration ?? Configuration.Default; this.memoryAllocator = this.configuration.MemoryAllocator; - this.textEncoding = options.TextEncoding ?? PngConstants.DefaultEncoding; this.ignoreMetadata = options.IgnoreMetadata; } @@ -193,23 +183,29 @@ namespace SixLabors.ImageSharp.Formats.Png break; case PngChunkType.Palette: - byte[] pal = new byte[chunk.Length]; + var pal = new byte[chunk.Length]; Buffer.BlockCopy(chunk.Data.Array, 0, pal, 0, chunk.Length); this.palette = pal; break; case PngChunkType.Transparency: - byte[] alpha = new byte[chunk.Length]; + var alpha = new byte[chunk.Length]; Buffer.BlockCopy(chunk.Data.Array, 0, alpha, 0, chunk.Length); this.paletteAlpha = alpha; this.AssignTransparentMarkers(alpha, pngMetadata); break; case PngChunkType.Text: - this.ReadTextChunk(metadata, chunk.Data.Array.AsSpan(0, chunk.Length)); + this.ReadTextChunk(pngMetadata, chunk.Data.Array.AsSpan(0, chunk.Length)); + break; + case PngChunkType.CompressedText: + this.ReadCompressedTextChunk(pngMetadata, chunk.Data.Array.AsSpan(0, chunk.Length)); + break; + case PngChunkType.InternationalText: + this.ReadInternationalTextChunk(pngMetadata, chunk.Data.Array.AsSpan(0, chunk.Length)); break; case PngChunkType.Exif: if (!this.ignoreMetadata) { - byte[] exifData = new byte[chunk.Length]; + var exifData = new byte[chunk.Length]; Buffer.BlockCopy(chunk.Data.Array, 0, exifData, 0, chunk.Length); metadata.ExifProfile = new ExifProfile(exifData); } @@ -271,7 +267,7 @@ namespace SixLabors.ImageSharp.Formats.Png this.SkipChunkDataAndCrc(chunk); break; case PngChunkType.Text: - this.ReadTextChunk(metadata, chunk.Data.Array.AsSpan(0, chunk.Length)); + this.ReadTextChunk(pngMetadata, chunk.Data.Array.AsSpan(0, chunk.Length)); break; case PngChunkType.End: this.isEndChunkReached = true; @@ -550,13 +546,15 @@ namespace SixLabors.ImageSharp.Formats.Png private void DecodeInterlacedPixelData(Stream compressedStream, ImageFrame image, PngMetadata pngMetadata) where TPixel : struct, IPixel { + int pass = 0; + int width = this.header.Width; while (true) { - int numColumns = Adam7.ComputeColumns(this.header.Width, this.pass); + int numColumns = Adam7.ComputeColumns(width, pass); if (numColumns == 0) { - this.pass++; + pass++; // This pass contains no data; skip to next pass continue; @@ -604,23 +602,23 @@ namespace SixLabors.ImageSharp.Formats.Png } Span rowSpan = image.GetPixelRowSpan(this.currentRow); - this.ProcessInterlacedDefilteredScanline(this.scanline.GetSpan(), rowSpan, pngMetadata, Adam7.FirstColumn[this.pass], Adam7.ColumnIncrement[this.pass]); + this.ProcessInterlacedDefilteredScanline(this.scanline.GetSpan(), rowSpan, pngMetadata, Adam7.FirstColumn[pass], Adam7.ColumnIncrement[pass]); this.SwapBuffers(); - this.currentRow += Adam7.RowIncrement[this.pass]; + this.currentRow += Adam7.RowIncrement[pass]; } - this.pass++; + pass++; this.previousScanline.Clear(); - if (this.pass < 7) + if (pass < 7) { - this.currentRow = Adam7.FirstRow[this.pass]; + this.currentRow = Adam7.FirstRow[pass]; } else { - this.pass = 0; + pass = 0; break; } } @@ -653,7 +651,7 @@ namespace SixLabors.ImageSharp.Formats.Png this.header, scanlineSpan, rowSpan, - pngMetadata.HasTrans, + pngMetadata.HasTransparency, pngMetadata.TransparentGray16.GetValueOrDefault(), pngMetadata.TransparentGray8.GetValueOrDefault()); @@ -687,7 +685,7 @@ namespace SixLabors.ImageSharp.Formats.Png rowSpan, this.bytesPerPixel, this.bytesPerSample, - pngMetadata.HasTrans, + pngMetadata.HasTransparency, pngMetadata.TransparentRgb48.GetValueOrDefault(), pngMetadata.TransparentRgb24.GetValueOrDefault()); @@ -737,7 +735,7 @@ namespace SixLabors.ImageSharp.Formats.Png rowSpan, pixelOffset, increment, - pngMetadata.HasTrans, + pngMetadata.HasTransparency, pngMetadata.TransparentGray16.GetValueOrDefault(), pngMetadata.TransparentGray8.GetValueOrDefault()); @@ -776,7 +774,7 @@ namespace SixLabors.ImageSharp.Formats.Png increment, this.bytesPerPixel, this.bytesPerSample, - pngMetadata.HasTrans, + pngMetadata.HasTransparency, pngMetadata.TransparentRgb48.GetValueOrDefault(), pngMetadata.TransparentRgb24.GetValueOrDefault()); @@ -816,7 +814,7 @@ namespace SixLabors.ImageSharp.Formats.Png ushort bc = BinaryPrimitives.ReadUInt16LittleEndian(alpha.Slice(4, 2)); pngMetadata.TransparentRgb48 = new Rgb48(rc, gc, bc); - pngMetadata.HasTrans = true; + pngMetadata.HasTransparency = true; return; } @@ -824,7 +822,7 @@ namespace SixLabors.ImageSharp.Formats.Png byte g = ReadByteLittleEndian(alpha, 2); byte b = ReadByteLittleEndian(alpha, 4); pngMetadata.TransparentRgb24 = new Rgb24(r, g, b); - pngMetadata.HasTrans = true; + pngMetadata.HasTransparency = true; } } else if (this.pngColorType == PngColorType.Grayscale) @@ -840,7 +838,7 @@ namespace SixLabors.ImageSharp.Formats.Png pngMetadata.TransparentGray8 = new Gray8(ReadByteLittleEndian(alpha, 0)); } - pngMetadata.HasTrans = true; + pngMetadata.HasTransparency = true; } } } @@ -858,6 +856,7 @@ namespace SixLabors.ImageSharp.Formats.Png pngMetadata.BitDepth = (PngBitDepth)this.header.BitDepth; pngMetadata.ColorType = this.header.ColorType; + pngMetadata.InterlaceMethod = this.header.InterlaceMethod; this.pngColorType = this.header.ColorType; } @@ -867,7 +866,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// The metadata to decode to. /// The containing the data. - private void ReadTextChunk(ImageMetadata metadata, ReadOnlySpan data) + private void ReadTextChunk(PngMetadata metadata, ReadOnlySpan data) { if (this.ignoreMetadata) { @@ -876,10 +875,151 @@ namespace SixLabors.ImageSharp.Formats.Png int zeroIndex = data.IndexOf((byte)0); - string name = this.textEncoding.GetString(data.Slice(0, zeroIndex)); - string value = this.textEncoding.GetString(data.Slice(zeroIndex + 1)); + // Keywords are restricted to 1 to 79 bytes in length. + if (zeroIndex < PngConstants.MinTextKeywordLength || zeroIndex > PngConstants.MaxTextKeywordLength) + { + return; + } + + ReadOnlySpan keywordBytes = data.Slice(0, zeroIndex); + if (!this.TryReadTextKeyword(keywordBytes, out string name)) + { + return; + } + + string value = PngConstants.Encoding.GetString(data.Slice(zeroIndex + 1)); - metadata.Properties.Add(new ImageProperty(name, value)); + metadata.TextData.Add(new PngTextData(name, value, string.Empty, string.Empty)); + } + + /// + /// Reads the compressed text chunk. Contains a uncompressed keyword and a compressed text string. + /// + /// The metadata to decode to. + /// The containing the data. + private void ReadCompressedTextChunk(PngMetadata metadata, ReadOnlySpan data) + { + if (this.ignoreMetadata) + { + return; + } + + int zeroIndex = data.IndexOf((byte)0); + if (zeroIndex < PngConstants.MinTextKeywordLength || zeroIndex > PngConstants.MaxTextKeywordLength) + { + return; + } + + byte compressionMethod = data[zeroIndex + 1]; + if (compressionMethod != 0) + { + // Only compression method 0 is supported (zlib datastream with deflate compression). + return; + } + + ReadOnlySpan keywordBytes = data.Slice(0, zeroIndex); + if (!this.TryReadTextKeyword(keywordBytes, out string name)) + { + return; + } + + ReadOnlySpan compressedData = data.Slice(zeroIndex + 2); + metadata.TextData.Add(new PngTextData(name, this.UncompressTextData(compressedData, PngConstants.Encoding), string.Empty, string.Empty)); + } + + /// + /// Reads a iTXt chunk, which contains international text data. It contains: + /// - A uncompressed keyword. + /// - Compression flag, indicating if a compression is used. + /// - Compression method. + /// - Language tag (optional). + /// - A translated keyword (optional). + /// - Text data, which is either compressed or uncompressed. + /// + /// The metadata to decode to. + /// The containing the data. + private void ReadInternationalTextChunk(PngMetadata metadata, ReadOnlySpan data) + { + if (this.ignoreMetadata) + { + return; + } + + int zeroIndexKeyword = data.IndexOf((byte)0); + if (zeroIndexKeyword < PngConstants.MinTextKeywordLength || zeroIndexKeyword > PngConstants.MaxTextKeywordLength) + { + return; + } + + byte compressionFlag = data[zeroIndexKeyword + 1]; + if (!(compressionFlag == 0 || compressionFlag == 1)) + { + return; + } + + byte compressionMethod = data[zeroIndexKeyword + 2]; + if (compressionMethod != 0) + { + // Only compression method 0 is supported (zlib datastream with deflate compression). + return; + } + + int langStartIdx = zeroIndexKeyword + 3; + int languageLength = data.Slice(langStartIdx).IndexOf((byte)0); + if (languageLength < 0) + { + return; + } + + string language = PngConstants.LanguageEncoding.GetString(data.Slice(langStartIdx, languageLength)); + + int translatedKeywordStartIdx = langStartIdx + languageLength + 1; + int translatedKeywordLength = data.Slice(translatedKeywordStartIdx).IndexOf((byte)0); + string translatedKeyword = PngConstants.TranslatedEncoding.GetString(data.Slice(translatedKeywordStartIdx, translatedKeywordLength)); + + ReadOnlySpan keywordBytes = data.Slice(0, zeroIndexKeyword); + if (!this.TryReadTextKeyword(keywordBytes, out string keyword)) + { + return; + } + + int dataStartIdx = translatedKeywordStartIdx + translatedKeywordLength + 1; + if (compressionFlag == 1) + { + ReadOnlySpan compressedData = data.Slice(dataStartIdx); + metadata.TextData.Add(new PngTextData(keyword, this.UncompressTextData(compressedData, PngConstants.TranslatedEncoding), language, translatedKeyword)); + } + else + { + string value = PngConstants.TranslatedEncoding.GetString(data.Slice(dataStartIdx)); + metadata.TextData.Add(new PngTextData(keyword, value, language, translatedKeyword)); + } + } + + /// + /// Decompresses a byte array with zlib compressed text data. + /// + /// Compressed text data bytes. + /// The string encoding to use. + /// A string. + private string UncompressTextData(ReadOnlySpan compressedData, Encoding encoding) + { + using (var memoryStream = new MemoryStream(compressedData.ToArray())) + using (var inflateStream = new ZlibInflateStream(memoryStream, () => 0)) + { + inflateStream.AllocateNewBytes(compressedData.Length); + var uncompressedBytes = new List(); + + // Note: this uses the a buffer which is only 4 bytes long to read the stream, maybe allocating a larger buffer makes sense here. + int bytesRead = inflateStream.CompressedStream.Read(this.buffer, 0, this.buffer.Length); + while (bytesRead != 0) + { + uncompressedBytes.AddRange(this.buffer.AsSpan().Slice(0, bytesRead).ToArray()); + bytesRead = inflateStream.CompressedStream.Read(this.buffer, 0, this.buffer.Length); + } + + return encoding.GetString(uncompressedBytes.ToArray()); + } } /// @@ -1048,7 +1188,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// Attempts to read the length of the next chunk. /// /// - /// Whether the the length was read. + /// Whether the length was read. /// private bool TryReadChunkLength(out int result) { @@ -1060,10 +1200,40 @@ namespace SixLabors.ImageSharp.Formats.Png } result = default; - return false; } + /// + /// Tries to reads a text chunk keyword, which have some restrictions to be valid: + /// Keywords shall contain only printable Latin-1 characters and should not have leading or trailing whitespace. + /// See: https://www.w3.org/TR/PNG/#11zTXt + /// + /// The keyword bytes. + /// The name. + /// True, if the keyword could be read and is valid. + private bool TryReadTextKeyword(ReadOnlySpan keywordBytes, out string name) + { + name = string.Empty; + + // Keywords shall contain only printable Latin-1. + foreach (byte c in keywordBytes) + { + if (!((c >= 32 && c <= 126) || (c >= 161 && c <= 255))) + { + return false; + } + } + + // Keywords should not be empty or have leading or trailing whitespace. + name = PngConstants.Encoding.GetString(keywordBytes); + if (string.IsNullOrWhiteSpace(name) || name.StartsWith(" ") || name.EndsWith(" ")) + { + return false; + } + + return true; + } + private void SwapBuffers() { IManagedByteBuffer temp = this.previousScanline; @@ -1071,4 +1241,4 @@ namespace SixLabors.ImageSharp.Formats.Png this.scanline = temp; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index 96e97a305f..3e46ad29ec 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.IO; @@ -36,20 +36,31 @@ namespace SixLabors.ImageSharp.Formats.Png public int CompressionLevel { get; set; } = 6; /// - /// Gets or sets the gamma value, that will be written the the image. + /// Gets or sets the threshold of characters in text metadata, when compression should be used. + /// Defaults to 1024. + /// + public int TextCompressionThreshold { get; set; } = 1024; + + /// + /// Gets or sets the gamma value, that will be written the image. /// public float? Gamma { get; set; } /// /// Gets or sets quantizer for reducing the color count. - /// Defaults to the + /// Defaults to the . /// public IQuantizer Quantizer { get; set; } /// /// Gets or sets the transparency threshold. /// - public byte Threshold { get; set; } = 255; + public byte Threshold { get; set; } = byte.MaxValue; + + /// + /// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image. + /// + public PngInterlaceMode? InterlaceMethod { get; set; } /// /// Encodes the image to the specified stream from the . @@ -60,10 +71,10 @@ namespace SixLabors.ImageSharp.Formats.Png public void Encode(Image image, Stream stream) where TPixel : struct, IPixel { - using (var encoder = new PngEncoderCore(image.GetMemoryAllocator(), this)) + using (var encoder = new PngEncoderCore(image.GetMemoryAllocator(), image.GetConfiguration(), new PngEncoderOptions(this))) { encoder.Encode(image, stream); } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index def57c3b0e..09575bb288 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -1,13 +1,14 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Buffers; using System.Buffers.Binary; -using System.Collections.Generic; using System.IO; +using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats.Png.Chunks; using SixLabors.ImageSharp.Formats.Png.Filters; @@ -26,16 +27,9 @@ namespace SixLabors.ImageSharp.Formats.Png internal sealed class PngEncoderCore : IDisposable { /// - /// The dictionary of available color types. + /// The maximum block size, defaults at 64k for uncompressed blocks. /// - private static readonly Dictionary ColorTypes = new Dictionary() - { - [PngColorType.Grayscale] = new byte[] { 1, 2, 4, 8, 16 }, - [PngColorType.Rgb] = new byte[] { 8, 16 }, - [PngColorType.Palette] = new byte[] { 1, 2, 4, 8 }, - [PngColorType.GrayscaleWithAlpha] = new byte[] { 8, 16 }, - [PngColorType.RgbWithAlpha] = new byte[] { 8, 16 } - }; + private const int MaxBlockSize = 65535; /// /// Used the manage memory allocations. @@ -43,14 +37,9 @@ namespace SixLabors.ImageSharp.Formats.Png private readonly MemoryAllocator memoryAllocator; /// - /// The configuration instance for the decoding operation + /// The configuration instance for the decoding operation. /// - private Configuration configuration; - - /// - /// The maximum block size, defaults at 64k for uncompressed blocks. - /// - private const int MaxBlockSize = 65535; + private readonly Configuration configuration; /// /// Reusable buffer for writing general data. @@ -63,39 +52,19 @@ namespace SixLabors.ImageSharp.Formats.Png private readonly byte[] chunkDataBuffer = new byte[16]; /// - /// Reusable crc for validating chunks. + /// Reusable CRC for validating chunks. /// private readonly Crc32 crc = new Crc32(); /// - /// The png filter method. - /// - private readonly PngFilterMethod pngFilterMethod; - - /// - /// Gets or sets the CompressionLevel value - /// - private readonly int compressionLevel; - - /// - /// Gets or sets the alpha threshold value - /// - private readonly byte threshold; - - /// - /// The quantizer for reducing the color count. - /// - private IQuantizer quantizer; - - /// - /// Gets or sets a value indicating whether to write the gamma chunk + /// The encoder options /// - private bool writeGamma; + private readonly PngEncoderOptions options; /// - /// The png bit depth + /// The bit depth. /// - private PngBitDepth? pngBitDepth; + private byte bitDepth; /// /// Gets or sets a value indicating whether to use 16 bit encoding for supported color types. @@ -103,14 +72,9 @@ namespace SixLabors.ImageSharp.Formats.Png private bool use16Bit; /// - /// The png color type. - /// - private PngColorType? pngColorType; - - /// - /// Gets or sets the Gamma value + /// The number of bytes per pixel. /// - private float? gamma; + private int bytesPerPixel; /// /// The image width. @@ -123,74 +87,46 @@ namespace SixLabors.ImageSharp.Formats.Png private int height; /// - /// The number of bits required to encode the colors in the png. - /// - private byte bitDepth; - - /// - /// The number of bytes per pixel. - /// - private int bytesPerPixel; - - /// - /// The number of bytes per scanline. - /// - private int bytesPerScanline; - - /// - /// The previous scanline. + /// The raw data of previous scanline. /// private IManagedByteBuffer previousScanline; /// - /// The raw scanline. + /// The raw data of current scanline. /// - private IManagedByteBuffer rawScanline; + private IManagedByteBuffer currentScanline; /// - /// The filtered scanline result. + /// The common buffer for the filters. /// - private IManagedByteBuffer result; + private IManagedByteBuffer filterBuffer; /// - /// The buffer for the sub filter + /// The ext buffer for the sub filter, . /// - private IManagedByteBuffer sub; + private IManagedByteBuffer subFilter; /// - /// The buffer for the up filter + /// The ext buffer for the average filter, . /// - private IManagedByteBuffer up; + private IManagedByteBuffer averageFilter; /// - /// The buffer for the average filter + /// The ext buffer for the Paeth filter, . /// - private IManagedByteBuffer average; + private IManagedByteBuffer paethFilter; /// - /// The buffer for the Paeth filter + /// Initializes a new instance of the class. /// - private IManagedByteBuffer paeth; - - /// - /// Initializes a new instance of the class. - /// - /// The to use for buffer allocations. + /// The to use for buffer allocations. + /// The configuration. /// The options for influencing the encoder - public PngEncoderCore(MemoryAllocator memoryAllocator, IPngEncoderOptions options) + public PngEncoderCore(MemoryAllocator memoryAllocator, Configuration configuration, PngEncoderOptions options) { this.memoryAllocator = memoryAllocator; - this.pngBitDepth = options.BitDepth; - this.pngColorType = options.ColorType; - - // Specification recommends default filter method None for paletted images and Paeth for others. - this.pngFilterMethod = options.FilterMethod ?? (options.ColorType == PngColorType.Palette - ? PngFilterMethod.None - : PngFilterMethod.Paeth); - this.compressionLevel = options.CompressionLevel; - this.gamma = options.Gamma; - this.quantizer = options.Quantizer; - this.threshold = options.Threshold; + this.configuration = configuration; + this.options = options; } /// @@ -205,101 +141,24 @@ namespace SixLabors.ImageSharp.Formats.Png Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); - this.configuration = image.GetConfiguration(); this.width = image.Width; this.height = image.Height; - // Always take the encoder options over the metadata values. ImageMetadata metadata = image.Metadata; PngMetadata pngMetadata = metadata.GetFormatMetadata(PngFormat.Instance); - this.gamma = this.gamma ?? pngMetadata.Gamma; - this.writeGamma = this.gamma > 0; - this.pngColorType = this.pngColorType ?? pngMetadata.ColorType; - this.pngBitDepth = this.pngBitDepth ?? pngMetadata.BitDepth; - this.use16Bit = this.pngBitDepth == PngBitDepth.Bit16; - - // Ensure we are not allowing impossible combinations. - if (!ColorTypes.ContainsKey(this.pngColorType.Value)) - { - throw new NotSupportedException("Color type is not supported or not valid."); - } + PngEncoderOptionsHelpers.AdjustOptions(this.options, pngMetadata, out this.use16Bit, out this.bytesPerPixel); + IQuantizedFrame quantized = PngEncoderOptionsHelpers.CreateQuantizedFrame(this.options, image); + this.bitDepth = PngEncoderOptionsHelpers.CalculateBitDepth(this.options, image, quantized); stream.Write(PngConstants.HeaderBytes, 0, PngConstants.HeaderBytes.Length); - IQuantizedFrame quantized = null; - if (this.pngColorType == PngColorType.Palette) - { - byte bits = (byte)this.pngBitDepth; - if (Array.IndexOf(ColorTypes[this.pngColorType.Value], bits) == -1) - { - throw new NotSupportedException("Bit depth is not supported or not valid."); - } - - // Use the metadata to determine what quantization depth to use if no quantizer has been set. - if (this.quantizer is null) - { - this.quantizer = new WuQuantizer(ImageMaths.GetColorCountForBitDepth(bits)); - } - - // Create quantized frame returning the palette and set the bit depth. - using (IFrameQuantizer frameQuantizer = this.quantizer.CreateFrameQuantizer(image.GetConfiguration())) - { - quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame); - } - - byte quantizedBits = (byte)ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length).Clamp(1, 8); - bits = Math.Max(bits, quantizedBits); - - // Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk - // We check again for the bit depth as the bit depth of the color palette from a given quantizer might not - // be within the acceptable range. - if (bits == 3) - { - bits = 4; - } - else if (bits >= 5 && bits <= 7) - { - bits = 8; - } - - this.bitDepth = bits; - } - else - { - this.bitDepth = (byte)this.pngBitDepth; - if (Array.IndexOf(ColorTypes[this.pngColorType.Value], this.bitDepth) == -1) - { - throw new NotSupportedException("Bit depth is not supported or not valid."); - } - } - - this.bytesPerPixel = this.CalculateBytesPerPixel(); - - var header = new PngHeader( - width: image.Width, - height: image.Height, - bitDepth: this.bitDepth, - colorType: this.pngColorType.Value, - compressionMethod: 0, // None - filterMethod: 0, - interlaceMethod: 0); // TODO: Can't write interlaced yet. - - this.WriteHeaderChunk(stream, header); - - // Collect the indexed pixel data - if (quantized != null) - { - this.WritePaletteChunk(stream, quantized); - } - - if (pngMetadata.HasTrans) - { - this.WriteTransparencyChunk(stream, pngMetadata); - } - + this.WriteHeaderChunk(stream); + this.WritePaletteChunk(stream, quantized); + this.WriteTransparencyChunk(stream, pngMetadata); this.WritePhysicalChunk(stream, metadata); this.WriteGammaChunk(stream); this.WriteExifChunk(stream, metadata); + this.WriteTextChunks(stream, pngMetadata); this.WriteDataChunks(image.Frames.RootFrame, quantized, stream); this.WriteEndChunk(stream); stream.Flush(); @@ -311,27 +170,31 @@ namespace SixLabors.ImageSharp.Formats.Png public void Dispose() { this.previousScanline?.Dispose(); - this.rawScanline?.Dispose(); - this.result?.Dispose(); - this.sub?.Dispose(); - this.up?.Dispose(); - this.average?.Dispose(); - this.paeth?.Dispose(); + this.currentScanline?.Dispose(); + this.subFilter?.Dispose(); + this.averageFilter?.Dispose(); + this.paethFilter?.Dispose(); + this.filterBuffer?.Dispose(); + + this.previousScanline = null; + this.currentScanline = null; + this.subFilter = null; + this.averageFilter = null; + this.paethFilter = null; + this.filterBuffer = null; } - /// - /// Collects a row of grayscale pixels. - /// + /// Collects a row of grayscale pixels. /// The pixel format. /// The image row span. private void CollectGrayscaleBytes(ReadOnlySpan rowSpan) where TPixel : struct, IPixel { ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan); - Span rawScanlineSpan = this.rawScanline.GetSpan(); + Span rawScanlineSpan = this.currentScanline.GetSpan(); ref byte rawScanlineSpanRef = ref MemoryMarshal.GetReference(rawScanlineSpan); - if (this.pngColorType == PngColorType.Grayscale) + if (this.options.ColorType == PngColorType.Grayscale) { if (this.use16Bit) { @@ -342,7 +205,7 @@ namespace SixLabors.ImageSharp.Formats.Png ref Gray16 luminanceRef = ref MemoryMarshal.GetReference(luminanceSpan); PixelOperations.Instance.ToGray16(this.configuration, rowSpan, luminanceSpan); - // Can't map directly to byte array as it's big endian. + // Can't map directly to byte array as it's big-endian. for (int x = 0, o = 0; x < luminanceSpan.Length; x++, o += 2) { Gray16 luminance = Unsafe.Add(ref luminanceRef, x); @@ -377,7 +240,7 @@ namespace SixLabors.ImageSharp.Formats.Png rowSpan, tempSpan, rowSpan.Length); - this.ScaleDownFrom8BitArray(tempSpan, rawScanlineSpan, this.bitDepth, scaleFactor); + PngEncoderHelpers.ScaleDownFrom8BitArray(tempSpan, rawScanlineSpan, this.bitDepth, scaleFactor); } } } @@ -428,76 +291,76 @@ namespace SixLabors.ImageSharp.Formats.Png private void CollectTPixelBytes(ReadOnlySpan rowSpan) where TPixel : struct, IPixel { - Span rawScanlineSpan = this.rawScanline.GetSpan(); + Span rawScanlineSpan = this.currentScanline.GetSpan(); switch (this.bytesPerPixel) { case 4: - { - // 8 bit Rgba - PixelOperations.Instance.ToRgba32Bytes( - this.configuration, - rowSpan, - rawScanlineSpan, - this.width); - break; - } + { + // 8 bit Rgba + PixelOperations.Instance.ToRgba32Bytes( + this.configuration, + rowSpan, + rawScanlineSpan, + rowSpan.Length); + break; + } case 3: - { - // 8 bit Rgb - PixelOperations.Instance.ToRgb24Bytes( - this.configuration, - rowSpan, - rawScanlineSpan, - this.width); - break; - } + { + // 8 bit Rgb + PixelOperations.Instance.ToRgb24Bytes( + this.configuration, + rowSpan, + rawScanlineSpan, + rowSpan.Length); + break; + } case 8: + { + // 16 bit Rgba + using (IMemoryOwner rgbaBuffer = this.memoryAllocator.Allocate(rowSpan.Length)) { - // 16 bit Rgba - using (IMemoryOwner rgbaBuffer = this.memoryAllocator.Allocate(rowSpan.Length)) + Span rgbaSpan = rgbaBuffer.GetSpan(); + ref Rgba64 rgbaRef = ref MemoryMarshal.GetReference(rgbaSpan); + PixelOperations.Instance.ToRgba64(this.configuration, rowSpan, rgbaSpan); + + // Can't map directly to byte array as it's big endian. + for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 8) { - Span rgbaSpan = rgbaBuffer.GetSpan(); - ref Rgba64 rgbaRef = ref MemoryMarshal.GetReference(rgbaSpan); - PixelOperations.Instance.ToRgba64(this.configuration, rowSpan, rgbaSpan); - - // Can't map directly to byte array as it's big endian. - for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 8) - { - Rgba64 rgba = Unsafe.Add(ref rgbaRef, x); - BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), rgba.R); - BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.G); - BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 4, 2), rgba.B); - BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 6, 2), rgba.A); - } + Rgba64 rgba = Unsafe.Add(ref rgbaRef, x); + BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), rgba.R); + BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.G); + BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 4, 2), rgba.B); + BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 6, 2), rgba.A); } - - break; } + break; + } + default: + { + // 16 bit Rgb + using (IMemoryOwner rgbBuffer = this.memoryAllocator.Allocate(rowSpan.Length)) { - // 16 bit Rgb - using (IMemoryOwner rgbBuffer = this.memoryAllocator.Allocate(rowSpan.Length)) + Span rgbSpan = rgbBuffer.GetSpan(); + ref Rgb48 rgbRef = ref MemoryMarshal.GetReference(rgbSpan); + PixelOperations.Instance.ToRgb48(this.configuration, rowSpan, rgbSpan); + + // Can't map directly to byte array as it's big endian. + for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 6) { - Span rgbSpan = rgbBuffer.GetSpan(); - ref Rgb48 rgbRef = ref MemoryMarshal.GetReference(rgbSpan); - PixelOperations.Instance.ToRgb48(this.configuration, rowSpan, rgbSpan); - - // Can't map directly to byte array as it's big endian. - for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 6) - { - Rgb48 rgb = Unsafe.Add(ref rgbRef, x); - BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), rgb.R); - BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgb.G); - BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 4, 2), rgb.B); - } + Rgb48 rgb = Unsafe.Add(ref rgbRef, x); + BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), rgb.R); + BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgb.G); + BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 4, 2), rgb.B); } - - break; } + + break; + } } } @@ -509,22 +372,21 @@ namespace SixLabors.ImageSharp.Formats.Png /// The row span. /// The quantized pixels. Can be null. /// The row. - /// The - private IManagedByteBuffer EncodePixelRow(ReadOnlySpan rowSpan, IQuantizedFrame quantized, int row) + private void CollectPixelBytes(ReadOnlySpan rowSpan, IQuantizedFrame quantized, int row) where TPixel : struct, IPixel { - switch (this.pngColorType) + switch (this.options.ColorType) { case PngColorType.Palette: if (this.bitDepth < 8) { - this.ScaleDownFrom8BitArray(quantized.GetRowSpan(row), this.rawScanline.GetSpan(), this.bitDepth); + PngEncoderHelpers.ScaleDownFrom8BitArray(quantized.GetRowSpan(row), this.currentScanline.GetSpan(), this.bitDepth); } else { - int stride = this.rawScanline.Length(); - quantized.GetPixelSpan().Slice(row * stride, stride).CopyTo(this.rawScanline.GetSpan()); + int stride = this.currentScanline.Length(); + quantized.GetPixelSpan().Slice(row * stride, stride).CopyTo(this.currentScanline.GetSpan()); } break; @@ -536,34 +398,75 @@ namespace SixLabors.ImageSharp.Formats.Png this.CollectTPixelBytes(rowSpan); break; } + } - switch (this.pngFilterMethod) + /// + /// Apply filter for the raw scanline. + /// + private IManagedByteBuffer FilterPixelBytes() + { + switch (this.options.FilterMethod) { case PngFilterMethod.None: - NoneFilter.Encode(this.rawScanline.GetSpan(), this.result.GetSpan()); - return this.result; + NoneFilter.Encode(this.currentScanline.GetSpan(), this.filterBuffer.GetSpan()); + return this.filterBuffer; case PngFilterMethod.Sub: - SubFilter.Encode(this.rawScanline.GetSpan(), this.sub.GetSpan(), this.bytesPerPixel, out int _); - return this.sub; + SubFilter.Encode(this.currentScanline.GetSpan(), this.filterBuffer.GetSpan(), this.bytesPerPixel, out int _); + return this.filterBuffer; case PngFilterMethod.Up: - UpFilter.Encode(this.rawScanline.GetSpan(), this.previousScanline.GetSpan(), this.up.GetSpan(), out int _); - return this.up; + UpFilter.Encode(this.currentScanline.GetSpan(), this.previousScanline.GetSpan(), this.filterBuffer.GetSpan(), out int _); + return this.filterBuffer; case PngFilterMethod.Average: - AverageFilter.Encode(this.rawScanline.GetSpan(), this.previousScanline.GetSpan(), this.average.GetSpan(), this.bytesPerPixel, out int _); - return this.average; + AverageFilter.Encode(this.currentScanline.GetSpan(), this.previousScanline.GetSpan(), this.filterBuffer.GetSpan(), this.bytesPerPixel, out int _); + return this.filterBuffer; case PngFilterMethod.Paeth: - PaethFilter.Encode(this.rawScanline.GetSpan(), this.previousScanline.GetSpan(), this.paeth.GetSpan(), this.bytesPerPixel, out int _); - return this.paeth; + PaethFilter.Encode(this.currentScanline.GetSpan(), this.previousScanline.GetSpan(), this.filterBuffer.GetSpan(), this.bytesPerPixel, out int _); + return this.filterBuffer; default: return this.GetOptimalFilteredScanline(); } } + /// + /// Encodes the pixel data line by line. + /// Each scanline is encoded in the most optimal manner to improve compression. + /// + /// The pixel format. + /// The row span. + /// The quantized pixels. Can be null. + /// The row. + /// The + private IManagedByteBuffer EncodePixelRow(ReadOnlySpan rowSpan, IQuantizedFrame quantized, int row) + where TPixel : struct, IPixel + { + this.CollectPixelBytes(rowSpan, quantized, row); + return this.FilterPixelBytes(); + } + + /// + /// Encodes the indexed pixel data (with palette) for Adam7 interlaced mode. + /// + /// The row span. + private IManagedByteBuffer EncodeAdam7IndexedPixelRow(ReadOnlySpan rowSpan) + { + // CollectPixelBytes + if (this.bitDepth < 8) + { + PngEncoderHelpers.ScaleDownFrom8BitArray(rowSpan, this.currentScanline.GetSpan(), this.bitDepth); + } + else + { + rowSpan.CopyTo(this.currentScanline.GetSpan()); + } + + return this.FilterPixelBytes(); + } + /// /// Applies all PNG filters to the given scanline and returns the filtered scanline that is deemed /// to be most compressible, using lowest total variation as proxy for compressibility. @@ -572,84 +475,67 @@ namespace SixLabors.ImageSharp.Formats.Png private IManagedByteBuffer GetOptimalFilteredScanline() { // Palette images don't compress well with adaptive filtering. - if (this.pngColorType == PngColorType.Palette || this.bitDepth < 8) + if (this.options.ColorType == PngColorType.Palette || this.bitDepth < 8) { - NoneFilter.Encode(this.rawScanline.GetSpan(), this.result.GetSpan()); - return this.result; + NoneFilter.Encode(this.currentScanline.GetSpan(), this.filterBuffer.GetSpan()); + return this.filterBuffer; } - Span scanSpan = this.rawScanline.GetSpan(); + this.AllocateExtBuffers(); + Span scanSpan = this.currentScanline.GetSpan(); Span prevSpan = this.previousScanline.GetSpan(); // This order, while different to the enumerated order is more likely to produce a smaller sum // early on which shaves a couple of milliseconds off the processing time. - UpFilter.Encode(scanSpan, prevSpan, this.up.GetSpan(), out int currentSum); + UpFilter.Encode(scanSpan, prevSpan, this.filterBuffer.GetSpan(), out int currentSum); // TODO: PERF.. We should be breaking out of the encoding for each line as soon as we hit the sum. // That way the above comment would actually be true. It used to be anyway... // If we could use SIMD for none branching filters we could really speed it up. int lowestSum = currentSum; - IManagedByteBuffer actualResult = this.up; + IManagedByteBuffer actualResult = this.filterBuffer; - PaethFilter.Encode(scanSpan, prevSpan, this.paeth.GetSpan(), this.bytesPerPixel, out currentSum); + PaethFilter.Encode(scanSpan, prevSpan, this.paethFilter.GetSpan(), this.bytesPerPixel, out currentSum); if (currentSum < lowestSum) { lowestSum = currentSum; - actualResult = this.paeth; + actualResult = this.paethFilter; } - SubFilter.Encode(scanSpan, this.sub.GetSpan(), this.bytesPerPixel, out currentSum); + SubFilter.Encode(scanSpan, this.subFilter.GetSpan(), this.bytesPerPixel, out currentSum); if (currentSum < lowestSum) { lowestSum = currentSum; - actualResult = this.sub; + actualResult = this.subFilter; } - AverageFilter.Encode(scanSpan, prevSpan, this.average.GetSpan(), this.bytesPerPixel, out currentSum); + AverageFilter.Encode(scanSpan, prevSpan, this.averageFilter.GetSpan(), this.bytesPerPixel, out currentSum); if (currentSum < lowestSum) { - actualResult = this.average; + actualResult = this.averageFilter; } return actualResult; } - /// - /// Calculates the correct number of bytes per pixel for the given color type. - /// - /// Bytes per pixel - private int CalculateBytesPerPixel() - { - switch (this.pngColorType) - { - case PngColorType.Grayscale: - return this.use16Bit ? 2 : 1; - - case PngColorType.GrayscaleWithAlpha: - return this.use16Bit ? 4 : 2; - - case PngColorType.Palette: - return 1; - - case PngColorType.Rgb: - return this.use16Bit ? 6 : 3; - - // PngColorType.RgbWithAlpha - default: - return this.use16Bit ? 8 : 4; - } - } - /// /// Writes the header chunk to the stream. /// /// The containing image data. - /// The . - private void WriteHeaderChunk(Stream stream, in PngHeader header) + private void WriteHeaderChunk(Stream stream) { + var header = new PngHeader( + width: this.width, + height: this.height, + bitDepth: this.bitDepth, + colorType: this.options.ColorType.Value, + compressionMethod: 0, // None + filterMethod: 0, + interlaceMethod: this.options.InterlaceMethod.Value); + header.WriteTo(this.chunkDataBuffer); this.WriteChunk(stream, PngChunkType.Header, this.chunkDataBuffer, 0, PngHeader.Size); @@ -664,6 +550,11 @@ namespace SixLabors.ImageSharp.Formats.Png private void WritePaletteChunk(Stream stream, IQuantizedFrame quantized) where TPixel : struct, IPixel { + if (quantized == null) + { + return; + } + // Grab the palette and write it to the stream. ReadOnlySpan palette = quantized.Palette.Span; int paletteLength = Math.Min(palette.Length, 256); @@ -692,7 +583,7 @@ namespace SixLabors.ImageSharp.Formats.Png Unsafe.Add(ref colorTableRef, offset + 1) = rgba.G; Unsafe.Add(ref colorTableRef, offset + 2) = rgba.B; - if (alpha > this.threshold) + if (alpha > this.options.Threshold) { alpha = byte.MaxValue; } @@ -738,16 +629,95 @@ namespace SixLabors.ImageSharp.Formats.Png } } + /// + /// Writes a text chunk to the stream. Can be either a tTXt, iTXt or zTXt chunk, + /// depending whether the text contains any latin characters or should be compressed. + /// + /// The containing image data. + /// The image metadata. + private void WriteTextChunks(Stream stream, PngMetadata meta) + { + const int MaxLatinCode = 255; + foreach (PngTextData textData in meta.TextData) + { + bool hasUnicodeCharacters = textData.Value.Any(c => c > MaxLatinCode); + if (hasUnicodeCharacters || (!string.IsNullOrWhiteSpace(textData.LanguageTag) || !string.IsNullOrWhiteSpace(textData.TranslatedKeyword))) + { + // Write iTXt chunk. + byte[] keywordBytes = PngConstants.Encoding.GetBytes(textData.Keyword); + byte[] textBytes = textData.Value.Length > this.options.TextCompressionThreshold + ? this.GetCompressedTextBytes(PngConstants.TranslatedEncoding.GetBytes(textData.Value)) + : PngConstants.TranslatedEncoding.GetBytes(textData.Value); + + byte[] translatedKeyword = PngConstants.TranslatedEncoding.GetBytes(textData.TranslatedKeyword); + byte[] languageTag = PngConstants.LanguageEncoding.GetBytes(textData.LanguageTag); + + Span outputBytes = new byte[keywordBytes.Length + textBytes.Length + translatedKeyword.Length + languageTag.Length + 5]; + keywordBytes.CopyTo(outputBytes); + if (textData.Value.Length > this.options.TextCompressionThreshold) + { + // Indicate that the text is compressed. + outputBytes[keywordBytes.Length + 1] = 1; + } + + int keywordStart = keywordBytes.Length + 3; + languageTag.CopyTo(outputBytes.Slice(keywordStart)); + int translatedKeywordStart = keywordStart + languageTag.Length + 1; + translatedKeyword.CopyTo(outputBytes.Slice(translatedKeywordStart)); + textBytes.CopyTo(outputBytes.Slice(translatedKeywordStart + translatedKeyword.Length + 1)); + this.WriteChunk(stream, PngChunkType.InternationalText, outputBytes.ToArray()); + } + else + { + if (textData.Value.Length > this.options.TextCompressionThreshold) + { + // Write zTXt chunk. + byte[] compressedData = this.GetCompressedTextBytes(PngConstants.Encoding.GetBytes(textData.Value)); + Span outputBytes = new byte[textData.Keyword.Length + compressedData.Length + 2]; + PngConstants.Encoding.GetBytes(textData.Keyword).CopyTo(outputBytes); + compressedData.CopyTo(outputBytes.Slice(textData.Keyword.Length + 2)); + this.WriteChunk(stream, PngChunkType.CompressedText, outputBytes.ToArray()); + } + else + { + // Write tEXt chunk. + Span outputBytes = new byte[textData.Keyword.Length + textData.Value.Length + 1]; + PngConstants.Encoding.GetBytes(textData.Keyword).CopyTo(outputBytes); + PngConstants.Encoding.GetBytes(textData.Value).CopyTo(outputBytes.Slice(textData.Keyword.Length + 1)); + this.WriteChunk(stream, PngChunkType.Text, outputBytes.ToArray()); + } + } + } + } + + /// + /// Compresses a given text using Zlib compression. + /// + /// The text bytes to compress. + /// The compressed text byte array. + private byte[] GetCompressedTextBytes(byte[] textBytes) + { + using (var memoryStream = new MemoryStream()) + { + using (var deflateStream = new ZlibDeflateStream(memoryStream, this.options.CompressionLevel)) + { + deflateStream.Write(textBytes); + } + + return memoryStream.ToArray(); + } + } + /// /// Writes the gamma information to the stream. /// /// The containing image data. private void WriteGammaChunk(Stream stream) { - if (this.writeGamma) + if (this.options.Gamma > 0) { // 4-byte unsigned integer of gamma * 100,000. - uint gammaValue = (uint)(this.gamma * 100_000F); + uint gammaValue = (uint)(this.options.Gamma * 100_000F); BinaryPrimitives.WriteUInt32BigEndian(this.chunkDataBuffer.AsSpan(0, 4), gammaValue); @@ -756,12 +726,17 @@ namespace SixLabors.ImageSharp.Formats.Png } /// - /// Writes the transparency chunk to the stream + /// Writes the transparency chunk to the stream. /// /// The containing image data. /// The image metadata. private void WriteTransparencyChunk(Stream stream, PngMetadata pngMetadata) { + if (!pngMetadata.HasTransparency) + { + return; + } + Span alpha = this.chunkDataBuffer.AsSpan(); if (pngMetadata.ColorType == PngColorType.Rgb) { @@ -810,57 +785,27 @@ namespace SixLabors.ImageSharp.Formats.Png private void WriteDataChunks(ImageFrame pixels, IQuantizedFrame quantized, Stream stream) where TPixel : struct, IPixel { - this.bytesPerScanline = this.CalculateScanlineLength(this.width); - int resultLength = this.bytesPerScanline + 1; - - this.previousScanline = this.memoryAllocator.AllocateManagedByteBuffer(this.bytesPerScanline, AllocationOptions.Clean); - this.rawScanline = this.memoryAllocator.AllocateManagedByteBuffer(this.bytesPerScanline, AllocationOptions.Clean); - this.result = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); - - switch (this.pngFilterMethod) - { - case PngFilterMethod.None: - break; - - case PngFilterMethod.Sub: - this.sub = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); - break; - - case PngFilterMethod.Up: - this.up = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); - break; - - case PngFilterMethod.Average: - this.average = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); - break; - - case PngFilterMethod.Paeth: - this.paeth = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); - break; - - case PngFilterMethod.Adaptive: - this.sub = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); - this.up = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); - this.average = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); - this.paeth = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); - break; - } - byte[] buffer; int bufferLength; using (var memoryStream = new MemoryStream()) { - using (var deflateStream = new ZlibDeflateStream(memoryStream, this.compressionLevel)) + using (var deflateStream = new ZlibDeflateStream(memoryStream, this.options.CompressionLevel)) { - for (int y = 0; y < this.height; y++) + if (this.options.InterlaceMethod == PngInterlaceMode.Adam7) { - IManagedByteBuffer r = this.EncodePixelRow((ReadOnlySpan)pixels.GetPixelRowSpan(y), quantized, y); - deflateStream.Write(r.Array, 0, resultLength); - - IManagedByteBuffer temp = this.rawScanline; - this.rawScanline = this.previousScanline; - this.previousScanline = temp; + if (quantized != null) + { + this.EncodeAdam7IndexedPixels(quantized, deflateStream); + } + else + { + this.EncodeAdam7Pixels(pixels, deflateStream); + } + } + else + { + this.EncodePixels(pixels, quantized, deflateStream); } } @@ -890,6 +835,173 @@ namespace SixLabors.ImageSharp.Formats.Png } } + /// + /// Allocates the buffers for each scanline. + /// + /// The bytes per scanline. + /// Length of the result. + private void AllocateBuffers(int bytesPerScanline, int resultLength) + { + // Clean up from any potential previous runs. + this.subFilter?.Dispose(); + this.averageFilter?.Dispose(); + this.paethFilter?.Dispose(); + this.subFilter = null; + this.averageFilter = null; + this.paethFilter = null; + + this.previousScanline?.Dispose(); + this.currentScanline?.Dispose(); + this.filterBuffer?.Dispose(); + this.previousScanline = this.memoryAllocator.AllocateManagedByteBuffer(bytesPerScanline, AllocationOptions.Clean); + this.currentScanline = this.memoryAllocator.AllocateManagedByteBuffer(bytesPerScanline, AllocationOptions.Clean); + this.filterBuffer = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); + } + + /// + /// Allocates the ext buffers for adaptive filter. + /// + private void AllocateExtBuffers() + { + if (this.subFilter == null) + { + int resultLength = this.filterBuffer.Length(); + + this.subFilter = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); + this.averageFilter = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); + this.paethFilter = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); + } + } + + /// + /// Encodes the pixels. + /// + /// The type of the pixel. + /// The pixels. + /// The quantized pixels span. + /// The deflate stream. + private void EncodePixels(ImageFrame pixels, IQuantizedFrame quantized, ZlibDeflateStream deflateStream) + where TPixel : struct, IPixel + { + int bytesPerScanline = this.CalculateScanlineLength(this.width); + int resultLength = bytesPerScanline + 1; + this.AllocateBuffers(bytesPerScanline, resultLength); + + for (int y = 0; y < this.height; y++) + { + IManagedByteBuffer r = this.EncodePixelRow(pixels.GetPixelRowSpan(y), quantized, y); + deflateStream.Write(r.Array, 0, resultLength); + + IManagedByteBuffer temp = this.currentScanline; + this.currentScanline = this.previousScanline; + this.previousScanline = temp; + } + } + + /// + /// Interlaced encoding the pixels. + /// + /// The type of the pixel. + /// The pixels. + /// The deflate stream. + private void EncodeAdam7Pixels(ImageFrame pixels, ZlibDeflateStream deflateStream) + where TPixel : struct, IPixel + { + int width = pixels.Width; + int height = pixels.Height; + for (int pass = 0; pass < 7; pass++) + { + int startRow = Adam7.FirstRow[pass]; + int startCol = Adam7.FirstColumn[pass]; + int blockWidth = Adam7.ComputeBlockWidth(width, pass); + + int bytesPerScanline = this.bytesPerPixel <= 1 + ? ((blockWidth * this.bitDepth) + 7) / 8 + : blockWidth * this.bytesPerPixel; + + int resultLength = bytesPerScanline + 1; + + this.AllocateBuffers(bytesPerScanline, resultLength); + + using (IMemoryOwner passData = this.memoryAllocator.Allocate(blockWidth)) + { + Span destSpan = passData.Memory.Span; + for (int row = startRow; + row < height; + row += Adam7.RowIncrement[pass]) + { + // collect data + Span srcRow = pixels.GetPixelRowSpan(row); + for (int col = startCol, i = 0; + col < width; + col += Adam7.ColumnIncrement[pass]) + { + destSpan[i++] = srcRow[col]; + } + + // encode data + // note: quantized parameter not used + // note: row parameter not used + IManagedByteBuffer r = this.EncodePixelRow((ReadOnlySpan)destSpan, null, -1); + deflateStream.Write(r.Array, 0, resultLength); + + IManagedByteBuffer temp = this.currentScanline; + this.currentScanline = this.previousScanline; + this.previousScanline = temp; + } + } + } + } + + /// + /// Interlaced encoding the quantized (indexed, with palette) pixels. + /// + /// The type of the pixel. + /// The quantized. + /// The deflate stream. + private void EncodeAdam7IndexedPixels(IQuantizedFrame quantized, ZlibDeflateStream deflateStream) + where TPixel : struct, IPixel + { + int width = quantized.Width; + int height = quantized.Height; + for (int pass = 0; pass < 7; pass++) + { + int startRow = Adam7.FirstRow[pass]; + int startCol = Adam7.FirstColumn[pass]; + int blockWidth = Adam7.ComputeBlockWidth(width, pass); + + int bytesPerScanline = this.bytesPerPixel <= 1 + ? ((blockWidth * this.bitDepth) + 7) / 8 + : blockWidth * this.bytesPerPixel; + + int resultLength = bytesPerScanline + 1; + + this.AllocateBuffers(bytesPerScanline, resultLength); + + using (IMemoryOwner passData = this.memoryAllocator.Allocate(blockWidth)) + { + Span destSpan = passData.Memory.Span; + for (int row = startRow; + row < height; + row += Adam7.RowIncrement[pass]) + { + // collect data + ReadOnlySpan srcRow = quantized.GetRowSpan(row); + for (int col = startCol, i = 0; + col < width; + col += Adam7.ColumnIncrement[pass]) + { + destSpan[i++] = srcRow[col]; + } + + // encode data + IManagedByteBuffer r = this.EncodeAdam7IndexedPixelRow(destSpan); + deflateStream.Write(r.Array, 0, resultLength); + } + } + } + } + /// /// Writes the chunk end to the stream. /// @@ -935,48 +1047,6 @@ namespace SixLabors.ImageSharp.Formats.Png stream.Write(this.buffer, 0, 4); // write the crc } - /// - /// Packs the given 8 bit array into and array of depths. - /// - /// The source span in 8 bits. - /// The resultant span in . - /// The bit depth. - /// The scaling factor. - private void ScaleDownFrom8BitArray(ReadOnlySpan source, Span result, int bits, float scale = 1) - { - ref byte sourceRef = ref MemoryMarshal.GetReference(source); - ref byte resultRef = ref MemoryMarshal.GetReference(result); - - int shift = 8 - bits; - byte mask = (byte)(0xFF >> shift); - byte shift0 = (byte)shift; - int v = 0; - int resultOffset = 0; - - for (int i = 0; i < source.Length; i++) - { - int value = ((int)MathF.Round(Unsafe.Add(ref sourceRef, i) / scale)) & mask; - v |= value << shift; - - if (shift == 0) - { - shift = shift0; - Unsafe.Add(ref resultRef, resultOffset) = (byte)v; - resultOffset++; - v = 0; - } - else - { - shift -= bits; - } - } - - if (shift != shift0) - { - Unsafe.Add(ref resultRef, resultOffset) = (byte)v; - } - } - /// /// Calculates the scanline length. /// diff --git a/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs new file mode 100644 index 0000000000..78cd5d8742 --- /dev/null +++ b/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs @@ -0,0 +1,57 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace SixLabors.ImageSharp.Formats.Png +{ + /// + /// The helper methods for class. + /// + internal static class PngEncoderHelpers + { + /// + /// Packs the given 8 bit array into and array of depths. + /// + /// The source span in 8 bits. + /// The resultant span in . + /// The bit depth. + /// The scaling factor. + public static void ScaleDownFrom8BitArray(ReadOnlySpan source, Span result, int bits, float scale = 1) + { + ref byte sourceRef = ref MemoryMarshal.GetReference(source); + ref byte resultRef = ref MemoryMarshal.GetReference(result); + + int shift = 8 - bits; + byte mask = (byte)(0xFF >> shift); + byte shift0 = (byte)shift; + int v = 0; + int resultOffset = 0; + + for (int i = 0; i < source.Length; i++) + { + int value = ((int)MathF.Round(Unsafe.Add(ref sourceRef, i) / scale)) & mask; + v |= value << shift; + + if (shift == 0) + { + shift = shift0; + Unsafe.Add(ref resultRef, resultOffset) = (byte)v; + resultOffset++; + v = 0; + } + else + { + shift -= bits; + } + } + + if (shift != shift0) + { + Unsafe.Add(ref resultRef, resultOffset) = (byte)v; + } + } + } +} diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptions.cs b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs new file mode 100644 index 0000000000..dd6c66cb7c --- /dev/null +++ b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs @@ -0,0 +1,82 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Processing.Processors.Quantization; + +namespace SixLabors.ImageSharp.Formats.Png +{ + /// + /// The options structure for the . + /// + internal class PngEncoderOptions : IPngEncoderOptions + { + /// + /// Initializes a new instance of the class. + /// + /// The source. + public PngEncoderOptions(IPngEncoderOptions source) + { + this.BitDepth = source.BitDepth; + this.ColorType = source.ColorType; + + // Specification recommends default filter method None for paletted images and Paeth for others. + this.FilterMethod = source.FilterMethod ?? (source.ColorType == PngColorType.Palette + ? PngFilterMethod.None + : PngFilterMethod.Paeth); + this.CompressionLevel = source.CompressionLevel; + this.TextCompressionThreshold = source.TextCompressionThreshold; + this.Gamma = source.Gamma; + this.Quantizer = source.Quantizer; + this.Threshold = source.Threshold; + this.InterlaceMethod = source.InterlaceMethod; + } + + /// + /// Gets or sets the number of bits per sample or per palette index (not per pixel). + /// Not all values are allowed for all values. + /// + public PngBitDepth? BitDepth { get; set; } + + /// + /// Gets or sets the color type. + /// + public PngColorType? ColorType { get; set; } + + /// + /// Gets the filter method. + /// + public PngFilterMethod? FilterMethod { get; } + + /// + /// Gets the compression level 1-9. + /// Defaults to 6. + /// + public int CompressionLevel { get; } + + /// + public int TextCompressionThreshold { get; } + + /// + /// Gets or sets the gamma value, that will be written the image. + /// + /// + /// The gamma value of the image. + /// + public float? Gamma { get; set; } + + /// + /// Gets or sets the quantizer for reducing the color count. + /// + public IQuantizer Quantizer { get; set; } + + /// + /// Gets the transparency threshold. + /// + public byte Threshold { get; } + + /// + /// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image. + /// + public PngInterlaceMode? InterlaceMethod { get; set; } + } +} diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs new file mode 100644 index 0000000000..e3f2948864 --- /dev/null +++ b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs @@ -0,0 +1,152 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors.Quantization; + +namespace SixLabors.ImageSharp.Formats.Png +{ + /// + /// The helper methods for the PNG encoder options. + /// + internal static class PngEncoderOptionsHelpers + { + /// + /// Adjusts the options. + /// + /// The options. + /// The PNG metadata. + /// if set to true [use16 bit]. + /// The bytes per pixel. + public static void AdjustOptions( + PngEncoderOptions options, + PngMetadata pngMetadata, + out bool use16Bit, + out int bytesPerPixel) + { + // Always take the encoder options over the metadata values. + options.Gamma = options.Gamma ?? pngMetadata.Gamma; + options.ColorType = options.ColorType ?? pngMetadata.ColorType; + options.BitDepth = options.BitDepth ?? pngMetadata.BitDepth; + options.InterlaceMethod = options.InterlaceMethod ?? pngMetadata.InterlaceMethod; + + use16Bit = options.BitDepth == PngBitDepth.Bit16; + bytesPerPixel = CalculateBytesPerPixel(options.ColorType, use16Bit); + + // Ensure we are not allowing impossible combinations. + if (!PngConstants.ColorTypes.ContainsKey(options.ColorType.Value)) + { + throw new NotSupportedException("Color type is not supported or not valid."); + } + } + + /// + /// Creates the quantized frame. + /// + /// The type of the pixel. + /// The options. + /// The image. + public static IQuantizedFrame CreateQuantizedFrame( + PngEncoderOptions options, + Image image) + where TPixel : struct, IPixel + { + if (options.ColorType != PngColorType.Palette) + { + return null; + } + + byte bits = (byte)options.BitDepth; + if (Array.IndexOf(PngConstants.ColorTypes[options.ColorType.Value], bits) == -1) + { + throw new NotSupportedException("Bit depth is not supported or not valid."); + } + + // Use the metadata to determine what quantization depth to use if no quantizer has been set. + if (options.Quantizer is null) + { + options.Quantizer = new WuQuantizer(ImageMaths.GetColorCountForBitDepth(bits)); + } + + // Create quantized frame returning the palette and set the bit depth. + using (IFrameQuantizer frameQuantizer = options.Quantizer.CreateFrameQuantizer(image.GetConfiguration())) + { + return frameQuantizer.QuantizeFrame(image.Frames.RootFrame); + } + } + + /// + /// Calculates the bit depth value. + /// + /// The type of the pixel. + /// The options. + /// The image. + /// The quantized frame. + public static byte CalculateBitDepth( + PngEncoderOptions options, + Image image, + IQuantizedFrame quantizedFrame) + where TPixel : struct, IPixel + { + byte bitDepth; + if (options.ColorType == PngColorType.Palette) + { + byte quantizedBits = (byte)ImageMaths.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length).Clamp(1, 8); + byte bits = Math.Max((byte)options.BitDepth, quantizedBits); + + // Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk + // We check again for the bit depth as the bit depth of the color palette from a given quantizer might not + // be within the acceptable range. + if (bits == 3) + { + bits = 4; + } + else if (bits >= 5 && bits <= 7) + { + bits = 8; + } + + bitDepth = bits; + } + else + { + bitDepth = (byte)options.BitDepth; + } + + if (Array.IndexOf(PngConstants.ColorTypes[options.ColorType.Value], bitDepth) == -1) + { + throw new NotSupportedException("Bit depth is not supported or not valid."); + } + + return bitDepth; + } + + /// + /// Calculates the correct number of bytes per pixel for the given color type. + /// + /// Bytes per pixel. + private static int CalculateBytesPerPixel(PngColorType? pngColorType, bool use16Bit) + { + switch (pngColorType) + { + case PngColorType.Grayscale: + return use16Bit ? 2 : 1; + + case PngColorType.GrayscaleWithAlpha: + return use16Bit ? 4 : 2; + + case PngColorType.Palette: + return 1; + + case PngColorType.Rgb: + return use16Bit ? 6 : 3; + + // PngColorType.RgbWithAlpha + default: + return use16Bit ? 8 : 4; + } + } + } +} diff --git a/src/ImageSharp/Formats/Png/PngInterlaceMode.cs b/src/ImageSharp/Formats/Png/PngInterlaceMode.cs index 10ebcc7bbe..e8c2db1475 100644 --- a/src/ImageSharp/Formats/Png/PngInterlaceMode.cs +++ b/src/ImageSharp/Formats/Png/PngInterlaceMode.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// Provides enumeration of available PNG interlace modes. /// - internal enum PngInterlaceMode : byte + public enum PngInterlaceMode : byte { /// /// Non interlaced diff --git a/src/ImageSharp/Formats/Png/PngMetaData.cs b/src/ImageSharp/Formats/Png/PngMetaData.cs index dd951763f7..ec8779a59a 100644 --- a/src/ImageSharp/Formats/Png/PngMetaData.cs +++ b/src/ImageSharp/Formats/Png/PngMetaData.cs @@ -1,6 +1,7 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.Collections.Generic; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Png @@ -26,11 +27,17 @@ namespace SixLabors.ImageSharp.Formats.Png this.BitDepth = other.BitDepth; this.ColorType = other.ColorType; this.Gamma = other.Gamma; - this.HasTrans = other.HasTrans; + this.InterlaceMethod = other.InterlaceMethod; + this.HasTransparency = other.HasTransparency; this.TransparentGray8 = other.TransparentGray8; this.TransparentGray16 = other.TransparentGray16; this.TransparentRgb24 = other.TransparentRgb24; this.TransparentRgb48 = other.TransparentRgb48; + + for (int i = 0; i < other.TextData.Count; i++) + { + this.TextData.Add(other.TextData[i]); + } } /// @@ -44,37 +51,74 @@ namespace SixLabors.ImageSharp.Formats.Png /// public PngColorType ColorType { get; set; } = PngColorType.RgbWithAlpha; + /// + /// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image. + /// + public PngInterlaceMode? InterlaceMethod { get; set; } = PngInterlaceMode.None; + /// /// Gets or sets the gamma value for the image. /// public float Gamma { get; set; } /// - /// Gets or sets the Rgb 24 transparent color. This represents any color in an 8 bit Rgb24 encoded png that should be transparent + /// Gets or sets the Rgb24 transparent color. + /// This represents any color in an 8 bit Rgb24 encoded png that should be transparent. /// public Rgb24? TransparentRgb24 { get; set; } /// - /// Gets or sets the Rgb 48 transparent color. This represents any color in a 16 bit Rgb24 encoded png that should be transparent + /// Gets or sets the Rgb48 transparent color. + /// This represents any color in a 16 bit Rgb24 encoded png that should be transparent. /// public Rgb48? TransparentRgb48 { get; set; } /// - /// Gets or sets the 8 bit grayscale transparent color. This represents any color in an 8 bit grayscale encoded png that should be transparent + /// Gets or sets the 8 bit grayscale transparent color. + /// This represents any color in an 8 bit grayscale encoded png that should be transparent. /// public Gray8? TransparentGray8 { get; set; } /// - /// Gets or sets the 16 bit grayscale transparent color. This represents any color in a 16 bit grayscale encoded png that should be transparent + /// Gets or sets the 16 bit grayscale transparent color. + /// This represents any color in a 16 bit grayscale encoded png that should be transparent. /// public Gray16? TransparentGray16 { get; set; } /// - /// Gets or sets a value indicating whether the image has transparency chunk and markers were decoded + /// Gets or sets a value indicating whether the image contains a transparency chunk and markers were decoded. + /// + public bool HasTransparency { get; set; } + + /// + /// Gets or sets the collection of text data stored within the iTXt, tEXt, and zTXt chunks. + /// Used for conveying textual information associated with the image. + /// + public IList TextData { get; set; } = new List(); + + /// + /// Gets the list of png text properties for storing meta information about this image. /// - public bool HasTrans { get; set; } + public IList PngTextProperties { get; } = new List(); /// public IDeepCloneable DeepClone() => new PngMetadata(this); + + internal bool TryGetPngTextProperty(string keyword, out PngTextData result) + { + for (int i = 0; i < this.TextData.Count; i++) + { + if (this.TextData[i].Keyword == keyword) + { + result = this.TextData[i]; + + return true; + } + } + + result = default; + + return false; + } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/PngTextData.cs b/src/ImageSharp/Formats/Png/PngTextData.cs new file mode 100644 index 0000000000..21171487ea --- /dev/null +++ b/src/ImageSharp/Formats/Png/PngTextData.cs @@ -0,0 +1,143 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; + +namespace SixLabors.ImageSharp.Formats.Png +{ + /// + /// Stores text data contained in the iTXt, tEXt, and zTXt chunks. + /// Used for conveying textual information associated with the image, like the name of the author, + /// the copyright information, the date, where the image was created, or some other information. + /// + public readonly struct PngTextData : IEquatable + { + /// + /// Initializes a new instance of the struct. + /// + /// The keyword of the property. + /// The value of the property. + /// An optional language tag. + /// A optional translated keyword. + public PngTextData(string keyword, string value, string languageTag, string translatedKeyword) + { + Guard.NotNullOrWhiteSpace(keyword, nameof(keyword)); + + // No leading or trailing whitespace is allowed in keywords. + this.Keyword = keyword.Trim(); + this.Value = value; + this.LanguageTag = languageTag; + this.TranslatedKeyword = translatedKeyword; + } + + /// + /// Gets the keyword of this which indicates + /// the type of information represented by the text string as described in https://www.w3.org/TR/PNG/#11keywords. + /// + /// + /// Typical properties are the author, copyright information or other meta information. + /// + public string Keyword { get; } + + /// + /// Gets the value of this . + /// + public string Value { get; } + + /// + /// Gets an optional language tag defined in https://www.w3.org/TR/PNG/#2-RFC-3066 indicates the human language used by the translated keyword and the text. + /// If the first word is two or three letters long, it is an ISO language code https://www.w3.org/TR/PNG/#2-ISO-639. + /// + /// + /// Examples: cn, en-uk, no-bok, x-klingon, x-KlInGoN. + /// + public string LanguageTag { get; } + + /// + /// Gets an optional translated keyword, should contain a translation of the keyword into the language indicated by the language tag. + /// + public string TranslatedKeyword { get; } + + /// + /// Compares two objects. The result specifies whether the values + /// of the properties of the two objects are equal. + /// + /// + /// The on the left side of the operand. + /// + /// + /// The on the right side of the operand. + /// + /// + /// True if the current left is equal to the parameter; otherwise, false. + /// + public static bool operator ==(PngTextData left, PngTextData right) + { + return left.Equals(right); + } + + /// + /// Compares two objects. The result specifies whether the values + /// of the properties of the two objects are unequal. + /// + /// + /// The on the left side of the operand. + /// + /// + /// The on the right side of the operand. + /// + /// + /// True if the current left is unequal to the parameter; otherwise, false. + /// + public static bool operator !=(PngTextData left, PngTextData right) + { + return !(left == right); + } + + /// + /// Indicates whether this instance and a specified object are equal. + /// + /// + /// The object to compare with the current instance. + /// + /// + /// true if and this instance are the same type and represent the + /// same value; otherwise, false. + /// + public override bool Equals(object obj) + { + return obj is PngTextData other && this.Equals(other); + } + + /// + /// Returns the hash code for this instance. + /// + /// + /// A 32-bit signed integer that is the hash code for this instance. + /// + public override int GetHashCode() => HashCode.Combine(this.Keyword, this.Value, this.LanguageTag, this.TranslatedKeyword); + + /// + /// Returns the fully qualified type name of this instance. + /// + /// + /// A containing a fully qualified type name. + /// + public override string ToString() => $"PngTextData [ Name={this.Keyword}, Value={this.Value} ]"; + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// + /// True if the current object is equal to the parameter; otherwise, false. + /// + /// An object to compare with this object. + public bool Equals(PngTextData other) + { + return this.Keyword.Equals(other.Keyword) + && this.Value.Equals(other.Value) + && this.LanguageTag.Equals(other.LanguageTag) + && this.TranslatedKeyword.Equals(other.TranslatedKeyword); + } + } +} diff --git a/src/ImageSharp/IO/IFileSystem.cs b/src/ImageSharp/IO/IFileSystem.cs index 593c760fcf..9dc97afb60 100644 --- a/src/ImageSharp/IO/IFileSystem.cs +++ b/src/ImageSharp/IO/IFileSystem.cs @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.IO Stream OpenRead(string path); /// - /// Creates or opens a file and returns it as a writeable stream as defined by the path. + /// Creates or opens a file and returns it as a writable stream as defined by the path. /// /// Path to the file to open. /// A stream representing the file to open. diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs index 25dc5a1e0e..465139b2e5 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image.FromBytes.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp /// The configuration. /// The byte array containing encoded image data to read the header from. /// The mime type or null if none found. - public static unsafe IImageFormat DetectFormat(Configuration config, ReadOnlySpan data) + public static IImageFormat DetectFormat(Configuration config, ReadOnlySpan data) { int maxHeaderSize = config.MaxHeaderSize; if (maxHeaderSize <= 0) @@ -351,7 +351,7 @@ namespace SixLabors.ImageSharp /// The configuration options. /// The byte span containing image data. /// A new . - public static unsafe Image Load(Configuration config, ReadOnlySpan data) => Load(config, data, out _); + public static Image Load(Configuration config, ReadOnlySpan data) => Load(config, data, out _); /// /// Load a new instance of from the given encoded byte span. @@ -395,4 +395,4 @@ namespace SixLabors.ImageSharp } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs index 86fef715d1..57f60f2e75 100644 --- a/src/ImageSharp/Image.cs +++ b/src/ImageSharp/Image.cs @@ -80,8 +80,22 @@ namespace SixLabors.ImageSharp /// Configuration IConfigurable.Configuration => this.Configuration; + /// + /// Gets a value indicating whether the image instance is disposed. + /// + public bool IsDisposed { get; private set; } + /// - public abstract void Dispose(); + public void Dispose() + { + if (this.IsDisposed) + { + return; + } + + this.IsDisposed = true; + this.DisposeImpl(); + } /// /// Saves the image to the given stream using the given image encoder. @@ -93,6 +107,7 @@ namespace SixLabors.ImageSharp { Guard.NotNull(stream, nameof(stream)); Guard.NotNull(encoder, nameof(encoder)); + this.EnsureNotDisposed(); EncodeVisitor visitor = new EncodeVisitor(encoder, stream); this.AcceptVisitor(visitor); @@ -128,6 +143,11 @@ namespace SixLabors.ImageSharp /// The . protected void UpdateSize(Size size) => this.size = size; + /// + /// Implements the Dispose logic. + /// + protected abstract void DisposeImpl(); + private class EncodeVisitor : IImageVisitor { private readonly IImageEncoder encoder; diff --git a/src/ImageSharp/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs index ec4c364d83..6ea2b234c5 100644 --- a/src/ImageSharp/ImageExtensions.cs +++ b/src/ImageSharp/ImageExtensions.cs @@ -119,5 +119,16 @@ namespace SixLabors.ImageSharp return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(stream.ToArray())}"; } } + + /// + /// Throws if the image is disposed. + /// + internal static void EnsureNotDisposed(this Image image) + { + if (image.IsDisposed) + { + throw new ObjectDisposedException(nameof(image), "Trying to execute an operation on a disposed image."); + } + } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/ImageFrameCollection{TPixel}.cs b/src/ImageSharp/ImageFrameCollection{TPixel}.cs index ffd7225bd4..893a7a4a80 100644 --- a/src/ImageSharp/ImageFrameCollection{TPixel}.cs +++ b/src/ImageSharp/ImageFrameCollection{TPixel}.cs @@ -347,7 +347,7 @@ namespace SixLabors.ImageSharp private ImageFrame CopyNonCompatibleFrame(ImageFrame source) { - ImageFrame result = new ImageFrame( + var result = new ImageFrame( this.parent.GetConfiguration(), source.Size(), source.Metadata.DeepClone()); diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 982f8d8f29..5c9ff489e1 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -1,10 +1,10 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Threading.Tasks; + using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Metadata; @@ -91,7 +91,7 @@ namespace SixLabors.ImageSharp Guard.MustBeGreaterThan(height, 0, nameof(height)); this.PixelBuffer = this.MemoryAllocator.Allocate2D(width, height); - this.Clear(configuration.GetParallelOptions(), backgroundColor); + this.Clear(backgroundColor); } /// @@ -267,7 +267,7 @@ namespace SixLabors.ImageSharp ParallelHelper.IterateRows( this.Bounds(), configuration, - (rows) => + rows => { for (int y = rows.Min; y < rows.Max; y++) { @@ -283,9 +283,8 @@ namespace SixLabors.ImageSharp /// /// Clears the bitmap. /// - /// The parallel options. /// The value to initialize the bitmap with. - internal void Clear(ParallelOptions parallelOptions, TPixel value) + internal void Clear(TPixel value) { Span span = this.GetPixelSpan(); diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 3b02114349..8dff3b9779 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -14,11 +14,9 @@ true true - SixLabors.ImageSharp SixLabors.ImageSharp Image Resize Crop Gif Jpg Jpeg Bitmap Png Core SixLabors.ImageSharp - netcoreapp2.1;netstandard1.3;netstandard2.0;net472 diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 5d0364dd87..a7ea58652c 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -162,6 +162,8 @@ namespace SixLabors.ImageSharp /// Returns a new with all the same pixel data as the original. public Image Clone(Configuration configuration) { + this.EnsureNotDisposed(); + IEnumerable> clonedFrames = this.Frames.Select, ImageFrame>(x => x.Clone(configuration)); return new Image(configuration, this.Metadata.DeepClone(), clonedFrames); @@ -175,17 +177,21 @@ namespace SixLabors.ImageSharp /// The . public override Image CloneAs(Configuration configuration) { + this.EnsureNotDisposed(); + IEnumerable> clonedFrames = this.Frames.Select, ImageFrame>(x => x.CloneAs(configuration)); return new Image(configuration, this.Metadata.DeepClone(), clonedFrames); } /// - public override void Dispose() => this.Frames.Dispose(); + protected override void DisposeImpl() => this.Frames.Dispose(); /// internal override void AcceptVisitor(IImageVisitor visitor) { + this.EnsureNotDisposed(); + visitor.Visit(this); } diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs index 61fcb99db2..59247aa2d2 100644 --- a/src/ImageSharp/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Buffers; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -42,7 +41,7 @@ namespace SixLabors.ImageSharp.Memory fixed (byte* ptr = span) { - byte* basePtr = (byte*)ptr; + byte* basePtr = ptr; for (int y = 0; y < buffer.Height; y++) { byte* sPtr = basePtr + sOffset; @@ -185,4 +184,4 @@ namespace SixLabors.ImageSharp.Memory } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index 41a560cdb6..82a98bfc63 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -61,13 +61,31 @@ namespace SixLabors.ImageSharp.Memory [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ImageSharp.DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); - ImageSharp.DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); + DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); + DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); + Span span = this.Span; return ref span[(this.Width * y) + x]; } } + /// + /// Creates a new instance that maps to a target rows interval from the current instance. + /// + /// The target vertical offset for the rows interval to retrieve. + /// The desired number of rows to extract. + /// The new instance with the requested rows interval. + public Buffer2D Slice(int y, int h) + { + DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y)); + DebugGuard.MustBeGreaterThan(h, 0, nameof(h)); + DebugGuard.MustBeLessThanOrEqualTo(y + h, this.Height, nameof(h)); + + Memory slice = this.Memory.Slice(y * this.Width, h * this.Width); + var memory = new MemorySource(slice); + return new Buffer2D(memory, this.Width, h); + } + /// /// Disposes the instance /// @@ -98,4 +116,4 @@ namespace SixLabors.ImageSharp.Memory a.Height = bSize.Height; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Memory/MemoryOwnerExtensions.cs b/src/ImageSharp/Memory/MemoryOwnerExtensions.cs index 9b68f52c4d..d82e3aaee7 100644 --- a/src/ImageSharp/Memory/MemoryOwnerExtensions.cs +++ b/src/ImageSharp/Memory/MemoryOwnerExtensions.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Memory => buffer.GetSpan().Length; /// - /// Gets a to an offseted position inside the buffer. + /// Gets a to an offsetted position inside the buffer. /// /// The buffer /// The start @@ -60,4 +60,4 @@ namespace SixLabors.ImageSharp.Memory where T : struct => ref MemoryMarshal.GetReference(buffer.GetSpan()); } -} \ No newline at end of file +} diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs index b9efca4fee..b3751bfbdc 100644 --- a/src/ImageSharp/MetaData/ImageMetaData.cs +++ b/src/ImageSharp/MetaData/ImageMetaData.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; @@ -63,11 +63,6 @@ namespace SixLabors.ImageSharp.Metadata this.formatMetadata.Add(meta.Key, meta.Value.DeepClone()); } - foreach (ImageProperty property in other.Properties) - { - this.Properties.Add(property); - } - this.ExifProfile = other.ExifProfile?.DeepClone(); this.IccProfile = other.IccProfile?.DeepClone(); } @@ -127,11 +122,6 @@ namespace SixLabors.ImageSharp.Metadata /// public IccProfile IccProfile { get; set; } - /// - /// Gets the list of properties for storing meta information about this image. - /// - public IList Properties { get; } = new List(); - /// /// Gets the metadata value associated with the specified key. /// @@ -156,29 +146,6 @@ namespace SixLabors.ImageSharp.Metadata /// public ImageMetadata DeepClone() => new ImageMetadata(this); - /// - /// Looks up a property with the provided name. - /// - /// The name of the property to lookup. - /// The property, if found, with the provided name. - /// Whether the property was found. - internal bool TryGetProperty(string name, out ImageProperty result) - { - foreach (ImageProperty property in this.Properties) - { - if (property.Name == name) - { - result = property; - - return true; - } - } - - result = default; - - return false; - } - /// /// Synchronizes the profiles with the current metadata. /// diff --git a/src/ImageSharp/MetaData/ImageProperty.cs b/src/ImageSharp/MetaData/ImageProperty.cs deleted file mode 100644 index 905e42dab1..0000000000 --- a/src/ImageSharp/MetaData/ImageProperty.cs +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; - -namespace SixLabors.ImageSharp.Metadata -{ - /// - /// Stores meta information about a image, like the name of the author, - /// the copyright information, the date, where the image was created - /// or some other information. - /// - public readonly struct ImageProperty : IEquatable - { - /// - /// Initializes a new instance of the struct. - /// - /// The name of the property. - /// The value of the property. - public ImageProperty(string name, string value) - { - Guard.NotNullOrWhiteSpace(name, nameof(name)); - - this.Name = name; - this.Value = value; - } - - /// - /// Gets the name of this indicating which kind of - /// information this property stores. - /// - /// - /// Typical properties are the author, copyright - /// information or other meta information. - /// - public string Name { get; } - - /// - /// Gets the value of this . - /// - public string Value { get; } - - /// - /// Compares two objects. The result specifies whether the values - /// of the or properties of the two - /// objects are equal. - /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the current left is equal to the parameter; otherwise, false. - /// - public static bool operator ==(ImageProperty left, ImageProperty right) - { - return left.Equals(right); - } - - /// - /// Compares two objects. The result specifies whether the values - /// of the or properties of the two - /// objects are unequal. - /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the current left is unequal to the parameter; otherwise, false. - /// - public static bool operator !=(ImageProperty left, ImageProperty right) - { - return !(left == right); - } - - /// - /// Indicates whether this instance and a specified object are equal. - /// - /// - /// The object to compare with the current instance. - /// - /// - /// true if and this instance are the same type and represent the - /// same value; otherwise, false. - /// - public override bool Equals(object obj) - { - return obj is ImageProperty other && this.Equals(other); - } - - /// - /// Returns the hash code for this instance. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - public override int GetHashCode() => HashCode.Combine(this.Name, this.Value); - - /// - /// Returns the fully qualified type name of this instance. - /// - /// - /// A containing a fully qualified type name. - /// - public override string ToString() => $"ImageProperty [ Name={this.Name}, Value={this.Value} ]"; - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// - /// True if the current object is equal to the parameter; otherwise, false. - /// - /// An object to compare with this object. - public bool Equals(ImageProperty other) - { - return this.Name.Equals(other.Name) && Equals(this.Value, other.Value); - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index e40e6c26c2..77c1cf2eab 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -419,16 +419,6 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif : default; } - private string ReadString(int length) - { - if (this.TryReadSpan(length, out ReadOnlySpan span) && span.Length != 0) - { - return this.ConvertToString(span); - } - - return null; - } - private void GetThumbnail(uint offset) { var values = new List(); diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs index 93fe7fbbee..67c1b2b65e 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -53,12 +53,12 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif if (this.exifIndexes.Count > 0) { - exifIndex = (int)this.GetIndex(this.ifdIndexes, ExifTag.SubIFDOffset); + exifIndex = this.GetIndex(this.ifdIndexes, ExifTag.SubIFDOffset); } if (this.gpsIndexes.Count > 0) { - gpsIndex = (int)this.GetIndex(this.ifdIndexes, ExifTag.GPSIFDOffset); + gpsIndex = this.GetIndex(this.ifdIndexes, ExifTag.GPSIFDOffset); } uint ifdLength = 2 + this.GetLength(this.ifdIndexes) + 4; @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif length += 4 + 2; - byte[] result = new byte[length]; + var result = new byte[length]; int i = 0; @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif i = this.WriteData(startIndex, this.gpsIndexes, result, i); } - WriteUInt16((ushort)0, result, i); + WriteUInt16(0, result, i); return result; } @@ -373,4 +373,4 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif return this.WriteValue(value.DataType, value.Value, destination, offset); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs index 111911080e..58ca46d816 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -18,13 +18,13 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { ushort segmentCount = this.ReadUInt16(); this.AddIndex(2); // 2 bytes reserved - float[] breakPoints = new float[segmentCount - 1]; + var breakPoints = new float[segmentCount - 1]; for (int i = 0; i < breakPoints.Length; i++) { breakPoints[i] = this.ReadSingle(); } - IccCurveSegment[] segments = new IccCurveSegment[segmentCount]; + var segments = new IccCurveSegment[segmentCount]; for (int i = 0; i < segmentCount; i++) { segments[i] = this.ReadCurveSegment(); @@ -41,19 +41,19 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public IccResponseCurve ReadResponseCurve(int channelCount) { var type = (IccCurveMeasurementEncodings)this.ReadUInt32(); - uint[] measurement = new uint[channelCount]; + var measurement = new uint[channelCount]; for (int i = 0; i < channelCount; i++) { measurement[i] = this.ReadUInt32(); } - Vector3[] xyzValues = new Vector3[channelCount]; + var xyzValues = new Vector3[channelCount]; for (int i = 0; i < channelCount; i++) { xyzValues[i] = this.ReadXyzNumber(); } - IccResponseNumber[][] response = new IccResponseNumber[channelCount][]; + var response = new IccResponseNumber[channelCount][]; for (int i = 0; i < channelCount; i++) { response[i] = new IccResponseNumber[measurement[i]]; @@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public IccSampledCurveElement ReadSampledCurveElement() { uint count = this.ReadUInt32(); - float[] entries = new float[count]; + var entries = new float[count]; for (int i = 0; i < count; i++) { entries[i] = this.ReadSingle(); diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs index 5262e3ee95..0aa3c31e08 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc /// The read LUT public IccLut ReadLut16(int count) { - ushort[] values = new ushort[count]; + var values = new ushort[count]; for (int i = 0; i < count; i++) { values[i] = this.ReadUInt16(); @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public IccClut ReadClut(int inChannelCount, int outChannelCount, bool isFloat) { // Grid-points are always 16 bytes long but only 0-inChCount are used - byte[] gridPointCount = new byte[inChannelCount]; + var gridPointCount = new byte[inChannelCount]; Buffer.BlockCopy(this.data, this.AddIndex(16), gridPointCount, 0, inChannelCount); if (!isFloat) @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc const float Max = byte.MaxValue; - float[][] values = new float[length][]; + var values = new float[length][]; for (int i = 0; i < length; i++) { values[i] = new float[outChannelCount]; @@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc const float Max = ushort.MaxValue; - float[][] values = new float[length][]; + var values = new float[length][]; for (int i = 0; i < length; i++) { values[i] = new float[outChannelCount]; @@ -154,7 +154,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc length /= inChCount; - float[][] values = new float[length][]; + var values = new float[length][]; for (int i = 0; i < length; i++) { values[i] = new float[outChCount]; @@ -168,4 +168,4 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc return new IccClut(values, gridPointCount, IccClutDataType.Float); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Matrix.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Matrix.cs index 3157b9ef38..ecc33dd776 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Matrix.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Matrix.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Metadata.Profiles.Icc @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc /// The read matrix public float[,] ReadMatrix(int xCount, int yCount, bool isSingle) { - float[,] matrix = new float[xCount, yCount]; + var matrix = new float[xCount, yCount]; for (int y = 0; y < yCount; y++) { for (int x = 0; x < xCount; x++) @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc /// The read matrix public float[] ReadMatrix(int yCount, bool isSingle) { - float[] matrix = new float[yCount]; + var matrix = new float[yCount]; for (int i = 0; i < yCount; i++) { if (isSingle) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs index 4253058288..b854247da3 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.MultiProcessElement.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Metadata.Profiles.Icc @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc /// The read public IccCurveSetProcessElement ReadCurveSetProcessElement(int inChannelCount, int outChannelCount) { - IccOneDimensionalCurve[] curves = new IccOneDimensionalCurve[inChannelCount]; + var curves = new IccOneDimensionalCurve[inChannelCount]; for (int i = 0; i < inChannelCount; i++) { curves[i] = this.ReadOneDimensionalCurve(); diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs index aacbbcc1dd..b5326225cf 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { string name = this.ReadAsciiString(32); ushort[] pcsCoord = { this.ReadUInt16(), this.ReadUInt16(), this.ReadUInt16() }; - ushort[] deviceCoord = new ushort[deviceCoordCount]; + var deviceCoord = new ushort[deviceCoordCount]; for (int i = 0; i < deviceCoordCount; i++) { diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs index 2cbf798ec2..3f016444bd 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -165,7 +165,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc /// The read bytes public byte[] ReadBytes(int count) { - byte[] bytes = new byte[count]; + var bytes = new byte[count]; Buffer.BlockCopy(this.data, this.AddIndex(count), bytes, 0, count); return bytes; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs index 3f330ef729..a0ee1d5e50 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -153,12 +153,10 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc else { // The type is not know, so the values need be read - double[][] values = new double[channelCount][]; + var values = new double[channelCount][]; for (int i = 0; i < channelCount; i++) { - values[i] = new double[2]; - values[i][0] = this.ReadUFix16(); - values[i][1] = this.ReadUFix16(); + values[i] = new double[] { this.ReadUFix16(), this.ReadUFix16() }; } return new IccChromaticityTagDataEntry(values); @@ -210,7 +208,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc return new IccCurveTagDataEntry(this.ReadUFix8()); } - float[] cdata = new float[pointCount]; + var cdata = new float[pointCount]; for (int i = 0; i < pointCount; i++) { cdata[i] = this.ReadUInt16() / 65535f; @@ -266,7 +264,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc // Input LUT var inValues = new IccLut[inChCount]; - byte[] gridPointCount = new byte[inChCount]; + var gridPointCount = new byte[inChCount]; for (int i = 0; i < inChCount; i++) { inValues[i] = this.ReadLut16(inTableCount); @@ -301,7 +299,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc // Input LUT var inValues = new IccLut[inChCount]; - byte[] gridPointCount = new byte[inChCount]; + var gridPointCount = new byte[inChCount]; for (int i = 0; i < inChCount; i++) { inValues[i] = this.ReadLut8(); @@ -466,8 +464,8 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc var text = new IccLocalizedString[recordCount]; var culture = new CultureInfo[recordCount]; - uint[] length = new uint[recordCount]; - uint[] offset = new uint[recordCount]; + var length = new uint[recordCount]; + var offset = new uint[recordCount]; for (int i = 0; i < recordCount; i++) { @@ -526,9 +524,8 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { int start = this.currentIndex - 8; - // TODO: Why are we storing variable - ushort inChannelCount = this.ReadUInt16(); - ushort outChannelCount = this.ReadUInt16(); + this.ReadUInt16(); + this.ReadUInt16(); uint elementCount = this.ReadUInt32(); var positionTable = new IccPositionNumber[elementCount]; @@ -630,7 +627,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc ushort channelCount = this.ReadUInt16(); ushort measurementCount = this.ReadUInt16(); - uint[] offset = new uint[measurementCount]; + var offset = new uint[measurementCount]; for (int i = 0; i < measurementCount; i++) { offset[i] = this.ReadUInt32(); @@ -654,7 +651,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public IccFix16ArrayTagDataEntry ReadFix16ArrayTagDataEntry(uint size) { uint count = (size - 8) / 4; - float[] arrayData = new float[count]; + var arrayData = new float[count]; for (int i = 0; i < count; i++) { arrayData[i] = this.ReadFix16() / 256f; @@ -690,7 +687,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public IccUFix16ArrayTagDataEntry ReadUFix16ArrayTagDataEntry(uint size) { uint count = (size - 8) / 4; - float[] arrayData = new float[count]; + var arrayData = new float[count]; for (int i = 0; i < count; i++) { arrayData[i] = this.ReadUFix16(); @@ -707,7 +704,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public IccUInt16ArrayTagDataEntry ReadUInt16ArrayTagDataEntry(uint size) { uint count = (size - 8) / 2; - ushort[] arrayData = new ushort[count]; + var arrayData = new ushort[count]; for (int i = 0; i < count; i++) { arrayData[i] = this.ReadUInt16(); @@ -724,7 +721,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public IccUInt32ArrayTagDataEntry ReadUInt32ArrayTagDataEntry(uint size) { uint count = (size - 8) / 4; - uint[] arrayData = new uint[count]; + var arrayData = new uint[count]; for (int i = 0; i < count; i++) { arrayData[i] = this.ReadUInt32(); @@ -741,7 +738,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public IccUInt64ArrayTagDataEntry ReadUInt64ArrayTagDataEntry(uint size) { uint count = (size - 8) / 8; - ulong[] arrayData = new ulong[count]; + var arrayData = new ulong[count]; for (int i = 0; i < count; i++) { arrayData[i] = this.ReadUInt64(); @@ -881,14 +878,14 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public IccUcrBgTagDataEntry ReadUcrBgTagDataEntry(uint size) { uint ucrCount = this.ReadUInt32(); - ushort[] ucrCurve = new ushort[ucrCount]; + var ucrCurve = new ushort[ucrCount]; for (int i = 0; i < ucrCurve.Length; i++) { ucrCurve[i] = this.ReadUInt16(); } uint bgCount = this.ReadUInt32(); - ushort[] bgCurve = new ushort[bgCount]; + var bgCurve = new ushort[bgCount]; for (int i = 0; i < bgCurve.Length; i++) { bgCurve[i] = this.ReadUInt16(); @@ -902,4 +899,4 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc return new IccUcrBgTagDataEntry(ucrCurve, bgCurve, description); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs index 7d694bec6e..79542b85fd 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs @@ -1,8 +1,7 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; -using System.Text; namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { @@ -84,16 +83,5 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { return ((value >> (7 - position)) & 1) == 1; } - - /// - /// Gets the bit value at a specified position - /// - /// The value from where the bit will be extracted - /// Position of the bit. Zero based index from left to right. - /// The bit value at specified position - private bool GetBit(ushort value, int position) - { - return ((value >> (15 - position)) & 1) == 1; - } } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs index c48ba8ab7c..4f03ed6101 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -41,7 +41,6 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc public int WriteResponseCurve(IccResponseCurve value) { int count = this.WriteUInt32((uint)value.CurveType); - int channels = value.XyzValues.Length; foreach (IccResponseNumber[] responseArray in value.ResponseArrays) { @@ -118,9 +117,9 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc switch (value.Signature) { case IccCurveSegmentSignature.FormulaCurve: - return count + this.WriteFormulaCurveElement(value as IccFormulaCurveElement); + return count + this.WriteFormulaCurveElement((IccFormulaCurveElement)value); case IccCurveSegmentSignature.SampledCurve: - return count + this.WriteSampledCurveElement(value as IccSampledCurveElement); + return count + this.WriteSampledCurveElement((IccSampledCurveElement)value); default: throw new InvalidIccProfileException($"Invalid CurveSegment type of {value.Signature}"); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs index 824a9bef61..65490f1807 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MultiProcessElement.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Metadata.Profiles.Icc @@ -22,11 +22,11 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc switch (value.Signature) { case IccMultiProcessElementSignature.CurveSet: - return count + this.WriteCurveSetProcessElement(value as IccCurveSetProcessElement); + return count + this.WriteCurveSetProcessElement((IccCurveSetProcessElement)value); case IccMultiProcessElementSignature.Matrix: - return count + this.WriteMatrixProcessElement(value as IccMatrixProcessElement); + return count + this.WriteMatrixProcessElement((IccMatrixProcessElement)value); case IccMultiProcessElementSignature.Clut: - return count + this.WriteClutProcessElement(value as IccClutProcessElement); + return count + this.WriteClutProcessElement((IccClutProcessElement)value); case IccMultiProcessElementSignature.BAcs: case IccMultiProcessElementSignature.EAcs: diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs index e681f84b85..ce80574ad3 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -37,9 +37,6 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc int minor = value.Minor.Clamp(0, 15); int bugfix = value.Patch.Clamp(0, 15); - // TODO: This is not used? - byte mb = (byte)((minor << 4) | bugfix); - int version = (major << 24) | (minor << 20) | (bugfix << 16); return this.WriteInt32(version); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs index f3c632a869..b761f48ba0 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Linq; @@ -37,102 +37,102 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc switch (entry.Signature) { case IccTypeSignature.Chromaticity: - count += this.WriteChromaticityTagDataEntry(entry as IccChromaticityTagDataEntry); + count += this.WriteChromaticityTagDataEntry((IccChromaticityTagDataEntry)entry); break; case IccTypeSignature.ColorantOrder: - count += this.WriteColorantOrderTagDataEntry(entry as IccColorantOrderTagDataEntry); + count += this.WriteColorantOrderTagDataEntry((IccColorantOrderTagDataEntry)entry); break; case IccTypeSignature.ColorantTable: - count += this.WriteColorantTableTagDataEntry(entry as IccColorantTableTagDataEntry); + count += this.WriteColorantTableTagDataEntry((IccColorantTableTagDataEntry)entry); break; case IccTypeSignature.Curve: - count += this.WriteCurveTagDataEntry(entry as IccCurveTagDataEntry); + count += this.WriteCurveTagDataEntry((IccCurveTagDataEntry)entry); break; case IccTypeSignature.Data: - count += this.WriteDataTagDataEntry(entry as IccDataTagDataEntry); + count += this.WriteDataTagDataEntry((IccDataTagDataEntry)entry); break; case IccTypeSignature.DateTime: - count += this.WriteDateTimeTagDataEntry(entry as IccDateTimeTagDataEntry); + count += this.WriteDateTimeTagDataEntry((IccDateTimeTagDataEntry)entry); break; case IccTypeSignature.Lut16: - count += this.WriteLut16TagDataEntry(entry as IccLut16TagDataEntry); + count += this.WriteLut16TagDataEntry((IccLut16TagDataEntry)entry); break; case IccTypeSignature.Lut8: - count += this.WriteLut8TagDataEntry(entry as IccLut8TagDataEntry); + count += this.WriteLut8TagDataEntry((IccLut8TagDataEntry)entry); break; case IccTypeSignature.LutAToB: - count += this.WriteLutAtoBTagDataEntry(entry as IccLutAToBTagDataEntry); + count += this.WriteLutAtoBTagDataEntry((IccLutAToBTagDataEntry)entry); break; case IccTypeSignature.LutBToA: - count += this.WriteLutBtoATagDataEntry(entry as IccLutBToATagDataEntry); + count += this.WriteLutBtoATagDataEntry((IccLutBToATagDataEntry)entry); break; case IccTypeSignature.Measurement: - count += this.WriteMeasurementTagDataEntry(entry as IccMeasurementTagDataEntry); + count += this.WriteMeasurementTagDataEntry((IccMeasurementTagDataEntry)entry); break; case IccTypeSignature.MultiLocalizedUnicode: - count += this.WriteMultiLocalizedUnicodeTagDataEntry(entry as IccMultiLocalizedUnicodeTagDataEntry); + count += this.WriteMultiLocalizedUnicodeTagDataEntry((IccMultiLocalizedUnicodeTagDataEntry)entry); break; case IccTypeSignature.MultiProcessElements: - count += this.WriteMultiProcessElementsTagDataEntry(entry as IccMultiProcessElementsTagDataEntry); + count += this.WriteMultiProcessElementsTagDataEntry((IccMultiProcessElementsTagDataEntry)entry); break; case IccTypeSignature.NamedColor2: - count += this.WriteNamedColor2TagDataEntry(entry as IccNamedColor2TagDataEntry); + count += this.WriteNamedColor2TagDataEntry((IccNamedColor2TagDataEntry)entry); break; case IccTypeSignature.ParametricCurve: - count += this.WriteParametricCurveTagDataEntry(entry as IccParametricCurveTagDataEntry); + count += this.WriteParametricCurveTagDataEntry((IccParametricCurveTagDataEntry)entry); break; case IccTypeSignature.ProfileSequenceDesc: - count += this.WriteProfileSequenceDescTagDataEntry(entry as IccProfileSequenceDescTagDataEntry); + count += this.WriteProfileSequenceDescTagDataEntry((IccProfileSequenceDescTagDataEntry)entry); break; case IccTypeSignature.ProfileSequenceIdentifier: - count += this.WriteProfileSequenceIdentifierTagDataEntry(entry as IccProfileSequenceIdentifierTagDataEntry); + count += this.WriteProfileSequenceIdentifierTagDataEntry((IccProfileSequenceIdentifierTagDataEntry)entry); break; case IccTypeSignature.ResponseCurveSet16: - count += this.WriteResponseCurveSet16TagDataEntry(entry as IccResponseCurveSet16TagDataEntry); + count += this.WriteResponseCurveSet16TagDataEntry((IccResponseCurveSet16TagDataEntry)entry); break; case IccTypeSignature.S15Fixed16Array: - count += this.WriteFix16ArrayTagDataEntry(entry as IccFix16ArrayTagDataEntry); + count += this.WriteFix16ArrayTagDataEntry((IccFix16ArrayTagDataEntry)entry); break; case IccTypeSignature.Signature: - count += this.WriteSignatureTagDataEntry(entry as IccSignatureTagDataEntry); + count += this.WriteSignatureTagDataEntry((IccSignatureTagDataEntry)entry); break; case IccTypeSignature.Text: - count += this.WriteTextTagDataEntry(entry as IccTextTagDataEntry); + count += this.WriteTextTagDataEntry((IccTextTagDataEntry)entry); break; case IccTypeSignature.U16Fixed16Array: - count += this.WriteUFix16ArrayTagDataEntry(entry as IccUFix16ArrayTagDataEntry); + count += this.WriteUFix16ArrayTagDataEntry((IccUFix16ArrayTagDataEntry)entry); break; case IccTypeSignature.UInt16Array: - count += this.WriteUInt16ArrayTagDataEntry(entry as IccUInt16ArrayTagDataEntry); + count += this.WriteUInt16ArrayTagDataEntry((IccUInt16ArrayTagDataEntry)entry); break; case IccTypeSignature.UInt32Array: - count += this.WriteUInt32ArrayTagDataEntry(entry as IccUInt32ArrayTagDataEntry); + count += this.WriteUInt32ArrayTagDataEntry((IccUInt32ArrayTagDataEntry)entry); break; case IccTypeSignature.UInt64Array: - count += this.WriteUInt64ArrayTagDataEntry(entry as IccUInt64ArrayTagDataEntry); + count += this.WriteUInt64ArrayTagDataEntry((IccUInt64ArrayTagDataEntry)entry); break; case IccTypeSignature.UInt8Array: - count += this.WriteUInt8ArrayTagDataEntry(entry as IccUInt8ArrayTagDataEntry); + count += this.WriteUInt8ArrayTagDataEntry((IccUInt8ArrayTagDataEntry)entry); break; case IccTypeSignature.ViewingConditions: - count += this.WriteViewingConditionsTagDataEntry(entry as IccViewingConditionsTagDataEntry); + count += this.WriteViewingConditionsTagDataEntry((IccViewingConditionsTagDataEntry)entry); break; case IccTypeSignature.Xyz: - count += this.WriteXyzTagDataEntry(entry as IccXyzTagDataEntry); + count += this.WriteXyzTagDataEntry((IccXyzTagDataEntry)entry); break; // V2 Types: case IccTypeSignature.TextDescription: - count += this.WriteTextDescriptionTagDataEntry(entry as IccTextDescriptionTagDataEntry); + count += this.WriteTextDescriptionTagDataEntry((IccTextDescriptionTagDataEntry)entry); break; case IccTypeSignature.CrdInfo: - count += this.WriteCrdInfoTagDataEntry(entry as IccCrdInfoTagDataEntry); + count += this.WriteCrdInfoTagDataEntry((IccCrdInfoTagDataEntry)entry); break; case IccTypeSignature.Screening: - count += this.WriteScreeningTagDataEntry(entry as IccScreeningTagDataEntry); + count += this.WriteScreeningTagDataEntry((IccScreeningTagDataEntry)entry); break; case IccTypeSignature.UcrBg: - count += this.WriteUcrBgTagDataEntry(entry as IccUcrBgTagDataEntry); + count += this.WriteUcrBgTagDataEntry((IccUcrBgTagDataEntry)entry); break; // Unsupported or unknown @@ -560,8 +560,8 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc // TODO: Investigate cost of Linq GroupBy IGrouping[] texts = value.Texts.GroupBy(t => t.Text).ToArray(); - uint[] offset = new uint[texts.Length]; - int[] lengths = new int[texts.Length]; + var offset = new uint[texts.Length]; + var lengths = new int[texts.Length]; for (int i = 0; i < texts.Length; i++) { @@ -746,7 +746,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc long tablePosition = this.dataStream.Position; this.dataStream.Position += value.Curves.Length * 4; - uint[] offset = new uint[value.Curves.Length]; + var offset = new uint[value.Curves.Length]; for (int i = 0; i < value.Curves.Length; i++) { diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardObserver.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardObserver.cs index 1454b28273..14c0a04678 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardObserver.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccStandardObserver.cs @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc /// /// Unknown observer /// - Unkown = 0, + Unknown = 0, /// /// CIE 1931 observer diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs index afdd7ebfb5..7c5139475b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc const int profileIdPos = 84; // need to copy some values because they need to be zero for the hashing - byte[] temp = new byte[24]; + var temp = new byte[24]; Buffer.BlockCopy(data, profileFlagPos, temp, 0, 4); Buffer.BlockCopy(data, renderingIntentPos, temp, 4, 4); Buffer.BlockCopy(data, profileIdPos, temp, 8, 16); @@ -171,7 +171,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { if (this.data != null) { - byte[] copy = new byte[this.data.Length]; + var copy = new byte[this.data.Length]; Buffer.BlockCopy(this.data, 0, copy, 0, copy.Length); return copy; } @@ -216,4 +216,4 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc this.entries = reader.ReadTagData(this.data); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs index 4134779c3c..23e81fe993 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc && p3 >= 0x41 && p3 <= 0x5A && p4 >= 0x41 && p4 <= 0x5A) { - string culture = new string(new[] { (char)p1, (char)p2, '-', (char)p3, (char)p4 }); + var culture = new string(new[] { (char)p1, (char)p2, '-', (char)p3, (char)p4 }); return new CultureInfo(culture); } @@ -175,4 +175,4 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc this.ScriptCodeCode); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs b/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs index 0d182d3c24..62dc0fcf59 100644 --- a/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs +++ b/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.PixelFormats @@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.PixelFormats Dest, /// - /// The source where they don't overlap othersie dest in overlapping parts. + /// The source where they don't overlap otherwise dest in overlapping parts. /// DestAtop, diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index 0cf8d6bbbf..e94ea452be 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. // @@ -38,26 +38,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrc(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrc(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -73,26 +73,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplySrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrc(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrc(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -108,26 +108,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrc(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrc(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -143,26 +143,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrc(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrc(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -178,26 +178,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrc(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrc(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -213,26 +213,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrc(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrc(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -248,26 +248,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrc(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrc(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -283,26 +283,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlaySrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrc(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrc(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -318,26 +318,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrc(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrc(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -353,26 +353,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -388,26 +388,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -423,26 +423,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -458,26 +458,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -493,26 +493,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -528,26 +528,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -563,26 +563,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -598,26 +598,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -633,26 +633,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -668,26 +668,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -703,26 +703,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -738,26 +738,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -773,26 +773,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -808,26 +808,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -843,26 +843,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -878,26 +878,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -913,26 +913,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -948,26 +948,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -983,26 +983,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1018,26 +1018,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1053,26 +1053,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1088,26 +1088,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1123,26 +1123,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1158,26 +1158,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1193,26 +1193,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1228,26 +1228,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1263,26 +1263,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1298,26 +1298,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1333,26 +1333,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1368,26 +1368,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1403,26 +1403,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1438,26 +1438,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1473,26 +1473,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1508,26 +1508,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1543,26 +1543,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1578,26 +1578,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1613,26 +1613,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDest(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDest(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1648,26 +1648,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplyDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDest(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDest(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1683,26 +1683,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDest(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDest(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1718,26 +1718,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDest(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDest(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1753,26 +1753,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDest(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDest(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1788,26 +1788,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDest(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDest(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1823,26 +1823,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDest(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDest(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1858,26 +1858,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlayDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDest(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDest(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1893,26 +1893,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDest(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDest(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1928,26 +1928,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1963,26 +1963,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -1998,26 +1998,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2033,26 +2033,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2068,26 +2068,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2103,26 +2103,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2138,26 +2138,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2173,26 +2173,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlayDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2208,26 +2208,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestAtop(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2243,26 +2243,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2278,26 +2278,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2313,26 +2313,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2348,26 +2348,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2383,26 +2383,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2418,26 +2418,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2453,26 +2453,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2488,26 +2488,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlayDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2523,26 +2523,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestOver(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestOver(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2558,26 +2558,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2593,26 +2593,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2628,26 +2628,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2663,26 +2663,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2698,26 +2698,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2733,26 +2733,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2768,26 +2768,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2803,26 +2803,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlayDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2838,26 +2838,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestIn(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestIn(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2873,26 +2873,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2908,26 +2908,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2943,26 +2943,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -2978,26 +2978,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3013,26 +3013,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3048,26 +3048,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3083,26 +3083,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3118,26 +3118,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlayDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3153,26 +3153,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestOut(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestOut(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3188,26 +3188,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalClear(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalClear(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3223,26 +3223,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplyClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyClear(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyClear(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3258,26 +3258,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddClear(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddClear(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3293,26 +3293,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractClear(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractClear(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3328,26 +3328,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenClear(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenClear(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3363,26 +3363,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenClear(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenClear(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3398,26 +3398,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenClear(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenClear(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3433,26 +3433,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlayClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayClear(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayClear(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3468,26 +3468,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightClear(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightClear(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3503,26 +3503,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.NormalXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalXor(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalXor(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3538,26 +3538,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.MultiplyXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyXor(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyXor(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3573,26 +3573,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.AddXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddXor(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddXor(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3608,26 +3608,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.SubtractXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractXor(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractXor(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3643,26 +3643,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.ScreenXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenXor(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenXor(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3678,26 +3678,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.DarkenXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenXor(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenXor(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3713,26 +3713,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.LightenXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenXor(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenXor(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3748,26 +3748,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.OverlayXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayXor(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayXor(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -3783,28 +3783,28 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.HardLightXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightXor(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightXor(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt index 2cca55e4c3..66a00975e1 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt @@ -1,4 +1,4 @@ -<# +<# // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. #> @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { <# - string[] composers = new []{ + var composers = new []{ "Src", "SrcAtop", "SrcOver", @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders "Xor", }; - string[] blenders = new []{ + var blenders = new []{ "Normal", "Multiply", "Add", @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders foreach(var composer in composers) { foreach(var blender in blenders) { - string blender_composer= $"{blender}{composer}"; + var blender_composer= $"{blender}{composer}"; #> internal class <#= blender_composer#> : PixelBlender @@ -82,26 +82,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { TPixel dest = default; dest.FromScaledVector4(PorterDuffFunctions.<#=blender_composer#>(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); - return dest; + return dest; } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { amount = amount.Clamp(0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount); - } + } } /// - protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) + protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount) { for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount[i].Clamp(0, 1)); - } + } } } @@ -111,4 +111,4 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders #> } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs index a99deb535a..8b92f95c36 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. // @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 NormalClear(Vector4 backdrop, Vector4 source, float opacity) @@ -110,7 +110,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return Clear(backdrop, source); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalSrc(TPixel backdrop, TPixel source, float opacity) @@ -122,7 +121,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalSrcAtop(TPixel backdrop, TPixel source, float opacity) @@ -134,7 +132,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalSrcOver(TPixel backdrop, TPixel source, float opacity) @@ -146,7 +143,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalSrcIn(TPixel backdrop, TPixel source, float opacity) @@ -158,7 +154,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalSrcOut(TPixel backdrop, TPixel source, float opacity) @@ -170,7 +165,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalDest(TPixel backdrop, TPixel source, float opacity) @@ -182,7 +176,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalDestAtop(TPixel backdrop, TPixel source, float opacity) @@ -194,7 +187,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalDestOver(TPixel backdrop, TPixel source, float opacity) @@ -206,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalDestIn(TPixel backdrop, TPixel source, float opacity) @@ -218,7 +209,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalDestOut(TPixel backdrop, TPixel source, float opacity) @@ -230,7 +220,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalClear(TPixel backdrop, TPixel source, float opacity) @@ -242,7 +231,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel NormalXor(TPixel backdrop, TPixel source, float opacity) @@ -339,7 +327,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 MultiplyClear(Vector4 backdrop, Vector4 source, float opacity) @@ -348,7 +336,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return Clear(backdrop, source); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplySrc(TPixel backdrop, TPixel source, float opacity) @@ -360,7 +347,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplySrcAtop(TPixel backdrop, TPixel source, float opacity) @@ -372,7 +358,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplySrcOver(TPixel backdrop, TPixel source, float opacity) @@ -384,7 +369,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplySrcIn(TPixel backdrop, TPixel source, float opacity) @@ -396,7 +380,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplySrcOut(TPixel backdrop, TPixel source, float opacity) @@ -408,7 +391,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplyDest(TPixel backdrop, TPixel source, float opacity) @@ -420,7 +402,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplyDestAtop(TPixel backdrop, TPixel source, float opacity) @@ -432,7 +413,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplyDestOver(TPixel backdrop, TPixel source, float opacity) @@ -444,7 +424,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplyDestIn(TPixel backdrop, TPixel source, float opacity) @@ -456,7 +435,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplyDestOut(TPixel backdrop, TPixel source, float opacity) @@ -468,7 +446,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplyClear(TPixel backdrop, TPixel source, float opacity) @@ -480,7 +457,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel MultiplyXor(TPixel backdrop, TPixel source, float opacity) @@ -577,7 +553,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 AddClear(Vector4 backdrop, Vector4 source, float opacity) @@ -586,7 +562,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return Clear(backdrop, source); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddSrc(TPixel backdrop, TPixel source, float opacity) @@ -598,7 +573,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddSrcAtop(TPixel backdrop, TPixel source, float opacity) @@ -610,7 +584,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddSrcOver(TPixel backdrop, TPixel source, float opacity) @@ -622,7 +595,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddSrcIn(TPixel backdrop, TPixel source, float opacity) @@ -634,7 +606,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddSrcOut(TPixel backdrop, TPixel source, float opacity) @@ -646,7 +617,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddDest(TPixel backdrop, TPixel source, float opacity) @@ -658,7 +628,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddDestAtop(TPixel backdrop, TPixel source, float opacity) @@ -670,7 +639,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddDestOver(TPixel backdrop, TPixel source, float opacity) @@ -682,7 +650,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddDestIn(TPixel backdrop, TPixel source, float opacity) @@ -694,7 +661,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddDestOut(TPixel backdrop, TPixel source, float opacity) @@ -706,7 +672,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddClear(TPixel backdrop, TPixel source, float opacity) @@ -718,7 +683,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel AddXor(TPixel backdrop, TPixel source, float opacity) @@ -815,7 +779,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 SubtractClear(Vector4 backdrop, Vector4 source, float opacity) @@ -824,7 +788,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return Clear(backdrop, source); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractSrc(TPixel backdrop, TPixel source, float opacity) @@ -836,7 +799,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractSrcAtop(TPixel backdrop, TPixel source, float opacity) @@ -848,7 +810,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractSrcOver(TPixel backdrop, TPixel source, float opacity) @@ -860,7 +821,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractSrcIn(TPixel backdrop, TPixel source, float opacity) @@ -872,7 +832,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractSrcOut(TPixel backdrop, TPixel source, float opacity) @@ -884,7 +843,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractDest(TPixel backdrop, TPixel source, float opacity) @@ -896,7 +854,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractDestAtop(TPixel backdrop, TPixel source, float opacity) @@ -908,7 +865,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractDestOver(TPixel backdrop, TPixel source, float opacity) @@ -920,7 +876,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractDestIn(TPixel backdrop, TPixel source, float opacity) @@ -932,7 +887,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractDestOut(TPixel backdrop, TPixel source, float opacity) @@ -944,7 +898,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractClear(TPixel backdrop, TPixel source, float opacity) @@ -956,7 +909,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel SubtractXor(TPixel backdrop, TPixel source, float opacity) @@ -1053,7 +1005,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 ScreenClear(Vector4 backdrop, Vector4 source, float opacity) @@ -1062,7 +1014,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return Clear(backdrop, source); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenSrc(TPixel backdrop, TPixel source, float opacity) @@ -1074,7 +1025,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenSrcAtop(TPixel backdrop, TPixel source, float opacity) @@ -1086,7 +1036,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenSrcOver(TPixel backdrop, TPixel source, float opacity) @@ -1098,7 +1047,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenSrcIn(TPixel backdrop, TPixel source, float opacity) @@ -1110,7 +1058,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenSrcOut(TPixel backdrop, TPixel source, float opacity) @@ -1122,7 +1069,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenDest(TPixel backdrop, TPixel source, float opacity) @@ -1134,7 +1080,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenDestAtop(TPixel backdrop, TPixel source, float opacity) @@ -1146,7 +1091,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenDestOver(TPixel backdrop, TPixel source, float opacity) @@ -1158,7 +1102,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenDestIn(TPixel backdrop, TPixel source, float opacity) @@ -1170,7 +1113,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenDestOut(TPixel backdrop, TPixel source, float opacity) @@ -1182,7 +1124,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenClear(TPixel backdrop, TPixel source, float opacity) @@ -1194,7 +1135,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ScreenXor(TPixel backdrop, TPixel source, float opacity) @@ -1291,7 +1231,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 DarkenClear(Vector4 backdrop, Vector4 source, float opacity) @@ -1300,7 +1240,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return Clear(backdrop, source); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenSrc(TPixel backdrop, TPixel source, float opacity) @@ -1312,7 +1251,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenSrcAtop(TPixel backdrop, TPixel source, float opacity) @@ -1324,7 +1262,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenSrcOver(TPixel backdrop, TPixel source, float opacity) @@ -1336,7 +1273,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenSrcIn(TPixel backdrop, TPixel source, float opacity) @@ -1348,7 +1284,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenSrcOut(TPixel backdrop, TPixel source, float opacity) @@ -1360,7 +1295,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenDest(TPixel backdrop, TPixel source, float opacity) @@ -1372,7 +1306,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenDestAtop(TPixel backdrop, TPixel source, float opacity) @@ -1384,7 +1317,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenDestOver(TPixel backdrop, TPixel source, float opacity) @@ -1396,7 +1328,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenDestIn(TPixel backdrop, TPixel source, float opacity) @@ -1408,7 +1339,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenDestOut(TPixel backdrop, TPixel source, float opacity) @@ -1420,7 +1350,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenClear(TPixel backdrop, TPixel source, float opacity) @@ -1432,7 +1361,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel DarkenXor(TPixel backdrop, TPixel source, float opacity) @@ -1529,7 +1457,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 LightenClear(Vector4 backdrop, Vector4 source, float opacity) @@ -1538,7 +1466,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return Clear(backdrop, source); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenSrc(TPixel backdrop, TPixel source, float opacity) @@ -1550,7 +1477,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenSrcAtop(TPixel backdrop, TPixel source, float opacity) @@ -1562,7 +1488,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenSrcOver(TPixel backdrop, TPixel source, float opacity) @@ -1574,7 +1499,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenSrcIn(TPixel backdrop, TPixel source, float opacity) @@ -1586,7 +1510,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenSrcOut(TPixel backdrop, TPixel source, float opacity) @@ -1598,7 +1521,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenDest(TPixel backdrop, TPixel source, float opacity) @@ -1610,7 +1532,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenDestAtop(TPixel backdrop, TPixel source, float opacity) @@ -1622,7 +1543,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenDestOver(TPixel backdrop, TPixel source, float opacity) @@ -1634,7 +1554,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenDestIn(TPixel backdrop, TPixel source, float opacity) @@ -1646,7 +1565,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenDestOut(TPixel backdrop, TPixel source, float opacity) @@ -1658,7 +1576,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenClear(TPixel backdrop, TPixel source, float opacity) @@ -1670,7 +1587,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel LightenXor(TPixel backdrop, TPixel source, float opacity) @@ -1767,7 +1683,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 OverlayClear(Vector4 backdrop, Vector4 source, float opacity) @@ -1776,7 +1692,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return Clear(backdrop, source); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlaySrc(TPixel backdrop, TPixel source, float opacity) @@ -1788,7 +1703,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlaySrcAtop(TPixel backdrop, TPixel source, float opacity) @@ -1800,7 +1714,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlaySrcOver(TPixel backdrop, TPixel source, float opacity) @@ -1812,7 +1725,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlaySrcIn(TPixel backdrop, TPixel source, float opacity) @@ -1824,7 +1736,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlaySrcOut(TPixel backdrop, TPixel source, float opacity) @@ -1836,7 +1747,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlayDest(TPixel backdrop, TPixel source, float opacity) @@ -1848,7 +1758,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlayDestAtop(TPixel backdrop, TPixel source, float opacity) @@ -1860,7 +1769,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlayDestOver(TPixel backdrop, TPixel source, float opacity) @@ -1872,7 +1780,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlayDestIn(TPixel backdrop, TPixel source, float opacity) @@ -1884,7 +1791,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlayDestOut(TPixel backdrop, TPixel source, float opacity) @@ -1896,7 +1802,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlayClear(TPixel backdrop, TPixel source, float opacity) @@ -1908,7 +1813,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel OverlayXor(TPixel backdrop, TPixel source, float opacity) @@ -2005,7 +1909,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 HardLightClear(Vector4 backdrop, Vector4 source, float opacity) @@ -2014,7 +1918,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return Clear(backdrop, source); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightSrc(TPixel backdrop, TPixel source, float opacity) @@ -2026,7 +1929,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightSrcAtop(TPixel backdrop, TPixel source, float opacity) @@ -2038,7 +1940,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightSrcOver(TPixel backdrop, TPixel source, float opacity) @@ -2050,7 +1951,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightSrcIn(TPixel backdrop, TPixel source, float opacity) @@ -2062,7 +1962,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightSrcOut(TPixel backdrop, TPixel source, float opacity) @@ -2074,7 +1973,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightDest(TPixel backdrop, TPixel source, float opacity) @@ -2086,7 +1984,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightDestAtop(TPixel backdrop, TPixel source, float opacity) @@ -2098,7 +1995,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightDestOver(TPixel backdrop, TPixel source, float opacity) @@ -2110,7 +2006,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightDestIn(TPixel backdrop, TPixel source, float opacity) @@ -2122,7 +2017,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightDestOut(TPixel backdrop, TPixel source, float opacity) @@ -2134,7 +2028,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightClear(TPixel backdrop, TPixel source, float opacity) @@ -2146,7 +2039,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders return dest; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel HardLightXor(TPixel backdrop, TPixel source, float opacity) @@ -2159,4 +2051,4 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt index c8345cfb9f..f591ee873d 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt @@ -1,4 +1,4 @@ -<# +<# // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. #> @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders source.W *= opacity; return Xor(backdrop, source); - } + } [MethodImpl(MethodImplOptions.NoInlining)] public static Vector4 <#=blender#>Clear(Vector4 backdrop, Vector4 source, float opacity) @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders <# } #> -<# void GenerateGenericPixelBlender(string blender, string composer) { #> +<# void GenerateGenericPixelBlender(string blender, string composer) { #> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel <#=blender#><#=composer#>(TPixel backdrop, TPixel source, float opacity) @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders <# -string[] composers = new []{ +var composers = new []{ "Src", "SrcAtop", "SrcOver", @@ -156,7 +156,7 @@ string[] composers = new []{ "Xor", }; -string[] blenders = new []{ +var blenders = new []{ "Normal", "Multiply", "Add", @@ -166,12 +166,12 @@ string[] blenders = new []{ "Lighten", "Overlay", "HardLight" -}; +}; foreach(var blender in blenders) - { - GeneratePixelBlenders(blender); - + { + GeneratePixelBlenders(blender); + foreach(var composer in composers) { GenerateGenericPixelBlender(blender,composer); @@ -180,4 +180,4 @@ string[] blenders = new []{ #> } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelConversionModifiers.cs b/src/ImageSharp/PixelFormats/PixelConversionModifiers.cs index 5df5dc62bc..2f9abce5d8 100644 --- a/src/ImageSharp/PixelFormats/PixelConversionModifiers.cs +++ b/src/ImageSharp/PixelFormats/PixelConversionModifiers.cs @@ -8,7 +8,7 @@ using SixLabors.ImageSharp.ColorSpaces.Companding; namespace SixLabors.ImageSharp.PixelFormats { /// - /// Flags responsible to select additional operations which could be effitiently applied in + /// Flags responsible to select additional operations which could be efficiently applied in /// /// or /// @@ -37,4 +37,4 @@ namespace SixLabors.ImageSharp.PixelFormats /// SRgbCompand = 1 << 2, } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Gray16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Gray16.cs index 195a8bedb0..b5bd14d9f1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Gray16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Gray16.cs @@ -1,7 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -16,7 +15,6 @@ namespace SixLabors.ImageSharp.PixelFormats public partial struct Gray16 : IPixel, IPackedVector { private const float Max = ushort.MaxValue; - private const float Average = 1 / 3F; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Gray8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Gray8.cs index 09597a949f..ac67c9d170 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Gray8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Gray8.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -16,12 +16,6 @@ namespace SixLabors.ImageSharp.PixelFormats { private static readonly Vector4 MaxBytes = new Vector4(255F); private static readonly Vector4 Half = new Vector4(0.5F); - private const float Average = 1 / 3F; - - private static readonly Vector4 Min = new Vector4(0, 0, 0, 1f); - private static readonly Vector4 Max = Vector4.One; - - private static readonly Vector4 Accumulator = new Vector4(255f * Average, 255f * Average, 255f * Average, 0.5f); /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs index e2ed931b75..8854f16501 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromScaledVector4(Vector4 vector) { - Vector2 scaled = new Vector2(vector.X, vector.Y) * 2F; + var scaled = new Vector2(vector.X, vector.Y) * 2F; scaled -= Vector2.One; this.PackedValue = Pack(scaled.X, scaled.Y); } @@ -173,4 +173,4 @@ namespace SixLabors.ImageSharp.PixelFormats return num2 | num; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs index cd95e87ecf..a24e725692 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromScaledVector4(Vector4 vector) { - Vector2 scaled = new Vector2(vector.X, vector.Y) * 2F; + var scaled = new Vector2(vector.X, vector.Y) * 2F; scaled -= Vector2.One; this.PackedValue = Pack(scaled); } @@ -179,4 +179,4 @@ namespace SixLabors.ImageSharp.PixelFormats return (ushort)(byte2 | byte1); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs index 8d7c400b45..3ede947139 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromScaledVector4(Vector4 vector) { - Vector2 scaled = new Vector2(vector.X, vector.Y) * 2F; + var scaled = new Vector2(vector.X, vector.Y) * 2F; scaled -= Vector2.One; this.PackedValue = Pack(scaled); } @@ -186,4 +186,4 @@ namespace SixLabors.ImageSharp.PixelFormats return word2 | word1; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs index 3da5d1855b..da02f374e1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs @@ -6,7 +6,6 @@ using System.Numerics; using System.Runtime.InteropServices; using SixLabors.ImageSharp.PixelFormats.Utils; -using SixLabors.Memory; namespace SixLabors.ImageSharp.PixelFormats { diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs index 38e75d1836..445f899817 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -193,11 +193,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override string ToString() { - var vector = this.ToVector4(); return FormattableString.Invariant($"RgbaVector({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##}, {this.A:#0.##})"); } /// public override int GetHashCode() => HashCode.Combine(this.R, this.G, this.B, this.A); } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs index 803a77b23f..14987e5829 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromScaledVector4(Vector4 vector) { - Vector2 scaled = new Vector2(vector.X, vector.Y) * 65534F; + var scaled = new Vector2(vector.X, vector.Y) * 65534F; scaled -= new Vector2(32767F); this.PackedValue = Pack(scaled); } @@ -179,4 +179,4 @@ namespace SixLabors.ImageSharp.PixelFormats return word2 | word1; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs index 2b2d79c732..f557f348a1 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs @@ -4,8 +4,6 @@ using System; using System.Buffers; using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using SixLabors.ImageSharp.Memory; diff --git a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs index 4c4e60276d..e67bd9d53e 100644 --- a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs +++ b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs @@ -6,8 +6,6 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.ColorSpaces.Companding; - namespace SixLabors.ImageSharp.PixelFormats.Utils { /// diff --git a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs index fe8d7dec3b..0350c669ab 100644 --- a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs +++ b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs @@ -7,8 +7,6 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.ColorSpaces.Companding; - namespace SixLabors.ImageSharp.PixelFormats.Utils { /// diff --git a/src/ImageSharp/Primitives/ColorMatrix.cs b/src/ImageSharp/Primitives/ColorMatrix.cs index af2e9465a9..11886c9c2a 100644 --- a/src/ImageSharp/Primitives/ColorMatrix.cs +++ b/src/ImageSharp/Primitives/ColorMatrix.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. #pragma warning disable SA1117 // Parameters should be on same line or separate lines @@ -269,7 +269,7 @@ namespace SixLabors.ImageSharp.Primitives /// /// The source matrix. /// The negated matrix. - public static unsafe ColorMatrix operator -(ColorMatrix value) + public static ColorMatrix operator -(ColorMatrix value) { ColorMatrix m; @@ -456,4 +456,4 @@ namespace SixLabors.ImageSharp.Primitives this.M51.ToString(ci), this.M52.ToString(ci), this.M53.ToString(ci), this.M54.ToString(ci)); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Primitives/Complex64.cs b/src/ImageSharp/Primitives/Complex64.cs new file mode 100644 index 0000000000..96883229c4 --- /dev/null +++ b/src/ImageSharp/Primitives/Complex64.cs @@ -0,0 +1,95 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp.Primitives +{ + /// + /// Represents a complex number, where the real and imaginary parts are stored as values. + /// + /// + /// This is a more efficient version of the type. + /// + internal readonly struct Complex64 : IEquatable + { + /// + /// The real part of the complex number + /// + public readonly float Real; + + /// + /// The imaginary part of the complex number + /// + public readonly float Imaginary; + + /// + /// Initializes a new instance of the struct. + /// + /// The real part in the complex number. + /// The imaginary part in the complex number. + public Complex64(float real, float imaginary) + { + this.Real = real; + this.Imaginary = imaginary; + } + + /// + /// Performs the multiplication operation between a instance and a scalar. + /// + /// The value to multiply. + /// The scalar to use to multiply the value. + /// The result + [MethodImpl(InliningOptions.ShortMethod)] + public static Complex64 operator *(Complex64 value, float scalar) => new Complex64(value.Real * scalar, value.Imaginary * scalar); + + /// + /// Performs the multiplication operation between a instance and a . + /// + /// The value to multiply. + /// The instance to use to multiply the value. + /// The result + [MethodImpl(InliningOptions.ShortMethod)] + public static ComplexVector4 operator *(Complex64 value, Vector4 vector) + { + return new ComplexVector4 { Real = vector * value.Real, Imaginary = vector * value.Imaginary }; + } + + /// + /// Performs the multiplication operation between a instance and a . + /// + /// The value to multiply. + /// The instance to use to multiply the value. + /// The result + [MethodImpl(InliningOptions.ShortMethod)] + public static ComplexVector4 operator *(Complex64 value, ComplexVector4 vector) + { + Vector4 real = (value.Real * vector.Real) - (value.Imaginary * vector.Imaginary); + Vector4 imaginary = (value.Real * vector.Imaginary) + (value.Imaginary * vector.Real); + return new ComplexVector4 { Real = real, Imaginary = imaginary }; + } + + /// + public bool Equals(Complex64 other) + { + return this.Real.Equals(other.Real) && this.Imaginary.Equals(other.Imaginary); + } + + /// + public override bool Equals(object obj) => obj is Complex64 other && this.Equals(other); + + /// + public override int GetHashCode() + { + unchecked + { + return (this.Real.GetHashCode() * 397) ^ this.Imaginary.GetHashCode(); + } + } + + /// + public override string ToString() => $"{this.Real}{(this.Imaginary >= 0 ? "+" : string.Empty)}{this.Imaginary}j"; + } +} diff --git a/src/ImageSharp/Primitives/ComplexVector4.cs b/src/ImageSharp/Primitives/ComplexVector4.cs new file mode 100644 index 0000000000..b90da65b2d --- /dev/null +++ b/src/ImageSharp/Primitives/ComplexVector4.cs @@ -0,0 +1,63 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp.Primitives +{ + /// + /// A vector with 4 values of type . + /// + internal struct ComplexVector4 : IEquatable + { + /// + /// The real part of the complex vector + /// + public Vector4 Real; + + /// + /// The imaginary part of the complex number + /// + public Vector4 Imaginary; + + /// + /// Sums the values in the input to the current instance + /// + /// The input to sum + [MethodImpl(InliningOptions.ShortMethod)] + public void Sum(in ComplexVector4 value) + { + this.Real += value.Real; + this.Imaginary += value.Imaginary; + } + + /// + /// Performs a weighted sum on the current instance according to the given parameters + /// + /// The 'a' parameter, for the real component + /// The 'b' parameter, for the imaginary component + /// The resulting value + [MethodImpl(InliningOptions.ShortMethod)] + public Vector4 WeightedSum(float a, float b) => (this.Real * a) + (this.Imaginary * b); + + /// + public bool Equals(ComplexVector4 other) + { + return this.Real.Equals(other.Real) && this.Imaginary.Equals(other.Imaginary); + } + + /// + public override bool Equals(object obj) => obj is ComplexVector4 other && this.Equals(other); + + /// + public override int GetHashCode() + { + unchecked + { + return (this.Real.GetHashCode() * 397) ^ this.Imaginary.GetHashCode(); + } + } + } +} diff --git a/src/ImageSharp/Primitives/Rational.cs b/src/ImageSharp/Primitives/Rational.cs index b598f0e02f..f9299bc178 100644 --- a/src/ImageSharp/Primitives/Rational.cs +++ b/src/ImageSharp/Primitives/Rational.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Primitives { if (simplify) { - LongRational rational = new LongRational(numerator, denominator).Simplify(); + var rational = new LongRational(numerator, denominator).Simplify(); this.Numerator = (uint)rational.Numerator; this.Denominator = (uint)rational.Denominator; @@ -187,4 +187,4 @@ namespace SixLabors.ImageSharp.Primitives return rational.ToString(provider); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Primitives/SignedRational.cs b/src/ImageSharp/Primitives/SignedRational.cs index 7e486e4f22..395a24b14e 100644 --- a/src/ImageSharp/Primitives/SignedRational.cs +++ b/src/ImageSharp/Primitives/SignedRational.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Primitives { if (simplify) { - LongRational rational = new LongRational(numerator, denominator).Simplify(); + var rational = new LongRational(numerator, denominator).Simplify(); this.Numerator = (int)rational.Numerator; this.Denominator = (int)rational.Denominator; @@ -187,4 +187,4 @@ namespace SixLabors.ImageSharp.Primitives return rational.ToString(provider); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/BokehBlurExecutionMode.cs b/src/ImageSharp/Processing/BokehBlurExecutionMode.cs new file mode 100644 index 0000000000..bc44dca03c --- /dev/null +++ b/src/ImageSharp/Processing/BokehBlurExecutionMode.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Processing.Processors.Convolution; + +namespace SixLabors.ImageSharp.Processing +{ + /// + /// An that indicates execution options for the . + /// + public enum BokehBlurExecutionMode + { + /// + /// Indicates that the maximum performance should be prioritized over memory usage. + /// + PreferMaximumPerformance, + + /// + /// Indicates that the memory usage should be prioritized over raw performance. + /// + PreferLowMemoryUsage + } +} diff --git a/src/ImageSharp/Processing/Extensions/AutoOrientExtensions.cs b/src/ImageSharp/Processing/Extensions/AutoOrientExtensions.cs index a831e2d9af..984081dffe 100644 --- a/src/ImageSharp/Processing/Extensions/AutoOrientExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/AutoOrientExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Transforms; namespace SixLabors.ImageSharp.Processing diff --git a/src/ImageSharp/Processing/Extensions/BlackWhiteExtensions.cs b/src/ImageSharp/Processing/Extensions/BlackWhiteExtensions.cs index ee34cd99e2..c148ccbcb9 100644 --- a/src/ImageSharp/Processing/Extensions/BlackWhiteExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/BlackWhiteExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/BokehBlurExtensions.cs b/src/ImageSharp/Processing/Extensions/BokehBlurExtensions.cs new file mode 100644 index 0000000000..ef20f940af --- /dev/null +++ b/src/ImageSharp/Processing/Extensions/BokehBlurExtensions.cs @@ -0,0 +1,106 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Processing.Processors.Convolution; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing +{ + /// + /// Adds bokeh blurring extensions to the type. + /// + public static class BokehBlurExtensions + { + /// + /// Applies a bokeh blur to the image. + /// + /// The image this method extends. + /// The to allow chaining of operations. + public static IImageProcessingContext BokehBlur(this IImageProcessingContext source) + => source.ApplyProcessor(new BokehBlurProcessor()); + + /// + /// Applies a bokeh blur to the image. + /// + /// The image this method extends. + /// The execution mode to use when applying the processor. + /// The to allow chaining of operations. + public static IImageProcessingContext BokehBlur(this IImageProcessingContext source, BokehBlurExecutionMode executionMode) + => source.ApplyProcessor(new BokehBlurProcessor(executionMode)); + + /// + /// Applies a bokeh blur to the image. + /// + /// The image this method extends. + /// The 'radius' value representing the size of the area to sample. + /// The 'components' value representing the number of kernels to use to approximate the bokeh effect. + /// The gamma highlight factor to use to emphasize bright spots in the source image + /// The to allow chaining of operations. + public static IImageProcessingContext BokehBlur(this IImageProcessingContext source, int radius, int components, float gamma) + => source.ApplyProcessor(new BokehBlurProcessor(radius, components, gamma)); + + /// + /// Applies a bokeh blur to the image. + /// + /// The image this method extends. + /// The 'radius' value representing the size of the area to sample. + /// The 'components' value representing the number of kernels to use to approximate the bokeh effect. + /// The gamma highlight factor to use to emphasize bright spots in the source image + /// The execution mode to use when applying the processor. + /// The to allow chaining of operations. + public static IImageProcessingContext BokehBlur(this IImageProcessingContext source, int radius, int components, float gamma, BokehBlurExecutionMode executionMode) + => source.ApplyProcessor(new BokehBlurProcessor(radius, components, gamma, executionMode)); + + /// + /// Applies a bokeh blur to the image. + /// + /// The image this method extends. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The to allow chaining of operations. + public static IImageProcessingContext BokehBlur(this IImageProcessingContext source, Rectangle rectangle) + => source.ApplyProcessor(new BokehBlurProcessor(), rectangle); + + /// + /// Applies a bokeh blur to the image. + /// + /// The image this method extends. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The execution mode to use when applying the processor. + /// The to allow chaining of operations. + public static IImageProcessingContext BokehBlur(this IImageProcessingContext source, Rectangle rectangle, BokehBlurExecutionMode executionMode) + => source.ApplyProcessor(new BokehBlurProcessor(executionMode), rectangle); + + /// + /// Applies a bokeh blur to the image. + /// + /// The image this method extends. + /// The 'radius' value representing the size of the area to sample. + /// The 'components' value representing the number of kernels to use to approximate the bokeh effect. + /// The gamma highlight factor to use to emphasize bright spots in the source image + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The to allow chaining of operations. + public static IImageProcessingContext BokehBlur(this IImageProcessingContext source, int radius, int components, float gamma, Rectangle rectangle) + => source.ApplyProcessor(new BokehBlurProcessor(radius, components, gamma), rectangle); + + /// + /// Applies a bokeh blur to the image. + /// + /// The image this method extends. + /// The 'radius' value representing the size of the area to sample. + /// The 'components' value representing the number of kernels to use to approximate the bokeh effect. + /// The gamma highlight factor to use to emphasize bright spots in the source image + /// The execution mode to use when applying the processor. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The to allow chaining of operations. + public static IImageProcessingContext BokehBlur(this IImageProcessingContext source, int radius, int components, float gamma, BokehBlurExecutionMode executionMode, Rectangle rectangle) + => source.ApplyProcessor(new BokehBlurProcessor(radius, components, gamma, executionMode), rectangle); + } +} diff --git a/src/ImageSharp/Processing/Extensions/BoxBlurExtensions.cs b/src/ImageSharp/Processing/Extensions/BoxBlurExtensions.cs index f3400c24e6..42dfd425cc 100644 --- a/src/ImageSharp/Processing/Extensions/BoxBlurExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/BoxBlurExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/BrightnessExtensions.cs b/src/ImageSharp/Processing/Extensions/BrightnessExtensions.cs index db84091763..8e43f06c5a 100644 --- a/src/ImageSharp/Processing/Extensions/BrightnessExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/BrightnessExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/FilterExtensions.cs b/src/ImageSharp/Processing/Extensions/FilterExtensions.cs index 5a66502ce5..662e3a6e16 100644 --- a/src/ImageSharp/Processing/Extensions/FilterExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/FilterExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/GaussianBlurExtensions.cs b/src/ImageSharp/Processing/Extensions/GaussianBlurExtensions.cs index e527a14b73..858e3213b1 100644 --- a/src/ImageSharp/Processing/Extensions/GaussianBlurExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/GaussianBlurExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/GrayscaleExtensions.cs b/src/ImageSharp/Processing/Extensions/GrayscaleExtensions.cs index a87341025d..a4bfaa516c 100644 --- a/src/ImageSharp/Processing/Extensions/GrayscaleExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/GrayscaleExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/HueExtensions.cs b/src/ImageSharp/Processing/Extensions/HueExtensions.cs index 3c1239da67..3955ea7f6e 100644 --- a/src/ImageSharp/Processing/Extensions/HueExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/HueExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/InvertExtensions.cs b/src/ImageSharp/Processing/Extensions/InvertExtensions.cs index c45f24c2ea..16c7a89178 100644 --- a/src/ImageSharp/Processing/Extensions/InvertExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/InvertExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/KodachromeExtensions.cs b/src/ImageSharp/Processing/Extensions/KodachromeExtensions.cs index 810094a180..6c9b279835 100644 --- a/src/ImageSharp/Processing/Extensions/KodachromeExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/KodachromeExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/LomographExtensions.cs b/src/ImageSharp/Processing/Extensions/LomographExtensions.cs index dd7ab21ec1..c2b6ac0804 100644 --- a/src/ImageSharp/Processing/Extensions/LomographExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/LomographExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/OpacityExtensions.cs b/src/ImageSharp/Processing/Extensions/OpacityExtensions.cs index ecf6ce783e..9c67113ecf 100644 --- a/src/ImageSharp/Processing/Extensions/OpacityExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/OpacityExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/PolaroidExtensions.cs b/src/ImageSharp/Processing/Extensions/PolaroidExtensions.cs index eace463579..6b6d43d5b8 100644 --- a/src/ImageSharp/Processing/Extensions/PolaroidExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/PolaroidExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs b/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs index 2304a44c39..48876251e2 100644 --- a/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -21,7 +21,11 @@ namespace SixLabors.ImageSharp.Processing /// The operation to perform on the source. public static void Mutate(this Image source, Action operation) { - ProcessingVisitor visitor = new ProcessingVisitor(operation, true); + Guard.NotNull(source, nameof(source)); + Guard.NotNull(operation, nameof(operation)); + source.EnsureNotDisposed(); + + var visitor = new ProcessingVisitor(operation, true); source.AcceptVisitor(visitor); } @@ -34,8 +38,9 @@ namespace SixLabors.ImageSharp.Processing public static void Mutate(this Image source, Action operation) where TPixel : struct, IPixel { - Guard.NotNull(operation, nameof(operation)); Guard.NotNull(source, nameof(source)); + Guard.NotNull(operation, nameof(operation)); + source.EnsureNotDisposed(); IInternalImageProcessingContext operationsRunner = source.GetConfiguration().ImageOperationsProvider .CreateImageProcessingContext(source, true); @@ -51,8 +56,9 @@ namespace SixLabors.ImageSharp.Processing public static void Mutate(this Image source, params IImageProcessor[] operations) where TPixel : struct, IPixel { - Guard.NotNull(operations, nameof(operations)); Guard.NotNull(source, nameof(source)); + Guard.NotNull(operations, nameof(operations)); + source.EnsureNotDisposed(); IInternalImageProcessingContext operationsRunner = source.GetConfiguration().ImageOperationsProvider .CreateImageProcessingContext(source, true); @@ -67,7 +73,11 @@ namespace SixLabors.ImageSharp.Processing /// The new . public static Image Clone(this Image source, Action operation) { - ProcessingVisitor visitor = new ProcessingVisitor(operation, false); + Guard.NotNull(source, nameof(source)); + Guard.NotNull(operation, nameof(operation)); + source.EnsureNotDisposed(); + + var visitor = new ProcessingVisitor(operation, false); source.AcceptVisitor(visitor); return visitor.ResultImage; } @@ -82,8 +92,9 @@ namespace SixLabors.ImageSharp.Processing public static Image Clone(this Image source, Action operation) where TPixel : struct, IPixel { - Guard.NotNull(operation, nameof(operation)); Guard.NotNull(source, nameof(source)); + Guard.NotNull(operation, nameof(operation)); + source.EnsureNotDisposed(); IInternalImageProcessingContext operationsRunner = source.GetConfiguration().ImageOperationsProvider .CreateImageProcessingContext(source, false); @@ -101,8 +112,9 @@ namespace SixLabors.ImageSharp.Processing public static Image Clone(this Image source, params IImageProcessor[] operations) where TPixel : struct, IPixel { - Guard.NotNull(operations, nameof(operations)); Guard.NotNull(source, nameof(source)); + Guard.NotNull(operations, nameof(operations)); + source.EnsureNotDisposed(); IInternalImageProcessingContext operationsRunner = source.GetConfiguration().ImageOperationsProvider .CreateImageProcessingContext(source, false); @@ -152,4 +164,4 @@ namespace SixLabors.ImageSharp.Processing } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Extensions/ResizeExtensions.cs b/src/ImageSharp/Processing/Extensions/ResizeExtensions.cs index 4578b4353f..81b1c2c663 100644 --- a/src/ImageSharp/Processing/Extensions/ResizeExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/ResizeExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/RotateFlipExtensions.cs b/src/ImageSharp/Processing/Extensions/RotateFlipExtensions.cs index 4d5d90c30e..0e4ad4066c 100644 --- a/src/ImageSharp/Processing/Extensions/RotateFlipExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/RotateFlipExtensions.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing { /// diff --git a/src/ImageSharp/Processing/Extensions/SaturateExtensions.cs b/src/ImageSharp/Processing/Extensions/SaturateExtensions.cs index e9ba820b6c..a94a9a407d 100644 --- a/src/ImageSharp/Processing/Extensions/SaturateExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/SaturateExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Extensions/SepiaExtensions.cs b/src/ImageSharp/Processing/Extensions/SepiaExtensions.cs index 5ee5151fae..df32307f47 100644 --- a/src/ImageSharp/Processing/Extensions/SepiaExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/SepiaExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/KnownFilterMatrices.cs b/src/ImageSharp/Processing/KnownFilterMatrices.cs index 9c725d0277..1f36e2593a 100644 --- a/src/ImageSharp/Processing/KnownFilterMatrices.cs +++ b/src/ImageSharp/Processing/KnownFilterMatrices.cs @@ -1,10 +1,10 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using SixLabors.ImageSharp.Primitives; -// Many of these matrices are tranlated from Chromium project where +// Many of these matrices are translated from Chromium project where // SkScalar[] is memory-mapped to a row-major matrix. // The following translates to our column-major form: // @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Processing /// /// Gets an approximated black and white filter /// - public static ColorMatrix BlackWhiteFilter { get; } = new ColorMatrix() + public static ColorMatrix BlackWhiteFilter { get; } = new ColorMatrix { M11 = 1.5F, M12 = 1.5F, @@ -461,4 +461,4 @@ namespace SixLabors.ImageSharp.Processing }; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/KnownResamplers.cs b/src/ImageSharp/Processing/KnownResamplers.cs index 70a413ec07..621215b280 100644 --- a/src/ImageSharp/Processing/KnownResamplers.cs +++ b/src/ImageSharp/Processing/KnownResamplers.cs @@ -70,12 +70,12 @@ namespace SixLabors.ImageSharp.Processing /// /// Gets the Robidoux sampler. This algorithm developed by Nicolas Robidoux providing a very good equilibrium between - /// detail preservation (sharpness) and smoothness comprable to . + /// detail preservation (sharpness) and smoothness comparable to . /// public static IResampler Robidoux { get; } = new RobidouxResampler(); /// - /// Gets the Robidoux Sharp sampler. A sharpend form of the sampler + /// Gets the Robidoux Sharp sampler. A sharpened form of the sampler /// public static IResampler RobidouxSharp { get; } = new RobidouxSharpResampler(); @@ -91,7 +91,7 @@ namespace SixLabors.ImageSharp.Processing public static IResampler Triangle { get; } = new TriangleResampler(); /// - /// Gets the Welch sampler. A high speed algorthm that delivers very sharpened results. + /// Gets the Welch sampler. A high speed algorithm that delivers very sharpened results. /// public static IResampler Welch { get; } = new WelchResampler(); } diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs index 8129836641..840d1c1f46 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; - using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Dithering; diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs index 83701aa8a2..7f00d0219d 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; - using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Binarization diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs new file mode 100644 index 0000000000..ede68e3191 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs @@ -0,0 +1,121 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Processors.Convolution +{ + /// + /// Applies bokeh blur processing to the image. + /// + public sealed class BokehBlurProcessor : IImageProcessor + { + /// + /// The default radius used by the parameterless constructor. + /// + public const int DefaultRadius = 32; + + /// + /// The default component count used by the parameterless constructor. + /// + public const int DefaultComponents = 2; + + /// + /// The default gamma used by the parameterless constructor. + /// + public const float DefaultGamma = 3F; + + /// + /// The default execution mode used by the parameterless constructor. + /// + public const BokehBlurExecutionMode DefaultExecutionMode = BokehBlurExecutionMode.PreferLowMemoryUsage; + + /// + /// Initializes a new instance of the class. + /// + public BokehBlurProcessor() + : this(DefaultRadius, DefaultComponents, DefaultGamma, DefaultExecutionMode) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The execution mode to use when applying the processor. + /// + public BokehBlurProcessor(BokehBlurExecutionMode executionMode) + : this(DefaultRadius, DefaultComponents, DefaultGamma, executionMode) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The 'radius' value representing the size of the area to sample. + /// + /// + /// The number of components to use to approximate the original 2D bokeh blur convolution kernel. + /// + /// + /// The gamma highlight factor to use to further process the image. + /// + public BokehBlurProcessor(int radius, int components, float gamma) + : this(radius, components, gamma, DefaultExecutionMode) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The 'radius' value representing the size of the area to sample. + /// + /// + /// The number of components to use to approximate the original 2D bokeh blur convolution kernel. + /// + /// + /// The gamma highlight factor to use to further process the image. + /// + /// + /// The execution mode to use when applying the processor. + /// + public BokehBlurProcessor(int radius, int components, float gamma, BokehBlurExecutionMode executionMode) + { + Guard.MustBeGreaterThanOrEqualTo(gamma, 1, nameof(gamma)); + + this.Radius = radius; + this.Components = components; + this.Gamma = gamma; + this.ExecutionMode = executionMode; + } + + /// + /// Gets the radius. + /// + public int Radius { get; } + + /// + /// Gets the number of components. + /// + public int Components { get; } + + /// + /// Gets the gamma highlight factor to use when applying the effect. + /// + public float Gamma { get; } + + /// + /// Gets the execution mode to use when applying the effect. + /// + public BokehBlurExecutionMode ExecutionMode { get; } + + /// + public IImageProcessor CreatePixelSpecificProcessor() + where TPixel : struct, IPixel + { + return new BokehBlurProcessor(this); + } + } +} diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs new file mode 100644 index 0000000000..a083026c37 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs @@ -0,0 +1,585 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.ParallelUtils; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Processors.Convolution.Parameters; +using SixLabors.Memory; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Processors.Convolution +{ + /// + /// Applies bokeh blur processing to the image. + /// + /// The pixel format. + /// This processor is based on the code from Mike Pound, see github.com/mikepound/convolve. + internal class BokehBlurProcessor : ImageProcessor + where TPixel : struct, IPixel + { + /// + /// The kernel radius. + /// + private readonly int radius; + + /// + /// The gamma highlight factor to use when applying the effect + /// + private readonly float gamma; + + /// + /// The execution mode to use when applying the effect + /// + private readonly BokehBlurExecutionMode executionMode; + + /// + /// The maximum size of the kernel in either direction + /// + private readonly int kernelSize; + + /// + /// The number of components to use when applying the bokeh blur + /// + private readonly int componentsCount; + + /// + /// The kernel parameters to use for the current instance (a: X, b: Y, A: Z, B: W) + /// + private readonly Vector4[] kernelParameters; + + /// + /// The kernel components for the current instance + /// + private readonly Complex64[][] kernels; + + /// + /// The scaling factor for kernel values + /// + private readonly float kernelsScale; + + /// + /// The mapping of initialized complex kernels and parameters, to speed up the initialization of new instances + /// + private static readonly ConcurrentDictionary Cache = new ConcurrentDictionary(); + + /// + /// Initializes a new instance of the class. + /// + /// The defining the processor parameters. + public BokehBlurProcessor(BokehBlurProcessor definition) + { + this.radius = definition.Radius; + this.kernelSize = (this.radius * 2) + 1; + this.componentsCount = definition.Components; + this.gamma = definition.Gamma; + this.executionMode = definition.ExecutionMode; + + // Reuse the initialized values from the cache, if possible + var parameters = new BokehBlurParameters(this.radius, this.componentsCount); + if (Cache.TryGetValue(parameters, out BokehBlurKernelData info)) + { + this.kernelParameters = info.Parameters; + this.kernelsScale = info.Scale; + this.kernels = info.Kernels; + } + else + { + // Initialize the complex kernels and parameters with the current arguments + (this.kernelParameters, this.kernelsScale) = this.GetParameters(); + this.kernels = this.CreateComplexKernels(); + this.NormalizeKernels(); + + // Store them in the cache for future use + Cache.TryAdd(parameters, new BokehBlurKernelData(this.kernelParameters, this.kernelsScale, this.kernels)); + } + } + + /// + /// Gets the complex kernels to use to apply the blur for the current instance + /// + public IReadOnlyList Kernels => this.kernels; + + /// + /// Gets the kernel parameters used to compute the pixel values from each complex pixel + /// + public IReadOnlyList KernelParameters => this.kernelParameters; + + /// + /// Gets the kernel scales to adjust the component values in each kernel + /// + private static IReadOnlyList KernelScales { get; } = new[] { 1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f }; + + /// + /// Gets the available bokeh blur kernel parameters + /// + private static IReadOnlyList KernelComponents { get; } = new[] + { + // 1 component + new[] { new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f) }, + + // 2 components + new[] + { + new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f), + new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f) + }, + + // 3 components + new[] + { + new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f), + new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f), + new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f) + }, + + // 4 components + new[] + { + new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f), + new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f), + new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f), + new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f) + }, + + // 5 components + new[] + { + new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f), + new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f), + new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f), + new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f), + new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f) + }, + + // 6 components + new[] + { + new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f), + new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f), + new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f), + new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f), + new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f), + new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f) + } + }; + + /// + /// Gets the kernel parameters and scaling factor for the current count value in the current instance + /// + private (Vector4[] Parameters, float Scale) GetParameters() + { + // Prepare the kernel components + int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Count)); + return (KernelComponents[index], KernelScales[index]); + } + + /// + /// Creates the collection of complex 1D kernels with the specified parameters + /// + private Complex64[][] CreateComplexKernels() + { + var kernels = new Complex64[this.kernelParameters.Length][]; + ref Vector4 baseRef = ref MemoryMarshal.GetReference(this.kernelParameters.AsSpan()); + for (int i = 0; i < this.kernelParameters.Length; i++) + { + ref Vector4 paramsRef = ref Unsafe.Add(ref baseRef, i); + kernels[i] = this.CreateComplex1DKernel(paramsRef.X, paramsRef.Y); + } + + return kernels; + } + + /// + /// Creates a complex 1D kernel with the specified parameters + /// + /// The exponential parameter for each complex component + /// The angle component for each complex component + private Complex64[] CreateComplex1DKernel(float a, float b) + { + var kernel = new Complex64[this.kernelSize]; + ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel.AsSpan()); + int r = this.radius, n = -r; + + for (int i = 0; i < this.kernelSize; i++, n++) + { + // Incrementally compute the range values + float value = n * this.kernelsScale * (1f / r); + value *= value; + + // Fill in the complex kernel values + Unsafe.Add(ref baseRef, i) = new Complex64( + MathF.Exp(-a * value) * MathF.Cos(b * value), + MathF.Exp(-a * value) * MathF.Sin(b * value)); + } + + return kernel; + } + + /// + /// Normalizes the kernels with respect to A * real + B * imaginary + /// + private void NormalizeKernels() + { + // Calculate the complex weighted sum + float total = 0; + Span kernelsSpan = this.kernels.AsSpan(); + ref Complex64[] baseKernelsRef = ref MemoryMarshal.GetReference(kernelsSpan); + ref Vector4 baseParamsRef = ref MemoryMarshal.GetReference(this.kernelParameters.AsSpan()); + + for (int i = 0; i < this.kernelParameters.Length; i++) + { + ref Complex64[] kernelRef = ref Unsafe.Add(ref baseKernelsRef, i); + int length = kernelRef.Length; + ref Complex64 valueRef = ref kernelRef[0]; + ref Vector4 paramsRef = ref Unsafe.Add(ref baseParamsRef, i); + + for (int j = 0; j < length; j++) + { + for (int k = 0; k < length; k++) + { + ref Complex64 jRef = ref Unsafe.Add(ref valueRef, j); + ref Complex64 kRef = ref Unsafe.Add(ref valueRef, k); + total += + (paramsRef.Z * ((jRef.Real * kRef.Real) - (jRef.Imaginary * kRef.Imaginary))) + + (paramsRef.W * ((jRef.Real * kRef.Imaginary) + (jRef.Imaginary * kRef.Real))); + } + } + } + + // Normalize the kernels + float scalar = 1f / MathF.Sqrt(total); + for (int i = 0; i < kernelsSpan.Length; i++) + { + ref Complex64[] kernelsRef = ref Unsafe.Add(ref baseKernelsRef, i); + int length = kernelsRef.Length; + ref Complex64 valueRef = ref kernelsRef[0]; + + for (int j = 0; j < length; j++) + { + Unsafe.Add(ref valueRef, j) *= scalar; + } + } + } + + /// + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + { + // Preliminary gamma highlight pass + this.ApplyGammaExposure(source.PixelBuffer, sourceRectangle, configuration); + + // Create a 0-filled buffer to use to store the result of the component convolutions + using (Buffer2D processing = configuration.MemoryAllocator.Allocate2D(source.Size(), AllocationOptions.Clean)) + { + if (this.executionMode == BokehBlurExecutionMode.PreferLowMemoryUsage) + { + // Memory usage priority: allocate a shared buffer and execute the second convolution in sequential mode + using (Buffer2D buffer = configuration.MemoryAllocator.Allocate2D(source.Width, source.Height + this.radius)) + using (Buffer2D firstPassBuffer = buffer.Slice(this.radius, source.Height)) + using (Buffer2D secondPassBuffer = buffer.Slice(0, source.Height)) + { + this.OnFrameApplyCore(source, sourceRectangle, configuration, processing, firstPassBuffer, secondPassBuffer); + } + } + else + { + // Performance priority: allocate two independent buffers and execute both convolutions in parallel mode + using (Buffer2D firstPassValues = configuration.MemoryAllocator.Allocate2D(source.Size())) + using (Buffer2D secondPassBuffer = configuration.MemoryAllocator.Allocate2D(source.Size())) + { + this.OnFrameApplyCore(source, sourceRectangle, configuration, processing, firstPassValues, secondPassBuffer); + } + } + + // Apply the inverse gamma exposure pass, and write the final pixel data + this.ApplyInverseGammaExposure(source.PixelBuffer, processing, sourceRectangle, configuration); + } + } + + /// + /// Computes and aggregates the convolution for each complex kernel component in the processor. + /// + /// The source image. Cannot be null. + /// The structure that specifies the portion of the image object to draw. + /// The configuration. + /// The buffer with the raw pixel data to use to aggregate the results of each convolution. + /// The complex buffer to use for the first 1D convolution pass for each kernel. + /// The complex buffer to use for the second 1D convolution pass for each kernel. + private void OnFrameApplyCore( + ImageFrame source, + Rectangle sourceRectangle, + Configuration configuration, + Buffer2D processingBuffer, + Buffer2D firstPassBuffer, + Buffer2D secondPassBuffer) + { + // Perform two 1D convolutions for each component in the current instance + ref Complex64[] baseRef = ref MemoryMarshal.GetReference(this.kernels.AsSpan()); + for (int i = 0; i < this.kernels.Length; i++) + { + // Compute the resulting complex buffer for the current component + var interest = Rectangle.Intersect(sourceRectangle, source.Bounds()); + Complex64[] kernel = Unsafe.Add(ref baseRef, i); + this.ApplyConvolution(firstPassBuffer, source.PixelBuffer, interest, kernel, configuration); + this.ApplyConvolution(secondPassBuffer, firstPassBuffer, interest, kernel, configuration); + + // Add the results of the convolution with the current kernel + Vector4 parameters = this.kernelParameters[i]; + this.SumProcessingPartials(processingBuffer, secondPassBuffer, sourceRectangle, configuration, parameters.Z, parameters.W); + } + } + + /// + /// Applies the process to the specified portion of the specified at the specified location + /// and with the specified size. + /// + /// The target values to use to store the results. + /// The source pixels. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + /// The 1D kernel. + /// The + private void ApplyConvolution( + Buffer2D targetValues, + Buffer2D sourcePixels, + Rectangle sourceRectangle, + Complex64[] kernel, + Configuration configuration) + { + int startY = sourceRectangle.Y; + int endY = sourceRectangle.Bottom; + int startX = sourceRectangle.X; + int endX = sourceRectangle.Right; + int maxY = endY - 1; + int maxX = endX - 1; + + var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); + int width = workingRectangle.Width; + + ParallelHelper.IterateRows( + workingRectangle, + configuration, + rows => + { + for (int y = rows.Min; y < rows.Max; y++) + { + Span targetRowSpan = targetValues.GetRowSpan(y).Slice(startX); + + for (int x = 0; x < width; x++) + { + Buffer2DUtils.Convolve4(kernel, sourcePixels, targetRowSpan, y, x, startY, maxY, startX, maxX); + } + } + }); + } + + /// + /// Applies the process to the specified portion of the specified buffer at the specified location + /// and with the specified size. + /// + /// The target values to use to store the results. + /// The source complex values. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + /// The 1D kernel. + /// The + private void ApplyConvolution( + Buffer2D targetValues, + Buffer2D sourceValues, + Rectangle sourceRectangle, + Complex64[] kernel, + Configuration configuration) + { + int startY = sourceRectangle.Y; + int endY = sourceRectangle.Bottom; + int startX = sourceRectangle.X; + int endX = sourceRectangle.Right; + int maxY = endY - 1; + int maxX = endX - 1; + + var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); + int width = workingRectangle.Width; + + if (this.executionMode == BokehBlurExecutionMode.PreferLowMemoryUsage) + { + configuration = configuration.Clone(); + configuration.MaxDegreeOfParallelism = 1; + } + + ParallelHelper.IterateRows( + workingRectangle, + configuration, + rows => + { + for (int y = rows.Min; y < rows.Max; y++) + { + Span targetRowSpan = targetValues.GetRowSpan(y).Slice(startX); + + for (int x = 0; x < width; x++) + { + Buffer2DUtils.Convolve4(kernel, sourceValues, targetRowSpan, y, x, startY, maxY, startX, maxX); + } + } + }); + } + + /// + /// Applies the gamma correction/highlight to the input pixel buffer. + /// + /// The target pixel buffer to adjust. + /// + /// The structure that specifies the portion of the image object to draw. + /// + /// The + private void ApplyGammaExposure( + Buffer2D targetPixels, + Rectangle sourceRectangle, + Configuration configuration) + { + int startY = sourceRectangle.Y; + int endY = sourceRectangle.Bottom; + int startX = sourceRectangle.X; + int endX = sourceRectangle.Right; + + var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); + int width = workingRectangle.Width; + float exp = this.gamma; + + ParallelHelper.IterateRowsWithTempBuffer( + workingRectangle, + configuration, + (rows, vectorBuffer) => + { + Span vectorSpan = vectorBuffer.Span; + int length = vectorSpan.Length; + + for (int y = rows.Min; y < rows.Max; y++) + { + Span targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX); + PixelOperations.Instance.ToVector4(configuration, targetRowSpan.Slice(0, length), vectorSpan, PixelConversionModifiers.Premultiply); + ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectorSpan); + + for (int x = 0; x < width; x++) + { + ref Vector4 v = ref Unsafe.Add(ref baseRef, x); + v.X = MathF.Pow(v.X, exp); + v.Y = MathF.Pow(v.Y, exp); + v.Z = MathF.Pow(v.Z, exp); + } + + PixelOperations.Instance.FromVector4Destructive(configuration, vectorSpan.Slice(0, length), targetRowSpan); + } + }); + } + + /// + /// Applies the inverse gamma correction/highlight pass, and converts the input buffer into pixel values. + /// + /// The target pixels to apply the process to. + /// The source values. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + /// The + private void ApplyInverseGammaExposure( + Buffer2D targetPixels, + Buffer2D sourceValues, + Rectangle sourceRectangle, + Configuration configuration) + { + int startY = sourceRectangle.Y; + int endY = sourceRectangle.Bottom; + int startX = sourceRectangle.X; + int endX = sourceRectangle.Right; + + var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); + int width = workingRectangle.Width; + float expGamma = 1 / this.gamma; + + ParallelHelper.IterateRows( + workingRectangle, + configuration, + rows => + { + Vector4 low = Vector4.Zero; + var high = new Vector4(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); + + for (int y = rows.Min; y < rows.Max; y++) + { + Span targetPixelSpan = targetPixels.GetRowSpan(y).Slice(startX); + Span sourceRowSpan = sourceValues.GetRowSpan(y).Slice(startX); + ref Vector4 sourceRef = ref MemoryMarshal.GetReference(sourceRowSpan); + + for (int x = 0; x < width; x++) + { + ref Vector4 v = ref Unsafe.Add(ref sourceRef, x); + var clamp = Vector4.Clamp(v, low, high); + v.X = MathF.Pow(clamp.X, expGamma); + v.Y = MathF.Pow(clamp.Y, expGamma); + v.Z = MathF.Pow(clamp.Z, expGamma); + } + + PixelOperations.Instance.FromVector4Destructive(configuration, sourceRowSpan.Slice(0, width), targetPixelSpan, PixelConversionModifiers.Premultiply); + } + }); + } + + /// + /// Applies the process to the specified portion of the specified at the specified location + /// and with the specified size. + /// + /// The target instance to use to store the results. + /// The source complex pixels. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + /// The + /// The weight factor for the real component of the complex pixel values. + /// The weight factor for the imaginary component of the complex pixel values. + private void SumProcessingPartials( + Buffer2D targetValues, + Buffer2D sourceValues, + Rectangle sourceRectangle, + Configuration configuration, + float z, + float w) + { + int startY = sourceRectangle.Y; + int endY = sourceRectangle.Bottom; + int startX = sourceRectangle.X; + int endX = sourceRectangle.Right; + + var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); + int width = workingRectangle.Width; + + ParallelHelper.IterateRows( + workingRectangle, + configuration, + rows => + { + for (int y = rows.Min; y < rows.Max; y++) + { + Span targetRowSpan = targetValues.GetRowSpan(y).Slice(startX); + Span sourceRowSpan = sourceValues.GetRowSpan(y).Slice(startX); + ref Vector4 baseTargetRef = ref MemoryMarshal.GetReference(targetRowSpan); + ref ComplexVector4 baseSourceRef = ref MemoryMarshal.GetReference(sourceRowSpan); + + for (int x = 0; x < width; x++) + { + Unsafe.Add(ref baseTargetRef, x) += Unsafe.Add(ref baseSourceRef, x).WeightedSum(z, w); + } + } + }); + } + } +} diff --git a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs index 4e56e75d39..726947ac91 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs @@ -1,8 +1,7 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Primitives; namespace SixLabors.ImageSharp.Processing.Processors.Convolution { @@ -47,4 +46,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution return new BoxBlurProcessor(this); } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs index 764f4ca517..8504db1617 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Primitives; namespace SixLabors.ImageSharp.Processing.Processors.Convolution { diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs index 23282af36d..75acc90e0c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Convolution diff --git a/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs index 9c9488fec0..ab6658f3b2 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelData.cs b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelData.cs new file mode 100644 index 0000000000..4338bcf6b9 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelData.cs @@ -0,0 +1,43 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Numerics; + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Processors.Convolution.Parameters +{ + /// + /// A that contains data about a set of bokeh blur kernels + /// + internal readonly struct BokehBlurKernelData + { + /// + /// The kernel parameters to use for the current set of complex kernels + /// + public readonly Vector4[] Parameters; + + /// + /// The scaling factor for the kernel values + /// + public readonly float Scale; + + /// + /// The kernel components to apply the bokeh blur effect + /// + public readonly Complex64[][] Kernels; + + /// + /// Initializes a new instance of the struct. + /// + /// The kernel parameters + /// The kernel scale factor + /// The complex kernel components + public BokehBlurKernelData(Vector4[] parameters, float scale, Complex64[][] kernels) + { + this.Parameters = parameters; + this.Scale = scale; + this.Kernels = kernels; + } + } +} diff --git a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurParameters.cs b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurParameters.cs new file mode 100644 index 0000000000..73688c5869 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurParameters.cs @@ -0,0 +1,52 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; + +namespace SixLabors.ImageSharp.Processing.Processors.Convolution.Parameters +{ + /// + /// A that contains parameters to apply a bokeh blur filter + /// + internal readonly struct BokehBlurParameters : IEquatable + { + /// + /// The size of the convolution kernel to use when applying the bokeh blur + /// + public readonly int Radius; + + /// + /// The number of complex components to use to approximate the bokeh kernel + /// + public readonly int Components; + + /// + /// Initializes a new instance of the struct. + /// + /// The size of the kernel + /// The number of kernel components + public BokehBlurParameters(int radius, int components) + { + this.Radius = radius; + this.Components = components; + } + + /// + public bool Equals(BokehBlurParameters other) + { + return this.Radius.Equals(other.Radius) && this.Components.Equals(other.Components); + } + + /// + public override bool Equals(object obj) => obj is BokehBlurParameters other && this.Equals(other); + + /// + public override int GetHashCode() + { + unchecked + { + return (this.Radius.GetHashCode() * 397) ^ this.Components.GetHashCode(); + } + } + } +} diff --git a/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs index a9db37a076..ca7d8895a8 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs index fd73789027..6f5373fae5 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs @@ -1,9 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Primitives; - namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs index ec0183dc63..da76aa971c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs index 3d5d1e7bf1..5fb32f4e62 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs @@ -1,9 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; - namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// diff --git a/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs b/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs index e0b79c2b20..e612b4bf03 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs @@ -3,8 +3,6 @@ using System; -using SixLabors.ImageSharp.Processing.Processors.Binarization; - namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs index 7efb71fa1c..d31858ba15 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs @@ -69,10 +69,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects int maxIntensity = 0; int maxIndex = 0; - int[] intensityBin = new int[levels]; - float[] redBin = new float[levels]; - float[] blueBin = new float[levels]; - float[] greenBin = new float[levels]; + var intensityBin = new int[levels]; + var redBin = new float[levels]; + var blueBin = new float[levels]; + var greenBin = new float[levels]; for (int fy = 0; fy <= radius; fy++) { @@ -126,4 +126,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs index ae6d5f6f79..71d3f9c9cc 100644 --- a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs @@ -1,9 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; - namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// diff --git a/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs index 012b10ee03..30484f0590 100644 --- a/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// diff --git a/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs index 922ca32330..a537b8f606 100644 --- a/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs index 333444eb39..537a3089ec 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs @@ -51,10 +51,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { int sourceWidth = source.Width; int sourceHeight = source.Height; - int numberOfPixels = sourceWidth * sourceHeight; int tileWidth = (int)MathF.Ceiling(sourceWidth / (float)this.Tiles); int tileHeight = (int)MathF.Ceiling(sourceHeight / (float)this.Tiles); - int pixelsInTile = tileWidth * tileHeight; + int tileCount = this.Tiles; int halfTileWidth = tileWidth / 2; int halfTileHeight = tileHeight / 2; int luminanceLevels = this.LuminanceLevels; @@ -75,36 +74,33 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization Parallel.For( 0, tileYStartPositions.Count, - new ParallelOptions() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism }, + new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism }, index => { - int cdfX = 0; - int tileX = 0; - int tileY = 0; int y = tileYStartPositions[index].y; int cdfYY = tileYStartPositions[index].cdfY; // It's unfortunate that we have to do this per iteration. ref TPixel sourceBase = ref source.GetPixelReference(0, 0); - cdfX = 0; + int cdfX = 0; for (int x = halfTileWidth; x < sourceWidth - halfTileWidth; x += tileWidth) { - tileY = 0; + int tileY = 0; int yEnd = Math.Min(y + tileHeight, sourceHeight); int xEnd = Math.Min(x + tileWidth, sourceWidth); for (int dy = y; dy < yEnd; dy++) { int dyOffSet = dy * sourceWidth; - tileX = 0; + int tileX = 0; for (int dx = x; dx < xEnd; dx++) { ref TPixel pixel = ref Unsafe.Add(ref sourceBase, dyOffSet + dx); float luminanceEqualized = InterpolateBetweenFourTiles( pixel, cdfData, - this.Tiles, - this.Tiles, + tileCount, + tileCount, tileX, tileY, cdfX, @@ -222,7 +218,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization int xEnd, int luminanceLevels) { - int halfTileWidth = tileWidth / 2; int halfTileHeight = tileHeight / 2; int cdfY = 0; @@ -233,13 +228,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization for (int dy = y; dy < yLimit; dy++) { int dyOffSet = dy * sourceWidth; - int tileX = halfTileWidth; for (int dx = xStart; dx < xEnd; dx++) { ref TPixel pixel = ref Unsafe.Add(ref pixelBase, dyOffSet + dx); float luminanceEqualized = InterpolateBetweenTwoTiles(pixel, cdfData, cdfX, cdfY, cdfX, cdfY + 1, tileY, tileHeight, luminanceLevels); pixel.FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, pixel.ToVector4().W)); - tileX++; } tileY++; @@ -278,7 +271,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization int cdfX = 0; for (int x = halfTileWidth; x < sourceWidth - halfTileWidth; x += tileWidth) { - int tileY = 0; for (int dy = yStart; dy < yEnd; dy++) { int dyOffSet = dy * sourceWidth; @@ -291,8 +283,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization pixel.FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, pixel.ToVector4().W)); tileX++; } - - tileY++; } cdfX++; @@ -467,12 +457,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization int tileWidth = this.tileWidth; int tileHeight = this.tileHeight; int luminanceLevels = this.luminanceLevels; - MemoryAllocator memoryAllocator = this.memoryAllocator; Parallel.For( 0, this.tileYStartPositions.Count, - new ParallelOptions() { MaxDegreeOfParallelism = this.configuration.MaxDegreeOfParallelism }, + new ParallelOptions { MaxDegreeOfParallelism = this.configuration.MaxDegreeOfParallelism }, index => { int cdfX = 0; @@ -498,8 +487,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization int dyOffset = dy * sourceWidth; for (int dx = x; dx < xlimit; dx++) { - int luminace = GetLuminance(Unsafe.Add(ref sourceBase, dyOffset + dx), luminanceLevels); - histogram[luminace]++; + int luminance = GetLuminance(Unsafe.Add(ref sourceBase, dyOffset + dx), luminanceLevels); + histogram[luminance]++; } } @@ -543,4 +532,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs index 40e2d41d9b..377af51354 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs @@ -49,16 +49,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { MemoryAllocator memoryAllocator = configuration.MemoryAllocator; - int numberOfPixels = source.Width * source.Height; - Span pixels = source.GetPixelSpan(); - var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism }; + var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism }; int tileWidth = source.Width / this.Tiles; int tileHeight = tileWidth; - int pixeInTile = tileWidth * tileHeight; + int pixelInTile = tileWidth * tileHeight; int halfTileHeight = tileHeight / 2; int halfTileWidth = halfTileHeight; - var slidingWindowInfos = new SlidingWindowInfos(tileWidth, tileHeight, halfTileWidth, halfTileHeight, pixeInTile); + var slidingWindowInfos = new SlidingWindowInfos(tileWidth, tileHeight, halfTileWidth, halfTileHeight, pixelInTile); using (Buffer2D targetPixels = configuration.MemoryAllocator.Allocate2D(source.Width, source.Height)) { @@ -149,7 +147,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization /// The source image. /// The memory allocator. /// The target pixels. - /// Informations about the sliding window dimensions. + /// about the sliding window dimensions. /// The y start position. /// The y end position. /// if set to true the borders of the image will not be checked. @@ -204,7 +202,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { // Clipping the histogram, but doing it on a copy to keep the original un-clipped values for the next iteration. histogram.CopyTo(histogramCopy); - this.ClipHistogram(histogramCopy, this.ClipLimitPercentage, swInfos.PixeInTile); + this.ClipHistogram(histogramCopy, this.ClipLimitPercentage, swInfos.PixelInTile); } // Calculate the cumulative distribution function, which will map each input pixel in the current tile to a new value. @@ -212,7 +210,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization ? this.CalculateCdf(ref cdfBase, ref histogramCopyBase, histogram.Length - 1) : this.CalculateCdf(ref cdfBase, ref histogramBase, histogram.Length - 1); - float numberOfPixelsMinusCdfMin = swInfos.PixeInTile - cdfMin; + float numberOfPixelsMinusCdfMin = swInfos.PixelInTile - cdfMin; // Map the current pixel to the new equalized value. int luminance = GetLuminance(source[x, y], this.LuminanceLevels); @@ -367,24 +365,24 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization private class SlidingWindowInfos { - public SlidingWindowInfos(int tileWidth, int tileHeight, int halfTileWidth, int halfTileHeight, int pixeInTile) + public SlidingWindowInfos(int tileWidth, int tileHeight, int halfTileWidth, int halfTileHeight, int pixelInTile) { this.TileWidth = tileWidth; this.TileHeight = tileHeight; this.HalfTileWidth = halfTileWidth; this.HalfTileHeight = halfTileHeight; - this.PixeInTile = pixeInTile; + this.PixelInTile = pixelInTile; } public int TileWidth { get; private set; } public int TileHeight { get; private set; } - public int PixeInTile { get; private set; } + public int PixelInTile { get; private set; } public int HalfTileWidth { get; private set; } public int HalfTileHeight { get; private set; } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs index b3a1603e6f..a790263fa1 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs @@ -42,7 +42,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { MemoryAllocator memoryAllocator = configuration.MemoryAllocator; int numberOfPixels = source.Width * source.Height; - Span pixels = source.GetPixelSpan(); var workingRect = new Rectangle(0, 0, source.Width, source.Height); using (IMemoryOwner histogramBuffer = memoryAllocator.Allocate(this.LuminanceLevels, AllocationOptions.Clean)) @@ -104,4 +103,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs index ba434a4b21..17734bcdc0 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization public IFrameQuantizer CreateFrameQuantizer(Configuration configuration) where TPixel : struct, IPixel { - TPixel[] palette = new TPixel[this.Palette.Length]; + var palette = new TPixel[this.Palette.Length]; Color.ToPixel(configuration, this.Palette.Span, palette.AsSpan()); return new PaletteFrameQuantizer(this.Diffuser, palette); } @@ -71,11 +71,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization maxColors = maxColors.Clamp(QuantizerConstants.MinColors, QuantizerConstants.MaxColors); int max = Math.Min(maxColors, this.Palette.Length); - TPixel[] palette = new TPixel[max]; + var palette = new TPixel[max]; Color.ToPixel(configuration, this.Palette.Span.Slice(0, max), palette.AsSpan()); return new PaletteFrameQuantizer(this.Diffuser, palette); } private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null; } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Quantization/WebSafePaletteQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/WebSafePaletteQuantizer.cs index 3f6dfde281..c912572f0e 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WebSafePaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WebSafePaletteQuantizer.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Dithering; namespace SixLabors.ImageSharp.Processing.Processors.Quantization diff --git a/src/ImageSharp/Processing/Processors/Quantization/WernerPaletteQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/WernerPaletteQuantizer.cs index d659ecabf7..cd320a9a36 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WernerPaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WernerPaletteQuantizer.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Dithering; namespace SixLabors.ImageSharp.Processing.Processors.Quantization diff --git a/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs index 2b1a24aee5..87d696dc91 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -828,7 +828,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization private void BuildCube() { this.colorCube = new Box[this.colors]; - double[] vv = new double[this.colors]; + var vv = new double[this.colors]; ref Box cube = ref this.colorCube[0]; cube.RMin = cube.GMin = cube.BMin = cube.AMin = 0; @@ -985,4 +985,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs index 529a49bf7a..a33352c73b 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms Rectangle sourceRectangle, Configuration configuration) { - // Handle tranforms that result in output identical to the original. + // Handle transforms that result in output identical to the original. if (this.TransformMatrix.Equals(default) || this.TransformMatrix.Equals(Matrix3x2.Identity)) { // The clone will be blank here copy all the pixel data over @@ -133,4 +133,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs index 9bbbba843c..3eb0d998a2 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; namespace SixLabors.ImageSharp.Processing.Processors.Transforms { diff --git a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs index 80b03000b8..f95040facd 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms { Matrix4x4 transformMatrix = this.definition.TransformMatrix; - // Handle tranforms that result in output identical to the original. + // Handle transforms that result in output identical to the original. if (transformMatrix.Equals(default) || transformMatrix.Equals(Matrix4x4.Identity)) { // The clone will be blank here copy all the pixel data over diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs index dce4e70d62..14bf552b9d 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.Processing.Processors.Transforms { diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.PeriodicKernelMap.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.PeriodicKernelMap.cs index 4b81aaa64e..6d6e22a6a5 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.PeriodicKernelMap.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.PeriodicKernelMap.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; - using SixLabors.Memory; namespace SixLabors.ImageSharp.Processing.Processors.Transforms diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs index fb03057a48..b68a7f93f7 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs @@ -1,13 +1,9 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; -using System.Buffers; using System.Collections.Generic; using System.Linq; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; @@ -64,6 +60,15 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// public bool Compand => this.parameterSource.Compand; + /// + /// This is a shim for tagging the CreateDestination virtual generic method for the AoT iOS compiler. + /// This method should never be referenced outside of the AotCompiler code. + /// + /// Passed through as source to the CreateDestination method. + /// Passed through as sourceRectangle to the CreateDestination method. + /// The result returned from CreateDestination. + internal Image AotCreateDestination(Image source, Rectangle sourceRectangle) => this.CreateDestination(source, sourceRectangle); + /// protected override Image CreateDestination(Image source, Rectangle sourceRectangle) { @@ -151,8 +156,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms return; } - int sourceHeight = source.Height; - PixelConversionModifiers conversionModifiers = PixelConversionModifiers.Premultiply.ApplyCompanding(this.Compand); @@ -188,4 +191,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms this.verticalKernelMap = null; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs index cb73bb66c2..4b87d6d2c1 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs @@ -3,7 +3,6 @@ using System.Numerics; -using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Processors.Transforms diff --git a/src/ImageSharp/Processing/Processors/Transforms/TransformProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/TransformProcessor.cs index ef508549ac..f6d3299fcd 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/TransformProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TransformProcessor.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Processors.Transforms diff --git a/src/ImageSharp/Processing/Processors/Transforms/TransformUtils.cs b/src/ImageSharp/Processing/Processors/Transforms/TransformUtils.cs index 0ec8c83939..794645550e 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/TransformUtils.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TransformUtils.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms Matrix4x4 matrix = Matrix4x4.Identity; /* - * SkMatrix is layed out in the following manner: + * SkMatrix is laid out in the following manner: * * [ ScaleX SkewY Persp0 ] * [ SkewX ScaleY Persp1 ] @@ -329,7 +329,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int width = rectangle.Left < 0 ? rectangle.Right : Math.Max(rectangle.Width, rectangle.Right); // If location in either direction is translated to a negative value equal to or exceeding the - // dimensions in eith direction we need to reassign the dimension. + // dimensions in either direction we need to reassign the dimension. if (height <= 0) { height = rectangle.Height; diff --git a/src/ImageSharp/Properties/AssemblyInfo.cs b/src/ImageSharp/Properties/AssemblyInfo.cs index 2862b45851..225de354ae 100644 --- a/src/ImageSharp/Properties/AssemblyInfo.cs +++ b/src/ImageSharp/Properties/AssemblyInfo.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Runtime.CompilerServices; - // Redundant suppressing of SA1413 for Rider. [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_DivideRound.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_DivideRound.cs index 5502475d43..15a3c7eb7d 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_DivideRound.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_DivideRound.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations private static readonly Vector4 Half = new Vector4(0.5f); private Block8x8F inputDividend; - private Block8x8F inputDivisior; + private Block8x8F inputDivisor; [GlobalSetup] public void Setup() @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations for (int i = 0; i < Block8x8F.Size; i++) { this.inputDividend[i] = i*44.8f; - this.inputDivisior[i] = 100 - i; + this.inputDivisor[i] = 100 - i; } } @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations int sum = 0; Block8x8F b1 = this.inputDividend; - Block8x8F b2 = this.inputDivisior; + Block8x8F b2 = this.inputDivisor; float* pDividend = (float*)&b1; float* pDivisor = (float*)&b2; @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations int sum = 0; Block8x8F b1 = this.inputDividend; - Block8x8F b2 = this.inputDivisior; + Block8x8F b2 = this.inputDivisor; float* pDividend = (float*)&b1; float* pDivisor = (float*)&b2; @@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations int sum = 0; Block8x8F bDividend = this.inputDividend; - Block8x8F bDivisor = this.inputDivisior; + Block8x8F bDivisor = this.inputDivisor; float* pDividend = (float*)&bDividend; for (int cnt = 0; cnt < ExecutionCount; cnt++) @@ -155,4 +155,4 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations return -((-dividend + (divisor >> 1)) / divisor); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs index c7b5802c4f..09e25827c7 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. // ReSharper disable InconsistentNaming @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations { public class Block8x8F_Round { - private Block8x8F block = default(Block8x8F); + private Block8x8F block; [GlobalSetup] public void Setup() @@ -66,4 +66,4 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations row7 = SimdUtils.FastRound(row7); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs index 5a4a9ab17c..f40c15cc14 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using BenchmarkDotNet.Attributes; @@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg { using (var memoryStream = new MemoryStream(this.jpegBytes)) { - var decoder = new JpegDecoderCore(Configuration.Default, new Formats.Jpeg.JpegDecoder() { IgnoreMetadata = true }); + var decoder = new JpegDecoderCore(Configuration.Default, new Formats.Jpeg.JpegDecoder { IgnoreMetadata = true }); decoder.ParseStream(memoryStream); decoder.Dispose(); } @@ -65,4 +65,4 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg // | 'System.Drawing FULL' | Core | Core | Jpg/b(...)f.jpg [28] | 17.68 ms | 2.711 ms | 0.1486 ms | 1.00 | 0.00 | 343.7500 | - | - | 757.04 KB | // | JpegDecoderCore.ParseStream | Core | Core | Jpg/b(...)f.jpg [28] | 14.27 ms | 3.671 ms | 0.2012 ms | 0.81 | 0.00 | - | - | - | 11.76 KB | } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg_ImageSpecific.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg_ImageSpecific.cs index 62742f729b..99b071e59e 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg_ImageSpecific.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg_ImageSpecific.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Drawing; @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg { using (var memoryStream = new MemoryStream(this.jpegBytes)) { - using (var image = Image.Load(memoryStream, new JpegDecoder() { IgnoreMetadata = true })) + using (var image = Image.Load(memoryStream, new JpegDecoder { IgnoreMetadata = true })) { return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs index b0834eb52d..6f2c492d0a 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg private static byte[] CreateTestBytes() { - byte[] buffer = new byte[DoubleBufferedStreamReader.ChunkLength * 3]; + var buffer = new byte[DoubleBufferedStreamReader.ChunkLength * 3]; var random = new Random(); random.NextBytes(buffer); diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs index 8417b32f27..313a7c97d3 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -67,10 +67,10 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg float maxVal = 255f) { var rnd = new Random(42); - Buffer2D[] buffers = new Buffer2D[componentCount]; + var buffers = new Buffer2D[componentCount]; for (int i = 0; i < componentCount; i++) { - float[] values = new float[inputBufferLength]; + var values = new float[inputBufferLength]; for (int j = 0; j < inputBufferLength; j++) { @@ -84,4 +84,4 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg return buffers; } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Codecs/MultiImageBenchmarkBase.cs b/tests/ImageSharp.Benchmarks/Codecs/MultiImageBenchmarkBase.cs index 84e2d06167..bf694211de 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/MultiImageBenchmarkBase.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/MultiImageBenchmarkBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using BenchmarkDotNet.Configs; @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs } /// - /// Execute code for each image stream. If the returned object of the opearation is it will be disposed. + /// Execute code for each image stream. If the returned object of the operation is it will be disposed. /// /// The operation to execute. If the returned object is <see cref="IDisposable"/> it will be disposed protected void ForEachStream(Func operation) @@ -271,4 +271,4 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs b/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs index b4e5ab3802..0571513f56 100644 --- a/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs +++ b/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -85,7 +85,6 @@ namespace SixLabors.ImageSharp.Benchmarks } } - // Waiting for C# 7 stackalloc keyword patiently ... private static class OnStackInputCache { public unsafe struct Byte @@ -94,7 +93,7 @@ namespace SixLabors.ImageSharp.Benchmarks public static Byte Create(byte[] data) { - Byte result = default(Byte); + Byte result = default; for (int i = 0; i < data.Length; i++) { result.Data[i] = data[i]; @@ -113,9 +112,9 @@ namespace SixLabors.ImageSharp.Benchmarks // The operation is defined as "RGBA -> YCbCr Transform a stream of bytes into a stream of floats" // We need to benchmark the whole operation, to get true results, not missing any side effects! - private byte[] inputSourceRGB = null; + private byte[] inputSourceRGB; - private int[] inputSourceRGBAsInteger = null; + private int[] inputSourceRGBAsInteger; [GlobalSetup] public void Setup() @@ -133,13 +132,13 @@ namespace SixLabors.ImageSharp.Benchmarks public unsafe void RgbaToYcbCrScalarFloat() { // Copy the input to the stack: - OnStackInputCache.Byte input = OnStackInputCache.Byte.Create(this.inputSourceRGB); + var input = OnStackInputCache.Byte.Create(this.inputSourceRGB); // On-stack output: Result result = default; - float* yPtr = (float*)&result.Y; - float* cbPtr = (float*)&result.Cb; - float* crPtr = (float*)&result.Cr; + var yPtr = (float*)&result.Y; + var cbPtr = (float*)&result.Cb; + var crPtr = (float*)&result.Cr; // end of code-bloat block :) for (int i = 0; i < InputColorCount; i++) @@ -159,20 +158,20 @@ namespace SixLabors.ImageSharp.Benchmarks public unsafe void RgbaToYcbCrSimdFloat() { // Copy the input to the stack: - OnStackInputCache.Byte input = OnStackInputCache.Byte.Create(this.inputSourceRGB); + var input = OnStackInputCache.Byte.Create(this.inputSourceRGB); // On-stack output: Result result = default; - float* yPtr = (float*)&result.Y; - float* cbPtr = (float*)&result.Cb; - float* crPtr = (float*)&result.Cr; + var yPtr = (float*)&result.Y; + var cbPtr = (float*)&result.Cb; + var crPtr = (float*)&result.Cr; // end of code-bloat block :) for (int i = 0; i < InputColorCount; i++) { int i3 = i * 3; - Vector3 vectorRgb = new Vector3( + var vectorRgb = new Vector3( input.Data[i3 + 0], input.Data[i3 + 1], input.Data[i3 + 2] @@ -195,9 +194,9 @@ namespace SixLabors.ImageSharp.Benchmarks // On-stack output: Result result = default; - float* yPtr = (float*)&result.Y; - float* cbPtr = (float*)&result.Cb; - float* crPtr = (float*)&result.Cr; + var yPtr = (float*)&result.Y; + var cbPtr = (float*)&result.Cb; + var crPtr = (float*)&result.Cr; // end of code-bloat block :) var yCoeffs = new Vector(ScaledCoeffs.Y); @@ -211,7 +210,7 @@ namespace SixLabors.ImageSharp.Benchmarks for (int i = 0; i < InputColorCount; i += 2) { - Vector rgb = new Vector(this.inputSourceRGBAsInteger, i * 3); + var rgb = new Vector(this.inputSourceRGBAsInteger, i * 3); Vector y = yCoeffs * rgb; Vector cb = cbCoeffs * rgb; @@ -228,7 +227,7 @@ namespace SixLabors.ImageSharp.Benchmarks } /// - /// This should perform better. Coreclr emmitted Vector.Dot() code lacks the vectorization even with IsHardwareAccelerated == true. + /// This should perform better. Coreclr emitted Vector.Dot() code lacks the vectorization even with IsHardwareAccelerated == true. /// Kept this benchmark because maybe it will be improved in a future CLR release. /// /// https://www.gamedev.net/topic/673396-c-systemnumericsvectors-slow/ @@ -265,7 +264,7 @@ namespace SixLabors.ImageSharp.Benchmarks for (int i = 0; i < InputColorCount; i += 2) { - Vector rgb = new Vector(this.inputSourceRGBAsInteger, i * 3); + var rgb = new Vector(this.inputSourceRGBAsInteger, i * 3); Vector y = yCoeffs * rgb; Vector cb = cbCoeffs * rgb; @@ -300,10 +299,10 @@ namespace SixLabors.ImageSharp.Benchmarks public unsafe void RgbaToYcbCrScaledInteger() { // Copy the input to the stack: - OnStackInputCache.Byte input = OnStackInputCache.Byte.Create(this.inputSourceRGB); + var input = OnStackInputCache.Byte.Create(this.inputSourceRGB); // On-stack output: - Result result = default(Result); + Result result = default; float* yPtr = (float*)&result.Y; float* cbPtr = (float*)&result.Cb; float* crPtr = (float*)&result.Cr; @@ -339,10 +338,10 @@ namespace SixLabors.ImageSharp.Benchmarks public unsafe void RgbaToYcbCrScaledIntegerLut() { // Copy the input to the stack: - OnStackInputCache.Byte input = OnStackInputCache.Byte.Create(this.inputSourceRGB); + var input = OnStackInputCache.Byte.Create(this.inputSourceRGB); // On-stack output: - Result result = default(Result); + Result result = default; float* yPtr = (float*)&result.Y; float* cbPtr = (float*)&result.Cb; float* crPtr = (float*)&result.Cr; diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index 8999afaeda..8f4a7dfcb7 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Drawing; @@ -48,12 +48,10 @@ namespace SixLabors.ImageSharp.Benchmarks image.Mutate(x => x.DrawBeziers( Rgba32.HotPink, 10, - new SixLabors.Primitives.PointF[] { - new Vector2(10, 500), - new Vector2(30, 10), - new Vector2(240, 30), - new Vector2(300, 500) - })); + new Vector2(10, 500), + new Vector2(30, 10), + new Vector2(240, 30), + new Vector2(300, 500))); using (var stream = new MemoryStream()) { @@ -62,4 +60,4 @@ namespace SixLabors.ImageSharp.Benchmarks } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index 408e87f9ee..43b7672c47 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Drawing; @@ -48,11 +48,9 @@ namespace SixLabors.ImageSharp.Benchmarks image.Mutate(x => x.DrawLines( Rgba32.HotPink, 10, - new SixLabors.Primitives.PointF[] { - new Vector2(10, 10), - new Vector2(550, 50), - new Vector2(200, 400) - })); + new Vector2(10, 10), + new Vector2(550, 50), + new Vector2(200, 400))); using (var stream = new MemoryStream()) { @@ -61,4 +59,4 @@ namespace SixLabors.ImageSharp.Benchmarks } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index 2b4cff8cbe..f20469b63d 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Drawing; @@ -46,11 +46,9 @@ namespace SixLabors.ImageSharp.Benchmarks image.Mutate(x => x.DrawPolygon( Rgba32.HotPink, 10, - new SixLabors.Primitives.PointF[] { - new Vector2(10, 10), - new Vector2(550, 50), - new Vector2(200, 400) - })); + new Vector2(10, 10), + new Vector2(550, 50), + new Vector2(200, 400))); using (var ms = new MemoryStream()) { @@ -59,4 +57,4 @@ namespace SixLabors.ImageSharp.Benchmarks } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index 396cc18d10..f33df7ec62 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Drawing; @@ -54,11 +54,9 @@ namespace SixLabors.ImageSharp.Benchmarks { image.Mutate(x => x.FillPolygon( Rgba32.HotPink, - new SixLabors.Primitives.PointF[] { - new Vector2(10, 10), - new Vector2(550, 50), - new Vector2(200, 400) - })); + new Vector2(10, 10), + new Vector2(550, 50), + new Vector2(200, 400))); using (var stream = new MemoryStream()) { @@ -68,7 +66,7 @@ namespace SixLabors.ImageSharp.Benchmarks } [Benchmark(Description = "ImageSharp Fill Polygon - cached shape")] - public void DrawSolidPolygonCoreCahced() + public void DrawSolidPolygonCoreCached() { using (var image = new Image(800, 800)) { @@ -83,4 +81,4 @@ namespace SixLabors.ImageSharp.Benchmarks } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index d45b791aea..531c540da7 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Drawing; @@ -24,13 +24,13 @@ namespace SixLabors.ImageSharp.Benchmarks graphics.InterpolationMode = InterpolationMode.Default; graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.FillRectangle(System.Drawing.Brushes.HotPink, new Rectangle(10, 10, 190, 140)); - + return destination.Size; } } [Benchmark(Description = "ImageSharp Fill Rectangle")] - public CoreSize FillRactangleCore() + public CoreSize FillRectangleCore() { using (var image = new Image(800, 800)) { @@ -47,14 +47,13 @@ namespace SixLabors.ImageSharp.Benchmarks { image.Mutate(x => x.FillPolygon( Rgba32.HotPink, - new SixLabors.Primitives.PointF[] { - new Vector2(10, 10), - new Vector2(200, 10), - new Vector2(200, 150), - new Vector2(10, 150) })); + new Vector2(10, 10), + new Vector2(200, 10), + new Vector2(200, 150), + new Vector2(10, 150))); return new CoreSize(image.Width, image.Height); } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/BasicMath/ClampFloat.cs b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampFloat.cs index 3b7dea0955..404714a54b 100644 --- a/tests/ImageSharp.Benchmarks/General/BasicMath/ClampFloat.cs +++ b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampFloat.cs @@ -2,7 +2,6 @@ using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Running; namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath { diff --git a/tests/ImageSharp.Benchmarks/General/BasicMath/ClampInt32IntoByte.cs b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampInt32IntoByte.cs index a8686fc187..c01d988ee3 100644 --- a/tests/ImageSharp.Benchmarks/General/BasicMath/ClampInt32IntoByte.cs +++ b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampInt32IntoByte.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -76,8 +76,8 @@ namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath public byte ClampBitwise() { int x = this.Value; - int absmax = byte.MaxValue - x; - x = (x + byte.MaxValue - AbsBitwiseVer(ref absmax)) >> 1; + int absMax = byte.MaxValue - x; + x = (x + byte.MaxValue - AbsBitwiseVer(ref absMax)) >> 1; x = (x + byte.MinValue + AbsBitwiseVer(ref x)) >> 1; return (byte)x; diff --git a/tests/ImageSharp.Benchmarks/General/CopyBuffers.cs b/tests/ImageSharp.Benchmarks/General/CopyBuffers.cs index 32f1d10c79..2c325d184a 100644 --- a/tests/ImageSharp.Benchmarks/General/CopyBuffers.cs +++ b/tests/ImageSharp.Benchmarks/General/CopyBuffers.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -33,8 +33,8 @@ namespace SixLabors.ImageSharp.Benchmarks.General [Params(10, 50, 100, 1000, 10000)] public int Count { get; set; } - - + + [GlobalSetup] public void Setup() { @@ -89,11 +89,11 @@ namespace SixLabors.ImageSharp.Benchmarks.General } [Benchmark(Description = "Unsafe.CopyBlock(ref)")] - public unsafe void UnsafeCopyBlockReferences() + public void UnsafeCopyBlockReferences() { Unsafe.CopyBlock(ref this.destArray[0], ref this.sourceArray[0], (uint)this.Count); } - + [Benchmark(Description = "Unsafe.CopyBlock(ptr)")] public unsafe void UnsafeCopyBlockPointers() { @@ -101,13 +101,13 @@ namespace SixLabors.ImageSharp.Benchmarks.General void* pinnedSource = this.sourceHandle.Pointer; Unsafe.CopyBlock(pinnedDestination, pinnedSource, (uint)this.Count); } - + [Benchmark(Description = "Unsafe.CopyBlockUnaligned(ref)")] - public unsafe void UnsafeCopyBlockUnalignedReferences() + public void UnsafeCopyBlockUnalignedReferences() { Unsafe.CopyBlockUnaligned(ref this.destArray[0], ref this.sourceArray[0], (uint)this.Count); } - + [Benchmark(Description = "Unsafe.CopyBlockUnaligned(ptr)")] public unsafe void UnsafeCopyBlockUnalignedPointers() { @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General void* pinnedSource = this.sourceHandle.Pointer; Unsafe.CopyBlockUnaligned(pinnedDestination, pinnedSource, (uint)this.Count); } - + // BenchmarkDotNet=v0.11.3, OS=Windows 10.0.17134.706 (1803/April2018Update/Redstone4) // Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores // Frequency=2742189 Hz, Resolution=364.6722 ns, Timer=TSC @@ -123,9 +123,9 @@ namespace SixLabors.ImageSharp.Benchmarks.General // [Host] : .NET Core 2.1.9 (CoreCLR 4.6.27414.06, CoreFX 4.6.27415.01), 64bit RyuJIT // Clr : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3394.0 // Core : .NET Core 2.1.9 (CoreCLR 4.6.27414.06, CoreFX 4.6.27415.01), 64bit RyuJIT - // - // IterationCount=3 LaunchCount=1 WarmupCount=3 - // + // + // IterationCount=3 LaunchCount=1 WarmupCount=3 + // // | Method | Job | Runtime | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | // |------------------------------- |----- |-------- |------ |-----------:|-----------:|----------:|------:|--------:|------:|------:|------:|----------:| // | Array.Copy() | Clr | Clr | 10 | 23.636 ns | 2.5299 ns | 0.1387 ns | 1.00 | 0.00 | - | - | - | - | @@ -228,4 +228,4 @@ namespace SixLabors.ImageSharp.Benchmarks.General // | Unsafe.CopyBlockUnaligned(ref) | Core | Core | 10000 | 187.489 ns | 13.1527 ns | 0.7209 ns | 0.92 | 0.00 | - | - | - | - | // | Unsafe.CopyBlockUnaligned(ptr) | Core | Core | 10000 | 186.586 ns | 4.6274 ns | 0.2536 ns | 0.91 | 0.00 | - | - | - | - | } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs index 3b288260c5..cd0aed3c47 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -253,8 +253,8 @@ namespace SixLabors.ImageSharp.Benchmarks.General.PixelConversion private static void BitopsSimdImpl(ref Octet.OfUInt32 s, ref Octet.OfUInt32 d) { Vector sVec = Unsafe.As>(ref s); - Vector aMask = new Vector(0xFF00FF00); - Vector bMask = new Vector(0x00FF00FF); + var aMask = new Vector(0xFF00FF00); + var bMask = new Vector(0x00FF00FF); Vector aa = sVec & aMask; Vector bb = sVec & bMask; @@ -388,4 +388,4 @@ namespace SixLabors.ImageSharp.Benchmarks.General.PixelConversion // Bitops_Tuple | 64 | 75.47 ns | 1.1824 ns | 1.1060 ns | 0.91 | 0.01 | // BitOps_GroupAsULong | 64 | 65.42 ns | 0.7157 ns | 0.6695 ns | 0.79 | 0.01 | } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/Vector4Constants.cs b/tests/ImageSharp.Benchmarks/General/Vector4Constants.cs index 3597207ee4..02bc5d843e 100644 --- a/tests/ImageSharp.Benchmarks/General/Vector4Constants.cs +++ b/tests/ImageSharp.Benchmarks/General/Vector4Constants.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General private static readonly Vector4 C = new Vector4(5.6f); private static readonly Vector4 D = new Vector4(7.8f); - private Random random = null; + private Random random; private Vector4 parameter; @@ -58,4 +58,4 @@ namespace SixLabors.ImageSharp.Benchmarks.General private float GetRandomFloat() => (float)this.random.NextDouble(); } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs index 3afb796a7c..60bf615c56 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs @@ -41,14 +41,14 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization [Benchmark] public void Simd() { - Vector v = new Vector(this.testValue); + var v = new Vector(this.testValue); for (int i = 0; i < this.input.Length; i+=Vector.Count) { - Vector a = new Vector(this.input, i); + var a = new Vector(this.input, i); a = Vector.BitwiseOr(a, v); a.CopyTo(this.result, i); } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs index 418209cbc3..79207a9ff3 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs @@ -41,11 +41,11 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization [Benchmark] public void SimdMultiplyByVector() { - Vector v = new Vector(this.testValue); + var v = new Vector(this.testValue); for (int i = 0; i < this.input.Length; i += Vector.Count) { - Vector a = new Vector(this.input, i); + var a = new Vector(this.input, i); a = a * v; a.CopyTo(this.result, i); } @@ -58,10 +58,10 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization for (int i = 0; i < this.input.Length; i += Vector.Count) { - Vector a = new Vector(this.input, i); + var a = new Vector(this.input, i); a = a * v; a.CopyTo(this.result, i); } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs index 7253dbd6a1..d837556f7d 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs @@ -45,10 +45,10 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization for (int i = 0; i < this.input.Length; i += Vector.Count) { - Vector a = new Vector(this.input, i); + var a = new Vector(this.input, i); a = a * v; a.CopyTo(this.result, i); } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs index 67a8a9f39e..19a1bcea45 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs @@ -53,10 +53,10 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization { for (int i = 0; i < this.input.Length; i += Vector.Count) { - Vector a = new Vector(this.input, i); + var a = new Vector(this.input, i); Vector b = Vector.AsVectorSingle(a); b.CopyTo(this.result, i); } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs index 8fc9d9977a..8a14f02451 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs @@ -16,7 +16,7 @@ namespace ImageSharp.Benchmarks.General.Vectorization protected Vector testVector; - protected virtual T GetTestValue() => default(T); + protected virtual T GetTestValue() => default; protected virtual Vector GetTestVector() => new Vector(this.GetTestValue()); @@ -66,4 +66,4 @@ namespace ImageSharp.Benchmarks.General.Vectorization } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs index ca85a350cc..2c9f4289e3 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs @@ -1,4 +1,4 @@ -using System.Numerics; +using System.Numerics; using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization var bVec = new Vector(256.0f / 255.0f); var magicFloat = new Vector(32768.0f); - var magicInt = new Vector(1191182336); // reinterpreded value of 32768.0f + var magicInt = new Vector(1191182336); // reinterpreted value of 32768.0f var mask = new Vector(255); for (int i = 0; i < n; i++) @@ -94,8 +94,6 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization int n = Count / Vector.Count; ref Vector bf = ref Unsafe.As>(ref this.data[0]); - ref Vector bu = ref Unsafe.As, Vector>(ref bf); - var scale = new Vector(1f / 255f); for (int i = 0; i < n; i++) @@ -110,4 +108,4 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs index 017f58ef74..4d83dd4910 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs @@ -5,7 +5,6 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using BenchmarkDotNet.Attributes; - using SixLabors.Memory; /// /// This benchmark compares different methods for fetching memory data into @@ -45,11 +44,11 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization [Benchmark] public void FetchWithVectorConstructor() { - Vector v = new Vector(this.testValue); + var v = new Vector(this.testValue); for (int i = 0; i < this.data.Length; i += Vector.Count) { - Vector a = new Vector(this.data, i); + var a = new Vector(this.data, i); a = a * v; a.CopyTo(this.data, i); } @@ -58,7 +57,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization [Benchmark] public void FetchWithUnsafeCast() { - Vector v = new Vector(this.testValue); + var v = new Vector(this.testValue); ref Vector start = ref Unsafe.As>(ref this.data[0]); int n = this.InputSize / Vector.Count; @@ -77,7 +76,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization [Benchmark] public void FetchWithUnsafeCastNoTempVector() { - Vector v = new Vector(this.testValue); + var v = new Vector(this.testValue); ref Vector start = ref Unsafe.As>(ref this.data[0]); int n = this.InputSize / Vector.Count; @@ -107,4 +106,4 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 263ce6a7e4..28cb047356 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -144,7 +144,7 @@ namespace SixLabors.ImageSharp.Benchmarks { amount = amount.Clamp(0, 1); - // Santize on zero alpha + // Sanitize on zero alpha if (Math.Abs(backdrop.W) < Constants.Epsilon) { source.W *= amount; @@ -173,4 +173,4 @@ namespace SixLabors.ImageSharp.Benchmarks } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Sandbox46/Program.cs b/tests/ImageSharp.Sandbox46/Program.cs index afe7eb04ff..93fe74076e 100644 --- a/tests/ImageSharp.Sandbox46/Program.cs +++ b/tests/ImageSharp.Sandbox46/Program.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -10,8 +10,6 @@ namespace SixLabors.ImageSharp.Sandbox46 { using System; using SixLabors.ImageSharp.Tests.Formats.Jpg; - using SixLabors.ImageSharp.Tests.PixelFormats; - using SixLabors.ImageSharp.Tests.Processing.Processors.Transforms; using Xunit.Abstractions; diff --git a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs index 974099991d..8d60338498 100644 --- a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs @@ -1,4 +1,5 @@ // Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -10,10 +11,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Advanced { - using System.Buffers; - - using SixLabors.Memory; - public class AdvancedImageExtensionsTests { public class GetPixelMemory @@ -55,9 +52,9 @@ namespace SixLabors.ImageSharp.Tests.Advanced var targetBuffer = new TPixel[image0.Width * image0.Height]; image0.GetPixelSpan().CopyTo(targetBuffer); - var managerOfExeternalMemory = new TestMemoryManager(targetBuffer); + var managerOfExternalMemory = new TestMemoryManager(targetBuffer); - Memory externalMemory = managerOfExeternalMemory.Memory; + Memory externalMemory = managerOfExternalMemory.Memory; using (var image1 = Image.WrapMemory(externalMemory, image0.Width, image0.Height)) { diff --git a/tests/ImageSharp.Tests/Advanced/AotCompilerTests.cs b/tests/ImageSharp.Tests/Advanced/AotCompilerTests.cs deleted file mode 100644 index f6397dbd09..0000000000 --- a/tests/ImageSharp.Tests/Advanced/AotCompilerTests.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.PixelFormats; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Advanced -{ - public class AotCompilerTests - { - [Fact] - public void AotCompiler_NoExceptions() => AotCompilerTools.Seed(); - } -} diff --git a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs index d3de04354c..d298f61976 100644 --- a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs @@ -3,7 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs b/tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs index 22c6d55ad8..3fc4c56591 100644 --- a/tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs +++ b/tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs @@ -14,8 +14,8 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void Rgba64() { - Rgba64 source = new Rgba64(100, 2222, 3333, 4444); - + var source = new Rgba64(100, 2222, 3333, 4444); + // Act: Color color = source; @@ -23,12 +23,12 @@ namespace SixLabors.ImageSharp.Tests Rgba64 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Rgba32() { - Rgba32 source = new Rgba32(1, 22, 33, 231); - + var source = new Rgba32(1, 22, 33, 231); + // Act: Color color = source; @@ -36,12 +36,12 @@ namespace SixLabors.ImageSharp.Tests Rgba32 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Argb32() { - Argb32 source = new Argb32(1, 22, 33, 231); - + var source = new Argb32(1, 22, 33, 231); + // Act: Color color = source; @@ -49,12 +49,12 @@ namespace SixLabors.ImageSharp.Tests Argb32 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Bgra32() { - Bgra32 source = new Bgra32(1, 22, 33, 231); - + var source = new Bgra32(1, 22, 33, 231); + // Act: Color color = source; @@ -62,12 +62,12 @@ namespace SixLabors.ImageSharp.Tests Bgra32 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Rgb24() { - Rgb24 source = new Rgb24(1, 22, 231); - + var source = new Rgb24(1, 22, 231); + // Act: Color color = source; @@ -75,12 +75,12 @@ namespace SixLabors.ImageSharp.Tests Rgb24 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Bgr24() { - Bgr24 source = new Bgr24(1, 22, 231); - + var source = new Bgr24(1, 22, 231); + // Act: Color color = source; @@ -90,4 +90,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs b/tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs index d44472b28a..fbd1c73f16 100644 --- a/tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs +++ b/tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs @@ -14,75 +14,75 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void Rgba64() { - Rgba64 source = new Rgba64(100, 2222, 3333, 4444); - + var source = new Rgba64(100, 2222, 3333, 4444); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Rgba64 data = color; Assert.Equal(source, data); } - + [Fact] public void Rgba32() { - Rgba32 source = new Rgba32(1, 22, 33, 231); - + var source = new Rgba32(1, 22, 33, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Rgba32 data = color; Assert.Equal(source, data); } - + [Fact] public void Argb32() { - Argb32 source = new Argb32(1, 22, 33, 231); - + var source = new Argb32(1, 22, 33, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Argb32 data = color; Assert.Equal(source, data); } - + [Fact] public void Bgra32() { - Bgra32 source = new Bgra32(1, 22, 33, 231); - + var source = new Bgra32(1, 22, 33, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Bgra32 data = color; Assert.Equal(source, data); } - + [Fact] public void Rgb24() { - Rgb24 source = new Rgb24(1, 22, 231); - + var source = new Rgb24(1, 22, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Rgb24 data = color; Assert.Equal(source, data); } - + [Fact] public void Bgr24() { - Bgr24 source = new Bgr24(1, 22, 231); - + var source = new Bgr24(1, 22, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Bgr24 data = color; @@ -90,4 +90,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs b/tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs index 9d21cd80c5..7f7c084e74 100644 --- a/tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs +++ b/tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs @@ -14,75 +14,75 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void Rgba64() { - Rgba64 source = new Rgba64(100, 2222, 3333, 4444); - + var source = new Rgba64(100, 2222, 3333, 4444); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Rgba64 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Rgba32() { - Rgba32 source = new Rgba32(1, 22, 33, 231); - + var source = new Rgba32(1, 22, 33, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Rgba32 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Argb32() { - Argb32 source = new Argb32(1, 22, 33, 231); - + var source = new Argb32(1, 22, 33, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Argb32 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Bgra32() { - Bgra32 source = new Bgra32(1, 22, 33, 231); - + var source = new Bgra32(1, 22, 33, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Bgra32 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Rgb24() { - Rgb24 source = new Rgb24(1, 22, 231); - + var source = new Rgb24(1, 22, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Rgb24 data = color.ToPixel(); Assert.Equal(source, data); } - + [Fact] public void Bgr24() { - Bgr24 source = new Bgr24(1, 22, 231); - + var source = new Bgr24(1, 22, 231); + // Act: - Color color = new Color(source); + var color = new Color(source); // Assert: Bgr24 data = color.ToPixel(); @@ -90,4 +90,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Color/ColorTests.cs b/tests/ImageSharp.Tests/Color/ColorTests.cs index eb5cc70b29..6d9b34ee95 100644 --- a/tests/ImageSharp.Tests/Color/ColorTests.cs +++ b/tests/ImageSharp.Tests/Color/ColorTests.cs @@ -3,7 +3,6 @@ using System; using System.Linq; -using System.Reflection; using SixLabors.ImageSharp.PixelFormats; @@ -19,47 +18,47 @@ namespace SixLabors.ImageSharp.Tests Color c1 = Color.FromRgba(111, 222, 55, 255); Color c2 = c1.WithAlpha(0.5f); - Rgba32 expected = new Rgba32(111, 222, 55, 128); - + var expected = new Rgba32(111, 222, 55, 128); + Assert.Equal(expected, (Rgba32)c2); } - + [Fact] public void Equality_WhenTrue() { Color c1 = new Rgba64(100, 2000, 3000, 40000); Color c2 = new Rgba64(100, 2000, 3000, 40000); - + Assert.True(c1.Equals(c2)); Assert.True(c1 == c2); Assert.False(c1 != c2); Assert.True(c1.GetHashCode() == c2.GetHashCode()); } - + [Fact] public void Equality_WhenFalse() { Color c1 = new Rgba64(100, 2000, 3000, 40000); Color c2 = new Rgba64(101, 2000, 3000, 40000); Color c3 = new Rgba64(100, 2000, 3000, 40001); - + Assert.False(c1.Equals(c2)); Assert.False(c2.Equals(c3)); Assert.False(c3.Equals(c1)); - + Assert.False(c1 == c2); Assert.True(c1 != c2); - + Assert.False(c1.Equals(null)); } - + [Fact] public void ToHex() { string expected = "ABCD1234"; Color color = Color.FromHex(expected); string actual = color.ToHex(); - + Assert.Equal(expected, actual); } @@ -76,7 +75,7 @@ namespace SixLabors.ImageSharp.Tests Rgba32[] actualPalette = Color.WernerPalette.ToArray().Select(c => (Rgba32)c).ToArray(); Assert.Equal(ReferencePalette.WernerColors, actualPalette); } - + public class FromHex { [Fact] @@ -107,4 +106,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Colorspaces/RgbTests.cs b/tests/ImageSharp.Tests/Colorspaces/RgbTests.cs index 7987fbe9f2..17816aab18 100644 --- a/tests/ImageSharp.Tests/Colorspaces/RgbTests.cs +++ b/tests/ImageSharp.Tests/Colorspaces/RgbTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; diff --git a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs index 4f8a2cdaf7..58317ca49f 100644 --- a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs +++ b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Common private static Vector CreateExactTestVector1() { - float[] data = new float[Vector.Count]; + var data = new float[Vector.Count]; data[0] = 0.1f; data[1] = 0.4f; @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Tests.Common private static Vector CreateRandomTestVector(int seed, float min, float max) { - float[] data = new float[Vector.Count]; + var data = new float[Vector.Count]; var rnd = new Random(seed); @@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.Tests.Common float[] orig = new Random(seed).GenerateRandomRoundedFloatArray(count, 0, 256); float[] normalized = orig.Select(f => f / 255f).ToArray(); - byte[] dest = new byte[count]; + var dest = new byte[count]; SimdUtils.BasicIntrinsics256.BulkConvertNormalizedFloatToByte(normalized, dest); @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.Tests.Common float[] source = new Random(seed).GenerateRandomFloatArray(count, 0, 1f); - byte[] dest = new byte[count]; + var dest = new byte[count]; SimdUtils.BasicIntrinsics256.BulkConvertNormalizedFloatToByte(source, dest); @@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp.Tests.Common count, (s, d) => SimdUtils.BasicIntrinsics256.BulkConvertByteToNormalizedFloat(s.Span, d.Span)); } - + [Theory] [MemberData(nameof(ArraySizesDivisibleBy32))] public void ExtendedIntrinsics_BulkConvertByteToNormalizedFloat(int count) @@ -217,7 +217,7 @@ namespace SixLabors.ImageSharp.Tests.Common Action, Memory> convert) { byte[] source = new Random(count).GenerateRandomByteArray(count); - float[] result = new float[count]; + var result = new float[count]; float[] expected = source.Select(b => (float)b / 255f).ToArray(); convert(source, result); @@ -306,7 +306,7 @@ namespace SixLabors.ImageSharp.Tests.Common seed = seed > 0 ? seed : count; float[] source = new Random(seed).GenerateRandomFloatArray(count, -0.2f, 1.2f); byte[] expected = source.Select(NormalizedFloatToByte).ToArray(); - byte[] actual = new byte[count]; + var actual = new byte[count]; convert(source, actual); @@ -325,7 +325,7 @@ namespace SixLabors.ImageSharp.Tests.Common private void MagicConvertToByte(float value) { byte actual = MagicConvert(value / 256f); - byte expected = (byte)value; + var expected = (byte)value; Assert.Equal(expected, actual); } @@ -362,7 +362,7 @@ namespace SixLabors.ImageSharp.Tests.Common { var magick = new Vector(32768.0f); - Vector scale = new Vector(255f) / new Vector(256f); + var scale = new Vector(255f) / new Vector(256f); Vector x = MemoryMarshal.Cast>(source)[0]; @@ -392,4 +392,4 @@ namespace SixLabors.ImageSharp.Tests.Common } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Drawing/DrawBezierTests.cs b/tests/ImageSharp.Tests/Drawing/DrawBezierTests.cs index 4ccc7fd355..de5b2bf474 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawBezierTests.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; diff --git a/tests/ImageSharp.Tests/Drawing/DrawComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/DrawComplexPolygonTests.cs index f28f3345fc..76d29dff38 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawComplexPolygonTests.cs @@ -3,7 +3,6 @@ using System.Numerics; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.Shapes; diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTests.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTests.cs index b2d499c7fa..86c1c28504 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTests.cs @@ -1,15 +1,13 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; -using SixLabors.Shapes; using Xunit; @@ -77,13 +75,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing using (Image image = provider.GetImage()) using (var blend = Image.Load(TestFile.Create(brushImage).Bytes)) { - Size size = new Size(image.Width * 3 / 4, image.Height * 3 / 4); - Point position = new Point(image.Width / 8, image.Height / 8); + var size = new Size(image.Width * 3 / 4, image.Height * 3 / 4); + var position = new Point(image.Width / 8, image.Height / 8); blend.Mutate(x => x.Resize(size.Width, size.Height, KnownResamplers.Bicubic)); image.Mutate(x => x.DrawImage(blend, position, mode, opacity)); FormattableString testInfo = $"{System.IO.Path.GetFileNameWithoutExtension(brushImage)}-{mode}-{opacity}"; - PngEncoder encoder = new PngEncoder(); + var encoder = new PngEncoder(); if (provider.PixelType == PixelTypes.Rgba64) { @@ -199,4 +197,4 @@ namespace SixLabors.ImageSharp.Tests.Drawing } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Drawing/DrawLinesTests.cs b/tests/ImageSharp.Tests/Drawing/DrawLinesTests.cs index 12eb150b1b..2836f8a38d 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawLinesTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawLinesTests.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index 5e9743c31a..8c2c6fc6ed 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -1,10 +1,9 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Numerics; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.Primitives; @@ -30,17 +29,17 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void DrawPath(TestImageProvider provider, string colorName, byte alpha, float thickness) where TPixel : struct, IPixel { - var linerSegemnt = new LinearLineSegment( + var linearSegment = new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300)); - var bazierSegment = new CubicBezierLineSegment( + var bezierSegment = new CubicBezierLineSegment( new Vector2(50, 300), new Vector2(500, 500), new Vector2(60, 10), new Vector2(10, 400)); - var path = new Path(linerSegemnt, bazierSegment); + var path = new Path(linearSegment, bezierSegment); Rgba32 rgba = TestUtils.GetColorByName(colorName); rgba.A = alpha; @@ -60,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void PathExtendingOffEdgeOfImageShouldNotBeCropped(TestImageProvider provider) where TPixel : struct, IPixel { - Color color = Color.White; + var color = Color.White; Pen pen = Pens.Solid(color, 5f); provider.RunValidatingProcessorTest( @@ -68,7 +67,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { for (int i = 0; i < 300; i += 20) { - PointF[] points = new PointF[] { new Vector2(100, 2), new Vector2(-10, i) }; + var points = new PointF[] { new Vector2(100, 2), new Vector2(-10, i) }; x.DrawLines(pen, points); } }, @@ -76,4 +75,4 @@ namespace SixLabors.ImageSharp.Tests.Drawing appendSourceFileOrDescription: false); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Drawing/DrawPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPolygonTests.cs index b7c54fdbd1..18fde6ad8f 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPolygonTests.cs @@ -1,12 +1,10 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Numerics; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; using SixLabors.ImageSharp.Processing; using Xunit; @@ -28,16 +26,16 @@ namespace SixLabors.ImageSharp.Tests.Drawing new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha); - + GraphicsOptions options = new GraphicsOptions(antialias); string aa = antialias ? "" : "_NoAntialias"; FormattableString outputDetails = $"{colorName}_A({alpha})_T({thickness}){aa}"; - + provider.RunValidatingProcessorTest( c => c.DrawPolygon(options, color, thickness, simplePath), outputDetails, appendSourceFileOrDescription: false); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Drawing/FillComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/FillComplexPolygonTests.cs index d6c85cd1d6..e0fff8da50 100644 --- a/tests/ImageSharp.Tests/Drawing/FillComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillComplexPolygonTests.cs @@ -3,7 +3,6 @@ using System.Numerics; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.Shapes; diff --git a/tests/ImageSharp.Tests/Drawing/FillImageBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillImageBrushTests.cs index d33d7b70d2..cbf49b8301 100644 --- a/tests/ImageSharp.Tests/Drawing/FillImageBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillImageBrushTests.cs @@ -1,14 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; - using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; -using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/FillPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/FillPolygonTests.cs index 5393e9954f..104237ec3e 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPolygonTests.cs @@ -1,10 +1,9 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Numerics; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.Shapes; @@ -29,18 +28,18 @@ namespace SixLabors.ImageSharp.Tests.Drawing new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha); - - GraphicsOptions options = new GraphicsOptions(antialias); + + var options = new GraphicsOptions(antialias); string aa = antialias ? "" : "_NoAntialias"; FormattableString outputDetails = $"{colorName}_A{alpha}{aa}"; - + provider.RunValidatingProcessorTest( c => c.FillPolygon(options, color, simplePath), outputDetails, appendSourceFileOrDescription: false); } - + [Theory] [WithBasicTestPatternImages(200, 200, PixelTypes.Rgba32)] public void FillPolygon_Concave(TestImageProvider provider) @@ -48,15 +47,15 @@ namespace SixLabors.ImageSharp.Tests.Drawing { var points = new SixLabors.Primitives.PointF[] { - new Vector2(8, 8), - new Vector2(64, 8), - new Vector2(64, 64), + new Vector2(8, 8), + new Vector2(64, 8), + new Vector2(64, 64), new Vector2(120, 64), - new Vector2(120, 120), + new Vector2(120, 120), new Vector2(8, 120) }; - - Color color = Color.LightGreen; + + var color = Color.LightGreen; provider.RunValidatingProcessorTest( c => c.FillPolygon(color, points), @@ -73,15 +72,15 @@ namespace SixLabors.ImageSharp.Tests.Drawing { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; - Color color = Color.Yellow; + var color = Color.Yellow; var brush = Brushes.Horizontal(color); - + provider.RunValidatingProcessorTest( c => c.FillPolygon(brush, simplePath), appendSourceFileOrDescription: false); } - + [Theory] [WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32, TestImages.Png.Ducky)] [WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32, TestImages.Bmp.Car)] @@ -96,7 +95,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing using (Image brushImage = Image.Load(TestFile.Create(brushImageName).Bytes)) { var brush = new ImageBrush(brushImage); - + provider.RunValidatingProcessorTest( c => c.FillPolygon(brush, simplePath), System.IO.Path.GetFileNameWithoutExtension(brushImageName), @@ -110,13 +109,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing where TPixel : struct, IPixel { var polygon = new SixLabors.Shapes.RectangularPolygon(10, 10, 190, 140); - Color color = Color.White; + var color = Color.White; provider.RunValidatingProcessorTest( c => c.Fill(color, polygon), - appendSourceFileOrDescription: false); + appendSourceFileOrDescription: false); } - + [Theory] [WithBasicTestPatternImages(200, 200, PixelTypes.Rgba32, 3, 50, 0f)] [WithBasicTestPatternImages(200, 200, PixelTypes.Rgba32, 3, 60, 20f)] @@ -128,7 +127,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { float angle = GeometryUtilities.DegreeToRadian(angleDeg); var polygon = new RegularPolygon(100, 100, vertices, radius, angle); - Color color = Color.Yellow; + var color = Color.Yellow; FormattableString testOutput = $"V({vertices})_R({radius})_Ang({angleDeg})"; provider.RunValidatingProcessorTest( @@ -144,7 +143,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing where TPixel : struct, IPixel { var polygon = new EllipsePolygon(100, 100, 80, 120); - Color color = Color.Azure; + var color = Color.Azure; provider.RunValidatingProcessorTest( c => c.Fill(color, polygon), diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index bb78054a4d..972f5cf4a1 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -12,6 +12,7 @@ using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; using Xunit; using SixLabors.ImageSharp.Processing.Processors.Drawing; +using SixLabors.Shapes; namespace SixLabors.ImageSharp.Tests.Drawing { @@ -19,14 +20,14 @@ namespace SixLabors.ImageSharp.Tests.Drawing public class FillRegionProcessorTests { - + [Theory] [InlineData(true, 1, 4)] [InlineData(true, 2, 4)] [InlineData(true, 5, 5)] [InlineData(true, 8, 8)] [InlineData(false, 8, 4)] - [InlineData(false, 16, 4)] // we always do 4 sub=pixels when antialising is off. + [InlineData(false, 16, 4)] // we always do 4 sub=pixels when antialiasing is off. public void MinimumAntialiasSubpixelDepth(bool antialias, int antialiasSubpixelDepth, int expectedAntialiasSubpixelDepth) { var bounds = new Rectangle(0, 0, 1, 1); @@ -62,10 +63,53 @@ namespace SixLabors.ImageSharp.Tests.Drawing using (var img = new Image(10, 10)) { - img.Mutate(x => x.DrawLines(new Pen(Rgba32.Black, 10), new SixLabors.Primitives.PointF[] { + img.Mutate(x => x.DrawLines(new Pen(Rgba32.Black, 10), new Vector2(-10, 5), - new Vector2(20, 5), - })); + new Vector2(20, 5))); + } + } + + [Fact] + public void DoesNotThrowForIssue928() + { + var rectText = new RectangleF(0, 0, 2000, 2000); + using (Image img = new Image((int)rectText.Width, (int)rectText.Height)) + { + img.Mutate(x => x.Fill(Rgba32.Transparent)); + + img.Mutate(ctx => { + ctx.DrawLines( + Rgba32.Red, + 0.984252f, + new PointF(104.762581f, 1074.99365f), + new PointF(104.758667f, 1075.01721f), + new PointF(104.757675f, 1075.04114f), + new PointF(104.759628f, 1075.065f), + new PointF(104.764488f, 1075.08838f), + new PointF(104.772186f, 1075.111f), + new PointF(104.782608f, 1075.13245f), + new PointF(104.782608f, 1075.13245f) + ); + } + ); + } + } + + [Fact] + public void DoesNotThrowFillingTriangle() + { + using(var image = new Image(28, 28)) + { + var path = new Polygon( + new LinearLineSegment(new PointF(17.11f, 13.99659f), new PointF(14.01433f, 27.06201f)), + new LinearLineSegment(new PointF(14.01433f, 27.06201f), new PointF(13.79267f, 14.00023f)), + new LinearLineSegment(new PointF(13.79267f, 14.00023f), new PointF(17.11f, 13.99659f)) + ); + + image.Mutate(ctx => + { + ctx.Fill(Rgba32.White, path); + }); } } diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index 358552bf81..a5e7450839 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { using (Image image = provider.GetImage()) { - Color color = Color.HotPink; + var color = Color.HotPink; image.Mutate(c => c.Fill(color)); image.DebugSave(provider, appendPixelTypeToFileName: false); @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { using (Image image = provider.GetImage()) { - Color color = Color.HotPink; + var color = Color.HotPink; image.Mutate(c => c.Fill(color)); image.DebugSave(provider, appendSourceFileOrDescription: false); @@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing } public static readonly TheoryData BlendData = - new TheoryData() + new TheoryData { { false, "Blue", 0.5f, PixelColorBlendingMode.Normal, 1.0f }, { false, "Blue", 1.0f, PixelColorBlendingMode.Normal, 0.5f }, @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing [Theory] [WithSolidFilledImages(nameof(BlendData), 16, 16, "Red", PixelTypes.Rgba32)] - public void BlendFillColorOverBackround( + public void BlendFillColorOverBackground( TestImageProvider provider, bool triggerFillRegion, string newColorName, @@ -196,4 +196,4 @@ namespace SixLabors.ImageSharp.Tests.Drawing } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs index 5ab7894355..ee95bc743b 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapePath region = Assert.IsType(processor.Region); // path is converted to a polygon before filling - ComplexPolygon polygon = Assert.IsType(region.Shape); + Assert.IsType(region.Shape); Assert.Equal(this.pen.StrokeFill, processor.Brush); } @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths Assert.Equal(this.noneDefault, processor.Options); ShapePath region = Assert.IsType(processor.Region); - ComplexPolygon polygon = Assert.IsType(region.Shape); + Assert.IsType(region.Shape); Assert.Equal(this.pen.StrokeFill, processor.Brush); } @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths Assert.Equal(GraphicsOptions.Default, processor.Options); ShapePath region = Assert.IsType(processor.Region); - ComplexPolygon polygon = Assert.IsType(region.Shape); + Assert.IsType(region.Shape); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths Assert.Equal(this.noneDefault, processor.Options); ShapePath region = Assert.IsType(processor.Region); - ComplexPolygon polygon = Assert.IsType(region.Shape); + Assert.IsType(region.Shape); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index d65dcd8c64..d12441ac2f 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths // path is converted to a polygon before filling Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); Assert.Equal(this.brush, processor.Brush); } @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); Assert.Equal(this.brush, processor.Brush); } @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs index 1f8e2d423d..17bb7e6ee5 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths // path is converted to a polygon before filling Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); Assert.Equal(this.brush, processor.Brush); } @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); Assert.Equal(this.brush, processor.Brush); } @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); @@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index b270a03cfc..22b741ec1e 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); Assert.Equal(this.brush, processor.Brush); } @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); Assert.Equal(this.brush, processor.Brush); } @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); @@ -82,7 +82,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); - LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); + Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs index 40c5f950da..69dff72369 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Primitives; @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths public ShapeRegionTests() { - this.pathMock = new Mock() { CallBase = true }; + this.pathMock = new Mock { CallBase = true }; this.bounds = new RectangleF(10.5f, 10, 10, 10); this.pathMock.Setup(x => x.Bounds).Returns(this.bounds); @@ -124,4 +124,4 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths this.pathMock.Verify(x => x.MaxIntersections); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs b/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs index 546bdef4b3..da7c865b96 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; using System.Collections.Generic; -using System.Linq; + using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index 8520a2f3fb..181ec9b9d7 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -14,14 +14,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { public class DrawText : BaseImageOperationsExtensionTest { - Rgba32 color = Color.HotPink; - - SolidBrush brush = Brushes.Solid(Color.HotPink); - - IPath path = new SixLabors.Shapes.Path( - new LinearLineSegment( - new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), new Vector2(30, 10), })); - private readonly FontCollection FontCollection; private readonly Font Font; @@ -33,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } [Fact] - public void FillsForEachACharachterWhenBrushSetAndNotPen() + public void FillsForEachACharacterWhenBrushSetAndNotPen() { this.operations.DrawText( new TextGraphicsOptions(true), @@ -47,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } [Fact] - public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() + public void FillsForEachACharacterWhenBrushSetAndNotPenDefaultOptions() { this.operations.DrawText("123", this.Font, Brushes.Solid(Color.Red), null, Vector2.Zero); @@ -55,7 +47,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } [Fact] - public void FillsForEachACharachterWhenBrushSet() + public void FillsForEachACharacterWhenBrushSet() { this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Brushes.Solid(Color.Red), Vector2.Zero); @@ -63,7 +55,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } [Fact] - public void FillsForEachACharachterWhenBrushSetDefaultOptions() + public void FillsForEachACharacterWhenBrushSetDefaultOptions() { this.operations.DrawText("123", this.Font, Brushes.Solid(Color.Red), Vector2.Zero); @@ -71,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } [Fact] - public void FillsForEachACharachterWhenColorSet() + public void FillsForEachACharacterWhenColorSet() { this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Color.Red, Vector2.Zero); @@ -82,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } [Fact] - public void FillsForEachACharachterWhenColorSetDefaultOptions() + public void FillsForEachACharacterWhenColorSetDefaultOptions() { this.operations.DrawText("123", this.Font, Color.Red, Vector2.Zero); @@ -93,7 +85,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } [Fact] - public void DrawForEachACharachterWhenPenSetAndNotBrush() + public void DrawForEachACharacterWhenPenSetAndNotBrush() { this.operations.DrawText( new TextGraphicsOptions(true), @@ -103,27 +95,27 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text Pens.Dash(Color.Red, 1), Vector2.Zero); - var processor = this.Verify(0); + this.Verify(0); } [Fact] - public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() + public void DrawForEachACharacterWhenPenSetAndNotBrushDefaultOptions() { this.operations.DrawText("123", this.Font, null, Pens.Dash(Color.Red, 1), Vector2.Zero); - var processor = this.Verify(0); + this.Verify(0); } [Fact] - public void DrawForEachACharachterWhenPenSet() + public void DrawForEachACharacterWhenPenSet() { this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero); - var processor = this.Verify(0); + this.Verify(0); } [Fact] - public void DrawForEachACharachterWhenPenSetDefaultOptions() + public void DrawForEachACharacterWhenPenSetDefaultOptions() { this.operations.DrawText("123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero); @@ -138,7 +130,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } [Fact] - public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() + public void DrawForEachACharacterWhenPenSetAndFillFroEachWhenBrushSet() { this.operations.DrawText( new TextGraphicsOptions(true), diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs index ebd9cf6448..7bebdabd3a 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -40,23 +40,19 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text where TPixel : struct, IPixel { Font font = CreateFont("OpenSans-Regular.ttf", 36); - Color color = Color.Black; - float padding = 5; + var color = Color.Black; var text = "A short piece of text"; using (var img = provider.GetImage()) { - float targetWidth = img.Width - (padding * 2); - float targetHeight = img.Height - (padding * 2); - // measure the text size SizeF size = TextMeasurer.Measure(text, new RendererOptions(font)); //find out how much we need to scale the text to fill the space (up or down) float scalingFactor = Math.Min(img.Width / size.Width, img.Height / size.Height); - //create a new font - Font scaledFont = new Font(font, scalingFactor * font.Size); + //create a new font + var scaledFont = new Font(font, scalingFactor * font.Size); var center = new PointF(img.Width / 2, img.Height / 2); var textGraphicOptions = new TextGraphicsOptions(true) @@ -64,7 +60,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; - + img.Mutate(i => i.DrawText(textGraphicOptions, text, scaledFont, color, center)); } } @@ -84,7 +80,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text where TPixel : struct, IPixel { Font font = CreateFont(fontName, fontSize); - Color color = Color.Black; + var color = Color.Black; provider.VerifyOperation( TextDrawingComparer, @@ -129,7 +125,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text HorizontalAlignment = HorizontalAlignment.Left, }; - Color color = Color.Black; + var color = Color.Black; // Based on the reported 0.0270% difference with AccuracyMultiple = 8 // We should avoid quality regressions leading to higher difference! @@ -159,7 +155,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text where TPixel : struct, IPixel { Font font = CreateFont(fontName, fontSize); - Color color = Color.Black; + var color = Color.Black; provider.VerifyOperation( OutlinedTextDrawingComparer, @@ -186,7 +182,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text where TPixel : struct, IPixel { Font font = CreateFont(fontName, fontSize); - Color color = Color.Black; + var color = Color.Black; provider.VerifyOperation( OutlinedTextDrawingComparer, @@ -241,6 +237,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text return font; } - + } } diff --git a/tests/ImageSharp.Tests/Drawing/Utils/QuickSortTests.cs b/tests/ImageSharp.Tests/Drawing/Utils/QuickSortTests.cs index 6660cd87af..5ad7a1248d 100644 --- a/tests/ImageSharp.Tests/Drawing/Utils/QuickSortTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Utils/QuickSortTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Tests.Drawing.Utils @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Utils public class QuickSortTests { - public static readonly TheoryData Data = new TheoryData() + public static readonly TheoryData Data = new TheoryData { new float[]{ 3, 2, 1 }, new float[0], @@ -48,4 +48,4 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Utils Assert.Equal(actual, expected); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index c3ae0cddff..fb4afc28d1 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Tests public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { - this.Applied.Add(new AppliedOperation() + this.Applied.Add(new AppliedOperation { Rectangle = rectangle, NonGenericProcessor = processor @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Tests public IImageProcessingContext ApplyProcessor(IImageProcessor processor) { - this.Applied.Add(new AppliedOperation() + this.Applied.Add(new AppliedOperation { NonGenericProcessor = processor }); @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Tests { public Rectangle? Rectangle { get; set; } public IImageProcessor GenericProcessor { get; set; } - + public IImageProcessor NonGenericProcessor { get; set; } } } diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs index dadce92d13..ecec6f0a7a 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs @@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp public void BmpDecoder_CanDecode_RunLengthEncoded_4Bit_WithDelta(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage(new BmpDecoder() { RleSkippedPixelHandling = RleSkippedPixelHandling.Black })) + using (Image image = provider.GetImage(new BmpDecoder { RleSkippedPixelHandling = RleSkippedPixelHandling.Black })) { image.DebugSave(provider); // The Magick Reference Decoder can not decode 4-Bit bitmaps, so only execute this on windows. @@ -173,7 +173,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp public void BmpDecoder_CanDecode_RunLengthEncoded_4Bit(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage(new BmpDecoder() { RleSkippedPixelHandling = RleSkippedPixelHandling.Black })) + using (Image image = provider.GetImage(new BmpDecoder { RleSkippedPixelHandling = RleSkippedPixelHandling.Black })) { image.DebugSave(provider); // The Magick Reference Decoder can not decode 4-Bit bitmaps, so only execute this on windows. @@ -192,7 +192,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp public void BmpDecoder_CanDecode_RunLengthEncoded_8Bit_WithDelta_SystemDrawingRefDecoder(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage(new BmpDecoder() { RleSkippedPixelHandling = RleSkippedPixelHandling.Black })) + using (Image image = provider.GetImage(new BmpDecoder { RleSkippedPixelHandling = RleSkippedPixelHandling.Black })) { image.DebugSave(provider); if (TestEnvironment.IsWindows) @@ -208,7 +208,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp public void BmpDecoder_CanDecode_RunLengthEncoded_8Bit_WithDelta_MagickRefDecoder(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage(new BmpDecoder() { RleSkippedPixelHandling = RleSkippedPixelHandling.FirstColorOfPalette })) + using (Image image = provider.GetImage(new BmpDecoder { RleSkippedPixelHandling = RleSkippedPixelHandling.FirstColorOfPalette })) { image.DebugSave(provider); image.CompareToOriginal(provider, new MagickReferenceDecoder()); @@ -221,7 +221,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp public void BmpDecoder_CanDecode_RunLengthEncoded_8Bit(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage(new BmpDecoder() { RleSkippedPixelHandling = RleSkippedPixelHandling.FirstColorOfPalette })) + using (Image image = provider.GetImage(new BmpDecoder { RleSkippedPixelHandling = RleSkippedPixelHandling.FirstColorOfPalette })) { image.DebugSave(provider); image.CompareToOriginal(provider, new MagickReferenceDecoder()); @@ -235,7 +235,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp public void BmpDecoder_CanDecode_RunLengthEncoded_24Bit(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage(new BmpDecoder() { RleSkippedPixelHandling = RleSkippedPixelHandling.Black })) + using (Image image = provider.GetImage(new BmpDecoder { RleSkippedPixelHandling = RleSkippedPixelHandling.Black })) { image.DebugSave(provider); @@ -283,8 +283,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp // seems to be wrong. This bitmap has an alpha channel of two bits. In many cases this alpha channel has a value of 3, // which should be remapped to 255 for RGBA32, but the magick decoder has a value of 191 set. // The total difference without the alpha channel is still: 0.0204% - // Exporting the image as PNG with GIMP yields to the same result as the imagesharp implementation. - image.CompareToOriginal(provider, ImageComparer.TolerantPercentage(6.1f), new MagickReferenceDecoder()); + // Exporting the image as PNG with GIMP yields to the same result as the ImageSharp implementation. + image.CompareToOriginal(provider, ImageComparer.TolerantPercentage(6.1f), new MagickReferenceDecoder()); } } @@ -346,7 +346,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp public void BmpDecoder_ThrowsImageFormatException_OnInvalidPaletteSize(TestImageProvider provider) where TPixel : struct, IPixel { - Assert.Throws( () => { using (Image image = provider.GetImage(new BmpDecoder())) { } }); + Assert.Throws( () => { using (provider.GetImage(new BmpDecoder())) { } }); } [Theory] @@ -355,7 +355,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp public void BmpDecoder_ThrowsNotSupportedException_OnUnsupportedBitmaps(TestImageProvider provider) where TPixel : struct, IPixel { - Assert.Throws(() => { using (Image image = provider.GetImage(new BmpDecoder())) { } }); + Assert.Throws(() => { using (provider.GetImage(new BmpDecoder())) { } }); } [Theory] diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpFileHeaderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpFileHeaderTests.cs index 8ad227cfdc..25cf29406e 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpFileHeaderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpFileHeaderTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using SixLabors.ImageSharp.Formats.Bmp; using Xunit; @@ -11,11 +11,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp { var header = new BmpFileHeader(1, 2, 3, 4); - byte[] buffer = new byte[14]; + var buffer = new byte[14]; header.WriteTo(buffer); Assert.Equal("AQACAAAAAwAAAAQAAAA=", Convert.ToBase64String(buffer)); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpMetaDataTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpMetaDataTests.cs index da17dfb983..7045d64508 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpMetaDataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpMetaDataTests.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp [Fact] public void CloneIsDeep() { - var meta = new BmpMetadata() { BitsPerPixel = BmpBitsPerPixel.Pixel24 }; + var meta = new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel24 }; var clone = (BmpMetadata)meta.DeepClone(); clone.BitsPerPixel = BmpBitsPerPixel.Pixel32; diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index b2f9788ae4..62e9acf747 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.IO; @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Tests using (Image image = provider.GetImage()) { - image.DebugSave(provider, new PngEncoder() { ColorType = PngColorType.Palette, Quantizer = quantizer }, testOutputDetails: quantizerName); + image.DebugSave(provider, new PngEncoder { ColorType = PngColorType.Palette, Quantizer = quantizer }, testOutputDetails: quantizerName); } provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); @@ -201,4 +201,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index 784f7ce703..6c8732b5d8 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -37,14 +37,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif TestImages.Gif.Issues.BadDescriptorWidth }; - public static readonly TheoryData RatioFiles = - new TheoryData - { - { TestImages.Gif.Rings, (int)ImageMetadata.DefaultHorizontalResolution, (int)ImageMetadata.DefaultVerticalResolution , PixelResolutionUnit.PixelsPerInch}, - { TestImages.Gif.Ratio1x4, 1, 4 , PixelResolutionUnit.AspectRatio}, - { TestImages.Gif.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio } - }; - private static readonly Dictionary BasicVerificationFrameCount = new Dictionary { @@ -91,40 +83,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif } } - [Theory] - [MemberData(nameof(RatioFiles))] - public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) - { - var testFile = TestFile.Create(imagePath); - using (var stream = new MemoryStream(testFile.Bytes, false)) - { - var decoder = new GifDecoder(); - using (Image image = decoder.Decode(Configuration.Default, stream)) - { - ImageMetadata meta = image.Metadata; - Assert.Equal(xResolution, meta.HorizontalResolution); - Assert.Equal(yResolution, meta.VerticalResolution); - Assert.Equal(resolutionUnit, meta.ResolutionUnits); - } - } - } - - [Theory] - [MemberData(nameof(RatioFiles))] - public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) - { - var testFile = TestFile.Create(imagePath); - using (var stream = new MemoryStream(testFile.Bytes, false)) - { - var decoder = new GifDecoder(); - IImageInfo image = decoder.Identify(Configuration.Default, stream); - ImageMetadata meta = image.Metadata; - Assert.Equal(xResolution, meta.HorizontalResolution); - Assert.Equal(yResolution, meta.VerticalResolution); - Assert.Equal(resolutionUnit, meta.ResolutionUnits); - } - } - [Theory] [WithFile(TestImages.Gif.Trans, TestPixelTypes)] public void GifDecoder_IsNotBoundToSinglePixelType(TestImageProvider provider) @@ -155,57 +113,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif } } - [Fact] - public void Decode_IgnoreMetadataIsFalse_CommentsAreRead() - { - var options = new GifDecoder - { - IgnoreMetadata = false - }; - - var testFile = TestFile.Create(TestImages.Gif.Rings); - - using (Image image = testFile.CreateRgba32Image(options)) - { - Assert.Equal(1, image.Metadata.Properties.Count); - Assert.Equal("Comments", image.Metadata.Properties[0].Name); - Assert.Equal("ImageSharp", image.Metadata.Properties[0].Value); - } - } - - [Fact] - public void Decode_IgnoreMetadataIsTrue_CommentsAreIgnored() - { - var options = new GifDecoder - { - IgnoreMetadata = true - }; - - var testFile = TestFile.Create(TestImages.Gif.Rings); - - using (Image image = testFile.CreateRgba32Image(options)) - { - Assert.Equal(0, image.Metadata.Properties.Count); - } - } - - [Fact] - public void Decode_TextEncodingSetToUnicode_TextIsReadWithCorrectEncoding() - { - var options = new GifDecoder - { - TextEncoding = Encoding.Unicode - }; - - var testFile = TestFile.Create(TestImages.Gif.Rings); - - using (Image image = testFile.CreateRgba32Image(options)) - { - Assert.Equal(1, image.Metadata.Properties.Count); - Assert.Equal("浉条卥慨灲", image.Metadata.Properties[0].Value); - } - } - [Theory] [WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32)] public void CanDecodeJustOneFrame(TestImageProvider provider) @@ -246,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif public void CanDecodeIntermingledImages() { using (var kumin1 = Image.Load(TestFile.Create(TestImages.Gif.Kumin).Bytes)) - using (var icon = Image.Load(TestFile.Create(TestImages.Png.Icon).Bytes)) + using (Image.Load(TestFile.Create(TestImages.Png.Icon).Bytes)) using (var kumin2 = Image.Load(TestFile.Create(TestImages.Gif.Kumin).Bytes)) { for (int i = 0; i < kumin1.Frames.Count; i++) @@ -258,4 +165,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs index eab30944e9..d6d58eae7a 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.IO; @@ -32,10 +32,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif { using (Image image = provider.GetImage()) { - var encoder = new GifEncoder() + var encoder = new GifEncoder { - // Use the palette quantizer without dithering to ensure results - // are consistant + // Use the palette quantizer without dithering to ensure results + // are consistent Quantizer = new WebSafePaletteQuantizer(false) }; @@ -92,55 +92,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif memStream.Position = 0; using (var output = Image.Load(memStream)) { - Assert.Equal(1, output.Metadata.Properties.Count); - Assert.Equal("Comments", output.Metadata.Properties[0].Name); - Assert.Equal("ImageSharp", output.Metadata.Properties[0].Value); - } - } - } - } - - [Fact] - public void Encode_IgnoreMetadataIsTrue_CommentsAreNotWritten() - { - var options = new GifEncoder(); - - var testFile = TestFile.Create(TestImages.Gif.Rings); - - using (Image input = testFile.CreateRgba32Image()) - { - input.Metadata.Properties.Clear(); - using (var memStream = new MemoryStream()) - { - input.SaveAsGif(memStream, options); - - memStream.Position = 0; - using (var output = Image.Load(memStream)) - { - Assert.Equal(0, output.Metadata.Properties.Count); - } - } - } - } - - [Fact] - public void Encode_WhenCommentIsTooLong_CommentIsTrimmed() - { - using (var input = new Image(1, 1)) - { - string comments = new string('c', 256); - input.Metadata.Properties.Add(new ImageProperty("Comments", comments)); - - using (var memStream = new MemoryStream()) - { - input.Save(memStream, new GifEncoder()); - - memStream.Position = 0; - using (var output = Image.Load(memStream)) - { - Assert.Equal(1, output.Metadata.Properties.Count); - Assert.Equal("Comments", output.Metadata.Properties[0].Name); - Assert.Equal(255, output.Metadata.Properties[0].Value.Length); + GifMetadata metadata = output.Metadata.GetFormatMetadata(GifFormat.Instance); + Assert.Equal(1, metadata.Comments.Count); + Assert.Equal("ImageSharp", metadata.Comments[0]); } } } @@ -184,7 +138,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif GifMetadata metaData = image.Metadata.GetFormatMetadata(GifFormat.Instance); GifFrameMetadata frameMetaData = image.Frames.RootFrame.Metadata.GetFormatMetadata(GifFormat.Instance); GifColorTableMode colorMode = metaData.ColorTableMode; - var encoder = new GifEncoder() + var encoder = new GifEncoder { ColorTableMode = colorMode, Quantizer = new OctreeQuantizer(frameMetaData.ColorTableLength) @@ -196,7 +150,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif outStream.Position = 0; var clone = Image.Load(outStream); - GifMetadata cloneMetaData = clone.Metadata.GetFormatMetadata(GifFormat.Instance); + GifMetadata cloneMetaData = clone.Metadata.GetFormatMetadata(GifFormat.Instance); Assert.Equal(metaData.ColorTableMode, cloneMetaData.ColorTableMode); // Gifiddle and Cyotek GifInfo say this image has 64 colors. diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifFrameMetaDataTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifFrameMetaDataTests.cs index d82bfbf227..b891c8ed20 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifFrameMetaDataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifFrameMetaDataTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Formats.Gif; @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif [Fact] public void CloneIsDeep() { - var meta = new GifFrameMetadata() + var meta = new GifFrameMetadata { FrameDelay = 1, DisposalMethod = GifDisposalMethod.RestoreToBackground, diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifMetaDataTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifMetaDataTests.cs index 8510a3461c..a5bd6efbb0 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifMetaDataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifMetaDataTests.cs @@ -1,21 +1,38 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + using SixLabors.ImageSharp.Formats.Gif; +using SixLabors.ImageSharp.Metadata; +using SixLabors.ImageSharp.PixelFormats; + using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.Gif { public class GifMetaDataTests { + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Gif.Rings, (int)ImageMetadata.DefaultHorizontalResolution, (int)ImageMetadata.DefaultVerticalResolution , PixelResolutionUnit.PixelsPerInch}, + { TestImages.Gif.Ratio1x4, 1, 4 , PixelResolutionUnit.AspectRatio}, + { TestImages.Gif.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio } + }; + [Fact] public void CloneIsDeep() { - var meta = new GifMetadata() + var meta = new GifMetadata { RepeatCount = 1, ColorTableMode = GifColorTableMode.Global, - GlobalColorTableLength = 2 + GlobalColorTableLength = 2, + Comments = new List { "Foo" } }; var clone = (GifMetadata)meta.DeepClone(); @@ -27,6 +44,114 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif Assert.False(meta.RepeatCount.Equals(clone.RepeatCount)); Assert.False(meta.ColorTableMode.Equals(clone.ColorTableMode)); Assert.False(meta.GlobalColorTableLength.Equals(clone.GlobalColorTableLength)); + Assert.False(meta.Comments.Equals(clone.Comments)); + Assert.True(meta.Comments.SequenceEqual(clone.Comments)); + } + + [Fact] + public void Decode_IgnoreMetadataIsFalse_CommentsAreRead() + { + var options = new GifDecoder + { + IgnoreMetadata = false + }; + + var testFile = TestFile.Create(TestImages.Gif.Rings); + + using (Image image = testFile.CreateRgba32Image(options)) + { + GifMetadata metadata = image.Metadata.GetFormatMetadata(GifFormat.Instance); + Assert.Equal(1, metadata.Comments.Count); + Assert.Equal("ImageSharp", metadata.Comments[0]); + } + } + + [Fact] + public void Decode_IgnoreMetadataIsTrue_CommentsAreIgnored() + { + var options = new GifDecoder + { + IgnoreMetadata = true + }; + + var testFile = TestFile.Create(TestImages.Gif.Rings); + + using (Image image = testFile.CreateRgba32Image(options)) + { + GifMetadata metadata = image.Metadata.GetFormatMetadata(GifFormat.Instance); + Assert.Equal(0, metadata.Comments.Count); + } + } + + [Fact] + public void Decode_CanDecodeLargeTextComment() + { + var options = new GifDecoder(); + var testFile = TestFile.Create(TestImages.Gif.LargeComment); + + using (Image image = testFile.CreateRgba32Image(options)) + { + GifMetadata metadata = image.Metadata.GetFormatMetadata(GifFormat.Instance); + Assert.Equal(2, metadata.Comments.Count); + Assert.Equal(new string('c', 349), metadata.Comments[0]); + Assert.Equal("ImageSharp", metadata.Comments[1]); + } + } + + [Fact] + public void Encode_PreservesTextData() + { + var decoder = new GifDecoder(); + var testFile = TestFile.Create(TestImages.Gif.LargeComment); + + using (Image input = testFile.CreateRgba32Image(decoder)) + using (var memoryStream = new MemoryStream()) + { + input.Save(memoryStream, new GifEncoder()); + memoryStream.Position = 0; + + using (Image image = decoder.Decode(Configuration.Default, memoryStream)) + { + GifMetadata metadata = image.Metadata.GetFormatMetadata(GifFormat.Instance); + Assert.Equal(2, metadata.Comments.Count); + Assert.Equal(new string('c', 349), metadata.Comments[0]); + Assert.Equal("ImageSharp", metadata.Comments[1]); + } + } + } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new GifDecoder(); + IImageInfo image = decoder.Identify(Configuration.Default, stream); + ImageMetadata meta = image.Metadata; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new GifDecoder(); + using (Image image = decoder.Decode(Configuration.Default, stream)) + { + ImageMetadata meta = image.Metadata; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } } } } diff --git a/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs b/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs index 8628d054a0..9a15e1c1b3 100644 --- a/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs +++ b/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Tests } [Fact] - public void AddImageFormatDetectorNullthrows() + public void AddImageFormatDetectorNullThrows() { Assert.Throws(() => { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs index 7e7218c9dc..21b9b6cab6 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. // Uncomment this to turn unit tests into benchmarks: @@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg () => { // Block8x8F block = new Block8x8F(); - float[] block = new float[64]; + var block = new float[64]; for (int i = 0; i < Block8x8F.Size; i++) { block[i] = i; @@ -90,8 +90,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Fact] public void Load_Store_FloatArray() { - float[] data = new float[Block8x8F.Size]; - float[] mirror = new float[Block8x8F.Size]; + var data = new float[Block8x8F.Size]; + var mirror = new float[Block8x8F.Size]; for (int i = 0; i < Block8x8F.Size; i++) { @@ -115,8 +115,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Fact] public unsafe void Load_Store_FloatArray_Ptr() { - float[] data = new float[Block8x8F.Size]; - float[] mirror = new float[Block8x8F.Size]; + var data = new float[Block8x8F.Size]; + var mirror = new float[Block8x8F.Size]; for (int i = 0; i < Block8x8F.Size; i++) { @@ -140,8 +140,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Fact] public void Load_Store_IntArray() { - int[] data = new int[Block8x8F.Size]; - int[] mirror = new int[Block8x8F.Size]; + var data = new int[Block8x8F.Size]; + var mirror = new int[Block8x8F.Size]; for (int i = 0; i < Block8x8F.Size; i++) { @@ -174,7 +174,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg var dest = new Block8x8F(); source.TransposeInto(ref dest); - float[] actual = new float[64]; + var actual = new float[64]; dest.CopyTo(actual); Assert.Equal(expected, actual); @@ -186,13 +186,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } [Fact] - public void TranposeInto_Benchmark() + public void TransposeInto_Benchmark() { var source = new BufferHolder(); source.Buffer.LoadFrom(Create8x8FloatData()); var dest = new BufferHolder(); - this.Output.WriteLine($"TranposeInto_PinningImpl_Benchmark X {Times} ..."); + this.Output.WriteLine($"TransposeInto_PinningImpl_Benchmark X {Times} ..."); var sw = Stopwatch.StartNew(); for (int i = 0; i < Times; i++) @@ -201,12 +201,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } sw.Stop(); - this.Output.WriteLine($"TranposeInto_PinningImpl_Benchmark finished in {sw.ElapsedMilliseconds} ms"); + this.Output.WriteLine($"TransposeInto_PinningImpl_Benchmark finished in {sw.ElapsedMilliseconds} ms"); } private static float[] Create8x8ColorCropTestData() { - float[] result = new float[64]; + var result = new float[64]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) @@ -230,7 +230,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Block8x8F dest = block; dest.NormalizeColorsInplace(255); - float[] array = new float[64]; + var array = new float[64]; dest.CopyTo(array); this.Output.WriteLine("Result:"); this.PrintLinearData(array); @@ -426,7 +426,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg for (int i = 0; i < Block8x8F.Size; i++) { - Assert.Equal((float)data[i], dest[i]); + Assert.Equal(data[i], dest[i]); } } @@ -441,14 +441,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg short[] data = Create8x8ShortData(); var source = new Block8x8(data); - + Block8x8F dest = default; dest.LoadFromInt16ExtendedAvx2(ref source); for (int i = 0; i < Block8x8F.Size; i++) { - Assert.Equal((float)data[i], dest[i]); + Assert.Equal(data[i], dest[i]); } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs index 3df927aeb0..da75e059f4 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Fact] public unsafe void Indexer_GetScalarAt_SetScalarAt() { - int sum = 0; + int sum; var block = default(Block8x8); for (int i = 0; i < Block8x8.Size; i++) @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg for (int i = 0; i < Block8x8F.Size; i++) { - Assert.Equal((float)data[i], dest[i]); + Assert.Equal(data[i], dest[i]); } } @@ -141,4 +141,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.Equal(15, d); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs index 92b92eb100..91e2f43d35 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs @@ -21,8 +21,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Fact] public void iDCT2D8x4_LeftPart() { - float[] sourceArray = JpegFixture.Create8x8FloatData(); - float[] expectedDestArray = new float[64]; + float[] sourceArray = Create8x8FloatData(); + var expectedDestArray = new float[64]; ReferenceImplementations.LLM_FloatingPoint_DCT.iDCT2D8x4_32f(sourceArray, expectedDestArray); @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg FastFloatingPointDCT.IDCT8x4_LeftPart(ref source, ref dest); - float[] actualDestArray = new float[64]; + var actualDestArray = new float[64]; dest.CopyTo(actualDestArray); this.Print8x8Data(expectedDestArray); @@ -46,8 +46,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Fact] public void iDCT2D8x4_RightPart() { - float[] sourceArray = JpegFixture.Create8x8FloatData(); - float[] expectedDestArray = new float[64]; + float[] sourceArray = Create8x8FloatData(); + var expectedDestArray = new float[64]; ReferenceImplementations.LLM_FloatingPoint_DCT.iDCT2D8x4_32f(sourceArray.AsSpan(4), expectedDestArray.AsSpan(4)); @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg FastFloatingPointDCT.IDCT8x4_RightPart(ref source, ref dest); - float[] actualDestArray = new float[64]; + var actualDestArray = new float[64]; dest.CopyTo(actualDestArray); this.Print8x8Data(expectedDestArray); @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(3)] public void LLM_TransformIDCT_CompareToNonOptimized(int seed) { - float[] sourceArray = JpegFixture.Create8x8RoundedRandomFloatData(-1000, 1000, seed); + float[] sourceArray = Create8x8RoundedRandomFloatData(-1000, 1000, seed); var source = Block8x8F.Load(sourceArray); @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(3)] public void LLM_TransformIDCT_CompareToAccurate(int seed) { - float[] sourceArray = JpegFixture.Create8x8RoundedRandomFloatData(-1000, 1000, seed); + float[] sourceArray = Create8x8RoundedRandomFloatData(-1000, 1000, seed); var source = Block8x8F.Load(sourceArray); @@ -112,18 +112,18 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(2)] public void FDCT8x4_LeftPart(int seed) { - Span src = JpegFixture.Create8x8RoundedRandomFloatData(-200, 200, seed); + Span src = Create8x8RoundedRandomFloatData(-200, 200, seed); var srcBlock = new Block8x8F(); srcBlock.LoadFrom(src); var destBlock = new Block8x8F(); - float[] expectedDest = new float[64]; + var expectedDest = new float[64]; ReferenceImplementations.LLM_FloatingPoint_DCT.fDCT2D8x4_32f(src, expectedDest); FastFloatingPointDCT.FDCT8x4_LeftPart(ref srcBlock, ref destBlock); - float[] actualDest = new float[64]; + var actualDest = new float[64]; destBlock.CopyTo(actualDest); Assert.Equal(actualDest, expectedDest, new ApproximateFloatComparer(1f)); @@ -134,18 +134,18 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(2)] public void FDCT8x4_RightPart(int seed) { - Span src = JpegFixture.Create8x8RoundedRandomFloatData(-200, 200, seed); + Span src = Create8x8RoundedRandomFloatData(-200, 200, seed); var srcBlock = new Block8x8F(); srcBlock.LoadFrom(src); var destBlock = new Block8x8F(); - float[] expectedDest = new float[64]; + var expectedDest = new float[64]; ReferenceImplementations.LLM_FloatingPoint_DCT.fDCT2D8x4_32f(src.Slice(4), expectedDest.AsSpan(4)); FastFloatingPointDCT.FDCT8x4_RightPart(ref srcBlock, ref destBlock); - float[] actualDest = new float[64]; + var actualDest = new float[64]; destBlock.CopyTo(actualDest); Assert.Equal(actualDest, expectedDest, new ApproximateFloatComparer(1f)); @@ -156,20 +156,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(2)] public void TransformFDCT(int seed) { - Span src = JpegFixture.Create8x8RoundedRandomFloatData(-200, 200, seed); + Span src = Create8x8RoundedRandomFloatData(-200, 200, seed); var srcBlock = new Block8x8F(); srcBlock.LoadFrom(src); var destBlock = new Block8x8F(); - float[] expectedDest = new float[64]; - float[] temp1 = new float[64]; + var expectedDest = new float[64]; + var temp1 = new float[64]; var temp2 = new Block8x8F(); ReferenceImplementations.LLM_FloatingPoint_DCT.fDCT2D_llm(src, expectedDest, temp1, downscaleBy8: true); FastFloatingPointDCT.TransformFDCT(ref srcBlock, ref destBlock, ref temp2, false); - float[] actualDest = new float[64]; + var actualDest = new float[64]; destBlock.CopyTo(actualDest); Assert.Equal(actualDest, expectedDest, new ApproximateFloatComparer(1f)); @@ -177,4 +177,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs b/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs index 341d67f0f1..7c42af5961 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { for (int j = 0; j < 10; j++) { - var rgba = new Rgba32((byte)(i + 1), (byte)(j + 1), (byte)200, (byte)255); + var rgba = new Rgba32((byte)(i + 1), (byte)(j + 1), 200, 255); var color = default(TPixel); color.FromRgba32(rgba); @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Theory] [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Rgb24 | PixelTypes.Rgba32)] - public unsafe void LoadAndStretchCorners_WithOffset(TestImageProvider provider) + public void LoadAndStretchCorners_WithOffset(TestImageProvider provider) where TPixel : struct, IPixel { using (Image s = provider.GetImage()) @@ -121,4 +121,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.Equal(expected77, block[7, 7]); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs index 31a5a0eeb0..2485561f1e 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs @@ -36,6 +36,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Theory] [WithFileCollection(nameof(UnrecoverableTestJpegs), PixelTypes.Rgba32)] public void UnrecoverableImagesShouldThrowCorrectError(TestImageProvider provider) - where TPixel : struct, IPixel => Assert.Throws(() => provider.GetImage()); + where TPixel : struct, IPixel => Assert.Throws(provider.GetImage); } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs index 308cf28b35..1d5c3e27a4 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg public partial class JpegDecoderTests { - // TODO: A JPEGsnoop & metadata expert should review if the Exif/Icc expectations are correct. + // TODO: A JPEGsnoop & metadata expert should review if the Exif/Icc expectations are correct. // I'm seeing several entries with Exif-related names in images where we do not decode an exif profile. (- Anton) public static readonly TheoryData MetaDataTestData = new TheoryData @@ -211,7 +211,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(true)] public void IgnoreMetaData_ControlsWhetherMetaDataIsParsed(bool ignoreMetaData) { - var decoder = new JpegDecoder() { IgnoreMetadata = ignoreMetaData }; + var decoder = new JpegDecoder { IgnoreMetadata = ignoreMetaData }; // Snake.jpg has both Exif and ICC profiles defined: var testFile = TestFile.Create(TestImages.Jpeg.Baseline.Snake); @@ -257,4 +257,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg }); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index e316fe67eb..a9cddebc85 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg return; } - // For 32 bit test enviroments: + // For 32 bit test environments: provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); using (Image image = provider.GetImage(JpegDecoder)) @@ -107,25 +107,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); } - private string GetDifferenceInPercentageString(Image image, TestImageProvider provider) - where TPixel : struct, IPixel - { - var reportingComparer = ImageComparer.Tolerant(0, 0); - - ImageSimilarityReport report = image.GetReferenceOutputSimilarityReports( - provider, - reportingComparer, - appendPixelTypeToFileName: false - ).SingleOrDefault(); - - if (report?.TotalNormalizedDifference != null) - { - return report.DifferencePercentageString; - } - - return "0%"; - } - // DEBUG ONLY! // The PDF.js output should be saved by "tests\ImageSharp.Tests\Formats\Jpg\pdfjs\jpeg-converter.htm" // into "\tests\Images\ActualOutput\JpegDecoderTests\" @@ -158,4 +139,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs index d9013b507e..639ec520ec 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.IO; @@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg // There is no alpha in Jpeg! image.Mutate(c => c.MakeOpaque()); - var encoder = new JpegEncoder() + var encoder = new JpegEncoder { Subsample = subsample, Quality = quality @@ -198,4 +198,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegMetaDataTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegMetaDataTests.cs index 793bdd5229..59ad571f49 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegMetaDataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegMetaDataTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Formats.Jpeg; @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Fact] public void CloneIsDeep() { - var meta = new JpegMetadata() { Quality = 50 }; + var meta = new JpegMetadata { Quality = 50 }; var clone = (JpegMetadata)meta.DeepClone(); clone.Quality = 99; @@ -19,4 +19,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.False(meta.Quality.Equals(clone.Quality)); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs index 3657110c6c..1d7ca746f6 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs @@ -30,11 +30,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(TestImages.Jpeg.Baseline.Cmyk, JpegColorSpace.Cmyk)] public void ColorSpace_IsDeducedCorrectly(string imageFile, object expectedColorSpaceValue) { - var expecteColorSpace = (JpegColorSpace)expectedColorSpaceValue; + var expectedColorSpace = (JpegColorSpace)expectedColorSpaceValue; using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile)) { - Assert.Equal(expecteColorSpace, decoder.ColorSpace); + Assert.Equal(expectedColorSpace, decoder.ColorSpace); } } @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg this.Output.WriteLine(sb.ToString()); } - public static readonly TheoryData ComponentVerificationData = new TheoryData() + public static readonly TheoryData ComponentVerificationData = new TheoryData { { TestImages.Jpeg.Baseline.Jpeg444, 3, new Size(1, 1), new Size(1, 1) }, { TestImages.Jpeg.Baseline.Jpeg420Exif, 3, new Size(2, 2), new Size(1, 1) }, @@ -131,4 +131,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs index dd2113624e..82fcc368fc 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(2)] public void ForwardThenInverse(int seed) { - float[] data = JpegFixture.Create8x8RandomFloatData(-1000, 1000, seed); + float[] data = Create8x8RandomFloatData(-1000, 1000, seed); var b0 = default(Block8x8F); b0.LoadFrom(data); @@ -36,4 +36,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs index ce6f0a744f..60a019c290 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(2, 0)] public void LLM_ForwardThenInverse(int seed, int startAt) { - int[] data = JpegFixture.Create8x8RandomIntData(-1000, 1000, seed); + int[] data = Create8x8RandomIntData(-1000, 1000, seed); float[] original = data.ConvertAllToFloat(); float[] src = data.ConvertAllToFloat(); float[] dest = new float[64]; @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(2, 200)] public void LLM_IDCT_IsEquivalentTo_AccurateImplementation(int seed, int range) { - float[] sourceArray = JpegFixture.Create8x8RoundedRandomFloatData(-range, range, seed); + float[] sourceArray = Create8x8RoundedRandomFloatData(-range, range, seed); var source = Block8x8F.Load(sourceArray); @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(2)] public void LLM_FDCT_IsEquivalentTo_AccurateImplementation(int seed) { - float[] floatData = JpegFixture.Create8x8RandomFloatData(-1000, 1000); + float[] floatData = Create8x8RandomFloatData(-1000, 1000); Block8x8F source = default; source.LoadFrom(floatData); @@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(2, 200)] public void GT_IDCT_IsEquivalentTo_AccurateImplementation(int seed, int range) { - int[] intData = JpegFixture.Create8x8RandomIntData(-range, range, seed); + int[] intData = Create8x8RandomIntData(-range, range, seed); float[] floatSrc = intData.ConvertAllToFloat(); ReferenceImplementations.AccurateDCT.TransformIDCTInplace(intData); @@ -120,4 +120,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs index f299807fc7..f16d04bf60 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(2, 0)] public void ForwardThenInverse(int seed, int startAt) { - Span original = JpegFixture.Create8x8RandomIntData(-200, 200, seed); + Span original = Create8x8RandomIntData(-200, 200, seed); Span block = original.AddScalarToAllValues(128); @@ -80,11 +80,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg for (int i = startAt; i < 64; i++) { float expected = original[i]; - float actual = (float)block[i]; + float actual = block[i]; Assert.Equal(expected, actual, new ApproximateFloatComparer(3f)); } } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs index 89fdd5745e..20830a33f5 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. // ReSharper disable InconsistentNaming @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils // ReSharper disable once InconsistentNaming public static float[] Create8x8FloatData() { - float[] result = new float[64]; + var result = new float[64]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) @@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils // ReSharper disable once InconsistentNaming public static int[] Create8x8IntData() { - int[] result = new int[64]; + var result = new int[64]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils // ReSharper disable once InconsistentNaming public static short[] Create8x8ShortData() { - short[] result = new short[64]; + var result = new short[64]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public static int[] Create8x8RandomIntData(int minValue, int maxValue, int seed = 42) { var rnd = new Random(seed); - int[] result = new int[64]; + var result = new int[64]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public static float[] Create8x8RandomFloatData(float minValue, float maxValue, int seed = 42) { var rnd = new Random(seed); - float[] result = new float[64]; + var result = new float[64]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) @@ -189,4 +189,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index e4fcd10c5f..91cd80d144 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -52,8 +52,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils internal void MakeBlock(short[] data, int y, int x) { - this.MinVal = Math.Min((short)this.MinVal, data.Min()); - this.MaxVal = Math.Max((short)this.MaxVal, data.Max()); + this.MinVal = Math.Min(this.MinVal, data.Min()); + this.MaxVal = Math.Max(this.MaxVal, data.Max()); this.SpectralBlocks[x, y] = new Block8x8(data); } @@ -189,4 +189,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs index f5618d26d2..ac9e2835c2 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils internal static partial class LibJpegTools { /// - /// Stores spectral jpeg compoent data in libjpeg-compatible style. + /// Stores spectral jpeg component data in libjpeg-compatible style. /// public class SpectralData : IEquatable { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs index 3de4673f5d..31779df453 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { TestFile testFile = TestFile.Create(inputFile); - string outDir = TestEnvironment.CreateOutputDirectory(".Temp", $"JpegCoeffs"); + string outDir = TestEnvironment.CreateOutputDirectory(".Temp", "JpegCoeffs"); string fn = $"{Path.GetFileName(inputFile)}-{new Random().Next(1000)}.dctcoeffs"; string coeffFileFullPath = Path.Combine(outDir, fn); @@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils result[i] = resultComponent; } - byte[] buffer = new byte[64 * sizeof(short)]; + var buffer = new byte[64 * sizeof(short)]; for (int i = 0; i < result.Length; i++) { @@ -139,4 +139,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs index 2712d1933c..58fa4231e6 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs @@ -14,12 +14,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils /// /* reference idct taken from "ieeetest.c" /// * Written by Tom Lane (tgl@cs.cmu.edu). /// * Released to public domain 11/22/93. - /// */ + /// */ /// internal static class AccurateDCT { private static double[,] CosLut = InitCosLut(); - + public static Block8x8 TransformIDCT(ref Block8x8 block) { Block8x8F temp = block.AsFloatBlock(); @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils for (v=0; v<8; v++) { tmp2 = 0.0; for (u=0; u<8; u++) { - tmp2 += (double) block[v * 8 + u] * CosLut[x, u]; + tmp2 += block[v * 8 + u] * CosLut[x, u]; } tmp += CosLut[y, v] * tmp2; } @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils } return res; } - + public static Block8x8F TransformFDCT(ref Block8x8F block) { int x, y, u, v; @@ -88,27 +88,27 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils tmp2 = 0.0; for (x = 0; x < 8; x++) { - tmp2 += (double)block[y * 8 + x] * CosLut[x,u]; + tmp2 += block[y * 8 + x] * CosLut[x,u]; } tmp += CosLut[y, v] * tmp2; } res[v * 8 + u] = (float) tmp; } } - + return res; } private static double[,] InitCosLut() { - double[,] coslu = new double[8, 8]; + var coslu = new double[8, 8]; int a, b; double tmp; for (a = 0; a < 8; a++) for (b = 0; b < 8; b++) { - tmp = Math.Cos((double)((a + a + 1) * b) * (3.14159265358979323846 / 16.0)); + tmp = Math.Cos((a + a + 1) * b * (3.14159265358979323846 / 16.0)); if (b == 0) { tmp /= Math.Sqrt(2.0); @@ -119,4 +119,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs index 46f4fe14dc..0c644e5c21 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs @@ -14,14 +14,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils /// /// Contains port of non-optimized methods in: /// https://github.com/norishigefukushima/dct_simd/blob/master/dct/dct8x8_simd.cpp - /// + /// /// *** Paper *** /// paper LLM89 - /// C. Loeffler, A. Ligtenberg, and G. S. Moschytz, + /// C. Loeffler, A. Ligtenberg, and G. S. Moschytz, /// "Practical fast 1-D DCT algorithms with 11 multiplications," /// Proc. Int'l. Conf. on Acoustics, Speech, and Signal Processing (ICASSP89), pp. 988-991, 1989. - /// - /// The main purpose of this code is testing and documentation, it is intented to be similar to it's original counterpart. + /// + /// The main purpose of this code is testing and documentation, it is intended to be similar to it's original counterpart. /// DO NOT clean it! /// DO NOT StyleCop it! /// @@ -29,10 +29,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { public static Block8x8F TransformIDCT(ref Block8x8F source) { - float[] s = new float[64]; + var s = new float[64]; source.CopyTo(s); - float[] d = new float[64]; - float[] temp = new float[64]; + var d = new float[64]; + var temp = new float[64]; iDCT2D_llm(s, d, temp); Block8x8F result = default; @@ -42,10 +42,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public static Block8x8F TransformFDCT_UpscaleBy8(ref Block8x8F source) { - float[] s = new float[64]; + var s = new float[64]; source.CopyTo(s); - float[] d = new float[64]; - float[] temp = new float[64]; + var d = new float[64]; + var temp = new float[64]; fDCT2D_llm(s, d, temp); Block8x8F result = default; @@ -61,10 +61,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public static float[] PrintConstants(ITestOutputHelper output) { - float[] r = new float[8]; + var r = new float[8]; for (int i = 0; i < 8; i++) { - r[i] = (float)(Cos((double)i / 16.0 * M_PI) * M_SQRT2); + r[i] = (float)(Cos(i / 16.0 * M_PI) * M_SQRT2); output?.WriteLine($"float r{i} = {r[i]:R}f;"); } return r; @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils /// /// Original: https://github.com/norishigefukushima/dct_simd/blob/master/dct/dct8x8_simd.cpp#L239 - /// Applyies IDCT transformation on "s" copying transformed values to "d", using temporary block "temp" + /// Applies IDCT transformation on "s" copying transformed values to "d", using temporary block "temp" /// /// /// @@ -267,13 +267,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public static void fDCT8x8_llm_sse(Span s, Span d, Span temp) { - ReferenceImplementations.Transpose8x8(s, temp); + Transpose8x8(s, temp); fDCT2D8x4_32f(temp, d); fDCT2D8x4_32f(temp.Slice(4), d.Slice(4)); - ReferenceImplementations.Transpose8x8(d, temp); + Transpose8x8(d, temp); fDCT2D8x4_32f(temp, d); @@ -466,7 +466,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { float t0, t1, t2, t3, t4, t5, t6, t7; float c0, c1, c2, c3; - float[] r = new float[8]; + var r = new float[8]; //for(i = 0;i < 8;i++){ r[i] = (float)(cos((double)i / 16.0 * M_PI) * M_SQRT2); } r[0] = 1.414214f; @@ -535,14 +535,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils fDCT1Dllm_32f(sWorker.Slice(j * 8), temp.Slice(j * 8)); } - ReferenceImplementations.Transpose8x8(temp, d); + Transpose8x8(temp, d); for (int j = 0; j < 8; j++) { fDCT1Dllm_32f(d.Slice(j * 8), temp.Slice(j * 8)); } - ReferenceImplementations.Transpose8x8(temp, d); + Transpose8x8(temp, d); if (downscaleBy8) { @@ -554,4 +554,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs index 18c0bdb50e..a929e0eb02 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs @@ -9,18 +9,18 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { /// /// TODO: produces really bad results for bigger values! - /// + /// /// Contains the "original" golang based DCT/IDCT implementations as reference implementations. /// 1. ===== Forward DCT ===== /// **** The original golang source claims: /// It is based on the code in jfdctint.c from the Independent JPEG Group, /// found at http://www.ijg.org/files/jpegsrc.v8c.tar.gz. - /// + /// /// **** Could be found here as well: - /// https://github.com/mozilla/mozjpeg/blob/master/jfdctint.c - /// + /// https://github.com/mozilla/mozjpeg/blob/master/jfdctint.c + /// /// 2. ===== Inverse DCT ===== - /// + /// /// The golang source claims: /// http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_IEC_13818-4_2004_Conformance_Testing/Video/verifier/mpeg2decode_960109.tar.gz /// The referenced MPEG2 code claims: @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils /// /* coefficients extended to 12 bit for IEEE1180-1990 */ /// /* compliance sE, 2.1.94 */ /// /**********************************************************/ - /// + /// /// **** The code looks pretty similar to the standard libjpeg IDCT, but without quantization: /// https://github.com/mozilla/mozjpeg/blob/master/jidctint.c /// @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public static Block8x8 Subtract128_TransformFDCT_Upscale8(ref Block8x8 block) { - int[] temp = new int[Block8x8.Size]; + var temp = new int[Block8x8.Size]; block.CopyTo(temp); Subtract128_TransformFDCT_Upscale8_Inplace(temp); var result = default(Block8x8); @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils // [Obsolete("Looks like this method produces really bad results for bigger values!")] public static Block8x8 TransformIDCT(ref Block8x8 block) { - int[] temp = new int[Block8x8.Size]; + var temp = new int[Block8x8.Size]; block.CopyTo(temp); TransformIDCTInplace(temp); var result = default(Block8x8); @@ -364,4 +364,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs index f5940e05d4..527cc3feda 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. // ReSharper disable InconsistentNaming @@ -11,7 +11,7 @@ using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { /// - /// This class contains simplified (unefficient) reference implementations to produce verification data for unit tests + /// This class contains simplified (inefficient) reference implementations to produce verification data for unit tests /// Floating point DCT code Ported from https://github.com/norishigefukushima/dct_simd /// internal static partial class ReferenceImplementations @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils /// Rounds a rational number defined as dividend/divisor into an integer /// /// The dividend - /// The divisior + /// The divisor /// [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int RationalRound(int dividend, int divisor) @@ -144,4 +144,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils return -((-dividend + (divisor >> 1)) / divisor); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/SpanExtensions.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/SpanExtensions.cs index e9527e4c3b..142e38dc0a 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/SpanExtensions.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/SpanExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -75,10 +75,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils /// A new with float values public static float[] ConvertAllToFloat(this int[] src) { - float[] result = new float[src.Length]; + var result = new float[src.Length]; for (int i = 0; i < src.Length; i++) { - result[i] = (float)src[i]; + result[i] = src[i]; } return result; @@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils /// A new instance of public static Span AddScalarToAllValues(this Span src, float scalar) { - float[] result = new float[src.Length]; + var result = new float[src.Length]; for (int i = 0; i < src.Length; i++) { result[i] = src[i] + scalar; @@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils /// A new instance of public static Span AddScalarToAllValues(this Span src, int scalar) { - int[] result = new int[src.Length]; + var result = new int[src.Length]; for (int i = 0; i < src.Length; i++) { result[i] = src[i] + scalar; @@ -118,4 +118,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils return result; } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ZigZagTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ZigZagTests.cs index e59584991e..61a5d8f1d8 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ZigZagTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ZigZagTests.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg public void ZigZagCanHandleAllPossibleCoefficients() { // Mimic the behaviour of the huffman scan decoder using all possible byte values - short[] block = new short[64]; + var block = new short[64]; var zigzag = ZigZag.CreateUnzigTable(); for (int h = 0; h < 255; h++) diff --git a/tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs index 894d902b78..64a394cc98 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Buffers.Binary; +using System.Buffers.Binary; using System.Text; using SixLabors.ImageSharp.Formats.Png; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs index 6a0119f0f1..e976d5a768 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs @@ -1,4 +1,4 @@ -using System.Buffers.Binary; +using System.Buffers.Binary; using System.IO; using System.Text; @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png private static string GetChunkTypeName(uint value) { - byte[] data = new byte[4]; + var data = new byte[4]; BinaryPrimitives.WriteUInt32BigEndian(data, value); @@ -125,4 +125,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png memStream.Position = 0; } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index 5bb2db7848..2e9fd7481e 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -3,12 +3,9 @@ // ReSharper disable InconsistentNaming -using System.Buffers.Binary; using System.IO; -using System.Text; using SixLabors.ImageSharp.Formats.Png; -using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; @@ -77,14 +74,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png TestImages.Png.GrayAlpha8BitInterlaced }; - public static readonly TheoryData RatioFiles = - new TheoryData - { - { TestImages.Png.Splash, 11810, 11810 , PixelResolutionUnit.PixelsPerMeter}, - { TestImages.Png.Ratio1x4, 1, 4 , PixelResolutionUnit.AspectRatio}, - { TestImages.Png.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio } - }; - [Theory] [WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)] public void Decode(TestImageProvider provider) @@ -193,57 +182,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png } } - [Fact] - public void Decode_IgnoreMetadataIsFalse_TextChunckIsRead() - { - var options = new PngDecoder() - { - IgnoreMetadata = false - }; - - var testFile = TestFile.Create(TestImages.Png.Blur); - - using (Image image = testFile.CreateRgba32Image(options)) - { - Assert.Equal(1, image.Metadata.Properties.Count); - Assert.Equal("Software", image.Metadata.Properties[0].Name); - Assert.Equal("paint.net 4.0.6", image.Metadata.Properties[0].Value); - } - } - - [Fact] - public void Decode_IgnoreMetadataIsTrue_TextChunksAreIgnored() - { - var options = new PngDecoder() - { - IgnoreMetadata = true - }; - - var testFile = TestFile.Create(TestImages.Png.Blur); - - using (Image image = testFile.CreateRgba32Image(options)) - { - Assert.Equal(0, image.Metadata.Properties.Count); - } - } - - [Fact] - public void Decode_TextEncodingSetToUnicode_TextIsReadWithCorrectEncoding() - { - var options = new PngDecoder() - { - TextEncoding = Encoding.Unicode - }; - - var testFile = TestFile.Create(TestImages.Png.Blur); - - using (Image image = testFile.CreateRgba32Image(options)) - { - Assert.Equal(1, image.Metadata.Properties.Count); - Assert.Equal("潓瑦慷敲", image.Metadata.Properties[0].Name); - } - } - [Theory] [InlineData(TestImages.Png.Bpp1, 1)] [InlineData(TestImages.Png.Gray4Bpp, 4)] @@ -260,39 +198,5 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png Assert.Equal(expectedPixelSize, Image.Identify(stream)?.PixelType?.BitsPerPixel); } } - - [Theory] - [MemberData(nameof(RatioFiles))] - public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) - { - var testFile = TestFile.Create(imagePath); - using (var stream = new MemoryStream(testFile.Bytes, false)) - { - var decoder = new PngDecoder(); - using (Image image = decoder.Decode(Configuration.Default, stream)) - { - ImageMetadata meta = image.Metadata; - Assert.Equal(xResolution, meta.HorizontalResolution); - Assert.Equal(yResolution, meta.VerticalResolution); - Assert.Equal(resolutionUnit, meta.ResolutionUnits); - } - } - } - - [Theory] - [MemberData(nameof(RatioFiles))] - public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) - { - var testFile = TestFile.Create(imagePath); - using (var stream = new MemoryStream(testFile.Bytes, false)) - { - var decoder = new PngDecoder(); - IImageInfo image = decoder.Identify(Configuration.Default, stream); - ImageMetadata meta = image.Metadata; - Assert.Equal(xResolution, meta.HorizontalResolution); - Assert.Equal(yResolution, meta.VerticalResolution); - Assert.Equal(resolutionUnit, meta.ResolutionUnits); - } - } } } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index b8178fd4f3..2584391bb7 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. // ReSharper disable InconsistentNaming @@ -76,6 +76,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png 80, 100, 120, 230 }; + public static readonly PngInterlaceMode[] InterlaceMode = new[] + { + PngInterlaceMode.None, + PngInterlaceMode.Adam7 + }; + public static readonly TheoryData RatioFiles = new TheoryData { @@ -99,6 +105,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png pngColorType, PngFilterMethod.Adaptive, PngBitDepth.Bit8, + PngInterlaceMode.None, appendPngColorType: true); } @@ -107,13 +114,17 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png public void IsNotBoundToSinglePixelType(TestImageProvider provider, PngColorType pngColorType) where TPixel : struct, IPixel { - TestPngEncoderCore( + foreach (PngInterlaceMode interlaceMode in InterlaceMode) + { + TestPngEncoderCore( provider, pngColorType, PngFilterMethod.Adaptive, PngBitDepth.Bit8, + interlaceMode, appendPixelType: true, appendPngColorType: true); + } } [Theory] @@ -121,12 +132,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png public void WorksWithAllFilterMethods(TestImageProvider provider, PngFilterMethod pngFilterMethod) where TPixel : struct, IPixel { - TestPngEncoderCore( + foreach (PngInterlaceMode interlaceMode in InterlaceMode) + { + TestPngEncoderCore( provider, PngColorType.RgbWithAlpha, pngFilterMethod, PngBitDepth.Bit8, + interlaceMode, appendPngFilterMethod: true); + } } [Theory] @@ -134,13 +149,17 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png public void WorksWithAllCompressionLevels(TestImageProvider provider, int compressionLevel) where TPixel : struct, IPixel { - TestPngEncoderCore( + foreach (PngInterlaceMode interlaceMode in InterlaceMode) + { + TestPngEncoderCore( provider, PngColorType.RgbWithAlpha, PngFilterMethod.Adaptive, PngBitDepth.Bit8, + interlaceMode, compressionLevel, appendCompressionLevel: true); + } } [Theory] @@ -162,14 +181,18 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png public void WorksWithAllBitDepths(TestImageProvider provider, PngColorType pngColorType, PngBitDepth pngBitDepth) where TPixel : struct, IPixel { - TestPngEncoderCore( + foreach (PngInterlaceMode interlaceMode in InterlaceMode) + { + TestPngEncoderCore( provider, pngColorType, PngFilterMethod.Adaptive, pngBitDepth, + interlaceMode, appendPngColorType: true, appendPixelType: true, appendPngBitDepth: true); + } } [Theory] @@ -177,13 +200,17 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png public void PaletteColorType_WuQuantizer(TestImageProvider provider, int paletteSize) where TPixel : struct, IPixel { - TestPngEncoderCore( + foreach (PngInterlaceMode interlaceMode in InterlaceMode) + { + TestPngEncoderCore( provider, PngColorType.Palette, PngFilterMethod.Adaptive, PngBitDepth.Bit8, + interlaceMode, paletteSize: paletteSize, appendPaletteSize: true); + } } [Theory] @@ -271,7 +298,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png using (Image input = testFile.CreateRgba32Image()) { PngMetadata inMeta = input.Metadata.GetFormatMetadata(PngFormat.Instance); - Assert.True(inMeta.HasTrans); + Assert.True(inMeta.HasTransparency); using (var memStream = new MemoryStream()) { @@ -280,7 +307,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png using (var output = Image.Load(memStream)) { PngMetadata outMeta = output.Metadata.GetFormatMetadata(PngFormat.Instance); - Assert.True(outMeta.HasTrans); + Assert.True(outMeta.HasTransparency); switch (pngColorType) { @@ -321,6 +348,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png PngColorType pngColorType, PngFilterMethod pngFilterMethod, PngBitDepth bitDepth, + PngInterlaceMode interlaceMode, int compressionLevel = 6, int paletteSize = 255, bool appendPngColorType = false, @@ -339,7 +367,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png FilterMethod = pngFilterMethod, CompressionLevel = compressionLevel, BitDepth = bitDepth, - Quantizer = new WuQuantizer(paletteSize) + Quantizer = new WuQuantizer(paletteSize), + InterlaceMethod = interlaceMode }; string pngColorTypeInfo = appendPngColorType ? pngColorType.ToString() : string.Empty; @@ -347,15 +376,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png string compressionLevelInfo = appendCompressionLevel ? $"_C{compressionLevel}" : string.Empty; string paletteSizeInfo = appendPaletteSize ? $"_PaletteSize-{paletteSize}" : string.Empty; string pngBitDepthInfo = appendPngBitDepth ? bitDepth.ToString() : string.Empty; - string debugInfo = $"{pngColorTypeInfo}{pngFilterMethodInfo}{compressionLevelInfo}{paletteSizeInfo}{pngBitDepthInfo}"; + string pngInterlaceModeInfo = interlaceMode != PngInterlaceMode.None ? $"_{interlaceMode}" : string.Empty; + + string debugInfo = $"{pngColorTypeInfo}{pngFilterMethodInfo}{compressionLevelInfo}{paletteSizeInfo}{pngBitDepthInfo}{pngInterlaceModeInfo}"; string actualOutputFile = provider.Utility.SaveTestOutputFile(image, "png", encoder, debugInfo, appendPixelType); // Compare to the Magick reference decoder. IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile); - // We compare using both our decoder and the reference decoder as pixel transformation - // occurrs within the encoder itself leaving the input image unaffected. + // occurs within the encoder itself leaving the input image unaffected. // This means we are benefiting from testing our decoder also. using (var imageSharpImage = Image.Load(actualOutputFile, new PngDecoder())) using (var referenceImage = Image.Load(actualOutputFile, referenceDecoder)) @@ -365,4 +395,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Png/PngMetaDataTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngMetaDataTests.cs index 72fc2f8656..dfa7fd2922 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngMetaDataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngMetaDataTests.cs @@ -1,31 +1,223 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.Collections.Generic; +using System.IO; +using System.Linq; using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.Metadata; +using SixLabors.ImageSharp.PixelFormats; using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.Png { public class PngMetaDataTests { + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Png.Splash, 11810, 11810 , PixelResolutionUnit.PixelsPerMeter}, + { TestImages.Png.Ratio1x4, 1, 4 , PixelResolutionUnit.AspectRatio}, + { TestImages.Png.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio } + }; + [Fact] public void CloneIsDeep() { - var meta = new PngMetadata() + var meta = new PngMetadata { BitDepth = PngBitDepth.Bit16, ColorType = PngColorType.GrayscaleWithAlpha, - Gamma = 2 + InterlaceMethod = PngInterlaceMode.Adam7, + Gamma = 2, + TextData = new List { new PngTextData("name", "value", "foo", "bar") } }; + var clone = (PngMetadata)meta.DeepClone(); clone.BitDepth = PngBitDepth.Bit2; clone.ColorType = PngColorType.Palette; + clone.InterlaceMethod = PngInterlaceMode.None; clone.Gamma = 1; - Assert.False(meta.BitDepth.Equals(clone.BitDepth)); - Assert.False(meta.ColorType.Equals(clone.ColorType)); + Assert.False(meta.BitDepth == clone.BitDepth); + Assert.False(meta.ColorType == clone.ColorType); + Assert.False(meta.InterlaceMethod == clone.InterlaceMethod); Assert.False(meta.Gamma.Equals(clone.Gamma)); + Assert.False(meta.TextData.Equals(clone.TextData)); + Assert.True(meta.TextData.SequenceEqual(clone.TextData)); + } + + [Theory] + [WithFile(TestImages.Png.PngWithMetaData, PixelTypes.Rgba32)] + public void Decoder_CanReadTextData(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage(new PngDecoder())) + { + PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Comment") && m.Value.Equals("comment")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Author") && m.Value.Equals("ImageSharp")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Copyright") && m.Value.Equals("ImageSharp")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Title") && m.Value.Equals("unittest")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Description") && m.Value.Equals("compressed-text")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("International") && m.Value.Equals("'e', mu'tlheghvam, ghaH yu'") && m.LanguageTag.Equals("x-klingon") && m.TranslatedKeyword.Equals("warning")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("International2") && m.Value.Equals("ИМАГЕШАРП") && m.LanguageTag.Equals("rus")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational") && m.Value.Equals("la plume de la mante") && m.LanguageTag.Equals("fra") && m.TranslatedKeyword.Equals("foobar")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational2") && m.Value.Equals("這是一個考驗") && m.LanguageTag.Equals("chinese")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoLang") && m.Value.Equals("this text chunk is missing a language tag")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoTranslatedKeyword") && m.Value.Equals("dieser chunk hat kein übersetztes Schlüßelwort")); + } + } + + [Theory] + [WithFile(TestImages.Png.PngWithMetaData, PixelTypes.Rgba32)] + public void Encoder_PreservesTextData(TestImageProvider provider) + where TPixel : struct, IPixel + { + var decoder = new PngDecoder(); + using (Image input = provider.GetImage(decoder)) + using (var memoryStream = new MemoryStream()) + { + input.Save(memoryStream, new PngEncoder()); + + memoryStream.Position = 0; + using (Image image = decoder.Decode(Configuration.Default, memoryStream)) + { + PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Comment") && m.Value.Equals("comment")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Author") && m.Value.Equals("ImageSharp")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Copyright") && m.Value.Equals("ImageSharp")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Title") && m.Value.Equals("unittest")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Description") && m.Value.Equals("compressed-text")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("International") && m.Value.Equals("'e', mu'tlheghvam, ghaH yu'") && m.LanguageTag.Equals("x-klingon") && m.TranslatedKeyword.Equals("warning")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("International2") && m.Value.Equals("ИМАГЕШАРП") && m.LanguageTag.Equals("rus")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational") && m.Value.Equals("la plume de la mante") && m.LanguageTag.Equals("fra") && m.TranslatedKeyword.Equals("foobar")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational2") && m.Value.Equals("這是一個考驗") && m.LanguageTag.Equals("chinese")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoLang") && m.Value.Equals("this text chunk is missing a language tag")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoTranslatedKeyword") && m.Value.Equals("dieser chunk hat kein übersetztes Schlüßelwort")); + } + } + } + + [Theory] + [WithFile(TestImages.Png.InvalidTextData, PixelTypes.Rgba32)] + public void Decoder_IgnoresInvalidTextData(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage(new PngDecoder())) + { + PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("leading space")); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("trailing space")); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("space")); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("empty")); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("invalid characters")); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("too large")); + } + } + + [Theory] + [WithFile(TestImages.Png.PngWithMetaData, PixelTypes.Rgba32)] + public void Encode_UseCompression_WhenTextIsGreaterThenThreshold_Works(TestImageProvider provider) + where TPixel : struct, IPixel + { + var decoder = new PngDecoder(); + using (Image input = provider.GetImage(decoder)) + using (var memoryStream = new MemoryStream()) + { + // this will be a zTXt chunk. + var expectedText = new PngTextData("large-text", new string('c', 100), string.Empty, string.Empty); + // this will be a iTXt chunk. + var expectedTextNoneLatin = new PngTextData("large-text-non-latin", new string('Ф', 100), "language-tag", "translated-keyword"); + PngMetadata inputMetadata = input.Metadata.GetFormatMetadata(PngFormat.Instance); + inputMetadata.TextData.Add(expectedText); + inputMetadata.TextData.Add(expectedTextNoneLatin); + input.Save(memoryStream, new PngEncoder + { + TextCompressionThreshold = 50 + }); + + memoryStream.Position = 0; + using (Image image = decoder.Decode(Configuration.Default, memoryStream)) + { + PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance); + Assert.Contains(meta.TextData, m => m.Equals(expectedText)); + Assert.Contains(meta.TextData, m => m.Equals(expectedTextNoneLatin)); + } + } + } + + [Fact] + public void Decode_IgnoreMetadataIsFalse_TextChunkIsRead() + { + var options = new PngDecoder + { + IgnoreMetadata = false + }; + + var testFile = TestFile.Create(TestImages.Png.Blur); + + using (Image image = testFile.CreateRgba32Image(options)) + { + PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance); + + Assert.Equal(1, meta.TextData.Count); + Assert.Equal("Software", meta.TextData[0].Keyword); + Assert.Equal("paint.net 4.0.6", meta.TextData[0].Value); + Assert.Equal(0.4545d, meta.Gamma, precision: 4); + } + } + + [Fact] + public void Decode_IgnoreMetadataIsTrue_TextChunksAreIgnored() + { + var options = new PngDecoder + { + IgnoreMetadata = true + }; + + var testFile = TestFile.Create(TestImages.Png.Blur); + + using (Image image = testFile.CreateRgba32Image(options)) + { + PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance); + Assert.Equal(0, meta.TextData.Count); + } + } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new PngDecoder(); + using (Image image = decoder.Decode(Configuration.Default, stream)) + { + ImageMetadata meta = image.Metadata; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new PngDecoder(); + IImageInfo image = decoder.Identify(Configuration.Default, stream); + ImageMetadata meta = image.Metadata; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs index 81a31e42d3..e26aaf8e65 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs @@ -1,9 +1,9 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.IO; using Xunit; -using SixLabors.ImageSharp.Formats; + using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png public void GeneralTest(TestImageProvider provider) where TPixel : struct, IPixel { - // does saving a file then repoening mean both files are identical??? + // does saving a file then reopening mean both files are identical??? using (Image image = provider.GetImage()) using (MemoryStream ms = new MemoryStream()) { @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png //public void CanSaveIndexedPng(TestImageProvider provider) // where TPixel : struct, IPixel //{ - // // does saving a file then repoening mean both files are identical??? + // // does saving a file then reopening mean both files are identical??? // using (Image image = provider.GetImage()) // using (MemoryStream ms = new MemoryStream()) // { @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png //public void CanSaveIndexedPngTwice(TestImageProvider provider) // where TPixel : struct, IPixel //{ - // // does saving a file then repoening mean both files are identical??? + // // does saving a file then reopening mean both files are identical??? // using (Image source = provider.GetImage()) // using (MemoryStream ms = new MemoryStream()) // { @@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png public void Resize(TestImageProvider provider) where TPixel : struct, IPixel { - // does saving a file then repoening mean both files are identical??? + // does saving a file then reopening mean both files are identical??? using (Image image = provider.GetImage()) using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Tests/Formats/Png/PngTextDataTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngTextDataTests.cs new file mode 100644 index 0000000000..72c0fd7ab0 --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Png/PngTextDataTests.cs @@ -0,0 +1,76 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Formats.Png; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Formats.Png +{ + /// + /// Tests the class. + /// + public class PngTextDataTests + { + /// + /// Tests the equality operators for inequality. + /// + [Fact] + public void AreEqual() + { + var property1 = new PngTextData("Foo", "Bar", "foo", "bar"); + var property2 = new PngTextData("Foo", "Bar", "foo", "bar"); + + Assert.Equal(property1, property2); + Assert.True(property1 == property2); + } + + /// + /// Tests the equality operators for equality. + /// + [Fact] + public void AreNotEqual() + { + var property1 = new PngTextData("Foo", "Bar", "foo", "bar"); + var property2 = new PngTextData("Foo", "Foo", string.Empty, string.Empty); + var property3 = new PngTextData("Bar", "Bar", "unit", "test"); + var property4 = new PngTextData("Foo", null, "test", "case"); + + Assert.NotEqual(property1, property2); + Assert.True(property1 != property2); + + Assert.NotEqual(property1, property3); + Assert.NotEqual(property1, property4); + } + + /// + /// Tests whether the constructor throws an exception when the property keyword is null or empty. + /// + [Fact] + public void ConstructorThrowsWhenKeywordIsNullOrEmpty() + { + Assert.Throws(() => new PngTextData(null, "Foo", "foo", "bar")); + + Assert.Throws(() => new PngTextData(string.Empty, "Foo", "foo", "bar")); + } + + /// + /// Tests whether the constructor correctly assigns properties. + /// + [Fact] + public void ConstructorAssignsProperties() + { + var property = new PngTextData("Foo", null, "unit", "test"); + Assert.Equal("Foo", property.Keyword); + Assert.Null(property.Value); + Assert.Equal("unit", property.LanguageTag); + Assert.Equal("test", property.TranslatedKeyword); + + property = new PngTextData("Foo", string.Empty, string.Empty, null); + Assert.Equal("Foo", property.Keyword); + Assert.Equal(string.Empty, property.Value); + Assert.Equal(string.Empty, property.LanguageTag); + Assert.Null(property.TranslatedKeyword); + } + } +} diff --git a/tests/ImageSharp.Tests/GlobalSuppressions.cs b/tests/ImageSharp.Tests/GlobalSuppressions.cs index 3d161049b9..2709d32ebc 100644 --- a/tests/ImageSharp.Tests/GlobalSuppressions.cs +++ b/tests/ImageSharp.Tests/GlobalSuppressions.cs @@ -1,7 +1,7 @@ - -// This file is used by Code Analysis to maintain SuppressMessage + +// This file is used by Code Analysis to maintain SuppressMessage // attributes that are applied to this project. -// Project-level suppressions either have no target or are given +// Project-level suppressions either have no target or are given // a specific target and scoped to a namespace, type, member, etc. [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] diff --git a/tests/ImageSharp.Tests/Helpers/GuardTests.cs b/tests/ImageSharp.Tests/Helpers/GuardTests.cs index b847e581f5..6bccea2c3e 100644 --- a/tests/ImageSharp.Tests/Helpers/GuardTests.cs +++ b/tests/ImageSharp.Tests/Helpers/GuardTests.cs @@ -3,7 +3,6 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Linq; using Xunit; // ReSharper disable InconsistentNaming diff --git a/tests/ImageSharp.Tests/Helpers/ParallelHelperTests.cs b/tests/ImageSharp.Tests/Helpers/ParallelHelperTests.cs index ee309e0e30..aeadfcebb5 100644 --- a/tests/ImageSharp.Tests/Helpers/ParallelHelperTests.cs +++ b/tests/ImageSharp.Tests/Helpers/ParallelHelperTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers public class ParallelHelperTests { private readonly ITestOutputHelper Output; - + public ParallelHelperTests(ITestOutputHelper output) { this.Output = output; @@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers /// maxDegreeOfParallelism, minY, maxY, expectedStepLength, expectedLastStepLength /// public static TheoryData IterateRows_OverMinimumPixelsLimit_Data = - new TheoryData() + new TheoryData { { 1, 0, 100, -1, 100 }, { 2, 0, 9, 5, 4 }, @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers var rectangle = new Rectangle(0, minY, 10, maxY - minY); int actualNumberOfSteps = 0; - + ParallelHelper.IterateRows( rectangle, parallelSettings, @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers int[] expectedData = Enumerable.Repeat(0, minY).Concat(Enumerable.Range(minY, maxY - minY)).ToArray(); - int[] actualData = new int[maxY]; + var actualData = new int[maxY]; ParallelHelper.IterateRows( rectangle, @@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers actualData[y] = y; } }); - + Assert.Equal(expectedData, actualData); } @@ -144,7 +144,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers int step = rows.Max - rows.Min; int expected = rows.Max < maxY ? expectedStepLength : expectedLastStepLength; - + Interlocked.Increment(ref actualNumberOfSteps); Assert.Equal(expected, step); }); @@ -172,7 +172,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers var rectangle = new Rectangle(0, minY, 10, maxY - minY); int[] expectedData = Enumerable.Repeat(0, minY).Concat(Enumerable.Range(minY, maxY - minY)).ToArray(); - int[] actualData = new int[maxY]; + var actualData = new int[maxY]; ParallelHelper.IterateRowsWithTempBuffer( rectangle, @@ -190,7 +190,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers } public static TheoryData IterateRows_WithEffectiveMinimumPixelsLimit_Data = - new TheoryData() + new TheoryData { { 2, 200, 50, 2, 1, -1, 2 }, { 2, 200, 200, 1, 1, -1, 1 }, @@ -256,7 +256,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers Configuration.Default.MemoryAllocator); var rectangle = new Rectangle(0, 0, width, height); - + int actualNumberOfSteps = 0; ParallelHelper.IterateRowsWithTempBuffer( rectangle, @@ -277,7 +277,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers } public static readonly TheoryData IterateRectangularBuffer_Data = - new TheoryData() + new TheoryData { { 8, 582, 453, 10, 10, 291, 226 }, // boundary data from DetectEdgesTest.DetectEdges_InBox { 2, 582, 453, 10, 10, 291, 226 }, @@ -303,7 +303,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers using (Buffer2D actual = memoryAllocator.Allocate2D(bufferWidth, bufferHeight, AllocationOptions.Clean)) { var rect = new Rectangle(rectX, rectY, rectWidth, rectHeight); - + void FillRow(int y, Buffer2D buffer) { for (int x = rect.Left; x < rect.Right; x++) @@ -348,7 +348,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers var rect = new Rectangle(0, 0, width, height); ArgumentOutOfRangeException ex = Assert.Throws( - () => ParallelHelper.IterateRows(rect, parallelSettings, (rows) => { })); + () => ParallelHelper.IterateRows(rect, parallelSettings, rows => { })); Assert.Contains(width <= 0 ? "Width" : "Height", ex.Message); } @@ -370,4 +370,4 @@ namespace SixLabors.ImageSharp.Tests.Helpers Assert.Contains(width <= 0 ? "Width" : "Height", ex.Message); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Helpers/RowIntervalTests.cs b/tests/ImageSharp.Tests/Helpers/RowIntervalTests.cs index 3aead6aaa9..45067f82fe 100644 --- a/tests/ImageSharp.Tests/Helpers/RowIntervalTests.cs +++ b/tests/ImageSharp.Tests/Helpers/RowIntervalTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers var rows = new RowInterval(min, max); Span span = buffer.GetMultiRowSpan(rows); - + ref int expected0 = ref buffer.Span[min * width]; int expectedLength = (max - min) * width; @@ -38,9 +38,9 @@ namespace SixLabors.ImageSharp.Tests.Helpers [Fact] public void Slice1() { - RowInterval rowInterval = new RowInterval(10, 20); + var rowInterval = new RowInterval(10, 20); RowInterval sliced = rowInterval.Slice(5); - + Assert.Equal(15, sliced.Min); Assert.Equal(20, sliced.Max); } @@ -48,9 +48,9 @@ namespace SixLabors.ImageSharp.Tests.Helpers [Fact] public void Slice2() { - RowInterval rowInterval = new RowInterval(10, 20); + var rowInterval = new RowInterval(10, 20); RowInterval sliced = rowInterval.Slice(3, 5); - + Assert.Equal(13, sliced.Min); Assert.Equal(18, sliced.Max); } @@ -58,9 +58,9 @@ namespace SixLabors.ImageSharp.Tests.Helpers [Fact] public void Equality_WhenTrue() { - RowInterval a = new RowInterval(42, 123); - RowInterval b = new RowInterval(42, 123); - + var a = new RowInterval(42, 123); + var b = new RowInterval(42, 123); + Assert.True(a.Equals(b)); Assert.True(a.Equals((object)b)); Assert.True(a == b); @@ -70,14 +70,14 @@ namespace SixLabors.ImageSharp.Tests.Helpers [Fact] public void Equality_WhenFalse() { - RowInterval a = new RowInterval(42, 123); - RowInterval b = new RowInterval(42, 125); - RowInterval c = new RowInterval(40, 123); - + var a = new RowInterval(42, 123); + var b = new RowInterval(42, 125); + var c = new RowInterval(40, 123); + Assert.False(a.Equals(b)); Assert.False(c.Equals(a)); Assert.False(b.Equals(c)); - + Assert.False(a.Equals((object)b)); Assert.False(a.Equals(null)); Assert.False(a == b); diff --git a/tests/ImageSharp.Tests/IO/DoubleBufferedStreamReaderTests.cs b/tests/ImageSharp.Tests/IO/DoubleBufferedStreamReaderTests.cs index 4fac8d9546..2d5e81173b 100644 --- a/tests/ImageSharp.Tests/IO/DoubleBufferedStreamReaderTests.cs +++ b/tests/ImageSharp.Tests/IO/DoubleBufferedStreamReaderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Tests.IO { using (MemoryStream stream = this.CreateTestStream()) { - byte[] buffer = new byte[2]; + var buffer = new byte[2]; byte[] expected = stream.ToArray(); var reader = new DoubleBufferedStreamReader(this.allocator, stream); @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Tests.IO { using (MemoryStream stream = this.CreateTestStream()) { - byte[] buffer = new byte[2]; + var buffer = new byte[2]; byte[] expected = stream.ToArray(); var reader = new DoubleBufferedStreamReader(this.allocator, stream); @@ -167,7 +167,7 @@ namespace SixLabors.ImageSharp.Tests.IO private MemoryStream CreateTestStream() { - byte[] buffer = new byte[DoubleBufferedStreamReader.ChunkLength * 3]; + var buffer = new byte[DoubleBufferedStreamReader.ChunkLength * 3]; var random = new Random(); random.NextBytes(buffer); diff --git a/tests/ImageSharp.Tests/Image/ImageCloneTests.cs b/tests/ImageSharp.Tests/Image/ImageCloneTests.cs index 82864f1562..035babcb8b 100644 --- a/tests/ImageSharp.Tests/Image/ImageCloneTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageCloneTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using Xunit; @@ -7,6 +7,24 @@ namespace SixLabors.ImageSharp.Tests { public class ImageCloneTests { + [Fact] + public void CloneAs_WhenDisposed_Throws() + { + var image = new Image(5, 5); + image.Dispose(); + + Assert.Throws(() => image.CloneAs()); + } + + [Fact] + public void Clone_WhenDisposed_Throws() + { + var image = new Image(5, 5); + image.Dispose(); + + Assert.Throws(() => image.Clone()); + } + [Theory] [WithTestPatternImages(9, 9, PixelTypes.Rgba32)] public void CloneAs_ToBgra32(TestImageProvider provider) @@ -109,4 +127,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs index 37c3a27cd0..80ab860efe 100644 --- a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs +++ b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Tests ArgumentException ex = Assert.Throws( () => { - var collection = new ImageFrameCollection( + new ImageFrameCollection( this.Image, new[] { @@ -274,25 +274,23 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void AddFrame_clones_sourceFrame() { - var pixelData = this.Image.Frames.RootFrame.GetPixelSpan().ToArray(); - var otherFRame = new ImageFrame(Configuration.Default, 10, 10); - var addedFrame = this.Image.Frames.AddFrame(otherFRame); - addedFrame.ComparePixelBufferTo(otherFRame.GetPixelSpan()); - Assert.NotEqual(otherFRame, addedFrame); + var otherFrame = new ImageFrame(Configuration.Default, 10, 10); + var addedFrame = this.Image.Frames.AddFrame(otherFrame); + addedFrame.ComparePixelBufferTo(otherFrame.GetPixelSpan()); + Assert.NotEqual(otherFrame, addedFrame); } [Fact] public void InsertFrame_clones_sourceFrame() { - var pixelData = this.Image.Frames.RootFrame.GetPixelSpan().ToArray(); - var otherFRame = new ImageFrame(Configuration.Default, 10, 10); - var addedFrame = this.Image.Frames.InsertFrame(0, otherFRame); - addedFrame.ComparePixelBufferTo(otherFRame.GetPixelSpan()); - Assert.NotEqual(otherFRame, addedFrame); + var otherFrame = new ImageFrame(Configuration.Default, 10, 10); + var addedFrame = this.Image.Frames.InsertFrame(0, otherFrame); + addedFrame.ComparePixelBufferTo(otherFrame.GetPixelSpan()); + Assert.NotEqual(otherFrame, addedFrame); } [Fact] - public void MoveFrame_LeavesFrmaeInCorrectLocation() + public void MoveFrame_LeavesFrameInCorrectLocation() { for (var i = 0; i < 9; i++) { diff --git a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs index 0956cce9c4..e972012e29 100644 --- a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs +++ b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs @@ -2,7 +2,6 @@ // // Licensed under the Apache License, Version 2.0. using System; -using System.Drawing.Imaging; using System.Linq; using SixLabors.ImageSharp.Advanced; @@ -25,11 +24,11 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void AddFrame_OfDifferentPixelType() { - using (Image sourceImage = new Image( + using (var sourceImage = new Image( this.Image.GetConfiguration(), this.Image.Width, this.Image.Height, - (Bgra32)Color.Blue)) + Color.Blue)) { this.Collection.AddFrame(sourceImage.Frames.RootFrame); } @@ -38,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests Enumerable.Repeat(Rgba32.Blue, this.Image.Width * this.Image.Height).ToArray(); Assert.Equal(2, this.Collection.Count); - ImageFrame actualFrame = (ImageFrame)this.Collection[1]; + var actualFrame = (ImageFrame)this.Collection[1]; actualFrame.ComparePixelBufferTo(expectedAllBlue); } @@ -46,11 +45,11 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void InsertFrame_OfDifferentPixelType() { - using (Image sourceImage = new Image( + using (var sourceImage = new Image( this.Image.GetConfiguration(), this.Image.Width, this.Image.Height, - (Bgra32)Color.Blue)) + Color.Blue)) { this.Collection.InsertFrame(0, sourceImage.Frames.RootFrame); } @@ -59,7 +58,7 @@ namespace SixLabors.ImageSharp.Tests Enumerable.Repeat(Rgba32.Blue, this.Image.Width * this.Image.Height).ToArray(); Assert.Equal(2, this.Collection.Count); - ImageFrame actualFrame = (ImageFrame)this.Collection[0]; + var actualFrame = (ImageFrame)this.Collection[0]; actualFrame.ComparePixelBufferTo(expectedAllBlue); @@ -89,7 +88,7 @@ namespace SixLabors.ImageSharp.Tests ArgumentNullException ex = Assert.Throws( () => { - this.Collection.AddFrame((ImageFrame)null); + this.Collection.AddFrame(null); }); Assert.StartsWith("Value cannot be null.", ex.Message); @@ -161,7 +160,7 @@ namespace SixLabors.ImageSharp.Tests { Assert.Equal(2, img.Frames.Count); - Image expectedClone = (Image)cloned; + var expectedClone = (Image)cloned; expectedClone.ComparePixelBufferTo(img.GetPixelSpan()); } @@ -184,7 +183,7 @@ namespace SixLabors.ImageSharp.Tests { Assert.Equal(1, img.Frames.Count); - Image expectedClone = (Image)cloned; + var expectedClone = (Image)cloned; expectedClone.ComparePixelBufferTo(sourcePixelData); } } @@ -197,7 +196,7 @@ namespace SixLabors.ImageSharp.Tests Assert.Equal(2, this.Image.Frames.Count); - ImageFrame frame = (ImageFrame)this.Image.Frames[1]; + var frame = (ImageFrame)this.Image.Frames[1]; frame.ComparePixelBufferTo(default(Rgba32)); } @@ -209,13 +208,13 @@ namespace SixLabors.ImageSharp.Tests Assert.Equal(2, this.Image.Frames.Count); - ImageFrame frame = (ImageFrame)this.Image.Frames[1]; + var frame = (ImageFrame)this.Image.Frames[1]; frame.ComparePixelBufferTo(Rgba32.HotPink); } [Fact] - public void MoveFrame_LeavesFrmaeInCorrectLocation() + public void MoveFrame_LeavesFrameInCorrectLocation() { for (var i = 0; i < 9; i++) { @@ -274,7 +273,7 @@ namespace SixLabors.ImageSharp.Tests where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (Image dest = new Image(source.GetConfiguration(), source.Width, source.Height)) + using (var dest = new Image(source.GetConfiguration(), source.Width, source.Height)) { // Giphy.gif has 5 frames diff --git a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.cs b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.cs index a29f45271b..d475513fa6 100644 --- a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using SixLabors.ImageSharp.PixelFormats; diff --git a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs index 3f4cb8afa2..25bc3f6049 100644 --- a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs @@ -1,9 +1,9 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.IO; -using System.Linq; + using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.PixelFormats; @@ -13,9 +13,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests { - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - /// /// Tests the class. /// @@ -39,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests this.encoderNotInFormat = new Mock(); this.fileSystem = new Mock(); - var config = new Configuration() + var config = new Configuration { FileSystem = this.fileSystem.Object }; @@ -51,23 +48,23 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void SavePath() { - Stream stream = new MemoryStream(); + var stream = new MemoryStream(); this.fileSystem.Setup(x => x.Create("path.png")).Returns(stream); this.Image.Save("path.png"); - this.encoder.Verify(x => x.Encode(this.Image, stream)); + this.encoder.Verify(x => x.Encode(this.Image, stream)); } [Fact] public void SavePathWithEncoder() { - Stream stream = new MemoryStream(); + var stream = new MemoryStream(); this.fileSystem.Setup(x => x.Create("path.jpg")).Returns(stream); this.Image.Save("path.jpg", this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream)); } [Fact] @@ -75,26 +72,26 @@ namespace SixLabors.ImageSharp.Tests { string str = this.Image.ToBase64String(this.localImageFormat.Object); - this.encoder.Verify(x => x.Encode(this.Image, It.IsAny())); + this.encoder.Verify(x => x.Encode(this.Image, It.IsAny())); } [Fact] public void SaveStreamWithMime() { - Stream stream = new MemoryStream(); + var stream = new MemoryStream(); this.Image.Save(stream, this.localImageFormat.Object); - this.encoder.Verify(x => x.Encode(this.Image, stream)); + this.encoder.Verify(x => x.Encode(this.Image, stream)); } [Fact] public void SaveStreamWithEncoder() { - Stream stream = new MemoryStream(); + var stream = new MemoryStream(); this.Image.Save(stream, this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream)); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Image/ImageTests.DetectFormat.cs b/tests/ImageSharp.Tests/Image/ImageTests.DetectFormat.cs index 9d709d488b..96747b0d29 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.DetectFormat.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.DetectFormat.cs @@ -1,11 +1,10 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.IO; using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.IO; -using Moq; + using Xunit; // ReSharper disable InconsistentNaming @@ -26,8 +25,6 @@ namespace SixLabors.ImageSharp.Tests private byte[] ByteArray => this.DataStream.ToArray(); - private ReadOnlySpan ByteSpan => this.ByteArray.AsSpan(); - private IImageFormat LocalImageFormat => this.localImageFormatMock.Object; private static readonly IImageFormat ExpectedGlobalFormat = diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_PassLocalConfiguration.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_PassLocalConfiguration.cs index 92159f0c9a..58e19c9f70 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_PassLocalConfiguration.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_PassLocalConfiguration.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Tests this.TestFormat.VerifySpecificDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Fact] public void Configuration_Path_Agnostic() { @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Fact] public void Configuration_Path_Decoder_Specific() { @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests Assert.NotNull(img); this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, this.DataStream)); } - + [Fact] public void Configuration_Path_Decoder_Agnostic() { @@ -61,10 +61,10 @@ namespace SixLabors.ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.TestFormat, format); - + this.TestFormat.VerifySpecificDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Fact] public void Configuration_Path_OutFormat_Agnostic() { @@ -72,14 +72,14 @@ namespace SixLabors.ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.TestFormat, format); - + this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); - } - + } + [Fact] public void WhenFileNotFound_Throws() { - System.IO.FileNotFoundException ex = Assert.Throws( + Assert.Throws( () => { Image.Load(this.TopLevelConfiguration, Guid.NewGuid().ToString()); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void WhenPathIsNull_Throws() { - ArgumentNullException ex = Assert.Throws( + Assert.Throws( () => { Image.Load(this.TopLevelConfiguration,(string)null); @@ -97,4 +97,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_UseDefaultConfiguration.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_UseDefaultConfiguration.cs index 19cf7ee647..4d3a229c55 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_UseDefaultConfiguration.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_UseDefaultConfiguration.cs @@ -82,7 +82,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void WhenFileNotFound_Throws() { - System.IO.FileNotFoundException ex = Assert.Throws( + Assert.Throws( () => { Image.Load(Guid.NewGuid().ToString()); @@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void WhenPathIsNull_Throws() { - ArgumentNullException ex = Assert.Throws( + Assert.Throws( () => { Image.Load((string)null); @@ -100,4 +100,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_PassLocalConfiguration.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_PassLocalConfiguration.cs index 5fe87fedca..2b1411fa63 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_PassLocalConfiguration.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_PassLocalConfiguration.cs @@ -18,11 +18,6 @@ namespace SixLabors.ImageSharp.Tests private ReadOnlySpan ByteSpan => this.ByteArray.AsSpan(); - private byte[] ActualImageBytes => TestFile.Create(TestImages.Bmp.F).Bytes; - - private ReadOnlySpan ActualImageSpan => this.ActualImageBytes.AsSpan(); - - [Theory] [InlineData(false)] [InlineData(true)] @@ -37,7 +32,7 @@ namespace SixLabors.ImageSharp.Tests this.TestFormat.VerifySpecificDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Theory] [InlineData(false)] [InlineData(true)] @@ -52,14 +47,14 @@ namespace SixLabors.ImageSharp.Tests this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Theory] [InlineData(false)] [InlineData(true)] public void Configuration_Bytes_Decoder_Specific(bool useSpan) { - TestFormat localFormat = new TestFormat(); - + var localFormat = new TestFormat(); + var img = useSpan ? Image.Load(this.TopLevelConfiguration, this.ByteSpan, localFormat.Decoder) : Image.Load(this.TopLevelConfiguration, this.ByteArray, localFormat.Decoder); @@ -67,14 +62,14 @@ namespace SixLabors.ImageSharp.Tests Assert.NotNull(img); localFormat.VerifySpecificDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Theory] [InlineData(false)] [InlineData(true)] public void Configuration_Bytes_Decoder_Agnostic(bool useSpan) { - TestFormat localFormat = new TestFormat(); - + var localFormat = new TestFormat(); + var img = useSpan ? Image.Load(this.TopLevelConfiguration, this.ByteSpan, localFormat.Decoder) : Image.Load(this.TopLevelConfiguration, this.ByteArray, localFormat.Decoder); @@ -95,10 +90,10 @@ namespace SixLabors.ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.TestFormat, format); - + this.TestFormat.VerifySpecificDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Theory] [InlineData(false)] [InlineData(true)] @@ -111,9 +106,9 @@ namespace SixLabors.ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.TestFormat, format); - + this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_UseGlobalConfiguration.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_UseGlobalConfiguration.cs index 67b19a0867..19887d9bcc 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_UseGlobalConfiguration.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_UseGlobalConfiguration.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.IO; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_PassLocalConfiguration.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_PassLocalConfiguration.cs index 5ca86c3cee..4e91cfebce 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_PassLocalConfiguration.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_PassLocalConfiguration.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Tests this.TestFormat.VerifySpecificDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Fact] public void Configuration_Stream_Agnostic() { @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Fact] public void NonSeekableStream() { @@ -46,21 +46,21 @@ namespace SixLabors.ImageSharp.Tests this.TestFormat.VerifySpecificDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Fact] public void Configuration_Stream_Decoder_Specific() { - Stream stream = new MemoryStream(); + var stream = new MemoryStream(); var img = Image.Load(this.TopLevelConfiguration, stream, this.localDecoder.Object); Assert.NotNull(img); this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, stream)); } - + [Fact] public void Configuration_Stream_Decoder_Agnostic() { - Stream stream = new MemoryStream(); + var stream = new MemoryStream(); var img = Image.Load(this.TopLevelConfiguration, stream, this.localDecoder.Object); Assert.NotNull(img); @@ -74,10 +74,10 @@ namespace SixLabors.ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.TestFormat, format); - + this.TestFormat.VerifySpecificDecodeCall(this.Marker, this.TopLevelConfiguration); } - + [Fact] public void Configuration_Stream_OutFormat_Agnostic() { @@ -85,9 +85,9 @@ namespace SixLabors.ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.TestFormat, format); - + this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); - } + } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_ThrowsRightException.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_ThrowsRightException.cs index df1f73c7a0..171b681cec 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_ThrowsRightException.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_ThrowsRightException.cs @@ -5,9 +5,7 @@ using System; using System.IO; using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; using Xunit; @@ -18,26 +16,26 @@ namespace SixLabors.ImageSharp.Tests public class Load_FromStream_Throws : IDisposable { private static readonly byte[] Data = new byte[] { 0x01 }; - + private MemoryStream Stream { get; } = new MemoryStream(Data); - + [Fact] - public void Image_Load_Throws_UknownImageFormatException() + public void Image_Load_Throws_UnknownImageFormatException() { Assert.Throws(() => { - using (var img = Image.Load(Configuration.Default, this.Stream, out IImageFormat format)) + using (Image.Load(Configuration.Default, this.Stream, out IImageFormat format)) { } }); } [Fact] - public void Image_Load_T_Throws_UknownImageFormatException() + public void Image_Load_T_Throws_UnknownImageFormatException() { Assert.Throws(() => { - using (var img = Image.Load(Configuration.Default, this.Stream, out IImageFormat format)) + using (Image.Load(Configuration.Default, this.Stream, out IImageFormat format)) { } }); diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Save.cs b/tests/ImageSharp.Tests/Image/ImageTests.Save.cs index 45399919a0..e00a70e392 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Save.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Save.cs @@ -1,9 +1,13 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. // ReSharper disable InconsistentNaming using System; +using System.IO; + +using Moq; + using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; using Xunit; @@ -17,17 +21,17 @@ namespace SixLabors.ImageSharp.Tests public class Save { [Fact] - public void DetecedEncoding() + public void DetectedEncoding() { string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageTests)); - string file = System.IO.Path.Combine(dir, "DetecedEncoding.png"); + string file = System.IO.Path.Combine(dir, "DetectedEncoding.png"); using (var image = new Image(10, 10)) { image.Save(file); } - using (var img = Image.Load(file, out IImageFormat mime)) + using (Image.Load(file, out IImageFormat mime)) { Assert.Equal("image/png", mime.DefaultMimeType); } @@ -39,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageTests)); string file = System.IO.Path.Combine(dir, "UnknownExtensionsEncoding_Throws.tmp"); - NotSupportedException ex = Assert.Throws( + Assert.Throws( () => { using (var image = new Image(10, 10)) @@ -60,11 +64,23 @@ namespace SixLabors.ImageSharp.Tests image.Save(file, new PngEncoder()); } - using (var img = Image.Load(file, out var mime)) + using (Image.Load(file, out var mime)) { Assert.Equal("image/png", mime.DefaultMimeType); } } + + [Fact] + public void ThrowsWhenDisposed() + { + var image = new Image(5, 5); + image.Dispose(); + IImageEncoder encoder = Mock.Of(); + using (var stream = new MemoryStream()) + { + Assert.Throws(() => image.Save(stream, encoder)); + } + } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/ImageOperationTests.cs b/tests/ImageSharp.Tests/ImageOperationTests.cs index 30371f0008..d2dc95cfe8 100644 --- a/tests/ImageSharp.Tests/ImageOperationTests.cs +++ b/tests/ImageSharp.Tests/ImageOperationTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -23,19 +23,22 @@ namespace SixLabors.ImageSharp.Tests private readonly FakeImageOperationsProvider provider; private readonly IImageProcessor processorDefinition; + private static readonly string ExpectedExceptionMessage = GetExpectedExceptionText(); + public ImageOperationTests() { this.provider = new FakeImageOperationsProvider(); - Mock processorMock = new Mock(); + var processorMock = new Mock(); this.processorDefinition = processorMock.Object; - - this.image = new Image(new Configuration() + + this.image = new Image(new Configuration { ImageOperationsProvider = this.provider }, 1, 1); } + [Fact] public void MutateCallsImageOperationsProvider_Func_OriginalImage() { @@ -81,9 +84,9 @@ namespace SixLabors.ImageSharp.Tests } [Fact] - public void CloneCallsImageOperationsProvider_Func_NotOnOrigional() + public void CloneCallsImageOperationsProvider_Func_NotOnOriginal() { - Image returned = this.image.Clone(x => x.ApplyProcessor(this.processorDefinition)); + this.image.Clone(x => x.ApplyProcessor(this.processorDefinition)); Assert.False(this.provider.HasCreated(this.image)); Assert.DoesNotContain( this.processorDefinition, @@ -91,9 +94,9 @@ namespace SixLabors.ImageSharp.Tests } [Fact] - public void CloneCallsImageOperationsProvider_ListOfProcessors_NotOnOrigional() + public void CloneCallsImageOperationsProvider_ListOfProcessors_NotOnOriginal() { - Image returned = this.image.Clone(this.processorDefinition); + this.image.Clone(this.processorDefinition); Assert.False(this.provider.HasCreated(this.image)); Assert.DoesNotContain( this.processorDefinition, @@ -109,5 +112,65 @@ namespace SixLabors.ImageSharp.Tests } public void Dispose() => this.image.Dispose(); + + [Fact] + public void GenericMutate_WhenDisposed_Throws() + { + this.image.Dispose(); + + CheckThrowsCorrectObjectDisposedException( + () => this.image.Mutate(x => x.ApplyProcessor(this.processorDefinition))); + } + + [Fact] + public void GenericClone_WhenDisposed_Throws() + { + this.image.Dispose(); + + CheckThrowsCorrectObjectDisposedException( + () => this.image.Clone(x => x.ApplyProcessor(this.processorDefinition))); + } + + [Fact] + public void AgnosticMutate_WhenDisposed_Throws() + { + this.image.Dispose(); + Image img = this.image; + + CheckThrowsCorrectObjectDisposedException( + () => img.Mutate(x => x.ApplyProcessor(this.processorDefinition))); + } + + [Fact] + public void AgnosticClone_WhenDisposed_Throws() + { + this.image.Dispose(); + Image img = this.image; + + CheckThrowsCorrectObjectDisposedException( + () => img.Clone(x => x.ApplyProcessor(this.processorDefinition))); + } + + private static string GetExpectedExceptionText() + { + try + { + var img = new Image(1, 1); + img.Dispose(); + img.EnsureNotDisposed(); + } + catch (ObjectDisposedException ex) + { + return ex.Message; + } + + return "?"; + } + + private static void CheckThrowsCorrectObjectDisposedException(Action action) + { + var ex = Assert.Throws(action); + Assert.Equal(ExpectedExceptionMessage, ex.Message); + } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 4f92f4007d..1ac5f8085a 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -8,11 +8,9 @@ full portable True - SixLabors.ImageSharp.Tests SixLabors.ImageSharp.Tests AnyCPU;x64;x86 SixLabors.ImageSharp.Tests - netcoreapp2.1;net462;net472 diff --git a/tests/ImageSharp.Tests/Issues/Issue412.cs b/tests/ImageSharp.Tests/Issues/Issue412.cs index 7b2cfd81c6..5a590018e5 100644 --- a/tests/ImageSharp.Tests/Issues/Issue412.cs +++ b/tests/ImageSharp.Tests/Issues/Issue412.cs @@ -23,21 +23,15 @@ namespace SixLabors.ImageSharp.Tests.Issues new GraphicsOptions(false), Color.Black, 1, - new[] - { new PointF(i, 0.1066f), - new PointF(i, 10.1066f) - }); + new PointF(i, 10.1066f)); context.DrawLines( new GraphicsOptions(false), Color.Red, 1, - new[] - { new PointF(i, 15.1066f), - new PointF(i, 25.1066f) - }); + new PointF(i, 25.1066f)); } }); diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index 4af3b81e20..ee32be3ca7 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Memory ref T actual = ref MemoryMarshal.GetReference(span); ref T expected = ref Unsafe.Add(ref buffer.GetReference(), bufferOffset); - Assert.True(Unsafe.AreSame(ref expected, ref actual), "span does not point to the expected position"); + True(Unsafe.AreSame(ref expected, ref actual), "span does not point to the expected position"); } } @@ -137,11 +137,11 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(5, 1, 1, 3, 2)] public void CopyColumns(int width, int height, int startIndex, int destIndex, int columnCount) { - Random rnd = new Random(123); + var rnd = new Random(123); using (Buffer2D b = this.MemoryAllocator.Allocate2D(width, height)) { rnd.RandomFill(b.Span, 0, 1); - + b.CopyColumns(startIndex, destIndex, columnCount); for (int y = 0; y < b.Height; y++) @@ -150,7 +150,7 @@ namespace SixLabors.ImageSharp.Tests.Memory Span s = row.Slice(startIndex, columnCount); Span d = row.Slice(destIndex, columnCount); - + Xunit.Assert.True(s.SequenceEqual(d)); } } @@ -159,11 +159,11 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void CopyColumns_InvokeMultipleTimes() { - Random rnd = new Random(123); + var rnd = new Random(123); using (Buffer2D b = this.MemoryAllocator.Allocate2D(100, 100)) { rnd.RandomFill(b.Span, 0, 1); - + b.CopyColumns(0, 50, 22); b.CopyColumns(0, 50, 22); @@ -173,10 +173,10 @@ namespace SixLabors.ImageSharp.Tests.Memory Span s = row.Slice(0, 22); Span d = row.Slice(50, 22); - + Xunit.Assert.True(s.SequenceEqual(d)); } } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs index dc735e41b4..9192798628 100644 --- a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs +++ b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (Buffer2D buffer = CreateTestBuffer(20, 30)) { - Rectangle r = new Rectangle(rx, ry, 5, 6); + var r = new Rectangle(rx, ry, 5, 6); BufferArea area = buffer.GetArea(r); @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (Buffer2D buffer = CreateTestBuffer(20, 30)) { - Rectangle r = new Rectangle(rx, ry, w, h); + var r = new Rectangle(rx, ry, w, h); BufferArea area = buffer.GetArea(r); @@ -145,4 +145,4 @@ namespace SixLabors.ImageSharp.Tests.Memory } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Memory/MemorySourceTests.cs b/tests/ImageSharp.Tests/Memory/MemorySourceTests.cs index 21217d73f2..535204e8dc 100644 --- a/tests/ImageSharp.Tests/Memory/MemorySourceTests.cs +++ b/tests/ImageSharp.Tests/Memory/MemorySourceTests.cs @@ -49,11 +49,11 @@ namespace SixLabors.ImageSharp.Tests.Memory [Theory] [InlineData(false)] [InlineData(true)] - public void WhenOwnershipIsTransfered_ShouldDisposeMemoryOwner(bool isInternalMemorySource) + public void WhenOwnershipIsTransferred_ShouldDisposeMemoryOwner(bool isInternalMemorySource) { var mmg = new TestMemoryManager(new int[10]); var bmg = new MemorySource(mmg, isInternalMemorySource); - + bmg.Dispose(); Assert.True(mmg.IsDisposed); } @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Memory Assert.False(mmg.IsDisposed); } } - + public class SwapOrCopyContent { private MemoryAllocator MemoryAllocator { get; } = new TestMemoryAllocator(); @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests.Memory MemorySource source = sourceIsOwner ? new MemorySource(sourceOwner, isInternalMemorySource) : new MemorySource(sourceOwner.Memory); - + sourceOwner.Memory.Span[10] = color; // Act: @@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests.Memory Assert.ThrowsAny( () => MemorySource.SwapOrCopyContent(ref dest, ref source) ); - + Assert.Equal(color, source.Memory.Span[10]); Assert.NotEqual(color, dest.Memory.Span[10]); } diff --git a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs index 5f02ce7aeb..6730605e98 100644 --- a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs +++ b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs @@ -1,6 +1,8 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.Collections.Generic; + using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata.Profiles.Exif; @@ -9,7 +11,7 @@ using SixLabors.ImageSharp.Primitives; using Xunit; -namespace SixLabors.ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests.MetaData { /// /// Tests the class. @@ -22,33 +24,27 @@ namespace SixLabors.ImageSharp.Tests var metaData = new ImageMetadata(); var exifProfile = new ExifProfile(); - var imageProperty = new ImageProperty("name", "value"); metaData.ExifProfile = exifProfile; metaData.HorizontalResolution = 4; metaData.VerticalResolution = 2; - metaData.Properties.Add(imageProperty); ImageMetadata clone = metaData.DeepClone(); Assert.Equal(exifProfile.ToByteArray(), clone.ExifProfile.ToByteArray()); Assert.Equal(4, clone.HorizontalResolution); Assert.Equal(2, clone.VerticalResolution); - Assert.Equal(imageProperty, clone.Properties[0]); } [Fact] public void CloneIsDeep() { - var metaData = new ImageMetadata(); - - var exifProfile = new ExifProfile(); - var imageProperty = new ImageProperty("name", "value"); - - metaData.ExifProfile = exifProfile; - metaData.HorizontalResolution = 4; - metaData.VerticalResolution = 2; - metaData.Properties.Add(imageProperty); + var metaData = new ImageMetadata + { + ExifProfile = new ExifProfile(), + HorizontalResolution = 4, + VerticalResolution = 2 + }; ImageMetadata clone = metaData.DeepClone(); clone.HorizontalResolution = 2; @@ -57,8 +53,6 @@ namespace SixLabors.ImageSharp.Tests Assert.False(metaData.ExifProfile.Equals(clone.ExifProfile)); Assert.False(metaData.HorizontalResolution.Equals(clone.HorizontalResolution)); Assert.False(metaData.VerticalResolution.Equals(clone.VerticalResolution)); - Assert.False(metaData.Properties.Equals(clone.Properties)); - Assert.False(metaData.GetFormatMetadata(GifFormat.Instance).Equals(clone.GetFormatMetadata(GifFormat.Instance))); } [Fact] @@ -100,15 +94,17 @@ namespace SixLabors.ImageSharp.Tests exifProfile.SetValue(ExifTag.XResolution, new Rational(200)); exifProfile.SetValue(ExifTag.YResolution, new Rational(300)); - var image = new Image(1, 1); - image.Metadata.ExifProfile = exifProfile; - image.Metadata.HorizontalResolution = 400; - image.Metadata.VerticalResolution = 500; + using (var image = new Image(1, 1)) + { + image.Metadata.ExifProfile = exifProfile; + image.Metadata.HorizontalResolution = 400; + image.Metadata.VerticalResolution = 500; - image.Metadata.SyncProfiles(); + image.Metadata.SyncProfiles(); - Assert.Equal(400, ((Rational)image.Metadata.ExifProfile.GetValue(ExifTag.XResolution).Value).ToDouble()); - Assert.Equal(500, ((Rational)image.Metadata.ExifProfile.GetValue(ExifTag.YResolution).Value).ToDouble()); + Assert.Equal(400, ((Rational)image.Metadata.ExifProfile.GetValue(ExifTag.XResolution).Value).ToDouble()); + Assert.Equal(500, ((Rational)image.Metadata.ExifProfile.GetValue(ExifTag.YResolution).Value).ToDouble()); + } } } } diff --git a/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs b/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs deleted file mode 100644 index 8cce5ba414..0000000000 --- a/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using SixLabors.ImageSharp.Metadata; -using Xunit; - -namespace SixLabors.ImageSharp.Tests -{ - /// - /// Tests the class. - /// - public class ImagePropertyTests - { - /// - /// Tests the equality operators for inequality. - /// - [Fact] - public void AreEqual() - { - var property1 = new ImageProperty("Foo", "Bar"); - var property2 = new ImageProperty("Foo", "Bar"); - - Assert.Equal(property1, property2); - Assert.True(property1 == property2); - } - - /// - /// Tests the equality operators for equality. - /// - [Fact] - public void AreNotEqual() - { - var property1 = new ImageProperty("Foo", "Bar"); - var property2 = new ImageProperty("Foo", "Foo"); - var property3 = new ImageProperty("Bar", "Bar"); - var property4 = new ImageProperty("Foo", null); - - Assert.False(property1.Equals("Foo")); - - Assert.NotEqual(property1, property2); - Assert.True(property1 != property2); - - Assert.NotEqual(property1, property3); - Assert.NotEqual(property1, property4); - } - - /// - /// Tests whether the constructor throws an exception when the property name is null or empty. - /// - [Fact] - public void ConstructorThrowsWhenNameIsNullOrEmpty() - { - Assert.Throws(() => new ImageProperty(null, "Foo")); - - Assert.Throws(() => new ImageProperty(string.Empty, "Foo")); - } - - /// - /// Tests whether the constructor correctly assigns properties. - /// - [Fact] - public void ConstructorAssignsProperties() - { - var property = new ImageProperty("Foo", null); - Assert.Equal("Foo", property.Name); - Assert.Null(property.Value); - - property = new ImageProperty("Foo", string.Empty); - Assert.Equal(string.Empty, property.Value); - } - } -} diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs index 668e699c5f..3ae452d7d7 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests Png } - private static readonly Dictionary TestProfileValues = new Dictionary() + private static readonly Dictionary TestProfileValues = new Dictionary { { ExifTag.Software, "Software" }, { ExifTag.Copyright, "Copyright" }, @@ -373,7 +373,6 @@ namespace SixLabors.ImageSharp.Tests public void ProfileToByteArray() { // arrange - byte[] exifBytesWithExifCode = ProfileResolver.ExifMarker.Concat(ExifConstants.LittleEndianByteOrderMarker).ToArray(); byte[] exifBytesWithoutExifCode = ExifConstants.LittleEndianByteOrderMarker; ExifProfile expectedProfile = CreateExifProfile(); var expectedProfileTags = expectedProfile.Values.Select(x => x.Tag).ToList(); diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.PrimitivesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.PrimitivesTests.cs index e73ee7c9e9..0275303291 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.PrimitivesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.PrimitivesTests.cs @@ -8,7 +8,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Icc { public class IccDataReaderPrimitivesTests - { + { [Theory] [MemberData(nameof(IccTestDataPrimitives.AsciiTestData), MemberType = typeof(IccTestDataPrimitives))] public void ReadAsciiString(byte[] textBytes, int length, string expected) @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Tests.Icc } [Fact] - public void ReadAsciiStringWithNegativeLenghtThrowsArgumentException() + public void ReadAsciiStringWithNegativeLengthThrowsArgumentException() { IccDataReader reader = CreateReader(new byte[4]); @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests.Icc } [Fact] - public void ReadUnicodeStringWithNegativeLenghtThrowsArgumentException() + public void ReadUnicodeStringWithNegativeLengthThrowsArgumentException() { IccDataReader reader = CreateReader(new byte[4]); diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs index 0882222226..15bf762e25 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System.Numerics; -using SixLabors.Memory; + using SixLabors.ImageSharp.Metadata.Profiles.Icc; using Xunit; diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs index 098950be85..464a701411 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Icc } [Fact] - public void WriteAsciiStringWithNegativeLenghtThrowsArgumentException() + public void WriteAsciiStringWithNegativeLengthThrowsArgumentException() { IccDataWriter writer = CreateWriter(); diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccProfileTests.cs index a1944669d0..633c7c8230 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccProfileTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -22,10 +22,10 @@ namespace SixLabors.ImageSharp.Tests.Icc public void CalculateHash_WithByteArray_DoesNotModifyData() { byte[] data = IccTestDataProfiles.Profile_Random_Array; - byte[] copy = new byte[data.Length]; + var copy = new byte[data.Length]; Buffer.BlockCopy(data, 0, copy, 0, data.Length); - IccProfileId result = IccProfile.CalculateHash(data); + IccProfile.CalculateHash(data); Assert.Equal(data, copy); } diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccWriterTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccWriterTests.cs index 43c27335a9..e66554b85b 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccWriterTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccWriterTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Metadata.Profiles.Icc; @@ -13,12 +13,12 @@ namespace SixLabors.ImageSharp.Tests.Icc { IccWriter writer = CreateWriter(); - IccProfile profile = new IccProfile() + var profile = new IccProfile { Header = IccTestDataProfiles.Header_Random_Write }; byte[] output = writer.Write(profile); - + Assert.Equal(IccTestDataProfiles.Header_Random_Array, output); } @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Tests.Icc IccWriter writer = CreateWriter(); byte[] output = writer.Write(IccTestDataProfiles.Profile_Random_Val); - + Assert.Equal(IccTestDataProfiles.Profile_Random_Array, output); } diff --git a/tests/ImageSharp.Tests/Numerics/RationalTests.cs b/tests/ImageSharp.Tests/Numerics/RationalTests.cs index caddd49216..7cdae7f602 100644 --- a/tests/ImageSharp.Tests/Numerics/RationalTests.cs +++ b/tests/ImageSharp.Tests/Numerics/RationalTests.cs @@ -91,7 +91,7 @@ namespace SixLabors.ImageSharp.Tests } [Fact] - public void ToStringRepresention() + public void ToStringRepresentation() { var rational = new Rational(0, 0); Assert.Equal("[ Indeterminate ]", rational.ToString()); diff --git a/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs b/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs index 77920ba2fe..f828cf74f5 100644 --- a/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs +++ b/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Primitives; @@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Tests } [Fact] - public void ToStringRepresention() + public void ToStringRepresentation() { var rational = new SignedRational(0, 0); Assert.Equal("[ Indeterminate ]", rational.ToString()); @@ -119,4 +119,4 @@ namespace SixLabors.ImageSharp.Tests Assert.Equal("1/2", rational.ToString()); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs index 0266704850..7638c5f862 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats } public static readonly TheoryData ColorData = - new TheoryData() { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 255, 42 } }; + new TheoryData { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 255, 42 } }; [Theory] [MemberData(nameof(ColorData))] @@ -129,4 +129,4 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.Equal(255, bgr.B); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs index 4c5de7ee91..28c022709f 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using Xunit; @@ -35,7 +34,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats } public static readonly TheoryData ColorData = - new TheoryData() + new TheoryData { { 1, 2, 3, 4 }, { 4, 5, 6, 7 }, { 0, 255, 42, 0 }, { 1, 2, 3, 255 } }; @@ -142,4 +141,4 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.Equal(expected, bgra.PackedValue); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/PixelFormats/Gray8Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Gray8Tests.cs index 74fd903ca9..d7b50ee1e2 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Gray8Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Gray8Tests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { public class Gray8Tests { - public static readonly TheoryData LuminanceData = new TheoryData() + public static readonly TheoryData LuminanceData = new TheoryData { 0, 1, @@ -279,4 +279,4 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs index 9a196d9d5b..e397f70b08 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders { public class PorterDuffFunctionsTests { - public static TheoryData NormalBlendFunctionData = new TheoryData() { + public static TheoryData NormalBlendFunctionData = new TheoryData { { new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) }, { new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(0.6f, 0.6f, 0.6f, 1) }, }; @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders Assert.Equal(expected, actual); } - public static TheoryData MultiplyFunctionData = new TheoryData() { + public static TheoryData MultiplyFunctionData = new TheoryData { { new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) }, { new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(0.6f, 0.6f, 0.6f, 1) }, { @@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, actual, 5); } - public static TheoryData AddFunctionData = new TheoryData() { + public static TheoryData AddFunctionData = new TheoryData { { new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) }, { new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(.6f, .6f, .6f, 1f) }, { @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, actual, 5); } - public static TheoryData SubstractFunctionData = new TheoryData() { + public static TheoryData SubtractFunctionData = new TheoryData { { new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(0,0,0,1) }, { new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(1,1,1, 1f) }, { @@ -73,14 +73,14 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders }; [Theory] - [MemberData(nameof(SubstractFunctionData))] - public void SubstractFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected) + [MemberData(nameof(SubtractFunctionData))] + public void SubtractFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected) { Vector4 actual = PorterDuffFunctions.SubtractSrcOver((Vector4)back, source, amount); VectorAssert.Equal(expected, actual, 5); } - public static TheoryData ScreenFunctionData = new TheoryData() { + public static TheoryData ScreenFunctionData = new TheoryData { { new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) }, { new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(1,1,1, 1f) }, { @@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, actual, 5); } - public static TheoryData DarkenFunctionData = new TheoryData() { + public static TheoryData DarkenFunctionData = new TheoryData { { new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) }, { new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(.6f,.6f,.6f, 1f) }, { @@ -118,7 +118,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, actual, 5); } - public static TheoryData LightenFunctionData = new TheoryData() { + public static TheoryData LightenFunctionData = new TheoryData { { new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) }, { new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(1,1,1,1f) }, { @@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, actual, 5); } - public static TheoryData OverlayFunctionData = new TheoryData() { + public static TheoryData OverlayFunctionData = new TheoryData { { new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) }, { new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(1,1,1,1f) }, { @@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, actual, 5); } - public static TheoryData HardLightFunctionData = new TheoryData() { + public static TheoryData HardLightFunctionData = new TheoryData { { new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) }, { new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(0.6f,0.6f,0.6f,1f) }, { diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs index 7de1cbb190..859be6b205 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -9,8 +9,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders { - using SixLabors.Memory; - public class PorterDuffFunctionsTestsTPixel { private static Span AsSpan(T value) @@ -19,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders return new Span(new[] { value }); } - public static TheoryData NormalBlendFunctionData = new TheoryData() { + public static TheoryData NormalBlendFunctionData = new TheoryData { { new TestPixel(1,1,1,1), new TestPixel(1,1,1,1), 1, new TestPixel(1,1,1,1) }, { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(0.6f, 0.6f, 0.6f, 1) }, }; @@ -31,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders public void NormalBlendFunction(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - TPixel actual = PorterDuffFunctions.NormalSrcOver((TPixel)(TPixel)back, source, amount); + TPixel actual = PorterDuffFunctions.NormalSrcOver((TPixel)back, source, amount); VectorAssert.Equal(expected, actual, 2); } @@ -54,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, dest[0], 2); } - public static TheoryData MultiplyFunctionData = new TheoryData() { + public static TheoryData MultiplyFunctionData = new TheoryData { { new TestPixel(1,1,1,1), new TestPixel(1,1,1,1), 1, new TestPixel(1,1,1,1) }, { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(0.6f, 0.6f, 0.6f, 1) }, { @@ -93,7 +91,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, dest[0], 2); } - public static TheoryData AddFunctionData = new TheoryData() { + public static TheoryData AddFunctionData = new TheoryData { { new TestPixel(1,1,1,1), new TestPixel(1,1,1,1), 1, new TestPixel(1,1,1,1) }, { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(1f, 1f, 1f, 1f) }, { @@ -132,7 +130,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, dest[0], 2); } - public static TheoryData SubstractFunctionData = new TheoryData() { + public static TheoryData SubtractFunctionData = new TheoryData { { new TestPixel(1,1,1,1), new TestPixel(1,1,1,1), 1, new TestPixel(0,0,0,1) }, { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(1,1,1, 1f) }, { @@ -144,8 +142,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders }; [Theory] - [MemberData(nameof(SubstractFunctionData))] - public void SubstractFunction(TestPixel back, TestPixel source, float amount, TestPixel expected) + [MemberData(nameof(SubtractFunctionData))] + public void SubtractFunction(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { TPixel actual = PorterDuffFunctions.SubtractSrcOver((TPixel)back, source, amount); @@ -153,8 +151,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders } [Theory] - [MemberData(nameof(SubstractFunctionData))] - public void SubstractFunctionBlender(TestPixel back, TestPixel source, float amount, TestPixel expected) + [MemberData(nameof(SubtractFunctionData))] + public void SubtractFunctionBlender(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { TPixel actual = new DefaultPixelBlenders.SubtractSrcOver().Blend(back, source, amount); @@ -162,8 +160,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders } [Theory] - [MemberData(nameof(SubstractFunctionData))] - public void SubstractFunctionBlenderBulk(TestPixel back, TestPixel source, float amount, TestPixel expected) + [MemberData(nameof(SubtractFunctionData))] + public void SubtractFunctionBlenderBulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { var dest = new Span(new TPixel[1]); @@ -171,7 +169,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, dest[0], 2); } - public static TheoryData ScreenFunctionData = new TheoryData() { + public static TheoryData ScreenFunctionData = new TheoryData { { new TestPixel(1,1,1,1), new TestPixel(1,1,1,1), 1, new TestPixel(1,1,1,1) }, { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(1,1,1, 1f) }, { @@ -210,7 +208,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, dest[0], 2); } - public static TheoryData DarkenFunctionData = new TheoryData() { + public static TheoryData DarkenFunctionData = new TheoryData { { new TestPixel(1,1,1,1), new TestPixel(1,1,1,1), 1, new TestPixel(1,1,1,1) }, { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(.6f,.6f,.6f, 1f) }, { @@ -249,7 +247,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, dest[0], 2); } - public static TheoryData LightenFunctionData = new TheoryData() { + public static TheoryData LightenFunctionData = new TheoryData { { new TestPixel(1,1,1,1), new TestPixel(1,1,1,1), 1, new TestPixel(1,1,1,1) }, { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(1,1,1,1f) }, { @@ -288,7 +286,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, dest[0], 2); } - public static TheoryData OverlayFunctionData = new TheoryData() { + public static TheoryData OverlayFunctionData = new TheoryData { { new TestPixel(1,1,1,1), new TestPixel(1,1,1,1), 1, new TestPixel(1,1,1,1) }, { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(1,1,1,1f) }, { @@ -327,7 +325,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders VectorAssert.Equal(expected, dest[0], 2); } - public static TheoryData HardLightFunctionData = new TheoryData() { + public static TheoryData HardLightFunctionData = new TheoryData { { new TestPixel(1,1,1,1), new TestPixel(1,1,1,1), 1, new TestPixel(1,1,1,1) }, { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(0.6f,0.6f,0.6f,1f) }, { diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Gray16OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Gray16OperationsTests.cs index f44401ae90..ffb1a0b027 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Gray16OperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Gray16OperationsTests.cs @@ -1,12 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using Xunit; diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Gray8OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Gray8OperationsTests.cs index 30c4290006..24b20eecab 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Gray8OperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Gray8OperationsTests.cs @@ -1,11 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using Xunit; diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index 71adc17494..682da89fcc 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -10,7 +10,6 @@ using System.Runtime.InteropServices; using SixLabors.ImageSharp.ColorSpaces.Companding; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using Xunit; using Xunit.Abstractions; @@ -298,7 +297,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { const int Count = 2134; TPixel[] source = CreatePixelTestData(Count); - TDestPixel[] expected = new TDestPixel[Count]; + var expected = new TDestPixel[Count]; PixelConverterTests.ReferenceImplementations.To(this.Configuration, source, expected); @@ -458,7 +457,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public void ToArgb32Bytes(int count) { TPixel[] source = CreatePixelTestData(count); - byte[] expected = new byte[count * 4]; + var expected = new byte[count * 4]; var argb = default(Argb32); for (int i = 0; i < count; i++) @@ -505,7 +504,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public void ToBgr24Bytes(int count) { TPixel[] source = CreatePixelTestData(count); - byte[] expected = new byte[count * 3]; + var expected = new byte[count * 3]; var bgr = default(Bgr24); for (int i = 0; i < count; i++) @@ -550,7 +549,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public void ToBgra32Bytes(int count) { TPixel[] source = CreatePixelTestData(count); - byte[] expected = new byte[count * 4]; + var expected = new byte[count * 4]; var bgra = default(Bgra32); for (int i = 0; i < count; i++) @@ -596,7 +595,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public void ToRgb24Bytes(int count) { TPixel[] source = CreatePixelTestData(count); - byte[] expected = new byte[count * 3]; + var expected = new byte[count * 3]; var rgb = default(Rgb24); for (int i = 0; i < count; i++) @@ -641,7 +640,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public void ToRgba32Bytes(int count) { TPixel[] source = CreatePixelTestData(count); - byte[] expected = new byte[count * 4]; + var expected = new byte[count * 4]; var rgba = default(Rgba32); for (int i = 0; i < count; i++) @@ -687,7 +686,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public void ToRgb48Bytes(int count) { TPixel[] source = CreatePixelTestData(count); - byte[] expected = new byte[count * 6]; + var expected = new byte[count * 6]; Rgb48 rgb = default; for (int i = 0; i < count; i++) @@ -736,7 +735,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public void ToRgba64Bytes(int count) { TPixel[] source = CreatePixelTestData(count); - byte[] expected = new byte[count * 8]; + var expected = new byte[count * 8]; Rgba64 rgba = default; for (int i = 0; i < count; i++) @@ -788,7 +787,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public void ToGray8(int count) { TPixel[] source = CreatePixelTestData(count); - Gray8[] expected = new Gray8[count]; + var expected = new Gray8[count]; for (int i = 0; i < count; i++) { @@ -817,7 +816,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations for (int i = 0; i < count; i++) { - int i2 = i * 2; expected[i].FromGray16(source[i]); } @@ -833,7 +831,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public void ToGray16(int count) { TPixel[] source = CreatePixelTestData(count); - Gray16[] expected = new Gray16[count]; + var expected = new Gray16[count]; for (int i = 0; i < count; i++) { @@ -948,7 +946,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations internal static byte[] CreateByteTestData(int length) { - byte[] result = new byte[length]; + var result = new byte[length]; var rnd = new Random(42); // Deterministic random values for (int i = 0; i < result.Length; i++) diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs index a044ebae9b..74360e8574 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs @@ -1,9 +1,8 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Generic; -using System.Text; + using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats.PixelBlenders; using SixLabors.ImageSharp.Tests.TestUtilities; @@ -13,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { public class PixelBlenderTests { - public static TheoryData BlenderMappings = new TheoryData() + public static TheoryData BlenderMappings = new TheoryData { { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOver), PixelColorBlendingMode.Normal }, { new TestPixel(), typeof(DefaultPixelBlenders.ScreenSrcOver), PixelColorBlendingMode.Screen }, @@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.IsType(type, blender); } - public static TheoryData ColorBlendingExpectedResults = new TheoryData() + public static TheoryData ColorBlendingExpectedResults = new TheoryData { { Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Normal, Rgba32.MidnightBlue }, { Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Screen, new Rgba32(0xFFEEE7FF) }, @@ -72,7 +71,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.Equal(actualResult.ToVector4(), expectedResult.ToVector4()); } - public static TheoryData AlphaCompositionExpectedResults = new TheoryData() + public static TheoryData AlphaCompositionExpectedResults = new TheoryData { { Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.Clear, new Rgba32(0) }, { Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.Xor, new Rgba32(0) }, diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs index df459422c9..06e3d59482 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs @@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public class Rgb24Tests { public static readonly TheoryData ColorData = - new TheoryData() + new TheoryData { { 1, 2, 3 }, { 4, 5, 6 }, @@ -130,4 +130,4 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.Equal(255, rgb.B); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs index 275afa35d6..1ab5f8e3df 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs @@ -1,11 +1,10 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using Xunit; -using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests.PixelFormats { @@ -108,7 +107,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats } /// - /// Tests that the individual byte elements are layed out in RGBA order. + /// Tests that the individual byte elements are laid out in RGBA order. /// [Fact] public unsafe void ByteLayout() @@ -291,4 +290,4 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.Equal(expected, rgb.PackedValue); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs index 55a2dda7a9..9cdf4125c7 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -65,16 +65,16 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void Rgba64_FromScaledVector4(ushort r, ushort g, ushort b, ushort a) { // arrange - + var source = new Rgba64(r, g, b, a); - - // act + + // act Vector4 scaled = source.ToScaledVector4(); Rgba64 actual = default; actual.FromScaledVector4(scaled); - + // assert Assert.Equal(source, actual); } @@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats // assert Assert.Equal(expected, actual); } - + [Fact] public void Rgba64_FromBgra5551() @@ -126,20 +126,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats [Fact] public void Equality_WhenTrue() { - Rgba64 c1 = new Rgba64(100, 2000, 3000, 40000); - Rgba64 c2 = new Rgba64(100, 2000, 3000, 40000); - + var c1 = new Rgba64(100, 2000, 3000, 40000); + var c2 = new Rgba64(100, 2000, 3000, 40000); + Assert.True(c1.Equals(c2)); Assert.True(c1.GetHashCode() == c2.GetHashCode()); } - + [Fact] public void Equality_WhenFalse() { - Rgba64 c1 = new Rgba64(100, 2000, 3000, 40000); - Rgba64 c2 = new Rgba64(101, 2000, 3000, 40000); - Rgba64 c3 = new Rgba64(100, 2000, 3000, 40001); - + var c1 = new Rgba64(100, 2000, 3000, 40000); + var c2 = new Rgba64(101, 2000, 3000, 40000); + var c3 = new Rgba64(100, 2000, 3000, 40001); + Assert.False(c1.Equals(c2)); Assert.False(c2.Equals(c3)); Assert.False(c3.Equals(c1)); @@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Rgba64 actual = default; actual.FromRgba32(source); - + Assert.Equal(expected, actual); } @@ -162,127 +162,127 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { var expected = new Rgba64(5140, 9766, 19532, 29555); var source = new Rgba32(20, 38, 76, 115); - Rgba64 actual = new Rgba64(source); - + var actual = new Rgba64(source); + Assert.Equal(expected, actual); } - + [Fact] public void ConstructFrom_Bgra32() { var expected = new Rgba64(5140, 9766, 19532, 29555); var source = new Bgra32(20, 38, 76, 115); - Rgba64 actual = new Rgba64(source); - + var actual = new Rgba64(source); + Assert.Equal(expected, actual); } - + [Fact] public void ConstructFrom_Argb32() { var expected = new Rgba64(5140, 9766, 19532, 29555); var source = new Argb32(20, 38, 76, 115); - Rgba64 actual = new Rgba64(source); - + var actual = new Rgba64(source); + Assert.Equal(expected, actual); } - + [Fact] public void ConstructFrom_Rgb24() { var expected = new Rgba64(5140, 9766, 19532, ushort.MaxValue); var source = new Rgb24(20, 38, 76); - Rgba64 actual = new Rgba64(source); - + var actual = new Rgba64(source); + Assert.Equal(expected, actual); } - + [Fact] public void ConstructFrom_Bgr24() { var expected = new Rgba64(5140, 9766, 19532, ushort.MaxValue); var source = new Bgr24(20, 38, 76); - Rgba64 actual = new Rgba64(source); - + var actual = new Rgba64(source); + Assert.Equal(expected, actual); } - + [Fact] public void ConstructFrom_Vector4() { - Vector4 source = new Vector4(0f, 0.2f, 0.5f, 1f); + var source = new Vector4(0f, 0.2f, 0.5f, 1f); Rgba64 expected = default; expected.FromScaledVector4(source); - - Rgba64 actual = new Rgba64(source); - + + var actual = new Rgba64(source); + Assert.Equal(expected, actual); } - + [Fact] public void ToRgba32_Retval() { // arrange var source = new Rgba64(5140, 9766, 19532, 29555); var expected = new Rgba32(20, 38, 76, 115); - + // act var actual = source.ToRgba32(); // assert Assert.Equal(expected, actual); } - + [Fact] public void ToBgra32_Retval() { // arrange var source = new Rgba64(5140, 9766, 19532, 29555); var expected = new Bgra32(20, 38, 76, 115); - + // act var actual = source.ToBgra32(); // assert Assert.Equal(expected, actual); } - + [Fact] public void ToArgb32_Retval() { // arrange var source = new Rgba64(5140, 9766, 19532, 29555); var expected = new Argb32(20, 38, 76, 115); - + // act var actual = source.ToArgb32(); // assert Assert.Equal(expected, actual); } - + [Fact] public void ToRgb24_Retval() { // arrange var source = new Rgba64(5140, 9766, 19532, 29555); var expected = new Rgb24(20, 38, 76); - + // act var actual = source.ToRgb24(); // assert Assert.Equal(expected, actual); } - + [Fact] public void ToBgr24_Retval() { // arrange var source = new Rgba64(5140, 9766, 19532, 29555); var expected = new Bgr24(20, 38, 76); - + // act var actual = source.ToBgr24(); diff --git a/tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs b/tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs index 570d72cf49..fe2f8394ff 100644 --- a/tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/RgbaVectorTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats } /// - /// Tests that the individual float elements are layed out in RGBA order. + /// Tests that the individual float elements are laid out in RGBA order. /// [Fact] public void FloatLayout() @@ -189,4 +189,4 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.Equal(expected, rgba.ToScaledVector4()); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs index 1cb7d89980..45f8e25f43 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; @@ -61,7 +61,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats // act var pixel = default(Short4); pixel.FromScaledVector4(scaled); - ulong actual = pixel.PackedValue; // assert Assert.Equal((ulong)expected, pixel.PackedValue); diff --git a/tests/ImageSharp.Tests/Primitives/DenseMatrixTests.cs b/tests/ImageSharp.Tests/Primitives/DenseMatrixTests.cs index 0af8ae45f9..d684198fa7 100644 --- a/tests/ImageSharp.Tests/Primitives/DenseMatrixTests.cs +++ b/tests/ImageSharp.Tests/Primitives/DenseMatrixTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -19,37 +19,25 @@ namespace SixLabors.ImageSharp.Tests.Primitives [Fact] public void DenseMatrixThrowsOnNullInitializer() { - Assert.Throws(() => - { - var dense = new DenseMatrix(null); - }); + Assert.Throws(() => new DenseMatrix(null)); } [Fact] public void DenseMatrixThrowsOnEmptyZeroWidth() { - Assert.Throws(() => - { - var dense = new DenseMatrix(0, 10); - }); + Assert.Throws(() => new DenseMatrix(0, 10)); } [Fact] public void DenseMatrixThrowsOnEmptyZeroHeight() { - Assert.Throws(() => - { - var dense = new DenseMatrix(10, 0); - }); + Assert.Throws(() => new DenseMatrix(10, 0)); } [Fact] public void DenseMatrixThrowsOnEmptyInitializer() { - Assert.Throws(() => - { - var dense = new DenseMatrix(new float[0, 0]); - }); + Assert.Throws(() => new DenseMatrix(new float[0, 0])); } [Fact] @@ -131,4 +119,4 @@ namespace SixLabors.ImageSharp.Tests.Primitives Assert.Equal(3, transposed[2, 0]); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs index dcbf0ca038..531ad69b83 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Binarization; using SixLabors.ImageSharp.Processing.Processors.Dithering; diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs index f0fcba1815..34165319af 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Binarization; diff --git a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs index 8c659848fc..b67c482dd2 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Convolution; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs index 07b9b1b8c6..6a864d83a4 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs @@ -2,12 +2,11 @@ // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; -using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.ImageSharp.Tests.TestUtilities; -using SixLabors.Primitives; + using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Convolution diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs index 0f64ebbeb4..8d17bc3564 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Convolution; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs index 7c2205f4e4..5849f1a98e 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Convolution; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs index d91688cd2c..c5d18cbb2b 100644 --- a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs @@ -1,9 +1,8 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Dithering; using SixLabors.ImageSharp.Processing.Processors.Dithering; @@ -18,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization { public static void Equal(ReadOnlySpan a, ReadOnlySpan b) { - Xunit.Assert.True(a.SequenceEqual(b)); + True(a.SequenceEqual(b)); } } @@ -113,4 +112,4 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization Assert.Equal(this.TestPalette, p.Palette); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs index 14758958f0..1b5bd656dc 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Overlays; diff --git a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs index 6e1ee40f56..18842e1f36 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Effects; using Xunit; @@ -30,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects Assert.Equal(15, processor.BrushSize); } [Fact] - public void OilPaint_Levels_Brsuh_OilPaintingProcessorDefaultsSet() + public void OilPaint_Levels_Brush_OilPaintingProcessorDefaultsSet() { this.operations.OilPaint(34, 65); var processor = this.Verify(); @@ -40,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects } [Fact] - public void OilPaint_Levels_Brsuh_rect_OilPaintingProcessorDefaultsSet() + public void OilPaint_Levels_Brush_rect_OilPaintingProcessorDefaultsSet() { this.operations.OilPaint(54, 43, this.rect); var processor = this.Verify(this.rect); diff --git a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs index d8ce291707..f449b8cb50 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Effects; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs index f913068e35..41e60c84ae 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs @@ -1,7 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; @@ -14,14 +13,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters public void BlackWhite_CorrectProcessor() { this.operations.BlackWhite(); - BlackWhiteProcessor p = this.Verify(); + this.Verify(); } [Fact] public void BlackWhite_rect_CorrectProcessor() { this.operations.BlackWhite(this.rect); - BlackWhiteProcessor p = this.Verify(this.rect); + this.Verify(this.rect); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs index c26524880a..a8b5b36435 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs index 7dd894403d..e287fb7b5f 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs @@ -1,9 +1,8 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.ImageSharp.Processing.Processors; @@ -32,7 +31,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters where T : IImageProcessor { this.operations.ColorBlindness(colorBlindness); - T p = this.Verify(); + this.Verify(); } [Theory] [MemberData(nameof(TheoryData))] @@ -40,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters where T : IImageProcessor { this.operations.ColorBlindness(colorBlindness, this.rect); - T p = this.Verify(this.rect); + this.Verify(this.rect); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs index ff2b1c702d..e55e983dad 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects diff --git a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs index d598f0ac88..46fa611686 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs @@ -1,9 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters @@ -17,14 +14,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters public void Filter_CorrectProcessor() { this.operations.Filter(KnownFilterMatrices.AchromatomalyFilter * KnownFilterMatrices.CreateHueFilter(90F)); - FilterProcessor p = this.Verify(); + this.Verify(); } [Fact] public void Filter_rect_CorrectProcessor() { this.operations.Filter(KnownFilterMatrices.AchromatomalyFilter * KnownFilterMatrices.CreateHueFilter(90F), this.rect); - FilterProcessor p = this.Verify(this.rect); + this.Verify(this.rect); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs index 94e1b00a71..08de55d6b1 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs @@ -1,9 +1,8 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.ImageSharp.Processing.Processors; @@ -25,7 +24,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters where T : IImageProcessor { this.operations.Grayscale(mode); - var p = this.Verify(); + this.Verify(); } [Theory] @@ -44,4 +43,4 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters this.Verify(this.rect); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs b/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs index 0eb25043c7..8aef5415cd 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; diff --git a/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs index ff59eab054..7e8b76458b 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs @@ -1,7 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; @@ -14,14 +13,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects public void Invert_InvertProcessorDefaultsSet() { this.operations.Invert(); - var processor = this.Verify(); + this.Verify(); } [Fact] public void Pixelate_rect_PixelateProcessorDefaultsSet() { this.operations.Invert(this.rect); - var processor = this.Verify(this.rect); + this.Verify(this.rect); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs index a06a9d65c0..c171a12431 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs @@ -1,7 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; @@ -14,14 +13,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters public void Kodachrome_amount_KodachromeProcessorDefaultsSet() { this.operations.Kodachrome(); - var processor = this.Verify(); + this.Verify(); } [Fact] public void Kodachrome_amount_rect_KodachromeProcessorDefaultsSet() { this.operations.Kodachrome(this.rect); - var processor = this.Verify(this.rect); + this.Verify(this.rect); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs index 446cfa1c33..a9aecaa9ca 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs @@ -1,10 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.IO; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests @@ -18,14 +14,14 @@ namespace SixLabors.ImageSharp.Tests public void Lomograph_amount_LomographProcessorDefaultsSet() { this.operations.Lomograph(); - var processor = this.Verify(); + this.Verify(); } [Fact] public void Lomograph_amount_rect_LomographProcessorDefaultsSet() { this.operations.Lomograph(this.rect); - var processor = this.Verify(this.rect); + this.Verify(this.rect); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs b/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs index 95ea2c23e9..89e7d5ef9a 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs index f63b892bc9..c3e2c3c502 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs @@ -1,7 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; @@ -15,14 +14,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters public void Polaroid_amount_PolaroidProcessorDefaultsSet() { this.operations.Polaroid(); - var processor = this.Verify(); + this.Verify(); } [Fact] public void Polaroid_amount_rect_PolaroidProcessorDefaultsSet() { this.operations.Polaroid(this.rect); - var processor = this.Verify(this.rect); + this.Verify(this.rect); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs b/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs index b1583b4aca..8ae4107687 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs index 441c9739d7..02e5f42763 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs @@ -1,7 +1,6 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; @@ -14,14 +13,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters public void Sepia_amount_SepiaProcessorDefaultsSet() { this.operations.Sepia(); - var processor = this.Verify(); + this.Verify(); } [Fact] public void Sepia_amount_rect_SepiaProcessorDefaultsSet() { this.operations.Sepia(this.rect); - var processor = this.Verify(this.rect); + this.Verify(this.rect); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs index fc9a583dd1..5d8a155f05 100644 --- a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs +++ b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization public void HistogramEqualizationTest(int luminanceLevels) { // Arrange - byte[] pixels = new byte[] + var pixels = new byte[] { 52, 55, 61, 59, 70, 61, 76, 61, 62, 59, 55, 104, 94, 85, 59, 71, @@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization } } - byte[] expected = new byte[] + var expected = new byte[] { 0, 12, 53, 32, 146, 53, 174, 53, 57, 32, 12, 227, 219, 202, 32, 154, @@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization }; // Act - image.Mutate(x => x.HistogramEqualization(new HistogramEqualizationOptions() + image.Mutate(x => x.HistogramEqualization(new HistogramEqualizationOptions { LuminanceLevels = luminanceLevels })); @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization { using (Image image = provider.GetImage()) { - var options = new HistogramEqualizationOptions() + var options = new HistogramEqualizationOptions { Method = HistogramEqualizationMethod.AdaptiveSlidingWindow, LuminanceLevels = 256, @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization { using (Image image = provider.GetImage()) { - var options = new HistogramEqualizationOptions() + var options = new HistogramEqualizationOptions { Method = HistogramEqualizationMethod.AdaptiveTileInterpolation, LuminanceLevels = 256, diff --git a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs index 0301f5c039..978fd416bc 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; - using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; diff --git a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs index 2538aa137c..2484cf0cb8 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Overlays; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs new file mode 100644 index 0000000000..3796c51a3b --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs @@ -0,0 +1,156 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text.RegularExpressions; + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Convolution; +using SixLabors.Primitives; + +using Xunit; +using Xunit.Abstractions; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution +{ + public class BokehBlurTest + { + private static readonly string Components10x2 = @" + [[ 0.00451261+0.0165137j 0.02161237-0.00299122j 0.00387479-0.02682816j + -0.02752798-0.01788438j -0.03553877+0.0154543j -0.01428268+0.04224722j + 0.01747482+0.04687464j 0.04243676+0.03451751j 0.05564306+0.01742537j + 0.06040984+0.00459225j 0.06136251+0.0j 0.06040984+0.00459225j + 0.05564306+0.01742537j 0.04243676+0.03451751j 0.01747482+0.04687464j + -0.01428268+0.04224722j -0.03553877+0.0154543j -0.02752798-0.01788438j + 0.00387479-0.02682816j 0.02161237-0.00299122j 0.00451261+0.0165137j ]] + [[-0.00227282+0.002851j -0.00152245+0.00604545j 0.00135338+0.00998296j + 0.00698622+0.01370844j 0.0153483+0.01605112j 0.02565295+0.01611732j + 0.03656958+0.01372368j 0.04662725+0.00954624j 0.05458942+0.00491277j + 0.05963937+0.00133843j 0.06136251+0.0j 0.05963937+0.00133843j + 0.05458942+0.00491277j 0.04662725+0.00954624j 0.03656958+0.01372368j + 0.02565295+0.01611732j 0.0153483+0.01605112j 0.00698622+0.01370844j + 0.00135338+0.00998296j -0.00152245+0.00604545j -0.00227282+0.002851j ]]"; + + [Fact] + public void VerifyComplexComponents() + { + // Get the saved components + var components = new List(); + foreach (Match match in Regex.Matches(Components10x2, @"\[\[(.*?)\]\]", RegexOptions.Singleline)) + { + string[] values = match.Groups[1].Value.Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + Complex64[] component = values.Select( + value => + { + Match pair = Regex.Match(value, @"([+-]?\d+\.\d+)([+-]?\d+\.\d+)j"); + return new Complex64( + float.Parse(pair.Groups[1].Value, CultureInfo.InvariantCulture), + float.Parse(pair.Groups[2].Value, CultureInfo.InvariantCulture)); + }).ToArray(); + components.Add(component); + } + + // Make sure the kernel components are the same + var definition = new BokehBlurProcessor(10, BokehBlurProcessor.DefaultComponents, BokehBlurProcessor.DefaultGamma); + var processor = new BokehBlurProcessor(definition); + Assert.Equal(components.Count, processor.Kernels.Count); + foreach ((Complex64[] a, Complex64[] b) in components.Zip(processor.Kernels, (a, b) => (a, b))) + { + Span spanA = a.AsSpan(), spanB = b.AsSpan(); + Assert.Equal(spanA.Length, spanB.Length); + for (int i = 0; i < spanA.Length; i++) + { + Assert.True(Math.Abs(Math.Abs(spanA[i].Real) - Math.Abs(spanB[i].Real)) < 0.0001f); + Assert.True(Math.Abs(Math.Abs(spanA[i].Imaginary) - Math.Abs(spanB[i].Imaginary)) < 0.0001f); + } + } + } + + public sealed class BokehBlurInfo : IXunitSerializable + { + public int Radius { get; set; } + + public int Components { get; set; } + + public float Gamma { get; set; } + + public void Deserialize(IXunitSerializationInfo info) + { + this.Radius = info.GetValue(nameof(this.Radius)); + this.Components = info.GetValue(nameof(this.Components)); + this.Gamma = info.GetValue(nameof(this.Gamma)); + } + + public void Serialize(IXunitSerializationInfo info) + { + info.AddValue(nameof(this.Radius), this.Radius, typeof(int)); + info.AddValue(nameof(this.Components), this.Components, typeof(int)); + info.AddValue(nameof(this.Gamma), this.Gamma, typeof(float)); + } + + public override string ToString() => $"R{this.Radius}_C{this.Components}_G{this.Gamma}"; + } + + public static readonly TheoryData BokehBlurValues = new TheoryData + { + new BokehBlurInfo { Radius = 8, Components = 1, Gamma = 1 }, + new BokehBlurInfo { Radius = 16, Components = 1, Gamma = 3 }, + new BokehBlurInfo { Radius = 16, Components = 2, Gamma = 3 } + }; + + public static readonly string[] TestFiles = + { + TestImages.Png.CalliphoraPartial, + TestImages.Png.Bike, + TestImages.Png.BikeGrayscale, + TestImages.Png.Cross, + }; + + [Theory] + [WithFileCollection(nameof(TestFiles), nameof(BokehBlurValues), PixelTypes.Rgba32)] + [WithSolidFilledImages(nameof(BokehBlurValues), 50, 50, "Red", PixelTypes.Rgba32)] + [WithTestPatternImages(nameof(BokehBlurValues), 200, 100, PixelTypes.Rgba32)] + [WithTestPatternImages(nameof(BokehBlurValues), 23, 31, PixelTypes.Rgba32)] + [WithTestPatternImages(nameof(BokehBlurValues), 30, 20, PixelTypes.Rgba32)] + public void BokehBlurFilterProcessor(TestImageProvider provider, BokehBlurInfo value) + where TPixel : struct, IPixel + { + provider.RunValidatingProcessorTest( + x => x.BokehBlur(value.Radius, value.Components, value.Gamma), + testOutputDetails: value.ToString(), + appendPixelTypeToFileName: false); + } + + [Theory] + [WithTestPatternImages(200, 200, PixelTypes.Bgr24 | PixelTypes.Bgra32 | PixelTypes.Gray8)] + public void BokehBlurFilterProcessor_WorksWithAllPixelTypes(TestImageProvider provider) + where TPixel : struct, IPixel + { + provider.RunValidatingProcessorTest( + x => x.BokehBlur(8, 2, 3), + appendSourceFileOrDescription: false); + } + + + [Theory] + [WithFileCollection(nameof(TestFiles), nameof(BokehBlurValues), PixelTypes.Rgba32)] + public void BokehBlurFilterProcessor_Bounded(TestImageProvider provider, BokehBlurInfo value) + where TPixel : struct, IPixel + { + provider.RunValidatingProcessorTest( + x => + { + Size size = x.GetCurrentSize(); + var bounds = new Rectangle(10, 10, size.Width / 2, size.Height / 2); + x.BokehBlur(value.Radius, value.Components, value.Gamma, bounds); + }, + testOutputDetails: value.ToString(), + appendPixelTypeToFileName: false); + } + } +} diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs index 68eb8c4f63..24ed090d8a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs @@ -1,13 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; -using Xunit; - namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { [GroupOutput("Convolution")] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs index 4b497309ee..96d223ee9f 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs @@ -1,11 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; -using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs index cb901c2a88..5417bc1f34 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Dithering; using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; -using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs index dc6ff6f3eb..56ffceb47a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs @@ -3,9 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; -using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs index ea2273cd5d..aad48e357a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs @@ -3,9 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; -using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs index 726f4b707b..e95452ffb7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs @@ -3,8 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; -using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs index f08ec147ec..c2728e0435 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs @@ -1,9 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs index 27aeb4b053..5462a8b2da 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs @@ -1,12 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; - using SixLabors.Primitives; -using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs index eaad82f9a3..c1c6bbd7cf 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Reflection; - using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; @@ -20,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays public static string[] InputImages = { TestImages.Png.Ducky, TestImages.Png.Splash }; private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05f); - + [Theory] [WithFileCollection(nameof(InputImages), nameof(ColorNames), PixelTypes.Rgba32)] public void FullImage_ApplyColor(TestImageProvider provider, string colorName) @@ -54,13 +52,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays where TPixel : struct, IPixel { provider.Utility.TestGroupName = this.GetType().Name; - provider.RunRectangleConstrainedValidatingProcessorTest((x, rect) => this.Apply(x, rect)); + provider.RunRectangleConstrainedValidatingProcessorTest(this.Apply); } protected abstract void Apply(IImageProcessingContext ctx, Color color); - + protected abstract void Apply(IImageProcessingContext ctx, float radiusX, float radiusY); - + protected abstract void Apply(IImageProcessingContext ctx, Rectangle rect); } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs index 05ce700476..f2e1136ca6 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Quantization; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs index 6dc9b36309..ceb6f8363b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs @@ -1,11 +1,10 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; @@ -24,10 +23,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { ExifDataType.SignedByte, new byte[] { 2 } }, { ExifDataType.SignedShort, BitConverter.GetBytes((short) 3) }, { ExifDataType.Long, BitConverter.GetBytes((uint) 4) }, - { ExifDataType.SignedLong, BitConverter.GetBytes((int) 5) } + { ExifDataType.SignedLong, BitConverter.GetBytes(5) } }; - public static readonly TheoryData ExifOrientationValues = new TheoryData() + public static readonly TheoryData ExifOrientationValues = new TheoryData { 0, 1, @@ -49,7 +48,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, orientation); - + image.Mutate(x => x.AutoOrient()); image.DebugSave(provider, orientation, appendPixelTypeToFileName: false); image.CompareToReferenceOutput(provider, orientation, appendPixelTypeToFileName: false); @@ -72,8 +71,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms bytes[18] = (byte)dataType; // Change the number of components bytes[20] = 1; - - byte[] orientationCodeData = new byte[8]; + + var orientationCodeData = new byte[8]; Array.Copy(orientation, orientationCodeData, orientation.Length); ulong orientationCode = BitConverter.ToUInt64(orientationCodeData, 0); @@ -88,4 +87,4 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs index f568278706..dbaff43f0c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; @@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public void ImageShouldPadWithBackgroundColor(TestImageProvider provider) where TPixel : struct, IPixel { - Color color = Color.Red; + var color = Color.Red; TPixel expected = color.ToPixel(); using (Image image = provider.GetImage()) { @@ -58,4 +58,4 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs index 2c5914253a..1681c3046a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms double sum = 0; - double[] values = new double[right - left + 1]; + var values = new double[right - left + 1]; for (int j = left; j <= right; j++) { @@ -108,4 +108,4 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs index 51680eee04..91b011ed6a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs @@ -1,10 +1,8 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Generic; using System.Linq; -using System.Reflection; using System.Text; using SixLabors.ImageSharp.Processing; @@ -133,7 +131,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms var referenceMap = ReferenceKernelMap.Calculate(resampler, destSize, srcSize); var kernelMap = ResizeKernelMap.Calculate(resampler, destSize, srcSize, Configuration.Default.MemoryAllocator); - + #if DEBUG this.Output.WriteLine(kernelMap.Info); @@ -241,4 +239,4 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms return result; } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index 8ae298c51e..43384aee7c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -12,7 +12,6 @@ using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.ImageSharp.Tests.Memory; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; -using SixLabors.Memory; using SixLabors.Primitives; using Xunit; @@ -34,8 +33,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public static readonly string[] SmokeTestResamplerNames = { - nameof(KnownResamplers.NearestNeighbor), - nameof(KnownResamplers.Bicubic), + nameof(KnownResamplers.NearestNeighbor), + nameof(KnownResamplers.Bicubic), nameof(KnownResamplers.Box), nameof(KnownResamplers.Lanczos5), }; @@ -47,18 +46,18 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public void Resize_PixelAgnostic() { var filePath = TestFile.GetInputFileFullPath(TestImages.Jpeg.Baseline.Calliphora); - + using (Image image = Image.Load(filePath)) { image.Mutate(x => x.Resize(image.Size() / 2)); string path = System.IO.Path.Combine( TestEnvironment.CreateOutputDirectory(nameof(ResizeTests)), nameof(this.Resize_PixelAgnostic) + ".png"); - + image.Save(path); } } - + [Theory( Skip = "Debug only, enable manually" )] @@ -81,7 +80,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms image.DebugSave(provider, appendPixelTypeToFileName: false); } } - + [Theory] [WithBasicTestPatternImages(15, 12, PixelTypes.Rgba32, 2, 3, 1, 2)] [WithBasicTestPatternImages(2, 256, PixelTypes.Rgba32, 1, 1, 1, 8)] @@ -93,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms // [WithBasicTestPatternImages(15, 12, PixelTypes.Rgba32, 2, 3, 1, 2)] means: // resizing: (15, 12) -> (10, 6) // kernel dimensions: (3, 4) - + using (Image image = provider.GetImage()) { @@ -123,9 +122,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms using (Image image0 = provider.GetImage()) { Size destSize = image0.Size() / 4; - + Configuration configuration = Configuration.CreateDefaultInstance(); - + int workingBufferSizeHintInBytes = workingBufferLimitInRows * destSize.Width * SizeOfVector4; TestMemoryAllocator allocator = new TestMemoryAllocator(); configuration.MemoryAllocator = allocator; @@ -138,7 +137,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms Configuration.Default.MemoryAllocator); int minimumWorkerAllocationInBytes = verticalKernelMap.MaxDiameter * 2 * destSize.Width * SizeOfVector4; verticalKernelMap.Dispose(); - + using (Image image = image0.Clone(configuration)) { image.Mutate(x => x.Resize(destSize, KnownResamplers.Bicubic, false)); @@ -152,12 +151,12 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms provider, testOutputDetails: workingBufferLimitInRows, appendPixelTypeToFileName: false); - + Assert.NotEmpty(allocator.AllocationLog); int maxAllocationSize = allocator.AllocationLog.Where( e => e.ElementType == typeof(Vector4)).Max(e => e.LengthInBytes); - + Assert.True(maxAllocationSize <= Math.Max(workingBufferSizeHintInBytes, minimumWorkerAllocationInBytes)); } } @@ -285,7 +284,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { IResampler sampler = TestUtils.GetResampler(samplerName); - // NeirestNeighbourResampler is producing slightly different results With classic .NET framework on 32bit + // NearestNeighbourResampler is producing slightly different results With classic .NET framework on 32bit // most likely because of differences in numeric behavior. // The difference is well visible when comparing output for // Resize_WorksWithAllResamplers_TestPattern301x1180_NearestNeighbor-300x480.png @@ -298,7 +297,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms // Let's make the working buffer size non-default: provider.Configuration.WorkingBufferSizeHintInBytes = 16 * 1024 * SizeOfVector4; - + provider.RunValidatingProcessorTest( ctx => { @@ -539,4 +538,4 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs index 20e12cb7f9..1e08836c13 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; + using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs index 0547b46e3b..16ff9419ae 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms diff --git a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs index 1c3bf2e90d..5350bd4a33 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs index aa684acd55..8525528c7e 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Transforms; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs index 9fe2977adb..7bb155f3a9 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs @@ -1,10 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs index 056f66af7f..3679180f49 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms public void RawTransformMatchesDocumentedExample(TestImageProvider provider) where TPixel : struct, IPixel { - // Printing some extra output to help investigating roundoff errors: + // Printing some extra output to help investigating rounding errors: this.Output.WriteLine($"Vector.IsHardwareAccelerated: {Vector.IsHardwareAccelerated}"); // This test matches the output described in the example at @@ -160,4 +160,4 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms return (IResampler)property.GetValue(null); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs index 570ac4e2cd..c7ebe65e8c 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs index 079ff67b7a..327b14bcd5 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Transforms; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs index 3e2b859714..b1831f96e8 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Transforms; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs index 38033e80d0..66a157a8ad 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Transforms; diff --git a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs index 04e9803af4..7750017095 100644 --- a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs +++ b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -18,17 +18,17 @@ namespace SixLabors.ImageSharp.Tests public void QuantizersDitherByDefault() { var werner = new WernerPaletteQuantizer(); - var websafe = new WebSafePaletteQuantizer(); + var webSafe = new WebSafePaletteQuantizer(); var octree = new OctreeQuantizer(); var wu = new WuQuantizer(); Assert.NotNull(werner.Diffuser); - Assert.NotNull(websafe.Diffuser); + Assert.NotNull(webSafe.Diffuser); Assert.NotNull(octree.Diffuser); Assert.NotNull(wu.Diffuser); Assert.True(werner.CreateFrameQuantizer(this.Configuration).Dither); - Assert.True(websafe.CreateFrameQuantizer(this.Configuration).Dither); + Assert.True(webSafe.CreateFrameQuantizer(this.Configuration).Dither); Assert.True(octree.CreateFrameQuantizer(this.Configuration).Dither); Assert.True(wu.CreateFrameQuantizer(this.Configuration).Dither); } @@ -101,4 +101,4 @@ namespace SixLabors.ImageSharp.Tests return index; } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs index 1fb745c38f..799794ca4f 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System.Numerics; -using SixLabors.Memory; namespace SixLabors.ImageSharp.Tests { diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs index f19029f8cc..44af423479 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -249,11 +249,6 @@ namespace SixLabors.ImageSharp.Tests LocalizedString_Rand1, LocalizedString_Rand2, }; - private static readonly IccLocalizedString[] LocalizedString_RandArr2 = new IccLocalizedString[] - { - LocalizedString_Rand2, - LocalizedString_Rand1, - }; private static readonly IccMultiLocalizedUnicodeTagDataEntry MultiLocalizedUnicode_Val = new IccMultiLocalizedUnicodeTagDataEntry(LocalizedString_RandArr1); private static readonly byte[] MultiLocalizedUnicode_Arr = ArrayHelper.Concat diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index 6ca86ced6e..8219920909 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -3,10 +3,8 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Reflection; + using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; diff --git a/tests/ImageSharp.Tests/TestFont.cs b/tests/ImageSharp.Tests/TestFont.cs index ee65402f53..c01f50f203 100644 --- a/tests/ImageSharp.Tests/TestFont.cs +++ b/tests/ImageSharp.Tests/TestFont.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; @@ -52,9 +52,9 @@ namespace SixLabors.ImageSharp.Tests Path.GetFullPath(x) }).ToList(); - AddFormatsDirectoryFromTestAssebmlyPath(directories); + AddFormatsDirectoryFromTestAssemblyPath(directories); - string directory = directories.FirstOrDefault(x => Directory.Exists(x)); + string directory = directories.FirstOrDefault(Directory.Exists); if (directory != null) { @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.Tests /// This method calculates and adds the format directory based on the ImageSharp.Tests assembly location. /// /// The directories list - private static void AddFormatsDirectoryFromTestAssebmlyPath(List directories) + private static void AddFormatsDirectoryFromTestAssemblyPath(List directories) { string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location; assemblyLocation = Path.GetDirectoryName(assemblyLocation); diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs index 23bd0a54c3..0a56110560 100644 --- a/tests/ImageSharp.Tests/TestFormat.cs +++ b/tests/ImageSharp.Tests/TestFormat.cs @@ -1,13 +1,12 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; -using System.Reflection; + using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; using Xunit; @@ -20,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests public class TestFormat : IConfigurationModule, IImageFormat { private readonly Dictionary sampleImages = new Dictionary(); - + // We should not change Configuration.Default in individual tests! // Create new configuration instances with new Configuration(TestFormat.GlobalTestFormat) instead! public static TestFormat GlobalTestFormat { get; } = new TestFormat(); @@ -58,20 +57,20 @@ namespace SixLabors.ImageSharp.Tests DecodeOperation[] discovered = this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TPixel))).ToArray(); - Assert.True(discovered.Any(), "No calls to decode on this formate with the proveded options happend"); + Assert.True(discovered.Any(), "No calls to decode on this format with the provided options happened"); foreach (DecodeOperation d in discovered) { this.DecodeCalls.Remove(d); } } - + public void VerifyAgnosticDecodeCall(byte[] marker, Configuration config) { DecodeOperation[] discovered = this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TestPixelForAgnosticDecode))).ToArray(); - Assert.True(discovered.Any(), "No calls to decode on this formate with the proveded options happend"); + Assert.True(discovered.Any(), "No calls to decode on this format with the provided options happened"); foreach (DecodeOperation d in discovered) { @@ -139,7 +138,7 @@ namespace SixLabors.ImageSharp.Tests public byte[] marker; internal Configuration config; - public Type pixelType; + public Type pixelType; public bool IsMatch(byte[] testMarker, Configuration config, Type pixelType) { @@ -213,12 +212,12 @@ namespace SixLabors.ImageSharp.Tests pixelType = typeof(TPixel) }); - // TODO record this happend so we can verify it. + // TODO record this happened so we can verify it. return this.testFormat.Sample(); } public bool IsSupportedFileFormat(Span header) => testFormat.IsSupportedFileFormat(header); - + public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream); } @@ -237,11 +236,11 @@ namespace SixLabors.ImageSharp.Tests public void Encode(Image image, Stream stream) where TPixel : struct, IPixel { - // TODO record this happend so we can verify it. + // TODO record this happened so we can verify it. } } - - + + struct TestPixelForAgnosticDecode : IPixel { public PixelOperations CreatePixelOperations() => new PixelOperations(); diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 754ce20ca9..e95ce09073 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -54,6 +54,8 @@ namespace SixLabors.ImageSharp.Tests public const string Gray4BitTrans = "Png/gray-4-tRNS.png"; public const string Gray8BitTrans = "Png/gray-8-tRNS.png"; public const string LowColorVariance = "Png/low-variance.png"; + public const string PngWithMetaData = "Png/PngWithMetaData.png"; + public const string InvalidTextData = "Png/InvalidTextData.png"; // Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html public const string Filter0 = "Png/filter0.png"; @@ -343,6 +345,7 @@ namespace SixLabors.ImageSharp.Tests public const string Leo = "Gif/leo.gif"; public const string Ratio4x1 = "Gif/base_4x1.gif"; public const string Ratio1x4 = "Gif/base_1x4.gif"; + public const string LargeComment = "Gif/large_comment.gif"; public static class Issues { diff --git a/tests/ImageSharp.Tests/TestUtilities/ArrayHelper.cs b/tests/ImageSharp.Tests/TestUtilities/ArrayHelper.cs index e35cbfa422..fdb694dccb 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ArrayHelper.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ArrayHelper.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Linq; @@ -11,16 +11,16 @@ namespace SixLabors.ImageSharp.Tests /// Concatenates multiple arrays of the same type into one. /// /// The array type - /// The arrays to concatenate. The order is kept + /// The arrays to concatenate. The order is kept /// The concatenated array - public static T[] Concat(params T[][] arrs) + public static T[] Concat(params T[][] arrays) { - var result = new T[arrs.Sum(t => t.Length)]; + var result = new T[arrays.Sum(t => t.Length)]; int offset = 0; - for (int i = 0; i < arrs.Length; i++) + for (int i = 0; i < arrays.Length; i++) { - arrs[i].CopyTo(result, offset); - offset += arrs[i].Length; + arrays[i].CopyTo(result, offset); + offset += arrays[i].Length; } return result; } diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs index 6107154d0e..f03d68307b 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -72,8 +72,8 @@ namespace SixLabors.ImageSharp.Tests addedRows = new[] { new object[0] }; } - bool firstIsprovider = this.FirstIsProvider(testMethod); - if (firstIsprovider) + bool firstIsProvider = this.FirstIsProvider(testMethod); + if (firstIsProvider) { return this.InnerGetData(testMethod, addedRows); } @@ -98,19 +98,19 @@ namespace SixLabors.ImageSharp.Tests { Type factoryType = typeof(TestImageProvider<>).MakeGenericType(kv.Value); - foreach (object[] originalFacoryMethodArgs in this.GetAllFactoryMethodArgs(testMethod, factoryType)) + foreach (object[] originalFactoryMethodArgs in this.GetAllFactoryMethodArgs(testMethod, factoryType)) { foreach (object[] row in memberData) { - object[] actualFactoryMethodArgs = new object[originalFacoryMethodArgs.Length + 2]; - Array.Copy(originalFacoryMethodArgs, actualFactoryMethodArgs, originalFacoryMethodArgs.Length); + var actualFactoryMethodArgs = new object[originalFactoryMethodArgs.Length + 2]; + Array.Copy(originalFactoryMethodArgs, actualFactoryMethodArgs, originalFactoryMethodArgs.Length); actualFactoryMethodArgs[actualFactoryMethodArgs.Length - 2] = testMethod; actualFactoryMethodArgs[actualFactoryMethodArgs.Length - 1] = kv.Key; object factory = factoryType.GetMethod(this.GetFactoryMethodName(testMethod)) .Invoke(null, actualFactoryMethodArgs); - object[] result = new object[this.AdditionalParameters.Length + 1 + row.Length]; + var result = new object[this.AdditionalParameters.Length + 1 + row.Length]; result[0] = factory; Array.Copy(row, 0, result, 1, row.Length); Array.Copy(this.AdditionalParameters, 0, result, 1 + row.Length, this.AdditionalParameters.Length); @@ -192,4 +192,4 @@ namespace SixLabors.ImageSharp.Tests return () => propInfo.GetValue(null, null); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs index 462782ba5e..59167cc888 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison int width = actual.Width; - // TODO: Comparing through Rgba64 may not be robust enough because of the existance of super high precision pixel types. + // TODO: Comparing through Rgba64 may not be robust enough because of the existence of super high precision pixel types. var aBuffer = new Rgba64[width]; var bBuffer = new Rgba64[width]; @@ -54,4 +54,4 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison return new ImageSimilarityReport(expected, actual, differences); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs index e8f60ade31..024c2ee215 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison public class ImageDimensionsMismatchException : ImagesSimilarityException { public ImageDimensionsMismatchException(Size expectedSize, Size actualSize) - : base((string)$"The image dimensions {actualSize} do not match the expected {expectedSize}!") + : base($"The image dimensions {actualSize} do not match the expected {expectedSize}!") { this.ExpectedSize = expectedSize; this.ActualSize = actualSize; @@ -17,4 +17,4 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison public Size ExpectedSize { get; } public Size ActualSize { get; } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index be12f56211..8bed3a7155 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison /// Individual manhattan pixel difference is only added to total image difference when the individual difference is over 'perPixelManhattanThreshold'. /// /// The maximal tolerated difference represented by a value between 0.0 and 1.0 scaled to 0 and 65535. - /// Gets the threshold of the individual pixels before they acumulate towards the overall difference. + /// Gets the threshold of the individual pixels before they accumulate towards the overall difference. public TolerantImageComparer(float imageThreshold, int perPixelManhattanThreshold = 0) { Guard.MustBeGreaterThanOrEqualTo(imageThreshold, 0, nameof(imageThreshold)); @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison public float ImageThreshold { get; } /// - /// Gets the threshold of the individual pixels before they acumulate towards the overall difference. + /// Gets the threshold of the individual pixels before they accumulate towards the overall difference. /// For an individual pixel pair the value is the Manhattan distance of pixels: /// /// https://en.wikipedia.org/wiki/Taxicab_geometry @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison int width = actual.Width; - // TODO: Comparing through Rgba64 may not robust enough because of the existance of super high precision pixel types. + // TODO: Comparing through Rgba64 may not robust enough because of the existence of super high precision pixel types. var aBuffer = new Rgba64[width]; var bBuffer = new Rgba64[width]; @@ -120,4 +120,4 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int Diff(ushort a, ushort b) => Math.Abs(a - b); } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs index 752f8e18bd..63f07eed11 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs @@ -5,7 +5,6 @@ using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Tests { diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs index dae2f0cfe4..0860af1a4e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; - using SixLabors.ImageSharp.PixelFormats; using Xunit.Abstractions; diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index 8d493c7d43..63de4c96f4 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests public Configuration Configuration { get; set; } = Configuration.CreateDefaultInstance(); /// - /// Utility instance to provide informations about the test image & manage input/output + /// Utility instance to provide information about the test image & manage input/output /// public ImagingTestCaseUtility Utility { get; private set; } @@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp.Tests protected TestImageProvider Init( string typeName, string methodName, - string outputSubfolerName, + string outputSubfolderName, PixelTypes pixelTypeOverride) { if (pixelTypeOverride != PixelTypes.Undefined) @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Tests } this.TypeName = typeName; this.MethodName = methodName; - this.OutputSubfolderName = outputSubfolerName; + this.OutputSubfolderName = outputSubfolderName; this.Utility = new ImagingTestCaseUtility { @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.Tests if (methodName != null) { - this.Utility.Init(typeName, methodName, outputSubfolerName); + this.Utility.Init(typeName, methodName, outputSubfolderName); } return this; @@ -166,8 +166,7 @@ namespace SixLabors.ImageSharp.Tests public override string ToString() { - string provName = this.GetType().Name.Replace("Provider", ""); return $"{this.SourceFileOrDescription}[{this.PixelType}]"; } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index 94b2b33913..8965458cd0 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -1,9 +1,8 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Collections.Generic; -using System.Net.Mime; using System.Numerics; using SixLabors.ImageSharp.Memory; @@ -141,7 +140,7 @@ namespace SixLabors.ImageSharp.Tests } /// - /// Fills the bottom left quadrent with 3 horizental bars in Red, Green and Blue with a alpha gradient from left (transparent) to right (solid). + /// Fills the bottom left quadrant with 3 horizontal bars in Red, Green and Blue with a alpha gradient from left (transparent) to right (solid). /// /// private static void TransparentGradients(Buffer2D pixels) @@ -185,7 +184,7 @@ namespace SixLabors.ImageSharp.Tests } /// - /// Fills the bottom right quadrant with all the colors producable by converting itterating over a uint and unpacking it. + /// Fills the bottom right quadrant with all the colors producible by converting iterating over a uint and unpacking it. /// A better algorithm could be used but it works /// /// @@ -199,7 +198,7 @@ namespace SixLabors.ImageSharp.Tests int pixelCount = left * top; uint stepsPerPixel = (uint)(uint.MaxValue / pixelCount); TPixel c = default; - Rgba32 t = new Rgba32(0); + var t = new Rgba32(0); for (int x = left; x < right; x++) { @@ -215,4 +214,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/MeasureFixture.cs b/tests/ImageSharp.Tests/TestUtilities/MeasureFixture.cs index 6d06ec5e93..61bd7cd9fb 100644 --- a/tests/ImageSharp.Tests/TestUtilities/MeasureFixture.cs +++ b/tests/ImageSharp.Tests/TestUtilities/MeasureFixture.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Tests public class MeasureFixture { /// - /// Value indicating whether priniting is enabled. + /// Value indicating whether printing is enabled. /// protected bool EnablePrinting = true; @@ -79,4 +79,4 @@ namespace SixLabors.ImageSharp.Tests this.Output.WriteLine($"{this.operation} completed in {this.stopwatch.ElapsedMilliseconds}ms"); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/TestDataGenerator.cs b/tests/ImageSharp.Tests/TestUtilities/TestDataGenerator.cs index 4ccb387451..7c29ac4db0 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestDataGenerator.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestDataGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Tests /// The . public static float[] GenerateRandomFloatArray(this Random rnd, int length, float minVal, float maxVal) { - float[] values = new float[length]; + var values = new float[length]; RandomFill(rnd, values, minVal, maxVal); @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.Tests /// The . public static float[] GenerateRandomRoundedFloatArray(this Random rnd, int length, float minVal, float maxVal) { - float[] values = new float[length]; + var values = new float[length]; for (int i = 0; i < length; i++) { @@ -88,14 +88,14 @@ namespace SixLabors.ImageSharp.Tests /// The . public static byte[] GenerateRandomByteArray(this Random rnd, int length) { - byte[] values = new byte[length]; + var values = new byte[length]; rnd.NextBytes(values); return values; } public static short[] GenerateRandomInt16Array(this Random rnd, int length, short minVal, short maxVal) { - short[] values = new short[length]; + var values = new short[length]; for (int i = 0; i < values.Length; i++) { values[i] = (short)rnd.Next(minVal, maxVal); @@ -106,4 +106,4 @@ namespace SixLabors.ImageSharp.Tests private static float GetRandomFloat(this Random rnd, float minVal, float maxVal) => ((float)rnd.NextDouble() * (maxVal - minVal)) + minVal; } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 8de3a347ba..91943d9a6a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -10,7 +10,6 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.ParallelUtils; -using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; @@ -538,7 +537,7 @@ namespace SixLabors.ImageSharp.Tests /// Utility method for doing the following in one step: /// 1. Executing an operation (taken as a delegate) /// 2. Executing DebugSave() - /// 3. Executing CopareToReferenceOutput() + /// 3. Executing CompareToReferenceOutput() /// internal static void VerifyOperation( this TestImageProvider provider, @@ -571,7 +570,7 @@ namespace SixLabors.ImageSharp.Tests /// Utility method for doing the following in one step: /// 1. Executing an operation (taken as a delegate) /// 2. Executing DebugSave() - /// 3. Executing CopareToReferenceOutput() + /// 3. Executing CompareToReferenceOutput() /// internal static void VerifyOperation( this TestImageProvider provider, @@ -593,7 +592,7 @@ namespace SixLabors.ImageSharp.Tests /// Utility method for doing the following in one step: /// 1. Executing an operation (taken as a delegate) /// 2. Executing DebugSave() - /// 3. Executing CopareToReferenceOutput() + /// 3. Executing CompareToReferenceOutput() /// internal static void VerifyOperation( this TestImageProvider provider, @@ -615,7 +614,7 @@ namespace SixLabors.ImageSharp.Tests /// Utility method for doing the following in one step: /// 1. Executing an operation (taken as a delegate) /// 2. Executing DebugSave() - /// 3. Executing CopareToReferenceOutput() + /// 3. Executing CompareToReferenceOutput() /// internal static void VerifyOperation( this TestImageProvider provider, @@ -710,4 +709,4 @@ namespace SixLabors.ImageSharp.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs b/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs index 5613e7b684..e1209a0c6a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs @@ -11,21 +11,21 @@ namespace SixLabors.ImageSharp.Tests.Memory internal class TestMemoryAllocator : MemoryAllocator { private List allocationLog = new List(); - + public TestMemoryAllocator(byte dirtyValue = 42) { this.DirtyValue = dirtyValue; } /// - /// The value to initilazie the result buffer with, with non-clean options () + /// The value to initialize the result buffer with, with non-clean options () /// public byte DirtyValue { get; } public IList AllocationLog => this.allocationLog; public override IMemoryOwner Allocate(int length, AllocationOptions options = AllocationOptions.None) - { + { T[] array = this.AllocateArray(length, options); return new BasicArrayBuffer(array, length); } @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Memory byte[] array = this.AllocateArray(length, options); return new ManagedByteBuffer(array); } - + private T[] AllocateArray(int length, AllocationOptions options) where T : struct { @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Memory return array; } - + public struct AllocationRequest { private AllocationRequest(Type elementType, AllocationOptions allocationOptions, int length, int lengthInBytes) @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Memory if (elementType == typeof(Vector4)) { - + } } diff --git a/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs b/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs index e998ccd3dc..1e1a45f074 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs @@ -2,8 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Generic; -using System.Text; + using SixLabors.ImageSharp.PixelFormats; using Xunit.Abstractions; diff --git a/tests/ImageSharp.Tests/TestUtilities/TestType.cs b/tests/ImageSharp.Tests/TestUtilities/TestType.cs index 852aaf2d43..7643fb321e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestType.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestType.cs @@ -1,10 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Collections.Generic; -using System.Text; -using SixLabors.ImageSharp.PixelFormats; using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests.TestUtilities diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs index c935a4b982..61db992988 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests [WithTestPatternImages(100, 100, PixelTypes.Rgba32, 0, 0)] public void TolerantImageComparer_ApprovesPerfectSimilarity( TestImageProvider provider, - float imageTheshold, + float imageThreshold, int pixelThreshold) where TPixel : struct, IPixel { @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests { using (Image clone = image.Clone()) { - var comparer = ImageComparer.Tolerant(imageTheshold, pixelThreshold); + var comparer = ImageComparer.Tolerant(imageThreshold, pixelThreshold); comparer.VerifySimilarity(image, clone); } } diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceDecoderBenchmarks.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceDecoderBenchmarks.cs index 15213d5d32..b0d3b8c7e8 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceDecoderBenchmarks.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceDecoderBenchmarks.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests public void BenchmarkMagickPngDecoder(TestImageProvider provider) where TPixel : struct, IPixel { - this.BenckmarkDecoderImpl(PngBenchmarkFiles, new MagickReferenceDecoder(), $@"Magick Decode Png"); + this.BenchmarkDecoderImpl(PngBenchmarkFiles, new MagickReferenceDecoder(), "Magick Decode Png"); } [Theory(Skip = SkipBenchmarks)] @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests public void BenchmarkSystemDrawingPngDecoder(TestImageProvider provider) where TPixel : struct, IPixel { - this.BenckmarkDecoderImpl(PngBenchmarkFiles, new SystemDrawingReferenceDecoder(), $@"System.Drawing Decode Png"); + this.BenchmarkDecoderImpl(PngBenchmarkFiles, new SystemDrawingReferenceDecoder(), "System.Drawing Decode Png"); } [Theory(Skip = SkipBenchmarks)] @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests public void BenchmarkMagickBmpDecoder(TestImageProvider provider) where TPixel : struct, IPixel { - this.BenckmarkDecoderImpl(BmpBenchmarkFiles, new MagickReferenceDecoder(), $@"Magick Decode Bmp"); + this.BenchmarkDecoderImpl(BmpBenchmarkFiles, new MagickReferenceDecoder(), "Magick Decode Bmp"); } [Theory(Skip = SkipBenchmarks)] @@ -75,10 +75,10 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests public void BenchmarkSystemDrawingBmpDecoder(TestImageProvider provider) where TPixel : struct, IPixel { - this.BenckmarkDecoderImpl(BmpBenchmarkFiles, new SystemDrawingReferenceDecoder(), $@"System.Drawing Decode Bmp"); + this.BenchmarkDecoderImpl(BmpBenchmarkFiles, new SystemDrawingReferenceDecoder(), "System.Drawing Decode Bmp"); } - private void BenckmarkDecoderImpl(IEnumerable testFiles, IImageDecoder decoder, string info, int times = DefaultExecutionCount) + private void BenchmarkDecoderImpl(IEnumerable testFiles, IImageDecoder decoder, string info, int times = DefaultExecutionCount) { var measure = new MeasureFixture(this.Output); measure.Measure(times, @@ -93,4 +93,4 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests info); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/SystemDrawingReferenceCodecTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/SystemDrawingReferenceCodecTests.cs index 3cdb67dbdb..4a02d280e5 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/SystemDrawingReferenceCodecTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/SystemDrawingReferenceCodecTests.cs @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests sourceImage.Mutate(c => c.MakeOpaque()); } - var encoder = new PngEncoder() { ColorType = pngColorType }; + var encoder = new PngEncoder { ColorType = pngColorType }; return provider.Utility.SaveTestOutputFile(sourceImage, "png", encoder); } } @@ -133,4 +133,4 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs index 122234ae89..096f78299b 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs @@ -3,8 +3,6 @@ using System; using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Formats; diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index b49baa5c41..738465a6ed 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -19,18 +19,17 @@ namespace SixLabors.ImageSharp.Tests { public class TestImageProviderTests { - public static readonly TheoryData BasicData = new TheoryData() - { - TestImageProvider.Blank(10, 20), - TestImageProvider.Blank(10, 20), - }; - - public static readonly TheoryData FileData = new TheoryData() - { - TestImageProvider.File(TestImages.Bmp.Car), - TestImageProvider.File( - TestImages.Bmp.F) - }; + public static readonly TheoryData BasicData = new TheoryData + { + TestImageProvider.Blank(10, 20), + TestImageProvider.Blank(10, 20), + }; + + public static readonly TheoryData FileData = new TheoryData + { + TestImageProvider.File(TestImages.Bmp.Car), + TestImageProvider.File(TestImages.Bmp.F) + }; public static string[] AllBmpFiles = { TestImages.Bmp.F, TestImages.Bmp.Bit8 }; @@ -115,10 +114,10 @@ namespace SixLabors.ImageSharp.Tests string testName = nameof(this .GetImage_WithCustomParametricDecoder_ShouldNotUtilizeCache_WhenParametersAreNotEqual); - var decoder1 = new TestDecoderWithParameters() { Param1 = "Lol", Param2 = 42 }; + var decoder1 = new TestDecoderWithParameters { Param1 = "Lol", Param2 = 42 }; decoder1.InitCaller(testName); - var decoder2 = new TestDecoderWithParameters() { Param1 = "LoL", Param2 = 42 }; + var decoder2 = new TestDecoderWithParameters { Param1 = "LoL", Param2 = 42 }; decoder2.InitCaller(testName); provider.GetImage(decoder1); @@ -149,10 +148,10 @@ namespace SixLabors.ImageSharp.Tests string testName = nameof(this .GetImage_WithCustomParametricDecoder_ShouldUtilizeCache_WhenParametersAreEqual); - var decoder1 = new TestDecoderWithParameters() { Param1 = "Lol", Param2 = 666 }; + var decoder1 = new TestDecoderWithParameters { Param1 = "Lol", Param2 = 666 }; decoder1.InitCaller(testName); - var decoder2 = new TestDecoderWithParameters() { Param1 = "Lol", Param2 = 666 }; + var decoder2 = new TestDecoderWithParameters { Param1 = "Lol", Param2 = 666 }; decoder2.InitCaller(testName); provider.GetImage(decoder1); @@ -320,7 +319,7 @@ namespace SixLabors.ImageSharp.Tests img.DebugSave(provider); } } - + [Theory] [WithTestPatternImages(20, 20, PixelTypes.Rgba32)] public void Use_WithTestPatternImages_CustomConfiguration(TestImageProvider provider) @@ -332,13 +331,13 @@ namespace SixLabors.ImageSharp.Tests private static void EnsureCustomConfigurationIsApplied(TestImageProvider provider) where TPixel : struct, IPixel { - using (var image1 = provider.GetImage()) + using (provider.GetImage()) { var customConfiguration = Configuration.CreateDefaultInstance(); provider.Configuration = customConfiguration; - using (var image2 = provider.GetImage()) - using (var image3 = provider.GetImage()) + using (Image image2 = provider.GetImage()) + using (Image image3 = provider.GetImage()) { Assert.Same(customConfiguration, image2.GetConfiguration()); Assert.Same(customConfiguration, image3.GetConfiguration()); @@ -355,7 +354,7 @@ namespace SixLabors.ImageSharp.Tests private static readonly object Monitor = new object(); - private string callerName = null; + private string callerName; public static void DoTestThreadSafe(Action action) { @@ -379,7 +378,7 @@ namespace SixLabors.ImageSharp.Tests this.callerName = name; invocationCounts[name] = 0; } - + public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream); } @@ -390,7 +389,7 @@ namespace SixLabors.ImageSharp.Tests private static readonly object Monitor = new object(); - private string callerName = null; + private string callerName; public string Param1 { get; set; } @@ -418,8 +417,8 @@ namespace SixLabors.ImageSharp.Tests this.callerName = name; invocationCounts[name] = 0; } - + public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/VectorAssert.cs b/tests/ImageSharp.Tests/VectorAssert.cs index 402d066555..9612882b3d 100644 --- a/tests/ImageSharp.Tests/VectorAssert.cs +++ b/tests/ImageSharp.Tests/VectorAssert.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.Numerics; -using SixLabors.ImageSharp; + using SixLabors.ImageSharp.PixelFormats; using Xunit; diff --git a/tests/Images/External b/tests/Images/External index acc32594c1..36f39bc624 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit acc32594c125656840f8a17e69b0ebb49a370fa6 +Subproject commit 36f39bc624f8a49caf512077bf70cab30c2e5fb4 diff --git a/tests/Images/Input/Gif/large_comment.gif b/tests/Images/Input/Gif/large_comment.gif new file mode 100644 index 0000000000..1d378fbf88 Binary files /dev/null and b/tests/Images/Input/Gif/large_comment.gif differ diff --git a/tests/Images/Input/Jpg/baseline/JpegSnoopReports/Floorplan.jpg.txt b/tests/Images/Input/Jpg/baseline/JpegSnoopReports/Floorplan.jpg.txt index 3afec1c893..a557d16c13 100644 --- a/tests/Images/Input/Jpg/baseline/JpegSnoopReports/Floorplan.jpg.txt +++ b/tests/Images/Input/Jpg/baseline/JpegSnoopReports/Floorplan.jpg.txt @@ -63,8 +63,8 @@ Start Offset: 0x00000000 Length = 12772 Identifier = [http://ns.adobe.com/xap/1.0/] XMP = - | - |Windows Photo Editor 10.0.10011.163842016-01-02T19:22:28 + | + |Windows Photo Editor 10.0.10011.163842016-01-02T19:22:28 *** Marker: DQT (xFFDB) *** Define a Quantization Table. diff --git a/tests/Images/Input/Jpg/baseline/JpegSnoopReports/badrst.jpg.txt b/tests/Images/Input/Jpg/baseline/JpegSnoopReports/badrst.jpg.txt index d7c49652e3..3ec02b50d9 100644 --- a/tests/Images/Input/Jpg/baseline/JpegSnoopReports/badrst.jpg.txt +++ b/tests/Images/Input/Jpg/baseline/JpegSnoopReports/badrst.jpg.txt @@ -54,8 +54,8 @@ Start Offset: 0x00000000 Length = 2464 Identifier = [http://ns.adobe.com/xap/1.0/] XMP = - | - |2016-02-28T11:17:08.057 + | + |2016-02-28T11:17:08.057 *** Marker: DQT (xFFDB) *** Define a Quantization Table. diff --git a/tests/Images/Input/Png/InvalidTextData.png b/tests/Images/Input/Png/InvalidTextData.png new file mode 100644 index 0000000000..59f8a97562 Binary files /dev/null and b/tests/Images/Input/Png/InvalidTextData.png differ diff --git a/tests/Images/Input/Png/PngWithMetaData.png b/tests/Images/Input/Png/PngWithMetaData.png new file mode 100644 index 0000000000..af417b1f30 Binary files /dev/null and b/tests/Images/Input/Png/PngWithMetaData.png differ diff --git a/tests/Images/Input/Png/versioning-1_1.png b/tests/Images/Input/Png/versioning-1_1.png index c13f98fd16..96fb7b078d 100644 Binary files a/tests/Images/Input/Png/versioning-1_1.png and b/tests/Images/Input/Png/versioning-1_1.png differ