Browse Source

Add parallel options

Former-commit-id: a81f9393544d2c2fac2a4ebe247dc83cc27a3934
Former-commit-id: 098166601a68b3b8d34f5e8206aea51ed02f82aa
Former-commit-id: c5b423b967d17e571d9bc6b1918f7414eddde44e
pull/1/head
James Jackson-South 10 years ago
parent
commit
c8aeebeb1f
  1. 6
      src/ImageProcessorCore/Bootstrapper.cs
  2. 7
      src/ImageProcessorCore/Image/IImageProcessor.cs
  3. 4
      src/ImageProcessorCore/ImageProcessor.cs
  4. 3
      src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs

6
src/ImageProcessorCore/Bootstrapper.cs

@ -10,6 +10,7 @@ namespace ImageProcessorCore
using System.Collections.ObjectModel;
using ImageProcessorCore.Formats;
using System.Threading.Tasks;
/// <summary>
/// Provides initialization code which allows extending the library.
@ -58,6 +59,11 @@ namespace ImageProcessorCore
/// </summary>
public IReadOnlyCollection<IImageFormat> ImageFormats => new ReadOnlyCollection<IImageFormat>(this.imageFormats);
/// <summary>
/// Gets or sets the global parallel options for processing tasks in parallel.
/// </summary>
public ParallelOptions ParallelOptions { get; set; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
/// <summary>
/// Adds a new <see cref="IImageFormat"/> to the collection of supported image formats.
/// </summary>

7
src/ImageProcessorCore/Image/IImageProcessor.cs

@ -3,6 +3,8 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Threading.Tasks;
namespace ImageProcessorCore.Processors
{
/// <summary>
@ -26,6 +28,11 @@ namespace ImageProcessorCore.Processors
/// </remarks>
event ProgressEventHandler OnProgress;
/// <summary>
/// Gets or sets the global parallel options for processing tasks in parallel.
/// </summary>
ParallelOptions ParallelOptions { get; set; }
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{T, TP}"/>.
/// </summary>

4
src/ImageProcessorCore/ImageProcessor.cs

@ -7,6 +7,7 @@ namespace ImageProcessorCore.Processors
{
using System;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Allows the application of processors to images.
@ -26,6 +27,9 @@ namespace ImageProcessorCore.Processors
/// </summary>
private int totalRows;
/// <inheritdoc/>
public virtual ParallelOptions ParallelOptions { get; set; } = Bootstrapper.Instance.ParallelOptions;
/// <inheritdoc/>
public void Apply<T, TP>(ImageBase<T, TP> target, ImageBase<T, TP> source, Rectangle sourceRectangle)
where T : IPackedVector<TP>, new()

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

@ -84,6 +84,7 @@ namespace ImageProcessorCore.Processors
Parallel.For(
startY,
endY,
this.ParallelOptions,
y =>
{
if (targetY <= y && y < targetBottom)
@ -122,6 +123,7 @@ namespace ImageProcessorCore.Processors
Parallel.For(
0,
sourceHeight,
this.ParallelOptions,
y =>
{
for (int x = startX; x < endX; x++)
@ -160,6 +162,7 @@ namespace ImageProcessorCore.Processors
Parallel.For(
startY,
endY,
this.ParallelOptions,
y =>
{
if (y >= 0 && y < height)

Loading…
Cancel
Save