mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2025-12-12 13:28:35 +00:00
Added logging; Updated stable-diffusion.cpp to 7cb41b1
This commit is contained in:
parent
a7ccbe8ef2
commit
c277e9c830
11
StableDiffusion.NET/EventArgs/StableDiffusionLogEventArgs.cs
Normal file
11
StableDiffusion.NET/EventArgs/StableDiffusionLogEventArgs.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
public class StableDiffusionLogEventArgs(LogLevel level, string text)
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public LogLevel Level { get; } = level;
|
||||
public string Text { get; } = text;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -21,6 +21,12 @@ internal unsafe partial class Native
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delegates
|
||||
|
||||
internal delegate void sd_log_cb_t(sd_log_level_t level, [MarshalAs(UnmanagedType.LPStr)] string text, void* data);
|
||||
|
||||
#endregion
|
||||
|
||||
#region DLL-Import
|
||||
|
||||
internal struct sd_ctx_t;
|
||||
@ -98,5 +104,8 @@ internal unsafe partial class Native
|
||||
sd_image_t input_image,
|
||||
int upscale_factor);
|
||||
|
||||
[LibraryImport(LIB_NAME, EntryPoint = "sd_set_log_callback")]
|
||||
internal static partial void sd_set_log_callback(sd_log_cb_t sd_log_cb, void* data);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=attributes/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enums/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=eventargs/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
@ -18,8 +18,19 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public static event EventHandler<StableDiffusionLogEventArgs>? Log;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
static StableDiffusionModel()
|
||||
{
|
||||
Native.sd_set_log_callback(OnNativeLog, null);
|
||||
}
|
||||
|
||||
public StableDiffusionModel(string modelPath, ModelParameter parameter, UpscalerModelParameter? upscalerParameter = null)
|
||||
{
|
||||
this._modelPath = modelPath;
|
||||
@ -177,5 +188,14 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
||||
|
||||
public static int GetNumPhysicalCores() => Native.get_num_physical_cores();
|
||||
|
||||
private static void OnNativeLog(LogLevel level, string text, void* data)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log?.Invoke(null, new StableDiffusionLogEventArgs(level, text));
|
||||
}
|
||||
catch { /**/ }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user