Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Clippy 1.99: fix new lints so `cargo xtask ci` is green again

Brandon Thomas3a392ae8da65
diff --git a/crates/ac3/src/lib.rs b/crates/ac3/src/lib.rs
index ff06ea301..ab34ad901 100644
--- a/crates/ac3/src/lib.rs
+++ b/crates/ac3/src/lib.rs
@@ -359,8 +359,7 @@ fn bit_allocation(exp: &[u8; 256], p: &AllocParams, g: &Globals, bap: &mut [u8;
let bndend = tables::MASKTAB[end - 1] as usize + 1;
let mut excite = [0i32; 50];
let (mut fastleak, mut slowleak) = p.leak.unwrap_or((0, 0));
- let begin;
- if bndstrt == 0 {
+ let begin = if bndstrt == 0 {
// the last band of the LFE channel (bndend 7) has no band above it
let lfe_last = |bin: usize| !(bndend == 7 && bin == 6);
let mut lowcomp = 0;
@@ -391,10 +390,10 @@ fn bit_allocation(exp: &[u8; 256], p: &AllocParams, g: &Globals, bap: &mut [u8;
slowleak = slowleak.max(bndpsd[bin] - sgain);
excite[bin] = (fastleak - lowcomp).max(slowleak);
}
- begin = 22;
+ 22
} else {
- begin = bndstrt;
- }
+ bndstrt
+ };
for bin in begin..bndend {
fastleak -= fdecay;
fastleak = fastleak.max(bndpsd[bin] - p.fgain);
diff --git a/crates/ac3/tests/oracle.rs b/crates/ac3/tests/oracle.rs
index 9c2ea4222..019d81387 100644
--- a/crates/ac3/tests/oracle.rs
+++ b/crates/ac3/tests/oracle.rs
@@ -99,7 +99,7 @@ fn ffmpeg_encoded_streams_decode() {
}
}
let o = Command::new(&ff).args(["-v", "error", "-i"]).arg(&f).args(["-f", "f32le", "-"]).output().unwrap();
- let want: Vec<f32> = o.stdout.chunks_exact(4).map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
+ let want: Vec<f32> = o.stdout.as_chunks::<4>().0.iter().map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
let ch = s.channels as usize;
let n = want.len() / ch;
assert_eq!(n, ours[0].len(), "{}: sample count", s.name);
diff --git a/crates/av1/tests/common/mod.rs b/crates/av1/tests/common/mod.rs
index b470e9b37..7998dbd13 100644
--- a/crates/av1/tests/common/mod.rs
+++ b/crates/av1/tests/common/mod.rs
@@ -76,7 +76,7 @@ pub fn reference(ff: &Path, path: &Path, pix_fmt: &str) -> Vec<u16> {
.expect("run ffmpeg");
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
if pix_fmt.ends_with("le") {
- out.stdout.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect()
+ out.stdout.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect()
} else {
out.stdout.iter().map(|&b| b as u16).collect()
}
diff --git a/crates/captions/src/lib.rs b/crates/captions/src/lib.rs
index 7ddf759f2..6200b63bb 100644
--- a/crates/captions/src/lib.rs
+++ b/crates/captions/src/lib.rs
@@ -253,7 +253,7 @@ pub fn decode_text(bytes: &[u8]) -> String {
} else if bytes.starts_with(&[0xff, 0xfe]) || bytes.starts_with(&[0xfe, 0xff]) {
let le = bytes[0] == 0xff;
let units: Vec<u16> =
- bytes[2..].chunks_exact(2).map(|c| if le { u16::from_le_bytes([c[0], c[1]]) } else { u16::from_be_bytes([c[0], c[1]]) }).collect();
+ bytes[2..].as_chunks::<2>().0.iter().map(|c| if le { u16::from_le_bytes([c[0], c[1]]) } else { u16::from_be_bytes([c[0], c[1]]) }).collect();
String::from_utf16_lossy(&units)
} else {
match std::str::from_utf8(bytes) {
diff --git a/crates/captions/src/stl.rs b/crates/captions/src/stl.rs
index 7b4a7b47c..3878cc4f5 100644
--- a/crates/captions/src/stl.rs
+++ b/crates/captions/src/stl.rs
@@ -277,7 +277,7 @@ pub fn parse(bytes: &[u8]) -> Result<Document> {
}
}
};
- for blk in bytes[GSI..].chunks_exact(TTI) {
+ for blk in bytes[GSI..].as_chunks::<TTI>().0 {
let sn = u16::from_le_bytes([blk[1], blk[2]]);
let ebn = blk[3];
let cf = blk[15];
diff --git a/crates/cfb/src/read.rs b/crates/cfb/src/read.rs
index 32cea2d0c..58c300b56 100644
--- a/crates/cfb/src/read.rs
+++ b/crates/cfb/src/read.rs
@@ -143,7 +143,7 @@ impl<'a> CompoundFile<'a> {
// Mini FAT and mini stream.
if first_minifat <= MAXREGSECT {
let mf = cf.read_chain(first_minifat, None)?;
- cf.minifat = mf.chunks_exact(4).map(|c| u32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect();
+ cf.minifat = mf.as_chunks::<4>().0.iter().map(|c| u32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect();
}
let root = &cf.entries[0];
if root.start <= MAXREGSECT && root.size > 0 {
diff --git a/crates/codecs/src/tests.rs b/crates/codecs/src/tests.rs
index af383cb8c..e984856d8 100644
--- a/crates/codecs/src/tests.rs
+++ b/crates/codecs/src/tests.rs
@@ -472,7 +472,7 @@ fn opus_reference(name: &str) -> Option<Vec<f32>> {
if !st.success() {
return None;
}
- Some(std::fs::read(out).ok()?.chunks_exact(4).map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect())
+ Some(std::fs::read(out).ok()?.as_chunks::<4>().0.iter().map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect())
}
fn snr_db(reference: &[f32], test: &[f32]) -> f64 {
diff --git a/crates/codecs/tests/common/mod.rs b/crates/codecs/tests/common/mod.rs
index 9a4bbbd2b..19662410a 100644
--- a/crates/codecs/tests/common/mod.rs
+++ b/crates/codecs/tests/common/mod.rs
@@ -48,7 +48,7 @@ pub fn ffmpeg_audio_f32(ff: &Path, file: &Path, extra: &[&str]) -> Vec<f32> {
let mut args = vec!["-i", file.to_str().unwrap()];
args.extend_from_slice(extra);
args.extend_from_slice(&["-map", "0:a:0", "-f", "f32le", "-"]);
- ffmpeg_out(ff, &args).chunks_exact(4).map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()
+ ffmpeg_out(ff, &args).as_chunks::<4>().0.iter().map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()
}
/// Our frame's three planes widened to u16 (and their sizes).
@@ -63,7 +63,7 @@ pub fn planes(f: &VideoFrame) -> Vec<Vec<u16>> {
/// Split one raw frame of `ffmpeg_frames` into planes (`bps` bytes per sample, chroma `cw`×`ch`).
pub fn raw_planes(raw: &[u8], w: usize, h: usize, cw: usize, ch: usize, bps: usize) -> Vec<Vec<u16>> {
let get = |b: &[u8]| -> Vec<u16> {
- if bps == 1 { b.iter().map(|&v| v as u16).collect() } else { b.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect() }
+ if bps == 1 { b.iter().map(|&v| v as u16).collect() } else { b.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect() }
};
let y = w * h * bps;
let c = cw * ch * bps;
diff --git a/crates/codecs/tests/ogg_oracle.rs b/crates/codecs/tests/ogg_oracle.rs
index 48a30e919..043715a12 100644
--- a/crates/codecs/tests/ogg_oracle.rs
+++ b/crates/codecs/tests/ogg_oracle.rs
@@ -92,7 +92,7 @@ fn decode_both(ff: &Path, file: &Path, decoder: &[&str]) -> (OggSource, Vec<f32>
let ch = a.channels as usize;
let mut args: Vec<&str> = decoder.to_vec();
args.extend_from_slice(&["-i", file.to_str().unwrap(), "-map", "0:a:0", "-f", "f32le", "-"]);
- let want: Vec<f32> = ffmpeg_out(ff, &args).chunks_exact(4).map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
+ let want: Vec<f32> = ffmpeg_out(ff, &args).as_chunks::<4>().0.iter().map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
let n = want.len() / ch;
let frames = src.info().duration.to_units_floor(a.sample_rate as i64) as usize;
assert_eq!(frames, n, "{}: our length = ffmpeg's ({} samples)", file.display(), n);
diff --git a/crates/dnx/src/ffmpeg_probe.rs b/crates/dnx/src/ffmpeg_probe.rs
index 49622fa22..88cbaa818 100644
--- a/crates/dnx/src/ffmpeg_probe.rs
+++ b/crates/dnx/src/ffmpeg_probe.rs
@@ -127,7 +127,7 @@ fn probe_weights() {
let px: Vec<f64> = if depth == 8 {
out.stdout.iter().map(|&b| b as f64).collect()
} else {
- out.stdout.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]]) as f64).collect()
+ out.stdout.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]]) as f64).collect()
};
let (off, stride) = if blk == 0 { (0, w as usize) } else { ((w * h) as usize, w as usize / 2) };
let mid = (1 << (depth - 1)) as f64;
@@ -224,7 +224,7 @@ fn probe_reconstruction() {
let px: Vec<f64> = if depth == 8 {
out.stdout.iter().map(|&b| b as f64).collect()
} else {
- out.stdout.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]]) as f64).collect()
+ out.stdout.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]]) as f64).collect()
};
let mid = (1 << (depth - 1)) as f64;
let mut sum = 0f64;
diff --git a/crates/dnx/tests/common/mod.rs b/crates/dnx/tests/common/mod.rs
index 8af783482..ef0fef836 100644
--- a/crates/dnx/tests/common/mod.rs
+++ b/crates/dnx/tests/common/mod.rs
@@ -91,7 +91,7 @@ pub fn reference(ff: &Path, mov: &Path, pix_fmt: &str) -> Vec<u16> {
.expect("run ffmpeg");
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
if pix_fmt.ends_with("le") {
- out.stdout.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect()
+ out.stdout.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect()
} else {
out.stdout.iter().map(|&b| b as u16).collect()
}
@@ -247,7 +247,7 @@ pub fn ffmpeg_decode(ff: &Path, mov: &Path, pix_fmt: &str) -> Vec<u16> {
let err = String::from_utf8_lossy(&out.stderr).to_string();
assert!(out.status.success() && err.trim().is_empty(), "ffmpeg failed: {err}");
if pix_fmt.ends_with("le") {
- out.stdout.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect()
+ out.stdout.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect()
} else {
out.stdout.iter().map(|&b| b as u16).collect()
}
@@ -270,8 +270,11 @@ pub fn source_frames(ff: &Path, name: &str, lavfi: &str, frames: u32, w: u32, h:
std::fs::rename(&tmp, &path).unwrap();
}
let bytes = std::fs::read(&path).unwrap();
- let s: Vec<u16> =
- if depth == 8 { bytes.iter().map(|&b| b as u16).collect() } else { bytes.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect() };
+ let s: Vec<u16> = if depth == 8 {
+ bytes.iter().map(|&b| b as u16).collect()
+ } else {
+ bytes.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect()
+ };
let proto = Frame::new(w, h, chroma, depth, false);
let per = frame_samples(&proto);
assert_eq!(s.len(), per * frames as usize);
diff --git a/crates/engine/src/color_tests.rs b/crates/engine/src/color_tests.rs
index fe7d7aaa7..61513ea4a 100644
--- a/crates/engine/src/color_tests.rs
+++ b/crates/engine/src/color_tests.rs
@@ -33,7 +33,7 @@ fn lumetri_text(s: &Session, clip: ClipId, p: &str) -> String {
fn mean(img: &filmcraft_render::Image) -> [f32; 3] {
assert!(img.px.iter().any(|v| *v > 0.01), "blank render");
let mut m = [0f64; 3];
- for p in img.px.chunks_exact(4) {
+ for p in img.px.as_chunks::<4>().0 {
for k in 0..3 {
m[k] += p[k] as f64;
}
@@ -213,7 +213,7 @@ fn lumetri_presets_list_apply_and_thumbnails() {
assert!(it.effects[k + 1..].iter().all(|e| e.def().is_some_and(|d| d.intrinsic)) || k + 1 == it.effects.len());
assert_eq!(it.effects[k].param("saturation").unwrap().value, ParamValue::Float(0.0));
let img = s.render_program(0.25).unwrap();
- let grey = img.px.chunks_exact(4).filter(|p| p[3] > 0.5).all(|p| (p[0] - p[1]).abs() < 0.01 && (p[1] - p[2]).abs() < 0.01);
+ let grey = img.px.as_chunks::<4>().0.iter().filter(|p| p[3] > 0.5).all(|p| (p[0] - p[1]).abs() < 0.01 && (p[1] - p[2]).abs() < 0.01);
assert!(grey, "the program is black and white");
s.execute("edit.undo", json!({})).unwrap();
assert_eq!(s.active_sequence().unwrap().find_item(clip).unwrap().1.effects.len(), before);
@@ -242,7 +242,7 @@ fn hdr_lumetri_and_mastering_metadata_through_commands() {
for k in 0..3 {
assert!((m1[k] / m0[k] - 2.0).abs() < 0.08, "channel {k}: {m0:?} → {m1:?}");
}
- assert!(up.px.chunks_exact(4).any(|p| p[1] > 1.2), "values above reference white survive");
+ assert!(up.px.as_chunks::<4>().0.iter().any(|p| p[1] > 1.2), "values above reference white survive");
// HDR White / HDR Specular / HDR Range are ordinary Lumetri parameters
s.execute("effects.setParam", json!({"clip": clip.0, "effect": idx, "param": "hdr_white", "value": 2000.0})).unwrap();
s.execute("effects.setParam", json!({"clip": clip.0, "effect": idx, "param": "hdr_specular", "value": -50.0})).unwrap();
diff --git a/crates/engine/src/media_test_util.rs b/crates/engine/src/media_test_util.rs
index b32038320..a8e80ca68 100644
--- a/crates/engine/src/media_test_util.rs
+++ b/crates/engine/src/media_test_util.rs
@@ -101,7 +101,7 @@ pub fn psnr(a: &[u8], b: &[u8]) -> f64 {
assert_eq!(a.len(), b.len());
let mut se = 0.0;
let mut n = 0.0;
- for (x, y) in a.chunks_exact(4).zip(b.chunks_exact(4)) {
+ for (x, y) in a.as_chunks::<4>().0.iter().zip(b.as_chunks::<4>().0) {
for c in 0..3 {
let d = x[c] as f64 - y[c] as f64;
se += d * d;
diff --git a/crates/engine/src/previews.rs b/crates/engine/src/previews.rs
index 5651f9b77..e3e209317 100644
--- a/crates/engine/src/previews.rs
+++ b/crates/engine/src/previews.rs
@@ -680,7 +680,7 @@ pub fn read_wav_f32(b: &[u8]) -> Option<Vec<f32>> {
if !float_stereo {
return None;
}
- return Some(body.chunks_exact(4).map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect());
+ return Some(body.as_chunks::<4>().0.iter().map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect());
}
i += 8 + len + (len & 1);
}
diff --git a/crates/engine/src/relink.rs b/crates/engine/src/relink.rs
index 72708a9bf..373ece986 100644
--- a/crates/engine/src/relink.rs
+++ b/crates/engine/src/relink.rs
@@ -35,12 +35,11 @@ pub fn fingerprint(size: u64, head: &[u8], tail: &[u8]) -> u64 {
h ^= h >> 29;
};
for part in [head, tail] {
- let mut chunks = part.chunks_exact(8);
- for c in &mut chunks {
- mix(u64::from_le_bytes([c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]]));
+ let (chunks, r) = part.as_chunks::<8>();
+ for c in chunks {
+ mix(u64::from_le_bytes(*c));
}
let mut last = [0u8; 8];
- let r = chunks.remainder();
last[..r.len()].copy_from_slice(r);
mix(u64::from_le_bytes(last) ^ (r.len() as u64) << 56);
mix(part.len() as u64);
diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rs
index cf73c6639..041270b45 100644
--- a/crates/export/src/lib.rs
+++ b/crates/export/src/lib.rs
@@ -568,7 +568,7 @@ impl VideoEncoder for MjpegEncoder {
self.rate.num as u32
}
fn encode(&mut self, f: &EncoderFrame) -> Result<Vec<EncodedPacket>> {
- let rgb: Vec<u8> = f.rgba.chunks_exact(4).flat_map(|p| [p[0], p[1], p[2]]).collect();
+ let rgb: Vec<u8> = f.rgba.as_chunks::<4>().0.iter().flat_map(|p| [p[0], p[1], p[2]]).collect();
let mut out = Vec::new();
let mut enc = image::codecs::jpeg::JpegEncoder::new_with_quality(&mut out, self.quality);
enc.encode(&rgb, f.width, f.height, image::ExtendedColorType::Rgb8).map_err(|e| ExportError::Encode(e.to_string()))?;
diff --git a/crates/export/src/mxf_tests.rs b/crates/export/src/mxf_tests.rs
index 27576e740..cb61bb744 100644
--- a/crates/export/src/mxf_tests.rs
+++ b/crates/export/src/mxf_tests.rs
@@ -225,7 +225,7 @@ fn ffmpeg_oracle_op1a_and_op_atom() {
let at = mx.track_of_kind(filmcraft_mxf::TrackKind::Sound).unwrap();
let ours = mx.read_pcm(&bytes, at, 0, 48_000).unwrap();
assert_eq!(pcm.len(), 48_000 * 2 * 4, "{codec:?}");
- for (i, c) in pcm.chunks_exact(4).enumerate() {
+ for (i, c) in pcm.as_chunks::<4>().0.iter().enumerate() {
let s = i32::from_le_bytes([c[0], c[1], c[2], c[3]]) >> 8;
assert_eq!(s as f32 / 8_388_608.0, ours[i % 2][i / 2], "{codec:?}: sample {i}");
}
@@ -255,7 +255,7 @@ fn ffmpeg_oracle_op1a_and_op_atom() {
assert_eq!((s["codec_name"].as_str(), s["channels"].as_u64(), s["sample_rate"].as_str()), (Some("pcm_s24le"), Some(1), Some("48000")), "{a}");
let mono = ffmpeg_raw(&ffmpeg, a, "0:a:0", &["-f", "s32le", "-acodec", "pcm_s32le"]);
assert_eq!(mono.len(), 48_000 * 4, "{a}");
- let want: Vec<u8> = stereo.chunks_exact(8).flat_map(|f| f[k * 4..k * 4 + 4].to_vec()).collect();
+ let want: Vec<u8> = stereo.as_chunks::<8>().0.iter().flat_map(|f| f[k * 4..k * 4 + 4].to_vec()).collect();
assert!(mono == want, "{a}: channel {k} differs from the WAV export");
}
}
diff --git a/crates/export/src/pipeline.rs b/crates/export/src/pipeline.rs
index c9b3c6a84..d151e87d3 100644
--- a/crates/export/src/pipeline.rs
+++ b/crates/export/src/pipeline.rs
@@ -111,7 +111,7 @@ impl Pipeline {
if let Some(tf) = self.out_tf.as_ref().filter(|_| self.hdr_out) {
let mut out = vec![0f32; img.w * img.h * 3];
out.par_chunks_mut(img.w * 3).zip(img.px.par_chunks(img.w * 4)).for_each(|(o, s)| {
- for (o, p) in o.chunks_exact_mut(3).zip(s.chunks_exact(4)) {
+ for (o, p) in o.as_chunks_mut::<3>().0.iter_mut().zip(s.as_chunks::<4>().0) {
o.copy_from_slice(&tf.encode([p[0], p[1], p[2]]));
}
});
@@ -239,7 +239,7 @@ fn load_overlay(path: &str, width: f32) -> Result<Image> {
let rgba = image::load_from_memory(&bytes).map_err(|e| ExportError::Unsupported(format!("image overlay {path}: {e}")))?.to_rgba8();
let (iw, ih) = (rgba.width() as usize, rgba.height() as usize);
let mut img = Image::new(iw, ih);
- for (o, p) in img.px.chunks_exact_mut(4).zip(rgba.as_raw().chunks_exact(4)) {
+ for (o, p) in img.px.as_chunks_mut::<4>().0.iter_mut().zip(rgba.as_raw().as_chunks::<4>().0) {
let a = p[3] as f32 / 255.0;
for c in 0..3 {
o[c] = filmcraft_color::srgb_to_linear(p[c] as f32 / 255.0) * a;
@@ -310,7 +310,7 @@ fn resample_axis(src: &Image, n: usize, horizontal: bool) -> Image {
pub fn limit_rgba8(rgba: &mut [u8], min_percent: f32, max_percent: f32) {
let (lo, hi) = (min_percent.clamp(0.0, 100.0) / 100.0, max_percent.clamp(0.0, 100.0) / 100.0);
rgba.par_chunks_mut(4 * 1024).for_each(|chunk| {
- for p in chunk.chunks_exact_mut(4) {
+ for p in chunk.as_chunks_mut::<4>().0 {
let mut c = [p[0] as f32 / 255.0, p[1] as f32 / 255.0, p[2] as f32 / 255.0];
limit_px(&mut c, lo, hi);
for i in 0..3 {
@@ -323,7 +323,7 @@ pub fn limit_rgba8(rgba: &mut [u8], min_percent: f32, max_percent: f32) {
fn limit_f32(rgb: &mut [f32], min_percent: f32, max_percent: f32) {
let (lo, hi) = (min_percent.clamp(0.0, 100.0) / 100.0, max_percent.clamp(0.0, 100.0) / 100.0);
rgb.par_chunks_mut(3 * 1024).for_each(|chunk| {
- for p in chunk.chunks_exact_mut(3) {
+ for p in chunk.as_chunks_mut::<3>().0 {
let mut c = [p[0], p[1], p[2]];
limit_px(&mut c, lo, hi);
p.copy_from_slice(&c);
diff --git a/crates/export/src/settings_tests.rs b/crates/export/src/settings_tests.rs
index 4053c5327..9904d3c3b 100644
--- a/crates/export/src/settings_tests.rs
+++ b/crates/export/src/settings_tests.rs
@@ -204,7 +204,7 @@ fn read_wav16(path: &str) -> Vec<Vec<f32>> {
let ch = u16::from_le_bytes([b[22], b[23]]) as usize;
let data = &b[44..];
let mut out = vec![Vec::new(); ch];
- for (i, s) in data.chunks_exact(2).enumerate() {
+ for (i, s) in data.as_chunks::<2>().0.iter().enumerate() {
out[i % ch].push(i16::from_le_bytes([s[0], s[1]]) as f32 / 32768.0);
}
out
diff --git a/crates/export/src/surround_tests.rs b/crates/export/src/surround_tests.rs
index 9dcb77e92..bb7068ec7 100644
--- a/crates/export/src/surround_tests.rs
+++ b/crates/export/src/surround_tests.rs
@@ -110,7 +110,7 @@ fn decode(path: &str) -> Option<Vec<Vec<f64>>> {
let out =
std::process::Command::new(ffmpeg).args(["-v", "error", "-i", path, "-map", "0:a:0", "-f", "s32le", "-acodec", "pcm_s32le", "-"]).output().unwrap();
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
- let ints: Vec<i32> = out.stdout.chunks_exact(4).map(|b| i32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
+ let ints: Vec<i32> = out.stdout.as_chunks::<4>().0.iter().map(|b| i32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
let n = ints.len() / 6;
Some((0..6).map(|c| (0..n).map(|i| ints[i * 6 + c] as f64).collect()).collect())
}
diff --git a/crates/frame/src/lib.rs b/crates/frame/src/lib.rs
index 51c3dcbb4..69b29a608 100644
--- a/crates/frame/src/lib.rs
+++ b/crates/frame/src/lib.rs
@@ -383,14 +383,14 @@ impl VideoFrame {
pub fn luma8(&self) -> Vec<u8> {
match &self.data {
PixelData::Yuv8 { planes, .. } => planes[0].as_ref().clone(),
- _ => self.to_rgba8().chunks_exact(4).map(|p| (0.2126 * p[0] as f32 + 0.7152 * p[1] as f32 + 0.0722 * p[2] as f32) as u8).collect(),
+ _ => self.to_rgba8().as_chunks::<4>().0.iter().map(|p| (0.2126 * p[0] as f32 + 0.7152 * p[1] as f32 + 0.0722 * p[2] as f32) as u8).collect(),
}
}
}
/// Convert a row of premultiplied linear f32 RGBA into straight sRGB RGBA8.
pub fn linear_premul_to_srgb8(src: &[f32], dst: &mut [u8]) {
- for (s, o) in src.chunks_exact(4).zip(dst.chunks_exact_mut(4)) {
+ for (s, o) in src.as_chunks::<4>().0.iter().zip(dst.as_chunks_mut::<4>().0) {
let a = s[3].clamp(0.0, 1.0);
if a <= 0.0 {
o.copy_from_slice(&[0, 0, 0, 0]);
diff --git a/crates/golden/tests/golden.rs b/crates/golden/tests/golden.rs
index 20f93d0c7..f4945a366 100644
--- a/crates/golden/tests/golden.rs
+++ b/crates/golden/tests/golden.rs
@@ -185,7 +185,9 @@ impl MediaSource for Encoded {
let m = filmcraft_color::spaces::to_f32(&filmcraft_color::spaces::gamut_matrix(Gamut::Bt709, self.target.gamut()));
let curve = self.target.curve();
let out: Vec<u8> = rgba
- .chunks_exact(4)
+ .as_chunks::<4>()
+ .0
+ .iter()
.flat_map(|p| {
let lin = [0, 1, 2].map(|k| filmcraft_color::srgb_to_linear(p[k] as f32 / 255.0) * self.gain);
let c = filmcraft_color::spaces::apply3(&m, lin);
@@ -723,7 +725,7 @@ fn lumetri_presets_grid() {
fn scenes_are_distinct() {
let imgs: Vec<(&str, Rgba8)> = scenes().into_iter().map(|(n, _, f)| (n, render_cpu(&f()))).collect();
for (n, img) in &imgs {
- let lit = img.px.chunks_exact(4).filter(|p| p[0] as u32 + p[1] as u32 + p[2] as u32 > 30).count();
+ let lit = img.px.as_chunks::<4>().0.iter().filter(|p| p[0] as u32 + p[1] as u32 + p[2] as u32 > 30).count();
assert!(lit > img.px.len() / 4 / 4, "{n}: mostly black");
}
for i in 0..imgs.len() {
@@ -758,7 +760,7 @@ fn gpu_matches_cpu_on_golden_scenes() {
let kind = if matches!(plan, filmcraft_render::plan::FramePlan::Layers { .. }) { "layers" } else { "cpu image" };
c.composite(&plan);
let (gw, gh, mut px) = c.read_output().expect("GPU readback");
- px.chunks_exact_mut(4).for_each(|p| p[3] = 255);
+ px.as_chunks_mut::<4>().0.iter_mut().for_each(|p| p[3] = 255);
let gpu = Rgba8::new(gw, gh, px);
let d = diff(&cpu, &gpu).unwrap();
// mean over RGB only (alpha is equal by construction)
diff --git a/crates/gpu/src/lib.rs b/crates/gpu/src/lib.rs
index 72233d571..4663121e8 100644
--- a/crates/gpu/src/lib.rs
+++ b/crates/gpu/src/lib.rs
@@ -135,7 +135,7 @@ const CHUNK: usize = 1 << 15;
fn f32_to_f16_bytes(v: &[f32]) -> Vec<u8> {
let mut out = vec![0u8; v.len() * 2];
out.par_chunks_mut(CHUNK * 2).zip(v.par_chunks(CHUNK)).for_each(|(o, s)| {
- for (o, x) in o.chunks_exact_mut(2).zip(s) {
+ for (o, x) in o.as_chunks_mut::<2>().0.iter_mut().zip(s) {
o.copy_from_slice(&f32_to_f16(*x).to_le_bytes());
}
});
@@ -157,7 +157,7 @@ fn codes_to_f16_bytes(v: &[u16], bits: u32) -> Vec<u8> {
let table = code_table(bits);
let mut out = vec![0u8; v.len() * 2];
out.par_chunks_mut(CHUNK * 2).zip(v.par_chunks(CHUNK)).for_each(|(o, s)| {
- for (o, c) in o.chunks_exact_mut(2).zip(s) {
+ for (o, c) in o.as_chunks_mut::<2>().0.iter_mut().zip(s) {
o.copy_from_slice(&table[*c as usize]);
}
});
diff --git a/crates/gpu/src/lut.rs b/crates/gpu/src/lut.rs
index 7d53710b7..4743bd15d 100644
--- a/crates/gpu/src/lut.rs
+++ b/crates/gpu/src/lut.rs
@@ -112,7 +112,7 @@ impl GpuLut {
let _ = d.poll(wgpu::PollType::wait_indefinitely());
rx.recv().ok()?.ok()?;
let data = slice.get_mapped_range().ok()?;
- let out = data.chunks_exact(4).map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
+ let out = data.as_chunks::<4>().0.iter().map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
drop(data);
rb.unmap();
Some(out)
diff --git a/crates/gpu/src/mask.rs b/crates/gpu/src/mask.rs
index 250b2bad7..35bd821fd 100644
--- a/crates/gpu/src/mask.rs
+++ b/crates/gpu/src/mask.rs
@@ -162,7 +162,7 @@ impl GpuMask {
let _ = d.poll(wgpu::PollType::wait_indefinitely());
rx.recv().ok()?.ok()?;
let data = slice.get_mapped_range().ok()?;
- let v = data.chunks_exact(4).map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
+ let v = data.as_chunks::<4>().0.iter().map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
drop(data);
b.unmap();
Some(v)
diff --git a/crates/gpu/src/tests.rs b/crates/gpu/src/tests.rs
index 241cbc946..014d68ddf 100644
--- a/crates/gpu/src/tests.rs
+++ b/crates/gpu/src/tests.rs
@@ -172,7 +172,7 @@ fn gpu_lut_matches_cpu_tetrahedral() {
}
let gpu = g.apply(&lut, &px).expect("gpu lut");
let mut worst = 0f32;
- for (i, p) in px.chunks_exact(4).enumerate() {
+ for (i, p) in px.as_chunks::<4>().0.iter().enumerate() {
let c = lut.apply([p[0], p[1], p[2]]);
for k in 0..3 {
worst = worst.max((c[k] - gpu[i * 4 + k]).abs());
diff --git a/crates/h264enc/src/lib.rs b/crates/h264enc/src/lib.rs
index 78e891e57..f43aadea4 100644
--- a/crates/h264enc/src/lib.rs
+++ b/crates/h264enc/src/lib.rs
@@ -650,7 +650,7 @@ impl Encoder {
let mut jobs: Vec<Job> = Vec::with_capacity(pics.len());
for (input, mut st, idr) in pics {
if idr {
- let old: Vec<RefPic> = self.dpb.drain(..).collect();
+ let old: Vec<RefPic> = std::mem::take(&mut self.dpb);
for r in old {
self.recycle_ref(r);
}
diff --git a/crates/interchange/src/aaf/store.rs b/crates/interchange/src/aaf/store.rs
index 92c424af3..c89b143d8 100644
--- a/crates/interchange/src/aaf/store.rs
+++ b/crates/interchange/src/aaf/store.rs
@@ -162,7 +162,7 @@ pub(crate) fn utf16z(s: &str) -> Vec<u8> {
}
pub(crate) fn utf16_of(d: &[u8]) -> String {
- let u: Vec<u16> = d.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).take_while(|&c| c != 0).collect();
+ let u: Vec<u16> = d.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).take_while(|&c| c != 0).collect();
String::from_utf16_lossy(&u)
}
@@ -361,7 +361,7 @@ pub(crate) fn read(bytes: &[u8]) -> Result<Obj, String> {
{
let count = u16::from_le_bytes([rp[1], rp[2]]) as usize;
let mut cur = Vec::new();
- for c in rp[7..].chunks_exact(2) {
+ for c in rp[7..].as_chunks::<2>().0 {
let pid = u16::from_le_bytes([c[0], c[1]]);
if pid == 0 {
paths.push(std::mem::take(&mut cur));
diff --git a/crates/interchange/src/aaf/tests.rs b/crates/interchange/src/aaf/tests.rs
index 0e9adbcf1..84933fc04 100644
--- a/crates/interchange/src/aaf/tests.rs
+++ b/crates/interchange/src/aaf/tests.rs
@@ -238,7 +238,7 @@ fn written_files_have_the_required_structure() {
assert_eq!(a1[1].strong(pid::OPERATION_GROUP).unwrap().weak_key(pid::OPERATION), Some(&def::MONO_AUDIO_DISSOLVE[..]));
// weak reference paths are registered
let rp = cf.read_path("referenced properties").unwrap();
- let pids: Vec<u16> = rp[7..].chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect();
+ let pids: Vec<u16> = rp[7..].as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect();
assert!(pids.windows(3).any(|w| w == path::DATA_DEFS));
}
}
diff --git a/crates/interchange/src/omf/bento.rs b/crates/interchange/src/omf/bento.rs
index 3b1e37eec..d3a0a80d7 100644
--- a/crates/interchange/src/omf/bento.rs
+++ b/crates/interchange/src/omf/bento.rs
@@ -346,7 +346,7 @@ impl<'a> Container<'a> {
if let Some(p) = self.objects.get(&obj).and_then(|v| v.iter().find(|p| p.prop == OBJ_REFERENCES))
&& let Ok(v) = self.value(p)
{
- for pair in v.chunks_exact(8) {
+ for pair in v.as_chunks::<8>().0 {
if be32(pair, 0) == Some(key) {
return be32(pair, 4).unwrap_or(key);
}
diff --git a/crates/interchange/src/omf/read.rs b/crates/interchange/src/omf/read.rs
index 13bcb9556..f07cb4fb4 100644
--- a/crates/interchange/src/omf/read.rs
+++ b/crates/interchange/src/omf/read.rs
@@ -113,7 +113,7 @@ impl R<'_, '_> {
return Vec::new();
}
let n = u16::from_be_bytes([v[0], v[1]]) as usize;
- v[2..].chunks_exact(4).take(n).map(|k| self.c.resolve(o, u32::from_be_bytes([k[0], k[1], k[2], k[3]]))).collect()
+ v[2..].as_chunks::<4>().0.iter().take(n).map(|k| self.c.resolve(o, u32::from_be_bytes([k[0], k[1], k[2], k[3]]))).collect()
}
fn data_kind(&self, o: u32) -> String {
self.r#ref(o, "OMFI:CPNT:DataKind").and_then(|d| self.string(d, "OMFI:DDEF:DataKindID")).unwrap_or_default()
diff --git a/crates/interchange/src/omf/tests.rs b/crates/interchange/src/omf/tests.rs
index 0c80e018a..fb47e58f7 100644
--- a/crates/interchange/src/omf/tests.rs
+++ b/crates/interchange/src/omf/tests.rs
@@ -137,7 +137,7 @@ fn written_files_have_the_required_structure() {
let refs = |o: u32, p: &str| -> Vec<u32> {
let v = c.get(o, p).unwrap();
let n = u16::from_be_bytes([v[0], v[1]]) as usize;
- v[2..].chunks_exact(4).take(n).map(|k| c.resolve(o, u32::from_be_bytes([k[0], k[1], k[2], k[3]]))).collect()
+ v[2..].as_chunks::<4>().0.iter().take(n).map(|k| c.resolve(o, u32::from_be_bytes([k[0], k[1], k[2], k[3]]))).collect()
};
let one = |o: u32, p: &str| -> u32 { c.resolve(o, u32::from_be_bytes(c.get(o, p).unwrap()[..4].try_into().unwrap())) };
for m in refs(head, "OMFI:HEAD:Mobs") {
diff --git a/crates/isobmff/src/demux.rs b/crates/isobmff/src/demux.rs
index be70d2e03..b9b685ac0 100644
--- a/crates/isobmff/src/demux.rs
+++ b/crates/isobmff/src/demux.rs
@@ -449,7 +449,7 @@ fn parse_trak(p: &[u8], file: &Mp4File, file_len: u64) -> Result<Track> {
}
b"tref" => {
for r in boxes(b.payload).map_while(|b| b.ok()) {
- let ids = r.payload.chunks_exact(4).map(|c| u32::from_be_bytes([c[0], c[1], c[2], c[3]])).collect();
+ let ids = r.payload.as_chunks::<4>().0.iter().map(|c| u32::from_be_bytes([c[0], c[1], c[2], c[3]])).collect();
t.references.push((r.kind, ids));
}
}
diff --git a/crates/media/src/generators.rs b/crates/media/src/generators.rs
index 769b6f839..bbe9efbe2 100644
--- a/crates/media/src/generators.rs
+++ b/crates/media/src/generators.rs
@@ -293,9 +293,9 @@ pub fn render(g: &Generator, w: u32, h: u32, t: f32, frame: i64, rate: FrameRate
Generator::BarsAndTone => bars(&mut px, wu, hu),
Generator::ColorMatte { color } => {
let c = [(color[0] * 255.0) as u8, (color[1] * 255.0) as u8, (color[2] * 255.0) as u8, (color[3] * 255.0) as u8];
- px.chunks_exact_mut(4).for_each(|p| p.copy_from_slice(&c));
+ px.as_chunks_mut::<4>().0.iter_mut().for_each(|p| p.copy_from_slice(&c));
}
- Generator::BlackVideo => px.chunks_exact_mut(4).for_each(|p| p.copy_from_slice(&[0, 0, 0, 255])),
+ Generator::BlackVideo => px.as_chunks_mut::<4>().0.iter_mut().for_each(|p| p.copy_from_slice(&[0, 0, 0, 255])),
Generator::TransparentVideo | Generator::Tone { .. } => {}
Generator::CountingLeader => leader(&mut px, wu, hu, t, frame, rate),
Generator::Demo(scene) => {
@@ -573,7 +573,7 @@ mod tests {
fn all_scenes_render() {
for s in DemoScene::ALL {
let px = render(&Generator::Demo(s), 64, 36, 1.5, 36, FrameRate::FPS_24);
- assert!(px.chunks_exact(4).any(|p| p[0] > 20 || p[1] > 20 || p[2] > 20));
+ assert!(px.as_chunks::<4>().0.iter().any(|p| p[0] > 20 || p[1] > 20 || p[2] > 20));
}
let px = render(&Generator::CountingLeader, 64, 36, 1.5, 36, FrameRate::FPS_24);
assert_eq!(px.len(), 64 * 36 * 4);
diff --git a/crates/media/src/lib.rs b/crates/media/src/lib.rs
index 610495c84..3298adcd5 100644
--- a/crates/media/src/lib.rs
+++ b/crates/media/src/lib.rs
@@ -186,7 +186,7 @@ impl MediaSource for OfflineSource {
let s = req.scale.clamp(0.02, 1.0);
let (w, h) = (((v.width as f32 * s) as u32).max(2), ((v.height as f32 * s) as u32).max(2));
let mut px = vec![0u8; (w * h * 4) as usize];
- for p in px.chunks_exact_mut(4) {
+ for p in px.as_chunks_mut::<4>().0 {
p.copy_from_slice(&[140, 16, 16, 255]);
}
Ok(Arc::new(VideoFrame::rgba8(w, h, px).with_pts(req.time)))
diff --git a/crates/mpegts/src/ts.rs b/crates/mpegts/src/ts.rs
index d39b4cfba..48cdff0c2 100644
--- a/crates/mpegts/src/ts.rs
+++ b/crates/mpegts/src/ts.rs
@@ -283,7 +283,7 @@ pub(crate) fn scan<S: ByteSource + ?Sized>(src: &S, packet_size: usize, sync_off
continue;
}
let body = &sec[8..sec.len() - 4];
- for e in body.chunks_exact(4) {
+ for e in body.as_chunks::<4>().0 {
let num = u16::from_be_bytes([e[0], e[1]]);
let pid = (((e[2] & 0x1F) as u16) << 8) | e[3] as u16;
if num != 0 && pmt_pid.is_none() {
diff --git a/crates/mxf/src/klv.rs b/crates/mxf/src/klv.rs
index 76e31eeb7..fe32de3cf 100644
--- a/crates/mxf/src/klv.rs
+++ b/crates/mxf/src/klv.rs
@@ -221,7 +221,7 @@ pub fn batch_of(v: &[u8]) -> Vec<&[u8]> {
/// A UTF-16BE string property (trailing NULs removed).
pub fn utf16_of(v: &[u8]) -> String {
- let units: Vec<u16> = v.chunks_exact(2).map(|c| u16::from_be_bytes([c[0], c[1]])).take_while(|&u| u != 0).collect();
+ let units: Vec<u16> = v.as_chunks::<2>().0.iter().map(|c| u16::from_be_bytes([c[0], c[1]])).take_while(|&u| u != 0).collect();
String::from_utf16_lossy(&units)
}
diff --git a/crates/opus/src/celt/bands.rs b/crates/opus/src/celt/bands.rs
index 8d7f1604e..1e4131721 100644
--- a/crates/opus/src/celt/bands.rs
+++ b/crates/opus/src/celt/bands.rs
@@ -442,14 +442,13 @@ impl BandCtx<'_, '_, '_> {
x[..n].fill(0.0);
0
} else {
- let cm;
- match lowband {
+ let cm = match lowband {
None => {
for v in x[..n].iter_mut() {
self.seed = lcg_rand(self.seed);
*v = ((self.seed as i32) >> 20) as f32;
}
- cm = cm_mask;
+ cm_mask
}
Some(lb) => {
for j in 0..n {
@@ -457,9 +456,9 @@ impl BandCtx<'_, '_, '_> {
let tmp = if self.seed & 0x8000 != 0 { 1.0 / 256.0 } else { -1.0 / 256.0 };
x[j] = lb[j] + tmp;
}
- cm = fill;
+ fill
}
- }
+ };
renormalise_vector(&mut x[..n], gain);
cm
}
diff --git a/crates/opus/src/celt/rate.rs b/crates/opus/src/celt/rate.rs
index 12979f17c..bd398d617 100644
--- a/crates/opus/src/celt/rate.rs
+++ b/crates/opus/src/celt/rate.rs
@@ -216,9 +216,8 @@ fn compute_caps(m: &Mode) -> Vec<u8> {
for c in 1..=2i32 {
for j in 0..nb {
let mut n0 = EBANDS[j + 1] - EBANDS[j];
- let max_bits;
- if n0 << i == 1 {
- max_bits = c * (1 + MAX_FINE_BITS) << BITRES;
+ let max_bits = if n0 << i == 1 {
+ c * (1 + MAX_FINE_BITS) << BITRES
} else {
let mut lm0 = 0;
if n0 > 2 {
@@ -259,8 +258,8 @@ fn compute_caps(m: &Mode) -> Vec<u8> {
let den = (ndof - 1) << BITRES;
let qb = ((num + (den >> 1)) / den).min(MAX_FINE_BITS);
mb += c * qb << BITRES;
- max_bits = mb;
- }
+ mb
+ };
let w = c * ((EBANDS[j + 1] - EBANDS[j]) << i);
let v = (4 * max_bits / w) - 64;
caps[((i * 2 + c - 1) as usize) * nb + j] = v.clamp(0, 255) as u8;
diff --git a/crates/opus/tests/oracle.rs b/crates/opus/tests/oracle.rs
index 0c87e9ad6..0917479ed 100644
--- a/crates/opus/tests/oracle.rs
+++ b/crates/opus/tests/oracle.rs
@@ -65,7 +65,7 @@ fn run(case: &Case, rate: u32) -> (f64, f64, Vec<Mode>) {
.status()
.unwrap();
assert!(st.success());
- let reference: Vec<f32> = std::fs::read(&dec).unwrap().chunks_exact(4).map(|c| f32::from_le_bytes(c.try_into().unwrap())).collect();
+ let reference: Vec<f32> = std::fs::read(&dec).unwrap().as_chunks::<4>().0.iter().map(|c| f32::from_le_bytes(*c)).collect();
let (packets, granule) = common::ogg_packets(&std::fs::read(&opus).unwrap());
let mut d = Decoder::from_head(OpusHead::parse(&packets[0]).unwrap(), rate).unwrap();
diff --git a/crates/opus/tests/vectors.rs b/crates/opus/tests/vectors.rs
index b725dda05..e36529b7c 100644
--- a/crates/opus/tests/vectors.rs
+++ b/crates/opus/tests/vectors.rs
@@ -36,7 +36,7 @@ fn read_bit(path: &PathBuf) -> Vec<(Vec<u8>, u32)> {
}
fn read_pcm(path: &PathBuf) -> Vec<f32> {
- std::fs::read(path).unwrap().chunks_exact(2).map(|c| i16::from_le_bytes([c[0], c[1]]) as f32 / 32768.0).collect()
+ std::fs::read(path).unwrap().as_chunks::<2>().0.iter().map(|c| i16::from_le_bytes([c[0], c[1]]) as f32 / 32768.0).collect()
}
/// Decodes a vector; returns (interleaved output, index of first range mismatch).
@@ -75,7 +75,7 @@ fn rfc8251_test_vectors() {
let mut reference = read_pcm(&dir.join(format!("{name}{suffix}.dec")));
if channels == 1 {
// Mono output is compared against the downmix of the phase-inversion-free reference.
- reference = reference.chunks_exact(2).map(|c| 0.5 * (c[0] + c[1])).collect();
+ reference = reference.as_chunks::<2>().0.iter().map(|c| 0.5 * (c[0] + c[1])).collect();
}
let q = common::opus_quality(&reference, &out, channels, 48000);
let snr = common::snr_db(&reference, &out);
diff --git a/crates/project/src/mask.rs b/crates/project/src/mask.rs
index e1531a7c7..d2266b4d7 100644
--- a/crates/project/src/mask.rs
+++ b/crates/project/src/mask.rs
@@ -181,7 +181,12 @@ impl MaskPath {
/// Inverse of [`MaskPath::components`] (`closed` is taken from `self`).
pub fn with_components(&self, c: &[f64]) -> Self {
Self {
- vertices: c.chunks_exact(6).map(|k| MaskVertex { p: Vec2::new(k[0], k[1]), t_in: Vec2::new(k[2], k[3]), t_out: Vec2::new(k[4], k[5]) }).collect(),
+ vertices: c
+ .as_chunks::<6>()
+ .0
+ .iter()
+ .map(|k| MaskVertex { p: Vec2::new(k[0], k[1]), t_in: Vec2::new(k[2], k[3]), t_out: Vec2::new(k[4], k[5]) })
+ .collect(),
closed: self.closed,
}
}
diff --git a/crates/prores/tests/common/mod.rs b/crates/prores/tests/common/mod.rs
index 9b3192aa0..dafdf86c8 100644
--- a/crates/prores/tests/common/mod.rs
+++ b/crates/prores/tests/common/mod.rs
@@ -85,7 +85,7 @@ pub fn reference(ff: &Path, mov: &Path, pix_fmt: &str) -> Vec<u16> {
.output()
.expect("run ffmpeg");
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
- out.stdout.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect()
+ out.stdout.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect()
}
/// Number of u16 samples per frame of a raw planar image.
@@ -242,7 +242,7 @@ pub fn ffmpeg_decode(ff: &Path, mov: &Path, pix_fmt: &str) -> (Vec<u16>, String)
.expect("run ffmpeg");
let err = String::from_utf8_lossy(&out.stderr).to_string();
assert!(out.status.success(), "ffmpeg failed: {err}");
- (out.stdout.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect(), err)
+ (out.stdout.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect(), err)
}
/// Render a lavfi source to raw 10-bit planar frames with ffmpeg and load them as [`Frame`]s.
@@ -260,7 +260,7 @@ pub fn source_frames(ff: &Path, name: &str, lavfi: &str, frames: u32, w: u32, h:
std::fs::rename(&tmp, &path).unwrap();
}
let bytes = std::fs::read(&path).unwrap();
- let s: Vec<u16> = bytes.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect();
+ let s: Vec<u16> = bytes.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes([c[0], c[1]])).collect();
let (w, h) = (w as usize, h as usize);
let per = frame_samples(w, h, chroma, alpha);
assert_eq!(s.len(), per * frames as usize);
diff --git a/crates/render/src/color_match.rs b/crates/render/src/color_match.rs
index 009d5ca36..6d2c98b1e 100644
--- a/crates/render/src/color_match.rs
+++ b/crates/render/src/color_match.rs
@@ -88,7 +88,7 @@ pub fn stats(img: &Image, skin_protect: bool) -> Stats {
let mut acc = [[0f64; 4]; 3];
let mut chroma = (0f64, 0f64);
let mut skin = [0f64; 3];
- for p in img.px.chunks_exact(4) {
+ for p in img.px.as_chunks::<4>().0 {
if p[3] <= 1e-3 {
continue;
}
@@ -112,7 +112,7 @@ pub fn stats(img: &Image, skin_protect: bool) -> Stats {
}
// colour weights per band for normalisation
let mut cwsum = [0f64; 3];
- for p in img.px.chunks_exact(4) {
+ for p in img.px.as_chunks::<4>().0 {
if p[3] <= 1e-3 {
continue;
}
diff --git a/crates/render/src/graphic_clip.rs b/crates/render/src/graphic_clip.rs
index 94caf930b..88c84765c 100644
--- a/crates/render/src/graphic_clip.rs
+++ b/crates/render/src/graphic_clip.rs
@@ -179,7 +179,7 @@ fn over_mask(px: &mut [f32], m: &Mask, c: [f32; 4]) {
return;
}
px.par_chunks_mut(4 * m.w).zip(m.a.par_chunks(m.w)).for_each(|(row, mrow)| {
- for (p, &a) in row.chunks_exact_mut(4).zip(mrow) {
+ for (p, &a) in row.as_chunks_mut::<4>().0.iter_mut().zip(mrow) {
if a > 0.0 {
let k = 1.0 - c[3] * a;
for i in 0..4 {
diff --git a/crates/render/src/image.rs b/crates/render/src/image.rs
index 7c525c4f9..c30808c52 100644
--- a/crates/render/src/image.rs
+++ b/crates/render/src/image.rs
@@ -188,7 +188,7 @@ impl Image {
pub fn over_black_rgba8(&self) -> Vec<u8> {
let mut out = vec![0u8; self.w * self.h * 4];
out.par_chunks_mut(self.w * 4).zip(self.px.par_chunks(self.w * 4)).for_each(|(o, s)| {
- for (o, s) in o.chunks_exact_mut(4).zip(s.chunks_exact(4)) {
+ for (o, s) in o.as_chunks_mut::<4>().0.iter_mut().zip(s.as_chunks::<4>().0) {
o[0] = filmcraft_color::linear_to_srgb_u8(s[0]);
o[1] = filmcraft_color::linear_to_srgb_u8(s[1]);
o[2] = filmcraft_color::linear_to_srgb_u8(s[2]);
diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs
index cad220a38..f21573a47 100644
--- a/crates/render/src/lib.rs
+++ b/crates/render/src/lib.rs
@@ -162,7 +162,7 @@ pub(crate) fn render_seq_tracks(project: &Project, seq: &Sequence, t: Tick, opts
mask::apply_opacity_masks(&mut adj, item, mt, opts.scale);
// Motion moves / scales the adjustment layer's frame: it only applies inside it.
if let Some(region) = adjustment_region(seq, item, project, mt, opts.scale, w, h) {
- let cov: Vec<f32> = region.px.chunks_exact(4).map(|p| p[3]).collect();
+ let cov: Vec<f32> = region.px.as_chunks::<4>().0.iter().map(|p| p[3]).collect();
mask::scale_by(&mut adj, &cov);
}
blend::composite(&mut out, &adj, 1.0, bl);
diff --git a/crates/render/src/track.rs b/crates/render/src/track.rs
index c73dda8e8..bb328e438 100644
--- a/crates/render/src/track.rs
+++ b/crates/render/src/track.rs
@@ -47,7 +47,7 @@ impl Gray {
}
/// Luma of 8-bit RGBA (Rec. 709 weights on the encoded values).
pub fn from_rgba8(w: usize, h: usize, rgba: &[u8]) -> Self {
- let px = rgba.chunks_exact(4).map(|p| (0.2126 * p[0] as f32 + 0.7152 * p[1] as f32 + 0.0722 * p[2] as f32) / 255.0).collect();
+ let px = rgba.as_chunks::<4>().0.iter().map(|p| (0.2126 * p[0] as f32 + 0.7152 * p[1] as f32 + 0.0722 * p[2] as f32) / 255.0).collect();
Self { w, h, px }
}
#[inline]
diff --git a/crates/render/src/vfx/blur.rs b/crates/render/src/vfx/blur.rs
index f55cb37d1..37aaaaa5b 100644
--- a/crates/render/src/vfx/blur.rs
+++ b/crates/render/src/vfx/blur.rs
@@ -85,7 +85,7 @@ fn blur_channel(img: &mut Image, ch: usize, sx: f32, sy: f32, repeat: bool) {
if sx <= 0.3 && sy <= 0.3 {
return;
}
- let mut plane = Image { w: img.w, h: img.h, px: img.px.chunks_exact(4).flat_map(|p| [p[ch], 0.0, 0.0, 0.0]).collect() };
+ let mut plane = Image { w: img.w, h: img.h, px: img.px.as_chunks::<4>().0.iter().flat_map(|p| [p[ch], 0.0, 0.0, 0.0]).collect() };
gaussian(&mut plane, sx, sy, repeat);
img.px.par_chunks_mut(4).zip(plane.px.par_chunks(4)).for_each(|(p, q)| p[ch] = q[0]);
}
diff --git a/crates/render/src/vfx/mod.rs b/crates/render/src/vfx/mod.rs
index 7b0619073..09774a1b1 100644
--- a/crates/render/src/vfx/mod.rs
+++ b/crates/render/src/vfx/mod.rs
@@ -374,7 +374,7 @@ pub(crate) fn blur_plane(plane: &[f32], w: usize, h: usize, sigma: f32) -> Vec<f
}
let mut im = Image { w, h, px: plane.iter().flat_map(|&v| [v, 0.0, 0.0, 0.0]).collect() };
crate::effects::gaussian(&mut im, sigma, sigma, false);
- im.px.chunks_exact(4).map(|p| p[0]).collect()
+ im.px.as_chunks::<4>().0.iter().map(|p| p[0]).collect()
}
/// Bright parts of an image above `threshold` (display luma), premultiplied linear, for glows.
diff --git a/crates/render/src/vfx/tests.rs b/crates/render/src/vfx/tests.rs
index e7c533442..6a00196d8 100644
--- a/crates/render/src/vfx/tests.rs
+++ b/crates/render/src/vfx/tests.rs
@@ -182,7 +182,7 @@ fn every_effect_is_finite_in_range_and_deterministic() {
let b = run(id, &e, &img, &c);
assert_eq!(a.px, b.px, "{id} not deterministic");
assert_eq!((a.w, a.h), (img.w, img.h), "{id} changed size");
- for p in a.px.chunks_exact(4) {
+ for p in a.px.as_chunks::<4>().0 {
assert!(p.iter().all(|v| v.is_finite()), "{id}: {p:?}");
assert!(p[3] >= -1e-4 && p[3] <= 1.0 + 1e-3, "{id}: alpha {}", p[3]);
assert!(p[..3].iter().all(|v| *v >= -1e-3), "{id}: negative {p:?}");
@@ -550,7 +550,7 @@ fn lights_add_light_around_highlights() {
img.px[(y * 48 + x) * 4..(y * 48 + x) * 4 + 4].copy_from_slice(&[1.0, 1.0, 1.0, 1.0]);
}
}
- let total = |i: &Image| i.px.chunks_exact(4).map(|p| p[0] as f64).sum::<f64>();
+ let total = |i: &Image| i.px.as_chunks::<4>().0.iter().map(|p| p[0] as f64).sum::<f64>();
for id in ["echo_glow", "glint", "wonder_glow", "volumetric_rays", "edge_glow"] {
let o = run(id, &inst(id), &img, &cx());
let added = total(&o) - total(&img);
@@ -628,7 +628,7 @@ fn generators_known_values() {
assert!(o.get(28, 10)[3] > 0.8 && o.get(20, 10)[3] < 0.01, "{:?} {:?}", o.get(28, 10), o.get(20, 10));
// Cell Pattern is opaque grey in 0..1
let o = run("cell_pattern", &inst("cell_pattern"), &img, &cx());
- assert!(o.px.chunks_exact(4).all(|p| p[3] == 1.0 && p[0] >= 0.0 && p[0] <= 1.0 && p[0] == p[1]));
+ assert!(o.px.as_chunks::<4>().0.iter().all(|p| p[3] == 1.0 && p[0] >= 0.0 && p[0] <= 1.0 && p[0] == p[1]));
// Lightning: deterministic per seed, different across seeds and strikes
let a = run("lightning", &inst("lightning"), &img, &cx());
let mut e = inst("lightning");
@@ -1015,7 +1015,7 @@ fn warp_stabilizer_removes_camera_jitter() {
let env = mk(9.0 / 24.0);
let mut st = env.render(9.0 / 24.0, 1.0);
crate::effects::apply(&mut st, &e, &FxCtx { seconds: 9.0 / 24.0, env: Some(&env), ..cx() });
- assert!(st.px.chunks_exact(4).all(|p| p[3] > 0.99), "auto-scale leaves no border");
+ assert!(st.px.as_chunks::<4>().0.iter().all(|p| p[3] > 0.99), "auto-scale leaves no border");
// the path cache is reused
assert!(stabilizer_path(&env, 0.0, filmcraft_project::TrackMethod::Position, false).is_some());
}
diff --git a/crates/scopes/src/paint.rs b/crates/scopes/src/paint.rs
index 0cd3d5c08..871a777a5 100644
--- a/crates/scopes/src/paint.rs
+++ b/crates/scopes/src/paint.rs
@@ -43,7 +43,7 @@ pub fn grids(layers: &[(&Grid, [f32; 3])], reference: f32, gain: f32) -> (usize,
}
}
}
- for (o, a) in out.chunks_exact_mut(4).zip(&acc) {
+ for (o, a) in out.as_chunks_mut::<4>().0.iter_mut().zip(&acc) {
let m = a[0].max(a[1]).max(a[2]);
if m <= 0.0 {
continue;
@@ -101,7 +101,7 @@ pub fn vectorscope(v: &Vectorscope, col: [f32; 3], gain: f32, colorize: bool) ->
}
}
let mut out = vec![0u8; n * n * 4];
- for ((o, l), t) in out.chunks_exact_mut(4).zip(&level).zip(&tint) {
+ for ((o, l), t) in out.as_chunks_mut::<4>().0.iter_mut().zip(&level).zip(&tint) {
if *l > 0.0 {
o.copy_from_slice(&[
(t[0] * l * 255.0).round() as u8,
diff --git a/crates/scopes/src/tests.rs b/crates/scopes/src/tests.rs
index 34a2716bc..02da184a6 100644
--- a/crates/scopes/src/tests.rs
+++ b/crates/scopes/src/tests.rs
@@ -260,7 +260,7 @@ fn paint_adds_traces_and_leaves_empty_cells_transparent() {
let (n, _, vp) = paint::vectorscope(&v, [1.0; 3], 1.0, true);
assert_eq!(vp.len(), n * n * 4);
// seven spots of 3 × 3 texels each (none touch)
- assert_eq!(vp.chunks_exact(4).filter(|p| p[3] > 0).count(), 7 * 9);
+ assert_eq!(vp.as_chunks::<4>().0.iter().filter(|p| p[3] > 0).count(), 7 * 9);
}
#[test]
diff --git a/crates/speech/examples/transcribe.rs b/crates/speech/examples/transcribe.rs
index 8d7beaa67..f56118b23 100644
--- a/crates/speech/examples/transcribe.rs
+++ b/crates/speech/examples/transcribe.rs
@@ -24,7 +24,7 @@ fn main() {
"--diarize" => diarize = true,
l if l.starts_with("--lang=") => language = Some(l[7..].to_string()),
p => {
- let audio: Vec<f32> = std::fs::read(p).expect("read").chunks_exact(4).map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect();
+ let audio: Vec<f32> = std::fs::read(p).expect("read").as_chunks::<4>().0.iter().map(|b| f32::from_le_bytes(*b)).collect();
let t1 = std::time::Instant::now();
let opts = Options { language: language.clone(), diarize, ..Default::default() };
let t = w.transcribe(&audio, &opts, &mut |_, _| true).expect("transcribe");
diff --git a/crates/speech/tests/whisper_model.rs b/crates/speech/tests/whisper_model.rs
index d2fbd8ea8..c806fcbea 100644
--- a/crates/speech/tests/whisper_model.rs
+++ b/crates/speech/tests/whisper_model.rs
@@ -58,7 +58,7 @@ fn samples() -> Vec<(PathBuf, String)> {
}
fn read_f32(p: &Path) -> Vec<f32> {
- std::fs::read(p).unwrap().chunks_exact(4).map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()
+ std::fs::read(p).unwrap().as_chunks::<4>().0.iter().map(|b| f32::from_le_bytes(*b)).collect()
}
#[test]
diff --git a/crates/testkit/src/golden.rs b/crates/testkit/src/golden.rs
index d79fbad02..922d4facb 100644
--- a/crates/testkit/src/golden.rs
+++ b/crates/testkit/src/golden.rs
@@ -32,7 +32,7 @@ impl Rgba8 {
[self.px[i], self.px[i + 1], self.px[i + 2], self.px[i + 3]]
}
fn opaque(&self) -> bool {
- self.px.chunks_exact(4).all(|p| p[3] == 255)
+ self.px.as_chunks::<4>().0.iter().all(|p| p[3] == 255)
}
}
@@ -47,7 +47,7 @@ pub fn encode_png(img: &Rgba8) -> Result<Vec<u8>, String> {
enc.set_compression(png::Compression::High);
let mut w = enc.write_header().map_err(|e| e.to_string())?;
if opaque {
- let rgb: Vec<u8> = img.px.chunks_exact(4).flat_map(|p| [p[0], p[1], p[2]]).collect();
+ let rgb: Vec<u8> = img.px.as_chunks::<4>().0.iter().flat_map(|p| [p[0], p[1], p[2]]).collect();
w.write_image_data(&rgb).map_err(|e| e.to_string())?;
} else {
w.write_image_data(&img.px).map_err(|e| e.to_string())?;
@@ -68,8 +68,8 @@ pub fn decode_png(bytes: &[u8]) -> Result<Rgba8, String> {
let n = w as usize * h as usize;
let px = match info.color_type {
png::ColorType::Rgba => buf[..n * 4].to_vec(),
- png::ColorType::Rgb => buf[..n * 3].chunks_exact(3).flat_map(|p| [p[0], p[1], p[2], 255]).collect(),
- png::ColorType::GrayscaleAlpha => buf[..n * 2].chunks_exact(2).flat_map(|p| [p[0], p[0], p[0], p[1]]).collect(),
+ png::ColorType::Rgb => buf[..n * 3].as_chunks::<3>().0.iter().flat_map(|p| [p[0], p[1], p[2], 255]).collect(),
+ png::ColorType::GrayscaleAlpha => buf[..n * 2].as_chunks::<2>().0.iter().flat_map(|p| [p[0], p[0], p[0], p[1]]).collect(),
png::ColorType::Grayscale => buf[..n].iter().flat_map(|&g| [g, g, g, 255]).collect(),
png::ColorType::Indexed => return Err("unexpanded palette PNG".into()),
};
@@ -118,7 +118,7 @@ pub fn diff(a: &Rgba8, b: &Rgba8) -> Result<Diff, String> {
}
let mut hist = [0usize; 256];
let (mut sum, mut sq, mut max, mut differing) = (0u64, 0u64, 0u8, 0usize);
- for (p, q) in a.px.chunks_exact(4).zip(b.px.chunks_exact(4)) {
+ for (p, q) in a.px.as_chunks::<4>().0.iter().zip(b.px.as_chunks::<4>().0) {
let mut m = 0u8;
for k in 0..4 {
let d = p[k].abs_diff(q[k]);
@@ -180,8 +180,10 @@ pub fn failures_dir() -> PathBuf {
/// Difference image: |a − b| per channel ×8, opaque.
pub fn diff_image(a: &Rgba8, b: &Rgba8) -> Rgba8 {
let px =
- a.px.chunks_exact(4)
- .zip(b.px.chunks_exact(4))
+ a.px.as_chunks::<4>()
+ .0
+ .iter()
+ .zip(b.px.as_chunks::<4>().0)
.flat_map(|(p, q)| {
let d = |k: usize| (p[k].abs_diff(q[k]) as u32 * 8).min(255) as u8;
let al = d(3);
diff --git a/crates/text/src/sfnt.rs b/crates/text/src/sfnt.rs
index bb00d515f..156dd52a6 100644
--- a/crates/text/src/sfnt.rs
+++ b/crates/text/src/sfnt.rs
@@ -102,11 +102,11 @@ fn name_string(b: &[u8], id: u16) -> Option<String> {
let raw = b.get(storage + off..storage + off + len)?;
let (rank, s) = match plat {
3 if enc == 1 || enc == 10 => {
- let u: Vec<u16> = raw.chunks_exact(2).map(|c| u16::from_be_bytes([c[0], c[1]])).collect();
+ let u: Vec<u16> = raw.as_chunks::<2>().0.iter().map(|c| u16::from_be_bytes([c[0], c[1]])).collect();
(if lang == 0x409 { 0 } else { 1 }, String::from_utf16_lossy(&u))
}
0 => {
- let u: Vec<u16> = raw.chunks_exact(2).map(|c| u16::from_be_bytes([c[0], c[1]])).collect();
+ let u: Vec<u16> = raw.as_chunks::<2>().0.iter().map(|c| u16::from_be_bytes([c[0], c[1]])).collect();
(2, String::from_utf16_lossy(&u))
}
1 if enc == 0 => (3, raw.iter().map(|&c| if c < 128 { c as char } else { '?' }).collect()),
diff --git a/crates/ui-egui/src/panels/monitor_view.rs b/crates/ui-egui/src/panels/monitor_view.rs
index 8b6ca8175..cf33d04ec 100644
--- a/crates/ui-egui/src/panels/monitor_view.rs
+++ b/crates/ui-egui/src/panels/monitor_view.rs
@@ -313,7 +313,7 @@ pub fn enabled(app: &FilmcraftApp, id: &str) -> bool {
/// shown premultiplied, so transparent areas are black.
pub fn channel_view(img: &Rgba, mode: DisplayMode) -> Rgba {
let mut px = Vec::with_capacity(img.px.len());
- for p in img.px.chunks_exact(4) {
+ for p in img.px.as_chunks::<4>().0 {
let a = p[3] as u32;
let v = match mode {
DisplayMode::Alpha => p[3],