diff --git a/Cargo.lock b/Cargo.lock index 3dc1a317f..7e59e273b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1103,6 +1103,11 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-codepage" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" + [[package]] name = "craft-doc" version = "0.1.0" @@ -1224,6 +1229,16 @@ dependencies = [ "serde_json", ] +[[package]] +name = "craft-mime" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +dependencies = [ + "chrono", + "craft-codepage", + "encoding_rs", +] + [[package]] name = "craft-pcraft-format" version = "0.1.0" @@ -1608,6 +1623,7 @@ name = "effectcraft-aep" version = "0.24.1" dependencies = [ "craft-aep", + "craft-mime", "effectcraft-color", "effectcraft-effects", "effectcraft-keyframe", @@ -1623,6 +1639,7 @@ dependencies = [ name = "effectcraft-automation" version = "0.24.1" dependencies = [ + "craft-mime", "effectcraft-engine", "effectcraft-host", "effectcraft-model", @@ -2120,6 +2137,7 @@ dependencies = [ name = "effectcraft-track" version = "0.24.1" dependencies = [ + "craft-mime", "effectcraft-raster", "effectcraft-segment", "rayon", @@ -2134,6 +2152,7 @@ version = "0.24.1" dependencies = [ "bytemuck", "chrono", + "craft-mime", "craft-quit", "craft-ui", "craft-update", diff --git a/Cargo.toml b/Cargo.toml index a0884be6d..071089c7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] +craft-mime = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.1.0", default-features = false, features = ["read"] } craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } diff --git a/crates/aep/Cargo.toml b/crates/aep/Cargo.toml index 0523edb9b..1189df8dc 100644 --- a/crates/aep/Cargo.toml +++ b/crates/aep/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-mime = { workspace = true } craft-aep = { workspace = true } effectcraft-time = { workspace = true } effectcraft-color = { workspace = true } diff --git a/crates/aep/src/export/icc.rs b/crates/aep/src/export/icc.rs index ae6db7893..04a900d00 100644 --- a/crates/aep/src/export/icc.rs +++ b/crates/aep/src/export/icc.rs @@ -224,19 +224,7 @@ pub(crate) fn profile_json(icc: &[u8], name: &str) -> String { /// Standard base64 with padding. pub(crate) fn base64(data: &[u8]) -> String { - const T: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - let mut out = String::with_capacity(data.len().div_ceil(3) * 4); - for c in data.chunks(3) { - let n = (u32::from(c[0]) << 16) | (u32::from(c.get(1).copied().unwrap_or(0)) << 8) | u32::from(c.get(2).copied().unwrap_or(0)); - for (i, shift) in [18u32, 12, 6, 0].iter().enumerate() { - if i <= c.len() { - out.push(char::from(T[((n >> shift) & 63) as usize])); - } else { - out.push('='); - } - } - } - out + craft_mime::base64::STANDARD.encode(data) } #[cfg(test)] diff --git a/crates/automation/Cargo.toml b/crates/automation/Cargo.toml index e0caf3218..23cff63c8 100644 --- a/crates/automation/Cargo.toml +++ b/crates/automation/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-mime = { workspace = true } effectcraft-engine = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } diff --git a/crates/automation/src/base64.rs b/crates/automation/src/base64.rs index 90002c600..21dd66d7e 100644 --- a/crates/automation/src/base64.rs +++ b/crates/automation/src/base64.rs @@ -1,16 +1,7 @@ //! Standard base64 (RFC 4648 §4, padded): MCP image content and the control channel's inline PNGs. -const A: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - pub fn encode(data: &[u8]) -> String { - let mut s = String::with_capacity(data.len().div_ceil(3) * 4); - for c in data.chunks(3) { - let n = (c[0] as u32) << 16 | (*c.get(1).unwrap_or(&0) as u32) << 8 | *c.get(2).unwrap_or(&0) as u32; - for i in 0..4 { - s.push(if i <= c.len() { A[(n >> (18 - 6 * i) & 63) as usize] as char } else { '=' }); - } - } - s + craft_mime::base64::STANDARD.encode(data) } /// Decode, ignoring ASCII whitespace; `None` on any other invalid input. @@ -48,6 +39,18 @@ pub fn decode(s: &str) -> Option> { #[cfg(test)] mod tests { + #[test] + fn shared_encoder_round_trips_every_byte_and_remainder() { + let all: Vec = (0..=255).cycle().take(513).collect(); + for length in 0..=all.len() { + let input = &all[..length]; + let encoded = super::encode(input); + assert_eq!(encoded.len(), length.div_ceil(3) * 4); + assert_eq!(super::decode(&encoded).as_deref(), Some(input)); + assert_eq!(encoded.bytes().rev().take_while(|b| *b == b'=').count(), (3 - length % 3) % 3); + } + } + #[test] fn rfc4648_vectors() { for (i, o) in [("", ""), ("f", "Zg=="), ("fo", "Zm8="), ("foo", "Zm9v"), ("foob", "Zm9vYg=="), ("fooba", "Zm9vYmE="), ("foobar", "Zm9vYmFy")] { diff --git a/crates/gpu/src/context.rs b/crates/gpu/src/context.rs index d074fe213..cce00bc7f 100644 --- a/crates/gpu/src/context.rs +++ b/crates/gpu/src/context.rs @@ -1207,17 +1207,25 @@ impl GpuContext { if !ticket.active() { return; } + let mapping = Arc::new(crate::readback::Mapping::new()); let b = buffer.clone(); + let callback_mapping = Arc::clone(&mapping); buffer.map_async(wgpu::MapMode::Read, .., move |r| { - if !ticket.active() { - b.unmap(); + if let Err(e) = r { + callback_mapping.failed(); + ticket.complete(Err(format!("GPU buffer mapping: {e}"))); return; } - let result = r.map_err(|e| format!("GPU buffer mapping: {e}")).and_then(|_| { - let view = b.get_mapped_range(..).map_err(|e| format!("GPU mapped range: {e}"))?; - crate::readback::packed(&view, row, stride, height) - }); - b.unmap(); + if !callback_mapping.mapped() { + return; + } + if !ticket.active() { + callback_mapping.unmap(|| b.unmap()); + return; + } + let result = + b.get_mapped_range(..).map_err(|e| format!("GPU mapped range: {e}")).and_then(|view| crate::readback::packed(&view, row, stride, height)); + callback_mapping.unmap(|| b.unmap()); ticket.complete(result); }); } @@ -1264,20 +1272,30 @@ impl GpuContext { if !ticket.active() { return Err("GPU readback cancelled".into()); } + let mapping = Arc::new(crate::readback::Mapping::new()); let b = buffer.clone(); + let callback_mapping = Arc::clone(&mapping); buffer.map_async(wgpu::MapMode::Read, .., move |r| { + if let Err(e) = r { + callback_mapping.failed(); + ticket.complete(Err(format!("GPU buffer mapping: {e}"))); + return; + } + if !callback_mapping.mapped() { + return; + } // Timed out or cancelled: nobody reads the mapping. if !ticket.active() { - b.unmap(); + callback_mapping.unmap(|| b.unmap()); return; } // Mapped: the waiting thread reads the rows and unmaps (an empty vector = mapped). - ticket.complete(r.map(|_| Vec::new()).map_err(|e| format!("GPU buffer mapping: {e}"))); + ticket.complete(Ok(Vec::new())); }); - // On any failure, unmap (harmless when not mapped; cancels a pending map) so a mapped - // buffer can never be handed out again. + // A timeout can cancel a pending map while its callback is being dispatched. The shared + // guard makes sure the callback and waiter cannot both unmap the same buffer. let fail = |e: String| { - buffer.unmap(); + mapping.unmap(|| buffer.unmap()); e }; self.wait_mapped(&rx, submission).map_err(fail)?.map_err(fail)?; @@ -1285,7 +1303,7 @@ impl GpuContext { let view = buffer.get_mapped_range(..).map_err(|e| format!("GPU mapped range: {e}")); view.and_then(|view| read(&view)) }; - buffer.unmap(); + mapping.unmap(|| buffer.unmap()); result } diff --git a/crates/gpu/src/readback.rs b/crates/gpu/src/readback.rs index 290ae08de..51d941640 100644 --- a/crates/gpu/src/readback.rs +++ b/crates/gpu/src/readback.rs @@ -4,6 +4,7 @@ use std::collections::BTreeMap; #[cfg(not(target_arch = "wasm32"))] use std::sync::Condvar; +use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::{Arc, Mutex, Weak}; use std::time::Duration; @@ -92,6 +93,48 @@ pub(crate) struct Ticket { id: u64, } +/// Tracks one GPU buffer mapping shared by the callback and its waiter. A timeout can race a +/// late callback, so the buffer must be unmapped exactly once. A failed map is never unmapped. +pub(crate) struct Mapping(AtomicU8); + +impl Mapping { + const PENDING: u8 = 0; + const MAPPED: u8 = 1; + const FAILED: u8 = 2; + const FINISHED: u8 = 3; + + pub(crate) fn new() -> Self { + Self(AtomicU8::new(Self::PENDING)) + } + + /// Claim a successful map callback. False means a timeout already cancelled the map. + pub(crate) fn mapped(&self) -> bool { + self.0.compare_exchange(Self::PENDING, Self::MAPPED, Ordering::AcqRel, Ordering::Acquire).is_ok() + } + + /// Record a failed map so the waiter will not unmap a buffer that was never mapped. + pub(crate) fn failed(&self) { + let _ = self.0.compare_exchange(Self::PENDING, Self::FAILED, Ordering::AcqRel, Ordering::Acquire); + } + + /// Unmap once if mapping is pending (cancel it) or mapped (release it). + pub(crate) fn unmap(&self, unmap: impl FnOnce()) { + let mut unmap = Some(unmap); + loop { + let state = self.0.load(Ordering::Acquire); + if state != Self::PENDING && state != Self::MAPPED { + return; + } + if self.0.compare_exchange(state, Self::FINISHED, Ordering::AcqRel, Ordering::Acquire).is_ok() { + if let Some(unmap) = unmap.take() { + unmap(); + } + return; + } + } + } +} + /// User callbacks run outside locks and are isolated one at a time. On panic=abort /// (including the usual wasm build), Rust panics cannot be caught: the host must /// avoid panicking callbacks. This branch does not claim abort-mode recovery. @@ -402,6 +445,83 @@ mod tests { use super::*; use std::sync::atomic::{AtomicUsize, Ordering}; + #[test] + fn timeout_racing_late_map_callback_unmaps_once() { + let mapping = Arc::new(Mapping::new()); + let unmap_calls = Arc::new(AtomicUsize::new(0)); + let barrier = Arc::new(std::sync::Barrier::new(3)); + + let timeout_mapping = Arc::clone(&mapping); + let timeout_calls = Arc::clone(&unmap_calls); + let timeout_barrier = Arc::clone(&barrier); + let timeout = std::thread::spawn(move || { + timeout_barrier.wait(); + timeout_mapping.unmap(|| { + timeout_calls.fetch_add(1, Ordering::SeqCst); + }); + }); + + let callback_mapping = Arc::clone(&mapping); + let callback_calls = Arc::clone(&unmap_calls); + let callback_barrier = Arc::clone(&barrier); + let callback = std::thread::spawn(move || { + callback_barrier.wait(); + if callback_mapping.mapped() { + callback_mapping.unmap(|| { + callback_calls.fetch_add(1, Ordering::SeqCst); + }); + } + }); + + barrier.wait(); + timeout.join().unwrap(); + callback.join().unwrap(); + assert_eq!(unmap_calls.load(Ordering::SeqCst), 1); + } + + #[test] + fn timeout_before_map_callback_cancels_late_map() { + let mapping = Mapping::new(); + let unmap_calls = AtomicUsize::new(0); + + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + assert!(!mapping.mapped()); + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + + assert_eq!(unmap_calls.load(Ordering::SeqCst), 1); + } + + #[test] + fn mapped_callback_and_timeout_release_once() { + let mapping = Mapping::new(); + let unmap_calls = AtomicUsize::new(0); + assert!(mapping.mapped()); + + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + + assert_eq!(unmap_calls.load(Ordering::SeqCst), 1); + } + + #[test] + fn failed_map_is_not_unmapped() { + let mapping = Mapping::new(); + let unmap_calls = AtomicUsize::new(0); + mapping.failed(); + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + assert_eq!(unmap_calls.load(Ordering::SeqCst), 0); + } + #[test] fn early_rejection_reports_no_pixels_exactly_once() { let calls = Arc::new(AtomicUsize::new(0)); diff --git a/crates/gpu/src/shaders/fx_color.wgsl b/crates/gpu/src/shaders/fx_color.wgsl index f616a2d9d..8d95ee166 100644 --- a/crates/gpu/src/shaders/fx_color.wgsl +++ b/crates/gpu/src/shaders/fx_color.wgsl @@ -75,8 +75,9 @@ fn fxc_colorama_phase(c: vec3, a: f32, mode: u32) -> f32 { // Selective Color range weights (color2::sc_weights). fn fxc_sc_weights(c0: vec3) -> array { let c = clamp(c0, vec3(0.0), vec3(1.0)); - // Stable descending sort of the channel indices. - var idx = vec3(0u, 1u, 2u); + // Stable descending sort of the channel indices. Use an array because llvmpipe does not + // preserve dynamically indexed writes to vector components here. + var idx = array(0u, 1u, 2u); for (var i = 1u; i < 3u; i++) { var j = i; while (j > 0u && c[idx[j]] > c[idx[j - 1u]]) { @@ -86,14 +87,14 @@ fn fxc_sc_weights(c0: vec3) -> array { j--; } } - let mx = c[idx.x]; - let md = c[idx.y]; - let mn = c[idx.z]; + let mx = c[idx[0]]; + let md = c[idx[1]]; + let mn = c[idx[2]]; var w = array(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); var prim = array(0u, 2u, 4u); var sec = array(3u, 5u, 1u); - w[prim[idx.x]] = mx - md; - w[sec[idx.z]] = md - mn; + w[prim[idx[0]]] = mx - md; + w[sec[idx[2]]] = md - mn; w[6] = max((mn - 0.5) * 2.0, 0.0); w[8] = max((0.5 - mx) * 2.0, 0.0); w[7] = clamp(1.0 - (abs(mx - 0.5) + abs(mn - 0.5)), 0.0, 1.0); diff --git a/crates/gpu/src/shaders/fx_lut.wgsl b/crates/gpu/src/shaders/fx_lut.wgsl index 87966df7d..f9081f834 100644 --- a/crates/gpu/src/shaders/fx_lut.wgsl +++ b/crates/gpu/src/shaders/fx_lut.wgsl @@ -130,12 +130,15 @@ fn fxl_shape(at: u32, n: u32, x: f32, flip: bool) -> f32 { // partition_point(|p| p.x < x). var lo = 0u; var hi = n; - while (lo < hi) { - let mid = (lo + hi) / 2u; - if (data[at + mid * 2u + kx] < x) { - lo = mid + 1u; - } else { - hi = mid; + // Bound the partition search as for inverse 1D LUTs below. + for (var step = 0u; step < 32u; step++) { + if (lo < hi) { + let mid = lo + (hi - lo) / 2u; + if (data[at + mid * 2u + kx] < x) { + lo = mid + 1u; + } else { + hi = mid; + } } } let i = clamp(lo, 1u, n - 1u); @@ -156,13 +159,22 @@ fn fxl_shaper_at(s: u32, k: u32) -> vec2 { return vec2(at, u32(data[s + k])); } +// Evaluate independent shaper channels without dynamically writing vector lanes. +fn fxl_shaper_apply(sh: u32, c: vec3, flip: bool) -> vec3 { + let r = fxl_shaper_at(sh, 0u); + let g = fxl_shaper_at(sh, 1u); + let b = fxl_shaper_at(sh, 2u); + return vec3( + fxl_shape(r.x, r.y, c.x, flip), + fxl_shape(g.x, g.y, c.y, flip), + fxl_shape(b.x, b.y, c.z, flip) + ); +} + fn fxl_file_fwd(o: u32, sh: i32, c0: vec3, interp: u32) -> vec3 { var c = c0; if (sh >= 0) { - for (var k = 0u; k < 3u; k++) { - let a = fxl_shaper_at(u32(sh), k); - c[k] = fxl_shape(a.x, a.y, c[k], false); - } + c = fxl_shaper_apply(u32(sh), c, false); } return fxl_lut_apply(o, c, interp); } @@ -176,12 +188,16 @@ fn fxl_inv_1d(o: u32, i: u32, y: f32) -> f32 { // partition_point over the table's values. var lo = 0u; var hi = n; - while (lo < hi) { - let mid = (lo + hi) / 2u; - if (data[b1 + mid * 3u + i] < y) { - lo = mid + 1u; - } else { - hi = mid; + // A u32 interval needs at most 32 halvings. A fixed trip count avoids + // a divergent data-dependent loop on software Vulkan without changing lookup. + for (var step = 0u; step < 32u; step++) { + if (lo < hi) { + let mid = lo + (hi - lo) / 2u; + if (data[b1 + mid * 3u + i] < y) { + lo = mid + 1u; + } else { + hi = mid; + } } } let k = clamp(lo, 1u, n - 1u); @@ -205,10 +221,7 @@ fn fxl_file(o: u32, sh: i32, c: vec3, interp: u32, inverse: bool) -> vec3(fxl_inv_1d(o, 0u, c.x), fxl_inv_1d(o, 1u, c.y), fxl_inv_1d(o, 2u, c.z)); } if (sh >= 0) { - for (var k = 0u; k < 3u; k++) { - let a = fxl_shaper_at(u32(sh), k); - x[k] = fxl_shape(a.x, a.y, x[k], true); - } + x = fxl_shaper_apply(u32(sh), x, true); } return x; } @@ -444,12 +457,11 @@ fn fxl_run(c0: vec3) -> vec3 { case 1u, 2u: { let tf = u32(data[pc + 1u]); let g = data[pc + 2u]; - for (var i = 0u; i < 3u; i++) { - if (op == 1u) { - c[i] = fxl_decode(tf, g, c[i]); - } else { - c[i] = fxl_encode(tf, g, c[i]); - } + // Explicit components avoid llvmpipe's dynamically indexed vector writes. + if (op == 1u) { + c = vec3(fxl_decode(tf, g, c.x), fxl_decode(tf, g, c.y), fxl_decode(tf, g, c.z)); + } else { + c = vec3(fxl_encode(tf, g, c.x), fxl_encode(tf, g, c.y), fxl_encode(tf, g, c.z)); } pc += 3u; } diff --git a/crates/gpu/src/tests/fx_lut.rs b/crates/gpu/src/tests/fx_lut.rs index b74e90f09..acac88835 100644 --- a/crates/gpu/src/tests/fx_lut.rs +++ b/crates/gpu/src/tests/fx_lut.rs @@ -97,6 +97,35 @@ fn apply_color_lut() { effect_case("ec.utility.applylut", &[("lut", s("/nonexistent/grade.cube"))]); } +// Keep this separate so Nextest runs the inverse lookup in a fresh process/device, +// without the preceding 3D LUT submissions in `ocio_file_transform`. The combined +// test stays intact to cover ordering and shared-device state as well. +#[test] +fn inverse_1d_lut_on_a_fresh_device_matches_cpu() { + effect_direct("ec.color.ociofile", &[("file", s(&cube_1d())), ("direction", e(1))], false); +} + +// Isolate the first profile conversion that failed in hosted llvmpipe coverage. +// This retains the same oracle and tolerance as the broader profile test. +#[test] +fn profile_conversion_on_a_fresh_device_matches_cpu() { + effect_direct("ec.utility.colorprofileconverter", &[("inputProfile", e(1)), ("outputProfile", e(3)), ("intent", e(0))], false); +} + +// Unequal CSP channel point counts exercise shaper offsets on a fresh device. +#[test] +fn csp_shaper_on_a_fresh_device_matches_cpu() { + effect_direct("ec.color.ociofile", &[("file", s(&csp())), ("interpolation", e(1))], false); + effect_direct("ec.color.ociofile", &[("file", s(&csp())), ("direction", e(1))], false); +} + +// A 1D CSP takes the direct inverse-shaper path (flip=true), unlike a 3D CSP. +#[test] +fn inverse_1d_csp_shaper_on_a_fresh_device_matches_cpu() { + let lut = "CSPLUTV100\n1D\n3\n0 0.5 1\n0 0.3 1\n2\n0 1\n0 1\n4\n0 0.2 0.6 1\n0 0.4 0.7 1\n2\n0 0 0\n1 1 1\n"; + effect_direct("ec.color.ociofile", &[("file", s(lut)), ("direction", e(1))], false); +} + #[test] fn ocio_file_transform() { for interp in 1..4 { diff --git a/crates/track/Cargo.toml b/crates/track/Cargo.toml index cd9daae36..f374a81f8 100644 --- a/crates/track/Cargo.toml +++ b/crates/track/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-mime = { workspace = true } effectcraft-raster = { workspace = true } effectcraft-segment = { workspace = true } rayon = { workspace = true } diff --git a/crates/track/src/roto/rle.rs b/crates/track/src/roto/rle.rs index 914bcad83..4a4152d82 100644 --- a/crates/track/src/roto/rle.rs +++ b/crates/track/src/roto/rle.rs @@ -1,19 +1,8 @@ //! Compact text encodings of mattes for project storage: run-length coding (LEB128 varints) //! wrapped in standard base64 (RFC 4648 §4). -const B64: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - pub fn base64_encode(data: &[u8]) -> String { - let mut out = String::with_capacity(data.len().div_ceil(3) * 4); - for c in data.chunks(3) { - let b = [c[0], *c.get(1).unwrap_or(&0), *c.get(2).unwrap_or(&0)]; - let n = (b[0] as u32) << 16 | (b[1] as u32) << 8 | b[2] as u32; - out.push(B64[(n >> 18) as usize & 63] as char); - out.push(B64[(n >> 12) as usize & 63] as char); - out.push(if c.len() > 1 { B64[(n >> 6) as usize & 63] as char } else { '=' }); - out.push(if c.len() > 2 { B64[n as usize & 63] as char } else { '=' }); - } - out + craft_mime::base64::STANDARD.encode(data) } pub fn base64_decode(s: &str) -> Option> { diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index 3c5862594..81f2023c4 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-mime = { workspace = true } craft-ui = { workspace = true } craft-quit = { workspace = true, features = ["egui"] } effectcraft-time = { workspace = true } diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 9f86c7ace..b1717d55e 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -803,19 +803,7 @@ fn render_frame(app: &EffectcraftApp, p: &Value) -> Outcome { /// Standard base64 (RFC 4648, padded). pub fn base64(data: &[u8]) -> String { - const A: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - let mut s = String::with_capacity(data.len().div_ceil(3) * 4); - for c in data.chunks(3) { - let n = (c[0] as u32) << 16 | (*c.get(1).unwrap_or(&0) as u32) << 8 | *c.get(2).unwrap_or(&0) as u32; - for i in 0..4 { - if i <= c.len() { - s.push(A[(n >> (18 - 6 * i) & 63) as usize] as char); - } else { - s.push('='); - } - } - } - s + craft_mime::base64::STANDARD.encode(data) } /// Builds the `ui.inspect` reply: window size and pixels per point, fps, UI state with the