// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Tests { using System; using System.Collections.Concurrent; public abstract partial class TestImageProvider where TColor : struct, IPackedPixel, IEquatable { private class FileProvider : TestImageProvider { private static ConcurrentDictionary> cache = new ConcurrentDictionary>(); private string filePath; public FileProvider(string filePath) { this.filePath = filePath; } public override string SourceFileOrDescription => this.filePath; public override Image GetImage() { var cachedImage = cache.GetOrAdd( this.filePath, fn => { var testFile = TestFile.Create(this.filePath); return this.Factory.CreateImage(testFile.Bytes); }); return new Image(cachedImage); } } } }