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.

258 lines
9.7KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  7. *
  8. * This file is part of Libav.
  9. *
  10. * Libav is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * Libav is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with Libav; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /**
  25. * @file
  26. * DSP utils
  27. */
  28. #include "bit_depth_template.c"
  29. #if BIT_DEPTH == 8
  30. /* draw the edges of width 'w' of an image of size width, height */
  31. //FIXME check that this is ok for mpeg4 interlaced
  32. static void FUNCC(draw_edges)(uint8_t *_buf, int _wrap, int width, int height, int w, int h, int sides)
  33. {
  34. pixel *buf = (pixel*)_buf;
  35. int wrap = _wrap / sizeof(pixel);
  36. pixel *ptr, *last_line;
  37. int i;
  38. /* left and right */
  39. ptr = buf;
  40. for(i=0;i<height;i++) {
  41. memset(ptr - w, ptr[0], w);
  42. memset(ptr + width, ptr[width-1], w);
  43. ptr += wrap;
  44. }
  45. /* top and bottom + corners */
  46. buf -= w;
  47. last_line = buf + (height - 1) * wrap;
  48. if (sides & EDGE_TOP)
  49. for(i = 0; i < h; i++)
  50. memcpy(buf - (i + 1) * wrap, buf, (width + w + w) * sizeof(pixel)); // top
  51. if (sides & EDGE_BOTTOM)
  52. for (i = 0; i < h; i++)
  53. memcpy(last_line + (i + 1) * wrap, last_line, (width + w + w) * sizeof(pixel)); // bottom
  54. }
  55. #endif
  56. static void FUNCC(get_pixels)(int16_t *restrict block,
  57. const uint8_t *_pixels,
  58. int line_size)
  59. {
  60. const pixel *pixels = (const pixel *) _pixels;
  61. int i;
  62. /* read the pixels */
  63. for(i=0;i<8;i++) {
  64. block[0] = pixels[0];
  65. block[1] = pixels[1];
  66. block[2] = pixels[2];
  67. block[3] = pixels[3];
  68. block[4] = pixels[4];
  69. block[5] = pixels[5];
  70. block[6] = pixels[6];
  71. block[7] = pixels[7];
  72. pixels += line_size / sizeof(pixel);
  73. block += 8;
  74. }
  75. }
  76. #if BIT_DEPTH == 8
  77. static void FUNCC(clear_block)(int16_t *block)
  78. {
  79. memset(block, 0, sizeof(int16_t)*64);
  80. }
  81. static void FUNCC(clear_blocks)(int16_t *blocks)
  82. {
  83. memset(blocks, 0, sizeof(int16_t)*6*64);
  84. }
  85. #endif
  86. #if BIT_DEPTH == 8
  87. #include "hpel_template.c"
  88. #endif
  89. #define PIXOP2(OPNAME, OP) \
  90. static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  91. int src_stride1, int src_stride2, int h){\
  92. int i;\
  93. for(i=0; i<h; i++){\
  94. pixel4 a,b;\
  95. a= AV_RN4P(&src1[i*src_stride1 ]);\
  96. b= AV_RN4P(&src2[i*src_stride2 ]);\
  97. OP(*((pixel4*)&dst[i*dst_stride ]), no_rnd_avg_pixel4(a, b));\
  98. a= AV_RN4P(&src1[i*src_stride1+4*sizeof(pixel)]);\
  99. b= AV_RN4P(&src2[i*src_stride2+4*sizeof(pixel)]);\
  100. OP(*((pixel4*)&dst[i*dst_stride+4*sizeof(pixel)]), no_rnd_avg_pixel4(a, b));\
  101. }\
  102. }\
  103. \
  104. static inline void FUNC(OPNAME ## _no_rnd_pixels16_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  105. int src_stride1, int src_stride2, int h){\
  106. FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  107. FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, h);\
  108. }\
  109. \
  110. static inline void FUNC(OPNAME ## _pixels8_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
  111. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  112. /* FIXME HIGH BIT DEPTH */\
  113. int i;\
  114. for(i=0; i<h; i++){\
  115. uint32_t a, b, c, d, l0, l1, h0, h1;\
  116. a= AV_RN32(&src1[i*src_stride1]);\
  117. b= AV_RN32(&src2[i*src_stride2]);\
  118. c= AV_RN32(&src3[i*src_stride3]);\
  119. d= AV_RN32(&src4[i*src_stride4]);\
  120. l0= (a&0x03030303UL)\
  121. + (b&0x03030303UL)\
  122. + 0x02020202UL;\
  123. h0= ((a&0xFCFCFCFCUL)>>2)\
  124. + ((b&0xFCFCFCFCUL)>>2);\
  125. l1= (c&0x03030303UL)\
  126. + (d&0x03030303UL);\
  127. h1= ((c&0xFCFCFCFCUL)>>2)\
  128. + ((d&0xFCFCFCFCUL)>>2);\
  129. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  130. a= AV_RN32(&src1[i*src_stride1+4]);\
  131. b= AV_RN32(&src2[i*src_stride2+4]);\
  132. c= AV_RN32(&src3[i*src_stride3+4]);\
  133. d= AV_RN32(&src4[i*src_stride4+4]);\
  134. l0= (a&0x03030303UL)\
  135. + (b&0x03030303UL)\
  136. + 0x02020202UL;\
  137. h0= ((a&0xFCFCFCFCUL)>>2)\
  138. + ((b&0xFCFCFCFCUL)>>2);\
  139. l1= (c&0x03030303UL)\
  140. + (d&0x03030303UL);\
  141. h1= ((c&0xFCFCFCFCUL)>>2)\
  142. + ((d&0xFCFCFCFCUL)>>2);\
  143. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  144. }\
  145. }\
  146. \
  147. static inline void FUNC(OPNAME ## _no_rnd_pixels8_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
  148. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  149. /* FIXME HIGH BIT DEPTH*/\
  150. int i;\
  151. for(i=0; i<h; i++){\
  152. uint32_t a, b, c, d, l0, l1, h0, h1;\
  153. a= AV_RN32(&src1[i*src_stride1]);\
  154. b= AV_RN32(&src2[i*src_stride2]);\
  155. c= AV_RN32(&src3[i*src_stride3]);\
  156. d= AV_RN32(&src4[i*src_stride4]);\
  157. l0= (a&0x03030303UL)\
  158. + (b&0x03030303UL)\
  159. + 0x01010101UL;\
  160. h0= ((a&0xFCFCFCFCUL)>>2)\
  161. + ((b&0xFCFCFCFCUL)>>2);\
  162. l1= (c&0x03030303UL)\
  163. + (d&0x03030303UL);\
  164. h1= ((c&0xFCFCFCFCUL)>>2)\
  165. + ((d&0xFCFCFCFCUL)>>2);\
  166. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  167. a= AV_RN32(&src1[i*src_stride1+4]);\
  168. b= AV_RN32(&src2[i*src_stride2+4]);\
  169. c= AV_RN32(&src3[i*src_stride3+4]);\
  170. d= AV_RN32(&src4[i*src_stride4+4]);\
  171. l0= (a&0x03030303UL)\
  172. + (b&0x03030303UL)\
  173. + 0x01010101UL;\
  174. h0= ((a&0xFCFCFCFCUL)>>2)\
  175. + ((b&0xFCFCFCFCUL)>>2);\
  176. l1= (c&0x03030303UL)\
  177. + (d&0x03030303UL);\
  178. h1= ((c&0xFCFCFCFCUL)>>2)\
  179. + ((d&0xFCFCFCFCUL)>>2);\
  180. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  181. }\
  182. }\
  183. static inline void FUNC(OPNAME ## _pixels16_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
  184. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  185. FUNC(OPNAME ## _pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  186. FUNC(OPNAME ## _pixels8_l4)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), src3+8*sizeof(pixel), src4+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  187. }\
  188. static inline void FUNC(OPNAME ## _no_rnd_pixels16_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
  189. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  190. FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  191. FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), src3+8*sizeof(pixel), src4+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  192. }\
  193. \
  194. static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\
  195. {\
  196. /* FIXME HIGH BIT DEPTH */\
  197. int j;\
  198. for(j=0; j<2; j++){\
  199. int i;\
  200. const uint32_t a= AV_RN32(pixels );\
  201. const uint32_t b= AV_RN32(pixels+1);\
  202. uint32_t l0= (a&0x03030303UL)\
  203. + (b&0x03030303UL)\
  204. + 0x02020202UL;\
  205. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  206. + ((b&0xFCFCFCFCUL)>>2);\
  207. uint32_t l1,h1;\
  208. \
  209. pixels+=line_size;\
  210. for(i=0; i<h; i+=2){\
  211. uint32_t a= AV_RN32(pixels );\
  212. uint32_t b= AV_RN32(pixels+1);\
  213. l1= (a&0x03030303UL)\
  214. + (b&0x03030303UL);\
  215. h1= ((a&0xFCFCFCFCUL)>>2)\
  216. + ((b&0xFCFCFCFCUL)>>2);\
  217. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  218. pixels+=line_size;\
  219. block +=line_size;\
  220. a= AV_RN32(pixels );\
  221. b= AV_RN32(pixels+1);\
  222. l0= (a&0x03030303UL)\
  223. + (b&0x03030303UL)\
  224. + 0x02020202UL;\
  225. h0= ((a&0xFCFCFCFCUL)>>2)\
  226. + ((b&0xFCFCFCFCUL)>>2);\
  227. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  228. pixels+=line_size;\
  229. block +=line_size;\
  230. }\
  231. pixels+=4-line_size*(h+1);\
  232. block +=4-line_size*h;\
  233. }\
  234. }\
  235. \
  236. CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\
  237. #define op_avg(a, b) a = rnd_avg_pixel4(a, b)
  238. #define op_put(a, b) a = b
  239. #if BIT_DEPTH == 8
  240. #define put_no_rnd_pixels8_8_c put_pixels8_8_c
  241. PIXOP2(avg, op_avg)
  242. PIXOP2(put, op_put)
  243. #endif
  244. #undef op_avg
  245. #undef op_put