using BlurgText; using Dashboard.Media; using Dashboard.Media.Color; namespace Dashboard.BlurgText { public class DashboardBlurg : IDisposable { private readonly List images = new List(); public Blurg Blurg { get; } public IReadOnlyList Images => images.AsReadOnly(); public DashboardBlurg() { Blurg = new Blurg(TextureAllocationCallback, TextureUpdateCallback); } private nint TextureAllocationCallback(int width, int height) { QImageBuffer image = new QImageBuffer(QImageFormat.RgbaU8, width, height); images.Add(image); return images.Count - 1; } private void TextureUpdateCallback(nint userData, nint buffer, int x, int y, int width, int height) { if (width == 0 || height == 0) return; QImageLock src = new QImageLock(QImageFormat.RgbaU8, width, height, 1, buffer); QImageBuffer image = images[(int)userData]; image.LockBits2d(out QImageLock dest, QImageLockOptions.Default); src.CopyTo(dest, x, y); image.UnlockBits(); } private bool _isDisposed = false; private void Dispose(bool disposing) { if (_isDisposed) return; if (disposing) { Blurg.Dispose(); foreach (QImageBuffer image in images) { image.Dispose(); } images.Clear(); } _isDisposed = true; } public void Dispose() => Dispose(true); } }