rename sp_bit_vec_* to sp_bitvec_*
This commit is contained in:
parent
fbc8cd6c31
commit
c6450d7759
4 changed files with 490 additions and 490 deletions
|
|
@ -196,213 +196,6 @@ typedef struct SPByteSlice {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
/**
|
|
||||||
* Clones a [SPBitVec].
|
|
||||||
*
|
|
||||||
* returns: new [SPBitVec] instance. Will never return NULL.
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `bit_vec` is NULL
|
|
||||||
*
|
|
||||||
* # Safety
|
|
||||||
*
|
|
||||||
* The caller has to make sure that:
|
|
||||||
*
|
|
||||||
* - `bit_vec` points to a valid [SPBitVec]
|
|
||||||
* - `bit_vec` is not written to concurrently
|
|
||||||
* - the returned instance is freed in some way, either by using a consuming function or
|
|
||||||
* by explicitly calling `sp_bitvec_free`.
|
|
||||||
*/
|
|
||||||
struct SPBitVec *sp_bitvec_clone(const struct SPBitVec *bit_vec);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of all bits in the [SPBitVec].
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
*
|
|
||||||
* - `bit_vec`: instance to write to
|
|
||||||
* - `value`: the value to set all bits to
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `bit_vec` is NULL
|
|
||||||
*
|
|
||||||
* # Safety
|
|
||||||
*
|
|
||||||
* The caller has to make sure that:
|
|
||||||
*
|
|
||||||
* - `bit_vec` points to a valid [SPBitVec]
|
|
||||||
* - `bit_vec` is not written to or read from concurrently
|
|
||||||
*/
|
|
||||||
void sp_bitvec_fill(struct SPBitVec *bit_vec, bool value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deallocates a [SPBitVec].
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `but_vec` is NULL
|
|
||||||
*
|
|
||||||
* # Safety
|
|
||||||
*
|
|
||||||
* The caller has to make sure that:
|
|
||||||
*
|
|
||||||
* - `bit_vec` points to a valid [SPBitVec]
|
|
||||||
* - `bit_vec` is not used concurrently or after this call
|
|
||||||
* - `bit_vec` was not passed to another consuming function, e.g. to create a [SPCommand]
|
|
||||||
*/
|
|
||||||
void sp_bitvec_free(struct SPBitVec *bit_vec);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of a bit from the [SPBitVec].
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
*
|
|
||||||
* - `bit_vec`: instance to read from
|
|
||||||
* - `index`: the bit index to read
|
|
||||||
*
|
|
||||||
* returns: value of the bit
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `bit_vec` is NULL
|
|
||||||
* - when accessing `index` out of bounds
|
|
||||||
*
|
|
||||||
* # Safety
|
|
||||||
*
|
|
||||||
* The caller has to make sure that:
|
|
||||||
*
|
|
||||||
* - `bit_vec` points to a valid [SPBitVec]
|
|
||||||
* - `bit_vec` is not written to concurrently
|
|
||||||
*/
|
|
||||||
bool sp_bitvec_get(const struct SPBitVec *bit_vec, size_t index);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if length is 0.
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
*
|
|
||||||
* - `bit_vec`: instance to write to
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `bit_vec` is NULL
|
|
||||||
*
|
|
||||||
* # Safety
|
|
||||||
*
|
|
||||||
* The caller has to make sure that:
|
|
||||||
*
|
|
||||||
* - `bit_vec` points to a valid [SPBitVec]
|
|
||||||
*/
|
|
||||||
bool sp_bitvec_is_empty(const struct SPBitVec *bit_vec);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the length of the [SPBitVec] in bits.
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
*
|
|
||||||
* - `bit_vec`: instance to write to
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `bit_vec` is NULL
|
|
||||||
*
|
|
||||||
* # Safety
|
|
||||||
*
|
|
||||||
* The caller has to make sure that:
|
|
||||||
*
|
|
||||||
* - `bit_vec` points to a valid [SPBitVec]
|
|
||||||
*/
|
|
||||||
size_t sp_bitvec_len(const struct SPBitVec *bit_vec);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interpret the data as a series of bits and load then into a new [SPBitVec] instance.
|
|
||||||
*
|
|
||||||
* returns: [SPBitVec] instance containing data. Will never return NULL.
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `data` is NULL
|
|
||||||
*
|
|
||||||
* # 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_bitvec_free`.
|
|
||||||
*/
|
|
||||||
struct SPBitVec *sp_bitvec_load(const uint8_t *data,
|
|
||||||
size_t data_length);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new [SPBitVec] instance.
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
*
|
|
||||||
* - `size`: size in bits.
|
|
||||||
*
|
|
||||||
* returns: [SPBitVec] with all bits set to false. Will never return NULL.
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `size` is not divisible 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_bitvec_free`.
|
|
||||||
*/
|
|
||||||
struct SPBitVec *sp_bitvec_new(size_t size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of a bit in the [SPBitVec].
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
*
|
|
||||||
* - `bit_vec`: instance to write to
|
|
||||||
* - `index`: the bit index to edit
|
|
||||||
* - `value`: the value to set the bit to
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `bit_vec` is NULL
|
|
||||||
* - when accessing `index` out of bounds
|
|
||||||
*
|
|
||||||
* # Safety
|
|
||||||
*
|
|
||||||
* The caller has to make sure that:
|
|
||||||
*
|
|
||||||
* - `bit_vec` points to a valid [SPBitVec]
|
|
||||||
* - `bit_vec` is not written to or read from concurrently
|
|
||||||
*/
|
|
||||||
void sp_bitvec_set(struct SPBitVec *bit_vec, size_t index, bool value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an unsafe reference to the data of the [SPBitVec] instance.
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
*
|
|
||||||
* - `bit_vec`: instance to write to
|
|
||||||
*
|
|
||||||
* # Panics
|
|
||||||
*
|
|
||||||
* - when `bit_vec` is NULL
|
|
||||||
*
|
|
||||||
* ## Safety
|
|
||||||
*
|
|
||||||
* The caller has to make sure that:
|
|
||||||
*
|
|
||||||
* - `bit_vec` points to a valid [SPBitVec]
|
|
||||||
* - the returned memory range is never accessed after the passed [SPBitVec] has been freed
|
|
||||||
* - the returned memory range is never accessed concurrently, either via the [SPBitVec] or directly
|
|
||||||
*/
|
|
||||||
struct SPByteSlice sp_bitvec_unsafe_data_ref(struct SPBitVec *bit_vec);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clones a [SPBitmap].
|
* Clones a [SPBitmap].
|
||||||
*
|
*
|
||||||
|
|
@ -616,6 +409,213 @@ struct SPByteSlice sp_bitmap_unsafe_data_ref(struct SPBitmap *bitmap);
|
||||||
*/
|
*/
|
||||||
size_t sp_bitmap_width(const struct SPBitmap *bitmap);
|
size_t sp_bitmap_width(const struct SPBitmap *bitmap);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones a [SPBitVec].
|
||||||
|
*
|
||||||
|
* returns: new [SPBitVec] instance. Will never return NULL.
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `bit_vec` is NULL
|
||||||
|
*
|
||||||
|
* # Safety
|
||||||
|
*
|
||||||
|
* The caller has to make sure that:
|
||||||
|
*
|
||||||
|
* - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
* - `bit_vec` is not written to concurrently
|
||||||
|
* - the returned instance is freed in some way, either by using a consuming function or
|
||||||
|
* by explicitly calling `sp_bitvec_free`.
|
||||||
|
*/
|
||||||
|
struct SPBitVec *sp_bitvec_clone(const struct SPBitVec *bit_vec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of all bits in the [SPBitVec].
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
|
* - `value`: the value to set all bits to
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `bit_vec` is NULL
|
||||||
|
*
|
||||||
|
* # Safety
|
||||||
|
*
|
||||||
|
* The caller has to make sure that:
|
||||||
|
*
|
||||||
|
* - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
* - `bit_vec` is not written to or read from concurrently
|
||||||
|
*/
|
||||||
|
void sp_bitvec_fill(struct SPBitVec *bit_vec, bool value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deallocates a [SPBitVec].
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `but_vec` is NULL
|
||||||
|
*
|
||||||
|
* # Safety
|
||||||
|
*
|
||||||
|
* The caller has to make sure that:
|
||||||
|
*
|
||||||
|
* - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
* - `bit_vec` is not used concurrently or after this call
|
||||||
|
* - `bit_vec` was not passed to another consuming function, e.g. to create a [SPCommand]
|
||||||
|
*/
|
||||||
|
void sp_bitvec_free(struct SPBitVec *bit_vec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of a bit from the [SPBitVec].
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bit_vec`: instance to read from
|
||||||
|
* - `index`: the bit index to read
|
||||||
|
*
|
||||||
|
* returns: value of the bit
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `bit_vec` is NULL
|
||||||
|
* - when accessing `index` out of bounds
|
||||||
|
*
|
||||||
|
* # Safety
|
||||||
|
*
|
||||||
|
* The caller has to make sure that:
|
||||||
|
*
|
||||||
|
* - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
* - `bit_vec` is not written to concurrently
|
||||||
|
*/
|
||||||
|
bool sp_bitvec_get(const struct SPBitVec *bit_vec, size_t index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if length is 0.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `bit_vec` is NULL
|
||||||
|
*
|
||||||
|
* # Safety
|
||||||
|
*
|
||||||
|
* The caller has to make sure that:
|
||||||
|
*
|
||||||
|
* - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
*/
|
||||||
|
bool sp_bitvec_is_empty(const struct SPBitVec *bit_vec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the length of the [SPBitVec] in bits.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `bit_vec` is NULL
|
||||||
|
*
|
||||||
|
* # Safety
|
||||||
|
*
|
||||||
|
* The caller has to make sure that:
|
||||||
|
*
|
||||||
|
* - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
*/
|
||||||
|
size_t sp_bitvec_len(const struct SPBitVec *bit_vec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interpret the data as a series of bits and load then into a new [SPBitVec] instance.
|
||||||
|
*
|
||||||
|
* returns: [SPBitVec] instance containing data. Will never return NULL.
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `data` is NULL
|
||||||
|
*
|
||||||
|
* # 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_bitvec_free`.
|
||||||
|
*/
|
||||||
|
struct SPBitVec *sp_bitvec_load(const uint8_t *data,
|
||||||
|
size_t data_length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new [SPBitVec] instance.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `size`: size in bits.
|
||||||
|
*
|
||||||
|
* returns: [SPBitVec] with all bits set to false. Will never return NULL.
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `size` is not divisible 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_bitvec_free`.
|
||||||
|
*/
|
||||||
|
struct SPBitVec *sp_bitvec_new(size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a bit in the [SPBitVec].
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
|
* - `index`: the bit index to edit
|
||||||
|
* - `value`: the value to set the bit to
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `bit_vec` is NULL
|
||||||
|
* - when accessing `index` out of bounds
|
||||||
|
*
|
||||||
|
* # Safety
|
||||||
|
*
|
||||||
|
* The caller has to make sure that:
|
||||||
|
*
|
||||||
|
* - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
* - `bit_vec` is not written to or read from concurrently
|
||||||
|
*/
|
||||||
|
void sp_bitvec_set(struct SPBitVec *bit_vec, size_t index, bool value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an unsafe reference to the data of the [SPBitVec] instance.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `bit_vec` is NULL
|
||||||
|
*
|
||||||
|
* ## Safety
|
||||||
|
*
|
||||||
|
* The caller has to make sure that:
|
||||||
|
*
|
||||||
|
* - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
* - the returned memory range is never accessed after the passed [SPBitVec] has been freed
|
||||||
|
* - the returned memory range is never accessed concurrently, either via the [SPBitVec] or directly
|
||||||
|
*/
|
||||||
|
struct SPByteSlice sp_bitvec_unsafe_data_ref(struct SPBitVec *bit_vec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clones a [SPBrightnessGrid].
|
* Clones a [SPBrightnessGrid].
|
||||||
*
|
*
|
||||||
|
|
|
||||||
284
crates/servicepoint_binding_c/src/bitvec.rs
Normal file
284
crates/servicepoint_binding_c/src/bitvec.rs
Normal file
|
|
@ -0,0 +1,284 @@
|
||||||
|
//! C functions for interacting with [SPBitVec]s
|
||||||
|
//!
|
||||||
|
//! prefix `sp_bitvec_`
|
||||||
|
|
||||||
|
use crate::SPByteSlice;
|
||||||
|
use servicepoint::bitvec::prelude::{BitVec, Msb0};
|
||||||
|
|
||||||
|
/// A vector of bits
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```C
|
||||||
|
/// SPBitVec vec = sp_bitvec_new(8);
|
||||||
|
/// sp_bitvec_set(vec, 5, true);
|
||||||
|
/// sp_bitvec_free(vec);
|
||||||
|
/// ```
|
||||||
|
pub struct SPBitVec(BitVec<u8, Msb0>);
|
||||||
|
|
||||||
|
impl From<BitVec<u8, Msb0>> for SPBitVec {
|
||||||
|
fn from(actual: BitVec<u8, Msb0>) -> Self {
|
||||||
|
Self(actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SPBitVec> for BitVec<u8, Msb0> {
|
||||||
|
fn from(value: SPBitVec) -> Self {
|
||||||
|
value.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clone for SPBitVec {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
SPBitVec(self.0.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new [SPBitVec] instance.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `size`: size in bits.
|
||||||
|
///
|
||||||
|
/// returns: [SPBitVec] with all bits set to false. Will never return NULL.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `size` is not divisible 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_bitvec_free`.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_new(size: usize) -> *mut SPBitVec {
|
||||||
|
let result = Box::into_raw(Box::new(SPBitVec(BitVec::repeat(false, size))));
|
||||||
|
assert!(!result.is_null());
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Interpret the data as a series of bits and load then into a new [SPBitVec] instance.
|
||||||
|
///
|
||||||
|
/// returns: [SPBitVec] instance containing data. Will never return NULL.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `data` is NULL
|
||||||
|
///
|
||||||
|
/// # 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_bitvec_free`.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_load(
|
||||||
|
data: *const u8,
|
||||||
|
data_length: usize,
|
||||||
|
) -> *mut SPBitVec {
|
||||||
|
assert!(!data.is_null());
|
||||||
|
let data = std::slice::from_raw_parts(data, data_length);
|
||||||
|
let result = Box::into_raw(Box::new(SPBitVec(BitVec::from_slice(data))));
|
||||||
|
assert!(!result.is_null());
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clones a [SPBitVec].
|
||||||
|
///
|
||||||
|
/// returns: new [SPBitVec] instance. Will never return NULL.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `bit_vec` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
/// - `bit_vec` is not written to concurrently
|
||||||
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||||
|
/// by explicitly calling `sp_bitvec_free`.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_clone(
|
||||||
|
bit_vec: *const SPBitVec,
|
||||||
|
) -> *mut SPBitVec {
|
||||||
|
assert!(!bit_vec.is_null());
|
||||||
|
let result = Box::into_raw(Box::new((*bit_vec).clone()));
|
||||||
|
assert!(!result.is_null());
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deallocates a [SPBitVec].
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `but_vec` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
/// - `bit_vec` is not used concurrently or after this call
|
||||||
|
/// - `bit_vec` was not passed to another consuming function, e.g. to create a [SPCommand]
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_free(bit_vec: *mut SPBitVec) {
|
||||||
|
assert!(!bit_vec.is_null());
|
||||||
|
_ = Box::from_raw(bit_vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets the value of a bit from the [SPBitVec].
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `bit_vec`: instance to read from
|
||||||
|
/// - `index`: the bit index to read
|
||||||
|
///
|
||||||
|
/// returns: value of the bit
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `bit_vec` is NULL
|
||||||
|
/// - when accessing `index` out of bounds
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
/// - `bit_vec` is not written to concurrently
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_get(
|
||||||
|
bit_vec: *const SPBitVec,
|
||||||
|
index: usize,
|
||||||
|
) -> bool {
|
||||||
|
assert!(!bit_vec.is_null());
|
||||||
|
*(*bit_vec).0.get(index).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the value of a bit in the [SPBitVec].
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `bit_vec`: instance to write to
|
||||||
|
/// - `index`: the bit index to edit
|
||||||
|
/// - `value`: the value to set the bit to
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `bit_vec` is NULL
|
||||||
|
/// - when accessing `index` out of bounds
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
/// - `bit_vec` is not written to or read from concurrently
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_set(
|
||||||
|
bit_vec: *mut SPBitVec,
|
||||||
|
index: usize,
|
||||||
|
value: bool,
|
||||||
|
) {
|
||||||
|
assert!(!bit_vec.is_null());
|
||||||
|
(*bit_vec).0.set(index, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the value of all bits in the [SPBitVec].
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `bit_vec`: instance to write to
|
||||||
|
/// - `value`: the value to set all bits to
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `bit_vec` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
/// - `bit_vec` is not written to or read from concurrently
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_fill(bit_vec: *mut SPBitVec, value: bool) {
|
||||||
|
assert!(!bit_vec.is_null());
|
||||||
|
(*bit_vec).0.fill(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets the length of the [SPBitVec] in bits.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `bit_vec`: instance to write to
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `bit_vec` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_len(bit_vec: *const SPBitVec) -> usize {
|
||||||
|
assert!(!bit_vec.is_null());
|
||||||
|
(*bit_vec).0.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if length is 0.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `bit_vec`: instance to write to
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `bit_vec` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_is_empty(bit_vec: *const SPBitVec) -> bool {
|
||||||
|
assert!(!bit_vec.is_null());
|
||||||
|
(*bit_vec).0.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets an unsafe reference to the data of the [SPBitVec] instance.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `bit_vec`: instance to write to
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `bit_vec` is NULL
|
||||||
|
///
|
||||||
|
/// ## Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `bit_vec` points to a valid [SPBitVec]
|
||||||
|
/// - the returned memory range is never accessed after the passed [SPBitVec] has been freed
|
||||||
|
/// - the returned memory range is never accessed concurrently, either via the [SPBitVec] or directly
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref(
|
||||||
|
bit_vec: *mut SPBitVec,
|
||||||
|
) -> SPByteSlice {
|
||||||
|
assert!(!bit_vec.is_null());
|
||||||
|
let data = (*bit_vec).0.as_raw_mut_slice();
|
||||||
|
SPByteSlice {
|
||||||
|
start: data.as_mut_ptr_range().start,
|
||||||
|
length: data.len(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
pub use crate::bit_vec::*;
|
pub use crate::bitvec::*;
|
||||||
pub use crate::bitmap::*;
|
pub use crate::bitmap::*;
|
||||||
pub use crate::brightness_grid::*;
|
pub use crate::brightness_grid::*;
|
||||||
pub use crate::byte_slice::*;
|
pub use crate::byte_slice::*;
|
||||||
|
|
@ -35,7 +35,7 @@ pub use crate::constants::*;
|
||||||
pub use crate::cp437_grid::*;
|
pub use crate::cp437_grid::*;
|
||||||
pub use crate::packet::*;
|
pub use crate::packet::*;
|
||||||
|
|
||||||
mod bit_vec;
|
mod bitvec;
|
||||||
mod bitmap;
|
mod bitmap;
|
||||||
mod brightness_grid;
|
mod brightness_grid;
|
||||||
mod byte_slice;
|
mod byte_slice;
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,171 @@ namespace ServicePoint.BindGen
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitvec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitvec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern ByteSlice sp_bitvec_unsafe_data_ref(BitVec* bit_vec);
|
public static extern ByteSlice sp_bitvec_unsafe_data_ref(BitVec* bit_vec);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of [SPConnection].
|
||||||
|
///
|
||||||
|
/// returns: NULL if connection fails, or connected instance
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `host` is null or an invalid host
|
||||||
|
///
|
||||||
|
/// # 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_connection_free`.
|
||||||
|
/// </summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "sp_connection_open", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern Connection* sp_connection_open(byte* host);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a [SPPacket] to the display using the [SPConnection].
|
||||||
|
///
|
||||||
|
/// The passed `packet` gets consumed.
|
||||||
|
///
|
||||||
|
/// returns: true in case of success
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `connection` is NULL
|
||||||
|
/// - when `packet` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `connection` points to a valid instance of [SPConnection]
|
||||||
|
/// - `packet` points to a valid instance of [SPPacket]
|
||||||
|
/// - `packet` is not used concurrently or after this call
|
||||||
|
/// </summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "sp_connection_send_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
[return: MarshalAs(UnmanagedType.U1)]
|
||||||
|
public static extern bool sp_connection_send_packet(Connection* connection, Packet* packet);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a [SPCommand] to the display using the [SPConnection].
|
||||||
|
///
|
||||||
|
/// The passed `command` gets consumed.
|
||||||
|
///
|
||||||
|
/// returns: true in case of success
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `connection` is NULL
|
||||||
|
/// - when `command` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `connection` points to a valid instance of [SPConnection]
|
||||||
|
/// - `command` points to a valid instance of [SPPacket]
|
||||||
|
/// - `command` is not used concurrently or after this call
|
||||||
|
/// </summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "sp_connection_send_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
[return: MarshalAs(UnmanagedType.U1)]
|
||||||
|
public static extern bool sp_connection_send_command(Connection* connection, Command* command);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closes and deallocates a [SPConnection].
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `connection` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `connection` points to a valid [SPConnection]
|
||||||
|
/// - `connection` is not used concurrently or after this call
|
||||||
|
/// </summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "sp_connection_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern void sp_connection_free(Connection* connection);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Turns a [SPCommand] into a [SPPacket].
|
||||||
|
/// The [SPCommand] gets consumed.
|
||||||
|
///
|
||||||
|
/// Will never return NULL.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `command` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - [SPCommand] points to a valid instance of [SPCommand]
|
||||||
|
/// - [SPCommand] is not used concurrently or after this call
|
||||||
|
/// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or
|
||||||
|
/// by explicitly calling `sp_packet_free`.
|
||||||
|
/// </summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "sp_packet_from_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern Packet* sp_packet_from_command(Command* command);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tries to load a [SPPacket] from the passed array with the specified length.
|
||||||
|
///
|
||||||
|
/// returns: NULL in case of an error, pointer to the allocated packet otherwise
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `data` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `data` points to a valid memory region of at least `length` bytes
|
||||||
|
/// - `data` is not written to concurrently
|
||||||
|
/// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or
|
||||||
|
/// by explicitly calling `sp_packet_free`.
|
||||||
|
/// </summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "sp_packet_try_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern Packet* sp_packet_try_load(byte* data, nuint length);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clones a [SPPacket].
|
||||||
|
///
|
||||||
|
/// Will never return NULL.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `packet` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `packet` points to a valid [SPPacket]
|
||||||
|
/// - `packet` is not written to concurrently
|
||||||
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||||
|
/// by explicitly calling `sp_packet_free`.
|
||||||
|
/// </summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "sp_packet_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern Packet* sp_packet_clone(Packet* packet);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deallocates a [SPPacket].
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `sp_packet_free` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `packet` points to a valid [SPPacket]
|
||||||
|
/// - `packet` is not used concurrently or after this call
|
||||||
|
/// </summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "sp_packet_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern void sp_packet_free(Packet* packet);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new [SPBrightnessGrid] with the specified dimensions.
|
/// Creates a new [SPBrightnessGrid] with the specified dimensions.
|
||||||
///
|
///
|
||||||
|
|
@ -465,194 +630,125 @@ namespace ServicePoint.BindGen
|
||||||
public static extern ByteSlice sp_brightness_grid_unsafe_data_ref(BrightnessGrid* brightness_grid);
|
public static extern ByteSlice sp_brightness_grid_unsafe_data_ref(BrightnessGrid* brightness_grid);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of [SPConnection].
|
/// Creates a new [SPBitmap] with the specified dimensions.
|
||||||
///
|
///
|
||||||
/// returns: NULL if connection fails, or connected instance
|
/// # 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
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `host` is null or an invalid host
|
/// - when the width is not dividable by 8
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||||
/// by explicitly calling `sp_connection_free`.
|
/// by explicitly calling `sp_bitmap_free`.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_connection_open", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern Connection* sp_connection_open(byte* host);
|
public static extern Bitmap* sp_bitmap_new(nuint width, nuint height);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a [SPPacket] to the display using the [SPConnection].
|
/// Loads a [SPBitmap] with the specified dimensions from the provided data.
|
||||||
///
|
///
|
||||||
/// The passed `packet` gets consumed.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// returns: true in case of success
|
/// - `width`: size in pixels in x-direction
|
||||||
|
/// - `height`: size in pixels in y-direction
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// returns: [SPBitmap] that contains a copy of the provided data. Will never return NULL.
|
||||||
///
|
|
||||||
/// - when `connection` is NULL
|
|
||||||
/// - when `packet` is NULL
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The caller has to make sure that:
|
|
||||||
///
|
|
||||||
/// - `connection` points to a valid instance of [SPConnection]
|
|
||||||
/// - `packet` points to a valid instance of [SPPacket]
|
|
||||||
/// - `packet` is not used concurrently or after this call
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(__DllName, EntryPoint = "sp_connection_send_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
||||||
[return: MarshalAs(UnmanagedType.U1)]
|
|
||||||
public static extern bool sp_connection_send_packet(Connection* connection, Packet* packet);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sends a [SPCommand] to the display using the [SPConnection].
|
|
||||||
///
|
|
||||||
/// The passed `command` gets consumed.
|
|
||||||
///
|
|
||||||
/// returns: true in case of success
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when `connection` is NULL
|
|
||||||
/// - when `command` is NULL
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The caller has to make sure that:
|
|
||||||
///
|
|
||||||
/// - `connection` points to a valid instance of [SPConnection]
|
|
||||||
/// - `command` points to a valid instance of [SPPacket]
|
|
||||||
/// - `command` is not used concurrently or after this call
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(__DllName, EntryPoint = "sp_connection_send_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
||||||
[return: MarshalAs(UnmanagedType.U1)]
|
|
||||||
public static extern bool sp_connection_send_command(Connection* connection, Command* command);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Closes and deallocates a [SPConnection].
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when `connection` is NULL
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The caller has to make sure that:
|
|
||||||
///
|
|
||||||
/// - `connection` points to a valid [SPConnection]
|
|
||||||
/// - `connection` is not used concurrently or after this call
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(__DllName, EntryPoint = "sp_connection_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
||||||
public static extern void sp_connection_free(Connection* connection);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new [SPCp437Grid] with the specified dimensions.
|
|
||||||
///
|
|
||||||
/// returns: [SPCp437Grid] initialized to 0. 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_cp437_grid_free`.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
||||||
public static extern Cp437Grid* sp_cp437_grid_new(nuint width, nuint height);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Loads a [SPCp437Grid] with the specified dimensions from the provided data.
|
|
||||||
///
|
|
||||||
/// Will never return NULL.
|
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `data` is NULL
|
/// - when `data` is NULL
|
||||||
/// - when the provided `data_length` does not match `height` and `width`
|
/// - when the dimensions and data size do not match exactly.
|
||||||
|
/// - when the width is not dividable by 8
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `data` points to a valid memory location of at least `data_length`
|
/// - `data` points to a valid memory location of at least `data_length` bytes in size.
|
||||||
/// bytes in size.
|
|
||||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||||
/// by explicitly calling `sp_cp437_grid_free`.
|
/// by explicitly calling `sp_bitmap_free`.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern Cp437Grid* sp_cp437_grid_load(nuint width, nuint height, byte* data, nuint data_length);
|
public static extern Bitmap* sp_bitmap_load(nuint width, nuint height, byte* data, nuint data_length);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clones a [SPCp437Grid].
|
/// Clones a [SPBitmap].
|
||||||
///
|
///
|
||||||
/// Will never return NULL.
|
/// Will never return NULL.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `cp437_grid` is NULL
|
/// - when `bitmap` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
/// - `cp437_grid` is not written to concurrently
|
/// - `bitmap` is not written to concurrently
|
||||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||||
/// by explicitly calling `sp_cp437_grid_free`.
|
/// by explicitly calling `sp_bitmap_free`.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern Cp437Grid* sp_cp437_grid_clone(Cp437Grid* cp437_grid);
|
public static extern Bitmap* sp_bitmap_clone(Bitmap* bitmap);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deallocates a [SPCp437Grid].
|
/// Deallocates a [SPBitmap].
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `cp437_grid` is NULL
|
/// - when `bitmap` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
/// - `cp437_grid` is not used concurrently or after cp437_grid call
|
/// - `bitmap` is not used concurrently or after bitmap call
|
||||||
/// - `cp437_grid` was not passed to another consuming function, e.g. to create a [SPCommand]
|
/// - `bitmap` was not passed to another consuming function, e.g. to create a [SPCommand]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void sp_cp437_grid_free(Cp437Grid* cp437_grid);
|
public static extern void sp_bitmap_free(Bitmap* bitmap);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current value at the specified position.
|
/// Gets the current value at the specified position in the [SPBitmap].
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `cp437_grid`: instance to read from
|
/// - `bitmap`: instance to read from
|
||||||
/// - `x` and `y`: position of the cell to read
|
/// - `x` and `y`: position of the cell to read
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `cp437_grid` is NULL
|
/// - when `bitmap` is NULL
|
||||||
/// - when accessing `x` or `y` out of bounds
|
/// - when accessing `x` or `y` out of bounds
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
/// - `cp437_grid` is not written to concurrently
|
/// - `bitmap` is not written to concurrently
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern byte sp_cp437_grid_get(Cp437Grid* cp437_grid, nuint x, nuint y);
|
[return: MarshalAs(UnmanagedType.U1)]
|
||||||
|
public static extern bool sp_bitmap_get(Bitmap* bitmap, nuint x, nuint y);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the value of the specified position in the [SPCp437Grid].
|
/// Sets the value of the specified position in the [SPBitmap].
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `cp437_grid`: instance to write to
|
/// - `bitmap`: instance to write to
|
||||||
/// - `x` and `y`: position of the cell
|
/// - `x` and `y`: position of the cell
|
||||||
/// - `value`: the value to write to the cell
|
/// - `value`: the value to write to the cell
|
||||||
///
|
///
|
||||||
|
|
@ -660,181 +756,98 @@ namespace ServicePoint.BindGen
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `cp437_grid` is NULL
|
/// - when `bitmap` is NULL
|
||||||
/// - when accessing `x` or `y` out of bounds
|
/// - when accessing `x` or `y` out of bounds
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `cp437_grid` points to a valid [SPBitVec]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
/// - `cp437_grid` is not written to or read from concurrently
|
/// - `bitmap` is not written to or read from concurrently
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void sp_cp437_grid_set(Cp437Grid* cp437_grid, nuint x, nuint y, byte value);
|
public static extern void sp_bitmap_set(Bitmap* bitmap, nuint x, nuint y, [MarshalAs(UnmanagedType.U1)] bool value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the value of all cells in the [SPCp437Grid].
|
/// Sets the state of all pixels in the [SPBitmap].
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `cp437_grid`: instance to write to
|
/// - `bitmap`: instance to write to
|
||||||
/// - `value`: the value to set all cells to
|
/// - `value`: the value to set all pixels to
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `cp437_grid` is NULL
|
/// - when `bitmap` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
/// - `cp437_grid` is not written to or read from concurrently
|
/// - `bitmap` is not written to or read from concurrently
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void sp_cp437_grid_fill(Cp437Grid* cp437_grid, byte value);
|
public static extern void sp_bitmap_fill(Bitmap* bitmap, [MarshalAs(UnmanagedType.U1)] bool value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the width of the [SPCp437Grid] instance.
|
/// Gets the width in pixels of the [SPBitmap] instance.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `cp437_grid`: instance to read from
|
/// - `bitmap`: instance to read from
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `cp437_grid` is NULL
|
/// - when `bitmap` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern nuint sp_cp437_grid_width(Cp437Grid* cp437_grid);
|
public static extern nuint sp_bitmap_width(Bitmap* bitmap);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the height of the [SPCp437Grid] instance.
|
/// Gets the height in pixels of the [SPBitmap] instance.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `cp437_grid`: instance to read from
|
/// - `bitmap`: instance to read from
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `cp437_grid` is NULL
|
/// - when `bitmap` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern nuint sp_cp437_grid_height(Cp437Grid* cp437_grid);
|
public static extern nuint sp_bitmap_height(Bitmap* bitmap);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets an unsafe reference to the data of the [SPCp437Grid] instance.
|
/// Gets an unsafe reference to the data of the [SPBitmap] instance.
|
||||||
///
|
|
||||||
/// Will never return NULL.
|
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `cp437_grid` is NULL
|
/// - when `bitmap` is NULL
|
||||||
///
|
|
||||||
/// ## Safety
|
|
||||||
///
|
|
||||||
/// The caller has to make sure that:
|
|
||||||
///
|
|
||||||
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
|
||||||
/// - the returned memory range is never accessed after the passed [SPCp437Grid] has been freed
|
|
||||||
/// - the returned memory range is never accessed concurrently, either via the [SPCp437Grid] or directly
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
||||||
public static extern ByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid* cp437_grid);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Turns a [SPCommand] into a [SPPacket].
|
|
||||||
/// The [SPCommand] gets consumed.
|
|
||||||
///
|
|
||||||
/// Will never return NULL.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when `command` is NULL
|
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - [SPCommand] points to a valid instance of [SPCommand]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
/// - [SPCommand] is not used concurrently or after this call
|
/// - the returned memory range is never accessed after the passed [SPBitmap] has been freed
|
||||||
/// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or
|
/// - the returned memory range is never accessed concurrently, either via the [SPBitmap] or directly
|
||||||
/// by explicitly calling `sp_packet_free`.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_packet_from_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_bitmap_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern Packet* sp_packet_from_command(Command* command);
|
public static extern ByteSlice sp_bitmap_unsafe_data_ref(Bitmap* bitmap);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tries to load a [SPPacket] from the passed array with the specified length.
|
|
||||||
///
|
|
||||||
/// returns: NULL in case of an error, pointer to the allocated packet otherwise
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when `data` is NULL
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The caller has to make sure that:
|
|
||||||
///
|
|
||||||
/// - `data` points to a valid memory region of at least `length` bytes
|
|
||||||
/// - `data` is not written to concurrently
|
|
||||||
/// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or
|
|
||||||
/// by explicitly calling `sp_packet_free`.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(__DllName, EntryPoint = "sp_packet_try_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
||||||
public static extern Packet* sp_packet_try_load(byte* data, nuint length);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clones a [SPPacket].
|
|
||||||
///
|
|
||||||
/// Will never return NULL.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when `packet` is NULL
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The caller has to make sure that:
|
|
||||||
///
|
|
||||||
/// - `packet` points to a valid [SPPacket]
|
|
||||||
/// - `packet` is not written to concurrently
|
|
||||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
|
||||||
/// by explicitly calling `sp_packet_free`.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(__DllName, EntryPoint = "sp_packet_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
||||||
public static extern Packet* sp_packet_clone(Packet* packet);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deallocates a [SPPacket].
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when `sp_packet_free` is NULL
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The caller has to make sure that:
|
|
||||||
///
|
|
||||||
/// - `packet` points to a valid [SPPacket]
|
|
||||||
/// - `packet` is not used concurrently or after this call
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(__DllName, EntryPoint = "sp_packet_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
||||||
public static extern void sp_packet_free(Packet* packet);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to turn a [SPPacket] into a [SPCommand].
|
/// Tries to turn a [SPPacket] into a [SPCommand].
|
||||||
|
|
@ -1172,125 +1185,110 @@ namespace ServicePoint.BindGen
|
||||||
public static extern void sp_command_free(Command* command);
|
public static extern void sp_command_free(Command* command);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new [SPBitmap] with the specified dimensions.
|
/// Creates a new [SPCp437Grid] with the specified dimensions.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// returns: [SPCp437Grid] initialized to 0. Will never return NULL.
|
||||||
///
|
|
||||||
/// - `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
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||||
/// by explicitly calling `sp_bitmap_free`.
|
/// by explicitly calling `sp_cp437_grid_free`.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern Bitmap* sp_bitmap_new(nuint width, nuint height);
|
public static extern Cp437Grid* sp_cp437_grid_new(nuint width, nuint height);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads a [SPBitmap] with the specified dimensions from the provided data.
|
/// Loads a [SPCp437Grid] 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`.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
||||||
public static extern Bitmap* sp_bitmap_load(nuint width, nuint height, byte* data, nuint data_length);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clones a [SPBitmap].
|
|
||||||
///
|
///
|
||||||
/// Will never return NULL.
|
/// Will never return NULL.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `bitmap` is NULL
|
/// - when `data` is NULL
|
||||||
|
/// - when the provided `data_length` does not match `height` and `width`
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `data` points to a valid memory location of at least `data_length`
|
||||||
/// - `bitmap` is not written to concurrently
|
/// bytes in size.
|
||||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||||
/// by explicitly calling `sp_bitmap_free`.
|
/// by explicitly calling `sp_cp437_grid_free`.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern Bitmap* sp_bitmap_clone(Bitmap* bitmap);
|
public static extern Cp437Grid* sp_cp437_grid_load(nuint width, nuint height, byte* data, nuint data_length);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deallocates a [SPBitmap].
|
/// Clones a [SPCp437Grid].
|
||||||
|
///
|
||||||
|
/// Will never return NULL.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `bitmap` is NULL
|
/// - when `cp437_grid` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
||||||
/// - `bitmap` is not used concurrently or after bitmap call
|
/// - `cp437_grid` is not written to concurrently
|
||||||
/// - `bitmap` was not passed to another consuming function, e.g. to create a [SPCommand]
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||||
|
/// by explicitly calling `sp_cp437_grid_free`.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void sp_bitmap_free(Bitmap* bitmap);
|
public static extern Cp437Grid* sp_cp437_grid_clone(Cp437Grid* cp437_grid);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current value at the specified position in the [SPBitmap].
|
/// Deallocates a [SPCp437Grid].
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `cp437_grid` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
||||||
|
/// - `cp437_grid` is not used concurrently or after cp437_grid call
|
||||||
|
/// - `cp437_grid` was not passed to another consuming function, e.g. to create a [SPCommand]
|
||||||
|
/// </summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern void sp_cp437_grid_free(Cp437Grid* cp437_grid);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current value at the specified position.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `bitmap`: instance to read from
|
/// - `cp437_grid`: instance to read from
|
||||||
/// - `x` and `y`: position of the cell to read
|
/// - `x` and `y`: position of the cell to read
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `bitmap` is NULL
|
/// - when `cp437_grid` is NULL
|
||||||
/// - when accessing `x` or `y` out of bounds
|
/// - when accessing `x` or `y` out of bounds
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
||||||
/// - `bitmap` is not written to concurrently
|
/// - `cp437_grid` is not written to concurrently
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
[return: MarshalAs(UnmanagedType.U1)]
|
public static extern byte sp_cp437_grid_get(Cp437Grid* cp437_grid, nuint x, nuint y);
|
||||||
public static extern bool sp_bitmap_get(Bitmap* bitmap, nuint x, nuint y);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the value of the specified position in the [SPBitmap].
|
/// Sets the value of the specified position in the [SPCp437Grid].
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `bitmap`: instance to write to
|
/// - `cp437_grid`: instance to write to
|
||||||
/// - `x` and `y`: position of the cell
|
/// - `x` and `y`: position of the cell
|
||||||
/// - `value`: the value to write to the cell
|
/// - `value`: the value to write to the cell
|
||||||
///
|
///
|
||||||
|
|
@ -1298,98 +1296,100 @@ namespace ServicePoint.BindGen
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `bitmap` is NULL
|
/// - when `cp437_grid` is NULL
|
||||||
/// - when accessing `x` or `y` out of bounds
|
/// - when accessing `x` or `y` out of bounds
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `cp437_grid` points to a valid [SPBitVec]
|
||||||
/// - `bitmap` is not written to or read from concurrently
|
/// - `cp437_grid` is not written to or read from concurrently
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void sp_bitmap_set(Bitmap* bitmap, nuint x, nuint y, [MarshalAs(UnmanagedType.U1)] bool value);
|
public static extern void sp_cp437_grid_set(Cp437Grid* cp437_grid, nuint x, nuint y, byte value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the state of all pixels in the [SPBitmap].
|
/// Sets the value of all cells in the [SPCp437Grid].
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `bitmap`: instance to write to
|
/// - `cp437_grid`: instance to write to
|
||||||
/// - `value`: the value to set all pixels to
|
/// - `value`: the value to set all cells to
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `bitmap` is NULL
|
/// - when `cp437_grid` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
||||||
/// - `bitmap` is not written to or read from concurrently
|
/// - `cp437_grid` is not written to or read from concurrently
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void sp_bitmap_fill(Bitmap* bitmap, [MarshalAs(UnmanagedType.U1)] bool value);
|
public static extern void sp_cp437_grid_fill(Cp437Grid* cp437_grid, byte value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the width in pixels of the [SPBitmap] instance.
|
/// Gets the width of the [SPCp437Grid] instance.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `bitmap`: instance to read from
|
/// - `cp437_grid`: instance to read from
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `bitmap` is NULL
|
/// - when `cp437_grid` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern nuint sp_bitmap_width(Bitmap* bitmap);
|
public static extern nuint sp_cp437_grid_width(Cp437Grid* cp437_grid);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the height in pixels of the [SPBitmap] instance.
|
/// Gets the height of the [SPCp437Grid] instance.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// - `bitmap`: instance to read from
|
/// - `cp437_grid`: instance to read from
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `bitmap` is NULL
|
/// - when `cp437_grid` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern nuint sp_bitmap_height(Bitmap* bitmap);
|
public static extern nuint sp_cp437_grid_height(Cp437Grid* cp437_grid);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets an unsafe reference to the data of the [SPBitmap] instance.
|
/// Gets an unsafe reference to the data of the [SPCp437Grid] instance.
|
||||||
|
///
|
||||||
|
/// Will never return NULL.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when `bitmap` is NULL
|
/// - when `cp437_grid` is NULL
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// ## Safety
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that:
|
/// The caller has to make sure that:
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `cp437_grid` points to a valid [SPCp437Grid]
|
||||||
/// - the returned memory range is never accessed after the passed [SPBitmap] has been freed
|
/// - the returned memory range is never accessed after the passed [SPCp437Grid] has been freed
|
||||||
/// - the returned memory range is never accessed concurrently, either via the [SPBitmap] or directly
|
/// - the returned memory range is never accessed concurrently, either via the [SPCp437Grid] or directly
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(__DllName, EntryPoint = "sp_bitmap_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern ByteSlice sp_bitmap_unsafe_data_ref(Bitmap* bitmap);
|
public static extern ByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid* cp437_grid);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1399,11 +1399,6 @@ namespace ServicePoint.BindGen
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe partial struct BrightnessGrid
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public unsafe partial struct ByteSlice
|
public unsafe partial struct ByteSlice
|
||||||
{
|
{
|
||||||
|
|
@ -1417,12 +1412,17 @@ namespace ServicePoint.BindGen
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public unsafe partial struct Cp437Grid
|
public unsafe partial struct Packet
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public unsafe partial struct Packet
|
public unsafe partial struct BrightnessGrid
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public unsafe partial struct Bitmap
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1432,7 +1432,7 @@ namespace ServicePoint.BindGen
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public unsafe partial struct Bitmap
|
public unsafe partial struct Cp437Grid
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue