From 5593bc4a4b119ca1a56ef5400383a6de4f0cde18 Mon Sep 17 00:00:00 2001 From: Dimitri Vranken Date: Mon, 20 Feb 2023 13:50:19 +0100 Subject: [PATCH] Improved SkiaSharp CreateVideoFrame performance Execution time is now approximately one fifth of what it was previously --- FFMpegCore.Test/Utilities/BitmapSources.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/FFMpegCore.Test/Utilities/BitmapSources.cs b/FFMpegCore.Test/Utilities/BitmapSources.cs index 6c15710..f3b657a 100644 --- a/FFMpegCore.Test/Utilities/BitmapSources.cs +++ b/FFMpegCore.Test/Utilities/BitmapSources.cs @@ -50,12 +50,9 @@ public static Extensions.SkiaSharp.BitmapVideoFrameWrapper CreateVideoFrame(int { var bitmap = new SKBitmap(w, h, fmt, SKAlphaType.Opaque); - using var bitmapCanvas = new SKCanvas(bitmap); - foreach (var (x, y, red, green, blue) in GenerateVideoFramePixels(index, w, h, scaleNoise, offset)) - { - var color = new SKColor(red, blue, green); - bitmapCanvas.DrawPoint(x, y, color); - } + bitmap.Pixels = GenerateVideoFramePixels(index, w, h, scaleNoise, offset) + .Select(args => new SKColor(args.red, args.blue, args.green)) + .ToArray(); return new Extensions.SkiaSharp.BitmapVideoFrameWrapper(bitmap); }