Browse Source

ImageSharp-762: Added methods to pre-seed AoT compiler on iOS

af/merge-core
Dan Manning 8 years ago
parent
commit
5faf9025a6
  1. 19
      src/ImageSharp/Formats/Gif/ImageExtensions.cs
  2. 2
      src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs

19
src/ImageSharp/Formats/Gif/ImageExtensions.cs

@ -5,6 +5,7 @@ using System.IO;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Quantization;
namespace SixLabors.ImageSharp
{
@ -35,5 +36,23 @@ namespace SixLabors.ImageSharp
public static void SaveAsGif<TPixel>(this Image<TPixel> source, Stream stream, GifEncoder encoder)
where TPixel : struct, IPixel<TPixel>
=> source.Save(stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance));
/// <summary>
/// This method doesn't actually do anything but serves an important purpose...
/// If you are running ImageSharp on iOS and try to call SaveAsGif, it will throw an excepion:
/// "Attempting to JIT compile method... OctreeFrameQuantizer.ConstructPalette... while running in aot-only mode."
/// The reason this happens is the SaveAsGif method makes haevy use of generics, which are too confusing for the AoT
/// compiler used on Xamarin.iOS. It spins up the JIT compiler to try and figure it out, but that is an illegal op on
/// iOS so it bombs out.
/// If you are getting the above error, you need to call this method, which will pre-seed the AoT compiler with the
/// necessary methods to complete the SaveAsGif call. That's it, otherwise you should NEVER need this method!!!
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public static void AotCompileOctreeQuantizer<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
var test = new OctreeFrameQuantizer<TPixel>(new OctreeQuantizer(false));
test.AotGetPalette();
}
}
}

2
src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs

@ -136,6 +136,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
}
}
internal TPixel[] AotGetPalette() => this.octree.Palletize(this.colors);
/// <inheritdoc/>
protected override TPixel[] GetPalette() => this.octree.Palletize(this.colors);

Loading…
Cancel
Save