You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2600 lines
77KB

  1. /*
  2. Copyright (C) 2001-2002 Michael Niedermayer <michaelni@gmx.at>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #undef MOVNTQ
  16. #undef PAVGB
  17. #undef PREFETCH
  18. #undef PREFETCHW
  19. #undef EMMS
  20. #undef SFENCE
  21. #ifdef HAVE_3DNOW
  22. /* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */
  23. #define EMMS "femms"
  24. #else
  25. #define EMMS "emms"
  26. #endif
  27. #ifdef HAVE_3DNOW
  28. #define PREFETCH "prefetch"
  29. #define PREFETCHW "prefetchw"
  30. #elif defined ( HAVE_MMX2 )
  31. #define PREFETCH "prefetchnta"
  32. #define PREFETCHW "prefetcht0"
  33. #else
  34. #define PREFETCH "/nop"
  35. #define PREFETCHW "/nop"
  36. #endif
  37. #ifdef HAVE_MMX2
  38. #define SFENCE "sfence"
  39. #else
  40. #define SFENCE "/nop"
  41. #endif
  42. #ifdef HAVE_MMX2
  43. #define PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
  44. #elif defined (HAVE_3DNOW)
  45. #define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
  46. #endif
  47. #ifdef HAVE_MMX2
  48. #define MOVNTQ(a,b) "movntq " #a ", " #b " \n\t"
  49. #else
  50. #define MOVNTQ(a,b) "movq " #a ", " #b " \n\t"
  51. #endif
  52. #define YSCALEYUV2YV12X(x) \
  53. "xorl %%eax, %%eax \n\t"\
  54. "pxor %%mm3, %%mm3 \n\t"\
  55. "pxor %%mm4, %%mm4 \n\t"\
  56. "movl %0, %%edx \n\t"\
  57. ".balign 16 \n\t" /* FIXME Unroll? */\
  58. "1: \n\t"\
  59. "movl (%1, %%edx, 4), %%esi \n\t"\
  60. "movq (%2, %%edx, 8), %%mm0 \n\t" /* filterCoeff */\
  61. "movq " #x "(%%esi, %%eax, 2), %%mm2 \n\t" /* srcData */\
  62. "movq 8+" #x "(%%esi, %%eax, 2), %%mm5 \n\t" /* srcData */\
  63. "pmulhw %%mm0, %%mm2 \n\t"\
  64. "pmulhw %%mm0, %%mm5 \n\t"\
  65. "paddw %%mm2, %%mm3 \n\t"\
  66. "paddw %%mm5, %%mm4 \n\t"\
  67. "addl $1, %%edx \n\t"\
  68. " jnz 1b \n\t"\
  69. "psraw $3, %%mm3 \n\t"\
  70. "psraw $3, %%mm4 \n\t"\
  71. "packuswb %%mm4, %%mm3 \n\t"\
  72. MOVNTQ(%%mm3, (%3, %%eax))\
  73. "addl $8, %%eax \n\t"\
  74. "cmpl %4, %%eax \n\t"\
  75. "pxor %%mm3, %%mm3 \n\t"\
  76. "pxor %%mm4, %%mm4 \n\t"\
  77. "movl %0, %%edx \n\t"\
  78. "jb 1b \n\t"
  79. #define YSCALEYUV2YV121 \
  80. "movl %2, %%eax \n\t"\
  81. ".balign 16 \n\t" /* FIXME Unroll? */\
  82. "1: \n\t"\
  83. "movq (%0, %%eax, 2), %%mm0 \n\t"\
  84. "movq 8(%0, %%eax, 2), %%mm1 \n\t"\
  85. "psraw $7, %%mm0 \n\t"\
  86. "psraw $7, %%mm1 \n\t"\
  87. "packuswb %%mm1, %%mm0 \n\t"\
  88. MOVNTQ(%%mm0, (%1, %%eax))\
  89. "addl $8, %%eax \n\t"\
  90. "jnc 1b \n\t"
  91. /*
  92. :: "m" (-lumFilterSize), "m" (-chrFilterSize),
  93. "m" (lumMmxFilter+lumFilterSize*4), "m" (chrMmxFilter+chrFilterSize*4),
  94. "r" (dest), "m" (dstW),
  95. "m" (lumSrc+lumFilterSize), "m" (chrSrc+chrFilterSize)
  96. : "%eax", "%ebx", "%ecx", "%edx", "%esi"
  97. */
  98. #define YSCALEYUV2RGBX \
  99. "xorl %%eax, %%eax \n\t"\
  100. ".balign 16 \n\t"\
  101. "1: \n\t"\
  102. "movl %1, %%edx \n\t" /* -chrFilterSize */\
  103. "movl %3, %%ebx \n\t" /* chrMmxFilter+lumFilterSize */\
  104. "movl %7, %%ecx \n\t" /* chrSrc+lumFilterSize */\
  105. "pxor %%mm3, %%mm3 \n\t"\
  106. "pxor %%mm4, %%mm4 \n\t"\
  107. "2: \n\t"\
  108. "movl (%%ecx, %%edx, 4), %%esi \n\t"\
  109. "movq (%%ebx, %%edx, 8), %%mm0 \n\t" /* filterCoeff */\
  110. "movq (%%esi, %%eax), %%mm2 \n\t" /* UsrcData */\
  111. "movq 4096(%%esi, %%eax), %%mm5 \n\t" /* VsrcData */\
  112. "pmulhw %%mm0, %%mm2 \n\t"\
  113. "pmulhw %%mm0, %%mm5 \n\t"\
  114. "paddw %%mm2, %%mm3 \n\t"\
  115. "paddw %%mm5, %%mm4 \n\t"\
  116. "addl $1, %%edx \n\t"\
  117. " jnz 2b \n\t"\
  118. \
  119. "movl %0, %%edx \n\t" /* -lumFilterSize */\
  120. "movl %2, %%ebx \n\t" /* lumMmxFilter+lumFilterSize */\
  121. "movl %6, %%ecx \n\t" /* lumSrc+lumFilterSize */\
  122. "pxor %%mm1, %%mm1 \n\t"\
  123. "pxor %%mm7, %%mm7 \n\t"\
  124. "2: \n\t"\
  125. "movl (%%ecx, %%edx, 4), %%esi \n\t"\
  126. "movq (%%ebx, %%edx, 8), %%mm0 \n\t" /* filterCoeff */\
  127. "movq (%%esi, %%eax, 2), %%mm2 \n\t" /* Y1srcData */\
  128. "movq 8(%%esi, %%eax, 2), %%mm5 \n\t" /* Y2srcData */\
  129. "pmulhw %%mm0, %%mm2 \n\t"\
  130. "pmulhw %%mm0, %%mm5 \n\t"\
  131. "paddw %%mm2, %%mm1 \n\t"\
  132. "paddw %%mm5, %%mm7 \n\t"\
  133. "addl $1, %%edx \n\t"\
  134. " jnz 2b \n\t"\
  135. \
  136. "psubw "MANGLE(w400)", %%mm3 \n\t" /* (U-128)8*/\
  137. "psubw "MANGLE(w400)", %%mm4 \n\t" /* (V-128)8*/\
  138. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  139. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  140. "pmulhw "MANGLE(ugCoeff)", %%mm3\n\t"\
  141. "pmulhw "MANGLE(vgCoeff)", %%mm4\n\t"\
  142. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  143. "pmulhw "MANGLE(ubCoeff)", %%mm2\n\t"\
  144. "pmulhw "MANGLE(vrCoeff)", %%mm5\n\t"\
  145. "psubw "MANGLE(w80)", %%mm1 \n\t" /* 8(Y-16)*/\
  146. "psubw "MANGLE(w80)", %%mm7 \n\t" /* 8(Y-16)*/\
  147. "pmulhw "MANGLE(yCoeff)", %%mm1 \n\t"\
  148. "pmulhw "MANGLE(yCoeff)", %%mm7 \n\t"\
  149. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  150. "paddw %%mm3, %%mm4 \n\t"\
  151. "movq %%mm2, %%mm0 \n\t"\
  152. "movq %%mm5, %%mm6 \n\t"\
  153. "movq %%mm4, %%mm3 \n\t"\
  154. "punpcklwd %%mm2, %%mm2 \n\t"\
  155. "punpcklwd %%mm5, %%mm5 \n\t"\
  156. "punpcklwd %%mm4, %%mm4 \n\t"\
  157. "paddw %%mm1, %%mm2 \n\t"\
  158. "paddw %%mm1, %%mm5 \n\t"\
  159. "paddw %%mm1, %%mm4 \n\t"\
  160. "punpckhwd %%mm0, %%mm0 \n\t"\
  161. "punpckhwd %%mm6, %%mm6 \n\t"\
  162. "punpckhwd %%mm3, %%mm3 \n\t"\
  163. "paddw %%mm7, %%mm0 \n\t"\
  164. "paddw %%mm7, %%mm6 \n\t"\
  165. "paddw %%mm7, %%mm3 \n\t"\
  166. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  167. "packuswb %%mm0, %%mm2 \n\t"\
  168. "packuswb %%mm6, %%mm5 \n\t"\
  169. "packuswb %%mm3, %%mm4 \n\t"\
  170. "pxor %%mm7, %%mm7 \n\t"
  171. #define FULL_YSCALEYUV2RGB \
  172. "pxor %%mm7, %%mm7 \n\t"\
  173. "movd %6, %%mm6 \n\t" /*yalpha1*/\
  174. "punpcklwd %%mm6, %%mm6 \n\t"\
  175. "punpcklwd %%mm6, %%mm6 \n\t"\
  176. "movd %7, %%mm5 \n\t" /*uvalpha1*/\
  177. "punpcklwd %%mm5, %%mm5 \n\t"\
  178. "punpcklwd %%mm5, %%mm5 \n\t"\
  179. "xorl %%eax, %%eax \n\t"\
  180. ".balign 16 \n\t"\
  181. "1: \n\t"\
  182. "movq (%0, %%eax, 2), %%mm0 \n\t" /*buf0[eax]*/\
  183. "movq (%1, %%eax, 2), %%mm1 \n\t" /*buf1[eax]*/\
  184. "movq (%2, %%eax,2), %%mm2 \n\t" /* uvbuf0[eax]*/\
  185. "movq (%3, %%eax,2), %%mm3 \n\t" /* uvbuf1[eax]*/\
  186. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  187. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  188. "pmulhw %%mm6, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  189. "pmulhw %%mm5, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  190. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  191. "movq 4096(%2, %%eax,2), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  192. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  193. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  194. "movq 4096(%3, %%eax,2), %%mm0 \n\t" /* uvbuf1[eax+2048]*/\
  195. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  196. "psubw %%mm0, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  197. "psubw "MANGLE(w80)", %%mm1 \n\t" /* 8(Y-16)*/\
  198. "psubw "MANGLE(w400)", %%mm3 \n\t" /* 8(U-128)*/\
  199. "pmulhw "MANGLE(yCoeff)", %%mm1 \n\t"\
  200. \
  201. \
  202. "pmulhw %%mm5, %%mm4 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  203. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  204. "pmulhw "MANGLE(ubCoeff)", %%mm3\n\t"\
  205. "psraw $4, %%mm0 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  206. "pmulhw "MANGLE(ugCoeff)", %%mm2\n\t"\
  207. "paddw %%mm4, %%mm0 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  208. "psubw "MANGLE(w400)", %%mm0 \n\t" /* (V-128)8*/\
  209. \
  210. \
  211. "movq %%mm0, %%mm4 \n\t" /* (V-128)8*/\
  212. "pmulhw "MANGLE(vrCoeff)", %%mm0\n\t"\
  213. "pmulhw "MANGLE(vgCoeff)", %%mm4\n\t"\
  214. "paddw %%mm1, %%mm3 \n\t" /* B*/\
  215. "paddw %%mm1, %%mm0 \n\t" /* R*/\
  216. "packuswb %%mm3, %%mm3 \n\t"\
  217. \
  218. "packuswb %%mm0, %%mm0 \n\t"\
  219. "paddw %%mm4, %%mm2 \n\t"\
  220. "paddw %%mm2, %%mm1 \n\t" /* G*/\
  221. \
  222. "packuswb %%mm1, %%mm1 \n\t"
  223. #define YSCALEYUV2RGB \
  224. "movd %6, %%mm6 \n\t" /*yalpha1*/\
  225. "punpcklwd %%mm6, %%mm6 \n\t"\
  226. "punpcklwd %%mm6, %%mm6 \n\t"\
  227. "movq %%mm6, "MANGLE(asm_yalpha1)"\n\t"\
  228. "movd %7, %%mm5 \n\t" /*uvalpha1*/\
  229. "punpcklwd %%mm5, %%mm5 \n\t"\
  230. "punpcklwd %%mm5, %%mm5 \n\t"\
  231. "movq %%mm5, "MANGLE(asm_uvalpha1)"\n\t"\
  232. "xorl %%eax, %%eax \n\t"\
  233. ".balign 16 \n\t"\
  234. "1: \n\t"\
  235. "movq (%2, %%eax), %%mm2 \n\t" /* uvbuf0[eax]*/\
  236. "movq (%3, %%eax), %%mm3 \n\t" /* uvbuf1[eax]*/\
  237. "movq 4096(%2, %%eax), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  238. "movq 4096(%3, %%eax), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  239. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  240. "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  241. "movq "MANGLE(asm_uvalpha1)", %%mm0\n\t"\
  242. "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  243. "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  244. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  245. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  246. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  247. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  248. "psubw "MANGLE(w400)", %%mm3 \n\t" /* (U-128)8*/\
  249. "psubw "MANGLE(w400)", %%mm4 \n\t" /* (V-128)8*/\
  250. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  251. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  252. "pmulhw "MANGLE(ugCoeff)", %%mm3\n\t"\
  253. "pmulhw "MANGLE(vgCoeff)", %%mm4\n\t"\
  254. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  255. "movq (%0, %%eax, 2), %%mm0 \n\t" /*buf0[eax]*/\
  256. "movq (%1, %%eax, 2), %%mm1 \n\t" /*buf1[eax]*/\
  257. "movq 8(%0, %%eax, 2), %%mm6 \n\t" /*buf0[eax]*/\
  258. "movq 8(%1, %%eax, 2), %%mm7 \n\t" /*buf1[eax]*/\
  259. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  260. "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
  261. "pmulhw "MANGLE(asm_yalpha1)", %%mm0\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  262. "pmulhw "MANGLE(asm_yalpha1)", %%mm6\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  263. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  264. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  265. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  266. "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  267. "pmulhw "MANGLE(ubCoeff)", %%mm2\n\t"\
  268. "pmulhw "MANGLE(vrCoeff)", %%mm5\n\t"\
  269. "psubw "MANGLE(w80)", %%mm1 \n\t" /* 8(Y-16)*/\
  270. "psubw "MANGLE(w80)", %%mm7 \n\t" /* 8(Y-16)*/\
  271. "pmulhw "MANGLE(yCoeff)", %%mm1 \n\t"\
  272. "pmulhw "MANGLE(yCoeff)", %%mm7 \n\t"\
  273. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  274. "paddw %%mm3, %%mm4 \n\t"\
  275. "movq %%mm2, %%mm0 \n\t"\
  276. "movq %%mm5, %%mm6 \n\t"\
  277. "movq %%mm4, %%mm3 \n\t"\
  278. "punpcklwd %%mm2, %%mm2 \n\t"\
  279. "punpcklwd %%mm5, %%mm5 \n\t"\
  280. "punpcklwd %%mm4, %%mm4 \n\t"\
  281. "paddw %%mm1, %%mm2 \n\t"\
  282. "paddw %%mm1, %%mm5 \n\t"\
  283. "paddw %%mm1, %%mm4 \n\t"\
  284. "punpckhwd %%mm0, %%mm0 \n\t"\
  285. "punpckhwd %%mm6, %%mm6 \n\t"\
  286. "punpckhwd %%mm3, %%mm3 \n\t"\
  287. "paddw %%mm7, %%mm0 \n\t"\
  288. "paddw %%mm7, %%mm6 \n\t"\
  289. "paddw %%mm7, %%mm3 \n\t"\
  290. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  291. "packuswb %%mm0, %%mm2 \n\t"\
  292. "packuswb %%mm6, %%mm5 \n\t"\
  293. "packuswb %%mm3, %%mm4 \n\t"\
  294. "pxor %%mm7, %%mm7 \n\t"
  295. #define YSCALEYUV2RGB1 \
  296. "xorl %%eax, %%eax \n\t"\
  297. ".balign 16 \n\t"\
  298. "1: \n\t"\
  299. "movq (%2, %%eax), %%mm3 \n\t" /* uvbuf0[eax]*/\
  300. "movq 4096(%2, %%eax), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  301. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  302. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  303. "psubw "MANGLE(w400)", %%mm3 \n\t" /* (U-128)8*/\
  304. "psubw "MANGLE(w400)", %%mm4 \n\t" /* (V-128)8*/\
  305. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  306. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  307. "pmulhw "MANGLE(ugCoeff)", %%mm3\n\t"\
  308. "pmulhw "MANGLE(vgCoeff)", %%mm4\n\t"\
  309. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  310. "movq (%0, %%eax, 2), %%mm1 \n\t" /*buf0[eax]*/\
  311. "movq 8(%0, %%eax, 2), %%mm7 \n\t" /*buf0[eax]*/\
  312. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  313. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  314. "pmulhw "MANGLE(ubCoeff)", %%mm2\n\t"\
  315. "pmulhw "MANGLE(vrCoeff)", %%mm5\n\t"\
  316. "psubw "MANGLE(w80)", %%mm1 \n\t" /* 8(Y-16)*/\
  317. "psubw "MANGLE(w80)", %%mm7 \n\t" /* 8(Y-16)*/\
  318. "pmulhw "MANGLE(yCoeff)", %%mm1 \n\t"\
  319. "pmulhw "MANGLE(yCoeff)", %%mm7 \n\t"\
  320. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  321. "paddw %%mm3, %%mm4 \n\t"\
  322. "movq %%mm2, %%mm0 \n\t"\
  323. "movq %%mm5, %%mm6 \n\t"\
  324. "movq %%mm4, %%mm3 \n\t"\
  325. "punpcklwd %%mm2, %%mm2 \n\t"\
  326. "punpcklwd %%mm5, %%mm5 \n\t"\
  327. "punpcklwd %%mm4, %%mm4 \n\t"\
  328. "paddw %%mm1, %%mm2 \n\t"\
  329. "paddw %%mm1, %%mm5 \n\t"\
  330. "paddw %%mm1, %%mm4 \n\t"\
  331. "punpckhwd %%mm0, %%mm0 \n\t"\
  332. "punpckhwd %%mm6, %%mm6 \n\t"\
  333. "punpckhwd %%mm3, %%mm3 \n\t"\
  334. "paddw %%mm7, %%mm0 \n\t"\
  335. "paddw %%mm7, %%mm6 \n\t"\
  336. "paddw %%mm7, %%mm3 \n\t"\
  337. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  338. "packuswb %%mm0, %%mm2 \n\t"\
  339. "packuswb %%mm6, %%mm5 \n\t"\
  340. "packuswb %%mm3, %%mm4 \n\t"\
  341. "pxor %%mm7, %%mm7 \n\t"
  342. // do vertical chrominance interpolation
  343. #define YSCALEYUV2RGB1b \
  344. "xorl %%eax, %%eax \n\t"\
  345. ".balign 16 \n\t"\
  346. "1: \n\t"\
  347. "movq (%2, %%eax), %%mm2 \n\t" /* uvbuf0[eax]*/\
  348. "movq (%3, %%eax), %%mm3 \n\t" /* uvbuf1[eax]*/\
  349. "movq 4096(%2, %%eax), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  350. "movq 4096(%3, %%eax), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  351. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
  352. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
  353. "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\
  354. "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\
  355. "psubw "MANGLE(w400)", %%mm3 \n\t" /* (U-128)8*/\
  356. "psubw "MANGLE(w400)", %%mm4 \n\t" /* (V-128)8*/\
  357. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  358. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  359. "pmulhw "MANGLE(ugCoeff)", %%mm3\n\t"\
  360. "pmulhw "MANGLE(vgCoeff)", %%mm4\n\t"\
  361. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  362. "movq (%0, %%eax, 2), %%mm1 \n\t" /*buf0[eax]*/\
  363. "movq 8(%0, %%eax, 2), %%mm7 \n\t" /*buf0[eax]*/\
  364. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  365. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  366. "pmulhw "MANGLE(ubCoeff)", %%mm2\n\t"\
  367. "pmulhw "MANGLE(vrCoeff)", %%mm5\n\t"\
  368. "psubw "MANGLE(w80)", %%mm1 \n\t" /* 8(Y-16)*/\
  369. "psubw "MANGLE(w80)", %%mm7 \n\t" /* 8(Y-16)*/\
  370. "pmulhw "MANGLE(yCoeff)", %%mm1 \n\t"\
  371. "pmulhw "MANGLE(yCoeff)", %%mm7 \n\t"\
  372. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  373. "paddw %%mm3, %%mm4 \n\t"\
  374. "movq %%mm2, %%mm0 \n\t"\
  375. "movq %%mm5, %%mm6 \n\t"\
  376. "movq %%mm4, %%mm3 \n\t"\
  377. "punpcklwd %%mm2, %%mm2 \n\t"\
  378. "punpcklwd %%mm5, %%mm5 \n\t"\
  379. "punpcklwd %%mm4, %%mm4 \n\t"\
  380. "paddw %%mm1, %%mm2 \n\t"\
  381. "paddw %%mm1, %%mm5 \n\t"\
  382. "paddw %%mm1, %%mm4 \n\t"\
  383. "punpckhwd %%mm0, %%mm0 \n\t"\
  384. "punpckhwd %%mm6, %%mm6 \n\t"\
  385. "punpckhwd %%mm3, %%mm3 \n\t"\
  386. "paddw %%mm7, %%mm0 \n\t"\
  387. "paddw %%mm7, %%mm6 \n\t"\
  388. "paddw %%mm7, %%mm3 \n\t"\
  389. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  390. "packuswb %%mm0, %%mm2 \n\t"\
  391. "packuswb %%mm6, %%mm5 \n\t"\
  392. "packuswb %%mm3, %%mm4 \n\t"\
  393. "pxor %%mm7, %%mm7 \n\t"
  394. #define WRITEBGR32 \
  395. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  396. "movq %%mm2, %%mm1 \n\t" /* B */\
  397. "movq %%mm5, %%mm6 \n\t" /* R */\
  398. "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
  399. "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
  400. "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
  401. "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
  402. "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
  403. "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
  404. "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
  405. "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
  406. "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
  407. "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
  408. \
  409. MOVNTQ(%%mm0, (%4, %%eax, 4))\
  410. MOVNTQ(%%mm2, 8(%4, %%eax, 4))\
  411. MOVNTQ(%%mm1, 16(%4, %%eax, 4))\
  412. MOVNTQ(%%mm3, 24(%4, %%eax, 4))\
  413. \
  414. "addl $8, %%eax \n\t"\
  415. "cmpl %5, %%eax \n\t"\
  416. " jb 1b \n\t"
  417. #define WRITEBGR16 \
  418. "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\
  419. "pand "MANGLE(bFC)", %%mm4 \n\t" /* G */\
  420. "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\
  421. "psrlq $3, %%mm2 \n\t"\
  422. \
  423. "movq %%mm2, %%mm1 \n\t"\
  424. "movq %%mm4, %%mm3 \n\t"\
  425. \
  426. "punpcklbw %%mm7, %%mm3 \n\t"\
  427. "punpcklbw %%mm5, %%mm2 \n\t"\
  428. "punpckhbw %%mm7, %%mm4 \n\t"\
  429. "punpckhbw %%mm5, %%mm1 \n\t"\
  430. \
  431. "psllq $3, %%mm3 \n\t"\
  432. "psllq $3, %%mm4 \n\t"\
  433. \
  434. "por %%mm3, %%mm2 \n\t"\
  435. "por %%mm4, %%mm1 \n\t"\
  436. \
  437. MOVNTQ(%%mm2, (%4, %%eax, 2))\
  438. MOVNTQ(%%mm1, 8(%4, %%eax, 2))\
  439. \
  440. "addl $8, %%eax \n\t"\
  441. "cmpl %5, %%eax \n\t"\
  442. " jb 1b \n\t"
  443. #define WRITEBGR15 \
  444. "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\
  445. "pand "MANGLE(bF8)", %%mm4 \n\t" /* G */\
  446. "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\
  447. "psrlq $3, %%mm2 \n\t"\
  448. "psrlq $1, %%mm5 \n\t"\
  449. \
  450. "movq %%mm2, %%mm1 \n\t"\
  451. "movq %%mm4, %%mm3 \n\t"\
  452. \
  453. "punpcklbw %%mm7, %%mm3 \n\t"\
  454. "punpcklbw %%mm5, %%mm2 \n\t"\
  455. "punpckhbw %%mm7, %%mm4 \n\t"\
  456. "punpckhbw %%mm5, %%mm1 \n\t"\
  457. \
  458. "psllq $2, %%mm3 \n\t"\
  459. "psllq $2, %%mm4 \n\t"\
  460. \
  461. "por %%mm3, %%mm2 \n\t"\
  462. "por %%mm4, %%mm1 \n\t"\
  463. \
  464. MOVNTQ(%%mm2, (%4, %%eax, 2))\
  465. MOVNTQ(%%mm1, 8(%4, %%eax, 2))\
  466. \
  467. "addl $8, %%eax \n\t"\
  468. "cmpl %5, %%eax \n\t"\
  469. " jb 1b \n\t"
  470. #define WRITEBGR24OLD \
  471. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  472. "movq %%mm2, %%mm1 \n\t" /* B */\
  473. "movq %%mm5, %%mm6 \n\t" /* R */\
  474. "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
  475. "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
  476. "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
  477. "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
  478. "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
  479. "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
  480. "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
  481. "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
  482. "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
  483. "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
  484. \
  485. "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\
  486. "psrlq $8, %%mm0 \n\t" /* 00RGB0RG 0 */\
  487. "pand "MANGLE(bm00000111)", %%mm4\n\t" /* 00000RGB 0 */\
  488. "pand "MANGLE(bm11111000)", %%mm0\n\t" /* 00RGB000 0.5 */\
  489. "por %%mm4, %%mm0 \n\t" /* 00RGBRGB 0 */\
  490. "movq %%mm2, %%mm4 \n\t" /* 0RGB0RGB 1 */\
  491. "psllq $48, %%mm2 \n\t" /* GB000000 1 */\
  492. "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\
  493. \
  494. "movq %%mm4, %%mm2 \n\t" /* 0RGB0RGB 1 */\
  495. "psrld $16, %%mm4 \n\t" /* 000R000R 1 */\
  496. "psrlq $24, %%mm2 \n\t" /* 0000RGB0 1.5 */\
  497. "por %%mm4, %%mm2 \n\t" /* 000RRGBR 1 */\
  498. "pand "MANGLE(bm00001111)", %%mm2\n\t" /* 0000RGBR 1 */\
  499. "movq %%mm1, %%mm4 \n\t" /* 0RGB0RGB 2 */\
  500. "psrlq $8, %%mm1 \n\t" /* 00RGB0RG 2 */\
  501. "pand "MANGLE(bm00000111)", %%mm4\n\t" /* 00000RGB 2 */\
  502. "pand "MANGLE(bm11111000)", %%mm1\n\t" /* 00RGB000 2.5 */\
  503. "por %%mm4, %%mm1 \n\t" /* 00RGBRGB 2 */\
  504. "movq %%mm1, %%mm4 \n\t" /* 00RGBRGB 2 */\
  505. "psllq $32, %%mm1 \n\t" /* BRGB0000 2 */\
  506. "por %%mm1, %%mm2 \n\t" /* BRGBRGBR 1 */\
  507. \
  508. "psrlq $32, %%mm4 \n\t" /* 000000RG 2.5 */\
  509. "movq %%mm3, %%mm5 \n\t" /* 0RGB0RGB 3 */\
  510. "psrlq $8, %%mm3 \n\t" /* 00RGB0RG 3 */\
  511. "pand "MANGLE(bm00000111)", %%mm5\n\t" /* 00000RGB 3 */\
  512. "pand "MANGLE(bm11111000)", %%mm3\n\t" /* 00RGB000 3.5 */\
  513. "por %%mm5, %%mm3 \n\t" /* 00RGBRGB 3 */\
  514. "psllq $16, %%mm3 \n\t" /* RGBRGB00 3 */\
  515. "por %%mm4, %%mm3 \n\t" /* RGBRGBRG 2.5 */\
  516. \
  517. MOVNTQ(%%mm0, (%%ebx))\
  518. MOVNTQ(%%mm2, 8(%%ebx))\
  519. MOVNTQ(%%mm3, 16(%%ebx))\
  520. "addl $24, %%ebx \n\t"\
  521. \
  522. "addl $8, %%eax \n\t"\
  523. "cmpl %5, %%eax \n\t"\
  524. " jb 1b \n\t"
  525. #define WRITEBGR24MMX \
  526. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  527. "movq %%mm2, %%mm1 \n\t" /* B */\
  528. "movq %%mm5, %%mm6 \n\t" /* R */\
  529. "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
  530. "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
  531. "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
  532. "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
  533. "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
  534. "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
  535. "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
  536. "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
  537. "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
  538. "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
  539. \
  540. "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\
  541. "movq %%mm2, %%mm6 \n\t" /* 0RGB0RGB 1 */\
  542. "movq %%mm1, %%mm5 \n\t" /* 0RGB0RGB 2 */\
  543. "movq %%mm3, %%mm7 \n\t" /* 0RGB0RGB 3 */\
  544. \
  545. "psllq $40, %%mm0 \n\t" /* RGB00000 0 */\
  546. "psllq $40, %%mm2 \n\t" /* RGB00000 1 */\
  547. "psllq $40, %%mm1 \n\t" /* RGB00000 2 */\
  548. "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\
  549. \
  550. "punpckhdq %%mm4, %%mm0 \n\t" /* 0RGBRGB0 0 */\
  551. "punpckhdq %%mm6, %%mm2 \n\t" /* 0RGBRGB0 1 */\
  552. "punpckhdq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */\
  553. "punpckhdq %%mm7, %%mm3 \n\t" /* 0RGBRGB0 3 */\
  554. \
  555. "psrlq $8, %%mm0 \n\t" /* 00RGBRGB 0 */\
  556. "movq %%mm2, %%mm6 \n\t" /* 0RGBRGB0 1 */\
  557. "psllq $40, %%mm2 \n\t" /* GB000000 1 */\
  558. "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\
  559. MOVNTQ(%%mm0, (%%ebx))\
  560. \
  561. "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\
  562. "movq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */\
  563. "psllq $24, %%mm1 \n\t" /* BRGB0000 2 */\
  564. "por %%mm1, %%mm6 \n\t" /* BRGBRGBR 1 */\
  565. MOVNTQ(%%mm6, 8(%%ebx))\
  566. \
  567. "psrlq $40, %%mm5 \n\t" /* 000000RG 2 */\
  568. "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\
  569. "por %%mm3, %%mm5 \n\t" /* RGBRGBRG 2 */\
  570. MOVNTQ(%%mm5, 16(%%ebx))\
  571. \
  572. "addl $24, %%ebx \n\t"\
  573. \
  574. "addl $8, %%eax \n\t"\
  575. "cmpl %5, %%eax \n\t"\
  576. " jb 1b \n\t"
  577. #define WRITEBGR24MMX2 \
  578. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  579. "movq "MANGLE(M24A)", %%mm0 \n\t"\
  580. "movq "MANGLE(M24C)", %%mm7 \n\t"\
  581. "pshufw $0x50, %%mm2, %%mm1 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\
  582. "pshufw $0x50, %%mm4, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\
  583. "pshufw $0x00, %%mm5, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\
  584. \
  585. "pand %%mm0, %%mm1 \n\t" /* B2 B1 B0 */\
  586. "pand %%mm0, %%mm3 \n\t" /* G2 G1 G0 */\
  587. "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\
  588. \
  589. "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\
  590. "por %%mm1, %%mm6 \n\t"\
  591. "por %%mm3, %%mm6 \n\t"\
  592. MOVNTQ(%%mm6, (%%ebx))\
  593. \
  594. "psrlq $8, %%mm4 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\
  595. "pshufw $0xA5, %%mm2, %%mm1 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\
  596. "pshufw $0x55, %%mm4, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\
  597. "pshufw $0xA5, %%mm5, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\
  598. \
  599. "pand "MANGLE(M24B)", %%mm1 \n\t" /* B5 B4 B3 */\
  600. "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\
  601. "pand %%mm0, %%mm6 \n\t" /* R4 R3 R2 */\
  602. \
  603. "por %%mm1, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\
  604. "por %%mm3, %%mm6 \n\t"\
  605. MOVNTQ(%%mm6, 8(%%ebx))\
  606. \
  607. "pshufw $0xFF, %%mm2, %%mm1 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\
  608. "pshufw $0xFA, %%mm4, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\
  609. "pshufw $0xFA, %%mm5, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\
  610. \
  611. "pand %%mm7, %%mm1 \n\t" /* B7 B6 */\
  612. "pand %%mm0, %%mm3 \n\t" /* G7 G6 G5 */\
  613. "pand "MANGLE(M24B)", %%mm6 \n\t" /* R7 R6 R5 */\
  614. \
  615. "por %%mm1, %%mm3 \n\t"\
  616. "por %%mm3, %%mm6 \n\t"\
  617. MOVNTQ(%%mm6, 16(%%ebx))\
  618. \
  619. "addl $24, %%ebx \n\t"\
  620. \
  621. "addl $8, %%eax \n\t"\
  622. "cmpl %5, %%eax \n\t"\
  623. " jb 1b \n\t"
  624. #ifdef HAVE_MMX2
  625. #undef WRITEBGR24
  626. #define WRITEBGR24 WRITEBGR24MMX2
  627. #else
  628. #undef WRITEBGR24
  629. #define WRITEBGR24 WRITEBGR24MMX
  630. #endif
  631. static inline void RENAME(yuv2yuvX)(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
  632. int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
  633. uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW,
  634. int16_t * lumMmxFilter, int16_t * chrMmxFilter)
  635. {
  636. #ifdef HAVE_MMX
  637. if(uDest != NULL)
  638. {
  639. asm volatile(
  640. YSCALEYUV2YV12X(0)
  641. :: "m" (-chrFilterSize), "r" (chrSrc+chrFilterSize),
  642. "r" (chrMmxFilter+chrFilterSize*4), "r" (uDest), "m" (dstW>>1)
  643. : "%eax", "%edx", "%esi"
  644. );
  645. asm volatile(
  646. YSCALEYUV2YV12X(4096)
  647. :: "m" (-chrFilterSize), "r" (chrSrc+chrFilterSize),
  648. "r" (chrMmxFilter+chrFilterSize*4), "r" (vDest), "m" (dstW>>1)
  649. : "%eax", "%edx", "%esi"
  650. );
  651. }
  652. asm volatile(
  653. YSCALEYUV2YV12X(0)
  654. :: "m" (-lumFilterSize), "r" (lumSrc+lumFilterSize),
  655. "r" (lumMmxFilter+lumFilterSize*4), "r" (dest), "m" (dstW)
  656. : "%eax", "%edx", "%esi"
  657. );
  658. #else
  659. yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize,
  660. chrFilter, chrSrc, chrFilterSize,
  661. dest, uDest, vDest, dstW);
  662. #endif
  663. }
  664. static inline void RENAME(yuv2yuv1)(int16_t *lumSrc, int16_t *chrSrc,
  665. uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW)
  666. {
  667. #ifdef HAVE_MMX
  668. if(uDest != NULL)
  669. {
  670. asm volatile(
  671. YSCALEYUV2YV121
  672. :: "r" (chrSrc + (dstW>>1)), "r" (uDest + (dstW>>1)),
  673. "g" (-(dstW>>1))
  674. : "%eax"
  675. );
  676. asm volatile(
  677. YSCALEYUV2YV121
  678. :: "r" (chrSrc + 2048 + (dstW>>1)), "r" (vDest + (dstW>>1)),
  679. "g" (-(dstW>>1))
  680. : "%eax"
  681. );
  682. }
  683. asm volatile(
  684. YSCALEYUV2YV121
  685. :: "r" (lumSrc + dstW), "r" (dest + dstW),
  686. "g" (-dstW)
  687. : "%eax"
  688. );
  689. #else
  690. //FIXME Optimize (just quickly writen not opti..)
  691. //FIXME replace MINMAX with LUTs
  692. int i;
  693. for(i=0; i<dstW; i++)
  694. {
  695. int val= lumSrc[i]>>7;
  696. dest[i]= MIN(MAX(val>>19, 0), 255);
  697. }
  698. if(uDest != NULL)
  699. for(i=0; i<(dstW>>1); i++)
  700. {
  701. int u=chrSrc[i]>>7;
  702. int v=chrSrc[i + 2048]>>7;
  703. uDest[i]= MIN(MAX(u>>19, 0), 255);
  704. vDest[i]= MIN(MAX(v>>19, 0), 255);
  705. }
  706. #endif
  707. }
  708. /**
  709. * vertical scale YV12 to RGB
  710. */
  711. static inline void RENAME(yuv2rgbX)(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
  712. int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
  713. uint8_t *dest, int dstW, int dstFormat, int16_t * lumMmxFilter, int16_t * chrMmxFilter)
  714. {
  715. /* if(flags&SWS_FULL_UV_IPOL)
  716. {
  717. //FIXME
  718. }//FULL_UV_IPOL
  719. else*/
  720. {
  721. #ifdef HAVE_MMX
  722. if(dstFormat == IMGFMT_BGR32) //FIXME untested
  723. {
  724. asm volatile(
  725. YSCALEYUV2RGBX
  726. WRITEBGR32
  727. :: "m" (-lumFilterSize), "m" (-chrFilterSize),
  728. "m" (lumMmxFilter+lumFilterSize*4), "m" (chrMmxFilter+chrFilterSize*4),
  729. "r" (dest), "m" (dstW),
  730. "m" (lumSrc+lumFilterSize), "m" (chrSrc+chrFilterSize)
  731. : "%eax", "%ebx", "%ecx", "%edx", "%esi"
  732. );
  733. }
  734. else if(dstFormat == IMGFMT_BGR24) //FIXME untested
  735. {
  736. asm volatile(
  737. YSCALEYUV2RGBX
  738. "leal (%%eax, %%eax, 2), %%ebx \n\t" //FIXME optimize
  739. "addl %4, %%ebx \n\t"
  740. WRITEBGR24
  741. :: "m" (-lumFilterSize), "m" (-chrFilterSize),
  742. "m" (lumMmxFilter+lumFilterSize*4), "m" (chrMmxFilter+chrFilterSize*4),
  743. "r" (dest), "m" (dstW),
  744. "m" (lumSrc+lumFilterSize), "m" (chrSrc+chrFilterSize)
  745. : "%eax", "%ebx", "%ecx", "%edx", "%esi"
  746. );
  747. }
  748. else if(dstFormat==IMGFMT_BGR15)
  749. {
  750. asm volatile(
  751. YSCALEYUV2RGBX
  752. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  753. #ifdef DITHER1XBPP
  754. "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
  755. "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
  756. "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
  757. #endif
  758. WRITEBGR15
  759. :: "m" (-lumFilterSize), "m" (-chrFilterSize),
  760. "m" (lumMmxFilter+lumFilterSize*4), "m" (chrMmxFilter+chrFilterSize*4),
  761. "r" (dest), "m" (dstW),
  762. "m" (lumSrc+lumFilterSize), "m" (chrSrc+chrFilterSize)
  763. : "%eax", "%ebx", "%ecx", "%edx", "%esi"
  764. );
  765. }
  766. else if(dstFormat==IMGFMT_BGR16)
  767. {
  768. asm volatile(
  769. YSCALEYUV2RGBX
  770. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  771. #ifdef DITHER1XBPP
  772. "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
  773. "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
  774. "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
  775. #endif
  776. WRITEBGR16
  777. :: "m" (-lumFilterSize), "m" (-chrFilterSize),
  778. "m" (lumMmxFilter+lumFilterSize*4), "m" (chrMmxFilter+chrFilterSize*4),
  779. "r" (dest), "m" (dstW),
  780. "m" (lumSrc+lumFilterSize), "m" (chrSrc+chrFilterSize)
  781. : "%eax", "%ebx", "%ecx", "%edx", "%esi"
  782. );
  783. }
  784. #else
  785. yuv2rgbXinC(lumFilter, lumSrc, lumFilterSize,
  786. chrFilter, chrSrc, chrFilterSize,
  787. dest, dstW, dstFormat);
  788. #endif
  789. } //!FULL_UV_IPOL
  790. }
  791. /**
  792. * vertical bilinear scale YV12 to RGB
  793. */
  794. static inline void RENAME(yuv2rgb2)(uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1,
  795. uint8_t *dest, int dstW, int yalpha, int uvalpha, int dstFormat, int flags)
  796. {
  797. int yalpha1=yalpha^4095;
  798. int uvalpha1=uvalpha^4095;
  799. if(flags&SWS_FULL_CHR_H_INT)
  800. {
  801. #ifdef HAVE_MMX
  802. if(dstFormat==IMGFMT_BGR32)
  803. {
  804. asm volatile(
  805. FULL_YSCALEYUV2RGB
  806. "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
  807. "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
  808. "movq %%mm3, %%mm1 \n\t"
  809. "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
  810. "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
  811. MOVNTQ(%%mm3, (%4, %%eax, 4))
  812. MOVNTQ(%%mm1, 8(%4, %%eax, 4))
  813. "addl $4, %%eax \n\t"
  814. "cmpl %5, %%eax \n\t"
  815. " jb 1b \n\t"
  816. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  817. "m" (yalpha1), "m" (uvalpha1)
  818. : "%eax"
  819. );
  820. }
  821. else if(dstFormat==IMGFMT_BGR24)
  822. {
  823. asm volatile(
  824. FULL_YSCALEYUV2RGB
  825. // lsb ... msb
  826. "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
  827. "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
  828. "movq %%mm3, %%mm1 \n\t"
  829. "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
  830. "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
  831. "movq %%mm3, %%mm2 \n\t" // BGR0BGR0
  832. "psrlq $8, %%mm3 \n\t" // GR0BGR00
  833. "pand "MANGLE(bm00000111)", %%mm2\n\t" // BGR00000
  834. "pand "MANGLE(bm11111000)", %%mm3\n\t" // 000BGR00
  835. "por %%mm2, %%mm3 \n\t" // BGRBGR00
  836. "movq %%mm1, %%mm2 \n\t"
  837. "psllq $48, %%mm1 \n\t" // 000000BG
  838. "por %%mm1, %%mm3 \n\t" // BGRBGRBG
  839. "movq %%mm2, %%mm1 \n\t" // BGR0BGR0
  840. "psrld $16, %%mm2 \n\t" // R000R000
  841. "psrlq $24, %%mm1 \n\t" // 0BGR0000
  842. "por %%mm2, %%mm1 \n\t" // RBGRR000
  843. "movl %4, %%ebx \n\t"
  844. "addl %%eax, %%ebx \n\t"
  845. #ifdef HAVE_MMX2
  846. //FIXME Alignment
  847. "movntq %%mm3, (%%ebx, %%eax, 2)\n\t"
  848. "movntq %%mm1, 8(%%ebx, %%eax, 2)\n\t"
  849. #else
  850. "movd %%mm3, (%%ebx, %%eax, 2) \n\t"
  851. "psrlq $32, %%mm3 \n\t"
  852. "movd %%mm3, 4(%%ebx, %%eax, 2) \n\t"
  853. "movd %%mm1, 8(%%ebx, %%eax, 2) \n\t"
  854. #endif
  855. "addl $4, %%eax \n\t"
  856. "cmpl %5, %%eax \n\t"
  857. " jb 1b \n\t"
  858. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW),
  859. "m" (yalpha1), "m" (uvalpha1)
  860. : "%eax", "%ebx"
  861. );
  862. }
  863. else if(dstFormat==IMGFMT_BGR15)
  864. {
  865. asm volatile(
  866. FULL_YSCALEYUV2RGB
  867. #ifdef DITHER1XBPP
  868. "paddusb "MANGLE(g5Dither)", %%mm1\n\t"
  869. "paddusb "MANGLE(r5Dither)", %%mm0\n\t"
  870. "paddusb "MANGLE(b5Dither)", %%mm3\n\t"
  871. #endif
  872. "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
  873. "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
  874. "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
  875. "psrlw $3, %%mm3 \n\t"
  876. "psllw $2, %%mm1 \n\t"
  877. "psllw $7, %%mm0 \n\t"
  878. "pand "MANGLE(g15Mask)", %%mm1 \n\t"
  879. "pand "MANGLE(r15Mask)", %%mm0 \n\t"
  880. "por %%mm3, %%mm1 \n\t"
  881. "por %%mm1, %%mm0 \n\t"
  882. MOVNTQ(%%mm0, (%4, %%eax, 2))
  883. "addl $4, %%eax \n\t"
  884. "cmpl %5, %%eax \n\t"
  885. " jb 1b \n\t"
  886. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  887. "m" (yalpha1), "m" (uvalpha1)
  888. : "%eax"
  889. );
  890. }
  891. else if(dstFormat==IMGFMT_BGR16)
  892. {
  893. asm volatile(
  894. FULL_YSCALEYUV2RGB
  895. #ifdef DITHER1XBPP
  896. "paddusb "MANGLE(g6Dither)", %%mm1\n\t"
  897. "paddusb "MANGLE(r5Dither)", %%mm0\n\t"
  898. "paddusb "MANGLE(b5Dither)", %%mm3\n\t"
  899. #endif
  900. "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
  901. "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
  902. "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
  903. "psrlw $3, %%mm3 \n\t"
  904. "psllw $3, %%mm1 \n\t"
  905. "psllw $8, %%mm0 \n\t"
  906. "pand "MANGLE(g16Mask)", %%mm1 \n\t"
  907. "pand "MANGLE(r16Mask)", %%mm0 \n\t"
  908. "por %%mm3, %%mm1 \n\t"
  909. "por %%mm1, %%mm0 \n\t"
  910. MOVNTQ(%%mm0, (%4, %%eax, 2))
  911. "addl $4, %%eax \n\t"
  912. "cmpl %5, %%eax \n\t"
  913. " jb 1b \n\t"
  914. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  915. "m" (yalpha1), "m" (uvalpha1)
  916. : "%eax"
  917. );
  918. }
  919. #else
  920. if(dstFormat==IMGFMT_BGR32)
  921. {
  922. int i;
  923. for(i=0;i<dstW;i++){
  924. // vertical linear interpolation && yuv2rgb in a single step:
  925. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  926. int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
  927. int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
  928. dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)];
  929. dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)];
  930. dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)];
  931. dest+= 4;
  932. }
  933. }
  934. else if(dstFormat==IMGFMT_BGR24)
  935. {
  936. int i;
  937. for(i=0;i<dstW;i++){
  938. // vertical linear interpolation && yuv2rgb in a single step:
  939. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  940. int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
  941. int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
  942. dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)];
  943. dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)];
  944. dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)];
  945. dest+= 3;
  946. }
  947. }
  948. else if(dstFormat==IMGFMT_BGR16)
  949. {
  950. int i;
  951. for(i=0;i<dstW;i++){
  952. // vertical linear interpolation && yuv2rgb in a single step:
  953. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  954. int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
  955. int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
  956. ((uint16_t*)dest)[i] =
  957. clip_table16b[(Y + yuvtab_40cf[U]) >>13] |
  958. clip_table16g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] |
  959. clip_table16r[(Y + yuvtab_3343[V]) >>13];
  960. }
  961. }
  962. else if(dstFormat==IMGFMT_BGR15)
  963. {
  964. int i;
  965. for(i=0;i<dstW;i++){
  966. // vertical linear interpolation && yuv2rgb in a single step:
  967. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  968. int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
  969. int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
  970. ((uint16_t*)dest)[i] =
  971. clip_table15b[(Y + yuvtab_40cf[U]) >>13] |
  972. clip_table15g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] |
  973. clip_table15r[(Y + yuvtab_3343[V]) >>13];
  974. }
  975. }
  976. #endif
  977. }//FULL_UV_IPOL
  978. else
  979. {
  980. #ifdef HAVE_MMX
  981. if(dstFormat==IMGFMT_BGR32)
  982. {
  983. asm volatile(
  984. YSCALEYUV2RGB
  985. WRITEBGR32
  986. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  987. "m" (yalpha1), "m" (uvalpha1)
  988. : "%eax"
  989. );
  990. }
  991. else if(dstFormat==IMGFMT_BGR24)
  992. {
  993. asm volatile(
  994. "movl %4, %%ebx \n\t"
  995. YSCALEYUV2RGB
  996. WRITEBGR24
  997. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW),
  998. "m" (yalpha1), "m" (uvalpha1)
  999. : "%eax", "%ebx"
  1000. );
  1001. }
  1002. else if(dstFormat==IMGFMT_BGR15)
  1003. {
  1004. asm volatile(
  1005. YSCALEYUV2RGB
  1006. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1007. #ifdef DITHER1XBPP
  1008. "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
  1009. "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
  1010. "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
  1011. #endif
  1012. WRITEBGR15
  1013. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  1014. "m" (yalpha1), "m" (uvalpha1)
  1015. : "%eax"
  1016. );
  1017. }
  1018. else if(dstFormat==IMGFMT_BGR16)
  1019. {
  1020. asm volatile(
  1021. YSCALEYUV2RGB
  1022. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1023. #ifdef DITHER1XBPP
  1024. "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
  1025. "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
  1026. "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
  1027. #endif
  1028. WRITEBGR16
  1029. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  1030. "m" (yalpha1), "m" (uvalpha1)
  1031. : "%eax"
  1032. );
  1033. }
  1034. #else
  1035. if(dstFormat==IMGFMT_BGR32)
  1036. {
  1037. int i;
  1038. for(i=0; i<dstW-1; i+=2){
  1039. // vertical linear interpolation && yuv2rgb in a single step:
  1040. int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  1041. int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
  1042. int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
  1043. int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
  1044. int Cb= yuvtab_40cf[U];
  1045. int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
  1046. int Cr= yuvtab_3343[V];
  1047. dest[4*i+0]=clip_table[((Y1 + Cb) >>13)];
  1048. dest[4*i+1]=clip_table[((Y1 + Cg) >>13)];
  1049. dest[4*i+2]=clip_table[((Y1 + Cr) >>13)];
  1050. dest[4*i+4]=clip_table[((Y2 + Cb) >>13)];
  1051. dest[4*i+5]=clip_table[((Y2 + Cg) >>13)];
  1052. dest[4*i+6]=clip_table[((Y2 + Cr) >>13)];
  1053. }
  1054. }
  1055. else if(dstFormat==IMGFMT_BGR24)
  1056. {
  1057. int i;
  1058. for(i=0; i<dstW-1; i+=2){
  1059. // vertical linear interpolation && yuv2rgb in a single step:
  1060. int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  1061. int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
  1062. int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
  1063. int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
  1064. int Cb= yuvtab_40cf[U];
  1065. int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
  1066. int Cr= yuvtab_3343[V];
  1067. dest[0]=clip_table[((Y1 + Cb) >>13)];
  1068. dest[1]=clip_table[((Y1 + Cg) >>13)];
  1069. dest[2]=clip_table[((Y1 + Cr) >>13)];
  1070. dest[3]=clip_table[((Y2 + Cb) >>13)];
  1071. dest[4]=clip_table[((Y2 + Cg) >>13)];
  1072. dest[5]=clip_table[((Y2 + Cr) >>13)];
  1073. dest+=6;
  1074. }
  1075. }
  1076. else if(dstFormat==IMGFMT_BGR16)
  1077. {
  1078. int i;
  1079. #ifdef DITHER1XBPP
  1080. static int ditherb1=1<<14;
  1081. static int ditherg1=1<<13;
  1082. static int ditherr1=2<<14;
  1083. static int ditherb2=3<<14;
  1084. static int ditherg2=3<<13;
  1085. static int ditherr2=0<<14;
  1086. ditherb1 ^= (1^2)<<14;
  1087. ditherg1 ^= (1^2)<<13;
  1088. ditherr1 ^= (1^2)<<14;
  1089. ditherb2 ^= (3^0)<<14;
  1090. ditherg2 ^= (3^0)<<13;
  1091. ditherr2 ^= (3^0)<<14;
  1092. #else
  1093. const int ditherb1=0;
  1094. const int ditherg1=0;
  1095. const int ditherr1=0;
  1096. const int ditherb2=0;
  1097. const int ditherg2=0;
  1098. const int ditherr2=0;
  1099. #endif
  1100. for(i=0; i<dstW-1; i+=2){
  1101. // vertical linear interpolation && yuv2rgb in a single step:
  1102. int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  1103. int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
  1104. int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
  1105. int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
  1106. int Cb= yuvtab_40cf[U];
  1107. int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
  1108. int Cr= yuvtab_3343[V];
  1109. ((uint16_t*)dest)[i] =
  1110. clip_table16b[(Y1 + Cb + ditherb1) >>13] |
  1111. clip_table16g[(Y1 + Cg + ditherg1) >>13] |
  1112. clip_table16r[(Y1 + Cr + ditherr1) >>13];
  1113. ((uint16_t*)dest)[i+1] =
  1114. clip_table16b[(Y2 + Cb + ditherb2) >>13] |
  1115. clip_table16g[(Y2 + Cg + ditherg2) >>13] |
  1116. clip_table16r[(Y2 + Cr + ditherr2) >>13];
  1117. }
  1118. }
  1119. else if(dstFormat==IMGFMT_BGR15)
  1120. {
  1121. int i;
  1122. #ifdef DITHER1XBPP
  1123. static int ditherb1=1<<14;
  1124. static int ditherg1=1<<14;
  1125. static int ditherr1=2<<14;
  1126. static int ditherb2=3<<14;
  1127. static int ditherg2=3<<14;
  1128. static int ditherr2=0<<14;
  1129. ditherb1 ^= (1^2)<<14;
  1130. ditherg1 ^= (1^2)<<14;
  1131. ditherr1 ^= (1^2)<<14;
  1132. ditherb2 ^= (3^0)<<14;
  1133. ditherg2 ^= (3^0)<<14;
  1134. ditherr2 ^= (3^0)<<14;
  1135. #else
  1136. const int ditherb1=0;
  1137. const int ditherg1=0;
  1138. const int ditherr1=0;
  1139. const int ditherb2=0;
  1140. const int ditherg2=0;
  1141. const int ditherr2=0;
  1142. #endif
  1143. for(i=0; i<dstW-1; i+=2){
  1144. // vertical linear interpolation && yuv2rgb in a single step:
  1145. int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  1146. int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
  1147. int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
  1148. int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
  1149. int Cb= yuvtab_40cf[U];
  1150. int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
  1151. int Cr= yuvtab_3343[V];
  1152. ((uint16_t*)dest)[i] =
  1153. clip_table15b[(Y1 + Cb + ditherb1) >>13] |
  1154. clip_table15g[(Y1 + Cg + ditherg1) >>13] |
  1155. clip_table15r[(Y1 + Cr + ditherr1) >>13];
  1156. ((uint16_t*)dest)[i+1] =
  1157. clip_table15b[(Y2 + Cb + ditherb2) >>13] |
  1158. clip_table15g[(Y2 + Cg + ditherg2) >>13] |
  1159. clip_table15r[(Y2 + Cr + ditherr2) >>13];
  1160. }
  1161. }
  1162. #endif
  1163. } //!FULL_UV_IPOL
  1164. }
  1165. /**
  1166. * YV12 to RGB without scaling or interpolating
  1167. */
  1168. static inline void RENAME(yuv2rgb1)(uint16_t *buf0, uint16_t *uvbuf0, uint16_t *uvbuf1,
  1169. uint8_t *dest, int dstW, int uvalpha, int dstFormat, int flags)
  1170. {
  1171. int uvalpha1=uvalpha^4095;
  1172. const int yalpha1=0;
  1173. if(flags&SWS_FULL_CHR_H_INT)
  1174. {
  1175. RENAME(yuv2rgb2)(buf0, buf0, uvbuf0, uvbuf1, dest, dstW, 0, uvalpha, dstFormat, flags);
  1176. return;
  1177. }
  1178. #ifdef HAVE_MMX
  1179. if( uvalpha < 2048 ) // note this is not correct (shifts chrominance by 0.5 pixels) but its a bit faster
  1180. {
  1181. if(dstFormat==IMGFMT_BGR32)
  1182. {
  1183. asm volatile(
  1184. YSCALEYUV2RGB1
  1185. WRITEBGR32
  1186. :: "r" (buf0), "r" (buf0), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  1187. "m" (yalpha1), "m" (uvalpha1)
  1188. : "%eax"
  1189. );
  1190. }
  1191. else if(dstFormat==IMGFMT_BGR24)
  1192. {
  1193. asm volatile(
  1194. "movl %4, %%ebx \n\t"
  1195. YSCALEYUV2RGB1
  1196. WRITEBGR24
  1197. :: "r" (buf0), "r" (buf0), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW),
  1198. "m" (yalpha1), "m" (uvalpha1)
  1199. : "%eax", "%ebx"
  1200. );
  1201. }
  1202. else if(dstFormat==IMGFMT_BGR15)
  1203. {
  1204. asm volatile(
  1205. YSCALEYUV2RGB1
  1206. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1207. #ifdef DITHER1XBPP
  1208. "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
  1209. "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
  1210. "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
  1211. #endif
  1212. WRITEBGR15
  1213. :: "r" (buf0), "r" (buf0), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  1214. "m" (yalpha1), "m" (uvalpha1)
  1215. : "%eax"
  1216. );
  1217. }
  1218. else if(dstFormat==IMGFMT_BGR16)
  1219. {
  1220. asm volatile(
  1221. YSCALEYUV2RGB1
  1222. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1223. #ifdef DITHER1XBPP
  1224. "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
  1225. "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
  1226. "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
  1227. #endif
  1228. WRITEBGR16
  1229. :: "r" (buf0), "r" (buf0), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  1230. "m" (yalpha1), "m" (uvalpha1)
  1231. : "%eax"
  1232. );
  1233. }
  1234. }
  1235. else
  1236. {
  1237. if(dstFormat==IMGFMT_BGR32)
  1238. {
  1239. asm volatile(
  1240. YSCALEYUV2RGB1b
  1241. WRITEBGR32
  1242. :: "r" (buf0), "r" (buf0), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  1243. "m" (yalpha1), "m" (uvalpha1)
  1244. : "%eax"
  1245. );
  1246. }
  1247. else if(dstFormat==IMGFMT_BGR24)
  1248. {
  1249. asm volatile(
  1250. "movl %4, %%ebx \n\t"
  1251. YSCALEYUV2RGB1b
  1252. WRITEBGR24
  1253. :: "r" (buf0), "r" (buf0), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW),
  1254. "m" (yalpha1), "m" (uvalpha1)
  1255. : "%eax", "%ebx"
  1256. );
  1257. }
  1258. else if(dstFormat==IMGFMT_BGR15)
  1259. {
  1260. asm volatile(
  1261. YSCALEYUV2RGB1b
  1262. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1263. #ifdef DITHER1XBPP
  1264. "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
  1265. "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
  1266. "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
  1267. #endif
  1268. WRITEBGR15
  1269. :: "r" (buf0), "r" (buf0), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  1270. "m" (yalpha1), "m" (uvalpha1)
  1271. : "%eax"
  1272. );
  1273. }
  1274. else if(dstFormat==IMGFMT_BGR16)
  1275. {
  1276. asm volatile(
  1277. YSCALEYUV2RGB1b
  1278. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1279. #ifdef DITHER1XBPP
  1280. "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
  1281. "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
  1282. "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
  1283. #endif
  1284. WRITEBGR16
  1285. :: "r" (buf0), "r" (buf0), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
  1286. "m" (yalpha1), "m" (uvalpha1)
  1287. : "%eax"
  1288. );
  1289. }
  1290. }
  1291. #else
  1292. //FIXME write 2 versions (for even & odd lines)
  1293. if(dstFormat==IMGFMT_BGR32)
  1294. {
  1295. int i;
  1296. for(i=0; i<dstW-1; i+=2){
  1297. // vertical linear interpolation && yuv2rgb in a single step:
  1298. int Y1=yuvtab_2568[buf0[i]>>7];
  1299. int Y2=yuvtab_2568[buf0[i+1]>>7];
  1300. int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
  1301. int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
  1302. int Cb= yuvtab_40cf[U];
  1303. int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
  1304. int Cr= yuvtab_3343[V];
  1305. dest[4*i+0]=clip_table[((Y1 + Cb) >>13)];
  1306. dest[4*i+1]=clip_table[((Y1 + Cg) >>13)];
  1307. dest[4*i+2]=clip_table[((Y1 + Cr) >>13)];
  1308. dest[4*i+4]=clip_table[((Y2 + Cb) >>13)];
  1309. dest[4*i+5]=clip_table[((Y2 + Cg) >>13)];
  1310. dest[4*i+6]=clip_table[((Y2 + Cr) >>13)];
  1311. }
  1312. }
  1313. else if(dstFormat==IMGFMT_BGR24)
  1314. {
  1315. int i;
  1316. for(i=0; i<dstW-1; i+=2){
  1317. // vertical linear interpolation && yuv2rgb in a single step:
  1318. int Y1=yuvtab_2568[buf0[i]>>7];
  1319. int Y2=yuvtab_2568[buf0[i+1]>>7];
  1320. int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
  1321. int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
  1322. int Cb= yuvtab_40cf[U];
  1323. int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
  1324. int Cr= yuvtab_3343[V];
  1325. dest[0]=clip_table[((Y1 + Cb) >>13)];
  1326. dest[1]=clip_table[((Y1 + Cg) >>13)];
  1327. dest[2]=clip_table[((Y1 + Cr) >>13)];
  1328. dest[3]=clip_table[((Y2 + Cb) >>13)];
  1329. dest[4]=clip_table[((Y2 + Cg) >>13)];
  1330. dest[5]=clip_table[((Y2 + Cr) >>13)];
  1331. dest+=6;
  1332. }
  1333. }
  1334. else if(dstFormat==IMGFMT_BGR16)
  1335. {
  1336. int i;
  1337. #ifdef DITHER1XBPP
  1338. static int ditherb1=1<<14;
  1339. static int ditherg1=1<<13;
  1340. static int ditherr1=2<<14;
  1341. static int ditherb2=3<<14;
  1342. static int ditherg2=3<<13;
  1343. static int ditherr2=0<<14;
  1344. ditherb1 ^= (1^2)<<14;
  1345. ditherg1 ^= (1^2)<<13;
  1346. ditherr1 ^= (1^2)<<14;
  1347. ditherb2 ^= (3^0)<<14;
  1348. ditherg2 ^= (3^0)<<13;
  1349. ditherr2 ^= (3^0)<<14;
  1350. #else
  1351. const int ditherb1=0;
  1352. const int ditherg1=0;
  1353. const int ditherr1=0;
  1354. const int ditherb2=0;
  1355. const int ditherg2=0;
  1356. const int ditherr2=0;
  1357. #endif
  1358. for(i=0; i<dstW-1; i+=2){
  1359. // vertical linear interpolation && yuv2rgb in a single step:
  1360. int Y1=yuvtab_2568[buf0[i]>>7];
  1361. int Y2=yuvtab_2568[buf0[i+1]>>7];
  1362. int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
  1363. int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
  1364. int Cb= yuvtab_40cf[U];
  1365. int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
  1366. int Cr= yuvtab_3343[V];
  1367. ((uint16_t*)dest)[i] =
  1368. clip_table16b[(Y1 + Cb + ditherb1) >>13] |
  1369. clip_table16g[(Y1 + Cg + ditherg1) >>13] |
  1370. clip_table16r[(Y1 + Cr + ditherr1) >>13];
  1371. ((uint16_t*)dest)[i+1] =
  1372. clip_table16b[(Y2 + Cb + ditherb2) >>13] |
  1373. clip_table16g[(Y2 + Cg + ditherg2) >>13] |
  1374. clip_table16r[(Y2 + Cr + ditherr2) >>13];
  1375. }
  1376. }
  1377. else if(dstFormat==IMGFMT_BGR15)
  1378. {
  1379. int i;
  1380. #ifdef DITHER1XBPP
  1381. static int ditherb1=1<<14;
  1382. static int ditherg1=1<<14;
  1383. static int ditherr1=2<<14;
  1384. static int ditherb2=3<<14;
  1385. static int ditherg2=3<<14;
  1386. static int ditherr2=0<<14;
  1387. ditherb1 ^= (1^2)<<14;
  1388. ditherg1 ^= (1^2)<<14;
  1389. ditherr1 ^= (1^2)<<14;
  1390. ditherb2 ^= (3^0)<<14;
  1391. ditherg2 ^= (3^0)<<14;
  1392. ditherr2 ^= (3^0)<<14;
  1393. #else
  1394. const int ditherb1=0;
  1395. const int ditherg1=0;
  1396. const int ditherr1=0;
  1397. const int ditherb2=0;
  1398. const int ditherg2=0;
  1399. const int ditherr2=0;
  1400. #endif
  1401. for(i=0; i<dstW-1; i+=2){
  1402. // vertical linear interpolation && yuv2rgb in a single step:
  1403. int Y1=yuvtab_2568[buf0[i]>>7];
  1404. int Y2=yuvtab_2568[buf0[i+1]>>7];
  1405. int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
  1406. int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
  1407. int Cb= yuvtab_40cf[U];
  1408. int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
  1409. int Cr= yuvtab_3343[V];
  1410. ((uint16_t*)dest)[i] =
  1411. clip_table15b[(Y1 + Cb + ditherb1) >>13] |
  1412. clip_table15g[(Y1 + Cg + ditherg1) >>13] |
  1413. clip_table15r[(Y1 + Cr + ditherr1) >>13];
  1414. ((uint16_t*)dest)[i+1] =
  1415. clip_table15b[(Y2 + Cb + ditherb2) >>13] |
  1416. clip_table15g[(Y2 + Cg + ditherg2) >>13] |
  1417. clip_table15r[(Y2 + Cr + ditherr2) >>13];
  1418. }
  1419. }
  1420. #endif
  1421. }
  1422. //FIXME yuy2* can read upto 7 samples to much
  1423. static inline void RENAME(yuy2ToY)(uint8_t *dst, uint8_t *src, int width)
  1424. {
  1425. #ifdef HAVE_MMX
  1426. asm volatile(
  1427. "movq "MANGLE(bm01010101)", %%mm2\n\t"
  1428. "movl %0, %%eax \n\t"
  1429. "1: \n\t"
  1430. "movq (%1, %%eax,2), %%mm0 \n\t"
  1431. "movq 8(%1, %%eax,2), %%mm1 \n\t"
  1432. "pand %%mm2, %%mm0 \n\t"
  1433. "pand %%mm2, %%mm1 \n\t"
  1434. "packuswb %%mm1, %%mm0 \n\t"
  1435. "movq %%mm0, (%2, %%eax) \n\t"
  1436. "addl $8, %%eax \n\t"
  1437. " js 1b \n\t"
  1438. : : "g" (-width), "r" (src+width*2), "r" (dst+width)
  1439. : "%eax"
  1440. );
  1441. #else
  1442. int i;
  1443. for(i=0; i<width; i++)
  1444. dst[i]= src[2*i];
  1445. #endif
  1446. }
  1447. static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
  1448. {
  1449. #if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
  1450. asm volatile(
  1451. "movq "MANGLE(bm01010101)", %%mm4\n\t"
  1452. "movl %0, %%eax \n\t"
  1453. "1: \n\t"
  1454. "movq (%1, %%eax,4), %%mm0 \n\t"
  1455. "movq 8(%1, %%eax,4), %%mm1 \n\t"
  1456. "movq (%2, %%eax,4), %%mm2 \n\t"
  1457. "movq 8(%2, %%eax,4), %%mm3 \n\t"
  1458. PAVGB(%%mm2, %%mm0)
  1459. PAVGB(%%mm3, %%mm1)
  1460. "psrlw $8, %%mm0 \n\t"
  1461. "psrlw $8, %%mm1 \n\t"
  1462. "packuswb %%mm1, %%mm0 \n\t"
  1463. "movq %%mm0, %%mm1 \n\t"
  1464. "psrlw $8, %%mm0 \n\t"
  1465. "pand %%mm4, %%mm1 \n\t"
  1466. "packuswb %%mm0, %%mm0 \n\t"
  1467. "packuswb %%mm1, %%mm1 \n\t"
  1468. "movd %%mm0, (%4, %%eax) \n\t"
  1469. "movd %%mm1, (%3, %%eax) \n\t"
  1470. "addl $4, %%eax \n\t"
  1471. " js 1b \n\t"
  1472. : : "g" (-width), "r" (src1+width*4), "r" (src2+width*4), "r" (dstU+width), "r" (dstV+width)
  1473. : "%eax"
  1474. );
  1475. #else
  1476. int i;
  1477. for(i=0; i<width; i++)
  1478. {
  1479. dstU[i]= (src1[4*i + 1] + src2[4*i + 1])>>1;
  1480. dstV[i]= (src1[4*i + 3] + src2[4*i + 3])>>1;
  1481. }
  1482. #endif
  1483. }
  1484. static inline void RENAME(bgr32ToY)(uint8_t *dst, uint8_t *src, int width)
  1485. {
  1486. #ifdef HAVE_MMXFIXME
  1487. #else
  1488. int i;
  1489. for(i=0; i<width; i++)
  1490. {
  1491. int b= src[i*4+0];
  1492. int g= src[i*4+1];
  1493. int r= src[i*4+2];
  1494. dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
  1495. }
  1496. #endif
  1497. }
  1498. static inline void RENAME(bgr32ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
  1499. {
  1500. #ifdef HAVE_MMXFIXME
  1501. #else
  1502. int i;
  1503. for(i=0; i<width; i++)
  1504. {
  1505. int b= src1[8*i + 0] + src1[8*i + 4] + src2[8*i + 0] + src2[8*i + 4];
  1506. int g= src1[8*i + 1] + src1[8*i + 5] + src2[8*i + 1] + src2[8*i + 5];
  1507. int r= src1[8*i + 2] + src1[8*i + 6] + src2[8*i + 2] + src2[8*i + 6];
  1508. dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+2)) + 128;
  1509. dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+2)) + 128;
  1510. }
  1511. #endif
  1512. }
  1513. static inline void RENAME(bgr24ToY)(uint8_t *dst, uint8_t *src, int width)
  1514. {
  1515. #ifdef HAVE_MMXFIXME
  1516. #else
  1517. int i;
  1518. for(i=0; i<width; i++)
  1519. {
  1520. int b= src[i*3+0];
  1521. int g= src[i*3+1];
  1522. int r= src[i*3+2];
  1523. dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
  1524. }
  1525. #endif
  1526. }
  1527. static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
  1528. {
  1529. #ifdef HAVE_MMXFIXME
  1530. #else
  1531. int i;
  1532. for(i=0; i<width; i++)
  1533. {
  1534. int b= src1[6*i + 0] + src1[6*i + 3] + src2[6*i + 0] + src2[6*i + 3];
  1535. int g= src1[6*i + 1] + src1[6*i + 4] + src2[6*i + 1] + src2[6*i + 4];
  1536. int r= src1[6*i + 2] + src1[6*i + 5] + src2[6*i + 2] + src2[6*i + 5];
  1537. dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+2)) + 128;
  1538. dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+2)) + 128;
  1539. }
  1540. #endif
  1541. }
  1542. static inline void RENAME(bgr16ToY)(uint8_t *dst, uint8_t *src, int width)
  1543. {
  1544. int i;
  1545. for(i=0; i<width; i++)
  1546. {
  1547. int d= src[i*2] + (src[i*2+1]<<8);
  1548. int b= d&0x1F;
  1549. int g= (d>>5)&0x3F;
  1550. int r= (d>>11)&0x1F;
  1551. dst[i]= ((2*RY*r + GY*g + 2*BY*b)>>(RGB2YUV_SHIFT-2)) + 16;
  1552. }
  1553. }
  1554. static inline void RENAME(bgr16ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
  1555. {
  1556. int i;
  1557. for(i=0; i<width; i++)
  1558. {
  1559. #if 1
  1560. int d0= le2me_32( ((uint32_t*)src1)[i] );
  1561. int d1= le2me_32( ((uint32_t*)src2)[i] );
  1562. int dl= (d0&0x07E0F81F) + (d1&0x07E0F81F);
  1563. int dh= ((d0>>5)&0x07C0F83F) + ((d1>>5)&0x07C0F83F);
  1564. int dh2= (dh>>11) + (dh<<21);
  1565. int d= dh2 + dl;
  1566. int b= d&0x7F;
  1567. int r= (d>>11)&0x7F;
  1568. int g= d>>21;
  1569. #else
  1570. int d0= src1[i*4] + (src1[i*4+1]<<8);
  1571. int b0= d0&0x1F;
  1572. int g0= (d0>>5)&0x3F;
  1573. int r0= (d0>>11)&0x1F;
  1574. int d1= src1[i*4+2] + (src1[i*4+3]<<8);
  1575. int b1= d1&0x1F;
  1576. int g1= (d1>>5)&0x3F;
  1577. int r1= (d1>>11)&0x1F;
  1578. int d2= src2[i*4] + (src2[i*4+1]<<8);
  1579. int b2= d2&0x1F;
  1580. int g2= (d2>>5)&0x3F;
  1581. int r2= (d2>>11)&0x1F;
  1582. int d3= src2[i*4+2] + (src2[i*4+3]<<8);
  1583. int b3= d3&0x1F;
  1584. int g3= (d3>>5)&0x3F;
  1585. int r3= (d3>>11)&0x1F;
  1586. int b= b0 + b1 + b2 + b3;
  1587. int g= g0 + g1 + g2 + g3;
  1588. int r= r0 + r1 + r2 + r3;
  1589. #endif
  1590. dstU[i]= ((2*RU*r + GU*g + 2*BU*b)>>(RGB2YUV_SHIFT+2-2)) + 128;
  1591. dstV[i]= ((2*RV*r + GV*g + 2*BV*b)>>(RGB2YUV_SHIFT+2-2)) + 128;
  1592. }
  1593. }
  1594. static inline void RENAME(rgb32ToY)(uint8_t *dst, uint8_t *src, int width)
  1595. {
  1596. int i;
  1597. for(i=0; i<width; i++)
  1598. {
  1599. int r= src[i*4+0];
  1600. int g= src[i*4+1];
  1601. int b= src[i*4+2];
  1602. dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
  1603. }
  1604. }
  1605. static inline void RENAME(rgb32ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
  1606. {
  1607. int i;
  1608. for(i=0; i<width; i++)
  1609. {
  1610. int r= src1[8*i + 0] + src1[8*i + 4] + src2[8*i + 0] + src2[8*i + 4];
  1611. int g= src1[8*i + 1] + src1[8*i + 5] + src2[8*i + 1] + src2[8*i + 5];
  1612. int b= src1[8*i + 2] + src1[8*i + 6] + src2[8*i + 2] + src2[8*i + 6];
  1613. dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+2)) + 128;
  1614. dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+2)) + 128;
  1615. }
  1616. }
  1617. static inline void RENAME(rgb24ToY)(uint8_t *dst, uint8_t *src, int width)
  1618. {
  1619. int i;
  1620. for(i=0; i<width; i++)
  1621. {
  1622. int r= src[i*3+0];
  1623. int g= src[i*3+1];
  1624. int b= src[i*3+2];
  1625. dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
  1626. }
  1627. }
  1628. static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
  1629. {
  1630. int i;
  1631. for(i=0; i<width; i++)
  1632. {
  1633. int r= src1[6*i + 0] + src1[6*i + 3] + src2[6*i + 0] + src2[6*i + 3];
  1634. int g= src1[6*i + 1] + src1[6*i + 4] + src2[6*i + 1] + src2[6*i + 4];
  1635. int b= src1[6*i + 2] + src1[6*i + 5] + src2[6*i + 2] + src2[6*i + 5];
  1636. dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+2)) + 128;
  1637. dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+2)) + 128;
  1638. }
  1639. }
  1640. // Bilinear / Bicubic scaling
  1641. static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc,
  1642. int16_t *filter, int16_t *filterPos, int filterSize)
  1643. {
  1644. #ifdef HAVE_MMX
  1645. if(filterSize==4) // allways true for upscaling, sometimes for down too
  1646. {
  1647. int counter= -2*dstW;
  1648. filter-= counter*2;
  1649. filterPos-= counter/2;
  1650. dst-= counter/2;
  1651. asm volatile(
  1652. "pxor %%mm7, %%mm7 \n\t"
  1653. "movq "MANGLE(w02)", %%mm6 \n\t"
  1654. "pushl %%ebp \n\t" // we use 7 regs here ...
  1655. "movl %%eax, %%ebp \n\t"
  1656. ".balign 16 \n\t"
  1657. "1: \n\t"
  1658. "movzwl (%2, %%ebp), %%eax \n\t"
  1659. "movzwl 2(%2, %%ebp), %%ebx \n\t"
  1660. "movq (%1, %%ebp, 4), %%mm1 \n\t"
  1661. "movq 8(%1, %%ebp, 4), %%mm3 \n\t"
  1662. "movd (%3, %%eax), %%mm0 \n\t"
  1663. "movd (%3, %%ebx), %%mm2 \n\t"
  1664. "punpcklbw %%mm7, %%mm0 \n\t"
  1665. "punpcklbw %%mm7, %%mm2 \n\t"
  1666. "pmaddwd %%mm1, %%mm0 \n\t"
  1667. "pmaddwd %%mm2, %%mm3 \n\t"
  1668. "psrad $8, %%mm0 \n\t"
  1669. "psrad $8, %%mm3 \n\t"
  1670. "packssdw %%mm3, %%mm0 \n\t"
  1671. "pmaddwd %%mm6, %%mm0 \n\t"
  1672. "packssdw %%mm0, %%mm0 \n\t"
  1673. "movd %%mm0, (%4, %%ebp) \n\t"
  1674. "addl $4, %%ebp \n\t"
  1675. " jnc 1b \n\t"
  1676. "popl %%ebp \n\t"
  1677. : "+a" (counter)
  1678. : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
  1679. : "%ebx"
  1680. );
  1681. }
  1682. else if(filterSize==8)
  1683. {
  1684. int counter= -2*dstW;
  1685. filter-= counter*4;
  1686. filterPos-= counter/2;
  1687. dst-= counter/2;
  1688. asm volatile(
  1689. "pxor %%mm7, %%mm7 \n\t"
  1690. "movq "MANGLE(w02)", %%mm6 \n\t"
  1691. "pushl %%ebp \n\t" // we use 7 regs here ...
  1692. "movl %%eax, %%ebp \n\t"
  1693. ".balign 16 \n\t"
  1694. "1: \n\t"
  1695. "movzwl (%2, %%ebp), %%eax \n\t"
  1696. "movzwl 2(%2, %%ebp), %%ebx \n\t"
  1697. "movq (%1, %%ebp, 8), %%mm1 \n\t"
  1698. "movq 16(%1, %%ebp, 8), %%mm3 \n\t"
  1699. "movd (%3, %%eax), %%mm0 \n\t"
  1700. "movd (%3, %%ebx), %%mm2 \n\t"
  1701. "punpcklbw %%mm7, %%mm0 \n\t"
  1702. "punpcklbw %%mm7, %%mm2 \n\t"
  1703. "pmaddwd %%mm1, %%mm0 \n\t"
  1704. "pmaddwd %%mm2, %%mm3 \n\t"
  1705. "movq 8(%1, %%ebp, 8), %%mm1 \n\t"
  1706. "movq 24(%1, %%ebp, 8), %%mm5 \n\t"
  1707. "movd 4(%3, %%eax), %%mm4 \n\t"
  1708. "movd 4(%3, %%ebx), %%mm2 \n\t"
  1709. "punpcklbw %%mm7, %%mm4 \n\t"
  1710. "punpcklbw %%mm7, %%mm2 \n\t"
  1711. "pmaddwd %%mm1, %%mm4 \n\t"
  1712. "pmaddwd %%mm2, %%mm5 \n\t"
  1713. "paddd %%mm4, %%mm0 \n\t"
  1714. "paddd %%mm5, %%mm3 \n\t"
  1715. "psrad $8, %%mm0 \n\t"
  1716. "psrad $8, %%mm3 \n\t"
  1717. "packssdw %%mm3, %%mm0 \n\t"
  1718. "pmaddwd %%mm6, %%mm0 \n\t"
  1719. "packssdw %%mm0, %%mm0 \n\t"
  1720. "movd %%mm0, (%4, %%ebp) \n\t"
  1721. "addl $4, %%ebp \n\t"
  1722. " jnc 1b \n\t"
  1723. "popl %%ebp \n\t"
  1724. : "+a" (counter)
  1725. : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
  1726. : "%ebx"
  1727. );
  1728. }
  1729. else
  1730. {
  1731. int counter= -2*dstW;
  1732. // filter-= counter*filterSize/2;
  1733. filterPos-= counter/2;
  1734. dst-= counter/2;
  1735. asm volatile(
  1736. "pxor %%mm7, %%mm7 \n\t"
  1737. "movq "MANGLE(w02)", %%mm6 \n\t"
  1738. ".balign 16 \n\t"
  1739. "1: \n\t"
  1740. "movl %2, %%ecx \n\t"
  1741. "movzwl (%%ecx, %0), %%eax \n\t"
  1742. "movzwl 2(%%ecx, %0), %%ebx \n\t"
  1743. "movl %5, %%ecx \n\t"
  1744. "pxor %%mm4, %%mm4 \n\t"
  1745. "pxor %%mm5, %%mm5 \n\t"
  1746. "2: \n\t"
  1747. "movq (%1), %%mm1 \n\t"
  1748. "movq (%1, %6), %%mm3 \n\t"
  1749. "movd (%%ecx, %%eax), %%mm0 \n\t"
  1750. "movd (%%ecx, %%ebx), %%mm2 \n\t"
  1751. "punpcklbw %%mm7, %%mm0 \n\t"
  1752. "punpcklbw %%mm7, %%mm2 \n\t"
  1753. "pmaddwd %%mm1, %%mm0 \n\t"
  1754. "pmaddwd %%mm2, %%mm3 \n\t"
  1755. "paddd %%mm3, %%mm5 \n\t"
  1756. "paddd %%mm0, %%mm4 \n\t"
  1757. "addl $8, %1 \n\t"
  1758. "addl $4, %%ecx \n\t"
  1759. "cmpl %4, %%ecx \n\t"
  1760. " jb 2b \n\t"
  1761. "addl %6, %1 \n\t"
  1762. "psrad $8, %%mm4 \n\t"
  1763. "psrad $8, %%mm5 \n\t"
  1764. "packssdw %%mm5, %%mm4 \n\t"
  1765. "pmaddwd %%mm6, %%mm4 \n\t"
  1766. "packssdw %%mm4, %%mm4 \n\t"
  1767. "movl %3, %%eax \n\t"
  1768. "movd %%mm4, (%%eax, %0) \n\t"
  1769. "addl $4, %0 \n\t"
  1770. " jnc 1b \n\t"
  1771. : "+r" (counter), "+r" (filter)
  1772. : "m" (filterPos), "m" (dst), "m"(src+filterSize),
  1773. "m" (src), "r" (filterSize*2)
  1774. : "%ebx", "%eax", "%ecx"
  1775. );
  1776. }
  1777. #else
  1778. int i;
  1779. for(i=0; i<dstW; i++)
  1780. {
  1781. int j;
  1782. int srcPos= filterPos[i];
  1783. int val=0;
  1784. // printf("filterPos: %d\n", filterPos[i]);
  1785. for(j=0; j<filterSize; j++)
  1786. {
  1787. // printf("filter: %d, src: %d\n", filter[i], src[srcPos + j]);
  1788. val += ((int)src[srcPos + j])*filter[filterSize*i + j];
  1789. }
  1790. // filter += hFilterSize;
  1791. dst[i] = MIN(MAX(0, val>>7), (1<<15)-1); // the cubic equation does overflow ...
  1792. // dst[i] = val>>7;
  1793. }
  1794. #endif
  1795. }
  1796. // *** horizontal scale Y line to temp buffer
  1797. static inline void RENAME(hyscale)(uint16_t *dst, int dstWidth, uint8_t *src, int srcW, int xInc,
  1798. int flags, int canMMX2BeUsed, int16_t *hLumFilter,
  1799. int16_t *hLumFilterPos, int hLumFilterSize, void *funnyYCode,
  1800. int srcFormat, uint8_t *formatConvBuffer)
  1801. {
  1802. if(srcFormat==IMGFMT_YUY2)
  1803. {
  1804. RENAME(yuy2ToY)(formatConvBuffer, src, srcW);
  1805. src= formatConvBuffer;
  1806. }
  1807. else if(srcFormat==IMGFMT_BGR32)
  1808. {
  1809. RENAME(bgr32ToY)(formatConvBuffer, src, srcW);
  1810. src= formatConvBuffer;
  1811. }
  1812. else if(srcFormat==IMGFMT_BGR24)
  1813. {
  1814. RENAME(bgr24ToY)(formatConvBuffer, src, srcW);
  1815. src= formatConvBuffer;
  1816. }
  1817. else if(srcFormat==IMGFMT_BGR16)
  1818. {
  1819. RENAME(bgr16ToY)(formatConvBuffer, src, srcW);
  1820. src= formatConvBuffer;
  1821. }
  1822. else if(srcFormat==IMGFMT_RGB32)
  1823. {
  1824. RENAME(rgb32ToY)(formatConvBuffer, src, srcW);
  1825. src= formatConvBuffer;
  1826. }
  1827. else if(srcFormat==IMGFMT_RGB24)
  1828. {
  1829. RENAME(rgb24ToY)(formatConvBuffer, src, srcW);
  1830. src= formatConvBuffer;
  1831. }
  1832. #ifdef HAVE_MMX
  1833. // use the new MMX scaler if th mmx2 cant be used (its faster than the x86asm one)
  1834. if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
  1835. #else
  1836. if(!(flags&SWS_FAST_BILINEAR))
  1837. #endif
  1838. {
  1839. RENAME(hScale)(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize);
  1840. }
  1841. else // Fast Bilinear upscale / crap downscale
  1842. {
  1843. #ifdef ARCH_X86
  1844. #ifdef HAVE_MMX2
  1845. int i;
  1846. if(canMMX2BeUsed)
  1847. {
  1848. asm volatile(
  1849. "pxor %%mm7, %%mm7 \n\t"
  1850. "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
  1851. "movd %5, %%mm6 \n\t" // xInc&0xFFFF
  1852. "punpcklwd %%mm6, %%mm6 \n\t"
  1853. "punpcklwd %%mm6, %%mm6 \n\t"
  1854. "movq %%mm6, %%mm2 \n\t"
  1855. "psllq $16, %%mm2 \n\t"
  1856. "paddw %%mm6, %%mm2 \n\t"
  1857. "psllq $16, %%mm2 \n\t"
  1858. "paddw %%mm6, %%mm2 \n\t"
  1859. "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=xInc&0xFF
  1860. "movq %%mm2, %%mm4 \n\t"
  1861. "movd %4, %%mm6 \n\t" //(xInc*4)&0xFFFF
  1862. "punpcklwd %%mm6, %%mm6 \n\t"
  1863. "punpcklwd %%mm6, %%mm6 \n\t"
  1864. "xorl %%eax, %%eax \n\t" // i
  1865. "movl %0, %%esi \n\t" // src
  1866. "movl %1, %%edi \n\t" // buf1
  1867. "movl %3, %%edx \n\t" // (xInc*4)>>16
  1868. "xorl %%ecx, %%ecx \n\t"
  1869. "xorl %%ebx, %%ebx \n\t"
  1870. "movw %4, %%bx \n\t" // (xInc*4)&0xFFFF
  1871. #define FUNNY_Y_CODE \
  1872. PREFETCH" 1024(%%esi) \n\t"\
  1873. PREFETCH" 1056(%%esi) \n\t"\
  1874. PREFETCH" 1088(%%esi) \n\t"\
  1875. "call *%6 \n\t"\
  1876. "movq %%mm4, %%mm2 \n\t"\
  1877. "xorl %%ecx, %%ecx \n\t"
  1878. FUNNY_Y_CODE
  1879. FUNNY_Y_CODE
  1880. FUNNY_Y_CODE
  1881. FUNNY_Y_CODE
  1882. FUNNY_Y_CODE
  1883. FUNNY_Y_CODE
  1884. FUNNY_Y_CODE
  1885. FUNNY_Y_CODE
  1886. :: "m" (src), "m" (dst), "m" (dstWidth), "m" ((xInc*4)>>16),
  1887. "m" ((xInc*4)&0xFFFF), "m" (xInc&0xFFFF), "m" (funnyYCode)
  1888. : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
  1889. );
  1890. for(i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) dst[i] = src[srcW-1]*128;
  1891. }
  1892. else
  1893. {
  1894. #endif
  1895. //NO MMX just normal asm ...
  1896. asm volatile(
  1897. "xorl %%eax, %%eax \n\t" // i
  1898. "xorl %%ebx, %%ebx \n\t" // xx
  1899. "xorl %%ecx, %%ecx \n\t" // 2*xalpha
  1900. ".balign 16 \n\t"
  1901. "1: \n\t"
  1902. "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
  1903. "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
  1904. "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
  1905. "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
  1906. "shll $16, %%edi \n\t"
  1907. "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
  1908. "movl %1, %%edi \n\t"
  1909. "shrl $9, %%esi \n\t"
  1910. "movw %%si, (%%edi, %%eax, 2) \n\t"
  1911. "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
  1912. "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
  1913. "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
  1914. "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
  1915. "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
  1916. "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
  1917. "shll $16, %%edi \n\t"
  1918. "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
  1919. "movl %1, %%edi \n\t"
  1920. "shrl $9, %%esi \n\t"
  1921. "movw %%si, 2(%%edi, %%eax, 2) \n\t"
  1922. "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
  1923. "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
  1924. "addl $2, %%eax \n\t"
  1925. "cmpl %2, %%eax \n\t"
  1926. " jb 1b \n\t"
  1927. :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc>>16), "m" (xInc&0xFFFF)
  1928. : "%eax", "%ebx", "%ecx", "%edi", "%esi"
  1929. );
  1930. #ifdef HAVE_MMX2
  1931. } //if MMX2 cant be used
  1932. #endif
  1933. #else
  1934. int i;
  1935. unsigned int xpos=0;
  1936. for(i=0;i<dstWidth;i++)
  1937. {
  1938. register unsigned int xx=xpos>>16;
  1939. register unsigned int xalpha=(xpos&0xFFFF)>>9;
  1940. dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha;
  1941. xpos+=xInc;
  1942. }
  1943. #endif
  1944. }
  1945. }
  1946. inline static void RENAME(hcscale)(uint16_t *dst, int dstWidth, uint8_t *src1, uint8_t *src2,
  1947. int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter,
  1948. int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode,
  1949. int srcFormat, uint8_t *formatConvBuffer)
  1950. {
  1951. if(srcFormat==IMGFMT_YUY2)
  1952. {
  1953. RENAME(yuy2ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
  1954. src1= formatConvBuffer;
  1955. src2= formatConvBuffer+2048;
  1956. }
  1957. else if(srcFormat==IMGFMT_BGR32)
  1958. {
  1959. RENAME(bgr32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
  1960. src1= formatConvBuffer;
  1961. src2= formatConvBuffer+2048;
  1962. }
  1963. else if(srcFormat==IMGFMT_BGR24)
  1964. {
  1965. RENAME(bgr24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
  1966. src1= formatConvBuffer;
  1967. src2= formatConvBuffer+2048;
  1968. }
  1969. else if(srcFormat==IMGFMT_BGR16)
  1970. {
  1971. RENAME(bgr16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
  1972. src1= formatConvBuffer;
  1973. src2= formatConvBuffer+2048;
  1974. }
  1975. else if(srcFormat==IMGFMT_RGB32)
  1976. {
  1977. RENAME(rgb32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
  1978. src1= formatConvBuffer;
  1979. src2= formatConvBuffer+2048;
  1980. }
  1981. else if(srcFormat==IMGFMT_RGB24)
  1982. {
  1983. RENAME(rgb24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
  1984. src1= formatConvBuffer;
  1985. src2= formatConvBuffer+2048;
  1986. }
  1987. else if(isGray(srcFormat))
  1988. {
  1989. return;
  1990. }
  1991. #ifdef HAVE_MMX
  1992. // use the new MMX scaler if th mmx2 cant be used (its faster than the x86asm one)
  1993. if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
  1994. #else
  1995. if(!(flags&SWS_FAST_BILINEAR))
  1996. #endif
  1997. {
  1998. RENAME(hScale)(dst , dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
  1999. RENAME(hScale)(dst+2048, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
  2000. }
  2001. else // Fast Bilinear upscale / crap downscale
  2002. {
  2003. #ifdef ARCH_X86
  2004. #ifdef HAVE_MMX2
  2005. int i;
  2006. if(canMMX2BeUsed)
  2007. {
  2008. asm volatile(
  2009. "pxor %%mm7, %%mm7 \n\t"
  2010. "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
  2011. "movd %5, %%mm6 \n\t" // xInc&0xFFFF
  2012. "punpcklwd %%mm6, %%mm6 \n\t"
  2013. "punpcklwd %%mm6, %%mm6 \n\t"
  2014. "movq %%mm6, %%mm2 \n\t"
  2015. "psllq $16, %%mm2 \n\t"
  2016. "paddw %%mm6, %%mm2 \n\t"
  2017. "psllq $16, %%mm2 \n\t"
  2018. "paddw %%mm6, %%mm2 \n\t"
  2019. "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=xInc&0xFFFF
  2020. "movq %%mm2, %%mm4 \n\t"
  2021. "movd %4, %%mm6 \n\t" //(xInc*4)&0xFFFF
  2022. "punpcklwd %%mm6, %%mm6 \n\t"
  2023. "punpcklwd %%mm6, %%mm6 \n\t"
  2024. "xorl %%eax, %%eax \n\t" // i
  2025. "movl %0, %%esi \n\t" // src
  2026. "movl %1, %%edi \n\t" // buf1
  2027. "movl %3, %%edx \n\t" // (xInc*4)>>16
  2028. "xorl %%ecx, %%ecx \n\t"
  2029. "xorl %%ebx, %%ebx \n\t"
  2030. "movw %4, %%bx \n\t" // (xInc*4)&0xFFFF
  2031. #define FUNNYUVCODE \
  2032. PREFETCH" 1024(%%esi) \n\t"\
  2033. PREFETCH" 1056(%%esi) \n\t"\
  2034. PREFETCH" 1088(%%esi) \n\t"\
  2035. "call *%7 \n\t"\
  2036. "movq %%mm4, %%mm2 \n\t"\
  2037. "xorl %%ecx, %%ecx \n\t"
  2038. FUNNYUVCODE
  2039. FUNNYUVCODE
  2040. FUNNYUVCODE
  2041. FUNNYUVCODE
  2042. FUNNYUVCODE
  2043. FUNNYUVCODE
  2044. FUNNYUVCODE
  2045. FUNNYUVCODE
  2046. "xorl %%eax, %%eax \n\t" // i
  2047. "movl %6, %%esi \n\t" // src
  2048. "movl %1, %%edi \n\t" // buf1
  2049. "addl $4096, %%edi \n\t"
  2050. FUNNYUVCODE
  2051. FUNNYUVCODE
  2052. FUNNYUVCODE
  2053. FUNNYUVCODE
  2054. FUNNYUVCODE
  2055. FUNNYUVCODE
  2056. FUNNYUVCODE
  2057. FUNNYUVCODE
  2058. :: "m" (src1), "m" (dst), "m" (dstWidth), "m" ((xInc*4)>>16),
  2059. "m" ((xInc*4)&0xFFFF), "m" (xInc&0xFFFF), "m" (src2), "m" (funnyUVCode)
  2060. : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
  2061. );
  2062. for(i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
  2063. {
  2064. // printf("%d %d %d\n", dstWidth, i, srcW);
  2065. dst[i] = src1[srcW-1]*128;
  2066. dst[i+2048] = src2[srcW-1]*128;
  2067. }
  2068. }
  2069. else
  2070. {
  2071. #endif
  2072. asm volatile(
  2073. "xorl %%eax, %%eax \n\t" // i
  2074. "xorl %%ebx, %%ebx \n\t" // xx
  2075. "xorl %%ecx, %%ecx \n\t" // 2*xalpha
  2076. ".balign 16 \n\t"
  2077. "1: \n\t"
  2078. "movl %0, %%esi \n\t"
  2079. "movzbl (%%esi, %%ebx), %%edi \n\t" //src[xx]
  2080. "movzbl 1(%%esi, %%ebx), %%esi \n\t" //src[xx+1]
  2081. "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
  2082. "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
  2083. "shll $16, %%edi \n\t"
  2084. "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
  2085. "movl %1, %%edi \n\t"
  2086. "shrl $9, %%esi \n\t"
  2087. "movw %%si, (%%edi, %%eax, 2) \n\t"
  2088. "movzbl (%5, %%ebx), %%edi \n\t" //src[xx]
  2089. "movzbl 1(%5, %%ebx), %%esi \n\t" //src[xx+1]
  2090. "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
  2091. "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
  2092. "shll $16, %%edi \n\t"
  2093. "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
  2094. "movl %1, %%edi \n\t"
  2095. "shrl $9, %%esi \n\t"
  2096. "movw %%si, 4096(%%edi, %%eax, 2)\n\t"
  2097. "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
  2098. "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
  2099. "addl $1, %%eax \n\t"
  2100. "cmpl %2, %%eax \n\t"
  2101. " jb 1b \n\t"
  2102. :: "m" (src1), "m" (dst), "m" (dstWidth), "m" (xInc>>16), "m" (xInc&0xFFFF),
  2103. "r" (src2)
  2104. : "%eax", "%ebx", "%ecx", "%edi", "%esi"
  2105. );
  2106. #ifdef HAVE_MMX2
  2107. } //if MMX2 cant be used
  2108. #endif
  2109. #else
  2110. int i;
  2111. unsigned int xpos=0;
  2112. for(i=0;i<dstWidth;i++)
  2113. {
  2114. register unsigned int xx=xpos>>16;
  2115. register unsigned int xalpha=(xpos&0xFFFF)>>9;
  2116. dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
  2117. dst[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
  2118. /* slower
  2119. dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha;
  2120. dst[i+2048]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha;
  2121. */
  2122. xpos+=xInc;
  2123. }
  2124. #endif
  2125. }
  2126. }
  2127. static void RENAME(swScale)(SwsContext *c, uint8_t* srcParam[], int srcStrideParam[], int srcSliceY,
  2128. int srcSliceH, uint8_t* dstParam[], int dstStride[]){
  2129. /* load a few things into local vars to make the code more readable? and faster */
  2130. const int srcW= c->srcW;
  2131. const int dstW= c->dstW;
  2132. const int dstH= c->dstH;
  2133. const int chrDstW= c->chrDstW;
  2134. const int lumXInc= c->lumXInc;
  2135. const int chrXInc= c->chrXInc;
  2136. const int dstFormat= c->dstFormat;
  2137. const int flags= c->flags;
  2138. const int canMMX2BeUsed= c->canMMX2BeUsed;
  2139. int16_t *vLumFilterPos= c->vLumFilterPos;
  2140. int16_t *vChrFilterPos= c->vChrFilterPos;
  2141. int16_t *hLumFilterPos= c->hLumFilterPos;
  2142. int16_t *hChrFilterPos= c->hChrFilterPos;
  2143. int16_t *vLumFilter= c->vLumFilter;
  2144. int16_t *vChrFilter= c->vChrFilter;
  2145. int16_t *hLumFilter= c->hLumFilter;
  2146. int16_t *hChrFilter= c->hChrFilter;
  2147. int16_t *lumMmxFilter= c->lumMmxFilter;
  2148. int16_t *chrMmxFilter= c->chrMmxFilter;
  2149. const int vLumFilterSize= c->vLumFilterSize;
  2150. const int vChrFilterSize= c->vChrFilterSize;
  2151. const int hLumFilterSize= c->hLumFilterSize;
  2152. const int hChrFilterSize= c->hChrFilterSize;
  2153. int16_t **lumPixBuf= c->lumPixBuf;
  2154. int16_t **chrPixBuf= c->chrPixBuf;
  2155. const int vLumBufSize= c->vLumBufSize;
  2156. const int vChrBufSize= c->vChrBufSize;
  2157. uint8_t *funnyYCode= c->funnyYCode;
  2158. uint8_t *funnyUVCode= c->funnyUVCode;
  2159. uint8_t *formatConvBuffer= c->formatConvBuffer;
  2160. /* vars whch will change and which we need to storw back in the context */
  2161. int dstY= c->dstY;
  2162. int lumBufIndex= c->lumBufIndex;
  2163. int chrBufIndex= c->chrBufIndex;
  2164. int lastInLumBuf= c->lastInLumBuf;
  2165. int lastInChrBuf= c->lastInChrBuf;
  2166. int srcStride[3];
  2167. uint8_t *src[3];
  2168. uint8_t *dst[3];
  2169. if(c->srcFormat == IMGFMT_I420){
  2170. src[0]= srcParam[0];
  2171. src[1]= srcParam[2];
  2172. src[2]= srcParam[1];
  2173. srcStride[0]= srcStrideParam[0];
  2174. srcStride[1]= srcStrideParam[2];
  2175. srcStride[2]= srcStrideParam[1];
  2176. }
  2177. else if(c->srcFormat==IMGFMT_YV12){
  2178. src[0]= srcParam[0];
  2179. src[1]= srcParam[1];
  2180. src[2]= srcParam[2];
  2181. srcStride[0]= srcStrideParam[0];
  2182. srcStride[1]= srcStrideParam[1];
  2183. srcStride[2]= srcStrideParam[2];
  2184. }
  2185. else if(isPacked(c->srcFormat)){
  2186. src[0]=
  2187. src[1]=
  2188. src[2]= srcParam[0];
  2189. srcStride[0]= srcStrideParam[0];
  2190. srcStride[1]=
  2191. srcStride[2]= srcStrideParam[0]<<1;
  2192. }
  2193. else if(isGray(c->srcFormat)){
  2194. src[0]= srcParam[0];
  2195. src[1]=
  2196. src[2]= NULL;
  2197. srcStride[0]= srcStrideParam[0];
  2198. srcStride[1]=
  2199. srcStride[2]= 0;
  2200. }
  2201. if(c->dstFormat == IMGFMT_I420){
  2202. dst[0]= dstParam[0];
  2203. dst[1]= dstParam[2];
  2204. dst[2]= dstParam[1];
  2205. }else{
  2206. dst[0]= dstParam[0];
  2207. dst[1]= dstParam[1];
  2208. dst[2]= dstParam[2];
  2209. }
  2210. //printf("sws Strides:%d %d %d -> %d %d %d\n", srcStride[0],srcStride[1],srcStride[2],
  2211. //dstStride[0],dstStride[1],dstStride[2]);
  2212. if(dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0)
  2213. {
  2214. static int firstTime=1; //FIXME move this into the context perhaps
  2215. if(flags & SWS_PRINT_INFO && firstTime)
  2216. {
  2217. fprintf(stderr, "SwScaler: Warning: dstStride is not aligned!\n"
  2218. "SwScaler: ->cannot do aligned memory acesses anymore\n");
  2219. firstTime=0;
  2220. }
  2221. }
  2222. /* Note the user might start scaling the picture in the middle so this will not get executed
  2223. this is not really intended but works currently, so ppl might do it */
  2224. if(srcSliceY ==0){
  2225. lumBufIndex=0;
  2226. chrBufIndex=0;
  2227. dstY=0;
  2228. lastInLumBuf= -1;
  2229. lastInChrBuf= -1;
  2230. }
  2231. for(;dstY < dstH; dstY++){
  2232. unsigned char *dest =dst[0]+dstStride[0]*dstY;
  2233. unsigned char *uDest=dst[1]+dstStride[1]*(dstY>>1);
  2234. unsigned char *vDest=dst[2]+dstStride[2]*(dstY>>1);
  2235. const int chrDstY= isHalfChrV(dstFormat) ? (dstY>>1) : dstY;
  2236. const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
  2237. const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
  2238. const int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input
  2239. const int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input
  2240. //handle holes (FAST_BILINEAR & weird filters)
  2241. if(firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1;
  2242. if(firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1;
  2243. //printf("%d %d %d\n", firstChrSrcY, lastInChrBuf, vChrBufSize);
  2244. ASSERT(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1)
  2245. ASSERT(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1)
  2246. // Do we have enough lines in this slice to output the dstY line
  2247. if(lastLumSrcY < srcSliceY + srcSliceH && lastChrSrcY < ((srcSliceY + srcSliceH)>>1))
  2248. {
  2249. //Do horizontal scaling
  2250. while(lastInLumBuf < lastLumSrcY)
  2251. {
  2252. uint8_t *s= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0];
  2253. lumBufIndex++;
  2254. // printf("%d %d %d %d\n", lumBufIndex, vLumBufSize, lastInLumBuf, lastLumSrcY);
  2255. ASSERT(lumBufIndex < 2*vLumBufSize)
  2256. ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH)
  2257. ASSERT(lastInLumBuf + 1 - srcSliceY >= 0)
  2258. // printf("%d %d\n", lumBufIndex, vLumBufSize);
  2259. RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc,
  2260. flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize,
  2261. funnyYCode, c->srcFormat, formatConvBuffer);
  2262. lastInLumBuf++;
  2263. }
  2264. while(lastInChrBuf < lastChrSrcY)
  2265. {
  2266. uint8_t *src1= src[1]+(lastInChrBuf + 1 - (srcSliceY>>1))*srcStride[1];
  2267. uint8_t *src2= src[2]+(lastInChrBuf + 1 - (srcSliceY>>1))*srcStride[2];
  2268. chrBufIndex++;
  2269. ASSERT(chrBufIndex < 2*vChrBufSize)
  2270. ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) < (srcSliceH>>1))
  2271. ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) >= 0)
  2272. //FIXME replace parameters through context struct (some at least)
  2273. RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, (srcW+1)>>1, chrXInc,
  2274. flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize,
  2275. funnyUVCode, c->srcFormat, formatConvBuffer);
  2276. lastInChrBuf++;
  2277. }
  2278. //wrap buf index around to stay inside the ring buffer
  2279. if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize;
  2280. if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize;
  2281. }
  2282. else // not enough lines left in this slice -> load the rest in the buffer
  2283. {
  2284. /* printf("%d %d Last:%d %d LastInBuf:%d %d Index:%d %d Y:%d FSize: %d %d BSize: %d %d\n",
  2285. firstChrSrcY,firstLumSrcY,lastChrSrcY,lastLumSrcY,
  2286. lastInChrBuf,lastInLumBuf,chrBufIndex,lumBufIndex,dstY,vChrFilterSize,vLumFilterSize,
  2287. vChrBufSize, vLumBufSize);
  2288. */
  2289. //Do horizontal scaling
  2290. while(lastInLumBuf+1 < srcSliceY + srcSliceH)
  2291. {
  2292. uint8_t *s= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0];
  2293. lumBufIndex++;
  2294. ASSERT(lumBufIndex < 2*vLumBufSize)
  2295. ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH)
  2296. ASSERT(lastInLumBuf + 1 - srcSliceY >= 0)
  2297. RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc,
  2298. flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize,
  2299. funnyYCode, c->srcFormat, formatConvBuffer);
  2300. lastInLumBuf++;
  2301. }
  2302. while(lastInChrBuf+1 < ((srcSliceY + srcSliceH)>>1))
  2303. {
  2304. uint8_t *src1= src[1]+(lastInChrBuf + 1 - (srcSliceY>>1))*srcStride[1];
  2305. uint8_t *src2= src[2]+(lastInChrBuf + 1 - (srcSliceY>>1))*srcStride[2];
  2306. chrBufIndex++;
  2307. ASSERT(chrBufIndex < 2*vChrBufSize)
  2308. ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) < (srcSliceH>>1))
  2309. ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) >= 0)
  2310. RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, (srcW+1)>>1, chrXInc,
  2311. flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize,
  2312. funnyUVCode, c->srcFormat, formatConvBuffer);
  2313. lastInChrBuf++;
  2314. }
  2315. //wrap buf index around to stay inside the ring buffer
  2316. if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize;
  2317. if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize;
  2318. break; //we cant output a dstY line so lets try with the next slice
  2319. }
  2320. #ifdef HAVE_MMX
  2321. b5Dither= dither8[dstY&1];
  2322. g6Dither= dither4[dstY&1];
  2323. g5Dither= dither8[dstY&1];
  2324. r5Dither= dither8[(dstY+1)&1];
  2325. #endif
  2326. if(dstY < dstH-2)
  2327. {
  2328. if(isPlanarYUV(dstFormat)) //YV12 like
  2329. {
  2330. if(dstY&1) uDest=vDest= NULL; //FIXME split functions in lumi / chromi
  2331. if(vLumFilterSize == 1 && vChrFilterSize == 1) // Unscaled YV12
  2332. {
  2333. int16_t *lumBuf = lumPixBuf[0];
  2334. int16_t *chrBuf= chrPixBuf[0];
  2335. RENAME(yuv2yuv1)(lumBuf, chrBuf, dest, uDest, vDest, dstW);
  2336. }
  2337. else //General YV12
  2338. {
  2339. int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
  2340. int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  2341. RENAME(yuv2yuvX)(
  2342. vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
  2343. vChrFilter+(dstY>>1)*vChrFilterSize, chrSrcPtr, vChrFilterSize,
  2344. dest, uDest, vDest, dstW,
  2345. lumMmxFilter+dstY*vLumFilterSize*4, chrMmxFilter+(dstY>>1)*vChrFilterSize*4);
  2346. }
  2347. }
  2348. else
  2349. {
  2350. int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
  2351. int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  2352. ASSERT(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2);
  2353. ASSERT(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2);
  2354. if(vLumFilterSize == 1 && vChrFilterSize == 2) //Unscaled RGB
  2355. {
  2356. int chrAlpha= vChrFilter[2*dstY+1];
  2357. RENAME(yuv2rgb1)(*lumSrcPtr, *chrSrcPtr, *(chrSrcPtr+1),
  2358. dest, dstW, chrAlpha, dstFormat, flags);
  2359. }
  2360. else if(vLumFilterSize == 2 && vChrFilterSize == 2) //BiLinear Upscale RGB
  2361. {
  2362. int lumAlpha= vLumFilter[2*dstY+1];
  2363. int chrAlpha= vChrFilter[2*dstY+1];
  2364. RENAME(yuv2rgb2)(*lumSrcPtr, *(lumSrcPtr+1), *chrSrcPtr, *(chrSrcPtr+1),
  2365. dest, dstW, lumAlpha, chrAlpha, dstFormat, flags);
  2366. }
  2367. else //General RGB
  2368. {
  2369. RENAME(yuv2rgbX)(
  2370. vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
  2371. vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize,
  2372. dest, dstW, dstFormat,
  2373. lumMmxFilter+dstY*vLumFilterSize*4, chrMmxFilter+dstY*vChrFilterSize*4);
  2374. }
  2375. }
  2376. }
  2377. else // hmm looks like we cant use MMX here without overwriting this arrays tail
  2378. {
  2379. int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
  2380. int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  2381. if(isPlanarYUV(dstFormat)) //YV12
  2382. {
  2383. if(dstY&1) uDest=vDest= NULL; //FIXME split functions in lumi / chromi
  2384. yuv2yuvXinC(
  2385. vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
  2386. vChrFilter+(dstY>>1)*vChrFilterSize, chrSrcPtr, vChrFilterSize,
  2387. dest, uDest, vDest, dstW);
  2388. }
  2389. else
  2390. {
  2391. ASSERT(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2);
  2392. ASSERT(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2);
  2393. yuv2rgbXinC(
  2394. vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
  2395. vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize,
  2396. dest, dstW, dstFormat);
  2397. }
  2398. }
  2399. }
  2400. #ifdef HAVE_MMX
  2401. __asm __volatile(SFENCE:::"memory");
  2402. __asm __volatile(EMMS:::"memory");
  2403. #endif
  2404. /* store changed local vars back in the context */
  2405. c->dstY= dstY;
  2406. c->lumBufIndex= lumBufIndex;
  2407. c->chrBufIndex= chrBufIndex;
  2408. c->lastInLumBuf= lastInLumBuf;
  2409. c->lastInChrBuf= lastInChrBuf;
  2410. }