Allow manually loading SD library

This commit is contained in:
Timothy Miller 2024-07-31 17:50:45 +09:00
parent f21a3d876c
commit cde04582ac
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);