mirror of https://github.com/SixLabors/ImageSharp
95 changed files with 220 additions and 257 deletions
@ -1,28 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
using SixLabors.ImageSharp.Processing; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Extension methods for the <see cref="Image{TPixel}"/> type.
|
|
||||
/// </summary>
|
|
||||
public static partial class ImageExtensions |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Applies the given operation to the mutable image.
|
|
||||
/// Useful when we need to extract information like Width/Height to parameterize the next operation working on the <see cref="IImageProcessingContext{TPixel}"/> chain.
|
|
||||
/// To achieve this the method actually implements an "inline" <see cref="IImageProcessor{TPixel}"/> with <paramref name="operation"/> as it's processing logic.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
||||
/// <param name="source">The image to mutate.</param>
|
|
||||
/// <param name="operation">The operation to perform on the source.</param>
|
|
||||
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
|
|
||||
public static IImageProcessingContext<TPixel> Apply<TPixel>(this IImageProcessingContext<TPixel> source, Action<Image<TPixel>> operation) |
|
||||
where TPixel : struct, IPixel<TPixel> |
|
||||
=> source.ApplyProcessor(new DelegateProcessor<TPixel>(operation)); |
|
||||
} |
|
||||
} |
|
||||
@ -1,89 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests.Memory |
|
||||
{ |
|
||||
using System; |
|
||||
|
|
||||
using SixLabors.ImageSharp.Memory; |
|
||||
|
|
||||
using Xunit; |
|
||||
|
|
||||
public class Fast2DArrayTests |
|
||||
{ |
|
||||
private static readonly float[,] FloydSteinbergMatrix = |
|
||||
{ |
|
||||
{ 0, 0, 7 }, |
|
||||
{ 3, 5, 1 } |
|
||||
}; |
|
||||
|
|
||||
[Fact] |
|
||||
public void Fast2DArrayThrowsOnNullInitializer() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentNullException>(() => |
|
||||
{ |
|
||||
var fast = new Fast2DArray<float>(null); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Fast2DArrayThrowsOnEmptyZeroWidth() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => |
|
||||
{ |
|
||||
var fast = new Fast2DArray<float>(0, 10); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Fast2DArrayThrowsOnEmptyZeroHeight() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => |
|
||||
{ |
|
||||
var fast = new Fast2DArray<float>(10, 0); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Fast2DArrayThrowsOnEmptyInitializer() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => |
|
||||
{ |
|
||||
var fast = new Fast2DArray<float>(new float[0, 0]); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Fast2DArrayReturnsCorrectDimensions() |
|
||||
{ |
|
||||
var fast = new Fast2DArray<float>(FloydSteinbergMatrix); |
|
||||
Assert.True(fast.Width == FloydSteinbergMatrix.GetLength(1)); |
|
||||
Assert.True(fast.Height == FloydSteinbergMatrix.GetLength(0)); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Fast2DArrayGetReturnsCorrectResults() |
|
||||
{ |
|
||||
Fast2DArray<float> fast = FloydSteinbergMatrix; |
|
||||
|
|
||||
for (int row = 0; row < fast.Height; row++) |
|
||||
{ |
|
||||
for (int column = 0; column < fast.Width; column++) |
|
||||
{ |
|
||||
Assert.True(Math.Abs(fast[row, column] - FloydSteinbergMatrix[row, column]) < Constants.Epsilon); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Fast2DArrayGetSetReturnsCorrectResults() |
|
||||
{ |
|
||||
var fast = new Fast2DArray<float>(4, 4); |
|
||||
const float Val = 5F; |
|
||||
|
|
||||
fast[3, 3] = Val; |
|
||||
|
|
||||
Assert.True(Math.Abs(Val - fast[3, 3]) < Constants.Epsilon); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue