You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
11KB

  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. extern void rgbx_to_nv12_neon_32(const uint8_t *src, uint8_t *y, uint8_t *chroma,
  25. int width, int height,
  26. int y_stride, int c_stride, int src_stride,
  27. int32_t coeff_tbl[9]);
  28. extern void rgbx_to_nv12_neon_16(const uint8_t *src, uint8_t *y, uint8_t *chroma,
  29. int width, int height,
  30. int y_stride, int c_stride, int src_stride,
  31. int32_t coeff_tbl[9]);
  32. static int rgbx_to_nv12_neon_32_wrapper(SwsContext *context, const uint8_t *src[],
  33. int srcStride[], int srcSliceY, int srcSliceH,
  34. uint8_t *dst[], int dstStride[]) {
  35. rgbx_to_nv12_neon_32(src[0] + srcSliceY * srcStride[0],
  36. dst[0] + srcSliceY * dstStride[0],
  37. dst[1] + (srcSliceY / 2) * dstStride[1],
  38. context->srcW, srcSliceH,
  39. dstStride[0], dstStride[1], srcStride[0],
  40. context->input_rgb2yuv_table);
  41. return 0;
  42. }
  43. static int rgbx_to_nv12_neon_16_wrapper(SwsContext *context, const uint8_t *src[],
  44. int srcStride[], int srcSliceY, int srcSliceH,
  45. uint8_t *dst[], int dstStride[]) {
  46. rgbx_to_nv12_neon_16(src[0] + srcSliceY * srcStride[0],
  47. dst[0] + srcSliceY * dstStride[0],
  48. dst[1] + (srcSliceY / 2) * dstStride[1],
  49. context->srcW, srcSliceH,
  50. dstStride[0], dstStride[1], srcStride[0],
  51. context->input_rgb2yuv_table);
  52. return 0;
  53. }
  54. #define YUV_TO_RGB_TABLE \
  55. c->yuv2rgb_v2r_coeff, \
  56. c->yuv2rgb_u2g_coeff, \
  57. c->yuv2rgb_v2g_coeff, \
  58. c->yuv2rgb_u2b_coeff, \
  59. #define DECLARE_FF_YUVX_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 *srcU, int linesizeU, \
  64. const uint8_t *srcV, int linesizeV, \
  65. const int16_t *table, \
  66. int y_offset, \
  67. int y_coeff); \
  68. \
  69. static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
  70. int srcStride[], int srcSliceY, int srcSliceH, \
  71. uint8_t *dst[], int dstStride[]) { \
  72. const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
  73. \
  74. ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
  75. dst[0] + srcSliceY * dstStride[0], dstStride[0], \
  76. src[0], srcStride[0], \
  77. src[1], srcStride[1], \
  78. src[2], srcStride[2], \
  79. yuv2rgb_table, \
  80. c->yuv2rgb_y_offset >> 6, \
  81. c->yuv2rgb_y_coeff); \
  82. \
  83. return 0; \
  84. } \
  85. #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \
  86. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \
  87. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \
  88. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \
  89. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \
  90. DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv420p)
  91. DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv422p)
  92. #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt) \
  93. int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
  94. uint8_t *dst, int linesize, \
  95. const uint8_t *srcY, int linesizeY, \
  96. const uint8_t *srcC, int linesizeC, \
  97. const int16_t *table, \
  98. int y_offset, \
  99. int y_coeff); \
  100. \
  101. static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
  102. int srcStride[], int srcSliceY, int srcSliceH, \
  103. uint8_t *dst[], int dstStride[]) { \
  104. const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
  105. \
  106. ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
  107. dst[0] + srcSliceY * dstStride[0], dstStride[0], \
  108. src[0], srcStride[0], src[1], srcStride[1], \
  109. yuv2rgb_table, \
  110. c->yuv2rgb_y_offset >> 6, \
  111. c->yuv2rgb_y_coeff); \
  112. \
  113. return 0; \
  114. } \
  115. #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
  116. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
  117. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
  118. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
  119. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
  120. DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv12)
  121. DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21)
  122. /* We need a 16 pixel width alignment. This constraint can easily be removed
  123. * for input reading but for the output which is 4-bytes per pixel (RGBA) the
  124. * assembly might be writing as much as 4*15=60 extra bytes at the end of the
  125. * line, which won't fit the 32-bytes buffer alignment. */
  126. #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
  127. if (c->srcFormat == AV_PIX_FMT_##IFMT \
  128. && c->dstFormat == AV_PIX_FMT_##OFMT \
  129. && !(c->srcH & 1) \
  130. && !(c->srcW & 15) \
  131. && !accurate_rnd) { \
  132. c->swscale = ifmt##_to_##ofmt##_neon_wrapper; \
  133. } \
  134. } while (0)
  135. #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
  136. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
  137. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
  138. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
  139. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
  140. } while (0)
  141. static void get_unscaled_swscale_neon(SwsContext *c) {
  142. int accurate_rnd = c->flags & SWS_ACCURATE_RND;
  143. if (c->srcFormat == AV_PIX_FMT_RGBA
  144. && c->dstFormat == AV_PIX_FMT_NV12
  145. && (c->srcW >= 16)) {
  146. c->swscale = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper
  147. : rgbx_to_nv12_neon_16_wrapper;
  148. }
  149. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
  150. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
  151. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
  152. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
  153. }
  154. void ff_get_unscaled_swscale_arm(SwsContext *c)
  155. {
  156. int cpu_flags = av_get_cpu_flags();
  157. if (have_neon(cpu_flags))
  158. get_unscaled_swscale_neon(c);
  159. }