MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / register_bytes

Function register_bytes

native/watchos/src/textures.rs:55–73  ·  view source on GitHub ↗

Register in-memory image bytes (PNG or JPEG) by writing them to a temp file inside the app's sandbox and returning a handle. Used by the glTF loader for embedded textures. Returns 0 on failure.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

53/// file inside the app's sandbox and returning a handle. Used by the glTF
54/// loader for embedded textures. Returns 0 on failure.
55pub fn register_bytes(bytes: &[u8]) -> u32 {
56 if bytes.len() < 8 { return 0; }
57 let (ext, (w, h)) = detect_image(bytes);
58 if ext.is_empty() { return 0; }
59
60 // Write to a stable path inside the temp dir. We include a counter so
61 // distinct blobs don't collide.
62 let mut reg = REG.lock().unwrap();
63 let idx = reg.entries.len();
64 let dir = std::env::temp_dir().join("bloom_watchos_tex");
65 let _ = std::fs::create_dir_all(&dir);
66 let file = dir.join(format!("tex_{}.{}", idx, ext));
67 if std::fs::write(&file, bytes).is_err() { return 0; }
68
69 let path_str = file.to_string_lossy().to_string();
70 let Ok(cpath) = CString::new(path_str) else { return 0; };
71 reg.entries.push(TexEntry { path: cpath, width: w, height: h });
72 reg.entries.len() as u32
73}
74
75/// Detect PNG or JPEG by magic bytes, returning extension + (width, height).
76/// Both formats are common in glTF .glb embeds.

Callers 1

resolve_textureFunction · 0.85

Calls 2

detect_imageFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected