Image operations

Source-owned programs from the current OA SDK. Rust and Python examples follow their respective public APIs.

Rust · Python

The former six-view augmentation tutorial has not been ported. These current programs demonstrate Rust headless image rendering and Python image operations; they are separate workflows.

Example

1use oa::image::decode_file as decode_image;
2use oa::render::{blit, clear, save_texture_file, texture_from_image};
3use oa::{Engine, ImageFormat, Result};
4use std::path::PathBuf;
5
6fn main() -> Result<()> {
7 let args: Vec<String> = std::env::args().collect();
8 let default_input = oa::Path::asset_rel("image/coverMl.jpg");
9 let in_path: PathBuf = args
10 .get(1)
11 .map(PathBuf::from)
12 .unwrap_or(default_input.into());
13 let out_path: PathBuf = args
14 .get(2)
15 .map(PathBuf::from)
16 .unwrap_or_else(|| PathBuf::from("/tmp/oa_viewport_batch.png"));
17
18 // ── Engine bring-up — headless (pure compute) ─────────────────────────────
19 // No surface, no VK_KHR_swapchain. Any GPU admitted by the driver works.
20 let engine = Engine::builder().build()?;
21
22 eprintln!(
23 "tu_viewer_image_headless: {} → {}",
24 in_path.display(),
25 out_path.display()
26 );
27
28 // ── Producer: decode a semantic image, then lower it to a Texture ────────
29 let image = decode_image(&engine, &in_path, ImageFormat::Rgba)?;
30 let tex = texture_from_image(&image)?;
31
32 // ── Sink: save to file (readback + encode + write) ────────────────────────
33 save_texture_file(&tex, &out_path, 90)?;
34 println!(
35 "OK: {}×{} {} → {}",
36 tex.width(),
37 tex.height(),
38 in_path.display(),
39 out_path.display()
40 );
41
42 // ── Smoke: blit (GPU copy — should round-trip to original) ───────────────
43 let blit_path = PathBuf::from("/tmp/oa_viewport_batch_blit.png");
44 let clone = blit(&tex)?;
45 save_texture_file(&clone, &blit_path, 90)?;
46 println!("OK: Blit → {}", blit_path.display());
47
48 // ── Smoke: clear (solid red) ──────────────────────────────────────────────
49 let clear_path = PathBuf::from("/tmp/oa_viewport_batch_clear.png");
50 let red = clear(&clone, oa::Color::new(0.95, 0.10, 0.10, 1.0))?;
51 save_texture_file(&red, &clear_path, 90)?;
52 println!("OK: clear(red) → {}", clear_path.display());
53
54 Ok(())
55}
56

Run Rust tutorials from the OA checkout with cargo run --release --example <name>. Run Python with the environment containing the OA native extension. Consult each program's arguments and capability checks before running it.