Realm

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

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.