FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Refactor prores for strict Clippy checks
Dylan M. Taylorac06ed16b702
diff --git a/crates/prores/src/decode.rs b/crates/prores/src/decode.rsindex 60318d848..4e2a5b339 100644--- a/crates/prores/src/decode.rs+++ b/crates/prores/src/decode.rs@@ -3,7 +3,7 @@use crate::bits::Reader;use crate::dct::idct8x8;use crate::header::{FrameHeader, PictureHeader, row_slice_widths};-use crate::tables::*;+use crate::tables::{DC_CB, DC_CTX_INIT, FIRST_DC_CB, LEVEL_CB, LEVEL_CTX_INIT, RUN_CB, RUN_CTX_INIT, SCAN_INTERLACED, SCAN_PROGRESSIVE, qscale};use crate::{AlphaType, ChromaFormat, Error, Frame, Interlace, Result};/// Maximum aggregate decoded plane storage for one ProRes frame (256 MiB).@@ -219,7 +219,8 @@ pub fn decode_frame_into(data: &[u8], opts: &DecodeOptions, out: &mut Frame) ->for (k, &w) in widths.iter().enumerate() {let si = row * widths.len() + k;let (start, len) = pic.slices[si];- decode_slice(&ctx, &data[start..start + len], mb_x, w, band, step, pic.parity, scratch).map_err(|_| Error::Slice { picture: pi, slice: si })?;+ decode_slice(&ctx, &data[start..start + len], mb_x, w, band, Lines { step, parity: pic.parity }, scratch)+ .map_err(|_| Error::Slice { picture: pi, slice: si })?;mb_x += w;}}@@ -272,8 +273,15 @@ fn qfactors(qmat: &[u8; 64], qs: u32) -> [f32; 64] {q}-#[allow(clippy::too_many_arguments)]-fn decode_slice(ctx: &Ctx, d: &[u8], mb_x: usize, mbs: usize, band: &mut Band, step: usize, parity: usize, s: &mut Scratch) -> std::result::Result<(), ()> {+/// Line stepping of the picture inside its frame: `step` is 2 for field pictures, `parity` the first line.+#[derive(Clone, Copy)]+struct Lines {+ step: usize,+ parity: usize,+}++fn decode_slice(ctx: &Ctx, d: &[u8], mb_x: usize, mbs: usize, band: &mut Band, il: Lines, s: &mut Scratch) -> std::result::Result<(), ()> {+ let Lines { step, parity } = il;if d.len() < 6 {return Err(());}@@ -309,7 +317,7 @@ fn decode_slice(ctx: &Ctx, d: &[u8], mb_x: usize, mbs: usize, band: &mut Band, sfor (b, blk) in s.coeffs[..nb].iter_mut().enumerate() {idct8x8(blk);let (mb, i) = (b >> 2, b & 3);- put_block(blk, band.y, ctx.width, x0 + mb * 16 + (i & 1) * 8, (i >> 1) * 8, band.rows, step, parity, ctx.conv);+ put_block(blk, band.y, ctx.width, (x0 + mb * 16 + (i & 1) * 8, (i >> 1) * 8), band.rows, il, ctx.conv);}// Chroma@@ -327,7 +335,7 @@ fn decode_slice(ctx: &Ctx, d: &[u8], mb_x: usize, mbs: usize, band: &mut Band, slet (mb, i) = (b >> 1, b & 1);(mb_x * 8 + mb * 8, i * 8)};- put_block(blk, plane, ctx.cwidth, bx, by, band.rows, step, parity, ctx.conv);+ put_block(blk, plane, ctx.cwidth, (bx, by), band.rows, il, ctx.conv);}}@@ -479,9 +487,9 @@ fn decode_alpha(data: &[u8], ty: AlphaType, out: &mut [u16]) -> std::result::ResOk(())}-#[allow(clippy::too_many_arguments)]#[inline]-fn put_block(f: &[f32; 64], plane: &mut [u16], stride: usize, x0: usize, y0: usize, rows: usize, step: usize, parity: usize, conv: OutConv) {+fn put_block(f: &[f32; 64], plane: &mut [u16], stride: usize, (x0, y0): (usize, usize), rows: usize, il: Lines, conv: OutConv) {+ let Lines { step, parity } = il;if x0 >= stride {return;}diff --git a/crates/prores/src/encode.rs b/crates/prores/src/encode.rsindex 24c925393..6307994d5 100644--- a/crates/prores/src/encode.rs+++ b/crates/prores/src/encode.rs@@ -3,7 +3,7 @@use crate::bits::{Counter, Sink, Writer};use crate::dct::fdct8x8;use crate::header::{FRAME_ID, FrameHeader, PictureHeader, row_slice_widths};-use crate::tables::*;+use crate::tables::{DC_CB, DC_CTX_INIT, FIRST_DC_CB, LEVEL_CB, LEVEL_CTX_INIT, RUN_CB, RUN_CTX_INIT, SCAN_PROGRESSIVE, qscale};use crate::{AlphaType, ChromaFormat, ColorInfo, Error, Frame, Interlace, Profile, Result};/// Encoder configuration.diff --git a/crates/prores/tests/it/common/mod.rs b/crates/prores/tests/it/common/mod.rsindex dafdf86c8..c31245537 100644--- a/crates/prores/tests/it/common/mod.rs+++ b/crates/prores/tests/it/common/mod.rs@@ -246,7 +246,18 @@ pub fn ffmpeg_decode(ff: &Path, mov: &Path, pix_fmt: &str) -> (Vec<u16>, String)}/// Render a lavfi source to raw 10-bit planar frames with ffmpeg and load them as [`Frame`]s.-pub fn source_frames(ff: &Path, name: &str, lavfi: &str, frames: u32, w: u32, h: u32, chroma: ChromaFormat, alpha: bool) -> Vec<Frame> {+pub struct SourceFrameSpec<'a> {+ pub name: &'a str,+ pub lavfi: &'a str,+ pub frames: u32,+ pub width: u32,+ pub height: u32,+ pub chroma: ChromaFormat,+ pub alpha: bool,+}++pub fn source_frames(ff: &Path, spec: SourceFrameSpec<'_>) -> Vec<Frame> {+ let SourceFrameSpec { name, lavfi, frames, width, height, chroma, alpha } = spec;let path = fixture_dir().join(format!("{name}.raw"));if !path.exists() {let pix = match (chroma, alpha) {@@ -261,7 +272,7 @@ pub fn source_frames(ff: &Path, name: &str, lavfi: &str, frames: u32, w: u32, h:}let bytes = std::fs::read(&path).unwrap();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 (w, h) = (width as usize, height as usize);let per = frame_samples(w, h, chroma, alpha);assert_eq!(s.len(), per * frames as usize);s.chunks_exact(per).map(|p| frame_from_raw(p, w as u32, h as u32, chroma, 10, alpha)).collect()diff --git a/crates/prores/tests/it/oracle_encode.rs b/crates/prores/tests/it/oracle_encode.rsindex 5fd9adc9f..2834a3489 100644--- a/crates/prores/tests/it/oracle_encode.rs+++ b/crates/prores/tests/it/oracle_encode.rs@@ -52,7 +52,7 @@ fn encoder_output_decodes_in_ffmpeg() {let chroma = profile.chroma();for c in contents(chroma) {let alpha = chroma == ChromaFormat::Yuv444;- let src = source_frames(&ff, c.name, c.lavfi, 2, W, H, chroma, alpha);+ let src = source_frames(&ff, SourceFrameSpec { name: c.name, lavfi: c.lavfi, frames: 2, width: W, height: H, chroma, alpha });let mut enc = Encoder::new(profile, W, H);let coded: Vec<Vec<u8>> = src.iter().map(|f| enc.encode(f).unwrap()).collect();let target = enc.target_frame_bytes() as f64;@@ -124,7 +124,7 @@ fn odd_geometry_encodes() {format!("mandelbrot=s={w}x{h}:r=25")};let name = format!("src_odd_{w}x{h}");- let src = source_frames(&ff, Box::leak(name.into_boxed_str()), &lav, 1, w, h, chroma, alpha);+ let src = source_frames(&ff, SourceFrameSpec { name: &name, lavfi: &lav, frames: 1, width: w, height: h, chroma, alpha });let mut enc = Encoder::new(profile, w, h);let coded = vec![enc.encode(&src[0]).unwrap()];let mov = fixture_dir().join(format!("enc_odd_{w}x{h}.mov"));