swscale.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "libavutil/attributes.h"
  20. #include "libavutil/riscv/cpu.h"
  21. #include "libswscale/swscale_internal.h"
  22. void ff_range_lum_to_jpeg_16_rvv(int16_t *, int);
  23. void ff_range_chr_to_jpeg_16_rvv(int16_t *, int16_t *, int);
  24. void ff_range_lum_from_jpeg_16_rvv(int16_t *, int);
  25. void ff_range_chr_from_jpeg_16_rvv(int16_t *, int16_t *, int);
  26. av_cold static void ff_sws_init_range_convert_riscv(SwsContext *c, int flags)
  27. {
  28. #if HAVE_RVV
  29. static const struct {
  30. void (*lum)(int16_t *, int);
  31. void (*chr)(int16_t *, int16_t *, int);
  32. } convs[2] = {
  33. { ff_range_lum_to_jpeg_16_rvv, ff_range_chr_to_jpeg_16_rvv },
  34. { ff_range_lum_from_jpeg_16_rvv, ff_range_chr_from_jpeg_16_rvv },
  35. };
  36. if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat) &&
  37. c->dstBpc <= 14 &&
  38. (flags & AV_CPU_FLAG_RVV_I32) && (flags & AV_CPU_FLAG_RVB_ADDR)) {
  39. bool from = c->srcRange != 0;
  40. c->lumConvertRange = convs[from].lum;
  41. c->chrConvertRange = convs[from].chr;
  42. }
  43. #endif
  44. }
  45. #define RVV_INPUT(name) \
  46. void ff_##name##ToY_rvv(uint8_t *dst, const uint8_t *src, const uint8_t *, \
  47. const uint8_t *, int w, uint32_t *coeffs, void *); \
  48. void ff_##name##ToUV_rvv(uint8_t *, uint8_t *, const uint8_t *, \
  49. const uint8_t *, const uint8_t *, int w, \
  50. uint32_t *coeffs, void *); \
  51. void ff_##name##ToUV_half_rvv(uint8_t *, uint8_t *, const uint8_t *, \
  52. const uint8_t *, const uint8_t *, int w, \
  53. uint32_t *coeffs, void *)
  54. RVV_INPUT(abgr32);
  55. RVV_INPUT(argb32);
  56. RVV_INPUT(bgr24);
  57. RVV_INPUT(bgra32);
  58. RVV_INPUT(rgb24);
  59. RVV_INPUT(rgba32);
  60. av_cold void ff_sws_init_swscale_riscv(SwsContext *c)
  61. {
  62. int flags = av_get_cpu_flags();
  63. #if HAVE_RVV
  64. if ((flags & AV_CPU_FLAG_RVV_I32) && (flags & AV_CPU_FLAG_RVB_ADDR)) {
  65. switch (c->srcFormat) {
  66. case AV_PIX_FMT_ABGR:
  67. c->lumToYV12 = ff_abgr32ToY_rvv;
  68. if (c->chrSrcHSubSample)
  69. c->chrToYV12 = ff_abgr32ToUV_half_rvv;
  70. else
  71. c->chrToYV12 = ff_abgr32ToUV_rvv;
  72. break;
  73. case AV_PIX_FMT_ARGB:
  74. c->lumToYV12 = ff_argb32ToY_rvv;
  75. if (c->chrSrcHSubSample)
  76. c->chrToYV12 = ff_argb32ToUV_half_rvv;
  77. else
  78. c->chrToYV12 = ff_argb32ToUV_rvv;
  79. break;
  80. case AV_PIX_FMT_BGR24:
  81. c->lumToYV12 = ff_bgr24ToY_rvv;
  82. if (c->chrSrcHSubSample)
  83. c->chrToYV12 = ff_bgr24ToUV_half_rvv;
  84. else
  85. c->chrToYV12 = ff_bgr24ToUV_rvv;
  86. break;
  87. case AV_PIX_FMT_BGRA:
  88. c->lumToYV12 = ff_bgra32ToY_rvv;
  89. if (c->chrSrcHSubSample)
  90. c->chrToYV12 = ff_bgra32ToUV_half_rvv;
  91. else
  92. c->chrToYV12 = ff_bgra32ToUV_rvv;
  93. break;
  94. case AV_PIX_FMT_RGB24:
  95. c->lumToYV12 = ff_rgb24ToY_rvv;
  96. if (c->chrSrcHSubSample)
  97. c->chrToYV12 = ff_rgb24ToUV_half_rvv;
  98. else
  99. c->chrToYV12 = ff_rgb24ToUV_rvv;
  100. break;
  101. case AV_PIX_FMT_RGBA:
  102. c->lumToYV12 = ff_rgba32ToY_rvv;
  103. if (c->chrSrcHSubSample)
  104. c->chrToYV12 = ff_rgba32ToUV_half_rvv;
  105. else
  106. c->chrToYV12 = ff_rgba32ToUV_rvv;
  107. break;
  108. }
  109. }
  110. #endif
  111. ff_sws_init_range_convert_riscv(c, flags);
  112. }