From 4cba9706973b0938f1cad0f4db5364e187cb50cd Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 14 Dec 2023 21:49:31 +0100 Subject: [PATCH] Cleaned Project --- StableDiffusion.NET/Attributes/NativeName.cs | 4 +- .../Extensions/EnumExtension.cs | 3 +- StableDiffusion.NET/Image.cs | 4 +- StableDiffusion.NET/Program.cs | 66 ------------------- .../StableDiffusion.NET.csproj | 6 -- StableDiffusion.NET/StableDiffusion.cs | 5 +- .../StableDiffusionParameter.cs | 4 +- 7 files changed, 15 insertions(+), 77 deletions(-) delete mode 100644 StableDiffusion.NET/Program.cs diff --git a/StableDiffusion.NET/Attributes/NativeName.cs b/StableDiffusion.NET/Attributes/NativeName.cs index 86dcb33..ac02cb3 100644 --- a/StableDiffusion.NET/Attributes/NativeName.cs +++ b/StableDiffusion.NET/Attributes/NativeName.cs @@ -1,4 +1,6 @@ -namespace StableDiffusion.NET; +using System; + +namespace StableDiffusion.NET; [AttributeUsage(AttributeTargets.Field)] internal class NativeName : Attribute diff --git a/StableDiffusion.NET/Extensions/EnumExtension.cs b/StableDiffusion.NET/Extensions/EnumExtension.cs index 11aaa83..319cf76 100644 --- a/StableDiffusion.NET/Extensions/EnumExtension.cs +++ b/StableDiffusion.NET/Extensions/EnumExtension.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; namespace StableDiffusion.NET; diff --git a/StableDiffusion.NET/Image.cs b/StableDiffusion.NET/Image.cs index b35d187..fd3fb0b 100644 --- a/StableDiffusion.NET/Image.cs +++ b/StableDiffusion.NET/Image.cs @@ -1,4 +1,6 @@ -namespace StableDiffusion.NET; +using System; + +namespace StableDiffusion.NET; public sealed unsafe class Image : IDisposable { diff --git a/StableDiffusion.NET/Program.cs b/StableDiffusion.NET/Program.cs deleted file mode 100644 index 7ee7ba0..0000000 --- a/StableDiffusion.NET/Program.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Drawing; -using System.Drawing.Imaging; -using StableDiffusion.NET; -using Image = StableDiffusion.NET.Image; - -using StableDiffusionModel sd = new(@"N:\StableDiffusion\stable-diffusion-webui\models\Stable-diffusion\ghostmix_v20Bakedvae.safetensors", - new ModelParameter - { - Quantization = Quantization.Q5_1, - Schedule = Schedule.Karras - }); - -using StableDiffusionParameter parameter = new StableDiffusionParameter { SampleMethod = Sampler.DPMPP2M }; -parameter.Width = 768; - -using Image image = sd.TextToImage("der ohne gesicht wo im aquarium schwimmt", parameter); -using Bitmap bitmap = ToBitmap2(image); -bitmap.Save("test.jpg"); - - -//unsafe -//{ -// Console.WriteLine(Native.stable_diffusion_get_system_info()); - -// Native.stable_diffusion_set_log_level("DEBUG"); - -// Native.stable_diffusion_ctx* ctx = Native.stable_diffusion_init(16, false, string.Empty, false, string.Empty, "STD_DEFAULT_RNG"); - -// Native.stable_diffusion_load_from_file(ctx, @"N:\StableDiffusion\stable-diffusion-webui\models\Stable-diffusion\ghostmix_v20Bakedvae.safetensors", string.Empty, "Q5_1", "KARRAS"); - -// Native.stable_diffusion_full_params* @params = Native.stable_diffusion_full_default_params_ref(); - -// Native.stable_diffusion_full_params_set_cfg_scale(@params, 7.5f); -// Native.stable_diffusion_full_params_set_width(@params, 512); -// Native.stable_diffusion_full_params_set_height(@params, 512); -// Native.stable_diffusion_full_params_set_batch_count(@params, 1); -// Native.stable_diffusion_full_params_set_sample_steps(@params, 30); -// Native.stable_diffusion_full_params_set_sample_method(@params, "DPMPP2M"); - -// byte* result = Native.stable_diffusion_predict_image(ctx, @params, "a wizard in a purple t-shirt casting a spell that causes a mountain to explode"); - -// Span image = new(result, 512 * 512 * 3); - -// using Bitmap bitmap = ToBitmap(image, 512, 512); -// bitmap.Save("test.jpg"); - -// Native.stable_diffusion_free_buffer(result); -// Native.stable_diffusion_free_full_params(@params); -// Native.stable_diffusion_free(ctx); -//} - - -static Bitmap ToBitmap2(Image image) => ToBitmap(image.Data, image.Width, image.Height); - -static unsafe Bitmap ToBitmap(ReadOnlySpan image, int width, int height) -{ - Bitmap output = new(width, height, PixelFormat.Format24bppRgb); - Rectangle rect = new(0, 0, width, height); - BitmapData bmpData = output.LockBits(rect, ImageLockMode.ReadWrite, output.PixelFormat); - - nint ptr = bmpData.Scan0; - image.CopyTo(new Span((void*)ptr, width * height * 3)); - - output.UnlockBits(bmpData); - return output; -} \ No newline at end of file diff --git a/StableDiffusion.NET/StableDiffusion.NET.csproj b/StableDiffusion.NET/StableDiffusion.NET.csproj index 57a741d..c84410e 100644 --- a/StableDiffusion.NET/StableDiffusion.NET.csproj +++ b/StableDiffusion.NET/StableDiffusion.NET.csproj @@ -1,15 +1,9 @@  - Exe net8.0 - enable enable true - - - - diff --git a/StableDiffusion.NET/StableDiffusion.cs b/StableDiffusion.NET/StableDiffusion.cs index 16b0f32..3987e98 100644 --- a/StableDiffusion.NET/StableDiffusion.cs +++ b/StableDiffusion.NET/StableDiffusion.cs @@ -1,4 +1,7 @@ -namespace StableDiffusion.NET; +using System; +using System.IO; + +namespace StableDiffusion.NET; public sealed unsafe class StableDiffusionModel : IDisposable { diff --git a/StableDiffusion.NET/StableDiffusionParameter.cs b/StableDiffusion.NET/StableDiffusionParameter.cs index 8ce78f8..296be62 100644 --- a/StableDiffusion.NET/StableDiffusionParameter.cs +++ b/StableDiffusion.NET/StableDiffusionParameter.cs @@ -1,4 +1,6 @@ -namespace StableDiffusion.NET; +using System; + +namespace StableDiffusion.NET; public sealed unsafe class StableDiffusionParameter : IDisposable {