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.

1329 lines
42 KiB

  1. /* File: sv_h263_recon.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. #include "sv_h263.h"
  19. #include "proto.h"
  20. /* private prototypes */
  21. static void sv_recon_comp(unsigned char *src, unsigned char *dst,
  22. int lx, int lx2, int w, int h, int x, int y, int dx, int dy, int flag);
  23. static void sv_recon_comp_obmc(SvH263DecompressInfo_t *H263Info, unsigned char *src, unsigned char *dst,
  24. int lx, int lx2, int comp, int w, int h, int x, int y);
  25. static void sv_rec(unsigned char *s, unsigned char *d, int lx, int lx2, int h);
  26. static void sv_recc(unsigned char *s, unsigned char *d, int lx, int lx2, int h);
  27. static void sv_reco(unsigned char *s, int *d, int lx2, int c, int xa, int xb, int ya, int yb);
  28. static void sv_rech(unsigned char *s, unsigned char *d, int lx, int lx2, int h);
  29. static void sv_rechc(unsigned char *s, unsigned char *d, int lx, int lx2, int h);
  30. static void sv_recho(unsigned char *s, int *d, int lx2, int c, int xa, int xb, int ya, int yb);
  31. static void sv_recv(unsigned char *s, unsigned char *d, int lx, int lx2, int h);
  32. static void sv_recvc(unsigned char *s, unsigned char *d, int lx, int lx2, int h);
  33. static void sv_recvo(unsigned char *s, int *d, int lx2, int c, int xa, int xb, int ya, int yb);
  34. static void sv_rec4(unsigned char *s, unsigned char *d, int lx, int lx2, int h);
  35. static void sv_rec4c(unsigned char *s, unsigned char *d, int lx, int lx2, int h);
  36. static void sv_rec4o(unsigned char *s, int *d, int lx2, int c, int xa, int xb, int ya, int yb);
  37. static int H263_roundtab[16]= {0,0,0,1,1,1,1,1,1,1,1,1,1,1,2,2};
  38. void sv_H263Reconstruct(SvH263DecompressInfo_t *H263Info, int bx, int by, int P, int bdx, int bdy)
  39. {
  40. int w,h,lx,lx2,dx,dy,xp,yp,comp,sum;
  41. int x,y,mode,xvec,yvec;
  42. unsigned char *src[3];
  43. x = bx/16+1; y = by/16+1;
  44. lx = H263Info->coded_picture_width;
  45. if (H263Info->mv_outside_frame) {
  46. lx2 = H263Info->coded_picture_width + 64;
  47. src[0] = H263Info->edgeframe[0];
  48. src[1] = H263Info->edgeframe[1];
  49. src[2] = H263Info->edgeframe[2];
  50. }
  51. else {
  52. lx2 = H263Info->coded_picture_width;
  53. src[0] = H263Info->oldrefframe[0];
  54. src[1] = H263Info->oldrefframe[1];
  55. src[2] = H263Info->oldrefframe[2];
  56. }
  57. mode = H263Info->modemap[y][x];
  58. if (P) {
  59. /* P prediction */
  60. if (H263Info->adv_pred_mode) {
  61. w = 8; h = 8;
  62. /* Y*/
  63. for (comp = 0; comp < 4; comp++) {
  64. xp = bx + ((comp&1)<<3);
  65. yp = by + ((comp&2)<<2);
  66. sv_recon_comp_obmc(H263Info, src[0],H263Info->newframe[0], lx,lx2,comp,w,h,xp,yp);
  67. }
  68. if (mode == H263_MODE_INTER4V) {
  69. sum = H263Info->MV[0][1][y][x]+H263Info->MV[0][2][y][x]+ H263Info->MV[0][3][y][x]+H263Info->MV[0][4][y][x];
  70. dx = sign(sum)*(H263_roundtab[abs(sum)%16] + (abs(sum)/16)*2);
  71. sum = H263Info->MV[1][1][y][x]+H263Info->MV[1][2][y][x]+ H263Info->MV[1][3][y][x]+H263Info->MV[1][4][y][x];
  72. dy = sign(sum)*(H263_roundtab[abs(sum)%16] + (abs(sum)/16)*2);
  73. }
  74. else {
  75. dx = H263Info->MV[0][0][y][x];
  76. dy = H263Info->MV[1][0][y][x];
  77. /* chroma rounding */
  78. dx = ( dx % 4 == 0 ? dx >> 1 : (dx>>1)|1 );
  79. dy = ( dy % 4 == 0 ? dy >> 1 : (dy>>1)|1 );
  80. }
  81. lx>>=1;bx>>=1; lx2>>=1;
  82. by>>=1;
  83. /* Chroma */
  84. sv_recon_comp(src[1],H263Info->newframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  85. sv_recon_comp(src[2],H263Info->newframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  86. }
  87. else { /* normal prediction mode */
  88. /* P prediction */
  89. w = 16; h = 16;
  90. dx = H263Info->MV[0][0][y][x];
  91. dy = H263Info->MV[1][0][y][x];
  92. /* Y */
  93. sv_recon_comp(src[0],H263Info->newframe[0], lx,lx2,w,h,bx,by,dx,dy,0);
  94. lx>>=1; w>>=1; bx>>=1; lx2>>=1;
  95. h>>=1; by>>=1;
  96. /* chroma rounding */
  97. dx = ( dx % 4 == 0 ? dx >> 1 : (dx>>1)|1 );
  98. dy = ( dy % 4 == 0 ? dy >> 1 : (dy>>1)|1 );
  99. /* Chroma */
  100. sv_recon_comp(src[1],H263Info->newframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  101. sv_recon_comp(src[2],H263Info->newframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  102. }
  103. }
  104. else {
  105. /* B forward prediction */
  106. if (H263Info->adv_pred_mode) {
  107. if (mode == H263_MODE_INTER4V) {
  108. w = 8; h = 8;
  109. /* Y*/
  110. xvec = yvec = 0;
  111. for (comp = 0; comp < 4; comp++) {
  112. xvec += (dx = (H263Info->trb)*H263Info->MV[0][comp+1][y][x]/H263Info->trd + bdx);
  113. yvec += (dy = (H263Info->trb)*H263Info->MV[1][comp+1][y][x]/H263Info->trd + bdy);
  114. xp = bx + ((comp&1)<<3);
  115. yp = by + ((comp&2)<<2);
  116. sv_recon_comp(src[0],H263Info->bframe[0], lx,lx2,w,h,xp,yp,dx,dy,0);
  117. }
  118. /* chroma rounding (table 16/H.263) */
  119. dx = sign(xvec)*(H263_roundtab[abs(xvec)%16] + (abs(xvec)/16)*2);
  120. dy = sign(yvec)*(H263_roundtab[abs(yvec)%16] + (abs(yvec)/16)*2);
  121. lx>>=1;bx>>=1; lx2>>=1;
  122. by>>=1;
  123. /* Chroma */
  124. sv_recon_comp(src[1],H263Info->bframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  125. sv_recon_comp(src[2],H263Info->bframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  126. }
  127. else { /* H263Info->adv_pred_mode but 16x16 vector */
  128. w = 16; h = 16;
  129. dx = (H263Info->trb)*H263Info->MV[0][0][y][x]/H263Info->trd + bdx;
  130. dy = (H263Info->trb)*H263Info->MV[1][0][y][x]/H263Info->trd + bdy;
  131. /* Y */
  132. sv_recon_comp(src[0],H263Info->bframe[0], lx,lx2,w,h,bx,by,dx,dy,0);
  133. lx>>=1; w>>=1; bx>>=1; lx2>>=1;
  134. h>>=1; by>>=1;
  135. xvec = 4*dx;
  136. yvec = 4*dy;
  137. /* chroma rounding (table 16/H.263) */
  138. dx = sign(xvec)*(H263_roundtab[abs(xvec)%16] + (abs(xvec)/16)*2);
  139. dy = sign(yvec)*(H263_roundtab[abs(yvec)%16] + (abs(yvec)/16)*2);
  140. /* Chroma */
  141. sv_recon_comp(src[1],H263Info->bframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  142. sv_recon_comp(src[2],H263Info->bframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  143. }
  144. }
  145. else { /* normal B forward prediction */
  146. w = 16; h = 16;
  147. dx = (H263Info->trb)*H263Info->MV[0][0][y][x]/H263Info->trd + bdx;
  148. dy = (H263Info->trb)*H263Info->MV[1][0][y][x]/H263Info->trd + bdy;
  149. /* Y */
  150. sv_recon_comp(src[0],H263Info->bframe[0], lx,lx2,w,h,bx,by,dx,dy,0);
  151. lx>>=1; w>>=1; bx>>=1; lx2>>=1;
  152. h>>=1; by>>=1;
  153. xvec = 4*dx;
  154. yvec = 4*dy;
  155. /* chroma rounding (table 16/H.263) */
  156. dx = sign(xvec)*(H263_roundtab[abs(xvec)%16] + (abs(xvec)/16)*2);
  157. dy = sign(yvec)*(H263_roundtab[abs(yvec)%16] + (abs(yvec)/16)*2);
  158. /* Chroma */
  159. sv_recon_comp(src[1],H263Info->bframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  160. sv_recon_comp(src[2],H263Info->bframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  161. }
  162. }
  163. }
  164. static void sv_recon_comp(src,dst,lx,lx2,w,h,x,y,dx,dy,chroma)
  165. unsigned char *src;
  166. unsigned char *dst;
  167. int lx,lx2;
  168. int w,h;
  169. int x,y;
  170. int dx,dy;
  171. int chroma;
  172. {
  173. register int xint, xh, yint, yh;
  174. register unsigned char *s, *d;
  175. xint = dx>>1;
  176. xh = dx & 1;
  177. yint = dy>>1;
  178. yh = dy & 1;
  179. /* origins */
  180. s = src + lx2*(y+yint) + x + xint;
  181. d = dst + lx*y + x;
  182. #if 0 /* fast but less accurate */
  183. if (w!=8) {
  184. if (!xh && !yh) svH263Rec16_S(s,d,lx,lx2,h);
  185. else if (!xh && yh) svH263Rec16V_S(s,d,lx,lx2,h);
  186. else if ( xh && !yh) svH263Rec16H_S(s,d,lx,lx2,h);
  187. else svH263Rec16B_S(s,d,lx,lx2,h);
  188. }
  189. else {
  190. if (!xh && !yh) svH263Rec8_S(s,d,lx,lx2,h);
  191. else if (!xh && yh) svH263Rec8V_S(s,d,lx,lx2,h);
  192. else if ( xh && !yh) svH263Rec8H_S(s,d,lx,lx2,h);
  193. else svH263Rec8B_S(s,d,lx,lx2,h);
  194. }
  195. #else
  196. if(w != 8) {
  197. if (!xh && !yh) sv_rec(s,d,lx,lx2,h);
  198. else if (!xh && yh) sv_recv(s,d,lx,lx2,h);
  199. else if ( xh && !yh) sv_rech(s,d,lx,lx2,h);
  200. else sv_rec4(s,d,lx,lx2,h);
  201. }
  202. else {
  203. if (!xh && !yh) sv_recc(s,d,lx,lx2,h);
  204. else if (!xh && yh) sv_recvc(s,d,lx,lx2,h);
  205. else if ( xh && !yh) sv_rechc(s,d,lx,lx2,h);
  206. else sv_rec4c(s,d,lx,lx2,h);
  207. }
  208. #endif
  209. }
  210. static void sv_rec(s,d,lx,lx2,h)
  211. unsigned char *s, *d;
  212. int lx,lx2,h;
  213. {
  214. register int j;
  215. register unsigned qword *p1;
  216. unsigned UNALIGNED qword *p2;
  217. for (j=0; j<h; j++)
  218. {
  219. p1 = (unsigned qword *) d;
  220. p2 = (unsigned qword *) s;
  221. p1[0] = p2[0];
  222. p1[1] = p2[1];
  223. s+= lx2;
  224. d+= lx;
  225. }
  226. /*
  227. for (j=0; j<h; j++)
  228. {
  229. d[0] = s[0];
  230. d[1] = s[1];
  231. d[2] = s[2];
  232. d[3] = s[3];
  233. d[4] = s[4];
  234. d[5] = s[5];
  235. d[6] = s[6];
  236. d[7] = s[7];
  237. d[8] = s[8];
  238. d[9] = s[9];
  239. d[10] = s[10];
  240. d[11] = s[11];
  241. d[12] = s[12];
  242. d[13] = s[13];
  243. d[14] = s[14];
  244. d[15] = s[15];
  245. s+= lx2;
  246. d+= lx;
  247. }
  248. */
  249. }
  250. static void sv_recc(s,d,lx,lx2,h)
  251. unsigned char *s, *d;
  252. int lx,lx2,h;
  253. {
  254. int j;
  255. for (j=0; j<h; j++)
  256. {
  257. unsigned qword *p1;
  258. unsigned UNALIGNED qword *p2;
  259. p1 = (unsigned qword *) d;
  260. p2 = (unsigned qword *) s;
  261. p1[0] = p2[0];
  262. s+= lx2;
  263. d+= lx;
  264. }
  265. /*
  266. for (j=0; j<h; j++)
  267. {
  268. d[0] = s[0];
  269. d[1] = s[1];
  270. d[2] = s[2];
  271. d[3] = s[3];
  272. d[4] = s[4];
  273. d[5] = s[5];
  274. d[6] = s[6];
  275. d[7] = s[7];
  276. s+= lx2;
  277. d+= lx;
  278. }
  279. */
  280. }
  281. static void sv_rech(s,d,lx,lx2,h)
  282. unsigned char *s, *d;
  283. int lx,lx2,h;
  284. {
  285. /* unsigned int s1,s2; */
  286. register unsigned char *dp,*sp;
  287. int j;
  288. register unsigned qword *dpl;
  289. register unsigned UNALIGNED qword *p1;
  290. register unsigned UNALIGNED qword *p2;
  291. register unsigned qword acc1,acc2,acc3,acc4;
  292. sp = s;
  293. dp = d;
  294. for (j=0; j<h; j++)
  295. {
  296. dpl = (unsigned qword *) dp;
  297. p1 = (unsigned qword *) sp;
  298. p2 = (unsigned qword *) (sp+1);
  299. acc1 = p1[0];
  300. acc2 = p2[0];
  301. acc3 = (acc1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  302. acc4 = (acc2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  303. acc1 &= 0x00ff00ff00ff00ff;
  304. acc2 &= 0x00ff00ff00ff00ff;
  305. acc3 += acc4 + (unsigned qword) 0x0001000100010001;
  306. acc1 += acc2 + (unsigned qword) 0x0001000100010001;
  307. acc3 = (acc3 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  308. acc1 = (acc1 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  309. dpl[0] = (acc3 << 8) | acc1;
  310. acc1 = p1[1];
  311. acc2 = p2[1];
  312. acc3 = (acc1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  313. acc4 = (acc2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  314. acc1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  315. acc2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  316. acc3 += acc4 + (unsigned qword) 0x0001000100010001;
  317. acc1 += acc2 + (unsigned qword) 0x0001000100010001;
  318. acc3 = (acc3 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  319. acc1 = (acc1 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  320. dpl[1] = (acc3 << 8) | acc1;
  321. /*
  322. s1=sp[0];
  323. dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
  324. dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
  325. dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
  326. dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
  327. dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
  328. dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
  329. dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
  330. dp[7] = (unsigned int)(s2+(s1=sp[8])+1)>>1;
  331. dp[8] = (unsigned int)(s1+(s2=sp[9])+1)>>1;
  332. dp[9] = (unsigned int)(s2+(s1=sp[10])+1)>>1;
  333. dp[10] = (unsigned int)(s1+(s2=sp[11])+1)>>1;
  334. dp[11] = (unsigned int)(s2+(s1=sp[12])+1)>>1;
  335. dp[12] = (unsigned int)(s1+(s2=sp[13])+1)>>1;
  336. dp[13] = (unsigned int)(s2+(s1=sp[14])+1)>>1;
  337. dp[14] = (unsigned int)(s1+(s2=sp[15])+1)>>1;
  338. dp[15] = (unsigned int)(s2+sp[16]+1)>>1;
  339. */
  340. sp+= lx2;
  341. dp+= lx;
  342. }
  343. }
  344. static void sv_rechc(s,d,lx,lx2,h)
  345. unsigned char *s, *d;
  346. int lx,lx2,h;
  347. {
  348. /* unsigned int s1,s2; */
  349. register unsigned char *dp,*sp;
  350. int j;
  351. unsigned qword *dpl;
  352. unsigned UNALIGNED qword *p1;
  353. unsigned UNALIGNED qword *p2;
  354. unsigned qword acc1,acc2,acc3,acc4;
  355. sp = s;
  356. dp = d;
  357. for (j=0; j<h; j++)
  358. {
  359. dpl = (unsigned qword *) dp;
  360. p1 = (unsigned qword *) sp;
  361. p2 = (unsigned qword *) (sp+1);
  362. acc1 = p1[0];
  363. acc2 = p2[0];
  364. acc3 = (acc1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  365. acc4 = (acc2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  366. acc1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  367. acc2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  368. acc3 += acc4 + (unsigned qword) 0x0001000100010001;
  369. acc1 += acc2 + (unsigned qword) 0x0001000100010001;
  370. acc3 = (acc3 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  371. acc1 = (acc1 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  372. dpl[0] = (acc3 << 8) | acc1;
  373. /*
  374. s1=sp[0];
  375. dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
  376. dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
  377. dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
  378. dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
  379. dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
  380. dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
  381. dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
  382. dp[7] = (unsigned int)(s2+sp[8]+1)>>1;
  383. */
  384. sp+= lx2;
  385. dp+= lx;
  386. }
  387. }
  388. static void sv_recv(s,d,lx,lx2,h)
  389. unsigned char *s, *d;
  390. int lx,lx2,h;
  391. {
  392. register unsigned char *dp,*sp,*sp2;
  393. int j;
  394. register unsigned qword *dpl;
  395. register unsigned UNALIGNED qword *p1;
  396. register unsigned UNALIGNED qword *p2;
  397. register unsigned qword acc1,acc2,acc3,acc4;
  398. sp = s;
  399. sp2 = s+lx2;
  400. dp = d;
  401. for (j=0; j<h; j++)
  402. {
  403. dpl = (unsigned qword *) dp;
  404. p1 = (unsigned qword *) sp;
  405. p2 = (unsigned qword *) sp2;
  406. acc1 = p1[0];
  407. acc2 = p2[0];
  408. acc3 = (acc1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  409. acc4 = (acc2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  410. acc1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  411. acc2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  412. acc3 += acc4 + (unsigned qword) 0x0001000100010001;
  413. acc1 += acc2 + (unsigned qword) 0x0001000100010001;
  414. acc3 = (acc3 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  415. acc1 = (acc1 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  416. dpl[0] = (acc3 << 8) | acc1;
  417. acc1 = p1[1];
  418. acc2 = p2[1];
  419. acc3 = (acc1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  420. acc4 = (acc2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  421. acc1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  422. acc2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  423. acc3 += acc4 + (unsigned qword) 0x0001000100010001;
  424. acc1 += acc2 + (unsigned qword) 0x0001000100010001;
  425. acc3 = (acc3 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  426. acc1 = (acc1 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  427. dpl[1] = (acc3 << 8) | acc1;
  428. /*
  429. dp[0] = (unsigned int)(sp[0]+sp2[0]+1)>>1;
  430. dp[1] = (unsigned int)(sp[1]+sp2[1]+1)>>1;
  431. dp[2] = (unsigned int)(sp[2]+sp2[2]+1)>>1;
  432. dp[3] = (unsigned int)(sp[3]+sp2[3]+1)>>1;
  433. dp[4] = (unsigned int)(sp[4]+sp2[4]+1)>>1;
  434. dp[5] = (unsigned int)(sp[5]+sp2[5]+1)>>1;
  435. dp[6] = (unsigned int)(sp[6]+sp2[6]+1)>>1;
  436. dp[7] = (unsigned int)(sp[7]+sp2[7]+1)>>1;
  437. dp[8] = (unsigned int)(sp[8]+sp2[8]+1)>>1;
  438. dp[9] = (unsigned int)(sp[9]+sp2[9]+1)>>1;
  439. dp[10] = (unsigned int)(sp[10]+sp2[10]+1)>>1;
  440. dp[11] = (unsigned int)(sp[11]+sp2[11]+1)>>1;
  441. dp[12] = (unsigned int)(sp[12]+sp2[12]+1)>>1;
  442. dp[13] = (unsigned int)(sp[13]+sp2[13]+1)>>1;
  443. dp[14] = (unsigned int)(sp[14]+sp2[14]+1)>>1;
  444. dp[15] = (unsigned int)(sp[15]+sp2[15]+1)>>1;
  445. */
  446. sp+= lx2;
  447. sp2+= lx2;
  448. dp+= lx;
  449. }
  450. }
  451. static void sv_recvc(s,d,lx,lx2,h)
  452. unsigned char *s, *d;
  453. int lx,lx2,h;
  454. {
  455. register unsigned char *dp,*sp,*sp2;
  456. int j;
  457. register unsigned qword *dpl;
  458. register unsigned UNALIGNED qword *p1;
  459. register unsigned UNALIGNED qword *p2;
  460. register unsigned qword acc1,acc2,acc3,acc4;
  461. sp = s;
  462. sp2 = s+lx2;
  463. dp = d;
  464. for (j=0; j<h; j++)
  465. {
  466. /*
  467. dp[0] = (unsigned int)(sp[0]+sp2[0]+1)>>1;
  468. dp[1] = (unsigned int)(sp[1]+sp2[1]+1)>>1;
  469. dp[2] = (unsigned int)(sp[2]+sp2[2]+1)>>1;
  470. dp[3] = (unsigned int)(sp[3]+sp2[3]+1)>>1;
  471. dp[4] = (unsigned int)(sp[4]+sp2[4]+1)>>1;
  472. dp[5] = (unsigned int)(sp[5]+sp2[5]+1)>>1;
  473. dp[6] = (unsigned int)(sp[6]+sp2[6]+1)>>1;
  474. dp[7] = (unsigned int)(sp[7]+sp2[7]+1)>>1;
  475. */
  476. dpl = (unsigned qword *) dp;
  477. p1 = (unsigned qword *) sp;
  478. p2 = (unsigned qword *) sp2;
  479. acc1 = p1[0];
  480. acc2 = p2[0];
  481. acc3 = (acc1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  482. acc4 = (acc2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  483. acc1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  484. acc2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  485. acc3 += acc4 + (unsigned qword) 0x0001000100010001;
  486. acc1 += acc2 + (unsigned qword) 0x0001000100010001;
  487. acc3 = (acc3 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  488. acc1 = (acc1 >> 1) & (unsigned qword) 0x00ff00ff00ff00ff;
  489. dpl[0] = (acc3 << 8) | acc1;
  490. sp+= lx2;
  491. sp2+= lx2;
  492. dp+= lx;
  493. }
  494. }
  495. static void sv_rec4(s,d,lx,lx2,h)
  496. unsigned char *s, *d;
  497. int lx,lx2,h;
  498. {
  499. /* unsigned int s1,s2,s3,s4; */
  500. register unsigned char *dp,*sp,*sp2;
  501. int j;
  502. register unsigned qword *dpl;
  503. register unsigned UNALIGNED qword *u1;
  504. register unsigned UNALIGNED qword *u2;
  505. register unsigned UNALIGNED qword *l1;
  506. register unsigned UNALIGNED qword *l2;
  507. unsigned qword odd1,odd2,even1,even2,oddacc,evenacc;
  508. sp = s;
  509. sp2 = s+lx2;
  510. dp = d;
  511. for (j=0; j<h; j++)
  512. {
  513. /*
  514. s1=sp[0]; s3=sp2[0];
  515. dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
  516. dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
  517. dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
  518. dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
  519. dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
  520. dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
  521. dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
  522. dp[7] = (unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2;
  523. dp[8] = (unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2;
  524. dp[9] = (unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2;
  525. dp[10] = (unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2;
  526. dp[11] = (unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2;
  527. dp[12] = (unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2;
  528. dp[13] = (unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2;
  529. dp[14] = (unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2;
  530. dp[15] = (unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2;
  531. */
  532. dpl = (unsigned qword *) dp;
  533. u1 = (unsigned qword *) sp;
  534. u2 = (unsigned qword *) (sp+1);
  535. l1 = (unsigned qword *) sp2;
  536. l2 = (unsigned qword *) (sp2+1);
  537. odd1 = u1[0];
  538. odd2 = u2[0];
  539. even1 = (odd1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  540. even2 = (odd2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  541. odd1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  542. odd2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  543. oddacc = odd1 + odd2;
  544. evenacc = even1 + even2;
  545. odd1 = l1[0];
  546. odd2 = l2[0];
  547. even1 = (odd1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  548. even2 = (odd2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  549. odd1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  550. odd2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  551. oddacc += odd1 + odd2 + (unsigned qword) 0x0002000200020002;
  552. evenacc += even1 + even2 + (unsigned qword) 0x0002000200020002;
  553. evenacc = (evenacc >> 2) & (unsigned qword) 0x00ff00ff00ff00ff;
  554. oddacc = (oddacc >> 2) & (unsigned qword) 0x00ff00ff00ff00ff;
  555. dpl[0] = (evenacc << 8) | oddacc;
  556. odd1 = u1[1];
  557. odd2 = u2[1];
  558. even1 = (odd1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  559. even2 = (odd2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  560. odd1 &= (unsigned qword)0x00ff00ff00ff00ff;
  561. odd2 &= (unsigned qword)0x00ff00ff00ff00ff;
  562. oddacc = odd1 + odd2;
  563. evenacc = even1 + even2;
  564. odd1 = l1[1];
  565. odd2 = l2[1];
  566. even1 = (odd1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  567. even2 = (odd2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  568. odd1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  569. odd2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  570. oddacc += odd1 + odd2 + (unsigned qword) 0x0002000200020002;
  571. evenacc += even1 + even2 + (unsigned qword) 0x0002000200020002;
  572. evenacc = (evenacc >> 2) & (unsigned qword) 0x00ff00ff00ff00ff;
  573. oddacc = (oddacc >> 2) & (unsigned qword) 0x00ff00ff00ff00ff;
  574. dpl[1] = (evenacc << 8) | oddacc;
  575. sp+= lx2;
  576. sp2+= lx2;
  577. dp+= lx;
  578. }
  579. }
  580. static void sv_rec4c(s,d,lx,lx2,h)
  581. unsigned char *s, *d;
  582. int lx,lx2,h;
  583. {
  584. /* unsigned int s1,s2,s3,s4; */
  585. register unsigned char *dp,*sp,*sp2;
  586. int j;
  587. register unsigned qword *dpl;
  588. register unsigned UNALIGNED qword *u1;
  589. register unsigned UNALIGNED qword *u2;
  590. register unsigned UNALIGNED qword *l1;
  591. register unsigned UNALIGNED qword *l2;
  592. unsigned qword odd1,odd2,even1,even2,oddacc,evenacc;
  593. sp = s;
  594. sp2 = s+lx2;
  595. dp = d;
  596. for (j=0; j<h; j++)
  597. {
  598. /*
  599. s1=sp[0]; s3=sp2[0];
  600. dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
  601. dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
  602. dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
  603. dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
  604. dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
  605. dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
  606. dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
  607. dp[7] = (unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2;
  608. */
  609. dpl = (unsigned qword *) dp;
  610. u1 = (unsigned qword *) sp;
  611. u2 = (unsigned qword *) (sp+1);
  612. l1 = (unsigned qword *) sp2;
  613. l2 = (unsigned qword *) (sp2+1);
  614. odd1 = u1[0];
  615. odd2 = u2[0];
  616. even1 = (odd1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  617. even2 = (odd2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  618. odd1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  619. odd2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  620. oddacc = odd1 + odd2;
  621. evenacc = even1 + even2;
  622. odd1 = l1[0];
  623. odd2 = l2[0];
  624. even1 = (odd1 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  625. even2 = (odd2 & (unsigned qword) 0xff00ff00ff00ff00) >> 8;
  626. odd1 &= (unsigned qword) 0x00ff00ff00ff00ff;
  627. odd2 &= (unsigned qword) 0x00ff00ff00ff00ff;
  628. oddacc += odd1 + odd2 + (unsigned qword) 0x0002000200020002;
  629. evenacc += even1 + even2 + (unsigned qword) 0x0002000200020002;
  630. evenacc = (evenacc >> 2) & (unsigned qword) 0x00ff00ff00ff00ff;
  631. oddacc = (oddacc >> 2) & (unsigned qword) 0x00ff00ff00ff00ff;
  632. dpl[0] = (evenacc << 8) | oddacc;
  633. sp+= lx2;
  634. sp2+= lx2;
  635. dp+= lx;
  636. }
  637. }
  638. static int DEC_OM[4][8][8] =
  639. {{
  640. {1,1,1,1,1,1,1,1},
  641. {0,0,1,1,1,1,0,0},
  642. {0,0,0,0,0,0,0,0},
  643. {0,0,0,0,0,0,0,0},
  644. {0,0,0,0,0,0,0,0},
  645. {0,0,0,0,0,0,0,0},
  646. {0,0,0,0,0,0,0,0},
  647. {0,0,0,0,0,0,0,0},
  648. },{
  649. {0,0,0,0,0,0,0,0},
  650. {0,0,0,0,0,0,0,0},
  651. {0,0,0,0,0,0,0,0},
  652. {0,0,0,0,0,0,0,0},
  653. {0,0,0,0,0,0,0,0},
  654. {0,0,0,0,0,0,0,0},
  655. {0,0,1,1,1,1,0,0},
  656. {1,1,1,1,1,1,1,1},
  657. },{
  658. {0,0,0,0,0,0,0,1},
  659. {0,0,0,0,0,0,1,1},
  660. {0,0,0,0,0,0,1,1},
  661. {0,0,0,0,0,0,1,1},
  662. {0,0,0,0,0,0,1,1},
  663. {0,0,0,0,0,0,1,1},
  664. {0,0,0,0,0,0,1,1},
  665. {0,0,0,0,0,0,0,1},
  666. },{
  667. {1,0,0,0,0,0,0,0},
  668. {1,1,0,0,0,0,0,0},
  669. {1,1,0,0,0,0,0,0},
  670. {1,1,0,0,0,0,0,0},
  671. {1,1,0,0,0,0,0,0},
  672. {1,1,0,0,0,0,0,0},
  673. {1,1,0,0,0,0,0,0},
  674. {1,0,0,0,0,0,0,0},
  675. } };
  676. static void sv_reco(s,d,lx2,c,xa,xb,ya,yb)
  677. unsigned char *s;
  678. int *d;
  679. int lx2,c,xa,xb,ya,yb;
  680. {
  681. int i,j;
  682. switch(c) {
  683. case 0:
  684. *d++ = (unsigned int)s[0] << 2;
  685. for (i = 1; i < 7; i++) *d++ = (unsigned int)s[i] * 5 ;
  686. *d++ = (unsigned int)s[7] << 2;
  687. s+= lx2;
  688. for (i = 0; i < 8; i++) *d++ = (unsigned int)s[i] * 5 ;
  689. s+= lx2;
  690. for (j = 2; j < 6; j++) {
  691. *d++ = (unsigned int)s[0] * 5;
  692. *d++ = (unsigned int)s[1] * 5;
  693. for (i = 2; i < 6; i++) *d++ = (unsigned int)s[i] * 6 ;
  694. *d++ = (unsigned int)s[6] * 5;
  695. *d++ = (unsigned int)s[7] * 5;
  696. s+= lx2;
  697. }
  698. for (i = 0; i < 8; i++) *d++ = (unsigned int)s[i] * 5 ;
  699. s+= lx2;
  700. *d++ = (unsigned int)s[0] << 2;
  701. for (i = 1; i < 7; i++) *d++ = (unsigned int)s[i] * 5 ;
  702. *d++ = (unsigned int)s[7] << 2;
  703. break;
  704. case 1:
  705. *d++ += ((unsigned int)s[0] << 1);
  706. *d++ += ((unsigned int)s[1] << 1);
  707. *d++ += ((unsigned int)s[2] << 1);
  708. *d++ += ((unsigned int)s[3] << 1);
  709. *d++ += ((unsigned int)s[4] << 1);
  710. *d++ += ((unsigned int)s[5] << 1);
  711. *d++ += ((unsigned int)s[6] << 1);
  712. *d++ += ((unsigned int)s[7] << 1);
  713. s += lx2;
  714. *d++ += s[0];
  715. *d++ += s[1];
  716. *d++ += ((unsigned int)s[2] << 1);
  717. *d++ += ((unsigned int)s[3] << 1);
  718. *d++ += ((unsigned int)s[4] << 1);
  719. *d++ += ((unsigned int)s[5] << 1);
  720. *d++ += s[6];
  721. *d++ += s[7];
  722. s += lx2;
  723. for (j=2; j<4; j++) {
  724. *d++ += s[0];
  725. *d++ += s[1];
  726. *d++ += s[2];
  727. *d++ += s[3];
  728. *d++ += s[4];
  729. *d++ += s[5];
  730. *d++ += s[6];
  731. *d++ += s[7];
  732. s += lx2;
  733. }
  734. break;
  735. case 2:
  736. for (j=0; j<2; j++) {
  737. *d++ += s[0];
  738. *d++ += s[1];
  739. *d++ += s[2];
  740. *d++ += s[3];
  741. *d++ += s[4];
  742. *d++ += s[5];
  743. *d++ += s[6];
  744. *d++ += s[7];
  745. s += lx2;
  746. }
  747. *d++ += s[0];
  748. *d++ += s[1];
  749. *d++ += ((unsigned int)s[2] << 1);
  750. *d++ += ((unsigned int)s[3] << 1);
  751. *d++ += ((unsigned int)s[4] << 1);
  752. *d++ += ((unsigned int)s[5] << 1);
  753. *d++ += s[6];
  754. *d++ += s[7];
  755. s += lx2;
  756. *d++ += ((unsigned int)s[0] << 1);
  757. *d++ += ((unsigned int)s[1] << 1);
  758. *d++ += ((unsigned int)s[2] << 1);
  759. *d++ += ((unsigned int)s[3] << 1);
  760. *d++ += ((unsigned int)s[4] << 1);
  761. *d++ += ((unsigned int)s[5] << 1);
  762. *d++ += ((unsigned int)s[6] << 1);
  763. *d++ += ((unsigned int)s[7] << 1);
  764. s += lx2;
  765. break;
  766. case 3:
  767. d[4] += s[4];
  768. d[5] += s[5];
  769. d[6] += s[6];
  770. d[7] += ((unsigned int)s[7] << 1) ;
  771. s += lx2; d += 8;
  772. for (j=0; j<6; j++) {
  773. d[4] += s[4];
  774. d[5] += s[5];
  775. d[6] += ((unsigned int)s[6] << 1) ;
  776. d[7] += ((unsigned int)s[7] << 1) ;
  777. s += lx2; d += 8;
  778. }
  779. d[4] += s[4];
  780. d[5] += s[5];
  781. d[6] += s[6];
  782. d[7] += ((unsigned int)s[7] << 1) ;
  783. break;
  784. case 4:
  785. d[0] += ((unsigned int)s[0] << 1) ;
  786. d[1] += s[1];
  787. d[2] += s[2];
  788. d[3] += s[3];
  789. s += lx2; d += 8;
  790. for (j=0; j<6; j++) {
  791. d[0] += ((unsigned int)s[0] << 1) ;
  792. d[1] += ((unsigned int)s[1] << 1) ;
  793. d[2] += s[2];
  794. d[3] += s[3];
  795. s += lx2; d += 8;
  796. }
  797. d[0] += ((unsigned int)s[0] << 1) ;
  798. d[1] += s[1];
  799. d[2] += s[2];
  800. d[3] += s[3];
  801. default:
  802. break;
  803. }
  804. }
  805. static void sv_recvo(s,d,lx2,c,xa,xb,ya,yb)
  806. unsigned char *s;
  807. int *d;
  808. int lx2,c,xa,xb,ya,yb;
  809. {
  810. register int *dp,*om;
  811. register unsigned char *sp,*sp2;
  812. int i,j;
  813. sp = s;
  814. sp2 = s+lx2;
  815. dp = d;
  816. if(!c) {
  817. *dp++ = (unsigned int)((sp[0] + sp2[0] + 1) >> 1) << 2;
  818. for (i = 1; i < 7; i++) *dp++ = ((unsigned int)(sp[i] + sp2[i] + 1)>>1) * 5 ;
  819. *dp++ = (unsigned int)((sp[7] + sp2[7] + 1) >> 1) << 2;
  820. sp += lx2; sp2 += lx2;
  821. for (i = 0; i < 8; i++) *dp++ = ((unsigned int)(sp[i] + sp2[i] + 1)>>1) * 5 ;
  822. sp += lx2; sp2 += lx2;
  823. for (j = 2; j < 6; j++) {
  824. *dp++ = ((unsigned int)(sp[0] + sp2[0] + 1)>>1) * 5;
  825. *dp++ = ((unsigned int)(sp[1] + sp2[1] + 1)>>1) * 5;
  826. for (i = 2; i < 6; i++) *dp++ = ((unsigned int)(sp[i] + sp2[i] + 1)>>1) * 6 ;
  827. *dp++ = ((unsigned int)(sp[6] + sp2[6] + 1)>>1) * 5;
  828. *dp++ = ((unsigned int)(sp[7] + sp2[7] + 1)>>1) * 5;
  829. sp+= lx2; sp2+=lx2;
  830. }
  831. for (i = 0; i < 8; i++) *dp++ = ((unsigned int)(sp[i] + sp2[i] + 1)>>1) * 5 ;
  832. sp+= lx2; sp2+=lx2;
  833. *dp++ = (unsigned int)((sp[0] + sp2[0] + 1) >> 1) << 2;
  834. for (i = 1; i < 7; i++) *dp++ = ((unsigned int)(sp[i] + sp2[i] + 1)>>1) * 5 ;
  835. *dp++ = (unsigned int)((sp[7] + sp2[7] + 1) >> 1) << 2;
  836. }
  837. else {
  838. om = &DEC_OM[c-1][ya][0];
  839. for (j = ya; j < yb; j++) {
  840. for (i = xa; i < xb; i++)
  841. dp[i] += (((unsigned int)(sp[i] + sp2[i] + 1)>>1) << om[i]) ;
  842. sp += lx2; sp2 += lx2; dp += 8; om += 8;
  843. }
  844. }
  845. }
  846. static void sv_recho(s,d,lx2,c,xa,xb,ya,yb)
  847. unsigned char *s;
  848. int *d;
  849. int lx2,c,xa,xb,ya,yb;
  850. {
  851. register int *dp,*om;
  852. register unsigned char *sp,tmp;
  853. int i,j;
  854. sp = s;
  855. dp = d;
  856. if(!c) {
  857. *dp++ = (unsigned int)((sp[0] + (tmp=sp[1]) + 1) >> 1) << 2;
  858. for (i = 1; i < 7; i++)
  859. *dp++ = ((unsigned int)(tmp + (tmp=sp[i+1]) + 1)>>1) * 5 ;
  860. *dp++ = (unsigned int)((tmp + sp[8]+1) >> 1) << 2;
  861. sp += lx2;
  862. tmp = sp[0] ;
  863. for (i = 0; i < 8; i++)
  864. *dp++ = ((unsigned int)(tmp + (tmp=sp[i+1]) + 1)>>1) * 5 ;
  865. sp += lx2;
  866. for (j = 2; j < 6; j++) {
  867. *dp++ = ((unsigned int)(sp[0] + (tmp=sp[1]) + 1)>>1) * 5;
  868. *dp++ = ((unsigned int)(tmp + (tmp=sp[2]) + 1)>>1) * 5;
  869. for (i = 2; i < 6; i++)
  870. *dp++ = ((unsigned int)(tmp + (tmp=sp[i+1]) + 1)>>1) * 6 ;
  871. *dp++ = ((unsigned int)(tmp + (tmp=sp[7]) + 1)>>1) * 5;
  872. *dp++ = ((unsigned int)(tmp + (tmp=sp[8]) + 1)>>1) * 5;
  873. sp+= lx2;
  874. }
  875. tmp = sp[0];
  876. for (i = 0; i < 8; i++)
  877. *dp++ = ((unsigned int)(tmp + (tmp=sp[i+1]) + 1)>>1) * 5 ;
  878. sp+= lx2;
  879. *dp++ = (unsigned int)((sp[0] + (tmp=sp[1]) + 1) >> 1) << 2;
  880. for (i = 1; i < 7; i++)
  881. *dp++ = ((unsigned int)(tmp + (tmp=sp[i+1]) + 1)>>1) * 5 ;
  882. *dp++ = (unsigned int)((tmp + sp[8]+1) >> 1) << 2;
  883. }
  884. else {
  885. om = &DEC_OM[c-1][ya][0];
  886. for (j = ya; j < yb; j++) {
  887. tmp = sp[xa];
  888. for (i = xa; i < xb; i++)
  889. dp[i] += ( ((unsigned int)(tmp + (tmp=sp[i+1]) + 1)>>1) << om[i]) ;
  890. sp+= lx2; dp+= 8; om+= 8;
  891. }
  892. }
  893. }
  894. static void sv_rec4o(s,d,lx2,c,xa,xb,ya,yb)
  895. unsigned char *s;
  896. int *d;
  897. int lx2,c,xa,xb,ya,yb;
  898. {
  899. register int *dp,tmp;
  900. register unsigned char *sp,*sp2;
  901. int i,j;
  902. sp = s;
  903. sp2 = s+lx2;
  904. dp = d;
  905. switch(c) {
  906. case 0:
  907. *dp++ = (unsigned int)(sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2);
  908. for (i = 1; i < 7; i++)
  909. *dp++ = ((unsigned int)(tmp+(tmp=(sp[i+1]+sp2[i+1]))+2)>>2)*5 ;
  910. *dp++ = (unsigned int)(tmp+sp[8]+sp2[8]+2);
  911. sp += lx2; sp2 += lx2;
  912. tmp = sp[0]+sp2[0];
  913. for (i = 0; i < 8; i++)
  914. *dp++ = ((unsigned int)(tmp+(tmp=(sp[i+1]+sp2[i+1]))+2)>>2)*5 ;
  915. sp += lx2; sp2 += lx2;
  916. for (j = 2; j < 6; j++) {
  917. *dp++ = ((unsigned int)(sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2)*5;
  918. *dp++ = ((unsigned int)(tmp+(tmp=(sp[2]+sp2[2]))+2)>>2)*5;
  919. for (i = 2; i < 6; i++)
  920. *dp++ = ((unsigned int)(tmp+(tmp=(sp[i+1]+sp2[i+1]))+2)>>2)*6 ;
  921. *dp++ = ((unsigned int)(tmp+(tmp=(sp[7]+sp2[7]))+2)>>2)*5;
  922. *dp++ = ((unsigned int)(tmp+sp[8]+sp2[8]+2)>>2)*5;
  923. sp+= lx2; sp2+=lx2;
  924. }
  925. tmp = sp[0]+sp2[0];
  926. for (i = 0; i < 7; i++)
  927. *dp++ = ((unsigned int)(tmp+(tmp=(sp[i+1]+sp2[i+1]))+2)>>2)*5 ;
  928. *dp++ = (unsigned int)((tmp+sp[8]+sp2[8]+2)>>2)*5 ;
  929. sp+= lx2; sp2+=lx2;
  930. *dp++ = (unsigned int)(sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2);
  931. for (i = 1; i < 7; i++)
  932. *dp++ = ((unsigned int)(tmp+(tmp=(sp[i+1]+sp2[i+1]))+2)>>2)*5 ;
  933. *dp++ = (unsigned int)(tmp+sp[8]+sp2[8]+2);
  934. break;
  935. case 1:
  936. *dp++ += (((unsigned int)(sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2) << 1);
  937. *dp++ += (((unsigned int)(tmp+(tmp=(sp[2]+sp2[2]))+2)>>2) << 1);
  938. *dp++ += (((unsigned int)(tmp+(tmp=(sp[3]+sp2[3]))+2)>>2) << 1);
  939. *dp++ += (((unsigned int)(tmp+(tmp=(sp[4]+sp2[4]))+2)>>2) << 1);
  940. *dp++ += (((unsigned int)(tmp+(tmp=(sp[5]+sp2[5]))+2)>>2) << 1);
  941. *dp++ += (((unsigned int)(tmp+(tmp=(sp[6]+sp2[6]))+2)>>2) << 1);
  942. *dp++ += (((unsigned int)(tmp+(tmp=(sp[7]+sp2[7]))+2)>>2) << 1);
  943. *dp++ += (((unsigned int)(tmp+(tmp=(sp[8]+sp2[8]))+2)>>2) << 1);
  944. sp+= lx2; sp2+= lx2;
  945. *dp++ += ((sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2);
  946. *dp++ += ((tmp+(tmp=(sp[2]+sp2[2]))+2)>>2);
  947. *dp++ += (((unsigned int)(tmp+(tmp=(sp[3]+sp2[3]))+2)>>2) << 1);
  948. *dp++ += (((unsigned int)(tmp+(tmp=(sp[4]+sp2[4]))+2)>>2) << 1);
  949. *dp++ += (((unsigned int)(tmp+(tmp=(sp[5]+sp2[5]))+2)>>2) << 1);
  950. *dp++ += (((unsigned int)(tmp+(tmp=(sp[6]+sp2[6]))+2)>>2) << 1);
  951. *dp++ += ((tmp+(tmp=(sp[7]+sp2[7]))+2)>>2);
  952. *dp++ += ((tmp+(tmp=(sp[8]+sp2[8]))+2)>>2);
  953. sp+= lx2; sp2+= lx2;
  954. for (j=2; j<4; j++) {
  955. *dp++ += ((sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2);
  956. *dp++ += ((tmp+(tmp=(sp[2]+sp2[2]))+2)>>2);
  957. *dp++ += ((tmp+(tmp=(sp[3]+sp2[3]))+2)>>2);
  958. *dp++ += ((tmp+(tmp=(sp[4]+sp2[4]))+2)>>2);
  959. *dp++ += ((tmp+(tmp=(sp[5]+sp2[5]))+2)>>2);
  960. *dp++ += ((tmp+(tmp=(sp[6]+sp2[6]))+2)>>2);
  961. *dp++ += ((tmp+(tmp=(sp[7]+sp2[7]))+2)>>2);
  962. *dp++ += ((tmp+sp[8]+sp2[8]+2)>>2);
  963. sp+= lx2; sp2+= lx2;
  964. }
  965. break;
  966. case 2:
  967. for (j=0; j<2; j++) {
  968. *dp++ += ((sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2);
  969. *dp++ += ((tmp+(tmp=(sp[2]+sp2[2]))+2)>>2);
  970. *dp++ += ((tmp+(tmp=(sp[3]+sp2[3]))+2)>>2);
  971. *dp++ += ((tmp+(tmp=(sp[4]+sp2[4]))+2)>>2);
  972. *dp++ += ((tmp+(tmp=(sp[5]+sp2[5]))+2)>>2);
  973. *dp++ += ((tmp+(tmp=(sp[6]+sp2[6]))+2)>>2);
  974. *dp++ += ((tmp+(tmp=(sp[7]+sp2[7]))+2)>>2);
  975. *dp++ += ((tmp+sp[8]+sp2[8]+2)>>2);
  976. sp+= lx2; sp2+= lx2;
  977. }
  978. *dp++ += ((sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2);
  979. *dp++ += ((tmp+(tmp=(sp[2]+sp2[2]))+2)>>2);
  980. *dp++ += (((unsigned int)(tmp+(tmp=(sp[3]+sp2[3]))+2)>>2) << 1);
  981. *dp++ += (((unsigned int)(tmp+(tmp=(sp[4]+sp2[4]))+2)>>2) << 1);
  982. *dp++ += (((unsigned int)(tmp+(tmp=(sp[5]+sp2[5]))+2)>>2) << 1);
  983. *dp++ += (((unsigned int)(tmp+(tmp=(sp[6]+sp2[6]))+2)>>2) << 1);
  984. *dp++ += ((tmp+(tmp=(sp[7]+sp2[7]))+2)>>2);
  985. *dp++ += ((tmp+sp[8]+sp2[8]+2)>>2);
  986. sp+= lx2; sp2+= lx2;
  987. *dp++ += (((unsigned int)(sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2) << 1);
  988. *dp++ += (((unsigned int)(tmp+(tmp=(sp[2]+sp2[2]))+2)>>2) << 1);
  989. *dp++ += (((unsigned int)(tmp+(tmp=(sp[3]+sp2[3]))+2)>>2) << 1);
  990. *dp++ += (((unsigned int)(tmp+(tmp=(sp[4]+sp2[4]))+2)>>2) << 1);
  991. *dp++ += (((unsigned int)(tmp+(tmp=(sp[5]+sp2[5]))+2)>>2) << 1);
  992. *dp++ += (((unsigned int)(tmp+(tmp=(sp[6]+sp2[6]))+2)>>2) << 1);
  993. *dp++ += (((unsigned int)(tmp+(tmp=(sp[7]+sp2[7]))+2)>>2) << 1);
  994. *dp++ += (((unsigned int)(tmp+sp[8]+sp2[8]+2)>>2) << 1);
  995. break;
  996. case 3:
  997. dp[4] += ((sp[4]+sp2[4]+(tmp=(sp[5]+sp2[5]))+2)>>2);
  998. dp[5] += ((tmp+(tmp=(sp[6]+sp2[6]))+2)>>2);
  999. dp[6] += ((tmp+(tmp=(sp[7]+sp2[7]))+2)>>2);
  1000. dp[7] += (((unsigned int)(tmp+sp[8]+sp2[8]+2)>>2) << 1) ;
  1001. sp += lx2; sp2 += lx2; dp += 8;
  1002. for (j=0; j<6; j++) {
  1003. dp[4] += ((sp[4]+sp2[4]+(tmp=(sp[5]+sp2[5]))+2)>>2);
  1004. dp[5] += ((tmp+(tmp=(sp[6]+sp2[6]))+2)>>2);
  1005. dp[6] += (((unsigned int)(tmp+(tmp=(sp[7]+sp2[7]))+2)>>2) << 1) ;
  1006. dp[7] += (((unsigned int)(tmp+sp[8]+sp2[8]+2)>>2) << 1) ;
  1007. sp += lx2; sp2 += lx2; dp += 8; ;
  1008. }
  1009. dp[4] += ((sp[4]+sp2[4]+(tmp=(sp[5]+sp2[5]))+2)>>2);
  1010. dp[5] += ((tmp+(tmp=(sp[6]+sp2[6]))+2)>>2);
  1011. dp[6] += ((tmp+(tmp=(sp[7]+sp2[7]))+2)>>2);
  1012. dp[7] += (((unsigned int)(tmp+sp[8]+sp2[8]+2)>>2) << 1) ;
  1013. break;
  1014. case 4:
  1015. dp[0] += (((unsigned int)(sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2) << 1) ;
  1016. dp[1] += ((tmp+(tmp=(sp[2]+sp2[2]))+2)>>2);
  1017. dp[2] += ((tmp+(tmp=(sp[3]+sp2[3]))+2)>>2);
  1018. dp[3] += ((tmp+sp[4]+sp2[4]+2)>>2);
  1019. sp += lx2; sp2 += lx2; dp += 8;
  1020. for (j=0; j<6; j++) {
  1021. dp[0] += (((unsigned int)(sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2) << 1) ;
  1022. dp[1] += (((unsigned int)(tmp+(tmp=(sp[2]+sp2[2]))+2)>>2) << 1) ;
  1023. dp[2] += ((tmp+(tmp=(sp[3]+sp2[3]))+2)>>2);
  1024. dp[3] += ((tmp+sp[4]+sp2[4]+2)>>2);
  1025. sp += lx2; sp2 += lx2; dp += 8;
  1026. }
  1027. dp[0] += (((unsigned int)(sp[0]+sp2[0]+(tmp=(sp[1]+sp2[1]))+2)>>2) << 1) ;
  1028. dp[1] += ((tmp+(tmp=(sp[2]+sp2[2]))+2)>>2);
  1029. dp[2] += ((tmp+(tmp=(sp[3]+sp2[3]))+2)>>2);
  1030. dp[3] += ((tmp+sp[4]+sp2[4]+2)>>2);
  1031. default:
  1032. break;
  1033. }
  1034. }
  1035. static void sv_recon_comp_obmc(SvH263DecompressInfo_t *H263Info, unsigned char *src, unsigned char *dst,
  1036. int lx, int lx2, int comp, int w, int h, int x, int y)
  1037. {
  1038. int j,k;
  1039. int xmb,ymb;
  1040. int c8,t8,l8,r8;
  1041. int ti8,li8,ri8;
  1042. int xit,xib,xir,xil;
  1043. int yit,yib,yir,yil;
  1044. int vect,vecb,vecr,vecl;
  1045. int nx[5],ny[5],xint,yint,xh[5],yh[5];
  1046. int p[64],*pd;
  1047. unsigned char *d,*s[5];
  1048. xmb = (x>>4)+1;
  1049. ymb = (y>>4)+1;
  1050. c8 = (H263Info->modemap[ymb][xmb] == H263_MODE_INTER4V ? 1 : 0);
  1051. t8 = (H263Info->modemap[ymb-1][xmb] == H263_MODE_INTER4V ? 1 : 0);
  1052. ti8 = (H263Info->modemap[ymb-1][xmb] == H263_MODE_INTRA ? 1 : 0);
  1053. ti8 = (H263Info->modemap[ymb-1][xmb] == H263_MODE_INTRA_Q ? 1 : ti8);
  1054. l8 = (H263Info->modemap[ymb][xmb-1] == H263_MODE_INTER4V ? 1 : 0);
  1055. li8 = (H263Info->modemap[ymb][xmb-1] == H263_MODE_INTRA ? 1 : 0);
  1056. li8 = (H263Info->modemap[ymb][xmb-1] == H263_MODE_INTRA_Q ? 1 : li8);
  1057. r8 = (H263Info->modemap[ymb][xmb+1] == H263_MODE_INTER4V ? 1 : 0);
  1058. ri8 = (H263Info->modemap[ymb][xmb+1] == H263_MODE_INTRA ? 1 : 0);
  1059. ri8 = (H263Info->modemap[ymb][xmb+1] == H263_MODE_INTRA_Q ? 1 : ri8);
  1060. if (H263Info->pb_frame) ti8 = li8 = ri8 = 0;
  1061. switch (comp+1) {
  1062. case 1:
  1063. vect = (ti8 ? (c8 ? 1 : 0) : (t8 ? 3 : 0));
  1064. yit = (ti8 ? ymb : ymb - 1);
  1065. xit = xmb;
  1066. vecb = (c8 ? 3 : 0) ; yib = ymb; xib = xmb;
  1067. vecl = (li8 ? (c8 ? 1 : 0) : (l8 ? 2 : 0));
  1068. yil = ymb;
  1069. xil = (li8 ? xmb : xmb-1);
  1070. vecr = (c8 ? 2 : 0) ; yir = ymb; xir = xmb;
  1071. /* edge handling */
  1072. if (ymb == 1) {
  1073. yit = ymb;
  1074. vect = (c8 ? 1 : 0);
  1075. }
  1076. if (xmb == 1) {
  1077. xil = xmb;
  1078. vecl = (c8 ? 1 : 0);
  1079. }
  1080. break;
  1081. case 2:
  1082. vect = (ti8 ? (c8 ? 2 : 0) : (t8 ? 4 : 0));
  1083. yit = (ti8 ? ymb : ymb-1);
  1084. xit = xmb;
  1085. vecb = (c8 ? 4 : 0) ; yib = ymb; xib = xmb;
  1086. vecl = (c8 ? 1 : 0) ; yil = ymb; xil = xmb;
  1087. vecr = (ri8 ? (c8 ? 2 : 0) : (r8 ? 1 : 0));
  1088. yir = ymb;
  1089. xir = (ri8 ? xmb : xmb+1);
  1090. /* edge handling */
  1091. if (ymb == 1) {
  1092. yit = ymb;
  1093. vect = (c8 ? 2 : 0);
  1094. }
  1095. if (xmb == H263Info->mb_width) {
  1096. xir = xmb;
  1097. vecr = (c8 ? 2 : 0);
  1098. }
  1099. break;
  1100. case 3:
  1101. vect = (c8 ? 1 : 0) ; yit = ymb ; xit = xmb;
  1102. vecb = (c8 ? 3 : 0) ; yib = ymb ; xib = xmb;
  1103. vecl = (li8 ? (c8 ? 3 : 0) : (l8 ? 4 : 0));
  1104. yil = ymb;
  1105. xil = (li8 ? xmb : xmb-1);
  1106. vecr = (c8 ? 4 : 0) ; yir = ymb ; xir = xmb;
  1107. /* edge handling */
  1108. if (xmb == 1) {
  1109. xil = xmb;
  1110. vecl = (c8 ? 3 : 0);
  1111. }
  1112. break;
  1113. case 4:
  1114. vect = (c8 ? 2 : 0) ; yit = ymb ; xit = xmb;
  1115. vecb = (c8 ? 4 : 0) ; yib = ymb ; xib = xmb;
  1116. vecl = (c8 ? 3 : 0) ; yil = ymb ; xil = xmb;
  1117. vecr = (ri8 ? (c8 ? 4 : 0) : (r8 ? 3 : 0));
  1118. yir = ymb;
  1119. xir = (ri8 ? xmb : xmb+1);
  1120. /* edge handling */
  1121. if (xmb == H263Info->mb_width) {
  1122. xir = xmb;
  1123. vecr = (c8 ? 4 : 0);
  1124. }
  1125. break;
  1126. default:
  1127. svH263Error("Illegal block number in sv_recon_comp_obmc (sv_recon.c)\n");
  1128. break;
  1129. }
  1130. nx[0] = H263Info->MV[0][c8 ? comp + 1 : 0][ymb][xmb];
  1131. ny[0] = H263Info->MV[1][c8 ? comp + 1 : 0][ymb][xmb];
  1132. nx[1] = H263Info->MV[0][vect][yit][xit]; ny[1] = H263Info->MV[1][vect][yit][xit];
  1133. nx[2] = H263Info->MV[0][vecb][yib][xib]; ny[2] = H263Info->MV[1][vecb][yib][xib];
  1134. nx[3] = H263Info->MV[0][vecr][yir][xir]; ny[3] = H263Info->MV[1][vecr][yir][xir];
  1135. nx[4] = H263Info->MV[0][vecl][yil][xil]; ny[4] = H263Info->MV[1][vecl][yil][xil];
  1136. for (k=0; k<5; k++) {
  1137. xint = nx[k]>>1;
  1138. xh[k] = nx[k] & 1;
  1139. yint = ny[k]>>1;
  1140. yh[k] = ny[k] & 1;
  1141. s[k] = src + lx2 * (y + yint) + x + xint;
  1142. }
  1143. d = dst + lx*y + x;
  1144. pd = &p[0];
  1145. if (!xh[0] && !yh[0]) sv_reco(s[0],pd,lx2,0,0,8,0,8);
  1146. else if (!xh[0] && yh[0]) sv_recvo(s[0],pd,lx2,0,0,8,0,8);
  1147. else if ( xh[0] && !yh[0]) sv_recho(s[0],pd,lx2,0,0,8,0,8);
  1148. else sv_rec4o(s[0],pd,lx2,0,0,8,0,8);
  1149. if (!xh[1] && !yh[1]) sv_reco(s[1],pd,lx2,1,0,8,0,4);
  1150. else if (!xh[1] && yh[1]) sv_recvo(s[1],pd,lx2,1,0,8,0,4);
  1151. else if ( xh[1] && !yh[1]) sv_recho(s[1],pd,lx2,1,0,8,0,4);
  1152. else sv_rec4o(s[1],pd,lx2,1,0,8,0,4);
  1153. if (!xh[2] && !yh[2]) sv_reco(s[2]+(lx2<<2),pd+32,lx2,2,0,8,4,8);
  1154. else if (!xh[2] && yh[2]) sv_recvo(s[2]+(lx2<<2),pd+32,lx2,2,0,8,4,8);
  1155. else if ( xh[2] && !yh[2]) sv_recho(s[2]+(lx2<<2),pd+32,lx2,2,0,8,4,8);
  1156. else sv_rec4o(s[2]+(lx2<<2),pd+32,lx2,2,0,8,4,8);
  1157. if (!xh[3] && !yh[3]) sv_reco(s[3],pd,lx2,3,4,8,0,8);
  1158. else if (!xh[3] && yh[3]) sv_recvo(s[3],pd,lx2,3,4,8,0,8);
  1159. else if ( xh[3] && !yh[3]) sv_recho(s[3],pd,lx2,3,4,8,0,8);
  1160. else sv_rec4o(s[3],pd,lx2,3,4,8,0,8);
  1161. if (!xh[4] && !yh[4]) sv_reco(s[4],pd,lx2,4,0,4,0,8);
  1162. else if (!xh[4] && yh[4]) sv_recvo(s[4],pd,lx2,4,0,4,0,8);
  1163. else if ( xh[4] && !yh[4]) sv_recho(s[4],pd,lx2,4,0,4,0,8);
  1164. else sv_rec4o(s[4],pd,lx2,4,0,4,0,8);
  1165. for (j = 0; j < 8; j++) {
  1166. d[0] = (pd[0] + 4 )>>3;
  1167. d[1] = (pd[1] + 4 )>>3;
  1168. d[2] = (pd[2] + 4 )>>3;
  1169. d[3] = (pd[3] + 4 )>>3;
  1170. d[4] = (pd[4] + 4 )>>3;
  1171. d[5] = (pd[5] + 4 )>>3;
  1172. d[6] = (pd[6] + 4 )>>3;
  1173. d[7] = (pd[7] + 4 )>>3;
  1174. d += lx;
  1175. pd += 8;
  1176. }
  1177. }