swscale_unscaled.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. 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. return 0; \
  51. } \
  52. #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \
  53. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \
  54. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \
  55. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \
  56. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \
  57. DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv420p)
  58. DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv422p)
  59. #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt) \
  60. int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
  61. uint8_t *dst, int linesize, \
  62. const uint8_t *srcY, int linesizeY, \
  63. const uint8_t *srcC, int linesizeC, \
  64. const int16_t *table, \
  65. int y_offset, \
  66. int y_coeff); \
  67. \
  68. static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
  69. int srcStride[], int srcSliceY, int srcSliceH, \
  70. uint8_t *dst[], int dstStride[]) { \
  71. const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
  72. \
  73. ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
  74. dst[0] + srcSliceY * dstStride[0], dstStride[0], \
  75. src[0], srcStride[0], src[1], srcStride[1], \
  76. yuv2rgb_table, \
  77. c->yuv2rgb_y_offset >> 6, \
  78. c->yuv2rgb_y_coeff); \
  79. \
  80. return 0; \
  81. } \
  82. #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
  83. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
  84. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
  85. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
  86. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
  87. DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv12)
  88. DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21)
  89. /* We need a 16 pixel width alignment. This constraint can easily be removed
  90. * for input reading but for the output which is 4-bytes per pixel (RGBA) the
  91. * assembly might be writing as much as 4*15=60 extra bytes at the end of the
  92. * line, which won't fit the 32-bytes buffer alignment. */
  93. #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
  94. if (c->srcFormat == AV_PIX_FMT_##IFMT \
  95. && c->dstFormat == AV_PIX_FMT_##OFMT \
  96. && !(c->srcH & 1) \
  97. && !(c->srcW & 15) \
  98. && !accurate_rnd) \
  99. c->swscale = ifmt##_to_##ofmt##_neon_wrapper; \
  100. } while (0)
  101. #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
  102. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
  103. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
  104. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
  105. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
  106. } while (0)
  107. static void get_unscaled_swscale_neon(SwsContext *c) {
  108. int accurate_rnd = c->flags & SWS_ACCURATE_RND;
  109. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
  110. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
  111. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
  112. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
  113. }
  114. void ff_get_unscaled_swscale_aarch64(SwsContext *c)
  115. {
  116. int cpu_flags = av_get_cpu_flags();
  117. if (have_neon(cpu_flags))
  118. get_unscaled_swscale_neon(c);
  119. }