📄 umc_h264_bs.cpp
字号:
{ {11,16},{14,16},{13,16},{ 8,15} }, // 14 Total_Coeffs
{ { 7,16},{10,16},{ 9,16},{12,16} }, // 15 Total_Coeffs
{ { 4,16},{ 6,16},{ 5,16},{ 8,16} } // 16 Total_Coeffs
},
{ // Num-VLC1
// 0 1 2 3 <-- Trailing Ones
{ { 3, 2},{ 0, 0},{ 0, 0},{ 0, 0} }, // 0 Total_Coeffs
{ {11, 6},{ 2, 2},{ 0, 0},{ 0, 0} }, // 1 Total_Coeffs
{ { 7, 6},{ 7, 5},{ 3, 3},{ 0, 0} }, // 2 Total_Coeffs
{ { 7, 7},{10, 6},{ 9, 6},{ 5, 4} }, // 3 Total_Coeffs
{ { 7, 8},{ 6, 6},{ 5, 6},{ 4, 4} }, // 4 Total_Coeffs
{ { 4, 8},{ 6, 7},{ 5, 7},{ 6, 5} }, // 5 Total_Coeffs
{ { 7, 9},{ 6, 8},{ 5, 8},{ 8, 6} }, // 6 Total_Coeffs
{ {15,11},{ 6, 9},{ 5, 9},{ 4, 6} }, // 7 Total_Coeffs
{ {11,11},{14,11},{13,11},{ 4, 7} }, // 8 Total_Coeffs
{ {15,12},{10,11},{ 9,11},{ 4, 9} }, // 9 Total_Coeffs
{ {11,12},{14,12},{13,12},{12,11} }, // 10 Total_Coeffs
{ { 8,12},{10,12},{ 9,12},{ 8,11} }, // 11 Total_Coeffs
{ {15,13},{14,13},{13,13},{12,12} }, // 12 Total_Coeffs
{ {11,13},{10,13},{ 9,13},{12,13} }, // 13 Total_Coeffs
{ { 7,13},{11,14},{ 6,13},{ 8,13} }, // 14 Total_Coeffs
{ { 9,14},{ 8,14},{10,14},{ 1,13} }, // 15 Total_Coeffs
{ { 7,14},{ 6,14},{ 5,14},{ 4,14} } // 16 Total_Coeffs
},
{ // Num-VLC2
// 0 1 2 3 <-- Trailing Ones
{ {15, 4},{ 0, 0},{ 0, 0},{ 0, 0} }, // 0 Total_Coeffs
{ {15, 6},{14, 4},{ 0, 0},{ 0, 0} }, // 1 Total_Coeffs
{ {11, 6},{15, 5},{13, 4},{ 0, 0} }, // 2 Total_Coeffs
{ { 8, 6},{12, 5},{14, 5},{12, 4} }, // 3 Total_Coeffs
{ {15, 7},{10, 5},{11, 5},{11, 4} }, // 4 Total_Coeffs
{ {11, 7},{ 8, 5},{ 9, 5},{10, 4} }, // 5 Total_Coeffs
{ { 9, 7},{14, 6},{13, 6},{ 9, 4} }, // 6 Total_Coeffs
{ { 8, 7},{10, 6},{ 9, 6},{ 8, 4} }, // 7 Total_Coeffs
{ {15, 8},{14, 7},{13, 7},{13, 5} }, // 8 Total_Coeffs
{ {11, 8},{14, 8},{10, 7},{12, 6} }, // 9 Total_Coeffs
{ {15, 9},{10, 8},{13, 8},{12, 7} }, // 10 Total_Coeffs
{ {11, 9},{14, 9},{ 9, 8},{12, 8} }, // 11 Total_Coeffs
{ { 8, 9},{10, 9},{13, 9},{ 8, 8} }, // 12 Total_Coeffs
{ {13,10},{ 7, 9},{ 9, 9},{12, 9} }, // 13 Total_Coeffs
{ { 9,10},{12,10},{11,10},{10,10} }, // 14 Total_Coeffs
{ { 5,10},{ 8,10},{ 7,10},{ 6,10} }, // 15 Total_Coeffs
{ { 1,10},{ 4,10},{ 3,10},{ 2,10} } // 16 Total_Coeffs
},
{ // Num-VLC_ChromaDC 420
// 0 1 2 3 <-- Trailing Ones
{ { 1, 2},{ 0, 0},{ 0, 0},{ 0, 0} }, // 0 Total_Coeffs
{ { 7, 6},{ 1, 1},{ 0, 0},{ 0, 0} }, // 1 Total_Coeffs
{ { 4, 6},{ 6, 6},{ 1, 3},{ 0, 0} }, // 2 Total_Coeffs
{ { 3, 6},{ 3, 7},{ 2, 7},{ 5, 6} }, // 3 Total_Coeffs
{ { 2, 6},{ 3, 8},{ 2, 8},{ 0, 7} }, // 4 Total_Coeffs
{ { 0, 0},{ 0, 0},{ 0, 0},{ 0, 0} }, // Not used...
{ { 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},{ 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} },
{ { 0, 0},{ 0, 0},{ 0, 0},{ 0, 0} },
{ { 0, 0},{ 0, 0},{ 0, 0},{ 0, 0} }
},
{ // Num-VLC_ChromaDC 422
// 0 1 2 3 <-- Trailing Ones
{ { 1, 1},{ 0, 0},{ 0, 0},{ 0, 0} }, // 0 Total_Coeffs
{ { 15, 7},{ 1, 2},{ 0, 0},{ 0, 0} }, // 1 Total_Coeffs
{ { 14, 7},{ 13, 7},{ 1, 3},{ 0, 0} }, // 2 Total_Coeffs
{ { 7, 9},{ 12, 7},{ 11, 7},{ 1, 5} }, // 3 Total_Coeffs
{ { 6, 9},{ 5, 9},{ 10, 7},{ 1, 6} }, // 4 Total_Coeffs
{ { 7, 10},{ 6, 10},{ 4, 9},{ 9, 7} }, // 5 Total_Coeffs
{ { 7, 11},{ 6, 11},{ 5, 10},{ 8, 7} }, // 6 Total_Coeffs
{ { 7, 12},{ 6, 12},{ 5, 11},{ 4, 10} }, // 7 Total_Coeffs
{ { 7, 13},{ 5, 12},{ 4, 12},{ 4, 11} }, // 8 Total_Coeffs
{ { 0, 0},{ 0, 0},{ 0, 0},{ 0, 0} }, // Not used...
{ { 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},{ 0, 0},{ 0, 0} },
{ { 0, 0},{ 0, 0},{ 0, 0},{ 0, 0} },
{ { 0, 0},{ 0, 0},{ 0, 0},{ 0, 0} }
}
};
template <class PixType, class CoeffsType>
Status CH264pBs<PixType,CoeffsType>::PutNumCoeffAndTrailingOnes(
Ipp32u N, // N, obtained from num coeffs of above/left blocks
Ipp32s bChromaDC, // True if this is a Chroma DC coeff block (2x2)
Ipp32u uNumCoeff, // Number of non-trailing one coeffs to follow (0-4 or 0-16)
Ipp32u uNumTrailingOnes, // Number of trailing ones (0-3)
Ipp32u TrOneSigns) // Signs of the trailing ones, packed into 3 LSBs, (1==neg)
{
Ipp32s uVLCSelect;
Status ps = UMC_OK;
if (bChromaDC) {
switch( bChromaDC ){
case 1:
uVLCSelect = 3; //nC = -1
break;
case 2:
uVLCSelect = 4; //nC = -2
break;
case 3:
uVLCSelect = 0; //nC = 0
break;
}
} else {
if (N < 2) {
uVLCSelect = 0; // 0<=nC<2
} else if (N < 4) {
uVLCSelect = 1; // 2<=nC<4
} else if (N < 8) {
uVLCSelect = 2; // 4<=nC<8
} else { // N > 7 // 8<=nC
uVLCSelect = -1; // escape to Fixed Length code
}
}
if (uVLCSelect >= 0) {
// Write coeff_token from Look-up table
PutBits(EncTotalCoeff[uVLCSelect][uNumCoeff][uNumTrailingOnes].code,
EncTotalCoeff[uVLCSelect][uNumCoeff][uNumTrailingOnes].len);
} else {
if (uNumCoeff == 0) {
PutBits(3, 6);
} else {
// // xxxxyy -> xxxx = uNumCoeff-l , yy = uNumTrailingOnes
PutBits((((uNumCoeff-1)<<2)|uNumTrailingOnes), 6);
}
}
// Write signs of NumTrailingOnes
if( uNumTrailingOnes )
PutBits(TrOneSigns, uNumTrailingOnes);
return ps;
}
//#define TRACE_CAVLC
template <class PixType, class CoeffsType>
Status CH264pBs<PixType,CoeffsType>::PutLevels(CoeffsType* iLevels, // Array of Levels to write
Ipp32s NumLevels, // Total Number of coeffs to write (0-4 or 0-16)
Ipp32s TrailingOnes) // Trailing Ones
{
Ipp32s VLCSelect = 0;
Status ps = UMC_OK;
Ipp32s vlc_inc_tab[7] = {0, 3, 6, 12, 24, 48, 0x8000};
Ipp32s escape_tab[7] = {16, 16, 31, 61, 121, 241, 481};
Ipp32s cnt;
Ipp32s level_adj = 0; // Used to flag that the next level
// is decreased in magnitude by 1 when coded.
// Fixup first coeff level if Trailing Ones < 3
if (TrailingOnes < 3)
{
level_adj = 1; // Subtracted from the level when coded
if ((TrailingOnes + NumLevels) > 10)
VLCSelect = 1; // Start with different table
}
#if defined TRACE_CAVLC
printf("PutLevels: NumLevels = %d, TOnes = %d level_adj = %d\n",
NumLevels, TrailingOnes, level_adj);
#endif // TRACE_CAVLC
for (cnt = 0; cnt < NumLevels; cnt++) {
Ipp32s L = ABS(iLevels[cnt]);
Ipp32s sign = (L != iLevels[cnt]);
#if defined TRACE_CAVLC
printf("iLevels[%d] = %d, L = %d, sign = %d, VLCSelect = %d, esc = %d\n",
cnt, iLevels[cnt], L, sign, VLCSelect, escape_tab[VLCSelect]);
if(L > 2063) {
printf("PutLevels: L(%d) > 2063, iLevels[%d] = %d, VLCSelect = %d, esc = %d\n",
L, cnt, iLevels[cnt], VLCSelect, escape_tab[VLCSelect]);
ps = (Status)cnt;
}
#endif // TRACE_CAVLC
L -= level_adj;
if (L >= escape_tab[VLCSelect]) { // 28-bit escape
// Catch cases where the level is too large to write to the BS
Ipp32u num = L-escape_tab[VLCSelect];
if( num & (0xffffffff<<11)){
Ipp32s addbit = 1;
while(((Ipp32s)num-(2048<<addbit)+2048) >= 0) addbit++;
addbit--;
PutBits(1, 16+addbit);
PutBits(((num-(2048<<addbit)+2048)<<1)|sign, 12+addbit);
}else{
PutBits(1, 16); // PutBits maxes out at 24 bits
PutBits((num<<1)|sign, 12);
}
} else if (VLCSelect) { // VLC Level 1-6
Ipp32s N= VLCSelect - 1;
PutBits(1, ((L-1)>>(N))+1);
// PutBits((((L-1)%(1<<N))<<1)+sign, VLCSelect);
PutBits((((L-1)&((1<<N)-1))<<1)+sign, VLCSelect);
} else { // VLC Level 0
if (L < 8) {
PutBits(1,sign+((L-1)<<1)+1); // Start with a 0 if negative
} else { // L 8-15
PutBits(16+((L&7)<<1)+sign,19); // 19 bit escape
}
}
L += level_adj; // Restore the true level for the following calculations
// Adjust the VLC table depending on the current table and
// the Level just coded.
if (!VLCSelect && (L > 3))
VLCSelect = 2;
else if (L > vlc_inc_tab[VLCSelect])
VLCSelect++;
level_adj = 0; // Clear this now that it's served its purpose
}
return ps;
}
#if 0
template
Status CH264pBs::PutLevels(Ipp16s* iLevels, // Array of Levels to write
Ipp32s NumLevels, // Total Number of coeffs to write (0-4 or 0-16)
Ipp32s TrailingOnes); // Trailing Ones
template
Status CH264pBs::PutLevels(Ipp32s* iLevels, // Array of Levels to write
Ipp32s NumLevels, // Total Number of coeffs to write (0-4 or 0-16)
Ipp32s TrailingOnes); // Trailing One
#endif
// Note, the following 2 tables are indexed by TotalZeros & TotalCoeff-1
static const struct_CodeEntry EncTotalZerosChroma[3][16][15] = {
{
// 0 1 2 <- (TotalCoeff-1)
{ {1,1},{1,1},{1,1} }, // 0 TotalZeros
{ {1,2},{1,2},{0,1} }, // 1 TotalZeros
{ {1,3},{0,2},{0,0} }, // 2 TotalZeros
{ {0,3},{0,0},{0,0} } // 3 TotalZeros
},{
// 0 1 2 3 4 5 6 <- (TotalCoeff-1)
{ {1,1},{0,3},{0,3},{6,3},{0,2},{0,2},{0,1} }, // 0 TotalZeros
{ {2,3},{1,2},{1,3},{0,2},{1,2},{1,2},{1,1} }, // 1 TotalZeros
{ {3,3},{1,3},{1,2},{1,2},{2,2},{1,1},{0,0} }, // 2 TotalZeros
{ {2,4},{4,3},{2,2},{2,2},{3,2},{0,0},{0,0} }, // 3 TotalZeros
{ {3,4},{5,3},{6,3},{7,3},{0,0},{0,0},{0,0} }, // 4 TotalZeros
{ {1,4},{6,3},{7,3},{0,0},{0,0},{0,0},{0,0} }, // 5 TotalZeros
{ {1,5},{7,3},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 6 TotalZeros
{ {0,5},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 7 TotalZeros
},{
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <- (TotalCoeff-1)
{ {1,1},{7,3},{5,4},{3,5},{5,4},{1,6},{1,6},{1,6},{1,6},{1,5},{0,4},{0,4},{0,3},{0,2},{0,1} }, // 0 TotalZeros
{ {3,3},{6,3},{7,3},{7,3},{4,4},{1,5},{1,5},{1,4},{0,6},{0,5},{1,4},{1,4},{1,3},{1,2},{1,1} }, // 1 TotalZeros
{ {2,3},{5,3},{6,3},{5,4},{3,4},{7,3},{5,3},{1,5},{1,4},{1,3},{1,3},{1,2},{1,1},{1,1},{0,0} }, // 2 TotalZeros
{ {3,4},{4,3},{5,3},{4,4},{7,3},{6,3},{4,3},{3,3},{3,2},{3,2},{2,3},{1,1},{1,2},{0,0},{0,0} }, // 3 TotalZeros
{ {2,4},{3,3},{4,4},{6,3},{6,3},{5,3},{3,3},{3,2},{2,2},{2,2},{1,1},{1,3},{0,0},{0,0},{0,0} }, // 4 TotalZeros
{ {3,5},{5,4},{3,4},{5,3},{5,3},{4,3},{3,2},{2,2},{1,3},{1,2},{3,3},{0,0},{0,0},{0,0},{0,0} }, // 5 TotalZeros
{ {2,5},{4,4},{4,3},{4,3},{4,3},{3,3},{2,3},{2,3},{1,2},{1,4},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 6 TotalZeros
{ {3,6},{3,4},{3,3},{3,4},{3,3},{2,3},{1,4},{1,3},{1,5},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 7 TotalZeros
{ {2,6},{2,4},{2,4},{3,3},{2,4},{1,4},{1,3},{0,6},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 8 TotalZeros
{ {3,7},{3,5},{3,5},{2,4},{1,5},{1,3},{0,6},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 9 TotalZeros
{ {2,7},{2,5},{2,5},{2,5},{1,4},{0,6},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 10 TotalZeros
{ {3,8},{3,6},{1,6},{1,5},{0,5},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 11 TotalZeros
{ {2,8},{2,6},{1,5},{0,5},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 12 TotalZeros
{ {3,9},{1,6},{0,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} }, // 13 TotalZeros
{ {2,9},{0,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} }, // 14 TotalZeros
{ {1,9},{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} }, // 15 TotalZeros
}
};
static const struct_CodeEntry EncTotalZeros4x4[16][15] = {
// 0/7 1/8 2/9 3/10 4/11 5/12 6/13 14 <- (TotalCoeff-1)
{ {1,1},{7,3},{5,4},{3,5},{5,4},{1,6},{1,6},
{1,6},{1,6},{1,5},{0,4},{0,4},{0,3},{0,2},{0,1} }, // 0 TotalZeros
{ {3,3},{6,3},{7,3},{7,3},{4,4},{1,5},{1,5},
{1,4},{0,6},{0,5},{1,4},{1,4},{1,3},{1,2},{1,1} }, // 1 TotalZeros
{ {2,3},{5,3},{6,3},{5,4},{3,4},{7,3},{5,3},
{1,5},{1,4},{1,3},{1,3},{1,2},{1,1},{1,1},{0,0} }, // 2 TotalZeros
{ {3,4},{4,3},{5,3},{4,4},{7,3},{6,3},{4,3},
{3,3},{3,2},{3,2},{2,3},{1,1},{1,2},{0,0},{0,0} }, // 3 TotalZeros
{ {2,4},{3,3},{4,4},{6,3},{6,3},{5,3},{3,3},
{3,2},{2,2},{2,2},{1,1},{1,3},{0,0},{0,0},{0,0} }, // 4 TotalZeros
{ {3,5},{5,4},{3,4},{5,3},{5,3},{4,3},{3,2},
{2,2},{1,3},{1,2},{3,3},{0,0},{0,0},{0,0},{0,0} }, // 5 TotalZeros
{ {2,5},{4,4},{4,3},{4,3},{4,3},{3,3},{2,3},
{2,3},{1,2},{1,4},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 6 TotalZeros
{ {3,6},{3,4},{3,3},{3,4},{3,3},{2,3},{1,4},
{1,3},{1,5},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 7 TotalZeros
{ {2,6},{2,4},{2,4},{3,3},{2,4},{1,4},{1,3},
{0,6},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 8 TotalZeros
{ {3,7},{3,5},{3,5},{2,4},{1,5},{1,3},{0,6},
{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 9 TotalZeros
{ {2,7},{2,5},{2,5},{2,5},{1,4},{0,6},{0,0},
{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 10 TotalZeros
{ {3,8},{3,6},{1,6},{1,5},{0,5},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 11 TotalZeros
{ {2,8},{2,6},{1,5},{0,5},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} }, // 12 TotalZeros
{ {3,9},{1,6},{0,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} }, // 13 TotalZeros
{ {2,9},{0,6},{0,0},{0,0},{0,0},{0,0},{0,0},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -