sw_rgb.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. /*
  2. *
  3. * This file is part of FFmpeg.
  4. *
  5. * FFmpeg is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * FFmpeg 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
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. #include <string.h>
  20. #include "libavutil/common.h"
  21. #include "libavutil/intreadwrite.h"
  22. #include "libavutil/mem_internal.h"
  23. #include "libavutil/pixdesc.h"
  24. #include "libswscale/rgb2rgb.h"
  25. #include "libswscale/swscale.h"
  26. #include "libswscale/swscale_internal.h"
  27. #include "checkasm.h"
  28. #define randomize_buffers(buf, size) \
  29. do { \
  30. int j; \
  31. for (j = 0; j < size; j+=4) \
  32. AV_WN32(buf + j, rnd()); \
  33. } while (0)
  34. static const uint8_t width[] = {12, 16, 20, 32, 36, 128};
  35. static const struct {uint8_t w, h, s;} planes[] = {
  36. {12,16,12}, {16,16,16}, {20,23,25}, {32,18,48}, {8,128,16}, {128,128,128}
  37. };
  38. #define MAX_STRIDE 128
  39. #define MAX_HEIGHT 128
  40. static void check_shuffle_bytes(void * func, const char * report)
  41. {
  42. int i;
  43. LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE]);
  44. LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE]);
  45. LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE]);
  46. LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE]);
  47. declare_func(void, const uint8_t *src, uint8_t *dst, int src_size);
  48. memset(dst0, 0, MAX_STRIDE);
  49. memset(dst1, 0, MAX_STRIDE);
  50. randomize_buffers(src0, MAX_STRIDE);
  51. memcpy(src1, src0, MAX_STRIDE);
  52. if (check_func(func, "%s", report)) {
  53. for (i = 0; i < 6; i ++) {
  54. call_ref(src0, dst0, width[i]);
  55. call_new(src1, dst1, width[i]);
  56. if (memcmp(dst0, dst1, MAX_STRIDE))
  57. fail();
  58. }
  59. bench_new(src0, dst0, width[5]);
  60. }
  61. }
  62. static void check_uyvy_to_422p(void)
  63. {
  64. int i;
  65. LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE * MAX_HEIGHT * 2]);
  66. LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE * MAX_HEIGHT * 2]);
  67. LOCAL_ALIGNED_32(uint8_t, dst_y_0, [MAX_STRIDE * MAX_HEIGHT]);
  68. LOCAL_ALIGNED_32(uint8_t, dst_y_1, [MAX_STRIDE * MAX_HEIGHT]);
  69. LOCAL_ALIGNED_32(uint8_t, dst_u_0, [(MAX_STRIDE/2) * MAX_HEIGHT]);
  70. LOCAL_ALIGNED_32(uint8_t, dst_u_1, [(MAX_STRIDE/2) * MAX_HEIGHT]);
  71. LOCAL_ALIGNED_32(uint8_t, dst_v_0, [(MAX_STRIDE/2) * MAX_HEIGHT]);
  72. LOCAL_ALIGNED_32(uint8_t, dst_v_1, [(MAX_STRIDE/2) * MAX_HEIGHT]);
  73. declare_func(void, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  74. const uint8_t *src, int width, int height,
  75. int lumStride, int chromStride, int srcStride);
  76. randomize_buffers(src0, MAX_STRIDE * MAX_HEIGHT * 2);
  77. memcpy(src1, src0, MAX_STRIDE * MAX_HEIGHT * 2);
  78. if (check_func(uyvytoyuv422, "uyvytoyuv422")) {
  79. for (i = 0; i < 6; i ++) {
  80. memset(dst_y_0, 0, MAX_STRIDE * MAX_HEIGHT);
  81. memset(dst_y_1, 0, MAX_STRIDE * MAX_HEIGHT);
  82. memset(dst_u_0, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
  83. memset(dst_u_1, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
  84. memset(dst_v_0, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
  85. memset(dst_v_1, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
  86. call_ref(dst_y_0, dst_u_0, dst_v_0, src0, planes[i].w, planes[i].h,
  87. MAX_STRIDE, MAX_STRIDE / 2, planes[i].s);
  88. call_new(dst_y_1, dst_u_1, dst_v_1, src1, planes[i].w, planes[i].h,
  89. MAX_STRIDE, MAX_STRIDE / 2, planes[i].s);
  90. if (memcmp(dst_y_0, dst_y_1, MAX_STRIDE * MAX_HEIGHT) ||
  91. memcmp(dst_u_0, dst_u_1, (MAX_STRIDE/2) * MAX_HEIGHT) ||
  92. memcmp(dst_v_0, dst_v_1, (MAX_STRIDE/2) * MAX_HEIGHT))
  93. fail();
  94. }
  95. bench_new(dst_y_1, dst_u_1, dst_v_1, src1, planes[5].w, planes[5].h,
  96. MAX_STRIDE, MAX_STRIDE / 2, planes[5].s);
  97. }
  98. }
  99. #define NUM_LINES 5
  100. #define MAX_LINE_SIZE 1920
  101. #define BUFSIZE (NUM_LINES * MAX_LINE_SIZE)
  102. static int cmp_off_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int accuracy)
  103. {
  104. for (size_t i = 0; i < n; i++) {
  105. if (abs(ref[i] - test[i]) > accuracy)
  106. return 1;
  107. }
  108. return 0;
  109. }
  110. static void check_rgb24toyv12(SwsContext *sws)
  111. {
  112. static const int input_sizes[] = {16, 128, 512, MAX_LINE_SIZE, -MAX_LINE_SIZE};
  113. SwsInternal *ctx = sws_internal(sws);
  114. LOCAL_ALIGNED_32(uint8_t, src, [BUFSIZE * 3]);
  115. LOCAL_ALIGNED_32(uint8_t, buf_y_0, [BUFSIZE]);
  116. LOCAL_ALIGNED_32(uint8_t, buf_y_1, [BUFSIZE]);
  117. LOCAL_ALIGNED_32(uint8_t, buf_u_0, [BUFSIZE / 4]);
  118. LOCAL_ALIGNED_32(uint8_t, buf_u_1, [BUFSIZE / 4]);
  119. LOCAL_ALIGNED_32(uint8_t, buf_v_0, [BUFSIZE / 4]);
  120. LOCAL_ALIGNED_32(uint8_t, buf_v_1, [BUFSIZE / 4]);
  121. declare_func(void, const uint8_t *src, uint8_t *ydst, uint8_t *udst,
  122. uint8_t *vdst, int width, int height, int lumStride,
  123. int chromStride, int srcStride, int32_t *rgb2yuv);
  124. randomize_buffers(src, BUFSIZE * 3);
  125. for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
  126. int input_size = input_sizes[isi];
  127. int negstride = input_size < 0;
  128. const char *negstride_str = negstride ? "_negstride" : "";
  129. int width = FFABS(input_size);
  130. int linesize = width + 32;
  131. /* calculate height based on specified width to use the entire buffer. */
  132. int height = (BUFSIZE / linesize) & ~1;
  133. uint8_t *src0 = src;
  134. uint8_t *src1 = src;
  135. uint8_t *dst_y_0 = buf_y_0;
  136. uint8_t *dst_y_1 = buf_y_1;
  137. uint8_t *dst_u_0 = buf_u_0;
  138. uint8_t *dst_u_1 = buf_u_1;
  139. uint8_t *dst_v_0 = buf_v_0;
  140. uint8_t *dst_v_1 = buf_v_1;
  141. if (negstride) {
  142. src0 += (height - 1) * (linesize * 3);
  143. src1 += (height - 1) * (linesize * 3);
  144. dst_y_0 += (height - 1) * linesize;
  145. dst_y_1 += (height - 1) * linesize;
  146. dst_u_0 += ((height / 2) - 1) * (linesize / 2);
  147. dst_u_1 += ((height / 2) - 1) * (linesize / 2);
  148. dst_v_0 += ((height / 2) - 1) * (linesize / 2);
  149. dst_v_1 += ((height / 2) - 1) * (linesize / 2);
  150. linesize *= -1;
  151. }
  152. if (check_func(ff_rgb24toyv12, "rgb24toyv12_%d_%d%s", width, height, negstride_str)) {
  153. memset(buf_y_0, 0xFF, BUFSIZE);
  154. memset(buf_y_1, 0xFF, BUFSIZE);
  155. memset(buf_u_0, 0xFF, BUFSIZE / 4);
  156. memset(buf_u_1, 0xFF, BUFSIZE / 4);
  157. memset(buf_v_0, 0xFF, BUFSIZE / 4);
  158. memset(buf_v_1, 0xFF, BUFSIZE / 4);
  159. call_ref(src0, dst_y_0, dst_u_0, dst_v_0, width, height,
  160. linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table);
  161. call_new(src1, dst_y_1, dst_u_1, dst_v_1, width, height,
  162. linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table);
  163. if (cmp_off_by_n(buf_y_0, buf_y_1, BUFSIZE, 1) ||
  164. cmp_off_by_n(buf_u_0, buf_u_1, BUFSIZE / 4, 1) ||
  165. cmp_off_by_n(buf_v_0, buf_v_1, BUFSIZE / 4, 1))
  166. fail();
  167. bench_new(src1, dst_y_1, dst_u_1, dst_v_1, width, height,
  168. linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table);
  169. }
  170. }
  171. }
  172. #undef NUM_LINES
  173. #undef MAX_LINE_SIZE
  174. #undef BUFSIZE
  175. static void check_interleave_bytes(void)
  176. {
  177. LOCAL_ALIGNED_16(uint8_t, src0_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  178. LOCAL_ALIGNED_16(uint8_t, src1_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  179. LOCAL_ALIGNED_16(uint8_t, dst0_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
  180. LOCAL_ALIGNED_16(uint8_t, dst1_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
  181. // Intentionally using unaligned buffers, as this function doesn't have
  182. // any alignment requirements.
  183. uint8_t *src0 = src0_buf + 1;
  184. uint8_t *src1 = src1_buf + 1;
  185. uint8_t *dst0 = dst0_buf + 2;
  186. uint8_t *dst1 = dst1_buf + 2;
  187. declare_func(void, const uint8_t *, const uint8_t *,
  188. uint8_t *, int, int, int, int, int);
  189. randomize_buffers(src0, MAX_STRIDE * MAX_HEIGHT);
  190. randomize_buffers(src1, MAX_STRIDE * MAX_HEIGHT);
  191. if (check_func(interleaveBytes, "interleave_bytes")) {
  192. for (int i = 0; i <= 16; i++) {
  193. // Try all widths [1,16], and try one random width.
  194. int w = i > 0 ? i : (1 + (rnd() % (MAX_STRIDE-2)));
  195. int h = 1 + (rnd() % (MAX_HEIGHT-2));
  196. int src0_offset = 0, src0_stride = MAX_STRIDE;
  197. int src1_offset = 0, src1_stride = MAX_STRIDE;
  198. int dst_offset = 0, dst_stride = 2 * MAX_STRIDE;
  199. memset(dst0, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
  200. memset(dst1, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
  201. // Try different combinations of negative strides
  202. if (i & 1) {
  203. src0_offset = (h-1)*src0_stride;
  204. src0_stride = -src0_stride;
  205. }
  206. if (i & 2) {
  207. src1_offset = (h-1)*src1_stride;
  208. src1_stride = -src1_stride;
  209. }
  210. if (i & 4) {
  211. dst_offset = (h-1)*dst_stride;
  212. dst_stride = -dst_stride;
  213. }
  214. call_ref(src0 + src0_offset, src1 + src1_offset, dst0 + dst_offset,
  215. w, h, src0_stride, src1_stride, dst_stride);
  216. call_new(src0 + src0_offset, src1 + src1_offset, dst1 + dst_offset,
  217. w, h, src0_stride, src1_stride, dst_stride);
  218. // Check a one pixel-pair edge around the destination area,
  219. // to catch overwrites past the end.
  220. checkasm_check(uint8_t, dst0, 2*MAX_STRIDE, dst1, 2*MAX_STRIDE,
  221. 2 * w + 2, h + 1, "dst");
  222. }
  223. bench_new(src0, src1, dst1, 127, MAX_HEIGHT,
  224. MAX_STRIDE, MAX_STRIDE, 2*MAX_STRIDE);
  225. }
  226. if (check_func(interleaveBytes, "interleave_bytes_aligned")) {
  227. // Bench the function in a more typical case, with aligned
  228. // buffers and widths.
  229. bench_new(src0_buf, src1_buf, dst1_buf, 128, MAX_HEIGHT,
  230. MAX_STRIDE, MAX_STRIDE, 2*MAX_STRIDE);
  231. }
  232. }
  233. static void check_deinterleave_bytes(void)
  234. {
  235. LOCAL_ALIGNED_16(uint8_t, src_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
  236. LOCAL_ALIGNED_16(uint8_t, dst0_u_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  237. LOCAL_ALIGNED_16(uint8_t, dst0_v_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  238. LOCAL_ALIGNED_16(uint8_t, dst1_u_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  239. LOCAL_ALIGNED_16(uint8_t, dst1_v_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  240. // Intentionally using unaligned buffers, as this function doesn't have
  241. // any alignment requirements.
  242. uint8_t *src = src_buf + 2;
  243. uint8_t *dst0_u = dst0_u_buf + 1;
  244. uint8_t *dst0_v = dst0_v_buf + 1;
  245. uint8_t *dst1_u = dst1_u_buf + 1;
  246. uint8_t *dst1_v = dst1_v_buf + 1;
  247. declare_func(void, const uint8_t *src, uint8_t *dst1, uint8_t *dst2,
  248. int width, int height, int srcStride,
  249. int dst1Stride, int dst2Stride);
  250. randomize_buffers(src, 2*MAX_STRIDE*MAX_HEIGHT);
  251. if (check_func(deinterleaveBytes, "deinterleave_bytes")) {
  252. for (int i = 0; i <= 16; i++) {
  253. // Try all widths [1,16], and try one random width.
  254. int w = i > 0 ? i : (1 + (rnd() % (MAX_STRIDE-2)));
  255. int h = 1 + (rnd() % (MAX_HEIGHT-2));
  256. int src_offset = 0, src_stride = 2 * MAX_STRIDE;
  257. int dst_u_offset = 0, dst_u_stride = MAX_STRIDE;
  258. int dst_v_offset = 0, dst_v_stride = MAX_STRIDE;
  259. memset(dst0_u, 0, MAX_STRIDE * MAX_HEIGHT);
  260. memset(dst0_v, 0, MAX_STRIDE * MAX_HEIGHT);
  261. memset(dst1_u, 0, MAX_STRIDE * MAX_HEIGHT);
  262. memset(dst1_v, 0, MAX_STRIDE * MAX_HEIGHT);
  263. // Try different combinations of negative strides
  264. if (i & 1) {
  265. src_offset = (h-1)*src_stride;
  266. src_stride = -src_stride;
  267. }
  268. if (i & 2) {
  269. dst_u_offset = (h-1)*dst_u_stride;
  270. dst_u_stride = -dst_u_stride;
  271. }
  272. if (i & 4) {
  273. dst_v_offset = (h-1)*dst_v_stride;
  274. dst_v_stride = -dst_v_stride;
  275. }
  276. call_ref(src + src_offset, dst0_u + dst_u_offset, dst0_v + dst_v_offset,
  277. w, h, src_stride, dst_u_stride, dst_v_stride);
  278. call_new(src + src_offset, dst1_u + dst_u_offset, dst1_v + dst_v_offset,
  279. w, h, src_stride, dst_u_stride, dst_v_stride);
  280. // Check a one pixel-pair edge around the destination area,
  281. // to catch overwrites past the end.
  282. checkasm_check(uint8_t, dst0_u, MAX_STRIDE, dst1_u, MAX_STRIDE,
  283. w + 1, h + 1, "dst_u");
  284. checkasm_check(uint8_t, dst0_v, MAX_STRIDE, dst1_v, MAX_STRIDE,
  285. w + 1, h + 1, "dst_v");
  286. }
  287. bench_new(src, dst1_u, dst1_v, 127, MAX_HEIGHT,
  288. 2*MAX_STRIDE, MAX_STRIDE, MAX_STRIDE);
  289. }
  290. if (check_func(deinterleaveBytes, "deinterleave_bytes_aligned")) {
  291. // Bench the function in a more typical case, with aligned
  292. // buffers and widths.
  293. bench_new(src_buf, dst1_u_buf, dst1_v_buf, 128, MAX_HEIGHT,
  294. 2*MAX_STRIDE, MAX_STRIDE, MAX_STRIDE);
  295. }
  296. }
  297. #define MAX_LINE_SIZE 1920
  298. static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE};
  299. static const enum AVPixelFormat rgb_formats[] = {
  300. AV_PIX_FMT_RGB24,
  301. AV_PIX_FMT_BGR24,
  302. AV_PIX_FMT_RGBA,
  303. AV_PIX_FMT_BGRA,
  304. AV_PIX_FMT_ABGR,
  305. AV_PIX_FMT_ARGB,
  306. };
  307. static void check_rgb_to_y(SwsContext *sws)
  308. {
  309. SwsInternal *ctx = sws_internal(sws);
  310. LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]);
  311. LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]);
  312. LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]);
  313. LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]);
  314. declare_func(void, uint8_t *dst, const uint8_t *src,
  315. const uint8_t *unused1, const uint8_t *unused2, int width,
  316. uint32_t *rgb2yuv, void *opq);
  317. randomize_buffers(src24, MAX_LINE_SIZE * 3);
  318. randomize_buffers(src32, MAX_LINE_SIZE * 4);
  319. for (int i = 0; i < FF_ARRAY_ELEMS(rgb_formats); i++) {
  320. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(rgb_formats[i]);
  321. sws->src_format = rgb_formats[i];
  322. ff_sws_init_scale(ctx);
  323. for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
  324. int w = input_sizes[j];
  325. if (check_func(ctx->lumToYV12, "%s_to_y_%d", desc->name, w)) {
  326. const uint8_t *src = desc->nb_components == 3 ? src24 : src32;
  327. memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2);
  328. memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2);
  329. call_ref(dst0_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
  330. call_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
  331. if (memcmp(dst0_y, dst1_y, w * 2))
  332. fail();
  333. if (desc->nb_components == 3 ||
  334. // only bench native endian formats
  335. (sws->src_format == AV_PIX_FMT_RGB32 || sws->src_format == AV_PIX_FMT_RGB32_1))
  336. bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
  337. }
  338. }
  339. }
  340. }
  341. static void check_rgb_to_uv(SwsContext *sws)
  342. {
  343. SwsInternal *ctx = sws_internal(sws);
  344. LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]);
  345. LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]);
  346. LOCAL_ALIGNED_16(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]);
  347. LOCAL_ALIGNED_16(uint8_t, dst0_v, [MAX_LINE_SIZE * 2]);
  348. LOCAL_ALIGNED_16(uint8_t, dst1_u, [MAX_LINE_SIZE * 2]);
  349. LOCAL_ALIGNED_16(uint8_t, dst1_v, [MAX_LINE_SIZE * 2]);
  350. declare_func(void, uint8_t *dstU, uint8_t *dstV,
  351. const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
  352. int width, uint32_t *pal, void *opq);
  353. randomize_buffers(src24, MAX_LINE_SIZE * 3);
  354. randomize_buffers(src32, MAX_LINE_SIZE * 4);
  355. for (int i = 0; i < 2 * FF_ARRAY_ELEMS(rgb_formats); i++) {
  356. enum AVPixelFormat src_fmt = rgb_formats[i / 2];
  357. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src_fmt);
  358. ctx->chrSrcHSubSample = (i % 2) ? 0 : 1;
  359. sws->src_format = src_fmt;
  360. sws->dst_format = ctx->chrSrcHSubSample ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P;
  361. ff_sws_init_scale(ctx);
  362. for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
  363. int w = input_sizes[j] >> ctx->chrSrcHSubSample;
  364. if (check_func(ctx->chrToYV12, "%s_to_uv%s_%d", desc->name,
  365. ctx->chrSrcHSubSample ? "_half" : "",
  366. input_sizes[j])) {
  367. const uint8_t *src = desc->nb_components == 3 ? src24 : src32;
  368. memset(dst0_u, 0xFF, MAX_LINE_SIZE * 2);
  369. memset(dst0_v, 0xFF, MAX_LINE_SIZE * 2);
  370. memset(dst1_u, 0xFF, MAX_LINE_SIZE * 2);
  371. memset(dst1_v, 0xFF, MAX_LINE_SIZE * 2);
  372. call_ref(dst0_u, dst0_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
  373. call_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
  374. if (memcmp(dst0_u, dst1_u, w * 2) || memcmp(dst0_v, dst1_v, w * 2))
  375. fail();
  376. if (desc->nb_components == 3 ||
  377. // only bench native endian formats
  378. (sws->src_format == AV_PIX_FMT_RGB32 || sws->src_format == AV_PIX_FMT_RGB32_1))
  379. bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
  380. }
  381. }
  382. }
  383. }
  384. static void check_rgba_to_a(SwsContext *sws)
  385. {
  386. SwsInternal *ctx = sws_internal(sws);
  387. LOCAL_ALIGNED_16(uint8_t, src, [MAX_LINE_SIZE * 4]);
  388. LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]);
  389. LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]);
  390. declare_func(void, uint8_t *dst, const uint8_t *src1,
  391. const uint8_t *src2, const uint8_t *src3, int width,
  392. uint32_t *rgb2yuv, void *opq);
  393. randomize_buffers(src, MAX_LINE_SIZE * 4);
  394. for (int i = 0; i < FF_ARRAY_ELEMS(rgb_formats); i++) {
  395. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(rgb_formats[i]);
  396. if (desc->nb_components < 4)
  397. continue;
  398. sws->src_format = rgb_formats[i];
  399. ff_sws_init_scale(ctx);
  400. for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
  401. int w = input_sizes[j];
  402. if (check_func(ctx->alpToYV12, "%s_to_y_%d", desc->name, w)) {
  403. memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2);
  404. memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2);
  405. call_ref(dst0_y, NULL, NULL, src, w, ctx->input_rgb2yuv_table, NULL);
  406. call_new(dst1_y, NULL, NULL, src, w, ctx->input_rgb2yuv_table, NULL);
  407. if (memcmp(dst0_y, dst1_y, w * 2))
  408. fail();
  409. // only bench native endian formats
  410. if (sws->src_format == AV_PIX_FMT_RGB32 || sws->src_format == AV_PIX_FMT_RGB32_1)
  411. bench_new(dst1_y, NULL, NULL, src, w, ctx->input_rgb2yuv_table, NULL);
  412. }
  413. }
  414. }
  415. }
  416. static const int packed_rgb_fmts[] = {
  417. AV_PIX_FMT_RGB24,
  418. AV_PIX_FMT_BGR24,
  419. AV_PIX_FMT_ARGB,
  420. AV_PIX_FMT_RGBA,
  421. AV_PIX_FMT_ABGR,
  422. AV_PIX_FMT_BGRA,
  423. AV_PIX_FMT_RGB48BE,
  424. AV_PIX_FMT_RGB48LE,
  425. AV_PIX_FMT_RGB565BE,
  426. AV_PIX_FMT_RGB565LE,
  427. AV_PIX_FMT_RGB555BE,
  428. AV_PIX_FMT_RGB555LE,
  429. AV_PIX_FMT_BGR565BE,
  430. AV_PIX_FMT_BGR565LE,
  431. AV_PIX_FMT_BGR555BE,
  432. AV_PIX_FMT_BGR555LE,
  433. AV_PIX_FMT_RGB444LE,
  434. AV_PIX_FMT_RGB444BE,
  435. AV_PIX_FMT_BGR444LE,
  436. AV_PIX_FMT_BGR444BE,
  437. AV_PIX_FMT_BGR48BE,
  438. AV_PIX_FMT_BGR48LE,
  439. AV_PIX_FMT_RGBA64BE,
  440. AV_PIX_FMT_RGBA64LE,
  441. AV_PIX_FMT_BGRA64BE,
  442. AV_PIX_FMT_BGRA64LE,
  443. AV_PIX_FMT_RGB8,
  444. AV_PIX_FMT_BGR8,
  445. AV_PIX_FMT_RGB4,
  446. AV_PIX_FMT_BGR4,
  447. AV_PIX_FMT_RGB4_BYTE,
  448. AV_PIX_FMT_BGR4_BYTE,
  449. };
  450. #define INPUT_SIZE 512
  451. static void check_yuv2packed1(void)
  452. {
  453. static const int alpha_values[] = {0, 2048, 4096};
  454. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT,
  455. void, SwsInternal *c, const int16_t *lumSrc,
  456. const int16_t *chrUSrc[2], const int16_t *chrVSrc[2],
  457. const int16_t *alpSrc, uint8_t *dest,
  458. int dstW, int uvalpha, int y);
  459. const int16_t *luma;
  460. const int16_t *chru[2];
  461. const int16_t *chrv[2];
  462. const int16_t *alpha;
  463. LOCAL_ALIGNED_8(int32_t, src_y, [2 * INPUT_SIZE]);
  464. LOCAL_ALIGNED_8(int32_t, src_u, [2 * INPUT_SIZE]);
  465. LOCAL_ALIGNED_8(int32_t, src_v, [2 * INPUT_SIZE]);
  466. LOCAL_ALIGNED_8(int32_t, src_a, [2 * INPUT_SIZE]);
  467. LOCAL_ALIGNED_8(uint8_t, dst0, [INPUT_SIZE * sizeof(int32_t[4])]);
  468. LOCAL_ALIGNED_8(uint8_t, dst1, [INPUT_SIZE * sizeof(int32_t[4])]);
  469. randomize_buffers((uint8_t*)src_y, 2 * INPUT_SIZE * sizeof(int32_t));
  470. randomize_buffers((uint8_t*)src_u, 2 * INPUT_SIZE * sizeof(int32_t));
  471. randomize_buffers((uint8_t*)src_v, 2 * INPUT_SIZE * sizeof(int32_t));
  472. randomize_buffers((uint8_t*)src_a, 2 * INPUT_SIZE * sizeof(int32_t));
  473. /* Limit to 14 bit input range */
  474. for (int i = 0; i < 2 * INPUT_SIZE; i++) {
  475. src_y[i] &= 0x3FFF3FFF;
  476. src_a[i] &= 0x3FFF3FFF;
  477. src_u[i] &= 0x3FFF3FFF;
  478. src_v[i] &= 0x3FFF3FFF;
  479. }
  480. luma = (int16_t *)src_y;
  481. alpha = (int16_t *)src_a;
  482. for (int i = 0; i < 2; i++) {
  483. chru[i] = (int16_t *)(src_u + i*INPUT_SIZE);
  484. chrv[i] = (int16_t *)(src_v + i*INPUT_SIZE);
  485. }
  486. for (int fmi = 0; fmi < FF_ARRAY_ELEMS(packed_rgb_fmts); fmi++) {
  487. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(packed_rgb_fmts[fmi]);
  488. int line_size = INPUT_SIZE * desc->comp[0].step;
  489. SwsContext *sws;
  490. SwsInternal *c;
  491. if (desc->flags & AV_PIX_FMT_FLAG_BITSTREAM)
  492. line_size = AV_CEIL_RSHIFT(line_size, 3);
  493. sws = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
  494. MAX_LINE_SIZE, MAX_LINE_SIZE, packed_rgb_fmts[fmi],
  495. SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
  496. if (!sws)
  497. fail();
  498. c = sws_internal(sws);
  499. for (int ai = 0; ai < FF_ARRAY_ELEMS(alpha_values); ai++) {
  500. const int chr_alpha = alpha_values[ai];
  501. if (check_func(c->yuv2packed1, "yuv2%s_1_%d_%d", desc->name, chr_alpha, INPUT_SIZE)) {
  502. memset(dst0, 0xFF, INPUT_SIZE * sizeof(int32_t[4]));
  503. memset(dst1, 0xFF, INPUT_SIZE * sizeof(int32_t[4]));
  504. call_ref(c, luma, chru, chrv, alpha, dst0, INPUT_SIZE, chr_alpha, 0);
  505. call_new(c, luma, chru, chrv, alpha, dst1, INPUT_SIZE, chr_alpha, 0);
  506. if (memcmp(dst0, dst1, line_size))
  507. fail();
  508. bench_new(c, luma, chru, chrv, alpha, dst1, INPUT_SIZE, chr_alpha, 0);
  509. }
  510. }
  511. sws_freeContext(sws);
  512. }
  513. }
  514. static void check_yuv2packed2(void)
  515. {
  516. static const int alpha_values[] = {0, 2048, 4096};
  517. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT,
  518. void, SwsInternal *c, const int16_t *lumSrc[2],
  519. const int16_t *chrUSrc[2], const int16_t *chrVSrc[2],
  520. const int16_t *alpSrc[2], uint8_t *dest,
  521. int dstW, int yalpha, int uvalpha, int y);
  522. const int16_t *luma[2];
  523. const int16_t *chru[2];
  524. const int16_t *chrv[2];
  525. const int16_t *alpha[2];
  526. LOCAL_ALIGNED_8(int32_t, src_y, [2 * INPUT_SIZE]);
  527. LOCAL_ALIGNED_8(int32_t, src_u, [2 * INPUT_SIZE]);
  528. LOCAL_ALIGNED_8(int32_t, src_v, [2 * INPUT_SIZE]);
  529. LOCAL_ALIGNED_8(int32_t, src_a, [2 * INPUT_SIZE]);
  530. LOCAL_ALIGNED_8(uint8_t, dst0, [INPUT_SIZE * sizeof(int32_t[4])]);
  531. LOCAL_ALIGNED_8(uint8_t, dst1, [INPUT_SIZE * sizeof(int32_t[4])]);
  532. randomize_buffers((uint8_t*)src_y, 2 * INPUT_SIZE * sizeof(int32_t));
  533. randomize_buffers((uint8_t*)src_u, 2 * INPUT_SIZE * sizeof(int32_t));
  534. randomize_buffers((uint8_t*)src_v, 2 * INPUT_SIZE * sizeof(int32_t));
  535. randomize_buffers((uint8_t*)src_a, 2 * INPUT_SIZE * sizeof(int32_t));
  536. /* Limit to 14 bit input range */
  537. for (int i = 0; i < 2 * INPUT_SIZE; i++) {
  538. src_y[i] &= 0x3FFF3FFF;
  539. src_u[i] &= 0x3FFF3FFF;
  540. src_v[i] &= 0x3FFF3FFF;
  541. src_a[i] &= 0x3FFF3FFF;
  542. }
  543. for (int i = 0; i < 2; i++) {
  544. luma[i] = (int16_t *)(src_y + i*INPUT_SIZE);
  545. chru[i] = (int16_t *)(src_u + i*INPUT_SIZE);
  546. chrv[i] = (int16_t *)(src_v + i*INPUT_SIZE);
  547. alpha[i] = (int16_t *)(src_a + i*INPUT_SIZE);
  548. }
  549. for (int fmi = 0; fmi < FF_ARRAY_ELEMS(packed_rgb_fmts); fmi++) {
  550. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(packed_rgb_fmts[fmi]);
  551. int line_size = INPUT_SIZE * desc->comp[0].step;
  552. SwsContext *sws;
  553. SwsInternal *c;
  554. if (desc->flags & AV_PIX_FMT_FLAG_BITSTREAM)
  555. line_size = AV_CEIL_RSHIFT(line_size, 3);
  556. sws = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
  557. MAX_LINE_SIZE, MAX_LINE_SIZE, packed_rgb_fmts[fmi],
  558. SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
  559. if (!sws)
  560. fail();
  561. c = sws_internal(sws);
  562. for (int ai = 0; ai < FF_ARRAY_ELEMS(alpha_values); ai++) {
  563. const int lum_alpha = alpha_values[ai];
  564. const int chr_alpha = alpha_values[ai];
  565. if (check_func(c->yuv2packed2, "yuv2%s_2_%d_%d", desc->name, lum_alpha, INPUT_SIZE)) {
  566. memset(dst0, 0xFF, INPUT_SIZE * sizeof(int32_t[4]));
  567. memset(dst1, 0xFF, INPUT_SIZE * sizeof(int32_t[4]));
  568. call_ref(c, luma, chru, chrv, alpha, dst0, INPUT_SIZE, lum_alpha, chr_alpha, 0);
  569. call_new(c, luma, chru, chrv, alpha, dst1, INPUT_SIZE, lum_alpha, chr_alpha, 0);
  570. if (memcmp(dst0, dst1, line_size))
  571. fail();
  572. bench_new(c, luma, chru, chrv, alpha, dst1, INPUT_SIZE, lum_alpha, chr_alpha, 0);
  573. }
  574. }
  575. sws_freeContext(sws);
  576. }
  577. }
  578. static void check_yuv2packedX(void)
  579. {
  580. #define LARGEST_FILTER 16
  581. static const int filter_sizes[] = {2, 16};
  582. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT,
  583. void, SwsInternal *c, const int16_t *lumFilter,
  584. const int16_t **lumSrcx, int lumFilterSize,
  585. const int16_t *chrFilter, const int16_t **chrUSrcx,
  586. const int16_t **chrVSrcx, int chrFilterSize,
  587. const int16_t **alpSrcx, uint8_t *dest,
  588. int dstW, int y);
  589. const int16_t *luma[LARGEST_FILTER];
  590. const int16_t *chru[LARGEST_FILTER];
  591. const int16_t *chrv[LARGEST_FILTER];
  592. const int16_t *alpha[LARGEST_FILTER];
  593. LOCAL_ALIGNED_8(int16_t, luma_filter, [LARGEST_FILTER]);
  594. LOCAL_ALIGNED_8(int16_t, chr_filter, [LARGEST_FILTER]);
  595. LOCAL_ALIGNED_8(int32_t, src_y, [LARGEST_FILTER * INPUT_SIZE]);
  596. LOCAL_ALIGNED_8(int32_t, src_u, [LARGEST_FILTER * INPUT_SIZE]);
  597. LOCAL_ALIGNED_8(int32_t, src_v, [LARGEST_FILTER * INPUT_SIZE]);
  598. LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_FILTER * INPUT_SIZE]);
  599. LOCAL_ALIGNED_8(uint8_t, dst0, [INPUT_SIZE * sizeof(int32_t[4])]);
  600. LOCAL_ALIGNED_8(uint8_t, dst1, [INPUT_SIZE * sizeof(int32_t[4])]);
  601. randomize_buffers((uint8_t*)src_y, LARGEST_FILTER * INPUT_SIZE * sizeof(int32_t));
  602. randomize_buffers((uint8_t*)src_u, LARGEST_FILTER * INPUT_SIZE * sizeof(int32_t));
  603. randomize_buffers((uint8_t*)src_v, LARGEST_FILTER * INPUT_SIZE * sizeof(int32_t));
  604. randomize_buffers((uint8_t*)src_a, LARGEST_FILTER * INPUT_SIZE * sizeof(int32_t));
  605. /* Limit to 14 bit input range */
  606. for (int i = 0; i < LARGEST_FILTER * INPUT_SIZE; i++) {
  607. src_y[i] &= 0x3FFF3FFF;
  608. src_u[i] &= 0x3FFF3FFF;
  609. src_v[i] &= 0x3FFF3FFF;
  610. src_a[i] &= 0x3FFF3FFF;
  611. }
  612. for (int i = 0; i < LARGEST_FILTER; i++) {
  613. luma[i] = (int16_t *)(src_y + i*INPUT_SIZE);
  614. chru[i] = (int16_t *)(src_u + i*INPUT_SIZE);
  615. chrv[i] = (int16_t *)(src_v + i*INPUT_SIZE);
  616. alpha[i] = (int16_t *)(src_a + i*INPUT_SIZE);
  617. }
  618. for (int fmi = 0; fmi < FF_ARRAY_ELEMS(packed_rgb_fmts); fmi++) {
  619. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(packed_rgb_fmts[fmi]);
  620. int line_size = INPUT_SIZE * desc->comp[0].step;
  621. SwsContext *sws;
  622. SwsInternal *c;
  623. if (desc->flags & AV_PIX_FMT_FLAG_BITSTREAM)
  624. line_size = AV_CEIL_RSHIFT(line_size, 3);
  625. sws = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
  626. MAX_LINE_SIZE, MAX_LINE_SIZE, packed_rgb_fmts[fmi],
  627. SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
  628. if (!sws)
  629. fail();
  630. c = sws_internal(sws);
  631. for (int fsi = 0; fsi < FF_ARRAY_ELEMS(filter_sizes); fsi++) {
  632. const int luma_filter_size = filter_sizes[fsi];
  633. const int chr_filter_size = filter_sizes[fsi];
  634. for (int i = 0; i < luma_filter_size; i++)
  635. luma_filter[i] = -((1 << 12) / (luma_filter_size - 1));
  636. luma_filter[rnd() % luma_filter_size] = (1 << 13) - 1;
  637. for (int i = 0; i < chr_filter_size; i++)
  638. chr_filter[i] = -((1 << 12) / (chr_filter_size - 1));
  639. chr_filter[rnd() % chr_filter_size] = (1 << 13) - 1;
  640. if (check_func(c->yuv2packedX, "yuv2%s_X_%d_%d", desc->name, luma_filter_size, INPUT_SIZE)) {
  641. memset(dst0, 0xFF, INPUT_SIZE * sizeof(int32_t[4]));
  642. memset(dst1, 0xFF, INPUT_SIZE * sizeof(int32_t[4]));
  643. call_ref(c, luma_filter, luma, luma_filter_size,
  644. chr_filter, chru, chrv, chr_filter_size,
  645. alpha, dst0, INPUT_SIZE, 0);
  646. call_new(c, luma_filter, luma, luma_filter_size,
  647. chr_filter, chru, chrv, chr_filter_size,
  648. alpha, dst1, INPUT_SIZE, 0);
  649. if (memcmp(dst0, dst1, line_size))
  650. fail();
  651. bench_new(c, luma_filter, luma, luma_filter_size,
  652. chr_filter, chru, chrv, chr_filter_size,
  653. alpha, dst1, INPUT_SIZE, 0);
  654. }
  655. }
  656. sws_freeContext(sws);
  657. }
  658. }
  659. #undef INPUT_SIZE
  660. #undef LARGEST_FILTER
  661. void checkasm_check_sw_rgb(void)
  662. {
  663. SwsContext *sws;
  664. ff_sws_rgb2rgb_init();
  665. check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103");
  666. report("shuffle_bytes_2103");
  667. check_shuffle_bytes(shuffle_bytes_0321, "shuffle_bytes_0321");
  668. report("shuffle_bytes_0321");
  669. check_shuffle_bytes(shuffle_bytes_1230, "shuffle_bytes_1230");
  670. report("shuffle_bytes_1230");
  671. check_shuffle_bytes(shuffle_bytes_3012, "shuffle_bytes_3012");
  672. report("shuffle_bytes_3012");
  673. check_shuffle_bytes(shuffle_bytes_3210, "shuffle_bytes_3210");
  674. report("shuffle_bytes_3210");
  675. check_uyvy_to_422p();
  676. report("uyvytoyuv422");
  677. check_interleave_bytes();
  678. report("interleave_bytes");
  679. check_deinterleave_bytes();
  680. report("deinterleave_bytes");
  681. sws = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24,
  682. MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
  683. SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
  684. if (!sws)
  685. fail();
  686. check_rgb_to_y(sws);
  687. report("rgb_to_y");
  688. check_rgb_to_uv(sws);
  689. report("rgb_to_uv");
  690. check_rgba_to_a(sws);
  691. report("rgba_to_a");
  692. check_rgb24toyv12(sws);
  693. report("rgb24toyv12");
  694. sws_freeContext(sws);
  695. check_yuv2packed1();
  696. report("yuv2packed1");
  697. check_yuv2packed2();
  698. report("yuv2packed2");
  699. check_yuv2packedX();
  700. report("yuv2packedX");
  701. }