📄 skl_mpg4_dec.cpp
字号:
/******************************************************** * Some code. Copyright (C) 2003 by Pascal Massimino. * * All Rights Reserved. (http://skal.planet-d.net) * * For Educational/Academic use ONLY. See 'LICENSE.TXT'.* ********************************************************//* * skl_mpg4_dec.cpp * * MPEG4 decoder ********************************************************/#include "./skl_mpg4i.h"#include "skl_syst/skl_exception.h"//////////////////////////////////////////////////////////// Decoding tables & values////////////////////////////////////////////////////////////////////////////////////////////////////////////////////struct SKL_VLC { SKL_INT16 Val, Len; };struct SKL_DCT_VLC { SKL_INT16 Run; SKL_INT8 Level, Len; }; // table 6-14. Shape type#define GRAYSCALE 3#define BINARY_ONLY 2#define BINARY 1#define RECTANGULAR 0 // Table 6-21static const int DC_Thresh_Tab[] = { 512, 13, 15, 17, 19, 21, 23, 0 }; // Table 6-27static const int DQuant_Tab[4] = {-1,-2, 1, 2 }; // Table 6-28static const int DBQuant_Tab[4] = { 0, 0,-2, 2 }; // Table 7-1const int SKL_MP4_I::DC_Scales[2][31] = { // index: [Lum][AC_Q-1] { /* DC_Q_chroma = (Q<5) ? 8 : (Q<24) ? (Q+13)/2 : Q-6; */ 8, 8, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 20, 21, 22, 23, 24, 25 }, { /* DC_Q_Lum = (Q<5) ? 8 : (Q<9) ? 2*Q : (Q<25) ? Q+8 : Q*2-16; */ 8, 8, 8, 8, 10, 12, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 36, 38, 40, 42, 44, 46 }}; // Table 7-6 (K=4) (modified)const int SKL_MB::Rnd_Tab_76[16] = { 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1 }; // Table 7-8 (K=2) (modified)const int SKL_MB::Rnd_Tab_78[ 8] = { 0, 0, 1, 1, 0, 0, 0, 1 }; // Table 7-9 (K=1) (modified)const int SKL_MB::Rnd_Tab_79[ 4] = { 0, 1, 0, 0 }; // Table B-4static const SKL_VLC BType_Tab_B4[15] = { { SKL_MB_FWD, 4},{ SKL_MB_BWD, 3},{ SKL_MB_BWD, 3}, { SKL_MB_INTERP, 2},{ SKL_MB_INTERP, 2},{ SKL_MB_INTERP, 2},{ SKL_MB_INTERP, 2}, { SKL_MB_DIRECT, 1},{ SKL_MB_DIRECT, 1},{ SKL_MB_DIRECT, 1},{ SKL_MB_DIRECT, 1}, { SKL_MB_DIRECT, 1},{ SKL_MB_DIRECT, 1},{ SKL_MB_DIRECT, 1},{ SKL_MB_DIRECT, 1}}; // Table B-6 packed: MB_Type = bits 2,3,4 / CBPC for blocks 5,6 = bits 0,1static const SKL_VLC MCBPC_Intra_B6_0[63] = { {17, 6},{18, 6},{19, 6},{16, 4},{16, 4},{16, 4},{16, 4}, {13, 3},{13, 3},{13, 3},{13, 3},{13, 3},{13, 3},{13, 3},{13, 3}, {14, 3},{14, 3},{14, 3},{14, 3},{14, 3},{14, 3},{14, 3},{14, 3}, {15, 3},{15, 3},{15, 3},{15, 3},{15, 3},{15, 3},{15, 3},{15, 3}, {12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1}, {12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1}, {12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1}, {12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1},{12, 1}}; // Table B-7 packed: MB_Type = bits 2,3,4 / CBPC for blocks 5,6 = bits 0,1static const SKL_VLC MCBPC_Inter_B7_0[13+1] = { { 0x00, 0 }, // special code for leading bit = 1 {12, 4},{ 2, 3},{ 2, 3},{ 1, 3},{ 1, 3}, { 8, 2},{ 8, 2},{ 8, 2},{ 8, 2},{ 4, 2},{ 4, 2},{ 4, 2},{ 4, 2}};static const SKL_VLC MCBPC_Inter_B7_1[46] = { {19, 8},{18, 8},{17, 8},{ 7, 8},{14, 7},{14, 7}, {13, 7},{13, 7},{11, 7},{11, 7},{15, 6},{15, 6},{15, 6},{15, 6}, {10, 6},{10, 6},{10, 6},{10, 6},{ 9, 6},{ 9, 6},{ 9, 6},{ 9, 6}, { 6, 6},{ 6, 6},{ 6, 6},{ 6, 6},{ 5, 6},{ 5, 6},{ 5, 6},{ 5, 6}, {16, 5},{16, 5},{16, 5},{16, 5},{16, 5},{16, 5},{16, 5},{16, 5}, { 3, 5},{ 3, 5},{ 3, 5},{ 3, 5},{ 3, 5},{ 3, 5},{ 3, 5},{ 3, 5}}; // Table B-8. CBPY (bits 2,3,4,5)static const SKL_VLC CBPY_Tab[62] = { {24, 6},{36, 6},{32, 5},{32, 5},{16, 5},{16, 5}, { 8, 5},{ 8, 5},{ 4, 5},{ 4, 5},{ 0, 4},{ 0, 4},{ 0, 4},{ 0, 4}, {48, 4},{48, 4},{48, 4},{48, 4},{40, 4},{40, 4},{40, 4},{40, 4}, {56, 4},{56, 4},{56, 4},{56, 4},{20, 4},{20, 4},{20, 4},{20, 4}, {52, 4},{52, 4},{52, 4},{52, 4},{12, 4},{12, 4},{12, 4},{12, 4}, {44, 4},{44, 4},{44, 4},{44, 4},{28, 4},{28, 4},{28, 4},{28, 4}, {60, 2},{60, 2},{60, 2},{60, 2},{60, 2},{60, 2},{60, 2},{60, 2}, {60, 2},{60, 2},{60, 2},{60, 2},{60, 2},{60, 2},{60, 2},{60, 2}}; // Table B-12. Motion vectors multiplied by 2, without // sign (trailing bit) and leading bit (dealt with separately) // Length is incremented by 1.static const SKL_VLC MV_Tab_B12_0[7] = { { 3, 4},{ 2, 3},{ 2, 3},{ 1, 2},{ 1, 2},{ 1, 2},{ 1, 2}};static const SKL_VLC MV_Tab_B12_1[60] = { {24,10},{23,10},{22,10},{21,10}, {20,10},{19,10},{18,10},{17,10},{16,10},{15,10},{14,10},{13,10}, {12,10},{11,10},{10, 9},{10, 9},{ 9, 9},{ 9, 9},{ 8, 9},{ 8, 9}, { 7, 7},{ 7, 7},{ 7, 7},{ 7, 7},{ 7, 7},{ 7, 7},{ 7, 7},{ 7, 7}, { 6, 7},{ 6, 7},{ 6, 7},{ 6, 7},{ 6, 7},{ 6, 7},{ 6, 7},{ 6, 7}, { 5, 7},{ 5, 7},{ 5, 7},{ 5, 7},{ 5, 7},{ 5, 7},{ 5, 7},{ 5, 7}, { 4, 6},{ 4, 6},{ 4, 6},{ 4, 6},{ 4, 6},{ 4, 6},{ 4, 6},{ 4, 6}, { 4, 6},{ 4, 6},{ 4, 6},{ 4, 6},{ 4, 6},{ 4, 6},{ 4, 6},{ 4, 6}};static const SKL_VLC MV_Tab_B12_2[14] = { {32,12},{31,12},{30,11},{30,11},{29,11},{29,11}, {28,11},{28,11},{27,11},{27,11},{26,11},{26,11},{25,11},{25,11}}; // Table B-13, restricted to code size <= 3static const SKL_VLC DC_Size_Lum_B13_0[7] = { { 4, 3},{ 3, 3},{ 0, 3},{ 2, 2},{ 2, 2},{ 1, 2},{ 1, 2}}; // Table B-14, restricted to code size <= 2 // Unused (hardcoded)// static const SKL_VLC DC_Size_Chrom_B14_0[3] = { { 2, 2},{ 1, 2},{ 0, 2} }; // Table B-16static const SKL_DCT_VLC Intra_B16_0[52] = { { 0,-2, 6},{ 5, 1, 6},{ 2,-1, 6},{ 1,-1, 6}, { 4, 1, 6},{ 3, 1, 6},{ 0, 8, 6},{ 0, 7, 6},{ 1, 2, 6},{ 0, 6, 6},{ 2, 1, 5},{ 2, 1, 5}, { 0, 5, 5},{ 0, 5, 5},{ 0, 4, 5},{ 0, 4, 5},{ 0,-1, 4},{ 0,-1, 4},{ 0,-1, 4},{ 0,-1, 4}, { 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2}, { 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2}, { 0, 2, 3},{ 0, 2, 3},{ 0, 2, 3},{ 0, 2, 3},{ 0, 2, 3},{ 0, 2, 3},{ 0, 2, 3},{ 0, 2, 3}, { 1, 1, 4},{ 1, 1, 4},{ 1, 1, 4},{ 1, 1, 4},{ 0, 3, 4},{ 0, 3, 4},{ 0, 3, 4},{ 0, 3, 4}};static const SKL_DCT_VLC Intra_B16_1[29] = { { 8,-1, 8},{ 7,-1, 8},{ 6,-1, 8},{ 0,-3, 8},{10, 1, 8}, { 9, 1, 8},{ 8, 1, 8},{ 9,-1, 8},{ 3, 2, 8},{ 1, 4, 8},{ 0,12, 8},{ 0,11, 8},{ 0,10, 8}, { 4,-1, 7},{ 4,-1, 7},{ 3,-1, 7},{ 3,-1, 7},{ 6, 1, 7},{ 6, 1, 7},{ 5,-1, 7},{ 5,-1, 7}, { 7, 1, 7},{ 7, 1, 7},{ 2, 2, 7},{ 2, 2, 7},{ 1, 3, 7},{ 1, 3, 7},{ 0, 9, 7},{ 0, 9, 7}};static const SKL_DCT_VLC Intra_B16_2[104] = { // These are the ESC codes {-1, 0, 8},{-1, 0, 8},{-1, 0, 8},{-1, 0, 8},{-1, 0, 8},{-1, 0, 8},{-1, 0, 8},{-1, 0, 8}, {-2, 0, 9},{-2, 0, 9},{-2, 0, 9},{-2, 0, 9},{-3, 0, 9},{-3, 0, 9},{-3, 0, 9},{-3, 0, 9}, { 0,18,10},{ 0,18,10},{ 0,17,10},{ 0,17,10},{14,-1, 9},{14,-1, 9},{14,-1, 9},{14,-1, 9}, {13,-1, 9},{13,-1, 9},{13,-1, 9},{13,-1, 9},{12,-1, 9},{12,-1, 9},{12,-1, 9},{12,-1, 9}, {11,-1, 9},{11,-1, 9},{11,-1, 9},{11,-1, 9},{10,-1, 9},{10,-1, 9},{10,-1, 9},{10,-1, 9}, { 1,-2, 9},{ 1,-2, 9},{ 1,-2, 9},{ 1,-2, 9},{ 0,-4, 9},{ 0,-4, 9},{ 0,-4, 9},{ 0,-4, 9}, {12, 1, 9},{12, 1, 9},{12, 1, 9},{12, 1, 9},{11, 1, 9},{11, 1, 9},{11, 1, 9},{11, 1, 9}, { 7, 2, 9},{ 7, 2, 9},{ 7, 2, 9},{ 7, 2, 9},{ 6, 2, 9},{ 6, 2, 9},{ 6, 2, 9},{ 6, 2, 9}, { 5, 2, 9},{ 5, 2, 9},{ 5, 2, 9},{ 5, 2, 9},{ 3, 3, 9},{ 3, 3, 9},{ 3, 3, 9},{ 3, 3, 9}, { 2, 3, 9},{ 2, 3, 9},{ 2, 3, 9},{ 2, 3, 9},{ 1, 6, 9},{ 1, 6, 9},{ 1, 6, 9},{ 1, 6, 9}, { 1, 5, 9},{ 1, 5, 9},{ 1, 5, 9},{ 1, 5, 9},{ 0,16, 9},{ 0,16, 9},{ 0,16, 9},{ 0,16, 9}, { 4, 2, 9},{ 4, 2, 9},{ 4, 2, 9},{ 4, 2, 9},{ 0,15, 9},{ 0,15, 9},{ 0,15, 9},{ 0,15, 9}, { 0,14, 9},{ 0,14, 9},{ 0,14, 9},{ 0,14, 9},{ 0,13, 9},{ 0,13, 9},{ 0,13, 9},{ 0,13, 9}};static const SKL_DCT_VLC Intra_B16_3[88] = { { 0,-7,11},{ 0,-7,11},{ 0,-6,11},{ 0,-6,11},{ 0,22,11},{ 0,22,11},{ 0,21,11},{ 0,21,11}, { 2,-2,10},{ 2,-2,10},{ 2,-2,10},{ 2,-2,10},{ 1,-3,10},{ 1,-3,10},{ 1,-3,10},{ 1,-3,10}, { 0,-5,10},{ 0,-5,10},{ 0,-5,10},{ 0,-5,10},{13, 1,10},{13, 1,10},{13, 1,10},{13, 1,10}, { 5, 3,10},{ 5, 3,10},{ 5, 3,10},{ 5, 3,10},{ 8, 2,10},{ 8, 2,10},{ 8, 2,10},{ 8, 2,10}, { 4, 3,10},{ 4, 3,10},{ 4, 3,10},{ 4, 3,10},{ 3, 4,10},{ 3, 4,10},{ 3, 4,10},{ 3, 4,10}, { 2, 4,10},{ 2, 4,10},{ 2, 4,10},{ 2, 4,10},{ 1, 7,10},{ 1, 7,10},{ 1, 7,10},{ 1, 7,10}, { 0,20,10},{ 0,20,10},{ 0,20,10},{ 0,20,10},{ 0,19,10},{ 0,19,10},{ 0,19,10},{ 0,19,10}, { 0,23,11},{ 0,23,11},{ 0,24,11},{ 0,24,11},{ 1, 8,11},{ 1, 8,11},{ 9, 2,11},{ 9, 2,11}, { 3,-2,11},{ 3,-2,11},{ 4,-2,11},{ 4,-2,11},{15,-1,11},{15,-1,11},{16,-1,11},{16,-1,11}, { 0,25,12},{ 0,26,12},{ 0,27,12},{ 1, 9,12},{ 6, 3,12},{ 1,10,12},{ 2, 5,12},{ 7, 3,12}, {14, 1,12},{ 0,-8,12},{ 5,-2,12},{ 6,-2,12},{17,-1,12},{18,-1,12},{19,-1,12},{20,-1,12}}; // Table B-17static const SKL_DCT_VLC Inter_B17_0[52] = { { 4,-1, 6},{ 3,-1, 6},{ 2,-1, 6},{ 1,-1, 6}, { 9, 1, 6},{ 8, 1, 6},{ 7, 1, 6},{ 6, 1, 6},{ 1, 2, 6},{ 0, 3, 6},{ 5, 1, 5},{ 5, 1, 5}, { 4, 1, 5},{ 4, 1, 5},{ 3, 1, 5},{ 3, 1, 5},{ 0,-1, 4},{ 0,-1, 4},{ 0,-1, 4},{ 0,-1, 4}, { 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2}, { 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2},{ 0, 1, 2}, { 1, 1, 3},{ 1, 1, 3},{ 1, 1, 3},{ 1, 1, 3},{ 1, 1, 3},{ 1, 1, 3},{ 1, 1, 3},{ 1, 1, 3}, { 2, 1, 4},{ 2, 1, 4},{ 2, 1, 4},{ 2, 1, 4},{ 0, 2, 4},{ 0, 2, 4},{ 0, 2, 4},{ 0, 2, 4}};static const SKL_DCT_VLC Inter_B17_1[29] = { {16,-1, 8},{15,-1, 8},{14,-1, 8},{13,-1, 8},{12,-1, 8}, {11,-1, 8},{10,-1, 8},{ 9,-1, 8},{14, 1, 8},{13, 1, 8},{ 2, 2, 8},{ 1, 3, 8},{ 0, 5, 8}, { 8,-1, 7},{ 8,-1, 7},{ 7,-1, 7},{ 7,-1, 7},{ 6,-1, 7},{ 6,-1, 7},{ 5,-1, 7},{ 5,-1, 7}, {12, 1, 7},{12, 1, 7},{11, 1, 7},{11, 1, 7},{10, 1, 7},{10, 1, 7},{ 0, 4, 7},{ 0, 4, 7}};static const SKL_DCT_VLC Inter_B17_2[52] = { // These are the ESC codes {-1, 0, 8},{-1, 0, 8},{-1, 0, 8},{-1, 0, 8},{-2, 0, 9},{-2, 0, 9},{-3, 0, 9},{-3, 0, 9}, { 0, 9,10},{ 0, 8,10},{24,-1, 9},{24,-1, 9},{23,-1, 9},{23,-1, 9},{22,-1, 9},{22,-1, 9}, {21,-1, 9},{21,-1, 9},{20,-1, 9},{20,-1, 9},{19,-1, 9},{19,-1, 9},{18,-1, 9},{18,-1, 9}, {17,-1, 9},{17,-1, 9},{ 0,-2, 9},{ 0,-2, 9},{22, 1, 9},{22, 1, 9},{21, 1, 9},{21, 1, 9}, {20, 1, 9},{20, 1, 9},{19, 1, 9},{19, 1, 9},{18, 1, 9},{18, 1, 9},{17, 1, 9},{17, 1, 9}, {16, 1, 9},{16, 1, 9},{15, 1, 9},{15, 1, 9},{ 4, 2, 9},{ 4, 2, 9},{ 3, 2, 9},{ 3, 2, 9}, { 0, 7, 9},{ 0, 7, 9},{ 0, 6, 9},{ 0, 6, 9}};static const SKL_DCT_VLC Inter_B17_3[88] = { { 1,-2,11},{ 1,-2,11},{ 0,-3,11},{ 0,-3,11},{ 0,11,11},{ 0,11,11},{ 0,10,11},{ 0,10,11}, {28,-1,10},{28,-1,10},{28,-1,10},{28,-1,10},{27,-1,10},{27,-1,10},{27,-1,10},{27,-1,10}, {26,-1,10},{26,-1,10},{26,-1,10},{26,-1,10},{25,-1,10},{25,-1,10},{25,-1,10},{25,-1,10}, { 9, 2,10},{ 9, 2,10},{ 9, 2,10},{ 9, 2,10},{ 8, 2,10},{ 8, 2,10},{ 8, 2,10},{ 8, 2,10}, { 7, 2,10},{ 7, 2,10},{ 7, 2,10},{ 7, 2,10},{ 6, 2,10},{ 6, 2,10},{ 6, 2,10},{ 6, 2,10}, { 5, 2,10},{ 5, 2,10},{ 5, 2,10},{ 5, 2,10},{ 3, 3,10},{ 3, 3,10},{ 3, 3,10},{ 3, 3,10}, { 2, 3,10},{ 2, 3,10},{ 2, 3,10},{ 2, 3,10},{ 1, 4,10},{ 1, 4,10},{ 1, 4,10},{ 1, 4,10}, { 0,12,11},{ 0,12,11},{ 1, 5,11},{ 1, 5,11},{23, 1,11},{23, 1,11},{24, 1,11},{24, 1,11}, {29,-1,11},{29,-1,11},{30,-1,11},{30,-1,11},{31,-1,11},{31,-1,11},{32,-1,11},{32,-1,11}, { 1, 6,12},{ 2, 4,12},{ 4, 3,12},{ 5, 3,12},{ 6, 3,12},{10, 2,12},{25, 1,12},{26, 1,12}, {33,-1,12},{34,-1,12},{35,-1,12},{36,-1,12},{37,-1,12},{38,-1,12},{39,-1,12},{40,-1,12}}; // Table B-19static const int Max_LEVEL_Intra_Last0[15] = /* INTRA */ { 27,10,5, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1 };static const int Max_LEVEL_Intra_Last1[21] = /* INTRA */ { 8, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; // Table B-20static const int Max_LEVEL_Inter_Last0[27] = /* INTER */ { 12,6, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };static const int Max_LEVEL_Inter_Last1[41] = /* INTER */ { 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };const int *(Max_LEVEL[2][2]) = { // index: [intra][last][run/level] { Max_LEVEL_Intra_Last0, Max_LEVEL_Intra_Last1 }, { Max_LEVEL_Inter_Last0, Max_LEVEL_Inter_Last1 }}; // Table B-21 (+1 included)static const int Max_RUN_Intra_Last0[28-1] = { 15, 10, 8, 4, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };static const int Max_RUN_Intra_Last1[9-1] = { 21, 7, 2, 1, 1, 1, 1, 1 }; // Table B-22static const int Max_RUN_Inter_Last0[13-1] = { 27, 11, 7, 3, 2, 2, 1, 1, 1, 1, 1, 1 };static const int Max_RUN_Inter_Last1[4-1] = { 41, 2, 1 };static const int *(Max_RUN[2][2]) = { { Max_RUN_Intra_Last0, Max_RUN_Intra_Last1 }, { Max_RUN_Inter_Last0, Max_RUN_Inter_Last1 }}; // Table B-33 (first part)static const SKL_VLC Spr_Tab_B33[8] = { { 0, 2},{ 0, 2},{ 1, 3},{ 2, 3},{ 3, 3},{ 4, 3},{ 5, 3},{-1, 3}}; // Table B-34 for size>=6static const SKL_VLC Spr_Tab_B34[8] = { { 6, 1},{ 6, 1},{ 6, 1},{ 6, 1},{ 7, 2},{ 7, 2},{ 9, 3},{10, 3}};//////////////////////////////////////////////////////////// Vector decoding//////////////////////////////////////////////////////////static int Read_Motion_Vector(SKL_FBB *Bits, SKL_INT32 Fix){ if (Bits->Get_Bits(1)) return 0; Bits->Check_Bits(11); SKL_UINT32 Code = Bits->Bits; const SKL_VLC *VLC; if (Code>=0x20000000) VLC = MV_Tab_B12_0 - 1 + (Code>>(21+8)); else if (Code>=0x02000000) VLC = MV_Tab_B12_1 - 4 + (Code>>(21+2)); else /*if (Code>=0x00400000)*/ VLC = MV_Tab_B12_2 - 2 + (Code>>(21+0)); int Val; if (!--Fix) { // special case for Fix==1 (residue=0) Val = VLC->Val; Code = Bits->Get_Bits(VLC->Len); // reads 'sign bit' if (Code & 1) Val = -Val; } else { Val = ((VLC->Val-1)<<Fix) + 1; Code = Bits->Get_Bits(VLC->Len + Fix); // reads 'sign bit' and 'res' too... const SKL_INT32 Scale = 1 << Fix; Val += Code & (Scale-1); // add residue... if (Code & Scale) Val = -Val; // ...and sign } return Val;}static void Read_Vector(SKL_FBB *Bits, SKL_INT32 Fix, SKL_MV MV){ const int High = 16 << Fix; int dx = MV[0] + Read_Motion_Vector(Bits, Fix); int dy = MV[1] + Read_Motion_Vector(Bits, Fix); if (dx<-High) dx += 2*High; else if (dx>=High) dx -= 2*High; MV[0] = dx; if (dy<-High) dy += 2*High; else if (dy>=High) dy -= 2*High; MV[1] = dy;}//////////////////////////////////////////////////////////// Coeffs decoding//////////////////////////////////////////////////////////static int Read_DC_Size_Lum(SKL_FBB *Bits){ int Size; const SKL_UINT32 Code = Bits->See_Bits_Safe(3); if (Code!=0) { const SKL_VLC *VLC = &DC_Size_Lum_B13_0[Code - 1]; Bits->Discard_Safe( VLC->Len ); Size = VLC->Val; } else { const int Val = 11 + 1 - SKL_BMASKS::Bit_Sizes[Bits->See_Bits_Safe(11)]; Bits->Discard_Safe( Val ); Size = Val+1; } return Size;}static int Read_DC_Size_Chroma(SKL_FBB *Bits){ int Size; const SKL_UINT32 Code = Bits->See_Bits_Safe(2); if (Code!=0) { Bits->Discard_Safe( 2 ); Size = 3-Code; // <- hardcoded version of DC_Size_Chrom_B14_0[] } else { const int Val = 12 + 1 - SKL_BMASKS::Log2(Bits->See_Bits_Safe(12)); Bits->Discard_Safe( Val ); Size = Val; } return Size;}static int Read_DC_Diff(SKL_FBB *Bits, int Lum){ Bits->Check_Bits(12); const int Size = Lum ? Read_DC_Size_Lum(Bits) : Read_DC_Size_Chroma(Bits); if (Size==0) return 0; SKL_UINT32 Code; if (Size<=8) Code = Bits->Get_Bits(Size); else { Code = Bits->Get_Bits(Size+1); // + marker bit Code >>= 1; } if (!(Code&SKL_BMASKS::Or[Size])) // MSB not set Code -= SKL_BMASKS::And[Size]; return Code; }static void Read_Intra_AC(SKL_FBB *Bits, SKL_INT16 *Coeff, const int * const Zigzag, int i){ while(1) { const SKL_DCT_VLC *VLC; Bits->Check_Bits(12); SKL_UINT32 Code = Bits->Bits; SKL_ASSERT(Code>=0x00800000); if (Code>=0x30000000) VLC = Intra_B16_0 - 12 + (Code>>(20+6)); else if (Code>=0x13000000) VLC = Intra_B16_1 - 19 + (Code>>(20+4)); else if (Code>=0x06000000) VLC = Intra_B16_2 - 48 + (Code>>(20+1)); else /*if (Code>=0x00800000)*/ VLC = Intra_B16_3 - 8 + (Code>>(20+0)); //else break; /* error */ int Run = VLC->Run;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -