swscale_init_loongarch.c 6.0 KB

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