mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01: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);
|
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);
|
var color = Color.FromArgb(red, blue, green);
|
||||||
bitmap.SetPixel(args.x, args.y, color);
|
bitmap.SetPixel(x, y, color);
|
||||||
});
|
}
|
||||||
|
|
||||||
return new Extensions.System.Drawing.Common.BitmapVideoFrameWrapper(bitmap);
|
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);
|
var bitmap = new SKBitmap(w, h, fmt, SKAlphaType.Opaque);
|
||||||
|
|
||||||
using var bitmapCanvas = new SKCanvas(bitmap);
|
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);
|
var color = new SKColor(red, blue, green);
|
||||||
bitmapCanvas.DrawPoint(args.x, args.y, color);
|
bitmapCanvas.DrawPoint(x, y, color);
|
||||||
});
|
}
|
||||||
|
|
||||||
return new Extensions.SkiaSharp.BitmapVideoFrameWrapper(bitmap);
|
return new Extensions.SkiaSharp.BitmapVideoFrameWrapper(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetVideoFramePixels(
|
private static IEnumerable<(int x, int y, byte red, byte green, byte blue)> GenerateVideoFramePixels(int index, int w, int h, float scaleNoise, float offset)
|
||||||
int index,
|
|
||||||
int w,
|
|
||||||
int h,
|
|
||||||
float scaleNoise,
|
|
||||||
float offset,
|
|
||||||
Action<(int x, int y, byte red, byte green, byte blue)> setPixel)
|
|
||||||
{
|
{
|
||||||
offset = offset * index;
|
offset = offset * index;
|
||||||
|
|
||||||
|
@ -81,7 +75,7 @@ private static void SetVideoFramePixels(
|
||||||
|
|
||||||
var value = (byte)((Perlin.Noise(nx, ny) + 1.0f) / 2.0f * 255);
|
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