Compare commits

..

No commits in common. "da26ca248f05b8ebfbe231950ee2f2a78ed37638" and "94695ab9cb7cf92236676c80db9fb4da2f3a4a8e" have entirely different histories.

5 changed files with 9 additions and 10 deletions

View File

@ -124,7 +124,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
if (stride < width) throw new ArgumentException("Stride can't be smaller than width."); if (stride < width) throw new ArgumentException("Stride can't be smaller than width.");
if (buffer.Length < (height * stride)) throw new ArgumentException("Not enough data in the buffer."); if (buffer.Length < (height * stride)) throw new ArgumentException("Not enough data in the buffer.");
byte[] data = GC.AllocateUninitializedArray<byte>(buffer.Length); byte[] data = new byte[buffer.Length];
buffer.CopyTo(data); buffer.CopyTo(data);
return new Image<T>(data, 0, 0, width, height, stride); return new Image<T>(data, 0, 0, width, height, stride);
} }
@ -152,7 +152,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
else else
{ {
byte[] data = ToRawArray(); byte[] data = ToRawArray();
byte[] target = GC.AllocateUninitializedArray<byte>(Width * Height * targetBpp); byte[] target = new byte[Width * Height * targetBpp];
MemoryMarshal.Cast<byte, T>(data.AsSpan()).Convert(MemoryMarshal.Cast<byte, TColor>(target)); MemoryMarshal.Cast<byte, T>(data.AsSpan()).Convert(MemoryMarshal.Cast<byte, TColor>(target));
return new Image<TColor>(target, 0, 0, Width, Height, Width * targetBpp); return new Image<TColor>(target, 0, 0, Width, Height, Width * targetBpp);
} }
@ -180,7 +180,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
/// <inheritdoc /> /// <inheritdoc />
public byte[] ToRawArray() public byte[] ToRawArray()
{ {
byte[] array = GC.AllocateUninitializedArray<byte>(SizeInBytes); byte[] array = new byte[SizeInBytes];
CopyTo(array); CopyTo(array);
return array; return array;
} }
@ -188,7 +188,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
/// <inheritdoc /> /// <inheritdoc />
public T[] ToArray() public T[] ToArray()
{ {
T[] colors = GC.AllocateUninitializedArray<T>(Width * Height); T[] colors = new T[Width * Height];
CopyTo(colors); CopyTo(colors);
return colors; return colors;
} }

View File

@ -64,7 +64,7 @@ public readonly ref struct ImageColumn<T>
public T[] ToArray() public T[] ToArray()
{ {
T[] array = GC.AllocateUninitializedArray<T>(Length); T[] array = new T[Length];
CopyTo(array); CopyTo(array);
return array; return array;
} }

View File

@ -62,11 +62,10 @@ public readonly ref struct ImageRow<T>
public T[] ToArray() public T[] ToArray()
{ {
T[] array = GC.AllocateUninitializedArray<T>(Length); T[] array = new T[Length];
CopyTo(array); CopyTo(array);
return array; return array;
} }
/// <inheritdoc cref="System.Collections.IEnumerable.GetEnumerator"/> /// <inheritdoc cref="System.Collections.IEnumerable.GetEnumerator"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ImageRowEnumerator GetEnumerator() => new(this); public ImageRowEnumerator GetEnumerator() => new(this);

View File

@ -128,7 +128,7 @@ public readonly ref struct RefImage<T>
/// <returns>The new array containing the data of this <see cref="RefImage{T}"/>.</returns> /// <returns>The new array containing the data of this <see cref="RefImage{T}"/>.</returns>
public T[] ToArray() public T[] ToArray()
{ {
T[] array = GC.AllocateUninitializedArray<T>(Width * Height); T[] array = new T[Width * Height];
CopyTo(array); CopyTo(array);
return array; return array;
} }

View File

@ -38,7 +38,7 @@ public static unsafe partial class PixelHelper
{ {
if (colors == null) throw new ArgumentNullException(nameof(colors)); if (colors == null) throw new ArgumentNullException(nameof(colors));
TTarget[] buffer = GC.AllocateUninitializedArray<TTarget>(colors.Length); TTarget[] buffer = new TTarget[colors.Length];
Convert(colors, buffer.AsSpan()); Convert(colors, buffer.AsSpan());
return buffer; return buffer;
} }
@ -49,7 +49,7 @@ public static unsafe partial class PixelHelper
{ {
if (colors == null) throw new ArgumentNullException(nameof(colors)); if (colors == null) throw new ArgumentNullException(nameof(colors));
TTarget[] buffer = GC.AllocateUninitializedArray<TTarget>(colors.Length); TTarget[] buffer = new TTarget[colors.Length];
Convert(colors, buffer.AsSpan()); Convert(colors, buffer.AsSpan());
return buffer; return buffer;
} }