sw_gbrp.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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/swscale.h"
  25. #include "libswscale/swscale_internal.h"
  26. #include "checkasm.h"
  27. #define randomize_buffers(buf, size) \
  28. do { \
  29. int j; \
  30. for (j = 0; j < size; j+=4) \
  31. AV_WN32(buf + j, rnd()); \
  32. } while (0)
  33. static const int planar_fmts[] = {
  34. AV_PIX_FMT_GBRP,
  35. AV_PIX_FMT_GBRP9BE,
  36. AV_PIX_FMT_GBRP9LE,
  37. AV_PIX_FMT_GBRP10BE,
  38. AV_PIX_FMT_GBRP10LE,
  39. AV_PIX_FMT_GBRP12BE,
  40. AV_PIX_FMT_GBRP12LE,
  41. AV_PIX_FMT_GBRP14BE,
  42. AV_PIX_FMT_GBRP14LE,
  43. AV_PIX_FMT_GBRAP,
  44. AV_PIX_FMT_GBRAP10BE,
  45. AV_PIX_FMT_GBRAP10LE,
  46. AV_PIX_FMT_GBRAP12BE,
  47. AV_PIX_FMT_GBRAP12LE,
  48. AV_PIX_FMT_GBRP16BE,
  49. AV_PIX_FMT_GBRP16LE,
  50. AV_PIX_FMT_GBRAP16BE,
  51. AV_PIX_FMT_GBRAP16LE,
  52. AV_PIX_FMT_GBRPF32BE,
  53. AV_PIX_FMT_GBRPF32LE,
  54. AV_PIX_FMT_GBRAPF32BE,
  55. AV_PIX_FMT_GBRAPF32LE
  56. };
  57. static void check_output_yuv2gbrp(void)
  58. {
  59. struct SwsContext *ctx;
  60. const AVPixFmtDescriptor *desc;
  61. int fmi, fsi, isi, i;
  62. int dstW, byte_size, luma_filter_size, chr_filter_size;
  63. #define LARGEST_FILTER 16
  64. #define FILTER_SIZES 4
  65. static const int filter_sizes[] = {1, 4, 8, 16};
  66. #define LARGEST_INPUT_SIZE 512
  67. #define INPUT_SIZES 6
  68. static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
  69. uint8_t *dst0[4];
  70. uint8_t *dst1[4];
  71. declare_func(void, struct SwsContext *c, const int16_t *lumFilter,
  72. const int16_t **lumSrcx, int lumFilterSize,
  73. const int16_t *chrFilter, const int16_t **chrUSrcx,
  74. const int16_t **chrVSrcx, int chrFilterSize,
  75. const int16_t **alpSrcx, uint8_t **dest,
  76. int dstW, int y);
  77. const int16_t *luma[LARGEST_FILTER];
  78. const int16_t *chru[LARGEST_FILTER];
  79. const int16_t *chrv[LARGEST_FILTER];
  80. const int16_t *alpha[LARGEST_FILTER];
  81. LOCAL_ALIGNED_8(int16_t, luma_filter, [LARGEST_FILTER]);
  82. LOCAL_ALIGNED_8(int16_t, chr_filter, [LARGEST_FILTER]);
  83. LOCAL_ALIGNED_8(int32_t, src_y, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
  84. LOCAL_ALIGNED_8(int32_t, src_u, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
  85. LOCAL_ALIGNED_8(int32_t, src_v, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
  86. LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
  87. LOCAL_ALIGNED_8(uint8_t, dst0_r, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  88. LOCAL_ALIGNED_8(uint8_t, dst0_g, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  89. LOCAL_ALIGNED_8(uint8_t, dst0_b, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  90. LOCAL_ALIGNED_8(uint8_t, dst0_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  91. LOCAL_ALIGNED_8(uint8_t, dst1_r, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  92. LOCAL_ALIGNED_8(uint8_t, dst1_g, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  93. LOCAL_ALIGNED_8(uint8_t, dst1_b, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  94. LOCAL_ALIGNED_8(uint8_t, dst1_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  95. randomize_buffers((uint8_t*)src_y, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t));
  96. randomize_buffers((uint8_t*)src_u, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t));
  97. randomize_buffers((uint8_t*)src_v, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t));
  98. randomize_buffers((uint8_t*)src_a, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t));
  99. randomize_buffers((uint8_t*)luma_filter, LARGEST_FILTER * sizeof(int16_t));
  100. randomize_buffers((uint8_t*)chr_filter, LARGEST_FILTER * sizeof(int16_t));
  101. dst0[0] = (uint8_t*)dst0_g;
  102. dst0[1] = (uint8_t*)dst0_b;
  103. dst0[2] = (uint8_t*)dst0_r;
  104. dst0[3] = (uint8_t*)dst0_a;
  105. dst1[0] = (uint8_t*)dst1_g;
  106. dst1[1] = (uint8_t*)dst1_b;
  107. dst1[2] = (uint8_t*)dst1_r;
  108. dst1[3] = (uint8_t*)dst1_a;
  109. for (i = 0; i < LARGEST_FILTER; i++) {
  110. luma[i] = (int16_t *)(src_y + i*LARGEST_INPUT_SIZE);
  111. chru[i] = (int16_t *)(src_u + i*LARGEST_INPUT_SIZE);
  112. chrv[i] = (int16_t *)(src_v + i*LARGEST_INPUT_SIZE);
  113. alpha[i] = (int16_t *)(src_a + i*LARGEST_INPUT_SIZE);
  114. }
  115. ctx = sws_alloc_context();
  116. if (sws_init_context(ctx, NULL, NULL) < 0)
  117. fail();
  118. ctx->flags |= SWS_FULL_CHR_H_INT;
  119. ctx->yuv2rgb_y_offset = rnd();
  120. ctx->yuv2rgb_y_coeff = rnd();
  121. ctx->yuv2rgb_v2r_coeff = rnd();
  122. ctx->yuv2rgb_v2g_coeff = rnd();
  123. ctx->yuv2rgb_u2g_coeff = rnd();
  124. ctx->yuv2rgb_u2b_coeff = rnd();
  125. for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) {
  126. for (fsi = 0; fsi < FILTER_SIZES; fsi++) {
  127. for (isi = 0; isi < INPUT_SIZES; isi++ ) {
  128. desc = av_pix_fmt_desc_get(planar_fmts[fmi]);
  129. ctx->dstFormat = planar_fmts[fmi];
  130. dstW = input_sizes[isi];
  131. luma_filter_size = filter_sizes[fsi];
  132. chr_filter_size = filter_sizes[fsi];
  133. if (desc->comp[0].depth > 16) {
  134. byte_size = 4;
  135. } else if (desc->comp[0].depth > 8) {
  136. byte_size = 2;
  137. } else {
  138. byte_size = 1;
  139. }
  140. ff_sws_init_scale(ctx);
  141. if (check_func(ctx->yuv2anyX, "yuv2%s_full_X_%d_%d", desc->name, luma_filter_size, dstW)) {
  142. for (i = 0; i < 4; i ++) {
  143. memset(dst0[i], 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
  144. memset(dst1[i], 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
  145. }
  146. call_ref(ctx, luma_filter, luma, luma_filter_size,
  147. chr_filter, chru, chrv, chr_filter_size,
  148. alpha, dst0, dstW, 0);
  149. call_new(ctx, luma_filter, luma, luma_filter_size,
  150. chr_filter, chru, chrv, chr_filter_size,
  151. alpha, dst1, dstW, 0);
  152. if (memcmp(dst0[0], dst1[0], dstW * byte_size) ||
  153. memcmp(dst0[1], dst1[1], dstW * byte_size) ||
  154. memcmp(dst0[2], dst1[2], dstW * byte_size) ||
  155. memcmp(dst0[3], dst1[3], dstW * byte_size) )
  156. fail();
  157. bench_new(ctx, luma_filter, luma, luma_filter_size,
  158. chr_filter, chru, chrv, chr_filter_size,
  159. alpha, dst1, dstW, 0);
  160. }
  161. }
  162. }
  163. }
  164. sws_freeContext(ctx);
  165. }
  166. #undef LARGEST_INPUT_SIZE
  167. #undef INPUT_SIZES
  168. static void check_input_planar_rgb_to_y(void)
  169. {
  170. struct SwsContext *ctx;
  171. const AVPixFmtDescriptor *desc;
  172. int fmi, isi;
  173. int dstW, byte_size;
  174. #define LARGEST_INPUT_SIZE 512
  175. #define INPUT_SIZES 6
  176. static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
  177. const uint8_t *src[4];
  178. int32_t rgb2yuv[9] = {0};
  179. declare_func(void, uint8_t *dst, const uint8_t *src[4],
  180. int w, int32_t *rgb2yuv, void *opaque);
  181. LOCAL_ALIGNED_8(int32_t, src_r, [LARGEST_INPUT_SIZE]);
  182. LOCAL_ALIGNED_8(int32_t, src_g, [LARGEST_INPUT_SIZE]);
  183. LOCAL_ALIGNED_8(int32_t, src_b, [LARGEST_INPUT_SIZE]);
  184. LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_INPUT_SIZE]);
  185. LOCAL_ALIGNED_8(uint8_t, dst0_y, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  186. LOCAL_ALIGNED_8(uint8_t, dst1_y, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  187. randomize_buffers((uint8_t*)src_r, LARGEST_INPUT_SIZE * sizeof(int32_t));
  188. randomize_buffers((uint8_t*)src_g, LARGEST_INPUT_SIZE * sizeof(int32_t));
  189. randomize_buffers((uint8_t*)src_b, LARGEST_INPUT_SIZE * sizeof(int32_t));
  190. randomize_buffers((uint8_t*)src_a, LARGEST_INPUT_SIZE * sizeof(int32_t));
  191. randomize_buffers((uint8_t*)rgb2yuv, 9 * sizeof(int32_t));
  192. src[0] = (uint8_t*)src_g;
  193. src[1] = (uint8_t*)src_b;
  194. src[2] = (uint8_t*)src_r;
  195. src[3] = (uint8_t*)src_a;
  196. ctx = sws_alloc_context();
  197. if (sws_init_context(ctx, NULL, NULL) < 0)
  198. fail();
  199. for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) {
  200. for (isi = 0; isi < INPUT_SIZES; isi++ ) {
  201. desc = av_pix_fmt_desc_get(planar_fmts[fmi]);
  202. ctx->srcFormat = planar_fmts[fmi];
  203. ctx->dstFormat = AV_PIX_FMT_YUVA444P16;
  204. byte_size = 2;
  205. dstW = input_sizes[isi];
  206. ff_sws_init_scale(ctx);
  207. if(check_func(ctx->readLumPlanar, "planar_%s_to_y_%d", desc->name, dstW)) {
  208. memset(dst0_y, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
  209. memset(dst1_y, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
  210. call_ref(dst0_y, src, dstW, rgb2yuv, NULL);
  211. call_new(dst1_y, src, dstW, rgb2yuv, NULL);
  212. if (memcmp(dst0_y, dst1_y, dstW * byte_size))
  213. fail();
  214. bench_new(dst1_y, src, dstW, rgb2yuv, NULL);
  215. }
  216. }
  217. }
  218. sws_freeContext(ctx);
  219. }
  220. #undef LARGEST_INPUT_SIZE
  221. #undef INPUT_SIZES
  222. static void check_input_planar_rgb_to_uv(void)
  223. {
  224. struct SwsContext *ctx;
  225. const AVPixFmtDescriptor *desc;
  226. int fmi, isi;
  227. int dstW, byte_size;
  228. #define LARGEST_INPUT_SIZE 512
  229. #define INPUT_SIZES 6
  230. static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
  231. const uint8_t *src[4];
  232. int32_t rgb2yuv[9] = {0};
  233. declare_func(void, uint8_t *dstU, uint8_t *dstV,
  234. const uint8_t *src[4], int w, int32_t *rgb2yuv, void *opaque);
  235. LOCAL_ALIGNED_8(int32_t, src_r, [LARGEST_INPUT_SIZE]);
  236. LOCAL_ALIGNED_8(int32_t, src_g, [LARGEST_INPUT_SIZE]);
  237. LOCAL_ALIGNED_8(int32_t, src_b, [LARGEST_INPUT_SIZE]);
  238. LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_INPUT_SIZE]);
  239. LOCAL_ALIGNED_8(uint8_t, dst0_u, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  240. LOCAL_ALIGNED_8(uint8_t, dst0_v, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  241. LOCAL_ALIGNED_8(uint8_t, dst1_u, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  242. LOCAL_ALIGNED_8(uint8_t, dst1_v, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  243. randomize_buffers((uint8_t*)src_r, LARGEST_INPUT_SIZE * sizeof(int32_t));
  244. randomize_buffers((uint8_t*)src_g, LARGEST_INPUT_SIZE * sizeof(int32_t));
  245. randomize_buffers((uint8_t*)src_b, LARGEST_INPUT_SIZE * sizeof(int32_t));
  246. randomize_buffers((uint8_t*)src_a, LARGEST_INPUT_SIZE * sizeof(int32_t));
  247. randomize_buffers((uint8_t*)rgb2yuv, 9 * sizeof(int32_t));
  248. src[0] = (uint8_t*)src_g;
  249. src[1] = (uint8_t*)src_b;
  250. src[2] = (uint8_t*)src_r;
  251. src[3] = (uint8_t*)src_a;
  252. ctx = sws_alloc_context();
  253. if (sws_init_context(ctx, NULL, NULL) < 0)
  254. fail();
  255. for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) {
  256. for (isi = 0; isi < INPUT_SIZES; isi++ ) {
  257. desc = av_pix_fmt_desc_get(planar_fmts[fmi]);
  258. ctx->srcFormat = planar_fmts[fmi];
  259. ctx->dstFormat = AV_PIX_FMT_YUVA444P16;
  260. byte_size = 2;
  261. dstW = input_sizes[isi];
  262. ff_sws_init_scale(ctx);
  263. if(check_func(ctx->readChrPlanar, "planar_%s_to_uv_%d", desc->name, dstW)) {
  264. memset(dst0_u, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
  265. memset(dst0_v, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
  266. memset(dst1_u, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
  267. memset(dst1_v, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
  268. call_ref(dst0_u, dst0_v, src, dstW, rgb2yuv, NULL);
  269. call_new(dst1_u, dst1_v, src, dstW, rgb2yuv, NULL);
  270. if (memcmp(dst0_u, dst1_u, dstW * byte_size) ||
  271. memcmp(dst0_v, dst1_v, dstW * byte_size))
  272. fail();
  273. bench_new(dst1_u, dst1_v, src, dstW, rgb2yuv, NULL);
  274. }
  275. }
  276. }
  277. sws_freeContext(ctx);
  278. }
  279. #undef LARGEST_INPUT_SIZE
  280. #undef INPUT_SIZES
  281. static void check_input_planar_rgb_to_a(void)
  282. {
  283. struct SwsContext *ctx;
  284. const AVPixFmtDescriptor *desc;
  285. int fmi, isi;
  286. int dstW, byte_size;
  287. #define LARGEST_INPUT_SIZE 512
  288. #define INPUT_SIZES 6
  289. static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
  290. const uint8_t *src[4];
  291. int32_t rgb2yuv[9] = {0};
  292. declare_func(void, uint8_t *dst, const uint8_t *src[4],
  293. int w, int32_t *rgb2yuv, void *opaque);
  294. LOCAL_ALIGNED_8(int32_t, src_r, [LARGEST_INPUT_SIZE]);
  295. LOCAL_ALIGNED_8(int32_t, src_g, [LARGEST_INPUT_SIZE]);
  296. LOCAL_ALIGNED_8(int32_t, src_b, [LARGEST_INPUT_SIZE]);
  297. LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_INPUT_SIZE]);
  298. LOCAL_ALIGNED_8(uint8_t, dst0_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  299. LOCAL_ALIGNED_8(uint8_t, dst1_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
  300. randomize_buffers((uint8_t*)src_r, LARGEST_INPUT_SIZE * sizeof(int32_t));
  301. randomize_buffers((uint8_t*)src_g, LARGEST_INPUT_SIZE * sizeof(int32_t));
  302. randomize_buffers((uint8_t*)src_b, LARGEST_INPUT_SIZE * sizeof(int32_t));
  303. randomize_buffers((uint8_t*)src_a, LARGEST_INPUT_SIZE * sizeof(int32_t));
  304. randomize_buffers((uint8_t*)rgb2yuv, 9 * sizeof(int32_t));
  305. src[0] = (uint8_t*)src_g;
  306. src[1] = (uint8_t*)src_b;
  307. src[2] = (uint8_t*)src_r;
  308. src[3] = (uint8_t*)src_a;
  309. ctx = sws_alloc_context();
  310. if (sws_init_context(ctx, NULL, NULL) < 0)
  311. fail();
  312. for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) {
  313. for (isi = 0; isi < INPUT_SIZES; isi++ ) {
  314. desc = av_pix_fmt_desc_get(planar_fmts[fmi]);
  315. if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
  316. continue;
  317. ctx->srcFormat = planar_fmts[fmi];
  318. ctx->dstFormat = AV_PIX_FMT_YUVA444P16;
  319. byte_size = 2;
  320. dstW = input_sizes[isi];
  321. ff_sws_init_scale(ctx);
  322. if(check_func(ctx->readAlpPlanar, "planar_%s_to_a_%d", desc->name, dstW)) {
  323. memset(dst0_a, 0x00, LARGEST_INPUT_SIZE * sizeof(int32_t));
  324. memset(dst1_a, 0x00, LARGEST_INPUT_SIZE * sizeof(int32_t));
  325. call_ref(dst0_a, src, dstW, rgb2yuv, NULL);
  326. call_new(dst1_a, src, dstW, rgb2yuv, NULL);
  327. if (memcmp(dst0_a, dst1_a, dstW * byte_size))
  328. fail();
  329. bench_new(dst1_a, src, dstW, rgb2yuv, NULL);
  330. }
  331. }
  332. }
  333. sws_freeContext(ctx);
  334. }
  335. void checkasm_check_sw_gbrp(void)
  336. {
  337. check_output_yuv2gbrp();
  338. report("output_yuv2gbrp");
  339. check_input_planar_rgb_to_y();
  340. report("input_planar_rgb_y");
  341. check_input_planar_rgb_to_uv();
  342. report("input_planar_rgb_uv");
  343. check_input_planar_rgb_to_a();
  344. report("input_planar_rgb_a");
  345. }