From 7c6f399d2df6e502367ad97284f8d68fc5025b4b Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sun, 3 Sep 2017 13:31:29 +0100 Subject: [PATCH] internalise span apis from imagebase --- .../Brushes/ImageBrush{TPixel}.cs | 5 +- .../Brushes/PatternBrush{TPixel}.cs | 3 +- .../Brushes/Processors/BrushApplicator.cs | 3 +- .../Brushes/RecolorBrush{TPixel}.cs | 3 +- .../Brushes/SolidBrush{TPixel}.cs | 22 +++++--- .../Unsafe/IPixelSource{TPixel}.cs} | 12 ++--- .../Advanced/Unsafe/ImageExtensions.cs | 50 +++++++++++++++++++ .../ErrorDiffusion/ErrorDiffuserBase.cs | 3 +- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 3 +- .../Formats/Jpeg/PdfJsPort/JpegDecoderCore.cs | 11 ++-- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 5 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 3 +- src/ImageSharp/Image/Image.LoadPixelData.cs | 3 +- src/ImageSharp/Image/ImageBase{TPixel}.cs | 36 +++---------- src/ImageSharp/Image/PixelAccessor{TPixel}.cs | 1 + src/ImageSharp/Memory/SpanHelper.cs | 1 + .../Binarization/BinaryThresholdProcessor.cs | 3 +- .../ErrorDiffusionDitherProcessor.cs | 3 +- .../Binarization/OrderedDitherProcessor.cs | 3 +- .../ColorMatrix/ColorMatrixProcessor.cs | 3 +- .../Convolution/Convolution2DProcessor.cs | 5 +- .../Convolution/ConvolutionProcessor.cs | 5 +- .../Processors/Effects/AlphaProcessor.cs | 3 +- .../Effects/BackgroundColorProcessor.cs | 3 +- .../Processors/Effects/BrightnessProcessor.cs | 3 +- .../Processors/Effects/ContrastProcessor.cs | 3 +- .../Processors/Effects/InvertProcessor.cs | 3 +- .../Effects/OilPaintingProcessor.cs | 5 +- .../Processors/Effects/PixelateProcessor.cs | 3 +- .../Processors/Overlays/GlowProcessor.cs | 3 +- .../Processors/Overlays/VignetteProcessor.cs | 3 +- .../Processors/Transforms/CropProcessor.cs | 3 +- .../Processors/Transforms/FlipProcessor.cs | 7 +-- .../Processors/Transforms/ResizeProcessor.cs | 11 ++-- .../Processors/Transforms/RotateProcessor.cs | 5 +- .../Quantizers/OctreeQuantizer{TPixel}.cs | 3 +- .../Quantizers/PaletteQuantizer{TPixel}.cs | 3 +- .../Quantizers/QuantizerBase{TPixel}.cs | 3 +- .../Quantizers/WuQuantizer{TPixel}.cs | 3 +- .../ImageSharp.Benchmarks/Image/CopyPixels.cs | 6 +-- .../ImageSharp.Tests/Image/ImageLoadTests.cs | 3 +- .../Processors/ColorMatrix/GrayscaleTest.cs | 5 +- .../ImageComparison/ExactImageComparer.cs | 6 +-- .../ImageComparison/TolerantImageComparer.cs | 5 +- .../ReferenceCodecs/SystemDrawingBridge.cs | 7 +-- 45 files changed, 179 insertions(+), 106 deletions(-) rename src/ImageSharp/{Image/IImageBase{TPixel}.cs => Advanced/Unsafe/IPixelSource{TPixel}.cs} (57%) create mode 100644 src/ImageSharp/Advanced/Unsafe/ImageExtensions.cs diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs index 593401777a..5df8138804 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Drawing.Brushes.Processors; using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.Memory; @@ -117,7 +118,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes { int sourceY = (y - this.offsetY) % this.yLength; int offsetX = x - this.offsetX; - Span sourceRow = this.source.GetRowSpan(sourceY); + Span sourceRow = this.source.GetPixelRowSpan(sourceY); for (int i = 0; i < scanline.Length; i++) { @@ -128,7 +129,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes overlay[i] = pixel; } - Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); + Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer); } } diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs index d02baae841..992de95870 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs @@ -3,6 +3,7 @@ using System; using System.Numerics; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Drawing.Brushes.Processors; using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.Memory; @@ -162,7 +163,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes overlay[i] = this.pattern[patternY, patternX]; } - Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); + Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer); } } diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs index 888c7acb09..ecc5e53495 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -77,7 +78,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes.Processors overlay[i] = this[x + i, y]; } - Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); + Span destinationRow = this.Target.GetPixelRowSpan(x).Slice(y, scanline.Length); this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer); } } diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs index 97eb56d30d..56cc934df8 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -3,6 +3,7 @@ using System; using System.Numerics; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Drawing.Brushes.Processors; using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.Memory; @@ -157,7 +158,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes overlay[i] = this[offsetX, y]; } - Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); + Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer); } } diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs index cd8456a478..dab1c6617a 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs @@ -3,6 +3,7 @@ using System; using System.Numerics; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Drawing.Brushes.Processors; using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.Memory; @@ -91,16 +92,23 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// internal override void Apply(Span scanline, int x, int y) { - Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); - - using (var amountBuffer = new Buffer(scanline.Length)) + try { - for (int i = 0; i < scanline.Length; i++) + Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); + + using (var amountBuffer = new Buffer(scanline.Length)) { - amountBuffer[i] = scanline[i] * this.Options.BlendPercentage; - } + for (int i = 0; i < scanline.Length; i++) + { + amountBuffer[i] = scanline[i] * this.Options.BlendPercentage; + } - this.Blender.Blend(destinationRow, destinationRow, this.Colors, amountBuffer); + this.Blender.Blend(destinationRow, destinationRow, this.Colors, amountBuffer); + } + } + catch (Exception) + { + throw; } } } diff --git a/src/ImageSharp/Image/IImageBase{TPixel}.cs b/src/ImageSharp/Advanced/Unsafe/IPixelSource{TPixel}.cs similarity index 57% rename from src/ImageSharp/Image/IImageBase{TPixel}.cs rename to src/ImageSharp/Advanced/Unsafe/IPixelSource{TPixel}.cs index a05867db3c..699a5c48ef 100644 --- a/src/ImageSharp/Image/IImageBase{TPixel}.cs +++ b/src/ImageSharp/Advanced/Unsafe/IPixelSource{TPixel}.cs @@ -4,18 +4,18 @@ using System; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Advanced.Unsafe { /// - /// Encapsulates the basic properties and methods required to manipulate images in varying formats. + /// Allows access to the pixels as an area of contiguous memory in the given pixel format. /// - /// The pixel format. - public interface IImageBase : IImageBase, IDisposable + /// The type of the pixel. + internal interface IPixelSource where TPixel : struct, IPixel { /// /// Gets the representation of the pixels as an area of contiguous memory in the given pixel format. /// - Span Pixels { get; } + Span Span { get; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Advanced/Unsafe/ImageExtensions.cs b/src/ImageSharp/Advanced/Unsafe/ImageExtensions.cs new file mode 100644 index 0000000000..b906ff972a --- /dev/null +++ b/src/ImageSharp/Advanced/Unsafe/ImageExtensions.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Advanced.Unsafe +{ + /// + /// Extension methods over Image{TPixel} + /// + public static partial class ImageExtensions + { + /// + /// Gets the representation of the pixels as an area of contiguous memory in the given pixel format. + /// + /// The type of the pixel. + /// The source. + /// The + public static Span GetPixelSpan(this ImageBase source) + where TPixel : struct, IPixel + => GetSpan(source); + + /// + /// Gets a representing the row 'y' beginning from the the first pixel on that row. + /// + /// The type of the pixel. + /// The source. + /// The row. + /// The + public static Span GetPixelRowSpan(this ImageBase source, int row) + where TPixel : struct, IPixel + => GetSpan(source).Slice(row * source.Width, source.Width); + + /// + /// Gets the span. + /// + /// The type of the pixel. + /// The source. + /// The span retuned from Pixel source + private static Span GetSpan(IPixelSource source) + where TPixel : struct, IPixel + => source.Span; + } +} diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs index 36029335ce..0b0bccb3e5 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -95,7 +96,7 @@ namespace SixLabors.ImageSharp.Dithering.Base int matrixY = y + row; if (matrixY > minY && matrixY < maxY) { - Span rowSpan = image.GetRowSpan(matrixY); + Span rowSpan = image.GetPixelRowSpan(matrixY); for (int col = 0; col < this.matrixWidth; col++) { diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index f94cf0e731..d7b2673891 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -6,6 +6,7 @@ using System.Buffers; using System.IO; using System.Runtime.CompilerServices; using System.Text; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -440,7 +441,7 @@ namespace SixLabors.ImageSharp.Formats.Gif writeY = y; } - Span rowSpan = image.GetRowSpan(writeY); + Span rowSpan = image.GetPixelRowSpan(writeY); Rgba32 rgba = new Rgba32(0, 0, 0, 255); diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegDecoderCore.cs index 3357d03874..f6976b1b3c 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/JpegDecoderCore.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; @@ -860,7 +861,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort { for (int y = 0; y < image.Height; y++) { - Span imageRowSpan = image.GetRowSpan(y); + Span imageRowSpan = image.GetPixelRowSpan(y); Span areaRowSpan = this.pixelArea.GetRowSpan(y); for (int x = 0; x < image.Width; x++) @@ -879,7 +880,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort { for (int y = 0; y < image.Height; y++) { - Span imageRowSpan = image.GetRowSpan(y); + Span imageRowSpan = image.GetPixelRowSpan(y); Span areaRowSpan = this.pixelArea.GetRowSpan(y); for (int x = 0, o = 0; x < image.Width; x++, o += 3) { @@ -898,7 +899,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort { for (int y = 0; y < image.Height; y++) { - Span imageRowSpan = image.GetRowSpan(y); + Span imageRowSpan = image.GetPixelRowSpan(y); Span areaRowSpan = this.pixelArea.GetRowSpan(y); for (int x = 0, o = 0; x < image.Width; x++, o += 4) { @@ -919,7 +920,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort { for (int y = 0; y < image.Height; y++) { - Span imageRowSpan = image.GetRowSpan(y); + Span imageRowSpan = image.GetPixelRowSpan(y); Span areaRowSpan = this.pixelArea.GetRowSpan(y); for (int x = 0, o = 0; x < image.Width; x++, o += 4) { @@ -945,7 +946,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort { for (int y = 0; y < image.Height; y++) { - Span imageRowSpan = image.GetRowSpan(y); + Span imageRowSpan = image.GetPixelRowSpan(y); Span areaRowSpan = this.pixelArea.GetRowSpan(y); PixelOperations.Instance.PackFromRgb24Bytes(areaRowSpan, imageRowSpan, image.Width); diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 2cb38f3ff8..0c8acd51f2 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; using SixLabors.ImageSharp.Memory; @@ -579,7 +580,7 @@ namespace SixLabors.ImageSharp.Formats.Png throw new ImageFormatException("Unknown filter type."); } - Span rowSpan = image.GetRowSpan(this.currentRow); + Span rowSpan = image.GetPixelRowSpan(this.currentRow); this.ProcessInterlacedDefilteredScanline(this.scanline.Array, rowSpan, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]); Swap(ref this.scanline, ref this.previousScanline); @@ -612,7 +613,7 @@ namespace SixLabors.ImageSharp.Formats.Png where TPixel : struct, IPixel { var color = default(TPixel); - Span rowSpan = pixels.GetRowSpan(this.currentRow); + Span rowSpan = pixels.GetPixelRowSpan(this.currentRow); // Trim the first marker byte from the buffer var scanlineBuffer = new Span(defilteredScanline, 1); diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 5e6e77316c..642358fc26 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -6,6 +6,7 @@ using System.Buffers; using System.IO; using System.Linq; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; using SixLabors.ImageSharp.Memory; @@ -676,7 +677,7 @@ namespace SixLabors.ImageSharp.Formats.Png { for (int y = 0; y < this.height; y++) { - Buffer r = this.EncodePixelRow(pixels.GetRowSpan(y), y); + Buffer r = this.EncodePixelRow(pixels.GetPixelRowSpan(y), y); deflateStream.Write(r.Array, 0, resultLength); Swap(ref this.rawScanline, ref this.previousScanline); diff --git a/src/ImageSharp/Image/Image.LoadPixelData.cs b/src/ImageSharp/Image/Image.LoadPixelData.cs index 2438d9eec8..00563e0ae5 100644 --- a/src/ImageSharp/Image/Image.LoadPixelData.cs +++ b/src/ImageSharp/Image/Image.LoadPixelData.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -69,7 +70,7 @@ namespace SixLabors.ImageSharp Guard.MustBeGreaterThanOrEqualTo(data.Length, count, nameof(data)); var image = new Image(config, width, height); - SpanHelper.Copy(data, image.Pixels, count); + SpanHelper.Copy(data, image.GetPixelSpan(), count); return image; } diff --git a/src/ImageSharp/Image/ImageBase{TPixel}.cs b/src/ImageSharp/Image/ImageBase{TPixel}.cs index 783d5d5646..9b243fda32 100644 --- a/src/ImageSharp/Image/ImageBase{TPixel}.cs +++ b/src/ImageSharp/Image/ImageBase{TPixel}.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; @@ -16,7 +17,7 @@ namespace SixLabors.ImageSharp /// images in different pixel formats. /// /// The pixel format. - public abstract class ImageBase : IImageBase + public abstract class ImageBase : IImageBase, IDisposable, IPixelSource where TPixel : struct, IPixel { #pragma warning disable SA1401 // Fields must be private @@ -92,11 +93,11 @@ namespace SixLabors.ImageSharp // Rent then copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here. this.RentPixels(); - other.Pixels.CopyTo(this.Pixels); + other.GetPixelSpan().CopyTo(this.GetPixelSpan()); } /// - public Span Pixels => new Span(this.PixelBuffer, 0, this.Width * this.Height); + Span IPixelSource.Span => new Span(this.PixelBuffer, 0, this.Width * this.Height); /// public int Width { get; private set; } @@ -139,37 +140,12 @@ namespace SixLabors.ImageSharp /// The y-coordinate of the pixel. Must be greater than or equal to zero and less than the height of the image. /// The at the specified position. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref TPixel GetPixelReference(int x, int y) + internal ref TPixel GetPixelReference(int x, int y) { this.CheckCoordinates(x, y); return ref this.PixelBuffer[(y * this.Width) + x]; } - /// - /// Gets a representing the row 'y' beginning from the the first pixel on that row. - /// - /// The y-coordinate of the pixel row. Must be greater than or equal to zero and less than the height of the image. - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Span GetRowSpan(int y) - { - this.CheckCoordinates(y); - return this.Pixels.Slice(y * this.Width, this.Width); - } - - /// - /// Gets a to the row 'y' beginning from the pixel at 'x'. - /// - /// The x coordinate (position in the row) - /// The y (row) coordinate - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Span GetRowSpan(int x, int y) - { - this.CheckCoordinates(x, y); - return this.Pixels.Slice((y * this.Width) + x, this.Width - x); - } - /// /// Clones the image /// @@ -210,7 +186,7 @@ namespace SixLabors.ImageSharp /// The target pixel buffer accessor. internal void CopyTo(PixelAccessor target) { - SpanHelper.Copy(this.Pixels, target.PixelBuffer.Span); + SpanHelper.Copy(this.GetPixelSpan(), target.PixelBuffer.Span); } /// diff --git a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs index 84d7d04450..90908529f5 100644 --- a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs +++ b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using Unsafe = System.Runtime.CompilerServices.Unsafe; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/Memory/SpanHelper.cs b/src/ImageSharp/Memory/SpanHelper.cs index 73bc5f55d8..8b9fad5222 100644 --- a/src/ImageSharp/Memory/SpanHelper.cs +++ b/src/ImageSharp/Memory/SpanHelper.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using Unsafe = System.Runtime.CompilerServices.Unsafe; namespace SixLabors.ImageSharp.Memory { diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs index 5fffb89360..b95f03b5d3 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -87,7 +88,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span row = source.GetRowSpan(y - startY); + Span row = source.GetPixelRowSpan(y - startY); for (int x = minX; x < maxX; x++) { diff --git a/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs index ec92993a35..107241d967 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -69,7 +70,7 @@ namespace SixLabors.ImageSharp.Processing.Processors for (int y = startY; y < endY; y++) { - Span row = source.GetRowSpan(y); + Span row = source.GetPixelRowSpan(y); for (int x = startX; x < endX; x++) { diff --git a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs index 27114be806..11efe3d07b 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs @@ -3,6 +3,7 @@ using System; using System.Buffers; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -78,7 +79,7 @@ namespace SixLabors.ImageSharp.Processing.Processors byte[] bytes = new byte[4]; for (int y = startY; y < endY; y++) { - Span row = source.GetRowSpan(y); + Span row = source.GetPixelRowSpan(y); for (int x = startX; x < endX; x++) { diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs index e93305cca1..5b6a168321 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -56,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span row = source.GetRowSpan(y - startY); + Span row = source.GetPixelRowSpan(y - startY); for (int x = minX; x < maxX; x++) { diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs index b13117a585..874feefa35 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -65,7 +66,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span sourceRow = source.GetRowSpan(y); + Span sourceRow = source.GetPixelRowSpan(y); Span targetRow = targetPixels.GetRowSpan(y); for (int x = startX; x < endX; x++) @@ -84,7 +85,7 @@ namespace SixLabors.ImageSharp.Processing.Processors int offsetY = y + fyr; offsetY = offsetY.Clamp(0, maxY); - Span sourceOffsetRow = source.GetRowSpan(offsetY); + Span sourceOffsetRow = source.GetPixelRowSpan(offsetY); for (int fx = 0; fx < kernelXWidth; fx++) { diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs index 9ffc04f055..14875b5022 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -54,7 +55,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span sourceRow = source.GetRowSpan(y); + Span sourceRow = source.GetPixelRowSpan(y); Span targetRow = targetPixels.GetRowSpan(y); for (int x = startX; x < endX; x++) @@ -70,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing.Processors int offsetY = y + fyr; offsetY = offsetY.Clamp(0, maxY); - Span sourceOffsetRow = source.GetRowSpan(offsetY); + Span sourceOffsetRow = source.GetPixelRowSpan(offsetY); for (int fx = 0; fx < kernelLength; fx++) { diff --git a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs index 97c0b6745d..008017268d 100644 --- a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -67,7 +68,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span row = source.GetRowSpan(y - startY); + Span row = source.GetPixelRowSpan(y - startY); for (int x = minX; x < maxX; x++) { diff --git a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs index d97d4534dc..deecc9c81d 100644 --- a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -82,7 +83,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span destination = source.GetRowSpan(y - startY).Slice(minX - startX, width); + Span destination = source.GetPixelRowSpan(y - startY).Slice(minX - startX, width); // This switched color & destination in the 2nd and 3rd places because we are applying the target colour under the current one blender.Blend(destination, colors, destination, amount); diff --git a/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs index 0aad1ef532..15071d9933 100644 --- a/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -67,7 +68,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span row = source.GetRowSpan(y - startY); + Span row = source.GetPixelRowSpan(y - startY); for (int x = minX; x < maxX; x++) { diff --git a/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs index 97159c8730..de3a199842 100644 --- a/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -69,7 +70,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span row = source.GetRowSpan(y - startY); + Span row = source.GetPixelRowSpan(y - startY); for (int x = minX; x < maxX; x++) { diff --git a/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs index 12692f2bd8..9d4f32390d 100644 --- a/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -48,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span row = source.GetRowSpan(y - startY); + Span row = source.GetPixelRowSpan(y - startY); for (int x = minX; x < maxX; x++) { diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs index 21c13634be..71469b7fce 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -74,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span sourceRow = source.GetRowSpan(y); + Span sourceRow = source.GetPixelRowSpan(y); Span targetRow = targetPixels.GetRowSpan(y); for (int x = startX; x < endX; x++) @@ -94,7 +95,7 @@ namespace SixLabors.ImageSharp.Processing.Processors offsetY = offsetY.Clamp(0, maxY); - Span sourceOffsetRow = source.GetRowSpan(offsetY); + Span sourceOffsetRow = source.GetPixelRowSpan(offsetY); for (int fx = 0; fx <= radius; fx++) { diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs index ce10915f29..bd34139868 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Common; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -84,7 +85,7 @@ namespace SixLabors.ImageSharp.Processing.Processors offsetPy--; } - Span row = source.GetRowSpan(offsetY + offsetPy); + Span row = source.GetPixelRowSpan(offsetY + offsetPy); for (int x = minX; x < maxX; x += size) { diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 725ad9eca3..f317994b87 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -104,7 +105,7 @@ namespace SixLabors.ImageSharp.Processing.Processors amounts[i] = (this.options.BlendPercentage * (1 - (.95F * (distance / maxDistance)))).Clamp(0, 1); } - Span destination = source.GetRowSpan(offsetY).Slice(offsetX, width); + Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); this.blender.Blend(destination, destination, rowColors, amounts); } diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index 4d9df46d81..92608ad5a8 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -125,7 +126,7 @@ namespace SixLabors.ImageSharp.Processing.Processors amounts[i] = (this.options.BlendPercentage * (.9F * (distance / maxDistance))).Clamp(0, 1); } - Span destination = source.GetRowSpan(offsetY).Slice(offsetX, width); + Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); this.blender.Blend(destination, destination, rowColors, amounts); } diff --git a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs index b4c4ca594b..f82c2553ad 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -51,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span sourceRow = source.GetRowSpan(minX, y); + Span sourceRow = source.GetPixelRowSpan(minX).Slice(y); Span targetRow = targetPixels.GetRowSpan(y - minY); SpanHelper.Copy(sourceRow, targetRow, maxX - minX); }); diff --git a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs index ba64392928..fa5ea5ed74 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -65,8 +66,8 @@ namespace SixLabors.ImageSharp.Processing.Processors y => { int newY = height - y - 1; - Span sourceRow = source.GetRowSpan(y); - Span altSourceRow = source.GetRowSpan(newY); + Span sourceRow = source.GetPixelRowSpan(y); + Span altSourceRow = source.GetPixelRowSpan(newY); Span targetRow = targetPixels.GetRowSpan(y); Span altTargetRow = targetPixels.GetRowSpan(newY); @@ -97,7 +98,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span sourceRow = source.GetRowSpan(y); + Span sourceRow = source.GetPixelRowSpan(y); Span targetRow = targetPixels.GetRowSpan(y); for (int x = 0; x < halfWidth; x++) diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index 4560da6e75..7a968e5607 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -73,7 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Processors if (source.Width == cloned.Width && source.Height == cloned.Height && sourceRectangle == this.ResizeRectangle) { // the cloned will be blank here copy all the pixel data over - source.Pixels.CopyTo(cloned.Pixels); + source.GetPixelSpan().CopyTo(cloned.GetPixelSpan()); return; } @@ -104,8 +105,8 @@ namespace SixLabors.ImageSharp.Processing.Processors y => { // Y coordinates of source points - Span sourceRow = source.GetRowSpan((int)(((y - startY) * heightFactor) + sourceY)); - Span targetRow = cloned.GetRowSpan(y); + Span sourceRow = source.GetPixelRowSpan((int)(((y - startY) * heightFactor) + sourceY)); + Span targetRow = cloned.GetPixelRowSpan(y); for (int x = minX; x < maxX; x++) { @@ -136,7 +137,7 @@ namespace SixLabors.ImageSharp.Processing.Processors using (var tempRowBuffer = new Buffer(source.Width)) { Span firstPassRow = firstPassPixels.GetRowSpan(y); - Span sourceRow = source.GetRowSpan(y); + Span sourceRow = source.GetPixelRowSpan(y); PixelOperations.Instance.ToVector4(sourceRow, tempRowBuffer, sourceRow.Length); if (this.Compand) @@ -167,7 +168,7 @@ namespace SixLabors.ImageSharp.Processing.Processors { // Ensure offsets are normalised for cropping and padding. WeightsWindow window = this.VerticalWeights.Weights[y - startY]; - Span targetRow = cloned.GetRowSpan(y); + Span targetRow = cloned.GetPixelRowSpan(y); if (this.Compand) { diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index 6e76834b91..209bcbe9c5 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -169,7 +170,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span sourceRow = source.GetRowSpan(y); + Span sourceRow = source.GetPixelRowSpan(y); Span targetRow = targetPixels.GetRowSpan(height - y - 1); for (int x = 0; x < width; x++) @@ -199,7 +200,7 @@ namespace SixLabors.ImageSharp.Processing.Processors source.Configuration.ParallelOptions, y => { - Span sourceRow = source.GetRowSpan(y); + Span sourceRow = source.GetPixelRowSpan(y); int newX = height - y - 1; for (int x = 0; x < width; x++) { diff --git a/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs index dc65442bbc..c873664833 100644 --- a/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Quantizers.Base; @@ -77,7 +78,7 @@ namespace SixLabors.ImageSharp.Quantizers for (int y = 0; y < height; y++) { - Span row = source.GetRowSpan(y); + Span row = source.GetPixelRowSpan(y); // And loop through each column for (int x = 0; x < width; x++) diff --git a/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs index b03e690e4d..056c5f38df 100644 --- a/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Quantizers.Base; @@ -73,7 +74,7 @@ namespace SixLabors.ImageSharp.Quantizers for (int y = 0; y < height; y++) { - Span row = source.GetRowSpan(y); + Span row = source.GetPixelRowSpan(y); // And loop through each column for (int x = 0; x < width; x++) diff --git a/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs b/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs index 2bd7267921..290f46b166 100644 --- a/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs +++ b/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; @@ -92,7 +93,7 @@ namespace SixLabors.ImageSharp.Quantizers.Base // Loop through each row for (int y = 0; y < height; y++) { - Span row = source.GetRowSpan(y); + Span row = source.GetPixelRowSpan(y); // And loop through each column for (int x = 0; x < width; x++) diff --git a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs index 79319cfbd7..62ba52dc48 100644 --- a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs @@ -6,6 +6,7 @@ using System.Buffers; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Quantizers.Base; @@ -251,7 +252,7 @@ namespace SixLabors.ImageSharp.Quantizers for (int y = 0; y < height; y++) { - Span row = source.GetRowSpan(y); + Span row = source.GetPixelRowSpan(y); // And loop through each column for (int x = 0; x < width; x++) diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index 7569d56f23..4f7eca5490 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image using System.Threading.Tasks; using BenchmarkDotNet.Attributes; - + using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; public class CopyPixels : BenchmarkBase @@ -103,8 +103,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Image Configuration.Default.ParallelOptions, y => { - Span sourceRow = source.GetRowSpan(y); - Span targetRow = target.GetRowSpan(y); + Span sourceRow = source.GetPixelRowSpan(y); + Span targetRow = target.GetPixelRowSpan(y); for (int x = 0; x < source.Width; x++) { diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs index 1f58b0a3b4..aa691aa6d0 100644 --- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs @@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.IO; using Moq; using Xunit; +using SixLabors.ImageSharp.Advanced.Unsafe; namespace SixLabors.ImageSharp.Tests { @@ -324,7 +325,7 @@ namespace SixLabors.ImageSharp.Tests using (Image img = image1Provider.GetImage()) { - Assert.Equal(166036, img.Pixels.Length); + Assert.Equal(166036, img.GetPixelSpan().Length); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs index ced24f596b..2ac6047464 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; @@ -31,9 +32,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix { image.Mutate(x => x.Grayscale(value)); byte[] data = new byte[3]; - for (int i = 0; i < image.Pixels.Length; i++) + for (int i = 0; i < image.GetPixelSpan().Length; i++) { - image.Pixels[i].ToXyzBytes(data, 0); + image.GetPixelSpan()[i].ToXyzBytes(data, 0); Assert.Equal(data[0], data[1]); Assert.Equal(data[1], data[2]); } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs index cb87b9e907..090f36614a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs @@ -2,7 +2,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison { using System; using System.Collections.Generic; - + using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -31,8 +31,8 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison for (int y = 0; y < actual.Height; y++) { - Span aSpan = expected.GetRowSpan(y); - Span bSpan = actual.GetRowSpan(y); + Span aSpan = expected.GetPixelRowSpan(y); + Span bSpan = actual.GetPixelRowSpan(y); PixelOperations.Instance.ToRgba32(aSpan, aBuffer, width); PixelOperations.Instance.ToRgba32(bSpan, bBuffer, width); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index 48335945c6..cb0381afba 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; + using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -64,8 +65,8 @@ for (int y = 0; y < actual.Height; y++) { - Span aSpan = expected.GetRowSpan(y); - Span bSpan = actual.GetRowSpan(y); + Span aSpan = expected.GetPixelRowSpan(y); + Span bSpan = actual.GetPixelRowSpan(y); PixelOperations.Instance.ToRgba32(aSpan, aBuffer, width); PixelOperations.Instance.ToRgba32(bSpan, bBuffer, width); diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index 758be0c36b..69a5420bea 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -4,6 +4,7 @@ using System; using System.Drawing.Imaging; +using SixLabors.ImageSharp.Advanced.Unsafe; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -100,7 +101,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs var destPtr = (Argb32*)workBuffer.Pin(); for (int y = 0; y < h; y++) { - Span row = image.GetRowSpan(y); + Span row = image.GetPixelRowSpan(y); byte* sourcePtr = sourcePtrBase + data.Stride * y; @@ -142,7 +143,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs var destPtr = (Rgb24*)workBuffer.Pin(); for (int y = 0; y < h; y++) { - Span row = image.GetRowSpan(y); + Span row = image.GetPixelRowSpan(y); byte* sourcePtr = sourcePtrBase + data.Stride * y; @@ -175,7 +176,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs for (int y = 0; y < h; y++) { - Span row = image.GetRowSpan(y); + Span row = image.GetPixelRowSpan(y); ToArgb32(row, workBuffer); byte* destPtr = destPtrBase + data.Stride * y;