comparison postproc/swscale_template.c @ 4467:9512d6832b38

YUY2, BGR24, BGR32 input support (no mmx yet)
author michael
date Fri, 01 Feb 2002 19:25:09 +0000
parents f002407e298d
children b8ec9cc1b2c5
comparison
equal deleted inserted replaced
4466:bc7b7102c147 4467:9512d6832b38
839 uint8_t *dest, int dstW, int yalpha, int uvalpha, int dstFormat, int flags) 839 uint8_t *dest, int dstW, int yalpha, int uvalpha, int dstFormat, int flags)
840 { 840 {
841 int yalpha1=yalpha^4095; 841 int yalpha1=yalpha^4095;
842 int uvalpha1=uvalpha^4095; 842 int uvalpha1=uvalpha^4095;
843 843
844 if(flags&SWS_FULL_UV_IPOL) 844 if(flags&SWS_FULL_CHR_H_INT)
845 { 845 {
846 846
847 #ifdef HAVE_MMX 847 #ifdef HAVE_MMX
848 if(dstFormat==IMGFMT_BGR32) 848 if(dstFormat==IMGFMT_BGR32)
849 { 849 {
1265 uint8_t *dest, int dstW, int uvalpha, int dstFormat, int flags) 1265 uint8_t *dest, int dstW, int uvalpha, int dstFormat, int flags)
1266 { 1266 {
1267 int uvalpha1=uvalpha^4095; 1267 int uvalpha1=uvalpha^4095;
1268 const int yalpha1=0; 1268 const int yalpha1=0;
1269 1269
1270 if(flags&SWS_FULL_UV_IPOL) 1270 if(flags&SWS_FULL_CHR_H_INT)
1271 { 1271 {
1272 RENAME(yuv2rgb2)(buf0, buf0, uvbuf0, uvbuf1, dest, dstW, 0, uvalpha, dstFormat, flags); 1272 RENAME(yuv2rgb2)(buf0, buf0, uvbuf0, uvbuf1, dest, dstW, 0, uvalpha, dstFormat, flags);
1273 return; 1273 return;
1274 } 1274 }
1275 1275
1532 clip_table15r[(Y2 + Cr + ditherr2) >>13]; 1532 clip_table15r[(Y2 + Cr + ditherr2) >>13];
1533 } 1533 }
1534 } 1534 }
1535 #endif 1535 #endif
1536 } 1536 }
1537
1538 static inline void RENAME(yuy2ToY)(uint8_t *dst, uint8_t *src, int width)
1539 {
1540 #ifdef HAVE_MMXFIXME
1541 #else
1542 int i;
1543 for(i=0; i<width; i++)
1544 dst[i]= src[2*i];
1545 #endif
1546 }
1547
1548 static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
1549 {
1550 #ifdef HAVE_MMXFIXME
1551 #else
1552 int i;
1553 for(i=0; i<width; i++)
1554 {
1555 dstU[i]= (src1[4*i + 1] + src2[4*i + 1])>>1;
1556 dstV[i]= (src1[4*i + 3] + src2[4*i + 3])>>1;
1557 }
1558 #endif
1559 }
1560
1561 static inline void RENAME(bgr32ToY)(uint8_t *dst, uint8_t *src, int width)
1562 {
1563 #ifdef HAVE_MMXFIXME
1564 #else
1565 int i;
1566 for(i=0; i<width; i++)
1567 {
1568 int b= src[i*4+0];
1569 int g= src[i*4+1];
1570 int r= src[i*4+2];
1571
1572 dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
1573 }
1574 #endif
1575 }
1576
1577 static inline void RENAME(bgr32ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
1578 {
1579 #ifdef HAVE_MMXFIXME
1580 #else
1581 int i;
1582 for(i=0; i<width; i++)
1583 {
1584 int b= src1[8*i + 0] + src1[8*i + 4] + src2[8*i + 0] + src2[8*i + 4];
1585 int g= src1[8*i + 1] + src1[8*i + 5] + src2[8*i + 1] + src2[8*i + 5];
1586 int r= src1[8*i + 2] + src1[8*i + 6] + src2[8*i + 2] + src2[8*i + 6];
1587
1588 dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+2)) + 128;
1589 dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+2)) + 128;
1590 }
1591 #endif
1592 }
1593
1594 static inline void RENAME(bgr24ToY)(uint8_t *dst, uint8_t *src, int width)
1595 {
1596 #ifdef HAVE_MMXFIXME
1597 #else
1598 int i;
1599 for(i=0; i<width; i++)
1600 {
1601 int b= src[i*3+0];
1602 int g= src[i*3+1];
1603 int r= src[i*3+2];
1604
1605 dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
1606 }
1607 #endif
1608 }
1609
1610 static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
1611 {
1612 #ifdef HAVE_MMXFIXME
1613 #else
1614 int i;
1615 for(i=0; i<width; i++)
1616 {
1617 int b= src1[6*i + 0] + src1[6*i + 3] + src2[6*i + 0] + src2[6*i + 3];
1618 int g= src1[6*i + 1] + src1[6*i + 4] + src2[6*i + 1] + src2[6*i + 4];
1619 int r= src1[6*i + 2] + src1[6*i + 5] + src2[6*i + 2] + src2[6*i + 5];
1620
1621 dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+2)) + 128;
1622 dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+2)) + 128;
1623 }
1624 #endif
1625 }
1626
1537 1627
1538 // Bilinear / Bicubic scaling 1628 // Bilinear / Bicubic scaling
1539 static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc, 1629 static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc,
1540 int16_t *filter, int16_t *filterPos, int filterSize) 1630 int16_t *filter, int16_t *filterPos, int filterSize)
1541 { 1631 {
1697 #endif 1787 #endif
1698 } 1788 }
1699 // *** horizontal scale Y line to temp buffer 1789 // *** horizontal scale Y line to temp buffer
1700 static inline void RENAME(hyscale)(uint16_t *dst, int dstWidth, uint8_t *src, int srcW, int xInc, 1790 static inline void RENAME(hyscale)(uint16_t *dst, int dstWidth, uint8_t *src, int srcW, int xInc,
1701 int flags, int canMMX2BeUsed, int16_t *hLumFilter, 1791 int flags, int canMMX2BeUsed, int16_t *hLumFilter,
1702 int16_t *hLumFilterPos, int hLumFilterSize, void *funnyYCode) 1792 int16_t *hLumFilterPos, int hLumFilterSize, void *funnyYCode,
1793 int srcFormat, uint8_t *formatConvBuffer)
1703 { 1794 {
1795 if(srcFormat==IMGFMT_YUY2)
1796 {
1797 RENAME(yuy2ToY)(formatConvBuffer, src, srcW);
1798 src= formatConvBuffer;
1799 }
1800 else if(srcFormat==IMGFMT_BGR32)
1801 {
1802 RENAME(bgr32ToY)(formatConvBuffer, src, srcW);
1803 src= formatConvBuffer;
1804 }
1805 else if(srcFormat==IMGFMT_BGR24)
1806 {
1807 RENAME(bgr24ToY)(formatConvBuffer, src, srcW);
1808 src= formatConvBuffer;
1809 }
1810
1704 #ifdef HAVE_MMX 1811 #ifdef HAVE_MMX
1705 // use the new MMX scaler if th mmx2 cant be used (its faster than the x86asm one) 1812 // use the new MMX scaler if th mmx2 cant be used (its faster than the x86asm one)
1706 if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) 1813 if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
1707 #else 1814 #else
1708 if(!(flags&SWS_FAST_BILINEAR)) 1815 if(!(flags&SWS_FAST_BILINEAR))
1824 } 1931 }
1825 } 1932 }
1826 1933
1827 inline static void RENAME(hcscale)(uint16_t *dst, int dstWidth, uint8_t *src1, uint8_t *src2, 1934 inline static void RENAME(hcscale)(uint16_t *dst, int dstWidth, uint8_t *src1, uint8_t *src2,
1828 int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter, 1935 int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter,
1829 int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode) 1936 int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode,
1937 int srcFormat, uint8_t *formatConvBuffer)
1830 { 1938 {
1939 if(srcFormat==IMGFMT_YUY2)
1940 {
1941 RENAME(yuy2ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
1942 src1= formatConvBuffer;
1943 src2= formatConvBuffer+2048;
1944 }
1945 else if(srcFormat==IMGFMT_BGR32)
1946 {
1947 RENAME(bgr32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
1948 src1= formatConvBuffer;
1949 src2= formatConvBuffer+2048;
1950 }
1951 else if(srcFormat==IMGFMT_BGR24)
1952 {
1953 RENAME(bgr24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
1954 src1= formatConvBuffer;
1955 src2= formatConvBuffer+2048;
1956 }
1957
1831 #ifdef HAVE_MMX 1958 #ifdef HAVE_MMX
1832 // use the new MMX scaler if th mmx2 cant be used (its faster than the x86asm one) 1959 // use the new MMX scaler if th mmx2 cant be used (its faster than the x86asm one)
1833 if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) 1960 if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
1834 #else 1961 #else
1835 if(!(flags&SWS_FAST_BILINEAR)) 1962 if(!(flags&SWS_FAST_BILINEAR))
1972 } 2099 }
1973 #endif 2100 #endif
1974 } 2101 }
1975 } 2102 }
1976 2103
1977 static void RENAME(swScale)(SwsContext *c, uint8_t* srcParam[], int srcStride[], int srcSliceY, 2104 static void RENAME(swScale)(SwsContext *c, uint8_t* srcParam[], int srcStrideParam[], int srcSliceY,
1978 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 2105 int srcSliceH, uint8_t* dstParam[], int dstStride[]){
1979 2106
1980 /* load a few things into local vars to make the code more readable? and faster */ 2107 /* load a few things into local vars to make the code more readable? and faster */
1981 const int srcW= c->srcW; 2108 const int srcW= c->srcW;
1982 const int dstW= c->dstW; 2109 const int dstW= c->dstW;
2005 int16_t **chrPixBuf= c->chrPixBuf; 2132 int16_t **chrPixBuf= c->chrPixBuf;
2006 const int vLumBufSize= c->vLumBufSize; 2133 const int vLumBufSize= c->vLumBufSize;
2007 const int vChrBufSize= c->vChrBufSize; 2134 const int vChrBufSize= c->vChrBufSize;
2008 uint8_t *funnyYCode= c->funnyYCode; 2135 uint8_t *funnyYCode= c->funnyYCode;
2009 uint8_t *funnyUVCode= c->funnyUVCode; 2136 uint8_t *funnyUVCode= c->funnyUVCode;
2137 uint8_t *formatConvBuffer= c->formatConvBuffer;
2010 2138
2011 /* vars whch will change and which we need to storw back in the context */ 2139 /* vars whch will change and which we need to storw back in the context */
2012 int dstY= c->dstY; 2140 int dstY= c->dstY;
2013 int lumBufIndex= c->lumBufIndex; 2141 int lumBufIndex= c->lumBufIndex;
2014 int chrBufIndex= c->chrBufIndex; 2142 int chrBufIndex= c->chrBufIndex;
2015 int lastInLumBuf= c->lastInLumBuf; 2143 int lastInLumBuf= c->lastInLumBuf;
2016 int lastInChrBuf= c->lastInChrBuf; 2144 int lastInChrBuf= c->lastInChrBuf;
2145 int srcStride[3];
2017 uint8_t *src[3]; 2146 uint8_t *src[3];
2018 uint8_t *dst[3]; 2147 uint8_t *dst[3];
2019 2148
2020 if((c->srcFormat == IMGFMT_IYUV) || (c->srcFormat == IMGFMT_I420)){ 2149 if((c->srcFormat == IMGFMT_IYUV) || (c->srcFormat == IMGFMT_I420)){
2021 src[0]= srcParam[0]; 2150 src[0]= srcParam[0];
2022 src[1]= srcParam[2]; 2151 src[1]= srcParam[2];
2023 src[2]= srcParam[1]; 2152 src[2]= srcParam[1];
2024 2153 srcStride[0]= srcStrideParam[0];
2025 }else{ 2154 srcStride[1]= srcStrideParam[2];
2155 srcStride[2]= srcStrideParam[1];
2156 }
2157 else if(c->srcFormat==IMGFMT_YV12){
2026 src[0]= srcParam[0]; 2158 src[0]= srcParam[0];
2027 src[1]= srcParam[1]; 2159 src[1]= srcParam[1];
2028 src[2]= srcParam[2]; 2160 src[2]= srcParam[2];
2161 srcStride[0]= srcStrideParam[0];
2162 srcStride[1]= srcStrideParam[1];
2163 srcStride[2]= srcStrideParam[2];
2164 }
2165 else if(isPacked(c->srcFormat)){
2166 src[0]=
2167 src[1]=
2168 src[2]= srcParam[0];
2169 srcStride[0]= srcStrideParam[0];
2170 srcStride[1]=
2171 srcStride[2]= srcStrideParam[0]<<1;
2172 }
2173 else if(c->srcFormat==IMGFMT_Y8){
2174 src[0]= srcParam[0];
2175 src[1]=
2176 src[2]= NULL;
2177 srcStride[0]= srcStrideParam[0];
2178 srcStride[1]=
2179 srcStride[2]= 0;
2029 } 2180 }
2030 2181
2031 if((c->dstFormat == IMGFMT_IYUV) || (c->dstFormat == IMGFMT_I420)){ 2182 if((c->dstFormat == IMGFMT_IYUV) || (c->dstFormat == IMGFMT_I420)){
2032 dst[0]= dstParam[0]; 2183 dst[0]= dstParam[0];
2033 dst[1]= dstParam[2]; 2184 dst[1]= dstParam[2];
2036 }else{ 2187 }else{
2037 dst[0]= dstParam[0]; 2188 dst[0]= dstParam[0];
2038 dst[1]= dstParam[1]; 2189 dst[1]= dstParam[1];
2039 dst[2]= dstParam[2]; 2190 dst[2]= dstParam[2];
2040 } 2191 }
2192
2041 2193
2042 if(dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0) 2194 if(dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0)
2043 { 2195 {
2044 static int firstTime=1; //FIXME move this into the context perhaps 2196 static int firstTime=1; //FIXME move this into the context perhaps
2045 if(flags & SWS_PRINT_INFO && firstTime) 2197 if(flags & SWS_PRINT_INFO && firstTime)
2048 "SwScaler: ->cannot do aligned memory acesses anymore\n"); 2200 "SwScaler: ->cannot do aligned memory acesses anymore\n");
2049 firstTime=0; 2201 firstTime=0;
2050 } 2202 }
2051 } 2203 }
2052 2204
2205 /* Note the user might start scaling the picture in the middle so this will not get executed
2206 this is not really intended but works currently, so ppl might do it */
2053 if(srcSliceY ==0){ 2207 if(srcSliceY ==0){
2054 lumBufIndex=0; 2208 lumBufIndex=0;
2055 chrBufIndex=0; 2209 chrBufIndex=0;
2056 dstY=0; 2210 dstY=0;
2057 lastInLumBuf= -1; 2211 lastInLumBuf= -1;
2058 lastInChrBuf= -1; 2212 lastInChrBuf= -1;
2059 } 2213 }
2060 2214
2061 for(;dstY < dstH; dstY++){ 2215 for(;dstY < dstH; dstY++){
2089 ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH) 2243 ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH)
2090 ASSERT(lastInLumBuf + 1 - srcSliceY >= 0) 2244 ASSERT(lastInLumBuf + 1 - srcSliceY >= 0)
2091 // printf("%d %d\n", lumBufIndex, vLumBufSize); 2245 // printf("%d %d\n", lumBufIndex, vLumBufSize);
2092 RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, 2246 RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc,
2093 flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, 2247 flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize,
2094 funnyYCode); 2248 funnyYCode, c->srcFormat, formatConvBuffer);
2095 lastInLumBuf++; 2249 lastInLumBuf++;
2096 } 2250 }
2097 while(lastInChrBuf < lastChrSrcY) 2251 while(lastInChrBuf < lastChrSrcY)
2098 { 2252 {
2099 uint8_t *src1= src[1]+(lastInChrBuf + 1 - (srcSliceY>>1))*srcStride[1]; 2253 uint8_t *src1= src[1]+(lastInChrBuf + 1 - (srcSliceY>>1))*srcStride[1];
2103 ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) < (srcSliceH>>1)) 2257 ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) < (srcSliceH>>1))
2104 ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) >= 0) 2258 ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) >= 0)
2105 //FIXME replace parameters through context struct (some at least) 2259 //FIXME replace parameters through context struct (some at least)
2106 RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, (srcW+1)>>1, chrXInc, 2260 RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, (srcW+1)>>1, chrXInc,
2107 flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, 2261 flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize,
2108 funnyUVCode); 2262 funnyUVCode, c->srcFormat, formatConvBuffer);
2109 lastInChrBuf++; 2263 lastInChrBuf++;
2110 } 2264 }
2111 //wrap buf index around to stay inside the ring buffer 2265 //wrap buf index around to stay inside the ring buffer
2112 if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize; 2266 if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize;
2113 if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize; 2267 if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize;
2127 ASSERT(lumBufIndex < 2*vLumBufSize) 2281 ASSERT(lumBufIndex < 2*vLumBufSize)
2128 ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH) 2282 ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH)
2129 ASSERT(lastInLumBuf + 1 - srcSliceY >= 0) 2283 ASSERT(lastInLumBuf + 1 - srcSliceY >= 0)
2130 RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, 2284 RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc,
2131 flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, 2285 flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize,
2132 funnyYCode); 2286 funnyYCode, c->srcFormat, formatConvBuffer);
2133 lastInLumBuf++; 2287 lastInLumBuf++;
2134 } 2288 }
2135 while(lastInChrBuf+1 < ((srcSliceY + srcSliceH)>>1)) 2289 while(lastInChrBuf+1 < ((srcSliceY + srcSliceH)>>1))
2136 { 2290 {
2137 uint8_t *src1= src[1]+(lastInChrBuf + 1 - (srcSliceY>>1))*srcStride[1]; 2291 uint8_t *src1= src[1]+(lastInChrBuf + 1 - (srcSliceY>>1))*srcStride[1];
2140 ASSERT(chrBufIndex < 2*vChrBufSize) 2294 ASSERT(chrBufIndex < 2*vChrBufSize)
2141 ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) < (srcSliceH>>1)) 2295 ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) < (srcSliceH>>1))
2142 ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) >= 0) 2296 ASSERT(lastInChrBuf + 1 - (srcSliceY>>1) >= 0)
2143 RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, (srcW+1)>>1, chrXInc, 2297 RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, (srcW+1)>>1, chrXInc,
2144 flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, 2298 flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize,
2145 funnyUVCode); 2299 funnyUVCode, c->srcFormat, formatConvBuffer);
2146 lastInChrBuf++; 2300 lastInChrBuf++;
2147 } 2301 }
2148 //wrap buf index around to stay inside the ring buffer 2302 //wrap buf index around to stay inside the ring buffer
2149 if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize; 2303 if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize;
2150 if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize; 2304 if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize;