63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
|
|
using BlurgText;
|
|
using Dashboard.Media;
|
|
using Dashboard.Media.Color;
|
|
|
|
namespace Dashboard.BlurgText
|
|
{
|
|
public class DashboardBlurg : IDisposable
|
|
{
|
|
private readonly List<QImageBuffer> images = new List<QImageBuffer>();
|
|
|
|
public Blurg Blurg { get; }
|
|
|
|
public IReadOnlyList<QImageBuffer> Images => images.AsReadOnly();
|
|
|
|
public DashboardBlurg()
|
|
{
|
|
Blurg = new Blurg(TextureAllocationCallback, TextureUpdateCallback);
|
|
}
|
|
|
|
private nint TextureAllocationCallback(int width, int height)
|
|
{
|
|
QImageBuffer image = new QImageBuffer(ImageFormat.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(ImageFormat.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);
|
|
}
|
|
} |