diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index 2ea456286f..dc0c59e7bf 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -3,12 +3,12 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.IO; using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.ImageSharp.Processing.Processors.Quantization; @@ -27,14 +27,14 @@ namespace SixLabors.ImageSharp.Advanced { static AotCompilerTools() { - System.Runtime.CompilerServices.Unsafe.SizeOf(); - System.Runtime.CompilerServices.Unsafe.SizeOf(); - System.Runtime.CompilerServices.Unsafe.SizeOf(); - System.Runtime.CompilerServices.Unsafe.SizeOf(); - System.Runtime.CompilerServices.Unsafe.SizeOf(); - System.Runtime.CompilerServices.Unsafe.SizeOf(); - System.Runtime.CompilerServices.Unsafe.SizeOf(); - System.Runtime.CompilerServices.Unsafe.SizeOf(); + Unsafe.SizeOf(); + Unsafe.SizeOf(); + Unsafe.SizeOf(); + Unsafe.SizeOf(); + Unsafe.SizeOf(); + Unsafe.SizeOf(); + Unsafe.SizeOf(); + Unsafe.SizeOf(); } /// @@ -90,10 +90,7 @@ namespace SixLabors.ImageSharp.Advanced Unsafe.SizeOf(); - AotCodec(new Formats.Png.PngDecoder(), new Formats.Png.PngEncoder()); - AotCodec(new Formats.Bmp.BmpDecoder(), new Formats.Bmp.BmpEncoder()); - AotCodec(new Formats.Gif.GifDecoder(), new Formats.Gif.GifEncoder()); - AotCodec(new Formats.Jpeg.JpegDecoder(), new Formats.Jpeg.JpegEncoder()); + AotCodecs(); // TODO: Do the discovery work to figure out what works and what doesn't. } @@ -112,11 +109,9 @@ namespace SixLabors.ImageSharp.Advanced private static void AotCompileOctreeQuantizer() where TPixel : unmanaged, IPixel { - using (var test = new OctreeQuantizer(Configuration.Default, new OctreeQuantizer().Options)) - { - var frame = new ImageFrame(Configuration.Default, 1, 1); - test.QuantizeFrame(frame, frame.Bounds()); - } + using var test = new OctreeQuantizer(Configuration.Default, new OctreeQuantizer().Options); + var frame = new ImageFrame(Configuration.Default, 1, 1); + test.QuantizeFrame(frame, frame.Bounds()); } /// @@ -126,11 +121,9 @@ namespace SixLabors.ImageSharp.Advanced private static void AotCompileWuQuantizer() where TPixel : unmanaged, IPixel { - using (var test = new WuQuantizer(Configuration.Default, new WuQuantizer().Options)) - { - var frame = new ImageFrame(Configuration.Default, 1, 1); - test.QuantizeFrame(frame, frame.Bounds()); - } + using var test = new WuQuantizer(Configuration.Default, new WuQuantizer().Options); + var frame = new ImageFrame(Configuration.Default, 1, 1); + test.QuantizeFrame(frame, frame.Bounds()); } /// @@ -140,11 +133,9 @@ namespace SixLabors.ImageSharp.Advanced private static void AotCompilePaletteQuantizer() where TPixel : unmanaged, IPixel { - using (var test = (PaletteQuantizer)new PaletteQuantizer(Array.Empty()).CreatePixelSpecificQuantizer(Configuration.Default)) - { - var frame = new ImageFrame(Configuration.Default, 1, 1); - test.QuantizeFrame(frame, frame.Bounds()); - } + using var test = (PaletteQuantizer)new PaletteQuantizer(Array.Empty()).CreatePixelSpecificQuantizer(Configuration.Default); + var frame = new ImageFrame(Configuration.Default, 1, 1); + test.QuantizeFrame(frame, frame.Bounds()); } /// @@ -167,26 +158,22 @@ namespace SixLabors.ImageSharp.Advanced /// /// This method pre-seeds the decoder and encoder for a given pixel format in the AoT compiler for iOS. /// - /// The image decoder to seed. - /// The image encoder to seed. /// The pixel format. - private static void AotCodec(IImageDecoder decoder, IImageEncoder encoder) + private static void AotCodecs() where TPixel : unmanaged, IPixel { - try + Configuration configuration = Configuration.Default; + ImageFormatManager formatsManager = configuration.ImageFormatsManager; + foreach (IImageFormat imageFormat in configuration.ImageFormats) { - decoder.Decode(Configuration.Default, null); - } - catch - { - } + using var ms = new MemoryStream(); + using (var encoded = new Image(1, 1)) + { + encoded.Save(ms, formatsManager.FindEncoder(imageFormat)); + ms.Position = 0; + } - try - { - encoder.Encode(null, null); - } - catch - { + using var decoded = Image.Load(ms); } }