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.

257 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 = buf, *last_line;
  37. int i;
  38. /* left and right */
  39. for(i=0;i<height;i++) {
  40. memset(ptr - w, ptr[0], w);
  41. memset(ptr + width, ptr[width-1], w);
  42. ptr += wrap;
  43. }
  44. /* top and bottom + corners */
  45. buf -= w;
  46. last_line = buf + (height - 1) * wrap;
  47. if (sides & EDGE_TOP)
  48. for(i = 0; i < h; i++)
  49. memcpy(buf - (i + 1) * wrap, buf, (width + w + w) * sizeof(pixel)); // top
  50. if (sides & EDGE_BOTTOM)
  51. for (i = 0; i < h; i++)
  52. memcpy(last_line + (i + 1) * wrap, last_line, (width + w + w) * sizeof(pixel)); // bottom
  53. }
  54. #endif
  55. static void FUNCC(get_pixels)(int16_t *restrict block,
  56. const uint8_t *_pixels,
  57. int line_size)
  58. {
  59. const pixel *pixels = (const pixel *) _pixels;
  60. int i;
  61. /* read the pixels */
  62. for(i=0;i<8;i++) {
  63. block[0] = pixels[0];
  64. block[1] = pixels[1];
  65. block[2] = pixels[2];
  66. block[3] = pixels[3];
  67. block[4] = pixels[4];
  68. block[5] = pixels[5];
  69. block[6] = pixels[6];
  70. block[7] = pixels[7];
  71. pixels += line_size / sizeof(pixel);
  72. block += 8;
  73. }
  74. }
  75. #if BIT_DEPTH == 8
  76. static void FUNCC(clear_block)(int16_t *block)
  77. {
  78. memset(block, 0, sizeof(int16_t)*64);
  79. }
  80. static void FUNCC(clear_blocks)(int16_t *blocks)
  81. {
  82. memset(blocks, 0, sizeof(int16_t)*6*64);
  83. }
  84. #endif
  85. #if BIT_DEPTH == 8
  86. #include "hpel_template.c"
  87. #endif
  88. #define PIXOP2(OPNAME, OP) \
  89. static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  90. int src_stride1, int src_stride2, int h){\
  91. int i;\
  92. for(i=0; i<h; i++){\
  93. pixel4 a,b;\
  94. a= AV_RN4P(&src1[i*src_stride1 ]);\
  95. b= AV_RN4P(&src2[i*src_stride2 ]);\
  96. OP(*((pixel4*)&dst[i*dst_stride ]), no_rnd_avg_pixel4(a, b));\
  97. a= AV_RN4P(&src1[i*src_stride1+4*sizeof(pixel)]);\
  98. b= AV_RN4P(&src2[i*src_stride2+4*sizeof(pixel)]);\
  99. OP(*((pixel4*)&dst[i*dst_stride+4*sizeof(pixel)]), no_rnd_avg_pixel4(a, b));\
  100. }\
  101. }\
  102. \
  103. static inline void FUNC(OPNAME ## _no_rnd_pixels16_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  104. int src_stride1, int src_stride2, int h){\
  105. FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  106. 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);\
  107. }\
  108. \
  109. 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,\
  110. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  111. /* FIXME HIGH BIT DEPTH */\
  112. int i;\
  113. for(i=0; i<h; i++){\
  114. uint32_t a, b, c, d, l0, l1, h0, h1;\
  115. a= AV_RN32(&src1[i*src_stride1]);\
  116. b= AV_RN32(&src2[i*src_stride2]);\
  117. c= AV_RN32(&src3[i*src_stride3]);\
  118. d= AV_RN32(&src4[i*src_stride4]);\
  119. l0= (a&0x03030303UL)\
  120. + (b&0x03030303UL)\
  121. + 0x02020202UL;\
  122. h0= ((a&0xFCFCFCFCUL)>>2)\
  123. + ((b&0xFCFCFCFCUL)>>2);\
  124. l1= (c&0x03030303UL)\
  125. + (d&0x03030303UL);\
  126. h1= ((c&0xFCFCFCFCUL)>>2)\
  127. + ((d&0xFCFCFCFCUL)>>2);\
  128. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  129. a= AV_RN32(&src1[i*src_stride1+4]);\
  130. b= AV_RN32(&src2[i*src_stride2+4]);\
  131. c= AV_RN32(&src3[i*src_stride3+4]);\
  132. d= AV_RN32(&src4[i*src_stride4+4]);\
  133. l0= (a&0x03030303UL)\
  134. + (b&0x03030303UL)\
  135. + 0x02020202UL;\
  136. h0= ((a&0xFCFCFCFCUL)>>2)\
  137. + ((b&0xFCFCFCFCUL)>>2);\
  138. l1= (c&0x03030303UL)\
  139. + (d&0x03030303UL);\
  140. h1= ((c&0xFCFCFCFCUL)>>2)\
  141. + ((d&0xFCFCFCFCUL)>>2);\
  142. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  143. }\
  144. }\
  145. \
  146. 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,\
  147. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  148. /* FIXME HIGH BIT DEPTH*/\
  149. int i;\
  150. for(i=0; i<h; i++){\
  151. uint32_t a, b, c, d, l0, l1, h0, h1;\
  152. a= AV_RN32(&src1[i*src_stride1]);\
  153. b= AV_RN32(&src2[i*src_stride2]);\
  154. c= AV_RN32(&src3[i*src_stride3]);\
  155. d= AV_RN32(&src4[i*src_stride4]);\
  156. l0= (a&0x03030303UL)\
  157. + (b&0x03030303UL)\
  158. + 0x01010101UL;\
  159. h0= ((a&0xFCFCFCFCUL)>>2)\
  160. + ((b&0xFCFCFCFCUL)>>2);\
  161. l1= (c&0x03030303UL)\
  162. + (d&0x03030303UL);\
  163. h1= ((c&0xFCFCFCFCUL)>>2)\
  164. + ((d&0xFCFCFCFCUL)>>2);\
  165. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  166. a= AV_RN32(&src1[i*src_stride1+4]);\
  167. b= AV_RN32(&src2[i*src_stride2+4]);\
  168. c= AV_RN32(&src3[i*src_stride3+4]);\
  169. d= AV_RN32(&src4[i*src_stride4+4]);\
  170. l0= (a&0x03030303UL)\
  171. + (b&0x03030303UL)\
  172. + 0x01010101UL;\
  173. h0= ((a&0xFCFCFCFCUL)>>2)\
  174. + ((b&0xFCFCFCFCUL)>>2);\
  175. l1= (c&0x03030303UL)\
  176. + (d&0x03030303UL);\
  177. h1= ((c&0xFCFCFCFCUL)>>2)\
  178. + ((d&0xFCFCFCFCUL)>>2);\
  179. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  180. }\
  181. }\
  182. 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,\
  183. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  184. FUNC(OPNAME ## _pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  185. 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);\
  186. }\
  187. 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,\
  188. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  189. FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  190. 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);\
  191. }\
  192. \
  193. static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\
  194. {\
  195. /* FIXME HIGH BIT DEPTH */\
  196. int j;\
  197. for(j=0; j<2; j++){\
  198. int i;\
  199. const uint32_t a= AV_RN32(pixels );\
  200. const uint32_t b= AV_RN32(pixels+1);\
  201. uint32_t l0= (a&0x03030303UL)\
  202. + (b&0x03030303UL)\
  203. + 0x02020202UL;\
  204. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  205. + ((b&0xFCFCFCFCUL)>>2);\
  206. uint32_t l1,h1;\
  207. \
  208. pixels+=line_size;\
  209. for(i=0; i<h; i+=2){\
  210. uint32_t a= AV_RN32(pixels );\
  211. uint32_t b= AV_RN32(pixels+1);\
  212. l1= (a&0x03030303UL)\
  213. + (b&0x03030303UL);\
  214. h1= ((a&0xFCFCFCFCUL)>>2)\
  215. + ((b&0xFCFCFCFCUL)>>2);\
  216. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  217. pixels+=line_size;\
  218. block +=line_size;\
  219. a= AV_RN32(pixels );\
  220. b= AV_RN32(pixels+1);\
  221. l0= (a&0x03030303UL)\
  222. + (b&0x03030303UL)\
  223. + 0x02020202UL;\
  224. h0= ((a&0xFCFCFCFCUL)>>2)\
  225. + ((b&0xFCFCFCFCUL)>>2);\
  226. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  227. pixels+=line_size;\
  228. block +=line_size;\
  229. }\
  230. pixels+=4-line_size*(h+1);\
  231. block +=4-line_size*h;\
  232. }\
  233. }\
  234. \
  235. CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\
  236. #define op_avg(a, b) a = rnd_avg_pixel4(a, b)
  237. #define op_put(a, b) a = b
  238. #if BIT_DEPTH == 8
  239. #define put_no_rnd_pixels8_8_c put_pixels8_8_c
  240. PIXOP2(avg, op_avg)
  241. PIXOP2(put, op_put)
  242. #endif
  243. #undef op_avg
  244. #undef op_put