Browse Source

Merge remote-tracking branch 'origin/master' into simplified-IPixel

pull/109/head
Anton Firszov 9 years ago
parent
commit
1e547a919d
  1. 4
      src/ImageSharp.Processing/Processors/Convolution/BoxBlurProcessor.cs
  2. 8
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs
  3. 32
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs
  4. 4
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs
  5. 4
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs
  6. 4
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs
  7. 8
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs
  8. 8
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs
  9. 32
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs
  10. 8
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs
  11. 8
      src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs
  12. 4
      src/ImageSharp.Processing/Processors/Convolution/GaussianBlurProcessor.cs
  13. 4
      src/ImageSharp.Processing/Processors/Convolution/GaussianSharpenProcessor.cs
  14. 29
      src/ImageSharp/Common/Memory/Fast2DArray{T}.cs
  15. 4
      src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs
  16. 4
      src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs
  17. 4
      src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs
  18. 4
      src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs
  19. 4
      src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs
  20. 4
      src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs
  21. 4
      src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs
  22. 4
      src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs
  23. 4
      src/ImageSharp/Dithering/Ordered/Bayer.cs
  24. 4
      src/ImageSharp/Dithering/Ordered/Ordered.cs
  25. 28
      tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs

4
src/ImageSharp.Processing/Processors/Convolution/BoxBlurProcessor.cs

@ -57,8 +57,8 @@ namespace ImageSharp.Processing.Processors
{
int size = this.kernelSize;
Fast2DArray<float> kernel = horizontal
? new Fast2DArray<float>(new float[1, size])
: new Fast2DArray<float>(new float[size, 1]);
? new Fast2DArray<float>(size, 1)
: new Fast2DArray<float>(1, size);
float sum = 0F;
for (int i = 0; i < size; i++)

8
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs

@ -21,23 +21,23 @@ namespace ImageSharp.Processing.Processors
/// The horizontal gradient operator.
/// </summary>
private static readonly Fast2DArray<float> KayyaliX =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 6, 0, -6 },
{ 0, 0, 0 },
{ -6, 0, 6 }
});
};
/// <summary>
/// The vertical gradient operator.
/// </summary>
private static readonly Fast2DArray<float> KayyaliY =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -6, 0, 6 },
{ 0, 0, 0 },
{ 6, 0, -6 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="KayyaliProcessor{TColor}"/> class.

32
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs

@ -21,89 +21,89 @@ namespace ImageSharp.Processing.Processors
/// The North gradient operator
/// </summary>
private static readonly Fast2DArray<float> KirschNorth =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 5, 5, 5 },
{ -3, 0, -3 },
{ -3, -3, -3 }
});
};
/// <summary>
/// The NorthWest gradient operator
/// </summary>
private static readonly Fast2DArray<float> KirschNorthWest =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 5, 5, -3 },
{ 5, 0, -3 },
{ -3, -3, -3 }
});
};
/// <summary>
/// The West gradient operator
/// </summary>
private static readonly Fast2DArray<float> KirschWest =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 5, -3, -3 },
{ 5, 0, -3 },
{ 5, -3, -3 }
});
};
/// <summary>
/// The SouthWest gradient operator
/// </summary>
private static readonly Fast2DArray<float> KirschSouthWest =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -3, -3, -3 },
{ 5, 0, -3 },
{ 5, 5, -3 }
});
};
/// <summary>
/// The South gradient operator
/// </summary>
private static readonly Fast2DArray<float> KirschSouth =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -3, -3, -3 },
{ -3, 0, -3 },
{ 5, 5, 5 }
});
};
/// <summary>
/// The SouthEast gradient operator
/// </summary>
private static readonly Fast2DArray<float> KirschSouthEast =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -3, -3, -3 },
{ -3, 0, 5 },
{ -3, 5, 5 }
});
};
/// <summary>
/// The East gradient operator
/// </summary>
private static readonly Fast2DArray<float> KirschEast =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -3, -3, 5 },
{ -3, 0, 5 },
{ -3, -3, 5 }
});
};
/// <summary>
/// The NorthEast gradient operator
/// </summary>
private static readonly Fast2DArray<float> KirschNorthEast =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -3, 5, 5 },
{ -3, 0, 5 },
{ -3, -3, -3 }
});
};
/// <inheritdoc/>
public override Fast2DArray<float> North => KirschNorth;

4
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs

@ -21,12 +21,12 @@ namespace ImageSharp.Processing.Processors
/// The 2d gradient operator.
/// </summary>
private static readonly Fast2DArray<float> Laplacian3X3XY =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -1, -1, -1 },
{ -1, 8, -1 },
{ -1, -1, -1 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="Laplacian3X3Processor{TColor}"/> class.

4
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs

@ -21,14 +21,14 @@ namespace ImageSharp.Processing.Processors
/// The 2d gradient operator.
/// </summary>
private static readonly Fast2DArray<float> Laplacian5X5XY =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -1, -1, -1, -1, -1 },
{ -1, -1, -1, -1, -1 },
{ -1, -1, 24, -1, -1 },
{ -1, -1, -1, -1, -1 },
{ -1, -1, -1, -1, -1 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="Laplacian5X5Processor{TColor}"/> class.

4
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs

@ -21,14 +21,14 @@ namespace ImageSharp.Processing.Processors
/// The 2d gradient operator.
/// </summary>
private static readonly Fast2DArray<float> LaplacianOfGaussianXY =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 0, -1, 0, 0 },
{ 0, -1, -2, -1, 0 },
{ -1, -2, 16, -2, -1 },
{ 0, -1, -2, -1, 0 },
{ 0, 0, -1, 0, 0 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="LaplacianOfGaussianProcessor{TColor}"/> class.

8
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs

@ -21,23 +21,23 @@ namespace ImageSharp.Processing.Processors
/// The horizontal gradient operator.
/// </summary>
private static readonly Fast2DArray<float> PrewittX =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -1, 0, 1 },
{ -1, 0, 1 },
{ -1, 0, 1 }
});
};
/// <summary>
/// The vertical gradient operator.
/// </summary>
private static readonly Fast2DArray<float> PrewittY =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 1, 1, 1 },
{ 0, 0, 0 },
{ -1, -1, -1 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="PrewittProcessor{TColor}"/> class.

8
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs

@ -21,21 +21,21 @@ namespace ImageSharp.Processing.Processors
/// The horizontal gradient operator.
/// </summary>
private static readonly Fast2DArray<float> RobertsCrossX =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 1, 0 },
{ 0, -1 }
});
};
/// <summary>
/// The vertical gradient operator.
/// </summary>
private static readonly Fast2DArray<float> RobertsCrossY =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 1 },
{ -1, 0 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="RobertsCrossProcessor{TColor}"/> class.

32
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs

@ -21,89 +21,89 @@ namespace ImageSharp.Processing.Processors
/// The North gradient operator
/// </summary>
private static readonly Fast2DArray<float> RobinsonNorth =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 1, 2, 1 },
{ 0, 0, 0 },
{ -1, -2, -1 }
});
};
/// <summary>
/// The NorthWest gradient operator
/// </summary>
private static readonly Fast2DArray<float> RobinsonNorthWest =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 2, 1, 0 },
{ 1, 0, -1 },
{ 0, -1, -2 }
});
};
/// <summary>
/// The West gradient operator
/// </summary>
private static readonly Fast2DArray<float> RobinsonWest =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 1, 0, -1 },
{ 2, 0, -2 },
{ 1, 0, -1 }
});
};
/// <summary>
/// The SouthWest gradient operator
/// </summary>
private static readonly Fast2DArray<float> RobinsonSouthWest =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, -1, -2 },
{ 1, 0, -1 },
{ 2, 1, 0 }
});
};
/// <summary>
/// The South gradient operator
/// </summary>
private static readonly Fast2DArray<float> RobinsonSouth =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -1, -2, -1 },
{ 0, 0, 0 },
{ 1, 2, 1 }
});
};
/// <summary>
/// The SouthEast gradient operator
/// </summary>
private static readonly Fast2DArray<float> RobinsonSouthEast =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -2, -1, 0 },
{ -1, 0, 1 },
{ 0, 1, 2 }
});
};
/// <summary>
/// The East gradient operator
/// </summary>
private static readonly Fast2DArray<float> RobinsonEast =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -1, 0, 1 },
{ -2, 0, 2 },
{ -1, 0, 1 }
});
};
/// <summary>
/// The NorthEast gradient operator
/// </summary>
private static readonly Fast2DArray<float> RobinsonNorthEast =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 1, 2 },
{ -1, 0, 1 },
{ -2, -1, 0 }
});
};
/// <inheritdoc/>
public override Fast2DArray<float> North => RobinsonNorth;

8
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs

@ -21,23 +21,23 @@ namespace ImageSharp.Processing.Processors
/// The horizontal gradient operator.
/// </summary>
private static readonly Fast2DArray<float> ScharrX =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -3, 0, 3 },
{ -10, 0, 10 },
{ -3, 0, 3 }
});
};
/// <summary>
/// The vertical gradient operator.
/// </summary>
private static readonly Fast2DArray<float> ScharrY =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 3, 10, 3 },
{ 0, 0, 0 },
{ -3, -10, -3 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="ScharrProcessor{TColor}"/> class.

8
src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs

@ -21,23 +21,23 @@ namespace ImageSharp.Processing.Processors
/// The horizontal gradient operator.
/// </summary>
private static readonly Fast2DArray<float> SobelX =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -1, 0, 1 },
{ -2, 0, 2 },
{ -1, 0, 1 }
});
};
/// <summary>
/// The vertical gradient operator.
/// </summary>
private static readonly Fast2DArray<float> SobelY =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ -1, -2, -1 },
{ 0, 0, 0 },
{ 1, 2, 1 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="SobelProcessor{TColor}"/> class.

4
src/ImageSharp.Processing/Processors/Convolution/GaussianBlurProcessor.cs

@ -94,8 +94,8 @@ namespace ImageSharp.Processing.Processors
int size = this.kernelSize;
float weight = this.sigma;
Fast2DArray<float> kernel = horizontal
? new Fast2DArray<float>(new float[1, size])
: new Fast2DArray<float>(new float[size, 1]);
? new Fast2DArray<float>(size, 1)
: new Fast2DArray<float>(1, size);
float sum = 0F;
float midpoint = (size - 1) / 2F;

4
src/ImageSharp.Processing/Processors/Convolution/GaussianSharpenProcessor.cs

@ -96,8 +96,8 @@ namespace ImageSharp.Processing.Processors
int size = this.kernelSize;
float weight = this.sigma;
Fast2DArray<float> kernel = horizontal
? new Fast2DArray<float>(new float[1, size])
: new Fast2DArray<float>(new float[size, 1]);
? new Fast2DArray<float>(size, 1)
: new Fast2DArray<float>(1, size);
float sum = 0;

29
src/ImageSharp/Common/Memory/Fast2DArray{T}.cs

@ -30,6 +30,22 @@ namespace ImageSharp
/// </summary>
public int Height;
/// <summary>
/// Initializes a new instance of the <see cref="Fast2DArray{T}" /> struct.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
public Fast2DArray(int width, int height)
{
this.Height = height;
this.Width = width;
Guard.MustBeGreaterThan(width, 0, nameof(width));
Guard.MustBeGreaterThan(height, 0, nameof(height));
this.Data = new T[this.Width * this.Height];
}
/// <summary>
/// Initializes a new instance of the <see cref="Fast2DArray{T}"/> struct.
/// </summary>
@ -77,6 +93,19 @@ namespace ImageSharp
}
}
/// <summary>
/// Performs an implicit conversion from a 2D array to a <see cref="ImageSharp.Fast2DArray{T}" />.
/// </summary>
/// <param name="data">The source array.</param>
/// <returns>
/// The <see cref="ImageSharp.Fast2DArray{T}"/> represenation on the source data.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Fast2DArray<T>(T[,] data)
{
return new Fast2DArray<T>(data);
}
/// <summary>
/// Checks the coordinates to ensure they are within bounds.
/// </summary>

4
src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs

@ -15,12 +15,12 @@ namespace ImageSharp.Dithering
/// The diffusion matrix
/// </summary>
private static readonly Fast2DArray<float> AtkinsonMatrix =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 0, 1, 1 },
{ 1, 1, 1, 0 },
{ 0, 1, 0, 0 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="Atkinson"/> class.

4
src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs

@ -15,11 +15,11 @@ namespace ImageSharp.Dithering
/// The diffusion matrix
/// </summary>
private static readonly Fast2DArray<float> BurksMatrix =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 0, 0, 8, 4 },
{ 2, 4, 8, 4, 2 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="Burks"/> class.

4
src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs

@ -15,11 +15,11 @@ namespace ImageSharp.Dithering
/// The diffusion matrix
/// </summary>
private static readonly Fast2DArray<float> FloydSteinbergMatrix =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 0, 7 },
{ 3, 5, 1 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="FloydSteinberg"/> class.

4
src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs

@ -15,12 +15,12 @@ namespace ImageSharp.Dithering
/// The diffusion matrix
/// </summary>
private static readonly Fast2DArray<float> JarvisJudiceNinkeMatrix =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 0, 0, 7, 5 },
{ 3, 5, 7, 5, 3 },
{ 1, 3, 5, 3, 1 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="JarvisJudiceNinke"/> class.

4
src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs

@ -15,11 +15,11 @@ namespace ImageSharp.Dithering
/// The diffusion matrix
/// </summary>
private static readonly Fast2DArray<float> Sierra2Matrix =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 0, 0, 4, 3 },
{ 1, 2, 3, 2, 1 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="Sierra2"/> class.

4
src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs

@ -15,12 +15,12 @@ namespace ImageSharp.Dithering
/// The diffusion matrix
/// </summary>
private static readonly Fast2DArray<float> Sierra3Matrix =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 0, 0, 5, 3 },
{ 2, 4, 5, 4, 2 },
{ 0, 2, 3, 2, 0 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="Sierra3"/> class.

4
src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs

@ -15,11 +15,11 @@ namespace ImageSharp.Dithering
/// The diffusion matrix
/// </summary>
private static readonly Fast2DArray<float> SierraLiteMatrix =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 0, 2 },
{ 1, 1, 0 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="SierraLite"/> class.

4
src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs

@ -15,12 +15,12 @@ namespace ImageSharp.Dithering
/// The diffusion matrix
/// </summary>
private static readonly Fast2DArray<float> StuckiMatrix =
new Fast2DArray<float>(new float[,]
new float[,]
{
{ 0, 0, 0, 8, 4 },
{ 2, 4, 8, 4, 2 },
{ 1, 2, 4, 2, 1 }
});
};
/// <summary>
/// Initializes a new instance of the <see cref="Stucki"/> class.

4
src/ImageSharp/Dithering/Ordered/Bayer.cs

@ -18,13 +18,13 @@ namespace ImageSharp.Dithering.Ordered
/// This is calculated by multiplying each value in the original matrix by 16 and subtracting 1
/// </summary>
private static readonly Fast2DArray<byte> ThresholdMatrix =
new Fast2DArray<byte>(new byte[,]
new byte[,]
{
{ 15, 143, 47, 175 },
{ 207, 79, 239, 111 },
{ 63, 191, 31, 159 },
{ 255, 127, 223, 95 }
});
};
/// <inheritdoc />
public Fast2DArray<byte> Matrix { get; } = ThresholdMatrix;

4
src/ImageSharp/Dithering/Ordered/Ordered.cs

@ -18,13 +18,13 @@ namespace ImageSharp.Dithering.Ordered
/// This is calculated by multiplying each value in the original matrix by 16
/// </summary>
private static readonly Fast2DArray<byte> ThresholdMatrix =
new Fast2DArray<byte>(new byte[,]
new byte[,]
{
{ 0, 128, 32, 160 },
{ 192, 64, 224, 96 },
{ 48, 176, 16, 144 },
{ 240, 112, 208, 80 }
});
};
/// <inheritdoc />
public Fast2DArray<byte> Matrix { get; } = ThresholdMatrix;

28
tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs

@ -21,9 +21,27 @@ namespace ImageSharp.Tests.Common
public void Fast2DArrayThrowsOnNullInitializer()
{
Assert.Throws<ArgumentNullException>(() =>
{
Fast2DArray<float> fast = new Fast2DArray<float>(null);
});
{
Fast2DArray<float> fast = new Fast2DArray<float>(null);
});
}
[Fact]
public void Fast2DArrayThrowsOnEmptyZeroWidth()
{
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
Fast2DArray<float> fast = new Fast2DArray<float>(0, 10);
});
}
[Fact]
public void Fast2DArrayThrowsOnEmptyZeroHeight()
{
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
Fast2DArray<float> fast = new Fast2DArray<float>(10, 0);
});
}
[Fact]
@ -46,7 +64,7 @@ namespace ImageSharp.Tests.Common
[Fact]
public void Fast2DArrayGetReturnsCorrectResults()
{
Fast2DArray<float> fast = new Fast2DArray<float>(FloydSteinbergMatrix);
Fast2DArray<float> fast = FloydSteinbergMatrix;
for (int row = 0; row < fast.Height; row++)
{
@ -60,7 +78,7 @@ namespace ImageSharp.Tests.Common
[Fact]
public void Fast2DArrayGetSetReturnsCorrectResults()
{
Fast2DArray<float> fast = new Fast2DArray<float>(new float[4, 4]);
Fast2DArray<float> fast = new Fast2DArray<float>(4, 4);
const float Val = 5F;
fast[3, 3] = Val;

Loading…
Cancel
Save