comparison h264data.h @ 1168:5af9aeadbdc3 libavcodec

H264 decoder & demuxer
author michaelni
date Fri, 04 Apr 2003 14:42:28 +0000
parents
children fea03d2c4946
comparison
equal deleted inserted replaced
1167:35b80080b2db 1168:5af9aeadbdc3
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
54 static const uint16_t pixel_aspect[16][2]={
55 {0, 0},
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
71 static const uint8_t golomb_to_pict_type[5]=
72 {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE};
73
74 static const uint8_t pict_type_to_golomb[7]=
75 {-1, 2, 0, 1, -1, 4, 3};
76
77 static 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
85 static 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
91 static 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
97 static 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
103 static 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
109 static 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
117 static 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
125 static 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
156 static 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
187 static 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
205 static 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
223 static 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
229 static 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
235 static 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
245 static 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 /*
256 o-o o-o
257 / / /
258 o-o o-o
259 ,---'
260 o-o o-o
261 / / /
262 o-o o-o
263 */
264
265 static 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
276 static 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
283 static 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
290 static 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
297 static 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
304 static 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
309 typedef struct IMbInfo{
310 uint16_t type;
311 uint8_t pred_mode;
312 uint8_t cbp;
313 } IMbInfo;
314
315 static const IMbInfo i_mb_type_info[26]={
316 {MB_TYPE_INTRA4x4 , -1, -1},
317 {MB_TYPE_INTRA16x16, 2, 0},
318 {MB_TYPE_INTRA16x16, 1, 0},
319 {MB_TYPE_INTRA16x16, 0, 0},
320 {MB_TYPE_INTRA16x16, 3, 0},
321 {MB_TYPE_INTRA16x16, 2, 16},
322 {MB_TYPE_INTRA16x16, 1, 16},
323 {MB_TYPE_INTRA16x16, 0, 16},
324 {MB_TYPE_INTRA16x16, 3, 16},
325 {MB_TYPE_INTRA16x16, 2, 32},
326 {MB_TYPE_INTRA16x16, 1, 32},
327 {MB_TYPE_INTRA16x16, 0, 32},
328 {MB_TYPE_INTRA16x16, 3, 32},
329 {MB_TYPE_INTRA16x16, 2, 15+0},
330 {MB_TYPE_INTRA16x16, 1, 15+0},
331 {MB_TYPE_INTRA16x16, 0, 15+0},
332 {MB_TYPE_INTRA16x16, 3, 15+0},
333 {MB_TYPE_INTRA16x16, 2, 15+16},
334 {MB_TYPE_INTRA16x16, 1, 15+16},
335 {MB_TYPE_INTRA16x16, 0, 15+16},
336 {MB_TYPE_INTRA16x16, 3, 15+16},
337 {MB_TYPE_INTRA16x16, 2, 15+32},
338 {MB_TYPE_INTRA16x16, 1, 15+32},
339 {MB_TYPE_INTRA16x16, 0, 15+32},
340 {MB_TYPE_INTRA16x16, 3, 15+32},
341 {MB_TYPE_INTRA_PCM , -1, -1},
342 };
343
344 typedef struct PMbInfo{
345 uint16_t type;
346 uint8_t partition_count;
347 } PMbInfo;
348
349 static const PMbInfo p_mb_type_info[5]={
350 {MB_TYPE_16x16|MB_TYPE_P0L0 , 1},
351 {MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},
352 {MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},
353 {MB_TYPE_8x8 , 4},
354 {MB_TYPE_8x8 |MB_TYPE_REF0 , 4},
355 };
356
357 static const PMbInfo p_sub_mb_type_info[4]={
358 {MB_TYPE_16x16|MB_TYPE_P0L0 , 1},
359 {MB_TYPE_16x8 |MB_TYPE_P0L0 , 2},
360 {MB_TYPE_8x16 |MB_TYPE_P0L0 , 2},
361 {MB_TYPE_8x8 |MB_TYPE_P0L0 , 4},
362 };
363
364 static const PMbInfo b_mb_type_info[23]={
365 {MB_TYPE_DIRECT , 1, },
366 {MB_TYPE_16x16|MB_TYPE_P0L0 , 1, },
367 {MB_TYPE_16x16 |MB_TYPE_P0L1 , 1, },
368 {MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1 , 1, },
369 {MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
370 {MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
371 {MB_TYPE_16x8 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
372 {MB_TYPE_8x16 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
373 {MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L1, 2, },
374 {MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L1, 2, },
375 {MB_TYPE_16x8 |MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
376 {MB_TYPE_8x16 |MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
377 {MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
378 {MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
379 {MB_TYPE_16x8 |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
380 {MB_TYPE_8x16 |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
381 {MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
382 {MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
383 {MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
384 {MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
385 {MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
386 {MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
387 {MB_TYPE_8x8 , 4, },
388 };
389
390 static const PMbInfo b_sub_mb_type_info[13]={
391 {MB_TYPE_DIRECT , 1, },
392 {MB_TYPE_16x16|MB_TYPE_P0L0 , 1, },
393 {MB_TYPE_16x16 |MB_TYPE_P0L1 , 1, },
394 {MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1 , 1, },
395 {MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
396 {MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
397 {MB_TYPE_16x8 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
398 {MB_TYPE_8x16 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
399 {MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
400 {MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
401 {MB_TYPE_8x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 4, },
402 {MB_TYPE_8x8 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 4, },
403 {MB_TYPE_8x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 4, },
404 };
405
406
407 static const uint8_t rem6[52]={
408 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, 4, 5, 0, 1, 2, 3,
409 };
410
411 static const uint8_t div6[52]={
412 0, 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,
413 };
414
415 static const uint16_t dequant_coeff[52][16]={
416 { 10, 13, 10, 13, 13, 16, 13, 16, 10, 13, 10, 13, 13, 16, 13, 16, },
417 { 11, 14, 11, 14, 14, 18, 14, 18, 11, 14, 11, 14, 14, 18, 14, 18, },
418 { 13, 16, 13, 16, 16, 20, 16, 20, 13, 16, 13, 16, 16, 20, 16, 20, },
419 { 14, 18, 14, 18, 18, 23, 18, 23, 14, 18, 14, 18, 18, 23, 18, 23, },
420 { 16, 20, 16, 20, 20, 25, 20, 25, 16, 20, 16, 20, 20, 25, 20, 25, },
421 { 18, 23, 18, 23, 23, 29, 23, 29, 18, 23, 18, 23, 23, 29, 23, 29, },
422 { 20, 26, 20, 26, 26, 32, 26, 32, 20, 26, 20, 26, 26, 32, 26, 32, },
423 { 22, 28, 22, 28, 28, 36, 28, 36, 22, 28, 22, 28, 28, 36, 28, 36, },
424 { 26, 32, 26, 32, 32, 40, 32, 40, 26, 32, 26, 32, 32, 40, 32, 40, },
425 { 28, 36, 28, 36, 36, 46, 36, 46, 28, 36, 28, 36, 36, 46, 36, 46, },
426 { 32, 40, 32, 40, 40, 50, 40, 50, 32, 40, 32, 40, 40, 50, 40, 50, },
427 { 36, 46, 36, 46, 46, 58, 46, 58, 36, 46, 36, 46, 46, 58, 46, 58, },
428 { 40, 52, 40, 52, 52, 64, 52, 64, 40, 52, 40, 52, 52, 64, 52, 64, },
429 { 44, 56, 44, 56, 56, 72, 56, 72, 44, 56, 44, 56, 56, 72, 56, 72, },
430 { 52, 64, 52, 64, 64, 80, 64, 80, 52, 64, 52, 64, 64, 80, 64, 80, },
431 { 56, 72, 56, 72, 72, 92, 72, 92, 56, 72, 56, 72, 72, 92, 72, 92, },
432 { 64, 80, 64, 80, 80, 100, 80, 100, 64, 80, 64, 80, 80, 100, 80, 100, },
433 { 72, 92, 72, 92, 92, 116, 92, 116, 72, 92, 72, 92, 92, 116, 92, 116, },
434 { 80, 104, 80, 104, 104, 128, 104, 128, 80, 104, 80, 104, 104, 128, 104, 128, },
435 { 88, 112, 88, 112, 112, 144, 112, 144, 88, 112, 88, 112, 112, 144, 112, 144, },
436 { 104, 128, 104, 128, 128, 160, 128, 160, 104, 128, 104, 128, 128, 160, 128, 160, },
437 { 112, 144, 112, 144, 144, 184, 144, 184, 112, 144, 112, 144, 144, 184, 144, 184, },
438 { 128, 160, 128, 160, 160, 200, 160, 200, 128, 160, 128, 160, 160, 200, 160, 200, },
439 { 144, 184, 144, 184, 184, 232, 184, 232, 144, 184, 144, 184, 184, 232, 184, 232, },
440 { 160, 208, 160, 208, 208, 256, 208, 256, 160, 208, 160, 208, 208, 256, 208, 256, },
441 { 176, 224, 176, 224, 224, 288, 224, 288, 176, 224, 176, 224, 224, 288, 224, 288, },
442 { 208, 256, 208, 256, 256, 320, 256, 320, 208, 256, 208, 256, 256, 320, 256, 320, },
443 { 224, 288, 224, 288, 288, 368, 288, 368, 224, 288, 224, 288, 288, 368, 288, 368, },
444 { 256, 320, 256, 320, 320, 400, 320, 400, 256, 320, 256, 320, 320, 400, 320, 400, },
445 { 288, 368, 288, 368, 368, 464, 368, 464, 288, 368, 288, 368, 368, 464, 368, 464, },
446 { 320, 416, 320, 416, 416, 512, 416, 512, 320, 416, 320, 416, 416, 512, 416, 512, },
447 { 352, 448, 352, 448, 448, 576, 448, 576, 352, 448, 352, 448, 448, 576, 448, 576, },
448 { 416, 512, 416, 512, 512, 640, 512, 640, 416, 512, 416, 512, 512, 640, 512, 640, },
449 { 448, 576, 448, 576, 576, 736, 576, 736, 448, 576, 448, 576, 576, 736, 576, 736, },
450 { 512, 640, 512, 640, 640, 800, 640, 800, 512, 640, 512, 640, 640, 800, 640, 800, },
451 { 576, 736, 576, 736, 736, 928, 736, 928, 576, 736, 576, 736, 736, 928, 736, 928, },
452 { 640, 832, 640, 832, 832,1024, 832,1024, 640, 832, 640, 832, 832,1024, 832,1024, },
453 { 704, 896, 704, 896, 896,1152, 896,1152, 704, 896, 704, 896, 896,1152, 896,1152, },
454 { 832,1024, 832,1024, 1024,1280,1024,1280, 832,1024, 832,1024, 1024,1280,1024,1280, },
455 { 896,1152, 896,1152, 1152,1472,1152,1472, 896,1152, 896,1152, 1152,1472,1152,1472, },
456 {1024,1280,1024,1280, 1280,1600,1280,1600, 1024,1280,1024,1280, 1280,1600,1280,1600, },
457 {1152,1472,1152,1472, 1472,1856,1472,1856, 1152,1472,1152,1472, 1472,1856,1472,1856, },
458 {1280,1664,1280,1664, 1664,2048,1664,2048, 1280,1664,1280,1664, 1664,2048,1664,2048, },
459 {1408,1792,1408,1792, 1792,2304,1792,2304, 1408,1792,1408,1792, 1792,2304,1792,2304, },
460 {1664,2048,1664,2048, 2048,2560,2048,2560, 1664,2048,1664,2048, 2048,2560,2048,2560, },
461 {1792,2304,1792,2304, 2304,2944,2304,2944, 1792,2304,1792,2304, 2304,2944,2304,2944, },
462 {2048,2560,2048,2560, 2560,3200,2560,3200, 2048,2560,2048,2560, 2560,3200,2560,3200, },
463 {2304,2944,2304,2944, 2944,3712,2944,3712, 2304,2944,2304,2944, 2944,3712,2944,3712, },
464 {2560,3328,2560,3328, 3328,4096,3328,4096, 2560,3328,2560,3328, 3328,4096,3328,4096, },
465 {2816,3584,2816,3584, 3584,4608,3584,4608, 2816,3584,2816,3584, 3584,4608,3584,4608, },
466 {3328,4096,3328,4096, 4096,5120,4096,5120, 3328,4096,3328,4096, 4096,5120,4096,5120, },
467 {3584,4608,3584,4608, 4608,5888,4608,5888, 3584,4608,3584,4608, 4608,5888,4608,5888, },
468 //{4096,5120,4096,5120, 5120,6400,5120,6400, 4096,5120,4096,5120, 5120,6400,5120,6400, },
469 //{4608,5888,4608,5888, 5888,7424,5888,7424, 4608,5888,4608,5888, 5888,7424,5888,7424, },
470 };
471
472 #define QUANT_SHIFT 22
473
474 static const int quant_coeff[52][16]={
475 { 419430,258111,419430,258111,258111,167772,258111,167772,419430,258111,419430,258111,258111,167772,258111,167772,},
476 { 381300,239675,381300,239675,239675,149131,239675,149131,381300,239675,381300,239675,239675,149131,239675,149131,},
477 { 322639,209715,322639,209715,209715,134218,209715,134218,322639,209715,322639,209715,209715,134218,209715,134218,},
478 { 299593,186414,299593,186414,186414,116711,186414,116711,299593,186414,299593,186414,186414,116711,186414,116711,},
479 { 262144,167772,262144,167772,167772,107374,167772,107374,262144,167772,262144,167772,167772,107374,167772,107374,},
480 { 233017,145889,233017,145889,145889, 92564,145889, 92564,233017,145889,233017,145889,145889, 92564,145889, 92564,},
481 { 209715,129056,209715,129056,129056, 83886,129056, 83886,209715,129056,209715,129056,129056, 83886,129056, 83886,},
482 { 190650,119837,190650,119837,119837, 74565,119837, 74565,190650,119837,190650,119837,119837, 74565,119837, 74565,},
483 { 161319,104858,161319,104858,104858, 67109,104858, 67109,161319,104858,161319,104858,104858, 67109,104858, 67109,},
484 { 149797, 93207,149797, 93207, 93207, 58356, 93207, 58356,149797, 93207,149797, 93207, 93207, 58356, 93207, 58356,},
485 { 131072, 83886,131072, 83886, 83886, 53687, 83886, 53687,131072, 83886,131072, 83886, 83886, 53687, 83886, 53687,},
486 { 116508, 72944,116508, 72944, 72944, 46282, 72944, 46282,116508, 72944,116508, 72944, 72944, 46282, 72944, 46282,},
487 { 104858, 64528,104858, 64528, 64528, 41943, 64528, 41943,104858, 64528,104858, 64528, 64528, 41943, 64528, 41943,},
488 { 95325, 59919, 95325, 59919, 59919, 37283, 59919, 37283, 95325, 59919, 95325, 59919, 59919, 37283, 59919, 37283,},
489 { 80660, 52429, 80660, 52429, 52429, 33554, 52429, 33554, 80660, 52429, 80660, 52429, 52429, 33554, 52429, 33554,},
490 { 74898, 46603, 74898, 46603, 46603, 29178, 46603, 29178, 74898, 46603, 74898, 46603, 46603, 29178, 46603, 29178,},
491 { 65536, 41943, 65536, 41943, 41943, 26844, 41943, 26844, 65536, 41943, 65536, 41943, 41943, 26844, 41943, 26844,},
492 { 58254, 36472, 58254, 36472, 36472, 23141, 36472, 23141, 58254, 36472, 58254, 36472, 36472, 23141, 36472, 23141,},
493 { 52429, 32264, 52429, 32264, 32264, 20972, 32264, 20972, 52429, 32264, 52429, 32264, 32264, 20972, 32264, 20972,},
494 { 47663, 29959, 47663, 29959, 29959, 18641, 29959, 18641, 47663, 29959, 47663, 29959, 29959, 18641, 29959, 18641,},
495 { 40330, 26214, 40330, 26214, 26214, 16777, 26214, 16777, 40330, 26214, 40330, 26214, 26214, 16777, 26214, 16777,},
496 { 37449, 23302, 37449, 23302, 23302, 14589, 23302, 14589, 37449, 23302, 37449, 23302, 23302, 14589, 23302, 14589,},
497 { 32768, 20972, 32768, 20972, 20972, 13422, 20972, 13422, 32768, 20972, 32768, 20972, 20972, 13422, 20972, 13422,},
498 { 29127, 18236, 29127, 18236, 18236, 11570, 18236, 11570, 29127, 18236, 29127, 18236, 18236, 11570, 18236, 11570,},
499 { 26214, 16132, 26214, 16132, 16132, 10486, 16132, 10486, 26214, 16132, 26214, 16132, 16132, 10486, 16132, 10486,},
500 { 23831, 14980, 23831, 14980, 14980, 9321, 14980, 9321, 23831, 14980, 23831, 14980, 14980, 9321, 14980, 9321,},
501 { 20165, 13107, 20165, 13107, 13107, 8389, 13107, 8389, 20165, 13107, 20165, 13107, 13107, 8389, 13107, 8389,},
502 { 18725, 11651, 18725, 11651, 11651, 7294, 11651, 7294, 18725, 11651, 18725, 11651, 11651, 7294, 11651, 7294,},
503 { 16384, 10486, 16384, 10486, 10486, 6711, 10486, 6711, 16384, 10486, 16384, 10486, 10486, 6711, 10486, 6711,},
504 { 14564, 9118, 14564, 9118, 9118, 5785, 9118, 5785, 14564, 9118, 14564, 9118, 9118, 5785, 9118, 5785,},
505 { 13107, 8066, 13107, 8066, 8066, 5243, 8066, 5243, 13107, 8066, 13107, 8066, 8066, 5243, 8066, 5243,},
506 { 11916, 7490, 11916, 7490, 7490, 4660, 7490, 4660, 11916, 7490, 11916, 7490, 7490, 4660, 7490, 4660,},
507 { 10082, 6554, 10082, 6554, 6554, 4194, 6554, 4194, 10082, 6554, 10082, 6554, 6554, 4194, 6554, 4194,},
508 { 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647, 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647,},
509 { 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355, 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355,},
510 { 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893, 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893,},
511 { 6554, 4033, 6554, 4033, 4033, 2621, 4033, 2621, 6554, 4033, 6554, 4033, 4033, 2621, 4033, 2621,},
512 { 5958, 3745, 5958, 3745, 3745, 2330, 3745, 2330, 5958, 3745, 5958, 3745, 3745, 2330, 3745, 2330,},
513 { 5041, 3277, 5041, 3277, 3277, 2097, 3277, 2097, 5041, 3277, 5041, 3277, 3277, 2097, 3277, 2097,},
514 { 4681, 2913, 4681, 2913, 2913, 1824, 2913, 1824, 4681, 2913, 4681, 2913, 2913, 1824, 2913, 1824,},
515 { 4096, 2621, 4096, 2621, 2621, 1678, 2621, 1678, 4096, 2621, 4096, 2621, 2621, 1678, 2621, 1678,},
516 { 3641, 2280, 3641, 2280, 2280, 1446, 2280, 1446, 3641, 2280, 3641, 2280, 2280, 1446, 2280, 1446,},
517 { 3277, 2016, 3277, 2016, 2016, 1311, 2016, 1311, 3277, 2016, 3277, 2016, 2016, 1311, 2016, 1311,},
518 { 2979, 1872, 2979, 1872, 1872, 1165, 1872, 1165, 2979, 1872, 2979, 1872, 1872, 1165, 1872, 1165,},
519 { 2521, 1638, 2521, 1638, 1638, 1049, 1638, 1049, 2521, 1638, 2521, 1638, 1638, 1049, 1638, 1049,},
520 { 2341, 1456, 2341, 1456, 1456, 912, 1456, 912, 2341, 1456, 2341, 1456, 1456, 912, 1456, 912,},
521 { 2048, 1311, 2048, 1311, 1311, 839, 1311, 839, 2048, 1311, 2048, 1311, 1311, 839, 1311, 839,},
522 { 1820, 1140, 1820, 1140, 1140, 723, 1140, 723, 1820, 1140, 1820, 1140, 1140, 723, 1140, 723,},
523 { 1638, 1008, 1638, 1008, 1008, 655, 1008, 655, 1638, 1008, 1638, 1008, 1008, 655, 1008, 655,},
524 { 1489, 936, 1489, 936, 936, 583, 936, 583, 1489, 936, 1489, 936, 936, 583, 936, 583,},
525 { 1260, 819, 1260, 819, 819, 524, 819, 524, 1260, 819, 1260, 819, 819, 524, 819, 524,},
526 { 1170, 728, 1170, 728, 728, 456, 728, 456, 1170, 728, 1170, 728, 728, 456, 728, 456,},
527 };