1#![allow(non_upper_case_globals)]
11#![allow(non_camel_case_types)]
12#![allow(dead_code)]
13
14use crate::context::*;
15use crate::partition::BlockSize::*;
16use crate::partition::*;
17use crate::transform::*;
18
19static has_null: &[u8] = &[];
20
21#[rustfmt::skip]
31static has_tr_4x4: &[u8] = &[
32  255, 255, 255, 255, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85,
33  127, 127, 127, 127, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85,
34  255, 127, 255, 127, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85,
35  127, 127, 127, 127, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85,
36  255, 255, 255, 127, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85,
37  127, 127, 127, 127, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85,
38  255, 127, 255, 127, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85,
39  127, 127, 127, 127, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85,
40];
41
42static has_tr_4x8: &[u8] = &[
43  255, 255, 255, 255, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119,
44  119, 255, 127, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119,
45  119, 119, 255, 255, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119,
46  119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127,
47  119, 119, 119, 119,
48];
49
50#[rustfmt::skip]
51static has_tr_8x4: &[u8] = &[
52  255, 255, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0,
53  127, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0,
54  255, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0,
55  127, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0,
56];
57
58#[rustfmt::skip]
59static has_tr_8x8: &[u8] = &[
60  255, 255, 85, 85, 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85,
61  255, 127, 85, 85, 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85,
62];
63static has_tr_8x16: &[u8] = &[
64  255, 255, 119, 119, 127, 127, 119, 119, 255, 127, 119, 119, 127, 127, 119,
65  119,
66];
67static has_tr_16x8: &[u8] =
68  &[255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0];
69static has_tr_16x16: &[u8] = &[255, 85, 119, 85, 127, 85, 119, 85];
70static has_tr_16x32: &[u8] = &[255, 119, 127, 119];
71static has_tr_32x16: &[u8] = &[15, 5, 7, 5];
72static has_tr_32x32: &[u8] = &[95, 87];
73static has_tr_32x64: &[u8] = &[127];
74static has_tr_64x32: &[u8] = &[19];
75static has_tr_64x64: &[u8] = &[7];
76static has_tr_64x128: &[u8] = &[3];
77static has_tr_128x64: &[u8] = &[1];
78static has_tr_128x128: &[u8] = &[1];
79static has_tr_4x16: &[u8] = &[
80  255, 255, 255, 255, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127, 127,
81  127, 255, 255, 255, 127, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127,
82  127, 127,
83];
84static has_tr_16x4: &[u8] = &[
85  255, 0, 0, 0, 85, 0, 0, 0, 119, 0, 0, 0, 85, 0, 0, 0, 127, 0, 0, 0, 85, 0,
86  0, 0, 119, 0, 0, 0, 85, 0, 0, 0,
87];
88static has_tr_8x32: &[u8] = &[255, 255, 127, 127, 255, 127, 127, 127];
89static has_tr_32x8: &[u8] = &[15, 0, 5, 0, 7, 0, 5, 0];
90static has_tr_16x64: &[u8] = &[255, 127];
91static has_tr_64x16: &[u8] = &[3, 1];
92
93static has_tr_tables: &[&[u8]] = &[
94  has_tr_4x4,     has_tr_4x8,     has_tr_8x4,     has_tr_8x8,     has_tr_8x16,    has_tr_16x8,    has_tr_16x16,   has_tr_16x32,   has_tr_32x16,   has_tr_32x32,   has_tr_32x64,   has_tr_64x32,   has_tr_64x64,   has_tr_64x128,  has_tr_128x64,  has_tr_128x128, has_tr_4x16,    has_tr_16x4,    has_tr_8x32,    has_tr_32x8,    has_tr_16x64,   has_tr_64x16,   ];
117
118#[rustfmt::skip]
119static has_tr_vert_8x8: &[u8] = &[
120  255, 255, 0, 0, 119, 119, 0, 0, 127, 127, 0, 0, 119, 119, 0, 0,
121  255, 127, 0, 0, 119, 119, 0, 0, 127, 127, 0, 0, 119, 119, 0, 0,
122];
123static has_tr_vert_16x16: &[u8] = &[255, 0, 119, 0, 127, 0, 119, 0];
124static has_tr_vert_32x32: &[u8] = &[15, 7];
125static has_tr_vert_64x64: &[u8] = &[3];
126
127static has_tr_vert_tables: &[&[u8]] = &[
137  has_null,          has_tr_4x8,        has_null,          has_tr_vert_8x8,   has_tr_8x16,       has_null,          has_tr_vert_16x16, has_tr_16x32,      has_null,          has_tr_vert_32x32, has_tr_32x64,      has_null,          has_tr_vert_64x64, has_tr_64x128,     has_null,          has_tr_128x128,    ];
154
155pub fn get_has_tr_table(
157  bsize: BlockSize,
158) -> &'static [u8] {
159  let ret: &[u8];
160  {
166    ret = has_tr_tables[bsize as usize];
167  }
168
169  ret
172}
173
174pub fn has_top_right(
175  bsize: BlockSize, partition_bo: TileBlockOffset, top_available: bool,
176  right_available: bool, tx_size: TxSize, row_off: usize, col_off: usize,
177  ss_x: usize, _ss_y: usize,
178) -> bool {
179  if !top_available || !right_available {
180    return false;
181  };
182
183  let bw_unit = bsize.width_mi();
184  let plane_bw_unit = (bw_unit >> ss_x).max(1);
185  let top_right_count_unit = tx_size.width_mi();
186
187  let mi_col = partition_bo.0.x;
188  let mi_row = partition_bo.0.y;
189
190  if row_off > 0 {
191    if bsize.width() > BLOCK_64X64.width() {
194      if row_off == BLOCK_64X64.height_mi() >> _ss_y
198        && col_off + top_right_count_unit == BLOCK_64X64.width_mi() >> ss_x
199      {
200        return false;
201      }
202      let plane_bw_unit_64 = BLOCK_64X64.width_mi() >> ss_x;
203      let col_off_64 = col_off % plane_bw_unit_64;
204      return col_off_64 + top_right_count_unit < plane_bw_unit_64;
205    }
206    col_off + top_right_count_unit < plane_bw_unit
207  } else {
208    if col_off + top_right_count_unit < plane_bw_unit {
210      return true;
211    };
212
213    let bw_in_mi_log2 = bsize.width_log2() - MI_SIZE_LOG2;
214    let bh_in_mi_log2 = bsize.height_log2() - MI_SIZE_LOG2;
215    let sb_mi_size: usize = 16; let blk_row_in_sb = (mi_row & (sb_mi_size - 1)) >> bh_in_mi_log2;
217    let blk_col_in_sb = (mi_col & (sb_mi_size - 1)) >> bw_in_mi_log2;
218
219    if blk_row_in_sb == 0 {
222      return true;
223    };
224
225    if ((blk_col_in_sb + 1) << bw_in_mi_log2) >= sb_mi_size {
228      return false;
229    };
230
231    let this_blk_index =
234      (blk_row_in_sb << (MAX_MIB_SIZE_LOG2 - bw_in_mi_log2)) + blk_col_in_sb;
235    let idx1 = this_blk_index / 8;
236    let idx2 = this_blk_index % 8;
237    let has_tr_table: &[u8] = get_has_tr_table(bsize);
238
239    ((has_tr_table[idx1] >> idx2) & 1) != 0
240  }
241}
242
243static has_bl_4x4: &[u8] = &[
246  84, 85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 1, 1, 1, 84, 85, 85, 85,
247  16, 17, 17, 17, 84, 85, 85, 85, 0, 0, 1, 0, 84, 85, 85, 85, 16, 17, 17, 17,
248  84, 85, 85, 85, 0, 1, 1, 1, 84, 85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85,
249  0, 0, 0, 0, 84, 85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 1, 1, 1, 84,
250  85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 0, 1, 0, 84, 85, 85, 85, 16,
251  17, 17, 17, 84, 85, 85, 85, 0, 1, 1, 1, 84, 85, 85, 85, 16, 17, 17, 17, 84,
252  85, 85, 85, 0, 0, 0, 0,
253];
254static has_bl_4x8: &[u8] = &[
255  16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0,
256  1, 1, 1, 16, 17, 17, 17, 0, 0, 0, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17,
257  17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 0, 0,
258];
259static has_bl_8x4: &[u8] = &[
260  254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254,
261  255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, 254, 255,
262  84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84,
263  85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0,
264];
265static has_bl_8x8: &[u8] = &[
266  84, 85, 16, 17, 84, 85, 0, 1, 84, 85, 16, 17, 84, 85, 0, 0, 84, 85, 16, 17,
267  84, 85, 0, 1, 84, 85, 16, 17, 84, 85, 0, 0,
268];
269static has_bl_8x16: &[u8] =
270  &[16, 17, 0, 1, 16, 17, 0, 0, 16, 17, 0, 1, 16, 17, 0, 0];
271static has_bl_16x8: &[u8] =
272  &[254, 84, 254, 16, 254, 84, 254, 0, 254, 84, 254, 16, 254, 84, 254, 0];
273static has_bl_16x16: &[u8] = &[84, 16, 84, 0, 84, 16, 84, 0];
274static has_bl_16x32: &[u8] = &[16, 0, 16, 0];
275static has_bl_32x16: &[u8] = &[78, 14, 78, 14];
276static has_bl_32x32: &[u8] = &[4, 4];
277static has_bl_32x64: &[u8] = &[0];
278static has_bl_64x32: &[u8] = &[34];
279static has_bl_64x64: &[u8] = &[0];
280static has_bl_64x128: &[u8] = &[0];
281static has_bl_128x64: &[u8] = &[0];
282static has_bl_128x128: &[u8] = &[0];
283static has_bl_4x16: &[u8] = &[
284  0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0,
285  1, 1, 1, 0, 0, 0, 0,
286];
287static has_bl_16x4: &[u8] = &[
288  254, 254, 254, 84, 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0,
289  254, 254, 254, 84, 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0,
290];
291static has_bl_8x32: &[u8] = &[0, 1, 0, 0, 0, 1, 0, 0];
292static has_bl_32x8: &[u8] = &[238, 78, 238, 14, 238, 78, 238, 14];
293static has_bl_16x64: &[u8] = &[0, 0];
294static has_bl_64x16: &[u8] = &[42, 42];
295
296static has_bl_tables: &[&[u8]] = &[
297  has_bl_4x4,     has_bl_4x8,     has_bl_8x4,     has_bl_8x8,     has_bl_8x16,    has_bl_16x8,    has_bl_16x16,   has_bl_16x32,   has_bl_32x16,   has_bl_32x32,   has_bl_32x64,   has_bl_64x32,   has_bl_64x64,   has_bl_64x128,  has_bl_128x64,  has_bl_128x128, has_bl_4x16,    has_bl_16x4,    has_bl_8x32,    has_bl_32x8,    has_bl_16x64,   has_bl_64x16,   ];
320
321#[rustfmt::skip]
322static has_bl_vert_8x8: &[u8] = &[
323  254, 255, 16, 17, 254, 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0,
324  254, 255, 16, 17, 254, 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0,
325];
326static has_bl_vert_16x16: &[u8] = &[254, 16, 254, 0, 254, 16, 254, 0];
327static has_bl_vert_32x32: &[u8] = &[14, 14];
328static has_bl_vert_64x64: &[u8] = &[2];
329
330static has_bl_vert_tables: &[&[u8]] = &[
340  has_null,          has_bl_4x8,        has_null,          has_bl_vert_8x8,   has_bl_8x16,       has_null,          has_bl_vert_16x16, has_bl_16x32,      has_null,          has_bl_vert_32x32, has_bl_32x64,      has_null,          has_bl_vert_64x64, has_bl_64x128,     has_null,          has_bl_128x128,    ];
357
358pub fn get_has_bl_table(
359  bsize: BlockSize,
360) -> &'static [u8] {
361  let ret: &[u8];
362  {
368    ret = has_bl_tables[bsize as usize];
369  }
370  ret
372}
373
374pub fn has_bottom_left(
375  bsize: BlockSize, partition_bo: TileBlockOffset, bottom_available: bool,
376  left_available: bool, tx_size: TxSize, row_off: usize, col_off: usize,
377  _ss_x: usize, ss_y: usize,
378) -> bool {
379  if !bottom_available || !left_available {
380    return false;
381  };
382
383  if bsize.width() > BLOCK_64X64.width() && col_off > 0 {
388    let plane_bw_unit_64 = BLOCK_64X64.width_mi() >> _ss_x;
389    let col_off_64 = col_off % plane_bw_unit_64;
390    if col_off_64 == 0 {
391      let plane_bh_unit_64 = BLOCK_64X64.height_mi() >> ss_y;
393      let row_off_64 = row_off % plane_bh_unit_64;
394      let plane_bh_unit = (bsize.height_mi() >> ss_y).min(plane_bh_unit_64);
395      return row_off_64 + tx_size.height_mi() < plane_bh_unit;
398    }
399  }
400
401  if col_off > 0 {
402    false
404  } else {
405    let bh_unit = bsize.height_mi();
406    let plane_bh_unit = (bh_unit >> ss_y).max(1);
407    let bottom_left_count_unit = tx_size.height_mi();
408
409    let mi_col = partition_bo.0.x;
410    let mi_row = partition_bo.0.y;
411
412    if row_off + bottom_left_count_unit < plane_bh_unit {
414      return true;
415    };
416
417    let bw_in_mi_log2 = bsize.width_log2() - MI_SIZE_LOG2;
418    let bh_in_mi_log2 = bsize.height_log2() - MI_SIZE_LOG2;
419    let sb_mi_size: usize = 16; let blk_row_in_sb = (mi_row & (sb_mi_size - 1)) >> bh_in_mi_log2;
421    let blk_col_in_sb = (mi_col & (sb_mi_size - 1)) >> bw_in_mi_log2;
422
423    if blk_col_in_sb == 0 {
427      let blk_start_row_off = blk_row_in_sb << bh_in_mi_log2 >> ss_y;
428      let row_off_in_sb = blk_start_row_off + row_off;
429      let sb_height_unit = sb_mi_size >> ss_y;
430      return row_off_in_sb + bottom_left_count_unit < sb_height_unit;
431      }
433
434    if ((blk_row_in_sb + 1) << bh_in_mi_log2) >= sb_mi_size {
437      return false;
438    };
439
440    let this_blk_index =
443      (blk_row_in_sb << (MAX_MIB_SIZE_LOG2 - bw_in_mi_log2)) + blk_col_in_sb;
444    let idx1 = this_blk_index / 8;
445    let idx2 = this_blk_index % 8;
446    let has_bl_table: &[u8] = get_has_bl_table(bsize);
447
448    ((has_bl_table[idx1] >> idx2) & 1) != 0
449  }
450}