aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/decode.rs21
-rw-r--r--src/encode.rs2
-rw-r--r--src/lib.rs2
3 files changed, 9 insertions, 16 deletions
diff --git a/src/decode.rs b/src/decode.rs
index 9c6a065..2202116 100644
--- a/src/decode.rs
+++ b/src/decode.rs
@@ -18,8 +18,8 @@ pub fn decode_image(obi_data: &mut Cursor<Vec<u8>>) -> OBIResult<Image> {
18 .read_u32::<LittleEndian>() 18 .read_u32::<LittleEndian>()
19 .map_err(|_| OBIError::Decode)?; 19 .map_err(|_| OBIError::Decode)?;
20 let file_header = FileHeader { 20 let file_header = FileHeader {
21 version,
22 file_size, 21 file_size,
22 version,
23 data_offset, 23 data_offset,
24 }; 24 };
25 25
@@ -59,8 +59,7 @@ pub fn decode_image(obi_data: &mut Cursor<Vec<u8>>) -> OBIResult<Image> {
59 obi_data 59 obi_data
60 .read_to_end(&mut rest) 60 .read_to_end(&mut rest)
61 .map_err(|_| OBIError::Decode)?; 61 .map_err(|_| OBIError::Decode)?;
62 let data_points = rest 62 rest.iter()
63 .iter()
64 .map(|&b| { 63 .map(|&b| {
65 BitVec::<Lsb0, u8>::from_element(b) 64 BitVec::<Lsb0, u8>::from_element(b)
66 .into_iter() 65 .into_iter()
@@ -68,23 +67,18 @@ pub fn decode_image(obi_data: &mut Cursor<Vec<u8>>) -> OBIResult<Image> {
68 .collect::<Vec<bool>>() 67 .collect::<Vec<bool>>()
69 }) 68 })
70 .flatten() 69 .flatten()
71 .collect::<Vec<bool>>();
72
73 let data = data_points
74 .into_iter() 70 .into_iter()
75 .zip(lengths) 71 .zip(lengths)
76 .map(|(d, l)| vec![d; l as usize]) 72 .map(|(d, l)| vec![d; l as usize])
77 .flatten() 73 .flatten()
78 .collect::<Vec<bool>>(); 74 .collect::<Vec<bool>>()
79 data
80 } 75 }
81 _ => { 76 _ => {
82 let mut rest = vec![]; 77 let mut rest = vec![];
83 obi_data 78 obi_data
84 .read_to_end(&mut rest) 79 .read_to_end(&mut rest)
85 .map_err(|_| OBIError::Decode)?; 80 .map_err(|_| OBIError::Decode)?;
86 let data_points = rest 81 rest.iter()
87 .iter()
88 .map(|&b| { 82 .map(|&b| {
89 BitVec::<Lsb0, u8>::from_element(b) 83 BitVec::<Lsb0, u8>::from_element(b)
90 .into_iter() 84 .into_iter()
@@ -92,13 +86,12 @@ pub fn decode_image(obi_data: &mut Cursor<Vec<u8>>) -> OBIResult<Image> {
92 .collect::<Vec<bool>>() 86 .collect::<Vec<bool>>()
93 }) 87 })
94 .flatten() 88 .flatten()
95 .collect::<Vec<_>>(); 89 .collect::<Vec<_>>()
96 data_points
97 } 90 }
98 }; 91 };
99 return Ok(Image { 92 Ok(Image {
100 file_header, 93 file_header,
101 image_info_header, 94 image_info_header,
102 data, 95 data,
103 }); 96 })
104} 97}
diff --git a/src/encode.rs b/src/encode.rs
index 30edc49..e52b69b 100644
--- a/src/encode.rs
+++ b/src/encode.rs
@@ -76,5 +76,5 @@ where
76 _ => write_pixel_data(pixmap, &mut obi_data)?, 76 _ => write_pixel_data(pixmap, &mut obi_data)?,
77 }; 77 };
78 78
79 return Ok(obi_data); 79 Ok(obi_data)
80} 80}
diff --git a/src/lib.rs b/src/lib.rs
index 2eb01a9..05070cb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -137,7 +137,7 @@ impl Image {
137 if x >= self.width() || y >= self.height() { 137 if x >= self.width() || y >= self.height() {
138 Err(OBIError::Image) 138 Err(OBIError::Image)
139 } else { 139 } else {
140 return Ok((y * self.width() + x) as usize); 140 Ok((y * self.width() + x) as usize)
141 } 141 }
142 } 142 }
143 143