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.

191 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. #if 0
  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. #endif
  56. #define YUV_TO_RGB_TABLE(precision) \
  57. c->yuv2rgb_v2r_coeff / ((precision) == 16 ? 1 << 7 : 1), \
  58. c->yuv2rgb_u2g_coeff / ((precision) == 16 ? 1 << 7 : 1), \
  59. c->yuv2rgb_v2g_coeff / ((precision) == 16 ? 1 << 7 : 1), \
  60. c->yuv2rgb_u2b_coeff / ((precision) == 16 ? 1 << 7 : 1), \
  61. #define DECLARE_FF_YUVX_TO_RGBX_FUNCS(ifmt, ofmt, precision) \
  62. int ff_##ifmt##_to_##ofmt##_neon_##precision(int w, int h, \
  63. uint8_t *dst, int linesize, \
  64. const uint8_t *srcY, int linesizeY, \
  65. const uint8_t *srcU, int linesizeU, \
  66. const uint8_t *srcV, int linesizeV, \
  67. const int16_t *table, \
  68. int y_offset, \
  69. int y_coeff); \
  70. \
  71. static int ifmt##_to_##ofmt##_neon_wrapper_##precision(SwsContext *c, const uint8_t *src[], \
  72. int srcStride[], int srcSliceY, int srcSliceH, \
  73. uint8_t *dst[], int dstStride[]) { \
  74. const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE(precision) }; \
  75. \
  76. ff_##ifmt##_to_##ofmt##_neon_##precision(c->srcW, srcSliceH, \
  77. dst[0] + srcSliceY * dstStride[0], dstStride[0], \
  78. src[0], srcStride[0], \
  79. src[1], srcStride[1], \
  80. src[2], srcStride[2], \
  81. yuv2rgb_table, \
  82. c->yuv2rgb_y_offset >> 9, \
  83. c->yuv2rgb_y_coeff / ((precision) == 16 ? 1 << 7 : 1)); \
  84. \
  85. return 0; \
  86. } \
  87. #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx, precision) \
  88. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb, precision) \
  89. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba, precision) \
  90. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr, precision) \
  91. DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra, precision) \
  92. #define DECLARE_FF_YUVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(yuvx) \
  93. DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx, 16) \
  94. DECLARE_FF_YUVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(yuv420p)
  95. DECLARE_FF_YUVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(yuv422p)
  96. #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt, precision) \
  97. int ff_##ifmt##_to_##ofmt##_neon_##precision(int w, int h, \
  98. uint8_t *dst, int linesize, \
  99. const uint8_t *srcY, int linesizeY, \
  100. const uint8_t *srcC, int linesizeC, \
  101. const int16_t *table, \
  102. int y_offset, \
  103. int y_coeff); \
  104. \
  105. static int ifmt##_to_##ofmt##_neon_wrapper_##precision(SwsContext *c, const uint8_t *src[], \
  106. int srcStride[], int srcSliceY, int srcSliceH, \
  107. uint8_t *dst[], int dstStride[]) { \
  108. const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE(precision) }; \
  109. \
  110. ff_##ifmt##_to_##ofmt##_neon_##precision(c->srcW, srcSliceH, \
  111. dst[0] + srcSliceY * dstStride[0], dstStride[0], \
  112. src[0], srcStride[0], src[1], srcStride[1], \
  113. yuv2rgb_table, \
  114. c->yuv2rgb_y_offset >> 9, \
  115. c->yuv2rgb_y_coeff / ((precision) == 16 ? 1 << 7 : 1)); \
  116. \
  117. return 0; \
  118. } \
  119. #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx, precision) \
  120. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb, precision) \
  121. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba, precision) \
  122. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr, precision) \
  123. DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra, precision) \
  124. #define DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nvx) \
  125. DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx, 16) \
  126. DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nv12)
  127. DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nv21)
  128. /* We need a 16 pixel width alignment. This constraint can easily be removed
  129. * for input reading but for the output which is 4-bytes per pixel (RGBA) the
  130. * assembly might be writing as much as 4*15=60 extra bytes at the end of the
  131. * line, which won't fit the 32-bytes buffer alignment. */
  132. #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
  133. if (c->srcFormat == AV_PIX_FMT_##IFMT \
  134. && c->dstFormat == AV_PIX_FMT_##OFMT \
  135. && !(c->srcH & 1) \
  136. && !(c->srcW & 15) \
  137. && !accurate_rnd) { \
  138. c->swscale = ifmt##_to_##ofmt##_neon_wrapper_16; \
  139. } \
  140. } while (0)
  141. #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
  142. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
  143. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
  144. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
  145. SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
  146. } while (0)
  147. static void get_unscaled_swscale_neon(SwsContext *c) {
  148. int accurate_rnd = c->flags & SWS_ACCURATE_RND;
  149. #if 0
  150. if (c->srcFormat == AV_PIX_FMT_RGBA
  151. && c->dstFormat == AV_PIX_FMT_NV12
  152. && (c->srcW >= 16)) {
  153. c->swscale = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper
  154. : rgbx_to_nv12_neon_16_wrapper;
  155. }
  156. #endif
  157. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
  158. SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
  159. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
  160. SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
  161. }
  162. void ff_get_unscaled_swscale_arm(SwsContext *c)
  163. {
  164. int cpu_flags = av_get_cpu_flags();
  165. if (have_neon(cpu_flags))
  166. get_unscaled_swscale_neon(c);
  167. }