comparison libswscale/swscale_template.c @ 29404:efbe0c7de351

Do not misuse HAVE_ defines. Introduce COMPILE_TEMPLATE_ defines and use them instead.
author ramiro
date Mon, 27 Jul 2009 06:47:41 +0000
parents 6c1b9f334f97
children 45759bfb13d6
comparison
equal deleted inserted replaced
29403:6c1b9f334f97 29404:efbe0c7de351
25 #undef MOVNTQ 25 #undef MOVNTQ
26 #undef PAVGB 26 #undef PAVGB
27 #undef PREFETCH 27 #undef PREFETCH
28 #undef PREFETCHW 28 #undef PREFETCHW
29 29
30 #if HAVE_AMD3DNOW 30 #if COMPILE_TEMPLATE_AMD3DNOW
31 #define PREFETCH "prefetch" 31 #define PREFETCH "prefetch"
32 #define PREFETCHW "prefetchw" 32 #define PREFETCHW "prefetchw"
33 #elif HAVE_MMX2 33 #elif COMPILE_TEMPLATE_MMX2
34 #define PREFETCH "prefetchnta" 34 #define PREFETCH "prefetchnta"
35 #define PREFETCHW "prefetcht0" 35 #define PREFETCHW "prefetcht0"
36 #else 36 #else
37 #define PREFETCH " # nop" 37 #define PREFETCH " # nop"
38 #define PREFETCHW " # nop" 38 #define PREFETCHW " # nop"
39 #endif 39 #endif
40 40
41 #if HAVE_MMX2 41 #if COMPILE_TEMPLATE_MMX2
42 #define PAVGB(a,b) "pavgb " #a ", " #b " \n\t" 42 #define PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
43 #elif HAVE_AMD3DNOW 43 #elif COMPILE_TEMPLATE_AMD3DNOW
44 #define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t" 44 #define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
45 #endif 45 #endif
46 46
47 #if HAVE_MMX2 47 #if COMPILE_TEMPLATE_MMX2
48 #define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t" 48 #define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t"
49 #else 49 #else
50 #define REAL_MOVNTQ(a,b) "movq " #a ", " #b " \n\t" 50 #define REAL_MOVNTQ(a,b) "movq " #a ", " #b " \n\t"
51 #endif 51 #endif
52 #define MOVNTQ(a,b) REAL_MOVNTQ(a,b) 52 #define MOVNTQ(a,b) REAL_MOVNTQ(a,b)
53 53
54 #if HAVE_ALTIVEC 54 #if COMPILE_TEMPLATE_ALTIVEC
55 #include "ppc/swscale_altivec_template.c" 55 #include "ppc/swscale_altivec_template.c"
56 #endif 56 #endif
57 57
58 #define YSCALEYUV2YV12X(x, offset, dest, width) \ 58 #define YSCALEYUV2YV12X(x, offset, dest, width) \
59 __asm__ volatile(\ 59 __asm__ volatile(\
873 \ 873 \
874 "add $8, "#index" \n\t"\ 874 "add $8, "#index" \n\t"\
875 "cmp "#dstw", "#index" \n\t"\ 875 "cmp "#dstw", "#index" \n\t"\
876 " jb 1b \n\t" 876 " jb 1b \n\t"
877 877
878 #if HAVE_MMX2 878 #if COMPILE_TEMPLATE_MMX2
879 #undef WRITEBGR24 879 #undef WRITEBGR24
880 #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX2(dst, dstw, index) 880 #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX2(dst, dstw, index)
881 #else 881 #else
882 #undef WRITEBGR24 882 #undef WRITEBGR24
883 #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX(dst, dstw, index) 883 #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX(dst, dstw, index)
903 903
904 static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, 904 static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
905 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, const int16_t **alpSrc, 905 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, const int16_t **alpSrc,
906 uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, long dstW, long chrDstW) 906 uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, long dstW, long chrDstW)
907 { 907 {
908 #if HAVE_MMX 908 #if COMPILE_TEMPLATE_MMX
909 if(!(c->flags & SWS_BITEXACT)){ 909 if(!(c->flags & SWS_BITEXACT)){
910 if (c->flags & SWS_ACCURATE_RND){ 910 if (c->flags & SWS_ACCURATE_RND){
911 if (uDest){ 911 if (uDest){
912 YSCALEYUV2YV12X_ACCURATE( "0", CHR_MMX_FILTER_OFFSET, uDest, chrDstW) 912 YSCALEYUV2YV12X_ACCURATE( "0", CHR_MMX_FILTER_OFFSET, uDest, chrDstW)
913 YSCALEYUV2YV12X_ACCURATE(AV_STRINGIFY(VOF), CHR_MMX_FILTER_OFFSET, vDest, chrDstW) 913 YSCALEYUV2YV12X_ACCURATE(AV_STRINGIFY(VOF), CHR_MMX_FILTER_OFFSET, vDest, chrDstW)
929 YSCALEYUV2YV12X("0", LUM_MMX_FILTER_OFFSET, dest, dstW) 929 YSCALEYUV2YV12X("0", LUM_MMX_FILTER_OFFSET, dest, dstW)
930 } 930 }
931 return; 931 return;
932 } 932 }
933 #endif 933 #endif
934 #if HAVE_ALTIVEC 934 #if COMPILE_TEMPLATE_ALTIVEC
935 yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize, 935 yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize,
936 chrFilter, chrSrc, chrFilterSize, 936 chrFilter, chrSrc, chrFilterSize,
937 dest, uDest, vDest, dstW, chrDstW); 937 dest, uDest, vDest, dstW, chrDstW);
938 #else //HAVE_ALTIVEC 938 #else //COMPILE_TEMPLATE_ALTIVEC
939 yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize, 939 yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize,
940 chrFilter, chrSrc, chrFilterSize, 940 chrFilter, chrSrc, chrFilterSize,
941 alpSrc, dest, uDest, vDest, aDest, dstW, chrDstW); 941 alpSrc, dest, uDest, vDest, aDest, dstW, chrDstW);
942 #endif //!HAVE_ALTIVEC 942 #endif //!COMPILE_TEMPLATE_ALTIVEC
943 } 943 }
944 944
945 static inline void RENAME(yuv2nv12X)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, 945 static inline void RENAME(yuv2nv12X)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
946 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, 946 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
947 uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat) 947 uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat)
953 953
954 static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc, const int16_t *chrSrc, const int16_t *alpSrc, 954 static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc, const int16_t *chrSrc, const int16_t *alpSrc,
955 uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, long dstW, long chrDstW) 955 uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, long dstW, long chrDstW)
956 { 956 {
957 int i; 957 int i;
958 #if HAVE_MMX 958 #if COMPILE_TEMPLATE_MMX
959 if(!(c->flags & SWS_BITEXACT)){ 959 if(!(c->flags & SWS_BITEXACT)){
960 long p= 4; 960 long p= 4;
961 uint8_t *src[4]= {alpSrc + dstW, lumSrc + dstW, chrSrc + chrDstW, chrSrc + VOFW + chrDstW}; 961 uint8_t *src[4]= {alpSrc + dstW, lumSrc + dstW, chrSrc + chrDstW, chrSrc + VOFW + chrDstW};
962 uint8_t *dst[4]= {aDest, dest, uDest, vDest}; 962 uint8_t *dst[4]= {aDest, dest, uDest, vDest};
963 x86_reg counter[4]= {dstW, dstW, chrDstW, chrDstW}; 963 x86_reg counter[4]= {dstW, dstW, chrDstW, chrDstW};
1030 */ 1030 */
1031 static inline void RENAME(yuv2packedX)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, 1031 static inline void RENAME(yuv2packedX)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
1032 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, 1032 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
1033 const int16_t **alpSrc, uint8_t *dest, long dstW, long dstY) 1033 const int16_t **alpSrc, uint8_t *dest, long dstW, long dstY)
1034 { 1034 {
1035 #if HAVE_MMX 1035 #if COMPILE_TEMPLATE_MMX
1036 x86_reg dummy=0; 1036 x86_reg dummy=0;
1037 if(!(c->flags & SWS_BITEXACT)){ 1037 if(!(c->flags & SWS_BITEXACT)){
1038 if (c->flags & SWS_ACCURATE_RND){ 1038 if (c->flags & SWS_ACCURATE_RND){
1039 switch(c->dstFormat){ 1039 switch(c->dstFormat){
1040 case PIX_FMT_RGB32: 1040 case PIX_FMT_RGB32:
1191 YSCALEYUV2PACKEDX_END 1191 YSCALEYUV2PACKEDX_END
1192 return; 1192 return;
1193 } 1193 }
1194 } 1194 }
1195 } 1195 }
1196 #endif /* HAVE_MMX */ 1196 #endif /* COMPILE_TEMPLATE_MMX */
1197 #if HAVE_ALTIVEC 1197 #if COMPILE_TEMPLATE_ALTIVEC
1198 /* The following list of supported dstFormat values should 1198 /* The following list of supported dstFormat values should
1199 match what's found in the body of ff_yuv2packedX_altivec() */ 1199 match what's found in the body of ff_yuv2packedX_altivec() */
1200 if (!(c->flags & SWS_BITEXACT) && !c->alpPixBuf && 1200 if (!(c->flags & SWS_BITEXACT) && !c->alpPixBuf &&
1201 (c->dstFormat==PIX_FMT_ABGR || c->dstFormat==PIX_FMT_BGRA || 1201 (c->dstFormat==PIX_FMT_ABGR || c->dstFormat==PIX_FMT_BGRA ||
1202 c->dstFormat==PIX_FMT_BGR24 || c->dstFormat==PIX_FMT_RGB24 || 1202 c->dstFormat==PIX_FMT_BGR24 || c->dstFormat==PIX_FMT_RGB24 ||
1219 { 1219 {
1220 int yalpha1=4095- yalpha; 1220 int yalpha1=4095- yalpha;
1221 int uvalpha1=4095-uvalpha; 1221 int uvalpha1=4095-uvalpha;
1222 int i; 1222 int i;
1223 1223
1224 #if HAVE_MMX 1224 #if COMPILE_TEMPLATE_MMX
1225 if(!(c->flags & SWS_BITEXACT)){ 1225 if(!(c->flags & SWS_BITEXACT)){
1226 switch(c->dstFormat) 1226 switch(c->dstFormat)
1227 { 1227 {
1228 //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( 1228 //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
1229 case PIX_FMT_RGB32: 1229 case PIX_FMT_RGB32:
1355 ); 1355 );
1356 return; 1356 return;
1357 default: break; 1357 default: break;
1358 } 1358 }
1359 } 1359 }
1360 #endif //HAVE_MMX 1360 #endif //COMPILE_TEMPLATE_MMX
1361 YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C(void,0), YSCALE_YUV_2_GRAY16_2_C, YSCALE_YUV_2_MONO2_C) 1361 YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C(void,0), YSCALE_YUV_2_GRAY16_2_C, YSCALE_YUV_2_MONO2_C)
1362 } 1362 }
1363 1363
1364 /** 1364 /**
1365 * YV12 to RGB without scaling or interpolating 1365 * YV12 to RGB without scaling or interpolating
1377 { 1377 {
1378 c->yuv2packed2(c, buf0, buf0, uvbuf0, uvbuf1, abuf0, abuf0, dest, dstW, 0, uvalpha, y); 1378 c->yuv2packed2(c, buf0, buf0, uvbuf0, uvbuf1, abuf0, abuf0, dest, dstW, 0, uvalpha, y);
1379 return; 1379 return;
1380 } 1380 }
1381 1381
1382 #if HAVE_MMX 1382 #if COMPILE_TEMPLATE_MMX
1383 if(!(flags & SWS_BITEXACT)){ 1383 if(!(flags & SWS_BITEXACT)){
1384 if (uvalpha < 2048) // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster 1384 if (uvalpha < 2048) // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1385 { 1385 {
1386 switch(dstFormat) 1386 switch(dstFormat)
1387 { 1387 {
1598 ); 1598 );
1599 return; 1599 return;
1600 } 1600 }
1601 } 1601 }
1602 } 1602 }
1603 #endif /* HAVE_MMX */ 1603 #endif /* COMPILE_TEMPLATE_MMX */
1604 if (uvalpha < 2048) 1604 if (uvalpha < 2048)
1605 { 1605 {
1606 YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C, YSCALE_YUV_2_PACKED1_C(void,0), YSCALE_YUV_2_GRAY16_1_C, YSCALE_YUV_2_MONO2_C) 1606 YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C, YSCALE_YUV_2_PACKED1_C(void,0), YSCALE_YUV_2_GRAY16_1_C, YSCALE_YUV_2_MONO2_C)
1607 }else{ 1607 }else{
1608 YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C, YSCALE_YUV_2_PACKED1B_C(void,0), YSCALE_YUV_2_GRAY16_1_C, YSCALE_YUV_2_MONO2_C) 1608 YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C, YSCALE_YUV_2_PACKED1B_C(void,0), YSCALE_YUV_2_GRAY16_1_C, YSCALE_YUV_2_MONO2_C)
1611 1611
1612 //FIXME yuy2* can read up to 7 samples too much 1612 //FIXME yuy2* can read up to 7 samples too much
1613 1613
1614 static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) 1614 static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1615 { 1615 {
1616 #if HAVE_MMX 1616 #if COMPILE_TEMPLATE_MMX
1617 __asm__ volatile( 1617 __asm__ volatile(
1618 "movq "MANGLE(bm01010101)", %%mm2 \n\t" 1618 "movq "MANGLE(bm01010101)", %%mm2 \n\t"
1619 "mov %0, %%"REG_a" \n\t" 1619 "mov %0, %%"REG_a" \n\t"
1620 "1: \n\t" 1620 "1: \n\t"
1621 "movq (%1, %%"REG_a",2), %%mm0 \n\t" 1621 "movq (%1, %%"REG_a",2), %%mm0 \n\t"
1636 #endif 1636 #endif
1637 } 1637 }
1638 1638
1639 static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) 1639 static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1640 { 1640 {
1641 #if HAVE_MMX 1641 #if COMPILE_TEMPLATE_MMX
1642 __asm__ volatile( 1642 __asm__ volatile(
1643 "movq "MANGLE(bm01010101)", %%mm4 \n\t" 1643 "movq "MANGLE(bm01010101)", %%mm4 \n\t"
1644 "mov %0, %%"REG_a" \n\t" 1644 "mov %0, %%"REG_a" \n\t"
1645 "1: \n\t" 1645 "1: \n\t"
1646 "movq (%1, %%"REG_a",4), %%mm0 \n\t" 1646 "movq (%1, %%"REG_a",4), %%mm0 \n\t"
1671 assert(src1 == src2); 1671 assert(src1 == src2);
1672 } 1672 }
1673 1673
1674 static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) 1674 static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1675 { 1675 {
1676 #if HAVE_MMX 1676 #if COMPILE_TEMPLATE_MMX
1677 __asm__ volatile( 1677 __asm__ volatile(
1678 "mov %0, %%"REG_a" \n\t" 1678 "mov %0, %%"REG_a" \n\t"
1679 "1: \n\t" 1679 "1: \n\t"
1680 "movq (%1, %%"REG_a",2), %%mm0 \n\t" 1680 "movq (%1, %%"REG_a",2), %%mm0 \n\t"
1681 "movq 8(%1, %%"REG_a",2), %%mm1 \n\t" 1681 "movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
1706 1706
1707 /* This is almost identical to the previous, end exists only because 1707 /* This is almost identical to the previous, end exists only because
1708 * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */ 1708 * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
1709 static inline void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) 1709 static inline void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1710 { 1710 {
1711 #if HAVE_MMX 1711 #if COMPILE_TEMPLATE_MMX
1712 __asm__ volatile( 1712 __asm__ volatile(
1713 "mov %0, %%"REG_a" \n\t" 1713 "mov %0, %%"REG_a" \n\t"
1714 "1: \n\t" 1714 "1: \n\t"
1715 "movq (%1, %%"REG_a",2), %%mm0 \n\t" 1715 "movq (%1, %%"REG_a",2), %%mm0 \n\t"
1716 "movq 8(%1, %%"REG_a",2), %%mm1 \n\t" 1716 "movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
1730 #endif 1730 #endif
1731 } 1731 }
1732 1732
1733 static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) 1733 static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1734 { 1734 {
1735 #if HAVE_MMX 1735 #if COMPILE_TEMPLATE_MMX
1736 __asm__ volatile( 1736 __asm__ volatile(
1737 "movq "MANGLE(bm01010101)", %%mm4 \n\t" 1737 "movq "MANGLE(bm01010101)", %%mm4 \n\t"
1738 "mov %0, %%"REG_a" \n\t" 1738 "mov %0, %%"REG_a" \n\t"
1739 "1: \n\t" 1739 "1: \n\t"
1740 "movq (%1, %%"REG_a",4), %%mm0 \n\t" 1740 "movq (%1, %%"REG_a",4), %%mm0 \n\t"
1765 assert(src1 == src2); 1765 assert(src1 == src2);
1766 } 1766 }
1767 1767
1768 static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) 1768 static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1769 { 1769 {
1770 #if HAVE_MMX 1770 #if COMPILE_TEMPLATE_MMX
1771 __asm__ volatile( 1771 __asm__ volatile(
1772 "movq "MANGLE(bm01010101)", %%mm4 \n\t" 1772 "movq "MANGLE(bm01010101)", %%mm4 \n\t"
1773 "mov %0, %%"REG_a" \n\t" 1773 "mov %0, %%"REG_a" \n\t"
1774 "1: \n\t" 1774 "1: \n\t"
1775 "movq (%1, %%"REG_a",2), %%mm0 \n\t" 1775 "movq (%1, %%"REG_a",2), %%mm0 \n\t"
1797 dstV[i]= src2[2*i]; 1797 dstV[i]= src2[2*i];
1798 } 1798 }
1799 #endif 1799 #endif
1800 } 1800 }
1801 1801
1802 #if HAVE_MMX 1802 #if COMPILE_TEMPLATE_MMX
1803 static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, long width, int srcFormat) 1803 static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, long width, int srcFormat)
1804 { 1804 {
1805 1805
1806 if(srcFormat == PIX_FMT_BGR24){ 1806 if(srcFormat == PIX_FMT_BGR24){
1807 __asm__ volatile( 1807 __asm__ volatile(
1912 } 1912 }
1913 #endif 1913 #endif
1914 1914
1915 static inline void RENAME(bgr24ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) 1915 static inline void RENAME(bgr24ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1916 { 1916 {
1917 #if HAVE_MMX 1917 #if COMPILE_TEMPLATE_MMX
1918 RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24); 1918 RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
1919 #else 1919 #else
1920 int i; 1920 int i;
1921 for (i=0; i<width; i++) 1921 for (i=0; i<width; i++)
1922 { 1922 {
1924 int g= src[i*3+1]; 1924 int g= src[i*3+1];
1925 int r= src[i*3+2]; 1925 int r= src[i*3+2];
1926 1926
1927 dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT); 1927 dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
1928 } 1928 }
1929 #endif /* HAVE_MMX */ 1929 #endif /* COMPILE_TEMPLATE_MMX */
1930 } 1930 }
1931 1931
1932 static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) 1932 static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1933 { 1933 {
1934 #if HAVE_MMX 1934 #if COMPILE_TEMPLATE_MMX
1935 RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24); 1935 RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
1936 #else 1936 #else
1937 int i; 1937 int i;
1938 for (i=0; i<width; i++) 1938 for (i=0; i<width; i++)
1939 { 1939 {
1942 int r= src1[3*i + 2]; 1942 int r= src1[3*i + 2];
1943 1943
1944 dstU[i]= (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT; 1944 dstU[i]= (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
1945 dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT; 1945 dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
1946 } 1946 }
1947 #endif /* HAVE_MMX */ 1947 #endif /* COMPILE_TEMPLATE_MMX */
1948 assert(src1 == src2); 1948 assert(src1 == src2);
1949 } 1949 }
1950 1950
1951 static inline void RENAME(bgr24ToUV_half)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) 1951 static inline void RENAME(bgr24ToUV_half)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1952 { 1952 {
1963 assert(src1 == src2); 1963 assert(src1 == src2);
1964 } 1964 }
1965 1965
1966 static inline void RENAME(rgb24ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) 1966 static inline void RENAME(rgb24ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1967 { 1967 {
1968 #if HAVE_MMX 1968 #if COMPILE_TEMPLATE_MMX
1969 RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24); 1969 RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
1970 #else 1970 #else
1971 int i; 1971 int i;
1972 for (i=0; i<width; i++) 1972 for (i=0; i<width; i++)
1973 { 1973 {
1980 #endif 1980 #endif
1981 } 1981 }
1982 1982
1983 static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) 1983 static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1984 { 1984 {
1985 #if HAVE_MMX 1985 #if COMPILE_TEMPLATE_MMX
1986 assert(src1==src2); 1986 assert(src1==src2);
1987 RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24); 1987 RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
1988 #else 1988 #else
1989 int i; 1989 int i;
1990 assert(src1==src2); 1990 assert(src1==src2);
2018 2018
2019 // bilinear / bicubic scaling 2019 // bilinear / bicubic scaling
2020 static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW, int xInc, 2020 static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW, int xInc,
2021 const int16_t *filter, const int16_t *filterPos, long filterSize) 2021 const int16_t *filter, const int16_t *filterPos, long filterSize)
2022 { 2022 {
2023 #if HAVE_MMX 2023 #if COMPILE_TEMPLATE_MMX
2024 assert(filterSize % 4 == 0 && filterSize>0); 2024 assert(filterSize % 4 == 0 && filterSize>0);
2025 if (filterSize==4) // Always true for upscaling, sometimes for down, too. 2025 if (filterSize==4) // Always true for upscaling, sometimes for down, too.
2026 { 2026 {
2027 x86_reg counter= -2*dstW; 2027 x86_reg counter= -2*dstW;
2028 filter-= counter*2; 2028 filter-= counter*2;
2174 "m" (src), "r" ((x86_reg)filterSize*2) 2174 "m" (src), "r" ((x86_reg)filterSize*2)
2175 : "%"REG_a, "%"REG_c, "%"REG_d 2175 : "%"REG_a, "%"REG_c, "%"REG_d
2176 ); 2176 );
2177 } 2177 }
2178 #else 2178 #else
2179 #if HAVE_ALTIVEC 2179 #if COMPILE_TEMPLATE_ALTIVEC
2180 hScale_altivec_real(dst, dstW, src, srcW, xInc, filter, filterPos, filterSize); 2180 hScale_altivec_real(dst, dstW, src, srcW, xInc, filter, filterPos, filterSize);
2181 #else 2181 #else
2182 int i; 2182 int i;
2183 for (i=0; i<dstW; i++) 2183 for (i=0; i<dstW; i++)
2184 { 2184 {
2193 } 2193 }
2194 //filter += hFilterSize; 2194 //filter += hFilterSize;
2195 dst[i] = FFMIN(val>>7, (1<<15)-1); // the cubic equation does overflow ... 2195 dst[i] = FFMIN(val>>7, (1<<15)-1); // the cubic equation does overflow ...
2196 //dst[i] = val>>7; 2196 //dst[i] = val>>7;
2197 } 2197 }
2198 #endif /* HAVE_ALTIVEC */ 2198 #endif /* COMPILE_ALTIVEC */
2199 #endif /* HAVE_MMX */ 2199 #endif /* COMPILE_MMX */
2200 } 2200 }
2201 2201
2202 #define FAST_BILINEAR_X86 \ 2202 #define FAST_BILINEAR_X86 \
2203 "subl %%edi, %%esi \n\t" /* src[xx+1] - src[xx] */ \ 2203 "subl %%edi, %%esi \n\t" /* src[xx+1] - src[xx] */ \
2204 "imull %%ecx, %%esi \n\t" /* (src[xx+1] - src[xx])*xalpha */ \ 2204 "imull %%ecx, %%esi \n\t" /* (src[xx+1] - src[xx])*xalpha */ \
2249 if (internal_func) { 2249 if (internal_func) {
2250 internal_func(formatConvBuffer, src, srcW, pal); 2250 internal_func(formatConvBuffer, src, srcW, pal);
2251 src= formatConvBuffer; 2251 src= formatConvBuffer;
2252 } 2252 }
2253 2253
2254 #if HAVE_MMX 2254 #if COMPILE_TEMPLATE_MMX
2255 // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one). 2255 // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one).
2256 if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) 2256 if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
2257 #else 2257 #else
2258 if (!(flags&SWS_FAST_BILINEAR)) 2258 if (!(flags&SWS_FAST_BILINEAR))
2259 #endif 2259 #endif
2261 c->hScale(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize); 2261 c->hScale(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize);
2262 } 2262 }
2263 else // fast bilinear upscale / crap downscale 2263 else // fast bilinear upscale / crap downscale
2264 { 2264 {
2265 #if ARCH_X86 && CONFIG_GPL 2265 #if ARCH_X86 && CONFIG_GPL
2266 #if HAVE_MMX2 2266 #if COMPILE_TEMPLATE_MMX2
2267 int i; 2267 int i;
2268 #if defined(PIC) 2268 #if defined(PIC)
2269 DECLARE_ALIGNED(8, uint64_t, ebxsave); 2269 DECLARE_ALIGNED(8, uint64_t, ebxsave);
2270 #endif 2270 #endif
2271 if (canMMX2BeUsed) 2271 if (canMMX2BeUsed)
2329 ); 2329 );
2330 for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) dst[i] = src[srcW-1]*128; 2330 for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) dst[i] = src[srcW-1]*128;
2331 } 2331 }
2332 else 2332 else
2333 { 2333 {
2334 #endif /* HAVE_MMX2 */ 2334 #endif /* COMPILE_TEMPLATE_MMX2 */
2335 x86_reg xInc_shr16 = xInc >> 16; 2335 x86_reg xInc_shr16 = xInc >> 16;
2336 uint16_t xInc_mask = xInc & 0xffff; 2336 uint16_t xInc_mask = xInc & 0xffff;
2337 //NO MMX just normal asm ... 2337 //NO MMX just normal asm ...
2338 __asm__ volatile( 2338 __asm__ volatile(
2339 "xor %%"REG_a", %%"REG_a" \n\t" // i 2339 "xor %%"REG_a", %%"REG_a" \n\t" // i
2362 2362
2363 2363
2364 :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask) 2364 :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask)
2365 : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" 2365 : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi"
2366 ); 2366 );
2367 #if HAVE_MMX2 2367 #if COMPILE_TEMPLATE_MMX2
2368 } //if MMX2 can't be used 2368 } //if MMX2 can't be used
2369 #endif 2369 #endif
2370 #else 2370 #else
2371 c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc); 2371 c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc);
2372 #endif /* ARCH_X86 */ 2372 #endif /* ARCH_X86 */
2434 c->hcscale_internal(formatConvBuffer, formatConvBuffer+VOFW, src1, src2, srcW, pal); 2434 c->hcscale_internal(formatConvBuffer, formatConvBuffer+VOFW, src1, src2, srcW, pal);
2435 src1= formatConvBuffer; 2435 src1= formatConvBuffer;
2436 src2= formatConvBuffer+VOFW; 2436 src2= formatConvBuffer+VOFW;
2437 } 2437 }
2438 2438
2439 #if HAVE_MMX 2439 #if COMPILE_TEMPLATE_MMX
2440 // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one). 2440 // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one).
2441 if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) 2441 if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
2442 #else 2442 #else
2443 if (!(flags&SWS_FAST_BILINEAR)) 2443 if (!(flags&SWS_FAST_BILINEAR))
2444 #endif 2444 #endif
2447 c->hScale(dst+VOFW, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); 2447 c->hScale(dst+VOFW, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
2448 } 2448 }
2449 else // fast bilinear upscale / crap downscale 2449 else // fast bilinear upscale / crap downscale
2450 { 2450 {
2451 #if ARCH_X86 && CONFIG_GPL 2451 #if ARCH_X86 && CONFIG_GPL
2452 #if HAVE_MMX2 2452 #if COMPILE_TEMPLATE_MMX2
2453 int i; 2453 int i;
2454 #if defined(PIC) 2454 #if defined(PIC)
2455 DECLARE_ALIGNED(8, uint64_t, ebxsave); 2455 DECLARE_ALIGNED(8, uint64_t, ebxsave);
2456 #endif 2456 #endif
2457 if (canMMX2BeUsed) 2457 if (canMMX2BeUsed)
2528 dst[i+VOFW] = src2[srcW-1]*128; 2528 dst[i+VOFW] = src2[srcW-1]*128;
2529 } 2529 }
2530 } 2530 }
2531 else 2531 else
2532 { 2532 {
2533 #endif /* HAVE_MMX2 */ 2533 #endif /* COMPILE_TEMPLATE_MMX2 */
2534 x86_reg xInc_shr16 = (x86_reg) (xInc >> 16); 2534 x86_reg xInc_shr16 = (x86_reg) (xInc >> 16);
2535 uint16_t xInc_mask = xInc & 0xffff; 2535 uint16_t xInc_mask = xInc & 0xffff;
2536 __asm__ volatile( 2536 __asm__ volatile(
2537 "xor %%"REG_a", %%"REG_a" \n\t" // i 2537 "xor %%"REG_a", %%"REG_a" \n\t" // i
2538 "xor %%"REG_d", %%"REG_d" \n\t" // xx 2538 "xor %%"REG_d", %%"REG_d" \n\t" // xx
2564 :: "m" (src1), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask), 2564 :: "m" (src1), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask),
2565 #endif 2565 #endif
2566 "r" (src2) 2566 "r" (src2)
2567 : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" 2567 : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi"
2568 ); 2568 );
2569 #if HAVE_MMX2 2569 #if COMPILE_TEMPLATE_MMX2
2570 } //if MMX2 can't be used 2570 } //if MMX2 can't be used
2571 #endif 2571 #endif
2572 #else 2572 #else
2573 c->hcscale_fast(c, dst, dstWidth, src1, src2, srcW, xInc); 2573 c->hcscale_fast(c, dst, dstWidth, src1, src2, srcW, xInc);
2574 #endif /* ARCH_X86 */ 2574 #endif /* ARCH_X86 */
2805 if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize; 2805 if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize;
2806 if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize; 2806 if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize;
2807 break; //we can't output a dstY line so let's try with the next slice 2807 break; //we can't output a dstY line so let's try with the next slice
2808 } 2808 }
2809 2809
2810 #if HAVE_MMX 2810 #if COMPILE_TEMPLATE_MMX
2811 c->blueDither= ff_dither8[dstY&1]; 2811 c->blueDither= ff_dither8[dstY&1];
2812 if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555) 2812 if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555)
2813 c->greenDither= ff_dither8[dstY&1]; 2813 c->greenDither= ff_dither8[dstY&1];
2814 else 2814 else
2815 c->greenDither= ff_dither4[dstY&1]; 2815 c->greenDither= ff_dither4[dstY&1];
2818 if (dstY < dstH-2) 2818 if (dstY < dstH-2)
2819 { 2819 {
2820 const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; 2820 const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
2821 const int16_t **chrSrcPtr= (const int16_t **) chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; 2821 const int16_t **chrSrcPtr= (const int16_t **) chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
2822 const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; 2822 const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
2823 #if HAVE_MMX 2823 #if COMPILE_TEMPLATE_MMX
2824 int i; 2824 int i;
2825 if (flags & SWS_ACCURATE_RND){ 2825 if (flags & SWS_ACCURATE_RND){
2826 int s= APCK_SIZE / 8; 2826 int s= APCK_SIZE / 8;
2827 for (i=0; i<vLumFilterSize; i+=2){ 2827 for (i=0; i<vLumFilterSize; i+=2){
2828 *(void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ]; 2828 *(void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ];
2991 } 2991 }
2992 2992
2993 if ((dstFormat == PIX_FMT_YUVA420P) && !alpPixBuf) 2993 if ((dstFormat == PIX_FMT_YUVA420P) && !alpPixBuf)
2994 fillPlane(dst[3], dstStride[3], dstW, dstY-lastDstY, lastDstY, 255); 2994 fillPlane(dst[3], dstStride[3], dstW, dstY-lastDstY, lastDstY, 255);
2995 2995
2996 #if HAVE_MMX 2996 #if COMPILE_TEMPLATE_MMX
2997 if (flags & SWS_CPU_CAPS_MMX2 ) __asm__ volatile("sfence":::"memory"); 2997 if (flags & SWS_CPU_CAPS_MMX2 ) __asm__ volatile("sfence":::"memory");
2998 /* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */ 2998 /* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */
2999 if (flags & SWS_CPU_CAPS_3DNOW) __asm__ volatile("femms" :::"memory"); 2999 if (flags & SWS_CPU_CAPS_3DNOW) __asm__ volatile("femms" :::"memory");
3000 else __asm__ volatile("emms" :::"memory"); 3000 else __asm__ volatile("emms" :::"memory");
3001 #endif 3001 #endif