+static void fillPlane(uint8_t* plane, int stride, int width, int height, int y, uint8_t val)
+{
+ int i;
+ uint8_t *ptr = plane + stride*y;
+ for (i=0; i<height; i++) {
+ memset(ptr, val, width);
+ ptr += stride;
+ }
+}
+
+static inline void rgb48ToY(uint8_t *dst, const uint8_t *src, int 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 + (33<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
+ }
+}
+
+static inline void rgb48ToUV(uint8_t *dstU, uint8_t *dstV,
+ const uint8_t *src1, const uint8_t *src2,
+ int 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 + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
+ dstV[i] = (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
+ }
+}
+
+static inline void rgb48ToUV_half(uint8_t *dstU, uint8_t *dstV,
+ const uint8_t *src1, const uint8_t *src2,
+ int 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 + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
+ dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
+ }
+}
+
+#define BGR2Y(type, name, shr, shg, shb, maskr, maskg, maskb, RY, GY, BY, S)\
+static inline void name(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)\
+{\
+ int i;\
+ for (i=0; i<width; i++) {\
+ int b= (((const type*)src)[i]>>shb)&maskb;\
+ int g= (((const type*)src)[i]>>shg)&maskg;\
+ int r= (((const type*)src)[i]>>shr)&maskr;\
+\
+ dst[i]= (((RY)*r + (GY)*g + (BY)*b + (33<<((S)-1)))>>(S));\
+ }\
+}
+
+BGR2Y(uint32_t, bgr32ToY,16, 0, 0, 0x00FF, 0xFF00, 0x00FF, RY<< 8, GY , BY<< 8, RGB2YUV_SHIFT+8)
+BGR2Y(uint32_t, rgb32ToY, 0, 0,16, 0x00FF, 0xFF00, 0x00FF, RY<< 8, GY , BY<< 8, 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)
+BGR2Y(uint16_t, rgb15ToY, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RY , GY<<5, BY<<10, RGB2YUV_SHIFT+7)
+
+static inline void abgrToA(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
+{
+ int i;
+ for (i=0; i<width; i++) {
+ dst[i]= src[4*i];
+ }
+}
+
+#define BGR2UV(type, name, shr, shg, shb, maska, 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;\
+\
+ dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<((S)-1)))>>(S);\
+ dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (257<<((S)-1)))>>(S);\
+ }\
+}\
+static inline void name ## _half(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 pix0= ((const type*)src)[2*i+0];\
+ int pix1= ((const type*)src)[2*i+1];\
+ 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;\
+ g&= maskg|(2*maskg);\
+\
+ g>>=shg;\
+\
+ dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<(S)))>>((S)+1);\
+ dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (257<<(S)))>>((S)+1);\
+ }\
+}
+
+BGR2UV(uint32_t, bgr32ToUV,16, 0, 0, 0xFF000000, 0xFF0000, 0xFF00, 0x00FF, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8)
+BGR2UV(uint32_t, rgb32ToUV, 0, 0,16, 0xFF000000, 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)
+{
+ int i;
+ for (i=0; i<width; i++) {
+ int d= src[i];
+
+ dst[i]= pal[d] & 0xFF;
+ }
+}
+
+static inline void palToUV(uint8_t *dstU, uint8_t *dstV,
+ const uint8_t *src1, const uint8_t *src2,
+ long width, uint32_t *pal)
+{
+ int i;
+ assert(src1 == src2);
+ for (i=0; i<width; i++) {
+ int p= pal[src1[i]];
+
+ dstU[i]= p>>8;
+ dstV[i]= p>>16;
+ }
+}
+
+static inline void monowhite2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
+{
+ int i, j;
+ for (i=0; i<width/8; i++) {
+ int d= ~src[i];
+ for(j=0; j<8; j++)
+ dst[8*i+j]= ((d>>(7-j))&1)*255;
+ }
+}
+
+static inline void monoblack2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
+{
+ int i, j;
+ for (i=0; i<width/8; i++) {
+ int d= src[i];
+ for(j=0; j<8; j++)
+ dst[8*i+j]= ((d>>(7-j))&1)*255;
+ }
+}
+
+
+//Note: we have C, MMX, MMX2, 3DNOW versions, there is no 3DNOW+MMX2 one