aboutsummaryrefslogtreecommitdiff
path: root/src/encode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/encode.rs')
-rw-r--r--src/encode.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/encode.rs b/src/encode.rs
index 24d3792..e5760a8 100644
--- a/src/encode.rs
+++ b/src/encode.rs
@@ -1,7 +1,6 @@
1use std::io; 1use std::io;
2 2
3use bitvec::prelude::*; 3use bitvec::{prelude::*, vec::BitVec};
4use bitvec::slice::BitSlice;
5use byteorder::{LittleEndian, WriteBytesExt}; 4use byteorder::{LittleEndian, WriteBytesExt};
6 5
7use crate::Image; 6use crate::Image;
@@ -25,9 +24,11 @@ pub fn encode_image(obi_image: Image) -> io::Result<Vec<u8>> {
25 // pixmap data 24 // pixmap data
26 let pixmap = obi_image.data; 25 let pixmap = obi_image.data;
27 for byte in pixmap.chunks(8) { 26 for byte in pixmap.chunks(8) {
28 let bits_as_u8 = byte.iter().map(|&e| e as u8).collect::<Vec<_>>(); 27 let mut bv = BitVec::<Lsb0, u8>::new();
29 let slice = BitSlice::<Lsb0, _>::from_slice(&bits_as_u8).unwrap(); 28 for &b in byte {
30 obi_data.write_u8(slice.load::<u8>())?; 29 bv.push(b);
30 }
31 obi_data.write_u8(bv.load::<u8>())?;
31 } 32 }
32 33
33 return Ok(obi_data); 34 return Ok(obi_data);