Browse Source

Revert additional changes

pull/2706/head
James Jackson-South 2 years ago
parent
commit
da497882fe
  1. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs
  3. 2
      src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
  4. 4
      src/ImageSharp/Memory/Allocators/MemoryAllocatorOptions.cs
  5. 14
      src/ImageSharp/Memory/MemoryAllocatorExtensions.cs
  6. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs
  7. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs
  8. 8
      tests/ImageSharp.Tests/Memory/Buffer2DTests.cs

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs

@ -16,7 +16,7 @@ internal abstract class ComponentProcessor : IDisposable
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);

2
src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs

@ -28,7 +28,7 @@ internal class ComponentProcessor : IDisposable
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,

2
src/ImageSharp/Formats/Tga/TgaDecoderCore.cs

@ -84,7 +84,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals
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)

4
src/ImageSharp/Memory/Allocators/MemoryAllocatorOptions.cs

@ -17,7 +17,7 @@ public struct MemoryAllocatorOptions
/// </summary>
public int? MaximumPoolSizeMegabytes
{
readonly get => this.maximumPoolSizeMegabytes;
get => this.maximumPoolSizeMegabytes;
set
{
if (value.HasValue)
@ -35,7 +35,7 @@ public struct MemoryAllocatorOptions
/// </summary>
public int? AllocationLimitMegabytes
{
readonly get => this.allocationLimitMegabytes;
get => this.allocationLimitMegabytes;
set
{
if (value.HasValue)

14
src/ImageSharp/Memory/MemoryAllocatorExtensions.cs

@ -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);
@ -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
@ -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,

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs

@ -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];

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs

@ -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);

8
tests/ImageSharp.Tests/Memory/Buffer2DTests.cs

@ -73,11 +73,11 @@ public partial class Buffer2DTests
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);
}
@ -88,7 +88,7 @@ public partial class Buffer2DTests
{
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;
@ -359,5 +359,5 @@ public partial class Buffer2DTests
[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));
}

Loading…
Cancel
Save