-
-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Framework/Packet/ImageVectorPacket.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Mediapipe | ||
{ | ||
public class ImageVectorPacket : Packet<List<Image>> | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal readonly struct ImageVector | ||
{ | ||
private readonly IntPtr _data; | ||
private readonly int _size; | ||
|
||
public void Dispose() | ||
{ | ||
UnsafeNativeMethods.mp_api_ImageArray__delete(_data); | ||
} | ||
|
||
public List<Image> Copy() | ||
{ | ||
var images = new List<Image>(_size); | ||
|
||
unsafe | ||
{ | ||
var imagePtr = (IntPtr*)_data; | ||
|
||
for (var i = 0; i < _size; i++) | ||
{ | ||
var image = new Image(*imagePtr++, true); | ||
images.Add(image); | ||
} | ||
} | ||
|
||
return images; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates an empty <see cref="ImageVectorPacket" /> instance. | ||
/// </summary> | ||
public ImageVectorPacket() : base(true) { } | ||
|
||
[UnityEngine.Scripting.Preserve] | ||
public ImageVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { } | ||
|
||
public ImageVectorPacket At(Timestamp timestamp) | ||
{ | ||
return At<ImageVectorPacket>(timestamp); | ||
} | ||
|
||
public override List<Image> Get() | ||
{ | ||
UnsafeNativeMethods.mp_Packet__GetImageVector(mpPtr, out var imageVector).Assert(); | ||
GC.KeepAlive(this); | ||
|
||
var images = imageVector.Copy(); | ||
imageVector.Dispose(); | ||
|
||
return images; | ||
} | ||
|
||
public override List<Image> Consume() | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...s/com.github.homuler.mediapipe/Runtime/Scripts/Framework/Packet/ImageVectorPacket.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters