diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2007-04-15 00:53:32 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2007-04-15 00:53:32 +0000 |
commit | 21c08a3f1c91c6a9fa7dbaf48d14078ecb4b985d (patch) | |
tree | b240c5c59022747f1468f19a6a9cbb1899ab9690 /libswscale | |
parent | fe2ad119e91eab9dead56c737ccc899655ae5618 (diff) | |
download | ffmpeg-streaming-21c08a3f1c91c6a9fa7dbaf48d14078ecb4b985d.zip ffmpeg-streaming-21c08a3f1c91c6a9fa7dbaf48d14078ecb4b985d.tar.gz |
convert palette to yuv instead of converting each pixel after pal->rgb
Originally committed as revision 22993 to svn://svn.mplayerhq.hu/mplayer/trunk/libswscale
Diffstat (limited to 'libswscale')
-rw-r--r-- | libswscale/swscale.c | 27 | ||||
-rw-r--r-- | libswscale/swscale_template.c | 12 |
2 files changed, 25 insertions, 14 deletions
diff --git a/libswscale/swscale.c b/libswscale/swscale.c index a56cdef..1b21a2f 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -2438,6 +2438,9 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH */ int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]){ + int i; + uint8_t* src2[4]= {src[0], src[1], src[2]}; + uint32_t pal[256]; if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { av_log(c, AV_LOG_ERROR, "swScaler: slices start in the middle!\n"); return 0; @@ -2446,24 +2449,38 @@ int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1; } + if(c->srcFormat == PIX_FMT_PAL8){ + for(i=0; i<256; i++){ + int p= ((uint32_t*)(src[1]))[i]; + int r= (p>>16)&0xFF; + int g= (p>> 8)&0xFF; + int b= p &0xFF; + int y= av_clip_uint8(((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16 ); + int u= av_clip_uint8(((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128); + int v= av_clip_uint8(((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128); + pal[i]= y + (u<<8) + (v<<16); + } + src2[1]= pal; + } + // copy strides, so they can safely be modified if (c->sliceDir == 1) { - uint8_t* src2[4]= {src[0], src[1], src[2]}; // slices go from top to bottom int srcStride2[4]= {srcStride[0], srcStride[1], srcStride[2]}; int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2]}; return c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst, dstStride2); } else { // slices go from bottom to top => we flip the image internally - uint8_t* src2[4]= {src[0] + (srcSliceH-1)*srcStride[0], - src[1] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1], - src[2] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2] - }; uint8_t* dst2[4]= {dst[0] + (c->dstH-1)*dstStride[0], dst[1] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[1], dst[2] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[2]}; int srcStride2[4]= {-srcStride[0], -srcStride[1], -srcStride[2]}; int dstStride2[4]= {-dstStride[0], -dstStride[1], -dstStride[2]}; + + src2[0] += (srcSliceH-1)*srcStride[0]; + if(c->srcFormat != PIX_FMT_PAL8) + src2[1] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1]; + src2[2] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2]; return c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2); } diff --git a/libswscale/swscale_template.c b/libswscale/swscale_template.c index 9c1bb5f..a8616ef 100644 --- a/libswscale/swscale_template.c +++ b/libswscale/swscale_template.c @@ -2285,11 +2285,8 @@ static inline void RENAME(palToY)(uint8_t *dst, uint8_t *src, int width, uint32_ for(i=0; i<width; i++) { int d= src[i]; - int b= pal[d] &0xFF; - int g=(pal[d]>>8 )&0xFF; - int r= pal[d]>>16; - dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; + dst[i]= pal[d] & 0xFF; } } @@ -2302,12 +2299,9 @@ static inline void RENAME(palToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, int d0= src1[2*i ]; int d1= src1[2*i+1]; int p = (pal[d0]&0xFF00FF) + (pal[d1]&0xFF00FF); - int g = (pal[d0]+pal[d1]-p)>>8; - int b= p&0x1FF; - int r= p>>16; - dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128; - dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; + dstU[i]= (pal[d0]+pal[d1]-p)>>9; + dstV[i]= p>>17; } } |