aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMåns Rullgård <mans@mansr.com>2010-08-23 21:22:24 +0000
committerMåns Rullgård <mans@mansr.com>2010-08-23 21:22:24 +0000
commit66842fe87479afbb93f288de9edf1bb16455d2f8 (patch)
tree8d40acfdab117ced0230d25d64b1cc9ff98ffde9
parent83761d5b583d2524ca2893ce1bd4937350664283 (diff)
downloadffmpeg-66842fe87479afbb93f288de9edf1bb16455d2f8.tar.gz
swscale: fix unaligned accesses in (RGB|BGR)32_1 to YUV conversion
Originally committed as revision 32011 to svn://svn.mplayerhq.hu/mplayer/trunk/libswscale
-rw-r--r--libswscale/swscale.c28
-rw-r--r--libswscale/swscale_template.c29
2 files changed, 28 insertions, 29 deletions
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 5a478b867d..adfadbb61b 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -1048,7 +1048,9 @@ static inline void name(uint8_t *dst, const uint8_t *src, long width, uint32_t *
}
BGR2Y(uint32_t, bgr32ToY,16, 0, 0, 0x00FF, 0xFF00, 0x00FF, RY<< 8, GY , BY<< 8, RGB2YUV_SHIFT+8)
+BGR2Y(uint32_t,bgr321ToY,16,16, 0, 0xFF00, 0x00FF, 0xFF00, RY , GY<<8, BY , RGB2YUV_SHIFT+8)
BGR2Y(uint32_t, rgb32ToY, 0, 0,16, 0x00FF, 0xFF00, 0x00FF, RY<< 8, GY , BY<< 8, RGB2YUV_SHIFT+8)
+BGR2Y(uint32_t,rgb321ToY, 0,16,16, 0xFF00, 0x00FF, 0xFF00, RY , GY<<8, BY , RGB2YUV_SHIFT+8)
BGR2Y(uint16_t, bgr16ToY, 0, 0, 0, 0x001F, 0x07E0, 0xF800, RY<<11, GY<<5, BY , RGB2YUV_SHIFT+8)
BGR2Y(uint16_t, bgr15ToY, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RY<<10, GY<<5, BY , RGB2YUV_SHIFT+7)
BGR2Y(uint16_t, rgb16ToY, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RY , GY<<5, BY<<11, RGB2YUV_SHIFT+8)
@@ -1062,14 +1064,14 @@ static inline void abgrToA(uint8_t *dst, const uint8_t *src, long width, uint32_
}
}
-#define BGR2UV(type, name, shr, shg, shb, maskr, maskg, maskb, RU, GU, BU, RV, GV, BV, S)\
+#define BGR2UV(type, name, shr, shg, shb, shp, maskr, maskg, maskb, RU, GU, BU, RV, GV, BV, S) \
static inline void name(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\
{\
int i;\
for (i=0; i<width; i++) {\
- int b= (((const type*)src)[i]&maskb)>>shb;\
- int g= (((const type*)src)[i]&maskg)>>shg;\
- int r= (((const type*)src)[i]&maskr)>>shr;\
+ int b= (((const type*)src)[i]&maskb)>>(shb+shp);\
+ int g= (((const type*)src)[i]&maskg)>>(shg+shp);\
+ int r= (((const type*)src)[i]&maskr)>>(shr+shp);\
\
dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<((S)-1)))>>(S);\
dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (257<<((S)-1)))>>(S);\
@@ -1079,8 +1081,8 @@ static inline void name ## _half(uint8_t *dstU, uint8_t *dstV, const uint8_t *sr
{\
int i;\
for (i=0; i<width; i++) {\
- int pix0= ((const type*)src)[2*i+0];\
- int pix1= ((const type*)src)[2*i+1];\
+ int pix0= ((const type*)src)[2*i+0]>>shp;\
+ int pix1= ((const type*)src)[2*i+1]>>shp;\
int g= (pix0&~(maskr|maskb))+(pix1&~(maskr|maskb));\
int b= ((pix0+pix1-g)&(maskb|(2*maskb)))>>shb;\
int r= ((pix0+pix1-g)&(maskr|(2*maskr)))>>shr;\
@@ -1093,12 +1095,14 @@ static inline void name ## _half(uint8_t *dstU, uint8_t *dstV, const uint8_t *sr
}\
}
-BGR2UV(uint32_t, bgr32ToUV,16, 0, 0, 0xFF0000, 0xFF00, 0x00FF, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8)
-BGR2UV(uint32_t, rgb32ToUV, 0, 0,16, 0x00FF, 0xFF00, 0xFF0000, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8)
-BGR2UV(uint16_t, bgr16ToUV, 0, 0, 0, 0x001F, 0x07E0, 0xF800, RU<<11, GU<<5, BU , RV<<11, GV<<5, BV , RGB2YUV_SHIFT+8)
-BGR2UV(uint16_t, bgr15ToUV, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RU<<10, GU<<5, BU , RV<<10, GV<<5, BV , RGB2YUV_SHIFT+7)
-BGR2UV(uint16_t, rgb16ToUV, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RU , GU<<5, BU<<11, RV , GV<<5, BV<<11, RGB2YUV_SHIFT+8)
-BGR2UV(uint16_t, rgb15ToUV, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RU , GU<<5, BU<<10, RV , GV<<5, BV<<10, RGB2YUV_SHIFT+7)
+BGR2UV(uint32_t, bgr32ToUV,16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8)
+BGR2UV(uint32_t,bgr321ToUV,16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8)
+BGR2UV(uint32_t, rgb32ToUV, 0, 0,16, 0, 0x00FF, 0xFF00, 0xFF0000, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8)
+BGR2UV(uint32_t,rgb321ToUV, 0, 0,16, 8, 0x00FF, 0xFF00, 0xFF0000, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8)
+BGR2UV(uint16_t, bgr16ToUV, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, RU<<11, GU<<5, BU , RV<<11, GV<<5, BV , RGB2YUV_SHIFT+8)
+BGR2UV(uint16_t, bgr15ToUV, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RU<<10, GU<<5, BU , RV<<10, GV<<5, BV , RGB2YUV_SHIFT+7)
+BGR2UV(uint16_t, rgb16ToUV, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RU , GU<<5, BU<<11, RV , GV<<5, BV<<11, RGB2YUV_SHIFT+8)
+BGR2UV(uint16_t, rgb15ToUV, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RU , GU<<5, BU<<10, RV , GV<<5, BV<<10, RGB2YUV_SHIFT+7)
static inline void palToY(uint8_t *dst, const uint8_t *src, long width, uint32_t *pal)
{
diff --git a/libswscale/swscale_template.c b/libswscale/swscale_template.c
index f4aa432d10..42c4a8ba5f 100644
--- a/libswscale/swscale_template.c
+++ b/libswscale/swscale_template.c
@@ -2966,13 +2966,13 @@ static void RENAME(sws_init_swScale)(SwsContext *c)
switch(srcFormat) {
case PIX_FMT_RGB48BE:
case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV_half; break;
- case PIX_FMT_RGB32 :
- case PIX_FMT_RGB32_1: c->chrToYV12 = bgr32ToUV_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 = RENAME(bgr24ToUV_half); break;
case PIX_FMT_BGR565 : c->chrToYV12 = bgr16ToUV_half; break;
case PIX_FMT_BGR555 : c->chrToYV12 = bgr15ToUV_half; break;
- case PIX_FMT_BGR32 :
- case PIX_FMT_BGR32_1: c->chrToYV12 = rgb32ToUV_half; break;
+ case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV_half; break;
+ case PIX_FMT_BGR32_1: c->chrToYV12 = rgb321ToUV_half; break;
case PIX_FMT_RGB24 : c->chrToYV12 = RENAME(rgb24ToUV_half); break;
case PIX_FMT_RGB565 : c->chrToYV12 = rgb16ToUV_half; break;
case PIX_FMT_RGB555 : c->chrToYV12 = rgb15ToUV_half; break;
@@ -2981,13 +2981,13 @@ static void RENAME(sws_init_swScale)(SwsContext *c)
switch(srcFormat) {
case PIX_FMT_RGB48BE:
case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV; break;
- case PIX_FMT_RGB32 :
- case PIX_FMT_RGB32_1: c->chrToYV12 = bgr32ToUV; break;
+ case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV; break;
+ case PIX_FMT_RGB32_1: c->chrToYV12 = bgr321ToUV; break;
case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV); break;
case PIX_FMT_BGR565 : c->chrToYV12 = bgr16ToUV; break;
case PIX_FMT_BGR555 : c->chrToYV12 = bgr15ToUV; break;
- case PIX_FMT_BGR32 :
- case PIX_FMT_BGR32_1: c->chrToYV12 = rgb32ToUV; break;
+ case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV; break;
+ case PIX_FMT_BGR32_1: c->chrToYV12 = rgb321ToUV; break;
case PIX_FMT_RGB24 : c->chrToYV12 = RENAME(rgb24ToUV); break;
case PIX_FMT_RGB565 : c->chrToYV12 = rgb16ToUV; break;
case PIX_FMT_RGB555 : c->chrToYV12 = rgb15ToUV; break;
@@ -3020,10 +3020,10 @@ static void RENAME(sws_init_swScale)(SwsContext *c)
case PIX_FMT_RGB4_BYTE: c->lumToYV12 = palToY; break;
case PIX_FMT_MONOBLACK: c->lumToYV12 = monoblack2Y; break;
case PIX_FMT_MONOWHITE: c->lumToYV12 = monowhite2Y; break;
- case PIX_FMT_RGB32 :
- case PIX_FMT_RGB32_1: c->lumToYV12 = bgr32ToY; break;
- case PIX_FMT_BGR32 :
- case PIX_FMT_BGR32_1: c->lumToYV12 = rgb32ToY; break;
+ case PIX_FMT_RGB32 : c->lumToYV12 = bgr32ToY; break;
+ 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;
}
@@ -3041,11 +3041,6 @@ static void RENAME(sws_init_swScale)(SwsContext *c)
case PIX_FMT_BGR32 :
c->alpSrcOffset = 3;
break;
- case PIX_FMT_RGB32_1:
- case PIX_FMT_BGR32_1:
- c->lumSrcOffset = ALT32_CORR;
- c->chrSrcOffset = ALT32_CORR;
- break;
case PIX_FMT_RGB48LE:
c->lumSrcOffset = 1;
c->chrSrcOffset = 1;