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