swscale: dont loose precission on RGB/BGR48 input, that is dont drop half the bits.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/2/head
Michael Niedermayer 14 years ago
parent f642982c10
commit 041dbd3c14
  1. 132
      libswscale/swscale.c
  2. 30
      libswscale/swscale_template.c
  3. 8
      tests/ref/lavfi/pixfmts_scale_le

@ -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)\

@ -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)) {

@ -1,8 +1,8 @@
abgr cff82561a074874027ac1cc896fd2730
argb 756dd1eaa5baca2238ce23dbdc452684
bgr24 e44192347a45586c6c157e3059610cd1
bgr48be 62e6043fbe9734e63ad679999ca8011c
bgr48le 61237dad4fa5f3e9109db85f53cd25d9
bgr48be 6d01b6ccd2ccf18c12985bcb2fde2218
bgr48le 4caa6914091ad03b8f67c02d6b050bc0
bgr4_byte ee1d35a7baf8e9016891929a2f565c0b
bgr555le 41e3e0961478dc634bf68a7bbd670cc9
bgr565le 614897eaeb422bd9a972f8ee51909be5
@ -16,8 +16,8 @@ monow fd5d417ab7728acddffc06870661df61
nv12 4676d59db43d657dc12841f6bc3ab452
nv21 69c699510ff1fb777b118ebee1002f14
rgb24 13ff53ebeab74dc05492836f1cfbd2c1
rgb48be 7f6b1f8139c6a64eadf9dfa867ac20e8
rgb48le 2756d8710c152cbc367656de4d0f1b76
rgb48be f82e99f13d5ede2a53cf3bf7178ca350
rgb48le 3a09d89e4b27ea1a98f762e662e306a7
rgb4_byte d81ffd3add95842a618eec81024f0b5c
rgb555le bd698d86c03170c4a16607c0fd1f750f
rgb565le bfa0c639d80c3c03fd0c9e5f34296a5e

Loading…
Cancel
Save