/**************************************************************************** * * Module Title : TokenEntropy.c * * Description : Entropy configuration routines. * ****************************************************************************/ #define STRICT /* Strict type checking. */ /**************************************************************************** * Header Files ****************************************************************************/ #include "tokenentropy.h" #include "pbdll.h" /**************************************************************************** * Exports ****************************************************************************/ // Costs in bits for different probabilities (expressed in range 0-255) // Costs are multiplied by 256 const UINT32 VP6_ProbCost[256] = { 2047, 2047, 1791, 1641, 1535, 1452, 1385, 1328, 1279, 1235, 1196, 1161, 1129, 1099, 1072, 1046, 1023, 1000, 979, 959, 940, 922, 905, 889, 873, 858, 843, 829, 816, 803, 790, 778, 767, 755, 744, 733, 723, 713, 703, 693, 684, 675, 666, 657, 649, 641, 633, 625, 617, 609, 602, 594, 587, 580, 573, 567, 560, 553, 547, 541, 534, 528, 522, 516, 511, 505, 499, 494, 488, 483, 477, 472, 467, 462, 457, 452, 447, 442, 437, 433, 428, 424, 419, 415, 410, 406, 401, 397, 393, 389, 385, 381, 377, 373, 369, 365, 361, 357, 353, 349, 346, 342, 338, 335, 331, 328, 324, 321, 317, 314, 311, 307, 304, 301, 297, 294, 291, 288, 285, 281, 278, 275, 272, 269, 266, 263, 260, 257, 255, 252, 249, 246, 243, 240, 238, 235, 232, 229, 227, 224, 221, 219, 216, 214, 211, 208, 206, 203, 201, 198, 196, 194, 191, 189, 186, 184, 181, 179, 177, 174, 172, 170, 168, 165, 163, 161, 159, 156, 154, 152, 150, 148, 145, 143, 141, 139, 137, 135, 133, 131, 129, 127, 125, 123, 121, 119, 117, 115, 113, 111, 109, 107, 105, 103, 101, 99, 97, 95, 93, 92, 90, 88, 86, 84, 82, 81, 79, 77, 75, 73, 72, 70, 68, 66, 65, 63, 61, 60, 58, 56, 55, 53, 51, 50, 48, 46, 45, 43, 41, 40, 38, 37, 35, 33, 32, 30, 29, 27, 25, 24, 22, 21, 19, 18, 16, 15, 13, 12, 10, 9, 7, 6, 4, 3, 1, 1 }; // Index categories for previous tokens in this block const UINT8 VP6_PrevTokenIndex[MAX_ENTROPY_TOKENS] = { 0,1,2,2,2,2,2,2,2,2,2,0 }; // For details of tokens and extra bit breakdown see token definitions in huffman.h const UINT8 ExtraBitLengths_VP6[MAX_ENTROPY_TOKENS] = { 0, 1, 1, 1, 1, 2, 3, 4, 5, 6, 12, 0 }; const UINT32 VP6_DctRangeMinVals[MAX_ENTROPY_TOKENS] = { 0, 1, 2, 3, 4, 5, 7, 11, 19, 35, 67, 0 }; const UINT8 VP6_DcUpdateProbs[2][MAX_ENTROPY_TOKENS-1] = { { 146, 255, 181, 207, 232, 243, 238, 251, 244, 250, 249 }, { 179, 255, 214, 240, 250, 255, 244, 255, 255, 255, 255 } }; const UINT8 ScanBandUpdateProbs[BLOCK_SIZE] = { 255, 132, 132, 159, 153, 151, 161, 170, 164, 162, 136, 110, 103, 114, 129, 118, 124, 125, 132, 136, 114, 110, 142, 135, 134, 123, 143, 126, 153, 183, 166, 161, 171, 180, 179, 164, 203, 218, 225, 217, 215, 206, 203, 217, 229, 241, 248, 243, 253, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; const UINT8 ZrlUpdateProbs[ZRL_BANDS][ZERO_RUN_PROB_CASES] = { { 219, 246, 238, 249, 232, 239, 249, 255, 248, 253, 239, 244, 241, 248 }, { 198, 232, 251, 253, 219, 241, 253, 255, 248, 249, 244, 238, 251, 255 }, }; // Zero run probs const UINT8 ZeroRunProbDefaults[ZRL_BANDS][ZERO_RUN_PROB_CASES] = { { 198, 197, 196, 146, 198, 204, 169, 142, 130, 136, 149, 149, 191, 249 }, { 135, 201, 181, 154, 98, 117, 132, 126, 146, 169, 184, 240, 246, 254 }, }; const UINT8 VP6_AcUpdateProbs[PREC_CASES][2][VP6_AC_BANDS][MAX_ENTROPY_TOKENS-1] = { { // preceded by 0 { { 227, 246, 230, 247, 244, 255, 255, 255, 255, 255, 255 }, { 255, 255, 209, 231, 231, 249, 249, 253, 255, 255, 255 }, { 255, 255, 225, 242, 241, 251, 253, 255, 255, 255, 255 }, { 255, 255, 241, 253, 252, 255, 255, 255, 255, 255, 255 }, { 255, 255, 248, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, }, { { 240, 255, 248, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 240, 253, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, }, }, { // preceded by 1 { { 206, 203, 227, 239, 247, 255, 253, 255, 255, 255, 255 }, { 207, 199, 220, 236, 243, 252, 252, 255, 255, 255, 255 }, { 212, 219, 230, 243, 244, 253, 252, 255, 255, 255, 255 }, { 236, 237, 247, 252, 253, 255, 255, 255, 255, 255, 255 }, { 240, 240, 248, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, }, { { 230, 233, 249, 255, 255, 255, 255, 255, 255, 255, 255 }, { 238, 238, 250, 255, 255, 255, 255, 255, 255, 255, 255 }, { 248, 251, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, }, }, { // preceded by > 1 { { 225, 239, 227, 231, 244, 253, 243, 255, 255, 253, 255 }, { 232, 234, 224, 228, 242, 249, 242, 252, 251, 251, 255 }, { 235, 249, 238, 240, 251, 255, 249, 255, 253, 253, 255 }, { 249, 253, 251, 250, 255, 255, 255, 255, 255, 255, 255 }, { 251, 250, 249, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, }, { { 243, 244, 250, 250, 255, 255, 255, 255, 255, 255, 255 }, { 249, 248, 250, 253, 255, 255, 255, 255, 255, 255, 255 }, { 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, }, }, }; /**************************************************************************** * Module Statics ****************************************************************************/ // Dc context equations: Dc Token contexts are 00 0!0 and !0!0 static const LINE_EQ VP6_DcNodeEqs[CONTEXT_NODES][DC_TOKEN_CONTEXTS] = { { { 122, 133 },{ 133, 51 },{ 142, -16 } }, // Zero Node { { 0, 1 },{ 0, 1 },{ 0, 1 } }, // EOB Node Dummy as no EOBs in DC { { 78, 171 },{ 169, 71 },{ 221, -30 } }, // One Node { { 139, 117 },{ 214, 44 },{ 246, -3 } }, // Low Val Node { { 168, 79 },{ 210, 38 },{ 203, 17 } }, // Two Node (2 vs 3 or 4) }; /**************************************************************************** * * ROUTINE : VP6_ConfigureContexts * * INPUTS : PB_INSTANCE *pbi : Pointer to decoder instance. * * OUTPUTS : None. * * RETURNS : void * * FUNCTION : Configures the context dependant entropy probabilities. * * SPECIAL NOTES : None. * ****************************************************************************/ void VP6_ConfigureContexts ( PB_INSTANCE *pbi ) { UINT32 i; UINT32 Node; UINT32 Plane; INT32 Temp; // Clear MMX state so floating point can work again #if defined(_MSC_VER) ClearSysState(); #endif // DC Node Probabilities for ( Plane=0; Plane<2; Plane++ ) { for ( i=0; iDcProbs[DCProbOffset(Plane,Node)] * VP6_DcNodeEqs[Node][i].M + 128 ) >> 8) + VP6_DcNodeEqs[Node][i].C; Temp = (Temp > 255)? 255: Temp; Temp = (Temp < 1)? 1 : Temp; //pbi->DcNodeContexts[Plane][i][Node] = (UINT8)Temp; *(pbi->DcNodeContexts + DcNodeOffset(Plane,i,Node)) = (UINT8)Temp; } } } }