add ability to load PixelGrid and BitVec
This commit is contained in:
		
							parent
							
								
									e6f8afb378
								
							
						
					
					
						commit
						a23ca55f60
					
				
					 2 changed files with 17 additions and 2 deletions
				
			
		|  | @ -10,6 +10,10 @@ impl BitVec { | |||
|         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 { | ||||
|         let (byte_index, bit_mask) = self.get_indexes(index); | ||||
| 
 | ||||
|  | @ -30,8 +34,8 @@ impl BitVec { | |||
|         return self.data[byte_index] & bit_mask != 0; | ||||
|     } | ||||
| 
 | ||||
|     pub fn fill(&mut self, value: bool){ | ||||
|         let byte: u8 = if value {0xFF} else {0x00}; | ||||
|     pub fn fill(&mut self, value: bool) { | ||||
|         let byte: u8 = if value { 0xFF } else { 0x00 }; | ||||
|         self.data.fill(byte); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -22,6 +22,17 @@ impl PixelGrid { | |||
|         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 { | ||||
|         self.bit_vec.set(x + y * self.width, value) | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter