1 /*****************************************************************************
2 * Copyright (C) 2014 x265 project
4 * Authors: Steve Borho <steve@borho.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
25 #include "constants.h"
26 #include "threading.h"
30 static int initialized
/* = 0 */;
32 // initialize ROM variables
35 if (ATOMIC_CAS32(&initialized
, 0, 1) == 1)
41 if (ATOMIC_CAS32(&initialized
, 1, 0) == 0)
46 // lambda = pow(2, (double)q / 6 - 2);
47 double x265_lambda_tab
[QP_MAX_MAX
+ 1] =
49 0.2500, 0.2806, 0.3150, 0.3536, 0.3969,
50 0.4454, 0.5000, 0.5612, 0.6300, 0.7071,
51 0.7937, 0.8909, 1.0000, 1.1225, 1.2599,
52 1.4142, 1.5874, 1.7818, 2.0000, 2.2449,
53 2.5198, 2.8284, 3.1748, 3.5636, 4.0000,
54 4.4898, 5.0397, 5.6569, 6.3496, 7.1272,
55 8.0000, 8.9797, 10.0794, 11.3137, 12.6992,
56 14.2544, 16.0000, 17.9594, 20.1587, 22.6274,
57 25.3984, 28.5088, 32.0000, 35.9188, 40.3175,
58 45.2548, 50.7968, 57.0175, 64.0000, 71.8376,
59 80.6349, 90.5097, 101.5937, 114.0350, 128.0000,
60 143.6751, 161.2699, 181.0193, 203.1873, 228.0701,
61 256.0000, 287.3503, 322.5398, 362.0387, 406.3747,
62 456.1401, 512.0000, 574.7006, 645.0796, 724.0773
65 // lambda2 = pow(lambda, 2) * scale (0.85);
66 double x265_lambda2_tab
[QP_MAX_MAX
+ 1] =
68 0.0531, 0.0669, 0.0843, 0.1063, 0.1339,
69 0.1687, 0.2125, 0.2677, 0.3373, 0.4250,
70 0.5355, 0.6746, 0.8500, 1.0709, 1.3493,
71 1.7000, 2.1419, 2.6986, 3.4000, 4.2837,
72 5.3970, 6.8000, 8.5675, 10.7943, 13.6000,
73 17.1345, 21.5887, 27.2004, 34.2699, 43.1773,
74 54.4000, 68.5397, 86.3551, 108.7998, 137.0792,
75 172.7097, 217.6000, 274.1590, 345.4172, 435.1993,
76 548.3169, 690.8389, 870.4000, 1096.6362, 1381.6757,
77 1740.7974, 2193.2676, 2763.3460, 3481.6000, 4386.5446,
78 5526.6890, 6963.2049, 8773.0879, 11053.3840, 13926.4000,
79 17546.1542, 22106.7835, 27852.7889, 35092.3170, 44213.5749,
80 55705.6000, 70184.6657, 88427.1342, 111411.2172, 140369.3373,
81 176854.2222, 222822.4000, 280738.6627, 353708.5368, 445644.7459
84 const uint16_t x265_chroma_lambda2_offset_tab
[MAX_CHROMA_LAMBDA_OFFSET
+1] =
86 16, 20, 25, 32, 40, 50,
87 64, 80, 101, 128, 161, 203,
88 256, 322, 406, 512, 645, 812,
89 1024, 1290, 1625, 2048, 2580, 3250,
90 4096, 5160, 6501, 8192, 10321, 13003,
91 16384, 20642, 26007, 32768, 41285, 52015,
95 uint32_t g_maxLog2CUSize
= MAX_LOG2_CU_SIZE
;
96 uint32_t g_maxCUSize
= MAX_CU_SIZE
;
97 uint32_t g_maxFullDepth
= NUM_FULL_DEPTH
- 1;
98 uint32_t g_maxCUDepth
= NUM_CU_DEPTH
- 1;
99 uint32_t g_zscanToRaster
[MAX_NUM_PARTITIONS
] = { 0, };
100 uint32_t g_rasterToZscan
[MAX_NUM_PARTITIONS
] = { 0, };
102 const uint8_t g_zscanToPelX
[MAX_NUM_PARTITIONS
] =
104 0, 4, 0, 4, 8, 12, 8, 12, 0, 4, 0, 4, 8, 12, 8, 12,
105 16, 20, 16, 20, 24, 28, 24, 28, 16, 20, 16, 20, 24, 28, 24, 28,
106 0, 4, 0, 4, 8, 12, 8, 12, 0, 4, 0, 4, 8, 12, 8, 12,
107 16, 20, 16, 20, 24, 28, 24, 28, 16, 20, 16, 20, 24, 28, 24, 28,
108 32, 36, 32, 36, 40, 44, 40, 44, 32, 36, 32, 36, 40, 44, 40, 44,
109 48, 52, 48, 52, 56, 60, 56, 60, 48, 52, 48, 52, 56, 60, 56, 60,
110 32, 36, 32, 36, 40, 44, 40, 44, 32, 36, 32, 36, 40, 44, 40, 44,
111 48, 52, 48, 52, 56, 60, 56, 60, 48, 52, 48, 52, 56, 60, 56, 60,
112 0, 4, 0, 4, 8, 12, 8, 12, 0, 4, 0, 4, 8, 12, 8, 12,
113 16, 20, 16, 20, 24, 28, 24, 28, 16, 20, 16, 20, 24, 28, 24, 28,
114 0, 4, 0, 4, 8, 12, 8, 12, 0, 4, 0, 4, 8, 12, 8, 12,
115 16, 20, 16, 20, 24, 28, 24, 28, 16, 20, 16, 20, 24, 28, 24, 28,
116 32, 36, 32, 36, 40, 44, 40, 44, 32, 36, 32, 36, 40, 44, 40, 44,
117 48, 52, 48, 52, 56, 60, 56, 60, 48, 52, 48, 52, 56, 60, 56, 60,
118 32, 36, 32, 36, 40, 44, 40, 44, 32, 36, 32, 36, 40, 44, 40, 44,
119 48, 52, 48, 52, 56, 60, 56, 60, 48, 52, 48, 52, 56, 60, 56, 60
122 const uint8_t g_zscanToPelY
[MAX_NUM_PARTITIONS
] =
124 0, 0, 4, 4, 0, 0, 4, 4, 8, 8, 12, 12, 8, 8, 12, 12,
125 0, 0, 4, 4, 0, 0, 4, 4, 8, 8, 12, 12, 8, 8, 12, 12,
126 16, 16, 20, 20, 16, 16, 20, 20, 24, 24, 28, 28, 24, 24, 28, 28,
127 16, 16, 20, 20, 16, 16, 20, 20, 24, 24, 28, 28, 24, 24, 28, 28,
128 0, 0, 4, 4, 0, 0, 4, 4, 8, 8, 12, 12, 8, 8, 12, 12,
129 0, 0, 4, 4, 0, 0, 4, 4, 8, 8, 12, 12, 8, 8, 12, 12,
130 16, 16, 20, 20, 16, 16, 20, 20, 24, 24, 28, 28, 24, 24, 28, 28,
131 16, 16, 20, 20, 16, 16, 20, 20, 24, 24, 28, 28, 24, 24, 28, 28,
132 32, 32, 36, 36, 32, 32, 36, 36, 40, 40, 44, 44, 40, 40, 44, 44,
133 32, 32, 36, 36, 32, 32, 36, 36, 40, 40, 44, 44, 40, 40, 44, 44,
134 48, 48, 52, 52, 48, 48, 52, 52, 56, 56, 60, 60, 56, 56, 60, 60,
135 48, 48, 52, 52, 48, 48, 52, 52, 56, 56, 60, 60, 56, 56, 60, 60,
136 32, 32, 36, 36, 32, 32, 36, 36, 40, 40, 44, 44, 40, 40, 44, 44,
137 32, 32, 36, 36, 32, 32, 36, 36, 40, 40, 44, 44, 40, 40, 44, 44,
138 48, 48, 52, 52, 48, 48, 52, 52, 56, 56, 60, 60, 56, 56, 60, 60,
139 48, 48, 52, 52, 48, 48, 52, 52, 56, 56, 60, 60, 56, 56, 60, 60
142 void initZscanToRaster(uint32_t maxFullDepth
, uint32_t depth
, uint32_t startVal
, uint32_t*& curIdx
)
144 uint32_t stride
= 1 << maxFullDepth
;
146 if (depth
> maxFullDepth
)
148 curIdx
[0] = startVal
;
153 int step
= stride
>> depth
;
154 initZscanToRaster(maxFullDepth
, depth
+ 1, startVal
, curIdx
);
155 initZscanToRaster(maxFullDepth
, depth
+ 1, startVal
+ step
, curIdx
);
156 initZscanToRaster(maxFullDepth
, depth
+ 1, startVal
+ step
* stride
, curIdx
);
157 initZscanToRaster(maxFullDepth
, depth
+ 1, startVal
+ step
* stride
+ step
, curIdx
);
161 void initRasterToZscan(uint32_t maxFullDepth
)
163 uint32_t numPartitions
= 1 << (maxFullDepth
* 2);
165 for (uint32_t i
= 0; i
< numPartitions
; i
++)
166 g_rasterToZscan
[g_zscanToRaster
[i
]] = i
;
169 const int16_t g_lumaFilter
[4][NTAPS_LUMA
] =
171 { 0, 0, 0, 64, 0, 0, 0, 0 },
172 { -1, 4, -10, 58, 17, -5, 1, 0 },
173 { -1, 4, -11, 40, 40, -11, 4, -1 },
174 { 0, 1, -5, 17, 58, -10, 4, -1 }
177 const int16_t g_chromaFilter
[8][NTAPS_CHROMA
] =
189 const int16_t g_t4
[4][4] =
192 { 83, 36, -36, -83 },
193 { 64, -64, -64, 64 },
197 const int16_t g_t8
[8][8] =
199 { 64, 64, 64, 64, 64, 64, 64, 64 },
200 { 89, 75, 50, 18, -18, -50, -75, -89 },
201 { 83, 36, -36, -83, -83, -36, 36, 83 },
202 { 75, -18, -89, -50, 50, 89, 18, -75 },
203 { 64, -64, -64, 64, 64, -64, -64, 64 },
204 { 50, -89, 18, 75, -75, -18, 89, -50 },
205 { 36, -83, 83, -36, -36, 83, -83, 36 },
206 { 18, -50, 75, -89, 89, -75, 50, -18 }
209 const int16_t g_t16
[16][16] =
211 { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
212 { 90, 87, 80, 70, 57, 43, 25, 9, -9, -25, -43, -57, -70, -80, -87, -90 },
213 { 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89 },
214 { 87, 57, 9, -43, -80, -90, -70, -25, 25, 70, 90, 80, 43, -9, -57, -87 },
215 { 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83 },
216 { 80, 9, -70, -87, -25, 57, 90, 43, -43, -90, -57, 25, 87, 70, -9, -80 },
217 { 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75 },
218 { 70, -43, -87, 9, 90, 25, -80, -57, 57, 80, -25, -90, -9, 87, 43, -70 },
219 { 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64 },
220 { 57, -80, -25, 90, -9, -87, 43, 70, -70, -43, 87, 9, -90, 25, 80, -57 },
221 { 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50 },
222 { 43, -90, 57, 25, -87, 70, 9, -80, 80, -9, -70, 87, -25, -57, 90, -43 },
223 { 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36 },
224 { 25, -70, 90, -80, 43, 9, -57, 87, -87, 57, -9, -43, 80, -90, 70, -25 },
225 { 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18 },
226 { 9, -25, 43, -57, 70, -80, 87, -90, 90, -87, 80, -70, 57, -43, 25, -9 }
229 const int16_t g_t32
[32][32] =
231 { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
232 { 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4, -4, -13, -22, -31, -38, -46, -54, -61, -67, -73, -78, -82, -85, -88, -90, -90 },
233 { 90, 87, 80, 70, 57, 43, 25, 9, -9, -25, -43, -57, -70, -80, -87, -90, -90, -87, -80, -70, -57, -43, -25, -9, 9, 25, 43, 57, 70, 80, 87, 90 },
234 { 90, 82, 67, 46, 22, -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13, 13, 38, 61, 78, 88, 90, 85, 73, 54, 31, 4, -22, -46, -67, -82, -90 },
235 { 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89, 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89 },
236 { 88, 67, 31, -13, -54, -82, -90, -78, -46, -4, 38, 73, 90, 85, 61, 22, -22, -61, -85, -90, -73, -38, 4, 46, 78, 90, 82, 54, 13, -31, -67, -88 },
237 { 87, 57, 9, -43, -80, -90, -70, -25, 25, 70, 90, 80, 43, -9, -57, -87, -87, -57, -9, 43, 80, 90, 70, 25, -25, -70, -90, -80, -43, 9, 57, 87 },
238 { 85, 46, -13, -67, -90, -73, -22, 38, 82, 88, 54, -4, -61, -90, -78, -31, 31, 78, 90, 61, 4, -54, -88, -82, -38, 22, 73, 90, 67, 13, -46, -85 },
239 { 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83 },
240 { 82, 22, -54, -90, -61, 13, 78, 85, 31, -46, -90, -67, 4, 73, 88, 38, -38, -88, -73, -4, 67, 90, 46, -31, -85, -78, -13, 61, 90, 54, -22, -82 },
241 { 80, 9, -70, -87, -25, 57, 90, 43, -43, -90, -57, 25, 87, 70, -9, -80, -80, -9, 70, 87, 25, -57, -90, -43, 43, 90, 57, -25, -87, -70, 9, 80 },
242 { 78, -4, -82, -73, 13, 85, 67, -22, -88, -61, 31, 90, 54, -38, -90, -46, 46, 90, 38, -54, -90, -31, 61, 88, 22, -67, -85, -13, 73, 82, 4, -78 },
243 { 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75, 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75 },
244 { 73, -31, -90, -22, 78, 67, -38, -90, -13, 82, 61, -46, -88, -4, 85, 54, -54, -85, 4, 88, 46, -61, -82, 13, 90, 38, -67, -78, 22, 90, 31, -73 },
245 { 70, -43, -87, 9, 90, 25, -80, -57, 57, 80, -25, -90, -9, 87, 43, -70, -70, 43, 87, -9, -90, -25, 80, 57, -57, -80, 25, 90, 9, -87, -43, 70 },
246 { 67, -54, -78, 38, 85, -22, -90, 4, 90, 13, -88, -31, 82, 46, -73, -61, 61, 73, -46, -82, 31, 88, -13, -90, -4, 90, 22, -85, -38, 78, 54, -67 },
247 { 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64 },
248 { 61, -73, -46, 82, 31, -88, -13, 90, -4, -90, 22, 85, -38, -78, 54, 67, -67, -54, 78, 38, -85, -22, 90, 4, -90, 13, 88, -31, -82, 46, 73, -61 },
249 { 57, -80, -25, 90, -9, -87, 43, 70, -70, -43, 87, 9, -90, 25, 80, -57, -57, 80, 25, -90, 9, 87, -43, -70, 70, 43, -87, -9, 90, -25, -80, 57 },
250 { 54, -85, -4, 88, -46, -61, 82, 13, -90, 38, 67, -78, -22, 90, -31, -73, 73, 31, -90, 22, 78, -67, -38, 90, -13, -82, 61, 46, -88, 4, 85, -54 },
251 { 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50, 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50 },
252 { 46, -90, 38, 54, -90, 31, 61, -88, 22, 67, -85, 13, 73, -82, 4, 78, -78, -4, 82, -73, -13, 85, -67, -22, 88, -61, -31, 90, -54, -38, 90, -46 },
253 { 43, -90, 57, 25, -87, 70, 9, -80, 80, -9, -70, 87, -25, -57, 90, -43, -43, 90, -57, -25, 87, -70, -9, 80, -80, 9, 70, -87, 25, 57, -90, 43 },
254 { 38, -88, 73, -4, -67, 90, -46, -31, 85, -78, 13, 61, -90, 54, 22, -82, 82, -22, -54, 90, -61, -13, 78, -85, 31, 46, -90, 67, 4, -73, 88, -38 },
255 { 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36 },
256 { 31, -78, 90, -61, 4, 54, -88, 82, -38, -22, 73, -90, 67, -13, -46, 85, -85, 46, 13, -67, 90, -73, 22, 38, -82, 88, -54, -4, 61, -90, 78, -31 },
257 { 25, -70, 90, -80, 43, 9, -57, 87, -87, 57, -9, -43, 80, -90, 70, -25, -25, 70, -90, 80, -43, -9, 57, -87, 87, -57, 9, 43, -80, 90, -70, 25 },
258 { 22, -61, 85, -90, 73, -38, -4, 46, -78, 90, -82, 54, -13, -31, 67, -88, 88, -67, 31, 13, -54, 82, -90, 78, -46, 4, 38, -73, 90, -85, 61, -22 },
259 { 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18, 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18 },
260 { 13, -38, 61, -78, 88, -90, 85, -73, 54, -31, 4, 22, -46, 67, -82, 90, -90, 82, -67, 46, -22, -4, 31, -54, 73, -85, 90, -88, 78, -61, 38, -13 },
261 { 9, -25, 43, -57, 70, -80, 87, -90, 90, -87, 80, -70, 57, -43, 25, -9, -9, 25, -43, 57, -70, 80, -87, 90, -90, 87, -80, 70, -57, 43, -25, 9 },
262 { 4, -13, 22, -31, 38, -46, 54, -61, 67, -73, 78, -82, 85, -88, 90, -90, 90, -90, 88, -85, 82, -78, 73, -67, 61, -54, 46, -38, 31, -22, 13, -4 }
265 const uint8_t g_chromaScale
[ChromaQPMappingTableSize
] =
267 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
268 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51
271 const uint8_t g_chroma422IntraAngleMappingTable
[AngleMapping422TableSize
] =
272 { 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31, DM_CHROMA_IDX
};
274 const uint8_t g_log2Size
[MAX_CU_SIZE
+ 1] =
276 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
277 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
278 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
279 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
283 const uint16_t g_scan2x2
[][2*2] =
289 const uint16_t g_scan8x8
[NUM_SCAN_TYPE
][8 * 8] =
291 { 0, 8, 1, 16, 9, 2, 24, 17, 10, 3, 25, 18, 11, 26, 19, 27, 32, 40, 33, 48, 41, 34, 56, 49, 42, 35, 57, 50, 43, 58, 51, 59,
292 4, 12, 5, 20, 13, 6, 28, 21, 14, 7, 29, 22, 15, 30, 23, 31, 36, 44, 37, 52, 45, 38, 60, 53, 46, 39, 61, 54, 47, 62, 55, 63 },
293 { 0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27, 4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31,
294 32, 33, 34, 35, 40, 41, 42, 43, 48, 49, 50, 51, 56, 57, 58, 59, 36, 37, 38, 39, 44, 45, 46, 47, 52, 53, 54, 55, 60, 61, 62, 63 },
295 { 0, 8, 16, 24, 1, 9, 17, 25, 2, 10, 18, 26, 3, 11, 19, 27, 32, 40, 48, 56, 33, 41, 49, 57, 34, 42, 50, 58, 35, 43, 51, 59,
296 4, 12, 20, 28, 5, 13, 21, 29, 6, 14, 22, 30, 7, 15, 23, 31, 36, 44, 52, 60, 37, 45, 53, 61, 38, 46, 54, 62, 39, 47, 55, 63 }
299 const uint16_t g_scan4x4
[NUM_SCAN_TYPE
][4 * 4] =
301 { 0, 4, 1, 8, 5, 2, 12, 9, 6, 3, 13, 10, 7, 14, 11, 15 },
302 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
303 { 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15 }
306 const uint16_t g_scan16x16
[16 * 16] =
308 0, 16, 1, 32, 17, 2, 48, 33, 18, 3, 49, 34, 19, 50, 35, 51,
309 64, 80, 65, 96, 81, 66, 112, 97, 82, 67, 113, 98, 83, 114, 99, 115,
310 4, 20, 5, 36, 21, 6, 52, 37, 22, 7, 53, 38, 23, 54, 39, 55,
311 128, 144, 129, 160, 145, 130, 176, 161, 146, 131, 177, 162, 147, 178, 163, 179,
312 68, 84, 69, 100, 85, 70, 116, 101, 86, 71, 117, 102, 87, 118, 103, 119,
313 8, 24, 9, 40, 25, 10, 56, 41, 26, 11, 57, 42, 27, 58, 43, 59,
314 192,208, 193,224,209, 194,240,225,210, 195,241,226,211,242,227,243,
315 132, 148, 133, 164, 149, 134, 180, 165, 150, 135, 181, 166, 151, 182, 167, 183,
316 72, 88, 73, 104, 89, 74, 120, 105, 90, 75, 121, 106, 91, 122, 107, 123,
317 12, 28, 13, 44, 29, 14, 60, 45, 30, 15, 61, 46, 31, 62, 47, 63,
318 196,212, 197,228,213, 198,244,229,214, 199,245,230,215,246,231,247,
319 136, 152, 137, 168, 153, 138, 184, 169, 154, 139, 185, 170, 155, 186, 171, 187,
320 76, 92, 77, 108, 93, 78, 124, 109, 94, 79, 125, 110, 95, 126, 111, 127,
321 200,216,201,232,217,202,248,233,218,203,249,234,219,250,235,251,
322 140, 156, 141, 172, 157, 142, 188, 173, 158, 143, 189, 174, 159, 190, 175, 191,
323 204,220,205,236,221,206,252,237,222,207,253,238,223,254,239,255
326 const uint16_t g_scan8x8diag
[8 * 8] =
328 0, 8, 1, 16, 9, 2, 24, 17,
329 10, 3, 32, 25, 18, 11, 4, 40,
330 33, 26, 19, 12, 5, 48, 41, 34,
331 27, 20, 13, 6, 56, 49, 42, 35,
332 28, 21, 14, 7, 57, 50, 43, 36,
333 29, 22, 15, 58, 51, 44, 37, 30,
334 23, 59, 52, 45, 38, 31, 60, 53,
335 46, 39, 61, 54, 47, 62, 55, 63
338 const uint16_t g_scan32x32
[32 * 32] =
340 0,32,1,64,33,2,96,65,34,3,97,66,35,98,67,99,128,160,129,192,161,130,224,193,162,131,225,194,163,226,195,227,
341 4,36,5,68,37,6,100,69,38,7,101,70,39,102,71,103,256,288,257,320,289,258,352,321,290,259,353,322,291,354,323,355,
342 132,164,133,196,165,134,228,197,166,135,229,198,167,230,199,231,8,40,9,72,41,10,104,73,42,11,105,74,43,106,75,107,
343 384,416,385,448,417,386,480,449,418,387,481,450,419,482,451,483,260,292,261,324,293,262,356,325,294,263,357,326,295,358,327,359,
344 136,168,137,200,169,138,232,201,170,139,233,202,171,234,203,235,12,44,13,76,45,14,108,77,46,15,109,78,47,110,79,111,
345 512,544,513,576,545,514,608,577,546,515,609,578,547,610,579,611,388,420,389,452,421,390,484,453,422,391,485,454,423,486,455,487,
346 264,296,265,328,297,266,360,329,298,267,361,330,299,362,331,363,140,172,141,204,173,142,236,205,174,143,237,206,175,238,207,239,
347 16,48,17,80,49,18,112,81,50,19,113,82,51,114,83,115,640,672,641,704,673,642,736,705,674,643,737,706,675,738,707,739,
348 516,548,517,580,549,518,612,581,550,519,613,582,551,614,583,615,392,424,393,456,425,394,488,457,426,395,489,458,427,490,459,491,
349 268,300,269,332,301,270,364,333,302,271,365,334,303,366,335,367,144,176,145,208,177,146,240,209,178,147,241,210,179,242,211,243,
350 20,52,21,84,53,22,116,85,54,23,117,86,55,118,87,119,768,800,769,832,801,770,864,833,802,771,865,834,803,866,835,867,
351 644,676,645,708,677,646,740,709,678,647,741,710,679,742,711,743,520,552,521,584,553,522,616,585,554,523,617,586,555,618,587,619,
352 396,428,397,460,429,398,492,461,430,399,493,462,431,494,463,495,272,304,273,336,305,274,368,337,306,275,369,338,307,370,339,371,
353 148,180,149,212,181,150,244,213,182,151,245,214,183,246,215,247,24,56,25,88,57,26,120,89,58,27,121,90,59,122,91,123,
354 896,928,897,960,929,898,992,961,930,899,993,962,931,994,963,995,772,804,773,836,805,774,868,837,806,775,869,838,807,870,839,871,
355 648,680,649,712,681,650,744,713,682,651,745,714,683,746,715,747,524,556,525,588,557,526,620,589,558,527,621,590,559,622,591,623,
356 400,432,401,464,433,402,496,465,434,403,497,466,435,498,467,499,276,308,277,340,309,278,372,341,310,279,373,342,311,374,343,375,
357 152,184,153,216,185,154,248,217,186,155,249,218,187,250,219,251,28,60,29,92,61,30,124,93,62,31,125,94,63,126,95,127,
358 900,932,901,964,933,902,996,965,934,903,997,966,935,998,967,999,776,808,777,840,809,778,872,841,810,779,873,842,811,874,843,875,
359 652,684,653,716,685,654,748,717,686,655,749,718,687,750,719,751,528,560,529,592,561,530,624,593,562,531,625,594,563,626,595,627,
360 404,436,405,468,437,406,500,469,438,407,501,470,439,502,471,503,280,312,281,344,313,282,376,345,314,283,377,346,315,378,347,379,
361 156,188,157,220,189,158,252,221,190,159,253,222,191,254,223,255,904,936,905,968,937,906,1000,969,938,907,1001,970,939,1002,971,1003,
362 780,812,781,844,813,782,876,845,814,783,877,846,815,878,847,879,656,688,657,720,689,658,752,721,690,659,753,722,691,754,723,755,
363 532,564,533,596,565,534,628,597,566,535,629,598,567,630,599,631,408,440,409,472,441,410,504,473,442,411,505,474,443,506,475,507,
364 284,316,285,348,317,286,380,349,318,287,381,350,319,382,351,383,908,940,909,972,941,910,1004,973,942,911,1005,974,943,1006,975,1007,
365 784,816,785,848,817,786,880,849,818,787,881,850,819,882,851,883,660,692,661,724,693,662,756,725,694,663,757,726,695,758,727,759,
366 536,568,537,600,569,538,632,601,570,539,633,602,571,634,603,635,412,444,413,476,445,414,508,477,446,415,509,478,447,510,479,511,
367 912,944,913,976,945,914,1008,977,946,915,1009,978,947,1010,979,1011,788,820,789,852,821,790,884,853,822,791,885,854,823,886,855,887,
368 664,696,665,728,697,666,760,729,698,667,761,730,699,762,731,763,540,572,541,604,573,542,636,605,574,543,637,606,575,638,607,639,
369 916,948,917,980,949,918,1012,981,950,919,1013,982,951,1014,983,1015,792,824,793,856,825,794,888,857,826,795,889,858,827,890,859,891,
370 668,700,669,732,701,670,764,733,702,671,765,734,703,766,735,767,920,952,921,984,953,922,1016,985,954,923,1017,986,955,1018,987,1019,
371 796,828,797,860,829,798,892,861,830,799,893,862,831,894,863,895,924,956,925,988,957,926,1020,989,958,927,1021,990,959,1022,991,1023
374 const uint16_t* const g_scanOrder
[NUM_SCAN_TYPE
][NUM_SCAN_SIZE
] =
376 { g_scan4x4
[0], g_scan8x8
[0], g_scan16x16
, g_scan32x32
},
377 { g_scan4x4
[1], g_scan8x8
[1], g_scan16x16
, g_scan32x32
},
378 { g_scan4x4
[2], g_scan8x8
[2], g_scan16x16
, g_scan32x32
}
381 const uint16_t* const g_scanOrderCG
[NUM_SCAN_TYPE
][NUM_SCAN_SIZE
] =
383 { g_scan4x4
[0], g_scan2x2
[0], g_scan4x4
[0], g_scan8x8diag
},
384 { g_scan4x4
[1], g_scan2x2
[1], g_scan4x4
[0], g_scan8x8diag
},
385 { g_scan4x4
[2], g_scan2x2
[0], g_scan4x4
[0], g_scan8x8diag
}
388 const uint8_t g_minInGroup
[10] = { 0, 1, 2, 3, 4, 6, 8, 12, 16, 24 };
390 // Rice parameters for absolute transform levels
391 const uint8_t g_goRiceRange
[5] = { 7, 14, 26, 46, 78 };
393 const uint8_t g_lpsTable
[64][4] =
395 { 128, 176, 208, 240 },
396 { 128, 167, 197, 227 },
397 { 128, 158, 187, 216 },
398 { 123, 150, 178, 205 },
399 { 116, 142, 169, 195 },
400 { 111, 135, 160, 185 },
401 { 105, 128, 152, 175 },
402 { 100, 122, 144, 166 },
403 { 95, 116, 137, 158 },
404 { 90, 110, 130, 150 },
405 { 85, 104, 123, 142 },
406 { 81, 99, 117, 135 },
407 { 77, 94, 111, 128 },
408 { 73, 89, 105, 122 },
409 { 69, 85, 100, 116 },
461 const uint8_t x265_exp2_lut
[64] =
463 0, 3, 6, 8, 11, 14, 17, 20, 23, 26, 29, 32, 36, 39, 42, 45,
464 48, 52, 55, 58, 62, 65, 69, 72, 76, 80, 83, 87, 91, 94, 98, 102,
465 106, 110, 114, 118, 122, 126, 130, 135, 139, 143, 147, 152, 156, 161, 165, 170,
466 175, 179, 184, 189, 194, 198, 203, 208, 214, 219, 224, 229, 234, 240, 245, 250
469 /* bFilter = g_intraFilterFlags[dir] & trSize */
470 const uint8_t g_intraFilterFlags
[NUM_INTRA_MODE
] =
473 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x20, 0x00, 0x20, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
474 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x20, 0x00, 0x20, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
478 /* Contains how much to increment shared depth buffer for different ctu sizes to get next best depth
479 * here, depth 0 = 64x64, depth 1 = 32x32, depth 2 = 16x16 and depth 3 = 8x8
480 * if ctu = 64, depth buffer size is 256 combination of depth values 0, 1, 2, 3
481 * if ctu = 32, depth buffer size is 64 combination of depth values 1, 2, 3
482 * if ctu = 16, depth buffer size is 16 combination of depth values 2, 3 */
483 const uint32_t g_depthInc
[3][4] =
490 /* g_depthScanIdx [y][x] */
491 const uint32_t g_depthScanIdx
[8][8] =
493 { 0, 1, 4, 5, 16, 17, 20, 21, },
494 { 2, 3, 6, 7, 18, 19, 22, 23, },
495 { 8, 9, 12, 13, 24, 25, 28, 29, },
496 { 10, 11, 14, 15, 26, 27, 30, 31, },
497 { 32, 33, 36, 37, 48, 49, 52, 53, },
498 { 34, 35, 38, 39, 50, 51, 54, 55, },
499 { 40, 41, 44, 45, 56, 57, 60, 61, },
500 { 42, 43, 46, 47, 58, 59, 62, 63, }