dsputil_align.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:12k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*
  2.  * aligned/packed access motion 
  3.  *
  4.  * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with this library; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  */
  20. #include "../avcodec.h"
  21. #include "../dsputil.h"
  22. #define LP(p) *(uint32_t*)(p)
  23. #define UNPACK(ph,pl,tt0,tt1) do { 
  24. uint32_t t0,t1; t0=tt0;t1=tt1; 
  25. ph = ( (t0 & ~BYTE_VEC32(0x03))>>2) + ( (t1 & ~BYTE_VEC32(0x03))>>2); 
  26. pl = (t0 & BYTE_VEC32(0x03)) + (t1 & BYTE_VEC32(0x03)); } while(0)
  27. #define rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x02))>>2) & BYTE_VEC32(0x03))
  28. #define no_rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x01))>>2) & BYTE_VEC32(0x03))
  29. /* little endian */
  30. #define MERGE1(a,b,ofs) (ofs==0)?a:( ((a)>>(8*ofs))|((b)<<(32-8*ofs)) )
  31. #define MERGE2(a,b,ofs) (ofs==3)?b:( ((a)>>(8*(ofs+1)))|((b)<<(32-8*(ofs+1))) )
  32. /* big
  33. #define MERGE1(a,b,ofs) (ofs==0)?a:( ((a)<<(8*ofs))|((b)>>(32-8*ofs)) )
  34. #define MERGE2(a,b,ofs) (ofs==3)?b:( ((a)<<(8+8*ofs))|((b)>>(32-8-8*ofs)) )
  35. */
  36. #define put(d,s) d = s
  37. #define avg(d,s) d = rnd_avg32(s,d)
  38. #define OP_C4(ofs) 
  39. ref-=ofs; 
  40. do { 
  41. OP(LP(dest),MERGE1(LP(ref),LP(ref+4),ofs)); 
  42. ref+=stride; 
  43. dest+=stride; 
  44. } while(--height)
  45. #define OP_C40() 
  46. do { 
  47. OP(LP(dest),LP(ref)); 
  48. ref+=stride; 
  49. dest+=stride; 
  50. } while(--height)
  51. #define OP put
  52. static void put_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
  53. {
  54. switch((int)ref&3){
  55. case 0: OP_C40(); return;
  56. case 1: OP_C4(1); return;
  57. case 2: OP_C4(2); return;
  58. case 3: OP_C4(3); return;
  59. }
  60. }
  61. #undef OP
  62. #define OP avg
  63. static void avg_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
  64. {
  65. switch((int)ref&3){
  66. case 0: OP_C40(); return;
  67. case 1: OP_C4(1); return;
  68. case 2: OP_C4(2); return;
  69. case 3: OP_C4(3); return;
  70. }
  71. }
  72. #undef OP
  73. #define OP_C(ofs,sz,avg2) 
  74. ref-=ofs; 
  75. do { 
  76. uint32_t t0,t1; 
  77. t0 = LP(ref+0); 
  78. t1 = LP(ref+4); 
  79. OP(LP(dest+0), MERGE1(t0,t1,ofs)); 
  80. t0 = LP(ref+8); 
  81. OP(LP(dest+4), MERGE1(t1,t0,ofs)); 
  82. if (sz==16) { 
  83. t1 = LP(ref+12); 
  84. OP(LP(dest+8), MERGE1(t0,t1,ofs)); 
  85. t0 = LP(ref+16); 
  86. OP(LP(dest+12), MERGE1(t1,t0,ofs)); 
  87. ref+=stride; 
  88. dest+= stride; 
  89. } while(--height); 
  90. }
  91. /* aligned */
  92. #define OP_C0(sz,avg2) 
  93. do { 
  94. OP(LP(dest+0), LP(ref+0)); 
  95. OP(LP(dest+4), LP(ref+4)); 
  96. if (sz==16) { 
  97. OP(LP(dest+8), LP(ref+8)); 
  98. OP(LP(dest+12), LP(ref+12)); 
  99. ref+=stride; 
  100. dest+= stride; 
  101. } while(--height); 
  102. }
  103. #define OP_X(ofs,sz,avg2) 
  104. ref-=ofs; 
  105. do { 
  106. uint32_t t0,t1; 
  107. t0 = LP(ref+0); 
  108. t1 = LP(ref+4); 
  109. OP(LP(dest+0), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); 
  110. t0 = LP(ref+8); 
  111. OP(LP(dest+4), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); 
  112. if (sz==16) { 
  113. t1 = LP(ref+12); 
  114. OP(LP(dest+8), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); 
  115. t0 = LP(ref+16); 
  116. OP(LP(dest+12), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); 
  117. ref+=stride; 
  118. dest+= stride; 
  119. } while(--height); 
  120. }
  121. /* aligned */
  122. #define OP_Y0(sz,avg2) 
  123. uint32_t t0,t1,t2,t3,t; 
  124. t0 = LP(ref+0); 
  125. t1 = LP(ref+4); 
  126. if (sz==16) { 
  127. t2 = LP(ref+8); 
  128. t3 = LP(ref+12); 
  129. do { 
  130. ref += stride; 
  131. t = LP(ref+0); 
  132. OP(LP(dest+0), avg2(t0,t)); t0 = t; 
  133. t = LP(ref+4); 
  134. OP(LP(dest+4), avg2(t1,t)); t1 = t; 
  135. if (sz==16) { 
  136. t = LP(ref+8); 
  137. OP(LP(dest+8), avg2(t2,t)); t2 = t; 
  138. t = LP(ref+12); 
  139. OP(LP(dest+12), avg2(t3,t)); t3 = t; 
  140. dest+= stride; 
  141. } while(--height); 
  142. }
  143. #define OP_Y(ofs,sz,avg2) 
  144. uint32_t t0,t1,t2,t3,t,w0,w1; 
  145. ref-=ofs; 
  146. w0 = LP(ref+0); 
  147. w1 = LP(ref+4); 
  148. t0 = MERGE1(w0,w1,ofs); 
  149. w0 = LP(ref+8); 
  150. t1 = MERGE1(w1,w0,ofs); 
  151. if (sz==16) { 
  152. w1 = LP(ref+12); 
  153. t2 = MERGE1(w0,w1,ofs); 
  154. w0 = LP(ref+16); 
  155. t3 = MERGE1(w1,w0,ofs); 
  156. do { 
  157. ref += stride; 
  158. w0 = LP(ref+0); 
  159. w1 = LP(ref+4); 
  160. t = MERGE1(w0,w1,ofs); 
  161. OP(LP(dest+0), avg2(t0,t)); t0 = t; 
  162. w0 = LP(ref+8); 
  163. t = MERGE1(w1,w0,ofs); 
  164. OP(LP(dest+4), avg2(t1,t)); t1 = t; 
  165. if (sz==16) { 
  166. w1 = LP(ref+12); 
  167. t = MERGE1(w0,w1,ofs); 
  168. OP(LP(dest+8), avg2(t2,t)); t2 = t; 
  169. w0 = LP(ref+16); 
  170. t = MERGE1(w1,w0,ofs); 
  171. OP(LP(dest+12), avg2(t3,t)); t3 = t; 
  172. dest+=stride; 
  173. } while(--height); 
  174. }
  175. #define OP_X0(sz,avg2) OP_X(0,sz,avg2)
  176. #define OP_XY0(sz,PACK) OP_XY(0,sz,PACK)
  177. #define OP_XY(ofs,sz,PACK) 
  178. uint32_t t2,t3,w0,w1; 
  179. uint32_t a0,a1,a2,a3,a4,a5,a6,a7; 
  180. ref -= ofs; 
  181. w0 = LP(ref+0); 
  182. w1 = LP(ref+4); 
  183. UNPACK(a0,a1,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); 
  184. w0 = LP(ref+8); 
  185. UNPACK(a2,a3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); 
  186. if (sz==16) { 
  187. w1 = LP(ref+12); 
  188. UNPACK(a4,a5,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); 
  189. w0 = LP(ref+16); 
  190. UNPACK(a6,a7,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); 
  191. do { 
  192. ref+=stride; 
  193. w0 = LP(ref+0); 
  194. w1 = LP(ref+4); 
  195. UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); 
  196. OP(LP(dest+0),PACK(a0,a1,t2,t3)); 
  197. a0 = t2; a1 = t3; 
  198. w0 = LP(ref+8); 
  199. UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); 
  200. OP(LP(dest+4),PACK(a2,a3,t2,t3)); 
  201. a2 = t2; a3 = t3; 
  202. if (sz==16) { 
  203. w1 = LP(ref+12); 
  204. UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); 
  205. OP(LP(dest+8),PACK(a4,a5,t2,t3)); 
  206. a4 = t2; a5 = t3; 
  207. w0 = LP(ref+16); 
  208. UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); 
  209. OP(LP(dest+12),PACK(a6,a7,t2,t3)); 
  210. a6 = t2; a7 = t3; 
  211. dest+=stride; 
  212. } while(--height); 
  213. }
  214. #define DEFFUNC(op,rnd,xy,sz,OP_N,avgfunc) 
  215. static void op##_##rnd##_pixels##sz##_##xy (uint8_t * dest, const uint8_t * ref,
  216.    const int stride, int height)
  217. switch((int)ref&3) { 
  218. case 0:OP_N##0(sz,rnd##_##avgfunc); return; 
  219. case 1:OP_N(1,sz,rnd##_##avgfunc); return; 
  220. case 2:OP_N(2,sz,rnd##_##avgfunc); return; 
  221. case 3:OP_N(3,sz,rnd##_##avgfunc); return; 
  222. }
  223. #define OP put
  224. DEFFUNC(put,   rnd,o,8,OP_C,avg2)
  225. DEFFUNC(put,   rnd,x,8,OP_X,avg2)
  226. DEFFUNC(put,no_rnd,x,8,OP_X,avg2)
  227. DEFFUNC(put,   rnd,y,8,OP_Y,avg2)
  228. DEFFUNC(put,no_rnd,y,8,OP_Y,avg2)
  229. DEFFUNC(put,   rnd,xy,8,OP_XY,PACK)
  230. DEFFUNC(put,no_rnd,xy,8,OP_XY,PACK)
  231. DEFFUNC(put,   rnd,o,16,OP_C,avg2)
  232. DEFFUNC(put,   rnd,x,16,OP_X,avg2)
  233. DEFFUNC(put,no_rnd,x,16,OP_X,avg2)
  234. DEFFUNC(put,   rnd,y,16,OP_Y,avg2)
  235. DEFFUNC(put,no_rnd,y,16,OP_Y,avg2)
  236. DEFFUNC(put,   rnd,xy,16,OP_XY,PACK)
  237. DEFFUNC(put,no_rnd,xy,16,OP_XY,PACK)
  238. #undef OP
  239. #define OP avg
  240. DEFFUNC(avg,   rnd,o,8,OP_C,avg2)
  241. DEFFUNC(avg,   rnd,x,8,OP_X,avg2)
  242. DEFFUNC(avg,no_rnd,x,8,OP_X,avg2)
  243. DEFFUNC(avg,   rnd,y,8,OP_Y,avg2)
  244. DEFFUNC(avg,no_rnd,y,8,OP_Y,avg2)
  245. DEFFUNC(avg,   rnd,xy,8,OP_XY,PACK)
  246. DEFFUNC(avg,no_rnd,xy,8,OP_XY,PACK)
  247. DEFFUNC(avg,   rnd,o,16,OP_C,avg2)
  248. DEFFUNC(avg,   rnd,x,16,OP_X,avg2)
  249. DEFFUNC(avg,no_rnd,x,16,OP_X,avg2)
  250. DEFFUNC(avg,   rnd,y,16,OP_Y,avg2)
  251. DEFFUNC(avg,no_rnd,y,16,OP_Y,avg2)
  252. DEFFUNC(avg,   rnd,xy,16,OP_XY,PACK)
  253. DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
  254. #undef OP
  255. #define put_no_rnd_pixels8_o put_rnd_pixels8_o
  256. #define put_no_rnd_pixels16_o put_rnd_pixels16_o
  257. #define avg_no_rnd_pixels8_o avg_rnd_pixels8_o
  258. #define avg_no_rnd_pixels16_o avg_rnd_pixels16_o
  259. #define put_pixels8_c put_rnd_pixels8_o
  260. #define put_pixels16_c put_rnd_pixels16_o
  261. #define avg_pixels8_c avg_rnd_pixels8_o
  262. #define avg_pixels16_c avg_rnd_pixels16_o
  263. #define put_no_rnd_pixels8_c put_rnd_pixels8_o
  264. #define put_no_rnd_pixels16_c put_rnd_pixels16_o
  265. #define avg_no_rnd_pixels8_c avg_rnd_pixels8_o
  266. #define avg_no_rnd_pixels16_c avg_rnd_pixels16_o
  267. #define QPEL
  268. #ifdef QPEL
  269. #include "qpel.c"
  270. #endif
  271. void dsputil_init_align(DSPContext* c, AVCodecContext *avctx)
  272. {
  273. c->put_pixels_tab[0][0] = put_rnd_pixels16_o;
  274. c->put_pixels_tab[0][1] = put_rnd_pixels16_x;
  275. c->put_pixels_tab[0][2] = put_rnd_pixels16_y;
  276. c->put_pixels_tab[0][3] = put_rnd_pixels16_xy;
  277. c->put_pixels_tab[1][0] = put_rnd_pixels8_o;
  278. c->put_pixels_tab[1][1] = put_rnd_pixels8_x;
  279. c->put_pixels_tab[1][2] = put_rnd_pixels8_y;
  280. c->put_pixels_tab[1][3] = put_rnd_pixels8_xy;
  281. c->put_no_rnd_pixels_tab[0][0] = put_no_rnd_pixels16_o;
  282. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x;
  283. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y;
  284. c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy;
  285. c->put_no_rnd_pixels_tab[1][0] = put_no_rnd_pixels8_o;
  286. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x;
  287. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y;
  288. c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy;
  289. c->avg_pixels_tab[0][0] = avg_rnd_pixels16_o;
  290. c->avg_pixels_tab[0][1] = avg_rnd_pixels16_x;
  291. c->avg_pixels_tab[0][2] = avg_rnd_pixels16_y;
  292. c->avg_pixels_tab[0][3] = avg_rnd_pixels16_xy;
  293. c->avg_pixels_tab[1][0] = avg_rnd_pixels8_o;
  294. c->avg_pixels_tab[1][1] = avg_rnd_pixels8_x;
  295. c->avg_pixels_tab[1][2] = avg_rnd_pixels8_y;
  296. c->avg_pixels_tab[1][3] = avg_rnd_pixels8_xy;
  297. c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_o;
  298. c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x;
  299. c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y;
  300. c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy;
  301. c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_o;
  302. c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x;
  303. c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y;
  304. c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy;
  305. #ifdef QPEL
  306. #define dspfunc(PFX, IDX, NUM) 
  307.     c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; 
  308.     c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; 
  309.     c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; 
  310.     c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; 
  311.     c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; 
  312.     c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; 
  313.     c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; 
  314.     c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; 
  315.     c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; 
  316.     c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; 
  317.     c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; 
  318.     c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; 
  319.     c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; 
  320.     c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; 
  321.     c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; 
  322.     c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  323.     dspfunc(put_qpel, 0, 16);
  324.     dspfunc(put_no_rnd_qpel, 0, 16);
  325.     dspfunc(avg_qpel, 0, 16);
  326.     /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  327.     dspfunc(put_qpel, 1, 8);
  328.     dspfunc(put_no_rnd_qpel, 1, 8);
  329.     dspfunc(avg_qpel, 1, 8);
  330.     /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  331.     dspfunc(put_h264_qpel, 0, 16);
  332.     dspfunc(put_h264_qpel, 1, 8);
  333.     dspfunc(put_h264_qpel, 2, 4);
  334.     dspfunc(avg_h264_qpel, 0, 16);
  335.     dspfunc(avg_h264_qpel, 1, 8);
  336.     dspfunc(avg_h264_qpel, 2, 4);
  337. #undef dspfunc
  338.     c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
  339.     c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
  340.     c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
  341.     c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
  342.     c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
  343.     c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
  344.     c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  345.     c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  346.     c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  347.     c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  348.     c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  349.     c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  350.     c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  351.     c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  352.     c->gmc1 = gmc1_c;
  353.     c->gmc = gmc_c;
  354. #endif
  355. }