Skip to content

Commit

Permalink
refactor and impl mjpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
payload committed Aug 15, 2023
1 parent a0f1689 commit 3339e16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ windows = { version = "0.48", features = [
v4l = "0.14"
ffimage = "0.9"
ffimage_yuv = "0.9"
mozjpeg = "0.9"

[dev-dependencies]
softbuffer = "0.3"
winit = "0.28"
iced = { version = "0.10", features = ["advanced", "image"] }

15 changes: 12 additions & 3 deletions src/linux_v4l2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::marker::PhantomData;

use std::sync::RwLock;

use crate::{ CameraInfo, InnerCamera };
use crate::{CameraInfo, InnerCamera};

pub struct Camera {
device: RwLock<v4l::Device>,
Expand Down Expand Up @@ -95,7 +95,10 @@ impl InnerCamera for Camera {
fn enumerate_cameras() -> Vec<CameraInfo> {
enum_devices()
.iter()
.map(|d| CameraInfo { device_id: name_or_path(d), label: d.path().to_string_lossy().to_string() })
.map(|d| CameraInfo {
device_id: name_or_path(d),
label: d.path().to_string_lossy().to_string(),
})
.collect()
}

Expand All @@ -120,7 +123,7 @@ impl InnerCamera for Camera {
let data = match &format.fourcc.repr {
b"RGB3" => buf.to_vec(),
b"YUYV" => yuyv_to_rgb32(buf, size.0, size.1),
b"MJPG" => todo!("NJPG not implemented"),
b"MJPG" => mjpeg_to_rgb32(buf, size.0, size.1),
_ => panic!("invalid buffer pixelformat"),
};

Expand Down Expand Up @@ -206,3 +209,9 @@ fn yuyv_to_rgb32(buf: &[u8], w: u32, h: u32) -> Vec<u8> {

rgba.into_buf()
}

fn mjpeg_to_rgb32(buf: &[u8], w: u32, h: u32) -> Vec<u8> {

Check failure on line 213 in src/linux_v4l2/mod.rs

View workflow job for this annotation

GitHub Actions / linux (stable)

unused variable: `w`

Check failure on line 213 in src/linux_v4l2/mod.rs

View workflow job for this annotation

GitHub Actions / linux (stable)

unused variable: `h`

Check warning on line 213 in src/linux_v4l2/mod.rs

View workflow job for this annotation

GitHub Actions / linux (stable)

unused variable: `w`

Check warning on line 213 in src/linux_v4l2/mod.rs

View workflow job for this annotation

GitHub Actions / linux (stable)

unused variable: `h`

Check warning on line 213 in src/linux_v4l2/mod.rs

View workflow job for this annotation

GitHub Actions / linux (stable)

unused variable: `w`

Check warning on line 213 in src/linux_v4l2/mod.rs

View workflow job for this annotation

GitHub Actions / linux (stable)

unused variable: `h`
let jpeg = mozjpeg::Decompress::new_mem(buf).unwrap();
let mut decompress = jpeg.rgba().unwrap();
decompress.read_scanlines_flat().unwrap()
}

0 comments on commit 3339e16

Please sign in to comment.