Browse Source

Flatten namespace [skip ci]

Former-commit-id: 16779a3ac82e4d9ca67d4b9dd318b443c12e0949
Former-commit-id: fd491dea8ad3366ca25c6f7cf0760addadb6f2d4
Former-commit-id: 1c04febd3c3b9e84f4ea724707caacca73237b40
af/merge-core
James Jackson-South 10 years ago
parent
commit
7835f9eaaa
  1. 1
      src/ImageProcessorCore/Filters/Binarization/Threshold.cs
  2. 1
      src/ImageProcessorCore/ImageExtensions.cs
  3. 4
      src/ImageProcessorCore/Samplers/Crop.cs
  4. 4
      src/ImageProcessorCore/Samplers/EntropyCrop.cs
  5. 2
      src/ImageProcessorCore/Samplers/Pad.cs
  6. 6
      src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs
  7. 10
      src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs
  8. 2
      src/ImageProcessorCore/Samplers/Processors/IImageSampler.cs
  9. 2
      src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs
  10. 186
      src/ImageProcessorCore/Samplers/Processors/Resampler.cs
  11. 172
      src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs
  12. 10
      src/ImageProcessorCore/Samplers/Processors/RotateFlip.cs
  13. 8
      src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs
  14. 8
      src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs
  15. 4
      src/ImageProcessorCore/Samplers/Resize.cs
  16. 4
      src/ImageProcessorCore/Samplers/Rotate.cs
  17. 4
      src/ImageProcessorCore/Samplers/RotateFlip.cs
  18. 4
      src/ImageProcessorCore/Samplers/Skew.cs
  19. 4
      tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

1
src/ImageProcessorCore/Filters/Binarization/Threshold.cs

@ -6,7 +6,6 @@
namespace ImageProcessorCore.Filters
{
using System;
using System.Numerics;
using System.Threading.Tasks;
/// <summary>

1
src/ImageProcessorCore/ImageExtensions.cs

@ -9,7 +9,6 @@ namespace ImageProcessorCore
using System.IO;
using Formats;
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.

4
src/ImageProcessorCore/Samplers/Crop.cs

@ -5,8 +5,6 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
@ -52,7 +50,7 @@ namespace ImageProcessorCore
source = source.Resize(sourceRectangle.Width, sourceRectangle.Height);
}
Crop processor = new Crop();
CropProcessor processor = new CropProcessor();
processor.OnProgress += progressHandler;
try

4
src/ImageProcessorCore/Samplers/EntropyCrop.cs

@ -5,8 +5,6 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
@ -21,7 +19,7 @@ namespace ImageProcessorCore
/// <returns>The <see cref="Image"/></returns>
public static Image EntropyCrop(this Image source, float threshold = .5f, ProgressEventHandler progressHandler = null)
{
EntropyCrop processor = new EntropyCrop(threshold);
EntropyCropProcessor processor = new EntropyCropProcessor(threshold);
processor.OnProgress += progressHandler;
try

2
src/ImageProcessorCore/Samplers/Pad.cs

@ -5,8 +5,6 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>

6
src/ImageProcessorCore/Samplers/Processors/Crop.cs → src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Crop.cs" company="James Jackson-South">
// <copyright file="CropProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
namespace ImageProcessorCore
{
using System.Threading.Tasks;
/// <summary>
/// Provides methods to allow the cropping of an image.
/// </summary>
public class Crop : ImageSampler
public class CropProcessor : ImageSampler
{
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)

10
src/ImageProcessorCore/Samplers/Processors/EntropyCrop.cs → src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs

@ -1,9 +1,9 @@
// <copyright file="EntropyCrop.cs" company="James Jackson-South">
// <copyright file="EntropyCropProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
namespace ImageProcessorCore
{
using System;
using System.Threading.Tasks;
@ -14,7 +14,7 @@ namespace ImageProcessorCore.Processors
/// Provides methods to allow the cropping of an image to preserve areas of highest
/// entropy.
/// </summary>
public class EntropyCrop : ImageSampler
public class EntropyCropProcessor : ImageSampler
{
/// <summary>
/// The rectangle for cropping
@ -22,13 +22,13 @@ namespace ImageProcessorCore.Processors
private Rectangle cropRectangle;
/// <summary>
/// Initializes a new instance of the <see cref="EntropyCrop"/> class.
/// Initializes a new instance of the <see cref="EntropyCropProcessor"/> class.
/// </summary>
/// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param>
/// <exception cref="ArgumentException">
/// <paramref name="threshold"/> is less than 0 or is greater than 1.
/// </exception>
public EntropyCrop(float threshold)
public EntropyCropProcessor(float threshold)
{
Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold));
this.Value = threshold;

2
src/ImageProcessorCore/Samplers/Processors/IImageSampler.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
namespace ImageProcessorCore
{
/// <summary>
/// Acts as a marker for generic parameters that require an image sampler.

2
src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
namespace ImageProcessorCore
{
/// <summary>
/// Applies sampling methods to an image.

186
src/ImageProcessorCore/Samplers/Processors/Resampler.cs

@ -1,186 +0,0 @@
// <copyright file="Resampler.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
using System;
/// <summary>
/// Provides methods that allow the resampling of images using various algorithms.
/// <see href="http://www.realtimerendering.com/resources/GraphicsGems/category.html#Image Processing_link"/>
/// <see href="http://www.realtimerendering.com/resources/GraphicsGems/gemsiii/filter_rcg.c"/>
/// </summary>
public abstract class Resampler : ImageSampler
{
/// <summary>
/// Initializes a new instance of the <see cref="Resampler"/> class.
/// </summary>
/// <param name="sampler">
/// The sampler to perform the resize operation.
/// </param>
protected Resampler(IResampler sampler)
{
Guard.NotNull(sampler, nameof(sampler));
this.Sampler = sampler;
}
/// <summary>
/// Gets the sampler to perform the resize operation.
/// </summary>
public IResampler Sampler { get; }
/// <summary>
/// Gets or sets the horizontal weights.
/// </summary>
protected Weights[] HorizontalWeights { get; set; }
/// <summary>
/// Gets or sets the vertical weights.
/// </summary>
protected Weights[] VerticalWeights { get; set; }
/// <summary>
/// Computes the weights to apply at each pixel when resizing.
/// </summary>
/// <param name="destinationSize">The destination section size.</param>
/// <param name="sourceSize">The source section size.</param>
/// <returns>
/// The <see cref="T:Weights[]"/>.
/// </returns>
protected Weights[] PrecomputeWeights(int destinationSize, int sourceSize)
{
float scale = (float)destinationSize / sourceSize;
IResampler sampler = this.Sampler;
float radius = sampler.Radius;
double left;
double right;
float weight;
int index;
int sum;
Weights[] result = new Weights[destinationSize];
// When shrinking, broaden the effective kernel support so that we still
// visit every source pixel.
if (scale < 1)
{
float width = radius / scale;
float filterScale = 1 / scale;
// Make the weights slices, one source for each column or row.
for (int i = 0; i < destinationSize; i++)
{
float centre = i / scale;
left = Math.Ceiling(centre - width);
right = Math.Floor(centre + width);
result[i] = new Weights
{
Values = new Weight[(int)(right - left + 1)]
};
for (double j = left; j <= right; j++)
{
weight = sampler.GetValue((float)((centre - j) / filterScale)) / filterScale;
if (j < 0)
{
index = (int)-j;
}
else if (j >= sourceSize)
{
index = (int)((sourceSize - j) + sourceSize - 1);
}
else
{
index = (int)j;
}
sum = (int)result[i].Sum++;
result[i].Values[sum] = new Weight(index, weight);
}
}
}
else
{
// Make the weights slices, one source for each column or row.
for (int i = 0; i < destinationSize; i++)
{
float centre = i / scale;
left = Math.Ceiling(centre - radius);
right = Math.Floor(centre + radius);
result[i] = new Weights
{
Values = new Weight[(int)(right - left + 1)]
};
for (double j = left; j <= right; j++)
{
weight = sampler.GetValue((float)(centre - j));
if (j < 0)
{
index = (int)-j;
}
else if (j >= sourceSize)
{
index = (int)((sourceSize - j) + sourceSize - 1);
}
else
{
index = (int)j;
}
sum = (int)result[i].Sum++;
result[i].Values[sum] = new Weight(index, weight);
}
}
}
return result;
}
/// <summary>
/// Represents the weight to be added to a scaled pixel.
/// </summary>
protected struct Weight
{
/// <summary>
/// Initializes a new instance of the <see cref="Weight"/> struct.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="value">The value.</param>
public Weight(int index, float value)
{
this.Index = index;
this.Value = value;
}
/// <summary>
/// Gets the pixel index.
/// </summary>
public int Index { get; }
/// <summary>
/// Gets the result of the interpolation algorithm.
/// </summary>
public float Value { get; }
}
/// <summary>
/// Represents a collection of weights and their sum.
/// </summary>
protected class Weights
{
/// <summary>
/// Gets or sets the values.
/// </summary>
public Weight[] Values { get; set; }
/// <summary>
/// Gets or sets the sum.
/// </summary>
public float Sum { get; set; }
}
}
}

172
src/ImageProcessorCore/Samplers/Processors/Resize.cs → src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs

@ -1,16 +1,17 @@
// <copyright file="Resize.cs" company="James Jackson-South">
// <copyright file="ResizeProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
namespace ImageProcessorCore
{
using System;
using System.Threading.Tasks;
/// <summary>
/// Provides methods that allow the resizing of images using various algorithms.
/// </summary>
public class Resize : Resampler
public class ResizeProcessor : ImageSampler
{
/// <summary>
/// The image used for storing the first pass pixels.
@ -18,19 +19,36 @@ namespace ImageProcessorCore.Processors
private Image firstPass;
/// <summary>
/// Initializes a new instance of the <see cref="Resize"/> class.
/// Initializes a new instance of the <see cref="ResizeProcessor"/> class.
/// </summary>
/// <param name="sampler">
/// The sampler to perform the resize operation.
/// </param>
public Resize(IResampler sampler)
: base(sampler)
public ResizeProcessor(IResampler sampler)
{
Guard.NotNull(sampler, nameof(sampler));
this.Sampler = sampler;
}
/// <inheritdoc/>
public override int Parallelism { get; set; } = 1;
/// <summary>
/// Gets the sampler to perform the resize operation.
/// </summary>
public IResampler Sampler { get; }
/// <summary>
/// Gets or sets the horizontal weights.
/// </summary>
protected Weights[] HorizontalWeights { get; set; }
/// <summary>
/// Gets or sets the vertical weights.
/// </summary>
protected Weights[] VerticalWeights { get; set; }
/// <inheritdoc/>
protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle)
{
@ -188,5 +206,147 @@ namespace ImageProcessorCore.Processors
// Clean up
this.firstPass?.Dispose();
}
/// <summary>
/// Computes the weights to apply at each pixel when resizing.
/// </summary>
/// <param name="destinationSize">The destination section size.</param>
/// <param name="sourceSize">The source section size.</param>
/// <returns>
/// The <see cref="T:Weights[]"/>.
/// </returns>
protected Weights[] PrecomputeWeights(int destinationSize, int sourceSize)
{
float scale = (float)destinationSize / sourceSize;
IResampler sampler = this.Sampler;
float radius = sampler.Radius;
double left;
double right;
float weight;
int index;
int sum;
Weights[] result = new Weights[destinationSize];
// When shrinking, broaden the effective kernel support so that we still
// visit every source pixel.
if (scale < 1)
{
float width = radius / scale;
float filterScale = 1 / scale;
// Make the weights slices, one source for each column or row.
for (int i = 0; i < destinationSize; i++)
{
float centre = i / scale;
left = Math.Ceiling(centre - width);
right = Math.Floor(centre + width);
result[i] = new Weights
{
Values = new Weight[(int)(right - left + 1)]
};
for (double j = left; j <= right; j++)
{
weight = sampler.GetValue((float)((centre - j) / filterScale)) / filterScale;
if (j < 0)
{
index = (int)-j;
}
else if (j >= sourceSize)
{
index = (int)((sourceSize - j) + sourceSize - 1);
}
else
{
index = (int)j;
}
sum = (int)result[i].Sum++;
result[i].Values[sum] = new Weight(index, weight);
}
}
}
else
{
// Make the weights slices, one source for each column or row.
for (int i = 0; i < destinationSize; i++)
{
float centre = i / scale;
left = Math.Ceiling(centre - radius);
right = Math.Floor(centre + radius);
result[i] = new Weights
{
Values = new Weight[(int)(right - left + 1)]
};
for (double j = left; j <= right; j++)
{
weight = sampler.GetValue((float)(centre - j));
if (j < 0)
{
index = (int)-j;
}
else if (j >= sourceSize)
{
index = (int)((sourceSize - j) + sourceSize - 1);
}
else
{
index = (int)j;
}
sum = (int)result[i].Sum++;
result[i].Values[sum] = new Weight(index, weight);
}
}
}
return result;
}
/// <summary>
/// Represents the weight to be added to a scaled pixel.
/// </summary>
protected struct Weight
{
/// <summary>
/// Initializes a new instance of the <see cref="Weight"/> struct.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="value">The value.</param>
public Weight(int index, float value)
{
this.Index = index;
this.Value = value;
}
/// <summary>
/// Gets the pixel index.
/// </summary>
public int Index { get; }
/// <summary>
/// Gets the result of the interpolation algorithm.
/// </summary>
public float Value { get; }
}
/// <summary>
/// Represents a collection of weights and their sum.
/// </summary>
protected class Weights
{
/// <summary>
/// Gets or sets the values.
/// </summary>
public Weight[] Values { get; set; }
/// <summary>
/// Gets or sets the sum.
/// </summary>
public float Sum { get; set; }
}
}
}

10
src/ImageProcessorCore/Samplers/Processors/RotateFlip.cs

@ -1,8 +1,8 @@
// <copyright file="RotateFlip.cs" company="James Jackson-South">
// <copyright file="RotateFlipProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
namespace ImageProcessorCore
{
using System;
using System.Threading.Tasks;
@ -10,14 +10,14 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Provides methods that allow the rotation and flipping of an image around its center point.
/// </summary>
public class RotateFlip : ImageSampler
public class RotateFlipProcessor : ImageSampler
{
/// <summary>
/// Initializes a new instance of the <see cref="RotateFlip"/> class.
/// Initializes a new instance of the <see cref="RotateFlipProcessor"/> class.
/// </summary>
/// <param name="rotateType">The <see cref="RotateType"/> used to perform rotation.</param>
/// <param name="flipType">The <see cref="FlipType"/> used to perform flipping.</param>
public RotateFlip(RotateType rotateType, FlipType flipType)
public RotateFlipProcessor(RotateType rotateType, FlipType flipType)
{
this.RotateType = rotateType;
this.FlipType = flipType;

8
src/ImageProcessorCore/Samplers/Processors/Rotate.cs → src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs

@ -1,9 +1,9 @@
// <copyright file="Rotate.cs" company="James Jackson-South">
// <copyright file="RotateProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
namespace ImageProcessorCore
{
using System.Numerics;
using System.Threading.Tasks;
@ -11,7 +11,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Provides methods that allow the rotating of images.
/// </summary>
public class Rotate : ImageSampler
public class RotateProcessor : ImageSampler
{
/// <summary>
/// The image used for storing the first pass pixels.
@ -83,7 +83,7 @@ namespace ImageProcessorCore.Processors
Rectangle bounds = ResizeHelper.CalculateTargetLocationAndBounds(source, options);
this.firstPass = new Image(rectangle.Width, rectangle.Height);
target.SetPixels(rectangle.Width, rectangle.Height, new float[rectangle.Width * rectangle.Height * 4]);
new Resize(new NearestNeighborResampler()).Apply(this.firstPass, source, rectangle.Width, rectangle.Height, bounds, sourceRectangle);
new ResizeProcessor(new NearestNeighborResampler()).Apply(this.firstPass, source, rectangle.Width, rectangle.Height, bounds, sourceRectangle);
}
else
{

8
src/ImageProcessorCore/Samplers/Processors/Skew.cs → src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs

@ -1,9 +1,9 @@
// <copyright file="Skew.cs" company="James Jackson-South">
// <copyright file="SkewProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
namespace ImageProcessorCore
{
using System.Numerics;
using System.Threading.Tasks;
@ -11,7 +11,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Provides methods that allow the skewing of images.
/// </summary>
public class Skew : ImageSampler
public class SkewProcessor : ImageSampler
{
/// <summary>
/// The image used for storing the first pass pixels.
@ -114,7 +114,7 @@ namespace ImageProcessorCore.Processors
Rectangle bounds = ResizeHelper.CalculateTargetLocationAndBounds(source, options);
this.firstPass = new Image(rectangle.Width, rectangle.Height);
target.SetPixels(rectangle.Width, rectangle.Height, new float[rectangle.Width * rectangle.Height * 4]);
new Resize(new NearestNeighborResampler()).Apply(this.firstPass, source, rectangle.Width, rectangle.Height, bounds, sourceRectangle);
new ResizeProcessor(new NearestNeighborResampler()).Apply(this.firstPass, source, rectangle.Width, rectangle.Height, bounds, sourceRectangle);
}
else
{

4
src/ImageProcessorCore/Samplers/Resize.cs

@ -5,8 +5,6 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
@ -118,7 +116,7 @@ namespace ImageProcessorCore
Guard.MustBeGreaterThan(width, 0, nameof(width));
Guard.MustBeGreaterThan(height, 0, nameof(height));
Resize processor = new Resize(sampler) { Compand = compand };
ResizeProcessor processor = new ResizeProcessor(sampler) { Compand = compand };
processor.OnProgress += progressHandler;
try

4
src/ImageProcessorCore/Samplers/Rotate.cs

@ -5,8 +5,6 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
@ -35,7 +33,7 @@ namespace ImageProcessorCore
/// <returns>The <see cref="Image"/></returns>
public static Image Rotate(this Image source, float degrees, Point center, bool expand, ProgressEventHandler progressHandler = null)
{
Rotate processor = new Rotate { Angle = degrees, Center = center, Expand = expand };
RotateProcessor processor = new RotateProcessor { Angle = degrees, Center = center, Expand = expand };
processor.OnProgress += progressHandler;
try

4
src/ImageProcessorCore/Samplers/RotateFlip.cs

@ -5,8 +5,6 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
@ -22,7 +20,7 @@ namespace ImageProcessorCore
/// <returns>The <see cref="Image"/></returns>
public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType, ProgressEventHandler progressHandler = null)
{
RotateFlip processor = new RotateFlip(rotateType, flipType);
RotateFlipProcessor processor = new RotateFlipProcessor(rotateType, flipType);
processor.OnProgress += progressHandler;
try

4
src/ImageProcessorCore/Samplers/Skew.cs

@ -5,8 +5,6 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
@ -37,7 +35,7 @@ namespace ImageProcessorCore
/// <returns>The <see cref="Image"/></returns>
public static Image Skew(this Image source, float degreesX, float degreesY, Point center, bool expand, ProgressEventHandler progressHandler = null)
{
Skew processor = new Skew { AngleX = degreesX, AngleY = degreesY, Center = center, Expand = expand };
SkewProcessor processor = new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Center = center, Expand = expand };
processor.OnProgress += progressHandler;
try

4
tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

@ -32,8 +32,8 @@
public static readonly TheoryData<string, IImageSampler> Samplers = new TheoryData<string, IImageSampler>
{
{ "Resize", new Resize(new BicubicResampler()) },
{ "Crop", new Crop() }
{ "Resize", new ResizeProcessor(new BicubicResampler()) },
{ "Crop", new CropProcessor() }
};
public static readonly TheoryData<RotateType, FlipType> RotateFlips = new TheoryData<RotateType, FlipType>

Loading…
Cancel
Save