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.

261 lines
9.8KB

  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 FFmpeg.
  9. *
  10. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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 *p_buf, int p_wrap, int width, int height, int w, int h, int sides)
  33. {
  34. pixel *buf = (pixel*)p_buf;
  35. int wrap = p_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 *av_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. /**
  82. * memset(blocks, 0, sizeof(int16_t)*6*64)
  83. */
  84. static void FUNCC(clear_blocks)(int16_t *blocks)
  85. {
  86. memset(blocks, 0, sizeof(int16_t)*6*64);
  87. }
  88. #endif
  89. #if BIT_DEPTH == 8
  90. #include "hpel_template.c"
  91. #endif
  92. #define PIXOP2(OPNAME, OP) \
  93. static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  94. int src_stride1, int src_stride2, int h){\
  95. int i;\
  96. for(i=0; i<h; i++){\
  97. pixel4 a,b;\
  98. a= AV_RN4P(&src1[i*src_stride1 ]);\
  99. b= AV_RN4P(&src2[i*src_stride2 ]);\
  100. OP(*((pixel4*)&dst[i*dst_stride ]), no_rnd_avg_pixel4(a, b));\
  101. a= AV_RN4P(&src1[i*src_stride1+4*sizeof(pixel)]);\
  102. b= AV_RN4P(&src2[i*src_stride2+4*sizeof(pixel)]);\
  103. OP(*((pixel4*)&dst[i*dst_stride+4*sizeof(pixel)]), no_rnd_avg_pixel4(a, b));\
  104. }\
  105. }\
  106. \
  107. static inline void FUNC(OPNAME ## _no_rnd_pixels16_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  108. int src_stride1, int src_stride2, int h){\
  109. FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  110. 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);\
  111. }\
  112. \
  113. 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,\
  114. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  115. /* FIXME HIGH BIT DEPTH */\
  116. int i;\
  117. for(i=0; i<h; i++){\
  118. uint32_t a, b, c, d, l0, l1, h0, h1;\
  119. a= AV_RN32(&src1[i*src_stride1]);\
  120. b= AV_RN32(&src2[i*src_stride2]);\
  121. c= AV_RN32(&src3[i*src_stride3]);\
  122. d= AV_RN32(&src4[i*src_stride4]);\
  123. l0= (a&0x03030303UL)\
  124. + (b&0x03030303UL)\
  125. + 0x02020202UL;\
  126. h0= ((a&0xFCFCFCFCUL)>>2)\
  127. + ((b&0xFCFCFCFCUL)>>2);\
  128. l1= (c&0x03030303UL)\
  129. + (d&0x03030303UL);\
  130. h1= ((c&0xFCFCFCFCUL)>>2)\
  131. + ((d&0xFCFCFCFCUL)>>2);\
  132. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  133. a= AV_RN32(&src1[i*src_stride1+4]);\
  134. b= AV_RN32(&src2[i*src_stride2+4]);\
  135. c= AV_RN32(&src3[i*src_stride3+4]);\
  136. d= AV_RN32(&src4[i*src_stride4+4]);\
  137. l0= (a&0x03030303UL)\
  138. + (b&0x03030303UL)\
  139. + 0x02020202UL;\
  140. h0= ((a&0xFCFCFCFCUL)>>2)\
  141. + ((b&0xFCFCFCFCUL)>>2);\
  142. l1= (c&0x03030303UL)\
  143. + (d&0x03030303UL);\
  144. h1= ((c&0xFCFCFCFCUL)>>2)\
  145. + ((d&0xFCFCFCFCUL)>>2);\
  146. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  147. }\
  148. }\
  149. \
  150. 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,\
  151. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  152. /* FIXME HIGH BIT DEPTH*/\
  153. int i;\
  154. for(i=0; i<h; i++){\
  155. uint32_t a, b, c, d, l0, l1, h0, h1;\
  156. a= AV_RN32(&src1[i*src_stride1]);\
  157. b= AV_RN32(&src2[i*src_stride2]);\
  158. c= AV_RN32(&src3[i*src_stride3]);\
  159. d= AV_RN32(&src4[i*src_stride4]);\
  160. l0= (a&0x03030303UL)\
  161. + (b&0x03030303UL)\
  162. + 0x01010101UL;\
  163. h0= ((a&0xFCFCFCFCUL)>>2)\
  164. + ((b&0xFCFCFCFCUL)>>2);\
  165. l1= (c&0x03030303UL)\
  166. + (d&0x03030303UL);\
  167. h1= ((c&0xFCFCFCFCUL)>>2)\
  168. + ((d&0xFCFCFCFCUL)>>2);\
  169. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  170. a= AV_RN32(&src1[i*src_stride1+4]);\
  171. b= AV_RN32(&src2[i*src_stride2+4]);\
  172. c= AV_RN32(&src3[i*src_stride3+4]);\
  173. d= AV_RN32(&src4[i*src_stride4+4]);\
  174. l0= (a&0x03030303UL)\
  175. + (b&0x03030303UL)\
  176. + 0x01010101UL;\
  177. h0= ((a&0xFCFCFCFCUL)>>2)\
  178. + ((b&0xFCFCFCFCUL)>>2);\
  179. l1= (c&0x03030303UL)\
  180. + (d&0x03030303UL);\
  181. h1= ((c&0xFCFCFCFCUL)>>2)\
  182. + ((d&0xFCFCFCFCUL)>>2);\
  183. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  184. }\
  185. }\
  186. 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,\
  187. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  188. FUNC(OPNAME ## _pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  189. 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);\
  190. }\
  191. 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,\
  192. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  193. FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  194. 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);\
  195. }\
  196. \
  197. static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\
  198. {\
  199. /* FIXME HIGH BIT DEPTH */\
  200. int j;\
  201. for(j=0; j<2; j++){\
  202. int i;\
  203. const uint32_t a= AV_RN32(pixels );\
  204. const uint32_t b= AV_RN32(pixels+1);\
  205. uint32_t l0= (a&0x03030303UL)\
  206. + (b&0x03030303UL)\
  207. + 0x02020202UL;\
  208. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  209. + ((b&0xFCFCFCFCUL)>>2);\
  210. uint32_t l1,h1;\
  211. \
  212. pixels+=line_size;\
  213. for(i=0; i<h; i+=2){\
  214. uint32_t a= AV_RN32(pixels );\
  215. uint32_t b= AV_RN32(pixels+1);\
  216. l1= (a&0x03030303UL)\
  217. + (b&0x03030303UL);\
  218. h1= ((a&0xFCFCFCFCUL)>>2)\
  219. + ((b&0xFCFCFCFCUL)>>2);\
  220. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  221. pixels+=line_size;\
  222. block +=line_size;\
  223. a= AV_RN32(pixels );\
  224. b= AV_RN32(pixels+1);\
  225. l0= (a&0x03030303UL)\
  226. + (b&0x03030303UL)\
  227. + 0x02020202UL;\
  228. h0= ((a&0xFCFCFCFCUL)>>2)\
  229. + ((b&0xFCFCFCFCUL)>>2);\
  230. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  231. pixels+=line_size;\
  232. block +=line_size;\
  233. }\
  234. pixels+=4-line_size*(h+1);\
  235. block +=4-line_size*h;\
  236. }\
  237. }\
  238. \
  239. CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\
  240. #define op_avg(a, b) a = rnd_avg_pixel4(a, b)
  241. #define op_put(a, b) a = b
  242. #if BIT_DEPTH == 8
  243. #define put_no_rnd_pixels8_8_c put_pixels8_8_c
  244. PIXOP2(avg, op_avg)
  245. PIXOP2(put, op_put)
  246. #endif
  247. #undef op_avg
  248. #undef op_put