2024-11-05 22:39:10 +01:00
|
|
|
use servicepoint::{DataRef, Grid};
|
2024-11-04 21:06:01 +01:00
|
|
|
use std::sync::{Arc, RwLock};
|
2024-11-04 19:20:40 +01:00
|
|
|
|
|
|
|
#[derive(uniffi::Object)]
|
|
|
|
pub struct Bitmap {
|
|
|
|
pub(crate) actual: RwLock<servicepoint::Bitmap>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Bitmap {
|
2024-11-04 21:06:01 +01:00
|
|
|
fn internal_new(actual: servicepoint::Bitmap) -> Arc<Self> {
|
|
|
|
Arc::new(Self {
|
|
|
|
actual: RwLock::new(actual),
|
|
|
|
})
|
2024-11-04 19:20:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[uniffi::export]
|
|
|
|
impl Bitmap {
|
|
|
|
#[uniffi::constructor]
|
|
|
|
pub fn new(width: u64, height: u64) -> Arc<Self> {
|
2024-11-04 21:06:01 +01:00
|
|
|
Self::internal_new(servicepoint::Bitmap::new(
|
|
|
|
width as usize,
|
|
|
|
height as usize,
|
|
|
|
))
|
2024-11-04 19:20:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[uniffi::constructor]
|
|
|
|
pub fn new_max_sized() -> Arc<Self> {
|
|
|
|
Self::internal_new(servicepoint::Bitmap::max_sized())
|
|
|
|
}
|
|
|
|
|
2024-11-04 21:06:01 +01:00
|
|
|
#[uniffi::constructor]
|
|
|
|
pub fn load(width: u64, height: u64, data: Vec<u8>) -> Arc<Self> {
|
|
|
|
Self::internal_new(servicepoint::Bitmap::load(
|
|
|
|
width as usize,
|
|
|
|
height as usize,
|
|
|
|
&data,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2024-11-04 22:21:28 +01:00
|
|
|
#[uniffi::constructor]
|
|
|
|
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
|
|
|
Self::internal_new(other.actual.read().unwrap().clone())
|
|
|
|
}
|
|
|
|
|
2024-11-04 19:20:40 +01:00
|
|
|
pub fn set(&self, x: u64, y: u64, value: bool) {
|
2024-11-04 21:06:01 +01:00
|
|
|
self.actual
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.set(x as usize, y as usize, value)
|
2024-11-04 19:20:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get(&self, x: u64, y: u64) -> bool {
|
|
|
|
self.actual.read().unwrap().get(x as usize, y as usize)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fill(&self, value: bool) {
|
|
|
|
self.actual.write().unwrap().fill(value)
|
|
|
|
}
|
|
|
|
pub fn width(&self) -> u64 {
|
|
|
|
self.actual.read().unwrap().width() as u64
|
|
|
|
}
|
2024-11-04 21:06:01 +01:00
|
|
|
|
2024-11-04 19:20:40 +01:00
|
|
|
pub fn height(&self) -> u64 {
|
|
|
|
self.actual.read().unwrap().height() as u64
|
|
|
|
}
|
2024-11-05 22:39:10 +01:00
|
|
|
|
|
|
|
pub fn equals(&self, other: &Bitmap) -> bool {
|
|
|
|
let a = self.actual.read().unwrap();
|
|
|
|
let b = other.actual.read().unwrap();
|
|
|
|
*a == *b
|
|
|
|
}
|
2024-11-10 15:08:39 +01:00
|
|
|
|
2024-11-05 22:39:10 +01:00
|
|
|
pub fn copy_raw(&self) -> Vec<u8> {
|
|
|
|
self.actual.read().unwrap().data_ref().to_vec()
|
|
|
|
}
|
2024-11-04 19:20:40 +01:00
|
|
|
}
|