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.

270 lines
8.3KB

  1. /*
  2. * Sun mediaLib optimized DSP utils
  3. * Copyright (c) 2001 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "../dsputil.h"
  20. #include "../mpegvideo.h"
  21. #include <mlib_types.h>
  22. #include <mlib_status.h>
  23. #include <mlib_sys.h>
  24. #include <mlib_video.h>
  25. /* copy block, width 16 pixel, height 8/16 */
  26. static void put_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
  27. int stride, int height)
  28. {
  29. assert(height == 16 || height == 8);
  30. if (height == 16)
  31. mlib_VideoCopyRef_U8_U8_16x16(dest, (uint8_t *)ref, stride);
  32. else
  33. mlib_VideoCopyRef_U8_U8_16x8 (dest, (uint8_t *)ref, stride);
  34. }
  35. static void put_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
  36. int stride, int height)
  37. {
  38. assert(height == 16 || height == 8);
  39. if (height == 16)
  40. mlib_VideoInterpX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  41. else
  42. mlib_VideoInterpX_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
  43. }
  44. static void put_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
  45. int stride, int height)
  46. {
  47. assert(height == 16 || height == 8);
  48. if (height == 16)
  49. mlib_VideoInterpY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  50. else
  51. mlib_VideoInterpY_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
  52. }
  53. static void put_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
  54. int stride, int height)
  55. {
  56. assert(height == 16 || height == 8);
  57. if (height == 16)
  58. mlib_VideoInterpXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  59. else
  60. mlib_VideoInterpXY_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
  61. }
  62. /* copy block, width 8 pixel, height 8/16 */
  63. static void put_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
  64. int stride, int height)
  65. {
  66. assert(height == 16 || height == 8);
  67. if (height == 16)
  68. mlib_VideoCopyRef_U8_U8_8x16(dest, (uint8_t *)ref, stride);
  69. else
  70. mlib_VideoCopyRef_U8_U8_8x8 (dest, (uint8_t *)ref, stride);
  71. }
  72. static void put_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
  73. int stride, int height)
  74. {
  75. assert(height == 16 || height == 8);
  76. if (height == 16)
  77. mlib_VideoInterpX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  78. else
  79. mlib_VideoInterpX_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
  80. }
  81. static void put_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
  82. int stride, int height)
  83. {
  84. assert(height == 16 || height == 8);
  85. if (height == 16)
  86. mlib_VideoInterpY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  87. else
  88. mlib_VideoInterpY_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
  89. }
  90. static void put_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
  91. int stride, int height)
  92. {
  93. assert(height == 16 || height == 8);
  94. if (height == 16)
  95. mlib_VideoInterpXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  96. else
  97. mlib_VideoInterpXY_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
  98. }
  99. /* average/merge dest+source block, width 16 pixel, height 8/16 */
  100. static void avg_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
  101. int stride, int height)
  102. {
  103. assert(height == 16 || height == 8);
  104. if (height == 16)
  105. mlib_VideoCopyRefAve_U8_U8_16x16(dest, (uint8_t *)ref, stride);
  106. else
  107. mlib_VideoCopyRefAve_U8_U8_16x8 (dest, (uint8_t *)ref, stride);
  108. }
  109. static void avg_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
  110. int stride, int height)
  111. {
  112. assert(height == 16 || height == 8);
  113. if (height == 16)
  114. mlib_VideoInterpAveX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  115. else
  116. mlib_VideoInterpAveX_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
  117. }
  118. static void avg_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
  119. int stride, int height)
  120. {
  121. assert(height == 16 || height == 8);
  122. if (height == 16)
  123. mlib_VideoInterpAveY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  124. else
  125. mlib_VideoInterpAveY_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
  126. }
  127. static void avg_pixels16_xy2_mlib (uint8_t * dest, const uint8_t * ref,
  128. int stride, int height)
  129. {
  130. assert(height == 16 || height == 8);
  131. if (height == 16)
  132. mlib_VideoInterpAveXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  133. else
  134. mlib_VideoInterpAveXY_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
  135. }
  136. /* average/merge dest+source block, width 8 pixel, height 8/16 */
  137. static void avg_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
  138. int stride, int height)
  139. {
  140. assert(height == 16 || height == 8);
  141. if (height == 16)
  142. mlib_VideoCopyRefAve_U8_U8_8x16(dest, (uint8_t *)ref, stride);
  143. else
  144. mlib_VideoCopyRefAve_U8_U8_8x8 (dest, (uint8_t *)ref, stride);
  145. }
  146. static void avg_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
  147. int stride, int height)
  148. {
  149. assert(height == 16 || height == 8);
  150. if (height == 16)
  151. mlib_VideoInterpAveX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  152. else
  153. mlib_VideoInterpAveX_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
  154. }
  155. static void avg_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
  156. int stride, int height)
  157. {
  158. assert(height == 16 || height == 8);
  159. if (height == 16)
  160. mlib_VideoInterpAveY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  161. else
  162. mlib_VideoInterpAveY_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
  163. }
  164. static void avg_pixels8_xy2_mlib (uint8_t * dest, const uint8_t * ref,
  165. int stride, int height)
  166. {
  167. assert(height == 16 || height == 8);
  168. if (height == 16)
  169. mlib_VideoInterpAveXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  170. else
  171. mlib_VideoInterpAveXY_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
  172. }
  173. static void (*put_pixels_clamped)(const DCTELEM *block, UINT8 *pixels, int line_size);
  174. static void add_pixels_clamped_mlib(const DCTELEM *block, UINT8 *pixels, int line_size)
  175. {
  176. mlib_VideoAddBlock_U8_S16(pixels, (mlib_s16 *)block, line_size);
  177. }
  178. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  179. converted */
  180. static void ff_idct_put_mlib(UINT8 *dest, int line_size, DCTELEM *data)
  181. {
  182. mlib_VideoIDCT8x8_S16_S16 (data, data);
  183. put_pixels_clamped(data, dest, line_size);
  184. }
  185. static void ff_idct_add_mlib(UINT8 *dest, int line_size, DCTELEM *data)
  186. {
  187. mlib_VideoIDCT8x8_S16_S16 (data, data);
  188. mlib_VideoAddBlock_U8_S16(dest, (mlib_s16 *)data, line_size);
  189. }
  190. static void ff_fdct_mlib(DCTELEM *data)
  191. {
  192. mlib_VideoDCT8x8_S16_S16 (data, data);
  193. }
  194. void dsputil_init_mlib(DSPContext* c, unsigned mask)
  195. {
  196. c->put_pixels_tab[0][0] = put_pixels16_mlib;
  197. c->put_pixels_tab[0][1] = put_pixels16_x2_mlib;
  198. c->put_pixels_tab[0][2] = put_pixels16_y2_mlib;
  199. c->put_pixels_tab[0][3] = put_pixels16_xy2_mlib;
  200. c->put_pixels_tab[1][0] = put_pixels8_mlib;
  201. c->put_pixels_tab[1][1] = put_pixels8_x2_mlib;
  202. c->put_pixels_tab[1][2] = put_pixels8_y2_mlib;
  203. c->put_pixels_tab[1][3] = put_pixels8_xy2_mlib;
  204. c->avg_pixels_tab[0][0] = avg_pixels16_mlib;
  205. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mlib;
  206. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mlib;
  207. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mlib;
  208. c->avg_pixels_tab[1][0] = avg_pixels8_mlib;
  209. c->avg_pixels_tab[1][1] = avg_pixels8_x2_mlib;
  210. c->avg_pixels_tab[1][2] = avg_pixels8_y2_mlib;
  211. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mlib;
  212. c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mlib;
  213. c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mlib;
  214. c->add_pixels_clamped = add_pixels_clamped_mlib;
  215. put_pixels_clamped = c->put_pixels_clamped;
  216. }
  217. void MPV_common_init_mlib(MpegEncContext *s)
  218. {
  219. int i;
  220. if(s->avctx->dct_algo==FF_DCT_AUTO || s->avctx->dct_algo==FF_DCT_MLIB){
  221. s->fdct = ff_fdct_mlib;
  222. }
  223. if(s->avctx->idct_algo==FF_IDCT_AUTO || s->avctx->idct_algo==FF_IDCT_MLIB){
  224. s->idct_put= ff_idct_put_mlib;
  225. s->idct_add= ff_idct_add_mlib;
  226. s->idct_permutation_type= FF_NO_IDCT_PERM;
  227. }
  228. }