mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-01-18 12:36:44 +00:00
Refactored video frame generator to pure function
This commit is contained in:
parent
9646c440bb
commit
317ba47dd2
1 changed files with 10 additions and 16 deletions
|
@ -37,11 +37,11 @@ public static Extensions.System.Drawing.Common.BitmapVideoFrameWrapper CreateVid
|
|||
{
|
||||
var bitmap = new Bitmap(w, h, fmt);
|
||||
|
||||
SetVideoFramePixels(index, w, h, scaleNoise, offset, ((int x, int y, byte red, byte green, byte blue) args) =>
|
||||
foreach (var (x, y, red, green, blue) in GenerateVideoFramePixels(index, w, h, scaleNoise, offset))
|
||||
{
|
||||
var color = Color.FromArgb(args.red, args.blue, args.green);
|
||||
bitmap.SetPixel(args.x, args.y, color);
|
||||
});
|
||||
var color = Color.FromArgb(red, blue, green);
|
||||
bitmap.SetPixel(x, y, color);
|
||||
}
|
||||
|
||||
return new Extensions.System.Drawing.Common.BitmapVideoFrameWrapper(bitmap);
|
||||
}
|
||||
|
@ -51,22 +51,16 @@ public static Extensions.SkiaSharp.BitmapVideoFrameWrapper CreateVideoFrame(int
|
|||
var bitmap = new SKBitmap(w, h, fmt, SKAlphaType.Opaque);
|
||||
|
||||
using var bitmapCanvas = new SKCanvas(bitmap);
|
||||
SetVideoFramePixels(index, w, h, scaleNoise, offset, ((int x, int y, byte red, byte green, byte blue) args) =>
|
||||
foreach (var (x, y, red, green, blue) in GenerateVideoFramePixels(index, w, h, scaleNoise, offset))
|
||||
{
|
||||
var color = new SKColor(args.red, args.blue, args.green);
|
||||
bitmapCanvas.DrawPoint(args.x, args.y, color);
|
||||
});
|
||||
var color = new SKColor(red, blue, green);
|
||||
bitmapCanvas.DrawPoint(x, y, color);
|
||||
}
|
||||
|
||||
return new Extensions.SkiaSharp.BitmapVideoFrameWrapper(bitmap);
|
||||
}
|
||||
|
||||
private static void SetVideoFramePixels(
|
||||
int index,
|
||||
int w,
|
||||
int h,
|
||||
float scaleNoise,
|
||||
float offset,
|
||||
Action<(int x, int y, byte red, byte green, byte blue)> setPixel)
|
||||
private static IEnumerable<(int x, int y, byte red, byte green, byte blue)> GenerateVideoFramePixels(int index, int w, int h, float scaleNoise, float offset)
|
||||
{
|
||||
offset = offset * index;
|
||||
|
||||
|
@ -81,7 +75,7 @@ private static void SetVideoFramePixels(
|
|||
|
||||
var value = (byte)((Perlin.Noise(nx, ny) + 1.0f) / 2.0f * 255);
|
||||
|
||||
setPixel((x, y, (byte)(value * xf), (byte)(value * yf), value));
|
||||
yield return ((x, y, (byte)(value * xf), (byte)(value * yf), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue