yuv2rgb_vis.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * VIS optimized software YUV to RGB converter
  3. * Copyright (c) 2007 Denes Balatoni <dbalatoni@programozo.hu>
  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 <inttypes.h>
  22. #include <stdlib.h>
  23. #include "libswscale/swscale.h"
  24. #include "libswscale/swscale_internal.h"
  25. #define YUV2RGB_INIT \
  26. "wr %%g0, 0x10, %%gsr \n\t" \
  27. "ldd [%5], %%f32 \n\t" \
  28. "ldd [%5 + 8], %%f34 \n\t" \
  29. "ldd [%5 + 16], %%f36 \n\t" \
  30. "ldd [%5 + 24], %%f38 \n\t" \
  31. "ldd [%5 + 32], %%f40 \n\t" \
  32. "ldd [%5 + 40], %%f42 \n\t" \
  33. "ldd [%5 + 48], %%f44 \n\t" \
  34. "ldd [%5 + 56], %%f46 \n\t" \
  35. "ldd [%5 + 64], %%f48 \n\t" \
  36. "ldd [%5 + 72], %%f50 \n\t"
  37. #define YUV2RGB_KERNEL \
  38. /* ^^^^ f0=Y f3=u f5=v */ \
  39. "fmul8x16 %%f3, %%f48, %%f6 \n\t" \
  40. "fmul8x16 %%f19, %%f48, %%f22 \n\t" \
  41. "fmul8x16 %%f5, %%f44, %%f8 \n\t" \
  42. "fmul8x16 %%f21, %%f44, %%f24 \n\t" \
  43. "fmul8x16 %%f0, %%f42, %%f0 \n\t" \
  44. "fmul8x16 %%f16, %%f42, %%f16 \n\t" \
  45. "fmul8x16 %%f3, %%f50, %%f2 \n\t" \
  46. "fmul8x16 %%f19, %%f50, %%f18 \n\t" \
  47. "fmul8x16 %%f5, %%f46, %%f4 \n\t" \
  48. "fmul8x16 %%f21, %%f46, %%f20 \n\t" \
  49. \
  50. "fpsub16 %%f6, %%f34, %%f6 \n\t" /* 1 */ \
  51. "fpsub16 %%f22, %%f34, %%f22 \n\t" /* 1 */ \
  52. "fpsub16 %%f8, %%f38, %%f8 \n\t" /* 3 */ \
  53. "fpsub16 %%f24, %%f38, %%f24 \n\t" /* 3 */ \
  54. "fpsub16 %%f0, %%f32, %%f0 \n\t" /* 0 */ \
  55. "fpsub16 %%f16, %%f32, %%f16 \n\t" /* 0 */ \
  56. "fpsub16 %%f2, %%f36, %%f2 \n\t" /* 2 */ \
  57. "fpsub16 %%f18, %%f36, %%f18 \n\t" /* 2 */ \
  58. "fpsub16 %%f4, %%f40, %%f4 \n\t" /* 4 */ \
  59. "fpsub16 %%f20, %%f40, %%f20 \n\t" /* 4 */ \
  60. \
  61. "fpadd16 %%f0, %%f8, %%f8 \n\t" /* Gt */ \
  62. "fpadd16 %%f16, %%f24, %%f24 \n\t" /* Gt */ \
  63. "fpadd16 %%f0, %%f4, %%f4 \n\t" /* R */ \
  64. "fpadd16 %%f16, %%f20, %%f20 \n\t" /* R */ \
  65. "fpadd16 %%f0, %%f6, %%f6 \n\t" /* B */ \
  66. "fpadd16 %%f16, %%f22, %%f22 \n\t" /* B */ \
  67. "fpadd16 %%f8, %%f2, %%f2 \n\t" /* G */ \
  68. "fpadd16 %%f24, %%f18, %%f18 \n\t" /* G */ \
  69. \
  70. "fpack16 %%f4, %%f4 \n\t" \
  71. "fpack16 %%f20, %%f20 \n\t" \
  72. "fpack16 %%f6, %%f6 \n\t" \
  73. "fpack16 %%f22, %%f22 \n\t" \
  74. "fpack16 %%f2, %%f2 \n\t" \
  75. "fpack16 %%f18, %%f18 \n\t"
  76. // FIXME: must be changed to set alpha to 255 instead of 0
  77. static int vis_420P_ARGB32(SwsContext *c, uint8_t *src[], int srcStride[],
  78. int srcSliceY, int srcSliceH,
  79. uint8_t *dst[], int dstStride[])
  80. {
  81. int y, out1, out2, out3, out4, out5, out6;
  82. for (y = 0; y < srcSliceH; ++y)
  83. __asm__ volatile (
  84. YUV2RGB_INIT
  85. "wr %%g0, 0xd2, %%asi \n\t" /* ASI_FL16_P */
  86. "1: \n\t"
  87. "ldda [%1] %%asi, %%f2 \n\t"
  88. "ldda [%1 + 2] %%asi, %%f18 \n\t"
  89. "ldda [%2] %%asi, %%f4 \n\t"
  90. "ldda [%2 + 2] %%asi, %%f20 \n\t"
  91. "ld [%0], %%f0 \n\t"
  92. "ld [%0+4], %%f16 \n\t"
  93. "fpmerge %%f3, %%f3, %%f2 \n\t"
  94. "fpmerge %%f19, %%f19, %%f18 \n\t"
  95. "fpmerge %%f5, %%f5, %%f4 \n\t"
  96. "fpmerge %%f21, %%f21, %%f20 \n\t"
  97. YUV2RGB_KERNEL
  98. "fzero %%f0 \n\t"
  99. "fpmerge %%f4, %%f6, %%f8 \n\t" // r, b, t1
  100. "fpmerge %%f20, %%f22, %%f24 \n\t" // r, b, t1
  101. "fpmerge %%f0, %%f2, %%f10 \n\t" // 0, g, t2
  102. "fpmerge %%f0, %%f18, %%f26 \n\t" // 0, g, t2
  103. "fpmerge %%f10, %%f8, %%f4 \n\t" // t2, t1, msb
  104. "fpmerge %%f26, %%f24, %%f20 \n\t" // t2, t1, msb
  105. "fpmerge %%f11, %%f9, %%f6 \n\t" // t2, t1, lsb
  106. "fpmerge %%f27, %%f25, %%f22 \n\t" // t2, t1, lsb
  107. "std %%f4, [%3] \n\t"
  108. "std %%f20, [%3 + 16] \n\t"
  109. "std %%f6, [%3 + 8] \n\t"
  110. "std %%f22, [%3 + 24] \n\t"
  111. "add %0, 8, %0 \n\t"
  112. "add %1, 4, %1 \n\t"
  113. "add %2, 4, %2 \n\t"
  114. "subcc %4, 8, %4 \n\t"
  115. "bne 1b \n\t"
  116. "add %3, 32, %3 \n\t" // delay slot
  117. : "=r" (out1), "=r" (out2), "=r" (out3), "=r" (out4), "=r" (out5), "=r" (out6)
  118. : "0" (src[0] + (y + srcSliceY) * srcStride[0]), "1" (src[1] + ((y + srcSliceY) >> 1) * srcStride[1]),
  119. "2" (src[2] + ((y + srcSliceY) >> 1) * srcStride[2]), "3" (dst[0] + (y + srcSliceY) * dstStride[0]),
  120. "4" (c->dstW),
  121. "5" (c->sparc_coeffs)
  122. );
  123. return srcSliceH;
  124. }
  125. // FIXME: must be changed to set alpha to 255 instead of 0
  126. static int vis_422P_ARGB32(SwsContext *c, uint8_t *src[], int srcStride[],
  127. int srcSliceY, int srcSliceH,
  128. uint8_t *dst[], int dstStride[])
  129. {
  130. int y, out1, out2, out3, out4, out5, out6;
  131. for (y = 0; y < srcSliceH; ++y)
  132. __asm__ volatile (
  133. YUV2RGB_INIT
  134. "wr %%g0, 0xd2, %%asi \n\t" /* ASI_FL16_P */
  135. "1: \n\t"
  136. "ldda [%1] %%asi, %%f2 \n\t"
  137. "ldda [%1 + 2] %%asi, %%f18 \n\t"
  138. "ldda [%2] %%asi, %%f4 \n\t"
  139. "ldda [%2 + 2] %%asi, %%f20 \n\t"
  140. "ld [%0], %%f0 \n\t"
  141. "ld [%0 + 4], %%f16 \n\t"
  142. "fpmerge %%f3, %%f3, %%f2 \n\t"
  143. "fpmerge %%f19, %%f19, %%f18 \n\t"
  144. "fpmerge %%f5, %%f5, %%f4 \n\t"
  145. "fpmerge %%f21, %%f21, %%f20 \n\t"
  146. YUV2RGB_KERNEL
  147. "fzero %%f0 \n\t"
  148. "fpmerge %%f4, %%f6, %%f8 \n\t" // r,b,t1
  149. "fpmerge %%f20, %%f22, %%f24 \n\t" // r,b,t1
  150. "fpmerge %%f0, %%f2, %%f10 \n\t" // 0,g,t2
  151. "fpmerge %%f0, %%f18, %%f26 \n\t" // 0,g,t2
  152. "fpmerge %%f10, %%f8, %%f4 \n\t" // t2,t1,msb
  153. "fpmerge %%f26, %%f24, %%f20 \n\t" // t2,t1,msb
  154. "fpmerge %%f11, %%f9, %%f6 \n\t" // t2,t1,lsb
  155. "fpmerge %%f27, %%f25, %%f22 \n\t" // t2,t1,lsb
  156. "std %%f4, [%3] \n\t"
  157. "std %%f20, [%3 + 16] \n\t"
  158. "std %%f6, [%3 + 8] \n\t"
  159. "std %%f22, [%3 + 24] \n\t"
  160. "add %0, 8, %0 \n\t"
  161. "add %1, 4, %1 \n\t"
  162. "add %2, 4, %2 \n\t"
  163. "subcc %4, 8, %4 \n\t"
  164. "bne 1b \n\t"
  165. "add %3, 32, %3 \n\t" //delay slot
  166. : "=r" (out1), "=r" (out2), "=r" (out3), "=r" (out4), "=r" (out5), "=r" (out6)
  167. : "0" (src[0] + (y + srcSliceY) * srcStride[0]), "1" (src[1] + (y + srcSliceY) * srcStride[1]),
  168. "2" (src[2] + (y + srcSliceY) * srcStride[2]), "3" (dst[0] + (y + srcSliceY) * dstStride[0]),
  169. "4" (c->dstW),
  170. "5" (c->sparc_coeffs)
  171. );
  172. return srcSliceH;
  173. }
  174. SwsFunc ff_yuv2rgb_init_vis(SwsContext *c)
  175. {
  176. c->sparc_coeffs[5] = c->yCoeff;
  177. c->sparc_coeffs[6] = c->vgCoeff;
  178. c->sparc_coeffs[7] = c->vrCoeff;
  179. c->sparc_coeffs[8] = c->ubCoeff;
  180. c->sparc_coeffs[9] = c->ugCoeff;
  181. c->sparc_coeffs[0] = (((int16_t)c->yOffset * (int16_t)c->yCoeff >> 11) & 0xffff) * 0x0001000100010001ULL;
  182. c->sparc_coeffs[1] = (((int16_t)c->uOffset * (int16_t)c->ubCoeff >> 11) & 0xffff) * 0x0001000100010001ULL;
  183. c->sparc_coeffs[2] = (((int16_t)c->uOffset * (int16_t)c->ugCoeff >> 11) & 0xffff) * 0x0001000100010001ULL;
  184. c->sparc_coeffs[3] = (((int16_t)c->vOffset * (int16_t)c->vgCoeff >> 11) & 0xffff) * 0x0001000100010001ULL;
  185. c->sparc_coeffs[4] = (((int16_t)c->vOffset * (int16_t)c->vrCoeff >> 11) & 0xffff) * 0x0001000100010001ULL;
  186. if (c->dstFormat == PIX_FMT_RGB32 && c->srcFormat == PIX_FMT_YUV422P && (c->dstW & 7) == 0) {
  187. av_log(c, AV_LOG_INFO,
  188. "SPARC VIS accelerated YUV422P -> RGB32 (WARNING: alpha value is wrong)\n");
  189. return vis_422P_ARGB32;
  190. } else if (c->dstFormat == PIX_FMT_RGB32 && c->srcFormat == PIX_FMT_YUV420P && (c->dstW & 7) == 0) {
  191. av_log(c, AV_LOG_INFO,
  192. "SPARC VIS accelerated YUV420P -> RGB32 (WARNING: alpha value is wrong)\n");
  193. return vis_420P_ARGB32;
  194. }
  195. return NULL;
  196. }