|
|
|
@ -5,10 +5,13 @@ |
|
|
|
|
|
|
|
namespace ImageSharp |
|
|
|
{ |
|
|
|
using System; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
|
|
|
|
using ImageSharp.PixelFormats; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Extension methods for the <see cref="byte"/> struct.
|
|
|
|
/// Extension methods for the <see cref="byte"/> struct buffers.
|
|
|
|
/// </summary>
|
|
|
|
internal static class ByteExtensions |
|
|
|
{ |
|
|
|
@ -44,5 +47,45 @@ namespace ImageSharp |
|
|
|
j--; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a reference to the given position of the array unsafe casted to <see cref="ImageSharp.PixelFormats.Rgb24"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="bytes">The byte array.</param>
|
|
|
|
/// <param name="offset">The offset in bytes.</param>
|
|
|
|
/// <returns>The <see cref="ImageSharp.PixelFormats.Rgb24"/> reference at the given offset.</returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static ref Rgb24 GetRgb24(this byte[] bytes, int offset) |
|
|
|
{ |
|
|
|
DebugGuard.MustBeLessThan(offset + 2, bytes.Length, nameof(offset)); |
|
|
|
|
|
|
|
return ref Unsafe.As<byte, Rgb24>(ref bytes[offset]); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a reference to the given position of the span unsafe casted to <see cref="ImageSharp.PixelFormats.Rgb24"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="bytes">The byte span.</param>
|
|
|
|
/// <param name="offset">The offset in bytes.</param>
|
|
|
|
/// <returns>The <see cref="ImageSharp.PixelFormats.Rgb24"/> reference at the given offset.</returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static ref Rgb24 GetRgb24(this Span<byte> bytes, int offset) |
|
|
|
{ |
|
|
|
DebugGuard.MustBeLessThan(offset + 2, bytes.Length, nameof(offset)); |
|
|
|
|
|
|
|
return ref Unsafe.As<byte, Rgb24>(ref bytes[offset]); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a reference to the given position of the buffer pointed by `baseRef` unsafe casted to <see cref="ImageSharp.PixelFormats.Rgb24"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="baseRef">A reference to the beginning of the buffer</param>
|
|
|
|
/// <param name="offset">The offset in bytes.</param>
|
|
|
|
/// <returns>The <see cref="ImageSharp.PixelFormats.Rgb24"/> reference at the given offset.</returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static ref Rgb24 GetRgb24(ref byte baseRef, int offset) |
|
|
|
{ |
|
|
|
return ref Unsafe.As<byte, Rgb24>(ref Unsafe.Add(ref baseRef, offset)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |