diff --git a/Cargo.lock b/Cargo.lock index 54ae0a6..2e7fa83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + [[package]] name = "cfg-if" version = "1.0.0" @@ -76,6 +82,8 @@ dependencies = [ "linuxvideo", "rayon", "thiserror", + "zune-core", + "zune-jpeg", ] [[package]] @@ -94,7 +102,7 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" name = "linuxvideo" version = "0.3.1" dependencies = [ - "bitflags", + "bitflags 1.3.2", "log", "nix", ] @@ -129,7 +137,7 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "libc", "memoffset 0.7.1", @@ -234,3 +242,18 @@ name = "unicode-ident" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "zune-core" +version = "0.2.14" +dependencies = [ + "bitflags 2.4.0", +] + +[[package]] +name = "zune-jpeg" +version = "0.3.17" +dependencies = [ + "log", + "zune-core", +] diff --git a/Cargo.toml b/Cargo.toml index f58f45f..5b9d109 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,5 @@ edition = "2021" linuxvideo = { path = "deps/LinuxVideo" } rayon = "1.7.0" thiserror = "1.0.48" +zune-core = { path = "deps/zune-image/zune-core" } +zune-jpeg = { path = "deps/zune-image/zune-jpeg", default-features = false, features = ["std"] } diff --git a/src/main.rs b/src/main.rs index 5032cee..67f4a67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,10 +48,76 @@ fn main() -> Result <(), Error> } let stop = Instant::now (); - dbg! (30_000.0f32 / (stop - start).as_millis () as f32); + let capture_fps = 30_000.0f32 / (stop - start).as_millis () as f32; + dbg! (capture_fps); + + let buf = &buf [0..bytesused]; let mut f = std::fs::File::create ("data.jpeg").unwrap (); - f.write_all (&buf [0..bytesused]).unwrap (); + f.write_all (buf).unwrap (); + + let start = Instant::now (); + let mut pixels = vec! []; + for _ in 0..30 + { + let mut decoder = zune_jpeg::JpegDecoder::new_with_options + ( + buf, + zune_core::options::DecoderOptions::new_fast ().jpeg_set_out_colorspace (zune_core::colorspace::ColorSpace::YCbCr), + ); + decoder.decode_headers ().unwrap (); + dbg! (decoder.get_output_colorspace ()); + pixels.resize (decoder.output_buffer_size ().unwrap (), 0); + + decoder.decode_into (&mut pixels).unwrap (); + } + let stop = Instant::now (); + let decode_mpf = (stop - start).as_millis () as f32 / 30.0f32; + dbg! (decode_mpf); + + let mut f = std::fs::File::create ("data.raw").unwrap (); + f.write_all (&pixels).unwrap (); + }, + Some ("decode") => + { + let jpeg = std::fs::read ("data.jpeg").unwrap (); + let start = Instant::now (); + let mut pixels = vec! []; + for _ in 0..30 + { + let mut decoder = zune_jpeg::JpegDecoder::new_with_options + ( + &jpeg, + zune_core::options::DecoderOptions::new_fast ().jpeg_set_out_colorspace (zune_core::colorspace::ColorSpace::YCbCr), + ); + decoder.decode_headers ().unwrap (); + pixels.resize (decoder.output_buffer_size ().unwrap (), 0); + + decoder.decode_into (&mut pixels).unwrap (); + } + let stop = Instant::now (); + let mpf_ycbcr = (stop - start).as_millis () as f32 / 30.0f32; + dbg! (mpf_ycbcr); + + std::fs::write ("raw.data", &pixels); + + let start = Instant::now (); + let mut pixels = vec! []; + for _ in 0..30 + { + let mut decoder = zune_jpeg::JpegDecoder::new_with_options + ( + &jpeg, + zune_core::options::DecoderOptions::new_fast ().jpeg_set_out_colorspace (zune_core::colorspace::ColorSpace::RGB), + ); + decoder.decode_headers ().unwrap (); + pixels.resize (decoder.output_buffer_size ().unwrap (), 0); + + decoder.decode_into (&mut pixels).unwrap (); + } + let stop = Instant::now (); + let mpf_rgb = (stop - start).as_millis () as f32 / 30.0f32; + dbg! (mpf_rgb); }, Some (_) => eprintln! ("Unknown subcommand"), } @@ -160,10 +226,6 @@ impl <'a> Driver <'_> fn handle_tx_event (&mut self, event: TxPipelineEvent) -> Result <(), TaskError> { - let thread_sys = &self.thread_sys; - let pool = &self.thread_sys.pool; - let send = self.thread_sys.send.clone (); - match event { TxPipelineEvent::Capture => CaptureWork::dispatch (self, ())?, @@ -379,7 +441,7 @@ impl CaptureWork fn dispatch (driver: &mut Driver, _input: ()) -> Result <(), TaskError> { let metadata = (); - let mut cap = driver.capture.start (metadata)?; + let cap = driver.capture.start (metadata)?; driver.thread_sys.dispatch (move || { let dur_capture = Duration::from_millis (1000);