Browse Source

Remove task splitting code.

Former-commit-id: a29d6e26e80dd4c47adfe6dab3cea8b41699165e
Former-commit-id: 5463d0ceda62e577377de3ad9d52d347a830622b
Former-commit-id: b3efff43e573ba7239d5724187cea5ae62f93690
af/merge-core
James Jackson-South 10 years ago
parent
commit
a11d0177e9
  1. 2
      src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs
  2. 2
      src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs
  3. 2
      src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs
  4. 2
      src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs
  5. 2
      src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs
  6. 15
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs
  7. 2
      src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs
  8. 3
      src/ImageProcessorCore/Filters/Processors/Convolution/BoxBlurProcessor.cs
  9. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2DFilter.cs
  10. 43
      src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2PassFilter.cs
  11. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs
  12. 3
      src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs
  13. 3
      src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs
  14. 2
      src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs
  15. 2
      src/ImageProcessorCore/Filters/Processors/InvertProcessor.cs
  16. 7
      src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs
  17. 2
      src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs
  18. 70
      src/ImageProcessorCore/ImageProcessor.cs
  19. 13
      src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs
  20. 2
      src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs
  21. 11
      src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs
  22. 3
      src/ImageProcessorCore/Samplers/Processors/RotateFlipProcessor.cs
  23. 3
      src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs
  24. 3
      src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs

2
src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs

@ -12,7 +12,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// An <see cref="IImageProcessor"/> to change the Alpha of an <see cref="Image"/>.
/// </summary>
public class AlphaProcessor : ParallelImageProcessor
public class AlphaProcessor : ImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="AlphaProcessor"/> class.

2
src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs

@ -11,7 +11,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Sets the background color of the image.
/// </summary>
public class BackgroundColorProcessor : ParallelImageProcessor
public class BackgroundColorProcessor : ImageProcessor
{
/// <summary>
/// The epsilon for comparing floating point numbers.

2
src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs

@ -13,7 +13,7 @@ namespace ImageProcessorCore.Processors
/// <see cref="Image"/>. The image will be converted to greyscale before thresholding
/// occurs.
/// </summary>
public class ThresholdProcessor : ParallelImageProcessor
public class ThresholdProcessor : ImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="ThresholdProcessor"/> class.

2
src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs

@ -10,7 +10,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Combines two images together by blending the pixels.
/// </summary>
public class BlendProcessor : ParallelImageProcessor
public class BlendProcessor : ImageProcessor
{
/// <summary>
/// The image to blend.

2
src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs

@ -12,7 +12,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// An <see cref="IImageProcessor"/> to change the brightness of an <see cref="Image"/>.
/// </summary>
public class BrightnessProcessor : ParallelImageProcessor
public class BrightnessProcessor : ImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="BrightnessProcessor"/> class.

15
src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs

@ -11,7 +11,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// The color matrix filter.
/// </summary>
public abstract class ColorMatrixFilter : ParallelImageProcessor, IColorMatrixFilter
public abstract class ColorMatrixFilter : ImageProcessor, IColorMatrixFilter
{
/// <inheritdoc/>
public abstract Matrix4x4 Matrix { get; }
@ -22,8 +22,6 @@ namespace ImageProcessorCore.Processors
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Matrix4x4 matrix = this.Matrix;
@ -36,15 +34,12 @@ namespace ImageProcessorCore.Processors
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
for (int x = startX; x < endX; x++)
{
for (int x = startX; x < endX; x++)
{
targetPixels[x, y] = this.ApplyMatrix(sourcePixels[x, y], matrix);
}
this.OnRowProcessed();
targetPixels[x, y] = this.ApplyMatrix(sourcePixels[x, y], matrix);
}
this.OnRowProcessed();
});
}
}

2
src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs

@ -12,7 +12,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// An <see cref="IImageProcessor"/> to change the contrast of an <see cref="Image"/>.
/// </summary>
public class ContrastProcessor : ParallelImageProcessor
public class ContrastProcessor : ImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="ContrastProcessor"/> class.

3
src/ImageProcessorCore/Filters/Processors/Convolution/BoxBlurProcessor.cs

@ -42,9 +42,6 @@ namespace ImageProcessorCore.Processors
/// <inheritdoc/>
public override float[,] KernelY => this.kernelY;
/// <inheritdoc/>
public override int Parallelism => 1;
/// <inheritdoc/>
protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle)
{

2
src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2DFilter.cs

@ -11,7 +11,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Defines a filter that uses two one-dimensional matrices to perform convolution against an image.
/// </summary>
public abstract class Convolution2DFilter : ParallelImageProcessor
public abstract class Convolution2DFilter : ImageProcessor
{
/// <summary>
/// Gets the horizontal gradient operator.

43
src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2PassFilter.cs

@ -10,7 +10,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Defines a filter that uses two one-dimensional matrices to perform two-pass convolution against an image.
/// </summary>
public abstract class Convolution2PassFilter : ParallelImageProcessor
public abstract class Convolution2PassFilter : ImageProcessor
{
/// <summary>
/// Gets the horizontal gradient operator.
@ -64,7 +64,6 @@ namespace ImageProcessorCore.Processors
int radiusY = kernelHeight >> 1;
int radiusX = kernelWidth >> 1;
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
@ -79,36 +78,34 @@ namespace ImageProcessorCore.Processors
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
for (int x = startX; x < endX; x++)
{
for (int x = startX; x < endX; x++)
{
Color destination = new Color();
Color destination = new Color();
// Apply each matrix multiplier to the color components for each pixel.
for (int fy = 0; fy < kernelHeight; fy++)
{
int fyr = fy - radiusY;
int offsetY = y + fyr;
// Apply each matrix multiplier to the color components for each pixel.
for (int fy = 0; fy < kernelHeight; fy++)
{
int fyr = fy - radiusY;
int offsetY = y + fyr;
offsetY = offsetY.Clamp(0, maxY);
offsetY = offsetY.Clamp(0, maxY);
for (int fx = 0; fx < kernelWidth; fx++)
{
int fxr = fx - radiusX;
int offsetX = x + fxr;
for (int fx = 0; fx < kernelWidth; fx++)
{
int fxr = fx - radiusX;
int offsetX = x + fxr;
offsetX = offsetX.Clamp(0, maxX);
offsetX = offsetX.Clamp(0, maxX);
Color currentColor = sourcePixels[offsetX, offsetY];
destination += kernel[fy, fx] * currentColor;
}
Color currentColor = sourcePixels[offsetX, offsetY];
destination += kernel[fy, fx] * currentColor;
}
targetPixels[x, y] = destination;
}
this.OnRowProcessed();
targetPixels[x, y] = destination;
}
this.OnRowProcessed();
});
}
}

2
src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs

@ -10,7 +10,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Defines a filter that uses a 2 dimensional matrix to perform convolution against an image.
/// </summary>
public abstract class ConvolutionFilter : ParallelImageProcessor
public abstract class ConvolutionFilter : ImageProcessor
{
/// <summary>
/// Gets the 2d gradient operator.

3
src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs

@ -76,9 +76,6 @@ namespace ImageProcessorCore.Processors
/// <inheritdoc/>
public override float[,] KernelY => this.kernelY;
/// <inheritdoc/>
public override int Parallelism => 1;
/// <inheritdoc/>
protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle)
{

3
src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs

@ -78,9 +78,6 @@ namespace ImageProcessorCore.Processors
/// <inheritdoc/>
public override float[,] KernelY => this.kernelY;
/// <inheritdoc/>
public override int Parallelism => 1;
/// <inheritdoc/>
protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle)
{

2
src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs

@ -12,7 +12,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Creates a glow effect on the image
/// </summary>
public class GlowProcessor : ParallelImageProcessor
public class GlowProcessor : ImageProcessor
{
/// <summary>
/// Gets or sets the glow color to apply.

2
src/ImageProcessorCore/Filters/Processors/InvertProcessor.cs

@ -11,7 +11,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// An <see cref="IImageProcessor"/> to invert the colors of an <see cref="Image"/>.
/// </summary>
public class InvertProcessor : ParallelImageProcessor
public class InvertProcessor : ImageProcessor
{
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)

7
src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs

@ -12,7 +12,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// An <see cref="IImageProcessor"/> to invert the colors of an <see cref="Image"/>.
/// </summary>
public class PixelateProcessor : ParallelImageProcessor
public class PixelateProcessor : ImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="PixelateProcessor"/> class.
@ -27,9 +27,6 @@ namespace ImageProcessorCore.Processors
this.Value = size;
}
/// <inheritdoc/>
public override int Parallelism { get; set; } = 1;
/// <summary>
/// Gets or the pixel size.
/// </summary>
@ -59,7 +56,6 @@ namespace ImageProcessorCore.Processors
{
for (int x = startX; x < endX; x += size)
{
int offsetX = offset;
int offsetY = offset;
@ -88,6 +84,7 @@ namespace ImageProcessorCore.Processors
}
}
}
this.OnRowProcessed();
}
});

2
src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs

@ -12,7 +12,7 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Creates a vignette effect on the image
/// </summary>
public class VignetteProcessor : ParallelImageProcessor
public class VignetteProcessor : ImageProcessor
{
/// <summary>
/// Gets or sets the vignette color to apply.

70
src/ImageProcessorCore/ParallelImageProcessor.cs → src/ImageProcessorCore/ImageProcessor.cs

@ -1,4 +1,4 @@
// <copyright file="ParallelImageProcessor.cs" company="James Jackson-South">
// <copyright file="ImageProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -7,21 +7,15 @@ namespace ImageProcessorCore.Processors
{
using System;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Allows the application of processors using parallel processing.
/// Allows the application of processors to images.
/// </summary>
public abstract class ParallelImageProcessor : IImageProcessor
public abstract class ImageProcessor : IImageProcessor
{
/// <inheritdoc/>
public event ProgressEventHandler OnProgress;
/// <summary>
/// Gets or sets the count of workers to run the process in parallel.
/// </summary>
public virtual int Parallelism { get; set; } = Environment.ProcessorCount * 2;
/// <summary>
/// The number of rows processed by a derived class.
/// </summary>
@ -42,34 +36,7 @@ namespace ImageProcessorCore.Processors
this.numRowsProcessed = 0;
this.totalRows = sourceRectangle.Height;
if (this.Parallelism > 1)
{
int partitionCount = this.Parallelism;
Task[] tasks = new Task[partitionCount];
for (int p = 0; p < partitionCount; p++)
{
int current = p;
tasks[p] = Task.Run(
() =>
{
int batchSize = sourceRectangle.Height / partitionCount;
int yStart = sourceRectangle.Y + (current * batchSize);
int yEnd = current == partitionCount - 1
? sourceRectangle.Bottom
: yStart + batchSize;
this.Apply(target, source, target.Bounds, sourceRectangle, yStart, yEnd);
});
}
Task.WaitAll(tasks);
}
else
{
this.Apply(target, source, target.Bounds, sourceRectangle, sourceRectangle.Y, sourceRectangle.Bottom);
}
this.Apply(target, source, target.Bounds, sourceRectangle, sourceRectangle.Y, sourceRectangle.Bottom);
this.AfterApply(target, source, target.Bounds, sourceRectangle);
}
@ -88,6 +55,7 @@ namespace ImageProcessorCore.Processors
float[] pixels = new float[width * height * 4];
target.SetPixels(width, height, pixels);
// Ensure we always have bounds.
if (sourceRectangle == Rectangle.Empty)
{
sourceRectangle = source.Bounds;
@ -101,33 +69,9 @@ namespace ImageProcessorCore.Processors
this.OnApply(target, source, targetRectangle, sourceRectangle);
this.numRowsProcessed = 0;
this.totalRows = targetRectangle.Bottom;
this.totalRows = targetRectangle.Height;
if (this.Parallelism > 1)
{
int partitionCount = this.Parallelism;
Task[] tasks = new Task[partitionCount];
for (int p = 0; p < partitionCount; p++)
{
int current = p;
tasks[p] = Task.Run(() =>
{
int batchSize = targetRectangle.Bottom / partitionCount;
int yStart = current * batchSize;
int yEnd = current == partitionCount - 1 ? targetRectangle.Bottom : yStart + batchSize;
this.Apply(target, source, targetRectangle, sourceRectangle, yStart, yEnd);
});
}
Task.WaitAll(tasks);
}
else
{
this.Apply(target, source, targetRectangle, sourceRectangle, targetRectangle.Y, targetRectangle.Bottom);
}
this.Apply(target, source, targetRectangle, sourceRectangle, targetRectangle.Y, targetRectangle.Bottom);
this.AfterApply(target, source, target.Bounds, sourceRectangle);
}

13
src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs

@ -15,8 +15,6 @@ namespace ImageProcessorCore.Processors
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int targetY = targetRectangle.Y;
int targetBottom = targetRectangle.Bottom;
int startX = targetRectangle.X;
int endX = targetRectangle.Right;
int sourceX = sourceRectangle.X;
@ -30,15 +28,12 @@ namespace ImageProcessorCore.Processors
endY,
y =>
{
if (y >= targetY && y < targetBottom)
for (int x = startX; x < endX; x++)
{
for (int x = startX; x < endX; x++)
{
targetPixels[x, y] = sourcePixels[x + sourceX, y + sourceY];
}
this.OnRowProcessed();
targetPixels[x, y] = sourcePixels[x + sourceX, y + sourceY];
}
this.OnRowProcessed();
});
}
}

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

@ -9,7 +9,7 @@ namespace ImageProcessorCore.Processors
/// Applies sampling methods to an image.
/// All processors requiring resampling or resizing should inherit from this.
/// </summary>
public abstract class ImageSampler : ParallelImageProcessor, IImageSampler
public abstract class ImageSampler : ImageProcessor, IImageSampler
{
/// <inheritdoc/>
public virtual bool Compand { get; set; } = false;

11
src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs

@ -31,9 +31,6 @@ namespace ImageProcessorCore.Processors
this.Sampler = sampler;
}
/// <inheritdoc/>
public override int Parallelism { get; set; } = 1;
/// <summary>
/// Gets the sampler to perform the resize operation.
/// </summary>
@ -62,13 +59,7 @@ namespace ImageProcessorCore.Processors
}
/// <inheritdoc/>
protected override void Apply(
ImageBase target,
ImageBase source,
Rectangle targetRectangle,
Rectangle sourceRectangle,
int startY,
int endY)
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
// Jump out, we'll deal with that later.
if (source.Bounds == target.Bounds && sourceRectangle == targetRectangle)

3
src/ImageProcessorCore/Samplers/Processors/RotateFlipProcessor.cs

@ -34,9 +34,6 @@ namespace ImageProcessorCore.Processors
/// </summary>
public RotateType RotateType { get; }
/// <inheritdoc/>
public override int Parallelism { get; set; } = 1;
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{

3
src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs

@ -18,9 +18,6 @@ namespace ImageProcessorCore.Processors
/// </summary>
private Matrix3x2 processMatrix;
/// <inheritdoc/>
public override int Parallelism { get; set; } = 1;
/// <summary>
/// Gets or sets the angle of processMatrix in degrees.
/// </summary>

3
src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs

@ -18,9 +18,6 @@ namespace ImageProcessorCore.Processors
/// </summary>
private Matrix3x2 processMatrix;
/// <inheritdoc/>
public override int Parallelism { get; set; } = 1;
/// <summary>
/// Gets or sets the angle of rotation along the x-axis in degrees.
/// </summary>

Loading…
Cancel
Save