// // This code is generated by csbindgen. // DON'T CHANGE THIS DIRECTLY. // #pragma warning disable CS8500 #pragma warning disable CS8981 using System; using System.Runtime.InteropServices; namespace ServicePoint { public unsafe sealed partial class Bitmap: IDisposable { #nullable enable /// /// Creates a new [SPBitmap] with the specified dimensions. /// /// # Arguments /// /// - `width`: size in pixels in x-direction /// - `height`: size in pixels in y-direction /// /// returns: [SPBitmap] initialized to all pixels off. Will never return NULL. /// /// # Panics /// /// - when the width is not dividable by 8 /// /// # Safety /// /// The caller has to make sure that: /// /// - the returned instance is freed in some way, either by using a consuming function or /// by explicitly calling `sp_bitmap_free`. /// public Bitmap(nuint width, nuint height) : this(sp_bitmap_new(width, height)) {} /// /// Loads a [SPBitmap] with the specified dimensions from the provided data. /// /// # Arguments /// /// - `width`: size in pixels in x-direction /// - `height`: size in pixels in y-direction /// /// returns: [SPBitmap] that contains a copy of the provided data. Will never return NULL. /// /// # Panics /// /// - when `data` is NULL /// - when the dimensions and data size do not match exactly. /// - when the width is not dividable by 8 /// /// # Safety /// /// The caller has to make sure that: /// /// - `data` points to a valid memory location of at least `data_length` bytes in size. /// - the returned instance is freed in some way, either by using a consuming function or /// by explicitly calling `sp_bitmap_free`. /// public static Bitmap Load(nuint width, nuint height, byte* data, nuint data_length) { return new Bitmap(Bitmap.sp_bitmap_load(width, height, data, data_length)); } /// /// Clones a [SPBitmap]. /// /// Will never return NULL. /// /// # Panics /// /// - when `bitmap` is NULL /// /// # Safety /// /// The caller has to make sure that: /// /// - `bitmap` points to a valid [SPBitmap] /// - `bitmap` is not written to concurrently /// - the returned instance is freed in some way, either by using a consuming function or /// by explicitly calling `sp_bitmap_free`. /// public Bitmap Clone() { return new Bitmap(Bitmap.sp_bitmap_clone(Instance)); } /// /// Gets the current value at the specified position in the [SPBitmap]. /// /// # Arguments /// /// - `bitmap`: instance to read from /// - `x` and `y`: position of the cell to read /// /// # Panics /// /// - when `bitmap` is NULL /// - when accessing `x` or `y` out of bounds /// /// # Safety /// /// The caller has to make sure that: /// /// - `bitmap` points to a valid [SPBitmap] /// - `bitmap` is not written to concurrently /// public bool Get(nuint x, nuint y) { return Bitmap.sp_bitmap_get(Instance, x, y); } /// /// Sets the value of the specified position in the [SPBitmap]. /// /// # Arguments /// /// - `bitmap`: instance to write to /// - `x` and `y`: position of the cell /// - `value`: the value to write to the cell /// /// returns: old value of the cell /// /// # Panics /// /// - when `bitmap` is NULL /// - when accessing `x` or `y` out of bounds /// /// # Safety /// /// The caller has to make sure that: /// /// - `bitmap` points to a valid [SPBitmap] /// - `bitmap` is not written to or read from concurrently /// public void Set(nuint x, nuint y, bool value) { Bitmap.sp_bitmap_set(Instance, x, y, value); } /// /// Sets the state of all pixels in the [SPBitmap]. /// /// # Arguments /// /// - `bitmap`: instance to write to /// - `value`: the value to set all pixels to /// /// # Panics /// /// - when `bitmap` is NULL /// /// # Safety /// /// The caller has to make sure that: /// /// - `bitmap` points to a valid [SPBitmap] /// - `bitmap` is not written to or read from concurrently /// public void Fill(bool value) { Bitmap.sp_bitmap_fill(Instance, value); } /// /// Gets the width in pixels of the [SPBitmap] instance. /// /// # Arguments /// /// - `bitmap`: instance to read from /// /// # Panics /// /// - when `bitmap` is NULL /// /// # Safety /// /// The caller has to make sure that: /// /// - `bitmap` points to a valid [SPBitmap] /// public nuint Width() { return Bitmap.sp_bitmap_width(Instance); } /// /// Gets the height in pixels of the [SPBitmap] instance. /// /// # Arguments /// /// - `bitmap`: instance to read from /// /// # Panics /// /// - when `bitmap` is NULL /// /// # Safety /// /// The caller has to make sure that: /// /// - `bitmap` points to a valid [SPBitmap] /// public nuint Height() { return Bitmap.sp_bitmap_height(Instance); } /// /// Gets an unsafe reference to the data of the [SPBitmap] instance. /// /// # Panics /// /// - when `bitmap` is NULL /// /// # Safety /// /// The caller has to make sure that: /// /// - `bitmap` points to a valid [SPBitmap] /// - the returned memory range is never accessed after the passed [SPBitmap] has been freed /// - the returned memory range is never accessed concurrently, either via the [SPBitmap] or directly /// public SPByteSlice UnsafeDataRef() { return Bitmap.sp_bitmap_unsafe_data_ref(Instance); } private SPBitmap* _instance; internal SPBitmap* Instance { get { if (_instance == null) throw new NullReferenceException("instance is null"); return _instance; } } private Bitmap(SPBitmap* instance) { ArgumentNullException.ThrowIfNull(instance); _instance = instance; } internal SPBitmap* Into() { var instance = Instance; _instance = null; return instance; } private void Free() { if (_instance != null) Bitmap.sp_bitmap_free(Into()); } public void Dispose() { Free(); GC.SuppressFinalize(this); } ~Bitmap() => Free(); const string __DllName = "servicepoint_binding_c"; #nullable restore [DllImport(__DllName, EntryPoint = "sp_bitmap_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBitmap* sp_bitmap_new(nuint width, nuint height); [DllImport(__DllName, EntryPoint = "sp_bitmap_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBitmap* sp_bitmap_load(nuint width, nuint height, byte* data, nuint data_length); [DllImport(__DllName, EntryPoint = "sp_bitmap_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBitmap* sp_bitmap_clone(SPBitmap* bitmap); [DllImport(__DllName, EntryPoint = "sp_bitmap_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_bitmap_free(SPBitmap* bitmap); [DllImport(__DllName, EntryPoint = "sp_bitmap_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool sp_bitmap_get(SPBitmap* bitmap, nuint x, nuint y); [DllImport(__DllName, EntryPoint = "sp_bitmap_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_bitmap_set(SPBitmap* bitmap, nuint x, nuint y, [MarshalAs(UnmanagedType.U1)] bool value); [DllImport(__DllName, EntryPoint = "sp_bitmap_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_bitmap_fill(SPBitmap* bitmap, [MarshalAs(UnmanagedType.U1)] bool value); [DllImport(__DllName, EntryPoint = "sp_bitmap_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern nuint sp_bitmap_width(SPBitmap* bitmap); [DllImport(__DllName, EntryPoint = "sp_bitmap_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern nuint sp_bitmap_height(SPBitmap* bitmap); [DllImport(__DllName, EntryPoint = "sp_bitmap_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPByteSlice sp_bitmap_unsafe_data_ref(SPBitmap* bitmap); } [StructLayout(LayoutKind.Sequential)] public unsafe partial struct SPBitmap { } }