mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-26 18:27:42 +00:00
media: switch non-fallback AUDIO_EXTENSIONS and convert tests to craft-libs (#4020)
* media: switch non-fallback AUDIO_EXTENSIONS and convert tests to craft-libs * media: accept FrameView in frame_to_image
This commit is contained in:
+15
-19
@@ -137,7 +137,7 @@ impl<'a> From<&'a crate::stream::DecodedFrame> for FrameView<'a> {
|
||||
|
||||
/// Convert a FilmCraft frame to an [`Image`].
|
||||
#[cfg(test)]
|
||||
pub(crate) fn frame_to_image(f: &VideoFrame, op: AlphaOp) -> Image {
|
||||
pub(crate) fn frame_to_image<'a>(f: impl Into<FrameView<'a>>, op: AlphaOp) -> Image {
|
||||
frame_to_image_in(f, op, Vec::new())
|
||||
}
|
||||
|
||||
@@ -533,25 +533,28 @@ pub(crate) fn straight_to_image(w: u32, h: u32, px: &[[f32; 4]], op: AlphaOp) ->
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use craft_color::ColorInfo;
|
||||
use craft_frame::{Chroma, PixelData, VideoFrame};
|
||||
use craft_time::Tick;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn yuv_frame(y: u8, u: u8, v: u8, color: filmcraft_color::ColorInfo) -> VideoFrame {
|
||||
fn yuv_frame(y: u8, u: u8, v: u8, color: ColorInfo) -> VideoFrame {
|
||||
VideoFrame {
|
||||
width: 4,
|
||||
height: 2,
|
||||
data: PixelData::Yuv8 { planes: [Arc::new(vec![y; 8]), Arc::new(vec![u; 2]), Arc::new(vec![v; 2])], chroma: Chroma::C420, alpha: None },
|
||||
color,
|
||||
par: (1, 1),
|
||||
pts: filmcraft_time::Tick::ZERO,
|
||||
pts: Tick::ZERO,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn limited_range_grey_and_white() {
|
||||
let op = AlphaOp::new(AlphaMode::Straight, [0.0; 3]);
|
||||
let img = frame_to_image(&yuv_frame(235, 128, 128, filmcraft_color::ColorInfo::REC709), op);
|
||||
let img = frame_to_image(&yuv_frame(235, 128, 128, ColorInfo::REC709), op);
|
||||
assert!(img.data.iter().all(|p| (p[0] - 1.0).abs() < 1e-5 && (p[1] - 1.0).abs() < 1e-5 && p[3] == 1.0));
|
||||
let img = frame_to_image(&yuv_frame(126, 128, 128, filmcraft_color::ColorInfo::REC709), op);
|
||||
let img = frame_to_image(&yuv_frame(126, 128, 128, ColorInfo::REC709), op);
|
||||
assert!((img.data[0][0] - 110.0 / 219.0).abs() < 1e-5);
|
||||
}
|
||||
|
||||
@@ -568,9 +571,9 @@ mod tests {
|
||||
chroma: Chroma::C420,
|
||||
alpha: None,
|
||||
},
|
||||
color: filmcraft_color::ColorInfo::REC709,
|
||||
color: ColorInfo::REC709,
|
||||
par: (1, 1),
|
||||
pts: filmcraft_time::Tick::ZERO,
|
||||
pts: Tick::ZERO,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,7 +591,7 @@ mod tests {
|
||||
// More than half the size, odd sizes, other chroma layouts: convert the full frame.
|
||||
assert!(frame_to_image_scaled(&f, 49, 32).is_none());
|
||||
assert!(frame_to_image_scaled(&smooth_420(95, 64), 40, 30).is_none());
|
||||
assert!(frame_to_image_scaled(&yuv_frame(100, 128, 128, filmcraft_color::ColorInfo::REC709), 2, 1).is_some());
|
||||
assert!(frame_to_image_scaled(&yuv_frame(100, 128, 128, ColorInfo::REC709), 2, 1).is_some());
|
||||
let mut f444 = smooth_420(96, 64);
|
||||
if let PixelData::Yuv8 { chroma, .. } = &mut f444.data {
|
||||
*chroma = Chroma::C444;
|
||||
@@ -600,7 +603,7 @@ mod tests {
|
||||
fn bt709_red() {
|
||||
// 8-bit limited BT.709 red: Y 63, Cb 102, Cr 240
|
||||
let op = AlphaOp::new(AlphaMode::Straight, [0.0; 3]);
|
||||
let p = frame_to_image(&yuv_frame(63, 102, 240, filmcraft_color::ColorInfo::REC709), op).data[0];
|
||||
let p = frame_to_image(&yuv_frame(63, 102, 240, ColorInfo::REC709), op).data[0];
|
||||
assert!(p[0] > 0.98 && p[1] < 0.02 && p[2] < 0.02, "{p:?}");
|
||||
}
|
||||
|
||||
@@ -631,14 +634,7 @@ mod tests {
|
||||
fn rgba8_levels_are_the_quantised_float_frame() {
|
||||
let (w, h) = (37usize, 18usize);
|
||||
let noise = |n: usize, seed: usize| Arc::new((0..n).map(|i| ((i * 7919 + seed * 104_729) % 256) as u8).collect::<Vec<u8>>());
|
||||
let frame = |data| VideoFrame {
|
||||
width: w as u32,
|
||||
height: h as u32,
|
||||
data,
|
||||
color: filmcraft_color::ColorInfo::REC709,
|
||||
par: (1, 1),
|
||||
pts: filmcraft_time::Tick::ZERO,
|
||||
};
|
||||
let frame = |data| VideoFrame { width: w as u32, height: h as u32, data, color: ColorInfo::REC709, par: (1, 1), pts: Tick::ZERO };
|
||||
let yuv = |chroma: Chroma, alpha: bool| {
|
||||
let n = w.div_ceil(1 << chroma.shifts().0) * h.div_ceil(1 << chroma.shifts().1);
|
||||
frame(PixelData::Yuv8 { planes: [noise(w * h, 1), noise(n, 2), noise(n, 3)], chroma, alpha: alpha.then(|| noise(w * h, 4)) })
|
||||
@@ -675,9 +671,9 @@ mod tests {
|
||||
chroma: Chroma::C420,
|
||||
alpha: None,
|
||||
},
|
||||
color: filmcraft_color::ColorInfo::REC709,
|
||||
color: ColorInfo::REC709,
|
||||
par: (1, 1),
|
||||
pts: filmcraft_time::Tick::ZERO,
|
||||
pts: Tick::ZERO,
|
||||
};
|
||||
let op = AlphaOp::new(AlphaMode::Straight, [0.0; 3]);
|
||||
for _ in 0..3 {
|
||||
|
||||
@@ -84,7 +84,7 @@ impl From<craft_media_source::MediaError> for MediaError {
|
||||
pub const STILL_EXTENSIONS: &[&str] =
|
||||
&["png", "jpg", "jpeg", "gif", "webp", "tif", "tiff", "bmp", "exr", "tga", "hdr", "psd", "psb", "svg", "pdf", "ai", "eps", "vectorcraft"];
|
||||
/// File extensions recognised as audio-only files.
|
||||
pub const AUDIO_EXTENSIONS: &[&str] = filmcraft_media::AUDIO_EXTENSIONS;
|
||||
pub const AUDIO_EXTENSIONS: &[&str] = craft_media_source::AUDIO_EXTENSIONS;
|
||||
pub use effectcraft_project::VIDEO_EXTENSIONS;
|
||||
|
||||
/// File extensions recognised as 3D models (Advanced 3D model layers).
|
||||
|
||||
Reference in New Issue
Block a user