Due to unforseen naming conflicts, the project has been rebranded under the ReFuel umbrealla and will now be referred to as Dashboard from now on. Other changes will occur to suit the library more for the engine whilst keeping the freestanding nature of the library. Rename folder. Rename to Dashboard.OpenTK Rename to Dashboard.Media.Defaults. Do the last renames and path fixes.
69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Dashboard.Media.Color
|
|
{
|
|
public class QImageBuffer : QImage
|
|
{
|
|
private byte[] buffer;
|
|
GCHandle handle;
|
|
private bool isSdf = false;
|
|
|
|
public override QImageFormat InternalFormat { get; }
|
|
public override int Width { get; }
|
|
public override int Height { get; }
|
|
public override int Depth { get; }
|
|
public override bool IsSdf => isSdf;
|
|
|
|
public QImageBuffer(QImageFormat format, int width, int height, int depth = 1)
|
|
{
|
|
InternalFormat = format;
|
|
Width = width;
|
|
Height = height;
|
|
Depth = depth;
|
|
|
|
buffer = new byte[width * height * depth];
|
|
}
|
|
~QImageBuffer()
|
|
{
|
|
Dispose(false);
|
|
}
|
|
|
|
private QImageLock Lock()
|
|
{
|
|
if (handle.IsAllocated) handle.Free();
|
|
handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
|
|
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
|
|
return new QImageLock(InternalFormat, Width, Height, Depth, ptr);
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (handle.IsAllocated) handle.Free();
|
|
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
public override void LockBits2d(out QImageLock imageLock, QImageLockOptions options)
|
|
{
|
|
imageLock = Lock();
|
|
}
|
|
|
|
public override void LockBits3d(out QImageLock imageLock, QImageLockOptions options)
|
|
{
|
|
imageLock = Lock();
|
|
}
|
|
|
|
public override void LockBits3d(out QImageLock imageLock, QImageLockOptions options, int depth)
|
|
{
|
|
imageLock = Lock();
|
|
}
|
|
|
|
public override void UnlockBits()
|
|
{
|
|
handle.Free();
|
|
}
|
|
|
|
public void SetSdf(bool value = true) => isSdf = value;
|
|
}
|
|
} |