diff --git a/src/ImageProcessorCore/Bootstrapper.cs b/src/ImageProcessorCore/Bootstrapper.cs
index 39e97e1100..0f47526b3b 100644
--- a/src/ImageProcessorCore/Bootstrapper.cs
+++ b/src/ImageProcessorCore/Bootstrapper.cs
@@ -10,6 +10,7 @@ namespace ImageProcessorCore
using System.Collections.ObjectModel;
using ImageProcessorCore.Formats;
+ using System.Threading.Tasks;
///
/// Provides initialization code which allows extending the library.
@@ -58,6 +59,11 @@ namespace ImageProcessorCore
///
public IReadOnlyCollection ImageFormats => new ReadOnlyCollection(this.imageFormats);
+ ///
+ /// Gets or sets the global parallel options for processing tasks in parallel.
+ ///
+ public ParallelOptions ParallelOptions { get; set; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
+
///
/// Adds a new to the collection of supported image formats.
///
diff --git a/src/ImageProcessorCore/Image/IImageProcessor.cs b/src/ImageProcessorCore/Image/IImageProcessor.cs
index 4241b88c75..2c3dd50204 100644
--- a/src/ImageProcessorCore/Image/IImageProcessor.cs
+++ b/src/ImageProcessorCore/Image/IImageProcessor.cs
@@ -3,6 +3,8 @@
// Licensed under the Apache License, Version 2.0.
//
+using System.Threading.Tasks;
+
namespace ImageProcessorCore.Processors
{
///
@@ -26,6 +28,11 @@ namespace ImageProcessorCore.Processors
///
event ProgressEventHandler OnProgress;
+ ///
+ /// Gets or sets the global parallel options for processing tasks in parallel.
+ ///
+ ParallelOptions ParallelOptions { get; set; }
+
///
/// Applies the process to the specified portion of the specified .
///
diff --git a/src/ImageProcessorCore/ImageProcessor.cs b/src/ImageProcessorCore/ImageProcessor.cs
index c7c0f4e1b7..211bbd5038 100644
--- a/src/ImageProcessorCore/ImageProcessor.cs
+++ b/src/ImageProcessorCore/ImageProcessor.cs
@@ -7,6 +7,7 @@ namespace ImageProcessorCore.Processors
{
using System;
using System.Threading;
+ using System.Threading.Tasks;
///
/// Allows the application of processors to images.
@@ -26,6 +27,9 @@ namespace ImageProcessorCore.Processors
///
private int totalRows;
+ ///
+ public virtual ParallelOptions ParallelOptions { get; set; } = Bootstrapper.Instance.ParallelOptions;
+
///
public void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle)
where T : IPackedVector, new()
diff --git a/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs
index a01fd92402..3f78ed0bef 100644
--- a/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs
+++ b/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)