• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef AOM_AV1_COMMON_COMMON_DATA_H_
13 #define AOM_AV1_COMMON_COMMON_DATA_H_
14 
15 #include "av1/common/enums.h"
16 #include "aom/aom_integer.h"
17 #include "aom_dsp/aom_dsp_common.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 // Log 2 conversion lookup tables in units of mode info (4x4).
24 // The Mi_Width_Log2 table in the spec (Section 9.3. Conversion tables).
25 static const uint8_t mi_size_wide_log2[BLOCK_SIZES_ALL] = {
26   0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 0, 2, 1, 3, 2, 4
27 };
28 // The Mi_Height_Log2 table in the spec (Section 9.3. Conversion tables).
29 static const uint8_t mi_size_high_log2[BLOCK_SIZES_ALL] = {
30   0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 2, 0, 3, 1, 4, 2
31 };
32 
33 // Width/height lookup tables in units of mode info (4x4).
34 // The Num_4x4_Blocks_Wide table in the spec (Section 9.3. Conversion tables).
35 static const uint8_t mi_size_wide[BLOCK_SIZES_ALL] = {
36   1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 1, 4, 2, 8, 4, 16
37 };
38 
39 // The Num_4x4_Blocks_High table in the spec (Section 9.3. Conversion tables).
40 static const uint8_t mi_size_high[BLOCK_SIZES_ALL] = {
41   1, 2, 1, 2, 4, 2, 4, 8, 4, 8, 16, 8, 16, 32, 16, 32, 4, 1, 8, 2, 16, 4
42 };
43 
44 // Width/height lookup tables in units of samples.
45 // The Block_Width table in the spec (Section 9.3. Conversion tables).
46 static const uint8_t block_size_wide[BLOCK_SIZES_ALL] = {
47   4,  4,  8,  8,   8,   16, 16, 16, 32, 32, 32,
48   64, 64, 64, 128, 128, 4,  16, 8,  32, 16, 64
49 };
50 
51 // The Block_Height table in the spec (Section 9.3. Conversion tables).
52 static const uint8_t block_size_high[BLOCK_SIZES_ALL] = {
53   4,  8,  4,   8,  16,  8,  16, 32, 16, 32, 64,
54   32, 64, 128, 64, 128, 16, 4,  32, 8,  64, 16
55 };
56 
57 // Maps a block size to a context.
58 // The Size_Group table in the spec (Section 9.3. Conversion tables).
59 // AOMMIN(3, AOMMIN(mi_size_wide_log2(bsize), mi_size_high_log2(bsize)))
60 static const uint8_t size_group_lookup[BLOCK_SIZES_ALL] = {
61   0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 0, 0, 1, 1, 2, 2
62 };
63 
64 static const uint8_t num_pels_log2_lookup[BLOCK_SIZES_ALL] = {
65   4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 13, 13, 14, 6, 6, 8, 8, 10, 10
66 };
67 
68 // A compressed version of the Partition_Subsize table in the spec (9.3.
69 // Conversion tables), for square block sizes only.
70 /* clang-format off */
71 static const BLOCK_SIZE subsize_lookup[EXT_PARTITION_TYPES][SQR_BLOCK_SIZES] = {
72   {     // PARTITION_NONE
73     BLOCK_4X4, BLOCK_8X8, BLOCK_16X16,
74     BLOCK_32X32, BLOCK_64X64, BLOCK_128X128
75   }, {  // PARTITION_HORZ
76     BLOCK_INVALID, BLOCK_8X4, BLOCK_16X8,
77     BLOCK_32X16, BLOCK_64X32, BLOCK_128X64
78   }, {  // PARTITION_VERT
79     BLOCK_INVALID, BLOCK_4X8, BLOCK_8X16,
80     BLOCK_16X32, BLOCK_32X64, BLOCK_64X128
81   }, {  // PARTITION_SPLIT
82     BLOCK_INVALID, BLOCK_4X4, BLOCK_8X8,
83     BLOCK_16X16, BLOCK_32X32, BLOCK_64X64
84   }, {  // PARTITION_HORZ_A
85     BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X8,
86     BLOCK_32X16, BLOCK_64X32, BLOCK_128X64
87   }, {  // PARTITION_HORZ_B
88     BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X8,
89     BLOCK_32X16, BLOCK_64X32, BLOCK_128X64
90   }, {  // PARTITION_VERT_A
91     BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X16,
92     BLOCK_16X32, BLOCK_32X64, BLOCK_64X128
93   }, {  // PARTITION_VERT_B
94     BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X16,
95     BLOCK_16X32, BLOCK_32X64, BLOCK_64X128
96   }, {  // PARTITION_HORZ_4
97     BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X4,
98     BLOCK_32X8, BLOCK_64X16, BLOCK_INVALID
99   }, {  // PARTITION_VERT_4
100     BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X16,
101     BLOCK_8X32, BLOCK_16X64, BLOCK_INVALID
102   }
103 };
104 
105 static const TX_SIZE max_txsize_lookup[BLOCK_SIZES_ALL] = {
106   //                   4X4
107                        TX_4X4,
108   // 4X8,    8X4,      8X8
109   TX_4X4,    TX_4X4,   TX_8X8,
110   // 8X16,   16X8,     16X16
111   TX_8X8,    TX_8X8,   TX_16X16,
112   // 16X32,  32X16,    32X32
113   TX_16X16,  TX_16X16, TX_32X32,
114   // 32X64,  64X32,
115   TX_32X32,  TX_32X32,
116   // 64X64
117   TX_64X64,
118   // 64x128, 128x64,   128x128
119   TX_64X64,  TX_64X64, TX_64X64,
120   // 4x16,   16x4,     8x32
121   TX_4X4,    TX_4X4,   TX_8X8,
122   // 32x8,   16x64     64x16
123   TX_8X8,    TX_16X16, TX_16X16
124 };
125 
126 static const TX_SIZE max_txsize_rect_lookup[BLOCK_SIZES_ALL] = {
127       // 4X4
128       TX_4X4,
129       // 4X8,    8X4,      8X8
130       TX_4X8,    TX_8X4,   TX_8X8,
131       // 8X16,   16X8,     16X16
132       TX_8X16,   TX_16X8,  TX_16X16,
133       // 16X32,  32X16,    32X32
134       TX_16X32,  TX_32X16, TX_32X32,
135       // 32X64,  64X32,
136       TX_32X64,  TX_64X32,
137       // 64X64
138       TX_64X64,
139       // 64x128, 128x64,   128x128
140       TX_64X64,  TX_64X64, TX_64X64,
141       // 4x16,   16x4,
142       TX_4X16,   TX_16X4,
143       // 8x32,   32x8
144       TX_8X32,   TX_32X8,
145       // 16x64,  64x16
146       TX_16X64,  TX_64X16
147 };
148 
149 static const TX_TYPE_1D vtx_tab[TX_TYPES] = {
150   DCT_1D,      ADST_1D, DCT_1D,      ADST_1D,
151   FLIPADST_1D, DCT_1D,  FLIPADST_1D, ADST_1D, FLIPADST_1D, IDTX_1D,
152   DCT_1D,      IDTX_1D, ADST_1D,     IDTX_1D, FLIPADST_1D, IDTX_1D,
153 };
154 
155 static const TX_TYPE_1D htx_tab[TX_TYPES] = {
156   DCT_1D,  DCT_1D,      ADST_1D,     ADST_1D,
157   DCT_1D,  FLIPADST_1D, FLIPADST_1D, FLIPADST_1D, ADST_1D, IDTX_1D,
158   IDTX_1D, DCT_1D,      IDTX_1D,     ADST_1D,     IDTX_1D, FLIPADST_1D,
159 };
160 
161 #define TXSIZE_CAT_INVALID (-1)
162 
163 /* clang-format on */
164 
165 static const TX_SIZE sub_tx_size_map[TX_SIZES_ALL] = {
166   TX_4X4,    // TX_4X4
167   TX_4X4,    // TX_8X8
168   TX_8X8,    // TX_16X16
169   TX_16X16,  // TX_32X32
170   TX_32X32,  // TX_64X64
171   TX_4X4,    // TX_4X8
172   TX_4X4,    // TX_8X4
173   TX_8X8,    // TX_8X16
174   TX_8X8,    // TX_16X8
175   TX_16X16,  // TX_16X32
176   TX_16X16,  // TX_32X16
177   TX_32X32,  // TX_32X64
178   TX_32X32,  // TX_64X32
179   TX_4X8,    // TX_4X16
180   TX_8X4,    // TX_16X4
181   TX_8X16,   // TX_8X32
182   TX_16X8,   // TX_32X8
183   TX_16X32,  // TX_16X64
184   TX_32X16,  // TX_64X16
185 };
186 
187 static const TX_SIZE txsize_horz_map[TX_SIZES_ALL] = {
188   TX_4X4,    // TX_4X4
189   TX_8X8,    // TX_8X8
190   TX_16X16,  // TX_16X16
191   TX_32X32,  // TX_32X32
192   TX_64X64,  // TX_64X64
193   TX_4X4,    // TX_4X8
194   TX_8X8,    // TX_8X4
195   TX_8X8,    // TX_8X16
196   TX_16X16,  // TX_16X8
197   TX_16X16,  // TX_16X32
198   TX_32X32,  // TX_32X16
199   TX_32X32,  // TX_32X64
200   TX_64X64,  // TX_64X32
201   TX_4X4,    // TX_4X16
202   TX_16X16,  // TX_16X4
203   TX_8X8,    // TX_8X32
204   TX_32X32,  // TX_32X8
205   TX_16X16,  // TX_16X64
206   TX_64X64,  // TX_64X16
207 };
208 
209 static const TX_SIZE txsize_vert_map[TX_SIZES_ALL] = {
210   TX_4X4,    // TX_4X4
211   TX_8X8,    // TX_8X8
212   TX_16X16,  // TX_16X16
213   TX_32X32,  // TX_32X32
214   TX_64X64,  // TX_64X64
215   TX_8X8,    // TX_4X8
216   TX_4X4,    // TX_8X4
217   TX_16X16,  // TX_8X16
218   TX_8X8,    // TX_16X8
219   TX_32X32,  // TX_16X32
220   TX_16X16,  // TX_32X16
221   TX_64X64,  // TX_32X64
222   TX_32X32,  // TX_64X32
223   TX_16X16,  // TX_4X16
224   TX_4X4,    // TX_16X4
225   TX_32X32,  // TX_8X32
226   TX_8X8,    // TX_32X8
227   TX_64X64,  // TX_16X64
228   TX_16X16,  // TX_64X16
229 };
230 
231 #define TX_SIZE_W_MIN 4
232 
233 // Transform block width in pixels
234 static const int tx_size_wide[TX_SIZES_ALL] = {
235   4, 8, 16, 32, 64, 4, 8, 8, 16, 16, 32, 32, 64, 4, 16, 8, 32, 16, 64,
236 };
237 
238 #define TX_SIZE_H_MIN 4
239 
240 // Transform block height in pixels
241 static const int tx_size_high[TX_SIZES_ALL] = {
242   4, 8, 16, 32, 64, 8, 4, 16, 8, 32, 16, 64, 32, 16, 4, 32, 8, 64, 16,
243 };
244 
245 // Transform block width in unit
246 static const int tx_size_wide_unit[TX_SIZES_ALL] = {
247   1, 2, 4, 8, 16, 1, 2, 2, 4, 4, 8, 8, 16, 1, 4, 2, 8, 4, 16,
248 };
249 
250 // Transform block height in unit
251 static const int tx_size_high_unit[TX_SIZES_ALL] = {
252   1, 2, 4, 8, 16, 2, 1, 4, 2, 8, 4, 16, 8, 4, 1, 8, 2, 16, 4,
253 };
254 
255 // Transform block width in log2
256 static const int tx_size_wide_log2[TX_SIZES_ALL] = {
257   2, 3, 4, 5, 6, 2, 3, 3, 4, 4, 5, 5, 6, 2, 4, 3, 5, 4, 6,
258 };
259 
260 // Transform block width in log2 unit
261 static const int tx_size_wide_unit_log2[TX_SIZES_ALL] = {
262   0, 1, 2, 3, 4, 0, 1, 1, 2, 2, 3, 3, 4, 0, 2, 1, 3, 2, 4,
263 };
264 
265 // Transform block height in log2
266 static const int tx_size_high_log2[TX_SIZES_ALL] = {
267   2, 3, 4, 5, 6, 3, 2, 4, 3, 5, 4, 6, 5, 4, 2, 5, 3, 6, 4,
268 };
269 
270 // Transform block height in log2 unit
271 static const int tx_size_high_unit_log2[TX_SIZES_ALL] = {
272   0, 1, 2, 3, 4, 1, 0, 2, 1, 3, 2, 4, 3, 2, 0, 3, 1, 4, 2,
273 };
274 
275 static const int tx_size_2d[TX_SIZES_ALL + 1] = {
276   16,  64,   256,  1024, 4096, 32,  32,  128,  128,  512,
277   512, 2048, 2048, 64,   64,   256, 256, 1024, 1024,
278 };
279 
280 static const BLOCK_SIZE txsize_to_bsize[TX_SIZES_ALL] = {
281   BLOCK_4X4,    // TX_4X4
282   BLOCK_8X8,    // TX_8X8
283   BLOCK_16X16,  // TX_16X16
284   BLOCK_32X32,  // TX_32X32
285   BLOCK_64X64,  // TX_64X64
286   BLOCK_4X8,    // TX_4X8
287   BLOCK_8X4,    // TX_8X4
288   BLOCK_8X16,   // TX_8X16
289   BLOCK_16X8,   // TX_16X8
290   BLOCK_16X32,  // TX_16X32
291   BLOCK_32X16,  // TX_32X16
292   BLOCK_32X64,  // TX_32X64
293   BLOCK_64X32,  // TX_64X32
294   BLOCK_4X16,   // TX_4X16
295   BLOCK_16X4,   // TX_16X4
296   BLOCK_8X32,   // TX_8X32
297   BLOCK_32X8,   // TX_32X8
298   BLOCK_16X64,  // TX_16X64
299   BLOCK_64X16,  // TX_64X16
300 };
301 
302 static const TX_SIZE txsize_sqr_map[TX_SIZES_ALL] = {
303   TX_4X4,    // TX_4X4
304   TX_8X8,    // TX_8X8
305   TX_16X16,  // TX_16X16
306   TX_32X32,  // TX_32X32
307   TX_64X64,  // TX_64X64
308   TX_4X4,    // TX_4X8
309   TX_4X4,    // TX_8X4
310   TX_8X8,    // TX_8X16
311   TX_8X8,    // TX_16X8
312   TX_16X16,  // TX_16X32
313   TX_16X16,  // TX_32X16
314   TX_32X32,  // TX_32X64
315   TX_32X32,  // TX_64X32
316   TX_4X4,    // TX_4X16
317   TX_4X4,    // TX_16X4
318   TX_8X8,    // TX_8X32
319   TX_8X8,    // TX_32X8
320   TX_16X16,  // TX_16X64
321   TX_16X16,  // TX_64X16
322 };
323 
324 static const TX_SIZE txsize_sqr_up_map[TX_SIZES_ALL] = {
325   TX_4X4,    // TX_4X4
326   TX_8X8,    // TX_8X8
327   TX_16X16,  // TX_16X16
328   TX_32X32,  // TX_32X32
329   TX_64X64,  // TX_64X64
330   TX_8X8,    // TX_4X8
331   TX_8X8,    // TX_8X4
332   TX_16X16,  // TX_8X16
333   TX_16X16,  // TX_16X8
334   TX_32X32,  // TX_16X32
335   TX_32X32,  // TX_32X16
336   TX_64X64,  // TX_32X64
337   TX_64X64,  // TX_64X32
338   TX_16X16,  // TX_4X16
339   TX_16X16,  // TX_16X4
340   TX_32X32,  // TX_8X32
341   TX_32X32,  // TX_32X8
342   TX_64X64,  // TX_16X64
343   TX_64X64,  // TX_64X16
344 };
345 
346 static const int8_t txsize_log2_minus4[TX_SIZES_ALL] = {
347   0,  // TX_4X4
348   2,  // TX_8X8
349   4,  // TX_16X16
350   6,  // TX_32X32
351   6,  // TX_64X64
352   1,  // TX_4X8
353   1,  // TX_8X4
354   3,  // TX_8X16
355   3,  // TX_16X8
356   5,  // TX_16X32
357   5,  // TX_32X16
358   6,  // TX_32X64
359   6,  // TX_64X32
360   2,  // TX_4X16
361   2,  // TX_16X4
362   4,  // TX_8X32
363   4,  // TX_32X8
364   5,  // TX_16X64
365   5,  // TX_64X16
366 };
367 
368 static const TX_SIZE tx_mode_to_biggest_tx_size[TX_MODES] = {
369   TX_4X4,    // ONLY_4X4
370   TX_64X64,  // TX_MODE_LARGEST
371   TX_64X64,  // TX_MODE_SELECT
372 };
373 
374 // The Subsampled_Size table in the spec (Section 5.11.38. Get plane residual
375 // size function).
376 extern const BLOCK_SIZE av1_ss_size_lookup[BLOCK_SIZES_ALL][2][2];
377 
378 // Generates 5 bit field in which each bit set to 1 represents
379 // a blocksize partition  11111 means we split 128x128, 64x64, 32x32, 16x16
380 // and 8x8.  10000 means we just split the 128x128 to 64x64
381 /* clang-format off */
382 static const struct {
383   PARTITION_CONTEXT above;
384   PARTITION_CONTEXT left;
385 } partition_context_lookup[BLOCK_SIZES_ALL] = {
386   { 31, 31 },  // 4X4   - {0b11111, 0b11111}
387   { 31, 30 },  // 4X8   - {0b11111, 0b11110}
388   { 30, 31 },  // 8X4   - {0b11110, 0b11111}
389   { 30, 30 },  // 8X8   - {0b11110, 0b11110}
390   { 30, 28 },  // 8X16  - {0b11110, 0b11100}
391   { 28, 30 },  // 16X8  - {0b11100, 0b11110}
392   { 28, 28 },  // 16X16 - {0b11100, 0b11100}
393   { 28, 24 },  // 16X32 - {0b11100, 0b11000}
394   { 24, 28 },  // 32X16 - {0b11000, 0b11100}
395   { 24, 24 },  // 32X32 - {0b11000, 0b11000}
396   { 24, 16 },  // 32X64 - {0b11000, 0b10000}
397   { 16, 24 },  // 64X32 - {0b10000, 0b11000}
398   { 16, 16 },  // 64X64 - {0b10000, 0b10000}
399   { 16, 0 },   // 64X128- {0b10000, 0b00000}
400   { 0, 16 },   // 128X64- {0b00000, 0b10000}
401   { 0, 0 },    // 128X128-{0b00000, 0b00000}
402   { 31, 28 },  // 4X16  - {0b11111, 0b11100}
403   { 28, 31 },  // 16X4  - {0b11100, 0b11111}
404   { 30, 24 },  // 8X32  - {0b11110, 0b11000}
405   { 24, 30 },  // 32X8  - {0b11000, 0b11110}
406   { 28, 16 },  // 16X64 - {0b11100, 0b10000}
407   { 16, 28 },  // 64X16 - {0b10000, 0b11100}
408 };
409 /* clang-format on */
410 
411 static const int intra_mode_context[INTRA_MODES] = {
412   0, 1, 2, 3, 4, 4, 4, 4, 3, 0, 1, 2, 0,
413 };
414 
415 // Note: this is also used in unit tests. So whenever one changes the table,
416 // the unit tests need to be changed accordingly.
417 static const int quant_dist_weight[4][2] = {
418   { 2, 3 }, { 2, 5 }, { 2, 7 }, { 1, MAX_FRAME_DISTANCE }
419 };
420 
421 static const int quant_dist_lookup_table[4][2] = {
422   { 9, 7 },
423   { 11, 5 },
424   { 12, 4 },
425   { 13, 3 },
426 };
427 
428 #ifdef __cplusplus
429 }  // extern "C"
430 #endif
431 
432 #endif  // AOM_AV1_COMMON_COMMON_DATA_H_
433