Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ImageSharp/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net.Http;
using SixLabors.ImageSharp.Formats;
Expand Down Expand Up @@ -78,7 +79,7 @@ public int MaxDegreeOfParallelism
/// Gets a set of properties for the Congiguration.
/// </summary>
/// <remarks>This can be used for storing global settings and defaults to be accessable to processors.</remarks>
public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>();
public IDictionary<object, object> Properties { get; } = new ConcurrentDictionary<object, object>();

/// <summary>
/// Gets the currently registered <see cref="IImageFormat"/>s.
Expand Down
4 changes: 1 addition & 3 deletions src/ImageSharp/GraphicOptionsDefaultsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ public static GraphicsOptions GetGraphicsOptions(this IImageProcessingContext co
return go;
}

var configOptions = context.Configuration.GetGraphicsOptions();

// do not cache the fall back to config into the the processing context
// in case someone want to change the value on the config and expects it re trflow thru
return configOptions;
return context.Configuration.GetGraphicsOptions();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.Collections.Concurrent;
using System.Collections.Generic;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
Expand Down Expand Up @@ -41,7 +42,7 @@ public DefaultImageProcessorContext(Configuration configuration, Image<TPixel> s
public Configuration Configuration { get; }

/// <inheritdoc/>
public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>();
public IDictionary<object, object> Properties { get; } = new ConcurrentDictionary<object, object>();

/// <inheritdoc/>
public Image<TPixel> GetResultImage()
Expand Down
15 changes: 15 additions & 0 deletions tests/ImageSharp.Tests/GraphicOptionsDefaultsExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.Threading.Tasks;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit;
Expand Down Expand Up @@ -168,5 +170,18 @@ public void GetDefaultOptionsFromProcessingContext_IgnoreIncorectlyTypesDictionE
Assert.NotNull(options);
Assert.IsType<GraphicsOptions>(options);
}

[Theory]
[WithBlankImages(100, 100, PixelTypes.Rgba32)]
public void CanGetGraphicsOptionsMultiThreaded<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
// Could not get fake operations to trigger #1230 so using a real image.
Parallel.For(0, 10, _ =>
{
using Image<TPixel> image = provider.GetImage();
image.Mutate(x => x.BackgroundColor(Color.White));
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using SixLabors.ImageSharp.PixelFormats;
Expand Down Expand Up @@ -56,7 +57,7 @@ public FakeImageOperations(Configuration configuration, Image<TPixel> source, bo

public Configuration Configuration { get; }

public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>();
public IDictionary<object, object> Properties { get; } = new ConcurrentDictionary<object, object>();

public Image<TPixel> GetResultImage()
{
Expand Down