diff --git a/.github/workflows/backends.yml b/.github/workflows/backends.yml index a6daac2..41b2c96 100644 --- a/.github/workflows/backends.yml +++ b/.github/workflows/backends.yml @@ -28,7 +28,7 @@ jobs: - build: 'avx512' defines: '-DGGML_AVX512=ON -DSD_BUILD_SHARED_LIBS=ON' - build: 'cuda11' - defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON' + defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_FLAGS="-allow-unsupported-compiler"' - build: 'cuda12' defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON' - build: 'rocm5' @@ -48,7 +48,7 @@ jobs: if: ${{ matrix.build == 'cuda11' }} uses: Jimver/cuda-toolkit@v0.2.14 with: - cuda: '11.7.1' + cuda: '11.8.0' method: network sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]' use-github-cache: false @@ -57,9 +57,9 @@ jobs: - name: Install cuda-toolkit id: cuda-toolkit-12 if: ${{ matrix.build == 'cuda12' }} - uses: Jimver/cuda-toolkit@v0.2.14 + uses: Jimver/cuda-toolkit@v0.2.16 with: - cuda: '12.2.0' + cuda: '12.5.0' method: network sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]' use-github-cache: false diff --git a/Examples/ImageCreationUI/Converter/ImageToImageSourceConverter.cs b/Examples/ImageCreationUI/Converter/ImageToImageSourceConverter.cs index 6370177..c3d8cb6 100644 --- a/Examples/ImageCreationUI/Converter/ImageToImageSourceConverter.cs +++ b/Examples/ImageCreationUI/Converter/ImageToImageSourceConverter.cs @@ -4,7 +4,8 @@ using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Imaging; -using StableDiffusion.NET.Helper.Images; +using HPPH; +using HPPH.System.Drawing; namespace ImageCreationUI.Converter; @@ -13,7 +14,7 @@ public class ImageToImageSourceConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { - Bitmap? bitmap = (value as IImage)?.ToBitmap(); + using Bitmap? bitmap = (value as IImage)?.ToBitmap(); if (bitmap == null) return null; using MemoryStream ms = new(); diff --git a/Examples/ImageCreationUI/Extensions/ImageExtension.cs b/Examples/ImageCreationUI/Extensions/ImageExtension.cs deleted file mode 100644 index 07d4d9c..0000000 --- a/Examples/ImageCreationUI/Extensions/ImageExtension.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System.Buffers; -using System.Drawing; -using System.Drawing.Imaging; -using StableDiffusion.NET.Helper.Images.Colors; -using StableDiffusion.NET.Helper.Images; -using System.IO; -using System.Runtime.InteropServices; - -namespace ImageCreationUI; - -public static class ImageExtension -{ - public static Bitmap ToBitmap(this IImage image) => image.AsRefImage().ToBitmap(); - public static Bitmap ToBitmap(this Image image) => image.AsRefImage().ToBitmap(); - - public static unsafe Bitmap ToBitmap(this RefImage image) - { - Bitmap output = new(image.Width, image.Height, PixelFormat.Format24bppRgb); - Rectangle rect = new(0, 0, image.Width, image.Height); - BitmapData bmpData = output.LockBits(rect, ImageLockMode.ReadWrite, output.PixelFormat); - - nint ptr = bmpData.Scan0; - foreach (ReadOnlyRefEnumerable row in image.Rows) - { - Span target = new((void*)ptr, bmpData.Stride); - for (int i = 0; i < row.Length; i++) - { - ColorRGB srcColor = row[i]; - target[i] = new ColorBGR(srcColor.B, srcColor.G, srcColor.R); - } - - ptr += bmpData.Stride; - } - - output.UnlockBits(bmpData); - return output; - } - - public static byte[] ToPng(this IImage image) - { - using Bitmap bitmap = image.ToBitmap(); - using MemoryStream ms = new(); - bitmap.Save(ms, ImageFormat.Png); - - return ms.ToArray(); - } - - public static unsafe Image ToImage(this Bitmap bitmap) - { - int width = bitmap.Width; - int height = bitmap.Height; - - byte[] buffer = new byte[height * width * ColorRGB.ColorFormat.BytesPerPixel]; - Span colorBuffer = MemoryMarshal.Cast(buffer); - - Rectangle rect = new(0, 0, bitmap.Width, bitmap.Height); - BitmapData bmpData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat); - - nint ptr = bmpData.Scan0; - for (int y = 0; y < height; y++) - { - Span source = new((void*)ptr, bmpData.Stride); - Span target = colorBuffer.Slice(y * width, width); - for (int x = 0; x < width; x++) - { - ColorBGR srcColor = source[x]; - target[x] = new ColorRGB(srcColor.R, srcColor.G, srcColor.B); - } - - ptr += bmpData.Stride; - } - - bitmap.UnlockBits(bmpData); - - return new Image(buffer, 0, 0, width, height, width); - } -} \ No newline at end of file diff --git a/Examples/ImageCreationUI/ImageCreationUI.csproj b/Examples/ImageCreationUI/ImageCreationUI.csproj index 6900133..66e1258 100644 --- a/Examples/ImageCreationUI/ImageCreationUI.csproj +++ b/Examples/ImageCreationUI/ImageCreationUI.csproj @@ -10,11 +10,11 @@ - - - - - + + + + + diff --git a/Examples/ImageCreationUI/MainWindow.xaml b/Examples/ImageCreationUI/MainWindow.xaml index 261f3cf..b5b234f 100644 --- a/Examples/ImageCreationUI/MainWindow.xaml +++ b/Examples/ImageCreationUI/MainWindow.xaml @@ -72,30 +72,44 @@