Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

489 lines
24 KiB

  1. /* File: sv_h263_getblk.c */
  2. /*****************************************************************************
  3. ** Copyright (c) Digital Equipment Corporation, 1995, 1997 **
  4. ** **
  5. ** All Rights Reserved. Unpublished rights reserved under the copyright **
  6. ** laws of the United States. **
  7. ** **
  8. ** The software contained on this media is proprietary to and embodies **
  9. ** the confidential technology of Digital Equipment Corporation. **
  10. ** Possession, use, duplication or dissemination of the software and **
  11. ** media is authorized only pursuant to a valid written license from **
  12. ** Digital Equipment Corporation. **
  13. ** **
  14. ** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S. **
  15. ** Government is subject to restrictions as set forth in Subparagraph **
  16. ** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable. **
  17. ******************************************************************************/
  18. /*
  19. #define _SLIBDEBUG_
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include "sv_h263.h"
  24. #include "sv_intrn.h"
  25. #include "SC_err.h"
  26. #include "proto.h"
  27. #ifdef _SLIBDEBUG_
  28. #include "sc_debug.h"
  29. #define _DEBUG_ 0 /* detailed debuging statements */
  30. #define _VERBOSE_ 0 /* show progress */
  31. #define _VERIFY_ 1 /* verify correct operation */
  32. #define _WARN_ 1 /* warnings about strange behavior */
  33. #endif
  34. static int H263_bquant_tab[] = {5,6,7,8};
  35. typedef struct {
  36. char run, level, len;
  37. } DCTtab;
  38. typedef struct {
  39. int val, len;
  40. } VLCtabI;
  41. typedef struct {
  42. int val, run, sign;
  43. } RunCoef;
  44. /* local prototypes */
  45. RunCoef vlc_word_decode(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn, int symbol_word, int *last);
  46. RunCoef Decode_Escape_Char(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn, int intra, int *last);
  47. int DecodeTCoef(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn, int position, int intra);
  48. extern VLCtabI DCT3Dtab0[],DCT3Dtab1[],DCT3Dtab2[];
  49. /* zig-zag scan */
  50. static unsigned char zig_zag_scan[64]=
  51. { 0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,
  52. 12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,
  53. 35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,
  54. 58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63 };
  55. static int H263_tcoeftab[103] = {1,2,3,4,5,6,7,8,9,10,11,12,17,18,19,20,21,22,33,34,35,36,49,50,51,65,66,67,81,82,83,97,98,99,113,114,129,130,145,146,161,162,177,193,209,225,241,257,273,289,305,321,337,353,369,385,401,417,4097,4098,4099,4113,4114,4129,4145,4161,4177,4193,4209,4225,4241,4257,4273,4289,4305,4321,4337,4353,4369,4385,4401,4417,4433,4449,4465,4481,4497,4513,4529,4545,4561,4577,4593,4609,4625,4641,4657,4673,4689,4705,4721,4737,7167};
  56. static int H263_signtab[2] = {0,1};
  57. static int H263_lasttab[2] = {0,1};
  58. static int H263_last_intratab[2] = {0,1};
  59. static int H263_runtab[64] = {0,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,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63};
  60. static int H263_leveltab[254] = {129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,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,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127};
  61. static int H263_cumf_SIGN[3]={16383, 8416, 0};
  62. static int H263_cumf_LAST[3]={16383, 9469, 0};
  63. static int H263_cumf_LAST_intra[3]={16383, 2820, 0};
  64. static int H263_cumf_RUN[65]={16383, 15310, 14702, 13022, 11883, 11234, 10612, 10192, 9516, 9016, 8623, 8366, 7595, 7068, 6730, 6487, 6379, 6285, 6177, 6150, 6083, 5989, 5949, 5922, 5895, 5828, 5774, 5773, 5394, 5164, 5016, 4569, 4366, 4136, 4015, 3867, 3773, 3692, 3611, 3476, 3341, 3301, 2787, 2503, 2219, 1989, 1515, 1095, 934, 799, 691, 583, 435, 300, 246, 206, 125, 124, 97, 57, 30, 3, 2, 1, 0};
  65. static int H263_cumf_RUN_intra[65]={16383, 10884, 8242, 7124, 5173, 4745, 4246, 3984, 3034, 2749, 2607, 2298, 966, 681, 396, 349, 302, 255, 254, 253, 206, 159, 158, 157, 156, 155, 154, 153, 106, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
  66. static int H263_cumf_LEVEL[255]={16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 16374, 16373, 16372, 16371, 16370, 16369, 16368, 16367, 16366, 16365, 16364, 16363, 16362, 16361, 16360, 16359, 16358, 16357, 16356, 16355, 16354, 16353, 16352, 16351, 16350, 16349, 16348, 16347, 16346, 16345, 16344, 16343, 16342, 16341, 16340, 16339, 16338, 16337, 16336, 16335, 16334, 16333, 16332, 16331, 16330, 16329, 16328, 16327, 16326, 16325, 16324, 16323, 16322, 16321, 16320, 16319, 16318, 16317, 16316, 16315, 16314, 16313, 16312, 16311, 16310, 16309, 16308, 16307, 16306, 16305, 16304, 16303, 16302, 16301, 16300, 16299, 16298, 16297, 16296, 16295, 16294, 16293, 16292, 16291, 16290, 16289, 16288, 16287, 16286, 16285, 16284, 16283, 16282, 16281, 16280, 16279, 16278, 16277, 16250, 16223, 16222, 16195, 16154, 16153, 16071, 15989, 15880, 15879, 15878, 15824, 15756, 15674, 15606, 15538, 15184, 14572, 13960, 10718, 7994, 5379, 2123, 1537, 992, 693, 611, 516, 448, 421, 380, 353, 352, 284, 257, 230, 203, 162, 161, 160, 133, 132, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
  67. static int H263_cumf_LEVEL_intra[255]={16383, 16379, 16378, 16377, 16376, 16375, 16374, 16373, 16372, 16371, 16370, 16369, 16368, 16367, 16366, 16365, 16364, 16363, 16362, 16361, 16360, 16359, 16358, 16357, 16356, 16355, 16354, 16353, 16352, 16351, 16350, 16349, 16348, 16347, 16346, 16345, 16344, 16343, 16342, 16341, 16340, 16339, 16338, 16337, 16336, 16335, 16334, 16333, 16332, 16331, 16330, 16329, 16328, 16327, 16326, 16325, 16324, 16323, 16322, 16321, 16320, 16319, 16318, 16317, 16316, 16315, 16314, 16313, 16312, 16311, 16268, 16267, 16224, 16223, 16180, 16179, 16136, 16135, 16134, 16133, 16132, 16131, 16130, 16129, 16128, 16127, 16126, 16061, 16018, 16017, 16016, 16015, 16014, 15971, 15970, 15969, 15968, 15925, 15837, 15794, 15751, 15750, 15749, 15661, 15618, 15508, 15376, 15288, 15045, 14913, 14781, 14384, 13965, 13502, 13083, 12509, 12289, 12135, 11892, 11738, 11429, 11010, 10812, 10371, 9664, 9113, 8117, 8116, 8028, 6855, 5883, 4710, 4401, 4203, 3740, 3453, 3343, 3189, 2946, 2881, 2661, 2352, 2132, 1867, 1558, 1382, 1250, 1162, 1097, 1032, 967, 835, 681, 549, 439, 351, 350, 307, 306, 305, 304, 303, 302, 301, 300, 299, 298, 255, 212, 211, 210, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 115, 114, 113, 112, 111, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
  68. #define F (float)
  69. static const float dct_constants[64] = {
  70. F 0.12500000, F 0.09011998, F 0.09567086, F 0.10630377,
  71. F 0.12500000, F 0.15909483, F 0.23096988, F 0.45306373,
  72. F 0.09011998, F 0.06497288, F 0.06897485, F 0.07664075,
  73. F 0.09011998, F 0.11470097, F 0.16652001, F 0.32664075,
  74. F 0.09567086, F 0.06897485, F 0.07322331, F 0.08136138,
  75. F 0.09567086, F 0.12176590, F 0.17677669, F 0.34675997,
  76. F 0.10630377, F 0.07664074, F 0.08136138, F 0.09040392,
  77. F 0.10630377, F 0.13529903, F 0.19642374, F 0.38529903,
  78. F 0.12500000, F 0.09011998, F 0.09567086, F 0.10630377,
  79. F 0.12500000, F 0.15909483, F 0.23096988, F 0.45306373,
  80. F 0.15909483, F 0.11470097, F 0.12176590, F 0.13529903,
  81. F 0.15909483, F 0.20248929, F 0.29396889, F 0.57664073,
  82. F 0.23096988, F 0.16652001, F 0.17677669, F 0.19642374,
  83. F 0.23096988, F 0.29396892, F 0.42677671, F 0.83715260,
  84. F 0.45306373, F 0.32664075, F 0.34675995, F 0.38529903,
  85. F 0.45306373, F 0.57664073, F 0.83715260, F 1.64213395
  86. };
  87. #ifndef USE_C
  88. #define SetExtraBlockInfo(bp) *((unsigned qword *)&bp[64])=cpattern;
  89. #define UpdateBlockInfo(i) cpattern |=(((unsigned qword)1)<<((i/8)+(i%8)*8));
  90. #endif
  91. void sv_H263GetBlock(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn, int comp, int mode)
  92. {
  93. register int val, i, j, sign;
  94. register unsigned int code;
  95. VLCtabI *tab;
  96. register int run, last, level, QP;
  97. int *qval;
  98. int *bp;
  99. #ifndef USE_C
  100. register unsigned qword cpattern;
  101. cpattern = (mode == 0) ? 1 : 1 ;
  102. #endif
  103. _SlibDebug(_VERBOSE_, ScDebugPrintf(H263Info->dbg, "sv_H263GetBlock()\n") );
  104. bp = H263Info->block[comp];
  105. /* decode AC coefficients */
  106. for (i=(mode==0); !BSIn->EOI || BSIn->shift; i++) /* HWG */
  107. {
  108. code = (unsigned int)ScBSPeekBits(BSIn, 12);
  109. if (code>=512)
  110. tab = &DCT3Dtab0[(code>>5)-16];
  111. else if (code>=128)
  112. tab = &DCT3Dtab1[(code>>2)-32];
  113. else if (code>=8)
  114. tab = &DCT3Dtab2[(code>>0)-8];
  115. else {
  116. _SlibDebug(_WARN_, ScDebugPrintf(H263Info->dbg,
  117. "sv_H263GetBlock() invalid Huffman code\n") );
  118. H263Info->expand = 1;
  119. return;
  120. }
  121. ScBSSkipBits(BSIn, tab->len);
  122. run = (tab->val >> 4) & 255;
  123. level = tab->val & 15;
  124. last = (tab->val >> 12) & 1;
  125. if (tab->val==H263_ESCAPE) { /* escape */
  126. #if 0
  127. if (H263Info->trace) {
  128. putchar(' ');
  129. svH263Printbits((int)ScBSPeekBits(BSIn, 1),1,1);
  130. }
  131. #endif
  132. last = ScBSGetBit(BSIn);
  133. #if 0
  134. if (H263Info->trace) {
  135. putchar(' ');
  136. svH263Printbits((int)ScBSPeekBits(BSIn, 6),6,6);
  137. }
  138. #endif
  139. i += run = (int)ScBSGetBits(BSIn, 6);
  140. #if 0
  141. if (H263Info->trace) {
  142. putchar(' ');
  143. svH263Printbits((int)ScBSPeekBits(BSIn, 8),8,8);
  144. }
  145. #endif
  146. level = (int)ScBSGetBits(BSIn, 8);
  147. if ((sign = (level>=128)))
  148. val = 256 - level;
  149. else
  150. val = level;
  151. }
  152. else {
  153. i+= run;
  154. val = level;
  155. sign = (int)ScBSGetBits(BSIn, 1);
  156. }
  157. if (i >= 64)
  158. {
  159. _SlibDebug(_WARN_, ScDebugPrintf(H263Info->dbg,
  160. "sv_H263GetBlock() DCT coeff index (i=%d) out of bounds\n", i) );
  161. H263Info->expand = 1;
  162. return;
  163. }
  164. if (H263Info->trace)
  165. printf("): %d/%d\n",run,sign ? -val : val);
  166. j = zig_zag_scan[i];
  167. qval = &bp[j];
  168. if (comp >= 6)
  169. QP = mmax (1, mmin( 31, (H263_bquant_tab[H263Info->bquant] * H263Info->quant ) >> 2 ));
  170. else
  171. QP = H263Info->quant;
  172. /* TMN3 dequantization */
  173. if ((QP % 2) == 1)
  174. *qval = ( sign ? -(QP * (2* val+1)) : QP * (2* val+1) );
  175. else
  176. *qval = ( sign ? -(QP * (2* val+1)-1): QP * (2* val+1)-1 );
  177. /* scale */
  178. (*qval) *= (int)(dct_constants[j] * H263_SCALED_IDCT_MULT);
  179. #ifndef USE_C
  180. UpdateBlockInfo(j) ;
  181. #endif
  182. if (last)
  183. { /* That's it */
  184. #ifndef USE_C
  185. SetExtraBlockInfo(bp) ;
  186. #endif
  187. _SlibDebug(_DEBUG_, ScDebugPrintf(H263Info->dbg,
  188. "sv_H263GetBlock() done: EOI=%d\n", BSIn->EOI) );
  189. return;
  190. }
  191. }
  192. }
  193. /*********************************************************************
  194. *
  195. * Name: get_sac_block
  196. *
  197. * Description: Decodes blocks of Arithmetic Encoded DCT Coeffs.
  198. * and performs Run Length Decoding and Coefficient
  199. * Dequantisation.
  200. *
  201. * Input: Picture block type and number.
  202. *
  203. * Returns: Nothing.
  204. *
  205. * Side Effects:
  206. *
  207. * Author: Wayne Ellis <ellis_w_wayne@bt-web.bt.co.uk>
  208. *
  209. *********************************************************************/
  210. void sv_H263GetSACblock(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn, int comp, int ptype)
  211. {
  212. register int position=0;
  213. register int TCOEF_index, symbol_word;
  214. int last=0, QP, i, j;
  215. RunCoef DCTcoef;
  216. int *qval;
  217. int *bp;
  218. #ifndef USE_C
  219. register unsigned qword cpattern;
  220. cpattern = (ptype == 0) ? (unsigned qword) 1 : (unsigned qword)1 ;
  221. #endif
  222. _SlibDebug(_VERBOSE_, ScDebugPrintf(H263Info->dbg, "sv_H263GetSACblock()\n") );
  223. bp = H263Info->block[comp];
  224. i = (ptype==0);
  225. /* HWG */
  226. while (!last && (!BSIn->EOI || BSIn->shift)) /* while there are DCT coefficients remaining */
  227. {
  228. position++; /* coefficient counter relates to Coeff. model */
  229. TCOEF_index = DecodeTCoef(H263Info,BSIn,position, !ptype);
  230. if (TCOEF_index == H263_ESCAPE_INDEX) { /* ESCAPE code encountered */
  231. DCTcoef = Decode_Escape_Char(H263Info,BSIn,!ptype, &last);
  232. _SlibDebug(_DEBUG_, ScDebugPrintf(H263Info->dbg, "sv_H263GetSACblock() ESC\n") );
  233. }
  234. else {
  235. symbol_word = H263_tcoeftab[TCOEF_index];
  236. DCTcoef = vlc_word_decode(H263Info,BSIn,symbol_word,&last);
  237. }
  238. _SlibDebug(_DEBUG_, ScDebugPrintf(H263Info->dbg,
  239. "sv_H263GetSACblock() val: %d, run: %d, sign: %d, last: %d\n",
  240. DCTcoef.val, DCTcoef.run, DCTcoef.sign, last) );
  241. i += DCTcoef.run;
  242. j = zig_zag_scan[i];
  243. qval = &bp[j];
  244. i++;
  245. if (comp >= 6)
  246. QP = mmax (1, mmin( 31, (H263_bquant_tab[H263Info->bquant] * H263Info->quant ) >> 2 ));
  247. else
  248. QP = H263Info->quant;
  249. if ((QP % 2) == 1)
  250. *qval = ( (DCTcoef.sign) ? -(QP * (2* (DCTcoef.val)+1)) :
  251. QP * (2* (DCTcoef.val)+1) );
  252. else
  253. *qval = ( (DCTcoef.sign) ? -(QP * (2* (DCTcoef.val)+1)-1):
  254. QP * (2* (DCTcoef.val)+1)-1 );
  255. /* scale */
  256. (*qval) *= (int)(dct_constants[j] * H263_SCALED_IDCT_MULT);
  257. #ifndef USE_C
  258. UpdateBlockInfo(j) ;
  259. #endif
  260. }
  261. #ifndef USE_C
  262. SetExtraBlockInfo(bp) ;
  263. #endif
  264. _SlibDebug(_DEBUG_, ScDebugPrintf(H263Info->dbg,
  265. "sv_H263GetSACblock() done: EOI=%d\n", BSIn->EOI) );
  266. return;
  267. }
  268. /*********************************************************************
  269. *
  270. * Name: vlc_word_decode
  271. *
  272. * Description: Fills Decoder FIFO after a fixed word length
  273. * string has been detected.
  274. *
  275. * Input: Symbol to be decoded, last data flag.
  276. *
  277. * Returns: Decoded Symbol via the structure DCTcoeff.
  278. *
  279. * Side Effects: Updates last flag.
  280. *
  281. * Author: Wayne Ellis <ellis_w_wayne@bt-web.bt.co.uk>
  282. *
  283. *********************************************************************/
  284. RunCoef vlc_word_decode(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn, int symbol_word, int *last)
  285. {
  286. int sign_index;
  287. RunCoef DCTcoef;
  288. *last = (symbol_word >> 12) & 01;
  289. DCTcoef.run = (symbol_word >> 4) & 255;
  290. DCTcoef.val = (symbol_word) & 15;
  291. sign_index = sv_H263SACDecode_a_symbol(BSIn, H263_cumf_SIGN);
  292. DCTcoef.sign = H263_signtab[sign_index];
  293. return (DCTcoef);
  294. }
  295. /*********************************************************************
  296. *
  297. * Name: Decode_Escape_Char
  298. *
  299. * Description: Decodes all components for a Symbol when an
  300. * ESCAPE character has been detected.
  301. *
  302. * Input: Picture Type and last data flag.
  303. *
  304. * Returns: Decoded Symbol via the structure DCTcoeff.
  305. *
  306. * Side Effects: Modifies last data flag.
  307. *
  308. * Author: Wayne Ellis <ellis_w_wayne@bt-web.bt.co.uk>
  309. *
  310. *********************************************************************/
  311. RunCoef Decode_Escape_Char(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn, int intra, int *last)
  312. {
  313. int last_index, run, run_index, level, level_index;
  314. RunCoef DCTcoef;
  315. if (intra) {
  316. last_index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_LAST_intra);
  317. *last = H263_last_intratab[last_index];
  318. }
  319. else {
  320. last_index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_LAST);
  321. *last = H263_lasttab[last_index];
  322. }
  323. if (intra)
  324. run_index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_RUN_intra);
  325. else
  326. run_index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_RUN);
  327. run = H263_runtab[run_index];
  328. /*$if (mrun) run|=64;$*/
  329. DCTcoef.run = run;
  330. if (intra)
  331. level_index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_LEVEL_intra);
  332. else
  333. level_index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_LEVEL);
  334. if (H263Info->trace)
  335. printf("level_idx: %d ",level_index);
  336. level = H263_leveltab[level_index];
  337. if (level >128)
  338. level -=256;
  339. if (level < 0) {
  340. DCTcoef.sign = 1;
  341. DCTcoef.val = abs(level);
  342. }
  343. else {
  344. DCTcoef.sign = 0;
  345. DCTcoef.val = level;
  346. }
  347. return (DCTcoef);
  348. }
  349. /*********************************************************************
  350. *
  351. * Name: DecodeTCoef
  352. *
  353. * Description: Decodes a.c DCT Coefficients using the
  354. * relevant arithmetic decoding model.
  355. *
  356. * Input: DCT Coeff count and Picture Type.
  357. *
  358. * Returns: Index to LUT
  359. *
  360. * Side Effects: None
  361. *
  362. * Author: Wayne Ellis <ellis_w_wayne@bt-web.bt.co.uk>
  363. *
  364. *********************************************************************/
  365. static int H263_cumf_TCOEF1[104]={16383, 13455, 12458, 12079, 11885, 11800, 11738, 11700, 11681, 11661, 11651, 11645, 11641, 10572, 10403, 10361, 10346, 10339, 10335, 9554, 9445, 9427, 9419, 9006, 8968, 8964, 8643, 8627, 8624, 8369, 8354, 8352, 8200, 8192, 8191, 8039, 8036, 7920, 7917, 7800, 7793, 7730, 7727, 7674, 7613, 7564, 7513, 7484, 7466, 7439, 7411, 7389, 7373, 7369, 7359, 7348, 7321, 7302, 7294, 5013, 4819, 4789, 4096, 4073, 3373, 3064, 2674, 2357, 2177, 1975, 1798, 1618, 1517, 1421, 1303, 1194, 1087, 1027, 960, 890, 819, 758, 707, 680, 656, 613, 566, 534, 505, 475, 465, 449, 430, 395, 358, 335, 324, 303, 295, 286, 272, 233, 215, 0};
  366. static int H263_cumf_TCOEF2[104]={16383, 13582, 12709, 12402, 12262, 12188, 12150, 12131, 12125, 12117, 12113, 12108, 12104, 10567, 10180, 10070, 10019, 9998, 9987, 9158, 9037, 9010, 9005, 8404, 8323, 8312, 7813, 7743, 7726, 7394, 7366, 7364, 7076, 7062, 7060, 6810, 6797, 6614, 6602, 6459, 6454, 6304, 6303, 6200, 6121, 6059, 6012, 5973, 5928, 5893, 5871, 5847, 5823, 5809, 5796, 5781, 5771, 5763, 5752, 4754, 4654, 4631, 3934, 3873, 3477, 3095, 2758, 2502, 2257, 2054, 1869, 1715, 1599, 1431, 1305, 1174, 1059, 983, 901, 839, 777, 733, 683, 658, 606, 565, 526, 488, 456, 434, 408, 380, 361, 327, 310, 296, 267, 259, 249, 239, 230, 221, 214, 0};
  367. static int H263_cumf_TCOEF3[104]={16383, 13532, 12677, 12342, 12195, 12112, 12059, 12034, 12020, 12008, 12003, 12002, 12001, 10586, 10297, 10224, 10202, 10195, 10191, 9223, 9046, 8999, 8987, 8275, 8148, 8113, 7552, 7483, 7468, 7066, 7003, 6989, 6671, 6642, 6631, 6359, 6327, 6114, 6103, 5929, 5918, 5792, 5785, 5672, 5580, 5507, 5461, 5414, 5382, 5354, 5330, 5312, 5288, 5273, 5261, 5247, 5235, 5227, 5219, 4357, 4277, 4272, 3847, 3819, 3455, 3119, 2829, 2550, 2313, 2104, 1881, 1711, 1565, 1366, 1219, 1068, 932, 866, 799, 750, 701, 662, 605, 559, 513, 471, 432, 403, 365, 336, 312, 290, 276, 266, 254, 240, 228, 223, 216, 206, 199, 192, 189, 0};
  368. static int H263_cumf_TCOEFr[104]={16383, 13216, 12233, 11931, 11822, 11776, 11758, 11748, 11743, 11742, 11741, 11740, 11739, 10203, 9822, 9725, 9691, 9677, 9674, 8759, 8609, 8576, 8566, 7901, 7787, 7770, 7257, 7185, 7168, 6716, 6653, 6639, 6276, 6229, 6220, 5888, 5845, 5600, 5567, 5348, 5327, 5160, 5142, 5004, 4900, 4798, 4743, 4708, 4685, 4658, 4641, 4622, 4610, 4598, 4589, 4582, 4578, 4570, 4566, 3824, 3757, 3748, 3360, 3338, 3068, 2835, 2592, 2359, 2179, 1984, 1804, 1614, 1445, 1234, 1068, 870, 739, 668, 616, 566, 532, 489, 453, 426, 385, 357, 335, 316, 297, 283, 274, 266, 259, 251, 241, 233, 226, 222, 217, 214, 211, 209, 208, 0};
  369. static int H263_cumf_TCOEF1_intra[104]={16383, 13383, 11498, 10201, 9207, 8528, 8099, 7768, 7546, 7368, 7167, 6994, 6869, 6005, 5474, 5220, 5084, 4964, 4862, 4672, 4591, 4570, 4543, 4397, 4337, 4326, 4272, 4240, 4239, 4212, 4196, 4185, 4158, 4157, 4156, 4140, 4139, 4138, 4137, 4136, 4125, 4124, 4123, 4112, 4111, 4110, 4109, 4108, 4107, 4106, 4105, 4104, 4103, 4102, 4101, 4100, 4099, 4098, 4097, 3043, 2897, 2843, 1974, 1790, 1677, 1552, 1416, 1379, 1331, 1288, 1251, 1250, 1249, 1248, 1247, 1236, 1225, 1224, 1223, 1212, 1201, 1200, 1199, 1198, 1197, 1196, 1195, 1194, 1193, 1192, 1191, 1190, 1189, 1188, 1187, 1186, 1185, 1184, 1183, 1182, 1181, 1180, 1179, 0};
  370. static int H263_cumf_TCOEF2_intra[104]={16383, 13242, 11417, 10134, 9254, 8507, 8012, 7556, 7273, 7062, 6924, 6839, 6741, 6108, 5851, 5785, 5719, 5687, 5655, 5028, 4917, 4864, 4845, 4416, 4159, 4074, 3903, 3871, 3870, 3765, 3752, 3751, 3659, 3606, 3580, 3541, 3540, 3514, 3495, 3494, 3493, 3474, 3473, 3441, 3440, 3439, 3438, 3425, 3424, 3423, 3422, 3421, 3420, 3401, 3400, 3399, 3398, 3397, 3396, 2530, 2419, 2360, 2241, 2228, 2017, 1687, 1576, 1478, 1320, 1281, 1242, 1229, 1197, 1178, 1152, 1133, 1114, 1101, 1088, 1087, 1086, 1085, 1072, 1071, 1070, 1069, 1068, 1067, 1066, 1065, 1064, 1063, 1062, 1061, 1060, 1059, 1058, 1057, 1056, 1055, 1054, 1053, 1052, 0};
  371. static int H263_cumf_TCOEF3_intra[104]={16383, 12741, 10950, 10071, 9493, 9008, 8685, 8516, 8385, 8239, 8209, 8179, 8141, 6628, 5980, 5634, 5503, 5396, 5327, 4857, 4642, 4550, 4481, 4235, 4166, 4151, 3967, 3922, 3907, 3676, 3500, 3324, 3247, 3246, 3245, 3183, 3168, 3084, 3069, 3031, 3030, 3029, 3014, 3013, 2990, 2975, 2974, 2973, 2958, 2943, 2928, 2927, 2926, 2925, 2924, 2923, 2922, 2921, 2920, 2397, 2298, 2283, 1891, 1799, 1591, 1445, 1338, 1145, 1068, 1006, 791, 768, 661, 631, 630, 615, 592, 577, 576, 561, 546, 523, 508, 493, 492, 491, 476, 475, 474, 473, 472, 471, 470, 469, 468, 453, 452, 451, 450, 449, 448, 447, 446, 0};
  372. static int H263_cumf_TCOEFr_intra[104]={16383, 12514, 10776, 9969, 9579, 9306, 9168, 9082, 9032, 9000, 8981, 8962, 8952, 7630, 7212, 7053, 6992, 6961, 6940, 6195, 5988, 5948, 5923, 5370, 5244, 5210, 4854, 4762, 4740, 4384, 4300, 4288, 4020, 3968, 3964, 3752, 3668, 3511, 3483, 3354, 3322, 3205, 3183, 3108, 3046, 2999, 2981, 2974, 2968, 2961, 2955, 2949, 2943, 2942, 2939, 2935, 2934, 2933, 2929, 2270, 2178, 2162, 1959, 1946, 1780, 1651, 1524, 1400, 1289, 1133, 1037, 942, 849, 763, 711, 591, 521, 503, 496, 474, 461, 449, 442, 436, 426, 417, 407, 394, 387, 377, 373, 370, 367, 366, 365, 364, 363, 362, 358, 355, 352, 351, 350, 0};
  373. int DecodeTCoef(SvH263DecompressInfo_t *H263Info, ScBitstream_t *BSIn, int position, int intra)
  374. {
  375. int index;
  376. switch (position) {
  377. case 1:
  378. {
  379. if (intra)
  380. index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_TCOEF1_intra);
  381. else
  382. index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_TCOEF1);
  383. break;
  384. }
  385. case 2:
  386. {
  387. if (intra)
  388. index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_TCOEF2_intra);
  389. else
  390. index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_TCOEF2);
  391. break;
  392. }
  393. case 3:
  394. {
  395. if (intra)
  396. index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_TCOEF3_intra);
  397. else
  398. index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_TCOEF3);
  399. break;
  400. }
  401. default:
  402. {
  403. if (intra)
  404. index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_TCOEFr_intra);
  405. else
  406. index = sv_H263SACDecode_a_symbol(BSIn,H263_cumf_TCOEFr);
  407. break;
  408. }
  409. }
  410. return (index);
  411. }