Skip to content

Commit 1073959

Browse files
committed
Have AotCompilerTools cache additional methods.
1 parent 65d103e commit 1073959

1 file changed

Lines changed: 348 additions & 0 deletions

File tree

src/ImageSharp/Advanced/AotCompilerTools.cs

Lines changed: 348 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,25 @@
77
using System.Numerics;
88
using System.Runtime.CompilerServices;
99
using SixLabors.ImageSharp.Formats;
10+
using SixLabors.ImageSharp.Formats.Bmp;
11+
using SixLabors.ImageSharp.Formats.Gif;
12+
using SixLabors.ImageSharp.Formats.Jpeg;
1013
using SixLabors.ImageSharp.Formats.Jpeg.Components;
14+
using SixLabors.ImageSharp.Formats.Png;
15+
using SixLabors.ImageSharp.Formats.Tga;
1116
using SixLabors.ImageSharp.PixelFormats;
17+
using SixLabors.ImageSharp.Processing;
18+
using SixLabors.ImageSharp.Processing.Processors;
19+
using SixLabors.ImageSharp.Processing.Processors.Binarization;
20+
using SixLabors.ImageSharp.Processing.Processors.Convolution;
1221
using SixLabors.ImageSharp.Processing.Processors.Dithering;
22+
using SixLabors.ImageSharp.Processing.Processors.Drawing;
23+
using SixLabors.ImageSharp.Processing.Processors.Effects;
24+
using SixLabors.ImageSharp.Processing.Processors.Filters;
25+
using SixLabors.ImageSharp.Processing.Processors.Normalization;
26+
using SixLabors.ImageSharp.Processing.Processors.Overlays;
1327
using SixLabors.ImageSharp.Processing.Processors.Quantization;
28+
using SixLabors.ImageSharp.Processing.Processors.Transforms;
1429

1530
namespace SixLabors.ImageSharp.Advanced
1631
{
@@ -89,6 +104,18 @@ private static void Seed<TPixel>()
89104
AotCompileDithering<TPixel>();
90105
AotCompilePixelOperations<TPixel>();
91106

107+
AotCompileImage<TPixel>();
108+
AotCompileImageProcessingContextFactory<TPixel>();
109+
AotCompileImageEncoderInternals<TPixel>();
110+
AotCompileImageDecoderInternals<TPixel>();
111+
AotCompileImageEncoders<TPixel>();
112+
AotCompileImageDecoders<TPixel>();
113+
AotCompileImageProcessors<TPixel>();
114+
AotCompileGenericImageProcessors<TPixel>();
115+
AotCompileResamplers<TPixel>();
116+
AotCompileQuantizers<TPixel>();
117+
AotCompilePixelSamplingStrategys<TPixel>();
118+
92119
Unsafe.SizeOf<TPixel>();
93120

94121
AotCodecs<TPixel>();
@@ -213,5 +240,326 @@ private static void AotCompilePixelOperations<TPixel>()
213240
var pixelOp = new PixelOperations<TPixel>();
214241
pixelOp.GetPixelBlender(PixelColorBlendingMode.Normal, PixelAlphaCompositionMode.Clear);
215242
}
243+
244+
/// <summary>
245+
/// This method pre-seeds the <see cref="Image{TPixel}"/> for a given pixel format in the AoT compiler.
246+
/// </summary>
247+
/// <typeparam name="TPixel">The pixel format.</typeparam>
248+
private static unsafe void AotCompileImage<TPixel>()
249+
where TPixel : unmanaged, IPixel<TPixel>
250+
{
251+
Image<TPixel> img = default;
252+
img.CloneAs<A8>(default);
253+
img.CloneAs<Argb32>(default);
254+
img.CloneAs<Bgr24>(default);
255+
img.CloneAs<Bgr565>(default);
256+
img.CloneAs<Bgra32>(default);
257+
img.CloneAs<Bgra4444>(default);
258+
img.CloneAs<Bgra5551>(default);
259+
img.CloneAs<Byte4>(default);
260+
img.CloneAs<L16>(default);
261+
img.CloneAs<L8>(default);
262+
img.CloneAs<La16>(default);
263+
img.CloneAs<La32>(default);
264+
img.CloneAs<HalfSingle>(default);
265+
img.CloneAs<HalfVector2>(default);
266+
img.CloneAs<HalfVector4>(default);
267+
img.CloneAs<NormalizedByte2>(default);
268+
img.CloneAs<NormalizedByte4>(default);
269+
img.CloneAs<NormalizedShort2>(default);
270+
img.CloneAs<NormalizedShort4>(default);
271+
img.CloneAs<Rg32>(default);
272+
img.CloneAs<Rgb24>(default);
273+
img.CloneAs<Rgb48>(default);
274+
img.CloneAs<Rgba1010102>(default);
275+
img.CloneAs<Rgba32>(default);
276+
img.CloneAs<Rgba64>(default);
277+
img.CloneAs<RgbaVector>(default);
278+
img.CloneAs<Short2>(default);
279+
img.CloneAs<Short4>(default);
280+
281+
ImageFrame.LoadPixelData<TPixel>(default, default(ReadOnlySpan<TPixel>), default, default);
282+
ImageFrame.LoadPixelData<TPixel>(default, default(ReadOnlySpan<byte>), default, default);
283+
}
284+
285+
private static void AotCompileImageProcessingContextFactory<TPixel>()
286+
where TPixel : unmanaged, IPixel<TPixel>
287+
=> default(DefaultImageOperationsProviderFactory).CreateImageProcessingContext<TPixel>(default, default, default);
288+
289+
/// <summary>
290+
/// This method pre-seeds the all <see cref="IImageEncoderInternals"/> in the AoT compiler.
291+
/// </summary>
292+
/// <typeparam name="TPixel">The pixel format.</typeparam>
293+
private static void AotCompileImageEncoderInternals<TPixel>()
294+
where TPixel : unmanaged, IPixel<TPixel>
295+
{
296+
default(BmpEncoderCore).Encode<TPixel>(default, default, default);
297+
default(GifEncoderCore).Encode<TPixel>(default, default, default);
298+
default(JpegEncoderCore).Encode<TPixel>(default, default, default);
299+
default(PngEncoderCore).Encode<TPixel>(default, default, default);
300+
default(TgaEncoderCore).Encode<TPixel>(default, default, default);
301+
}
302+
303+
/// <summary>
304+
/// This method pre-seeds the all <see cref="IImageDecoderInternals"/> in the AoT compiler.
305+
/// </summary>
306+
/// <typeparam name="TPixel">The pixel format.</typeparam>
307+
private static void AotCompileImageDecoderInternals<TPixel>()
308+
where TPixel : unmanaged, IPixel<TPixel>
309+
{
310+
default(BmpDecoderCore).Decode<TPixel>(default, default, default);
311+
default(GifDecoderCore).Decode<TPixel>(default, default, default);
312+
default(JpegDecoderCore).Decode<TPixel>(default, default, default);
313+
default(PngDecoderCore).Decode<TPixel>(default, default, default);
314+
default(TgaDecoderCore).Decode<TPixel>(default, default, default);
315+
}
316+
317+
/// <summary>
318+
/// This method pre-seeds the all <see cref="IImageEncoder"/> in the AoT compiler.
319+
/// </summary>
320+
/// <typeparam name="TPixel">The pixel format.</typeparam>
321+
private static void AotCompileImageEncoders<TPixel>()
322+
where TPixel : unmanaged, IPixel<TPixel>
323+
{
324+
AotCompileImageEncoder<TPixel, BmpEncoder>();
325+
AotCompileImageEncoder<TPixel, GifEncoder>();
326+
AotCompileImageEncoder<TPixel, JpegEncoder>();
327+
AotCompileImageEncoder<TPixel, PngEncoder>();
328+
AotCompileImageEncoder<TPixel, TgaEncoder>();
329+
}
330+
331+
/// <summary>
332+
/// This method pre-seeds the all <see cref="IImageDecoder"/> in the AoT compiler.
333+
/// </summary>
334+
/// <typeparam name="TPixel">The pixel format.</typeparam>
335+
private static void AotCompileImageDecoders<TPixel>()
336+
where TPixel : unmanaged, IPixel<TPixel>
337+
{
338+
AotCompileImageDecoder<TPixel, BmpDecoder>();
339+
AotCompileImageDecoder<TPixel, GifDecoder>();
340+
AotCompileImageDecoder<TPixel, JpegDecoder>();
341+
AotCompileImageDecoder<TPixel, PngDecoder>();
342+
AotCompileImageDecoder<TPixel, TgaDecoder>();
343+
}
344+
345+
/// <summary>
346+
/// This method pre-seeds the <see cref="IImageEncoder"/> in the AoT compiler.
347+
/// </summary>
348+
/// <typeparam name="TPixel">The pixel format.</typeparam>
349+
/// <typeparam name="TEncoder">The encoder.</typeparam>
350+
private static void AotCompileImageEncoder<TPixel, TEncoder>()
351+
where TPixel : unmanaged, IPixel<TPixel>
352+
where TEncoder : class, IImageEncoder
353+
{
354+
default(TEncoder).Encode<TPixel>(default, default);
355+
default(TEncoder).EncodeAsync<TPixel>(default, default, default);
356+
}
357+
358+
/// <summary>
359+
/// This method pre-seeds the <see cref="IImageDecoder"/> in the AoT compiler.
360+
/// </summary>
361+
/// <typeparam name="TPixel">The pixel format.</typeparam>
362+
/// <typeparam name="TDecoder">The decoder.</typeparam>
363+
private static void AotCompileImageDecoder<TPixel, TDecoder>()
364+
where TPixel : unmanaged, IPixel<TPixel>
365+
where TDecoder : class, IImageDecoder
366+
{
367+
default(TDecoder).Decode<TPixel>(default, default);
368+
default(TDecoder).DecodeAsync<TPixel>(default, default, default);
369+
}
370+
371+
/// <summary>
372+
/// This method pre-seeds the all <see cref="IImageProcessor" /> in the AoT compiler.
373+
/// </summary>
374+
/// <remarks>
375+
/// There is no structure that implements ISwizzler.
376+
/// </remarks>
377+
/// <typeparam name="TPixel">The pixel format.</typeparam>
378+
private static void AotCompileImageProcessors<TPixel>()
379+
where TPixel : unmanaged, IPixel<TPixel>
380+
{
381+
AotCompileImageProcessor<TPixel, CloningImageProcessor>();
382+
AotCompileImageProcessor<TPixel, CropProcessor>();
383+
AotCompileImageProcessor<TPixel, AffineTransformProcessor>();
384+
AotCompileImageProcessor<TPixel, ProjectiveTransformProcessor>();
385+
AotCompileImageProcessor<TPixel, RotateProcessor>();
386+
AotCompileImageProcessor<TPixel, SkewProcessor>();
387+
AotCompileImageProcessor<TPixel, ResizeProcessor>();
388+
AotCompileImageProcessor<TPixel, EntropyCropProcessor>();
389+
AotCompileImageProcessor<TPixel, AutoOrientProcessor>();
390+
AotCompileImageProcessor<TPixel, FlipProcessor>();
391+
AotCompileImageProcessor<TPixel, QuantizeProcessor>();
392+
AotCompileImageProcessor<TPixel, BackgroundColorProcessor>();
393+
AotCompileImageProcessor<TPixel, GlowProcessor>();
394+
AotCompileImageProcessor<TPixel, VignetteProcessor>();
395+
AotCompileImageProcessor<TPixel, AdaptiveHistogramEqualizationProcessor>();
396+
AotCompileImageProcessor<TPixel, AdaptiveHistogramEqualizationSlidingWindowProcessor>();
397+
AotCompileImageProcessor<TPixel, GlobalHistogramEqualizationProcessor>();
398+
AotCompileImageProcessor<TPixel, AchromatomalyProcessor>();
399+
AotCompileImageProcessor<TPixel, AchromatopsiaProcessor>();
400+
AotCompileImageProcessor<TPixel, BlackWhiteProcessor>();
401+
AotCompileImageProcessor<TPixel, BrightnessProcessor>();
402+
AotCompileImageProcessor<TPixel, ContrastProcessor>();
403+
AotCompileImageProcessor<TPixel, DeuteranomalyProcessor>();
404+
AotCompileImageProcessor<TPixel, DeuteranopiaProcessor>();
405+
AotCompileImageProcessor<TPixel, FilterProcessor>();
406+
AotCompileImageProcessor<TPixel, GrayscaleBt601Processor>();
407+
AotCompileImageProcessor<TPixel, GrayscaleBt709Processor>();
408+
AotCompileImageProcessor<TPixel, HueProcessor>();
409+
AotCompileImageProcessor<TPixel, InvertProcessor>();
410+
AotCompileImageProcessor<TPixel, KodachromeProcessor>();
411+
AotCompileImageProcessor<TPixel, LightnessProcessor>();
412+
AotCompileImageProcessor<TPixel, LomographProcessor>();
413+
AotCompileImageProcessor<TPixel, OpacityProcessor>();
414+
AotCompileImageProcessor<TPixel, PolaroidProcessor>();
415+
AotCompileImageProcessor<TPixel, ProtanomalyProcessor>();
416+
AotCompileImageProcessor<TPixel, ProtanopiaProcessor>();
417+
AotCompileImageProcessor<TPixel, SaturateProcessor>();
418+
AotCompileImageProcessor<TPixel, SepiaProcessor>();
419+
AotCompileImageProcessor<TPixel, TritanomalyProcessor>();
420+
AotCompileImageProcessor<TPixel, TritanopiaProcessor>();
421+
AotCompileImageProcessor<TPixel, OilPaintingProcessor>();
422+
AotCompileImageProcessor<TPixel, PixelateProcessor>();
423+
AotCompileImageProcessor<TPixel, PixelRowDelegateProcessor>();
424+
AotCompileImageProcessor<TPixel, PositionAwarePixelRowDelegateProcessor>();
425+
AotCompileImageProcessor<TPixel, DrawImageProcessor>();
426+
AotCompileImageProcessor<TPixel, PaletteDitherProcessor>();
427+
AotCompileImageProcessor<TPixel, BokehBlurProcessor>();
428+
AotCompileImageProcessor<TPixel, BoxBlurProcessor>();
429+
AotCompileImageProcessor<TPixel, EdgeDetector2DProcessor>();
430+
AotCompileImageProcessor<TPixel, EdgeDetectorCompassProcessor>();
431+
AotCompileImageProcessor<TPixel, EdgeDetectorProcessor>();
432+
AotCompileImageProcessor<TPixel, GaussianBlurProcessor>();
433+
AotCompileImageProcessor<TPixel, GaussianSharpenProcessor>();
434+
AotCompileImageProcessor<TPixel, AdaptiveThresholdProcessor>();
435+
AotCompileImageProcessor<TPixel, BinaryThresholdProcessor>();
436+
437+
AotCompilerCloningImageProcessor<TPixel, CloningImageProcessor>();
438+
AotCompilerCloningImageProcessor<TPixel, CropProcessor>();
439+
AotCompilerCloningImageProcessor<TPixel, AffineTransformProcessor>();
440+
AotCompilerCloningImageProcessor<TPixel, ProjectiveTransformProcessor>();
441+
AotCompilerCloningImageProcessor<TPixel, RotateProcessor>();
442+
AotCompilerCloningImageProcessor<TPixel, SkewProcessor>();
443+
AotCompilerCloningImageProcessor<TPixel, ResizeProcessor>();
444+
}
445+
446+
/// <summary>
447+
/// This method pre-seeds the <see cref="IImageProcessor" /> in the AoT compiler.
448+
/// </summary>
449+
/// <typeparam name="TPixel">The pixel format.</typeparam>
450+
/// <typeparam name="TProc">The processor type</typeparam>
451+
private static void AotCompileImageProcessor<TPixel, TProc>()
452+
where TPixel : unmanaged, IPixel<TPixel>
453+
where TProc : class, IImageProcessor
454+
=> default(TProc).CreatePixelSpecificProcessor<TPixel>(default, default, default);
455+
456+
/// <summary>
457+
/// This method pre-seeds the <see cref="ICloningImageProcessor" /> in the AoT compiler.
458+
/// </summary>
459+
/// <typeparam name="TPixel">The pixel format.</typeparam>
460+
/// <typeparam name="TProc">The processor type</typeparam>
461+
private static void AotCompilerCloningImageProcessor<TPixel, TProc>()
462+
where TPixel : unmanaged, IPixel<TPixel>
463+
where TProc : class, ICloningImageProcessor
464+
=> default(TProc).CreatePixelSpecificCloningProcessor<TPixel>(default, default, default);
465+
466+
/// <summary>
467+
/// This method pre-seeds the all <see cref="IImageProcessor"/> in the AoT compiler.
468+
/// </summary>
469+
/// <remarks>
470+
/// There is no structure that implements ISwizzler.
471+
/// </remarks>
472+
/// <typeparam name="TPixel">The pixel format.</typeparam>
473+
private static void AotCompileGenericImageProcessors<TPixel>()
474+
where TPixel : unmanaged, IPixel<TPixel>
475+
{
476+
AotCompileGenericCloningImageProcessor<TPixel, CropProcessor<TPixel>>();
477+
AotCompileGenericCloningImageProcessor<TPixel, AffineTransformProcessor<TPixel>>();
478+
AotCompileGenericCloningImageProcessor<TPixel, ProjectiveTransformProcessor<TPixel>>();
479+
AotCompileGenericCloningImageProcessor<TPixel, ResizeProcessor<TPixel>>();
480+
AotCompileGenericCloningImageProcessor<TPixel, RotateProcessor<TPixel>>();
481+
}
482+
483+
/// <summary>
484+
/// This method pre-seeds the <see cref="ICloningImageProcessor{TPixel}" /> in the AoT compiler.
485+
/// </summary>
486+
/// <typeparam name="TPixel">The pixel format.</typeparam>
487+
/// <typeparam name="TProc">The processor type</typeparam>
488+
private static void AotCompileGenericCloningImageProcessor<TPixel, TProc>()
489+
where TPixel : unmanaged, IPixel<TPixel>
490+
where TProc : class, ICloningImageProcessor<TPixel>
491+
=> default(TProc).CloneAndExecute();
492+
493+
/// <summary>
494+
/// This method pre-seeds the all<see cref="IResampler" /> in the AoT compiler.
495+
/// </summary>
496+
/// <typeparam name="TPixel">The pixel format.</typeparam>
497+
private static void AotCompileResamplers<TPixel>()
498+
where TPixel : unmanaged, IPixel<TPixel>
499+
{
500+
AotCompileResampler<TPixel, BicubicResampler>();
501+
AotCompileResampler<TPixel, BoxResampler>();
502+
AotCompileResampler<TPixel, CubicResampler>();
503+
AotCompileResampler<TPixel, LanczosResampler>();
504+
AotCompileResampler<TPixel, NearestNeighborResampler>();
505+
AotCompileResampler<TPixel, TriangleResampler>();
506+
AotCompileResampler<TPixel, WelchResampler>();
507+
}
508+
509+
/// <summary>
510+
/// This method pre-seeds the <see cref="IResampler" /> in the AoT compiler.
511+
/// </summary>
512+
/// <typeparam name="TPixel">The pixel format.</typeparam>
513+
/// <typeparam name="TResampler">The processor type</typeparam>
514+
private static void AotCompileResampler<TPixel, TResampler>()
515+
where TPixel : unmanaged, IPixel<TPixel>
516+
where TResampler : struct, IResampler
517+
{
518+
default(TResampler).ApplyTransform<TPixel>(default);
519+
520+
default(AffineTransformProcessor<TPixel>).ApplyTransform<TResampler>(default);
521+
default(ProjectiveTransformProcessor<TPixel>).ApplyTransform<TResampler>(default);
522+
default(ResizeProcessor<TPixel>).ApplyTransform<TResampler>(default);
523+
default(RotateProcessor<TPixel>).ApplyTransform<TResampler>(default);
524+
}
525+
526+
/// <summary>
527+
/// This method pre-seeds the all <see cref="IQuantizer" /> in the AoT compiler.
528+
/// </summary>
529+
/// <typeparam name="TPixel">The pixel format.</typeparam>
530+
private static void AotCompileQuantizers<TPixel>()
531+
where TPixel : unmanaged, IPixel<TPixel>
532+
{
533+
AotCompileQuantizer<TPixel, OctreeQuantizer>();
534+
AotCompileQuantizer<TPixel, PaletteQuantizer>();
535+
AotCompileQuantizer<TPixel, WebSafePaletteQuantizer>();
536+
AotCompileQuantizer<TPixel, WernerPaletteQuantizer>();
537+
AotCompileQuantizer<TPixel, WuQuantizer>();
538+
}
539+
540+
/// <summary>
541+
/// This method pre-seeds the <see cref="IQuantizer" /> in the AoT compiler.
542+
/// </summary>
543+
/// <typeparam name="TPixel">The pixel format.</typeparam>
544+
/// <typeparam name="TQuantizer">The quantizer type</typeparam>
545+
private static void AotCompileQuantizer<TPixel, TQuantizer>()
546+
where TPixel : unmanaged, IPixel<TPixel>
547+
548+
where TQuantizer : class, IQuantizer
549+
{
550+
default(TQuantizer).CreatePixelSpecificQuantizer<TPixel>(default);
551+
default(TQuantizer).CreatePixelSpecificQuantizer<TPixel>(default, default);
552+
}
553+
554+
/// <summary>
555+
/// This method pre-seeds the <see cref="IPixelSamplingStrategy" /> in the AoT compiler.
556+
/// </summary>
557+
/// <typeparam name="TPixel">The pixel format.</typeparam>
558+
private static void AotCompilePixelSamplingStrategys<TPixel>()
559+
where TPixel : unmanaged, IPixel<TPixel>
560+
{
561+
default(DefaultPixelSamplingStrategy).EnumeratePixelRegions<TPixel>(default);
562+
default(ExtensivePixelSamplingStrategy).EnumeratePixelRegions<TPixel>(default);
563+
}
216564
}
217565
}

0 commit comments

Comments
 (0)