swscale_init_loongarch.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_lasx(cpu_flags)) {
  29. ff_sws_init_output_loongarch(c);
  30. if (c->srcBpc == 8) {
  31. if (c->dstBpc <= 14) {
  32. c->hyScale = c->hcScale = ff_hscale_8_to_15_lasx;
  33. } else {
  34. c->hyScale = c->hcScale = ff_hscale_8_to_19_lasx;
  35. }
  36. } else {
  37. c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lasx
  38. : ff_hscale_16_to_15_lasx;
  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_lasx;
  45. c->readLumPlanar = planar_rgb_to_y_lasx;
  46. }
  47. break;
  48. }
  49. if (c->dstBpc == 8)
  50. c->yuv2planeX = ff_yuv2planeX_8_lasx;
  51. }
  52. }
  53. av_cold void rgb2rgb_init_loongarch(void)
  54. {
  55. int cpu_flags = av_get_cpu_flags();
  56. if (have_lasx(cpu_flags))
  57. interleaveBytes = ff_interleave_bytes_lasx;
  58. }
  59. av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c)
  60. {
  61. int cpu_flags = av_get_cpu_flags();
  62. if (have_lasx(cpu_flags)) {
  63. switch (c->dstFormat) {
  64. case AV_PIX_FMT_RGB24:
  65. return yuv420_rgb24_lasx;
  66. case AV_PIX_FMT_BGR24:
  67. return yuv420_bgr24_lasx;
  68. case AV_PIX_FMT_RGBA:
  69. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  70. break;
  71. } else
  72. return yuv420_rgba32_lasx;
  73. case AV_PIX_FMT_ARGB:
  74. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  75. break;
  76. } else
  77. return yuv420_argb32_lasx;
  78. case AV_PIX_FMT_BGRA:
  79. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  80. break;
  81. } else
  82. return yuv420_bgra32_lasx;
  83. case AV_PIX_FMT_ABGR:
  84. if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) {
  85. break;
  86. } else
  87. return yuv420_abgr32_lasx;
  88. }
  89. }
  90. return NULL;
  91. }