Browse Source

Fix review feedback

pull/3066/head
James Jackson-South 4 months ago
parent
commit
d557bb29e0
  1. 4
      src/ImageSharp/Image.WrapMemory.cs
  2. 6
      src/ImageSharp/Memory/Buffer2D{T}.cs

4
src/ImageSharp/Image.WrapMemory.cs

@ -609,14 +609,14 @@ public abstract partial class Image
ImageMetadata metadata) ImageMetadata metadata)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
Guard.IsFalse(pointer == null, nameof(pointer), "Pointer must be not null"); Guard.IsFalse(pointer == null, nameof(pointer), "Pointer must not be null");
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(metadata, nameof(metadata)); Guard.NotNull(metadata, nameof(metadata));
int rowStride = GetPixelRowStrideFromByteStride<TPixel>(width, rowStrideInBytes, nameof(rowStrideInBytes)); int rowStride = GetPixelRowStrideFromByteStride<TPixel>(width, rowStrideInBytes, nameof(rowStrideInBytes));
long requiredLength = GetRequiredLength(width, height, rowStride); long requiredLength = GetRequiredLength(width, height, rowStride);
Guard.MustBeLessThanOrEqualTo(requiredLength, int.MaxValue, nameof(height)); Guard.MustBeLessThanOrEqualTo(requiredLength, int.MaxValue, nameof(requiredLength));
Guard.MustBeGreaterThanOrEqualTo(bufferSizeInBytes / Unsafe.SizeOf<TPixel>(), requiredLength, nameof(bufferSizeInBytes)); Guard.MustBeGreaterThanOrEqualTo(bufferSizeInBytes / Unsafe.SizeOf<TPixel>(), requiredLength, nameof(bufferSizeInBytes));
UnmanagedMemoryManager<TPixel> memoryManager = new(pointer, (int)requiredLength); UnmanagedMemoryManager<TPixel> memoryManager = new(pointer, (int)requiredLength);

6
src/ImageSharp/Memory/Buffer2D{T}.cs

@ -356,7 +356,7 @@ public sealed class Buffer2D<T> : IDisposable
/// Thrown when the backing group is discontiguous. /// Thrown when the backing group is discontiguous.
/// </exception> /// </exception>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
internal Span<T> DangerousGetSingleSpan() => this.FastMemoryGroup[0].Span; internal Span<T> DangerousGetSingleSpan() => this.FastMemoryGroup.Single().Span;
/// <summary> /// <summary>
/// Gets a <see cref="Memory{T}"/> to the backing data of if the backing group consists of a single contiguous memory buffer. /// Gets a <see cref="Memory{T}"/> to the backing data of if the backing group consists of a single contiguous memory buffer.
@ -367,7 +367,7 @@ public sealed class Buffer2D<T> : IDisposable
/// Thrown when the backing group is discontiguous. /// Thrown when the backing group is discontiguous.
/// </exception> /// </exception>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
internal Memory<T> DangerousGetSingleMemory() => this.FastMemoryGroup[0]; internal Memory<T> DangerousGetSingleMemory() => this.FastMemoryGroup.Single();
/// <summary> /// <summary>
/// Swaps the contents of 'destination' with 'source' if the buffers are owned (1), /// Swaps the contents of 'destination' with 'source' if the buffers are owned (1),
@ -414,5 +414,5 @@ public sealed class Buffer2D<T> : IDisposable
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
private static long GetRequiredLength(int width, int height, int stride) private static long GetRequiredLength(int width, int height, int stride)
=> ((long)(height - 1) * stride) + width; => checked(((long)(height - 1) * stride) + width);
} }

Loading…
Cancel
Save