2024-05-25 11:16:37 +02:00
|
|
|
using ServicePoint.BindGen;
|
2024-05-13 00:17:40 +02:00
|
|
|
|
2024-05-25 11:16:37 +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-14 22:42:45 +02:00
|
|
|
public static Bitmap New(int width, int height)
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-14 22:42:45 +02:00
|
|
|
return new Bitmap(NativeMethods.sp_bitmap_new((nuint)width, (nuint)height));
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-14 22:42:45 +02:00
|
|
|
public static Bitmap Load(int width, int height, Span<byte> bytes)
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
fixed (byte* bytesPtr = bytes)
|
|
|
|
{
|
2024-10-14 22:42:45 +02:00
|
|
|
return new Bitmap(NativeMethods.sp_bitmap_load((nuint)width, (nuint)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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool this[int x, int y]
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-14 22:42:45 +02:00
|
|
|
return NativeMethods.sp_bitmap_get(Instance, (nuint)x, (nuint)y);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-14 22:42:45 +02:00
|
|
|
NativeMethods.sp_bitmap_set(Instance, (nuint)x, (nuint)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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Width
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-14 22:42:45 +02:00
|
|
|
return (int)NativeMethods.sp_bitmap_width(Instance);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Height
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-14 22:42:45 +02:00
|
|
|
return (int)NativeMethods.sp_bitmap_height(Instance);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-13 01:26:44 +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);
|
2024-05-15 20:34:51 +02:00
|
|
|
return new Span<byte>(slice.start, (int)slice.length);
|
2024-05-13 01:26:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|