diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2008-09-08 12:36:38 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2008-09-08 12:36:38 +0000 |
commit | 6bc0c7928a386d5cf99c198ec1b795aff6bf7656 (patch) | |
tree | a90c126c5d92e65bfe4ad9dac24473eaae8464ed | |
parent | f7b1d72f45c97f3fc57632a0a23d01cee51c4a4e (diff) | |
download | ffmpeg-6bc0c7928a386d5cf99c198ec1b795aff6bf7656.tar.gz |
Fix jpeg yuv.
Fixes issue504.
Originally committed as revision 27547 to svn://svn.mplayerhq.hu/mplayer/trunk/libswscale
-rw-r--r-- | libswscale/swscale.c | 4 | ||||
-rw-r--r-- | libswscale/swscale_template.c | 41 |
2 files changed, 37 insertions, 8 deletions
diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 3245521299..0b9bb1e63f 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1984,7 +1984,6 @@ int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange int64_t cy = 1<<16; int64_t oy = 0; - if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4); memcpy(c->dstColorspaceTable, table, sizeof(int)*4); @@ -1993,6 +1992,7 @@ int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange c->saturation= saturation; c->srcRange = srcRange; c->dstRange = dstRange; + if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return 0; c->uOffset= 0x0400040004000400LL; c->vOffset= 0x0400040004000400LL; @@ -2213,7 +2213,7 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH sws_setColorspaceDetails(c, Inverse_Table_6_9[SWS_CS_DEFAULT], srcRange, Inverse_Table_6_9[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16); /* unscaled special Cases */ - if (unscaled && !usesHFilter && !usesVFilter) + if (unscaled && !usesHFilter && !usesVFilter && (srcRange == dstRange || isBGR(dstFormat) || isRGB(dstFormat))) { /* yv12_to_nv12 */ if (srcFormat == PIX_FMT_YUV420P && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) diff --git a/libswscale/swscale_template.c b/libswscale/swscale_template.c index 7b82da5b55..ef964ff8ef 100644 --- a/libswscale/swscale_template.c +++ b/libswscale/swscale_template.c @@ -2501,7 +2501,7 @@ static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW #endif /* HAVE_MMX */ } // *** horizontal scale Y line to temp buffer -static inline void RENAME(hyscale)(uint16_t *dst, long dstWidth, uint8_t *src, int srcW, int xInc, +static inline void RENAME(hyscale)(SwsContext *c, uint16_t *dst, long dstWidth, uint8_t *src, int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hLumFilter, int16_t *hLumFilterPos, int hLumFilterSize, void *funnyYCode, int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter, @@ -2711,9 +2711,22 @@ FUNNY_Y_CODE } #endif /* defined(ARCH_X86) */ } + + if(c->srcRange != c->dstRange && !(isRGB(c->dstFormat) || isBGR(c->dstFormat))){ + int i; + //FIXME all pal and rgb srcFormats could do this convertion as well + //FIXME all scalers more complex than bilinear could do half of this transform + if(c->srcRange){ + for (i=0; i<dstWidth; i++) + dst[i]= (dst[i]*14071 + 33561947)>>14; + }else{ + for (i=0; i<dstWidth; i++) + dst[i]= (dst[i]*19077 - 39057361)>>14; + } + } } -inline static void RENAME(hcscale)(uint16_t *dst, long dstWidth, uint8_t *src1, uint8_t *src2, +inline static void RENAME(hcscale)(SwsContext *c, uint16_t *dst, long dstWidth, uint8_t *src1, uint8_t *src2, int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter, int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode, int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter, @@ -2962,6 +2975,22 @@ FUNNY_UV_CODE } #endif /* defined(ARCH_X86) */ } + if(c->srcRange != c->dstRange && !(isRGB(c->dstFormat) || isBGR(c->dstFormat))){ + int i; + //FIXME all pal and rgb srcFormats could do this convertion as well + //FIXME all scalers more complex than bilinear could do half of this transform + if(c->srcRange){ + for (i=0; i<dstWidth; i++){ + dst[i ]= (dst[i ]*1799 + 4081085)>>11; //1469 + dst[i+VOFW]= (dst[i+VOFW]*1799 + 4081085)>>11; //1469 + } + }else{ + for (i=0; i<dstWidth; i++){ + dst[i ]= (dst[i ]*4663 - 9289992)>>12; //-264 + dst[i+VOFW]= (dst[i+VOFW]*4663 - 9289992)>>12; //-264 + } + } + } } static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, @@ -3097,7 +3126,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s assert(lastInLumBuf + 1 - srcSliceY < srcSliceH); assert(lastInLumBuf + 1 - srcSliceY >= 0); //printf("%d %d\n", lumBufIndex, vLumBufSize); - RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, + RENAME(hyscale)(c, lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, funnyYCode, c->srcFormat, formatConvBuffer, c->lumMmx2Filter, c->lumMmx2FilterPos, pal); @@ -3114,7 +3143,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s //FIXME replace parameters through context struct (some at least) if (!(isGray(srcFormat) || isGray(dstFormat))) - RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, + RENAME(hcscale)(c, chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, funnyUVCode, c->srcFormat, formatConvBuffer, c->chrMmx2Filter, c->chrMmx2FilterPos, pal); @@ -3139,7 +3168,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s assert(lumBufIndex < 2*vLumBufSize); assert(lastInLumBuf + 1 - srcSliceY < srcSliceH); assert(lastInLumBuf + 1 - srcSliceY >= 0); - RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, + RENAME(hyscale)(c, lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, funnyYCode, c->srcFormat, formatConvBuffer, c->lumMmx2Filter, c->lumMmx2FilterPos, pal); @@ -3155,7 +3184,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s assert(lastInChrBuf + 1 - chrSrcSliceY >= 0); if (!(isGray(srcFormat) || isGray(dstFormat))) - RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, + RENAME(hcscale)(c, chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, funnyUVCode, c->srcFormat, formatConvBuffer, c->chrMmx2Filter, c->chrMmx2FilterPos, pal); |