Skip to content

Commit

Permalink
lint and add explicit format type
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlymatthew committed Jun 17, 2024
1 parent 38409f6 commit bf0c9a5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::bitreader::BitReader;
use crate::coding::{CodingProcess, EntropyCoding};
use crate::dequantizer::Dequantizer;
use crate::entropy_decoder::EntropyDecoder;
use crate::format::Format;
use crate::frame_header::Component;
use crate::huffman_tree::HuffmanClass;
use crate::idct::IDCT;
Expand Down Expand Up @@ -166,7 +167,7 @@ impl Decoder {
Ok(Parser::new(self.mmap.to_vec(), marlen_map, self.encoding))
}

pub fn decode(&mut self) -> Result<Vec<(Simd<f32, 64>, Simd<f32, 64>, Simd<f32, 64>)>> {
pub fn decode(&mut self) -> Result<Vec<Format>> {
let parser = self.setup()?;

let code_schema = self.encoding.schema();
Expand Down Expand Up @@ -290,7 +291,15 @@ impl Decoder {
image_data.push((res[0], res[1], res[2]))
}

Ok(image_data)
let mut ycbcrs = vec![];

for (y, cb, cr) in image_data {
for i in 0..64 {
ycbcrs.push(Format::YCbCr(y[i], cb[i], cr[i]));
}
}

Ok(ycbcrs)
}
_ => todo!(),
}
Expand Down
5 changes: 5 additions & 0 deletions src/format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[derive(Debug, PartialEq, Clone, Copy)]
pub(crate) enum Format {
YCbCr(f32, f32, f32),
RGB(f32, f32, f32),
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod bitreader;
mod coding;
mod dequantizer;
mod entropy_decoder;
mod format;
pub(crate) mod frame_header;
pub(crate) mod huffman_tree;
mod idct;
Expand Down
3 changes: 0 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ mod tests {

static INIT: Once = Once::new();

// this contains a mock start of frame and start of scan
pub(crate) fn setup() {
INIT.call_once(|| {
let data = vec![
Expand Down Expand Up @@ -454,7 +453,6 @@ mod tests {
file.write_all(&data).unwrap();
});
}

#[test]
fn test_decoding_various_markers() -> Result<()> {
setup();
Expand Down Expand Up @@ -535,7 +533,6 @@ mod tests {
assert_eq!(scan_header.end_of_spectral, 63);
assert_eq!(scan_header.successive_approx_bit_position_high, 1);
assert_eq!(scan_header.point_transform, 0);

assert_eq!(
parser.parse_image_data(s_idx)?,
[0xFF, 0x00, 0xFF, 0xFF, 0x02, 0x04, b'h', 0x02,].to_vec()
Expand Down

0 comments on commit bf0c9a5

Please sign in to comment.