Skip to main content

Crate egui_cameras

Crate egui_cameras 

Source
Expand description

egui / eframe integration for the cameras crate.

This crate owns only the thin glue between a running cameras::pump::Pump and an egui::TextureHandle. Every camera primitive (pause / resume, single-frame capture, hotplug, source abstraction) lives upstream in cameras itself and is re-exported here for convenience.

§Wiring an eframe app

use egui_cameras::cameras::{self, PixelFormat, Resolution, StreamConfig};
use eframe::egui;

struct App {
    stream: egui_cameras::Stream,
}

impl eframe::App for App {
    fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
        let ctx = ui.ctx().clone();
        egui_cameras::update_texture(&mut self.stream, &ctx).ok();
        egui::CentralPanel::default().show_inside(ui, |ui| {
            egui_cameras::show(&self.stream, ui);
        });
        ctx.request_repaint();
    }
}

The doctest is ignored because it uses eframe, which egui-cameras does not depend on. The apps/egui-demo app in this repo is the runnable version.

Re-exports§

pub use cameras;

Structs§

Pump
A running camera pump.
Sink
Shared slot that a Pump writes each frame into.
Stream
A running camera pump plus an egui::TextureHandle that is refreshed each time update_texture is called.

Functions§

capture_frame
Request a single fresh frame from the pump.
frame_to_color_image
Convert a cameras Frame into an egui ColorImage (RGBA8).
publish_frame
Publish frame to sink, replacing any previous frame.
set_active
Toggle whether the pump actively streams frames to its sink.
show
Draw the stream’s texture into ui as a sized egui::Image that fills the available width while preserving aspect ratio.
spawn
Spawn a pump that feeds a fresh Stream backed by a default-named texture. The returned Stream is in the active state.
spawn_named
Like spawn, but lets you name the egui texture. Useful when you have more than one concurrent camera stream in the same app.
spawn_pump
Spawn a Pump that writes each incoming frame into sink. Use this when you want to manage the Sink and TextureHandle yourself instead of bundling them in a Stream.
stop_and_join
Consume the pump, signal the worker to stop, and block until it has exited.
take_frame
Take the latest frame out of sink, returning None if no frame has arrived since the last call.
update_texture
Upload the latest frame on stream’s Sink to its TextureHandle.