swscale_unscaled.c 11 KB

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