// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageProcessorCore { using System; using System.Collections.Generic; using System.Collections.ObjectModel; using ImageProcessorCore.Formats; /// /// Provides initialization code which allows extending the library. /// public class Bootstrapper { /// /// A new instance Initializes a new instance of the class. /// with lazy initialization. /// private static readonly Lazy Lazy = new Lazy(() => new Bootstrapper()); /// /// The default list of supported /// private readonly List imageFormats; private readonly Dictionary> pixelAccessors; /// /// Prevents a default instance of the class from being created. /// private Bootstrapper() { this.imageFormats = new List { new BmpFormat(), //new JpegFormat(), //new PngFormat(), //new GifFormat() }; this.pixelAccessors = new Dictionary> { { typeof(Bgra32), i=> new Bgra32PixelAccessor(i) } }; } /// /// Gets the current bootstrapper instance. /// public static Bootstrapper Instance = Lazy.Value; /// /// Gets the list of supported /// public IReadOnlyCollection ImageFormats => new ReadOnlyCollection(this.imageFormats); /// /// Adds a new to the collection of supported image formats. /// /// The new format to add. public void AddImageFormat(IImageFormat format) { this.imageFormats.Add(format); } /// /// Gets an instance of the correct for the packed vector. /// /// The type of pixel data. /// The image /// The public IPixelAccessor GetPixelAccessor(IImageBase image) where T : IPackedVector, new() { Type packed = typeof(T); if (this.pixelAccessors.ContainsKey(packed)) { return (IPixelAccessor)this.pixelAccessors[packed].Invoke(image); } throw new NotSupportedException($"PixelAccessor cannot be loaded for {packed}:"); } } }