diff options
Diffstat (limited to 'src/encode.rs')
-rw-r--r-- | src/encode.rs | 11 |
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 @@ | |||
1 | use std::io; | 1 | use std::io; |
2 | 2 | ||
3 | use bitvec::prelude::*; | 3 | use bitvec::{prelude::*, vec::BitVec}; |
4 | use bitvec::slice::BitSlice; | ||
5 | use byteorder::{LittleEndian, WriteBytesExt}; | 4 | use byteorder::{LittleEndian, WriteBytesExt}; |
6 | 5 | ||
7 | use crate::Image; | 6 | use 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); |