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.

1217 lines
40KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * DSP utils
  25. */
  26. #include "libavutil/attributes.h"
  27. #include "libavutil/imgutils.h"
  28. #include "libavutil/internal.h"
  29. #include "avcodec.h"
  30. #include "copy_block.h"
  31. #include "dct.h"
  32. #include "dsputil.h"
  33. #include "simple_idct.h"
  34. #include "faandct.h"
  35. #include "imgconvert.h"
  36. #include "mathops.h"
  37. #include "mpegvideo.h"
  38. #include "config.h"
  39. uint32_t ff_square_tab[512] = { 0, };
  40. #define BIT_DEPTH 16
  41. #include "dsputilenc_template.c"
  42. #undef BIT_DEPTH
  43. #define BIT_DEPTH 8
  44. #include "dsputilenc_template.c"
  45. static int pix_sum_c(uint8_t *pix, int line_size)
  46. {
  47. int s = 0, i, j;
  48. for (i = 0; i < 16; i++) {
  49. for (j = 0; j < 16; j += 8) {
  50. s += pix[0];
  51. s += pix[1];
  52. s += pix[2];
  53. s += pix[3];
  54. s += pix[4];
  55. s += pix[5];
  56. s += pix[6];
  57. s += pix[7];
  58. pix += 8;
  59. }
  60. pix += line_size - 16;
  61. }
  62. return s;
  63. }
  64. static int pix_norm1_c(uint8_t *pix, int line_size)
  65. {
  66. int s = 0, i, j;
  67. uint32_t *sq = ff_square_tab + 256;
  68. for (i = 0; i < 16; i++) {
  69. for (j = 0; j < 16; j += 8) {
  70. #if 0
  71. s += sq[pix[0]];
  72. s += sq[pix[1]];
  73. s += sq[pix[2]];
  74. s += sq[pix[3]];
  75. s += sq[pix[4]];
  76. s += sq[pix[5]];
  77. s += sq[pix[6]];
  78. s += sq[pix[7]];
  79. #else
  80. #if HAVE_FAST_64BIT
  81. register uint64_t x = *(uint64_t *) pix;
  82. s += sq[x & 0xff];
  83. s += sq[(x >> 8) & 0xff];
  84. s += sq[(x >> 16) & 0xff];
  85. s += sq[(x >> 24) & 0xff];
  86. s += sq[(x >> 32) & 0xff];
  87. s += sq[(x >> 40) & 0xff];
  88. s += sq[(x >> 48) & 0xff];
  89. s += sq[(x >> 56) & 0xff];
  90. #else
  91. register uint32_t x = *(uint32_t *) pix;
  92. s += sq[x & 0xff];
  93. s += sq[(x >> 8) & 0xff];
  94. s += sq[(x >> 16) & 0xff];
  95. s += sq[(x >> 24) & 0xff];
  96. x = *(uint32_t *) (pix + 4);
  97. s += sq[x & 0xff];
  98. s += sq[(x >> 8) & 0xff];
  99. s += sq[(x >> 16) & 0xff];
  100. s += sq[(x >> 24) & 0xff];
  101. #endif
  102. #endif
  103. pix += 8;
  104. }
  105. pix += line_size - 16;
  106. }
  107. return s;
  108. }
  109. static int sse4_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  110. int line_size, int h)
  111. {
  112. int s = 0, i;
  113. uint32_t *sq = ff_square_tab + 256;
  114. for (i = 0; i < h; i++) {
  115. s += sq[pix1[0] - pix2[0]];
  116. s += sq[pix1[1] - pix2[1]];
  117. s += sq[pix1[2] - pix2[2]];
  118. s += sq[pix1[3] - pix2[3]];
  119. pix1 += line_size;
  120. pix2 += line_size;
  121. }
  122. return s;
  123. }
  124. static int sse8_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  125. int line_size, int h)
  126. {
  127. int s = 0, i;
  128. uint32_t *sq = ff_square_tab + 256;
  129. for (i = 0; i < h; i++) {
  130. s += sq[pix1[0] - pix2[0]];
  131. s += sq[pix1[1] - pix2[1]];
  132. s += sq[pix1[2] - pix2[2]];
  133. s += sq[pix1[3] - pix2[3]];
  134. s += sq[pix1[4] - pix2[4]];
  135. s += sq[pix1[5] - pix2[5]];
  136. s += sq[pix1[6] - pix2[6]];
  137. s += sq[pix1[7] - pix2[7]];
  138. pix1 += line_size;
  139. pix2 += line_size;
  140. }
  141. return s;
  142. }
  143. static int sse16_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  144. int line_size, int h)
  145. {
  146. int s = 0, i;
  147. uint32_t *sq = ff_square_tab + 256;
  148. for (i = 0; i < h; i++) {
  149. s += sq[pix1[0] - pix2[0]];
  150. s += sq[pix1[1] - pix2[1]];
  151. s += sq[pix1[2] - pix2[2]];
  152. s += sq[pix1[3] - pix2[3]];
  153. s += sq[pix1[4] - pix2[4]];
  154. s += sq[pix1[5] - pix2[5]];
  155. s += sq[pix1[6] - pix2[6]];
  156. s += sq[pix1[7] - pix2[7]];
  157. s += sq[pix1[8] - pix2[8]];
  158. s += sq[pix1[9] - pix2[9]];
  159. s += sq[pix1[10] - pix2[10]];
  160. s += sq[pix1[11] - pix2[11]];
  161. s += sq[pix1[12] - pix2[12]];
  162. s += sq[pix1[13] - pix2[13]];
  163. s += sq[pix1[14] - pix2[14]];
  164. s += sq[pix1[15] - pix2[15]];
  165. pix1 += line_size;
  166. pix2 += line_size;
  167. }
  168. return s;
  169. }
  170. static void diff_pixels_c(int16_t *av_restrict block, const uint8_t *s1,
  171. const uint8_t *s2, int stride)
  172. {
  173. int i;
  174. /* read the pixels */
  175. for (i = 0; i < 8; i++) {
  176. block[0] = s1[0] - s2[0];
  177. block[1] = s1[1] - s2[1];
  178. block[2] = s1[2] - s2[2];
  179. block[3] = s1[3] - s2[3];
  180. block[4] = s1[4] - s2[4];
  181. block[5] = s1[5] - s2[5];
  182. block[6] = s1[6] - s2[6];
  183. block[7] = s1[7] - s2[7];
  184. s1 += stride;
  185. s2 += stride;
  186. block += 8;
  187. }
  188. }
  189. static int sum_abs_dctelem_c(int16_t *block)
  190. {
  191. int sum = 0, i;
  192. for (i = 0; i < 64; i++)
  193. sum += FFABS(block[i]);
  194. return sum;
  195. }
  196. #define avg2(a, b) ((a + b + 1) >> 1)
  197. #define avg4(a, b, c, d) ((a + b + c + d + 2) >> 2)
  198. static inline int pix_abs16_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  199. int line_size, int h)
  200. {
  201. int s = 0, i;
  202. for (i = 0; i < h; i++) {
  203. s += abs(pix1[0] - pix2[0]);
  204. s += abs(pix1[1] - pix2[1]);
  205. s += abs(pix1[2] - pix2[2]);
  206. s += abs(pix1[3] - pix2[3]);
  207. s += abs(pix1[4] - pix2[4]);
  208. s += abs(pix1[5] - pix2[5]);
  209. s += abs(pix1[6] - pix2[6]);
  210. s += abs(pix1[7] - pix2[7]);
  211. s += abs(pix1[8] - pix2[8]);
  212. s += abs(pix1[9] - pix2[9]);
  213. s += abs(pix1[10] - pix2[10]);
  214. s += abs(pix1[11] - pix2[11]);
  215. s += abs(pix1[12] - pix2[12]);
  216. s += abs(pix1[13] - pix2[13]);
  217. s += abs(pix1[14] - pix2[14]);
  218. s += abs(pix1[15] - pix2[15]);
  219. pix1 += line_size;
  220. pix2 += line_size;
  221. }
  222. return s;
  223. }
  224. static int pix_abs16_x2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  225. int line_size, int h)
  226. {
  227. int s = 0, i;
  228. for (i = 0; i < h; i++) {
  229. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  230. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  231. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  232. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  233. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  234. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  235. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  236. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  237. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  238. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  239. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  240. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  241. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  242. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  243. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  244. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  245. pix1 += line_size;
  246. pix2 += line_size;
  247. }
  248. return s;
  249. }
  250. static int pix_abs16_y2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  251. int line_size, int h)
  252. {
  253. int s = 0, i;
  254. uint8_t *pix3 = pix2 + line_size;
  255. for (i = 0; i < h; i++) {
  256. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  257. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  258. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  259. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  260. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  261. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  262. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  263. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  264. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  265. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  266. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  267. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  268. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  269. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  270. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  271. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  272. pix1 += line_size;
  273. pix2 += line_size;
  274. pix3 += line_size;
  275. }
  276. return s;
  277. }
  278. static int pix_abs16_xy2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  279. int line_size, int h)
  280. {
  281. int s = 0, i;
  282. uint8_t *pix3 = pix2 + line_size;
  283. for (i = 0; i < h; i++) {
  284. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  285. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  286. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  287. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  288. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  289. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  290. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  291. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  292. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  293. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  294. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  295. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  296. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  297. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  298. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  299. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  300. pix1 += line_size;
  301. pix2 += line_size;
  302. pix3 += line_size;
  303. }
  304. return s;
  305. }
  306. static inline int pix_abs8_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  307. int line_size, int h)
  308. {
  309. int s = 0, i;
  310. for (i = 0; i < h; i++) {
  311. s += abs(pix1[0] - pix2[0]);
  312. s += abs(pix1[1] - pix2[1]);
  313. s += abs(pix1[2] - pix2[2]);
  314. s += abs(pix1[3] - pix2[3]);
  315. s += abs(pix1[4] - pix2[4]);
  316. s += abs(pix1[5] - pix2[5]);
  317. s += abs(pix1[6] - pix2[6]);
  318. s += abs(pix1[7] - pix2[7]);
  319. pix1 += line_size;
  320. pix2 += line_size;
  321. }
  322. return s;
  323. }
  324. static int pix_abs8_x2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  325. int line_size, int h)
  326. {
  327. int s = 0, i;
  328. for (i = 0; i < h; i++) {
  329. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  330. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  331. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  332. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  333. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  334. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  335. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  336. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  337. pix1 += line_size;
  338. pix2 += line_size;
  339. }
  340. return s;
  341. }
  342. static int pix_abs8_y2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  343. int line_size, int h)
  344. {
  345. int s = 0, i;
  346. uint8_t *pix3 = pix2 + line_size;
  347. for (i = 0; i < h; i++) {
  348. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  349. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  350. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  351. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  352. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  353. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  354. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  355. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  356. pix1 += line_size;
  357. pix2 += line_size;
  358. pix3 += line_size;
  359. }
  360. return s;
  361. }
  362. static int pix_abs8_xy2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  363. int line_size, int h)
  364. {
  365. int s = 0, i;
  366. uint8_t *pix3 = pix2 + line_size;
  367. for (i = 0; i < h; i++) {
  368. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  369. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  370. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  371. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  372. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  373. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  374. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  375. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  376. pix1 += line_size;
  377. pix2 += line_size;
  378. pix3 += line_size;
  379. }
  380. return s;
  381. }
  382. static int nsse16_c(MpegEncContext *c, uint8_t *s1, uint8_t *s2, int stride, int h)
  383. {
  384. int score1 = 0, score2 = 0, x, y;
  385. for (y = 0; y < h; y++) {
  386. for (x = 0; x < 16; x++)
  387. score1 += (s1[x] - s2[x]) * (s1[x] - s2[x]);
  388. if (y + 1 < h) {
  389. for (x = 0; x < 15; x++)
  390. score2 += FFABS(s1[x] - s1[x + stride] -
  391. s1[x + 1] + s1[x + stride + 1]) -
  392. FFABS(s2[x] - s2[x + stride] -
  393. s2[x + 1] + s2[x + stride + 1]);
  394. }
  395. s1 += stride;
  396. s2 += stride;
  397. }
  398. if (c)
  399. return score1 + FFABS(score2) * c->avctx->nsse_weight;
  400. else
  401. return score1 + FFABS(score2) * 8;
  402. }
  403. static int nsse8_c(MpegEncContext *c, uint8_t *s1, uint8_t *s2, int stride, int h)
  404. {
  405. int score1 = 0, score2 = 0, x, y;
  406. for (y = 0; y < h; y++) {
  407. for (x = 0; x < 8; x++)
  408. score1 += (s1[x] - s2[x]) * (s1[x] - s2[x]);
  409. if (y + 1 < h) {
  410. for (x = 0; x < 7; x++)
  411. score2 += FFABS(s1[x] - s1[x + stride] -
  412. s1[x + 1] + s1[x + stride + 1]) -
  413. FFABS(s2[x] - s2[x + stride] -
  414. s2[x + 1] + s2[x + stride + 1]);
  415. }
  416. s1 += stride;
  417. s2 += stride;
  418. }
  419. if (c)
  420. return score1 + FFABS(score2) * c->avctx->nsse_weight;
  421. else
  422. return score1 + FFABS(score2) * 8;
  423. }
  424. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64],
  425. int16_t basis[64], int scale)
  426. {
  427. int i;
  428. unsigned int sum = 0;
  429. for (i = 0; i < 8 * 8; i++) {
  430. int b = rem[i] + ((basis[i] * scale +
  431. (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
  432. (BASIS_SHIFT - RECON_SHIFT));
  433. int w = weight[i];
  434. b >>= RECON_SHIFT;
  435. av_assert2(-512 < b && b < 512);
  436. sum += (w * b) * (w * b) >> 4;
  437. }
  438. return sum >> 2;
  439. }
  440. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale)
  441. {
  442. int i;
  443. for (i = 0; i < 8 * 8; i++)
  444. rem[i] += (basis[i] * scale +
  445. (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
  446. (BASIS_SHIFT - RECON_SHIFT);
  447. }
  448. static int zero_cmp(MpegEncContext *s, uint8_t *a, uint8_t *b,
  449. int stride, int h)
  450. {
  451. return 0;
  452. }
  453. void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type)
  454. {
  455. int i;
  456. memset(cmp, 0, sizeof(void *) * 6);
  457. for (i = 0; i < 6; i++) {
  458. switch (type & 0xFF) {
  459. case FF_CMP_SAD:
  460. cmp[i] = c->sad[i];
  461. break;
  462. case FF_CMP_SATD:
  463. cmp[i] = c->hadamard8_diff[i];
  464. break;
  465. case FF_CMP_SSE:
  466. cmp[i] = c->sse[i];
  467. break;
  468. case FF_CMP_DCT:
  469. cmp[i] = c->dct_sad[i];
  470. break;
  471. case FF_CMP_DCT264:
  472. cmp[i] = c->dct264_sad[i];
  473. break;
  474. case FF_CMP_DCTMAX:
  475. cmp[i] = c->dct_max[i];
  476. break;
  477. case FF_CMP_PSNR:
  478. cmp[i] = c->quant_psnr[i];
  479. break;
  480. case FF_CMP_BIT:
  481. cmp[i] = c->bit[i];
  482. break;
  483. case FF_CMP_RD:
  484. cmp[i] = c->rd[i];
  485. break;
  486. case FF_CMP_VSAD:
  487. cmp[i] = c->vsad[i];
  488. break;
  489. case FF_CMP_VSSE:
  490. cmp[i] = c->vsse[i];
  491. break;
  492. case FF_CMP_ZERO:
  493. cmp[i] = zero_cmp;
  494. break;
  495. case FF_CMP_NSSE:
  496. cmp[i] = c->nsse[i];
  497. break;
  498. #if CONFIG_DWT
  499. case FF_CMP_W53:
  500. cmp[i]= c->w53[i];
  501. break;
  502. case FF_CMP_W97:
  503. cmp[i]= c->w97[i];
  504. break;
  505. #endif
  506. default:
  507. av_log(NULL, AV_LOG_ERROR,
  508. "internal error in cmp function selection\n");
  509. }
  510. }
  511. }
  512. #define BUTTERFLY2(o1, o2, i1, i2) \
  513. o1 = (i1) + (i2); \
  514. o2 = (i1) - (i2);
  515. #define BUTTERFLY1(x, y) \
  516. { \
  517. int a, b; \
  518. a = x; \
  519. b = y; \
  520. x = a + b; \
  521. y = a - b; \
  522. }
  523. #define BUTTERFLYA(x, y) (FFABS((x) + (y)) + FFABS((x) - (y)))
  524. static int hadamard8_diff8x8_c(MpegEncContext *s, uint8_t *dst,
  525. uint8_t *src, int stride, int h)
  526. {
  527. int i, temp[64], sum = 0;
  528. av_assert2(h == 8);
  529. for (i = 0; i < 8; i++) {
  530. // FIXME: try pointer walks
  531. BUTTERFLY2(temp[8 * i + 0], temp[8 * i + 1],
  532. src[stride * i + 0] - dst[stride * i + 0],
  533. src[stride * i + 1] - dst[stride * i + 1]);
  534. BUTTERFLY2(temp[8 * i + 2], temp[8 * i + 3],
  535. src[stride * i + 2] - dst[stride * i + 2],
  536. src[stride * i + 3] - dst[stride * i + 3]);
  537. BUTTERFLY2(temp[8 * i + 4], temp[8 * i + 5],
  538. src[stride * i + 4] - dst[stride * i + 4],
  539. src[stride * i + 5] - dst[stride * i + 5]);
  540. BUTTERFLY2(temp[8 * i + 6], temp[8 * i + 7],
  541. src[stride * i + 6] - dst[stride * i + 6],
  542. src[stride * i + 7] - dst[stride * i + 7]);
  543. BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 2]);
  544. BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 3]);
  545. BUTTERFLY1(temp[8 * i + 4], temp[8 * i + 6]);
  546. BUTTERFLY1(temp[8 * i + 5], temp[8 * i + 7]);
  547. BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 4]);
  548. BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 5]);
  549. BUTTERFLY1(temp[8 * i + 2], temp[8 * i + 6]);
  550. BUTTERFLY1(temp[8 * i + 3], temp[8 * i + 7]);
  551. }
  552. for (i = 0; i < 8; i++) {
  553. BUTTERFLY1(temp[8 * 0 + i], temp[8 * 1 + i]);
  554. BUTTERFLY1(temp[8 * 2 + i], temp[8 * 3 + i]);
  555. BUTTERFLY1(temp[8 * 4 + i], temp[8 * 5 + i]);
  556. BUTTERFLY1(temp[8 * 6 + i], temp[8 * 7 + i]);
  557. BUTTERFLY1(temp[8 * 0 + i], temp[8 * 2 + i]);
  558. BUTTERFLY1(temp[8 * 1 + i], temp[8 * 3 + i]);
  559. BUTTERFLY1(temp[8 * 4 + i], temp[8 * 6 + i]);
  560. BUTTERFLY1(temp[8 * 5 + i], temp[8 * 7 + i]);
  561. sum += BUTTERFLYA(temp[8 * 0 + i], temp[8 * 4 + i]) +
  562. BUTTERFLYA(temp[8 * 1 + i], temp[8 * 5 + i]) +
  563. BUTTERFLYA(temp[8 * 2 + i], temp[8 * 6 + i]) +
  564. BUTTERFLYA(temp[8 * 3 + i], temp[8 * 7 + i]);
  565. }
  566. return sum;
  567. }
  568. static int hadamard8_intra8x8_c(MpegEncContext *s, uint8_t *src,
  569. uint8_t *dummy, int stride, int h)
  570. {
  571. int i, temp[64], sum = 0;
  572. av_assert2(h == 8);
  573. for (i = 0; i < 8; i++) {
  574. // FIXME: try pointer walks
  575. BUTTERFLY2(temp[8 * i + 0], temp[8 * i + 1],
  576. src[stride * i + 0], src[stride * i + 1]);
  577. BUTTERFLY2(temp[8 * i + 2], temp[8 * i + 3],
  578. src[stride * i + 2], src[stride * i + 3]);
  579. BUTTERFLY2(temp[8 * i + 4], temp[8 * i + 5],
  580. src[stride * i + 4], src[stride * i + 5]);
  581. BUTTERFLY2(temp[8 * i + 6], temp[8 * i + 7],
  582. src[stride * i + 6], src[stride * i + 7]);
  583. BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 2]);
  584. BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 3]);
  585. BUTTERFLY1(temp[8 * i + 4], temp[8 * i + 6]);
  586. BUTTERFLY1(temp[8 * i + 5], temp[8 * i + 7]);
  587. BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 4]);
  588. BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 5]);
  589. BUTTERFLY1(temp[8 * i + 2], temp[8 * i + 6]);
  590. BUTTERFLY1(temp[8 * i + 3], temp[8 * i + 7]);
  591. }
  592. for (i = 0; i < 8; i++) {
  593. BUTTERFLY1(temp[8 * 0 + i], temp[8 * 1 + i]);
  594. BUTTERFLY1(temp[8 * 2 + i], temp[8 * 3 + i]);
  595. BUTTERFLY1(temp[8 * 4 + i], temp[8 * 5 + i]);
  596. BUTTERFLY1(temp[8 * 6 + i], temp[8 * 7 + i]);
  597. BUTTERFLY1(temp[8 * 0 + i], temp[8 * 2 + i]);
  598. BUTTERFLY1(temp[8 * 1 + i], temp[8 * 3 + i]);
  599. BUTTERFLY1(temp[8 * 4 + i], temp[8 * 6 + i]);
  600. BUTTERFLY1(temp[8 * 5 + i], temp[8 * 7 + i]);
  601. sum +=
  602. BUTTERFLYA(temp[8 * 0 + i], temp[8 * 4 + i])
  603. + BUTTERFLYA(temp[8 * 1 + i], temp[8 * 5 + i])
  604. + BUTTERFLYA(temp[8 * 2 + i], temp[8 * 6 + i])
  605. + BUTTERFLYA(temp[8 * 3 + i], temp[8 * 7 + i]);
  606. }
  607. sum -= FFABS(temp[8 * 0] + temp[8 * 4]); // -mean
  608. return sum;
  609. }
  610. static int dct_sad8x8_c(MpegEncContext *s, uint8_t *src1,
  611. uint8_t *src2, int stride, int h)
  612. {
  613. LOCAL_ALIGNED_16(int16_t, temp, [64]);
  614. av_assert2(h == 8);
  615. s->dsp.diff_pixels(temp, src1, src2, stride);
  616. s->dsp.fdct(temp);
  617. return s->dsp.sum_abs_dctelem(temp);
  618. }
  619. #if CONFIG_GPL
  620. #define DCT8_1D \
  621. { \
  622. const int s07 = SRC(0) + SRC(7); \
  623. const int s16 = SRC(1) + SRC(6); \
  624. const int s25 = SRC(2) + SRC(5); \
  625. const int s34 = SRC(3) + SRC(4); \
  626. const int a0 = s07 + s34; \
  627. const int a1 = s16 + s25; \
  628. const int a2 = s07 - s34; \
  629. const int a3 = s16 - s25; \
  630. const int d07 = SRC(0) - SRC(7); \
  631. const int d16 = SRC(1) - SRC(6); \
  632. const int d25 = SRC(2) - SRC(5); \
  633. const int d34 = SRC(3) - SRC(4); \
  634. const int a4 = d16 + d25 + (d07 + (d07 >> 1)); \
  635. const int a5 = d07 - d34 - (d25 + (d25 >> 1)); \
  636. const int a6 = d07 + d34 - (d16 + (d16 >> 1)); \
  637. const int a7 = d16 - d25 + (d34 + (d34 >> 1)); \
  638. DST(0, a0 + a1); \
  639. DST(1, a4 + (a7 >> 2)); \
  640. DST(2, a2 + (a3 >> 1)); \
  641. DST(3, a5 + (a6 >> 2)); \
  642. DST(4, a0 - a1); \
  643. DST(5, a6 - (a5 >> 2)); \
  644. DST(6, (a2 >> 1) - a3); \
  645. DST(7, (a4 >> 2) - a7); \
  646. }
  647. static int dct264_sad8x8_c(MpegEncContext *s, uint8_t *src1,
  648. uint8_t *src2, int stride, int h)
  649. {
  650. int16_t dct[8][8];
  651. int i, sum = 0;
  652. s->dsp.diff_pixels(dct[0], src1, src2, stride);
  653. #define SRC(x) dct[i][x]
  654. #define DST(x, v) dct[i][x] = v
  655. for (i = 0; i < 8; i++)
  656. DCT8_1D
  657. #undef SRC
  658. #undef DST
  659. #define SRC(x) dct[x][i]
  660. #define DST(x, v) sum += FFABS(v)
  661. for (i = 0; i < 8; i++)
  662. DCT8_1D
  663. #undef SRC
  664. #undef DST
  665. return sum;
  666. }
  667. #endif
  668. static int dct_max8x8_c(MpegEncContext *s, uint8_t *src1,
  669. uint8_t *src2, int stride, int h)
  670. {
  671. LOCAL_ALIGNED_16(int16_t, temp, [64]);
  672. int sum = 0, i;
  673. av_assert2(h == 8);
  674. s->dsp.diff_pixels(temp, src1, src2, stride);
  675. s->dsp.fdct(temp);
  676. for (i = 0; i < 64; i++)
  677. sum = FFMAX(sum, FFABS(temp[i]));
  678. return sum;
  679. }
  680. static int quant_psnr8x8_c(MpegEncContext *s, uint8_t *src1,
  681. uint8_t *src2, int stride, int h)
  682. {
  683. LOCAL_ALIGNED_16(int16_t, temp, [64 * 2]);
  684. int16_t *const bak = temp + 64;
  685. int sum = 0, i;
  686. av_assert2(h == 8);
  687. s->mb_intra = 0;
  688. s->dsp.diff_pixels(temp, src1, src2, stride);
  689. memcpy(bak, temp, 64 * sizeof(int16_t));
  690. s->block_last_index[0 /* FIXME */] =
  691. s->fast_dct_quantize(s, temp, 0 /* FIXME */, s->qscale, &i);
  692. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  693. ff_simple_idct_8(temp); // FIXME
  694. for (i = 0; i < 64; i++)
  695. sum += (temp[i] - bak[i]) * (temp[i] - bak[i]);
  696. return sum;
  697. }
  698. static int rd8x8_c(MpegEncContext *s, uint8_t *src1, uint8_t *src2,
  699. int stride, int h)
  700. {
  701. const uint8_t *scantable = s->intra_scantable.permutated;
  702. LOCAL_ALIGNED_16(int16_t, temp, [64]);
  703. LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]);
  704. LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]);
  705. int i, last, run, bits, level, distortion, start_i;
  706. const int esc_length = s->ac_esc_length;
  707. uint8_t *length, *last_length;
  708. av_assert2(h == 8);
  709. copy_block8(lsrc1, src1, 8, stride, 8);
  710. copy_block8(lsrc2, src2, 8, stride, 8);
  711. s->dsp.diff_pixels(temp, lsrc1, lsrc2, 8);
  712. s->block_last_index[0 /* FIXME */] =
  713. last =
  714. s->fast_dct_quantize(s, temp, 0 /* FIXME */, s->qscale, &i);
  715. bits = 0;
  716. if (s->mb_intra) {
  717. start_i = 1;
  718. length = s->intra_ac_vlc_length;
  719. last_length = s->intra_ac_vlc_last_length;
  720. bits += s->luma_dc_vlc_length[temp[0] + 256]; // FIXME: chroma
  721. } else {
  722. start_i = 0;
  723. length = s->inter_ac_vlc_length;
  724. last_length = s->inter_ac_vlc_last_length;
  725. }
  726. if (last >= start_i) {
  727. run = 0;
  728. for (i = start_i; i < last; i++) {
  729. int j = scantable[i];
  730. level = temp[j];
  731. if (level) {
  732. level += 64;
  733. if ((level & (~127)) == 0)
  734. bits += length[UNI_AC_ENC_INDEX(run, level)];
  735. else
  736. bits += esc_length;
  737. run = 0;
  738. } else
  739. run++;
  740. }
  741. i = scantable[last];
  742. level = temp[i] + 64;
  743. av_assert2(level - 64);
  744. if ((level & (~127)) == 0) {
  745. bits += last_length[UNI_AC_ENC_INDEX(run, level)];
  746. } else
  747. bits += esc_length;
  748. }
  749. if (last >= 0) {
  750. if (s->mb_intra)
  751. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  752. else
  753. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  754. }
  755. s->idsp.idct_add(lsrc2, 8, temp);
  756. distortion = s->dsp.sse[1](NULL, lsrc2, lsrc1, 8, 8);
  757. return distortion + ((bits * s->qscale * s->qscale * 109 + 64) >> 7);
  758. }
  759. static int bit8x8_c(MpegEncContext *s, uint8_t *src1, uint8_t *src2,
  760. int stride, int h)
  761. {
  762. const uint8_t *scantable = s->intra_scantable.permutated;
  763. LOCAL_ALIGNED_16(int16_t, temp, [64]);
  764. int i, last, run, bits, level, start_i;
  765. const int esc_length = s->ac_esc_length;
  766. uint8_t *length, *last_length;
  767. av_assert2(h == 8);
  768. s->dsp.diff_pixels(temp, src1, src2, stride);
  769. s->block_last_index[0 /* FIXME */] =
  770. last =
  771. s->fast_dct_quantize(s, temp, 0 /* FIXME */, s->qscale, &i);
  772. bits = 0;
  773. if (s->mb_intra) {
  774. start_i = 1;
  775. length = s->intra_ac_vlc_length;
  776. last_length = s->intra_ac_vlc_last_length;
  777. bits += s->luma_dc_vlc_length[temp[0] + 256]; // FIXME: chroma
  778. } else {
  779. start_i = 0;
  780. length = s->inter_ac_vlc_length;
  781. last_length = s->inter_ac_vlc_last_length;
  782. }
  783. if (last >= start_i) {
  784. run = 0;
  785. for (i = start_i; i < last; i++) {
  786. int j = scantable[i];
  787. level = temp[j];
  788. if (level) {
  789. level += 64;
  790. if ((level & (~127)) == 0)
  791. bits += length[UNI_AC_ENC_INDEX(run, level)];
  792. else
  793. bits += esc_length;
  794. run = 0;
  795. } else
  796. run++;
  797. }
  798. i = scantable[last];
  799. level = temp[i] + 64;
  800. av_assert2(level - 64);
  801. if ((level & (~127)) == 0)
  802. bits += last_length[UNI_AC_ENC_INDEX(run, level)];
  803. else
  804. bits += esc_length;
  805. }
  806. return bits;
  807. }
  808. #define VSAD_INTRA(size) \
  809. static int vsad_intra ## size ## _c(MpegEncContext *c, \
  810. uint8_t *s, uint8_t *dummy, \
  811. int stride, int h) \
  812. { \
  813. int score = 0, x, y; \
  814. \
  815. for (y = 1; y < h; y++) { \
  816. for (x = 0; x < size; x += 4) { \
  817. score += FFABS(s[x] - s[x + stride]) + \
  818. FFABS(s[x + 1] - s[x + stride + 1]) + \
  819. FFABS(s[x + 2] - s[x + 2 + stride]) + \
  820. FFABS(s[x + 3] - s[x + 3 + stride]); \
  821. } \
  822. s += stride; \
  823. } \
  824. \
  825. return score; \
  826. }
  827. VSAD_INTRA(8)
  828. VSAD_INTRA(16)
  829. #define VSAD(size) \
  830. static int vsad ## size ## _c(MpegEncContext *c, \
  831. uint8_t *s1, uint8_t *s2, \
  832. int stride, int h) \
  833. { \
  834. int score = 0, x, y; \
  835. \
  836. for (y = 1; y < h; y++) { \
  837. for (x = 0; x < size; x++) \
  838. score += FFABS(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \
  839. s1 += stride; \
  840. s2 += stride; \
  841. } \
  842. \
  843. return score; \
  844. }
  845. VSAD(8)
  846. VSAD(16)
  847. #define SQ(a) ((a) * (a))
  848. #define VSSE_INTRA(size) \
  849. static int vsse_intra ## size ## _c(MpegEncContext *c, \
  850. uint8_t *s, uint8_t *dummy, \
  851. int stride, int h) \
  852. { \
  853. int score = 0, x, y; \
  854. \
  855. for (y = 1; y < h; y++) { \
  856. for (x = 0; x < size; x += 4) { \
  857. score += SQ(s[x] - s[x + stride]) + \
  858. SQ(s[x + 1] - s[x + stride + 1]) + \
  859. SQ(s[x + 2] - s[x + stride + 2]) + \
  860. SQ(s[x + 3] - s[x + stride + 3]); \
  861. } \
  862. s += stride; \
  863. } \
  864. \
  865. return score; \
  866. }
  867. VSSE_INTRA(8)
  868. VSSE_INTRA(16)
  869. #define VSSE(size) \
  870. static int vsse ## size ## _c(MpegEncContext *c, uint8_t *s1, uint8_t *s2, \
  871. int stride, int h) \
  872. { \
  873. int score = 0, x, y; \
  874. \
  875. for (y = 1; y < h; y++) { \
  876. for (x = 0; x < size; x++) \
  877. score += SQ(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \
  878. s1 += stride; \
  879. s2 += stride; \
  880. } \
  881. \
  882. return score; \
  883. }
  884. VSSE(8)
  885. VSSE(16)
  886. #define WRAPPER8_16_SQ(name8, name16) \
  887. static int name16(MpegEncContext *s, uint8_t *dst, uint8_t *src, \
  888. int stride, int h) \
  889. { \
  890. int score = 0; \
  891. \
  892. score += name8(s, dst, src, stride, 8); \
  893. score += name8(s, dst + 8, src + 8, stride, 8); \
  894. if (h == 16) { \
  895. dst += 8 * stride; \
  896. src += 8 * stride; \
  897. score += name8(s, dst, src, stride, 8); \
  898. score += name8(s, dst + 8, src + 8, stride, 8); \
  899. } \
  900. return score; \
  901. }
  902. WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  903. WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  904. WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  905. #if CONFIG_GPL
  906. WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
  907. #endif
  908. WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
  909. WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  910. WRAPPER8_16_SQ(rd8x8_c, rd16_c)
  911. WRAPPER8_16_SQ(bit8x8_c, bit16_c)
  912. /* draw the edges of width 'w' of an image of size width, height */
  913. // FIXME: Check that this is OK for MPEG-4 interlaced.
  914. static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
  915. int w, int h, int sides)
  916. {
  917. uint8_t *ptr = buf, *last_line;
  918. int i;
  919. /* left and right */
  920. for (i = 0; i < height; i++) {
  921. memset(ptr - w, ptr[0], w);
  922. memset(ptr + width, ptr[width - 1], w);
  923. ptr += wrap;
  924. }
  925. /* top and bottom + corners */
  926. buf -= w;
  927. last_line = buf + (height - 1) * wrap;
  928. if (sides & EDGE_TOP)
  929. for (i = 0; i < h; i++)
  930. // top
  931. memcpy(buf - (i + 1) * wrap, buf, width + w + w);
  932. if (sides & EDGE_BOTTOM)
  933. for (i = 0; i < h; i++)
  934. // bottom
  935. memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
  936. }
  937. /* init static data */
  938. av_cold void ff_dsputil_static_init(void)
  939. {
  940. int i;
  941. for (i = 0; i < 512; i++)
  942. ff_square_tab[i] = (i - 256) * (i - 256);
  943. }
  944. int ff_check_alignment(void)
  945. {
  946. static int did_fail = 0;
  947. LOCAL_ALIGNED_16(int, aligned, [4]);
  948. if ((intptr_t)aligned & 15) {
  949. if (!did_fail) {
  950. #if HAVE_MMX || HAVE_ALTIVEC
  951. av_log(NULL, AV_LOG_ERROR,
  952. "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
  953. "and may be very slow or crash. This is not a bug in libavcodec,\n"
  954. "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
  955. "Do not report crashes to FFmpeg developers.\n");
  956. #endif
  957. did_fail=1;
  958. }
  959. return -1;
  960. }
  961. return 0;
  962. }
  963. av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
  964. {
  965. const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
  966. ff_check_alignment();
  967. #if CONFIG_ENCODERS
  968. if (avctx->bits_per_raw_sample == 10) {
  969. c->fdct = ff_jpeg_fdct_islow_10;
  970. c->fdct248 = ff_fdct248_islow_10;
  971. } else {
  972. if (avctx->dct_algo == FF_DCT_FASTINT) {
  973. c->fdct = ff_fdct_ifast;
  974. c->fdct248 = ff_fdct_ifast248;
  975. } else if (avctx->dct_algo == FF_DCT_FAAN) {
  976. c->fdct = ff_faandct;
  977. c->fdct248 = ff_faandct248;
  978. } else {
  979. c->fdct = ff_jpeg_fdct_islow_8; // slow/accurate/default
  980. c->fdct248 = ff_fdct248_islow_8;
  981. }
  982. }
  983. #endif /* CONFIG_ENCODERS */
  984. c->diff_pixels = diff_pixels_c;
  985. c->sum_abs_dctelem = sum_abs_dctelem_c;
  986. c->pix_sum = pix_sum_c;
  987. c->pix_norm1 = pix_norm1_c;
  988. /* TODO [0] 16 [1] 8 */
  989. c->pix_abs[0][0] = pix_abs16_c;
  990. c->pix_abs[0][1] = pix_abs16_x2_c;
  991. c->pix_abs[0][2] = pix_abs16_y2_c;
  992. c->pix_abs[0][3] = pix_abs16_xy2_c;
  993. c->pix_abs[1][0] = pix_abs8_c;
  994. c->pix_abs[1][1] = pix_abs8_x2_c;
  995. c->pix_abs[1][2] = pix_abs8_y2_c;
  996. c->pix_abs[1][3] = pix_abs8_xy2_c;
  997. #define SET_CMP_FUNC(name) \
  998. c->name[0] = name ## 16_c; \
  999. c->name[1] = name ## 8x8_c;
  1000. SET_CMP_FUNC(hadamard8_diff)
  1001. c->hadamard8_diff[4] = hadamard8_intra16_c;
  1002. c->hadamard8_diff[5] = hadamard8_intra8x8_c;
  1003. SET_CMP_FUNC(dct_sad)
  1004. SET_CMP_FUNC(dct_max)
  1005. #if CONFIG_GPL
  1006. SET_CMP_FUNC(dct264_sad)
  1007. #endif
  1008. c->sad[0] = pix_abs16_c;
  1009. c->sad[1] = pix_abs8_c;
  1010. c->sse[0] = sse16_c;
  1011. c->sse[1] = sse8_c;
  1012. c->sse[2] = sse4_c;
  1013. SET_CMP_FUNC(quant_psnr)
  1014. SET_CMP_FUNC(rd)
  1015. SET_CMP_FUNC(bit)
  1016. c->vsad[0] = vsad16_c;
  1017. c->vsad[1] = vsad8_c;
  1018. c->vsad[4] = vsad_intra16_c;
  1019. c->vsad[5] = vsad_intra8_c;
  1020. c->vsse[0] = vsse16_c;
  1021. c->vsse[1] = vsse8_c;
  1022. c->vsse[4] = vsse_intra16_c;
  1023. c->vsse[5] = vsse_intra8_c;
  1024. c->nsse[0] = nsse16_c;
  1025. c->nsse[1] = nsse8_c;
  1026. #if CONFIG_SNOW_DECODER || CONFIG_SNOW_ENCODER
  1027. ff_dsputil_init_dwt(c);
  1028. #endif
  1029. c->try_8x8basis = try_8x8basis_c;
  1030. c->add_8x8basis = add_8x8basis_c;
  1031. c->shrink[0] = av_image_copy_plane;
  1032. c->shrink[1] = ff_shrink22;
  1033. c->shrink[2] = ff_shrink44;
  1034. c->shrink[3] = ff_shrink88;
  1035. c->draw_edges = draw_edges_8_c;
  1036. switch (avctx->bits_per_raw_sample) {
  1037. case 9:
  1038. case 10:
  1039. case 12:
  1040. case 14:
  1041. c->get_pixels = get_pixels_16_c;
  1042. break;
  1043. default:
  1044. if (avctx->bits_per_raw_sample<=8 || avctx->codec_type != AVMEDIA_TYPE_VIDEO) {
  1045. c->get_pixels = get_pixels_8_c;
  1046. }
  1047. break;
  1048. }
  1049. if (ARCH_ALPHA)
  1050. ff_dsputil_init_alpha(c, avctx);
  1051. if (ARCH_ARM)
  1052. ff_dsputil_init_arm(c, avctx, high_bit_depth);
  1053. if (ARCH_PPC)
  1054. ff_dsputil_init_ppc(c, avctx, high_bit_depth);
  1055. if (ARCH_X86)
  1056. ff_dsputil_init_x86(c, avctx, high_bit_depth);
  1057. }
  1058. av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  1059. {
  1060. ff_dsputil_init(c, avctx);
  1061. }
  1062. av_cold void avpriv_dsputil_init(DSPContext *c, AVCodecContext *avctx)
  1063. {
  1064. ff_dsputil_init(c, avctx);
  1065. }