mirror of
https://github.com/cosyneco/MediaPipe.NET.git
synced 2025-08-23 16:11:59 +08:00
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:
@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user