me_cmp.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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. #include "libavutil/attributes.h"
  23. #include "libavutil/internal.h"
  24. #include "avcodec.h"
  25. #include "copy_block.h"
  26. #include "simple_idct.h"
  27. #include "me_cmp.h"
  28. #include "mpegvideo.h"
  29. #include "config.h"
  30. /* (i - 256) * (i - 256) */
  31. const uint32_t ff_square_tab[512] = {
  32. 65536, 65025, 64516, 64009, 63504, 63001, 62500, 62001, 61504, 61009, 60516, 60025, 59536, 59049, 58564, 58081,
  33. 57600, 57121, 56644, 56169, 55696, 55225, 54756, 54289, 53824, 53361, 52900, 52441, 51984, 51529, 51076, 50625,
  34. 50176, 49729, 49284, 48841, 48400, 47961, 47524, 47089, 46656, 46225, 45796, 45369, 44944, 44521, 44100, 43681,
  35. 43264, 42849, 42436, 42025, 41616, 41209, 40804, 40401, 40000, 39601, 39204, 38809, 38416, 38025, 37636, 37249,
  36. 36864, 36481, 36100, 35721, 35344, 34969, 34596, 34225, 33856, 33489, 33124, 32761, 32400, 32041, 31684, 31329,
  37. 30976, 30625, 30276, 29929, 29584, 29241, 28900, 28561, 28224, 27889, 27556, 27225, 26896, 26569, 26244, 25921,
  38. 25600, 25281, 24964, 24649, 24336, 24025, 23716, 23409, 23104, 22801, 22500, 22201, 21904, 21609, 21316, 21025,
  39. 20736, 20449, 20164, 19881, 19600, 19321, 19044, 18769, 18496, 18225, 17956, 17689, 17424, 17161, 16900, 16641,
  40. 16384, 16129, 15876, 15625, 15376, 15129, 14884, 14641, 14400, 14161, 13924, 13689, 13456, 13225, 12996, 12769,
  41. 12544, 12321, 12100, 11881, 11664, 11449, 11236, 11025, 10816, 10609, 10404, 10201, 10000, 9801, 9604, 9409,
  42. 9216, 9025, 8836, 8649, 8464, 8281, 8100, 7921, 7744, 7569, 7396, 7225, 7056, 6889, 6724, 6561,
  43. 6400, 6241, 6084, 5929, 5776, 5625, 5476, 5329, 5184, 5041, 4900, 4761, 4624, 4489, 4356, 4225,
  44. 4096, 3969, 3844, 3721, 3600, 3481, 3364, 3249, 3136, 3025, 2916, 2809, 2704, 2601, 2500, 2401,
  45. 2304, 2209, 2116, 2025, 1936, 1849, 1764, 1681, 1600, 1521, 1444, 1369, 1296, 1225, 1156, 1089,
  46. 1024, 961, 900, 841, 784, 729, 676, 625, 576, 529, 484, 441, 400, 361, 324, 289,
  47. 256, 225, 196, 169, 144, 121, 100, 81, 64, 49, 36, 25, 16, 9, 4, 1,
  48. 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225,
  49. 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961,
  50. 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209,
  51. 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969,
  52. 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241,
  53. 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025,
  54. 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449, 11664, 11881, 12100, 12321,
  55. 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884, 15129, 15376, 15625, 15876, 16129,
  56. 16384, 16641, 16900, 17161, 17424, 17689, 17956, 18225, 18496, 18769, 19044, 19321, 19600, 19881, 20164, 20449,
  57. 20736, 21025, 21316, 21609, 21904, 22201, 22500, 22801, 23104, 23409, 23716, 24025, 24336, 24649, 24964, 25281,
  58. 25600, 25921, 26244, 26569, 26896, 27225, 27556, 27889, 28224, 28561, 28900, 29241, 29584, 29929, 30276, 30625,
  59. 30976, 31329, 31684, 32041, 32400, 32761, 33124, 33489, 33856, 34225, 34596, 34969, 35344, 35721, 36100, 36481,
  60. 36864, 37249, 37636, 38025, 38416, 38809, 39204, 39601, 40000, 40401, 40804, 41209, 41616, 42025, 42436, 42849,
  61. 43264, 43681, 44100, 44521, 44944, 45369, 45796, 46225, 46656, 47089, 47524, 47961, 48400, 48841, 49284, 49729,
  62. 50176, 50625, 51076, 51529, 51984, 52441, 52900, 53361, 53824, 54289, 54756, 55225, 55696, 56169, 56644, 57121,
  63. 57600, 58081, 58564, 59049, 59536, 60025, 60516, 61009, 61504, 62001, 62500, 63001, 63504, 64009, 64516, 65025,
  64. };
  65. static int sse4_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  66. ptrdiff_t stride, int h)
  67. {
  68. int s = 0, i;
  69. const uint32_t *sq = ff_square_tab + 256;
  70. for (i = 0; i < h; i++) {
  71. s += sq[pix1[0] - pix2[0]];
  72. s += sq[pix1[1] - pix2[1]];
  73. s += sq[pix1[2] - pix2[2]];
  74. s += sq[pix1[3] - pix2[3]];
  75. pix1 += stride;
  76. pix2 += stride;
  77. }
  78. return s;
  79. }
  80. static int sse8_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  81. ptrdiff_t stride, int h)
  82. {
  83. int s = 0, i;
  84. const uint32_t *sq = ff_square_tab + 256;
  85. for (i = 0; i < h; i++) {
  86. s += sq[pix1[0] - pix2[0]];
  87. s += sq[pix1[1] - pix2[1]];
  88. s += sq[pix1[2] - pix2[2]];
  89. s += sq[pix1[3] - pix2[3]];
  90. s += sq[pix1[4] - pix2[4]];
  91. s += sq[pix1[5] - pix2[5]];
  92. s += sq[pix1[6] - pix2[6]];
  93. s += sq[pix1[7] - pix2[7]];
  94. pix1 += stride;
  95. pix2 += stride;
  96. }
  97. return s;
  98. }
  99. static int sse16_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  100. ptrdiff_t stride, int h)
  101. {
  102. int s = 0, i;
  103. const uint32_t *sq = ff_square_tab + 256;
  104. for (i = 0; i < h; i++) {
  105. s += sq[pix1[0] - pix2[0]];
  106. s += sq[pix1[1] - pix2[1]];
  107. s += sq[pix1[2] - pix2[2]];
  108. s += sq[pix1[3] - pix2[3]];
  109. s += sq[pix1[4] - pix2[4]];
  110. s += sq[pix1[5] - pix2[5]];
  111. s += sq[pix1[6] - pix2[6]];
  112. s += sq[pix1[7] - pix2[7]];
  113. s += sq[pix1[8] - pix2[8]];
  114. s += sq[pix1[9] - pix2[9]];
  115. s += sq[pix1[10] - pix2[10]];
  116. s += sq[pix1[11] - pix2[11]];
  117. s += sq[pix1[12] - pix2[12]];
  118. s += sq[pix1[13] - pix2[13]];
  119. s += sq[pix1[14] - pix2[14]];
  120. s += sq[pix1[15] - pix2[15]];
  121. pix1 += stride;
  122. pix2 += stride;
  123. }
  124. return s;
  125. }
  126. static int sum_abs_dctelem_c(int16_t *block)
  127. {
  128. int sum = 0, i;
  129. for (i = 0; i < 64; i++)
  130. sum += FFABS(block[i]);
  131. return sum;
  132. }
  133. #define avg2(a, b) (((a) + (b) + 1) >> 1)
  134. #define avg4(a, b, c, d) (((a) + (b) + (c) + (d) + 2) >> 2)
  135. static inline int pix_abs16_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  136. ptrdiff_t stride, int h)
  137. {
  138. int s = 0, i;
  139. for (i = 0; i < h; i++) {
  140. s += abs(pix1[0] - pix2[0]);
  141. s += abs(pix1[1] - pix2[1]);
  142. s += abs(pix1[2] - pix2[2]);
  143. s += abs(pix1[3] - pix2[3]);
  144. s += abs(pix1[4] - pix2[4]);
  145. s += abs(pix1[5] - pix2[5]);
  146. s += abs(pix1[6] - pix2[6]);
  147. s += abs(pix1[7] - pix2[7]);
  148. s += abs(pix1[8] - pix2[8]);
  149. s += abs(pix1[9] - pix2[9]);
  150. s += abs(pix1[10] - pix2[10]);
  151. s += abs(pix1[11] - pix2[11]);
  152. s += abs(pix1[12] - pix2[12]);
  153. s += abs(pix1[13] - pix2[13]);
  154. s += abs(pix1[14] - pix2[14]);
  155. s += abs(pix1[15] - pix2[15]);
  156. pix1 += stride;
  157. pix2 += stride;
  158. }
  159. return s;
  160. }
  161. static inline int pix_median_abs16_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  162. ptrdiff_t stride, int h)
  163. {
  164. int s = 0, i, j;
  165. #define V(x) (pix1[x] - pix2[x])
  166. s += abs(V(0));
  167. s += abs(V(1) - V(0));
  168. s += abs(V(2) - V(1));
  169. s += abs(V(3) - V(2));
  170. s += abs(V(4) - V(3));
  171. s += abs(V(5) - V(4));
  172. s += abs(V(6) - V(5));
  173. s += abs(V(7) - V(6));
  174. s += abs(V(8) - V(7));
  175. s += abs(V(9) - V(8));
  176. s += abs(V(10) - V(9));
  177. s += abs(V(11) - V(10));
  178. s += abs(V(12) - V(11));
  179. s += abs(V(13) - V(12));
  180. s += abs(V(14) - V(13));
  181. s += abs(V(15) - V(14));
  182. pix1 += stride;
  183. pix2 += stride;
  184. for (i = 1; i < h; i++) {
  185. s += abs(V(0) - V(-stride));
  186. for (j = 1; j < 16; j++)
  187. s += abs(V(j) - mid_pred(V(j-stride), V(j-1), V(j-stride) + V(j-1) - V(j-stride-1)));
  188. pix1 += stride;
  189. pix2 += stride;
  190. }
  191. #undef V
  192. return s;
  193. }
  194. static int pix_abs16_x2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  195. ptrdiff_t stride, int h)
  196. {
  197. int s = 0, i;
  198. for (i = 0; i < h; i++) {
  199. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  200. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  201. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  202. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  203. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  204. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  205. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  206. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  207. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  208. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  209. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  210. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  211. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  212. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  213. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  214. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  215. pix1 += stride;
  216. pix2 += stride;
  217. }
  218. return s;
  219. }
  220. static int pix_abs16_y2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  221. ptrdiff_t stride, int h)
  222. {
  223. int s = 0, i;
  224. uint8_t *pix3 = pix2 + stride;
  225. for (i = 0; i < h; i++) {
  226. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  227. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  228. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  229. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  230. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  231. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  232. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  233. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  234. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  235. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  236. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  237. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  238. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  239. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  240. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  241. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  242. pix1 += stride;
  243. pix2 += stride;
  244. pix3 += stride;
  245. }
  246. return s;
  247. }
  248. static int pix_abs16_xy2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  249. ptrdiff_t stride, int h)
  250. {
  251. int s = 0, i;
  252. uint8_t *pix3 = pix2 + stride;
  253. for (i = 0; i < h; i++) {
  254. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  255. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  256. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  257. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  258. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  259. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  260. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  261. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  262. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  263. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  264. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  265. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  266. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  267. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  268. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  269. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  270. pix1 += stride;
  271. pix2 += stride;
  272. pix3 += stride;
  273. }
  274. return s;
  275. }
  276. static inline int pix_abs8_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  277. ptrdiff_t stride, int h)
  278. {
  279. int s = 0, i;
  280. for (i = 0; i < h; i++) {
  281. s += abs(pix1[0] - pix2[0]);
  282. s += abs(pix1[1] - pix2[1]);
  283. s += abs(pix1[2] - pix2[2]);
  284. s += abs(pix1[3] - pix2[3]);
  285. s += abs(pix1[4] - pix2[4]);
  286. s += abs(pix1[5] - pix2[5]);
  287. s += abs(pix1[6] - pix2[6]);
  288. s += abs(pix1[7] - pix2[7]);
  289. pix1 += stride;
  290. pix2 += stride;
  291. }
  292. return s;
  293. }
  294. static inline int pix_median_abs8_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  295. ptrdiff_t stride, int h)
  296. {
  297. int s = 0, i, j;
  298. #define V(x) (pix1[x] - pix2[x])
  299. s += abs(V(0));
  300. s += abs(V(1) - V(0));
  301. s += abs(V(2) - V(1));
  302. s += abs(V(3) - V(2));
  303. s += abs(V(4) - V(3));
  304. s += abs(V(5) - V(4));
  305. s += abs(V(6) - V(5));
  306. s += abs(V(7) - V(6));
  307. pix1 += stride;
  308. pix2 += stride;
  309. for (i = 1; i < h; i++) {
  310. s += abs(V(0) - V(-stride));
  311. for (j = 1; j < 8; j++)
  312. s += abs(V(j) - mid_pred(V(j-stride), V(j-1), V(j-stride) + V(j-1) - V(j-stride-1)));
  313. pix1 += stride;
  314. pix2 += stride;
  315. }
  316. #undef V
  317. return s;
  318. }
  319. static int pix_abs8_x2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  320. ptrdiff_t stride, int h)
  321. {
  322. int s = 0, i;
  323. for (i = 0; i < h; i++) {
  324. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  325. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  326. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  327. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  328. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  329. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  330. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  331. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  332. pix1 += stride;
  333. pix2 += stride;
  334. }
  335. return s;
  336. }
  337. static int pix_abs8_y2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  338. ptrdiff_t stride, int h)
  339. {
  340. int s = 0, i;
  341. uint8_t *pix3 = pix2 + stride;
  342. for (i = 0; i < h; i++) {
  343. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  344. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  345. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  346. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  347. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  348. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  349. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  350. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  351. pix1 += stride;
  352. pix2 += stride;
  353. pix3 += stride;
  354. }
  355. return s;
  356. }
  357. static int pix_abs8_xy2_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
  358. ptrdiff_t stride, int h)
  359. {
  360. int s = 0, i;
  361. uint8_t *pix3 = pix2 + stride;
  362. for (i = 0; i < h; i++) {
  363. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  364. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  365. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  366. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  367. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  368. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  369. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  370. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  371. pix1 += stride;
  372. pix2 += stride;
  373. pix3 += stride;
  374. }
  375. return s;
  376. }
  377. static int nsse16_c(MpegEncContext *c, uint8_t *s1, uint8_t *s2,
  378. ptrdiff_t stride, int h)
  379. {
  380. int score1 = 0, score2 = 0, x, y;
  381. for (y = 0; y < h; y++) {
  382. for (x = 0; x < 16; x++)
  383. score1 += (s1[x] - s2[x]) * (s1[x] - s2[x]);
  384. if (y + 1 < h) {
  385. for (x = 0; x < 15; x++)
  386. score2 += FFABS(s1[x] - s1[x + stride] -
  387. s1[x + 1] + s1[x + stride + 1]) -
  388. FFABS(s2[x] - s2[x + stride] -
  389. s2[x + 1] + s2[x + stride + 1]);
  390. }
  391. s1 += stride;
  392. s2 += stride;
  393. }
  394. if (c)
  395. return score1 + FFABS(score2) * c->avctx->nsse_weight;
  396. else
  397. return score1 + FFABS(score2) * 8;
  398. }
  399. static int nsse8_c(MpegEncContext *c, uint8_t *s1, uint8_t *s2,
  400. ptrdiff_t stride, int h)
  401. {
  402. int score1 = 0, score2 = 0, x, y;
  403. for (y = 0; y < h; y++) {
  404. for (x = 0; x < 8; x++)
  405. score1 += (s1[x] - s2[x]) * (s1[x] - s2[x]);
  406. if (y + 1 < h) {
  407. for (x = 0; x < 7; x++)
  408. score2 += FFABS(s1[x] - s1[x + stride] -
  409. s1[x + 1] + s1[x + stride + 1]) -
  410. FFABS(s2[x] - s2[x + stride] -
  411. s2[x + 1] + s2[x + stride + 1]);
  412. }
  413. s1 += stride;
  414. s2 += stride;
  415. }
  416. if (c)
  417. return score1 + FFABS(score2) * c->avctx->nsse_weight;
  418. else
  419. return score1 + FFABS(score2) * 8;
  420. }
  421. static int zero_cmp(MpegEncContext *s, uint8_t *a, uint8_t *b,
  422. ptrdiff_t stride, int h)
  423. {
  424. return 0;
  425. }
  426. void ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
  427. {
  428. int i;
  429. memset(cmp, 0, sizeof(void *) * 6);
  430. for (i = 0; i < 6; i++) {
  431. switch (type & 0xFF) {
  432. case FF_CMP_SAD:
  433. cmp[i] = c->sad[i];
  434. break;
  435. case FF_CMP_MEDIAN_SAD:
  436. cmp[i] = c->median_sad[i];
  437. break;
  438. case FF_CMP_SATD:
  439. cmp[i] = c->hadamard8_diff[i];
  440. break;
  441. case FF_CMP_SSE:
  442. cmp[i] = c->sse[i];
  443. break;
  444. case FF_CMP_DCT:
  445. cmp[i] = c->dct_sad[i];
  446. break;
  447. case FF_CMP_DCT264:
  448. cmp[i] = c->dct264_sad[i];
  449. break;
  450. case FF_CMP_DCTMAX:
  451. cmp[i] = c->dct_max[i];
  452. break;
  453. case FF_CMP_PSNR:
  454. cmp[i] = c->quant_psnr[i];
  455. break;
  456. case FF_CMP_BIT:
  457. cmp[i] = c->bit[i];
  458. break;
  459. case FF_CMP_RD:
  460. cmp[i] = c->rd[i];
  461. break;
  462. case FF_CMP_VSAD:
  463. cmp[i] = c->vsad[i];
  464. break;
  465. case FF_CMP_VSSE:
  466. cmp[i] = c->vsse[i];
  467. break;
  468. case FF_CMP_ZERO:
  469. cmp[i] = zero_cmp;
  470. break;
  471. case FF_CMP_NSSE:
  472. cmp[i] = c->nsse[i];
  473. break;
  474. #if CONFIG_DWT
  475. case FF_CMP_W53:
  476. cmp[i]= c->w53[i];
  477. break;
  478. case FF_CMP_W97:
  479. cmp[i]= c->w97[i];
  480. break;
  481. #endif
  482. default:
  483. av_log(NULL, AV_LOG_ERROR,
  484. "internal error in cmp function selection\n");
  485. }
  486. }
  487. }
  488. #define BUTTERFLY2(o1, o2, i1, i2) \
  489. o1 = (i1) + (i2); \
  490. o2 = (i1) - (i2);
  491. #define BUTTERFLY1(x, y) \
  492. { \
  493. int a, b; \
  494. a = x; \
  495. b = y; \
  496. x = a + b; \
  497. y = a - b; \
  498. }
  499. #define BUTTERFLYA(x, y) (FFABS((x) + (y)) + FFABS((x) - (y)))
  500. static int hadamard8_diff8x8_c(MpegEncContext *s, uint8_t *dst,
  501. uint8_t *src, ptrdiff_t stride, int h)
  502. {
  503. int i, temp[64], sum = 0;
  504. av_assert2(h == 8);
  505. for (i = 0; i < 8; i++) {
  506. // FIXME: try pointer walks
  507. BUTTERFLY2(temp[8 * i + 0], temp[8 * i + 1],
  508. src[stride * i + 0] - dst[stride * i + 0],
  509. src[stride * i + 1] - dst[stride * i + 1]);
  510. BUTTERFLY2(temp[8 * i + 2], temp[8 * i + 3],
  511. src[stride * i + 2] - dst[stride * i + 2],
  512. src[stride * i + 3] - dst[stride * i + 3]);
  513. BUTTERFLY2(temp[8 * i + 4], temp[8 * i + 5],
  514. src[stride * i + 4] - dst[stride * i + 4],
  515. src[stride * i + 5] - dst[stride * i + 5]);
  516. BUTTERFLY2(temp[8 * i + 6], temp[8 * i + 7],
  517. src[stride * i + 6] - dst[stride * i + 6],
  518. src[stride * i + 7] - dst[stride * i + 7]);
  519. BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 2]);
  520. BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 3]);
  521. BUTTERFLY1(temp[8 * i + 4], temp[8 * i + 6]);
  522. BUTTERFLY1(temp[8 * i + 5], temp[8 * i + 7]);
  523. BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 4]);
  524. BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 5]);
  525. BUTTERFLY1(temp[8 * i + 2], temp[8 * i + 6]);
  526. BUTTERFLY1(temp[8 * i + 3], temp[8 * i + 7]);
  527. }
  528. for (i = 0; i < 8; i++) {
  529. BUTTERFLY1(temp[8 * 0 + i], temp[8 * 1 + i]);
  530. BUTTERFLY1(temp[8 * 2 + i], temp[8 * 3 + i]);
  531. BUTTERFLY1(temp[8 * 4 + i], temp[8 * 5 + i]);
  532. BUTTERFLY1(temp[8 * 6 + i], temp[8 * 7 + i]);
  533. BUTTERFLY1(temp[8 * 0 + i], temp[8 * 2 + i]);
  534. BUTTERFLY1(temp[8 * 1 + i], temp[8 * 3 + i]);
  535. BUTTERFLY1(temp[8 * 4 + i], temp[8 * 6 + i]);
  536. BUTTERFLY1(temp[8 * 5 + i], temp[8 * 7 + i]);
  537. sum += BUTTERFLYA(temp[8 * 0 + i], temp[8 * 4 + i]) +
  538. BUTTERFLYA(temp[8 * 1 + i], temp[8 * 5 + i]) +
  539. BUTTERFLYA(temp[8 * 2 + i], temp[8 * 6 + i]) +
  540. BUTTERFLYA(temp[8 * 3 + i], temp[8 * 7 + i]);
  541. }
  542. return sum;
  543. }
  544. static int hadamard8_intra8x8_c(MpegEncContext *s, uint8_t *src,
  545. uint8_t *dummy, ptrdiff_t stride, int h)
  546. {
  547. int i, temp[64], sum = 0;
  548. av_assert2(h == 8);
  549. for (i = 0; i < 8; i++) {
  550. // FIXME: try pointer walks
  551. BUTTERFLY2(temp[8 * i + 0], temp[8 * i + 1],
  552. src[stride * i + 0], src[stride * i + 1]);
  553. BUTTERFLY2(temp[8 * i + 2], temp[8 * i + 3],
  554. src[stride * i + 2], src[stride * i + 3]);
  555. BUTTERFLY2(temp[8 * i + 4], temp[8 * i + 5],
  556. src[stride * i + 4], src[stride * i + 5]);
  557. BUTTERFLY2(temp[8 * i + 6], temp[8 * i + 7],
  558. src[stride * i + 6], src[stride * i + 7]);
  559. BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 2]);
  560. BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 3]);
  561. BUTTERFLY1(temp[8 * i + 4], temp[8 * i + 6]);
  562. BUTTERFLY1(temp[8 * i + 5], temp[8 * i + 7]);
  563. BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 4]);
  564. BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 5]);
  565. BUTTERFLY1(temp[8 * i + 2], temp[8 * i + 6]);
  566. BUTTERFLY1(temp[8 * i + 3], temp[8 * i + 7]);
  567. }
  568. for (i = 0; i < 8; i++) {
  569. BUTTERFLY1(temp[8 * 0 + i], temp[8 * 1 + i]);
  570. BUTTERFLY1(temp[8 * 2 + i], temp[8 * 3 + i]);
  571. BUTTERFLY1(temp[8 * 4 + i], temp[8 * 5 + i]);
  572. BUTTERFLY1(temp[8 * 6 + i], temp[8 * 7 + i]);
  573. BUTTERFLY1(temp[8 * 0 + i], temp[8 * 2 + i]);
  574. BUTTERFLY1(temp[8 * 1 + i], temp[8 * 3 + i]);
  575. BUTTERFLY1(temp[8 * 4 + i], temp[8 * 6 + i]);
  576. BUTTERFLY1(temp[8 * 5 + i], temp[8 * 7 + i]);
  577. sum +=
  578. BUTTERFLYA(temp[8 * 0 + i], temp[8 * 4 + i])
  579. + BUTTERFLYA(temp[8 * 1 + i], temp[8 * 5 + i])
  580. + BUTTERFLYA(temp[8 * 2 + i], temp[8 * 6 + i])
  581. + BUTTERFLYA(temp[8 * 3 + i], temp[8 * 7 + i]);
  582. }
  583. sum -= FFABS(temp[8 * 0] + temp[8 * 4]); // -mean
  584. return sum;
  585. }
  586. static int dct_sad8x8_c(MpegEncContext *s, uint8_t *src1,
  587. uint8_t *src2, ptrdiff_t stride, int h)
  588. {
  589. LOCAL_ALIGNED_16(int16_t, temp, [64]);
  590. av_assert2(h == 8);
  591. s->pdsp.diff_pixels_unaligned(temp, src1, src2, stride);
  592. s->fdsp.fdct(temp);
  593. return s->mecc.sum_abs_dctelem(temp);
  594. }
  595. #if CONFIG_GPL
  596. #define DCT8_1D \
  597. { \
  598. const int s07 = SRC(0) + SRC(7); \
  599. const int s16 = SRC(1) + SRC(6); \
  600. const int s25 = SRC(2) + SRC(5); \
  601. const int s34 = SRC(3) + SRC(4); \
  602. const int a0 = s07 + s34; \
  603. const int a1 = s16 + s25; \
  604. const int a2 = s07 - s34; \
  605. const int a3 = s16 - s25; \
  606. const int d07 = SRC(0) - SRC(7); \
  607. const int d16 = SRC(1) - SRC(6); \
  608. const int d25 = SRC(2) - SRC(5); \
  609. const int d34 = SRC(3) - SRC(4); \
  610. const int a4 = d16 + d25 + (d07 + (d07 >> 1)); \
  611. const int a5 = d07 - d34 - (d25 + (d25 >> 1)); \
  612. const int a6 = d07 + d34 - (d16 + (d16 >> 1)); \
  613. const int a7 = d16 - d25 + (d34 + (d34 >> 1)); \
  614. DST(0, a0 + a1); \
  615. DST(1, a4 + (a7 >> 2)); \
  616. DST(2, a2 + (a3 >> 1)); \
  617. DST(3, a5 + (a6 >> 2)); \
  618. DST(4, a0 - a1); \
  619. DST(5, a6 - (a5 >> 2)); \
  620. DST(6, (a2 >> 1) - a3); \
  621. DST(7, (a4 >> 2) - a7); \
  622. }
  623. static int dct264_sad8x8_c(MpegEncContext *s, uint8_t *src1,
  624. uint8_t *src2, ptrdiff_t stride, int h)
  625. {
  626. int16_t dct[8][8];
  627. int i, sum = 0;
  628. s->pdsp.diff_pixels_unaligned(dct[0], src1, src2, stride);
  629. #define SRC(x) dct[i][x]
  630. #define DST(x, v) dct[i][x] = v
  631. for (i = 0; i < 8; i++)
  632. DCT8_1D
  633. #undef SRC
  634. #undef DST
  635. #define SRC(x) dct[x][i]
  636. #define DST(x, v) sum += FFABS(v)
  637. for (i = 0; i < 8; i++)
  638. DCT8_1D
  639. #undef SRC
  640. #undef DST
  641. return sum;
  642. }
  643. #endif
  644. static int dct_max8x8_c(MpegEncContext *s, uint8_t *src1,
  645. uint8_t *src2, ptrdiff_t stride, int h)
  646. {
  647. LOCAL_ALIGNED_16(int16_t, temp, [64]);
  648. int sum = 0, i;
  649. av_assert2(h == 8);
  650. s->pdsp.diff_pixels_unaligned(temp, src1, src2, stride);
  651. s->fdsp.fdct(temp);
  652. for (i = 0; i < 64; i++)
  653. sum = FFMAX(sum, FFABS(temp[i]));
  654. return sum;
  655. }
  656. static int quant_psnr8x8_c(MpegEncContext *s, uint8_t *src1,
  657. uint8_t *src2, ptrdiff_t stride, int h)
  658. {
  659. LOCAL_ALIGNED_16(int16_t, temp, [64 * 2]);
  660. int16_t *const bak = temp + 64;
  661. int sum = 0, i;
  662. av_assert2(h == 8);
  663. s->mb_intra = 0;
  664. s->pdsp.diff_pixels_unaligned(temp, src1, src2, stride);
  665. memcpy(bak, temp, 64 * sizeof(int16_t));
  666. s->block_last_index[0 /* FIXME */] =
  667. s->fast_dct_quantize(s, temp, 0 /* FIXME */, s->qscale, &i);
  668. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  669. ff_simple_idct_int16_8bit(temp); // FIXME
  670. for (i = 0; i < 64; i++)
  671. sum += (temp[i] - bak[i]) * (temp[i] - bak[i]);
  672. return sum;
  673. }
  674. static int rd8x8_c(MpegEncContext *s, uint8_t *src1, uint8_t *src2,
  675. ptrdiff_t stride, int h)
  676. {
  677. const uint8_t *scantable = s->intra_scantable.permutated;
  678. LOCAL_ALIGNED_16(int16_t, temp, [64]);
  679. LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]);
  680. LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]);
  681. int i, last, run, bits, level, distortion, start_i;
  682. const int esc_length = s->ac_esc_length;
  683. uint8_t *length, *last_length;
  684. av_assert2(h == 8);
  685. copy_block8(lsrc1, src1, 8, stride, 8);
  686. copy_block8(lsrc2, src2, 8, stride, 8);
  687. s->pdsp.diff_pixels(temp, lsrc1, lsrc2, 8);
  688. s->block_last_index[0 /* FIXME */] =
  689. last =
  690. s->fast_dct_quantize(s, temp, 0 /* FIXME */, s->qscale, &i);
  691. bits = 0;
  692. if (s->mb_intra) {
  693. start_i = 1;
  694. length = s->intra_ac_vlc_length;
  695. last_length = s->intra_ac_vlc_last_length;
  696. bits += s->luma_dc_vlc_length[temp[0] + 256]; // FIXME: chroma
  697. } else {
  698. start_i = 0;
  699. length = s->inter_ac_vlc_length;
  700. last_length = s->inter_ac_vlc_last_length;
  701. }
  702. if (last >= start_i) {
  703. run = 0;
  704. for (i = start_i; i < last; i++) {
  705. int j = scantable[i];
  706. level = temp[j];
  707. if (level) {
  708. level += 64;
  709. if ((level & (~127)) == 0)
  710. bits += length[UNI_AC_ENC_INDEX(run, level)];
  711. else
  712. bits += esc_length;
  713. run = 0;
  714. } else
  715. run++;
  716. }
  717. i = scantable[last];
  718. level = temp[i] + 64;
  719. av_assert2(level - 64);
  720. if ((level & (~127)) == 0) {
  721. bits += last_length[UNI_AC_ENC_INDEX(run, level)];
  722. } else
  723. bits += esc_length;
  724. }
  725. if (last >= 0) {
  726. if (s->mb_intra)
  727. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  728. else
  729. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  730. }
  731. s->idsp.idct_add(lsrc2, 8, temp);
  732. distortion = s->mecc.sse[1](NULL, lsrc2, lsrc1, 8, 8);
  733. return distortion + ((bits * s->qscale * s->qscale * 109 + 64) >> 7);
  734. }
  735. static int bit8x8_c(MpegEncContext *s, uint8_t *src1, uint8_t *src2,
  736. ptrdiff_t stride, int h)
  737. {
  738. const uint8_t *scantable = s->intra_scantable.permutated;
  739. LOCAL_ALIGNED_16(int16_t, temp, [64]);
  740. int i, last, run, bits, level, start_i;
  741. const int esc_length = s->ac_esc_length;
  742. uint8_t *length, *last_length;
  743. av_assert2(h == 8);
  744. s->pdsp.diff_pixels_unaligned(temp, src1, src2, stride);
  745. s->block_last_index[0 /* FIXME */] =
  746. last =
  747. s->fast_dct_quantize(s, temp, 0 /* FIXME */, s->qscale, &i);
  748. bits = 0;
  749. if (s->mb_intra) {
  750. start_i = 1;
  751. length = s->intra_ac_vlc_length;
  752. last_length = s->intra_ac_vlc_last_length;
  753. bits += s->luma_dc_vlc_length[temp[0] + 256]; // FIXME: chroma
  754. } else {
  755. start_i = 0;
  756. length = s->inter_ac_vlc_length;
  757. last_length = s->inter_ac_vlc_last_length;
  758. }
  759. if (last >= start_i) {
  760. run = 0;
  761. for (i = start_i; i < last; i++) {
  762. int j = scantable[i];
  763. level = temp[j];
  764. if (level) {
  765. level += 64;
  766. if ((level & (~127)) == 0)
  767. bits += length[UNI_AC_ENC_INDEX(run, level)];
  768. else
  769. bits += esc_length;
  770. run = 0;
  771. } else
  772. run++;
  773. }
  774. i = scantable[last];
  775. level = temp[i] + 64;
  776. av_assert2(level - 64);
  777. if ((level & (~127)) == 0)
  778. bits += last_length[UNI_AC_ENC_INDEX(run, level)];
  779. else
  780. bits += esc_length;
  781. }
  782. return bits;
  783. }
  784. #define VSAD_INTRA(size) \
  785. static int vsad_intra ## size ## _c(MpegEncContext *c, \
  786. uint8_t *s, uint8_t *dummy, \
  787. ptrdiff_t stride, int h) \
  788. { \
  789. int score = 0, x, y; \
  790. \
  791. for (y = 1; y < h; y++) { \
  792. for (x = 0; x < size; x += 4) { \
  793. score += FFABS(s[x] - s[x + stride]) + \
  794. FFABS(s[x + 1] - s[x + stride + 1]) + \
  795. FFABS(s[x + 2] - s[x + 2 + stride]) + \
  796. FFABS(s[x + 3] - s[x + 3 + stride]); \
  797. } \
  798. s += stride; \
  799. } \
  800. \
  801. return score; \
  802. }
  803. VSAD_INTRA(8)
  804. VSAD_INTRA(16)
  805. #define VSAD(size) \
  806. static int vsad ## size ## _c(MpegEncContext *c, \
  807. uint8_t *s1, uint8_t *s2, \
  808. ptrdiff_t stride, int h) \
  809. { \
  810. int score = 0, x, y; \
  811. \
  812. for (y = 1; y < h; y++) { \
  813. for (x = 0; x < size; x++) \
  814. score += FFABS(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \
  815. s1 += stride; \
  816. s2 += stride; \
  817. } \
  818. \
  819. return score; \
  820. }
  821. VSAD(8)
  822. VSAD(16)
  823. #define SQ(a) ((a) * (a))
  824. #define VSSE_INTRA(size) \
  825. static int vsse_intra ## size ## _c(MpegEncContext *c, \
  826. uint8_t *s, uint8_t *dummy, \
  827. ptrdiff_t stride, int h) \
  828. { \
  829. int score = 0, x, y; \
  830. \
  831. for (y = 1; y < h; y++) { \
  832. for (x = 0; x < size; x += 4) { \
  833. score += SQ(s[x] - s[x + stride]) + \
  834. SQ(s[x + 1] - s[x + stride + 1]) + \
  835. SQ(s[x + 2] - s[x + stride + 2]) + \
  836. SQ(s[x + 3] - s[x + stride + 3]); \
  837. } \
  838. s += stride; \
  839. } \
  840. \
  841. return score; \
  842. }
  843. VSSE_INTRA(8)
  844. VSSE_INTRA(16)
  845. #define VSSE(size) \
  846. static int vsse ## size ## _c(MpegEncContext *c, uint8_t *s1, uint8_t *s2, \
  847. ptrdiff_t stride, int h) \
  848. { \
  849. int score = 0, x, y; \
  850. \
  851. for (y = 1; y < h; y++) { \
  852. for (x = 0; x < size; x++) \
  853. score += SQ(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \
  854. s1 += stride; \
  855. s2 += stride; \
  856. } \
  857. \
  858. return score; \
  859. }
  860. VSSE(8)
  861. VSSE(16)
  862. #define WRAPPER8_16_SQ(name8, name16) \
  863. static int name16(MpegEncContext *s, uint8_t *dst, uint8_t *src, \
  864. ptrdiff_t stride, int h) \
  865. { \
  866. int score = 0; \
  867. \
  868. score += name8(s, dst, src, stride, 8); \
  869. score += name8(s, dst + 8, src + 8, stride, 8); \
  870. if (h == 16) { \
  871. dst += 8 * stride; \
  872. src += 8 * stride; \
  873. score += name8(s, dst, src, stride, 8); \
  874. score += name8(s, dst + 8, src + 8, stride, 8); \
  875. } \
  876. return score; \
  877. }
  878. WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  879. WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  880. WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  881. #if CONFIG_GPL
  882. WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
  883. #endif
  884. WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
  885. WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  886. WRAPPER8_16_SQ(rd8x8_c, rd16_c)
  887. WRAPPER8_16_SQ(bit8x8_c, bit16_c)
  888. int ff_check_alignment(void)
  889. {
  890. static int did_fail = 0;
  891. LOCAL_ALIGNED_16(int, aligned, [4]);
  892. if ((intptr_t)aligned & 15) {
  893. if (!did_fail) {
  894. #if HAVE_MMX || HAVE_ALTIVEC
  895. av_log(NULL, AV_LOG_ERROR,
  896. "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
  897. "and may be very slow or crash. This is not a bug in libavcodec,\n"
  898. "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
  899. "Do not report crashes to FFmpeg developers.\n");
  900. #endif
  901. did_fail=1;
  902. }
  903. return -1;
  904. }
  905. return 0;
  906. }
  907. av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
  908. {
  909. ff_check_alignment();
  910. c->sum_abs_dctelem = sum_abs_dctelem_c;
  911. /* TODO [0] 16 [1] 8 */
  912. c->pix_abs[0][0] = pix_abs16_c;
  913. c->pix_abs[0][1] = pix_abs16_x2_c;
  914. c->pix_abs[0][2] = pix_abs16_y2_c;
  915. c->pix_abs[0][3] = pix_abs16_xy2_c;
  916. c->pix_abs[1][0] = pix_abs8_c;
  917. c->pix_abs[1][1] = pix_abs8_x2_c;
  918. c->pix_abs[1][2] = pix_abs8_y2_c;
  919. c->pix_abs[1][3] = pix_abs8_xy2_c;
  920. #define SET_CMP_FUNC(name) \
  921. c->name[0] = name ## 16_c; \
  922. c->name[1] = name ## 8x8_c;
  923. SET_CMP_FUNC(hadamard8_diff)
  924. c->hadamard8_diff[4] = hadamard8_intra16_c;
  925. c->hadamard8_diff[5] = hadamard8_intra8x8_c;
  926. SET_CMP_FUNC(dct_sad)
  927. SET_CMP_FUNC(dct_max)
  928. #if CONFIG_GPL
  929. SET_CMP_FUNC(dct264_sad)
  930. #endif
  931. c->sad[0] = pix_abs16_c;
  932. c->sad[1] = pix_abs8_c;
  933. c->sse[0] = sse16_c;
  934. c->sse[1] = sse8_c;
  935. c->sse[2] = sse4_c;
  936. SET_CMP_FUNC(quant_psnr)
  937. SET_CMP_FUNC(rd)
  938. SET_CMP_FUNC(bit)
  939. c->vsad[0] = vsad16_c;
  940. c->vsad[1] = vsad8_c;
  941. c->vsad[4] = vsad_intra16_c;
  942. c->vsad[5] = vsad_intra8_c;
  943. c->vsse[0] = vsse16_c;
  944. c->vsse[1] = vsse8_c;
  945. c->vsse[4] = vsse_intra16_c;
  946. c->vsse[5] = vsse_intra8_c;
  947. c->nsse[0] = nsse16_c;
  948. c->nsse[1] = nsse8_c;
  949. #if CONFIG_SNOW_DECODER || CONFIG_SNOW_ENCODER
  950. ff_dsputil_init_dwt(c);
  951. #endif
  952. if (ARCH_ALPHA)
  953. ff_me_cmp_init_alpha(c, avctx);
  954. if (ARCH_ARM)
  955. ff_me_cmp_init_arm(c, avctx);
  956. if (ARCH_PPC)
  957. ff_me_cmp_init_ppc(c, avctx);
  958. if (ARCH_X86)
  959. ff_me_cmp_init_x86(c, avctx);
  960. if (ARCH_MIPS)
  961. ff_me_cmp_init_mips(c, avctx);
  962. c->median_sad[0] = pix_median_abs16_c;
  963. c->median_sad[1] = pix_median_abs8_c;
  964. }