From ed20a807d6420c9a63720c5bb6d037770e6f033f Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 6 Sep 2017 18:46:18 +0100 Subject: [PATCH] exlusivly use frames to access pixel spans --- src/ImageSharp/Advanced/IPixelSource.cs | 24 ++++++++++++++ src/ImageSharp/Advanced/ImageExtensions.cs | 33 ++++++++----------- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 4 +-- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 4 +-- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 2 +- .../Common/Decoder/JpegImagePostProcessor.cs | 6 ++-- .../Jpeg/GolangPort/OrigJpegDecoderCore.cs | 2 +- .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 14 ++++---- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 10 +++--- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 6 ++-- src/ImageSharp/Image/IImageFrame.cs | 13 -------- src/ImageSharp/Image/Image.LoadPixelData.cs | 2 +- src/ImageSharp/Image/ImageExtensions.cs | 11 ++----- src/ImageSharp/Image/ImageFrame{TPixel}.cs | 4 +-- src/ImageSharp/Image/Image{TPixel}.cs | 21 +++++------- .../Image/PixelAccessorExtensions.cs | 20 ++++++++++- src/ImageSharp/Image/PixelAccessor{TPixel}.cs | 8 ++--- .../ImageSharp.Benchmarks/Image/CopyPixels.cs | 4 +-- .../Jpg/JpegImagePostProcessorTests.cs | 6 ++-- .../ImageSharp.Tests/Image/ImageLoadTests.cs | 2 +- .../Processors/ColorMatrix/GrayscaleTest.cs | 5 +-- .../ReferenceCodecs/SystemDrawingBridge.cs | 6 ++-- .../TestUtilities/TestImageExtensions.cs | 2 +- 23 files changed, 111 insertions(+), 98 deletions(-) create mode 100644 src/ImageSharp/Advanced/IPixelSource.cs diff --git a/src/ImageSharp/Advanced/IPixelSource.cs b/src/ImageSharp/Advanced/IPixelSource.cs new file mode 100644 index 0000000000..c9edf118c6 --- /dev/null +++ b/src/ImageSharp/Advanced/IPixelSource.cs @@ -0,0 +1,24 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.MetaData; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Advanced +{ + /// + /// Encapsulates the basic properties and methods required to manipulate images. + /// + /// The type of the pixel. + internal interface IPixelSource + where TPixel : struct, IPixel + { + /// + /// Gets the pixel buffer. + /// + Buffer2D PixelBuffer { get; } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Advanced/ImageExtensions.cs b/src/ImageSharp/Advanced/ImageExtensions.cs index d3d563fae2..fdfbd923a6 100644 --- a/src/ImageSharp/Advanced/ImageExtensions.cs +++ b/src/ImageSharp/Advanced/ImageExtensions.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -26,16 +27,6 @@ namespace SixLabors.ImageSharp.Advanced where TPixel : struct, IPixel => GetSpan(source); - /// - /// 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 Image source) - where TPixel : struct, IPixel - => GetSpan(source); - /// /// Gets a representing the row 'y' beginning from the the first pixel on that row. /// @@ -48,25 +39,27 @@ namespace SixLabors.ImageSharp.Advanced => GetSpan(source, row); /// - /// Gets a representing the row 'y' beginning from the the first pixel on that row. + /// Gets the span. /// /// The type of the pixel. /// The source. - /// The row. - /// The - public static Span GetPixelRowSpan(this Image source, int row) + /// The span retuned from Pixel source + private static Span GetSpan(IPixelSource source) where TPixel : struct, IPixel - => GetSpan(source, row); + => source.PixelBuffer.Span; /// /// Gets the span. /// /// The type of the pixel. /// The source. - /// The span retuned from Pixel source - private static Span GetSpan(IImageFrame source) + /// The row. + /// + /// The span retuned from Pixel source + /// + private static Span GetSpan(IPixelSource source, int row) where TPixel : struct, IPixel - => source.PixelBuffer.Span; + => GetSpan(source.PixelBuffer, row); /// /// Gets the span. @@ -77,9 +70,9 @@ namespace SixLabors.ImageSharp.Advanced /// /// The span retuned from Pixel source /// - private static Span GetSpan(IImageFrame source, int row) + private static Span GetSpan(Buffer2D source, int row) where TPixel : struct, IPixel - => source.PixelBuffer.Span.Slice(row * source.Width, source.Width); + => source.Span.Slice(row * source.Width, source.Width); /// /// Gets the bounds of the image. diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 6ac1243620..d34d170847 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp WriteHeader(writer, fileHeader); this.WriteInfo(writer, infoHeader); - this.WriteImage(writer, image); + this.WriteImage(writer, image.Frames.RootFrame); writer.Flush(); } @@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp /// /// The containing pixel data. /// - private void WriteImage(EndianBinaryWriter writer, IImageFrame image) + private void WriteImage(EndianBinaryWriter writer, ImageFrame image) where TPixel : struct, IPixel { using (PixelAccessor pixels = image.Lock()) diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 8666dca7ae..c3c395e852 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -378,7 +378,7 @@ namespace SixLabors.ImageSharp.Formats.Gif this.SetFrameMetaData(this.metaData); - image = (ImageFrame)this.image; + image = this.image.Frames.RootFrame; } else { @@ -471,7 +471,7 @@ namespace SixLabors.ImageSharp.Formats.Gif return; } - this.previousFrame = currentFrame == null ? this.image : currentFrame; + this.previousFrame = currentFrame == null ? this.image.Frames.RootFrame : currentFrame; if (this.graphicsControlExtension != null && this.graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToBackground) diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 7b12b95b14..3da43967fe 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp.Formats.Gif ditheredQuantizer.Dither = !this.hasFrames; // Quantize the image returning a palette. - QuantizedImage quantized = ditheredQuantizer.Quantize(image, paletteSize); + QuantizedImage quantized = ditheredQuantizer.Quantize(image.Frames.RootFrame, paletteSize); int index = this.GetTransparentIndex(quantized); diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs index e3ca1d74c2..84867d2766 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs @@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder /// /// The pixel type /// The destination image - public void PostProcess(Image destination) + public void PostProcess(ImageFrame destination) where TPixel : struct, IPixel { this.PixelRowCounter = 0; @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder /// /// The pixel type /// The destination image. - public void DoPostProcessorStep(Image destination) + public void DoPostProcessorStep(ImageFrame destination) where TPixel : struct, IPixel { foreach (JpegComponentPostProcessor cpp in this.ComponentProcessors) @@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder /// /// The pixel type /// The destination image - private void ConvertColorsInto(Image destination) + private void ConvertColorsInto(ImageFrame destination) where TPixel : struct, IPixel { int maxY = Math.Min(destination.Height, this.PixelRowCounter + PixelRowsPerStep); diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs index 33ebe72d01..8369e92366 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs @@ -815,7 +815,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort using (var postProcessor = new JpegImagePostProcessor(this)) { var image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData); - postProcessor.PostProcess(image); + postProcessor.PostProcess(image.Frames.RootFrame); return image; } } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index c5225b5467..6c84597c99 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort this.QuantizeAndInverseAllComponents(); var image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, metadata); - this.FillPixelData(image); + this.FillPixelData(image.Frames.RootFrame); this.AssignResolution(image); return image; } @@ -326,7 +326,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort /// /// The pixel format. /// The image - private void FillPixelData(Image image) + private void FillPixelData(ImageFrame image) where TPixel : struct, IPixel { if (this.NumberOfComponents > 4) @@ -856,7 +856,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void FillGrayScaleImage(Image image) + private void FillGrayScaleImage(ImageFrame image) where TPixel : struct, IPixel { for (int y = 0; y < image.Height; y++) @@ -875,7 +875,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void FillYCbCrImage(Image image) + private void FillYCbCrImage(ImageFrame image) where TPixel : struct, IPixel { for (int y = 0; y < image.Height; y++) @@ -894,7 +894,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void FillYcckImage(Image image) + private void FillYcckImage(ImageFrame image) where TPixel : struct, IPixel { for (int y = 0; y < image.Height; y++) @@ -915,7 +915,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void FillCmykImage(Image image) + private void FillCmykImage(ImageFrame image) where TPixel : struct, IPixel { for (int y = 0; y < image.Height; y++) @@ -941,7 +941,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void FillRgbImage(Image image) + private void FillRgbImage(ImageFrame image) where TPixel : struct, IPixel { for (int y = 0; y < image.Height; y++) diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 48618c5eee..4fd57c2784 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -236,7 +236,7 @@ namespace SixLabors.ImageSharp.Formats.Png } deframeStream.AllocateNewBytes(currentChunk.Length); - this.ReadScanlines(deframeStream.CompressedStream, image); + this.ReadScanlines(deframeStream.CompressedStream, image.Frames.RootFrame); stream.Read(this.crcBuffer, 0, 4); break; case PngChunkTypes.Palette: @@ -442,7 +442,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// The pixel format. /// The containing data. /// The pixel data. - private void ReadScanlines(Stream dataStream, Image image) + private void ReadScanlines(Stream dataStream, ImageFrame image) where TPixel : struct, IPixel { if (this.header.InterlaceMethod == PngInterlaceMode.Adam7) @@ -461,7 +461,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// The pixel format. /// The compressed pixel data stream. /// The image to decode to. - private void DecodePixelData(Stream compressedStream, Image image) + private void DecodePixelData(Stream compressedStream, ImageFrame image) where TPixel : struct, IPixel { while (this.currentRow < this.header.Height) @@ -519,7 +519,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// The pixel format. /// The compressed pixel data stream. /// The current image. - private void DecodeInterlacedPixelData(Stream compressedStream, Image image) + private void DecodeInterlacedPixelData(Stream compressedStream, ImageFrame image) where TPixel : struct, IPixel { while (true) @@ -609,7 +609,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// The pixel format. /// The de-filtered scanline /// The image - private void ProcessDefilteredScanline(byte[] defilteredScanline, Image pixels) + private void ProcessDefilteredScanline(byte[] defilteredScanline, ImageFrame pixels) where TPixel : struct, IPixel { var color = default(TPixel); diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 6ca27d5333..660c371873 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -233,12 +233,12 @@ namespace SixLabors.ImageSharp.Formats.Png // Collect the indexed pixel data if (this.pngColorType == PngColorType.Palette) { - this.CollectIndexedBytes(image, stream, header); + this.CollectIndexedBytes(image.Frames.RootFrame, stream, header); } this.WritePhysicalChunk(stream, image); this.WriteGammaChunk(stream); - this.WriteDataChunks(image, stream); + this.WriteDataChunks(image.Frames.RootFrame, stream); this.WriteEndChunk(stream); stream.Flush(); } @@ -649,7 +649,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// The pixel format. /// The image. /// The stream. - private void WriteDataChunks(Image pixels, Stream stream) + private void WriteDataChunks(ImageFrame pixels, Stream stream) where TPixel : struct, IPixel { this.bytesPerScanline = this.width * this.bytesPerPixel; diff --git a/src/ImageSharp/Image/IImageFrame.cs b/src/ImageSharp/Image/IImageFrame.cs index 803f8a8695..a495b5ed8c 100644 --- a/src/ImageSharp/Image/IImageFrame.cs +++ b/src/ImageSharp/Image/IImageFrame.cs @@ -9,19 +9,6 @@ using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp { - /// - /// Encapsulates the basic properties and methods required to manipulate images. - /// - /// The type of the pixel. - internal interface IImageFrame : IImageFrame - where TPixel : struct, IPixel - { - /// - /// Gets the pixel buffer. - /// - Buffer2D PixelBuffer { get; } - } - /// /// Encapsulates the basic properties and methods required to manipulate images. /// diff --git a/src/ImageSharp/Image/Image.LoadPixelData.cs b/src/ImageSharp/Image/Image.LoadPixelData.cs index 6302eb66be..87edf0bc8c 100644 --- a/src/ImageSharp/Image/Image.LoadPixelData.cs +++ b/src/ImageSharp/Image/Image.LoadPixelData.cs @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp Guard.MustBeGreaterThanOrEqualTo(data.Length, count, nameof(data)); var image = new Image(config, width, height); - SpanHelper.Copy(data, image.GetPixelSpan(), count); + SpanHelper.Copy(data, image.Frames.RootFrame.GetPixelSpan(), count); return image; } diff --git a/src/ImageSharp/Image/ImageExtensions.cs b/src/ImageSharp/Image/ImageExtensions.cs index 8e78de0563..d1798abf3e 100644 --- a/src/ImageSharp/Image/ImageExtensions.cs +++ b/src/ImageSharp/Image/ImageExtensions.cs @@ -158,7 +158,7 @@ namespace SixLabors.ImageSharp /// Thrown if the stream is null. public static byte[] SavePixelData(this Image source) where TPixel : struct, IPixel - => source.GetPixelSpan().AsBytes().ToArray(); + => source.Frames.RootFrame.SavePixelData(); /// /// Saves the raw image to the given bytes. @@ -169,7 +169,7 @@ namespace SixLabors.ImageSharp /// Thrown if the stream is null. public static void SavePixelData(this Image source, byte[] buffer) where TPixel : struct, IPixel - => SavePixelData(source, new Span(buffer)); + => source.Frames.RootFrame.SavePixelData(buffer); /// /// Saves the raw image to the given bytes. @@ -180,12 +180,7 @@ namespace SixLabors.ImageSharp /// Thrown if the stream is null. public static void SavePixelData(this Image source, Span buffer) where TPixel : struct, IPixel - { - Span byteBuffer = source.GetPixelSpan().AsBytes(); - Guard.MustBeGreaterThanOrEqualTo(buffer.Length, byteBuffer.Length, nameof(buffer)); - - byteBuffer.CopyTo(buffer); - } + => source.Frames.RootFrame.SavePixelData(buffer); /// /// Returns a Base64 encoded string from the given image. diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs index 063108515b..a8cf640e20 100644 --- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp /// Represents a single frame in a animation. /// /// The pixel format. - public sealed class ImageFrame : IImageFrame + public sealed class ImageFrame : IImageFrame, IPixelSource where TPixel : struct, IPixel { /// @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp } /// - Buffer2D IImageFrame.PixelBuffer => this.pixelBuffer; + Buffer2D IPixelSource.PixelBuffer => this.pixelBuffer; /// public int Width => this.pixelBuffer.Width; diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index 1b8f8ec28d..f7ecae375a 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -1,10 +1,11 @@ // 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.Linq; - +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; @@ -16,7 +17,7 @@ namespace SixLabors.ImageSharp /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. /// /// The pixel format. - public sealed partial class Image : IImageFrame + public sealed partial class Image : IDisposable where TPixel : struct, IPixel { /// @@ -100,12 +101,12 @@ namespace SixLabors.ImageSharp /// /// Gets the width. /// - public int Width => this.RootFrame?.Width ?? 0; + public int Width => this.Frames.RootFrame.Width; /// /// Gets the height. /// - public int Height => this.RootFrame?.Height ?? 0; + public int Height => this.Frames.RootFrame.Height; /// /// Gets the meta data of the image. @@ -120,13 +121,7 @@ namespace SixLabors.ImageSharp /// /// Gets the root frame. /// - private IImageFrame RootFrame => this.Frames?.RootFrame; - - /// - Buffer2D IImageFrame.PixelBuffer => this.RootFrame.PixelBuffer; - - /// - ImageFrameMetaData IImageFrame.MetaData => this.RootFrame.MetaData; + private IPixelSource PixelSource => this.Frames?.RootFrame; /// /// Gets or sets the pixel at the specified position. @@ -136,9 +131,9 @@ namespace SixLabors.ImageSharp /// The at the specified position. public TPixel this[int x, int y] { - get => this.RootFrame.PixelBuffer[x, y]; + get => this.PixelSource.PixelBuffer[x, y]; - set => this.RootFrame.PixelBuffer[x, y] = value; + set => this.PixelSource.PixelBuffer[x, y] = value; } /// diff --git a/src/ImageSharp/Image/PixelAccessorExtensions.cs b/src/ImageSharp/Image/PixelAccessorExtensions.cs index 3c90a55c99..9146ef48da 100644 --- a/src/ImageSharp/Image/PixelAccessorExtensions.cs +++ b/src/ImageSharp/Image/PixelAccessorExtensions.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using Unsafe = System.Runtime.CompilerServices.Unsafe; @@ -27,10 +28,27 @@ namespace SixLabors.ImageSharp /// /// The /// - internal static PixelAccessor Lock(this IImageFrame frame) + internal static PixelAccessor Lock(this IPixelSource frame) where TPixel : struct, IPixel { return new PixelAccessor(frame); } + + /// + /// Locks the image providing access to the pixels. + /// + /// It is imperative that the accessor is correctly disposed off after use. + /// + /// + /// The type of the pixel. + /// The image. + /// + /// The + /// + internal static PixelAccessor Lock(this Image image) + where TPixel : struct, IPixel + { + return image.Frames.RootFrame.Lock(); + } } } \ No newline at end of file diff --git a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs index 0de76cbd13..3abe28aca0 100644 --- a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs +++ b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs @@ -4,7 +4,7 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; - +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using Unsafe = System.Runtime.CompilerServices.Unsafe; @@ -41,11 +41,11 @@ namespace SixLabors.ImageSharp /// Initializes a new instance of the class. /// /// The image to provide pixel access for. - public PixelAccessor(IImageFrame image) + public PixelAccessor(IPixelSource image) { Guard.NotNull(image, nameof(image)); - Guard.MustBeGreaterThan(image.Width, 0, "image width"); - Guard.MustBeGreaterThan(image.Height, 0, "image height"); + Guard.MustBeGreaterThan(image.PixelBuffer.Width, 0, "image width"); + Guard.MustBeGreaterThan(image.PixelBuffer.Height, 0, "image height"); this.SetPixelBufferUnsafe(image.PixelBuffer, false); } diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index b3f53949d1..674aef84c1 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -103,8 +103,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Image Configuration.Default.ParallelOptions, y => { - Span sourceRow = source.GetPixelRowSpan(y); - Span targetRow = target.GetPixelRowSpan(y); + Span sourceRow = source.Frames.RootFrame.GetPixelRowSpan(y); + Span targetRow = target.Frames.RootFrame.GetPixelRowSpan(y); for (int x = 0; x < source.Width; x++) { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs index 871321df9d..df6d1ef1bb 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs @@ -56,9 +56,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg string imageFile = provider.SourceFileOrDescription; using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile)) using (var pp = new JpegImagePostProcessor(decoder)) - using (var image = new Image(decoder.ImageWidth, decoder.ImageHeight)) + using (var imageFrame = new ImageFrame(decoder.ImageWidth, decoder.ImageHeight)) { - pp.DoPostProcessorStep(image); + pp.DoPostProcessorStep(imageFrame); JpegComponentPostProcessor[] cp = pp.ComponentProcessors; @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg using (var pp = new JpegImagePostProcessor(decoder)) using (var image = new Image(decoder.ImageWidth, decoder.ImageHeight)) { - pp.PostProcess(image); + pp.PostProcess(image.Frames.RootFrame); image.DebugSave(provider); diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs index cf5e484cfe..f61c73636e 100644 --- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs @@ -326,7 +326,7 @@ namespace SixLabors.ImageSharp.Tests using (Image img = image1Provider.GetImage()) { - Assert.Equal(166036, img.GetPixelSpan().Length); + Assert.Equal(166036, img.Frames.RootFrame.GetPixelSpan().Length); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs index 31ddd14f8a..fe003da32b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs @@ -32,9 +32,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix { image.Mutate(x => x.Grayscale(value)); byte[] data = new byte[3]; - for (int i = 0; i < image.GetPixelSpan().Length; i++) + System.Span span = image.Frames.RootFrame.GetPixelSpan(); + for (int i = 0; i < span.Length; i++) { - image.GetPixelSpan()[i].ToXyzBytes(data, 0); + span[i].ToXyzBytes(data, 0); Assert.Equal(data[0], data[1]); Assert.Equal(data[1], data[2]); } diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index 5fedaa124e..a201b39bd2 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs var destPtr = (Argb32*)workBuffer.Pin(); for (int y = 0; y < h; y++) { - Span row = image.GetPixelRowSpan(y); + Span row = image.Frames.RootFrame.GetPixelRowSpan(y); byte* sourcePtr = sourcePtrBase + data.Stride * y; @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs var destPtr = (Rgb24*)workBuffer.Pin(); for (int y = 0; y < h; y++) { - Span row = image.GetPixelRowSpan(y); + Span row = image.Frames.RootFrame.GetPixelRowSpan(y); byte* sourcePtr = sourcePtrBase + data.Stride * y; @@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs for (int y = 0; y < h; y++) { - Span row = image.GetPixelRowSpan(y); + Span row = image.Frames.RootFrame.GetPixelRowSpan(y); ToArgb32(row, workBuffer); byte* destPtr = destPtrBase + data.Stride * y; diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index b79165f950..b3dd763c7f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -196,7 +196,7 @@ namespace SixLabors.ImageSharp.Tests { var image = new Image(buffer.Width, buffer.Height); - Span pixels = image.GetPixelSpan(); + Span pixels = image.Frames.RootFrame.GetPixelSpan(); for (int i = 0; i < buffer.Length; i++) {