sw_yuv2yuv.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include <string.h>
  19. #include "libavutil/common.h"
  20. #include "libavutil/intreadwrite.h"
  21. #include "libavutil/mem_internal.h"
  22. #include "libavutil/pixdesc.h"
  23. #include "libswscale/swscale.h"
  24. #include "libswscale/swscale_internal.h"
  25. #include "checkasm.h"
  26. #define randomize_buffers(buf, size) \
  27. do { \
  28. for (int j = 0; j < size; j += 4) \
  29. AV_WN32(buf + j, rnd()); \
  30. } while (0)
  31. static void check_semiplanar(int dst_pix_fmt)
  32. {
  33. static const int src_fmts[] = {
  34. AV_PIX_FMT_NV24,
  35. AV_PIX_FMT_NV42,
  36. };
  37. const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
  38. #define NUM_LINES 4
  39. #define MAX_LINE_SIZE 1920
  40. static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE};
  41. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT,
  42. int, SwsInternal *c, const uint8_t *src[],
  43. int srcStride[], int srcSliceY, int srcSliceH,
  44. uint8_t *dst[], int dstStride[]);
  45. LOCAL_ALIGNED_8(uint8_t, src_y, [MAX_LINE_SIZE * NUM_LINES]);
  46. LOCAL_ALIGNED_8(uint8_t, src_uv, [MAX_LINE_SIZE * NUM_LINES * 2]);
  47. const uint8_t *src[4] = { src_y, src_uv };
  48. LOCAL_ALIGNED_8(uint8_t, dst0_y, [MAX_LINE_SIZE * NUM_LINES]);
  49. LOCAL_ALIGNED_8(uint8_t, dst0_u, [MAX_LINE_SIZE * NUM_LINES / 2]);
  50. LOCAL_ALIGNED_8(uint8_t, dst0_v, [MAX_LINE_SIZE * NUM_LINES / 2]);
  51. uint8_t *dst0[4] = { dst0_y, dst0_u, dst0_v };
  52. LOCAL_ALIGNED_8(uint8_t, dst1_y, [MAX_LINE_SIZE * NUM_LINES]);
  53. LOCAL_ALIGNED_8(uint8_t, dst1_u, [MAX_LINE_SIZE * NUM_LINES / 2]);
  54. LOCAL_ALIGNED_8(uint8_t, dst1_v, [MAX_LINE_SIZE * NUM_LINES / 2]);
  55. uint8_t *dst1[4] = { dst1_y, dst1_u, dst1_v };
  56. randomize_buffers(src_y, MAX_LINE_SIZE * NUM_LINES);
  57. randomize_buffers(src_uv, MAX_LINE_SIZE * NUM_LINES * 2);
  58. for (int sfi = 0; sfi < FF_ARRAY_ELEMS(src_fmts); sfi++) {
  59. int src_pix_fmt = src_fmts[sfi];
  60. const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
  61. for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
  62. SwsContext *sws;
  63. SwsInternal *c;
  64. int log_level;
  65. int width = input_sizes[isi];
  66. int srcSliceY = 0;
  67. int srcSliceH = NUM_LINES;
  68. int srcStride[4] = {
  69. MAX_LINE_SIZE,
  70. MAX_LINE_SIZE * 2,
  71. };
  72. int dstStride[4] = {
  73. MAX_LINE_SIZE,
  74. MAX_LINE_SIZE >> dst_desc->log2_chroma_w,
  75. MAX_LINE_SIZE >> dst_desc->log2_chroma_w,
  76. };
  77. // override log level to prevent spamming of the message
  78. // "No accelerated colorspace conversion found from %s to %s"
  79. log_level = av_log_get_level();
  80. av_log_set_level(AV_LOG_ERROR);
  81. sws = sws_getContext(width, srcSliceH, src_pix_fmt,
  82. width, srcSliceH, dst_pix_fmt,
  83. 0, NULL, NULL, NULL);
  84. av_log_set_level(log_level);
  85. if (!sws)
  86. fail();
  87. c = sws_internal(sws);
  88. if (check_func(c->convert_unscaled, "%s_%s_%d", src_desc->name, dst_desc->name, width)) {
  89. memset(dst0_y, 0xFF, MAX_LINE_SIZE * NUM_LINES);
  90. memset(dst0_u, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
  91. memset(dst0_v, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
  92. memset(dst1_y, 0xFF, MAX_LINE_SIZE * NUM_LINES);
  93. memset(dst1_u, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
  94. memset(dst1_v, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
  95. call_ref(c, src, srcStride, srcSliceY,
  96. srcSliceH, dst0, dstStride);
  97. call_new(c, src, srcStride, srcSliceY,
  98. srcSliceH, dst1, dstStride);
  99. if (memcmp(dst0_y, dst1_y, MAX_LINE_SIZE * NUM_LINES) ||
  100. memcmp(dst0_u, dst1_u, MAX_LINE_SIZE * NUM_LINES / 2) ||
  101. memcmp(dst0_v, dst1_v, MAX_LINE_SIZE * NUM_LINES / 2))
  102. fail();
  103. bench_new(c, src, srcStride, srcSliceY,
  104. srcSliceH, dst0, dstStride);
  105. }
  106. sws_freeContext(sws);
  107. }
  108. }
  109. }
  110. #undef NUM_LINES
  111. #undef MAX_LINE_SIZE
  112. void checkasm_check_sw_yuv2yuv(void)
  113. {
  114. check_semiplanar(AV_PIX_FMT_YUV420P);
  115. report("yuv420p");
  116. }