//! Tables of the MPEG-4 Part 2 decoder. //! //! The H.263 tables (MCBPC, CBPY, MVD, TCOEF, Advanced INTRA Coding, Modified //! Quantization, scans, picture formats ...) live in `h263data.rs`, generated from the //! text of ITU-T Rec. H.263, and are re-exported here. The tables below are specific to //! ISO/IEC 14496-2 (MPEG-4 Part 2), which is not freely available. They were taken //! from the constant tables of FFmpeg libavcodec n8.1 (LGPL) and could not yet be //! re-sourced from a freely downloadable document: //! //! * `MPEG4_DCTAB_LUM`/`MPEG4_DCTAB_CHROM`: DC size VLCs. //! * `MPEG4_INTRA_VLC`/`_RUN`/`_LEVEL`: INTRA TCOEF. Its codewords are //! those of Table 16/H.263 but the RUN/LEVEL assignment is MPEG-4's own. //! * `SPRITE_TRAJECTORY_LENS`: warping point displacement code lengths (dmv_length). //! * `MB_TYPE_B_TAB`: B-VOP macroblock type codes. //! * `MPEG4_DEFAULT_INTRA_MATRIX`/`MPEG4_DEFAULT_NON_INTRA_MATRIX`: default //! quantisation matrices. //! * `MPEG4_Y_DC_SCALE_TABLE`/`MPEG4_C_DC_SCALE_TABLE`: DC scaler. //! * `MPEG4_DC_THRESHOLD`: intra_dc_vlc_thr. //! * `MPEG4_RL_INTRA_*`: entry counts of the tables above. pub use crate::h263data::*; pub const MPEG4_DCTAB_LUM: [[u8; 2]; 13] = [ [3, 3], [3, 2], [2, 2], [2, 3], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], ]; pub const MPEG4_DCTAB_CHROM: [[u8; 2]; 13] = [ [3, 2], [2, 2], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], ]; pub const MPEG4_INTRA_VLC: [[u16; 2]; 103] = [ [2, 2], [6, 3], [15, 4], [13, 5], [12, 5], [21, 6], [19, 6], [18, 6], [23, 7], [31, 8], [30, 8], [29, 8], [37, 9], [36, 9], [35, 9], [33, 9], [33, 10], [32, 10], [15, 10], [14, 10], [7, 11], [6, 11], [32, 11], [33, 11], [80, 12], [81, 12], [82, 12], [14, 4], [20, 6], [22, 7], [28, 8], [32, 9], [31, 9], [13, 10], [34, 11], [83, 12], [85, 12], [11, 5], [21, 7], [30, 9], [12, 10], [86, 12], [17, 6], [27, 8], [29, 9], [11, 10], [16, 6], [34, 9], [10, 10], [13, 6], [28, 9], [8, 10], [18, 7], [27, 9], [84, 12], [20, 7], [26, 9], [87, 12], [25, 8], [9, 10], [24, 8], [35, 11], [23, 8], [25, 9], [24, 9], [7, 10], [88, 12], [7, 4], [12, 6], [22, 8], [23, 9], [6, 10], [5, 11], [4, 11], [89, 12], [15, 6], [22, 9], [5, 10], [14, 6], [4, 10], [17, 7], [36, 11], [16, 7], [37, 11], [19, 7], [90, 12], [21, 8], [91, 12], [20, 8], [19, 8], [26, 8], [21, 9], [20, 9], [19, 9], [18, 9], [17, 9], [38, 11], [39, 11], [92, 12], [93, 12], [94, 12], [95, 12], [3, 7], ]; pub const MPEG4_INTRA_LEVEL: [i8; 102] = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]; pub const MPEG4_INTRA_RUN: [i8; 102] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13, 14, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ]; pub const SPRITE_TRAJECTORY_LENS: [u8; 15] = [2, 3, 3, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; pub const MB_TYPE_B_TAB: [[u8; 2]; 4] = [[1, 1], [1, 2], [1, 3], [1, 4]]; pub const MPEG4_DEFAULT_INTRA_MATRIX: [i16; 64] = [ 8, 17, 18, 19, 21, 23, 25, 27, 17, 18, 19, 21, 23, 25, 27, 28, 20, 21, 22, 23, 24, 26, 28, 30, 21, 22, 23, 24, 26, 28, 30, 32, 22, 23, 24, 26, 28, 30, 32, 35, 23, 24, 26, 28, 30, 32, 35, 38, 25, 26, 28, 30, 32, 35, 38, 41, 27, 28, 30, 32, 35, 38, 41, 45, ]; pub const MPEG4_DEFAULT_NON_INTRA_MATRIX: [i16; 64] = [ 16, 17, 18, 19, 20, 21, 22, 23, 17, 18, 19, 20, 21, 22, 23, 24, 18, 19, 20, 21, 22, 23, 24, 25, 19, 20, 21, 22, 23, 24, 26, 27, 20, 21, 22, 23, 25, 26, 27, 28, 21, 22, 23, 24, 26, 27, 28, 30, 22, 23, 24, 26, 27, 28, 30, 31, 23, 24, 25, 27, 28, 30, 31, 33, ]; pub const MPEG4_Y_DC_SCALE_TABLE: [u8; 32] = [ 0, 8, 8, 8, 8, 10, 12, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 36, 38, 40, 42, 44, 46, ]; pub const MPEG4_C_DC_SCALE_TABLE: [u8; 32] = [ 0, 8, 8, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 20, 21, 22, 23, 24, 25, ]; pub const MPEG4_DC_THRESHOLD: [u8; 8] = [99, 13, 15, 17, 19, 21, 23, 0]; pub const MPEG4_RL_INTRA_N: usize = 102; pub const MPEG4_RL_INTRA_LAST: usize = 67; #[cfg(test)] mod tests { use super::*; fn prefix_free(name: &str, t: &[[u16; 2]]) { let e: Vec<(u32, u32)> = t .iter() .filter(|x| x[1] != 0) .map(|x| (x[0] as u32, x[1] as u32)) .collect(); for (i, &(ca, la)) in e.iter().enumerate() { for (j, &(cb, lb)) in e.iter().enumerate() { if i == j { continue; } if la <= lb { assert!( !(cb >> (lb - la) == ca), "{name}: entry {i} is a prefix of {j}" ); } } } } fn to16(t: &[[u8; 2]]) -> Vec<[u16; 2]> { t.iter().map(|x| [x[0] as u16, x[1] as u16]).collect() } #[test] fn vlcs_prefix_free() { prefix_free("MPEG4_INTRA_VLC", &MPEG4_INTRA_VLC); prefix_free("INTER_VLC", &INTER_VLC); prefix_free("MVTAB", &to16(&MVTAB)); prefix_free("H263_CBPY_TAB", &to16(&H263_CBPY_TAB)); prefix_free("MPEG4_DCTAB_LUM", &to16(&MPEG4_DCTAB_LUM)); prefix_free("MPEG4_DCTAB_CHROM", &to16(&MPEG4_DCTAB_CHROM)); let m: Vec<[u16; 2]> = H263_INTRA_MCBPC_CODE .iter() .zip(H263_INTRA_MCBPC_BITS.iter()) .map(|(&c, &b)| [c as u16, b as u16]) .collect(); prefix_free("INTRA_MCBPC", &m); } fn is_perm(t: &[u8; 64]) { let mut seen = [false; 64]; for &v in t { assert!(!seen[v as usize]); seen[v as usize] = true; } } #[test] fn scans_are_permutations() { is_perm(&ZIGZAG_DIRECT); is_perm(&ALTERNATE_HORIZONTAL_SCAN); is_perm(&ALTERNATE_VERTICAL_SCAN); } }