putvlc.c
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:19k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. #include "momusys.h"
  2. #include "vlc.h"
  3. #include "putvlc.h"
  4. #include "bitstream.h"
  5. Int
  6. PutDCsize_lum (Int size, Image *bitstream)
  7. {
  8. MOMCHECK(size >= 0 && size < 13);
  9. BitstreamPutBits (bitstream, DCtab_lum[size].code, DCtab_lum[size].len);
  10. return DCtab_lum[size].len;
  11. }
  12. Int
  13. PutDCsize_chrom (Int size, Image *bitstream)
  14. {
  15. MOMCHECK (size >= 0 && size < 13);
  16. BitstreamPutBits (bitstream, DCtab_chrom[size].code, DCtab_chrom[size].len);
  17. return DCtab_chrom[size].len;
  18. }
  19. Int
  20. PutMV (Int mvint, Image *bitstream)
  21. {
  22. Int sign = 0;
  23. Int absmv;
  24. if (mvint > 32)
  25. {
  26. absmv = -mvint + 65;
  27. sign = 1;
  28. }
  29. else
  30. absmv = mvint;
  31. BitstreamPutBits (bitstream, mvtab[absmv].code, mvtab[absmv].len);
  32. if (mvint != 0)
  33. {
  34. BitstreamPutBits (bitstream, sign, 1);
  35. return mvtab[absmv].len + 1;
  36. }
  37. else
  38. return mvtab[absmv].len;
  39. }
  40. Int
  41. PutMCBPC_Intra (Int cbpc, Int mode, Image *bitstream)
  42. {
  43. Int ind;
  44. ind = ((mode >> 1) & 3) | ((cbpc & 3) << 2);
  45. BitstreamPutBits (bitstream, mcbpc_intra_tab[ind].code, mcbpc_intra_tab[ind].len);
  46. return mcbpc_intra_tab[ind].len;
  47. }
  48. Int
  49. PutMCBPC_Inter (Int cbpc, Int mode, Image *bitstream)
  50. {
  51. Int ind;
  52. ind = (mode & 7) | ((cbpc & 3) << 3);
  53. BitstreamPutBits (bitstream, mcbpc_inter_tab[ind].code,
  54. mcbpc_inter_tab[ind].len);
  55. return mcbpc_inter_tab[ind].len;
  56. }
  57. Int
  58. PutMCBPC_Sprite (Int cbpc, Int mode, Image *bitstream)
  59. {
  60. Int ind;
  61. ind = (mode & 7) | ((cbpc & 3) << 3);
  62. BitstreamPutBits (bitstream, mcbpc_sprite_tab[ind].code,
  63. mcbpc_sprite_tab[ind].len);
  64. return mcbpc_sprite_tab[ind].len;
  65. }
  66. Int
  67. PutCBPY (Int cbpy, Char intra, Int *MB_transp_pattern, Image *bitstream)
  68. {
  69. Int ind;
  70. Int index=0;
  71. if (intra == 0) cbpy = 15 - cbpy;
  72. ind = cbpy;
  73. BitstreamPutBits (bitstream, cbpy_tab[ind].code, cbpy_tab[ind].len);
  74. return cbpy_tab[ind].len;
  75. }
  76. Int
  77. PutCoeff_Inter(Int run, Int level, Int last, Image *bitstream)
  78. {
  79. Int length = 0;
  80. MOMCHECK (last >= 0 && last < 2);
  81. MOMCHECK (run >= 0 && run < 64);
  82. MOMCHECK (level > 0 && level < 128);
  83. if (last == 0)
  84. {
  85. if (run < 2 && level < 13 )
  86. {
  87. BitstreamPutBits (bitstream, (LInt)coeff_tab0[run][level-1].code,
  88. (LInt)coeff_tab0[run][level-1].len);
  89. length = coeff_tab0[run][level-1].len;
  90. }
  91. else if (run > 1 && run < 27 && level < 5)
  92. {
  93. BitstreamPutBits (bitstream, (LInt)coeff_tab1[run-2][level-1].code,
  94. (LInt)coeff_tab1[run-2][level-1].len);
  95. length = coeff_tab1[run-2][level-1].len;
  96. }
  97. }
  98. else if (last == 1)
  99. {
  100. if (run < 2 && level < 4)
  101. {
  102. BitstreamPutBits (bitstream, (LInt)coeff_tab2[run][level-1].code,
  103. (LInt)coeff_tab2[run][level-1].len);
  104. length = coeff_tab2[run][level-1].len;
  105. }
  106. else if (run > 1 && run < 42 && level == 1)
  107. {
  108. BitstreamPutBits (bitstream, (LInt)coeff_tab3[run-2].code,
  109. (LInt)coeff_tab3[run-2].len);
  110. length = coeff_tab3[run-2].len;
  111. }
  112. }
  113. return length;
  114. }
  115. Int
  116. PutCoeff_Intra(Int run, Int level, Int last, Image *bitstream)
  117. {
  118. Int length = 0;
  119. MOMCHECK (last >= 0 && last < 2);
  120. MOMCHECK (run >= 0 && run < 64);
  121. MOMCHECK (level > 0 && level < 128);
  122. if (last == 0)
  123. {
  124. if (run == 0 && level < 28 )
  125. {
  126. BitstreamPutBits(bitstream, (LInt)coeff_tab4[level-1].code,
  127. (LInt)coeff_tab4[level-1].len);
  128. length = coeff_tab4[level-1].len;
  129. }
  130. else if (run == 1 && level < 11)
  131. {
  132. BitstreamPutBits(bitstream, (LInt)coeff_tab5[level-1].code,
  133. (LInt)coeff_tab5[level-1].len);
  134. length = coeff_tab5[level-1].len;
  135. }
  136. else if (run > 1 && run < 10 && level < 6)
  137. {
  138. BitstreamPutBits(bitstream, (LInt)coeff_tab6[run-2][level-1].code,
  139. (LInt)coeff_tab6[run-2][level-1].len);
  140. length = coeff_tab6[run-2][level-1].len;
  141. }
  142. else if (run > 9 && run < 15 && level == 1)
  143. {
  144. BitstreamPutBits(bitstream, (LInt)coeff_tab7[run-10].code,
  145. (LInt)coeff_tab7[run-10].len);
  146. length = coeff_tab7[run-10].len;
  147. }
  148. }
  149. else if (last == 1)
  150. {
  151. if (run == 0 && level < 9)
  152. {
  153. BitstreamPutBits(bitstream, (LInt)coeff_tab8[level-1].code,
  154. (LInt)coeff_tab8[level-1].len);
  155. length = coeff_tab8[level-1].len;
  156. }
  157. else if (run > 0 && run < 7 && level < 4)
  158. {
  159. BitstreamPutBits(bitstream, (LInt)coeff_tab9[run-1][level-1].code,
  160. (LInt)coeff_tab9[run-1][level-1].len);
  161. length = coeff_tab9[run-1][level-1].len;
  162. }
  163. else if (run > 6 && run < 21 && level == 1)
  164. {
  165. BitstreamPutBits(bitstream, (LInt)coeff_tab10[run-7].code,
  166. (LInt)coeff_tab10[run-7].len);
  167. length = coeff_tab10[run-7].len;
  168. }
  169. }
  170. return length;
  171. }
  172. Int
  173. PutCoeff_Inter_RVLC(Int run, Int level, Int last, Image *bitstream)
  174. {
  175. Int length = 0;
  176. MOMCHECK (last >= 0 && last < 2);
  177. MOMCHECK (run >= 0 && run < 64);
  178. MOMCHECK (level > 0 && level < 128);
  179. if (last == 0)
  180. {
  181. if (run == 0 && level < 20 )
  182. {
  183. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab14[level-1].code,
  184. (LInt)coeff_RVLCtab14[level-1].len);
  185. length = coeff_RVLCtab14[level-1].len;
  186. }
  187. else if (run == 1 && level < 11)
  188. {
  189. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab15[level-1].code,
  190. (LInt)coeff_RVLCtab15[level-1].len);
  191. length = coeff_RVLCtab15[level-1].len;
  192. }
  193. else if (run > 1 && run < 4 && level < 8)
  194. {
  195. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab16[run-2][level-1].code,
  196. (LInt)coeff_RVLCtab16[run-2][level-1].len);
  197. length = coeff_RVLCtab16[run-2][level-1].len;
  198. }
  199. else if (run == 4 && level < 6)
  200. {
  201. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab17[level-1].code,
  202. (LInt)coeff_RVLCtab17[level-1].len);
  203. length = coeff_RVLCtab17[level-1].len;
  204. }
  205. else if (run > 4 && run < 8 && level < 5)
  206. {
  207. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab18[run-5][level-1].code,
  208. (LInt)coeff_RVLCtab18[run-5][level-1].len);
  209. length = coeff_RVLCtab18[run-5][level-1].len;
  210. }
  211. else if (run > 7 && run < 10 && level < 4)
  212. {
  213. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab19[run-8][level-1].code,
  214. (LInt)coeff_RVLCtab19[run-8][level-1].len);
  215. length = coeff_RVLCtab19[run-8][level-1].len;
  216. }
  217. else if (run > 9 && run < 18 && level < 3)
  218. {
  219. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab20[run-10][level-1].code,
  220. (LInt)coeff_RVLCtab20[run-10][level-1].len);
  221. length = coeff_RVLCtab20[run-10][level-1].len;
  222. }
  223. else if (run > 17 && run < 39 && level == 1)
  224. {
  225. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab21[run-18].code,
  226. (LInt)coeff_RVLCtab21[run-18].len);
  227. length = coeff_RVLCtab21[run-18].len;
  228. }
  229. }
  230. else if (last == 1)
  231. {
  232. if (run >= 0 && run < 2 && level < 6)
  233. {
  234. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab22[run][level-1].code,
  235. (LInt)coeff_RVLCtab22[run][level-1].len);
  236. length = coeff_RVLCtab22[run][level-1].len;
  237. }
  238. else if (run == 2 && level < 4)
  239. {
  240. BitstreamPutBits (bitstream, (LInt)coeff_RVLCtab23[level-1].code,
  241. (LInt)coeff_RVLCtab23[level-1].len);
  242. length = coeff_RVLCtab23[level-1].len;
  243. }
  244. else if (run > 2 && run < 14 && level < 3)
  245. {
  246. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab24[run-3][level-1].code,
  247. (LInt)coeff_RVLCtab24[run-3][level-1].len);
  248. length = coeff_RVLCtab24[run-3][level-1].len;
  249. }
  250. else if (run > 13 && run < 46 && level == 1)
  251. {
  252. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab25[run-14].code,
  253. (LInt)coeff_RVLCtab25[run-14].len);
  254. length = coeff_RVLCtab25[run-14].len;
  255. }
  256. }
  257. return length;
  258. }
  259. Int
  260. PutCoeff_Intra_RVLC(Int run, Int level, Int last, Image *bitstream)
  261. {
  262. Int length = 0;
  263. MOMCHECK (last >= 0 && last < 2);
  264. MOMCHECK (run >= 0 && run < 64);
  265. MOMCHECK (level > 0 && level < 128);
  266. if (last == 0)
  267. {
  268. if (run == 0 && level < 28 )
  269. {
  270. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab1[level-1].code,
  271. (LInt)coeff_RVLCtab1[level-1].len);
  272. length = coeff_RVLCtab1[level-1].len;
  273. }
  274. else if (run == 1 && level < 14)
  275. {
  276. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab2[level-1].code,
  277. (LInt)coeff_RVLCtab2[level-1].len);
  278. length = coeff_RVLCtab2[level-1].len;
  279. }
  280. else if (run == 2 && level < 12)
  281. {
  282. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab3[level-1].code,
  283. (LInt)coeff_RVLCtab3[level-1].len);
  284. length = coeff_RVLCtab3[level-1].len;
  285. }
  286. else if (run == 3 && level < 10)
  287. {
  288. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab4[level-1].code,
  289. (LInt)coeff_RVLCtab4[level-1].len);
  290. length = coeff_RVLCtab4[level-1].len;
  291. }
  292. else if (run > 3 && run < 6 && level < 7)
  293. {
  294. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab5[run-4][level-1].code,
  295. (LInt)coeff_RVLCtab5[run-4][level-1].len);
  296. length = coeff_RVLCtab5[run-4][level-1].len;
  297. }
  298. else if (run > 5 && run < 8 && level < 6)
  299. {
  300. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab6[run-6][level-1].code,
  301. (LInt)coeff_RVLCtab6[run-6][level-1].len);
  302. length = coeff_RVLCtab6[run-6][level-1].len;
  303. }
  304. else if (run > 7 && run < 10 && level < 5)
  305. {
  306. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab7[run-8][level-1].code,
  307. (LInt)coeff_RVLCtab7[run-8][level-1].len);
  308. length = coeff_RVLCtab7[run-8][level-1].len;
  309. }
  310. else if (run > 9 && run < 13 && level < 3)
  311. {
  312. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab8[run-10][level-1].code,
  313. (LInt)coeff_RVLCtab8[run-10][level-1].len);
  314. length = coeff_RVLCtab8[run-10][level-1].len;
  315. }
  316. else if (run > 12 && run < 20 && level == 1)
  317. {
  318. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab9[run-13].code,
  319. (LInt)coeff_RVLCtab9[run-13].len);
  320. length = coeff_RVLCtab9[run-13].len;
  321. }
  322. }
  323. else if (last == 1)
  324. {
  325. if (run >= 0 && run < 2 && level < 6)
  326. {
  327. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab10[run][level-1].code,
  328. (LInt)coeff_RVLCtab10[run][level-1].len);
  329. length = coeff_RVLCtab10[run][level-1].len;
  330. }
  331. else if (run == 2 && level < 4)
  332. {
  333. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab11[level-1].code,
  334. (LInt)coeff_RVLCtab11[level-1].len);
  335. length = coeff_RVLCtab11[level-1].len;
  336. }
  337. else if (run > 2 && run < 14 && level < 3)
  338. {
  339. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab12[run-3][level-1].code,
  340. (LInt)coeff_RVLCtab12[run-3][level-1].len);
  341. length = coeff_RVLCtab12[run-3][level-1].len;
  342. }
  343. else if (run > 13 && run < 46 && level == 1)
  344. {
  345. BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab13[run-14].code,
  346. (LInt)coeff_RVLCtab13[run-14].len);
  347. length = coeff_RVLCtab13[run-14].len;
  348. }
  349. }
  350. return length;
  351. }
  352. Int
  353. PutRunCoeff_Inter(Int run, Int level, Int last, Image *bitstream)
  354. {
  355. Int length = 0;
  356. MOMCHECK (last >= 0 && last < 2);
  357. MOMCHECK (run >= 0 && run < 64);
  358. MOMCHECK (level > 0 && level < 128);
  359. if (last == 0)
  360. {
  361. if (run < 2 && level < 13 )
  362. {
  363. length = coeff_tab0[run][level-1].len;
  364. if (length != 0)
  365. {
  366.   
  367. BitstreamPutBits(bitstream, 3L, 7L);
  368.   
  369. BitstreamPutBits(bitstream, 2L, 2L);
  370. length += 9;   
  371. BitstreamPutBits (bitstream, (LInt)coeff_tab0[run][level-1].code,
  372. (LInt)coeff_tab0[run][level-1].len);
  373. }
  374. }
  375. else if (run > 1 && run < 27 && level < 5)
  376. {
  377. length = coeff_tab1[run-2][level-1].len;
  378. if (length != 0)
  379. {
  380.   
  381. BitstreamPutBits(bitstream, 3L, 7L);
  382.   
  383. BitstreamPutBits(bitstream, 2L, 2L);
  384. length += 9;   
  385. BitstreamPutBits (bitstream, (LInt)coeff_tab1[run-2][level-1].code,
  386. (LInt)coeff_tab1[run-2][level-1].len);
  387. }
  388. }
  389. }
  390. else if (last == 1)
  391. {
  392. if (run < 2 && level < 4)
  393. {
  394. length = coeff_tab2[run][level-1].len;
  395. if (length != 0)
  396. {
  397.   
  398. BitstreamPutBits(bitstream, 3L, 7L);
  399.   
  400. BitstreamPutBits(bitstream, 2L, 2L);
  401. length += 9;   
  402. BitstreamPutBits (bitstream, (LInt)coeff_tab2[run][level-1].code,
  403. (LInt)coeff_tab2[run][level-1].len);
  404. }
  405. }
  406. else if (run > 1 && run < 42 && level == 1)
  407. {
  408. length = coeff_tab3[run-2].len;
  409. if (length != 0)
  410. {
  411.   
  412. BitstreamPutBits(bitstream, 3L, 7L);
  413.   
  414. BitstreamPutBits(bitstream, 2L, 2L);
  415. length += 9;   
  416. BitstreamPutBits (bitstream, (LInt)coeff_tab3[run-2].code,
  417. (LInt)coeff_tab3[run-2].len);
  418. }
  419. }
  420. }
  421. return length;
  422. }
  423. Int
  424. PutRunCoeff_Intra(Int run, Int level, Int last, Image *bitstream)
  425. {
  426. Int length = 0;
  427. MOMCHECK (last >= 0 && last < 2);
  428. MOMCHECK (run >= 0 && run < 64);
  429. MOMCHECK (level > 0 && level < 128);
  430. if (last == 0)
  431. {
  432. if (run == 0 && level < 28 )
  433. {
  434. length = coeff_tab4[level-1].len;
  435. if (length != 0)
  436. {
  437.   
  438. BitstreamPutBits(bitstream, 3L, 7L);
  439.   
  440. BitstreamPutBits(bitstream, 2L, 2L);
  441. length += 9;   
  442. BitstreamPutBits(bitstream, (LInt)coeff_tab4[level-1].code,
  443. (LInt)coeff_tab4[level-1].len);
  444. }
  445. }
  446. else if (run == 1 && level < 11)
  447. {
  448. length = coeff_tab5[level-1].len;
  449. if (length != 0)
  450. {
  451.   
  452. BitstreamPutBits(bitstream, 3L, 7L);
  453.   
  454. BitstreamPutBits(bitstream, 2L, 2L);
  455. length += 9;   
  456. BitstreamPutBits(bitstream, (LInt)coeff_tab5[level-1].code,
  457. (LInt)coeff_tab5[level-1].len);
  458. }
  459. }
  460. else if (run > 1 && run < 10 && level < 6)
  461. {
  462. length = coeff_tab6[run-2][level-1].len;
  463. if (length != 0)
  464. {
  465.   
  466. BitstreamPutBits(bitstream, 3L, 7L);
  467.   
  468. BitstreamPutBits(bitstream, 2L, 2L);
  469. length += 9;   
  470. BitstreamPutBits(bitstream, (LInt)coeff_tab6[run-2][level-1].code,
  471. (LInt)coeff_tab6[run-2][level-1].len);
  472. }
  473. }
  474. else if (run > 9 && run < 15 && level == 1)
  475. {
  476. length = coeff_tab7[run-10].len;
  477. if (length != 0)
  478. {
  479.   
  480. BitstreamPutBits(bitstream, 3L, 7L);
  481.   
  482. BitstreamPutBits(bitstream, 2L, 2L);
  483. length += 9;   
  484. BitstreamPutBits(bitstream, (LInt)coeff_tab7[run-10].code,
  485. (LInt)coeff_tab7[run-10].len);
  486. }
  487. }
  488. }
  489. else if (last == 1)
  490. {
  491. if (run == 0 && level < 9)
  492. {
  493. length = coeff_tab8[level-1].len;
  494. if (length != 0)
  495. {
  496.   
  497. BitstreamPutBits(bitstream, 3L, 7L);
  498.   
  499. BitstreamPutBits(bitstream, 2L, 2L);
  500. length += 9;   
  501. BitstreamPutBits(bitstream, (LInt)coeff_tab8[level-1].code,
  502. (LInt)coeff_tab8[level-1].len);
  503. }
  504. }
  505. else if (run > 0 && run < 7 && level < 4)
  506. {
  507. length = coeff_tab9[run-1][level-1].len;
  508. if (length != 0)
  509. {
  510.   
  511. BitstreamPutBits(bitstream, 3L, 7L);
  512.   
  513. BitstreamPutBits(bitstream, 2L, 2L);
  514. length += 9;   
  515. BitstreamPutBits(bitstream, (LInt)coeff_tab9[run-1][level-1].code,
  516. (LInt)coeff_tab9[run-1][level-1].len);
  517. }
  518. }
  519. else if (run > 6 && run < 21 && level == 1)
  520. {
  521. length = coeff_tab10[run-7].len;
  522. if (length != 0)
  523. {
  524.   
  525. BitstreamPutBits(bitstream, 3L, 7L);
  526.   
  527. BitstreamPutBits(bitstream, 2L, 2L);
  528. length += 9;   
  529. BitstreamPutBits(bitstream, (LInt)coeff_tab10[run-7].code,
  530. (LInt)coeff_tab10[run-7].len);
  531. }
  532. }
  533. }
  534. return length;
  535. }
  536. Int
  537. PutLevelCoeff_Inter(Int run, Int level, Int last, Image *bitstream)
  538. {
  539. Int length = 0;
  540. MOMCHECK (last >= 0 && last < 2);
  541. MOMCHECK (run >= 0 && run < 64);
  542. MOMCHECK (level > 0 && level < 128);
  543. if (last == 0)
  544. {
  545. if (run < 2 && level < 13 )
  546. {
  547. length = coeff_tab0[run][level-1].len;
  548. if (length != 0)
  549. {
  550. BitstreamPutBits(bitstream, 3L, 7L);
  551.   
  552. BitstreamPutBits(bitstream, 0L, 1L);
  553. length += 8;   
  554. BitstreamPutBits (bitstream, (LInt)coeff_tab0[run][level-1].code,
  555. (LInt)coeff_tab0[run][level-1].len);
  556. }
  557. }
  558. else if (run > 1 && run < 27 && level < 5)
  559. {
  560. length = coeff_tab1[run-2][level-1].len;
  561. if (length != 0)
  562. {
  563. BitstreamPutBits(bitstream, 3L, 7L);
  564.   
  565. BitstreamPutBits(bitstream, 0L, 1L);
  566. length += 8;   
  567. BitstreamPutBits (bitstream, (LInt)coeff_tab1[run-2][level-1].code,
  568. (LInt)coeff_tab1[run-2][level-1].len);
  569. }
  570. }
  571. }
  572. else if (last == 1)
  573. {
  574. if (run < 2 && level < 4)
  575. {
  576. length = coeff_tab2[run][level-1].len;
  577. if (length != 0)
  578. {
  579. BitstreamPutBits(bitstream, 3L, 7L);
  580.   
  581. BitstreamPutBits(bitstream, 0L, 1L);
  582. length += 8;   
  583. BitstreamPutBits (bitstream, (LInt)coeff_tab2[run][level-1].code,
  584. (LInt)coeff_tab2[run][level-1].len);
  585. }
  586. }
  587. else if (run > 1 && run < 42 && level == 1)
  588. {
  589. length = coeff_tab3[run-2].len;
  590. if (length != 0)
  591. {
  592. BitstreamPutBits(bitstream, 3L, 7L);
  593.   
  594. BitstreamPutBits(bitstream, 0L, 1L);
  595. length += 8;   
  596. BitstreamPutBits (bitstream, (LInt)coeff_tab3[run-2].code,
  597. (LInt)coeff_tab3[run-2].len);
  598. }
  599. }
  600. }
  601. return length;
  602. }
  603. Int
  604. PutLevelCoeff_Intra(Int run, Int level, Int last, Image *bitstream)
  605. {
  606. Int length = 0;
  607. MOMCHECK (last >= 0 && last < 2);
  608. MOMCHECK (run >= 0 && run < 64);
  609. MOMCHECK (level > 0 && level < 128);
  610. if (last == 0)
  611. {
  612. if (run == 0 && level < 28 )
  613. {
  614. length = coeff_tab4[level-1].len;
  615. if (length != 0)
  616. {
  617. BitstreamPutBits(bitstream, 3L, 7L);
  618.   
  619. BitstreamPutBits(bitstream, 0L, 1L);
  620. length += 8;   
  621. BitstreamPutBits(bitstream, (LInt)coeff_tab4[level-1].code,
  622. (LInt)coeff_tab4[level-1].len);
  623. }
  624. }
  625. else if (run == 1 && level < 11)
  626. {
  627. length = coeff_tab5[level-1].len;
  628. if (length != 0)
  629. {
  630. BitstreamPutBits(bitstream, 3L, 7L);
  631.   
  632. BitstreamPutBits(bitstream, 0L, 1L);
  633. length += 8;   
  634. BitstreamPutBits(bitstream, (LInt)coeff_tab5[level-1].code,
  635. (LInt)coeff_tab5[level-1].len);
  636. }
  637. }
  638. else if (run > 1 && run < 10 && level < 6)
  639. {
  640. length = coeff_tab6[run-2][level-1].len;
  641. if (length != 0)
  642. {
  643. BitstreamPutBits(bitstream, 3L, 7L);
  644.   
  645. BitstreamPutBits(bitstream, 0L, 1L);
  646. length += 8;   
  647. BitstreamPutBits(bitstream, (LInt)coeff_tab6[run-2][level-1].code,
  648. (LInt)coeff_tab6[run-2][level-1].len);
  649. }
  650. }
  651. else if (run > 9 && run < 15 && level == 1)
  652. {
  653. length = coeff_tab7[run-10].len;
  654. if (length != 0)
  655. {
  656. BitstreamPutBits(bitstream, 3L, 7L);
  657.   
  658. BitstreamPutBits(bitstream, 0L, 1L);
  659. length += 8;   
  660. BitstreamPutBits(bitstream, (LInt)coeff_tab7[run-10].code,
  661. (LInt)coeff_tab7[run-10].len);
  662. }
  663. }
  664. }
  665. else if (last == 1)
  666. {
  667. if (run == 0 && level < 9)
  668. {
  669. length = coeff_tab8[level-1].len;
  670. if (length != 0)
  671. {
  672. BitstreamPutBits(bitstream, 3L, 7L);
  673.   
  674. BitstreamPutBits(bitstream, 0L, 1L);
  675. length += 8;   
  676. BitstreamPutBits(bitstream, (LInt)coeff_tab8[level-1].code,
  677. (LInt)coeff_tab8[level-1].len);
  678. }
  679. }
  680. else if (run > 0 && run < 7 && level < 4)
  681. {
  682. length = coeff_tab9[run-1][level-1].len;
  683. if (length != 0)
  684. {
  685. BitstreamPutBits(bitstream, 3L, 7L);
  686.   
  687. BitstreamPutBits(bitstream, 0L, 1L);
  688. length += 8;   
  689. BitstreamPutBits(bitstream, (LInt)coeff_tab9[run-1][level-1].code,
  690. (LInt)coeff_tab9[run-1][level-1].len);
  691. }
  692. }
  693. else if (run > 6 && run < 21 && level == 1)
  694. {
  695. length = coeff_tab10[run-7].len;
  696. if (length != 0)
  697. {
  698. BitstreamPutBits(bitstream, 3L, 7L);
  699.   
  700. BitstreamPutBits(bitstream, 0L, 1L);
  701. length += 8;   
  702. BitstreamPutBits(bitstream, (LInt)coeff_tab10[run-7].code,
  703. (LInt)coeff_tab10[run-7].len);
  704. }
  705. }
  706. }
  707. return length;
  708. }