• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2 *
3 * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18 /**
19 *******************************************************************************
20 * @file
21 *  ihevc_common_tables.c
22 *
23 * @brief
24 *  Contains common global tables
25 *
26 * @author
27 *  Harish M
28 *
29 * @par List of Tables:
30 * gai4_ihevc_max_luma_pic_size
31 * gai4_ihevc_max_wd_ht
32 * gai4_ihevc_min_wd_ht
33 * gai4_ihevc_ang_table
34 * col_for_intra_luma
35 * col_for_intra_chroma
36 * idx_neg_vals_3_9
37 * idx_neg_idx_3_9
38 * idx_neg_idx_chroma_3_9
39 * idx_neg_idx_11_17
40 * idx_neg_idx_chroma_11_17
41 * gai4_ihevc_inv_ang_table
42 * gau1_ihevc_invscan8x8
43 * gau1_ihevc_invscan4x4
44 * gau1_ihevc_invscan2x2
45 * gau1_ihevc_scan8x8
46 * gau1_ihevc_scan4x4
47 * gau1_ihevc_scan2x2
48 * *gapv_ihevc_scan
49 * *gapv_ihevc_invscan
50 * gau1_ihevc_chroma_qp_scale
51 * gai1_ihevc_chroma_qp_scale
52 * gau1_ihevc_planar_factor
53 * gau1_ihevc_planar_factor_1
54 * gai4_ihevc_ang_table_chroma
55 * gai4_ihevc_inv_ang_table_chroma
56 * gau1_ihevc_planar_factor_chroma
57 * gau1_intra_pred_ref_filter
58 * gi1_table_edge_idx
59 * gu1_table_band_idx
60 * gu2_table_band_idx
61 *
62 * @remarks
63 *  None
64 *
65 *******************************************************************************
66 */
67 
68 #include "ihevc_typedefs.h"
69 #include "ihevc_platform_macros.h"
70 #include "ihevc_common_tables.h"
71 
72 /*****************************************************************************/
73 /* Level specific tables                                                     */
74 /*****************************************************************************/
75 
76 /**
77  * Array giving size of max luma samples in a picture for a given level
78  */
79 const WORD32 gai4_ihevc_max_luma_pic_size[] =
80 {
81     /* Level 1 */
82     36864,
83     /* Level 2 */
84     122880,
85     /* Level 2.1 */
86     245760,
87     /* Level 3 */
88     552960,
89     /* Level 3.1 */
90     983040,
91     /* Level 4 */
92     2228224,
93     /* Level 4.1 */
94     2228224,
95     /* Level 5 */
96     8912896,
97     /* Level 5.1 */
98     8912896,
99     /* Level 5.2 */
100     8912896,
101     /* Level 6 */
102     33423360,
103     /* Level 6.1 */
104     33423360,
105     /* Level 6.2 */
106     33423360
107 };
108 /** Max width and height allowed for a given level */
109 /** This is derived as SQRT(8 * gai4_ihevc_max_luma_pic_size[]) */
110 const WORD32 gai4_ihevc_max_wd_ht[] =
111 {
112     /* Level 1 */
113     543,
114     /* Level 2 */
115     991,
116     /* Level 2.1 */
117     1402,
118     /* Level 3 */
119     2103,
120     /* Level 3.1 */
121     2804,
122     /* Level 4 */
123     4222,
124     /* Level 4.1 */
125     4222,
126     /* Level 5 */
127     8444,
128     /* Level 5.1 */
129     8444,
130     /* Level 5.2 */
131     8444,
132     /* Level 6 */
133     16888,
134     /* Level 6.1 */
135     16888,
136     /* Level 6.2 */
137     16888
138 };
139 
140 /** Min width and height allowed for a given level */
141 /** This is derived as gai4_ihevc_max_luma_pic_size[]/gai4_ihevc_max_wd_ht[] */
142 const WORD32 gai4_ihevc_min_wd_ht[] =
143 {
144     /* Level 1 */
145     67,
146     /* Level 2 */
147     123,
148     /* Level 2.1 */
149     175,
150     /* Level 3 */
151     262,
152     /* Level 3.1 */
153     350,
154     /* Level 4 */
155     527,
156     /* Level 4.1 */
157     527,
158     /* Level 5 */
159     1055,
160     /* Level 5.1 */
161     1055,
162     /* Level 5.2 */
163     1055,
164     /* Level 6 */
165     2111,
166     /* Level 6.1 */
167     2111,
168     /* Level 6.2 */
169     2111
170 };
171 /*****************************************************************************/
172 /* Intra prediction tables                                                   */
173 /*****************************************************************************/
174 /**
175  * Intra pred angles
176  */
177 /* g_ang_table = tan(actual angle) in Q5 format for all 33 modes */
178 const WORD32 gai4_ihevc_ang_table[35] =
179     { 0, 0, 32, 26, 21, 17, 13, 9, 5, 2, 0, -2, -5, -9, -13, -17, -21, -26, -32,
180                     -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
181 
182 const WORD8 col_for_intra_luma[32] =
183     { 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,
184                     29, 30, 31, 32 };
185 
186 const WORD8 col_for_intra_chroma[32] =
187     { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16 };
188 
189 const WORD8 idx_neg_vals_3_9[7] =
190     { 26, 21, 17, 13, 9, 5, 2 };
191 
192 const WORD32 idx_neg_idx_3_9[28] =
193     { 6, 13, 19, 26, 5, 10, 15, 21, 4, 8, 12, 17, 3, 6, 9, 13, 2, 4, 6, 9,
194                     1, 2, 3, 5, 0, 0, 1, 2 };
195 
196 
197 const WORD32 idx_neg_idx_chroma_3_9[28] =
198   { 3, 6, 9, 13,
199     2, 5, 7, 10,
200     2, 4, 6, 8,
201     1, 3, 4, 6,
202     1, 2, 3, 4,
203     0, 1, 1, 2,
204     0, 0, 0, 1 };
205 const WORD32 idx_neg_idx_11_17[28] =
206     { -1, -1, -2, -2, -2, -3, -4, -5, -3, -5, -7, -9, -4, -7, -10, -13, -5, -9, -13, -17, -6, -11,
207                     -16, -21, -7, -13, -20, -26 };
208 
209 const WORD32 idx_neg_idx_chroma_11_17[28] =
210   { -1, -1, -1, -1,
211     -1, -2, -2, -3,
212     -2, -3, -4, -5,
213     -2, -4, -5, -7,
214     -3, -5, -7, -9,
215     -3, -6, -8, -11,
216     -4, -7, -10, -13 };
217 
218 /**
219  * Intra pred inverse angles
220  */
221 /* g_invAngTable = Inverse angle in Q5 format, required for negative angles */
222 const WORD32 gai4_ihevc_inv_ang_table[14] =
223     { 4096, 1638, 910, 630, 482, 390, 315, 315, 390, 482, 630, 910, 1638, 4096 };
224 
225 /*****************************************************************************/
226 /* Scan matrices                                                             */
227 /*****************************************************************************/
228 /**
229  * Inverse Scan matrix for 8x8 Section 6.5.3
230  */
231 const UWORD8  gau1_ihevc_invscan8x8[][64] =
232 {
233     /* Upright diagonal */
234     {
235         0,  8,  1,  16, 9,  2,  24, 17,
236         10, 3,  32, 25, 18, 11, 4,  40,
237         33, 26, 19, 12, 5,  48, 41, 34,
238         27, 20, 13, 6,  56, 49, 42, 35,
239         28, 21, 14, 7,  57, 50, 43, 36,
240         29, 22, 15, 58, 51, 44, 37, 30,
241         23, 59, 52, 45, 38, 31, 60, 53,
242         46, 39, 61, 54, 47, 62, 55, 63
243     },
244     /* Horizontal */
245     {
246         0,  1,  2,  3,  4,  5,  6,  7,
247         8,  9,  10, 11, 12, 13, 14, 15,
248         16, 17, 18, 19, 20, 21, 22, 23,
249         24, 25, 26, 27, 28, 29, 30, 31,
250         32, 33, 34, 35, 36, 37, 38, 39,
251         40, 41, 42, 43, 44, 45, 46, 47,
252         48, 49, 50, 51, 52, 53, 54, 55,
253         56, 57, 58, 59, 60, 61, 62, 63
254     },
255     /* Vertical */
256     {
257         0,  8,  16, 24, 32, 40, 48, 56,
258         1,  9,  17, 25, 33, 41, 49, 57,
259         2,  10, 18, 26, 34, 42, 50, 58,
260         3,  11, 19, 27, 35, 43, 51, 59,
261         4,  12, 20, 28, 36, 44, 52, 60,
262         5,  13, 21, 29, 37, 45, 53, 61,
263         6,  14, 22, 30, 38, 46, 54, 62,
264         7,  15, 23, 31, 39, 47, 55, 63
265     }
266 };
267 
268 /**
269  * Inverse Scan matrix for 4x4 Section 6.5.3
270  */
271 const UWORD8  gau1_ihevc_invscan4x4[][16] =
272 {
273     /* Upright diagonal */
274     {
275         0, 4,  1,  8,
276         5, 2,  12, 9,
277         6, 3,  13, 10,
278         7, 14, 11, 15
279     },
280     /* Horizontal */
281     {
282         0,  1,  2,  3,
283         4,  5,  6,  7,
284         8,  9,  10, 11,
285         12, 13, 14, 15
286     },
287     /* Vertical */
288     {
289         0,  4,  8,  12,
290         1,  5,  9,  13,
291         2,  6,  10, 14,
292         3,  7,  11, 15
293     }
294 };
295 
296 /**
297  * Inverse Scan matrix for 4x4 Section 6.5.3
298  */
299 const UWORD8  gau1_ihevc_invscan2x2[][4] =
300 {
301     /* Upright diagonal */
302     {
303         0,  2,
304         1,  3
305     },
306     /* Horizontal */
307     {
308         0,  1,
309         2,  3
310     },
311     /* Vertical */
312     {
313         0,  2,
314         1,  3,
315     }
316 };
317 
318 /**
319  * Scan matrix for 8x8 Section 6.5.3
320  */
321 
322 const UWORD8  gau1_ihevc_scan8x8[][64] =
323 {
324     /* Upright diagonal */
325     {
326         0,  2,  5,  9,  14, 20, 27, 35,
327         1,  4,  8,  13, 19, 26, 34, 42,
328         3,  7,  12, 18, 25, 33, 41, 48,
329         6,  11, 17, 24, 32, 40, 47, 53,
330         10, 16, 23, 31, 39, 46, 52, 57,
331         15, 22, 30, 38, 45, 51, 56, 60,
332         21, 29, 37, 44, 50, 55, 59, 62,
333         28, 36, 43, 49, 54, 58, 61, 63
334     },
335     /* Horizontal */
336     {
337         0,  1,  2,  3,  4,  5,  6,  7,
338         8,  9,  10, 11, 12, 13, 14, 15,
339         16, 17, 18, 19, 20, 21, 22, 23,
340         24, 25, 26, 27, 28, 29, 30, 31,
341         32, 33, 34, 35, 36, 37, 38, 39,
342         40, 41, 42, 43, 44, 45, 46, 47,
343         48, 49, 50, 51, 52, 53, 54, 55,
344         56, 57, 58, 59, 60, 61, 62, 63
345     },
346     /* Vertical */
347     {
348         0,  8,  16, 24, 32, 40, 48, 56,
349         1,  9,  17, 25, 33, 41, 49, 57,
350         2,  10, 18, 26, 34, 42, 50, 58,
351         3,  11, 19, 27, 35, 43, 51, 59,
352         4,  12, 20, 28, 36, 44, 52, 60,
353         5,  13, 21, 29, 37, 45, 53, 61,
354         6,  14, 22, 30, 38, 46, 54, 62,
355         7,  15, 23, 31, 39, 47, 55, 63
356     }
357 };
358 
359 /**
360  * Scan matrix for 4x4 Section 6.5.3
361  */
362 const UWORD8  gau1_ihevc_scan4x4[][16] =
363 {
364     /* Upright diagonal */
365     {
366         0,  2,  5,  9,
367         1,  4,  8,  12,
368         3,  7,  11, 14,
369         6,  10, 13, 15
370     },
371     /* Horizontal */
372     {
373         0,  1,  2,  3,
374         4,  5,  6,  7,
375         8,  9,  10, 11,
376         12, 13, 14, 15
377     },
378     /* Vertical */
379     {
380         0,  4,  8,  12,
381         1,  5,  9,  13,
382         2,  6,  10, 14,
383         3,  7,  11, 15
384     }
385 };
386 
387 /**
388  * Scan matrix for 4x4 Section 6.5.3
389  */
390 const UWORD8  gau1_ihevc_scan2x2[][4] =
391 {
392     /* Upright diagonal */
393     {
394         0,  2,
395         1,  3
396     },
397     /* Horizontal */
398     {
399         0,  1,
400         2,  3
401     },
402     /* Vertical */
403     {
404         0,  2,
405         1,  3,
406     }
407 };
408 
409 /**
410  * Table containing all the scan matrices
411  */
412 const void *gapv_ihevc_scan[] =
413 {
414     gau1_ihevc_scan2x2[0],
415     gau1_ihevc_scan4x4[0],
416     gau1_ihevc_scan8x8[0],
417 
418     gau1_ihevc_scan2x2[1],
419     gau1_ihevc_scan4x4[1],
420     gau1_ihevc_scan8x8[1],
421 
422     gau1_ihevc_scan2x2[2],
423     gau1_ihevc_scan4x4[2],
424     gau1_ihevc_scan8x8[2],
425 
426 };
427 
428 const void *gapv_ihevc_invscan[] =
429 {
430     gau1_ihevc_invscan2x2[0],
431     gau1_ihevc_invscan4x4[0],
432     gau1_ihevc_invscan8x8[0],
433 
434     gau1_ihevc_invscan2x2[1],
435     gau1_ihevc_invscan4x4[1],
436     gau1_ihevc_invscan8x8[1],
437 
438     gau1_ihevc_invscan2x2[2],
439     gau1_ihevc_invscan4x4[2],
440     gau1_ihevc_invscan8x8[2],
441 };
442 /**
443  * Table for luma to chroma qp conversion
444  */
445 
446 // FOR MAIN branch encoder ( 8 bit)
447 const UWORD8 gau1_ihevc_chroma_qp_scale[58] =
448 {
449 
450      0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
451     17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 30, 31, 32,
452     33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44,
453     45, 46, 47, 48, 49, 50, 51
454 };
455 
456 // FOR HBD branch encoder ( 8, 10 and 12 bit)
457 const WORD8 gai1_ihevc_chroma_qp_scale[82]=  //EXTENDED for 12 bit
458 {
459   -24,-23,-22,-21,-20,-19,-18,-17,-16,-15,-14,-13,
460   -12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,
461   0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,
462   17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32,
463   33,33,34,34,35,35,36,36,37,37,38,39,40,41,42,43,44,
464   45,46,47,48,49,50,51
465 };
466 
467 
468 /** constant planar factor values table */
469 const UWORD8 gau1_ihevc_planar_factor[65] = {    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
470     11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
471     21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
472     31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
473     41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
474     51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
475     61, 62, 63, 64 };
476 //AX CHANGES
477 const UWORD8 gau1_ihevc_planar_factor_1[32] = {    1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9,
478     17, 17, 17, 17, 17, 17, 17, 17, 25, 25, 25, 25, 25, 25,
479     25, 25 };
480 //AX CHANGES
481 
482 /** g_ang_table = tan(actual angle) in Q5 format for all 33 modes */
483 const WORD32 gai4_ihevc_ang_table_chroma[35] = { 0, 0, 32, 26, 21, 17, 13, 9, 5, 2, 0, -2,  -5, -9,
484     -13, -17, -21, -26, -32, -26, -21, -17, -13, -9, -5,
485     -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
486 /** g_invAngTable = Inverse angle in Q5 format, required for negative angles */
487 const WORD32 gai4_ihevc_inv_ang_table_chroma[14] = { 4096, 1638, 910, 630, 482, 390, 315,
488     315, 390, 482, 630, 910, 1638, 4096 };
489 
490 
491 /** constant planar factor values table */
492 const UWORD8 gau1_ihevc_planar_factor_chroma[33] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
493     11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
494     21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
495     31, 32  };
496 
497 
498 
499 /** Filter flag values for intra pred referenece filtering - intra pred mode is the index
500 *   flag for nt = 4 is the Bit 0, nt = 8 is Bit 1, nt = 16 is Bit 2, nt = 32 is Bit 3
501 */
502 const UWORD8 gau1_intra_pred_ref_filter[] =
503 {
504     14,  0, 14, 12, 12, 12, 12,
505     12, 12,  8,  0,  8, 12, 12,
506     12, 12, 12, 12, 14, 12, 12,
507     12, 12, 12, 12,  8,  0,  8,
508     12, 12, 12, 12, 12, 12, 14
509 };
510 
511 
512 const WORD8 gi1_table_edge_idx[8] = { 1, 2, 0, 3, 4, 0, 0, 0 }; /* First 5 values are valid. Last 3 dummy values are added to help SIMD load*/
513 
514 const UWORD8 gu1_table_band_idx[32] = {  0,  1,  2,  3,  4,  5,  6,  7,
515                                          8,  9, 10, 11, 12, 13, 14, 15,
516                                         16, 17, 18, 19, 20, 21, 22, 23,
517                                         24, 25, 26, 27, 28, 29, 30, 31
518 };
519 
520 const UWORD16 gu2_table_band_idx[32] = {  0,  1,  2,  3,  4,  5,  6,  7,
521                                          8,  9, 10, 11, 12, 13, 14, 15,
522                                         16, 17, 18, 19, 20, 21, 22, 23,
523                                         24, 25, 26, 27, 28, 29, 30, 31
524 };
525 
526 #ifdef ENABLE_SSE4_1_INTR
527 /*Used as a lookup table to have popcnt instruction working for SSE4.1 platform.
528 Each unit indicates number of 1s the index at which it is persent
529 */
530 const WORD8   gi1_popcnt_byte_table[] =
531 {
532     0,  1,  1,  2,  1,  2,  2,  3,  1,  2,  2,  3,  2,  3,  3,  4,
533     1,  2,  2,  3,  2,  3,  3,  4,  2,  3,  3,  4,  3,  4,  4,  5,
534     1,  2,  2,  3,  2,  3,  3,  4,  2,  3,  3,  4,  3,  4,  4,  5,
535     2,  3,  3,  4,  3,  4,  4,  5,  3,  4,  4,  5,  4,  5,  5,  6,
536     1,  2,  2,  3,  2,  3,  3,  4,  2,  3,  3,  4,  3,  4,  4,  5,
537     2,  3,  3,  4,  3,  4,  4,  5,  3,  4,  4,  5,  4,  5,  5,  6,
538     2,  3,  3,  4,  3,  4,  4,  5,  3,  4,  4,  5,  4,  5,  5,  6,
539     3,  4,  4,  5,  4,  5,  5,  6,  4,  5,  5,  6,  5,  6,  6,  7,
540     1,  2,  2,  3,  2,  3,  3,  4,  2,  3,  3,  4,  3,  4,  4,  5,
541     2,  3,  3,  4,  3,  4,  4,  5,  3,  4,  4,  5,  4,  5,  5,  6,
542     2,  3,  3,  4,  3,  4,  4,  5,  3,  4,  4,  5,  4,  5,  5,  6,
543     3,  4,  4,  5,  4,  5,  5,  6,  4,  5,  5,  6,  5,  6,  6,  7,
544     2,  3,  3,  4,  3,  4,  4,  5,  3,  4,  4,  5,  4,  5,  5,  6,
545     3,  4,  4,  5,  4,  5,  5,  6,  4,  5,  5,  6,  5,  6,  6,  7,
546     3,  4,  4,  5,  4,  5,  5,  6,  4,  5,  5,  6,  5,  6,  6,  7,
547     4,  5,  5,  6,  5,  6,  6,  7,  5,  6,  6,  7,  6,  7,  7,  8
548 };
549 #endif
550