comparison postproc/swscale.c @ 14715:1fab95e4513c

Improved NV12/NV21 support. - Fixed PlanarToNV12Wrapper() and made it handle NV21. - Added yuv2nv12XinC() to handle software scaling. - Added NV12/NV21 handling to various places. - Removed NV12 from vf_hue and vf_spp as they don't look like they can actually handle it.
author syrjala
date Wed, 16 Feb 2005 23:47:00 +0000
parents 16b3c8e291ff
children f6284dd2516e
comparison
equal deleted inserted replaced
14714:c840f4309043 14715:1fab95e4513c
99 #define PI 3.14159265358979323846 99 #define PI 3.14159265358979323846
100 #endif 100 #endif
101 101
102 //FIXME replace this with something faster 102 //FIXME replace this with something faster
103 #define isPlanarYUV(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_YVU9 \ 103 #define isPlanarYUV(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_YVU9 \
104 || (x)==IMGFMT_NV12 || (x)==IMGFMT_NV21 \
104 || (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P) 105 || (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P)
105 #define isYUV(x) ((x)==IMGFMT_UYVY || (x)==IMGFMT_YUY2 || isPlanarYUV(x)) 106 #define isYUV(x) ((x)==IMGFMT_UYVY || (x)==IMGFMT_YUY2 || isPlanarYUV(x))
106 #define isGray(x) ((x)==IMGFMT_Y800) 107 #define isGray(x) ((x)==IMGFMT_Y800)
107 #define isRGB(x) (((x)&IMGFMT_RGB_MASK)==IMGFMT_RGB) 108 #define isRGB(x) (((x)&IMGFMT_RGB_MASK)==IMGFMT_RGB)
108 #define isBGR(x) (((x)&IMGFMT_BGR_MASK)==IMGFMT_BGR) 109 #define isBGR(x) (((x)&IMGFMT_BGR_MASK)==IMGFMT_BGR)
112 || (x)==IMGFMT_Y800 || (x)==IMGFMT_YVU9\ 113 || (x)==IMGFMT_Y800 || (x)==IMGFMT_YVU9\
113 || (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P) 114 || (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P)
114 #define isSupportedOut(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_YUY2 || (x)==IMGFMT_UYVY\ 115 #define isSupportedOut(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_YUY2 || (x)==IMGFMT_UYVY\
115 || (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P\ 116 || (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P\
116 || isRGB(x) || isBGR(x)\ 117 || isRGB(x) || isBGR(x)\
118 || (x)==IMGFMT_NV12 || (x)==IMGFMT_NV21\
117 || (x)==IMGFMT_Y800 || (x)==IMGFMT_YVU9) 119 || (x)==IMGFMT_Y800 || (x)==IMGFMT_YVU9)
118 #define isPacked(x) ((x)==IMGFMT_YUY2 || (x)==IMGFMT_UYVY ||isRGB(x) || isBGR(x)) 120 #define isPacked(x) ((x)==IMGFMT_YUY2 || (x)==IMGFMT_UYVY ||isRGB(x) || isBGR(x))
119 121
120 #define RGB2YUV_SHIFT 16 122 #define RGB2YUV_SHIFT 16
121 #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5)) 123 #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
249 uDest[i]= MIN(MAX(u>>19, 0), 255); 251 uDest[i]= MIN(MAX(u>>19, 0), 255);
250 vDest[i]= MIN(MAX(v>>19, 0), 255); 252 vDest[i]= MIN(MAX(v>>19, 0), 255);
251 } 253 }
252 } 254 }
253 255
256 static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
257 int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
258 uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat)
259 {
260 //FIXME Optimize (just quickly writen not opti..)
261 int i;
262 for(i=0; i<dstW; i++)
263 {
264 int val=1<<18;
265 int j;
266 for(j=0; j<lumFilterSize; j++)
267 val += lumSrc[j][i] * lumFilter[j];
268
269 dest[i]= MIN(MAX(val>>19, 0), 255);
270 }
271
272 if(uDest == NULL)
273 return;
274
275 if(dstFormat == IMGFMT_NV12)
276 for(i=0; i<chrDstW; i++)
277 {
278 int u=1<<18;
279 int v=1<<18;
280 int j;
281 for(j=0; j<chrFilterSize; j++)
282 {
283 u += chrSrc[j][i] * chrFilter[j];
284 v += chrSrc[j][i + 2048] * chrFilter[j];
285 }
286
287 uDest[2*i]= MIN(MAX(u>>19, 0), 255);
288 uDest[2*i+1]= MIN(MAX(v>>19, 0), 255);
289 }
290 else
291 for(i=0; i<chrDstW; i++)
292 {
293 int u=1<<18;
294 int v=1<<18;
295 int j;
296 for(j=0; j<chrFilterSize; j++)
297 {
298 u += chrSrc[j][i] * chrFilter[j];
299 v += chrSrc[j][i + 2048] * chrFilter[j];
300 }
301
302 uDest[2*i]= MIN(MAX(v>>19, 0), 255);
303 uDest[2*i+1]= MIN(MAX(u>>19, 0), 255);
304 }
305 }
254 306
255 #define YSCALE_YUV_2_PACKEDX_C(type) \ 307 #define YSCALE_YUV_2_PACKEDX_C(type) \
256 for(i=0; i<(dstW>>1); i++){\ 308 for(i=0; i<(dstW>>1); i++){\
257 int j;\ 309 int j;\
258 int Y1=1<<18;\ 310 int Y1=1<<18;\
1377 int i; 1429 int i;
1378 uint8_t *srcPtr= src[0]; 1430 uint8_t *srcPtr= src[0];
1379 uint8_t *dstPtr= dst; 1431 uint8_t *dstPtr= dst;
1380 for(i=0; i<srcSliceH; i++) 1432 for(i=0; i<srcSliceH; i++)
1381 { 1433 {
1382 memcpy(dstPtr, srcPtr, srcStride[0]); 1434 memcpy(dstPtr, srcPtr, c->srcW);
1383 srcPtr+= srcStride[0]; 1435 srcPtr+= srcStride[0];
1384 dstPtr+= dstStride[0]; 1436 dstPtr+= dstStride[0];
1385 } 1437 }
1386 } 1438 }
1387 dst = dstParam[1] + dstStride[1]*srcSliceY; 1439 dst = dstParam[1] + dstStride[1]*srcSliceY/2;
1388 interleaveBytes( src[1],src[2],dst,c->srcW,srcSliceH,srcStride[1],srcStride[2],dstStride[0] ); 1440 if (c->dstFormat == IMGFMT_NV12)
1441 interleaveBytes( src[1],src[2],dst,c->srcW/2,srcSliceH/2,srcStride[1],srcStride[2],dstStride[0] );
1442 else
1443 interleaveBytes( src[2],src[1],dst,c->srcW/2,srcSliceH/2,srcStride[2],srcStride[1],dstStride[0] );
1389 1444
1390 return srcSliceH; 1445 return srcSliceH;
1391 } 1446 }
1392 1447
1393 static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 1448 static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
1553 sortedP[1]= p[1]; 1608 sortedP[1]= p[1];
1554 sortedP[2]= p[2]; 1609 sortedP[2]= p[2];
1555 sortedStride[0]= stride[0]; 1610 sortedStride[0]= stride[0];
1556 sortedStride[1]= stride[1]; 1611 sortedStride[1]= stride[1];
1557 sortedStride[2]= stride[2]; 1612 sortedStride[2]= stride[2];
1613 }
1614 else if(format == IMGFMT_NV12 || format == IMGFMT_NV21)
1615 {
1616 sortedP[0]= p[0];
1617 sortedP[1]= p[1];
1618 sortedP[2]= NULL;
1619 sortedStride[0]= stride[0];
1620 sortedStride[1]= stride[1];
1621 sortedStride[2]= 0;
1558 }else{ 1622 }else{
1559 MSG_ERR("internal error in orderYUV\n"); 1623 MSG_ERR("internal error in orderYUV\n");
1560 } 1624 }
1561 } 1625 }
1562 1626
1643 *h=1; 1707 *h=1;
1644 *v=0; 1708 *v=0;
1645 break; 1709 break;
1646 case IMGFMT_YV12: 1710 case IMGFMT_YV12:
1647 case IMGFMT_Y800: //FIXME remove after different subsamplings are fully implemented 1711 case IMGFMT_Y800: //FIXME remove after different subsamplings are fully implemented
1712 case IMGFMT_NV12:
1713 case IMGFMT_NV21:
1648 *h=1; 1714 *h=1;
1649 *v=1; 1715 *v=1;
1650 break; 1716 break;
1651 case IMGFMT_YVU9: 1717 case IMGFMT_YVU9:
1652 *h=2; 1718 *h=2;
1871 1937
1872 /* unscaled special Cases */ 1938 /* unscaled special Cases */
1873 if(unscaled && !usesHFilter && !usesVFilter) 1939 if(unscaled && !usesHFilter && !usesVFilter)
1874 { 1940 {
1875 /* yv12_to_nv12 */ 1941 /* yv12_to_nv12 */
1876 if(srcFormat == IMGFMT_YV12 && dstFormat == IMGFMT_NV12) 1942 if(srcFormat == IMGFMT_YV12 && (dstFormat == IMGFMT_NV12 || dstFormat == IMGFMT_NV21))
1877 { 1943 {
1878 c->swScale= PlanarToNV12Wrapper; 1944 c->swScale= PlanarToNV12Wrapper;
1879 } 1945 }
1880 /* yuv2bgr */ 1946 /* yuv2bgr */
1881 if((srcFormat==IMGFMT_YV12 || srcFormat==IMGFMT_422P) && (isBGR(dstFormat) || isRGB(dstFormat))) 1947 if((srcFormat==IMGFMT_YV12 || srcFormat==IMGFMT_422P) && (isBGR(dstFormat) || isRGB(dstFormat)))