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-05-25 11:16:37 +02:00
|
|
|
public sealed class PixelGrid : SpNativeInstance<BindGen.PixelGrid>
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
|
|
|
public static PixelGrid New(int width, int height)
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-05-26 13:15:11 +02:00
|
|
|
return new PixelGrid(NativeMethods.sp_pixel_grid_new((nuint)width, (nuint)height));
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static PixelGrid Load(int width, int height, Span<byte> bytes)
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
fixed (byte* bytesPtr = bytes)
|
|
|
|
{
|
2024-05-26 13:15:11 +02:00
|
|
|
return new PixelGrid(NativeMethods.sp_pixel_grid_load((nuint)width, (nuint)height, bytesPtr,
|
2024-05-13 00:17:40 +02:00
|
|
|
(nuint)bytes.Length));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public PixelGrid Clone()
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-05-26 13:15:11 +02:00
|
|
|
return new PixelGrid(NativeMethods.sp_pixel_grid_clone(Instance));
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool this[int x, int y]
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-05-26 13:15:11 +02:00
|
|
|
return NativeMethods.sp_pixel_grid_get(Instance, (nuint)x, (nuint)y);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-05-26 13:15:11 +02:00
|
|
|
NativeMethods.sp_pixel_grid_set(Instance, (nuint)x, (nuint)y, value);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Fill(bool value)
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-05-26 13:15:11 +02:00
|
|
|
NativeMethods.sp_pixel_grid_fill(Instance, value);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Width
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-05-26 13:15:11 +02:00
|
|
|
return (int)NativeMethods.sp_pixel_grid_width(Instance);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Height
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-05-26 13:15:11 +02:00
|
|
|
return (int)NativeMethods.sp_pixel_grid_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-05-26 13:15:11 +02:00
|
|
|
var slice = NativeMethods.sp_pixel_grid_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-05-13 00:17:40 +02:00
|
|
|
private unsafe PixelGrid(BindGen.PixelGrid* instance) : base(instance)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
private protected override unsafe void Dealloc()
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
2024-05-26 13:15:11 +02:00
|
|
|
NativeMethods.sp_pixel_grid_dealloc(Instance);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|