Replace slow Marshal operations with unsafe (#13)

* Remove this bool marshal

* Literally remove all bool marshals

* Remove CharSet.Unicode warning

* Remove most FunctionPtr marshals

* Remove `[return: MarshalAs(...)]`

* Replace all `IntPtr`s with `void*`s

* Replace all `void*.Zero`s with `null`s

* Make native method classes unsafe

* U N S A F E

* Replace `PtrToStructure` with pointer arithmetic

* Run `dotnet format`

* Temp ugly Activator fix

* Remove `.ToPointer()`

* Use `byte` to return a `bool`

* Backwards compatibility with `Activator`

Yeah that sucks :(

* Replace `Marshal.Copy` by pointer arithmetic

* Replace `PtrToStringAnsi()` with `new string()`

* Remove unnecessary usings

* Explicitly type string pointers as `sbyte*`

* It actually doesn't hang?

* `MediaPipeException` -> `MediapipeException`

* Simplify `for` loops

* Remove unnecessary `float*` cast

* Some more explicit types for `ImageFrame`

* Remove unnecessary cast

* Looks like we forgor a `using` 💀

* Create `SafeArrayCopy` helper method

* Document `SafeArrayCopy`
This commit is contained in:
Speykious
2022-01-28 10:53:30 +01:00
committed by GitHub
parent b56693a010
commit 3371a2e745
99 changed files with 526 additions and 574 deletions

View File

@ -17,9 +17,7 @@ namespace Mediapipe.Net.Examples.FaceMesh
public static class Program
{
private static Camera? camera;
private static FrameConverter? converter;
private static FaceMeshCpuCalculator? calculator;
public static void Main(string[] args)
@ -76,11 +74,11 @@ namespace Mediapipe.Net.Examples.FaceMesh
ImageFrame imgframe;
fixed (byte* rawDataPtr = cFrame.RawData)
{
imgframe = new ImageFrame(ImageFormat.Srgba, cFrame.Width, cFrame.Height, cFrame.WidthStep,
rawDataPtr);
imgframe = new ImageFrame(ImageFormat.Srgba,
cFrame.Width, cFrame.Height, cFrame.WidthStep, rawDataPtr);
}
ImageFrame img = calculator.Send(imgframe);
using ImageFrame img = calculator.Send(imgframe);
imgframe.Dispose();
}