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 (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);
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
{
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));
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 />
public byte[] ToRawArray()
{
byte[] array = GC.AllocateUninitializedArray<byte>(SizeInBytes);
byte[] array = new byte[SizeInBytes];
CopyTo(array);
return array;
}
@ -188,7 +188,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
/// <inheritdoc />
public T[] ToArray()
{
T[] colors = GC.AllocateUninitializedArray<T>(Width * Height);
T[] colors = new T[Width * Height];
CopyTo(colors);
return colors;
}

View File

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

View File

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

View File

@ -38,7 +38,7 @@ public static unsafe partial class PixelHelper
{
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());
return buffer;
}
@ -49,7 +49,7 @@ public static unsafe partial class PixelHelper
{
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());
return buffer;
}