rgb2rgb.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <stdint.h>
  19. #include "config.h"
  20. #include "libavutil/attributes.h"
  21. #include "libavutil/aarch64/cpu.h"
  22. #include "libavutil/cpu.h"
  23. #include "libavutil/bswap.h"
  24. #include "libswscale/rgb2rgb.h"
  25. #include "libswscale/swscale.h"
  26. #include "libswscale/swscale_internal.h"
  27. // Only handle width aligned to 16
  28. void ff_rgb24toyv12_neon(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
  29. uint8_t *vdst, int width, int height, int lumStride,
  30. int chromStride, int srcStride, const int32_t *rgb2yuv);
  31. static void rgb24toyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
  32. uint8_t *vdst, int width, int height, int lumStride,
  33. int chromStride, int srcStride, const int32_t *rgb2yuv)
  34. {
  35. int width_align = width & (~15);
  36. if (width_align > 0)
  37. ff_rgb24toyv12_neon(src, ydst, udst, vdst, width_align, height,
  38. lumStride, chromStride, srcStride, rgb2yuv);
  39. if (width_align < width) {
  40. src += width_align * 3;
  41. ydst += width_align;
  42. udst += width_align / 2;
  43. vdst += width_align / 2;
  44. ff_rgb24toyv12_c(src, ydst, udst, vdst, width - width_align, height,
  45. lumStride, chromStride, srcStride, rgb2yuv);
  46. }
  47. }
  48. void ff_interleave_bytes_neon(const uint8_t *src1, const uint8_t *src2,
  49. uint8_t *dest, int width, int height,
  50. int src1Stride, int src2Stride, int dstStride);
  51. void ff_deinterleave_bytes_neon(const uint8_t *src, uint8_t *dst1, uint8_t *dst2,
  52. int width, int height, int srcStride,
  53. int dst1Stride, int dst2Stride);
  54. void ff_shuffle_bytes_0321_neon(const uint8_t *src, uint8_t *dst, int src_size);
  55. void ff_shuffle_bytes_2103_neon(const uint8_t *src, uint8_t *dst, int src_size);
  56. void ff_shuffle_bytes_1230_neon(const uint8_t *src, uint8_t *dst, int src_size);
  57. void ff_shuffle_bytes_3012_neon(const uint8_t *src, uint8_t *dst, int src_size);
  58. void ff_shuffle_bytes_3210_neon(const uint8_t *src, uint8_t *dst, int src_size);
  59. void ff_shuffle_bytes_3102_neon(const uint8_t *src, uint8_t *dst, int src_size);
  60. void ff_shuffle_bytes_2013_neon(const uint8_t *src, uint8_t *dst, int src_size);
  61. void ff_shuffle_bytes_2130_neon(const uint8_t *src, uint8_t *dst, int src_size);
  62. void ff_shuffle_bytes_1203_neon(const uint8_t *src, uint8_t *dst, int src_size);
  63. void ff_uyvytoyuv422_neon(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  64. const uint8_t *src, int width, int height,
  65. int lumStride, int chromStride, int srcStride);
  66. void ff_uyvytoyuv420_neon(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  67. const uint8_t *src, int width, int height,
  68. int lumStride, int chromStride, int srcStride);
  69. void ff_yuyvtoyuv420_neon(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  70. const uint8_t *src, int width, int height,
  71. int lumStride, int chromStride, int srcStride);
  72. void ff_yuyvtoyuv422_neon(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  73. const uint8_t *src, int width, int height,
  74. int lumStride, int chromStride, int srcStride);
  75. av_cold void rgb2rgb_init_aarch64(void)
  76. {
  77. int cpu_flags = av_get_cpu_flags();
  78. if (have_neon(cpu_flags)) {
  79. ff_rgb24toyv12 = rgb24toyv12;
  80. interleaveBytes = ff_interleave_bytes_neon;
  81. deinterleaveBytes = ff_deinterleave_bytes_neon;
  82. shuffle_bytes_0321 = ff_shuffle_bytes_0321_neon;
  83. shuffle_bytes_1230 = ff_shuffle_bytes_1230_neon;
  84. shuffle_bytes_2103 = ff_shuffle_bytes_2103_neon;
  85. shuffle_bytes_3012 = ff_shuffle_bytes_3012_neon;
  86. shuffle_bytes_3210 = ff_shuffle_bytes_3210_neon;
  87. shuffle_bytes_3102 = ff_shuffle_bytes_3102_neon;
  88. shuffle_bytes_2013 = ff_shuffle_bytes_2013_neon;
  89. shuffle_bytes_2130 = ff_shuffle_bytes_2130_neon;
  90. shuffle_bytes_1203 = ff_shuffle_bytes_1203_neon;
  91. uyvytoyuv422 = ff_uyvytoyuv422_neon;
  92. uyvytoyuv420 = ff_uyvytoyuv420_neon;
  93. yuyvtoyuv422 = ff_yuyvtoyuv422_neon;
  94. yuyvtoyuv420 = ff_yuyvtoyuv420_neon;
  95. }
  96. }