swscale_unscaled.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright (C) 2013 Xiaolei Yu <dreifachstein@gmail.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "config.h"
  21. #include "libswscale/swscale.h"
  22. #include "libswscale/swscale_internal.h"
  23. #include "libavutil/arm/cpu.h"
  24. #if HAVE_AS_DN_DIRECTIVE
  25. extern void rgbx_to_nv12_neon_32(const uint8_t *src, uint8_t *y, uint8_t *chroma,
  26. int width, int height,
  27. int y_stride, int c_stride, int src_stride,
  28. int32_t coeff_tbl[9]);
  29. extern void rgbx_to_nv12_neon_16(const uint8_t *src, uint8_t *y, uint8_t *chroma,
  30. int width, int height,
  31. int y_stride, int c_stride, int src_stride,
  32. int32_t coeff_tbl[9]);
  33. static int rgbx_to_nv12_neon_32_wrapper(SwsContext *context, const uint8_t *src[],
  34. int srcStride[], int srcSliceY, int srcSliceH,
  35. uint8_t *dst[], int dstStride[]) {
  36. rgbx_to_nv12_neon_32(src[0] + srcSliceY * srcStride[0],
  37. dst[0] + srcSliceY * dstStride[0],
  38. dst[1] + (srcSliceY / 2) * dstStride[1],
  39. context->srcW, srcSliceH,
  40. dstStride[0], dstStride[1], srcStride[0],
  41. context->input_rgb2yuv_table);
  42. return 0;
  43. }
  44. static int rgbx_to_nv12_neon_16_wrapper(SwsContext *context, const uint8_t *src[],
  45. int srcStride[], int srcSliceY, int srcSliceH,
  46. uint8_t *dst[], int dstStride[]) {
  47. rgbx_to_nv12_neon_16(src[0] + srcSliceY * srcStride[0],
  48. dst[0] + srcSliceY * dstStride[0],
  49. dst[1] + (srcSliceY / 2) * dstStride[1],
  50. context->srcW, srcSliceH,
  51. dstStride[0], dstStride[1], srcStride[0],
  52. context->input_rgb2yuv_table);
  53. return 0;
  54. }
  55. #define YUV_TO_RGB_TABLE \
  56. c->yuv2rgb_v2r_coeff, \
  57. c->yuv2rgb_u2g_coeff, \
  58. c->yuv2rgb_v2g_coeff, \
  59. c->yuv2rgb_u2b_coeff, \
  60. #define DECLARE_FF_YUVX_TO_RGBX_FUNCS(ifmt, ofmt) \
  61. int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
  62. uint8_t *dst, int linesize, \
  63. const uint8_t *srcY, int linesizeY, \
  64. const uint8_t *srcU, int linesizeU, \
  65. const uint8_t *srcV, int linesizeV, \
  66. const int16_t *table, \
  67. int y_offset, \
  68. int y_coeff); \
  69. \
  70. static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
  71. int srcStride[], int srcSliceY, int srcSliceH, \
  72. uint8_t *dst[], int dstStride[]) { \
  73. const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
  74. \
  75. ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
  76. dst[0] + srcSliceY * dstStride[0], dstStride[0], \
  77. src[0], srcStride[0], \
  78. src[1], srcStride[1], \
  79. src[2], srcStride[2], \
  80. yuv2rgb_table, \
  81. c->yuv2rgb_y_offset >> 6, \
  82. c->yuv2rgb_y_coeff); \
  83. \
  84. return 0; \
  85. } \
  86. #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \
  87. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \
  88. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \
  89. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \
  90. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \
  91. DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv420p)
  92. DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv422p)
  93. #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt) \
  94. int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
  95. uint8_t *dst, int linesize, \
  96. const uint8_t *srcY, int linesizeY, \
  97. const uint8_t *srcC, int linesizeC, \
  98. const int16_t *table, \
  99. int y_offset, \
  100. int y_coeff); \
  101. \
  102. static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
  103. int srcStride[], int srcSliceY, int srcSliceH, \
  104. uint8_t *dst[], int dstStride[]) { \
  105. const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
  106. \
  107. ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
  108. dst[0] + srcSliceY * dstStride[0], dstStride[0], \
  109. src[0], srcStride[0], src[1], srcStride[1], \
  110. yuv2rgb_table, \
  111. c->yuv2rgb_y_offset >> 6, \
  112. c->yuv2rgb_y_coeff); \
  113. \
  114. return 0; \
  115. } \
  116. #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
  117. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
  118. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
  119. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
  120. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
  121. DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv12)
  122. DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21)
  123. /* We need a 16 pixel width alignment. This constraint can easily be removed
  124. * for input reading but for the output which is 4-bytes per pixel (RGBA) the
  125. * assembly might be writing as much as 4*15=60 extra bytes at the end of the
  126. * line, which won't fit the 32-bytes buffer alignment. */
  127. #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
  128. if (c->srcFormat == AV_PIX_FMT_##IFMT \
  129. && c->dstFormat == AV_PIX_FMT_##OFMT \
  130. && !(c->srcH & 1) \
  131. && !(c->srcW & 15) \
  132. && !accurate_rnd) { \
  133. c->convert_unscaled = ifmt##_to_##ofmt##_neon_wrapper; \
  134. } \
  135. } while (0)
  136. #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
  137. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
  138. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
  139. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
  140. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
  141. } while (0)
  142. static void get_unscaled_swscale_neon(SwsContext *c) {
  143. int accurate_rnd = c->flags & SWS_ACCURATE_RND;
  144. if (c->srcFormat == AV_PIX_FMT_RGBA
  145. && c->dstFormat == AV_PIX_FMT_NV12
  146. && (c->srcW >= 16)) {
  147. c->convert_unscaled = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper
  148. : rgbx_to_nv12_neon_16_wrapper;
  149. }
  150. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
  151. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
  152. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
  153. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
  154. }
  155. void ff_get_unscaled_swscale_arm(SwsContext *c)
  156. {
  157. int cpu_flags = av_get_cpu_flags();
  158. if (have_neon(cpu_flags))
  159. get_unscaled_swscale_neon(c);
  160. }
  161. #else
  162. void ff_get_unscaled_swscale_arm(SwsContext *c)
  163. {
  164. }
  165. #endif