Add a safe overload for ImageFrame() (#20)

* Add a safe overload for ImageFrame()

Signed-off-by: GitHub <noreply@github.com>

* Reduce code dup by wrapping into the unsafe overload instead

Signed-off-by: GitHub <noreply@github.com>

* dotnet format

Signed-off-by: GitHub <noreply@github.com>

* Le unhaskellize

🖑Hey🖐 buddy,👬 I think🤔 you've 👉got the 🛇wrong🚫 door🚪 the 🐄leather🐄 club's ♴two♴ blocks down☟. 🖕Fuck🖕↗You↘.Oh, Fuck♂You 🐄leather🐄 man Maybe 👬you and I👬 should settle it💪 👇right here👇 on the 💍ring💍 if you think🤔 your so 💪tough💪. Oh yea?😡 I'll kick👣 your ass!👊 Ha!😂 Yeah right👍 man. Let's go!✔ Why don't you🤔 get out of that 🐄leather stuff?🐄 I'll strip👙 down☟ out of this and we'll settle👪 it right here👇 in the ring. What do you say? 🤐Yeah⁉ no problem buddy👬 You got it. 🖒Get out of that uh, jabroni outfit👕👔👖. Yeah, smart🤔 ass. I'll show😡you who's the ☝boss☝ of this 🏋gym.🏋

Signed-off-by: GitHub <noreply@github.com>

* I'll let this Le pass this time

Co-authored-by: Speykious <speykious@gmail.com>
This commit is contained in:
Ayane
2022-02-02 23:36:42 +08:00
committed by GitHub
parent ff98083149
commit ce85bd59a4

View File

@ -39,7 +39,7 @@ namespace Mediapipe.Net.Framework.Format
// mediapipe::ImageFormat::Format format,
// int width, int height, int width_step, uint8* pixel_data,
// Deleter* deleter, mediapipe::ImageFrame** image_frame_out);
unsafe public ImageFrame(ImageFormat format, int width, int height, int widthStep, byte* pixelData)
unsafe public ImageFrame(ImageFormat format, int width, int height, int widthStep, byte* pixelData) : base()
{
UnsafeNativeMethods.mp_ImageFrame__ui_i_i_i_Pui8_PF(
format, width, height, widthStep,
@ -49,6 +49,17 @@ namespace Mediapipe.Net.Framework.Format
Ptr = ptr;
}
public ImageFrame(ImageFormat format, int width, int height, int widthStep, ReadOnlySpan<byte> pixelData)
: this(format, width, height, widthStep, spanToBytePtr(pixelData)) { }
private static byte* spanToBytePtr(ReadOnlySpan<byte> span)
{
fixed (byte* ptr = span)
{
return ptr;
}
}
protected override void DeleteMpPtr() => UnsafeNativeMethods.mp_ImageFrame__delete(Ptr);
// [AOT.MonoPInvokeCallback(typeof(Deleter))] (?)