Skip to content

Commit c3a14c2

Browse files
authored
Merge pull request #19 from drasticactions/load-native-library
Allow manually loading SD library
2 parents f21a3d8 + cde0458 commit c3a14c2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

StableDiffusion.NET/Native/Native.Load.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ static Native()
2626

2727
#region Methods
2828

29+
internal static bool LoadNativeLibrary(string libraryPath)
30+
{
31+
if (_loadedLibraryHandle != nint.Zero) return true;
32+
if (NativeLibrary.TryLoad(libraryPath, out nint handle))
33+
{
34+
_loadedLibraryHandle = handle;
35+
return true;
36+
}
37+
38+
return false;
39+
}
40+
2941
private static nint ResolveDllImport(string libraryname, Assembly assembly, DllImportSearchPath? searchpath)
3042
{
3143
if (libraryname != LIB_NAME) return nint.Zero;

StableDiffusion.NET/StableDiffusionModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ private void Initialize()
9191
}
9292
}
9393

94+
/// <summary>
95+
/// Manually load the native stable diffusion library.
96+
/// Once set, it will continue to be used for all instances.
97+
/// </summary>
98+
/// <param name="libraryPath">Path to the stable diffusion library.</param>
99+
/// <returns>Bool if the library loaded.</returns>
100+
public static bool LoadNativeLibrary(string libraryPath)
101+
=> Native.LoadNativeLibrary(libraryPath);
102+
94103
public IImage<ColorRGB> TextToImage(string prompt, StableDiffusionParameter parameter)
95104
{
96105
ObjectDisposedException.ThrowIf(_disposed, this);

0 commit comments

Comments
 (0)