dsputil_mlib.c 11 KB

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