-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathImages.cs
53 lines (46 loc) · 1.57 KB
/
Images.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.ML.OnnxRuntimeGenAI
{
/// <summary>
/// This class can load images from the given path and prepare them for processing.
/// </summary>
public class Images : IDisposable
{
private IntPtr _imagesHandle;
private bool _disposed = false;
private Images(IntPtr imagesHandle)
{
_imagesHandle = imagesHandle;
}
internal IntPtr Handle { get { return _imagesHandle; } }
private static Images Load(string[] imagePaths)
{
Result.VerifySuccess(NativeMethods.OgaCreateStringArray(out IntPtr stringArray));
foreach (string imagePath in imagePaths)
{
Result.VerifySuccess(NativeMethods.OgaStringArrayAddString(stringArray, StringUtils.ToUtf8(imagePath)));
}
Result.VerifySuccess(NativeMethods.OgaLoadImages(stringArray, out IntPtr imagesHandle));
NativeMethods.OgaDestroyStringArray(stringArray);
return new Images(imagesHandle);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
return;
}
NativeMethods.OgaDestroyImages(_imagesHandle);
_imagesHandle = IntPtr.Zero;
_disposed = true;
}
}
}