servicepoint/crates/servicepoint_binding_cs/ServicePoint/Bitmap.cs

101 lines
1.8 KiB
C#
Raw Normal View History

using ServicePoint.BindGen;
2024-05-13 00:17:40 +02:00
namespace ServicePoint;
2024-05-13 00:17:40 +02:00
2024-10-16 22:46:34 +02:00
public sealed class Bitmap : SpNativeInstance<BindGen.Bitmap>
2024-05-13 00:17:40 +02:00
{
2024-10-16 20:56:55 +02:00
public static Bitmap New(nuint width, nuint height)
2024-05-13 00:17:40 +02:00
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new Bitmap(BitmapNative.sp_bitmap_new(width, height));
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public static Bitmap Load(nuint width, nuint height, Span<byte> bytes)
2024-05-13 00:17:40 +02:00
{
unsafe
{
fixed (byte* bytesPtr = bytes)
{
2024-10-16 21:59:35 +02:00
return new Bitmap(BitmapNative.sp_bitmap_load(width, height, bytesPtr,
2024-05-13 00:17:40 +02:00
(nuint)bytes.Length));
}
}
}
2024-10-14 22:42:45 +02:00
public Bitmap Clone()
2024-05-13 00:17:40 +02:00
{
unsafe
{
2024-10-16 22:46:34 +02:00
return new Bitmap(Instance->Clone());
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public bool this[nuint x, nuint y]
2024-05-13 00:17:40 +02:00
{
get
{
unsafe
{
2024-10-16 22:46:34 +02:00
return Instance->Get(x, y);
2024-05-13 00:17:40 +02:00
}
}
set
{
unsafe
{
2024-10-16 22:46:34 +02:00
Instance->Set(x, y, value);
2024-05-13 00:17:40 +02:00
}
}
}
public void Fill(bool value)
{
unsafe
{
2024-10-16 22:46:34 +02:00
Instance->Fill(value);
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public nuint Width
2024-05-13 00:17:40 +02:00
{
get
{
unsafe
{
2024-10-16 22:46:34 +02:00
return Instance->Width();
2024-05-13 00:17:40 +02:00
}
}
}
2024-10-16 20:56:55 +02:00
public nuint Height
2024-05-13 00:17:40 +02:00
{
get
{
unsafe
{
2024-10-16 22:46:34 +02:00
return Instance->Height();
2024-05-13 00:17:40 +02:00
}
}
}
public Span<byte> Data
{
get
{
unsafe
{
2024-10-16 22:46:34 +02:00
var slice = Instance->UnsafeDataRef();
return new Span<byte>(slice.start, (int)slice.length);
}
}
}
2024-10-16 22:46:34 +02:00
private unsafe Bitmap(BindGen.Bitmap* instance) : base(instance)
2024-05-13 00:17:40 +02:00
{
}
2024-10-16 22:46:34 +02:00
private protected override unsafe void Free() => Instance->Free();
2024-05-13 00:17:40 +02:00
}