diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b7c166512..88652ed4d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -390,7 +390,7 @@ build-freemovr-calibration-webapp: - echo $PATH - rustup target add wasm32-unknown-unknown - - cargo install wasm-bindgen-cli --version 0.2.92 --force --locked + - cargo install wasm-bindgen-cli --version 0.2.95 --force --locked - cargo install grass - wasm-bindgen --version @@ -1222,7 +1222,7 @@ braid-webapps: # ... and install latest (and therefore matching) wasm-pack - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh # ... and wasm-bindgen-cli - - cargo install wasm-bindgen-cli --version 0.2.92 --force --locked + - cargo install wasm-bindgen-cli --version 0.2.95 --force --locked - cargo install grass - rustup target add wasm32-unknown-unknown - export PATH="$PATH:$CARGO_HOME/bin" diff --git a/Cargo.toml b/Cargo.toml index 19f4e3779..addd3e509 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -131,7 +131,7 @@ debug = true [workspace.dependencies] num-traits = "0.2" -simba = "0.9" +simba = { version = "0.9", default-features = false } nalgebra = "0.33" nalgebra-mvn = "0.15" adskalman = "0.16" @@ -150,6 +150,10 @@ serde = "1.0" serde_yaml = "0.9" chrono = { version = "0.4.35", default-features = false } eyre = "0.6.12" +image = { version = "0.25", default-features = false } +rerun = { version = "0.19", default-features = false, features = ["sdk"] } +wasm-bindgen = { version = "0.2.95" } +web-sys = { version = "0.3.72" } [replace] # "tokio-threadpool:0.1.6" = {git="https://bare-git.strawlab.org/tokio.git", rev="472e64c1ea67f3976191cb1b291061faf2082735"} diff --git a/ads-webasm-example/Cargo.toml b/ads-webasm-example/Cargo.toml index 446a61b8f..6650dd3c1 100644 --- a/ads-webasm-example/Cargo.toml +++ b/ads-webasm-example/Cargo.toml @@ -9,7 +9,7 @@ rust-version = "1.76" crate-type = ["cdylib", "rlib"] [dependencies] -wasm-bindgen = "0.2.92" +wasm-bindgen = { workspace = true } js-sys = "0.3" chrono = { version = "0.4.23", default-features = false, features = [ "clock", diff --git a/ads-webasm/Cargo.toml b/ads-webasm/Cargo.toml index 783dc07c8..4a75dee4a 100644 --- a/ads-webasm/Cargo.toml +++ b/ads-webasm/Cargo.toml @@ -9,7 +9,7 @@ rust-version = "1.76" yew = { version = "0.21.0", features = ["csr"] } js-sys = "0.3" gloo-file = "0.2" -wasm-bindgen = "0.2.92" +wasm-bindgen = { workspace = true } serde = "1.0" serde_yaml = "0.9" serde_derive = "1.0" @@ -30,7 +30,7 @@ rust-cam-bui-types = { path = "../rust-cam-bui-types" } bui-backend-session-types = { path = "../bui-backend-session/types" } [dependencies.web-sys] -version = "0.3" +workspace = true features = [ "CanvasRenderingContext2d", "Document", diff --git a/apriltag/Cargo.toml b/apriltag/Cargo.toml index dbc312596..da6f47867 100644 --- a/apriltag/Cargo.toml +++ b/apriltag/Cargo.toml @@ -12,4 +12,4 @@ machine-vision-formats = "0.1" [dev-dependencies] convert-image = { path = "../convert-image" } -image = { version = "0.24.2", default-features = false, features = ["jpeg"] } +image = { workspace = true, features = ["jpeg"] } diff --git a/apriltag/apriltag-track-movie/src/lib.rs b/apriltag/apriltag-track-movie/src/lib.rs index c25a8f620..058c1a67e 100644 --- a/apriltag/apriltag-track-movie/src/lib.rs +++ b/apriltag/apriltag-track-movie/src/lib.rs @@ -153,7 +153,7 @@ pub fn run_cli(cli: Cli) -> Result<()> { if false { // This block for debugging ffmpeg video decoding. let png_buf = - convert_image::frame_to_image(&decoded_mono8, convert_image::ImageOptions::Png)?; + convert_image::frame_to_encoded_buffer(&decoded_mono8, convert_image::ImageOptions::Png)?; let fname = format!("frame{frame:09}.png"); println!("saving png {fname}"); let mut file = std::fs::File::create(&fname)?; diff --git a/braid-april-cal/braid-april-cal-webapp/Cargo.toml b/braid-april-cal/braid-april-cal-webapp/Cargo.toml index a02bb2e94..77a6132cb 100644 --- a/braid-april-cal/braid-april-cal-webapp/Cargo.toml +++ b/braid-april-cal/braid-april-cal-webapp/Cargo.toml @@ -12,8 +12,8 @@ crate-type = ["cdylib", "rlib"] yew = { version = "0.21.0", features = ["csr"] } yew-tincture = "0.2.2" js-sys = "0.3" -wasm-bindgen = "0.2.92" -web-sys = { version = "0.3", features = [ +wasm-bindgen = { workspace = true } +web-sys = { workspace = true, features = [ "CssStyleDeclaration", "HtmlAnchorElement", "Url", diff --git a/braid-april-cal/braid-april-cal-webapp/src/lib.rs b/braid-april-cal/braid-april-cal-webapp/src/lib.rs index 33464c23f..85ad595ef 100644 --- a/braid-april-cal/braid-april-cal-webapp/src/lib.rs +++ b/braid-april-cal/braid-april-cal-webapp/src/lib.rs @@ -276,11 +276,9 @@ fn download_file(orig_buf: &[u8], filename: &str) { let array = js_sys::Array::new(); array.push(&b.buffer()); - let blob = web_sys::Blob::new_with_u8_array_sequence_and_options( - &array, - web_sys::BlobPropertyBag::new().type_(mime_type), - ) - .unwrap(); + let options = web_sys::BlobPropertyBag::new(); + options.set_type(mime_type); + let blob = web_sys::Blob::new_with_u8_array_sequence_and_options(&array, &options).unwrap(); let data_url = web_sys::Url::create_object_url_with_blob(&blob).unwrap(); let document = web_sys::window().unwrap().document().unwrap(); let anchor = document diff --git a/braid-april-cal/flytrax-apriltags-calibration/Cargo.toml b/braid-april-cal/flytrax-apriltags-calibration/Cargo.toml index 50f0f651d..ce26fdb4a 100644 --- a/braid-april-cal/flytrax-apriltags-calibration/Cargo.toml +++ b/braid-april-cal/flytrax-apriltags-calibration/Cargo.toml @@ -8,10 +8,7 @@ anyhow = "1.0.71" apriltag-sys = "0.3" base64 = "0.6" clap = { version = "4.3.4", features = ["derive"] } -image = { version = "0.24.2", default-features = false, features = [ - "png", - "jpeg", -] } +image = { workspace = true, features = ["png", "jpeg"] } machine-vision-formats = "0.1" nalgebra = { workspace = true } resvg = "0.19" diff --git a/braid-april-cal/flytrax-apriltags-calibration/src/img_write.rs b/braid-april-cal/flytrax-apriltags-calibration/src/img_write.rs index 8fb0e1ad8..3f0fedb60 100644 --- a/braid-april-cal/flytrax-apriltags-calibration/src/img_write.rs +++ b/braid-april-cal/flytrax-apriltags-calibration/src/img_write.rs @@ -132,7 +132,7 @@ pub(crate) fn doit>( let rasterized = crate::tiny_skia_frame::Frame::new(pixmap)?; let mut png_fname = std::path::PathBuf::from(out_fname.as_ref()); png_fname.set_extension("png"); - let png_buf = convert_image::frame_to_image(&rasterized, convert_image::ImageOptions::Png)?; + let png_buf = convert_image::frame_to_encoded_buffer(&rasterized, convert_image::ImageOptions::Png)?; std::fs::write(&png_fname, png_buf)?; log::info!("Saved image for debugging to: {}", png_fname.display()); Ok(()) diff --git a/braid-process-video/Cargo.toml b/braid-process-video/Cargo.toml index 97aa5344d..28d4abbfb 100644 --- a/braid-process-video/Cargo.toml +++ b/braid-process-video/Cargo.toml @@ -25,7 +25,7 @@ resvg = "0.19" tagger = "4.0" tiny-skia = "0.6.1" usvg = { version = "0.19.0", default-features = false } -image = { version = "0.24.2", default-features = false, features = ["png"] } +image = { workspace = true, features = ["png"] } base64 = "0.6" ordered-float = "1" regex = "1" diff --git a/braid-process-video/src/lib.rs b/braid-process-video/src/lib.rs index 405ded744..df0dcfe65 100644 --- a/braid-process-video/src/lib.rs +++ b/braid-process-video/src/lib.rs @@ -250,7 +250,7 @@ impl PerCamRender { let (frame0_png_buf, width, height) = match frame_ref { DynamicFrame::Mono8(frame_mono8) => { let frame0_png_buf = - convert_image::frame_to_image(frame_mono8, convert_image::ImageOptions::Png) + convert_image::frame_to_encoded_buffer(frame_mono8, convert_image::ImageOptions::Png) .unwrap() .into(); ( @@ -261,7 +261,7 @@ impl PerCamRender { } DynamicFrame::RGB8(frame_rgb8) => { let frame0_png_buf = - convert_image::frame_to_image(frame_rgb8, convert_image::ImageOptions::Png) + convert_image::frame_to_encoded_buffer(frame_rgb8, convert_image::ImageOptions::Png) .unwrap() .into(); ( @@ -303,7 +303,7 @@ impl PerCamRender { ) .unwrap(); let frame0_png_buf = - convert_image::frame_to_image(&frame, convert_image::ImageOptions::Png) + convert_image::frame_to_encoded_buffer(&frame, convert_image::ImageOptions::Png) .unwrap() .into(); @@ -339,10 +339,10 @@ impl<'a> PerCamRenderFrame<'a> { pub(crate) fn set_original_image(&mut self, frame: &DynamicFrame) -> Result<()> { let png_buf = match frame { basic_frame::DynamicFrame::Mono8(frame_mono8) => { - convert_image::frame_to_image(frame_mono8, convert_image::ImageOptions::Png)? + convert_image::frame_to_encoded_buffer(frame_mono8, convert_image::ImageOptions::Png)? } basic_frame::DynamicFrame::RGB8(frame_rgb8) => { - convert_image::frame_to_image(frame_rgb8, convert_image::ImageOptions::Png)? + convert_image::frame_to_encoded_buffer(frame_rgb8, convert_image::ImageOptions::Png)? } _ => { panic!("only rgb8 and mono8 supported"); diff --git a/braid-process-video/src/output_video.rs b/braid-process-video/src/output_video.rs index 61b5f99f7..b1829c19e 100644 --- a/braid-process-video/src/output_video.rs +++ b/braid-process-video/src/output_video.rs @@ -311,7 +311,7 @@ impl<'lib> VideoStorage<'lib> { // Write rasterized image to disk as PNG. let png_buf = - convert_image::frame_to_image(&rasterized, convert_image::ImageOptions::Png)?; + convert_image::frame_to_encoded_buffer(&rasterized, convert_image::ImageOptions::Png)?; std::fs::write(format!("frame{:05}.png", out_fno), png_buf)?; } diff --git a/braid/braid-run/Cargo.toml b/braid/braid-run/Cargo.toml index 87b24301f..b4026b47e 100644 --- a/braid/braid-run/Cargo.toml +++ b/braid/braid-run/Cargo.toml @@ -39,7 +39,6 @@ bytes = "1.0" clap = { version = "4.3.4", features = ["derive"] } preferences-serde1 = "2.0.0" qrcodegen = "1.4" -image = "0.24.2" hyper = "1.1" lazy_static = "1.4" csv = "1.1" diff --git a/braid/braid-run/braid_frontend/Cargo.toml b/braid/braid-run/braid_frontend/Cargo.toml index 7db2a67e4..06f8fbe86 100644 --- a/braid/braid-run/braid_frontend/Cargo.toml +++ b/braid/braid-run/braid_frontend/Cargo.toml @@ -14,7 +14,7 @@ log = "0.4" wasm-logger = "0.2.0" gloo-events = "0.1.1" gloo-utils = "0.1" -wasm-bindgen = "0.2.92" +wasm-bindgen = { workspace = true } wasm-bindgen-futures = "0.4" js-sys = "0.3" yew = { version = "0.21.0", features = ["csr"] } @@ -33,7 +33,7 @@ rust-cam-bui-types = { path = "../../../rust-cam-bui-types" } ads-webasm = { path = "../../../ads-webasm" } [dependencies.web-sys] -version = "0.3" +workspace = true features = [ "Event", "EventSource", diff --git a/braid/braid-run/braid_frontend/src/lib.rs b/braid/braid-run/braid_frontend/src/lib.rs index 6d71c7317..3e355aed8 100644 --- a/braid/braid-run/braid_frontend/src/lib.rs +++ b/braid/braid-run/braid_frontend/src/lib.rs @@ -471,16 +471,16 @@ fn view_model_server_link(opt_addr: &Option) -> Html { async fn post_callback(msg: &BraidHttpApiCallback) -> Result<(), FetchError> { use web_sys::{Request, RequestInit, Response}; - let mut opts = RequestInit::new(); - opts.method("POST"); - opts.cache(web_sys::RequestCache::NoStore); + let opts = RequestInit::new(); + opts.set_method("POST"); + opts.set_cache(web_sys::RequestCache::NoStore); let buf = serde_json::to_string(&msg).unwrap_throw(); - opts.body(Some(&JsValue::from_str(&buf))); + opts.set_body(&JsValue::from_str(&buf)); let headers = web_sys::Headers::new().unwrap_throw(); headers .append("Content-Type", "application/json") .unwrap_throw(); - opts.headers(&headers); + opts.set_headers(&headers); let url = "callback"; let request = Request::new_with_str_and_init(url, &opts)?; diff --git a/braidz-export-rrd/Cargo.toml b/braidz-export-rrd/Cargo.toml index 0f8aeac2d..d03fd4957 100644 --- a/braidz-export-rrd/Cargo.toml +++ b/braidz-export-rrd/Cargo.toml @@ -12,12 +12,12 @@ serde_yaml = "0.9" color-eyre = "0.6.2" tracing = "0.1.40" -rerun = "0.17.0" +rerun = { workspace = true, features = ["image"] } +image = { workspace = true, features = ["jpeg"] } opencv-ros-camera = { workspace = true } cam-geom = { workspace = true } nalgebra = { workspace = true } regex = "1.10.3" -ndarray = "0.15.6" machine-vision-formats = "0.1.1" rayon = "1.9.0" opencv = { version = "0.88.8", optional = true } diff --git a/braidz-export-rrd/src/main.rs b/braidz-export-rrd/src/main.rs index 3a7b25087..e10c92656 100644 --- a/braidz-export-rrd/src/main.rs +++ b/braidz-export-rrd/src/main.rs @@ -3,10 +3,8 @@ use braidz_types::{camera_name_from_filename, CamNum}; use clap::{Parser, ValueEnum}; use color_eyre::eyre::{self as anyhow, WrapErr}; use frame_source::{ImageData, Timestamp}; -use machine_vision_formats::{pixel_format, PixFmt}; use mp4_writer::Mp4Writer; use mvg::rerun_io::{cam_geom_to_rr_pinhole_archetype as to_pinhole, AsRerunTransform3D}; -use ndarray::Array; use rayon::prelude::*; use std::{collections::BTreeMap, path::PathBuf}; @@ -262,6 +260,7 @@ impl OfflineBraidzRerunLogger { #[cfg(not(feature = "undistort-images"))] { let _ = intrinsics; // silence unused warning. + let _ = calibration; // silence unused warning. tracing::error!( "Support to undistortion images was not compiled. \ Images will be distorted but geometry will be linear." @@ -482,7 +481,7 @@ impl OfflineBraidzRerunLogger { fn to_rr_image( im: ImageData, undist_cache: Option<&UndistortionCache>, -) -> anyhow::Result<(rerun::Image, DynamicFrame)> { +) -> anyhow::Result<(rerun::EncodedImage, DynamicFrame)> { let decoded = match im { ImageData::Decoded(decoded) => decoded, _ => anyhow::bail!("image not decoded"), @@ -502,37 +501,13 @@ fn to_rr_image( decoded }; - if true { - // jpeg compression - let contents = basic_frame::match_all_dynamic_fmts!( - &decoded, - x, - convert_image::frame_to_image(x, convert_image::ImageOptions::Jpeg(80),) - )?; - let format = Some(rerun::external::image::ImageFormat::Jpeg); - Ok(( - rerun::Image::from_file_contents(contents, format).unwrap(), - decoded, - )) - } else { - // Much larger file size but higher quality. - let w = decoded.width() as usize; - let h = decoded.height() as usize; - - let image = match decoded.pixel_format() { - PixFmt::Mono8 => { - let mono8 = decoded.clone().into_pixel_format::()?; - Array::from_vec(mono8.into()).into_shape((h, w, 1)).unwrap() - } - _ => { - let rgb8 = decoded - .clone() - .into_pixel_format::()?; - Array::from_vec(rgb8.into()).into_shape((h, w, 3)).unwrap() - } - }; - Ok((rerun::Image::try_from(image)?, decoded)) - } + // jpeg compression TODO: give open to save uncompressed? + let contents = basic_frame::match_all_dynamic_fmts!( + &decoded, + x, + convert_image::frame_to_encoded_buffer(x, convert_image::ImageOptions::Jpeg(80),) + )?; + Ok((rerun::EncodedImage::from_file_contents(contents), decoded)) } fn main() -> anyhow::Result<()> { diff --git a/braidz-parser/Cargo.toml b/braidz-parser/Cargo.toml index ed617713b..3f989a0e9 100644 --- a/braidz-parser/Cargo.toml +++ b/braidz-parser/Cargo.toml @@ -18,7 +18,7 @@ serde-xml-rs = "0.5.1" hdrhistogram = "7.1" base64 = "0.12" ordered-float = "1" -image = {version = "0.24", default-features = false, features=["png"]} +image = { workspace = true, features=["png"]} regex = "1.8.4" csv-eof = {path="../csv-eof"} diff --git a/braidz-parser/src/incremental_parser.rs b/braidz-parser/src/incremental_parser.rs index e00d13994..ee2e02679 100644 --- a/braidz-parser/src/incremental_parser.rs +++ b/braidz-parser/src/incremental_parser.rs @@ -495,8 +495,11 @@ impl IncrementalParser { for cam_id in basics.cam_info.camid2camn.keys() { let relname = format!("{}/{cam_id}.png", flydra_types::IMAGES_DIRNAME); match self.archive.open(relname) { - Ok(rdr) => { - let decoder = image::codecs::png::PngDecoder::new(rdr)?; + Ok(mut rdr) => { + let mut buf = Vec::new(); + rdr.read_to_end(&mut buf)?; + let cur = std::io::Cursor::new(buf); + let decoder = image::codecs::png::PngDecoder::new(cur)?; let (w, h) = image::ImageDecoder::dimensions(&decoder); result.insert(cam_id.clone(), (w as usize, h as usize)); } diff --git a/braidz-parser/src/lib.rs b/braidz-parser/src/lib.rs index d6d38365e..3946c343a 100644 --- a/braidz-parser/src/lib.rs +++ b/braidz-parser/src/lib.rs @@ -557,22 +557,6 @@ pub enum MaybeGzippedReader<'a> { Gzipped(libflate::gzip::Decoder>), } -impl<'a> MaybeGzippedReader<'a> { - pub fn size(&self) -> u64 { - match self { - Self::Raw(f) => f.size(), - Self::Gzipped(gz) => gz.as_inner_ref().size(), - } - } - - pub fn position(&self) -> u64 { - match self { - Self::Raw(f) => f.position(), - Self::Gzipped(gz) => gz.as_inner_ref().position(), - } - } -} - impl<'a> Read for MaybeGzippedReader<'a> { fn read(&mut self, buf: &mut [u8]) -> Result { match self { diff --git a/braidz-viewer/Cargo.toml b/braidz-viewer/Cargo.toml index dcb6fc493..82a36fdc2 100644 --- a/braidz-viewer/Cargo.toml +++ b/braidz-viewer/Cargo.toml @@ -17,7 +17,7 @@ gloo = "0.8.0" gloo-file = "0.2" yew = { version = "0.21.0", features = ["csr"] } -wasm-bindgen = "0.2.92" +wasm-bindgen = { workspace = true } js-sys = "0.3.28" plotters = { version = "0.3.4", default-features = false, features = [ "bitmap_encoder", @@ -40,7 +40,7 @@ braidz-parser = { path = "../braidz-parser" } wasm-bindgen-futures = { version = "0.4.37" } [dependencies.web-sys] -version = "0.3.64" +workspace = true features = [ "Blob", "DateTimeValue", diff --git a/ci2-pyloncxx/src/lib.rs b/ci2-pyloncxx/src/lib.rs index eda3d95e4..40df766a8 100644 --- a/ci2-pyloncxx/src/lib.rs +++ b/ci2-pyloncxx/src/lib.rs @@ -1105,7 +1105,8 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { let fno: usize = match self.framecounting_method { FramecoutingMethod::BaslerGigE(ref mut i) => { - // Basler GigE cameras wrap after 65535 block + // Basler GigE cameras wrap after 65535 block. TODO: support + // "Extended ID" mode which does not have this wraparound. if block_id < 30000 && i.previous_block_id > 30000 { // check nothing crazy is going on if (i.store_fno - i.last_rollover) < 30000 { diff --git a/convert-image/Cargo.toml b/convert-image/Cargo.toml index eb336bc60..06857fe50 100644 --- a/convert-image/Cargo.toml +++ b/convert-image/Cargo.toml @@ -7,10 +7,7 @@ rust-version = "1.76" [dependencies] machine-vision-formats = "0.1.1" -image = { version = "0.24.2", default-features = false, features = [ - "jpeg", - "png", -] } +image = { workspace = true, features = ["jpeg", "png"] } thiserror = "1.0.33" bayer = { version = "0.1", default-features = false } itertools = "0.10.3" diff --git a/convert-image/src/lib.rs b/convert-image/src/lib.rs index c54ff8110..8ff86600c 100644 --- a/convert-image/src/lib.rs +++ b/convert-image/src/lib.rs @@ -991,8 +991,63 @@ pub enum ImageOptions { Png, } -/// Convert any type implementing `ImageStride` to a Jpeg or Png buffer. -pub fn frame_to_image(frame: &dyn ImageStride, opts: ImageOptions) -> Result> +/// Convert any type implementing [ImageStride] to an [image::DynamicImage]. +pub fn frame_to_image(frame: &dyn ImageStride) -> Result +where + FMT: PixelFormat, +{ + let frame = to_rgb8_or_mono8(frame)?; + + let (coding, bytes_per_pixel) = match &frame { + SupportedEncoding::Mono(_) => (image::ColorType::L8, 1), + SupportedEncoding::Rgb(_) => (image::ColorType::Rgb8, 3), + }; + + // The encoders in the `image` crate only handle packed inputs. We check if + // our data is packed and if not, make a packed copy. + + let mut packed = None; + let packed_stride = frame.width() as usize * bytes_per_pixel as usize; + if frame.stride() != packed_stride { + let mut dest = Vec::with_capacity(packed_stride * frame.height() as usize); + let src = frame.image_data(); + let chunk_iter = src.chunks_exact(frame.stride()); + if !chunk_iter.remainder().is_empty() { + return Err(invalid_buf_size_err()); + } + for src_row in chunk_iter { + dest.extend_from_slice(&src_row[..packed_stride]); + } + packed = Some(dest); + } + + let packed = match packed { + None => frame.image_data().to_vec(), + Some(p) => p, + }; + + match coding { + image::ColorType::L8 => { + let imbuf: image::ImageBuffer, _> = + image::ImageBuffer::from_raw(frame.width(), frame.height(), packed).unwrap(); + Ok(imbuf.into()) + } + image::ColorType::Rgb8 => { + let imbuf: image::ImageBuffer, _> = + image::ImageBuffer::from_raw(frame.width(), frame.height(), packed).unwrap(); + Ok(imbuf.into()) + } + _ => { + unreachable!() + } + } +} + +/// Convert any type implementing [ImageStride] to a Jpeg or Png buffer. +pub fn frame_to_encoded_buffer( + frame: &dyn ImageStride, + opts: ImageOptions, +) -> Result> where FMT: PixelFormat, { @@ -1032,12 +1087,12 @@ where ImageOptions::Jpeg(quality) => { let mut encoder = image::codecs::jpeg::JpegEncoder::new_with_quality(&mut result, quality); - encoder.encode(use_frame, frame.width(), frame.height(), coding)?; + encoder.encode(use_frame, frame.width(), frame.height(), coding.into())?; } ImageOptions::Png => { use image::ImageEncoder; let encoder = image::codecs::png::PngEncoder::new(&mut result); - encoder.write_image(use_frame, frame.width(), frame.height(), coding)?; + encoder.write_image(use_frame, frame.width(), frame.height(), coding.into())?; } } Ok(result) @@ -1151,7 +1206,7 @@ mod tests { } let frame: SimpleFrame = SimpleFrame::new(W, H, STRIDE as u32, image_data).unwrap(); - let buf = frame_to_image(&frame, ImageOptions::Png).unwrap(); + let buf = frame_to_encoded_buffer(&frame, ImageOptions::Png).unwrap(); // Decode the BMP data into an image. let im2 = image::load_from_memory_with_format(&buf, image::ImageFormat::Png).unwrap(); @@ -1184,7 +1239,7 @@ mod tests { } let frame: SimpleFrame = SimpleFrame::new(W, H, STRIDE as u32, image_data).unwrap(); - frame_to_image(&frame, ImageOptions::Jpeg(240)).unwrap(); + frame_to_encoded_buffer(&frame, ImageOptions::Jpeg(240)).unwrap(); } #[test] diff --git a/fly-eye/Cargo.toml b/fly-eye/Cargo.toml index bfdef6353..3b5a16e1c 100644 --- a/fly-eye/Cargo.toml +++ b/fly-eye/Cargo.toml @@ -11,7 +11,7 @@ log = { version = "0.4", features = ["release_max_level_debug"] } env_logger = "0.10" clap = { version = "4.3.4", features = ["derive"] } crossbeam-channel = "0.5" -image = "0.24.2" +image = { workspace = true, features = ["jpeg", "png"] } glium = "0.32.1" winit = "0.27.5" imagefmt = "4.0.0" diff --git a/flydra2/Cargo.toml b/flydra2/Cargo.toml index 0c1593e19..74ec3bbe5 100644 --- a/flydra2/Cargo.toml +++ b/flydra2/Cargo.toml @@ -84,7 +84,7 @@ simple-frame = { path = "../simple-frame" } convert-image = { path = "../convert-image" } strand-cam-csv-config-types = { path = "../strand-cam-csv-config-types" } event-stream-types = { path = "../event-stream-types" } -rerun = { version = "0.17", default-features = false, features = ["sdk"] } +rerun = { workspace = true } [dev-dependencies] tempfile = "3.4.0" diff --git a/flydra2/src/mini_arenas.rs b/flydra2/src/mini_arenas.rs index 3f6eb689f..1da2c359b 100644 --- a/flydra2/src/mini_arenas.rs +++ b/flydra2/src/mini_arenas.rs @@ -117,7 +117,7 @@ pub(crate) fn build_mini_arena_images( ) .unwrap(); let png_buf = - convert_image::frame_to_image(&frame, convert_image::ImageOptions::Png) + convert_image::frame_to_encoded_buffer(&frame, convert_image::ImageOptions::Png) .unwrap(); let dest_path = diff --git a/flytrax-csv-to-braidz/Cargo.toml b/flytrax-csv-to-braidz/Cargo.toml index 3b55161eb..a2b6c3b65 100644 --- a/flytrax-csv-to-braidz/Cargo.toml +++ b/flytrax-csv-to-braidz/Cargo.toml @@ -28,7 +28,7 @@ futures = "0.3" tokio = { version = "1.0.1", default-features = false, features = ["macros"] } tempfile = "3.4.0" anyhow = "1.0" -image = { version = "0.24.2", default-features = false, features = [ +image = { workspace = true, features = [ "jpeg", "png", ] } diff --git a/fmf/fmf-cli/Cargo.toml b/fmf/fmf-cli/Cargo.toml index 12d71004a..105702a2b 100644 --- a/fmf/fmf-cli/Cargo.toml +++ b/fmf/fmf-cli/Cargo.toml @@ -23,7 +23,7 @@ chrono = { version = "0.4.35", default-features = false, features = [ ] } anyhow = "1.0" glob = "0.3" -image = { version = "0.24.2", default-features = false, features = [ +image = { workspace = true, features = [ "jpeg", "png", "bmp", diff --git a/fmf/fmf-cli/src/fmf-cli.rs b/fmf/fmf-cli/src/fmf-cli.rs index 48c9f870d..04bc94c9b 100644 --- a/fmf/fmf-cli/src/fmf-cli.rs +++ b/fmf/fmf-cli/src/fmf-cli.rs @@ -356,7 +356,7 @@ fn export_images(path: PathBuf, opts: ImageOptions) -> Result<()> { let frame = frame?; let file = format!("frame{:05}.{}", i, ext); let fname = dirname.join(&file); - let buf = match_all_dynamic_fmts!(frame, x, convert_image::frame_to_image(&x, opts))?; + let buf = match_all_dynamic_fmts!(frame, x, convert_image::frame_to_encoded_buffer(&x, opts))?; let mut fd = std::fs::File::create(fname)?; fd.write_all(&buf)?; } diff --git a/freemovr-calibration/Cargo.toml b/freemovr-calibration/Cargo.toml index 5e65776a6..3bd45cb2c 100644 --- a/freemovr-calibration/Cargo.toml +++ b/freemovr-calibration/Cargo.toml @@ -21,7 +21,7 @@ opencv-ros-camera = { workspace = true } genmesh = "0.6" obj = { version = "0.10", features = ["genmesh"] } byteorder = "1.2.2" -image = "0.24.2" +image = { workspace = true, features = ["jpeg", "png"] } csv = "1.1" chrono = { version = "0.4.23", default-features = false, features = [ "serde", diff --git a/freemovr-calibration/freemovr-calibration-webapp/Cargo.toml b/freemovr-calibration/freemovr-calibration-webapp/Cargo.toml index 5e461fa19..eb0ee7c6d 100644 --- a/freemovr-calibration/freemovr-calibration-webapp/Cargo.toml +++ b/freemovr-calibration/freemovr-calibration-webapp/Cargo.toml @@ -13,8 +13,8 @@ yew = { version = "0.21.0", features = ["csr"] } yew-agent = "0.2.0" yew-tincture = "0.2.2" js-sys = "0.3" -wasm-bindgen = "0.2.92" -web-sys = { version = "0.3", features = [ +wasm-bindgen = { workspace = true } +web-sys = { workspace = true, features = [ "CssStyleDeclaration", "HtmlAnchorElement", ] } diff --git a/freemovr-calibration/freemovr-calibration-webapp/src/lib.rs b/freemovr-calibration/freemovr-calibration-webapp/src/lib.rs index ca9f489d5..91da5b3ce 100644 --- a/freemovr-calibration/freemovr-calibration-webapp/src/lib.rs +++ b/freemovr-calibration/freemovr-calibration-webapp/src/lib.rs @@ -419,11 +419,10 @@ fn download_file(orig_buf: &[u8], filename: &str) { let array = js_sys::Array::new(); array.push(&b.buffer()); - let blob = web_sys::Blob::new_with_u8_array_sequence_and_options( - &array, - web_sys::BlobPropertyBag::new().type_(mime_type), - ) - .unwrap_throw(); + let options = web_sys::BlobPropertyBag::new(); + options.set_type(mime_type); + let blob = + web_sys::Blob::new_with_u8_array_sequence_and_options(&array, &options).unwrap_throw(); let data_url = web_sys::Url::create_object_url_with_blob(&blob).unwrap_throw(); let document = web_sys::window().unwrap_throw().document().unwrap_throw(); let anchor = document diff --git a/freemovr-calibration/src/lib.rs b/freemovr-calibration/src/lib.rs index f995ea02c..c9c805589 100644 --- a/freemovr-calibration/src/lib.rs +++ b/freemovr-calibration/src/lib.rs @@ -435,7 +435,7 @@ fn debug_image( } let mut jpeg_buf = Vec::new(); let mut encoder = image::codecs::jpeg::JpegEncoder::new_with_quality(&mut jpeg_buf, quality); - encoder.encode(&rgb, width, height, image::ColorType::Rgb8)?; + encoder.encode(&rgb, width, height, image::ColorType::Rgb8.into())?; let mut f = std::fs::File::create(fname)?; { use std::io::Write; diff --git a/http-video-streaming/src/lib.rs b/http-video-streaming/src/lib.rs index 6dabfe394..8bcb998dd 100644 --- a/http-video-streaming/src/lib.rs +++ b/http-video-streaming/src/lib.rs @@ -104,7 +104,7 @@ impl PerSender { let bytes = basic_frame::match_all_dynamic_fmts!( &most_recent_frame_data.frame, x, - convert_image::frame_to_image(x, convert_image::ImageOptions::Jpeg(80),) + convert_image::frame_to_encoded_buffer(x, convert_image::ImageOptions::Jpeg(80),) )?; let firehose_frame_base64 = base64::encode(&bytes); let data_url = format!("data:image/jpeg;base64,{}", firehose_frame_base64); diff --git a/media-utils/dump-frame/Cargo.toml b/media-utils/dump-frame/Cargo.toml index bdfad0cf4..83b331ff7 100644 --- a/media-utils/dump-frame/Cargo.toml +++ b/media-utils/dump-frame/Cargo.toml @@ -11,7 +11,7 @@ chrono = {version="0.4.23", default-features=false} matroska = "0.19.0" openh264 = {workspace = true} tempfile = "3.4.0" -image = {version="0.24.2", default-features=false, features=["jpeg","png", "tiff", "bmp", "pnm", "gif"]} +image = {workspace = true, features=["jpeg","png", "tiff", "bmp", "pnm", "gif"]} y4m = "0.8.0" tiff = "0.9.0" diff --git a/media-utils/less-avc-wrapper/Cargo.toml b/media-utils/less-avc-wrapper/Cargo.toml index a2a33ec01..1ee0fce46 100644 --- a/media-utils/less-avc-wrapper/Cargo.toml +++ b/media-utils/less-avc-wrapper/Cargo.toml @@ -18,7 +18,7 @@ env_logger = "0.10" h264-reader = "0.7.0" rusttype = "0.9.2" ttf-firacode = "0.1" -image = { version = "0.24.2", default-features = false, features = [ +image = {workspace = true, features = [ "jpeg", "tiff", "png", diff --git a/media-utils/less-avc-wrapper/examples/formats-and-sizes.rs b/media-utils/less-avc-wrapper/examples/formats-and-sizes.rs index e3c795776..651920d0f 100644 --- a/media-utils/less-avc-wrapper/examples/formats-and-sizes.rs +++ b/media-utils/less-avc-wrapper/examples/formats-and-sizes.rs @@ -105,7 +105,7 @@ fn main() -> anyhow::Result<()> { let opts = convert_image::ImageOptions::Png; use basic_frame::{match_all_dynamic_fmts, DynamicFrame}; let png_buf = - match_all_dynamic_fmts!(&image, x, convert_image::frame_to_image(x, opts))?; + match_all_dynamic_fmts!(&image, x, convert_image::frame_to_encoded_buffer(x, opts))?; let mut fd = std::fs::File::create(png_fname)?; use std::io::Write; fd.write_all(&png_buf)?; diff --git a/media-utils/less-avc-wrapper/examples/save-animation.rs b/media-utils/less-avc-wrapper/examples/save-animation.rs index e6bd38332..447aab567 100644 --- a/media-utils/less-avc-wrapper/examples/save-animation.rs +++ b/media-utils/less-avc-wrapper/examples/save-animation.rs @@ -164,12 +164,12 @@ fn main() -> anyhow::Result<()> { match *format_str { "mono8" => { // if png_buf.is_none() { - // png_buf = Some(convert_image::frame_to_image(&frame, opts)?); + // png_buf = Some(convert_image::frame_to_encoded_buffer(&frame, opts)?); // } // convert to farget format, keeping full size let mono = convert_image::convert::<_, Mono8>(&frame)?; // if png_buf.is_none() { - // png_buf = Some(convert_image::frame_to_image(&mono, opts)?); + // png_buf = Some(convert_image::frame_to_encoded_buffer(&mono, opts)?); // } let out_size_bytes = mono.stride() * final_height as usize; @@ -181,14 +181,15 @@ fn main() -> anyhow::Result<()> { ) .unwrap(); if png_buf.is_none() { - png_buf = Some(convert_image::frame_to_image(&trimmed, opts)?); + png_buf = + Some(convert_image::frame_to_encoded_buffer(&trimmed, opts)?); } my_h264_writer.write(&trimmed)?; } "rgb8" => { // if png_buf.is_none() { - // png_buf = Some(convert_image::frame_to_image(&frame, opts)?); + // png_buf = Some(convert_image::frame_to_encoded_buffer(&frame, opts)?); // } let out_size_bytes = frame.stride() * final_height as usize; @@ -200,7 +201,8 @@ fn main() -> anyhow::Result<()> { ) .unwrap(); if png_buf.is_none() { - png_buf = Some(convert_image::frame_to_image(&trimmed, opts)?); + png_buf = + Some(convert_image::frame_to_encoded_buffer(&trimmed, opts)?); } my_h264_writer.write(&trimmed)?; diff --git a/media-utils/mp4-writer/Cargo.toml b/media-utils/mp4-writer/Cargo.toml index 7d394cd96..03be257cb 100644 --- a/media-utils/mp4-writer/Cargo.toml +++ b/media-utils/mp4-writer/Cargo.toml @@ -14,7 +14,7 @@ chrono = { version = "0.4.35", default-features = false, features = [ ] } mp4 = "0.14.0" -openh264 = {workspace = true, optional = true } +openh264 = { workspace = true, optional = true } thiserror = "1.0.33" machine-vision-formats = "0.1" bitvec = "1.0.1" @@ -39,11 +39,7 @@ env_logger = "0.10" anyhow = "1" ci2-remote-control = { path = "../../ci2-remote-control" } rusttype = "0.8.1" -image = { version = "0.24.2", default-features = false, features = [ - "jpeg", - "tiff", - "png", -] } +image = { workspace = true, features = ["jpeg", "tiff", "png"] } ttf-firacode = "0.1" simple-frame = { path = "../../simple-frame" } tempfile = "3.4.0" diff --git a/media-utils/mp4-writer/examples/formats-and-sizes.rs b/media-utils/mp4-writer/examples/formats-and-sizes.rs index 897872a98..5ef97a5ce 100644 --- a/media-utils/mp4-writer/examples/formats-and-sizes.rs +++ b/media-utils/mp4-writer/examples/formats-and-sizes.rs @@ -164,7 +164,7 @@ fn main() -> Result<(), anyhow::Error> { let opts = convert_image::ImageOptions::Png; use basic_frame::{match_all_dynamic_fmts, DynamicFrame}; let png_buf = - match_all_dynamic_fmts!(&image, x, convert_image::frame_to_image(x, opts))?; + match_all_dynamic_fmts!(&image, x, convert_image::frame_to_encoded_buffer(x, opts))?; let mut fd = std::fs::File::create(png_fname)?; use std::io::Write; fd.write_all(&png_buf)?; diff --git a/media-utils/strand-convert/src/lib.rs b/media-utils/strand-convert/src/lib.rs index edbe19fd5..0465d4243 100644 --- a/media-utils/strand-convert/src/lib.rs +++ b/media-utils/strand-convert/src/lib.rs @@ -163,7 +163,7 @@ impl ImageSequenceWriter { let buf = match_all_dynamic_fmts!( frame, x, - convert_image::frame_to_image(x, convert_image::ImageOptions::Png) + convert_image::frame_to_encoded_buffer(x, convert_image::ImageOptions::Png) )?; let mut fd = std::fs::File::create(fname)?; fd.write_all(&buf)?; diff --git a/media-utils/video2rrd/Cargo.toml b/media-utils/video2rrd/Cargo.toml index 530eb300c..b7c85619f 100644 --- a/media-utils/video2rrd/Cargo.toml +++ b/media-utils/video2rrd/Cargo.toml @@ -10,12 +10,12 @@ serde_yaml = "0.9" color-eyre = "0.6.2" tracing = "0.1.40" -rerun = "0.17.0" +rerun = { workspace = true, features = ["image"] } +image = { workspace = true, features = ["jpeg"] } opencv-ros-camera = { workspace = true } cam-geom = { workspace = true } nalgebra = { workspace = true } regex = "1.10.3" -ndarray = "0.15.6" machine-vision-formats = "0.1.1" opencv = { version = "0.88.8", optional = true } chrono = { version = "0.4.38", features = [ diff --git a/media-utils/video2rrd/src/main.rs b/media-utils/video2rrd/src/main.rs index 0b650356a..24aafd3c3 100644 --- a/media-utils/video2rrd/src/main.rs +++ b/media-utils/video2rrd/src/main.rs @@ -1,8 +1,6 @@ use clap::Parser; use color_eyre::eyre::{self, WrapErr}; use indicatif::{ProgressBar, ProgressStyle}; -use machine_vision_formats::{pixel_format, PixFmt}; -use ndarray::Array; use std::path::PathBuf; use basic_frame::DynamicFrame; @@ -42,40 +40,19 @@ struct Opt { no_progress: bool, } -fn to_rr_image(im: ImageData) -> eyre::Result { +fn to_rr_image(im: ImageData) -> eyre::Result { let decoded = match im { ImageData::Decoded(decoded) => decoded, _ => eyre::bail!("image not decoded"), }; - if true { - // jpeg compression - let contents = basic_frame::match_all_dynamic_fmts!( - &decoded, - x, - convert_image::frame_to_image(x, convert_image::ImageOptions::Jpeg(80),) - )?; - let format = Some(rerun::external::image::ImageFormat::Jpeg); - Ok(rerun::Image::from_file_contents(contents, format).unwrap()) - } else { - // Much larger file size but higher quality. - let w = decoded.width() as usize; - let h = decoded.height() as usize; - - let image = match decoded.pixel_format() { - PixFmt::Mono8 => { - let mono8 = decoded.clone().into_pixel_format::()?; - Array::from_vec(mono8.into()).into_shape((h, w, 1)).unwrap() - } - _ => { - let rgb8 = decoded - .clone() - .into_pixel_format::()?; - Array::from_vec(rgb8.into()).into_shape((h, w, 3)).unwrap() - } - }; - Ok(rerun::Image::try_from(image)?) - } + // jpeg compression TODO: give open to save uncompressed? + let contents = basic_frame::match_all_dynamic_fmts!( + &decoded, + x, + convert_image::frame_to_encoded_buffer(x, convert_image::ImageOptions::Jpeg(80),) + )?; + Ok(rerun::EncodedImage::from_file_contents(contents)) } fn main() -> eyre::Result<()> { diff --git a/mvg/Cargo.toml b/mvg/Cargo.toml index ce4fc7d01..a83c6294f 100644 --- a/mvg/Cargo.toml +++ b/mvg/Cargo.toml @@ -15,8 +15,7 @@ serde_json = "1.0" thiserror = "1.0.33" cam-geom = { workspace = true, features = ["serde-serialize"] } opencv-ros-camera = { workspace = true, features = ["serde-serialize"] } -rerun = { version = "0.17", optional = true } -glam = { version = "0.22", optional = true } +rerun = { workspace = true, optional = true } [dev-dependencies] num-iter = "0.1" @@ -24,8 +23,10 @@ approx = "0.5" dlt = { workspace = true } color-eyre = "0.6.2" +rerun = { workspace = true, features = ["glam"] } + [features] serde-serialize = [] backtrace = [] -rerun-io = ["rerun", "glam", "simba"] +rerun-io = ["rerun", "simba"] diff --git a/mvg/src/rerun_io.rs b/mvg/src/rerun_io.rs index 7587d94b4..744beff0b 100644 --- a/mvg/src/rerun_io.rs +++ b/mvg/src/rerun_io.rs @@ -55,9 +55,9 @@ impl ToR for f64 { fn rr_translation_and_mat3( extrinsics: &cam_geom::ExtrinsicParameters, -) -> rerun::TranslationAndMat3x3 { +) -> rerun::Transform3D { let t = extrinsics.camcenter(); - let translation = Some(rerun::Vec3D([t[0].f32(), t[1].f32(), t[2].f32()])); + let translation = rerun::Vec3D([t[0].f32(), t[1].f32(), t[2].f32()]); let rot = extrinsics.rotation(); let rot = rot.matrix(); let mut col_major = [0.0; 9]; @@ -67,12 +67,8 @@ fn rr_translation_and_mat3( col_major[idx] = rot[(col, row)].f32(); } } - let mat3x3 = Some(rerun::Mat3x3(col_major)); - rerun::TranslationAndMat3x3 { - translation, - mat3x3, - from_parent: false, - } + let mat3x3 = rerun::Mat3x3(col_major); + rerun::Transform3D::from_translation_mat3x3(translation, mat3x3) } pub trait AsRerunTransform3D { @@ -81,10 +77,7 @@ pub trait AsRerunTransform3D { impl AsRerunTransform3D for cam_geom::ExtrinsicParameters { fn as_rerun_transform3d(&self) -> impl Into { - rerun::Transform3D { - transform: rr_translation_and_mat3(self).into(), - axis_length: None, - } + rr_translation_and_mat3(self) } } @@ -280,7 +273,8 @@ fn test_intrinsics_rerun() { let pixels_orig = orig_intrinsics.camera_to_undistorted_pixel(&pts); for (pt3d, px_orig) in pts.data.row_iter().zip(pixels_orig.data.row_iter()) { - let pt3d_v2 = glam::Vec3::new(pt3d[0] as f32, pt3d[1] as f32, pt3d[2] as f32); + let pt3d_v2 = + rerun::external::glam::Vec3::new(pt3d[0] as f32, pt3d[1] as f32, pt3d[2] as f32); let pix_rr = rr.project(pt3d_v2); approx::assert_relative_eq!(pix_rr.x, px_orig[0] as f32, epsilon = 1e-10); approx::assert_relative_eq!(pix_rr.y, px_orig[1] as f32, epsilon = 1e-10); diff --git a/opencv-calibrate/find-chessboard/Cargo.toml b/opencv-calibrate/find-chessboard/Cargo.toml index 7cff7700e..59ff24204 100644 --- a/opencv-calibrate/find-chessboard/Cargo.toml +++ b/opencv-calibrate/find-chessboard/Cargo.toml @@ -9,7 +9,7 @@ rust-version = "1.76" [dependencies] opencv-calibrate = { path = ".." } -image = "0.24.2" +image = { workspace = true, features = ["jpeg", "png"] } serde_yaml = "0.9" clap = { version = "4.3.4", features = ["derive"] } anyhow = "1.0" diff --git a/strand-cam/src/frame_process_task.rs b/strand-cam/src/frame_process_task.rs index 109f591fa..bbfe395db 100644 --- a/strand-cam/src/frame_process_task.rs +++ b/strand-cam/src/frame_process_task.rs @@ -703,7 +703,7 @@ pub(crate) async fn frame_process_task<'a>( ); let stamped = debug_image_stamp.format(&format_str).to_string(); let png_buf = match_all_dynamic_fmts!(&frame, x, { - convert_image::frame_to_image( + convert_image::frame_to_encoded_buffer( x, convert_image::ImageOptions::Png, )? @@ -1091,7 +1091,7 @@ pub(crate) async fn frame_process_task<'a>( image_path.set_extension("jpg"); let bytes = match_all_dynamic_fmts!(&frame, x, { - convert_image::frame_to_image( + convert_image::frame_to_encoded_buffer( x, convert_image::ImageOptions::Jpeg(99), )? diff --git a/strand-cam/src/strand-cam.rs b/strand-cam/src/strand-cam.rs index 46ced34ab..03252cf51 100644 --- a/strand-cam/src/strand-cam.rs +++ b/strand-cam/src/strand-cam.rs @@ -1528,7 +1528,7 @@ where let image_height = frame.height(); let current_image_png = match_all_dynamic_fmts!(&frame, x, { - convert_image::frame_to_image(x, convert_image::ImageOptions::Png)? + convert_image::frame_to_encoded_buffer(x, convert_image::ImageOptions::Png)? }); #[cfg(feature = "flydra_feat_detect")] @@ -2320,8 +2320,11 @@ where if let Some(transmit_msg_tx) = transmit_msg_tx.as_mut() { // encode frame to png buf let current_image_png = match_all_dynamic_fmts!(frame, x, { - convert_image::frame_to_image(x, convert_image::ImageOptions::Png) - .unwrap() + convert_image::frame_to_encoded_buffer( + x, + convert_image::ImageOptions::Png, + ) + .unwrap() }); let msg = flydra_types::BraidHttpApiCallback::UpdateCurrentImage( diff --git a/strand-cam/strand-cam-offline-checkerboards/Cargo.toml b/strand-cam/strand-cam-offline-checkerboards/Cargo.toml index b21b71ed0..f35268aa5 100644 --- a/strand-cam/strand-cam-offline-checkerboards/Cargo.toml +++ b/strand-cam/strand-cam-offline-checkerboards/Cargo.toml @@ -9,7 +9,7 @@ clap = { version = "4.1.8", features = ["derive"] } env_logger = "0.10.0" glob = "0.3.1" log = "0.4.17" -image = { version = "0.24.5", default-features = false, features = ["png"] } +image = { workspace = true, features = ["png"] } opencv-ros-camera = { workspace = true } serde_yaml = { workspace = true } chrono = { workspace = true } diff --git a/strand-cam/yew_frontend/Cargo.toml b/strand-cam/yew_frontend/Cargo.toml index 9aa310510..482a74048 100644 --- a/strand-cam/yew_frontend/Cargo.toml +++ b/strand-cam/yew_frontend/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] anyhow = "1.0" wasm-logger = "0.2.0" -wasm-bindgen = "0.2.92" +wasm-bindgen = { workspace = true } wasm-bindgen-futures = "0.4" js-sys = "0.3" gloo-events = "0.1.1" @@ -37,7 +37,7 @@ enum-iter = { path = "../../enum-iter" } ads-webasm = { path = "../../ads-webasm" } [dependencies.web-sys] -version = "0.3" +workspace = true features = [ "DomRect", "DomTokenList", diff --git a/strand-cam/yew_frontend/src/components/video_field.rs b/strand-cam/yew_frontend/src/components/video_field.rs index 2f1f0e95d..990b23a90 100644 --- a/strand-cam/yew_frontend/src/components/video_field.rs +++ b/strand-cam/yew_frontend/src/components/video_field.rs @@ -35,7 +35,7 @@ pub struct VideoField { last_frame_render: f64, mouse_xy: Option, green_stroke: StrokeStyle, - green: JsValue, + green: &'static str, rendered_frame_number: Option, timeout: Option, zoom_mode: ZoomMode, @@ -95,7 +95,7 @@ impl Component for VideoField { mouse_xy: None, show_div: true, green_stroke: StrokeStyle::from_rgb(0x7F, 0xFF, 0x7F), - green: JsValue::from("7fff7f"), + green: "7fff7f", rendered_frame_number: None, timeout: None, zoom_mode: ZoomMode::FitWidth, @@ -420,11 +420,11 @@ impl VideoField { ctx.draw_image_with_html_image_element(&self.image, 0.0, 0.0) .unwrap_throw(); - ctx.set_stroke_style(&self.green); + ctx.set_stroke_style_str(self.green); ctx.set_line_width(1.0); for drawable_shape in in_msg.draw_shapes.iter() { - ctx.set_stroke_style(&drawable_shape.stroke_style.clone().into()); + ctx.set_stroke_style_str(&drawable_shape.stroke_style); ctx.set_line_width(drawable_shape.line_width as f64); use http_video_streaming_types::Shape; match &drawable_shape.shape { diff --git a/strand-cam/yew_frontend/src/lib.rs b/strand-cam/yew_frontend/src/lib.rs index b9140b0a2..1be76a853 100644 --- a/strand-cam/yew_frontend/src/lib.rs +++ b/strand-cam/yew_frontend/src/lib.rs @@ -1348,16 +1348,16 @@ fn to_rate(rate_enum: &RecordingFrameRate) -> Option { async fn post_message(msg: &CallbackType) -> Result<(), FetchError> { use web_sys::{Request, RequestInit, Response}; - let mut opts = RequestInit::new(); - opts.method("POST"); - opts.cache(web_sys::RequestCache::NoStore); + let opts = RequestInit::new(); + opts.set_method("POST"); + opts.set_cache(web_sys::RequestCache::NoStore); let buf = serde_json::to_string(&msg).unwrap_throw(); - opts.body(Some(&JsValue::from_str(&buf))); + opts.set_body(&JsValue::from_str(&buf)); let headers = web_sys::Headers::new().unwrap_throw(); headers .append("Content-Type", "application/json") .unwrap_throw(); - opts.headers(&headers); + opts.set_headers(&headers); let url = "callback"; let request = Request::new_with_str_and_init(url, &opts)?; diff --git a/zip-or-dir/src/lib.rs b/zip-or-dir/src/lib.rs index 12eaac856..66ccebaab 100644 --- a/zip-or-dir/src/lib.rs +++ b/zip-or-dir/src/lib.rs @@ -356,8 +356,6 @@ impl<'a> Read for MaybeGzReader<'a> { #[derive(Debug)] pub struct FileReader<'a> { inner: FileReaderInner<'a>, - size: u64, - position: u64, } enum FileReaderInner<'a> { @@ -375,32 +373,15 @@ impl<'a> std::fmt::Debug for FileReaderInner<'a> { } impl<'a> FileReader<'a> { - fn from_inner(inner: FileReaderInner<'a>, size: u64) -> Result> { - Ok(FileReader { - inner, - size, - position: 0, - }) + fn from_inner(inner: FileReaderInner<'a>) -> Result> { + Ok(FileReader { inner }) } fn open_file>(path: P) -> Result> { let f = File::open(path)?; - let size = f.metadata()?.len(); - Self::from_inner(FileReaderInner::File(BufReader::new(f)), size) + Self::from_inner(FileReaderInner::File(BufReader::new(f))) } fn from_zip(zipfile: zip::read::ZipFile<'a>) -> Result> { - let size = zipfile.size(); - Self::from_inner( - FileReaderInner::ZipFile(Box::new(BufReader::new(zipfile))), - size, - ) - } - - pub fn size(&self) -> u64 { - self.size - } - - pub fn position(&self) -> u64 { - self.position + Self::from_inner(FileReaderInner::ZipFile(Box::new(BufReader::new(zipfile)))) } } @@ -410,7 +391,6 @@ impl<'a> Read for FileReader<'a> { FileReaderInner::File(f) => f.read(buf)?, FileReaderInner::ZipFile(zf) => zf.read(buf)?, }; - self.position += n_bytes as u64; Ok(n_bytes) } }