nx_h264_bmb.nx source
↩ module page · 74 lines · 3216 B
1// nx_h264_bmb.nx -- H.264 B-macroblock type tables (Table 7-14 mb_type, 7-18 sub_mb_type).
2// Tells the entropy walk, per partition, which reference lists it predicts from (L0/L1/Bi) so it can
3// read the right number of ref_idx + mvd. Prediction-mode encoding here: 0=L0, 1=L1, 2=Bi, -1=Direct.
4// mb_type: 0=B_Direct_16x16; 1=L0 2=L1 3=Bi (16x16); 4..21 = two-partition 16x8/8x16 combos;
5// 22=B_8x8 (sub_mb_type per 8x8); >=23 = intra (caller uses mb_type-23).
6// genealogy_id: itu_t_h264_table7_14_7_18_b_mb_types license_tier: ORIGINAL
7import "nx_syscalls.nx"
8
9// mb_type -> B kind (0..22) or -1 if intra (mb_type>=23).
10func nx_h264_bmb_kind(mb_type: i64) -> i64 {
11 if mb_type < 0 { return 0 - 1 }
12 if mb_type >= 23 { return 0 - 1 }
13 return mb_type
14}
15func nx_h264_bmb_is_direct(bt: i64) -> i64 { if bt == 0 { return 1 } return 0 }
16func nx_h264_bmb_is_8x8(bt: i64) -> i64 { if bt == 22 { return 1 } return 0 }
17// geometric partition count for the non-8x8 inter B types: 1 (16x16, bt 1..3) or 2 (16x8/8x16, bt 4..21).
18func nx_h264_bmb_nparts(bt: i64) -> i64 {
19 if bt == 0 { return 0 }
20 if bt <= 3 { return 1 }
21 if bt <= 21 { return 2 }
22 return 0
23}
24// 16x8 (1) vs 8x16 (0) for bt 4..21 (even offset from 4 == 16x8).
25func nx_h264_bmb_is_16x8(bt: i64) -> i64 {
26 if bt < 4 { return 0 }
27 if bt > 21 { return 0 }
28 if ((bt - 4) % 2) == 0 { return 1 }
29 return 0
30}
31// prediction mode (0=L0,1=L1,2=Bi) of partition `part` for non-8x8 B type bt (1..21).
32func nx_h264_bmb_partmode(bt: i64, part: i64) -> i64 {
33 if bt == 1 { return 0 }
34 if bt == 2 { return 1 }
35 if bt == 3 { return 2 }
36 let g: i64 = (bt - 4) / 2
37 let m0: *i64 = sys_mmap(16 * 8) as *i64
38 let m1: *i64 = sys_mmap(16 * 8) as *i64
39 m0[0]=0; m0[1]=1; m0[2]=0; m0[3]=1; m0[4]=0; m0[5]=1; m0[6]=2; m0[7]=2; m0[8]=2
40 m1[0]=0; m1[1]=1; m1[2]=1; m1[3]=0; m1[4]=2; m1[5]=2; m1[6]=0; m1[7]=1; m1[8]=2
41 if part == 0 { return m0[g] }
42 return m1[g]
43}
44// does a prediction mode use list 0 / list 1?
45func nx_h264_mode_uses_l0(mode: i64) -> i64 { if mode == 0 { return 1 } if mode == 2 { return 1 } return 0 }
46func nx_h264_mode_uses_l1(mode: i64) -> i64 { if mode == 1 { return 1 } if mode == 2 { return 1 } return 0 }
47
48// ---- sub_mb_type (B_8x8) ----
49// 0=B_Direct_8x8; 1=L0 2=L1 3=Bi (8x8); 4=L0_8x4 5=L0_4x8 6=L1_8x4 7=L1_4x8 8=Bi_8x4 9=Bi_4x8;
50// 10=L0_4x4 11=L1_4x4 12=Bi_4x4.
51func nx_h264_bsub_is_direct(sub: i64) -> i64 { if sub == 0 { return 1 } return 0 }
52// number of motion partitions in the sub-MB (Direct=4 4x4 derived but 0 coded mvd -> treat as 0 here).
53func nx_h264_bsub_nparts(sub: i64) -> i64 {
54 if sub == 0 { return 0 }
55 if sub <= 3 { return 1 }
56 if sub <= 9 { return 2 }
57 return 4
58}
59// prediction mode of a B sub_mb_type (0=L0,1=L1,2=Bi); -1 for Direct.
60func nx_h264_bsub_mode(sub: i64) -> i64 {
61 if sub == 0 { return 0 - 1 }
62 if sub == 1 { return 0 }
63 if sub == 2 { return 1 }
64 if sub == 3 { return 2 }
65 if sub == 4 { return 0 }
66 if sub == 5 { return 0 }
67 if sub == 6 { return 1 }
68 if sub == 7 { return 1 }
69 if sub == 8 { return 2 }
70 if sub == 9 { return 2 }
71 if sub == 10 { return 0 }
72 if sub == 11 { return 1 }
73 return 2
74}