From 0afea0f9d66a2e85b3173d9d66010aea0f671cc5 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Fri, 15 Sep 2017 19:18:41 +0100 Subject: [PATCH] rename api to DangerousGetPinnableReferenceToPixelBuffer --- src/ImageSharp/Advanced/ImageExtensions.cs | 33 ++++++++++------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/ImageSharp/Advanced/ImageExtensions.cs b/src/ImageSharp/Advanced/ImageExtensions.cs index fa299f8111..63a66de832 100644 --- a/src/ImageSharp/Advanced/ImageExtensions.cs +++ b/src/ImageSharp/Advanced/ImageExtensions.cs @@ -13,26 +13,24 @@ namespace SixLabors.ImageSharp.Advanced internal static class ImageExtensions { /// - /// Gets a reference to the pixel at the specified position. + /// Returns a reference to the 0th element of the Pixel buffer. + /// Such a reference can be used for pinning but must never be dereferenced. /// /// The source image frame - /// The x coordinate (row) - /// The y coordinate (position at row) - /// A reference to the element. - public static ref TPixel GetPixelReference(this ImageFrame source, int x, int y) + /// A pinnable reference the first root of the pixel buffer. + public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this ImageFrame source) where TPixel : struct, IPixel - => ref GetPixelReference((IPixelSource)source, x, y); + => ref DangerousGetPinnableReferenceToPixelBuffer((IPixelSource)source); /// - /// Gets a reference to the pixel at the specified position. + /// Returns a reference to the 0th element of the Pixel buffer. + /// Such a reference can be used for pinning but must never be dereferenced. /// - /// The source image frame - /// The x coordinate (row) - /// The y coordinate (position at row) - /// A reference to the element. - public static ref TPixel GetPixelReference(this Image source, int x, int y) + /// The source image + /// A pinnable reference the first root of the pixel buffer. + public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this Image source) where TPixel : struct, IPixel - => ref source.Frames.RootFrame.GetPixelReference(x, y); + => ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer(); /// /// Gets the representation of the pixels as an area of contiguous memory in the given pixel format. @@ -131,14 +129,13 @@ namespace SixLabors.ImageSharp.Advanced => source?.Configuration ?? Configuration.Default; /// - /// Gets a reference to the pixel at the specified position. + /// Returns a reference to the 0th element of the Pixel buffer. + /// Such a reference can be used for pinning but must never be dereferenced. /// /// The source image frame - /// The x coordinate (row) - /// The y coordinate (position at row) /// A reference to the element. - private static ref TPixel GetPixelReference(IPixelSource source, int x, int y) + private static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(IPixelSource source) where TPixel : struct, IPixel - => ref source.PixelBuffer[x, y]; + => ref source.PixelBuffer.Span.DangerousGetPinnableReference(); } }