1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "vp9/common/vp9_common_data.h"
12 #include "vpx_dsp/vpx_dsp_common.h"
13 
14 // Log 2 conversion lookup tables for block width and height
15 const uint8_t b_width_log2_lookup[BLOCK_SIZES] =
16   {0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4};
17 const uint8_t b_height_log2_lookup[BLOCK_SIZES] =
18   {0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4};
19 const uint8_t num_4x4_blocks_wide_lookup[BLOCK_SIZES] =
20   {1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16};
21 const uint8_t num_4x4_blocks_high_lookup[BLOCK_SIZES] =
22   {1, 2, 1, 2, 4, 2, 4, 8, 4, 8, 16, 8, 16};
23 // Log 2 conversion lookup tables for modeinfo width and height
24 const uint8_t mi_width_log2_lookup[BLOCK_SIZES] =
25   {0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3};
26 const uint8_t num_8x8_blocks_wide_lookup[BLOCK_SIZES] =
27   {1, 1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 8, 8};
28 const uint8_t num_8x8_blocks_high_lookup[BLOCK_SIZES] =
29   {1, 1, 1, 1, 2, 1, 2, 4, 2, 4, 8, 4, 8};
30 
31 // VPXMIN(3, VPXMIN(b_width_log2(bsize), b_height_log2(bsize)))
32 const uint8_t size_group_lookup[BLOCK_SIZES] =
33   {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3};
34 
35 const uint8_t num_pels_log2_lookup[BLOCK_SIZES] =
36   {4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12};
37 
38 const PARTITION_TYPE partition_lookup[][BLOCK_SIZES] = {
39   {  // 4X4
40     // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
41     PARTITION_NONE, PARTITION_INVALID, PARTITION_INVALID,
42     PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
43     PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
44     PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
45     PARTITION_INVALID
46   }, {  // 8X8
47     // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
48     PARTITION_SPLIT, PARTITION_VERT, PARTITION_HORZ, PARTITION_NONE,
49     PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
50     PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
51     PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID
52   }, {  // 16X16
53     // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
54     PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT,
55     PARTITION_VERT, PARTITION_HORZ, PARTITION_NONE, PARTITION_INVALID,
56     PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
57     PARTITION_INVALID, PARTITION_INVALID
58   }, {  // 32X32
59     // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
60     PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT,
61     PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_VERT,
62     PARTITION_HORZ, PARTITION_NONE, PARTITION_INVALID,
63     PARTITION_INVALID, PARTITION_INVALID
64   }, {  // 64X64
65     // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
66     PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT,
67     PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT,
68     PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_VERT, PARTITION_HORZ,
69     PARTITION_NONE
70   }
71 };
72 
73 const BLOCK_SIZE subsize_lookup[PARTITION_TYPES][BLOCK_SIZES] = {
74   {     // PARTITION_NONE
75     BLOCK_4X4,   BLOCK_4X8,   BLOCK_8X4,
76     BLOCK_8X8,   BLOCK_8X16,  BLOCK_16X8,
77     BLOCK_16X16, BLOCK_16X32, BLOCK_32X16,
78     BLOCK_32X32, BLOCK_32X64, BLOCK_64X32,
79     BLOCK_64X64,
80   }, {  // PARTITION_HORZ
81     BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
82     BLOCK_8X4,     BLOCK_INVALID, BLOCK_INVALID,
83     BLOCK_16X8,    BLOCK_INVALID, BLOCK_INVALID,
84     BLOCK_32X16,   BLOCK_INVALID, BLOCK_INVALID,
85     BLOCK_64X32,
86   }, {  // PARTITION_VERT
87     BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
88     BLOCK_4X8,     BLOCK_INVALID, BLOCK_INVALID,
89     BLOCK_8X16,    BLOCK_INVALID, BLOCK_INVALID,
90     BLOCK_16X32,   BLOCK_INVALID, BLOCK_INVALID,
91     BLOCK_32X64,
92   }, {  // PARTITION_SPLIT
93     BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
94     BLOCK_4X4,     BLOCK_INVALID, BLOCK_INVALID,
95     BLOCK_8X8,     BLOCK_INVALID, BLOCK_INVALID,
96     BLOCK_16X16,   BLOCK_INVALID, BLOCK_INVALID,
97     BLOCK_32X32,
98   }
99 };
100 
101 const TX_SIZE max_txsize_lookup[BLOCK_SIZES] = {
102   TX_4X4,   TX_4X4,   TX_4X4,
103   TX_8X8,   TX_8X8,   TX_8X8,
104   TX_16X16, TX_16X16, TX_16X16,
105   TX_32X32, TX_32X32, TX_32X32, TX_32X32
106 };
107 
108 const BLOCK_SIZE txsize_to_bsize[TX_SIZES] = {
109     BLOCK_4X4,  // TX_4X4
110     BLOCK_8X8,  // TX_8X8
111     BLOCK_16X16,  // TX_16X16
112     BLOCK_32X32,  // TX_32X32
113 };
114 
115 const TX_SIZE tx_mode_to_biggest_tx_size[TX_MODES] = {
116   TX_4X4,  // ONLY_4X4
117   TX_8X8,  // ALLOW_8X8
118   TX_16X16,  // ALLOW_16X16
119   TX_32X32,  // ALLOW_32X32
120   TX_32X32,  // TX_MODE_SELECT
121 };
122 
123 const BLOCK_SIZE ss_size_lookup[BLOCK_SIZES][2][2] = {
124 //  ss_x == 0    ss_x == 0        ss_x == 1      ss_x == 1
125 //  ss_y == 0    ss_y == 1        ss_y == 0      ss_y == 1
126   {{BLOCK_4X4,   BLOCK_INVALID}, {BLOCK_INVALID, BLOCK_INVALID}},
127   {{BLOCK_4X8,   BLOCK_4X4},     {BLOCK_INVALID, BLOCK_INVALID}},
128   {{BLOCK_8X4,   BLOCK_INVALID}, {BLOCK_4X4,     BLOCK_INVALID}},
129   {{BLOCK_8X8,   BLOCK_8X4},     {BLOCK_4X8,     BLOCK_4X4}},
130   {{BLOCK_8X16,  BLOCK_8X8},     {BLOCK_INVALID, BLOCK_4X8}},
131   {{BLOCK_16X8,  BLOCK_INVALID}, {BLOCK_8X8,     BLOCK_8X4}},
132   {{BLOCK_16X16, BLOCK_16X8},    {BLOCK_8X16,    BLOCK_8X8}},
133   {{BLOCK_16X32, BLOCK_16X16},   {BLOCK_INVALID, BLOCK_8X16}},
134   {{BLOCK_32X16, BLOCK_INVALID}, {BLOCK_16X16,   BLOCK_16X8}},
135   {{BLOCK_32X32, BLOCK_32X16},   {BLOCK_16X32,   BLOCK_16X16}},
136   {{BLOCK_32X64, BLOCK_32X32},   {BLOCK_INVALID, BLOCK_16X32}},
137   {{BLOCK_64X32, BLOCK_INVALID}, {BLOCK_32X32,   BLOCK_32X16}},
138   {{BLOCK_64X64, BLOCK_64X32},   {BLOCK_32X64,   BLOCK_32X32}},
139 };
140 
141 // Generates 4 bit field in which each bit set to 1 represents
142 // a blocksize partition  1111 means we split 64x64, 32x32, 16x16
143 // and 8x8.  1000 means we just split the 64x64 to 32x32
144 const struct {
145   PARTITION_CONTEXT above;
146   PARTITION_CONTEXT left;
147 } partition_context_lookup[BLOCK_SIZES]= {
148   {15, 15},  // 4X4   - {0b1111, 0b1111}
149   {15, 14},  // 4X8   - {0b1111, 0b1110}
150   {14, 15},  // 8X4   - {0b1110, 0b1111}
151   {14, 14},  // 8X8   - {0b1110, 0b1110}
152   {14, 12},  // 8X16  - {0b1110, 0b1100}
153   {12, 14},  // 16X8  - {0b1100, 0b1110}
154   {12, 12},  // 16X16 - {0b1100, 0b1100}
155   {12, 8 },  // 16X32 - {0b1100, 0b1000}
156   {8,  12},  // 32X16 - {0b1000, 0b1100}
157   {8,  8 },  // 32X32 - {0b1000, 0b1000}
158   {8,  0 },  // 32X64 - {0b1000, 0b0000}
159   {0,  8 },  // 64X32 - {0b0000, 0b1000}
160   {0,  0 },  // 64X64 - {0b0000, 0b0000}
161 };
162