/*
Project : H.264 encoder test
Module : Tables
Author : Marko 'Fador' Viitanen
Date : 25/6/2009
Modified : 25/6/2009
*/
#include "common.h"
#include "cavlc.h"
#include "tables.h"
// [total_zeros][totalCoeffs]
const bitTable total_zeros_4x4[16][16]=
{
{{1,1},{3,7},{4,5},{5,3},{4,5},{6,1},{6,1},{6,1},{6,1},{5,1},{4,0},{4,0},{3,0},{2,0},{1,0},{0,0}},
{{3,3},{3,6},{3,7},{3,7},{4,4},{5,1},{5,1},{4,1},{6,0},{5,0},{4,1},{4,1},{3,1},{2,1},{1,1},{0,0}},
{{3,2},{3,5},{3,6},{4,5},{4,3},{3,7},{3,5},{5,1},{4,1},{3,1},{3,1},{2,1},{1,1},{1,1},{0,0},{0,0}},
{{4,3},{3,4},{3,5},{4,4},{3,7},{3,6},{3,4},{3,3},{2,3},{2,3},{3,2},{1,1},{2,1},{0,0},{0,0},{0,0}},
{{4,2},{3,3},{4,4},{3,6},{3,6},{3,5},{3,3},{2,3},{2,2},{2,2},{1,1},{3,1},{0,0},{0,0},{0,0},{0,0}},
{{5,3},{4,5},{4,3},{3,5},{3,5},{3,4},{2,3},{2,2},{3,1},{2,1},{3,3},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{5,2},{4,4},{3,4},{3,4},{3,4},{3,3},{3,2},{3,2},{2,1},{4,1},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{6,3},{4,3},{3,3},{4,3},{3,3},{3,2},{4,1},{3,1},{5,1},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{6,2},{4,2},{4,2},{3,3},{4,2},{4,1},{3,1},{6,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{7,3},{5,3},{5,3},{4,2},{5,1},{3,1},{6,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{7,2},{5,2},{5,2},{5,2},{4,1},{6,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{8,3},{6,3},{6,1},{5,1},{5,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{8,2},{6,2},{5,1},{5,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{9,3},{6,1},{6,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{9,2},{6,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{9,1},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}
};
// [run_before][zeros_left]
const bitTable run_before_table[15][7]=
{
{{1,1},{1,1},{2,3},{2,3},{2,3},{2,3},{3,7}},
{{1,0},{2,1},{2,2},{2,2},{2,2},{3,0},{3,4}},
{{0,0},{2,0},{2,1},{2,1},{3,3},{3,1},{3,5}},
{{0,0},{0,0},{2,0},{3,1},{3,2},{3,3},{3,4}},
{{0,0},{0,0},{0,0},{3,0},{3,1},{3,2},{3,3}},
{{0,0},{0,0},{0,0},{0,0},{3,0},{3,5},{3,2}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{3,4},{3,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{4,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{5,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{6,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{7,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{8,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{9,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{10,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{11,1}}
};
//coeff tokens [totalCoeffs][trailingOnes][tableid]
const bitTable coeff_token_tables[17][4][6]=
{
{
{{1,1},{2,3},{4,15},{6,3},{2,1},{1,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}
},
{
{{6,5},{6,11},{6,15},{6,0},{6,7},{7,15}},
{{2,1},{2,2},{8,224},{2,1},{1,1},{2,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}
},
{
{{8,7},{6,7},{6,11},{6,4},{6,4},{7,14}},
{{6,4},{5,7},{5,15},{6,5},{6,6},{7,13}},
{{3,1},{3,3},{4,13},{6,6},{3,1},{3,1}},
{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}
},
{
{{9,7},{7,7},{6,8},{6,8},{6,3},{9,7}},
{{8,6},{6,10},{5,12},{6,9},{7,3},{7,12}},
{{7,5},{6,9},{5,14},{6,10},{7,2},{7,11}},
{{5,3},{4,5},{4,12},{6,11},{6,5},{5,1}}
},
{
{{10,7},{8,7},{7,15},{6,12},{6,2},{9,6}},
{{9,6},{6,6},{5,10},{6,13},{8,3},{9,5}},
{{8,5},{6,5},{5,11},{6,14},{8,2},{7,10}},
{{6,3},{4,4},{4,11},{6,15},{7,0},{6,1}}
},
{
{{11,7},{8,4},{7,11},{6,16},{1,0},{10,7}},
{{10,6},{7,6},{5,8},{6,17},{1,0},{10,6}},
{{9,5},{7,5},{5,9},{6,18},{1,0},{9,4}},
{{7,4},{5,6},{4,10},{6,19},{1,0},{7,9}}
},
{
{{13,15},{9,7},{7,9},{6,20},{1,0},{11,7}},
{{11,6},{8,6},{6,14},{6,21},{1,0},{11,6}},
{{10,5},{8,5},{6,13},{6,22},{1,0},{10,5}},
{{8,4},{6,8},{4,9},{6,23},{1,0},{7,8}}
},
{
{{13,11},{11,15},{7,8},{6,24},{1,0},{12,7}},
{{13,14},{9,6},{6,10},{6,25},{1,0},{12,6}},
{{11,5},{9,5},{6,9},{6,26},{1,0},{11,5}},
{{9,4},{6,4},{4,8},{6,27},{1,0},{10,4}}
},
{
{{13,8},{11,11},{8,15},{6,28},{1,0},{13,7}},
{{13,10},{11,14},{7,14},{6,29},{1,0},{12,5}},
{{13,13},{11,13},{7,13},{6,30},{1,0},{12,4}},
{{10,4},{7,4},{5,13},{6,31},{1,0},{11,4}}
},
{
{{14,15},{12,15},{8,11},{6,32},{1,0},{1,0}},
{{14,14},{11,10},{8,14},{6,33},{1,0},{1,0}},
{{13,9},{11,9},{7,10},{6,34},{1,0},{1,0}},
{{11,4},{9,4},{6,12},{6,35},{1,0},{1,0}}
},
{
{{14,11},{12,11},{9,15},{6,36},{1,0},{1,0}},
{{14,10},{12,14},{8,10},{6,37},{1,0},{1,0}},
{{14,13},{12,13},{8,13},{6,38},{1,0},{1,0}},
{{13,12},{11,12},{7,12},{6,39},{1,0},{1,0}}
},
{
{{15,15},{12,8},{9,11},{6,40},{1,0},{1,0}},
{{15,14},{12,10},{9,14},{6,41},{1,0},{1,0}},
{{14,9},{12,9},{8,9},{6,42},{1,0},{1,0}},
{{14,12},{11,8},{8,12},{6,43},{1,0},{1,0}}
},
{
{{15,11},{13,15},{8,4},{1,0},{6,44},{1,0}},
{{15,10},{13,14},{8,5},{1,0},{6,45},{1,0}},
{{15,13},{13,13},{8,6},{1,1},{6,46},{1,0}},
{{14,8},{12,12},{8,8},{6,47},{1,0},{1,0}}
},
{
{{16,15},{13,11},{10,13},{6,48},{1,0},{1,0}},
{{15,1},{13,10},{9,7},{6,49},{1,0},{1,0}},
{{15,9},{13,9},{9,9},{6,50},{1,0},{1,0}},
{{15,12},{13,12},{9,12},{6,51},{1,0},{1,0}}
},
{
{{16,11},{13,7},{10,9},{6,52},{1,0},{1,0}},
{{16,14},{14,11},{10,12},{6,53},{1,0},{1,0}},
{{16,13},{13,6},{10,11},{6,54},{1,0},{1,0}},
{{15,8},{13,8},{10,10},{6,55},{1,0},{1,0}}
},
{
{{16,7},{14,9},{10,5},{6,56},{1,0},{1,0}},
{{16,10},{14,8},{10,8},{6,57},{1,0},{1,0}},
{{16,9},{14,10},{10,7},{6,58},{1,0},{1,0}},
{{16,12},{13,1},{10,6},{6,59},{1,0},{1,0}}
},
{
{{16,4},{14,7},{10,1},{6,60},{1,0},{1,0}},
{{16,6},{14,6},{10,4},{6,61},{1,0},{1,0}},
{{16,5},{14,5},{10,3},{6,62},{1,0},{1,0}},
{{16,8},{14,4},{10,2},{6,63},{1,0},{1,0}}
}
};
//Zig-zag scan order for 4x4 block
const uint8 zigzag_4x4[] =
{
0, 1, 4, 8,
5, 2, 3, 6,
9,12,13,10,
7,11,14,15
};
const uint8 coded_block_pattern_inter[] =
{
0, 16, 1,2, 4, 8, 32, 3,5, 10, 12, 15, 47, 7, 11, 13, 14, 6,9, 31, 35, 37, 42, 44, 33, 34,
36, 40, 39,43,45,46, 17, 18, 20, 24, 19,21,26, 28, 23, 27, 29, 30, 22, 25, 38, 41
};
const uint8 coded_block_pattern_intra[] = {
47,31,15,0,23,27,29,30,7,11,13,14, 39, 43, 45, 46, 16, 3, 5, 10, 12, 19, 21, 26, 28, 35,
37, 42, 44, 1, 2, 4, 8, 17, 18, 20, 24, 6, 9, 22, 25, 32, 33, 34, 36, 40, 38, 41
};