diff --git a/src/capture.rs b/src/capture.rs index 5918b8d..cc56b56 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -60,92 +60,26 @@ impl Sequence { } } -/// Submit the clean, mirrored camera frame to the default CUPS printer. -/// JPEG travels over stdin, so captured photos are never left in temporary files. +/// Count the captured, clean selfie frame and pass the intended copies to the +/// print hook. Printer integration is intentionally left unimplemented. pub fn take_picture( frame: &opencv::core::Mat, detector: &mut crate::faces::Detector, -) -> Result<(), Box> { - use opencv::{core::Vector, imgcodecs}; +) -> opencv::Result<()> { let copies = detector.count(frame)?; - if copies == 0 { - eprintln!("[capture DEBUG] No frontal faces; skipping print job"); - return Ok(()); - } - let mut jpeg = Vector::::new(); - if !imgcodecs::imencode(".jpg", frame, &mut jpeg, &Vector::new())? { - return Err("Could not encode captured image".into()); - } - submit_print( - jpeg.as_slice(), - copies, - &mut std::process::Command::new("lp"), - ) + eprintln!("[capture DEBUG] faces={copies} requested_copies={copies} printing=unimplemented"); + print_picture(frame, copies); + Ok(()) } -fn submit_print( - jpeg: &[u8], - copies: usize, - command: &mut std::process::Command, -) -> Result<(), Box> { - use std::{io::Write, process::Stdio}; - let mut child = command - .args([ - "-n", - &copies.to_string(), - "-t", - "winf photobooth", - "-o", - "fit-to-page", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .map_err(|error| format!("Could not start CUPS lp print command: {error}. Install the CUPS client and ensure lp is on PATH."))?; - let written = child - .stdin - .take() - .ok_or("Printer stdin unavailable")? - .write_all(jpeg); - // Reap lp even if writing fails; never retry an ambiguously submitted job. - let output = child.wait_with_output()?; - if !output.status.success() { - return Err(format!( - "lp failed ({}): {}", - output.status, - String::from_utf8_lossy(&output.stderr) - ) - .into()); - } - written?; - eprintln!( - "[capture DEBUG] Submitted copies={copies}: {}", - String::from_utf8_lossy(&output.stdout).trim() - ); - Ok(()) +fn print_picture(_frame: &opencv::core::Mat, _copies: usize) { + // TODO: Implement printing. } #[cfg(test)] mod tests { use super::*; - #[test] - fn printer_receives_copy_count_and_image_and_reports_failure() { - use std::process::Command; - let mut printer = Command::new("sh"); - printer.args(["-c", r#"test "$1" = -n && test "$2" = 3 && test "$4" = 'winf photobooth' && test "$6" = fit-to-page && test "$(cat)" = photo"#, "mock-lp"]); - submit_print(b"photo", 3, &mut printer).unwrap(); - let mut failing = Command::new("sh"); - failing.args(["-c", "cat >/dev/null; echo unavailable >&2; exit 1"]); - assert!( - submit_print(b"photo", 2, &mut failing) - .unwrap_err() - .to_string() - .contains("unavailable") - ); - } - #[test] fn flash_countdown_and_single_capture_then_release() { let start = Instant::now();