swscale_unscaled.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (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 GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "libswscale/swscale.h"
  20. #include "libswscale/swscale_internal.h"
  21. #include "libavutil/aarch64/cpu.h"
  22. #define YUV_TO_RGB_TABLE \
  23. c->yuv2rgb_v2r_coeff, \
  24. c->yuv2rgb_u2g_coeff, \
  25. c->yuv2rgb_v2g_coeff, \
  26. c->yuv2rgb_u2b_coeff, \
  27. #define DECLARE_FF_YUVX_TO_RGBX_FUNCS(ifmt, ofmt) \
  28. int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
  29. uint8_t *dst, int linesize, \
  30. const uint8_t *srcY, int linesizeY, \
  31. const uint8_t *srcU, int linesizeU, \
  32. const uint8_t *srcV, int linesizeV, \
  33. const int16_t *table, \
  34. int y_offset, \
  35. int y_coeff); \
  36. \
  37. static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
  38. int srcStride[], int srcSliceY, int srcSliceH, \
  39. uint8_t *dst[], int dstStride[]) { \
  40. const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
  41. \
  42. return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
  43. dst[0] + srcSliceY * dstStride[0], dstStride[0], \
  44. src[0], srcStride[0], \
  45. src[1], srcStride[1], \
  46. src[2], srcStride[2], \
  47. yuv2rgb_table, \
  48. c->yuv2rgb_y_offset >> 6, \
  49. c->yuv2rgb_y_coeff); \
  50. } \
  51. #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \
  52. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \
  53. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \
  54. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \
  55. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \
  56. DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv420p)
  57. DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv422p)
  58. #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt) \
  59. int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
  60. uint8_t *dst, int linesize, \
  61. const uint8_t *srcY, int linesizeY, \
  62. const uint8_t *srcC, int linesizeC, \
  63. const int16_t *table, \
  64. int y_offset, \
  65. int y_coeff); \
  66. \
  67. static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
  68. int srcStride[], int srcSliceY, int srcSliceH, \
  69. uint8_t *dst[], int dstStride[]) { \
  70. const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
  71. \
  72. return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
  73. dst[0] + srcSliceY * dstStride[0], dstStride[0], \
  74. src[0], srcStride[0], src[1], srcStride[1], \
  75. yuv2rgb_table, \
  76. c->yuv2rgb_y_offset >> 6, \
  77. c->yuv2rgb_y_coeff); \
  78. } \
  79. #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
  80. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
  81. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
  82. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
  83. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
  84. DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv12)
  85. DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21)
  86. /* We need a 16 pixel width alignment. This constraint can easily be removed
  87. * for input reading but for the output which is 4-bytes per pixel (RGBA) the
  88. * assembly might be writing as much as 4*15=60 extra bytes at the end of the
  89. * line, which won't fit the 32-bytes buffer alignment. */
  90. #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
  91. if (c->srcFormat == AV_PIX_FMT_##IFMT \
  92. && c->dstFormat == AV_PIX_FMT_##OFMT \
  93. && !(c->srcH & 1) \
  94. && !(c->srcW & 15) \
  95. && !accurate_rnd) \
  96. c->convert_unscaled = ifmt##_to_##ofmt##_neon_wrapper; \
  97. } while (0)
  98. #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
  99. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
  100. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
  101. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
  102. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
  103. } while (0)
  104. static void get_unscaled_swscale_neon(SwsContext *c) {
  105. int accurate_rnd = c->flags & SWS_ACCURATE_RND;
  106. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
  107. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
  108. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
  109. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
  110. }
  111. void ff_get_unscaled_swscale_aarch64(SwsContext *c)
  112. {
  113. int cpu_flags = av_get_cpu_flags();
  114. if (have_neon(cpu_flags))
  115. get_unscaled_swscale_neon(c);
  116. }