Merge pull request #19 from drasticactions/load-native-library

Allow manually loading SD library
This commit is contained in:
DarthAffe 2024-08-01 21:40:16 +02:00 committed by GitHub
commit c3a14c2883
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -26,6 +26,18 @@ internal static partial class Native
#region Methods
internal static bool LoadNativeLibrary(string libraryPath)
{
if (_loadedLibraryHandle != nint.Zero) return true;
if (NativeLibrary.TryLoad(libraryPath, out nint handle))
{
_loadedLibraryHandle = handle;
return true;
}
return false;
}
private static nint ResolveDllImport(string libraryname, Assembly assembly, DllImportSearchPath? searchpath)
{
if (libraryname != LIB_NAME) return nint.Zero;

View File

@ -91,6 +91,15 @@ public sealed unsafe class StableDiffusionModel : IDisposable
}
}
/// <summary>
/// Manually load the native stable diffusion library.
/// Once set, it will continue to be used for all instances.
/// </summary>
/// <param name="libraryPath">Path to the stable diffusion library.</param>
/// <returns>Bool if the library loaded.</returns>
public static bool LoadNativeLibrary(string libraryPath)
=> Native.LoadNativeLibrary(libraryPath);
public IImage<ColorRGB> TextToImage(string prompt, StableDiffusionParameter parameter)
{
ObjectDisposedException.ThrowIf(_disposed, this);