sw_rgb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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(struct SwsContext *ctx)
  111. {
  112. static const int input_sizes[] = {16, 128, 512, MAX_LINE_SIZE, -MAX_LINE_SIZE};
  113. LOCAL_ALIGNED_32(uint8_t, src, [BUFSIZE * 3]);
  114. LOCAL_ALIGNED_32(uint8_t, buf_y_0, [BUFSIZE]);
  115. LOCAL_ALIGNED_32(uint8_t, buf_y_1, [BUFSIZE]);
  116. LOCAL_ALIGNED_32(uint8_t, buf_u_0, [BUFSIZE / 4]);
  117. LOCAL_ALIGNED_32(uint8_t, buf_u_1, [BUFSIZE / 4]);
  118. LOCAL_ALIGNED_32(uint8_t, buf_v_0, [BUFSIZE / 4]);
  119. LOCAL_ALIGNED_32(uint8_t, buf_v_1, [BUFSIZE / 4]);
  120. declare_func(void, const uint8_t *src, uint8_t *ydst, uint8_t *udst,
  121. uint8_t *vdst, int width, int height, int lumStride,
  122. int chromStride, int srcStride, int32_t *rgb2yuv);
  123. randomize_buffers(src, BUFSIZE * 3);
  124. for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
  125. int input_size = input_sizes[isi];
  126. int negstride = input_size < 0;
  127. const char *negstride_str = negstride ? "_negstride" : "";
  128. int width = FFABS(input_size);
  129. int linesize = width + 32;
  130. /* calculate height based on specified width to use the entire buffer. */
  131. int height = (BUFSIZE / linesize) & ~1;
  132. uint8_t *src0 = src;
  133. uint8_t *src1 = src;
  134. uint8_t *dst_y_0 = buf_y_0;
  135. uint8_t *dst_y_1 = buf_y_1;
  136. uint8_t *dst_u_0 = buf_u_0;
  137. uint8_t *dst_u_1 = buf_u_1;
  138. uint8_t *dst_v_0 = buf_v_0;
  139. uint8_t *dst_v_1 = buf_v_1;
  140. if (negstride) {
  141. src0 += (height - 1) * (linesize * 3);
  142. src1 += (height - 1) * (linesize * 3);
  143. dst_y_0 += (height - 1) * linesize;
  144. dst_y_1 += (height - 1) * linesize;
  145. dst_u_0 += ((height / 2) - 1) * (linesize / 2);
  146. dst_u_1 += ((height / 2) - 1) * (linesize / 2);
  147. dst_v_0 += ((height / 2) - 1) * (linesize / 2);
  148. dst_v_1 += ((height / 2) - 1) * (linesize / 2);
  149. linesize *= -1;
  150. }
  151. if (check_func(ff_rgb24toyv12, "rgb24toyv12_%d_%d%s", width, height, negstride_str)) {
  152. memset(buf_y_0, 0xFF, BUFSIZE);
  153. memset(buf_y_1, 0xFF, BUFSIZE);
  154. memset(buf_u_0, 0xFF, BUFSIZE / 4);
  155. memset(buf_u_1, 0xFF, BUFSIZE / 4);
  156. memset(buf_v_0, 0xFF, BUFSIZE / 4);
  157. memset(buf_v_1, 0xFF, BUFSIZE / 4);
  158. call_ref(src0, dst_y_0, dst_u_0, dst_v_0, width, height,
  159. linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table);
  160. call_new(src1, dst_y_1, dst_u_1, dst_v_1, width, height,
  161. linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table);
  162. if (cmp_off_by_n(buf_y_0, buf_y_1, BUFSIZE, 1) ||
  163. cmp_off_by_n(buf_u_0, buf_u_1, BUFSIZE / 4, 1) ||
  164. cmp_off_by_n(buf_v_0, buf_v_1, BUFSIZE / 4, 1))
  165. fail();
  166. bench_new(src1, dst_y_1, dst_u_1, dst_v_1, width, height,
  167. linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table);
  168. }
  169. }
  170. }
  171. #undef NUM_LINES
  172. #undef MAX_LINE_SIZE
  173. #undef BUFSIZE
  174. static void check_interleave_bytes(void)
  175. {
  176. LOCAL_ALIGNED_16(uint8_t, src0_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  177. LOCAL_ALIGNED_16(uint8_t, src1_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  178. LOCAL_ALIGNED_16(uint8_t, dst0_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
  179. LOCAL_ALIGNED_16(uint8_t, dst1_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
  180. // Intentionally using unaligned buffers, as this function doesn't have
  181. // any alignment requirements.
  182. uint8_t *src0 = src0_buf + 1;
  183. uint8_t *src1 = src1_buf + 1;
  184. uint8_t *dst0 = dst0_buf + 2;
  185. uint8_t *dst1 = dst1_buf + 2;
  186. declare_func(void, const uint8_t *, const uint8_t *,
  187. uint8_t *, int, int, int, int, int);
  188. randomize_buffers(src0, MAX_STRIDE * MAX_HEIGHT);
  189. randomize_buffers(src1, MAX_STRIDE * MAX_HEIGHT);
  190. if (check_func(interleaveBytes, "interleave_bytes")) {
  191. for (int i = 0; i <= 16; i++) {
  192. // Try all widths [1,16], and try one random width.
  193. int w = i > 0 ? i : (1 + (rnd() % (MAX_STRIDE-2)));
  194. int h = 1 + (rnd() % (MAX_HEIGHT-2));
  195. int src0_offset = 0, src0_stride = MAX_STRIDE;
  196. int src1_offset = 0, src1_stride = MAX_STRIDE;
  197. int dst_offset = 0, dst_stride = 2 * MAX_STRIDE;
  198. memset(dst0, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
  199. memset(dst1, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
  200. // Try different combinations of negative strides
  201. if (i & 1) {
  202. src0_offset = (h-1)*src0_stride;
  203. src0_stride = -src0_stride;
  204. }
  205. if (i & 2) {
  206. src1_offset = (h-1)*src1_stride;
  207. src1_stride = -src1_stride;
  208. }
  209. if (i & 4) {
  210. dst_offset = (h-1)*dst_stride;
  211. dst_stride = -dst_stride;
  212. }
  213. call_ref(src0 + src0_offset, src1 + src1_offset, dst0 + dst_offset,
  214. w, h, src0_stride, src1_stride, dst_stride);
  215. call_new(src0 + src0_offset, src1 + src1_offset, dst1 + dst_offset,
  216. w, h, src0_stride, src1_stride, dst_stride);
  217. // Check a one pixel-pair edge around the destination area,
  218. // to catch overwrites past the end.
  219. checkasm_check(uint8_t, dst0, 2*MAX_STRIDE, dst1, 2*MAX_STRIDE,
  220. 2 * w + 2, h + 1, "dst");
  221. }
  222. bench_new(src0, src1, dst1, 127, MAX_HEIGHT,
  223. MAX_STRIDE, MAX_STRIDE, 2*MAX_STRIDE);
  224. }
  225. if (check_func(interleaveBytes, "interleave_bytes_aligned")) {
  226. // Bench the function in a more typical case, with aligned
  227. // buffers and widths.
  228. bench_new(src0_buf, src1_buf, dst1_buf, 128, MAX_HEIGHT,
  229. MAX_STRIDE, MAX_STRIDE, 2*MAX_STRIDE);
  230. }
  231. }
  232. static void check_deinterleave_bytes(void)
  233. {
  234. LOCAL_ALIGNED_16(uint8_t, src_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
  235. LOCAL_ALIGNED_16(uint8_t, dst0_u_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  236. LOCAL_ALIGNED_16(uint8_t, dst0_v_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  237. LOCAL_ALIGNED_16(uint8_t, dst1_u_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  238. LOCAL_ALIGNED_16(uint8_t, dst1_v_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
  239. // Intentionally using unaligned buffers, as this function doesn't have
  240. // any alignment requirements.
  241. uint8_t *src = src_buf + 2;
  242. uint8_t *dst0_u = dst0_u_buf + 1;
  243. uint8_t *dst0_v = dst0_v_buf + 1;
  244. uint8_t *dst1_u = dst1_u_buf + 1;
  245. uint8_t *dst1_v = dst1_v_buf + 1;
  246. declare_func(void, const uint8_t *src, uint8_t *dst1, uint8_t *dst2,
  247. int width, int height, int srcStride,
  248. int dst1Stride, int dst2Stride);
  249. randomize_buffers(src, 2*MAX_STRIDE*MAX_HEIGHT+2);
  250. if (check_func(deinterleaveBytes, "deinterleave_bytes")) {
  251. for (int i = 0; i <= 16; i++) {
  252. // Try all widths [1,16], and try one random width.
  253. int w = i > 0 ? i : (1 + (rnd() % (MAX_STRIDE-2)));
  254. int h = 1 + (rnd() % (MAX_HEIGHT-2));
  255. int src_offset = 0, src_stride = 2 * MAX_STRIDE;
  256. int dst_u_offset = 0, dst_u_stride = MAX_STRIDE;
  257. int dst_v_offset = 0, dst_v_stride = MAX_STRIDE;
  258. memset(dst0_u, 0, MAX_STRIDE * MAX_HEIGHT);
  259. memset(dst0_v, 0, MAX_STRIDE * MAX_HEIGHT);
  260. memset(dst1_u, 0, MAX_STRIDE * MAX_HEIGHT);
  261. memset(dst1_v, 0, MAX_STRIDE * MAX_HEIGHT);
  262. // Try different combinations of negative strides
  263. if (i & 1) {
  264. src_offset = (h-1)*src_stride;
  265. src_stride = -src_stride;
  266. }
  267. if (i & 2) {
  268. dst_u_offset = (h-1)*dst_u_stride;
  269. dst_u_stride = -dst_u_stride;
  270. }
  271. if (i & 4) {
  272. dst_v_offset = (h-1)*dst_v_stride;
  273. dst_v_stride = -dst_v_stride;
  274. }
  275. call_ref(src + src_offset, dst0_u + dst_u_offset, dst0_v + dst_v_offset,
  276. w, h, src_stride, dst_u_stride, dst_v_stride);
  277. call_new(src + src_offset, dst1_u + dst_u_offset, dst1_v + dst_v_offset,
  278. w, h, src_stride, dst_u_stride, dst_v_stride);
  279. // Check a one pixel-pair edge around the destination area,
  280. // to catch overwrites past the end.
  281. checkasm_check(uint8_t, dst0_u, MAX_STRIDE, dst1_u, MAX_STRIDE,
  282. w + 1, h + 1, "dst_u");
  283. checkasm_check(uint8_t, dst0_v, MAX_STRIDE, dst1_v, MAX_STRIDE,
  284. w + 1, h + 1, "dst_v");
  285. }
  286. bench_new(src, dst1_u, dst1_v, 127, MAX_HEIGHT,
  287. 2*MAX_STRIDE, MAX_STRIDE, MAX_STRIDE);
  288. }
  289. if (check_func(deinterleaveBytes, "deinterleave_bytes_aligned")) {
  290. // Bench the function in a more typical case, with aligned
  291. // buffers and widths.
  292. bench_new(src_buf, dst1_u_buf, dst1_v_buf, 128, MAX_HEIGHT,
  293. 2*MAX_STRIDE, MAX_STRIDE, MAX_STRIDE);
  294. }
  295. }
  296. #define MAX_LINE_SIZE 1920
  297. static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE};
  298. static const enum AVPixelFormat rgb_formats[] = {
  299. AV_PIX_FMT_RGB24,
  300. AV_PIX_FMT_BGR24,
  301. AV_PIX_FMT_RGBA,
  302. AV_PIX_FMT_BGRA,
  303. AV_PIX_FMT_ABGR,
  304. AV_PIX_FMT_ARGB,
  305. };
  306. static void check_rgb_to_y(struct SwsContext *ctx)
  307. {
  308. LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]);
  309. LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]);
  310. LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]);
  311. LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]);
  312. declare_func(void, uint8_t *dst, const uint8_t *src,
  313. const uint8_t *unused1, const uint8_t *unused2, int width,
  314. uint32_t *rgb2yuv, void *opq);
  315. randomize_buffers(src24, MAX_LINE_SIZE * 3);
  316. randomize_buffers(src32, MAX_LINE_SIZE * 4);
  317. for (int i = 0; i < FF_ARRAY_ELEMS(rgb_formats); i++) {
  318. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(rgb_formats[i]);
  319. ctx->srcFormat = rgb_formats[i];
  320. ff_sws_init_scale(ctx);
  321. for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
  322. int w = input_sizes[j];
  323. if (check_func(ctx->lumToYV12, "%s_to_y_%d", desc->name, w)) {
  324. const uint8_t *src = desc->nb_components == 3 ? src24 : src32;
  325. memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2);
  326. memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2);
  327. call_ref(dst0_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
  328. call_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
  329. if (memcmp(dst0_y, dst1_y, w * 2))
  330. fail();
  331. if (desc->nb_components == 3 ||
  332. // only bench native endian formats
  333. (ctx->srcFormat == AV_PIX_FMT_RGB32 || ctx->srcFormat == AV_PIX_FMT_RGB32_1))
  334. bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
  335. }
  336. }
  337. }
  338. }
  339. static void check_rgb_to_uv(struct SwsContext *ctx)
  340. {
  341. LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]);
  342. LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]);
  343. LOCAL_ALIGNED_16(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]);
  344. LOCAL_ALIGNED_16(uint8_t, dst0_v, [MAX_LINE_SIZE * 2]);
  345. LOCAL_ALIGNED_16(uint8_t, dst1_u, [MAX_LINE_SIZE * 2]);
  346. LOCAL_ALIGNED_16(uint8_t, dst1_v, [MAX_LINE_SIZE * 2]);
  347. declare_func(void, uint8_t *dstU, uint8_t *dstV,
  348. const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
  349. int width, uint32_t *pal, void *opq);
  350. randomize_buffers(src24, MAX_LINE_SIZE * 3);
  351. randomize_buffers(src32, MAX_LINE_SIZE * 4);
  352. for (int i = 0; i < 2 * FF_ARRAY_ELEMS(rgb_formats); i++) {
  353. enum AVPixelFormat src_fmt = rgb_formats[i / 2];
  354. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src_fmt);
  355. ctx->chrSrcHSubSample = (i % 2) ? 0 : 1;
  356. ctx->srcFormat = src_fmt;
  357. ctx->dstFormat = ctx->chrSrcHSubSample ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P;
  358. ff_sws_init_scale(ctx);
  359. for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
  360. int w = input_sizes[j] >> ctx->chrSrcHSubSample;
  361. if (check_func(ctx->chrToYV12, "%s_to_uv%s_%d", desc->name,
  362. ctx->chrSrcHSubSample ? "_half" : "",
  363. input_sizes[j])) {
  364. const uint8_t *src = desc->nb_components == 3 ? src24 : src32;
  365. memset(dst0_u, 0xFF, MAX_LINE_SIZE * 2);
  366. memset(dst0_v, 0xFF, MAX_LINE_SIZE * 2);
  367. memset(dst1_u, 0xFF, MAX_LINE_SIZE * 2);
  368. memset(dst1_v, 0xFF, MAX_LINE_SIZE * 2);
  369. call_ref(dst0_u, dst0_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
  370. call_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
  371. if (memcmp(dst0_u, dst1_u, w * 2) || memcmp(dst0_v, dst1_v, w * 2))
  372. fail();
  373. if (desc->nb_components == 3 ||
  374. // only bench native endian formats
  375. (ctx->srcFormat == AV_PIX_FMT_RGB32 || ctx->srcFormat == AV_PIX_FMT_RGB32_1))
  376. bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
  377. }
  378. }
  379. }
  380. }
  381. void checkasm_check_sw_rgb(void)
  382. {
  383. struct SwsContext *ctx;
  384. ff_sws_rgb2rgb_init();
  385. check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103");
  386. report("shuffle_bytes_2103");
  387. check_shuffle_bytes(shuffle_bytes_0321, "shuffle_bytes_0321");
  388. report("shuffle_bytes_0321");
  389. check_shuffle_bytes(shuffle_bytes_1230, "shuffle_bytes_1230");
  390. report("shuffle_bytes_1230");
  391. check_shuffle_bytes(shuffle_bytes_3012, "shuffle_bytes_3012");
  392. report("shuffle_bytes_3012");
  393. check_shuffle_bytes(shuffle_bytes_3210, "shuffle_bytes_3210");
  394. report("shuffle_bytes_3210");
  395. check_uyvy_to_422p();
  396. report("uyvytoyuv422");
  397. check_interleave_bytes();
  398. report("interleave_bytes");
  399. check_deinterleave_bytes();
  400. report("deinterleave_bytes");
  401. ctx = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24,
  402. MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
  403. SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
  404. if (!ctx)
  405. fail();
  406. check_rgb_to_y(ctx);
  407. report("rgb_to_y");
  408. check_rgb_to_uv(ctx);
  409. report("rgb_to_uv");
  410. check_rgb24toyv12(ctx);
  411. report("rgb24toyv12");
  412. sws_freeContext(ctx);
  413. }