From 308e02eb2f5940e9c5bbef9c68a62318e654f1a2 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Sat, 8 Dec 2018 13:04:39 +1030 Subject: [PATCH 1/4] Adds more to the AoT compiler. --- src/ImageSharp/Advanced/AotCompilerTools.cs | 41 +++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index 9e7624480d..9f20704cf7 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -1,6 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.Numerics; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.ImageSharp.Processing.Processors.Quantization; @@ -15,6 +18,20 @@ namespace SixLabors.ImageSharp.Advanced /// public static class AotCompilerTools { + /// + /// Seeds the calls. + /// + public static void SeedUnsafe() + { + 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(); + } + /// /// Seeds the compiler using the given pixel format. /// @@ -27,6 +44,13 @@ namespace SixLabors.ImageSharp.Advanced AotCompileWuQuantizer(); AotCompileDithering(); + System.Runtime.CompilerServices.Unsafe.SizeOf(); + + AotDecoder(new Formats.Png.PngDecoder()); + AotDecoder(new Formats.Bmp.BmpDecoder()); + AotDecoder(new Formats.Gif.GifDecoder()); + AotDecoder(new Formats.Jpeg.JpegDecoder()); + // TODO: Do the discovery work to figure out what works and what doesn't. } @@ -99,5 +123,22 @@ namespace SixLabors.ImageSharp.Advanced TPixel pixel = default; test.Dither(new ImageFrame(Configuration.Default, 1, 1), pixel, pixel, 0, 0, 0, 0, 0, 0); } + + /// + /// This method pre-seeds the decoder for a given pixel format in the AoT compiler for iOS. + /// + /// The image decoder to seed.. + /// The pixel format. + private static void AotDecoder(IImageDecoder decoder) + where TPixel : struct, IPixel + { + try + { + decoder.Decode(Configuration.Default, null); + } + catch + { + } + } } } \ No newline at end of file From 83d52d5f79f0f14b57e90346bd40de9012b3b1bc Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Thu, 13 Dec 2018 18:42:16 +1030 Subject: [PATCH 2/4] Seed unsafe calls from the static constructor. --- src/ImageSharp/Advanced/AotCompilerTools.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index 9f20704cf7..c9c0e40146 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -18,10 +18,7 @@ namespace SixLabors.ImageSharp.Advanced /// public static class AotCompilerTools { - /// - /// Seeds the calls. - /// - public static void SeedUnsafe() + static AotCompilerTools() { System.Runtime.CompilerServices.Unsafe.SizeOf(); System.Runtime.CompilerServices.Unsafe.SizeOf(); From 520d181b0dcbb11a5b8226c4d38e1438178599a7 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 14 Dec 2018 20:16:20 +1030 Subject: [PATCH 3/4] AoT seed image encoders as well as decoders --- src/ImageSharp/Advanced/AotCompilerTools.cs | 22 ++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index c9c0e40146..db46ab4ad3 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -43,10 +43,10 @@ namespace SixLabors.ImageSharp.Advanced System.Runtime.CompilerServices.Unsafe.SizeOf(); - AotDecoder(new Formats.Png.PngDecoder()); - AotDecoder(new Formats.Bmp.BmpDecoder()); - AotDecoder(new Formats.Gif.GifDecoder()); - AotDecoder(new Formats.Jpeg.JpegDecoder()); + 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()); // TODO: Do the discovery work to figure out what works and what doesn't. } @@ -122,11 +122,12 @@ namespace SixLabors.ImageSharp.Advanced } /// - /// This method pre-seeds the decoder for a given pixel format in the AoT compiler for iOS. + /// 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 decoder to seed. + /// The image encoder to seed. /// The pixel format. - private static void AotDecoder(IImageDecoder decoder) + private static void AotCodec(IImageDecoder decoder, IImageEncoder encoder) where TPixel : struct, IPixel { try @@ -136,6 +137,13 @@ namespace SixLabors.ImageSharp.Advanced catch { } + try + { + encoder.Encode(null, null); + } + catch + { + } } } } \ No newline at end of file From 50c3d7fd7a41a018a6ea856b2a8c95e285b18284 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 14 Dec 2018 20:38:18 +1030 Subject: [PATCH 4/4] Code sanity --- src/ImageSharp/Advanced/AotCompilerTools.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index db46ab4ad3..eb6991e6a1 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -137,6 +137,7 @@ namespace SixLabors.ImageSharp.Advanced catch { } + try { encoder.Encode(null, null);