add uniffi compression code, clone
add uniffi clone
This commit is contained in:
parent
18f1ccb2dc
commit
03aa432655
7 changed files with 213 additions and 40 deletions
|
@ -38,6 +38,11 @@ impl Bitmap {
|
|||
))
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||
Self::internal_new(other.actual.read().unwrap().clone())
|
||||
}
|
||||
|
||||
pub fn set(&self, x: u64, y: u64, value: bool) {
|
||||
self.actual
|
||||
.write()
|
||||
|
|
|
@ -24,6 +24,11 @@ impl BitVec {
|
|||
Self::internal_new(servicepoint::BitVec::from_slice(&data))
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||
Self::internal_new(other.actual.read().unwrap().clone())
|
||||
}
|
||||
|
||||
pub fn set(&self, index: u64, value: bool) {
|
||||
self.actual.write().unwrap().set(index as usize, value)
|
||||
}
|
||||
|
|
|
@ -33,6 +33,11 @@ impl BrightnessGrid {
|
|||
))
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||
Self::internal_new(other.actual.read().unwrap().clone())
|
||||
}
|
||||
|
||||
pub fn set(&self, x: u64, y: u64, value: u8) {
|
||||
self.actual.write().unwrap().set(
|
||||
x as usize,
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use crate::bitmap::Bitmap;
|
||||
use crate::bitvec::BitVec;
|
||||
use crate::brightness_grid::BrightnessGrid;
|
||||
use crate::compression_code::CompressionCode;
|
||||
use crate::errors::ServicePointError;
|
||||
use servicepoint::{CompressionCode, Origin};
|
||||
use servicepoint::Origin;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(uniffi::Object)]
|
||||
|
@ -48,14 +49,15 @@ impl Command {
|
|||
offset_x: u64,
|
||||
offset_y: u64,
|
||||
bitmap: &Arc<Bitmap>,
|
||||
compression: CompressionCode,
|
||||
) -> Arc<Self> {
|
||||
let origin = Origin::new(offset_x as usize, offset_y as usize);
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
// TODO: compression codes
|
||||
let actual = servicepoint::Command::BitmapLinearWin(
|
||||
origin,
|
||||
bitmap,
|
||||
CompressionCode::Uncompressed,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
}
|
||||
|
@ -73,50 +75,71 @@ impl Command {
|
|||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn bitmap_linear(offset: u64, bitmap: &Arc<BitVec>) -> Arc<Self> {
|
||||
pub fn bitmap_linear(
|
||||
offset: u64,
|
||||
bitmap: &Arc<BitVec>,
|
||||
compression: CompressionCode,
|
||||
) -> Arc<Self> {
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
// TODO: compression codes
|
||||
let actual = servicepoint::Command::BitmapLinear(
|
||||
offset as usize,
|
||||
bitmap,
|
||||
CompressionCode::Uncompressed,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn bitmap_linear_and(offset: u64, bitmap: &Arc<BitVec>) -> Arc<Self> {
|
||||
pub fn bitmap_linear_and(
|
||||
offset: u64,
|
||||
bitmap: &Arc<BitVec>,
|
||||
compression: CompressionCode,
|
||||
) -> Arc<Self> {
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
// TODO: compression codes
|
||||
let actual = servicepoint::Command::BitmapLinearAnd(
|
||||
offset as usize,
|
||||
bitmap,
|
||||
CompressionCode::Uncompressed,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn bitmap_linear_or(offset: u64, bitmap: &Arc<BitVec>) -> Arc<Self> {
|
||||
pub fn bitmap_linear_or(
|
||||
offset: u64,
|
||||
bitmap: &Arc<BitVec>,
|
||||
compression: CompressionCode,
|
||||
) -> Arc<Self> {
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
// TODO: compression codes
|
||||
let actual = servicepoint::Command::BitmapLinearOr(
|
||||
offset as usize,
|
||||
bitmap,
|
||||
CompressionCode::Uncompressed,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn bitmap_linear_xor(offset: u64, bitmap: &Arc<BitVec>) -> Arc<Self> {
|
||||
pub fn bitmap_linear_xor(
|
||||
offset: u64,
|
||||
bitmap: &Arc<BitVec>,
|
||||
compression: CompressionCode,
|
||||
) -> Arc<Self> {
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
// TODO: compression codes
|
||||
let actual = servicepoint::Command::BitmapLinearXor(
|
||||
offset as usize,
|
||||
bitmap,
|
||||
CompressionCode::Uncompressed,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||
Self::internal_new(other.actual.clone())
|
||||
}
|
||||
}
|
||||
|
|
14
crates/servicepoint_binding_uniffi/src/compression_code.rs
Normal file
14
crates/servicepoint_binding_uniffi/src/compression_code.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
#[repr(u16)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, uniffi::Enum)]
|
||||
pub enum CompressionCode {
|
||||
/// no compression
|
||||
Uncompressed = 0x0,
|
||||
/// compress using flate2 with zlib header
|
||||
Zlib = 0x677a,
|
||||
/// compress using bzip2
|
||||
Bzip2 = 0x627a,
|
||||
/// compress using lzma
|
||||
Lzma = 0x6c7a,
|
||||
/// compress using Zstandard
|
||||
Zstd = 0x7a73,
|
||||
}
|
|
@ -4,5 +4,6 @@ mod bitmap;
|
|||
mod bitvec;
|
||||
mod brightness_grid;
|
||||
mod command;
|
||||
mod compression_code;
|
||||
mod connection;
|
||||
mod errors;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue