From 7f17d68a52fcc08863ff8f0c709fff72cf6f9c8f Mon Sep 17 00:00:00 2001 From: Dimitri Vranken Date: Mon, 13 Feb 2023 11:39:03 +0100 Subject: [PATCH] Updated tests for SkiaSharp --- FFMpegCore.Test/Utilities/BitmapSources.cs | 11 ++--- FFMpegCore.Test/VideoTest.cs | 49 +++++++++++----------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/FFMpegCore.Test/Utilities/BitmapSources.cs b/FFMpegCore.Test/Utilities/BitmapSources.cs index b7ecb45..7e8d1a9 100644 --- a/FFMpegCore.Test/Utilities/BitmapSources.cs +++ b/FFMpegCore.Test/Utilities/BitmapSources.cs @@ -4,13 +4,14 @@ using System.Runtime.Versioning; using FFMpegCore.Extensions.System.Drawing.Common; using FFMpegCore.Pipes; +using SkiaSharp; namespace FFMpegCore.Test.Utilities { [SupportedOSPlatform("windows")] internal static class BitmapSource { - public static IEnumerable CreateBitmaps(int count, PixelFormat fmt, int w, int h) + public static IEnumerable CreateBitmaps(int count, SKColorType fmt, int w, int h) { for (var i = 0; i < count; i++) { @@ -21,9 +22,9 @@ public static IEnumerable CreateBitmaps(int count, PixelFormat fmt, } } - public static BitmapVideoFrameWrapper CreateVideoFrame(int index, PixelFormat fmt, int w, int h, float scaleNoise, float offset) + public static BitmapVideoFrameWrapper CreateVideoFrame(int index, SKColorType fmt, int w, int h, float scaleNoise, float offset) { - var bitmap = new Bitmap(w, h, fmt); + var bitmap = new SKBitmap(w, h, fmt, SKAlphaType.Opaque); offset = offset * index; @@ -36,9 +37,9 @@ public static BitmapVideoFrameWrapper CreateVideoFrame(int index, PixelFormat fm var nx = x * scaleNoise + offset; var ny = y * scaleNoise + offset; - var value = (int)((Perlin.Noise(nx, ny) + 1.0f) / 2.0f * 255); + var value = (byte)((Perlin.Noise(nx, ny) + 1.0f) / 2.0f * 255); - var color = Color.FromArgb((int)(value * xf), (int)(value * yf), value); + var color = new SKColor((byte)(value * xf), (byte)(value * yf), value); bitmap.SetPixel(x, y, color); } diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index e3e4b6b..23cc1b5 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -1,5 +1,4 @@ -using System.Drawing.Imaging; -using System.Runtime.Versioning; +using System.Runtime.Versioning; using System.Text; using FFMpegCore.Arguments; using FFMpegCore.Enums; @@ -9,6 +8,7 @@ using FFMpegCore.Test.Resources; using FFMpegCore.Test.Utilities; using Microsoft.VisualStudio.TestTools.UnitTesting; +using SkiaSharp; namespace FFMpegCore.Test { @@ -83,9 +83,9 @@ public void Video_ToH265_MKV_Args() [SupportedOSPlatform("windows")] [WindowsOnlyDataTestMethod, Timeout(10000)] - [DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)] - [DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)] - public void Video_ToMP4_Args_Pipe(System.Drawing.Imaging.PixelFormat pixelFormat) + [DataRow(SKColorType.Rgb565)] + [DataRow(SKColorType.Bgra8888)] + public void Video_ToMP4_Args_Pipe(SKColorType pixelFormat) { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -106,8 +106,8 @@ public void Video_ToMP4_Args_Pipe_DifferentImageSizes() var frames = new List { - BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 255, 255, 1, 0), - BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 256, 256, 1, 0) + BitmapSource.CreateVideoFrame(0, SKColorType.Rgb565, 255, 255, 1, 0), + BitmapSource.CreateVideoFrame(0, SKColorType.Rgb565, 256, 256, 1, 0) }; var videoFramesSource = new RawVideoPipeSource(frames); @@ -126,8 +126,8 @@ public async Task Video_ToMP4_Args_Pipe_DifferentImageSizes_Async() var frames = new List { - BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 255, 255, 1, 0), - BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 256, 256, 1, 0) + BitmapSource.CreateVideoFrame(0, SKColorType.Rgb565, 255, 255, 1, 0), + BitmapSource.CreateVideoFrame(0, SKColorType.Rgb565, 256, 256, 1, 0) }; var videoFramesSource = new RawVideoPipeSource(frames); @@ -146,8 +146,8 @@ public void Video_ToMP4_Args_Pipe_DifferentPixelFormats() var frames = new List { - BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 255, 255, 1, 0), - BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format32bppRgb, 255, 255, 1, 0) + BitmapSource.CreateVideoFrame(0, SKColorType.Rgb565, 255, 255, 1, 0), + BitmapSource.CreateVideoFrame(0, SKColorType.Bgra8888, 255, 255, 1, 0) }; var videoFramesSource = new RawVideoPipeSource(frames); @@ -166,8 +166,8 @@ public async Task Video_ToMP4_Args_Pipe_DifferentPixelFormats_Async() var frames = new List { - BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 255, 255, 1, 0), - BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format32bppRgb, 255, 255, 1, 0) + BitmapSource.CreateVideoFrame(0, SKColorType.Rgb565, 255, 255, 1, 0), + BitmapSource.CreateVideoFrame(0, SKColorType.Bgra8888, 255, 255, 1, 0) }; var videoFramesSource = new RawVideoPipeSource(frames); @@ -313,9 +313,9 @@ public void Video_ToTS_Args() [SupportedOSPlatform("windows")] [WindowsOnlyDataTestMethod, Timeout(10000)] - [DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)] - [DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)] - public async Task Video_ToTS_Args_Pipe(System.Drawing.Imaging.PixelFormat pixelFormat) + [DataRow(SKColorType.Rgb565)] + [DataRow(SKColorType.Bgra8888)] + public async Task Video_ToTS_Args_Pipe(SKColorType pixelFormat) { using var output = new TemporaryFile($"out{VideoType.Ts.Extension}"); var input = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); @@ -346,10 +346,9 @@ public async Task Video_ToOGV_Resize() [SupportedOSPlatform("windows")] [WindowsOnlyDataTestMethod, Timeout(10000)] - [DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)] - [DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)] - [DataRow(System.Drawing.Imaging.PixelFormat.Format48bppRgb)] - public void RawVideoPipeSource_Ogv_Scale(System.Drawing.Imaging.PixelFormat pixelFormat) + [DataRow(SKColorType.Rgb565)] + [DataRow(SKColorType.Bgra8888)] + public void RawVideoPipeSource_Ogv_Scale(SKColorType pixelFormat) { using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}"); var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); @@ -382,10 +381,10 @@ public void Scale_Mp4_Multithreaded() [SupportedOSPlatform("windows")] [WindowsOnlyDataTestMethod, Timeout(10000)] - [DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)] - [DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)] + [DataRow(SKColorType.Rgb565)] + [DataRow(SKColorType.Bgra8888)] // [DataRow(PixelFormat.Format48bppRgb)] - public void Video_ToMP4_Resize_Args_Pipe(System.Drawing.Imaging.PixelFormat pixelFormat) + public void Video_ToMP4_Resize_Args_Pipe(SKColorType pixelFormat) { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); @@ -407,7 +406,7 @@ public void Video_Snapshot_InMemory() var input = FFProbe.Analyse(TestResources.Mp4Video); Assert.AreEqual(input.PrimaryVideoStream!.Width, bitmap.Width); Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height); - Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png); + Assert.AreEqual(bitmap.ColorType, SKColorType.Bgra8888); } [TestMethod, Timeout(10000)] @@ -568,7 +567,7 @@ public void Video_TranscodeInMemory() { using var resStream = new MemoryStream(); var reader = new StreamPipeSink(resStream); - var writer = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 128, 128)); + var writer = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, SKColorType.Rgb565, 128, 128)); FFMpegArguments .FromPipeInput(writer)