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])
| 53 | /// file inside the app's sandbox and returning a handle. Used by the glTF |
| 54 | /// loader for embedded textures. Returns 0 on failure. |
| 55 | pub 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. |
no test coverage detected