swscale_init_loongarch.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_range_convert_loongarch(SwsInternal *c)
  26. {
  27. int cpu_flags = av_get_cpu_flags();
  28. if (have_lsx(cpu_flags)) {
  29. if (c->dstBpc <= 14) {
  30. if (c->srcRange) {
  31. c->lumConvertRange = lumRangeFromJpeg_lsx;
  32. c->chrConvertRange = chrRangeFromJpeg_lsx;
  33. } else {
  34. c->lumConvertRange = lumRangeToJpeg_lsx;
  35. c->chrConvertRange = chrRangeToJpeg_lsx;
  36. }
  37. }
  38. }
  39. #if HAVE_LASX
  40. if (have_lasx(cpu_flags)) {
  41. if (c->dstBpc <= 14) {
  42. if (c->srcRange) {
  43. c->lumConvertRange = lumRangeFromJpeg_lasx;
  44. c->chrConvertRange = chrRangeFromJpeg_lasx;
  45. } else {
  46. c->lumConvertRange = lumRangeToJpeg_lasx;
  47. c->chrConvertRange = chrRangeToJpeg_lasx;
  48. }
  49. }
  50. }
  51. #endif // #if HAVE_LASX
  52. }
  53. av_cold void ff_sws_init_swscale_loongarch(SwsInternal *c)
  54. {
  55. int cpu_flags = av_get_cpu_flags();
  56. if (have_lsx(cpu_flags)) {
  57. ff_sws_init_output_lsx(c, &c->yuv2plane1, &c->yuv2planeX,
  58. &c->yuv2nv12cX, &c->yuv2packed1,
  59. &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
  60. ff_sws_init_input_lsx(c);
  61. if (c->srcBpc == 8) {
  62. if (c->dstBpc <= 14) {
  63. c->hyScale = c->hcScale = ff_hscale_8_to_15_lsx;
  64. } else {
  65. c->hyScale = c->hcScale = ff_hscale_8_to_19_lsx;
  66. }
  67. } else {
  68. c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lsx
  69. : ff_hscale_16_to_15_lsx;
  70. }
  71. }
  72. #if HAVE_LASX
  73. if (have_lasx(cpu_flags)) {
  74. ff_sws_init_output_lasx(c, &c->yuv2plane1, &c->yuv2planeX,
  75. &c->yuv2nv12cX, &c->yuv2packed1,
  76. &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
  77. ff_sws_init_input_lasx(c);
  78. if (c->srcBpc == 8) {
  79. if (c->dstBpc <= 14) {
  80. c->hyScale = c->hcScale = ff_hscale_8_to_15_lasx;
  81. } else {
  82. c->hyScale = c->hcScale = ff_hscale_8_to_19_lasx;
  83. }
  84. } else {
  85. c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lasx
  86. : ff_hscale_16_to_15_lasx;
  87. }
  88. }
  89. #endif // #if HAVE_LASX
  90. }
  91. av_cold void rgb2rgb_init_loongarch(void)
  92. {
  93. #if HAVE_LASX
  94. int cpu_flags = av_get_cpu_flags();
  95. if (have_lasx(cpu_flags))
  96. interleaveBytes = ff_interleave_bytes_lasx;
  97. #endif // #if HAVE_LASX
  98. }
  99. av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsInternal *c)
  100. {
  101. int cpu_flags = av_get_cpu_flags();
  102. #if HAVE_LASX
  103. if (have_lasx(cpu_flags)) {
  104. if (c->srcFormat == AV_PIX_FMT_YUV420P) {
  105. switch (c->dstFormat) {
  106. case AV_PIX_FMT_RGB24:
  107. return yuv420_rgb24_lasx;
  108. case AV_PIX_FMT_BGR24:
  109. return yuv420_bgr24_lasx;
  110. case AV_PIX_FMT_RGBA:
  111. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  112. break;
  113. } else
  114. return yuv420_rgba32_lasx;
  115. case AV_PIX_FMT_ARGB:
  116. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  117. break;
  118. } else
  119. return yuv420_argb32_lasx;
  120. case AV_PIX_FMT_BGRA:
  121. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  122. break;
  123. } else
  124. return yuv420_bgra32_lasx;
  125. case AV_PIX_FMT_ABGR:
  126. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  127. break;
  128. } else
  129. return yuv420_abgr32_lasx;
  130. }
  131. }
  132. }
  133. #endif // #if HAVE_LASX
  134. if (have_lsx(cpu_flags)) {
  135. if (c->srcFormat == AV_PIX_FMT_YUV420P) {
  136. switch (c->dstFormat) {
  137. case AV_PIX_FMT_RGB24:
  138. return yuv420_rgb24_lsx;
  139. case AV_PIX_FMT_BGR24:
  140. return yuv420_bgr24_lsx;
  141. case AV_PIX_FMT_RGBA:
  142. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  143. break;
  144. } else
  145. return yuv420_rgba32_lsx;
  146. case AV_PIX_FMT_ARGB:
  147. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  148. break;
  149. } else
  150. return yuv420_argb32_lsx;
  151. case AV_PIX_FMT_BGRA:
  152. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  153. break;
  154. } else
  155. return yuv420_bgra32_lsx;
  156. case AV_PIX_FMT_ABGR:
  157. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  158. break;
  159. } else
  160. return yuv420_abgr32_lsx;
  161. }
  162. }
  163. }
  164. return NULL;
  165. }