[GUI] Improve memory usage of image previews

- also a bit increased performance of alpha mask resizing for previews
This commit is contained in:
VaDiM
2023-03-12 03:17:31 +03:00
parent 01957a9443
commit 44a1240f5f
5 changed files with 32 additions and 36 deletions

View File

@ -1,4 +1,7 @@
using System;
using AssetStudio;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
@ -7,13 +10,16 @@ namespace AssetStudioGUI
{
public sealed class DirectBitmap : IDisposable
{
public DirectBitmap(byte[] buff, int width, int height)
public DirectBitmap(Image<Bgra32> image)
{
Width = width;
Height = height;
Width = image.Width;
Height = image.Height;
var buff = BigArrayPool<byte>.Shared.Rent(Width * Height * 4);
image.CopyPixelDataTo(buff);
Bits = buff;
m_handle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
m_bitmap = new Bitmap(Width, Height, Stride, PixelFormat.Format32bppArgb, m_handle.AddrOfPinnedObject());
BigArrayPool<byte>.Shared.Return(buff);
}
private void Dispose(bool disposing)