aboutsummaryrefslogtreecommitdiff
path: root/src/decode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/decode.rs')
-rw-r--r--src/decode.rs37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/decode.rs b/src/decode.rs
index 59dae97..a9abd37 100644
--- a/src/decode.rs
+++ b/src/decode.rs
@@ -1,15 +1,22 @@
1use std::io::{self, Cursor, Read}; 1use std::io::{Cursor, Read};
2 2
3use bitvec::prelude::*; 3use bitvec::prelude::*;
4use byteorder::{LittleEndian, ReadBytesExt}; 4use byteorder::{LittleEndian, ReadBytesExt};
5 5
6use crate::error::{OBIError, OBIResult};
6use crate::{FileHeader, Image, ImageInfoHeader}; 7use crate::{FileHeader, Image, ImageInfoHeader};
7 8
8pub fn decode_image(obi_data: &mut Cursor<Vec<u8>>) -> io::Result<Image> { 9pub fn decode_image(obi_data: &mut Cursor<Vec<u8>>) -> OBIResult<Image> {
9 // file header 10 // file header
10 let version = obi_data.read_u16::<LittleEndian>()?; 11 let version = obi_data
11 let file_size = obi_data.read_u32::<LittleEndian>()?; 12 .read_u16::<LittleEndian>()
12 let data_offset = obi_data.read_u32::<LittleEndian>()?; 13 .map_err(|_| OBIError::Decode)?;
14 let file_size = obi_data
15 .read_u32::<LittleEndian>()
16 .map_err(|_| OBIError::Decode)?;
17 let data_offset = obi_data
18 .read_u32::<LittleEndian>()
19 .map_err(|_| OBIError::Decode)?;
13 let file_header = FileHeader { 20 let file_header = FileHeader {
14 version, 21 version,
15 file_size, 22 file_size,
@@ -17,10 +24,18 @@ pub fn decode_image(obi_data: &mut Cursor<Vec<u8>>) -> io::Result<Image> {
17 }; 24 };
18 25
19 // image info header 26 // image info header
20 let width = obi_data.read_u32::<LittleEndian>()?; 27 let width = obi_data
21 let height = obi_data.read_u32::<LittleEndian>()?; 28 .read_u32::<LittleEndian>()
22 let compression_type = obi_data.read_u32::<LittleEndian>()?; 29 .map_err(|_| OBIError::Decode)?;
23 let post_compression_size = obi_data.read_u32::<LittleEndian>()?; 30 let height = obi_data
31 .read_u32::<LittleEndian>()
32 .map_err(|_| OBIError::Decode)?;
33 let compression_type = obi_data
34 .read_u32::<LittleEndian>()
35 .map_err(|_| OBIError::Decode)?;
36 let post_compression_size = obi_data
37 .read_u32::<LittleEndian>()
38 .map_err(|_| OBIError::Decode)?;
24 let image_info_header = ImageInfoHeader { 39 let image_info_header = ImageInfoHeader {
25 width, 40 width,
26 height, 41 height,
@@ -30,7 +45,9 @@ pub fn decode_image(obi_data: &mut Cursor<Vec<u8>>) -> io::Result<Image> {
30 45
31 // pixmap data 46 // pixmap data
32 let mut data_bytes = vec![]; 47 let mut data_bytes = vec![];
33 obi_data.read_to_end(&mut data_bytes)?; 48 obi_data
49 .read_to_end(&mut data_bytes)
50 .map_err(|_| OBIError::Decode)?;
34 let data = data_bytes 51 let data = data_bytes
35 .iter() 52 .iter()
36 .map(|&b| { 53 .map(|&b| {