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.

463 lines
11KB

  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_algebra.h>
  25. #include <mlib_video.h>
  26. /* misc */
  27. static void get_pixels_mlib(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
  28. {
  29. int i;
  30. for (i=0;i<8;i++) {
  31. mlib_VectorConvert_S16_U8_Mod((mlib_s16 *)block, (mlib_u8 *)pixels, 8);
  32. pixels += line_size;
  33. block += 8;
  34. }
  35. }
  36. static void diff_pixels_mlib(DCTELEM *restrict block, const uint8_t *s1, const uint8_t *s2, int line_size)
  37. {
  38. int i;
  39. for (i=0;i<8;i++) {
  40. mlib_VectorSub_S16_U8_Mod((mlib_s16 *)block, (mlib_u8 *)s1, (mlib_u8 *)s2, 8);
  41. s1 += line_size;
  42. s2 += line_size;
  43. block += 8;
  44. }
  45. }
  46. static void add_pixels_clamped_mlib(const DCTELEM *block, uint8_t *pixels, int line_size)
  47. {
  48. mlib_VideoAddBlock_U8_S16(pixels, (mlib_s16 *)block, line_size);
  49. }
  50. /* put block, width 16 pixel, height 8/16 */
  51. static void put_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
  52. int stride, int height)
  53. {
  54. switch (height) {
  55. case 8:
  56. mlib_VideoCopyRef_U8_U8_16x8(dest, (uint8_t *)ref, stride);
  57. break;
  58. case 16:
  59. mlib_VideoCopyRef_U8_U8_16x16(dest, (uint8_t *)ref, stride);
  60. break;
  61. default:
  62. assert(0);
  63. }
  64. }
  65. static void put_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
  66. int stride, int height)
  67. {
  68. switch (height) {
  69. case 8:
  70. mlib_VideoInterpX_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
  71. break;
  72. case 16:
  73. mlib_VideoInterpX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  74. break;
  75. default:
  76. assert(0);
  77. }
  78. }
  79. static void put_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
  80. int stride, int height)
  81. {
  82. switch (height) {
  83. case 8:
  84. mlib_VideoInterpY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
  85. break;
  86. case 16:
  87. mlib_VideoInterpY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  88. break;
  89. default:
  90. assert(0);
  91. }
  92. }
  93. static void put_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
  94. int stride, int height)
  95. {
  96. switch (height) {
  97. case 8:
  98. mlib_VideoInterpXY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
  99. break;
  100. case 16:
  101. mlib_VideoInterpXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  102. break;
  103. default:
  104. assert(0);
  105. }
  106. }
  107. /* put block, width 8 pixel, height 4/8/16 */
  108. static void put_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
  109. int stride, int height)
  110. {
  111. switch (height) {
  112. case 4:
  113. mlib_VideoCopyRef_U8_U8_8x4(dest, (uint8_t *)ref, stride);
  114. break;
  115. case 8:
  116. mlib_VideoCopyRef_U8_U8_8x8(dest, (uint8_t *)ref, stride);
  117. break;
  118. case 16:
  119. mlib_VideoCopyRef_U8_U8_8x16(dest, (uint8_t *)ref, stride);
  120. break;
  121. default:
  122. assert(0);
  123. }
  124. }
  125. static void put_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
  126. int stride, int height)
  127. {
  128. switch (height) {
  129. case 4:
  130. mlib_VideoInterpX_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
  131. break;
  132. case 8:
  133. mlib_VideoInterpX_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
  134. break;
  135. case 16:
  136. mlib_VideoInterpX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  137. break;
  138. default:
  139. assert(0);
  140. }
  141. }
  142. static void put_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
  143. int stride, int height)
  144. {
  145. switch (height) {
  146. case 4:
  147. mlib_VideoInterpY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
  148. break;
  149. case 8:
  150. mlib_VideoInterpY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
  151. break;
  152. case 16:
  153. mlib_VideoInterpY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  154. break;
  155. default:
  156. assert(0);
  157. }
  158. }
  159. static void put_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
  160. int stride, int height)
  161. {
  162. switch (height) {
  163. case 4:
  164. mlib_VideoInterpXY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
  165. break;
  166. case 8:
  167. mlib_VideoInterpXY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
  168. break;
  169. case 16:
  170. mlib_VideoInterpXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  171. break;
  172. default:
  173. assert(0);
  174. }
  175. }
  176. /* average block, width 16 pixel, height 8/16 */
  177. static void avg_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
  178. int stride, int height)
  179. {
  180. switch (height) {
  181. case 8:
  182. mlib_VideoCopyRefAve_U8_U8_16x8(dest, (uint8_t *)ref, stride);
  183. break;
  184. case 16:
  185. mlib_VideoCopyRefAve_U8_U8_16x16(dest, (uint8_t *)ref, stride);
  186. break;
  187. default:
  188. assert(0);
  189. }
  190. }
  191. static void avg_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
  192. int stride, int height)
  193. {
  194. switch (height) {
  195. case 8:
  196. mlib_VideoInterpAveX_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
  197. break;
  198. case 16:
  199. mlib_VideoInterpAveX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  200. break;
  201. default:
  202. assert(0);
  203. }
  204. }
  205. static void avg_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
  206. int stride, int height)
  207. {
  208. switch (height) {
  209. case 8:
  210. mlib_VideoInterpAveY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
  211. break;
  212. case 16:
  213. mlib_VideoInterpAveY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  214. break;
  215. default:
  216. assert(0);
  217. }
  218. }
  219. static void avg_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
  220. int stride, int height)
  221. {
  222. switch (height) {
  223. case 8:
  224. mlib_VideoInterpAveXY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
  225. break;
  226. case 16:
  227. mlib_VideoInterpAveXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
  228. break;
  229. default:
  230. assert(0);
  231. }
  232. }
  233. /* average block, width 8 pixel, height 4/8/16 */
  234. static void avg_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
  235. int stride, int height)
  236. {
  237. switch (height) {
  238. case 4:
  239. mlib_VideoCopyRefAve_U8_U8_8x4(dest, (uint8_t *)ref, stride);
  240. break;
  241. case 8:
  242. mlib_VideoCopyRefAve_U8_U8_8x8(dest, (uint8_t *)ref, stride);
  243. break;
  244. case 16:
  245. mlib_VideoCopyRefAve_U8_U8_8x16(dest, (uint8_t *)ref, stride);
  246. break;
  247. default:
  248. assert(0);
  249. }
  250. }
  251. static void avg_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
  252. int stride, int height)
  253. {
  254. switch (height) {
  255. case 4:
  256. mlib_VideoInterpAveX_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
  257. break;
  258. case 8:
  259. mlib_VideoInterpAveX_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
  260. break;
  261. case 16:
  262. mlib_VideoInterpAveX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  263. break;
  264. default:
  265. assert(0);
  266. }
  267. }
  268. static void avg_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
  269. int stride, int height)
  270. {
  271. switch (height) {
  272. case 4:
  273. mlib_VideoInterpAveY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
  274. break;
  275. case 8:
  276. mlib_VideoInterpAveY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
  277. break;
  278. case 16:
  279. mlib_VideoInterpAveY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  280. break;
  281. default:
  282. assert(0);
  283. }
  284. }
  285. static void avg_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
  286. int stride, int height)
  287. {
  288. switch (height) {
  289. case 4:
  290. mlib_VideoInterpAveXY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
  291. break;
  292. case 8:
  293. mlib_VideoInterpAveXY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
  294. break;
  295. case 16:
  296. mlib_VideoInterpAveXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
  297. break;
  298. default:
  299. assert(0);
  300. }
  301. }
  302. /* swap byte order of a buffer */
  303. static void bswap_buf_mlib(uint32_t *dst, uint32_t *src, int w)
  304. {
  305. mlib_VectorReverseByteOrder_U32_U32(dst, src, w);
  306. }
  307. /* transformations */
  308. static void ff_idct_put_mlib(uint8_t *dest, int line_size, DCTELEM *data)
  309. {
  310. int i;
  311. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  312. mlib_VideoIDCT8x8_S16_S16 (data, data);
  313. for(i=0;i<8;i++) {
  314. dest[0] = cm[data[0]];
  315. dest[1] = cm[data[1]];
  316. dest[2] = cm[data[2]];
  317. dest[3] = cm[data[3]];
  318. dest[4] = cm[data[4]];
  319. dest[5] = cm[data[5]];
  320. dest[6] = cm[data[6]];
  321. dest[7] = cm[data[7]];
  322. dest += line_size;
  323. data += 8;
  324. }
  325. }
  326. static void ff_idct_add_mlib(uint8_t *dest, int line_size, DCTELEM *data)
  327. {
  328. mlib_VideoIDCT8x8_S16_S16 (data, data);
  329. mlib_VideoAddBlock_U8_S16(dest, (mlib_s16 *)data, line_size);
  330. }
  331. static void ff_idct_mlib(DCTELEM *data)
  332. {
  333. mlib_VideoIDCT8x8_S16_S16 (data, data);
  334. }
  335. static void ff_fdct_mlib(DCTELEM *data)
  336. {
  337. mlib_VideoDCT8x8_S16_S16 (data, data);
  338. }
  339. void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx)
  340. {
  341. c->get_pixels = get_pixels_mlib;
  342. c->diff_pixels = diff_pixels_mlib;
  343. c->add_pixels_clamped = add_pixels_clamped_mlib;
  344. c->put_pixels_tab[0][0] = put_pixels16_mlib;
  345. c->put_pixels_tab[0][1] = put_pixels16_x2_mlib;
  346. c->put_pixels_tab[0][2] = put_pixels16_y2_mlib;
  347. c->put_pixels_tab[0][3] = put_pixels16_xy2_mlib;
  348. c->put_pixels_tab[1][0] = put_pixels8_mlib;
  349. c->put_pixels_tab[1][1] = put_pixels8_x2_mlib;
  350. c->put_pixels_tab[1][2] = put_pixels8_y2_mlib;
  351. c->put_pixels_tab[1][3] = put_pixels8_xy2_mlib;
  352. c->avg_pixels_tab[0][0] = avg_pixels16_mlib;
  353. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mlib;
  354. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mlib;
  355. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mlib;
  356. c->avg_pixels_tab[1][0] = avg_pixels8_mlib;
  357. c->avg_pixels_tab[1][1] = avg_pixels8_x2_mlib;
  358. c->avg_pixels_tab[1][2] = avg_pixels8_y2_mlib;
  359. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mlib;
  360. c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mlib;
  361. c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mlib;
  362. c->bswap_buf = bswap_buf_mlib;
  363. }
  364. void MPV_common_init_mlib(MpegEncContext *s)
  365. {
  366. if(s->avctx->dct_algo==FF_DCT_AUTO || s->avctx->dct_algo==FF_DCT_MLIB){
  367. s->dsp.fdct = ff_fdct_mlib;
  368. }
  369. if(s->avctx->idct_algo==FF_IDCT_AUTO || s->avctx->idct_algo==FF_IDCT_MLIB){
  370. s->dsp.idct_put= ff_idct_put_mlib;
  371. s->dsp.idct_add= ff_idct_add_mlib;
  372. s->dsp.idct = ff_idct_mlib;
  373. s->dsp.idct_permutation_type= FF_NO_IDCT_PERM;
  374. }
  375. }