add sp_bitmap_new_screen_sized

This commit is contained in:
Vinzenz Schroeter 2024-10-20 12:35:14 +02:00
parent bcd65fb4f0
commit 52b1ce83d9
2 changed files with 37 additions and 0 deletions

View file

@ -47,6 +47,22 @@ pub unsafe extern "C" fn sp_bitmap_new(
NonNull::from(Box::leak(result)) NonNull::from(Box::leak(result))
} }
/// Creates a new [SPBitmap] with a size matching the screen.
///
/// returns: [SPBitmap] initialized to all pixels off. Will never return NULL.
///
/// # 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`.
#[no_mangle]
pub unsafe extern "C" fn sp_bitmap_new_screen_sized() -> NonNull<SPBitmap> {
let result = Box::new(SPBitmap(servicepoint::Bitmap::max_sized()));
NonNull::from(Box::leak(result))
}
/// Loads a [SPBitmap] with the specified dimensions from the provided data. /// Loads a [SPBitmap] with the specified dimensions from the provided data.
/// ///
/// # Arguments /// # Arguments

View file

@ -37,6 +37,24 @@ namespace ServicePoint
/// </summary> /// </summary>
public Bitmap(nuint width, nuint height) : this(sp_bitmap_new(width, height)) {} public Bitmap(nuint width, nuint height) : this(sp_bitmap_new(width, height)) {}
/// <summary>
/// Creates a new [SPBitmap] with a size matching the screen.
///
/// returns: [SPBitmap] initialized to all pixels off. Will never return NULL.
///
/// # 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`.
/// </summary>
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Bitmap NewScreenSized()
{
return new Bitmap(Bitmap.sp_bitmap_new_screen_sized());
}
/// <summary> /// <summary>
/// Loads a [SPBitmap] with the specified dimensions from the provided data. /// Loads a [SPBitmap] with the specified dimensions from the provided data.
/// ///
@ -286,6 +304,9 @@ namespace ServicePoint
[DllImport(__DllName, EntryPoint = "sp_bitmap_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport(__DllName, EntryPoint = "sp_bitmap_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPBitmap* sp_bitmap_new(nuint width, nuint height); private static extern SPBitmap* sp_bitmap_new(nuint width, nuint height);
[DllImport(__DllName, EntryPoint = "sp_bitmap_new_screen_sized", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPBitmap* sp_bitmap_new_screen_sized();
[DllImport(__DllName, EntryPoint = "sp_bitmap_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [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); private static extern SPBitmap* sp_bitmap_load(nuint width, nuint height, byte* data, nuint data_length);