From 563fea6582498e5b64a980ba3458a9d583e043bc Mon Sep 17 00:00:00 2001 From: Terra854 Date: Sun, 22 Nov 2026 02:33:27 +0800 Subject: [PATCH] media: use the shared GIF text control fix (#4040) * media: use the shared GIF text control fix * chore: repin craft-gif to storytold/craft-libs main (ba25ccd2) --------- Co-authored-by: Dylan M. Taylor --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/media/src/gif_anim.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ec8226e3..81cc29132 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1352,7 +1352,7 @@ dependencies = [ [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" +source = "git+https://github.com/storytold/craft-libs?rev=ba25ccd233934d1b2f74e3c0f235168bf5f13ef3#ba25ccd233934d1b2f74e3c0f235168bf5f13ef3" dependencies = [ "gif", "image", diff --git a/Cargo.toml b/Cargo.toml index e5753ceff..c1c46eb1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/c craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", default-features = false, features = ["read"] } craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3b8e426a260695af840a2cd79a064d40778f939e" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ba25ccd233934d1b2f74e3c0f235168bf5f13ef3" } craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "08da5e1486ee640de1d2cccd8fe8dd32b1d3b62c" } craft-codepage = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3dff4793f1a5bd1f99a4fe3280d48f515158dff3" } diff --git a/crates/media/src/gif_anim.rs b/crates/media/src/gif_anim.rs index dc5f55e27..146f18932 100644 --- a/crates/media/src/gif_anim.rs +++ b/crates/media/src/gif_anim.rs @@ -223,6 +223,32 @@ mod tests { assert!(e.to_lowercase().contains("memory"), "{e}"); } + #[test] + fn gif_probe_and_playback_respect_text_control_scope() { + let mut bytes = Vec::new(); + { + let mut encoder = gif::Encoder::new(&mut bytes, 2, 2, &[255, 0, 0, 0, 0, 255]).unwrap(); + for (index, delay, transparent) in [(0, 23, Some(0)), (1, 7, None)] { + let frame = gif::Frame { width: 2, height: 2, delay, transparent, buffer: vec![index; 4].into(), ..gif::Frame::default() }; + encoder.write_frame(&frame).unwrap(); + } + } + let offset = craft_gif::scan(&bytes, 1).unwrap().frames[0].offset; + // A text grid consumes the first Graphic Control Extension. The first + // image then uses the app's default display delay of 100 ms. + let text = [0x21, 0x01, 12, 0, 0, 0, 0, 2, 0, 2, 0, 1, 1, 1, 0, 1, b'X', 0]; + bytes.splice(offset..offset, text); + let bytes: std::sync::Arc<[u8]> = bytes.into(); + let footage = probe_bytes("text-control.gif", bytes.clone()).unwrap(); + let pool = MediaPool::new(); + pool.add_bytes("text-control.gif", bytes); + + assert_eq!( + (footage.duration, colour_at(&pool, &footage, 0.09), colour_at(&pool, &footage, 0.11)), + (Tick::from_units(17, 100), [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]) + ); + } + #[test] fn a_zero_delay_is_ten_hundredths_like_in_browsers() { let f = probe_bytes("a.gif", gif(&[(RED, 0), (GREEN, 1)]).into()).unwrap();