common_data.h 27 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10 11
 */

12 13
#ifndef AV1_COMMON_COMMON_DATA_H_
#define AV1_COMMON_COMMON_DATA_H_
Jingning Han's avatar
Jingning Han committed
14

15
#include "av1/common/enums.h"
16 17
#include "aom/aom_integer.h"
#include "aom_dsp/aom_dsp_common.h"
Jingning Han's avatar
Jingning Han committed
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

23
#if CONFIG_EXT_PARTITION
24
#define IF_EXT_PARTITION(...) __VA_ARGS__,
25
#else
26
#define IF_EXT_PARTITION(...)
27 28
#endif

Jingning Han's avatar
Jingning Han committed
29
// Log 2 conversion lookup tables for block width and height
30
static const uint8_t b_width_log2_lookup[BLOCK_SIZES_ALL] = {
31 32 33 34 35 36 37 38 39 40
  0, 0,
  1, 1,
  1, 2,
  2, 2,
  3, 3,
  3, 4,
  4, IF_EXT_PARTITION(4, 5, 5) 0,
  2, 1,
  3, 2,
  4, IF_EXT_PARTITION(3, 5)
41
};
42
static const uint8_t b_height_log2_lookup[BLOCK_SIZES_ALL] = {
43 44 45 46 47 48 49 50 51 52
  0, 1,
  0, 1,
  2, 1,
  2, 3,
  2, 3,
  4, 3,
  4, IF_EXT_PARTITION(5, 4, 5) 2,
  0, 3,
  1, 4,
  2, IF_EXT_PARTITION(5, 3)
53
};
Jingning Han's avatar
Jingning Han committed
54
// Log 2 conversion lookup tables for modeinfo width and height
55
static const uint8_t mi_width_log2_lookup[BLOCK_SIZES_ALL] = {
56 57 58 59 60 61 62 63 64 65
  0, 0,
  1, 1,
  1, 2,
  2, 2,
  3, 3,
  3, 4,
  4, IF_EXT_PARTITION(4, 5, 5) 0,
  2, 1,
  3, 2,
  4, IF_EXT_PARTITION(3, 5)
66
};
67
static const uint8_t mi_height_log2_lookup[BLOCK_SIZES_ALL] = {
68 69 70 71 72 73 74 75 76 77
  0, 1,
  0, 1,
  2, 1,
  2, 3,
  2, 3,
  4, 3,
  4, IF_EXT_PARTITION(5, 4, 5) 2,
  0, 3,
  1, 4,
  2, IF_EXT_PARTITION(5, 3)
78
};
79

80 81
/* clang-format off */
static const uint8_t mi_size_wide[BLOCK_SIZES_ALL] = {
82
  1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16,
83
  IF_EXT_PARTITION(16, 32, 32)  1, 4, 2, 8, 4, 16, IF_EXT_PARTITION(8, 32)
84
};
85
static const uint8_t mi_size_high[BLOCK_SIZES_ALL] = {
86
  1, 2, 1, 2, 4, 2, 4, 8, 4, 8, 16, 8, 16,
87
  IF_EXT_PARTITION(32, 16, 32)  4, 1, 8, 2, 16, 4, IF_EXT_PARTITION(32, 8)
88
};
89
/* clang-format on */
90

91
// Width/height lookup tables in units of various block sizes
92
static const uint8_t block_size_wide[BLOCK_SIZES_ALL] = {
93 94 95 96 97 98 99 100 101 102
  4,  4,
  8,  8,
  8,  16,
  16, 16,
  32, 32,
  32, 64,
  64, IF_EXT_PARTITION(64, 128, 128) 4,
  16, 8,
  32, 16,
  64, IF_EXT_PARTITION(32, 128)
103
};
104

105
static const uint8_t block_size_high[BLOCK_SIZES_ALL] = {
106 107 108 109 110 111 112 113 114 115
  4,  8,
  4,  8,
  16, 8,
  16, 32,
  16, 32,
  64, 32,
  64, IF_EXT_PARTITION(128, 64, 128) 16,
  4,  32,
  8,  64,
  16, IF_EXT_PARTITION(128, 32)
116
};
117

118
static const uint8_t num_4x4_blocks_wide_lookup[BLOCK_SIZES_ALL] = {
119 120 121 122 123 124 125 126 127 128
  1,  1,
  2,  2,
  2,  4,
  4,  4,
  8,  8,
  8,  16,
  16, IF_EXT_PARTITION(16, 32, 32) 1,
  4,  2,
  8,  4,
  16, IF_EXT_PARTITION(8, 32)
129
};
130
static const uint8_t num_4x4_blocks_high_lookup[BLOCK_SIZES_ALL] = {
131 132 133 134 135 136 137 138 139 140
  1,  2,
  1,  2,
  4,  2,
  4,  8,
  4,  8,
  16, 8,
  16, IF_EXT_PARTITION(32, 16, 32) 4,
  1,  8,
  2,  16,
  4,  IF_EXT_PARTITION(32, 8)
141
};
142
static const uint8_t num_8x8_blocks_wide_lookup[BLOCK_SIZES_ALL] = {
143 144 145 146 147 148 149 150 151 152
  1, 1,
  1, 1,
  1, 2,
  2, 2,
  4, 4,
  4, 8,
  8, IF_EXT_PARTITION(8, 16, 16) 1,
  2, 1,
  4, 2,
  8, IF_EXT_PARTITION(4, 16)
153
};
154
static const uint8_t num_8x8_blocks_high_lookup[BLOCK_SIZES_ALL] = {
155 156 157 158 159 160 161 162 163 164
  1, 1,
  1, 1,
  2, 1,
  2, 4,
  2, 4,
  8, 4,
  8, IF_EXT_PARTITION(16, 8, 16) 2,
  1, 4,
  1, 8,
  2, IF_EXT_PARTITION(16, 4)
165
};
Jingning Han's avatar
Jingning Han committed
166

167
// AOMMIN(3, AOMMIN(b_width_log2(bsize), b_height_log2(bsize)))
168
static const uint8_t size_group_lookup[BLOCK_SIZES_ALL] = {
169 170 171 172 173 174 175 176 177 178
  0, 0,
  0, 1,
  1, 1,
  2, 2,
  2, 3,
  3, 3,
  3, IF_EXT_PARTITION(3, 3, 3) 0,
  0, 1,
  1, 2,
  2, IF_EXT_PARTITION(3, 3)
179
};
Jingning Han's avatar
Jingning Han committed
180

181
static const uint8_t num_pels_log2_lookup[BLOCK_SIZES_ALL] = {
182 183 184 185 186 187 188 189 190 191
  4,  5,
  5,  6,
  7,  7,
  8,  9,
  9,  10,
  11, 11,
  12, IF_EXT_PARTITION(13, 13, 14) 6,
  6,  8,
  8,  10,
  10, IF_EXT_PARTITION(12, 12)
192
};
Jingning Han's avatar
Jingning Han committed
193

194
/* clang-format off */
195
#if CONFIG_EXT_PARTITION_TYPES
196
static const BLOCK_SIZE subsize_lookup[EXT_PARTITION_TYPES][BLOCK_SIZES_ALL] =
197
#else
198
static const BLOCK_SIZE subsize_lookup[PARTITION_TYPES][BLOCK_SIZES_ALL] =
199 200
#endif  // CONFIG_EXT_PARTITION_TYPES
{
201
  {     // PARTITION_NONE
202 203 204 205 206 207 208 209 210 211 212 213 214 215
    //                            4X4
                                  BLOCK_4X4,
    // 4X8,        8X4,           8X8
    BLOCK_4X8,     BLOCK_8X4,     BLOCK_8X8,
    // 8X16,       16X8,          16X16
    BLOCK_8X16,    BLOCK_16X8,    BLOCK_16X16,
    // 16X32,      32X16,         32X32
    BLOCK_16X32,   BLOCK_32X16,   BLOCK_32X32,
    // 32X64,      64X32,         64X64
    BLOCK_32X64,   BLOCK_64X32,   BLOCK_64X64,
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
    BLOCK_64X128,  BLOCK_128X64,  BLOCK_128X128,
#endif  // CONFIG_EXT_PARTITION
216 217
    // 4X16,       16X4,          8X32
    BLOCK_4X16,    BLOCK_16X4,    BLOCK_8X32,
218 219
    // 32X8,       16X64,         64X16
    BLOCK_32X8,    BLOCK_16X64,   BLOCK_64X16,
220 221 222 223
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_32X128,  BLOCK_128X32
#endif  // CONFIG_EXT_PARTITION
224
  }, {  // PARTITION_HORZ
225
    //                            4X4
226
                                  BLOCK_INVALID,
227 228 229 230 231 232 233 234 235 236 237 238
    // 4X8,        8X4,           8X8
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X4,
    // 8X16,       16X8,          16X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X8,
    // 16X32,      32X16,         32X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X16,
    // 32X64,      64X32,         64X64
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X32,
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64,
#endif  // CONFIG_EXT_PARTITION
239 240
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
241 242
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
243 244 245 246
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
247
  }, {  // PARTITION_VERT
248
    //                            4X4
249
                                  BLOCK_INVALID,
250 251 252 253 254 255 256 257 258 259 260 261
    // 4X8,        8X4,           8X8
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X8,
    // 8X16,       16X8,          16X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X16,
    // 16X32,      32X16,         32X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X32,
    // 32X64,      64X32,         64X64
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X64,
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X128,
#endif  // CONFIG_EXT_PARTITION
262 263
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
264 265
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
266 267 268 269
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
270
  }, {  // PARTITION_SPLIT
271 272 273 274 275 276 277 278 279 280 281 282 283 284
    //                            4X4
                                  BLOCK_INVALID,
    // 4X8,        8X4,           8X8
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X4,
    // 8X16,       16X8,          16X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X8,
    // 16X32,      32X16,         32X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X16,
    // 32X64,      64X32,         64X64
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X32,
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X64,
#endif  // CONFIG_EXT_PARTITION
285 286
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
287 288
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
289 290 291 292
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
293
#if CONFIG_EXT_PARTITION_TYPES
294
  }, {  // PARTITION_HORZ_A
295 296 297 298 299 300 301 302 303 304 305 306 307 308
    //                            4X4
                                  BLOCK_INVALID,
    // 4X8,        8X4,           8X8
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X4,
    // 8X16,       16X8,          16X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X8,
    // 16X32,      32X16,         32X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X16,
    // 32X64,      64X32,         64X64
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X32,
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64,
#endif  // CONFIG_EXT_PARTITION
309 310
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
311 312
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
313 314 315 316
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
317
  }, {  // PARTITION_HORZ_B
318 319 320 321 322 323 324 325 326 327 328 329 330 331
    //                            4X4
                                  BLOCK_INVALID,
    // 4X8,        8X4,           8X8
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X4,
    // 8X16,       16X8,          16X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X8,
    // 16X32,      32X16,         32X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X16,
    // 32X64,      64X32,         64X64
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X32,
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64,
#endif  // CONFIG_EXT_PARTITION
332 333
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
334 335
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
336 337 338 339
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
340
  }, {  // PARTITION_VERT_A
341 342 343 344 345 346 347 348 349 350 351 352 353 354
    //                            4X4
                                  BLOCK_INVALID,
    // 4X8,        8X4,           8X8
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X8,
    // 8X16,       16X8,          16X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X16,
    // 16X32,      32X16,         32X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X32,
    // 32X64,      64X32,         64X64
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X64,
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X128,
#endif  // CONFIG_EXT_PARTITION
355 356
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
357 358
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
359 360 361 362
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
363
  }, {  // PARTITION_VERT_B
364 365 366 367 368 369 370 371 372 373 374 375 376 377
    //                            4X4
                                  BLOCK_INVALID,
    // 4X8,        8X4,           8X8
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X8,
    // 8X16,       16X8,          16X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X16,
    // 16X32,      32X16,         32X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X32,
    // 32X64,      64X32,         64X64
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X64,
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X128,
#endif  // CONFIG_EXT_PARTITION
378 379
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
380 381
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
382 383 384 385
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
386 387 388 389 390 391 392 393 394 395
  }, {  // PARTITION_HORZ_4
    //                            4X4
                                  BLOCK_INVALID,
    // 4X8,        8X4,           8X8
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
    // 8X16,       16X8,          16X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X4,
    // 16X32,      32X16,         32X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X8,
    // 32X64,      64X32,         64X64
396
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X16,
397 398
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
399
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X32,
400 401 402
#endif  // CONFIG_EXT_PARTITION
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
403 404
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
405 406 407 408
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
409 410 411 412 413 414 415 416 417 418
  }, {  // PARTITION_VERT_4
    //                            4X4
                                  BLOCK_INVALID,
    // 4X8,        8X4,           8X8
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
    // 8X16,       16X8,          16X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X16,
    // 16X32,      32X16,         32X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X32,
    // 32X64,      64X32,         64X64
419
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X64,
420 421
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
422
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X128,
423 424 425
#endif  // CONFIG_EXT_PARTITION
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
426 427
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
428 429 430 431
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
432
#endif  // CONFIG_EXT_PARTITION_TYPES
Jingning Han's avatar
Jingning Han committed
433 434 435
  }
};

436
static const TX_SIZE max_txsize_lookup[BLOCK_SIZES_ALL] = {
437 438 439 440 441 442 443 444
  //                   4X4
                       TX_4X4,
  // 4X8,    8X4,      8X8
  TX_4X4,    TX_4X4,   TX_8X8,
  // 8X16,   16X8,     16X16
  TX_8X8,    TX_8X8,   TX_16X16,
  // 16X32,  32X16,    32X32
  TX_16X16,  TX_16X16, TX_32X32,
445 446 447 448 449 450 451 452
  // 32X64,  64X32,
  TX_32X32,  TX_32X32,
  // 64X64
  TX_64X64,
#if CONFIG_EXT_PARTITION
  // 64x128, 128x64,   128x128
  TX_64X64,  TX_64X64, TX_64X64,
#endif  // CONFIG_EXT_PARTITION
453 454
  // 4x16,   16x4,     8x32
  TX_4X4,    TX_4X4,   TX_8X8,
455
  // 32x8,   16x64     64x16
456 457 458 459 460
  TX_8X8,    TX_16X16, TX_16X16,
#if CONFIG_EXT_PARTITION
  // 32x128  128x32
  TX_32X32,  TX_32X32
#endif  // CONFIG_EXT_PARTITION
Jingning Han's avatar
Jingning Han committed
461 462
};

463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
static const TX_SIZE max_txsize_rect_lookup[2][BLOCK_SIZES_ALL] = {
  {
      // Intra
      //                   4X4
      TX_4X4,
      // 4X8,    8X4,      8X8
      TX_4X8,    TX_8X4,   TX_8X8,
      // 8X16,   16X8,     16X16
      TX_8X16,   TX_16X8,  TX_16X16,
      // 16X32,  32X16,    32X32
      TX_16X32,  TX_32X16, TX_32X32,
      // 32X64,  64X32,
      TX_32X64,  TX_64X32,
      // 64X64
      TX_64X64,
478
#if CONFIG_EXT_PARTITION
479 480
      // 64x128, 128x64,   128x128
      TX_64X64,  TX_64X64, TX_64X64,
481
#endif  // CONFIG_EXT_PARTITION
482
#if CONFIG_EXT_PARTITION_TYPES && CONFIG_RECT_TX_EXT_INTRA
483 484 485 486 487 488
      // 4x16,   16x4,
      TX_4X16,   TX_16X4,
      // 8x32,   32x8
      TX_8X32,   TX_32X8,
      // 16x64,  64x16
      TX_16X64,  TX_64X16,
489
#else
490 491 492 493 494 495
      // 4x16,   16x4,
      TX_4X8,    TX_8X4,
      // 8x32,   32x8
      TX_8X16,   TX_16X8,
      // 16x64,  64x16
      TX_16X32,  TX_32X16,
496
#endif  // CONFIG_EXT_PARTITION_TYPES && CONFIG_RECT_TX_EXT_INTRA
497
#if CONFIG_EXT_PARTITION
498 499
      // 32x128  128x32
      TX_32X64,  TX_64X32
500
#endif  // CONFIG_EXT_PARTITION
501 502 503 504 505 506 507 508 509 510 511 512 513 514
  }, {
      // Inter
      //                   4X4
      TX_4X4,
      // 4X8,    8X4,      8X8
      TX_4X8,    TX_8X4,   TX_8X8,
      // 8X16,   16X8,     16X16
      TX_8X16,   TX_16X8,  TX_16X16,
      // 16X32,  32X16,    32X32
      TX_16X32,  TX_32X16, TX_32X32,
      // 32X64,  64X32,
      TX_32X64,  TX_64X32,
      // 64X64
      TX_64X64,
515
#if CONFIG_EXT_PARTITION
516 517
      // 64x128, 128x64,   128x128
      TX_64X64,  TX_64X64, TX_64X64,
518
#endif  // CONFIG_EXT_PARTITION
519
#if CONFIG_EXT_PARTITION_TYPES && CONFIG_RECT_TX_EXT
520 521 522 523 524 525
      // 4x16,   16x4,     8x32
      TX_4X16,   TX_16X4,  TX_8X32,
      // 32x8
      TX_32X8,
      // 16x64,  64x16
      TX_16X64,  TX_64X16,
Yue Chen's avatar
Yue Chen committed
526
#else
527 528 529 530 531 532
      // 4x16,   16x4,     8x32
      TX_4X8,    TX_8X4,   TX_8X16,
      // 32x8
      TX_16X8,
      // 16x64,  64x16
      TX_16X32,  TX_32X16,
533
#endif  // CONFIG_EXT_PARTITION_TYPES && CONFIG_RECT_TX_EXT
534
#if CONFIG_EXT_PARTITION
535 536
      // 32x128  128x32
      TX_32X64,  TX_64X32
537
#endif  // CONFIG_EXT_PARTITION
538
  },
539
};
540

541 542 543 544 545 546 547 548 549 550 551 552
static const TX_TYPE_1D vtx_tab[TX_TYPES] = {
  DCT_1D,      ADST_1D, DCT_1D,      ADST_1D,
  FLIPADST_1D, DCT_1D,  FLIPADST_1D, ADST_1D, FLIPADST_1D, IDTX_1D,
  DCT_1D,      IDTX_1D, ADST_1D,     IDTX_1D, FLIPADST_1D, IDTX_1D,
};

static const TX_TYPE_1D htx_tab[TX_TYPES] = {
  DCT_1D,  DCT_1D,      ADST_1D,     ADST_1D,
  DCT_1D,  FLIPADST_1D, FLIPADST_1D, FLIPADST_1D, ADST_1D, IDTX_1D,
  IDTX_1D, DCT_1D,      IDTX_1D,     ADST_1D,     IDTX_1D, FLIPADST_1D,
};

553 554
#define TXSIZE_CAT_INVALID (-1)

555
/* clang-format on */
556

557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
static const TX_SIZE sub_tx_size_map[2][TX_SIZES_ALL] = {
  {
      // Intra
      TX_4X4,    // TX_4X4
      TX_4X4,    // TX_8X8
      TX_8X8,    // TX_16X16
      TX_16X16,  // TX_32X32
      TX_32X32,  // TX_64X64
      TX_4X4,    // TX_4X8
      TX_4X4,    // TX_8X4
      TX_8X8,    // TX_8X16
      TX_8X8,    // TX_16X8
      TX_16X16,  // TX_16X32
      TX_16X16,  // TX_32X16
      TX_32X32,  // TX_32X64
      TX_32X32,  // TX_64X32
#if CONFIG_EXT_PARTITION_TYPES && CONFIG_RECT_TX_EXT_INTRA
Yaowu Xu's avatar
Yaowu Xu committed
574 575 576 577
      TX_4X8,    // TX_4X16
      TX_8X4,    // TX_16X4
      TX_8X16,   // TX_8X32
      TX_16X8,   // TX_32X8
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
      TX_16X32,  // TX_16X64
      TX_32X16,  // TX_64X16
#else
      TX_4X4,    // TX_4X16
      TX_4X4,    // TX_16X4
      TX_8X8,    // TX_8X32
      TX_8X8,    // TX_32X8
      TX_16X16,  // TX_16X64
      TX_16X16,  // TX_64X16
#endif  // CONFIG_EXT_PARTITION_TYPES && CONFIG_RECT_TX_EXT_INTRA
  },
  {
      // Inter
      TX_4X4,    // TX_4X4
      TX_4X4,    // TX_8X8
      TX_8X8,    // TX_16X16
      TX_16X16,  // TX_32X32
      TX_32X32,  // TX_64X64
      TX_4X4,    // TX_4X8
      TX_4X4,    // TX_8X4
      TX_8X8,    // TX_8X16
      TX_8X8,    // TX_16X8
      TX_16X16,  // TX_16X32
      TX_16X16,  // TX_32X16
      TX_32X32,  // TX_32X64
      TX_32X32,  // TX_64X32
#if CONFIG_EXT_PARTITION_TYPES && CONFIG_RECT_TX_EXT
Yaowu Xu's avatar
Yaowu Xu committed
605 606 607 608
      TX_4X8,    // TX_4X16
      TX_8X4,    // TX_16X4
      TX_8X16,   // TX_8X32
      TX_16X8,   // TX_32X8
609 610 611 612 613 614 615 616 617 618 619
      TX_16X32,  // TX_16X64
      TX_32X16,  // TX_64X16
#else
      TX_4X4,    // TX_4X16
      TX_4X4,    // TX_16X4
      TX_8X8,    // TX_8X32
      TX_8X8,    // TX_32X8
      TX_16X16,  // TX_16X64
      TX_16X16,  // TX_64X16
#endif  // CONFIG_EXT_PARTITION_TYPES && CONFIG_RECT_TX_EXT
  },
620 621
};

622 623 624 625 626
static const TX_SIZE txsize_horz_map[TX_SIZES_ALL] = {
  TX_4X4,    // TX_4X4
  TX_8X8,    // TX_8X8
  TX_16X16,  // TX_16X16
  TX_32X32,  // TX_32X32
627
  TX_64X64,  // TX_64X64
628 629 630 631 632
  TX_4X4,    // TX_4X8
  TX_8X8,    // TX_8X4
  TX_8X8,    // TX_8X16
  TX_16X16,  // TX_16X8
  TX_16X16,  // TX_16X32
633
  TX_32X32,  // TX_32X16
634 635
  TX_32X32,  // TX_32X64
  TX_64X64,  // TX_64X32
636 637 638 639
  TX_4X4,    // TX_4X16
  TX_16X16,  // TX_16X4
  TX_8X8,    // TX_8X32
  TX_32X32,  // TX_32X8
640 641
  TX_16X16,  // TX_16X64
  TX_64X64,  // TX_64X16
642 643 644 645 646 647 648
};

static const TX_SIZE txsize_vert_map[TX_SIZES_ALL] = {
  TX_4X4,    // TX_4X4
  TX_8X8,    // TX_8X8
  TX_16X16,  // TX_16X16
  TX_32X32,  // TX_32X32
649
  TX_64X64,  // TX_64X64
650 651 652 653 654
  TX_8X8,    // TX_4X8
  TX_4X4,    // TX_8X4
  TX_16X16,  // TX_8X16
  TX_8X8,    // TX_16X8
  TX_32X32,  // TX_16X32
655
  TX_16X16,  // TX_32X16
656 657
  TX_64X64,  // TX_32X64
  TX_32X32,  // TX_64X32
658 659 660 661
  TX_16X16,  // TX_4X16
  TX_4X4,    // TX_16X4
  TX_32X32,  // TX_8X32
  TX_8X8,    // TX_32X8
662 663
  TX_64X64,  // TX_16X64
  TX_16X16,  // TX_64X16
664 665
};

666 667
#define TX_SIZE_W_MIN 4

668
// Transform block width in pixels
669
static const int tx_size_wide[TX_SIZES_ALL] = {
Yaowu Xu's avatar
Yaowu Xu committed
670
  4, 8, 16, 32, 64, 4, 8, 8, 16, 16, 32, 32, 64, 4, 16, 8, 32, 16, 64,
671
};
672

673 674
#define TX_SIZE_H_MIN 4

675
// Transform block height in pixels
676
static const int tx_size_high[TX_SIZES_ALL] = {
Yaowu Xu's avatar
Yaowu Xu committed
677
  4, 8, 16, 32, 64, 8, 4, 16, 8, 32, 16, 64, 32, 16, 4, 32, 8, 64, 16,
678
};
679 680

// Transform block width in unit
681
static const int tx_size_wide_unit[TX_SIZES_ALL] = {
Yaowu Xu's avatar
Yaowu Xu committed
682
  1, 2, 4, 8, 16, 1, 2, 2, 4, 4, 8, 8, 16, 1, 4, 2, 8, 4, 16,
683
};
684 685

// Transform block height in unit
686
static const int tx_size_high_unit[TX_SIZES_ALL] = {
Yaowu Xu's avatar
Yaowu Xu committed
687
  1, 2, 4, 8, 16, 2, 1, 4, 2, 8, 4, 16, 8, 4, 1, 8, 2, 16, 4,
688
};
689

690
// Transform block width in log2
691
static const int tx_size_wide_log2[TX_SIZES_ALL] = {
Yaowu Xu's avatar
Yaowu Xu committed
692
  2, 3, 4, 5, 6, 2, 3, 3, 4, 4, 5, 5, 6, 2, 4, 3, 5, 4, 6,
693
};
694 695

// Transform block height in log2
696
static const int tx_size_high_log2[TX_SIZES_ALL] = {
Yaowu Xu's avatar
Yaowu Xu committed
697
  2, 3, 4, 5, 6, 3, 2, 4, 3, 5, 4, 6, 5, 4, 2, 5, 3, 6, 4,
698
};
699

700 701 702
#define TX_UNIT_WIDE_LOG2 (MI_SIZE_LOG2 - tx_size_wide_log2[0])
#define TX_UNIT_HIGH_LOG2 (MI_SIZE_LOG2 - tx_size_high_log2[0])

703
static const int tx_size_2d[TX_SIZES_ALL + 1] = {
Yaowu Xu's avatar
Yaowu Xu committed
704 705
  16,  64,   256,  1024, 4096, 32,  32,  128,  128,  512,
  512, 2048, 2048, 64,   64,   256, 256, 1024, 1024,
706
};
707

708 709 710 711 712
static const BLOCK_SIZE txsize_to_bsize[TX_SIZES_ALL] = {
  BLOCK_4X4,    // TX_4X4
  BLOCK_8X8,    // TX_8X8
  BLOCK_16X16,  // TX_16X16
  BLOCK_32X32,  // TX_32X32
713 714 715 716 717 718 719
  BLOCK_64X64,  // TX_64X64
  BLOCK_4X8,    // TX_4X8
  BLOCK_8X4,    // TX_8X4
  BLOCK_8X16,   // TX_8X16
  BLOCK_16X8,   // TX_16X8
  BLOCK_16X32,  // TX_16X32
  BLOCK_32X16,  // TX_32X16
720 721
  BLOCK_32X64,  // TX_32X64
  BLOCK_64X32,  // TX_64X32
722 723 724 725
  BLOCK_4X16,   // TX_4X16
  BLOCK_16X4,   // TX_16X4
  BLOCK_8X32,   // TX_8X32
  BLOCK_32X8,   // TX_32X8
726 727
  BLOCK_16X64,  // TX_16X64
  BLOCK_64X16,  // TX_64X16
728 729 730 731 732 733 734
};

static const TX_SIZE txsize_sqr_map[TX_SIZES_ALL] = {
  TX_4X4,    // TX_4X4
  TX_8X8,    // TX_8X8
  TX_16X16,  // TX_16X16
  TX_32X32,  // TX_32X32
735
  TX_64X64,  // TX_64X64
736 737 738 739 740 741
  TX_4X4,    // TX_4X8
  TX_4X4,    // TX_8X4
  TX_8X8,    // TX_8X16
  TX_8X8,    // TX_16X8
  TX_16X16,  // TX_16X32
  TX_16X16,  // TX_32X16
742 743
  TX_32X32,  // TX_32X64
  TX_32X32,  // TX_64X32
744 745 746 747
  TX_4X4,    // TX_4X16
  TX_4X4,    // TX_16X4
  TX_8X8,    // TX_8X32
  TX_8X8,    // TX_32X8
748 749
  TX_16X16,  // TX_16X64
  TX_16X16,  // TX_64X16
Jingning Han's avatar
Jingning Han committed
750 751
};

752 753 754 755 756
static const TX_SIZE txsize_sqr_up_map[TX_SIZES_ALL] = {
  TX_4X4,    // TX_4X4
  TX_8X8,    // TX_8X8
  TX_16X16,  // TX_16X16
  TX_32X32,  // TX_32X32
757
  TX_64X64,  // TX_64X64
758 759 760 761 762 763
  TX_8X8,    // TX_4X8
  TX_8X8,    // TX_8X4
  TX_16X16,  // TX_8X16
  TX_16X16,  // TX_16X8
  TX_32X32,  // TX_16X32
  TX_32X32,  // TX_32X16
764 765
  TX_64X64,  // TX_32X64
  TX_64X64,  // TX_64X32
766 767 768 769
  TX_16X16,  // TX_4X16
  TX_16X16,  // TX_16X4
  TX_32X32,  // TX_8X32
  TX_32X32,  // TX_32X8
770 771
  TX_64X64,  // TX_16X64
  TX_64X64,  // TX_64X16
772 773
};

774 775 776 777 778
static const int8_t txsize_log2_minus4[TX_SIZES_ALL] = {
  0,  // TX_4X4
  2,  // TX_8X8
  4,  // TX_16X16
  6,  // TX_32X32
Yaowu Xu's avatar
Yaowu Xu committed
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
  6,  // TX_64X64
  1,  // TX_4X8
  1,  // TX_8X4
  3,  // TX_8X16
  3,  // TX_16X8
  5,  // TX_16X32
  5,  // TX_32X16
  6,  // TX_32X64
  6,  // TX_64X32
  2,  // TX_4X16
  2,  // TX_16X4
  4,  // TX_8X32
  4,  // TX_32X8
  5,  // TX_16X64
  5,  // TX_64X16
794 795
};

796
/* clang-format off */
797 798 799 800 801
static const TX_SIZE tx_mode_to_biggest_tx_size[TX_MODES] = {
  TX_4X4,    // ONLY_4X4
  TX_64X64,  // TX_MODE_LARGEST
  TX_64X64,  // TX_MODE_SELECT
};
802
/* clang-format on */
Jingning Han's avatar
Jingning Han committed
803

804
static const BLOCK_SIZE ss_size_lookup[BLOCK_SIZES_ALL][2][2] = {
805 806
  //  ss_x == 0    ss_x == 0        ss_x == 1      ss_x == 1
  //  ss_y == 0    ss_y == 1        ss_y == 0      ss_y == 1
807 808 809
  { { BLOCK_4X4, BLOCK_4X4 }, { BLOCK_4X4, BLOCK_4X4 } },
  { { BLOCK_4X8, BLOCK_4X4 }, { BLOCK_4X4, BLOCK_4X4 } },
  { { BLOCK_8X4, BLOCK_4X4 }, { BLOCK_4X4, BLOCK_4X4 } },
810
  { { BLOCK_8X8, BLOCK_8X4 }, { BLOCK_4X8, BLOCK_4X4 } },
811 812
  { { BLOCK_8X16, BLOCK_8X8 }, { BLOCK_4X16, BLOCK_4X8 } },
  { { BLOCK_16X8, BLOCK_16X4 }, { BLOCK_8X8, BLOCK_8X4 } },
813
  { { BLOCK_16X16, BLOCK_16X8 }, { BLOCK_8X16, BLOCK_8X8 } },
814 815
  { { BLOCK_16X32, BLOCK_16X16 }, { BLOCK_8X32, BLOCK_8X16 } },
  { { BLOCK_32X16, BLOCK_32X8 }, { BLOCK_16X16, BLOCK_16X8 } },
816
  { { BLOCK_32X32, BLOCK_32X16 }, { BLOCK_16X32, BLOCK_16X16 } },
817 818
  { { BLOCK_32X64, BLOCK_32X32 }, { BLOCK_16X64, BLOCK_16X32 } },
  { { BLOCK_64X32, BLOCK_64X16 }, { BLOCK_32X32, BLOCK_32X16 } },
819
  { { BLOCK_64X64, BLOCK_64X32 }, { BLOCK_32X64, BLOCK_32X32 } },
820
#if CONFIG_EXT_PARTITION
821 822
  { { BLOCK_64X128, BLOCK_64X64 }, { BLOCK_32X128, BLOCK_32X64 } },
  { { BLOCK_128X64, BLOCK_128X32 }, { BLOCK_64X64, BLOCK_64X32 } },
823
  { { BLOCK_128X128, BLOCK_128X64 }, { BLOCK_64X128, BLOCK_64X64 } },
824
#endif  // CONFIG_EXT_PARTITION
825 826
  { { BLOCK_4X16, BLOCK_4X8 }, { BLOCK_4X16, BLOCK_4X8 } },
  { { BLOCK_16X4, BLOCK_16X4 }, { BLOCK_8X4, BLOCK_8X4 } },
827 828
  { { BLOCK_8X32, BLOCK_8X16 }, { BLOCK_INVALID, BLOCK_4X16 } },
  { { BLOCK_32X8, BLOCK_INVALID }, { BLOCK_16X8, BLOCK_16X4 } },
829 830
  { { BLOCK_16X64, BLOCK_16X32 }, { BLOCK_INVALID, BLOCK_8X32 } },
  { { BLOCK_64X16, BLOCK_INVALID }, { BLOCK_32X16, BLOCK_32X8 } },
831 832 833 834
#if CONFIG_EXT_PARTITION
  { { BLOCK_32X128, BLOCK_32X64 }, { BLOCK_INVALID, BLOCK_16X64 } },
  { { BLOCK_128X32, BLOCK_INVALID }, { BLOCK_64X32, BLOCK_64X16 } },
#endif  // CONFIG_EXT_PARTITION
Jingning Han's avatar
Jingning Han committed
835 836 837 838 839
};

// Generates 4 bit field in which each bit set to 1 represents
// a blocksize partition  1111 means we split 64x64, 32x32, 16x16
// and 8x8.  1000 means we just split the 64x64 to 32x32
840
/* clang-format off */
Jingning Han's avatar
Jingning Han committed
841 842 843
static const struct {
  PARTITION_CONTEXT above;
  PARTITION_CONTEXT left;
844
} partition_context_lookup[BLOCK_SIZES_ALL] = {
845
#if CONFIG_EXT_PARTITION
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
  { 31, 31 },  // 4X4   - {0b11111, 0b11111}
  { 31, 30 },  // 4X8   - {0b11111, 0b11110}
  { 30, 31 },  // 8X4   - {0b11110, 0b11111}
  { 30, 30 },  // 8X8   - {0b11110, 0b11110}
  { 30, 28 },  // 8X16  - {0b11110, 0b11100}
  { 28, 30 },  // 16X8  - {0b11100, 0b11110}
  { 28, 28 },  // 16X16 - {0b11100, 0b11100}
  { 28, 24 },  // 16X32 - {0b11100, 0b11000}
  { 24, 28 },  // 32X16 - {0b11000, 0b11100}
  { 24, 24 },  // 32X32 - {0b11000, 0b11000}
  { 24, 16 },  // 32X64 - {0b11000, 0b10000}
  { 16, 24 },  // 64X32 - {0b10000, 0b11000}
  { 16, 16 },  // 64X64 - {0b10000, 0b10000}
  { 16, 0 },   // 64X128- {0b10000, 0b00000}
  { 0, 16 },   // 128X64- {0b00000, 0b10000}
  { 0, 0 },    // 128X128-{0b00000, 0b00000}
862 863 864 865 866 867 868 869
  { 31, 28 },  // 4X16  - {0b11111, 0b11100}
  { 28, 31 },  // 16X4  - {0b11100, 0b11111}
  { 30, 24 },  // 8X32  - {0b11110, 0b11000}
  { 24, 30 },  // 32X8  - {0b11000, 0b11110}
  { 28, 16 },  // 16X64 - {0b11100, 0b10000}
  { 16, 28 },  // 64X16 - {0b10000, 0b11100}
  { 24, 0 },   // 32X128- {0b11000, 0b00000}
  { 0, 24 },   // 128X32- {0b00000, 0b11000}
870
#else
871 872 873 874 875 876 877 878 879 880 881 882 883
  { 15, 15 },  // 4X4   - {0b1111, 0b1111}
  { 15, 14 },  // 4X8   - {0b1111, 0b1110}
  { 14, 15 },  // 8X4   - {0b1110, 0b1111}
  { 14, 14 },  // 8X8   - {0b1110, 0b1110}
  { 14, 12 },  // 8X16  - {0b1110, 0b1100}
  { 12, 14 },  // 16X8  - {0b1100, 0b1110}
  { 12, 12 },  // 16X16 - {0b1100, 0b1100}
  { 12, 8 },   // 16X32 - {0b1100, 0b1000}
  { 8, 12 },   // 32X16 - {0b1000, 0b1100}
  { 8, 8 },    // 32X32 - {0b1000, 0b1000}
  { 8, 0 },    // 32X64 - {0b1000, 0b0000}
  { 0, 8 },    // 64X32 - {0b0000, 0b1000}
  { 0, 0 },    // 64X64 - {0b0000, 0b0000}
884 885
  { 15, 12 },  // 4X16 - {0b1111, 0b1100}
  { 12, 15 },  // 16X4 - {0b1100, 0b1111}
886 887
  { 14, 8 },   // 8X32 - {0b1110, 0b1000}
  { 8, 14 },   // 32X8 - {0b1000, 0b1110}
888 889
  { 12, 0 },   // 16X64- {0b1100, 0b0000}
  { 0, 12 },   // 64X16- {0b0000, 0b1100}
890
#endif  // CONFIG_EXT_PARTITION
Jingning Han's avatar
Jingning Han committed
891
};
892
/* clang-format on */
Jingning Han's avatar
Jingning Han committed
893

894
static const int intra_mode_context[INTRA_MODES] = {
895
  0, 1, 2, 3, 4, 4, 4, 4, 3, 0, 1, 2, 0,
896 897
};

898
#if CONFIG_JNT_COMP
899 900
// Note: this is also used in unit tests. So whenever one changes the table,
// the unit tests need to be changed accordingly.
Cheng Chen's avatar
Cheng Chen committed
901 902 903
static const int quant_dist_weight[4][2] = {
  { 2, 3 }, { 2, 5 }, { 2, 7 }, { 1, MAX_FRAME_DISTANCE }
};
904
static const int quant_dist_lookup_table[2][4][2] = {
905 906
  { { 9, 7 }, { 11, 5 }, { 12, 4 }, { 13, 3 } },
  { { 7, 9 }, { 5, 11 }, { 4, 12 }, { 3, 13 } },
907 908 909
};
#endif  // CONFIG_JNT_COMP

Jingning Han's avatar
Jingning Han committed
910 911 912 913
#ifdef __cplusplus
}  // extern "C"
#endif

914
#endif  // AV1_COMMON_COMMON_DATA_H_