From: Kostya Shishkov Date: Sat, 9 Nov 2024 17:30:43 +0000 (+0100) Subject: switch some TableCodebookDescReader use cases to closures X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=635e417065c8dee4e7cab8dc51ab597ae57f9345;p=nihav.git switch some TableCodebookDescReader use cases to closures --- diff --git a/nihav-acorn/src/codecs/movingblockshq.rs b/nihav-acorn/src/codecs/movingblockshq.rs index ab17ff5..1784809 100644 --- a/nihav-acorn/src/codecs/movingblockshq.rs +++ b/nihav-acorn/src/codecs/movingblockshq.rs @@ -9,13 +9,9 @@ struct DeltaCodebook { cb: Codebook, } -fn map_idx(idx: usize) -> u16 { - idx as u16 -} - impl Default for DeltaCodebook { fn default() -> Self { - let mut cr = TableCodebookDescReader::new(&LUMA_CODES, &LUMA_BITS, map_idx); + let mut cr = TableCodebookDescReader::new(&LUMA_CODES, &LUMA_BITS, |idx| idx as u16); let cb = Codebook::new(&mut cr, CodebookMode::LSB).unwrap(); Self { cb } } diff --git a/nihav-acorn/src/codecs/supermovingblocks.rs b/nihav-acorn/src/codecs/supermovingblocks.rs index 8b82e83..9df1ae6 100644 --- a/nihav-acorn/src/codecs/supermovingblocks.rs +++ b/nihav-acorn/src/codecs/supermovingblocks.rs @@ -8,13 +8,9 @@ struct DeltaCodebook { cb: Codebook, } -fn map_idx(idx: usize) -> u16 { - idx as u16 -} - impl Default for DeltaCodebook { fn default() -> Self { - let mut cr = TableCodebookDescReader::new(&LUMA_CODES, &LUMA_BITS, map_idx); + let mut cr = TableCodebookDescReader::new(&LUMA_CODES, &LUMA_BITS, |idx| idx as u16); let cb = Codebook::new(&mut cr, CodebookMode::LSB).unwrap(); Self { cb } } diff --git a/nihav-duck/src/codecs/on2avc.rs b/nihav-duck/src/codecs/on2avc.rs index 6cbf2b3..4fabe2b 100644 --- a/nihav-duck/src/codecs/on2avc.rs +++ b/nihav-duck/src/codecs/on2avc.rs @@ -37,56 +37,39 @@ struct Codebooks { spec_cb: [Codebook; 15], } -fn scale_map(idx: usize) -> i8 { (idx as i8) - 60 } -fn cb_map1(idx: usize) -> u16 { AVC_SPEC_CB1_SYMS[idx] } -fn cb_map2(idx: usize) -> u16 { AVC_SPEC_CB2_SYMS[idx] } -fn cb_map3(idx: usize) -> u16 { AVC_SPEC_CB3_SYMS[idx] } -fn cb_map4(idx: usize) -> u16 { AVC_SPEC_CB4_SYMS[idx] } -fn cb_map5(idx: usize) -> u16 { AVC_SPEC_CB5_SYMS[idx] } -fn cb_map6(idx: usize) -> u16 { AVC_SPEC_CB6_SYMS[idx] } -fn cb_map7(idx: usize) -> u16 { AVC_SPEC_CB7_SYMS[idx] } -fn cb_map8(idx: usize) -> u16 { AVC_SPEC_CB8_SYMS[idx] } -fn cb_map9(idx: usize) -> u16 { AVC_SPEC_CB9_SYMS[idx] } -fn cb_map10(idx: usize) -> u16 { AVC_SPEC_CB10_SYMS[idx] } -fn cb_map11(idx: usize) -> u16 { AVC_SPEC_CB11_SYMS[idx] } -fn cb_map12(idx: usize) -> u16 { AVC_SPEC_CB12_SYMS[idx] } -fn cb_map13(idx: usize) -> u16 { AVC_SPEC_CB13_SYMS[idx] } -fn cb_map14(idx: usize) -> u16 { AVC_SPEC_CB14_SYMS[idx] } -fn cb_map15(idx: usize) -> u16 { AVC_SPEC_CB15_SYMS[idx] } - impl Codebooks { fn new() -> Self { - let mut coderead = TableCodebookDescReader::new(AVC_SCF_CODEBOOK_CODES, AVC_SCF_CODEBOOK_BITS, scale_map); + let mut coderead = TableCodebookDescReader::new(AVC_SCF_CODEBOOK_CODES, AVC_SCF_CODEBOOK_BITS, |idx| (idx as i8) - 60); let scale_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB1_CODES, AVC_SPEC_CB1_BITS, cb_map1); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB1_CODES, AVC_SPEC_CB1_BITS, |idx| AVC_SPEC_CB1_SYMS[idx]); let cb1 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB2_CODES, AVC_SPEC_CB2_BITS, cb_map2); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB2_CODES, AVC_SPEC_CB2_BITS, |idx| AVC_SPEC_CB2_SYMS[idx]); let cb2 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB3_CODES, AVC_SPEC_CB3_BITS, cb_map3); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB3_CODES, AVC_SPEC_CB3_BITS, |idx| AVC_SPEC_CB3_SYMS[idx]); let cb3 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB4_CODES, AVC_SPEC_CB4_BITS, cb_map4); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB4_CODES, AVC_SPEC_CB4_BITS, |idx| AVC_SPEC_CB4_SYMS[idx]); let cb4 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB5_CODES, AVC_SPEC_CB5_BITS, cb_map5); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB5_CODES, AVC_SPEC_CB5_BITS, |idx| AVC_SPEC_CB5_SYMS[idx]); let cb5 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB6_CODES, AVC_SPEC_CB6_BITS, cb_map6); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB6_CODES, AVC_SPEC_CB6_BITS, |idx| AVC_SPEC_CB6_SYMS[idx]); let cb6 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB7_CODES, AVC_SPEC_CB7_BITS, cb_map7); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB7_CODES, AVC_SPEC_CB7_BITS, |idx| AVC_SPEC_CB7_SYMS[idx]); let cb7 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB8_CODES, AVC_SPEC_CB8_BITS, cb_map8); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB8_CODES, AVC_SPEC_CB8_BITS, |idx| AVC_SPEC_CB8_SYMS[idx]); let cb8 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB9_CODES, AVC_SPEC_CB9_BITS, cb_map9); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB9_CODES, AVC_SPEC_CB9_BITS, |idx| AVC_SPEC_CB9_SYMS[idx]); let cb9 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB10_CODES, AVC_SPEC_CB10_BITS, cb_map10); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB10_CODES, AVC_SPEC_CB10_BITS, |idx| AVC_SPEC_CB10_SYMS[idx]); let cb10 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB11_CODES, AVC_SPEC_CB11_BITS, cb_map11); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB11_CODES, AVC_SPEC_CB11_BITS, |idx| AVC_SPEC_CB11_SYMS[idx]); let cb11 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB12_CODES, AVC_SPEC_CB12_BITS, cb_map12); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB12_CODES, AVC_SPEC_CB12_BITS, |idx| AVC_SPEC_CB12_SYMS[idx]); let cb12 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB13_CODES, AVC_SPEC_CB13_BITS, cb_map13); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB13_CODES, AVC_SPEC_CB13_BITS, |idx| AVC_SPEC_CB13_SYMS[idx]); let cb13 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB14_CODES, AVC_SPEC_CB14_BITS, cb_map14); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB14_CODES, AVC_SPEC_CB14_BITS, |idx| AVC_SPEC_CB14_SYMS[idx]); let cb14 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB15_CODES, AVC_SPEC_CB15_BITS, cb_map15); + let mut coderead = TableCodebookDescReader::new(AVC_SPEC_CB15_CODES, AVC_SPEC_CB15_BITS, |idx| AVC_SPEC_CB15_SYMS[idx]); let cb15 = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); let spec_cb = [cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9, cb10, cb11, cb12, cb13, cb14, cb15]; Self { scale_cb, spec_cb } diff --git a/nihav-duck/src/codecs/vp3.rs b/nihav-duck/src/codecs/vp3.rs index 86e512f..7eeb4e3 100644 --- a/nihav-duck/src/codecs/vp3.rs +++ b/nihav-duck/src/codecs/vp3.rs @@ -26,16 +26,12 @@ struct VP30Codes { mbtype_cb: Codebook, } -fn map_mbt(idx: usize) -> VPMBType { - VP30_MBTYPE_SYMS[idx] -} - impl VP30Codes { fn new() -> Self { let dc_cb; let ac_i_cb; let ac_p_cb; - let mut cr = TableCodebookDescReader::new(&VP30_MBTYPE_CODES, &VP30_MBTYPE_BITS, map_mbt); + let mut cr = TableCodebookDescReader::new(&VP30_MBTYPE_CODES, &VP30_MBTYPE_BITS, |idx| VP30_MBTYPE_SYMS[idx]); let mbtype_cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); unsafe { let mut udc_cb: mem::MaybeUninit::<[Codebook; 5]> = mem::MaybeUninit::uninit(); diff --git a/nihav-mpeg/src/codecs/aac/coeff_read.rs b/nihav-mpeg/src/codecs/aac/coeff_read.rs index 8fc4853..cbd2566 100644 --- a/nihav-mpeg/src/codecs/aac/coeff_read.rs +++ b/nihav-mpeg/src/codecs/aac/coeff_read.rs @@ -21,7 +21,6 @@ pub struct Codebooks { } fn scale_map(idx: usize) -> i8 { (idx as i8) - 60 } -fn cb_map(idx: usize) -> u16 { idx as u16 } impl Codebooks { pub fn new() -> Self { @@ -30,7 +29,7 @@ impl Codebooks { let spec_cb = unsafe { let mut uspec_cb: mem::MaybeUninit::<[Codebook; 11]> = mem::MaybeUninit::uninit(); for i in 0..AAC_SPEC_CODES.len() { - let mut coderead = TableCodebookDescReader::new(AAC_SPEC_CODES[i], AAC_SPEC_BITS[i], cb_map); + let mut coderead = TableCodebookDescReader::new(AAC_SPEC_CODES[i], AAC_SPEC_BITS[i], |idx| idx as u16); ptr::write(&mut (*uspec_cb.as_mut_ptr())[i], Codebook::new(&mut coderead, CodebookMode::MSB).unwrap()); } uspec_cb.assume_init() diff --git a/nihav-rad/src/codecs/bink2.rs b/nihav-rad/src/codecs/bink2.rs index 0dd66ef..b8c7162 100644 --- a/nihav-rad/src/codecs/bink2.rs +++ b/nihav-rad/src/codecs/bink2.rs @@ -1008,7 +1008,6 @@ struct Bink2Codes { } fn map_ac(idx: usize) -> u8 { idx as u8 } -fn map_mv(idx: usize) -> i8 { BINK2_MV_SYMS[idx] } impl Default for Bink2Codes { fn default() -> Self { @@ -1016,7 +1015,7 @@ impl Default for Bink2Codes { let ac_cb1 = Codebook::new(&mut cbr, CodebookMode::LSB).unwrap(); let mut cbr = TableCodebookDescReader::new(BINK2_AC_CODES2, BINK2_AC_BITS2, map_ac); let ac_cb2 = Codebook::new(&mut cbr, CodebookMode::LSB).unwrap(); - let mut cbr = TableCodebookDescReader::new(BINK2_MV_CODES, BINK2_MV_BITS, map_mv); + let mut cbr = TableCodebookDescReader::new(BINK2_MV_CODES, BINK2_MV_BITS, |idx| BINK2_MV_SYMS[idx]); let mv_cb = Codebook::new(&mut cbr, CodebookMode::LSB).unwrap(); let mut cbr = TableCodebookDescReader::new(BINK2_AC_VAL_CODES1, BINK2_AC_VAL_BITS1, map_ac); let val_cb1 = Codebook::new(&mut cbr, CodebookMode::LSB).unwrap(); diff --git a/nihav-rad/src/codecs/binkvid.rs b/nihav-rad/src/codecs/binkvid.rs index ef9aa60..f4fece8 100644 --- a/nihav-rad/src/codecs/binkvid.rs +++ b/nihav-rad/src/codecs/binkvid.rs @@ -383,14 +383,12 @@ struct BinkTrees { cb: [Codebook; 16], } -fn map_u8(idx: usize) -> u8 { idx as u8 } - impl Default for BinkTrees { fn default() -> Self { let cb = unsafe { let mut ucb: std::mem::MaybeUninit::<[Codebook; 16]> = std::mem::MaybeUninit::uninit(); for i in 0..16 { - let mut cr = TableCodebookDescReader::new(&BINK_TREE_CODES[i], &BINK_TREE_BITS[i], map_u8); + let mut cr = TableCodebookDescReader::new(&BINK_TREE_CODES[i], &BINK_TREE_BITS[i], |idx| idx as u8); std::ptr::write(&mut (*ucb.as_mut_ptr())[i], Codebook::new(&mut cr, CodebookMode::LSB).unwrap()); } ucb.assume_init() diff --git a/nihav-vivo/src/codecs/siren.rs b/nihav-vivo/src/codecs/siren.rs index d342898..89cb97d 100644 --- a/nihav-vivo/src/codecs/siren.rs +++ b/nihav-vivo/src/codecs/siren.rs @@ -57,13 +57,6 @@ struct SirenDecoder { } fn map_idx_diff(idx: usize) -> i8 { (idx as i8) - 12 } -fn map_idx0(idx: usize) -> u16 { VEC_CB0_SYMS[idx] } -fn map_idx1(idx: usize) -> u16 { VEC_CB1_SYMS[idx] } -fn map_idx2(idx: usize) -> u16 { VEC_CB2_SYMS[idx] } -fn map_idx3(idx: usize) -> u16 { VEC_CB3_SYMS[idx] } -fn map_idx4(idx: usize) -> u16 { VEC_CB4_SYMS[idx] } -fn map_idx5(idx: usize) -> u16 { VEC_CB5_SYMS[idx] } -fn map_idx6(idx: usize) -> u16 { VEC_CB6_SYMS[idx] } impl SirenDecoder { fn new() -> Self { let mut diff_cb = Vec::with_capacity(NUM_DIFF_CB); @@ -72,19 +65,19 @@ impl SirenDecoder { let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); diff_cb.push(cb); } - let mut cr = TableCodebookDescReader::new(&VEC_CB0_BITS, &VEC_CB0_LENS, map_idx0); + let mut cr = TableCodebookDescReader::new(&VEC_CB0_BITS, &VEC_CB0_LENS, |idx| VEC_CB0_SYMS[idx]); let vec_cb0 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); - let mut cr = TableCodebookDescReader::new(&VEC_CB1_BITS, &VEC_CB1_LENS, map_idx1); + let mut cr = TableCodebookDescReader::new(&VEC_CB1_BITS, &VEC_CB1_LENS, |idx| VEC_CB1_SYMS[idx]); let vec_cb1 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); - let mut cr = TableCodebookDescReader::new(&VEC_CB2_BITS, &VEC_CB2_LENS, map_idx2); + let mut cr = TableCodebookDescReader::new(&VEC_CB2_BITS, &VEC_CB2_LENS, |idx| VEC_CB2_SYMS[idx]); let vec_cb2 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); - let mut cr = TableCodebookDescReader::new(&VEC_CB3_BITS, &VEC_CB3_LENS, map_idx3); + let mut cr = TableCodebookDescReader::new(&VEC_CB3_BITS, &VEC_CB3_LENS, |idx| VEC_CB3_SYMS[idx]); let vec_cb3 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); - let mut cr = TableCodebookDescReader::new(&VEC_CB4_BITS, &VEC_CB4_LENS, map_idx4); + let mut cr = TableCodebookDescReader::new(&VEC_CB4_BITS, &VEC_CB4_LENS, |idx| VEC_CB4_SYMS[idx]); let vec_cb4 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); - let mut cr = TableCodebookDescReader::new(&VEC_CB5_BITS, &VEC_CB5_LENS, map_idx5); + let mut cr = TableCodebookDescReader::new(&VEC_CB5_BITS, &VEC_CB5_LENS, |idx| VEC_CB5_SYMS[idx]); let vec_cb5 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); - let mut cr = TableCodebookDescReader::new(&VEC_CB6_BITS, &VEC_CB6_LENS, map_idx6); + let mut cr = TableCodebookDescReader::new(&VEC_CB6_BITS, &VEC_CB6_LENS, |idx| VEC_CB6_SYMS[idx]); let vec_cb6 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); let vec_cb = [vec_cb0, vec_cb1, vec_cb2, vec_cb3, vec_cb4, vec_cb5, vec_cb6];