AVRational
[libav.git] / libavcodec / h264data.h
CommitLineData
0da71265
MN
1/*
2 * H26L/H264/AVC/JVT/14496-10/... encoder/decoder
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21/**
22 * @file h264data.h
23 * @brief
24 * H264 / AVC / MPEG4 part10 codec data table
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28#define VERT_PRED 0
29#define HOR_PRED 1
30#define DC_PRED 2
31#define DIAG_DOWN_LEFT_PRED 3
32#define DIAG_DOWN_RIGHT_PRED 4
33#define VERT_RIGHT_PRED 5
34#define HOR_DOWN_PRED 6
35#define VERT_LEFT_PRED 7
36#define HOR_UP_PRED 8
37
38#define LEFT_DC_PRED 9
39#define TOP_DC_PRED 10
40#define DC_128_PRED 11
41
42
43#define DC_PRED8x8 0
44#define HOR_PRED8x8 1
45#define VERT_PRED8x8 2
46#define PLANE_PRED8x8 3
47
48#define LEFT_DC_PRED8x8 4
49#define TOP_DC_PRED8x8 5
50#define DC_128_PRED8x8 6
51
52#define EXTENDED_SAR 255
53
5ff85f1d
MN
54static const AVRational pixel_aspect[14]={
55 {0, 1},
0da71265
MN
56 {1, 1},
57 {12, 11},
58 {10, 11},
59 {16, 11},
60 {40, 33},
61 {24, 11},
62 {20, 11},
63 {32, 11},
64 {80, 33},
65 {18, 11},
66 {15, 11},
67 {64, 33},
68 {160,99},
69};
70
71static const uint8_t golomb_to_pict_type[5]=
72{P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE};
73
74static const uint8_t pict_type_to_golomb[7]=
75{-1, 2, 0, 1, -1, 4, 3};
76
77static const uint8_t chroma_qp[52]={
78 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,
79 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,
80 28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,
81 37,38,38,38,39,39,39,39
82
83};
84
85static const uint8_t golomb_to_intra4x4_cbp[48]={
86 47, 31, 15, 0, 23, 27, 29, 30, 7, 11, 13, 14, 39, 43, 45, 46,
87 16, 3, 5, 10, 12, 19, 21, 26, 28, 35, 37, 42, 44, 1, 2, 4,
88 8, 17, 18, 20, 24, 6, 9, 22, 25, 32, 33, 34, 36, 40, 38, 41
89};
90
91static const uint8_t golomb_to_inter_cbp[48]={
92 0, 16, 1, 2, 4, 8, 32, 3, 5, 10, 12, 15, 47, 7, 11, 13,
93 14, 6, 9, 31, 35, 37, 42, 44, 33, 34, 36, 40, 39, 43, 45, 46,
94 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41
95};
96
97static const uint8_t intra4x4_cbp_to_golomb[48]={
98 3, 29, 30, 17, 31, 18, 37, 8, 32, 38, 19, 9, 20, 10, 11, 2,
99 16, 33, 34, 21, 35, 22, 39, 4, 36, 40, 23, 5, 24, 6, 7, 1,
100 41, 42, 43, 25, 44, 26, 46, 12, 45, 47, 27, 13, 28, 14, 15, 0
101};
102
103static const uint8_t inter_cbp_to_golomb[48]={
104 0, 2, 3, 7, 4, 8, 17, 13, 5, 18, 9, 14, 10, 15, 16, 11,
105 1, 32, 33, 36, 34, 37, 44, 40, 35, 45, 38, 41, 39, 42, 43, 19,
106 6, 24, 25, 20, 26, 21, 46, 28, 27, 47, 22, 29, 23, 30, 31, 12
107};
108
109static const uint8_t chroma_dc_coeff_token_len[4*5]={
110 2, 0, 0, 0,
111 6, 1, 0, 0,
112 6, 6, 3, 0,
113 6, 7, 7, 6,
114 6, 8, 8, 7,
115};
116
117static const uint8_t chroma_dc_coeff_token_bits[4*5]={
118 1, 0, 0, 0,
119 7, 1, 0, 0,
120 4, 6, 1, 0,
121 3, 3, 2, 5,
122 2, 3, 2, 0,
123};
124
125static const uint8_t coeff_token_len[4][4*17]={
126{
127 1, 0, 0, 0,
128 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6,
129 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10,
130 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14,
131 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16,
132},
133{
134 2, 0, 0, 0,
135 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4,
136 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7,
137 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12,
138 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14,
139},
140{
141 4, 0, 0, 0,
142 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4,
143 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5,
144 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8,
145 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10,
146},
147{
148 6, 0, 0, 0,
149 6, 6, 0, 0, 6, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6,
150 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
151 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
152 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
153}
154};
155
156static const uint8_t coeff_token_bits[4][4*17]={
157{
158 1, 0, 0, 0,
159 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3,
160 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4,
161 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8,
162 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8,
163},
164{
165 3, 0, 0, 0,
166 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4,
167 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4,
168 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12,
169 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4,
170},
171{
172 15, 0, 0, 0,
173 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11,
174 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13,
175 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8,
176 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2,
177},
178{
179 3, 0, 0, 0,
180 0, 1, 0, 0, 4, 5, 6, 0, 8, 9,10,11, 12,13,14,15,
181 16,17,18,19, 20,21,22,23, 24,25,26,27, 28,29,30,31,
182 32,33,34,35, 36,37,38,39, 40,41,42,43, 44,45,46,47,
183 48,49,50,51, 52,53,54,55, 56,57,58,59, 60,61,62,63,
184}
185};
186
187static const uint8_t total_zeros_len[16][16]= {
188 {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
189 {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
190 {4,3,3,3,4,4,3,3,4,5,5,6,5,6},
191 {5,3,4,4,3,3,3,4,3,4,5,5,5},
192 {4,4,4,3,3,3,3,3,4,5,4,5},
193 {6,5,3,3,3,3,3,3,4,3,6},
194 {6,5,3,3,3,2,3,4,3,6},
195 {6,4,5,3,2,2,3,3,6},
196 {6,6,4,2,2,3,2,5},
197 {5,5,3,2,2,2,4},
198 {4,4,3,3,1,3},
199 {4,4,2,1,3},
200 {3,3,1,2},
201 {2,2,1},
202 {1,1},
203};
204
205static const uint8_t total_zeros_bits[16][16]= {
206 {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1},
207 {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0},
208 {5,7,6,5,4,3,4,3,2,3,2,1,1,0},
209 {3,7,5,4,6,5,4,3,3,2,2,1,0},
210 {5,4,3,7,6,5,4,3,2,1,1,0},
211 {1,1,7,6,5,4,3,2,1,1,0},
212 {1,1,5,4,3,3,2,1,1,0},
213 {1,1,1,3,3,2,2,1,0},
214 {1,0,1,3,2,1,1,1},
215 {1,0,1,3,2,1,1},
216 {0,1,1,2,1,3},
217 {0,1,1,1,1},
218 {0,1,1,1},
219 {0,1,1},
220 {0,1},
221};
222
223static const uint8_t chroma_dc_total_zeros_len[3][4]= {
224 { 1, 2, 3, 3,},
225 { 1, 2, 2, 0,},
226 { 1, 1, 0, 0,},
227};
228
229static const uint8_t chroma_dc_total_zeros_bits[3][4]= {
230 { 1, 1, 1, 0,},
231 { 1, 1, 0, 0,},
232 { 1, 0, 0, 0,},
233};
234
235static const uint8_t run_len[7][16]={
236 {1,1},
237 {1,2,2},
238 {2,2,2,2},
239 {2,2,2,3,3},
240 {2,2,3,3,3,3},
241 {2,3,3,3,3,3,3},
242 {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11},
243};
244
245static const uint8_t run_bits[7][16]={
246 {1,0},
247 {1,1,0},
248 {3,2,1,0},
249 {3,2,1,1,0},
250 {3,2,3,2,1,0},
251 {3,0,1,3,2,5,4},
252 {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1},
253};
254
255/*
256o-o o-o
257 / / /
258o-o o-o
259 ,---'
260o-o o-o
261 / / /
262o-o o-o
263*/
264
265static const uint8_t scan8[16 + 2*4]={
266 4+1*8, 5+1*8, 4+2*8, 5+2*8,
267 6+1*8, 7+1*8, 6+2*8, 7+2*8,
268 4+3*8, 5+3*8, 4+4*8, 5+4*8,
269 6+3*8, 7+3*8, 6+4*8, 7+4*8,
270 1+1*8, 2+1*8,
271 1+2*8, 2+2*8,
272 1+4*8, 2+4*8,
273 1+5*8, 2+5*8,
274};
275
276static const uint8_t zigzag_scan[16]={
277 0+0*4, 1+0*4, 0+1*4, 0+2*4,
278 1+1*4, 2+0*4, 3+0*4, 2+1*4,
279 1+2*4, 0+3*4, 1+3*4, 2+2*4,
280 3+1*4, 3+2*4, 2+3*4, 3+3*4,
281};
282
283static const uint8_t field_scan[16]={
284 0+0*4, 0+1*4, 1+0*4, 0+2*4,
285 0+3*4, 1+1*4, 1+2*4, 1+3*4,
286 2+0*4, 2+1*4, 2+2*4, 2+3*4,
287 3+0*4, 3+1*4, 3+2*4, 3+3*4,
288};
289
290static const uint8_t luma_dc_zigzag_scan[16]={
291 0*16 + 0*64, 1*16 + 0*64, 2*16 + 0*64, 0*16 + 2*64,
292 3*16 + 0*64, 0*16 + 1*64, 1*16 + 1*64, 2*16 + 1*64,
293 1*16 + 2*64, 2*16 + 2*64, 3*16 + 2*64, 0*16 + 3*64,
294 3*16 + 1*64, 1*16 + 3*64, 2*16 + 3*64, 3*16 + 3*64,
295};
296
297static const uint8_t luma_dc_field_scan[16]={
298 0*16 + 0*64, 2*16 + 0*64, 1*16 + 0*64, 0*16 + 2*64,
299 2*16 + 2*64, 3*16 + 0*64, 1*16 + 2*64, 3*16 + 2*64,
300 0*16 + 1*64, 2*16 + 1*64, 0*16 + 3*64, 2*16 + 3*64,
301 1*16 + 1*64, 3*16 + 1*64, 1*16 + 3*64, 3*16 + 3*64,
302};
303
304static const uint8_t chroma_dc_scan[4]={
305 (0+0*2)*16, (1+0*2)*16,
306 (0+1*2)*16, (1+1*2)*16, //FIXME
307};
308
8a3b6f92 309#define MB_TYPE_REF0 MB_TYPE_ACPRED //dirty but it fits in 16bit
7bc9090a
MN
310#define IS_REF0(a) ((a)&MB_TYPE_REF0)
311
0da71265
MN
312typedef struct IMbInfo{
313 uint16_t type;
314 uint8_t pred_mode;
315 uint8_t cbp;
316} IMbInfo;
317
318static const IMbInfo i_mb_type_info[26]={
319{MB_TYPE_INTRA4x4 , -1, -1},
320{MB_TYPE_INTRA16x16, 2, 0},
321{MB_TYPE_INTRA16x16, 1, 0},
322{MB_TYPE_INTRA16x16, 0, 0},
323{MB_TYPE_INTRA16x16, 3, 0},
324{MB_TYPE_INTRA16x16, 2, 16},
325{MB_TYPE_INTRA16x16, 1, 16},
326{MB_TYPE_INTRA16x16, 0, 16},
327{MB_TYPE_INTRA16x16, 3, 16},
328{MB_TYPE_INTRA16x16, 2, 32},
329{MB_TYPE_INTRA16x16, 1, 32},
330{MB_TYPE_INTRA16x16, 0, 32},
331{MB_TYPE_INTRA16x16, 3, 32},
332{MB_TYPE_INTRA16x16, 2, 15+0},
333{MB_TYPE_INTRA16x16, 1, 15+0},
334{MB_TYPE_INTRA16x16, 0, 15+0},
335{MB_TYPE_INTRA16x16, 3, 15+0},
336{MB_TYPE_INTRA16x16, 2, 15+16},
337{MB_TYPE_INTRA16x16, 1, 15+16},
338{MB_TYPE_INTRA16x16, 0, 15+16},
339{MB_TYPE_INTRA16x16, 3, 15+16},
340{MB_TYPE_INTRA16x16, 2, 15+32},
341{MB_TYPE_INTRA16x16, 1, 15+32},
342{MB_TYPE_INTRA16x16, 0, 15+32},
343{MB_TYPE_INTRA16x16, 3, 15+32},
344{MB_TYPE_INTRA_PCM , -1, -1},
345};
346
347typedef struct PMbInfo{
348 uint16_t type;
349 uint8_t partition_count;
350} PMbInfo;
351
352static const PMbInfo p_mb_type_info[5]={
353{MB_TYPE_16x16|MB_TYPE_P0L0 , 1},
354{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},
355{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},
356{MB_TYPE_8x8 , 4},
357{MB_TYPE_8x8 |MB_TYPE_REF0 , 4},
358};
359
360static const PMbInfo p_sub_mb_type_info[4]={
361{MB_TYPE_16x16|MB_TYPE_P0L0 , 1},
362{MB_TYPE_16x8 |MB_TYPE_P0L0 , 2},
363{MB_TYPE_8x16 |MB_TYPE_P0L0 , 2},
364{MB_TYPE_8x8 |MB_TYPE_P0L0 , 4},
365};
366
367static const PMbInfo b_mb_type_info[23]={
7bc9090a 368{MB_TYPE_DIRECT2 , 1, },
0da71265
MN
369{MB_TYPE_16x16|MB_TYPE_P0L0 , 1, },
370{MB_TYPE_16x16 |MB_TYPE_P0L1 , 1, },
371{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1 , 1, },
372{MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
373{MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
374{MB_TYPE_16x8 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
375{MB_TYPE_8x16 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
376{MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L1, 2, },
377{MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L1, 2, },
378{MB_TYPE_16x8 |MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
379{MB_TYPE_8x16 |MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
380{MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
381{MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
382{MB_TYPE_16x8 |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
383{MB_TYPE_8x16 |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
384{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
385{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
386{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
387{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
388{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
389{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
390{MB_TYPE_8x8 , 4, },
391};
392
393static const PMbInfo b_sub_mb_type_info[13]={
7bc9090a 394{MB_TYPE_DIRECT2 , 1, },
0da71265
MN
395{MB_TYPE_16x16|MB_TYPE_P0L0 , 1, },
396{MB_TYPE_16x16 |MB_TYPE_P0L1 , 1, },
397{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1 , 1, },
398{MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
399{MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
400{MB_TYPE_16x8 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
401{MB_TYPE_8x16 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
402{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
403{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
404{MB_TYPE_8x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 4, },
405{MB_TYPE_8x8 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 4, },
406{MB_TYPE_8x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 4, },
407};
408
409
410static const uint8_t rem6[52]={
4110, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
412};
413
414static const uint8_t div6[52]={
4150, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
416};
417
418static const uint16_t dequant_coeff[52][16]={
419{ 10, 13, 10, 13, 13, 16, 13, 16, 10, 13, 10, 13, 13, 16, 13, 16, },
420{ 11, 14, 11, 14, 14, 18, 14, 18, 11, 14, 11, 14, 14, 18, 14, 18, },
421{ 13, 16, 13, 16, 16, 20, 16, 20, 13, 16, 13, 16, 16, 20, 16, 20, },
422{ 14, 18, 14, 18, 18, 23, 18, 23, 14, 18, 14, 18, 18, 23, 18, 23, },
423{ 16, 20, 16, 20, 20, 25, 20, 25, 16, 20, 16, 20, 20, 25, 20, 25, },
424{ 18, 23, 18, 23, 23, 29, 23, 29, 18, 23, 18, 23, 23, 29, 23, 29, },
425{ 20, 26, 20, 26, 26, 32, 26, 32, 20, 26, 20, 26, 26, 32, 26, 32, },
426{ 22, 28, 22, 28, 28, 36, 28, 36, 22, 28, 22, 28, 28, 36, 28, 36, },
427{ 26, 32, 26, 32, 32, 40, 32, 40, 26, 32, 26, 32, 32, 40, 32, 40, },
428{ 28, 36, 28, 36, 36, 46, 36, 46, 28, 36, 28, 36, 36, 46, 36, 46, },
429{ 32, 40, 32, 40, 40, 50, 40, 50, 32, 40, 32, 40, 40, 50, 40, 50, },
430{ 36, 46, 36, 46, 46, 58, 46, 58, 36, 46, 36, 46, 46, 58, 46, 58, },
431{ 40, 52, 40, 52, 52, 64, 52, 64, 40, 52, 40, 52, 52, 64, 52, 64, },
432{ 44, 56, 44, 56, 56, 72, 56, 72, 44, 56, 44, 56, 56, 72, 56, 72, },
433{ 52, 64, 52, 64, 64, 80, 64, 80, 52, 64, 52, 64, 64, 80, 64, 80, },
434{ 56, 72, 56, 72, 72, 92, 72, 92, 56, 72, 56, 72, 72, 92, 72, 92, },
435{ 64, 80, 64, 80, 80, 100, 80, 100, 64, 80, 64, 80, 80, 100, 80, 100, },
436{ 72, 92, 72, 92, 92, 116, 92, 116, 72, 92, 72, 92, 92, 116, 92, 116, },
437{ 80, 104, 80, 104, 104, 128, 104, 128, 80, 104, 80, 104, 104, 128, 104, 128, },
438{ 88, 112, 88, 112, 112, 144, 112, 144, 88, 112, 88, 112, 112, 144, 112, 144, },
439{ 104, 128, 104, 128, 128, 160, 128, 160, 104, 128, 104, 128, 128, 160, 128, 160, },
440{ 112, 144, 112, 144, 144, 184, 144, 184, 112, 144, 112, 144, 144, 184, 144, 184, },
441{ 128, 160, 128, 160, 160, 200, 160, 200, 128, 160, 128, 160, 160, 200, 160, 200, },
442{ 144, 184, 144, 184, 184, 232, 184, 232, 144, 184, 144, 184, 184, 232, 184, 232, },
443{ 160, 208, 160, 208, 208, 256, 208, 256, 160, 208, 160, 208, 208, 256, 208, 256, },
444{ 176, 224, 176, 224, 224, 288, 224, 288, 176, 224, 176, 224, 224, 288, 224, 288, },
445{ 208, 256, 208, 256, 256, 320, 256, 320, 208, 256, 208, 256, 256, 320, 256, 320, },
446{ 224, 288, 224, 288, 288, 368, 288, 368, 224, 288, 224, 288, 288, 368, 288, 368, },
447{ 256, 320, 256, 320, 320, 400, 320, 400, 256, 320, 256, 320, 320, 400, 320, 400, },
448{ 288, 368, 288, 368, 368, 464, 368, 464, 288, 368, 288, 368, 368, 464, 368, 464, },
449{ 320, 416, 320, 416, 416, 512, 416, 512, 320, 416, 320, 416, 416, 512, 416, 512, },
450{ 352, 448, 352, 448, 448, 576, 448, 576, 352, 448, 352, 448, 448, 576, 448, 576, },
451{ 416, 512, 416, 512, 512, 640, 512, 640, 416, 512, 416, 512, 512, 640, 512, 640, },
452{ 448, 576, 448, 576, 576, 736, 576, 736, 448, 576, 448, 576, 576, 736, 576, 736, },
453{ 512, 640, 512, 640, 640, 800, 640, 800, 512, 640, 512, 640, 640, 800, 640, 800, },
454{ 576, 736, 576, 736, 736, 928, 736, 928, 576, 736, 576, 736, 736, 928, 736, 928, },
455{ 640, 832, 640, 832, 832,1024, 832,1024, 640, 832, 640, 832, 832,1024, 832,1024, },
456{ 704, 896, 704, 896, 896,1152, 896,1152, 704, 896, 704, 896, 896,1152, 896,1152, },
457{ 832,1024, 832,1024, 1024,1280,1024,1280, 832,1024, 832,1024, 1024,1280,1024,1280, },
458{ 896,1152, 896,1152, 1152,1472,1152,1472, 896,1152, 896,1152, 1152,1472,1152,1472, },
459{1024,1280,1024,1280, 1280,1600,1280,1600, 1024,1280,1024,1280, 1280,1600,1280,1600, },
460{1152,1472,1152,1472, 1472,1856,1472,1856, 1152,1472,1152,1472, 1472,1856,1472,1856, },
461{1280,1664,1280,1664, 1664,2048,1664,2048, 1280,1664,1280,1664, 1664,2048,1664,2048, },
462{1408,1792,1408,1792, 1792,2304,1792,2304, 1408,1792,1408,1792, 1792,2304,1792,2304, },
463{1664,2048,1664,2048, 2048,2560,2048,2560, 1664,2048,1664,2048, 2048,2560,2048,2560, },
464{1792,2304,1792,2304, 2304,2944,2304,2944, 1792,2304,1792,2304, 2304,2944,2304,2944, },
465{2048,2560,2048,2560, 2560,3200,2560,3200, 2048,2560,2048,2560, 2560,3200,2560,3200, },
466{2304,2944,2304,2944, 2944,3712,2944,3712, 2304,2944,2304,2944, 2944,3712,2944,3712, },
467{2560,3328,2560,3328, 3328,4096,3328,4096, 2560,3328,2560,3328, 3328,4096,3328,4096, },
468{2816,3584,2816,3584, 3584,4608,3584,4608, 2816,3584,2816,3584, 3584,4608,3584,4608, },
469{3328,4096,3328,4096, 4096,5120,4096,5120, 3328,4096,3328,4096, 4096,5120,4096,5120, },
470{3584,4608,3584,4608, 4608,5888,4608,5888, 3584,4608,3584,4608, 4608,5888,4608,5888, },
471//{4096,5120,4096,5120, 5120,6400,5120,6400, 4096,5120,4096,5120, 5120,6400,5120,6400, },
472//{4608,5888,4608,5888, 5888,7424,5888,7424, 4608,5888,4608,5888, 5888,7424,5888,7424, },
473};
474
475#define QUANT_SHIFT 22
476
477static const int quant_coeff[52][16]={
478 { 419430,258111,419430,258111,258111,167772,258111,167772,419430,258111,419430,258111,258111,167772,258111,167772,},
479 { 381300,239675,381300,239675,239675,149131,239675,149131,381300,239675,381300,239675,239675,149131,239675,149131,},
480 { 322639,209715,322639,209715,209715,134218,209715,134218,322639,209715,322639,209715,209715,134218,209715,134218,},
481 { 299593,186414,299593,186414,186414,116711,186414,116711,299593,186414,299593,186414,186414,116711,186414,116711,},
482 { 262144,167772,262144,167772,167772,107374,167772,107374,262144,167772,262144,167772,167772,107374,167772,107374,},
483 { 233017,145889,233017,145889,145889, 92564,145889, 92564,233017,145889,233017,145889,145889, 92564,145889, 92564,},
484 { 209715,129056,209715,129056,129056, 83886,129056, 83886,209715,129056,209715,129056,129056, 83886,129056, 83886,},
485 { 190650,119837,190650,119837,119837, 74565,119837, 74565,190650,119837,190650,119837,119837, 74565,119837, 74565,},
486 { 161319,104858,161319,104858,104858, 67109,104858, 67109,161319,104858,161319,104858,104858, 67109,104858, 67109,},
487 { 149797, 93207,149797, 93207, 93207, 58356, 93207, 58356,149797, 93207,149797, 93207, 93207, 58356, 93207, 58356,},
488 { 131072, 83886,131072, 83886, 83886, 53687, 83886, 53687,131072, 83886,131072, 83886, 83886, 53687, 83886, 53687,},
489 { 116508, 72944,116508, 72944, 72944, 46282, 72944, 46282,116508, 72944,116508, 72944, 72944, 46282, 72944, 46282,},
490 { 104858, 64528,104858, 64528, 64528, 41943, 64528, 41943,104858, 64528,104858, 64528, 64528, 41943, 64528, 41943,},
491 { 95325, 59919, 95325, 59919, 59919, 37283, 59919, 37283, 95325, 59919, 95325, 59919, 59919, 37283, 59919, 37283,},
492 { 80660, 52429, 80660, 52429, 52429, 33554, 52429, 33554, 80660, 52429, 80660, 52429, 52429, 33554, 52429, 33554,},
493 { 74898, 46603, 74898, 46603, 46603, 29178, 46603, 29178, 74898, 46603, 74898, 46603, 46603, 29178, 46603, 29178,},
494 { 65536, 41943, 65536, 41943, 41943, 26844, 41943, 26844, 65536, 41943, 65536, 41943, 41943, 26844, 41943, 26844,},
495 { 58254, 36472, 58254, 36472, 36472, 23141, 36472, 23141, 58254, 36472, 58254, 36472, 36472, 23141, 36472, 23141,},
496 { 52429, 32264, 52429, 32264, 32264, 20972, 32264, 20972, 52429, 32264, 52429, 32264, 32264, 20972, 32264, 20972,},
497 { 47663, 29959, 47663, 29959, 29959, 18641, 29959, 18641, 47663, 29959, 47663, 29959, 29959, 18641, 29959, 18641,},
498 { 40330, 26214, 40330, 26214, 26214, 16777, 26214, 16777, 40330, 26214, 40330, 26214, 26214, 16777, 26214, 16777,},
499 { 37449, 23302, 37449, 23302, 23302, 14589, 23302, 14589, 37449, 23302, 37449, 23302, 23302, 14589, 23302, 14589,},
500 { 32768, 20972, 32768, 20972, 20972, 13422, 20972, 13422, 32768, 20972, 32768, 20972, 20972, 13422, 20972, 13422,},
501 { 29127, 18236, 29127, 18236, 18236, 11570, 18236, 11570, 29127, 18236, 29127, 18236, 18236, 11570, 18236, 11570,},
502 { 26214, 16132, 26214, 16132, 16132, 10486, 16132, 10486, 26214, 16132, 26214, 16132, 16132, 10486, 16132, 10486,},
503 { 23831, 14980, 23831, 14980, 14980, 9321, 14980, 9321, 23831, 14980, 23831, 14980, 14980, 9321, 14980, 9321,},
504 { 20165, 13107, 20165, 13107, 13107, 8389, 13107, 8389, 20165, 13107, 20165, 13107, 13107, 8389, 13107, 8389,},
505 { 18725, 11651, 18725, 11651, 11651, 7294, 11651, 7294, 18725, 11651, 18725, 11651, 11651, 7294, 11651, 7294,},
506 { 16384, 10486, 16384, 10486, 10486, 6711, 10486, 6711, 16384, 10486, 16384, 10486, 10486, 6711, 10486, 6711,},
507 { 14564, 9118, 14564, 9118, 9118, 5785, 9118, 5785, 14564, 9118, 14564, 9118, 9118, 5785, 9118, 5785,},
508 { 13107, 8066, 13107, 8066, 8066, 5243, 8066, 5243, 13107, 8066, 13107, 8066, 8066, 5243, 8066, 5243,},
509 { 11916, 7490, 11916, 7490, 7490, 4660, 7490, 4660, 11916, 7490, 11916, 7490, 7490, 4660, 7490, 4660,},
510 { 10082, 6554, 10082, 6554, 6554, 4194, 6554, 4194, 10082, 6554, 10082, 6554, 6554, 4194, 6554, 4194,},
511 { 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647, 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647,},
512 { 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355, 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355,},
513 { 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893, 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893,},
514 { 6554, 4033, 6554, 4033, 4033, 2621, 4033, 2621, 6554, 4033, 6554, 4033, 4033, 2621, 4033, 2621,},
515 { 5958, 3745, 5958, 3745, 3745, 2330, 3745, 2330, 5958, 3745, 5958, 3745, 3745, 2330, 3745, 2330,},
516 { 5041, 3277, 5041, 3277, 3277, 2097, 3277, 2097, 5041, 3277, 5041, 3277, 3277, 2097, 3277, 2097,},
517 { 4681, 2913, 4681, 2913, 2913, 1824, 2913, 1824, 4681, 2913, 4681, 2913, 2913, 1824, 2913, 1824,},
518 { 4096, 2621, 4096, 2621, 2621, 1678, 2621, 1678, 4096, 2621, 4096, 2621, 2621, 1678, 2621, 1678,},
519 { 3641, 2280, 3641, 2280, 2280, 1446, 2280, 1446, 3641, 2280, 3641, 2280, 2280, 1446, 2280, 1446,},
520 { 3277, 2016, 3277, 2016, 2016, 1311, 2016, 1311, 3277, 2016, 3277, 2016, 2016, 1311, 2016, 1311,},
521 { 2979, 1872, 2979, 1872, 1872, 1165, 1872, 1165, 2979, 1872, 2979, 1872, 1872, 1165, 1872, 1165,},
522 { 2521, 1638, 2521, 1638, 1638, 1049, 1638, 1049, 2521, 1638, 2521, 1638, 1638, 1049, 1638, 1049,},
523 { 2341, 1456, 2341, 1456, 1456, 912, 1456, 912, 2341, 1456, 2341, 1456, 1456, 912, 1456, 912,},
524 { 2048, 1311, 2048, 1311, 1311, 839, 1311, 839, 2048, 1311, 2048, 1311, 1311, 839, 1311, 839,},
525 { 1820, 1140, 1820, 1140, 1140, 723, 1140, 723, 1820, 1140, 1820, 1140, 1140, 723, 1140, 723,},
526 { 1638, 1008, 1638, 1008, 1008, 655, 1008, 655, 1638, 1008, 1638, 1008, 1008, 655, 1008, 655,},
527 { 1489, 936, 1489, 936, 936, 583, 936, 583, 1489, 936, 1489, 936, 936, 583, 936, 583,},
528 { 1260, 819, 1260, 819, 819, 524, 819, 524, 1260, 819, 1260, 819, 819, 524, 819, 524,},
529 { 1170, 728, 1170, 728, 728, 456, 728, 456, 1170, 728, 1170, 728, 728, 456, 728, 456,},
530};