Cleaned Project

This commit is contained in:
Darth Affe 2023-12-14 21:49:31 +01:00
parent e741cc14d1
commit 4cba970697
7 changed files with 15 additions and 77 deletions

View File

@ -1,4 +1,6 @@
namespace StableDiffusion.NET;
using System;
namespace StableDiffusion.NET;
[AttributeUsage(AttributeTargets.Field)]
internal class NativeName : Attribute

View File

@ -1,4 +1,5 @@
using System.Reflection;
using System;
using System.Reflection;
namespace StableDiffusion.NET;

View File

@ -1,4 +1,6 @@
namespace StableDiffusion.NET;
using System;
namespace StableDiffusion.NET;
public sealed unsafe class Image : IDisposable
{

View File

@ -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<byte> 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<byte> 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<byte>((void*)ptr, width * height * 3));
output.UnlockBits(bmpData);
return output;
}

View File

@ -1,15 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,7 @@
namespace StableDiffusion.NET;
using System;
using System.IO;
namespace StableDiffusion.NET;
public sealed unsafe class StableDiffusionModel : IDisposable
{

View File

@ -1,4 +1,6 @@
namespace StableDiffusion.NET;
using System;
namespace StableDiffusion.NET;
public sealed unsafe class StableDiffusionParameter : IDisposable
{