mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10:14 +01:00
add ability to load PixelGrid and BitVec
This commit is contained in:
parent
e6f8afb378
commit
a23ca55f60
|
@ -10,6 +10,10 @@ impl BitVec {
|
||||||
Self { data: vec!(0; size / 8) }
|
Self { data: vec!(0; size / 8) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load(data: &[u8]) -> BitVec {
|
||||||
|
Self { data: Vec::from(data) }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set(&mut self, index: usize, value: bool) -> bool {
|
pub fn set(&mut self, index: usize, value: bool) -> bool {
|
||||||
let (byte_index, bit_mask) = self.get_indexes(index);
|
let (byte_index, bit_mask) = self.get_indexes(index);
|
||||||
|
|
||||||
|
@ -30,8 +34,8 @@ impl BitVec {
|
||||||
return self.data[byte_index] & bit_mask != 0;
|
return self.data[byte_index] & bit_mask != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fill(&mut self, value: bool){
|
pub fn fill(&mut self, value: bool) {
|
||||||
let byte: u8 = if value {0xFF} else {0x00};
|
let byte: u8 = if value { 0xFF } else { 0x00 };
|
||||||
self.data.fill(byte);
|
self.data.fill(byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,17 @@ impl PixelGrid {
|
||||||
Self::new(PIXEL_WIDTH as usize, PIXEL_HEIGHT as usize)
|
Self::new(PIXEL_WIDTH as usize, PIXEL_HEIGHT as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load(width: usize, height: usize, data: &[u8]) -> Self {
|
||||||
|
assert_eq!(width % 8, 0);
|
||||||
|
assert_eq!(height % 8, 0);
|
||||||
|
assert_eq!(data.len(), height * width / 8);
|
||||||
|
Self {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
bit_vec: BitVec::load(data),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set(&mut self, x: usize, y: usize, value: bool) -> bool {
|
pub fn set(&mut self, x: usize, y: usize, value: bool) -> bool {
|
||||||
self.bit_vec.set(x + y * self.width, value)
|
self.bit_vec.set(x + y * self.width, value)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue