Browse Source

Merge pull request #1194 from SixLabors/js-buffer2dregion

BufferRegion => Buffer2DRegion
pull/1574/head
James Jackson-South 6 years ago
committed by GitHub
parent
commit
d1f24ff119
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopyTo.cs
  3. 22
      src/ImageSharp/Memory/Buffer2DExtensions.cs
  4. 36
      src/ImageSharp/Memory/Buffer2DRegion{T}.cs
  5. 4
      src/ImageSharp/Processing/Processors/Quantization/DefaultPixelSamplingStrategy.cs
  6. 2
      src/ImageSharp/Processing/Processors/Quantization/ExtensivePixelSamplingStrategy.cs
  7. 4
      src/ImageSharp/Processing/Processors/Quantization/IPixelSamplingStrategy.cs
  8. 4
      src/ImageSharp/Processing/Processors/Quantization/IQuantizer{TPixel}.cs
  9. 2
      src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs
  10. 2
      src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs
  11. 4
      src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs
  12. 2
      src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs
  13. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs
  14. 4
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs
  15. 2
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo2x2.cs
  16. 4
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs
  17. 14
      tests/ImageSharp.Tests/Memory/BufferAreaTests.cs
  18. 6
      tests/ImageSharp.Tests/Quantization/PixelSamplingStrategyTests.cs

2
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -543,7 +543,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
return; return;
} }
BufferRegion<TPixel> pixelRegion = frame.PixelBuffer.GetRegion(this.restoreArea.Value); Buffer2DRegion<TPixel> pixelRegion = frame.PixelBuffer.GetRegion(this.restoreArea.Value);
pixelRegion.Clear(); pixelRegion.Clear();
this.restoreArea = null; this.restoreArea = null;

2
src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopyTo.cs

@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Copy block data into the destination color buffer pixel area with the provided horizontal and vertical scale factors. /// Copy block data into the destination color buffer pixel area with the provided horizontal and vertical scale factors.
/// </summary> /// </summary>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void ScaledCopyTo(in BufferRegion<float> region, int horizontalScale, int verticalScale) public void ScaledCopyTo(in Buffer2DRegion<float> region, int horizontalScale, int verticalScale)
{ {
ref float areaOrigin = ref region.GetReferenceToOrigin(); ref float areaOrigin = ref region.GetReferenceToOrigin();
this.ScaledCopyTo(ref areaOrigin, region.Stride, horizontalScale, verticalScale); this.ScaledCopyTo(ref areaOrigin, region.Stride, horizontalScale, verticalScale);

22
src/ImageSharp/Memory/Buffer2DExtensions.cs

@ -80,29 +80,29 @@ namespace SixLabors.ImageSharp.Memory
} }
/// <summary> /// <summary>
/// Return a <see cref="BufferRegion{T}"/> to the subarea represented by 'rectangle' /// Return a <see cref="Buffer2DRegion{T}"/> to the subregion represented by 'rectangle'
/// </summary> /// </summary>
/// <typeparam name="T">The element type</typeparam> /// <typeparam name="T">The element type</typeparam>
/// <param name="buffer">The <see cref="Buffer2D{T}"/></param> /// <param name="buffer">The <see cref="Buffer2D{T}"/></param>
/// <param name="rectangle">The rectangle subarea</param> /// <param name="rectangle">The rectangle subregion</param>
/// <returns>The <see cref="BufferRegion{T}"/></returns> /// <returns>The <see cref="Buffer2DRegion{T}"/></returns>
internal static BufferRegion<T> GetRegion<T>(this Buffer2D<T> buffer, in Rectangle rectangle) internal static Buffer2DRegion<T> GetRegion<T>(this Buffer2D<T> buffer, Rectangle rectangle)
where T : unmanaged => where T : unmanaged =>
new BufferRegion<T>(buffer, rectangle); new Buffer2DRegion<T>(buffer, rectangle);
internal static BufferRegion<T> GetRegion<T>(this Buffer2D<T> buffer, int x, int y, int width, int height) internal static Buffer2DRegion<T> GetRegion<T>(this Buffer2D<T> buffer, int x, int y, int width, int height)
where T : unmanaged => where T : unmanaged =>
new BufferRegion<T>(buffer, new Rectangle(x, y, width, height)); new Buffer2DRegion<T>(buffer, new Rectangle(x, y, width, height));
/// <summary> /// <summary>
/// Return a <see cref="BufferRegion{T}"/> to the whole area of 'buffer' /// Return a <see cref="Buffer2DRegion{T}"/> to the whole area of 'buffer'
/// </summary> /// </summary>
/// <typeparam name="T">The element type</typeparam> /// <typeparam name="T">The element type</typeparam>
/// <param name="buffer">The <see cref="Buffer2D{T}"/></param> /// <param name="buffer">The <see cref="Buffer2D{T}"/></param>
/// <returns>The <see cref="BufferRegion{T}"/></returns> /// <returns>The <see cref="Buffer2DRegion{T}"/></returns>
internal static BufferRegion<T> GetRegion<T>(this Buffer2D<T> buffer) internal static Buffer2DRegion<T> GetRegion<T>(this Buffer2D<T> buffer)
where T : unmanaged => where T : unmanaged =>
new BufferRegion<T>(buffer); new Buffer2DRegion<T>(buffer);
/// <summary> /// <summary>
/// Returns the size of the buffer. /// Returns the size of the buffer.

36
src/ImageSharp/Memory/BufferRegion{T}.cs → src/ImageSharp/Memory/Buffer2DRegion{T}.cs

@ -9,16 +9,16 @@ namespace SixLabors.ImageSharp.Memory
/// Represents a rectangular region inside a 2D memory buffer (<see cref="Buffer2D{T}"/>). /// Represents a rectangular region inside a 2D memory buffer (<see cref="Buffer2D{T}"/>).
/// </summary> /// </summary>
/// <typeparam name="T">The element type.</typeparam> /// <typeparam name="T">The element type.</typeparam>
public readonly struct BufferRegion<T> public readonly struct Buffer2DRegion<T>
where T : unmanaged where T : unmanaged
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BufferRegion{T}"/> struct. /// Initializes a new instance of the <see cref="Buffer2DRegion{T}"/> struct.
/// </summary> /// </summary>
/// <param name="buffer">The <see cref="Buffer2D{T}"/>.</param> /// <param name="buffer">The <see cref="Buffer2D{T}"/>.</param>
/// <param name="rectangle">The <see cref="Rectangle"/> defining a rectangular area within the buffer.</param> /// <param name="rectangle">The <see cref="Rectangle"/> defining a rectangular area within the buffer.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public BufferRegion(Buffer2D<T> buffer, Rectangle rectangle) public Buffer2DRegion(Buffer2D<T> buffer, Rectangle rectangle)
{ {
DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.X, 0, nameof(rectangle)); DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.X, 0, nameof(rectangle));
DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.Y, 0, nameof(rectangle)); DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.Y, 0, nameof(rectangle));
@ -30,11 +30,11 @@ namespace SixLabors.ImageSharp.Memory
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BufferRegion{T}"/> struct. /// Initializes a new instance of the <see cref="Buffer2DRegion{T}"/> struct.
/// </summary> /// </summary>
/// <param name="buffer">The <see cref="Buffer2D{T}"/>.</param> /// <param name="buffer">The <see cref="Buffer2D{T}"/>.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public BufferRegion(Buffer2D<T> buffer) public Buffer2DRegion(Buffer2D<T> buffer)
: this(buffer, buffer.FullRectangle()) : this(buffer, buffer.FullRectangle())
{ {
} }
@ -98,27 +98,27 @@ namespace SixLabors.ImageSharp.Memory
} }
/// <summary> /// <summary>
/// Returns a sub-area as <see cref="BufferRegion{T}"/>. (Similar to <see cref="Span{T}.Slice(int, int)"/>.) /// Returns a subregion as <see cref="Buffer2DRegion{T}"/>. (Similar to <see cref="Span{T}.Slice(int, int)"/>.)
/// </summary> /// </summary>
/// <param name="x">The x index at the subarea origin.</param> /// <param name="x">The x index at the subregion origin.</param>
/// <param name="y">The y index at the subarea origin.</param> /// <param name="y">The y index at the subregion origin.</param>
/// <param name="width">The desired width of the subarea.</param> /// <param name="width">The desired width of the subregion.</param>
/// <param name="height">The desired height of the subarea.</param> /// <param name="height">The desired height of the subregion.</param>
/// <returns>The subarea</returns> /// <returns>The subregion</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public BufferRegion<T> GetSubArea(int x, int y, int width, int height) public Buffer2DRegion<T> GetSubRegion(int x, int y, int width, int height)
{ {
var rectangle = new Rectangle(x, y, width, height); var rectangle = new Rectangle(x, y, width, height);
return this.GetSubArea(rectangle); return this.GetSubRegion(rectangle);
} }
/// <summary> /// <summary>
/// Returns a sub-area as <see cref="BufferRegion{T}"/>. (Similar to <see cref="Span{T}.Slice(int, int)"/>.) /// Returns a subregion as <see cref="Buffer2DRegion{T}"/>. (Similar to <see cref="Span{T}.Slice(int, int)"/>.)
/// </summary> /// </summary>
/// <param name="rectangle">The <see cref="Rectangle"/> specifying the boundaries of the subarea</param> /// <param name="rectangle">The <see cref="Rectangle"/> specifying the boundaries of the subregion</param>
/// <returns>The subarea</returns> /// <returns>The subregion</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public BufferRegion<T> GetSubArea(Rectangle rectangle) public Buffer2DRegion<T> GetSubRegion(Rectangle rectangle)
{ {
DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, this.Rectangle.Width, nameof(rectangle)); DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, this.Rectangle.Width, nameof(rectangle));
DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, this.Rectangle.Height, nameof(rectangle)); DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, this.Rectangle.Height, nameof(rectangle));
@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Memory
int x = this.Rectangle.X + rectangle.X; int x = this.Rectangle.X + rectangle.X;
int y = this.Rectangle.Y + rectangle.Y; int y = this.Rectangle.Y + rectangle.Y;
rectangle = new Rectangle(x, y, rectangle.Width, rectangle.Height); rectangle = new Rectangle(x, y, rectangle.Width, rectangle.Height);
return new BufferRegion<T>(this.Buffer, rectangle); return new Buffer2DRegion<T>(this.Buffer, rectangle);
} }
/// <summary> /// <summary>

4
src/ImageSharp/Processing/Processors/Quantization/DefaultPixelSamplingStrategy.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
public double MinimumScanRatio { get; } public double MinimumScanRatio { get; }
/// <inheritdoc /> /// <inheritdoc />
public IEnumerable<BufferRegion<TPixel>> EnumeratePixelRegions<TPixel>(Image<TPixel> image) public IEnumerable<Buffer2DRegion<TPixel>> EnumeratePixelRegions<TPixel>(Image<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
long maximumPixels = Math.Min(this.MaximumPixels, (long)image.Width * image.Height * image.Frames.Count); long maximumPixels = Math.Min(this.MaximumPixels, (long)image.Width * image.Height * image.Frames.Count);
@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
} }
} }
BufferRegion<TPixel> GetRow(int pos) Buffer2DRegion<TPixel> GetRow(int pos)
{ {
int frameIdx = pos / image.Height; int frameIdx = pos / image.Height;
int y = pos % image.Height; int y = pos % image.Height;

2
src/ImageSharp/Processing/Processors/Quantization/ExtensivePixelSamplingStrategy.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
public class ExtensivePixelSamplingStrategy : IPixelSamplingStrategy public class ExtensivePixelSamplingStrategy : IPixelSamplingStrategy
{ {
/// <inheritdoc /> /// <inheritdoc />
public IEnumerable<BufferRegion<TPixel>> EnumeratePixelRegions<TPixel>(Image<TPixel> image) public IEnumerable<Buffer2DRegion<TPixel>> EnumeratePixelRegions<TPixel>(Image<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
foreach (ImageFrame<TPixel> frame in image.Frames) foreach (ImageFrame<TPixel> frame in image.Frames)

4
src/ImageSharp/Processing/Processors/Quantization/IPixelSamplingStrategy.cs

@ -13,12 +13,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
public interface IPixelSamplingStrategy public interface IPixelSamplingStrategy
{ {
/// <summary> /// <summary>
/// Enumerates pixel regions within the image as <see cref="BufferRegion{T}"/>. /// Enumerates pixel regions within the image as <see cref="Buffer2DRegion{T}"/>.
/// </summary> /// </summary>
/// <param name="image">The image.</param> /// <param name="image">The image.</param>
/// <typeparam name="TPixel">The pixel type.</typeparam> /// <typeparam name="TPixel">The pixel type.</typeparam>
/// <returns>An enumeration of pixel regions.</returns> /// <returns>An enumeration of pixel regions.</returns>
IEnumerable<BufferRegion<TPixel>> EnumeratePixelRegions<TPixel>(Image<TPixel> image) IEnumerable<Buffer2DRegion<TPixel>> EnumeratePixelRegions<TPixel>(Image<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel>; where TPixel : unmanaged, IPixel<TPixel>;
} }
} }

4
src/ImageSharp/Processing/Processors/Quantization/IQuantizer{TPixel}.cs

@ -35,8 +35,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <summary> /// <summary>
/// Adds colors to the quantized palette from the given pixel source. /// Adds colors to the quantized palette from the given pixel source.
/// </summary> /// </summary>
/// <param name="pixelRegion">The <see cref="BufferRegion{T}"/> of source pixels to register.</param> /// <param name="pixelRegion">The <see cref="Buffer2DRegion{T}"/> of source pixels to register.</param>
void AddPaletteColors(BufferRegion<TPixel> pixelRegion); void AddPaletteColors(Buffer2DRegion<TPixel> pixelRegion);
/// <summary> /// <summary>
/// Quantizes an image frame and return the resulting output pixels. /// Quantizes an image frame and return the resulting output pixels.

2
src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs

@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void AddPaletteColors(BufferRegion<TPixel> pixelRegion) public void AddPaletteColors(Buffer2DRegion<TPixel> pixelRegion)
{ {
Rectangle bounds = pixelRegion.Rectangle; Rectangle bounds = pixelRegion.Rectangle;
Buffer2D<TPixel> source = pixelRegion.Buffer; Buffer2D<TPixel> source = pixelRegion.Buffer;

2
src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs

@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void AddPaletteColors(BufferRegion<TPixel> pixelRegion) public void AddPaletteColors(Buffer2DRegion<TPixel> pixelRegion)
{ {
} }

4
src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs

@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
var interest = Rectangle.Intersect(source.Bounds(), bounds); var interest = Rectangle.Intersect(source.Bounds(), bounds);
BufferRegion<TPixel> region = source.PixelBuffer.GetRegion(interest); Buffer2DRegion<TPixel> region = source.PixelBuffer.GetRegion(interest);
// Collect the palette. Required before the second pass runs. // Collect the palette. Required before the second pass runs.
quantizer.AddPaletteColors(region); quantizer.AddPaletteColors(region);
@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
Image<TPixel> image) Image<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
foreach (BufferRegion<TPixel> region in pixelSamplingStrategy.EnumeratePixelRegions(image)) foreach (Buffer2DRegion<TPixel> region in pixelSamplingStrategy.EnumeratePixelRegions(image))
{ {
quantizer.AddPaletteColors(region); quantizer.AddPaletteColors(region);
} }

2
src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs

@ -118,7 +118,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
} }
/// <inheritdoc/> /// <inheritdoc/>
public void AddPaletteColors(BufferRegion<TPixel> pixelRegion) public void AddPaletteColors(Buffer2DRegion<TPixel> pixelRegion)
{ {
Rectangle bounds = pixelRegion.Rectangle; Rectangle bounds = pixelRegion.Rectangle;
Buffer2D<TPixel> source = pixelRegion.Buffer; Buffer2D<TPixel> source = pixelRegion.Buffer;

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

@ -172,7 +172,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
PixelConversionModifiers conversionModifiers = PixelConversionModifiers conversionModifiers =
PixelConversionModifiers.Premultiply.ApplyCompanding(compand); PixelConversionModifiers.Premultiply.ApplyCompanding(compand);
BufferRegion<TPixel> sourceRegion = source.PixelBuffer.GetRegion(sourceRectangle); Buffer2DRegion<TPixel> sourceRegion = source.PixelBuffer.GetRegion(sourceRectangle);
// To reintroduce parallel processing, we would launch multiple workers // To reintroduce parallel processing, we would launch multiple workers
// for different row intervals of the image. // for different row intervals of the image.

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

@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
private readonly ResizeKernelMap horizontalKernelMap; private readonly ResizeKernelMap horizontalKernelMap;
private readonly BufferRegion<TPixel> source; private readonly Buffer2DRegion<TPixel> source;
private readonly Rectangle sourceRectangle; private readonly Rectangle sourceRectangle;
@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public ResizeWorker( public ResizeWorker(
Configuration configuration, Configuration configuration,
BufferRegion<TPixel> source, Buffer2DRegion<TPixel> source,
PixelConversionModifiers conversionModifiers, PixelConversionModifiers conversionModifiers,
ResizeKernelMap horizontalKernelMap, ResizeKernelMap horizontalKernelMap,
ResizeKernelMap verticalKernelMap, ResizeKernelMap verticalKernelMap,

2
tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo2x2.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations
private Buffer2D<float> buffer; private Buffer2D<float> buffer;
private BufferRegion<float> destRegion; private Buffer2DRegion<float> destRegion;
[GlobalSetup] [GlobalSetup]
public void Setup() public void Setup()

4
tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs

@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
using (Buffer2D<float> buffer = Configuration.Default.MemoryAllocator.Allocate2D<float>(20, 20, AllocationOptions.Clean)) using (Buffer2D<float> buffer = Configuration.Default.MemoryAllocator.Allocate2D<float>(20, 20, AllocationOptions.Clean))
{ {
BufferRegion<float> region = buffer.GetRegion(5, 10, 8, 8); Buffer2DRegion<float> region = buffer.GetRegion(5, 10, 8, 8);
block.Copy1x1Scale(ref region.GetReferenceToOrigin(), region.Stride); block.Copy1x1Scale(ref region.GetReferenceToOrigin(), region.Stride);
Assert.Equal(block[0, 0], buffer[5, 10]); Assert.Equal(block[0, 0], buffer[5, 10]);
@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
using (Buffer2D<float> buffer = Configuration.Default.MemoryAllocator.Allocate2D<float>(100, 100, AllocationOptions.Clean)) using (Buffer2D<float> buffer = Configuration.Default.MemoryAllocator.Allocate2D<float>(100, 100, AllocationOptions.Clean))
{ {
BufferRegion<float> region = buffer.GetRegion(start.X, start.Y, 8 * horizontalFactor, 8 * verticalFactor); Buffer2DRegion<float> region = buffer.GetRegion(start.X, start.Y, 8 * horizontalFactor, 8 * verticalFactor);
block.ScaledCopyTo(region, horizontalFactor, verticalFactor); block.ScaledCopyTo(region, horizontalFactor, verticalFactor);
for (int y = 0; y < 8 * verticalFactor; y++) for (int y = 0; y < 8 * verticalFactor; y++)

14
tests/ImageSharp.Tests/Memory/BufferAreaTests.cs

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
{ {
using Buffer2D<int> buffer = this.memoryAllocator.Allocate2D<int>(10, 20); using Buffer2D<int> buffer = this.memoryAllocator.Allocate2D<int>(10, 20);
var rectangle = new Rectangle(3, 2, 5, 6); var rectangle = new Rectangle(3, 2, 5, 6);
var area = new BufferRegion<int>(buffer, rectangle); var area = new Buffer2DRegion<int>(buffer, rectangle);
Assert.Equal(buffer, area.Buffer); Assert.Equal(buffer, area.Buffer);
Assert.Equal(rectangle, area.Rectangle); Assert.Equal(rectangle, area.Rectangle);
@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30); using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30);
var r = new Rectangle(rx, ry, 5, 6); var r = new Rectangle(rx, ry, 5, 6);
BufferRegion<int> region = buffer.GetRegion(r); Buffer2DRegion<int> region = buffer.GetRegion(r);
int value = region[x, y]; int value = region[x, y];
int expected = ((ry + y) * 100) + rx + x; int expected = ((ry + y) * 100) + rx + x;
@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30); using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30);
var r = new Rectangle(rx, ry, w, h); var r = new Rectangle(rx, ry, w, h);
BufferRegion<int> region = buffer.GetRegion(r); Buffer2DRegion<int> region = buffer.GetRegion(r);
Span<int> span = region.GetRowSpan(y); Span<int> span = region.GetRowSpan(y);
@ -85,9 +85,9 @@ namespace SixLabors.ImageSharp.Tests.Memory
public void GetSubArea() public void GetSubArea()
{ {
using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30); using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30);
BufferRegion<int> area0 = buffer.GetRegion(6, 8, 10, 10); Buffer2DRegion<int> area0 = buffer.GetRegion(6, 8, 10, 10);
BufferRegion<int> area1 = area0.GetSubArea(4, 4, 5, 5); Buffer2DRegion<int> area1 = area0.GetSubRegion(4, 4, 5, 5);
var expectedRect = new Rectangle(10, 12, 5, 5); var expectedRect = new Rectangle(10, 12, 5, 5);
@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
this.memoryAllocator.BufferCapacityInBytes = sizeof(int) * bufferCapacity; this.memoryAllocator.BufferCapacityInBytes = sizeof(int) * bufferCapacity;
using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30); using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30);
BufferRegion<int> area0 = buffer.GetRegion(6, 8, 10, 10); Buffer2DRegion<int> area0 = buffer.GetRegion(6, 8, 10, 10);
ref int r = ref area0.GetReferenceToOrigin(); ref int r = ref area0.GetReferenceToOrigin();
@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
this.memoryAllocator.BufferCapacityInBytes = sizeof(int) * bufferCapacity; this.memoryAllocator.BufferCapacityInBytes = sizeof(int) * bufferCapacity;
using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30); using Buffer2D<int> buffer = this.CreateTestBuffer(20, 30);
BufferRegion<int> region = buffer.GetRegion(5, 5, 10, 10); Buffer2DRegion<int> region = buffer.GetRegion(5, 5, 10, 10);
region.Clear(); region.Clear();
Assert.NotEqual(0, buffer[4, 4]); Assert.NotEqual(0, buffer[4, 4]);

6
tests/ImageSharp.Tests/Quantization/PixelSamplingStrategyTests.cs

@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Tests.Quantization
using Image<L8> image = CreateTestImage(100, 100, 100); using Image<L8> image = CreateTestImage(100, 100, 100);
var strategy = new ExtensivePixelSamplingStrategy(); var strategy = new ExtensivePixelSamplingStrategy();
foreach (BufferRegion<L8> region in strategy.EnumeratePixelRegions(image)) foreach (Buffer2DRegion<L8> region in strategy.EnumeratePixelRegions(image))
{ {
PaintWhite(region); PaintWhite(region);
} }
@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Quantization
var strategy = new DefaultPixelSamplingStrategy(maximumNumberOfPixels, 0.1); var strategy = new DefaultPixelSamplingStrategy(maximumNumberOfPixels, 0.1);
long visitedPixels = 0; long visitedPixels = 0;
foreach (BufferRegion<L8> region in strategy.EnumeratePixelRegions(image)) foreach (Buffer2DRegion<L8> region in strategy.EnumeratePixelRegions(image))
{ {
PaintWhite(region); PaintWhite(region);
visitedPixels += region.Width * region.Height; visitedPixels += region.Width * region.Height;
@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.Tests.Quantization
Assert.True(visitRatio <= 1.1, $"{visitedPixels}>{maximumPixels}"); Assert.True(visitRatio <= 1.1, $"{visitedPixels}>{maximumPixels}");
} }
private static void PaintWhite(BufferRegion<L8> region) private static void PaintWhite(Buffer2DRegion<L8> region)
{ {
var white = new L8(255); var white = new L8(255);
for (int y = 0; y < region.Height; y++) for (int y = 0; y < region.Height; y++)

Loading…
Cancel
Save