Compare commits
No commits in common. "a418e4f0c3dcf3aaa26193bec72f016afc98d112" and "f483b5a2d5e3deea2b43a11b86cf65a20968bcb5" have entirely different histories.
a418e4f0c3
...
f483b5a2d5
|
@ -24,7 +24,7 @@ sort_by = "Name"
|
||||||
|
|
||||||
[parse]
|
[parse]
|
||||||
parse_deps = true
|
parse_deps = true
|
||||||
include = ["servicepoint", "std"]
|
include = ["servicepoint"]
|
||||||
extra_bindings = ["servicepoint"]
|
extra_bindings = ["servicepoint"]
|
||||||
|
|
||||||
[parse.expand]
|
[parse.expand]
|
||||||
|
|
|
@ -388,15 +388,6 @@ void sp_bitmap_fill(Bitmap */*notnull*/ bitmap, bool value);
|
||||||
*/
|
*/
|
||||||
void sp_bitmap_free(Bitmap */*notnull*/ bitmap);
|
void sp_bitmap_free(Bitmap */*notnull*/ bitmap);
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to convert the BitVec to a Bitmap.
|
|
||||||
*
|
|
||||||
* The provided BitVec gets consumed.
|
|
||||||
*
|
|
||||||
* Returns NULL in case of error.
|
|
||||||
*/
|
|
||||||
Bitmap *sp_bitmap_from_bitvec(size_t width, SPBitVec */*notnull*/ bitvec);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current value at the specified position in the [Bitmap].
|
* Gets the current value at the specified position in the [Bitmap].
|
||||||
*
|
*
|
||||||
|
@ -420,11 +411,6 @@ bool sp_bitmap_get(Bitmap */*notnull*/ bitmap, size_t x, size_t y);
|
||||||
*/
|
*/
|
||||||
size_t sp_bitmap_height(Bitmap */*notnull*/ bitmap);
|
size_t sp_bitmap_height(Bitmap */*notnull*/ bitmap);
|
||||||
|
|
||||||
/**
|
|
||||||
* Consumes the Bitmap and returns the contained BitVec
|
|
||||||
*/
|
|
||||||
SPBitVec */*notnull*/ sp_bitmap_into_bitvec(Bitmap */*notnull*/ bitmap);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a [Bitmap] with the specified dimensions from the provided data.
|
* Loads a [Bitmap] with the specified dimensions from the provided data.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::byte_slice::ByteSlice;
|
use crate::byte_slice::ByteSlice;
|
||||||
use crate::{heap_drop, heap_move, heap_move_nonnull, SPBitVec};
|
use crate::{heap_drop, heap_move, heap_move_nonnull};
|
||||||
use servicepoint::{Bitmap, DataRef, Grid};
|
use servicepoint::{Bitmap, DataRef, Grid};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
|
@ -68,24 +68,6 @@ pub unsafe extern "C" fn sp_bitmap_load(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to convert the BitVec to a Bitmap.
|
|
||||||
///
|
|
||||||
/// The provided BitVec gets consumed.
|
|
||||||
///
|
|
||||||
/// Returns NULL in case of error.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_bitmap_from_bitvec(
|
|
||||||
width: usize,
|
|
||||||
bitvec: NonNull<SPBitVec>,
|
|
||||||
) -> *mut Bitmap {
|
|
||||||
let bitvec = unsafe { *Box::from_raw(bitvec.as_ptr()) };
|
|
||||||
if let Ok(bitmap) = Bitmap::from_bitvec(width, bitvec.0) {
|
|
||||||
heap_move(bitmap)
|
|
||||||
} else {
|
|
||||||
std::ptr::null_mut()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clones a [Bitmap].
|
/// Clones a [Bitmap].
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_bitmap_clone(
|
pub unsafe extern "C" fn sp_bitmap_clone(
|
||||||
|
@ -190,12 +172,3 @@ pub unsafe extern "C" fn sp_bitmap_unsafe_data_ref(
|
||||||
) -> ByteSlice {
|
) -> ByteSlice {
|
||||||
unsafe { ByteSlice::from_slice(bitmap.as_mut().data_ref_mut()) }
|
unsafe { ByteSlice::from_slice(bitmap.as_mut().data_ref_mut()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consumes the Bitmap and returns the contained BitVec
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_bitmap_into_bitvec(
|
|
||||||
bitmap: NonNull<Bitmap>,
|
|
||||||
) -> NonNull<SPBitVec> {
|
|
||||||
let bitmap = unsafe { *Box::from_raw(bitmap.as_ptr()) };
|
|
||||||
heap_move_nonnull(SPBitVec(bitmap.into()))
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,8 +30,6 @@ pub unsafe extern "C" fn sp_brightness_grid_new(
|
||||||
|
|
||||||
/// Loads a [BrightnessGrid] with the specified dimensions from the provided data.
|
/// Loads a [BrightnessGrid] with the specified dimensions from the provided data.
|
||||||
///
|
///
|
||||||
/// Any out of range values will be set to [Brightness::MAX] or [Brightness::MIN].
|
|
||||||
///
|
|
||||||
/// returns: new [BrightnessGrid] instance, or NULL in case of an error.
|
/// returns: new [BrightnessGrid] instance, or NULL in case of an error.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_brightness_grid_load(
|
pub unsafe extern "C" fn sp_brightness_grid_load(
|
||||||
|
@ -40,12 +38,14 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
|
||||||
data: ByteSlice,
|
data: ByteSlice,
|
||||||
) -> *mut BrightnessGrid {
|
) -> *mut BrightnessGrid {
|
||||||
let data = unsafe { data.as_slice() };
|
let data = unsafe { data.as_slice() };
|
||||||
|
let grid = match ByteGrid::load(width, height, data) {
|
||||||
match ByteGrid::load(width, height, data)
|
None => return std::ptr::null_mut(),
|
||||||
.map(move |grid| grid.map(Brightness::saturating_from))
|
Some(grid) => grid,
|
||||||
{
|
};
|
||||||
None => std::ptr::null_mut(),
|
if let Ok(grid) = BrightnessGrid::try_from(grid) {
|
||||||
Some(grid) => heap_move(grid),
|
heap_move(grid)
|
||||||
|
} else {
|
||||||
|
std::ptr::null_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue