diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-05-27 12:47:03 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-05-27 13:21:17 +0200 |
commit | 041dbd3c145046e1bfd35079d23c6843a2f703cb (patch) | |
tree | e669e547af4e9dc886db60d7716f65de962e313c /libswscale | |
parent | f642982c10dd2257a372e36c00c66b8a57954ae1 (diff) | |
download | ffmpeg-041dbd3c145046e1bfd35079d23c6843a2f703cb.tar.gz |
swscale: dont loose precission on RGB/BGR48 input, that is dont drop half the bits.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswscale')
-rw-r--r-- | libswscale/swscale.c | 132 | ||||
-rw-r--r-- | libswscale/swscale_template.c | 30 |
2 files changed, 59 insertions, 103 deletions
diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 84926635c3..00941c9dfc 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1045,93 +1045,55 @@ static void fillPlane(uint8_t* plane, int stride, int width, int height, int y, } } -static inline void rgb48ToY(int16_t *dst, const uint8_t *src, long width, - uint32_t *unused) -{ - int i; - for (i = 0; i < width; i++) { - int r = src[i*6+0]; - int g = src[i*6+2]; - int b = src[i*6+4]; - - dst[i] = (RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6); - } -} - -static inline void rgb48ToUV(int16_t *dstU, int16_t *dstV, - const uint8_t *src1, const uint8_t *src2, - long width, uint32_t *unused) -{ - int i; - assert(src1==src2); - for (i = 0; i < width; i++) { - int r = src1[6*i + 0]; - int g = src1[6*i + 2]; - int b = src1[6*i + 4]; - - dstU[i] = (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6); - dstV[i] = (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6); - } -} - -static inline void rgb48ToUV_half(int16_t *dstU, int16_t *dstV, - const uint8_t *src1, const uint8_t *src2, - long width, uint32_t *unused) -{ - int i; - assert(src1==src2); - for (i = 0; i < width; i++) { - int r= src1[12*i + 0] + src1[12*i + 6]; - int g= src1[12*i + 2] + src1[12*i + 8]; - int b= src1[12*i + 4] + src1[12*i + 10]; - - dstU[i]= (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT)) + (1<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-5); - dstV[i]= (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT)) + (1<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-5); - } -} - -static inline void bgr48ToY(int16_t *dst, const uint8_t *src, long width, - uint32_t *unused) -{ - int i; - for (i = 0; i < width; i++) { - int b = src[i*6+0]; - int g = src[i*6+2]; - int r = src[i*6+4]; - - dst[i] = (RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6); - } -} - -static inline void bgr48ToUV(int16_t *dstU, int16_t *dstV, - const uint8_t *src1, const uint8_t *src2, - long width, uint32_t *unused) -{ - int i; - for (i = 0; i < width; i++) { - int b = src1[6*i + 0]; - int g = src1[6*i + 2]; - int r = src1[6*i + 4]; - - dstU[i] = (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6); - dstV[i] = (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6); - } +#define RGB48(name, R, B, READ)\ +static inline void name ## ToY(int16_t *dst, const uint16_t *src, long width, uint32_t *unused)\ +{\ + int i;\ + for (i = 0; i < width; i++) {\ + int r = READ(&src[i*3+R]);\ + int g = READ(&src[i*3+1]);\ + int b = READ(&src[i*3+B]);\ +\ + dst[i] = (RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);\ + }\ +}\ +\ +static inline void name ## ToUV(int16_t *dstU, int16_t *dstV,\ + const uint16_t *src1, const uint16_t *src2,\ + long width, uint32_t *unused)\ +{\ + int i;\ + assert(src1==src2);\ + for (i = 0; i < width; i++) {\ + int r = READ(&src1[3*i + R]);\ + int g = READ(&src1[3*i + 1]);\ + int b = READ(&src1[3*i + B]);\ +\ + dstU[i] = (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);\ + dstV[i] = (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);\ + }\ +}\ +\ +static inline void name ## ToUV_half(int16_t *dstU, int16_t *dstV,\ + const uint16_t *src1, const uint16_t *src2,\ + long width, uint32_t *unused)\ +{\ + int i;\ + assert(src1==src2);\ + for (i = 0; i < width; i++) {\ + int r= READ(&src1[6*i + R]) + READ(&src1[6*i + 3+R]);\ + int g= READ(&src1[6*i + 1]) + READ(&src1[6*i + 4]);\ + int b= READ(&src1[6*i + B]) + READ(&src1[6*i + 3+B]);\ +\ + dstU[i]= (RU*r + GU*g + BU*b + (256U<<(RGB2YUV_SHIFT+8)) + (1<<(RGB2YUV_SHIFT-6+8))) >> (RGB2YUV_SHIFT-5+8);\ + dstV[i]= (RV*r + GV*g + BV*b + (256U<<(RGB2YUV_SHIFT+8)) + (1<<(RGB2YUV_SHIFT-6+8))) >> (RGB2YUV_SHIFT-5+8);\ + }\ } -static inline void bgr48ToUV_half(int16_t *dstU, int16_t *dstV, - const uint8_t *src1, const uint8_t *src2, - long width, uint32_t *unused) -{ - int i; - for (i = 0; i < width; i++) { - int b= src1[12*i + 0] + src1[12*i + 6]; - int g= src1[12*i + 2] + src1[12*i + 8]; - int r= src1[12*i + 4] + src1[12*i + 10]; - - dstU[i]= (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT)) + (1<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-5); - dstV[i]= (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT)) + (1<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-5); - } -} +RGB48(rgb48LE, 0, 2, AV_RL16) +RGB48(rgb48BE, 0, 2, AV_RB16) +RGB48(bgr48LE, 2, 0, AV_RL16) +RGB48(bgr48BE, 2, 0, AV_RB16) #define BGR2Y(type, name, shr, shg, shb, maskr, maskg, maskb, RY, GY, BY, S)\ static inline void name(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)\ diff --git a/libswscale/swscale_template.c b/libswscale/swscale_template.c index 8bf38b5946..5a84ceb871 100644 --- a/libswscale/swscale_template.c +++ b/libswscale/swscale_template.c @@ -886,10 +886,10 @@ static void sws_init_swScale_c(SwsContext *c) } if (c->chrSrcHSubSample) { switch(srcFormat) { - case PIX_FMT_RGB48BE: - case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV_half; break; - case PIX_FMT_BGR48BE: - case PIX_FMT_BGR48LE: c->chrToYV12 = bgr48ToUV_half; break; + case PIX_FMT_RGB48BE: c->chrToYV12 = rgb48BEToUV_half; break; + case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48LEToUV_half; break; + case PIX_FMT_BGR48BE: c->chrToYV12 = bgr48BEToUV_half; break; + case PIX_FMT_BGR48LE: c->chrToYV12 = bgr48LEToUV_half; break; case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_half; break; case PIX_FMT_RGB32_1: c->chrToYV12 = bgr321ToUV_half; break; case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_half_c; break; @@ -903,10 +903,10 @@ static void sws_init_swScale_c(SwsContext *c) } } else { switch(srcFormat) { - case PIX_FMT_RGB48BE: - case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV; break; - case PIX_FMT_BGR48BE: - case PIX_FMT_BGR48LE: c->chrToYV12 = bgr48ToUV; break; + case PIX_FMT_RGB48BE: c->chrToYV12 = rgb48BEToUV; break; + case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48LEToUV; break; + case PIX_FMT_BGR48BE: c->chrToYV12 = bgr48BEToUV; break; + case PIX_FMT_BGR48LE: c->chrToYV12 = bgr48LEToUV; break; case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV; break; case PIX_FMT_RGB32_1: c->chrToYV12 = bgr321ToUV; break; case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_c; break; @@ -945,10 +945,10 @@ static void sws_init_swScale_c(SwsContext *c) case PIX_FMT_RGB32_1: c->lumToYV12 = bgr321ToY; break; case PIX_FMT_BGR32 : c->lumToYV12 = rgb32ToY; break; case PIX_FMT_BGR32_1: c->lumToYV12 = rgb321ToY; break; - case PIX_FMT_RGB48BE: - case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48ToY; break; - case PIX_FMT_BGR48BE: - case PIX_FMT_BGR48LE: c->lumToYV12 = bgr48ToY; break; + case PIX_FMT_RGB48BE: c->lumToYV12 = rgb48BEToY; break; + case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48LEToY; break; + case PIX_FMT_BGR48BE: c->lumToYV12 = bgr48BEToY; break; + case PIX_FMT_BGR48LE: c->lumToYV12 = bgr48LEToY; break; } if (c->alpPixBuf) { switch (srcFormat) { @@ -972,12 +972,6 @@ static void sws_init_swScale_c(SwsContext *c) case PIX_FMT_BGR32 : c->alpSrcOffset = 3; break; - case PIX_FMT_RGB48LE: - case PIX_FMT_BGR48LE: - c->lumSrcOffset = 1; - c->chrSrcOffset = 1; - c->alpSrcOffset = 1; - break; } if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { |