// Generated by tools/gen_h263_tables.py from the text of ITU-T Rec. H.263 (01/2005) // (https://www.itu.int/rec/T-REC-H.263). Do not edit by hand. // // Every table in this file is transcribed from the Recommendation; the clause or table // number is given in each doc comment. A `[code, bits]` pair holds a variable length // code as its integer value and its length in bits (the sign bit of TCOEF / MVD // codes is not included). /// MCBPC for I pictures, code value by spec index (Table 7/H.263; index 8 is stuffing). pub const H263_INTRA_MCBPC_CODE: [u8; 9] = [1, 1, 2, 3, 1, 1, 2, 3, 1]; /// MCBPC for I pictures, code length (Table 7/H.263). pub const H263_INTRA_MCBPC_BITS: [u8; 9] = [1, 3, 3, 3, 4, 6, 6, 6, 9]; /// MCBPC for P pictures, code value. Slot = 4 * group + CBPC with group = INTRA + 2 * Q + 4 * four-vectors flags of the MB type (types 0, 3, 1, 4, 2 -> groups 0..4, type 5 -> group 6), slot 20 = stuffing, slots 21-23 unused (Table 8/H.263). pub const H263_INTER_MCBPC_CODE: [u8; 28] = [ 1, 3, 2, 5, 3, 4, 3, 3, 3, 7, 6, 5, 4, 4, 3, 2, 2, 5, 4, 5, 1, 0, 0, 0, 2, 12, 14, 15, ]; /// MCBPC for P pictures, code length (Table 8/H.263); 0 marks an unused slot. pub const H263_INTER_MCBPC_BITS: [u8; 28] = [ 1, 4, 4, 6, 5, 8, 8, 7, 3, 7, 7, 9, 6, 9, 9, 9, 3, 7, 7, 8, 9, 0, 0, 0, 11, 13, 13, 13, ]; /// CBPC for B- and EP-pictures, indexed by the coded block pattern (Table O.4/H.263). pub const CBPC_B_TAB: [[u8; 2]; 4] = [[0, 1], [2, 2], [7, 3], [6, 3]]; /// CBPY, indexed by the INTRA pattern value (12,34) read as four bits (Table 12/H.263); the INTER code is that of the complemented pattern. pub const H263_CBPY_TAB: [[u8; 2]; 16] = [ [3, 4], [5, 5], [4, 5], [9, 4], [3, 5], [7, 4], [2, 6], [11, 4], [2, 5], [3, 6], [5, 4], [10, 4], [4, 4], [8, 4], [6, 4], [3, 2], ]; /// MVD, indexed by the absolute vector difference in half samples 0..32 (Table 14/H.263); the sign bit follows the code, +-16 share one code. pub const MVTAB: [[u8; 2]; 33] = [ [1, 1], [1, 2], [1, 3], [1, 4], [3, 6], [5, 7], [4, 7], [3, 7], [11, 9], [10, 9], [9, 9], [17, 10], [16, 10], [15, 10], [14, 10], [13, 10], [12, 10], [11, 10], [10, 10], [9, 10], [8, 10], [7, 10], [6, 10], [5, 10], [4, 10], [7, 11], [6, 11], [5, 11], [4, 11], [3, 11], [2, 11], [3, 12], [2, 12], ]; /// TCOEF VLC without the sign bit, 102 (LAST, RUN, |LEVEL|) codes sorted by LAST, RUN, |LEVEL| followed by ESCAPE (Table 16/H.263). pub const INTER_VLC: [[u16; 2]; 103] = [ [2, 2], [15, 4], [21, 6], [23, 7], [31, 8], [37, 9], [36, 9], [33, 10], [32, 10], [7, 11], [6, 11], [32, 11], [6, 3], [20, 6], [30, 8], [15, 10], [33, 11], [80, 12], [14, 4], [29, 8], [14, 10], [81, 12], [13, 5], [35, 9], [13, 10], [12, 5], [34, 9], [82, 12], [11, 5], [12, 10], [83, 12], [19, 6], [11, 10], [84, 12], [18, 6], [10, 10], [17, 6], [9, 10], [16, 6], [8, 10], [22, 7], [85, 12], [21, 7], [20, 7], [28, 8], [27, 8], [33, 9], [32, 9], [31, 9], [30, 9], [29, 9], [28, 9], [27, 9], [26, 9], [34, 11], [35, 11], [86, 12], [87, 12], [7, 4], [25, 9], [5, 11], [15, 6], [4, 11], [14, 6], [13, 6], [12, 6], [19, 7], [18, 7], [17, 7], [16, 7], [26, 8], [25, 8], [24, 8], [23, 8], [22, 8], [21, 8], [20, 8], [19, 8], [24, 9], [23, 9], [22, 9], [21, 9], [20, 9], [19, 9], [18, 9], [17, 9], [7, 10], [6, 10], [5, 10], [4, 10], [36, 11], [37, 11], [38, 11], [39, 11], [88, 12], [89, 12], [90, 12], [91, 12], [92, 12], [93, 12], [94, 12], [95, 12], [3, 7], ]; /// |LEVEL| of the entries of INTER_VLC (Table 16/H.263). pub const INTER_LEVEL: [i8; 102] = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]; /// RUN of the entries of INTER_VLC (Table 16/H.263). pub const INTER_RUN: [i8; 102] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 0, 0, 0, 1, 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, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, ]; /// INTRA TCOEF VLC for Advanced INTRA Coding, entries sorted by LAST, RUN, |LEVEL|, then ESCAPE (Table I.2/H.263). pub const INTRA_VLC_AIC: [[u16; 2]; 103] = [ [2, 2], [6, 3], [14, 4], [12, 5], [13, 5], [16, 6], [17, 6], [18, 6], [22, 7], [27, 8], [32, 9], [33, 9], [26, 9], [27, 9], [28, 9], [29, 9], [30, 9], [31, 9], [35, 11], [34, 11], [87, 12], [86, 12], [85, 12], [84, 12], [83, 12], [15, 4], [20, 6], [20, 7], [30, 8], [15, 10], [33, 11], [80, 12], [11, 5], [21, 7], [14, 10], [9, 10], [21, 6], [29, 8], [13, 10], [81, 12], [19, 6], [35, 9], [7, 11], [23, 7], [34, 9], [82, 12], [28, 8], [12, 10], [31, 8], [11, 10], [37, 9], [10, 10], [36, 9], [6, 11], [33, 10], [32, 10], [8, 10], [32, 11], [7, 4], [12, 6], [16, 7], [19, 8], [17, 9], [18, 9], [4, 10], [39, 11], [38, 11], [95, 12], [15, 6], [19, 9], [5, 10], [37, 11], [14, 6], [20, 9], [36, 11], [13, 6], [6, 10], [94, 12], [17, 7], [7, 10], [19, 7], [93, 12], [18, 7], [92, 12], [20, 8], [91, 12], [21, 8], [26, 8], [25, 8], [24, 8], [23, 8], [22, 8], [25, 9], [21, 9], [22, 9], [24, 9], [23, 9], [4, 11], [5, 11], [88, 12], [89, 12], [90, 12], [3, 7], ]; /// RUN of the entries of INTRA_VLC_AIC (Table I.2/H.263). pub const INTRA_RUN_AIC: [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, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, ]; /// |LEVEL| of the entries of INTRA_VLC_AIC (Table I.2/H.263). pub const INTRA_LEVEL_AIC: [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, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]; /// Advanced INTRA Coding reconstruction scale 2 * QUANT (Annex I.3: RecC = 2 * QUANT * LEVEL, applied to INTRADC too). pub const AIC_DC_SCALE_TABLE: [u8; 32] = [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, ]; /// Modified Quantization: new QUANT for DQUANT = 10 (row 0) and 11 (row 1) by prior QUANT (Table T.1/H.263); slot 0 is unused. pub const MODIFIED_QUANT_TAB: [[u8; 32]; 2] = [ [ 0, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, ], [ 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 31, 31, 26, ], ]; /// QUANT_C for chrominance in Modified Quantization mode (Table T.2/H.263); slot 0 is unused. pub const H263_CHROMA_QSCALE_TABLE: [u8; 32] = [ 0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, ]; /// Largest macroblock address per standard picture format, sub-QCIF to 2048x1152 (Table K.2/H.263). pub const MBA_MAX: [u16; 6] = [47, 98, 395, 1583, 6335, 9215]; /// MBA field width in bits for the same formats (Table K.2/H.263); the last slot repeats the 14 bits of the largest format. pub const MBA_LENGTH: [u8; 7] = [6, 7, 9, 11, 13, 14, 14]; /// Zigzag scan: raster position (row * 8 + column) of each scan index (Figure 14/H.263). pub const ZIGZAG_DIRECT: [u8; 64] = [ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63, ]; /// Alternate-Horizontal scan (Figure I.2-a/H.263). pub const ALTERNATE_HORIZONTAL_SCAN: [u8; 64] = [ 0, 1, 2, 3, 8, 9, 16, 17, 10, 11, 4, 5, 6, 7, 15, 14, 13, 12, 19, 18, 24, 25, 32, 33, 26, 27, 20, 21, 22, 23, 28, 29, 30, 31, 34, 35, 40, 41, 48, 49, 42, 43, 36, 37, 38, 39, 44, 45, 46, 47, 50, 51, 56, 57, 58, 59, 52, 53, 54, 55, 60, 61, 62, 63, ]; /// Alternate-Vertical scan (Figure I.2-b/H.263, as in H.262). pub const ALTERNATE_VERTICAL_SCAN: [u8; 64] = [ 0, 8, 16, 24, 1, 9, 2, 10, 17, 25, 32, 40, 48, 56, 57, 49, 41, 33, 26, 18, 3, 11, 4, 12, 19, 27, 34, 42, 50, 58, 35, 43, 51, 59, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 52, 60, 37, 45, 53, 61, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63, ]; /// Source format dimensions by PTYPE source-format code 0-7 (width, height; Table 2/H.263 and 5.1.3); 0, 6 and 7 are not standard formats. pub const H263_FORMAT: [[u16; 2]; 8] = [ [0, 0], [128, 96], [176, 144], [352, 288], [704, 576], [1408, 1152], [0, 0], [0, 0], ]; /// Pixel aspect ratio (width, height) by PAR code (Table 5/H.263); forbidden, reserved and extended codes give (0, 1). pub const H263_PIXEL_ASPECT: [[u8; 2]; 16] = [ [0, 1], [1, 1], [12, 11], [10, 11], [16, 11], [40, 33], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], ]; // Number of entries (without ESCAPE) and number of LAST = 0 entries of the TCOEF tables. pub const H263_RL_INTER_N: usize = 102; pub const H263_RL_INTER_LAST: usize = 58; pub const RL_INTRA_AIC_N: usize = 102; pub const RL_INTRA_AIC_LAST: usize = 58; #[cfg(test)] mod spec_tests { //! The rows below are the printed codes of the Recommendation; the tests rebuild //! the packed tables from them and compare. use super::*; fn val(c: &str) -> (u32, u32) { (u32::from_str_radix(c, 2).unwrap(), c.len() as u32) } /// (MB type, CBPC, code) of Table 7/H.263, indices 0-8. const T7: [(&str, &str, &str); 9] = [ ("3", "00", "1"), ("3", "01", "001"), ("3", "10", "010"), ("3", "11", "011"), ("4", "00", "0001"), ("4", "01", "000001"), ("4", "10", "000010"), ("4", "11", "000011"), ("Stuffing", "-", "000000001"), ]; /// (MB type, CBPC, code) of Table 8/H.263, indices 0-24. const T8: [(&str, &str, &str); 25] = [ ("0", "00", "1"), ("0", "01", "0011"), ("0", "10", "0010"), ("0", "11", "000101"), ("1", "00", "011"), ("1", "01", "0000111"), ("1", "10", "0000110"), ("1", "11", "000000101"), ("2", "00", "010"), ("2", "01", "0000101"), ("2", "10", "0000100"), ("2", "11", "00000101"), ("3", "00", "00011"), ("3", "01", "00000100"), ("3", "10", "00000011"), ("3", "11", "0000011"), ("4", "00", "000100"), ("4", "01", "000000100"), ("4", "10", "000000011"), ("4", "11", "000000010"), ("Stuffing", "-", "000000001"), ("5", "00", "00000000010"), ("5", "01", "0000000001100"), ("5", "10", "0000000001110"), ("5", "11", "0000000001111"), ]; /// Table 12/H.263 codes in index order (index = INTRA pattern). const T12: [&str; 16] = [ "0011", "00101", "00100", "1001", "00011", "0111", "000010", "1011", "00010", "000011", "0101", "1010", "0100", "1000", "0110", "11", ]; /// Table 14/H.263 codes for positive vectors 0, 0.5, ... 15.5 without sign bit, and -16 last. const T14: [&str; 33] = [ "1", "01", "001", "0001", "000011", "0000101", "0000100", "0000011", "000001011", "000001010", "000001001", "0000010001", "0000010000", "0000001111", "0000001110", "0000001101", "0000001100", "0000001011", "0000001010", "0000001001", "0000001000", "0000000111", "0000000110", "0000000101", "0000000100", "00000000111", "00000000110", "00000000101", "00000000100", "00000000011", "00000000010", "000000000011", "000000000010", ]; /// Table 16/H.263 rows: (LAST, RUN, |LEVEL|, code without sign) by index; ESCAPE code below. const T16: [(u8, i8, i8, &str); 102] = [ (0, 0, 1, "10"), (0, 0, 2, "1111"), (0, 0, 3, "010101"), (0, 0, 4, "0010111"), (0, 0, 5, "00011111"), (0, 0, 6, "000100101"), (0, 0, 7, "000100100"), (0, 0, 8, "0000100001"), (0, 0, 9, "0000100000"), (0, 0, 10, "00000000111"), (0, 0, 11, "00000000110"), (0, 0, 12, "00000100000"), (0, 1, 1, "110"), (0, 1, 2, "010100"), (0, 1, 3, "00011110"), (0, 1, 4, "0000001111"), (0, 1, 5, "00000100001"), (0, 1, 6, "000001010000"), (0, 2, 1, "1110"), (0, 2, 2, "00011101"), (0, 2, 3, "0000001110"), (0, 2, 4, "000001010001"), (0, 3, 1, "01101"), (0, 3, 2, "000100011"), (0, 3, 3, "0000001101"), (0, 4, 1, "01100"), (0, 4, 2, "000100010"), (0, 4, 3, "000001010010"), (0, 5, 1, "01011"), (0, 5, 2, "0000001100"), (0, 5, 3, "000001010011"), (0, 6, 1, "010011"), (0, 6, 2, "0000001011"), (0, 6, 3, "000001010100"), (0, 7, 1, "010010"), (0, 7, 2, "0000001010"), (0, 8, 1, "010001"), (0, 8, 2, "0000001001"), (0, 9, 1, "010000"), (0, 9, 2, "0000001000"), (0, 10, 1, "0010110"), (0, 10, 2, "000001010101"), (0, 11, 1, "0010101"), (0, 12, 1, "0010100"), (0, 13, 1, "00011100"), (0, 14, 1, "00011011"), (0, 15, 1, "000100001"), (0, 16, 1, "000100000"), (0, 17, 1, "000011111"), (0, 18, 1, "000011110"), (0, 19, 1, "000011101"), (0, 20, 1, "000011100"), (0, 21, 1, "000011011"), (0, 22, 1, "000011010"), (0, 23, 1, "00000100010"), (0, 24, 1, "00000100011"), (0, 25, 1, "000001010110"), (0, 26, 1, "000001010111"), (1, 0, 1, "0111"), (1, 0, 2, "000011001"), (1, 0, 3, "00000000101"), (1, 1, 1, "001111"), (1, 1, 2, "00000000100"), (1, 2, 1, "001110"), (1, 3, 1, "001101"), (1, 4, 1, "001100"), (1, 5, 1, "0010011"), (1, 6, 1, "0010010"), (1, 7, 1, "0010001"), (1, 8, 1, "0010000"), (1, 9, 1, "00011010"), (1, 10, 1, "00011001"), (1, 11, 1, "00011000"), (1, 12, 1, "00010111"), (1, 13, 1, "00010110"), (1, 14, 1, "00010101"), (1, 15, 1, "00010100"), (1, 16, 1, "00010011"), (1, 17, 1, "000011000"), (1, 18, 1, "000010111"), (1, 19, 1, "000010110"), (1, 20, 1, "000010101"), (1, 21, 1, "000010100"), (1, 22, 1, "000010011"), (1, 23, 1, "000010010"), (1, 24, 1, "000010001"), (1, 25, 1, "0000000111"), (1, 26, 1, "0000000110"), (1, 27, 1, "0000000101"), (1, 28, 1, "0000000100"), (1, 29, 1, "00000100100"), (1, 30, 1, "00000100101"), (1, 31, 1, "00000100110"), (1, 32, 1, "00000100111"), (1, 33, 1, "000001011000"), (1, 34, 1, "000001011001"), (1, 35, 1, "000001011010"), (1, 36, 1, "000001011011"), (1, 37, 1, "000001011100"), (1, 38, 1, "000001011101"), (1, 39, 1, "000001011110"), (1, 40, 1, "000001011111"), ]; const T16_ESC: &str = "0000011"; /// Table I.2/H.263 rows in index order. const TI2: [(u8, i8, i8, &str); 102] = [ (0, 0, 1, "10"), (0, 1, 1, "1111"), (0, 3, 1, "010101"), (0, 5, 1, "0010111"), (0, 7, 1, "00011111"), (0, 8, 1, "000100101"), (0, 9, 1, "000100100"), (0, 10, 1, "0000100001"), (0, 11, 1, "0000100000"), (0, 4, 3, "00000000111"), (0, 9, 2, "00000000110"), (0, 13, 1, "00000100000"), (0, 0, 2, "110"), (0, 1, 2, "010100"), (0, 1, 4, "00011110"), (0, 1, 5, "0000001111"), (0, 1, 6, "00000100001"), (0, 1, 7, "000001010000"), (0, 0, 3, "1110"), (0, 3, 2, "00011101"), (0, 2, 3, "0000001110"), (0, 3, 4, "000001010001"), (0, 0, 5, "01101"), (0, 4, 2, "000100011"), (0, 3, 3, "0000001101"), (0, 0, 4, "01100"), (0, 5, 2, "000100010"), (0, 5, 3, "000001010010"), (0, 2, 1, "01011"), (0, 6, 2, "0000001100"), (0, 0, 25, "000001010011"), (0, 4, 1, "010011"), (0, 7, 2, "0000001011"), (0, 0, 24, "000001010100"), (0, 0, 8, "010010"), (0, 8, 2, "0000001010"), (0, 0, 7, "010001"), (0, 2, 4, "0000001001"), (0, 0, 6, "010000"), (0, 12, 1, "0000001000"), (0, 0, 9, "0010110"), (0, 0, 23, "000001010101"), (0, 2, 2, "0010101"), (0, 1, 3, "0010100"), (0, 6, 1, "00011100"), (0, 0, 10, "00011011"), (0, 0, 12, "000100001"), (0, 0, 11, "000100000"), (0, 0, 18, "000011111"), (0, 0, 17, "000011110"), (0, 0, 16, "000011101"), (0, 0, 15, "000011100"), (0, 0, 14, "000011011"), (0, 0, 13, "000011010"), (0, 0, 20, "00000100010"), (0, 0, 19, "00000100011"), (0, 0, 22, "000001010110"), (0, 0, 21, "000001010111"), (1, 0, 1, "0111"), (1, 14, 1, "000011001"), (1, 20, 1, "00000000101"), (1, 1, 1, "001111"), (1, 19, 1, "00000000100"), (1, 2, 1, "001110"), (1, 3, 1, "001101"), (1, 0, 2, "001100"), (1, 5, 1, "0010011"), (1, 6, 1, "0010010"), (1, 4, 1, "0010001"), (1, 0, 3, "0010000"), (1, 9, 1, "00011010"), (1, 10, 1, "00011001"), (1, 11, 1, "00011000"), (1, 12, 1, "00010111"), (1, 13, 1, "00010110"), (1, 8, 1, "00010101"), (1, 7, 1, "00010100"), (1, 0, 4, "00010011"), (1, 17, 1, "000011000"), (1, 18, 1, "000010111"), (1, 16, 1, "000010110"), (1, 15, 1, "000010101"), (1, 2, 2, "000010100"), (1, 1, 2, "000010011"), (1, 0, 6, "000010010"), (1, 0, 5, "000010001"), (1, 4, 2, "0000000111"), (1, 3, 2, "0000000110"), (1, 1, 3, "0000000101"), (1, 0, 7, "0000000100"), (1, 2, 3, "00000100100"), (1, 1, 4, "00000100101"), (1, 0, 9, "00000100110"), (1, 0, 8, "00000100111"), (1, 21, 1, "000001011000"), (1, 22, 1, "000001011001"), (1, 23, 1, "000001011010"), (1, 7, 2, "000001011011"), (1, 6, 2, "000001011100"), (1, 5, 2, "000001011101"), (1, 3, 3, "000001011110"), (1, 0, 10, "000001011111"), ]; #[test] fn mcbpc_matches_tables_7_and_8() { for (i, r) in T7.iter().enumerate() { let (c, n) = val(r.2); assert_eq!( ( H263_INTRA_MCBPC_CODE[i] as u32, H263_INTRA_MCBPC_BITS[i] as u32 ), (c, n) ); } for r in T8.iter() { // group = flags of the MB type (INTRA 1, +Q 2, 4V 4); stuffing is group 5. let group = match r.0 { "Stuffing" => 5, t => [0, 2, 4, 1, 3, 6][t.parse::().unwrap()], }; let slot = 4 * group + if r.0 == "Stuffing" { 0 } else { usize::from_str_radix(r.1, 2).unwrap() }; let (c, n) = val(r.2); assert_eq!( ( H263_INTER_MCBPC_CODE[slot] as u32, H263_INTER_MCBPC_BITS[slot] as u32 ), (c, n) ); } for slot in 21..24 { assert_eq!(H263_INTER_MCBPC_BITS[slot], 0); } } #[test] fn cbpy_and_mvd_match_tables_12_and_14() { for (i, c) in T12.iter().enumerate() { let (v, n) = val(c); assert_eq!( (H263_CBPY_TAB[i][0] as u32, H263_CBPY_TAB[i][1] as u32), (v, n) ); } for (i, c) in T14.iter().enumerate() { let (v, n) = val(c); assert_eq!((MVTAB[i][0] as u32, MVTAB[i][1] as u32), (v, n)); } } fn check_rl( rows: &[(u8, i8, i8, &str); 102], vlc: &[[u16; 2]], run: &[i8], level: &[i8], last: usize, ) { let mut sorted: Vec<_> = rows.to_vec(); sorted.sort_by_key(|r| (r.0, r.1, r.2)); assert_eq!(sorted.iter().filter(|r| r.0 == 0).count(), last); for (i, r) in sorted.iter().enumerate() { let (v, n) = val(r.3); assert_eq!((vlc[i][0] as u32, vlc[i][1] as u32), (v, n), "entry {i}"); assert_eq!((run[i], level[i]), (r.1, r.2), "entry {i}"); } let (v, n) = val(T16_ESC); assert_eq!((vlc[102][0] as u32, vlc[102][1] as u32), (v, n)); } #[test] fn tcoef_matches_tables_16_and_i2() { check_rl( &T16, &INTER_VLC, &INTER_RUN, &INTER_LEVEL, H263_RL_INTER_LAST, ); check_rl( &TI2, &INTRA_VLC_AIC, &INTRA_RUN_AIC, &INTRA_LEVEL_AIC, RL_INTRA_AIC_LAST, ); // Table I.2 re-uses the codewords of Table 16 (I.3). let mut a: Vec<_> = T16.iter().map(|r| r.3).collect(); let mut b: Vec<_> = TI2.iter().map(|r| r.3).collect(); a.sort(); b.sort(); assert_eq!(a, b); } #[test] fn small_tables_match_the_text() { // Table O.4: 0, 10, 111, 110 for CBPC pattern 00, 01, 10, 11. assert_eq!(CBPC_B_TAB, [[0, 1], [2, 2], [7, 3], [6, 3]]); // Annex I.3: RecC = 2 * QUANT * LEVEL. for q in 0..32 { assert_eq!(AIC_DC_SCALE_TABLE[q] as usize, 2 * q); } // Table T.2. for q in 1..32usize { let c = match q { 1..=6 => q, 7..=9 => q - 1, 10..=11 => 9, 12..=13 => 10, 14..=15 => 11, 16..=18 => 12, 19..=21 => 13, 22..=26 => 14, _ => 15, }; assert_eq!(H263_CHROMA_QSCALE_TABLE[q] as usize, c, "QUANT {q}"); } // Table T.1: change of QUANT for DQUANT = 10 / 11. for q in 1..32i32 { let (d10, d11) = match q { 1 => (2, 1), 2..=10 => (-1, 1), 11..=20 => (-2, 2), 21..=28 => (-3, 3), 29 => (-3, 2), 30 => (-3, 1), _ => (-3, -5), }; assert_eq!(MODIFIED_QUANT_TAB[0][q as usize] as i32, q + d10); assert_eq!(MODIFIED_QUANT_TAB[1][q as usize] as i32, q + d11); } // Table K.2. assert_eq!(MBA_MAX, [47, 98, 395, 1583, 6335, 9215]); assert_eq!(MBA_LENGTH, [6, 7, 9, 11, 13, 14, 14]); // Table 2 (formats) and Table 5 (PAR). assert_eq!(H263_FORMAT[1], [128, 96]); assert_eq!(H263_FORMAT[5], [1408, 1152]); assert_eq!( &H263_PIXEL_ASPECT[1..6], &[[1, 1], [12, 11], [10, 11], [16, 11], [40, 33]] ); } #[test] fn scans_match_figures() { // Figure 14: first rows of the printed grid (scan positions, 1-based). let fig14: [[u8; 8]; 8] = [ [1, 2, 6, 7, 15, 16, 28, 29], [3, 5, 8, 14, 17, 27, 30, 43], [4, 9, 13, 18, 26, 31, 42, 44], [10, 12, 19, 25, 32, 41, 45, 54], [11, 20, 24, 33, 40, 46, 53, 55], [21, 23, 34, 39, 47, 52, 56, 61], [22, 35, 38, 48, 51, 57, 60, 62], [36, 37, 49, 50, 58, 59, 63, 64], ]; for (i, &p) in ZIGZAG_DIRECT.iter().enumerate() { assert_eq!(fig14[p as usize / 8][p as usize % 8] as usize, i + 1); } // Figure I.2-a and I.2-b. let a: [[u8; 8]; 8] = [ [1, 2, 3, 4, 11, 12, 13, 14], [5, 6, 9, 10, 18, 17, 16, 15], [7, 8, 20, 19, 27, 28, 29, 30], [21, 22, 25, 26, 31, 32, 33, 34], [23, 24, 35, 36, 43, 44, 45, 46], [37, 38, 41, 42, 47, 48, 49, 50], [39, 40, 51, 52, 57, 58, 59, 60], [53, 54, 55, 56, 61, 62, 63, 64], ]; let b: [[u8; 8]; 8] = [ [1, 5, 7, 21, 23, 37, 39, 53], [2, 6, 8, 22, 24, 38, 40, 54], [3, 9, 20, 25, 35, 41, 51, 55], [4, 10, 19, 26, 36, 42, 52, 56], [11, 18, 27, 31, 43, 47, 57, 61], [12, 17, 28, 32, 44, 48, 58, 62], [13, 16, 29, 33, 45, 49, 59, 63], [14, 15, 30, 34, 46, 50, 60, 64], ]; for (i, &p) in ALTERNATE_HORIZONTAL_SCAN.iter().enumerate() { assert_eq!(a[p as usize / 8][p as usize % 8] as usize, i + 1); } for (i, &p) in ALTERNATE_VERTICAL_SCAN.iter().enumerate() { assert_eq!(b[p as usize / 8][p as usize % 8] as usize, i + 1); } } }