swscale_altivec.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * AltiVec-enhanced yuv2yuvX
  3. *
  4. * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
  5. * based on the equivalent C code in swscale.c
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <inttypes.h>
  24. #include "config.h"
  25. #include "libswscale/swscale.h"
  26. #include "libswscale/swscale_internal.h"
  27. #include "libavutil/attributes.h"
  28. #include "libavutil/cpu.h"
  29. #include "yuv2rgb_altivec.h"
  30. #include "libavutil/ppc/util_altivec.h"
  31. #if HAVE_ALTIVEC && HAVE_BIGENDIAN
  32. #define vzero vec_splat_s32(0)
  33. #define GET_LS(a,b,c,s) {\
  34. vector signed short l2 = vec_ld(((b) << 1) + 16, s);\
  35. ls = vec_perm(a, l2, c);\
  36. a = l2;\
  37. }
  38. #define yuv2planeX_8(d1, d2, l1, src, x, perm, filter) do {\
  39. vector signed short ls;\
  40. GET_LS(l1, x, perm, src);\
  41. vector signed int i1 = vec_mule(filter, ls);\
  42. vector signed int i2 = vec_mulo(filter, ls);\
  43. vector signed int vf1, vf2;\
  44. vf1 = vec_mergeh(i1, i2);\
  45. vf2 = vec_mergel(i1, i2);\
  46. d1 = vec_add(d1, vf1);\
  47. d2 = vec_add(d2, vf2);\
  48. } while (0)
  49. #define LOAD_FILTER(vf,f) {\
  50. vector unsigned char perm0 = vec_lvsl(joffset, f);\
  51. vf = vec_ld(joffset, f);\
  52. vf = vec_perm(vf, vf, perm0);\
  53. }
  54. #define LOAD_L1(ll1,s,p){\
  55. p = vec_lvsl(xoffset, s);\
  56. ll1 = vec_ld(xoffset, s);\
  57. }
  58. // The 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2).
  59. // The neat trick: We only care for half the elements,
  60. // high or low depending on (i<<3)%16 (it's 0 or 8 here),
  61. // and we're going to use vec_mule, so we choose
  62. // carefully how to "unpack" the elements into the even slots.
  63. #define GET_VF4(a, vf, f) {\
  64. vf = vec_ld(a<< 3, f);\
  65. if ((a << 3) % 16)\
  66. vf = vec_mergel(vf, (vector signed short)vzero);\
  67. else\
  68. vf = vec_mergeh(vf, (vector signed short)vzero);\
  69. }
  70. #define FIRST_LOAD(sv, pos, s, per) {\
  71. sv = vec_ld(pos, s);\
  72. per = vec_lvsl(pos, s);\
  73. }
  74. #define UPDATE_PTR(s0, d0, s1, d1) {\
  75. d0 = s0;\
  76. d1 = s1;\
  77. }
  78. #define LOAD_SRCV(pos, a, s, per, v0, v1, vf) {\
  79. v1 = vec_ld(pos + a + 16, s);\
  80. vf = vec_perm(v0, v1, per);\
  81. }
  82. #define LOAD_SRCV8(pos, a, s, per, v0, v1, vf) {\
  83. if ((((uintptr_t)s + pos) % 16) > 8) {\
  84. v1 = vec_ld(pos + a + 16, s);\
  85. }\
  86. vf = vec_perm(v0, src_v1, per);\
  87. }
  88. #define GET_VFD(a, b, f, vf0, vf1, per, vf, off) {\
  89. vf1 = vec_ld((a * 2 * filterSize) + (b * 2) + 16 + off, f);\
  90. vf = vec_perm(vf0, vf1, per);\
  91. }
  92. #define FUNC(name) name ## _altivec
  93. #include "swscale_ppc_template.c"
  94. #undef FUNC
  95. #endif /* HAVE_ALTIVEC && HAVE_BIGENDIAN */
  96. av_cold void ff_sws_init_swscale_ppc(SwsContext *c)
  97. {
  98. #if HAVE_ALTIVEC
  99. enum AVPixelFormat dstFormat = c->dstFormat;
  100. if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
  101. return;
  102. #if HAVE_BIGENDIAN
  103. if (c->srcBpc == 8 && c->dstBpc <= 14) {
  104. c->hyScale = c->hcScale = hScale_real_altivec;
  105. }
  106. if (!is16BPS(dstFormat) && !isNBPS(dstFormat) &&
  107. dstFormat != AV_PIX_FMT_NV12 && dstFormat != AV_PIX_FMT_NV21 &&
  108. dstFormat != AV_PIX_FMT_GRAYF32BE && dstFormat != AV_PIX_FMT_GRAYF32LE &&
  109. !c->needAlpha) {
  110. c->yuv2planeX = yuv2planeX_altivec;
  111. }
  112. #endif
  113. /* The following list of supported dstFormat values should
  114. * match what's found in the body of ff_yuv2packedX_altivec() */
  115. if (!(c->flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->needAlpha) {
  116. switch (c->dstFormat) {
  117. case AV_PIX_FMT_ABGR:
  118. c->yuv2packedX = ff_yuv2abgr_X_altivec;
  119. break;
  120. case AV_PIX_FMT_BGRA:
  121. c->yuv2packedX = ff_yuv2bgra_X_altivec;
  122. break;
  123. case AV_PIX_FMT_ARGB:
  124. c->yuv2packedX = ff_yuv2argb_X_altivec;
  125. break;
  126. case AV_PIX_FMT_RGBA:
  127. c->yuv2packedX = ff_yuv2rgba_X_altivec;
  128. break;
  129. case AV_PIX_FMT_BGR24:
  130. c->yuv2packedX = ff_yuv2bgr24_X_altivec;
  131. break;
  132. case AV_PIX_FMT_RGB24:
  133. c->yuv2packedX = ff_yuv2rgb24_X_altivec;
  134. break;
  135. }
  136. }
  137. #endif /* HAVE_ALTIVEC */
  138. ff_sws_init_swscale_vsx(c);
  139. }