swscale_init_loongarch.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (C) 2022 Loongson Technology Corporation Limited
  3. * Contributed by Hao Chen(chenhao@loongson.cn)
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "swscale_loongarch.h"
  22. #include "libswscale/swscale_internal.h"
  23. #include "libswscale/rgb2rgb.h"
  24. #include "libavutil/loongarch/cpu.h"
  25. av_cold void ff_sws_init_swscale_loongarch(SwsContext *c)
  26. {
  27. int cpu_flags = av_get_cpu_flags();
  28. if (have_lsx(cpu_flags)) {
  29. ff_sws_init_output_lsx(c);
  30. if (c->srcBpc == 8) {
  31. if (c->dstBpc <= 14) {
  32. c->hyScale = c->hcScale = ff_hscale_8_to_15_lsx;
  33. } else {
  34. c->hyScale = c->hcScale = ff_hscale_8_to_19_lsx;
  35. }
  36. } else {
  37. c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lsx
  38. : ff_hscale_16_to_15_lsx;
  39. }
  40. switch (c->srcFormat) {
  41. case AV_PIX_FMT_GBRAP:
  42. case AV_PIX_FMT_GBRP:
  43. {
  44. c->readChrPlanar = planar_rgb_to_uv_lsx;
  45. c->readLumPlanar = planar_rgb_to_y_lsx;
  46. }
  47. break;
  48. }
  49. if (c->dstBpc == 8)
  50. c->yuv2planeX = ff_yuv2planeX_8_lsx;
  51. }
  52. #if HAVE_LASX
  53. if (have_lasx(cpu_flags)) {
  54. ff_sws_init_output_lasx(c);
  55. if (c->srcBpc == 8) {
  56. if (c->dstBpc <= 14) {
  57. c->hyScale = c->hcScale = ff_hscale_8_to_15_lasx;
  58. } else {
  59. c->hyScale = c->hcScale = ff_hscale_8_to_19_lasx;
  60. }
  61. } else {
  62. c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lasx
  63. : ff_hscale_16_to_15_lasx;
  64. }
  65. switch (c->srcFormat) {
  66. case AV_PIX_FMT_GBRAP:
  67. case AV_PIX_FMT_GBRP:
  68. {
  69. c->readChrPlanar = planar_rgb_to_uv_lasx;
  70. c->readLumPlanar = planar_rgb_to_y_lasx;
  71. }
  72. break;
  73. }
  74. if (c->dstBpc == 8)
  75. c->yuv2planeX = ff_yuv2planeX_8_lasx;
  76. }
  77. #endif // #if HAVE_LASX
  78. }
  79. av_cold void rgb2rgb_init_loongarch(void)
  80. {
  81. #if HAVE_LASX
  82. int cpu_flags = av_get_cpu_flags();
  83. if (have_lasx(cpu_flags))
  84. interleaveBytes = ff_interleave_bytes_lasx;
  85. #endif // #if HAVE_LASX
  86. }
  87. av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c)
  88. {
  89. int cpu_flags = av_get_cpu_flags();
  90. #if HAVE_LASX
  91. if (have_lasx(cpu_flags)) {
  92. if (c->srcFormat == AV_PIX_FMT_YUV420P) {
  93. switch (c->dstFormat) {
  94. case AV_PIX_FMT_RGB24:
  95. return yuv420_rgb24_lasx;
  96. case AV_PIX_FMT_BGR24:
  97. return yuv420_bgr24_lasx;
  98. case AV_PIX_FMT_RGBA:
  99. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  100. break;
  101. } else
  102. return yuv420_rgba32_lasx;
  103. case AV_PIX_FMT_ARGB:
  104. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  105. break;
  106. } else
  107. return yuv420_argb32_lasx;
  108. case AV_PIX_FMT_BGRA:
  109. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  110. break;
  111. } else
  112. return yuv420_bgra32_lasx;
  113. case AV_PIX_FMT_ABGR:
  114. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  115. break;
  116. } else
  117. return yuv420_abgr32_lasx;
  118. }
  119. }
  120. }
  121. #endif // #if HAVE_LASX
  122. if (have_lsx(cpu_flags)) {
  123. if (c->srcFormat == AV_PIX_FMT_YUV420P) {
  124. switch (c->dstFormat) {
  125. case AV_PIX_FMT_RGB24:
  126. return yuv420_rgb24_lsx;
  127. case AV_PIX_FMT_BGR24:
  128. return yuv420_bgr24_lsx;
  129. case AV_PIX_FMT_RGBA:
  130. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  131. break;
  132. } else
  133. return yuv420_rgba32_lsx;
  134. case AV_PIX_FMT_ARGB:
  135. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  136. break;
  137. } else
  138. return yuv420_argb32_lsx;
  139. case AV_PIX_FMT_BGRA:
  140. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  141. break;
  142. } else
  143. return yuv420_bgra32_lsx;
  144. case AV_PIX_FMT_ABGR:
  145. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  146. break;
  147. } else
  148. return yuv420_abgr32_lsx;
  149. }
  150. }
  151. }
  152. return NULL;
  153. }