Skip to content

Commit

Permalink
Revert additional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Apr 5, 2024
1 parent eec9718 commit da49788
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ComponentProcessor(MemoryAllocator memoryAllocator, JpegFrame frame, Size
this.Component = component;

this.BlockAreaSize = component.SubSamplingDivisors * blockSize;
this.ColorBuffer = memoryAllocator.Allocate2DOverAligned<float>(
this.ColorBuffer = memoryAllocator.Allocate2DOveraligned<float>(
postProcessorBufferSize.Width,
postProcessorBufferSize.Height,
this.BlockAreaSize.Height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ComponentProcessor(MemoryAllocator memoryAllocator, Component component,
this.blockAreaSize = component.SubSamplingDivisors * 8;

// alignment of 8 so each block stride can be sampled from a single 'ref pointer'
this.ColorBuffer = memoryAllocator.Allocate2DOverAligned<float>(
this.ColorBuffer = memoryAllocator.Allocate2DOveraligned<float>(
postProcessorBufferSize.Width,
postProcessorBufferSize.Height,
8,
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
throw new UnknownImageFormatException("Width or height cannot be 0");
}

Image<TPixel> image = new(this.configuration, this.fileHeader.Width, this.fileHeader.Height, this.metadata);
Image<TPixel> image = Image.CreateUninitialized<TPixel>(this.configuration, this.fileHeader.Width, this.fileHeader.Height, this.metadata);
Buffer2D<TPixel> pixels = image.GetRootFramePixelBuffer();

if (this.fileHeader.ColorMapType == 1)
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/Memory/Allocators/MemoryAllocatorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct MemoryAllocatorOptions
/// </summary>
public int? MaximumPoolSizeMegabytes
{
readonly get => this.maximumPoolSizeMegabytes;
get => this.maximumPoolSizeMegabytes;
set
{
if (value.HasValue)
Expand All @@ -35,7 +35,7 @@ public struct MemoryAllocatorOptions
/// </summary>
public int? AllocationLimitMegabytes
{
readonly get => this.allocationLimitMegabytes;
get => this.allocationLimitMegabytes;
set
{
if (value.HasValue)
Expand Down
14 changes: 7 additions & 7 deletions src/ImageSharp/Memory/MemoryAllocatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ public static class MemoryAllocatorExtensions
/// <param name="memoryAllocator">The memory allocator.</param>
/// <param name="width">The buffer width.</param>
/// <param name="height">The buffer height.</param>
/// <param name="preferContiguousImageBuffers">A value indicating whether the allocated buffer should be contiguous, unless bigger than <see cref="int.MaxValue"/>.</param>
/// <param name="preferContiguosImageBuffers">A value indicating whether the allocated buffer should be contiguous, unless bigger than <see cref="int.MaxValue"/>.</param>
/// <param name="options">The allocation options.</param>
/// <returns>The <see cref="Buffer2D{T}"/>.</returns>
public static Buffer2D<T> Allocate2D<T>(
this MemoryAllocator memoryAllocator,
int width,
int height,
bool preferContiguousImageBuffers,
bool preferContiguosImageBuffers,
AllocationOptions options = AllocationOptions.None)
where T : struct
{
long groupLength = (long)width * height;
MemoryGroup<T> memoryGroup;
if (preferContiguousImageBuffers && groupLength < int.MaxValue)
if (preferContiguosImageBuffers && groupLength < int.MaxValue)
{
IMemoryOwner<T> buffer = memoryAllocator.Allocate<T>((int)groupLength, options);
memoryGroup = MemoryGroup<T>.CreateContiguous(buffer, false);
Expand Down Expand Up @@ -69,16 +69,16 @@ public static class MemoryAllocatorExtensions
/// <typeparam name="T">The type of buffer items to allocate.</typeparam>
/// <param name="memoryAllocator">The memory allocator.</param>
/// <param name="size">The buffer size.</param>
/// <param name="preferContiguousImageBuffers">A value indicating whether the allocated buffer should be contiguous, unless bigger than <see cref="int.MaxValue"/>.</param>
/// <param name="preferContiguosImageBuffers">A value indicating whether the allocated buffer should be contiguous, unless bigger than <see cref="int.MaxValue"/>.</param>
/// <param name="options">The allocation options.</param>
/// <returns>The <see cref="Buffer2D{T}"/>.</returns>
public static Buffer2D<T> Allocate2D<T>(
this MemoryAllocator memoryAllocator,
Size size,
bool preferContiguousImageBuffers,
bool preferContiguosImageBuffers,
AllocationOptions options = AllocationOptions.None)
where T : struct =>
Allocate2D<T>(memoryAllocator, size.Width, size.Height, preferContiguousImageBuffers, options);
Allocate2D<T>(memoryAllocator, size.Width, size.Height, preferContiguosImageBuffers, options);

/// <summary>
/// Allocates a buffer of value type objects interpreted as a 2D region
Expand All @@ -96,7 +96,7 @@ public static class MemoryAllocatorExtensions
where T : struct =>
Allocate2D<T>(memoryAllocator, size.Width, size.Height, false, options);

internal static Buffer2D<T> Allocate2DOverAligned<T>(
internal static Buffer2D<T> Allocate2DOveraligned<T>(
this MemoryAllocator memoryAllocator,
int width,
int height,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal partial class ResizeKernelMap : IDisposable
this.sourceLength = sourceLength;
this.DestinationLength = destinationLength;
this.MaxDiameter = (radius * 2) + 1;
this.data = memoryAllocator.Allocate2D<float>(this.MaxDiameter, bufferHeight, preferContiguousImageBuffers: true, AllocationOptions.Clean);
this.data = memoryAllocator.Allocate2D<float>(this.MaxDiameter, bufferHeight, preferContiguosImageBuffers: true, AllocationOptions.Clean);
this.pinHandle = this.data.DangerousGetSingleMemory().Pin();
this.kernels = new ResizeKernel[destinationLength];
this.tempValues = new double[this.MaxDiameter];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal sealed class ResizeWorker<TPixel> : IDisposable
this.transposedFirstPassBuffer = configuration.MemoryAllocator.Allocate2D<Vector4>(
this.workerHeight,
targetWorkingRect.Width,
preferContiguousImageBuffers: true,
preferContiguosImageBuffers: true,
options: AllocationOptions.Clean);

this.tempRowBuffer = configuration.MemoryAllocator.Allocate<Vector4>(this.sourceRectangle.Width);
Expand Down
8 changes: 4 additions & 4 deletions tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public void Construct_PreferContiguousImageBuffers_AllocatesContiguousRegardless
using Buffer2D<byte> buffer = useSizeOverload ?
this.MemoryAllocator.Allocate2D<byte>(
new Size(200, 200),
preferContiguousImageBuffers: true) :
preferContiguosImageBuffers: true) :
this.MemoryAllocator.Allocate2D<byte>(
200,
200,
preferContiguousImageBuffers: true);
preferContiguosImageBuffers: true);
Assert.Equal(1, buffer.FastMemoryGroup.Count);
Assert.Equal(200 * 200, buffer.FastMemoryGroup.TotalLength);
}
Expand All @@ -88,7 +88,7 @@ public void Allocate2DOveraligned(int bufferCapacity, int width, int height, int
{
this.MemoryAllocator.BufferCapacityInBytes = sizeof(int) * bufferCapacity;

using Buffer2D<int> buffer = this.MemoryAllocator.Allocate2DOverAligned<int>(width, height, alignmentMultiplier);
using Buffer2D<int> buffer = this.MemoryAllocator.Allocate2DOveraligned<int>(width, height, alignmentMultiplier);
MemoryGroup<int> memoryGroup = buffer.FastMemoryGroup;
int expectedAlignment = width * alignmentMultiplier;

Expand Down Expand Up @@ -359,5 +359,5 @@ public void Allocate_IncorrectAmount_ThrowsCorrect_InvalidMemoryOperationExcepti
[Theory]
[MemberData(nameof(InvalidLengths))]
public void Allocate_IncorrectAmount_ThrowsCorrect_InvalidMemoryOperationException_OverAligned(Size size)
=> Assert.Throws<InvalidMemoryOperationException>(() => this.MemoryAllocator.Allocate2DOverAligned<Rgba32>(size.Width, size.Height, 1));
=> Assert.Throws<InvalidMemoryOperationException>(() => this.MemoryAllocator.Allocate2DOveraligned<Rgba32>(size.Width, size.Height, 1));
}

0 comments on commit da49788

Please sign in to comment.