Browse Source

Expose advanced pixel reference API.

af/merge-core
Scott Williams 9 years ago
parent
commit
eafbcb4fd7
  1. 44
      src/ImageSharp/Advanced/ImageExtensions.cs

44
src/ImageSharp/Advanced/ImageExtensions.cs

@ -12,13 +12,35 @@ namespace SixLabors.ImageSharp.Advanced
/// </summary> /// </summary>
internal static class ImageExtensions internal static class ImageExtensions
{ {
/// <summary>
/// Gets a reference to the pixel at the specified position.
/// </summary>
/// <param name="source">The source image frame</param>
/// <param name="x">The x coordinate (row)</param>
/// <param name="y">The y coordinate (position at row)</param>
/// <returns>A reference to the element.</returns>
public static ref TPixel GetPixelReference<TPixel>(this ImageFrame<TPixel> source, int x, int y)
where TPixel : struct, IPixel<TPixel>
=> ref GetPixelReference((IPixelSource<TPixel>)source, x, y);
/// <summary>
/// Gets a reference to the pixel at the specified position.
/// </summary>
/// <param name="source">The source image frame</param>
/// <param name="x">The x coordinate (row)</param>
/// <param name="y">The y coordinate (position at row)</param>
/// <returns>A reference to the element.</returns>
public static ref TPixel GetPixelReference<TPixel>(this Image<TPixel> source, int x, int y)
where TPixel : struct, IPixel<TPixel>
=> ref source.Frames.RootFrame.GetPixelReference(x, y);
/// <summary> /// <summary>
/// Gets the representation of the pixels as an area of contiguous memory in the given pixel format. /// Gets the representation of the pixels as an area of contiguous memory in the given pixel format.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the pixel.</typeparam> /// <typeparam name="TPixel">The type of the pixel.</typeparam>
/// <param name="source">The source.</param> /// <param name="source">The source.</param>
/// <returns>The <see cref="Span{TPixel}"/></returns> /// <returns>The <see cref="Span{TPixel}"/></returns>
public static Span<TPixel> GetPixelSpan<TPixel>(this ImageFrame<TPixel> source) internal static Span<TPixel> GetPixelSpan<TPixel>(this ImageFrame<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> GetSpan(source); => GetSpan(source);
@ -29,7 +51,7 @@ namespace SixLabors.ImageSharp.Advanced
/// <param name="source">The source.</param> /// <param name="source">The source.</param>
/// <param name="row">The row.</param> /// <param name="row">The row.</param>
/// <returns>The <see cref="Span{TPixel}"/></returns> /// <returns>The <see cref="Span{TPixel}"/></returns>
public static Span<TPixel> GetPixelRowSpan<TPixel>(this ImageFrame<TPixel> source, int row) internal static Span<TPixel> GetPixelRowSpan<TPixel>(this ImageFrame<TPixel> source, int row)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> GetSpan(source, row); => GetSpan(source, row);
@ -39,7 +61,7 @@ namespace SixLabors.ImageSharp.Advanced
/// <typeparam name="TPixel">The type of the pixel.</typeparam> /// <typeparam name="TPixel">The type of the pixel.</typeparam>
/// <param name="source">The source.</param> /// <param name="source">The source.</param>
/// <returns>The <see cref="Span{TPixel}"/></returns> /// <returns>The <see cref="Span{TPixel}"/></returns>
public static Span<TPixel> GetPixelSpan<TPixel>(this Image<TPixel> source) internal static Span<TPixel> GetPixelSpan<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.Frames.RootFrame.GetPixelSpan(); => source.Frames.RootFrame.GetPixelSpan();
@ -50,7 +72,7 @@ namespace SixLabors.ImageSharp.Advanced
/// <param name="source">The source.</param> /// <param name="source">The source.</param>
/// <param name="row">The row.</param> /// <param name="row">The row.</param>
/// <returns>The <see cref="Span{TPixel}"/></returns> /// <returns>The <see cref="Span{TPixel}"/></returns>
public static Span<TPixel> GetPixelRowSpan<TPixel>(this Image<TPixel> source, int row) internal static Span<TPixel> GetPixelRowSpan<TPixel>(this Image<TPixel> source, int row)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.Frames.RootFrame.GetPixelRowSpan(row); => source.Frames.RootFrame.GetPixelRowSpan(row);
@ -60,7 +82,7 @@ namespace SixLabors.ImageSharp.Advanced
/// <typeparam name="TPixel">The Pixel format.</typeparam> /// <typeparam name="TPixel">The Pixel format.</typeparam>
/// <param name="source">The source image</param> /// <param name="source">The source image</param>
/// <returns>Returns the configuration.</returns> /// <returns>Returns the configuration.</returns>
public static Configuration GetConfiguration<TPixel>(this Image<TPixel> source) internal static Configuration GetConfiguration<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> GetConfiguration((IConfigurable)source); => GetConfiguration((IConfigurable)source);
@ -107,5 +129,17 @@ namespace SixLabors.ImageSharp.Advanced
/// <returns>Returns the bounds of the image</returns> /// <returns>Returns the bounds of the image</returns>
private static Configuration GetConfiguration(IConfigurable source) private static Configuration GetConfiguration(IConfigurable source)
=> source?.Configuration ?? Configuration.Default; => source?.Configuration ?? Configuration.Default;
/// <summary>
/// Gets a reference to the pixel at the specified position.
/// </summary>
/// <param name="source">The source image frame</param>
/// <param name="x">The x coordinate (row)</param>
/// <param name="y">The y coordinate (position at row)</param>
/// <returns>A reference to the element.</returns>
private static ref TPixel GetPixelReference<TPixel>(IPixelSource<TPixel> source, int x, int y)
where TPixel : struct, IPixel<TPixel>
=> ref source.PixelBuffer[x, y];
} }
} }

Loading…
Cancel
Save