servicepoint/crates/servicepoint_binding_cs/ServicePoint/Bitmap.cs

101 lines
2 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-14 22:42:45 +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 20:56:55 +02:00
return new Bitmap(NativeMethods.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 20:56:55 +02:00
return new Bitmap(NativeMethods.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-14 22:42:45 +02:00
return new Bitmap(NativeMethods.sp_bitmap_clone(Instance));
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 20:56:55 +02:00
return NativeMethods.sp_bitmap_get(Instance, x, y);
2024-05-13 00:17:40 +02:00
}
}
set
{
unsafe
{
2024-10-16 20:56:55 +02:00
NativeMethods.sp_bitmap_set(Instance, x, y, value);
2024-05-13 00:17:40 +02:00
}
}
}
public void Fill(bool value)
{
unsafe
{
2024-10-14 22:42:45 +02:00
NativeMethods.sp_bitmap_fill(Instance, 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 20:56:55 +02:00
return NativeMethods.sp_bitmap_width(Instance);
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 20:56:55 +02:00
return NativeMethods.sp_bitmap_height(Instance);
2024-05-13 00:17:40 +02:00
}
}
}
public Span<byte> Data
{
get
{
unsafe
{
2024-10-14 22:42:45 +02:00
var slice = NativeMethods.sp_bitmap_unsafe_data_ref(Instance);
return new Span<byte>(slice.start, (int)slice.length);
}
}
}
2024-10-14 22:42:45 +02:00
private unsafe Bitmap(BindGen.Bitmap* instance) : base(instance)
2024-05-13 00:17:40 +02:00
{
}
2024-10-14 22:42:45 +02:00
private protected override unsafe void Free() => NativeMethods.sp_bitmap_free(Instance);
2024-05-13 00:17:40 +02:00
}