common_data.h 63 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
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
 */

Yaowu Xu's avatar
Yaowu Xu committed
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"
Yaowu Xu's avatar
Yaowu Xu committed
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
clang-format's avatar
clang-format committed
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
#if CONFIG_CHROMA_SUB8X8
32 33 34 35 36 37 38 39 40 41 42 43 44
  0, 0,
  0,
#endif
  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)
clang-format's avatar
clang-format committed
45
};
46
static const uint8_t b_height_log2_lookup[BLOCK_SIZES_ALL] = {
47
#if CONFIG_CHROMA_SUB8X8
48 49 50 51 52 53 54 55 56 57 58 59 60
  0, 0,
  0,
#endif
  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)
clang-format's avatar
clang-format committed
61
};
Jingning Han's avatar
Jingning Han committed
62
// Log 2 conversion lookup tables for modeinfo width and height
63
static const uint8_t mi_width_log2_lookup[BLOCK_SIZES_ALL] = {
64
#if CONFIG_CHROMA_SUB8X8
65 66 67 68 69 70 71 72 73 74 75 76 77
  0, 0,
  0,
#endif
  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)
clang-format's avatar
clang-format committed
78
};
79
static const uint8_t mi_height_log2_lookup[BLOCK_SIZES_ALL] = {
80
#if CONFIG_CHROMA_SUB8X8
81 82 83 84 85 86 87 88 89 90 91 92 93
  0, 0,
  0,
#endif
  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)
clang-format's avatar
clang-format committed
94
};
95

96 97
/* clang-format off */
static const uint8_t mi_size_wide[BLOCK_SIZES_ALL] = {
98
#if CONFIG_CHROMA_SUB8X8
99 100 101
  1, 1, 1,
#endif
  1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16,
102
  IF_EXT_PARTITION(16, 32, 32)  1, 4, 2, 8, 4, 16, IF_EXT_PARTITION(8, 32)
103
};
104
static const uint8_t mi_size_high[BLOCK_SIZES_ALL] = {
105
#if CONFIG_CHROMA_SUB8X8
106 107 108
  1, 1, 1,
#endif
  1, 2, 1, 2, 4, 2, 4, 8, 4, 8, 16, 8, 16,
109
  IF_EXT_PARTITION(32, 16, 32)  4, 1, 8, 2, 16, 4, IF_EXT_PARTITION(32, 8)
110
};
111
/* clang-format on */
112

113
// Width/height lookup tables in units of various block sizes
114
static const uint8_t block_size_wide[BLOCK_SIZES_ALL] = {
115
#if CONFIG_CHROMA_SUB8X8
116 117
  2,  2,
  4,
Jingning Han's avatar
Jingning Han committed
118
#endif
119 120 121 122 123 124 125 126 127 128
  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)
129
};
130

131
static const uint8_t block_size_high[BLOCK_SIZES_ALL] = {
132
#if CONFIG_CHROMA_SUB8X8
133 134
  2,  4,
  2,
Jingning Han's avatar
Jingning Han committed
135
#endif
136 137 138 139 140 141 142 143 144 145
  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)
146
};
147

148
static const uint8_t num_4x4_blocks_wide_lookup[BLOCK_SIZES_ALL] = {
149
#if CONFIG_CHROMA_SUB8X8
150 151
  1,  1,
  1,
Jingning Han's avatar
Jingning Han committed
152
#endif
153 154 155 156 157 158 159 160 161 162
  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)
clang-format's avatar
clang-format committed
163
};
164
static const uint8_t num_4x4_blocks_high_lookup[BLOCK_SIZES_ALL] = {
165
#if CONFIG_CHROMA_SUB8X8
166 167
  1,  1,
  1,
Jingning Han's avatar
Jingning Han committed
168
#endif
169 170 171 172 173 174 175 176 177 178
  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)
clang-format's avatar
clang-format committed
179
};
180
static const uint8_t num_8x8_blocks_wide_lookup[BLOCK_SIZES_ALL] = {
181
#if CONFIG_CHROMA_SUB8X8
182 183
  1, 1,
  1,
Jingning Han's avatar
Jingning Han committed
184
#endif
185 186 187 188 189 190 191 192 193 194
  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)
clang-format's avatar
clang-format committed
195
};
196
static const uint8_t num_8x8_blocks_high_lookup[BLOCK_SIZES_ALL] = {
197
#if CONFIG_CHROMA_SUB8X8
198 199
  1, 1,
  1,
Jingning Han's avatar
Jingning Han committed
200
#endif
201 202 203 204 205 206 207 208 209 210
  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)
clang-format's avatar
clang-format committed
211
};
212
static const uint8_t num_16x16_blocks_wide_lookup[BLOCK_SIZES_ALL] = {
213
#if CONFIG_CHROMA_SUB8X8
214 215
  1, 1,
  1,
Jingning Han's avatar
Jingning Han committed
216
#endif
217 218 219 220 221 222 223 224 225 226
  1, 1,
  1, 1,
  1, 1,
  1, 1,
  2, 2,
  2, 4,
  4, IF_EXT_PARTITION(4, 8, 8) 1,
  1, 1,
  2, 2,
  4, IF_EXT_PARTITION(2, 8)
clang-format's avatar
clang-format committed
227
};
228
static const uint8_t num_16x16_blocks_high_lookup[BLOCK_SIZES_ALL] = {
229
#if CONFIG_CHROMA_SUB8X8
230 231
  1, 1,
  1,
Jingning Han's avatar
Jingning Han committed
232
#endif
233 234 235 236 237 238 239 240 241 242
  1, 1,
  1, 1,
  1, 1,
  1, 2,
  1, 2,
  4, 2,
  4, IF_EXT_PARTITION(8, 4, 8) 1,
  1, 2,
  1, 4,
  2, IF_EXT_PARTITION(8, 2)
clang-format's avatar
clang-format committed
243
};
Jingning Han's avatar
Jingning Han committed
244

Yaowu Xu's avatar
Yaowu Xu committed
245
// AOMMIN(3, AOMMIN(b_width_log2(bsize), b_height_log2(bsize)))
246
static const uint8_t size_group_lookup[BLOCK_SIZES_ALL] = {
247
#if CONFIG_CHROMA_SUB8X8
248 249 250 251 252 253 254 255 256 257 258 259 260
  0, 0,
  0,
#endif
  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)
clang-format's avatar
clang-format committed
261
};
Jingning Han's avatar
Jingning Han committed
262

263
static const uint8_t num_pels_log2_lookup[BLOCK_SIZES_ALL] = {
264
#if CONFIG_CHROMA_SUB8X8
265 266 267 268 269 270 271 272 273 274 275 276 277
  2,  3,
  3,
#endif
  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)
clang-format's avatar
clang-format committed
278
};
Jingning Han's avatar
Jingning Han committed
279

clang-format's avatar
clang-format committed
280
/* clang-format off */
281
#if CONFIG_EXT_PARTITION_TYPES
282
static const BLOCK_SIZE subsize_lookup[EXT_PARTITION_TYPES][BLOCK_SIZES_ALL] =
283
#else
284
static const BLOCK_SIZE subsize_lookup[PARTITION_TYPES][BLOCK_SIZES_ALL] =
285 286
#endif  // CONFIG_EXT_PARTITION_TYPES
{
287
  {     // PARTITION_NONE
288
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
289 290 291
    // 2X2,        2X4,           4X2,
    BLOCK_2X2,     BLOCK_2X4,     BLOCK_4X2,
#endif
292 293 294 295 296 297 298 299 300 301 302 303 304 305
    //                            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
306 307
    // 4X16,       16X4,          8X32
    BLOCK_4X16,    BLOCK_16X4,    BLOCK_8X32,
308 309
    // 32X8,       16X64,         64X16
    BLOCK_32X8,    BLOCK_16X64,   BLOCK_64X16,
310 311 312 313
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_32X128,  BLOCK_128X32
#endif  // CONFIG_EXT_PARTITION
314
  }, {  // PARTITION_HORZ
315
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
316 317
    // 2X2,        2X4,           4X2,
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
318 319 320
    //                            4X4
                                  BLOCK_4X2,
#else
321 322
    //                            4X4
                                  BLOCK_INVALID,
323
#endif
324 325 326 327 328 329 330 331 332 333 334 335
    // 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
336 337
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
338 339
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
340 341 342 343
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
344
  }, {  // PARTITION_VERT
345
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
346 347
    // 2X2,        2X4,           4X2,
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
348 349 350
    //                            4X4
                                  BLOCK_2X4,
#else
351 352
    //                            4X4
                                  BLOCK_INVALID,
353
#endif
354 355 356 357 358 359 360 361 362 363 364 365
    // 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
366 367
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
368 369
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
370 371 372 373
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
374
  }, {  // PARTITION_SPLIT
375
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
376 377 378
    // 2X2,        2X4,           4X2,
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
#endif
379 380 381 382 383 384 385 386 387 388 389 390 391 392
    //                            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
393 394
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
395 396
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
397 398 399 400
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
401
#if CONFIG_EXT_PARTITION_TYPES
402
  }, {  // PARTITION_HORZ_A
403
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
404 405 406
    // 2X2,        2X4,           4X2,
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
#endif
407 408 409 410 411 412 413 414 415 416 417 418 419 420
    //                            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
421 422
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
423 424
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
425 426 427 428
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
429
  }, {  // PARTITION_HORZ_B
430
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
431 432 433
    // 2X2,        2X4,           4X2,
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
#endif
434 435 436 437 438 439 440 441 442 443 444 445 446 447
    //                            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
448 449
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
450 451
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
452 453 454 455
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
456
  }, {  // PARTITION_VERT_A
457
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
458 459 460
    // 2X2,        2X4,           4X2,
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
#endif
461 462 463 464 465 466 467 468 469 470 471 472 473 474
    //                            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
475 476
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
477 478
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
479 480 481 482
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
483
  }, {  // PARTITION_VERT_B
484
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
485 486 487
    // 2X2,        2X4,           4X2,
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
#endif
488 489 490 491 492 493 494 495 496 497 498 499 500 501
    //                            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
502 503
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
504 505
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
506 507 508 509
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
510
  }, {  // PARTITION_HORZ_4
511
#if CONFIG_CHROMA_SUB8X8
512 513
    // 2X2,        2X4,           4X2,
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
514
#endif
515 516 517 518 519 520 521 522 523
    //                            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
524
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X16,
525 526
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
527
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X32,
528 529 530
#endif  // CONFIG_EXT_PARTITION
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
531 532
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
533 534 535 536
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
537
  }, {  // PARTITION_VERT_4
538
#if CONFIG_CHROMA_SUB8X8
539 540
    // 2X2,        2X4,           4X2,
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
541
#endif
542 543 544 545 546 547 548 549 550
    //                            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
551
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X64,
552 553
#if CONFIG_EXT_PARTITION
    // 64x128,     128x64,        128x128
554
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X128,
555 556 557
#endif  // CONFIG_EXT_PARTITION
    // 4X16,       16X4,          8X32
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
558 559
    // 32X8,       16X64,         64X16
    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
560 561 562 563
#if CONFIG_EXT_PARTITION
    // 32x128,     128x32
    BLOCK_INVALID, BLOCK_INVALID
#endif  // CONFIG_EXT_PARTITION
564
#endif  // CONFIG_EXT_PARTITION_TYPES
Jingning Han's avatar
Jingning Han committed
565 566 567
  }
};

568
static const TX_SIZE max_txsize_lookup[BLOCK_SIZES_ALL] = {
Jingning Han's avatar
Jingning Han committed
569
  // 2X2,    2X4,      4X2,
570
#if   CONFIG_CHROMA_SUB8X8
571
  TX_4X4,    TX_4X4,   TX_4X4,
Jingning Han's avatar
Jingning Han committed
572
#endif
573 574 575 576 577 578 579 580
  //                   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,
581 582 583 584 585 586 587 588 589 590 591 592
  // 32X64,  64X32,
  TX_32X32,  TX_32X32,
#if CONFIG_TX64X64
  // 64X64
  TX_64X64,
#if CONFIG_EXT_PARTITION
  // 64x128, 128x64,   128x128
  TX_64X64,  TX_64X64, TX_64X64,
#endif  // CONFIG_EXT_PARTITION
#else
  // 64X64
  TX_32X32,
593 594 595 596
#if CONFIG_EXT_PARTITION
  // 64x128, 128x64,   128x128
  TX_32X32,  TX_32X32, TX_32X32,
#endif  // CONFIG_EXT_PARTITION
597
#endif  // CONFIG_TX64X64
598 599
  // 4x16,   16x4,     8x32
  TX_4X4,    TX_4X4,   TX_8X8,
600
  // 32x8,   16x64     64x16
601 602 603 604 605
  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
606 607
};

608
#if CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX)
609
static const TX_SIZE max_txsize_rect_lookup[BLOCK_SIZES_ALL] = {
Jingning Han's avatar
Jingning Han committed
610
  // 2X2,    2X4,      4X2,
611
#if   CONFIG_CHROMA_SUB8X8
612
  TX_4X4,    TX_4X4,   TX_4X4,
613
#endif  // CONFIG_CHROMA_SUB8X8
614 615 616 617 618
  //                   4X4
                       TX_4X4,
  // 4X8,    8X4,      8X8
  TX_4X8,    TX_8X4,   TX_8X8,
  // 8X16,   16X8,     16X16
619
  TX_8X16,   TX_16X8,  TX_16X16,
620
  // 16X32,  32X16,    32X32
621
  TX_16X32,  TX_32X16, TX_32X32,
622
#if CONFIG_TX64X64
623
  // 32X64,  64X32,
624
  TX_32X64,  TX_64X32,
625 626 627 628 629 630 631
  // 64X64
  TX_64X64,
#if CONFIG_EXT_PARTITION
  // 64x128, 128x64,   128x128
  TX_64X64,  TX_64X64, TX_64X64,
#endif  // CONFIG_EXT_PARTITION
#else
632 633
  // 32X64,  64X32,
  TX_32X32,  TX_32X32,
634 635
  // 64X64
  TX_32X32,
636 637 638 639
#if CONFIG_EXT_PARTITION
  // 64x128, 128x64,   128x128
  TX_32X32,  TX_32X32, TX_32X32,
#endif  // CONFIG_EXT_PARTITION
640
#endif  // CONFIG_TX64X64
Yue Chen's avatar
Yue Chen committed
641 642 643 644
#if CONFIG_RECT_TX_EXT
  // 4x16,   16x4,     8x32
  TX_4X16,   TX_16X4,  TX_8X32,
  // 32x8
645
  TX_32X8,
Yue Chen's avatar
Yue Chen committed
646
#else
647 648 649
  // 4x16,   16x4,     8x32
  TX_4X8,    TX_8X4,   TX_8X16,
  // 32x8
650
  TX_16X8,
Yue Chen's avatar
Yue Chen committed
651
#endif
652 653 654 655 656 657
  // 16x64,  64x16
  TX_16X32,  TX_32X16,
#if CONFIG_EXT_PARTITION
  // 32x128  128x32
  TX_32X32,  TX_32X32
#endif  // CONFIG_EXT_PARTITION
658
};
659

Yue Chen's avatar
Yue Chen committed
660
#if CONFIG_RECT_TX_EXT
661
static const TX_SIZE quarter_txsize_lookup[BLOCK_SIZES_ALL] = {
662
#if CONFIG_CHROMA_SUB8X8
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
  //     2X2,        2X4,        4X2,
  TX_INVALID, TX_INVALID, TX_INVALID,
#endif
  //                             4x4,
                          TX_INVALID,
  //     4x8,        8x4,        8x8,
  TX_INVALID, TX_INVALID, TX_INVALID,
  // 8x16, 16x8, 16x16,
  TX_4X16, TX_16X4, TX_INVALID,
  // 16x32, 32x16, 32x32,
  TX_8X32, TX_32X8, TX_INVALID,
  // 32x64, 64x32, 64x64
  TX_INVALID, TX_INVALID, TX_INVALID,
#if CONFIG_EXT_PARTITION
  // 64x128, 128x64, 128x128
  TX_INVALID, TX_INVALID, TX_INVALID,
#endif
680 681
  // 4x16,    16x4,       8x32
  TX_4X16,    TX_16X4,    TX_8X32,
682
  // 32x8     16x64       64x16
683 684 685 686 687
  TX_32X8,    TX_INVALID, TX_INVALID,
#if CONFIG_EXT_PARTITION
  // 32x128   128x32
  TX_INVALID, TX_INVALID
#endif  // CONFIG_EXT_PARTITION
688
};
Yue Chen's avatar
Yue Chen committed
689
#endif
Jingning Han's avatar
Jingning Han committed
690 691
#else
#define max_txsize_rect_lookup max_txsize_lookup
692
#endif  // CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX)
693

694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
static const TX_TYPE_1D vtx_tab[TX_TYPES] = {
  DCT_1D,      ADST_1D, DCT_1D,      ADST_1D,
#if CONFIG_EXT_TX
  FLIPADST_1D, DCT_1D,  FLIPADST_1D, ADST_1D, FLIPADST_1D, IDTX_1D,
  DCT_1D,      IDTX_1D, ADST_1D,     IDTX_1D, FLIPADST_1D, IDTX_1D,
#endif  // CONFIG_EXT_TX
};

static const TX_TYPE_1D htx_tab[TX_TYPES] = {
  DCT_1D,  DCT_1D,      ADST_1D,     ADST_1D,
#if CONFIG_EXT_TX
  DCT_1D,  FLIPADST_1D, FLIPADST_1D, FLIPADST_1D, ADST_1D, IDTX_1D,
  IDTX_1D, DCT_1D,      IDTX_1D,     ADST_1D,     IDTX_1D, FLIPADST_1D,
#endif  // CONFIG_EXT_TX
};

710
#if CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX)
711 712 713
// Same as "max_txsize_lookup[bsize] - TX_8X8", except for rectangular
// block which may use a rectangular transform, in which  case it is
// "(max_txsize_lookup[bsize] + 1) - TX_8X8", invalid for bsize < 8X8
714
static const int32_t intra_tx_size_cat_lookup[BLOCK_SIZES_ALL] = {
715
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
716 717
  // 2X2,             2X4,                4X2,
  INT32_MIN,          INT32_MIN,          INT32_MIN,
718
#endif
719 720 721 722
  //                                      4X4,
                                          INT32_MIN,
  // 4X8,             8X4,                8X8,
  TX_8X8 - TX_8X8,    TX_8X8 - TX_8X8,    TX_8X8 - TX_8X8,
723
  // 8X16,            16X8,               16X16
724
  TX_16X16 - TX_8X8,  TX_16X16 - TX_8X8,  TX_16X16 - TX_8X8,
725
  // 16X32,           32X16,              32X32
726
  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8,
727
#if CONFIG_TX64X64
728 729
  // 32X64,           64X32,
  TX_64X64 - TX_8X8,  TX_64X64 - TX_8X8,
730 731 732 733 734 735 736
  // 64X64
  TX_64X64 - TX_8X8,
#if CONFIG_EXT_PARTITION
  // 64x128,          128x64,             128x128
  TX_64X64 - TX_8X8,  TX_64X64 - TX_8X8,  TX_64X64 - TX_8X8,
#endif  // CONFIG_EXT_PARTITION
#else
737 738
  // 32X64,           64X32,
  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8,
739 740
  // 64X64
  TX_32X32 - TX_8X8,
741 742 743 744
#if CONFIG_EXT_PARTITION
  // 64x128,          128x64,             128x128
  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8,
#endif  // CONFIG_EXT_PARTITION
745
#endif  // CONFIG_TX64X64
746 747
  // TODO(david.barker): Change these if we support rectangular transforms
  // for 4:1 shaped partitions
748 749 750
  // 4x16,            16x4,               8x32
  TX_8X8 - TX_8X8,    TX_8X8 - TX_8X8,    TX_8X8 - TX_8X8,
  // 32x8,            16x64,              64x16
751 752 753 754 755
  TX_8X8 - TX_8X8,    TX_16X16 - TX_8X8,  TX_16X16 - TX_8X8,
#if CONFIG_EXT_PARTITION
  // 32x128,          128x32
  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8
#endif  // CONFIG_EXT_PARTITION
756
};
757 758
#else
// Same as "max_txsize_lookup[bsize] - TX_8X8", invalid for bsize < 8X8
759
static const int32_t intra_tx_size_cat_lookup[BLOCK_SIZES_ALL] = {
760
#if CONFIG_CHROMA_SUB8X8
Jingning Han's avatar
Jingning Han committed
761 762 763
  // 2X2,             2X4,                4X2,
  INT32_MIN,          INT32_MIN,          INT32_MIN,
#endif
764 765 766
  //                                      4X4
                                          INT32_MIN,
  // 4X8,             8X4,                8X8
767
  INT32_MIN,          INT32_MIN,          TX_8X8 - TX_8X8,
768
  // 8X16,            16X8,               16X16
769
  TX_8X8 - TX_8X8,    TX_8X8 - TX_8X8,    TX_16X16 - TX_8X8,
770
  // 16X32,           32X16,              32X32
771
  TX_16X16 - TX_8X8,  TX_16X16 - TX_8X8,  TX_32X32 - TX_8X8,
772
#if CONFIG_TX64X64
773 774
  // 32X64,           64X32,
  TX_64X64 - TX_8X8,  TX_64X64 - TX_8X8,
775 776 777 778 779 780 781
  // 64X64
  TX_64X64 - TX_8X8,
#if CONFIG_EXT_PARTITION
  // 64x128,          128x64,             128x128
  TX_64X64 - TX_8X8,  TX_64X64 - TX_8X8,  TX_64X64 - TX_8X8,
#endif  // CONFIG_EXT_PARTITION
#else
782 783
  // 32X64,           64X32,
  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8,
784 785
  // 64X64
  TX_32X32 - TX_8X8,
786 787 788 789
#if CONFIG_EXT_PARTITION
  // 64x128,          128x64,             128x128
  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8,
#endif  // CONFIG_EXT_PARTITION
790
#endif  // CONFIG_TX64X64
791 792 793
  // 4x16,            16x4,               8x32
  TX_8X8 - TX_8X8,    TX_8X8 - TX_8X8,    TX_8X8 - TX_8X8,
  // 32x8             16x64,              64x16
Debargha Mukherjee's avatar
Debargha Mukherjee committed
794
  TX_8X8 - TX_8X8,    TX_16X16 - TX_8X8,  TX_16X16 - TX_8X8,
795 796 797 798
#if CONFIG_EXT_PARTITION
  // 32x128,          128x32
  TX_32X32 - TX_8X8,  TX_32X32 - TX_8X8
#endif  // CONFIG_EXT_PARTITION
799
};
800
#endif  // CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX)
801

802 803
#define inter_tx_size_cat_lookup intra_tx_size_cat_lookup

clang-format's avatar
clang-format committed
804
/* clang-format on */
805

806 807 808 809 810
static const TX_SIZE sub_tx_size_map[TX_SIZES_ALL] = {
  TX_4X4,    // TX_4X4
  TX_4X4,    // TX_8X8
  TX_8X8,    // TX_16X16
  TX_16X16,  // TX_32X32
811 812 813
#if CONFIG_TX64X64
  TX_32X32,  // TX_64X64
#endif       // CONFIG_TX64X64
814 815 816 817 818
  TX_4X4,    // TX_4X8
  TX_4X4,    // TX_8X4
  TX_8X8,    // TX_8X16
  TX_8X8,    // TX_16X8
  TX_16X16,  // TX_16X32
819
  TX_16X16,  // TX_32X16
820 821 822 823
#if CONFIG_TX64X64
  TX_32X32,  // TX_32X64
  TX_32X32,  // TX_64X32
#endif       // CONFIG_TX64X64
824 825 826 827
  TX_4X4,    // TX_4X16
  TX_4X4,    // TX_16X4
  TX_8X8,    // TX_8X32
  TX_8X8,    // TX_32X8
828 829
};

830 831 832 833 834
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
835 836 837
#if CONFIG_TX64X64
  TX_64X64,  // TX_64X64
#endif       // CONFIG_TX64X64
838 839 840 841 842
  TX_4X4,    // TX_4X8
  TX_8X8,    // TX_8X4
  TX_8X8,    // TX_8X16
  TX_16X16,  // TX_16X8
  TX_16X16,  // TX_16X32
843
  TX_32X32,  // TX_32X16
844 845 846 847
#if CONFIG_TX64X64
  TX_32X32,  // TX_32X64
  TX_64X64,  // TX_64X32
#endif       // CONFIG_TX64X64
848 849 850 851
  TX_4X4,    // TX_4X16
  TX_16X16,  // TX_16X4
  TX_8X8,    // TX_8X32
  TX_32X32,  // TX_32X8
852 853 854 855 856 857 858
};

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
859 860 861
#if CONFIG_TX64X64
  TX_64X64,  // TX_64X64
#endif       // CONFIG_TX64X64
862 863 864 865 866
  TX_8X8,    // TX_4X8
  TX_4X4,    // TX_8X4
  TX_16X16,  // TX_8X16
  TX_8X8,    // TX_16X8
  TX_32X32,  // TX_16X32
867
  TX_16X16,  // TX_32X16
868 869 870 871
#if CONFIG_TX64X64
  TX_64X64,  // TX_32X64
  TX_32X32,  // TX_64X32
#endif       // CONFIG_TX64X64
872 873 874 875
  TX_16X16,  // TX_4X16
  TX_4X4,    // TX_16X4
  TX_32X32,  // TX_8X32
  TX_8X8,    // TX_32X8
876 877
};

Angie Chiang's avatar
Angie Chiang committed
878 879
#define TX_SIZE_W_MIN 4

880
// Transform block width in pixels
881
static const int tx_size_wide[TX_SIZES_ALL] = { 4,  8,  16, 32,
882
#if CONFIG_TX64X64
883
                                                64,
884
#endif  // CONFIG_TX64X64
885
                                                4,  8,  8,  16, 16, 32,
886
#if CONFIG_TX64X64
887
                                                32, 64,
888
#endif  // CONFIG_TX64X64
889
                                                4,  16, 8,  32 };
890

Angie Chiang's avatar
Angie Chiang committed
891 892
#define TX_SIZE_H_MIN 4

893
// Transform block height in pixels
894
static const int tx_size_high[TX_SIZES_ALL] = { 4,  8,  16, 32,
895
#if CONFIG_TX64X64
896
                                                64,
897
#endif  // CONFIG_TX64X64
898
                                                8,  4,  16, 8,  32, 16,
899
#if CONFIG_TX64X64
900
                                                64, 32,
901
#endif  // CONFIG_TX64X64
902
                                                16, 4,  32, 8 };
903 904

// Transform block width in unit
905
static const int tx_size_wide_unit[TX_SIZES_ALL] = { 1,  2,  4, 8,
906
#if CONFIG_TX64X64
907
                                                     16,
908
#endif  // CONFIG_TX64X64
909
                                                     1,  2,  2, 4, 4, 8,
910
#if CONFIG_TX64X64
911
                                                     8,  16,
912
#endif  // CONFIG_TX64X64
913
                                                     1,  4,  2, 8 };
914 915

// Transform block height in unit
916
static const int tx_size_high_unit[TX_SIZES_ALL] = { 1,  2, 4, 8,
917
#if CONFIG_TX64X64
918
                                                     16,
919
#endif  // CONFIG_TX64X64
920
                                                     2,  1, 4, 2, 8, 4,
921
#if CONFIG_TX64X64
922
                                                     16, 8,
923
#endif  // CONFIG_TX64X64
924
                                                     4,  1, 8, 2 };
Jingning Han's avatar
Jingning Han committed
925

926
// Transform block width in log2
927
static const int tx_size_wide_log2[TX_SIZES_ALL] = { 2, 3, 4, 5,
928
#if CONFIG_TX64X64
929
                                                     6,
930
#endif  // CONFIG_TX64X64
931
                                                     2, 3, 3, 4, 4, 5,
932
#if CONFIG_TX64X64
933
                                                     5, 6,
934
#endif  // CONFIG_TX64X64
935
                                                     2, 4, 3, 5 };
936 937

// Transform block height in log2
938
static const int tx_size_high_log2[TX_SIZES_ALL] = { 2, 3, 4, 5,
939
#if CONFIG_TX64X64
940
                                                     6