From 7be96acc8d04f0760566255b7ef8c872499889a9 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sun, 9 Jan 2022 14:15:34 +0100 Subject: [PATCH] split configuration for audio and video SMUSH decoders --- nihav-game/Cargo.toml | 7 ++++--- nihav-game/src/codecs/mod.rs | 10 +++++----- nihav-game/src/codecs/smush/mod.rs | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/nihav-game/Cargo.toml b/nihav-game/Cargo.toml index 24a846e..3811364 100644 --- a/nihav-game/Cargo.toml +++ b/nihav-game/Cargo.toml @@ -33,7 +33,7 @@ demuxer_vx = ["demuxers"] all_decoders = ["all_video_decoders", "all_audio_decoders"] decoders = [] -all_video_decoders = ["decoder_bmv", "decoder_bmv3", "decoder_fstvid", "decoder_gdvvid", "decoder_imax", "decoder_ipma", "decoder_midivid", "decoder_midivid3", "decoder_q", "decoder_smush", "decoder_vmd", "decoder_vx"] +all_video_decoders = ["decoder_bmv", "decoder_bmv3", "decoder_fstvid", "decoder_gdvvid", "decoder_imax", "decoder_ipma", "decoder_midivid", "decoder_midivid3", "decoder_q", "decoder_smush_video", "decoder_vmd", "decoder_vx"] decoder_bmv = ["decoders"] decoder_bmv3 = ["decoders"] decoder_fstvid = ["decoders"] @@ -43,10 +43,11 @@ decoder_ipma = ["decoders"] decoder_midivid = ["decoders"] decoder_midivid3 = ["decoders"] decoder_q = ["decoders"] -decoder_smush = ["decoders"] +decoder_smush_video = ["decoders"] decoder_vmd = ["decoders"] decoder_vx = ["decoders"] -all_audio_decoders = ["decoder_fstaud", "decoder_lhst500f22"] +all_audio_decoders = ["decoder_fstaud", "decoder_lhst500f22", "decoder_smush_audio"] decoder_fstaud = ["decoders"] decoder_lhst500f22 = ["decoders"] +decoder_smush_audio = ["decoders"] diff --git a/nihav-game/src/codecs/mod.rs b/nihav-game/src/codecs/mod.rs index b65bcc8..c75e263 100644 --- a/nihav-game/src/codecs/mod.rs +++ b/nihav-game/src/codecs/mod.rs @@ -25,7 +25,7 @@ pub mod midivid; pub mod midivid3; #[cfg(feature="decoder_q")] pub mod q; -#[cfg(feature="decoder_smush")] +#[cfg(any(feature="decoder_smush_video", feature="decoder_smush_audio"))] pub mod smush; #[cfg(feature="decoder_vmd")] pub mod vmd; @@ -59,13 +59,13 @@ const GAME_CODECS: &[DecoderInfo] = &[ DecoderInfo { name: "ipma2", get_decoder: ipma::get_decoder_v2 }, #[cfg(feature="decoder_q")] DecoderInfo { name: "legend-q-video", get_decoder: q::get_decoder }, -#[cfg(feature="decoder_smush")] +#[cfg(feature="decoder_smush_video")] DecoderInfo { name: "smushv1", get_decoder: smush::get_decoder_video_v1 }, -#[cfg(feature="decoder_smush")] +#[cfg(feature="decoder_smush_video")] DecoderInfo { name: "smushv2", get_decoder: smush::get_decoder_video_v2 }, -#[cfg(feature="decoder_smush")] +#[cfg(feature="decoder_smush_audio")] DecoderInfo { name: "smush-iact", get_decoder: smush::get_decoder_iact }, -#[cfg(feature="decoder_smush")] +#[cfg(feature="decoder_smush_audio")] DecoderInfo { name: "smush-vima", get_decoder: smush::get_decoder_vima }, #[cfg(feature="decoder_vmd")] DecoderInfo { name: "vmd-audio", get_decoder: vmd::get_decoder_audio }, diff --git a/nihav-game/src/codecs/smush/mod.rs b/nihav-game/src/codecs/smush/mod.rs index 9274cba..53bb61d 100644 --- a/nihav-game/src/codecs/smush/mod.rs +++ b/nihav-game/src/codecs/smush/mod.rs @@ -1,3 +1,4 @@ +#[cfg(feature="decoder_smush_video")] enum GlyphEdge { Left, Top, @@ -6,6 +7,7 @@ enum GlyphEdge { None } +#[cfg(feature="decoder_smush_video")] impl GlyphEdge { fn get(x: usize, y: usize, size: usize) -> Self { if y == 0 { @@ -22,6 +24,7 @@ impl GlyphEdge { } } +#[cfg(feature="decoder_smush_video")] enum GlyphDir { Left, Up, @@ -30,6 +33,7 @@ enum GlyphDir { None } +#[cfg(feature="decoder_smush_video")] impl GlyphDir { fn get(edge0: GlyphEdge, edge1: GlyphEdge) -> Self { match (edge0, edge1) { @@ -50,11 +54,16 @@ impl GlyphDir { } } +#[cfg(feature="decoder_smush_video")] const XVEC4: [usize; 16] = [0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1]; +#[cfg(feature="decoder_smush_video")] const YVEC4: [usize; 16] = [0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2]; +#[cfg(feature="decoder_smush_video")] const XVEC8: [usize; 16] = [0, 2, 5, 7, 7, 7, 7, 7, 7, 5, 2, 0, 0, 0, 0, 0]; +#[cfg(feature="decoder_smush_video")] const YVEC8: [usize; 16] = [0, 0, 0, 0, 1, 3, 4, 6, 7, 7, 7, 7, 6, 4, 3, 1]; +#[cfg(feature="decoder_smush_video")] fn make_glyphs_47(glyphs4: &mut [[u8; 16]; 256], glyphs8: &mut [[u8; 64]; 256]) { for (n, glyph) in glyphs4.iter_mut().enumerate() { let i = n >> 4; @@ -67,6 +76,7 @@ fn make_glyphs_47(glyphs4: &mut [[u8; 16]; 256], glyphs8: &mut [[u8; 64]; 256]) make_glyph_47(glyph, XVEC8[i], YVEC8[i], XVEC8[j], YVEC8[j], 8); } } +#[cfg(feature="decoder_smush_video")] fn make_glyph_47(dst: &mut [u8], xi: usize, yi: usize, xj: usize, yj: usize, size: usize) { let edge0 = GlyphEdge::get(xi, yi, size); let edge1 = GlyphEdge::get(xj, yj, size); @@ -105,16 +115,25 @@ fn make_glyph_47(dst: &mut [u8], xi: usize, yi: usize, xj: usize, yj: usize, siz }; } } +#[cfg(feature="decoder_smush_video")] fn interpolate(a: usize, b: usize, pos1: usize, range: usize) -> usize { (a * pos1 + b * (range - pos1) + range / 2) / range } +#[cfg(feature="decoder_smush_video")] mod v1; +#[cfg(feature="decoder_smush_video")] pub use v1::get_decoder_video_v1; +#[cfg(feature="decoder_smush_video")] mod v2; +#[cfg(feature="decoder_smush_video")] pub use v2::get_decoder_video_v2; +#[cfg(feature="decoder_smush_audio")] mod iact; +#[cfg(feature="decoder_smush_audio")] pub use iact::get_decoder_iact; +#[cfg(feature="decoder_smush_audio")] mod vima; +#[cfg(feature="decoder_smush_audio")] pub use vima::get_decoder_vima; -- 2.39.5