yuv2NBPS(16, BE, 1);
yuv2NBPS(16, LE, 0);
- static inline void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
- const int16_t **lumSrc, int lumFilterSize,
- const int16_t *chrFilter, const int16_t **chrUSrc,
- const int16_t **chrVSrc,
- int chrFilterSize, const int16_t **alpSrc,
- uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW,
- const uint8_t *lumDither, const uint8_t *chrDither)
+ static void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
+ const int16_t **lumSrc, int lumFilterSize,
+ const int16_t *chrFilter, const int16_t **chrUSrc,
+ const int16_t **chrVSrc,
+ int chrFilterSize, const int16_t **alpSrc,
+ uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW)
++ uint8_t *aDest, int dstW, int chrDstW,
++ const uint8_t *lumDither, const uint8_t *chrDither)
{
//FIXME Optimize (just quickly written not optimized..)
int i;
aDest[i]= av_clip_uint8(val>>19);
}
- const int16_t *chrUSrc, const int16_t *chrVSrc,
- const int16_t *alpSrc,
- uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW)
+ }
+
+ static void yuv2yuv1_c(SwsContext *c, const int16_t *lumSrc,
- int val= (lumSrc[i]+64)>>7;
++ const int16_t *chrUSrc, const int16_t *chrVSrc,
++ const int16_t *alpSrc,
++ uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
++ uint8_t *aDest, int dstW, int chrDstW, const uint8_t *lumDither, const uint8_t *chrDither)
+ {
+ int i;
++
+ for (i=0; i<dstW; i++) {
- int u=(chrUSrc[i]+64)>>7;
- int v=(chrVSrc[i]+64)>>7;
++ int val= (lumSrc[i]+lumDither[i&7])>>7;
+ dest[i]= av_clip_uint8(val);
+ }
+
+ if (uDest)
+ for (i=0; i<chrDstW; i++) {
++ int u=(chrUSrc[i]+chrDither[i&7])>>7;
++ int v=(chrVSrc[i]+chrDither[(i+3)&7])>>7;
+ uDest[i]= av_clip_uint8(u);
+ vDest[i]= av_clip_uint8(v);
+ }
- int val= (alpSrc[i]+64)>>7;
+ if (CONFIG_SWSCALE_ALPHA && aDest)
+ for (i=0; i<dstW; i++) {
++ int val= (alpSrc[i]+lumDither[i&7])>>7;
+ aDest[i]= av_clip_uint8(val);
+ }
}
- static inline void yuv2nv12X_c(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
- const int16_t *chrFilter, const int16_t **chrUSrc,
- const int16_t **chrVSrc, int chrFilterSize,
- const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest,
- uint8_t *vDest, uint8_t *aDest,
- int dstW, int chrDstW,
- const uint8_t *lumDither, const uint8_t *chrDither)
+ static void yuv2nv12X_c(SwsContext *c, const int16_t *lumFilter,
+ const int16_t **lumSrc, int lumFilterSize,
+ const int16_t *chrFilter, const int16_t **chrUSrc,
+ const int16_t **chrVSrc, int chrFilterSize,
+ const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest,
+ uint8_t *vDest, uint8_t *aDest,
- int dstW, int chrDstW)
++ int dstW, int chrDstW,
++ const uint8_t *lumDither, const uint8_t *chrDither)
{
enum PixelFormat dstFormat = c->dstFormat;
}\
A1>>=19;\
A2>>=19;\
+ if ((A1|A2)&0x100) {\
+ A1 = av_clip_uint8(A1); \
+ A2 = av_clip_uint8(A2); \
+ }\
}
- #define YSCALE_YUV_2_PACKEDX_C(type,alpha) \
- YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha)\
- if ((Y1|Y2|U|V)&256) {\
- if (Y1>255) Y1=255; \
- else if (Y1<0)Y1=0; \
- if (Y2>255) Y2=255; \
- else if (Y2<0)Y2=0; \
- if (U>255) U=255; \
- else if (U<0) U=0; \
- if (V>255) V=255; \
- else if (V<0) V=0; \
- }\
- if (alpha && ((A1|A2)&256)) {\
- A1=av_clip_uint8(A1);\
- A2=av_clip_uint8(A2);\
- }
-
- #define YSCALE_YUV_2_PACKEDX_FULL_C(rnd,alpha) \
+ #define YSCALE_YUV_2_RGBX_FULL_C(rnd,alpha) \
for (i=0; i<dstW; i++) {\
int j;\
- int Y = 0;\
- int U = -128<<19;\
- int V = -128<<19;\
+ int Y = 1<<9;\
+ int U = (1<<9)-(128<<19);\
+ int V = (1<<9)-(128<<19);\
int av_unused A;\
int R,G,B;\
\
U >>=10;\
V >>=10;\
if (alpha) {\
-- A = rnd;\
++ A = rnd>>3;\
for (j=0; j<lumFilterSize; j++)\
A += alpSrc[j][i ] * lumFilter[j];\
A >>=19;\
}
}
- #define RGB48(name, R, B, READ)\
- static inline void name ## ToY_c(int16_t *dst, const uint16_t *src, int 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_c(int16_t *dstU, int16_t *dstV,\
- const uint16_t *src1, const uint16_t *src2,\
- int 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_c(int16_t *dstU, int16_t *dstV,\
- const uint16_t *src1, const uint16_t *src2,\
- int 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 av_always_inline void
-rgb48ToY_c_template(uint8_t *dst, const uint8_t *src, int width,
++rgb48ToY_c_template(int16_t *dst, const uint16_t *src, int width,
+ enum PixelFormat origin)
+ {
+ int i;
+ for (i = 0; i < width; i++) {
+ #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
- int a = input_pixel(&src[i*6+0]) >> 8;
- int g = input_pixel(&src[i*6+2]) >> 8;
- int c = input_pixel(&src[i*6+4]) >> 8;
++ int a = input_pixel(&src[i*3+0]);
++ int g = input_pixel(&src[i*3+1]);
++ int c = input_pixel(&src[i*3+2]);
+
+ #define r ((origin == PIX_FMT_BGR48BE || origin == PIX_FMT_BGR48LE) ? c : a)
+ #define b ((origin == PIX_FMT_BGR48BE || origin == PIX_FMT_BGR48LE) ? a : c)
- dst[i] = (RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
++ dst[i] = (RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);
+ }
}
- 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 void name ## _c(int16_t *dst, const uint8_t *src, int 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 + (32<<((S)-1)) + (1<<(S-7)))>>((S)-6));\
- }\
+ static av_always_inline void
-rgb48ToUV_c_template(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
++rgb48ToUV_c_template(int16_t *dstU, int16_t *dstV,
++ const uint16_t *src1, const uint16_t *src2,
+ int width, enum PixelFormat origin)
+ {
+ int i;
+ assert(src1==src2);
+ for (i = 0; i < width; i++) {
- int a = input_pixel(&src1[6*i + 0]) >> 8;
- int g = input_pixel(&src1[6*i + 2]) >> 8;
- int c = input_pixel(&src1[6*i + 4]) >> 8;
++ int a = input_pixel(&src1[3*i + 0]);
++ int g = input_pixel(&src1[3*i + 1]);
++ int c = input_pixel(&src1[3*i + 2]);
+
- 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;
++ 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);
+ }
}
- 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)
- BGR2Y(uint16_t, rgb15ToY, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RY , GY<<5, BY<<10, RGB2YUV_SHIFT+7)
+ static av_always_inline void
-rgb48ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
++rgb48ToUV_half_c_template(int16_t *dstU, int16_t *dstV,
++ const uint16_t *src1, const uint16_t *src2,
+ int width, enum PixelFormat origin)
+ {
+ int i;
+ assert(src1==src2);
+ for (i = 0; i < width; i++) {
- int a = (input_pixel(&src1[12*i + 0]) >> 8) + (input_pixel(&src1[12*i + 6]) >> 8);
- int g = (input_pixel(&src1[12*i + 2]) >> 8) + (input_pixel(&src1[12*i + 8]) >> 8);
- int c = (input_pixel(&src1[12*i + 4]) >> 8) + (input_pixel(&src1[12*i + 10]) >> 8);
++ int a = (input_pixel(&src1[6*i + 0])) + (input_pixel(&src1[6*i + 3]));
++ int g = (input_pixel(&src1[6*i + 1])) + (input_pixel(&src1[6*i + 4]));
++ int c = (input_pixel(&src1[6*i + 2])) + (input_pixel(&src1[6*i + 5]));
+
- 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);
++ 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);
+ }
+ #undef r
+ #undef b
+ #undef input_pixel
+ }
+
+ #define rgb48funcs(pattern, BE_LE, origin) \
+ static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *dst, const uint8_t *src, \
+ int width, uint32_t *unused) \
+ { \
+ rgb48ToY_c_template(dst, src, width, origin); \
+ } \
+ \
+ static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
+ const uint8_t *src1, const uint8_t *src2, \
+ int width, uint32_t *unused) \
+ { \
+ rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \
+ } \
+ \
+ static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
+ const uint8_t *src1, const uint8_t *src2, \
+ int width, uint32_t *unused) \
+ { \
+ rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \
+ }
+
+ rgb48funcs(rgb, LE, PIX_FMT_RGB48LE);
+ rgb48funcs(rgb, BE, PIX_FMT_RGB48BE);
+ rgb48funcs(bgr, LE, PIX_FMT_BGR48LE);
+ rgb48funcs(bgr, BE, PIX_FMT_BGR48BE);
+
+ static av_always_inline void
-rgb16_32ToY_c_template(uint8_t *dst, const uint8_t *src,
++rgb16_32ToY_c_template(int16_t *dst, const uint8_t *src,
+ int width, enum PixelFormat origin,
+ int shr, int shg, int shb, int shp,
+ int maskr, int maskg, int maskb,
+ int rsh, int gsh, int bsh, int S)
+ {
+ const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh,
- rnd = 33 << (S - 1);
++ rnd = (32<<((S)-1)) + (1<<(S-7));
+ int i;
+
+ for (i = 0; i < width; i++) {
+ #define input_pixel(i) ((origin == PIX_FMT_RGBA || origin == PIX_FMT_BGRA || \
+ origin == PIX_FMT_ARGB || origin == PIX_FMT_ABGR) ? AV_RN32A(&src[(i)*4]) : \
+ (isBE(origin) ? AV_RB16(&src[(i)*2]) : AV_RL16(&src[(i)*2])))
+ int px = input_pixel(i) >> shp;
+ int b = (px & maskb) >> shb;
+ int g = (px & maskg) >> shg;
+ int r = (px & maskr) >> shr;
+
- dst[i] = (ry * r + gy * g + by * b + rnd) >> S;
++ dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6);
+ }
+ }
+
+ static av_always_inline void
-rgb16_32ToUV_c_template(uint8_t *dstU, uint8_t *dstV,
++rgb16_32ToUV_c_template(int16_t *dstU, int16_t *dstV,
+ const uint8_t *src, int width,
+ enum PixelFormat origin,
+ int shr, int shg, int shb, int shp,
+ int maskr, int maskg, int maskb,
+ int rsh, int gsh, int bsh, int S)
+ {
+ const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
+ rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
- rnd = 257 << (S - 1);
++ rnd = (256<<((S)-1)) + (1<<(S-7));
+ int i;
+
+ for (i = 0; i < width; i++) {
+ int px = input_pixel(i) >> shp;
+ int b = (px & maskb) >> shb;
+ int g = (px & maskg) >> shg;
+ int r = (px & maskr) >> shr;
+
- dstU[i] = (ru * r + gu * g + bu * b + rnd) >> S;
- dstV[i] = (rv * r + gv * g + bv * b + rnd) >> S;
++ dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6);
++ dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6);
+ }
+ }
+
+ static av_always_inline void
-rgb16_32ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV,
++rgb16_32ToUV_half_c_template(int16_t *dstU, int16_t *dstV,
+ const uint8_t *src, int width,
+ enum PixelFormat origin,
+ int shr, int shg, int shb, int shp,
+ int maskr, int maskg, int maskb,
+ int rsh, int gsh, int bsh, int S)
+ {
+ const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
+ rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
- rnd = 257 << S, maskgx = ~(maskr | maskb);
++ rnd = (256U<<(S)) + (1<<(S-6)), maskgx = ~(maskr | maskb);
+ int i;
+
+ maskr |= maskr << 1; maskb |= maskb << 1; maskg |= maskg << 1;
+ for (i = 0; i < width; i++) {
+ int px0 = input_pixel(2 * i + 0) >> shp;
+ int px1 = input_pixel(2 * i + 1) >> shp;
+ int b, r, g = (px0 & maskgx) + (px1 & maskgx);
+ int rb = px0 + px1 - g;
+
+ b = (rb & maskb) >> shb;
+ if (shp || origin == PIX_FMT_BGR565LE || origin == PIX_FMT_BGR565BE ||
+ origin == PIX_FMT_RGB565LE || origin == PIX_FMT_RGB565BE) {
+ g >>= shg;
+ } else {
+ g = (g & maskg) >> shg;
+ }
+ r = (rb & maskr) >> shr;
+
- dstU[i] = (ru * r + gu * g + bu * b + rnd) >> (S + 1);
- dstV[i] = (rv * r + gv * g + bv * b + rnd) >> (S + 1);
++ dstU[i] = (ru * r + gu * g + bu * b + (unsigned)rnd) >> ((S)-6+1);
++ dstV[i] = (rv * r + gv * g + bv * b + (unsigned)rnd) >> ((S)-6+1);
+ }
+ #undef input_pixel
+ }
+
+ #define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \
+ maskg, maskb, rsh, gsh, bsh, S) \
+ static void name ## ToY_c(uint8_t *dst, const uint8_t *src, \
+ int width, uint32_t *unused) \
+ { \
+ rgb16_32ToY_c_template(dst, src, width, fmt, shr, shg, shb, shp, \
+ maskr, maskg, maskb, rsh, gsh, bsh, S); \
+ } \
+ \
+ static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
+ const uint8_t *src, const uint8_t *dummy, \
+ int width, uint32_t *unused) \
+ { \
+ rgb16_32ToUV_c_template(dstU, dstV, src, width, fmt, shr, shg, shb, shp, \
+ maskr, maskg, maskb, rsh, gsh, bsh, S); \
+ } \
+ \
+ static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
+ const uint8_t *src, const uint8_t *dummy, \
+ int width, uint32_t *unused) \
+ { \
+ rgb16_32ToUV_half_c_template(dstU, dstV, src, width, fmt, shr, shg, shb, shp, \
+ maskr, maskg, maskb, rsh, gsh, bsh, S); \
+ }
+
+ rgb16_32_wrapper(PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT+8);
+ rgb16_32_wrapper(PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT+8);
+ rgb16_32_wrapper(PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT+8);
+ rgb16_32_wrapper(PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT+8);
+ rgb16_32_wrapper(PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT+8);
+ rgb16_32_wrapper(PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT+7);
+ rgb16_32_wrapper(PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT+8);
+ rgb16_32_wrapper(PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT+7);
+ rgb16_32_wrapper(PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT+8);
+ rgb16_32_wrapper(PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT+7);
+ rgb16_32_wrapper(PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT+8);
+ rgb16_32_wrapper(PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT+7);
-static void abgrToA_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
+static void abgrToA_c(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
{
int i;
for (i=0; i<width; i++) {
}
}
- #define BGR2UV(type, name, shr, shg, shb, shp, maskr, maskg, maskb, RU, GU, BU, RV, GV, BV, S) \
- static void name ## _c(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, int width, uint32_t *unused)\
- {\
- int i;\
- for (i=0; i<width; i++) {\
- int b= ((((const type*)src)[i]>>shp)&maskb)>>shb;\
- int g= ((((const type*)src)[i]>>shp)&maskg)>>shg;\
- int r= ((((const type*)src)[i]>>shp)&maskr)>>shr;\
- \
- dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (256<<((S)-1)) + (1<<(S-7)))>>((S)-6);\
- dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (256<<((S)-1)) + (1<<(S-7)))>>((S)-6);\
- }\
- }\
- static void name ## _half_c(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, int width, uint32_t *unused)\
- {\
- int i;\
- for (i=0; i<width; i++) {\
- 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;\
- g&= maskg|(2*maskg);\
- \
- g>>=shg;\
- \
- dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (256U<<(S)) + (1<<(S-6)))>>((S)-6+1);\
- dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (256U<<(S)) + (1<<(S-6)))>>((S)-6+1);\
- }\
- }
-
- 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 void palToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *pal)
+static void palToA_c(int16_t *dst, const uint8_t *src, int width, uint32_t *pal)
{
int i;
for (i=0; i<width; i++) {
}
}
-static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
- int width, uint32_t *unused)
-{
- nvXXtoUV_c(dstU, dstV, src1, width);
-}
-
-static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
- int width, uint32_t *unused)
-{
- nvXXtoUV_c(dstV, dstU, src1, width);
-}
-
// FIXME Maybe dither instead.
- #ifndef YUV_NBPS
- #define YUV_NBPS(depth, endianness, rfunc) \
- static void endianness ## depth ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
- const uint16_t *srcU, const uint16_t *srcV, \
- int width, uint32_t *unused) \
+ static av_always_inline void
+ yuv9_OR_10ToUV_c_template(uint8_t *dstU, uint8_t *dstV,
+ const uint8_t *_srcU, const uint8_t *_srcV,
+ int width, enum PixelFormat origin, int depth)
+ {
+ int i;
+ const uint16_t *srcU = (const uint16_t *) _srcU;
+ const uint16_t *srcV = (const uint16_t *) _srcV;
+
+ #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
+ for (i = 0; i < width; i++) {
+ dstU[i] = input_pixel(&srcU[i]) >> (depth - 8);
+ dstV[i] = input_pixel(&srcV[i]) >> (depth - 8);
+ }
+ }
+
+ static av_always_inline void
+ yuv9_or_10ToY_c_template(uint8_t *dstY, const uint8_t *_srcY,
+ int width, enum PixelFormat origin, int depth)
+ {
+ int i;
+ const uint16_t *srcY = (const uint16_t*)_srcY;
+
+ for (i = 0; i < width; i++)
+ dstY[i] = input_pixel(&srcY[i]) >> (depth - 8);
+ #undef input_pixel
+ }
+
+ #define YUV_NBPS(depth, BE_LE, origin) \
+ static void BE_LE ## depth ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
+ const uint8_t *srcU, const uint8_t *srcV, \
+ int width, uint32_t *unused) \
{ \
- int i; \
- for (i = 0; i < width; i++) { \
- dstU[i] = rfunc(&srcU[i])>>(depth-8); \
- dstV[i] = rfunc(&srcV[i])>>(depth-8); \
- } \
+ yuv9_OR_10ToUV_c_template(dstU, dstV, srcU, srcV, width, origin, depth); \
} \
- \
- static void endianness ## depth ## ToY_c(uint8_t *dstY, const uint16_t *srcY, int width, uint32_t *unused) \
+ static void BE_LE ## depth ## ToY_c(uint8_t *dstY, const uint8_t *srcY, \
+ int width, uint32_t *unused) \
{ \
- int i; \
- for (i = 0; i < width; i++) \
- dstY[i] = rfunc(&srcY[i])>>(depth-8); \
- } \
+ yuv9_or_10ToY_c_template(dstY, srcY, width, origin, depth); \
+ }
- YUV_NBPS( 9, LE, AV_RL16)
- YUV_NBPS( 9, BE, AV_RB16)
- YUV_NBPS(10, LE, AV_RL16)
- YUV_NBPS(10, BE, AV_RB16)
- #endif // YUV_NBPS
+ YUV_NBPS( 9, LE, PIX_FMT_YUV420P9LE);
+ YUV_NBPS( 9, BE, PIX_FMT_YUV420P9BE);
+ YUV_NBPS(10, LE, PIX_FMT_YUV420P10LE);
+ YUV_NBPS(10, BE, PIX_FMT_YUV420P10BE);
-static void bgr24ToY_c(uint8_t *dst, const uint8_t *src,
+static inline void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
+ const uint8_t *src1, const uint8_t *src2,
+ int width, uint32_t *unused)
+{
+ nvXXtoUV_c(dstU, dstV, src1, width);
+}
+
+static inline void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
+ const uint8_t *src1, const uint8_t *src2,
+ int width, uint32_t *unused)
+{
+ nvXXtoUV_c(dstV, dstU, src1, width);
+}
+
+static void bgr24ToY_c(int16_t *dst, const uint8_t *src,
int width, uint32_t *unused)
{
int i;
}
// *** horizontal scale Y line to temp buffer
- static inline void hyscale(SwsContext *c, uint16_t *dst, int dstWidth,
- const uint8_t *src, int srcW, int xInc,
- const int16_t *hLumFilter,
- const int16_t *hLumFilterPos, int hLumFilterSize,
- uint8_t *formatConvBuffer,
- uint32_t *pal, int isAlpha)
+ static av_always_inline void hyscale(SwsContext *c, uint16_t *dst, int dstWidth,
+ const uint8_t *src, int srcW, int xInc,
+ const int16_t *hLumFilter,
+ const int16_t *hLumFilterPos, int hLumFilterSize,
+ uint8_t *formatConvBuffer,
+ uint32_t *pal, int isAlpha)
{
void (*toYV12)(uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
- void (*convertRange)(uint16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
+ void (*convertRange)(int16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
if (toYV12) {
toYV12(formatConvBuffer, src, srcW, pal);
dst2[i]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
xpos+=xInc;
}
+ for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
+ dst1[i] = src1[srcW-1]*128;
+ dst2[i] = src2[srcW-1]*128;
+ }
}
- static inline void hcscale(SwsContext *c, uint16_t *dst1, uint16_t *dst2, int dstWidth,
- const uint8_t *src1, const uint8_t *src2,
- int srcW, int xInc, const int16_t *hChrFilter,
- const int16_t *hChrFilterPos, int hChrFilterSize,
- uint8_t *formatConvBuffer, uint32_t *pal)
+ static av_always_inline void hcscale(SwsContext *c, uint16_t *dst1, uint16_t *dst2, int dstWidth,
+ const uint8_t *src1, const uint8_t *src2,
+ int srcW, int xInc, const int16_t *hChrFilter,
+ const int16_t *hChrFilterPos, int hChrFilterSize,
+ uint8_t *formatConvBuffer, uint32_t *pal)
{
if (c->chrToYV12) {
- uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW, 16);
+ uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW*2+78, 16);
c->chrToYV12(formatConvBuffer, buf2, src1, src2, srcW, pal);
src1= formatConvBuffer;
src2= buf2;
c->lumToYV12 = NULL;
c->alpToYV12 = NULL;
switch (srcFormat) {
- case PIX_FMT_YUV420P9BE: c->lumToYV12 = BE9ToY_c; break;
- case PIX_FMT_YUV420P9LE: c->lumToYV12 = LE9ToY_c; break;
- case PIX_FMT_YUV420P10BE: c->lumToYV12 = BE10ToY_c; break;
- case PIX_FMT_YUV420P10LE: c->lumToYV12 = LE10ToY_c; break;
case PIX_FMT_YUYV422 :
- case PIX_FMT_YUV420P16BE:
- case PIX_FMT_YUV422P16BE:
- case PIX_FMT_YUV444P16BE:
- case PIX_FMT_Y400A :
- case PIX_FMT_GRAY16BE : c->lumToYV12 = yuy2ToY_c; break;
+ case PIX_FMT_GRAY8A :
+ c->lumToYV12 = yuy2ToY_c; break;
case PIX_FMT_UYVY422 :
- c->lumToYV12 = uyvyToY_c; break;
- case PIX_FMT_BGR24 : c->lumToYV12 = bgr24ToY_c; break;
- case PIX_FMT_BGR565 : c->lumToYV12 = bgr16ToY_c; break;
- case PIX_FMT_BGR555 : c->lumToYV12 = bgr15ToY_c; break;
- case PIX_FMT_RGB24 : c->lumToYV12 = rgb24ToY_c; break;
- case PIX_FMT_RGB565 : c->lumToYV12 = rgb16ToY_c; break;
- case PIX_FMT_RGB555 : c->lumToYV12 = rgb15ToY_c; break;
- case PIX_FMT_YUV420P16LE:
- case PIX_FMT_YUV422P16LE:
- case PIX_FMT_YUV444P16LE:
- case PIX_FMT_GRAY16LE : c->lumToYV12 = uyvyToY_c; break;
++ c->lumToYV12 = uyvyToY_c; break;
+ case PIX_FMT_BGR24 : c->lumToYV12 = bgr24ToY_c; break;
+ case PIX_FMT_BGR565LE : c->lumToYV12 = bgr16leToY_c; break;
+ case PIX_FMT_BGR565BE : c->lumToYV12 = bgr16beToY_c; break;
+ case PIX_FMT_BGR555LE : c->lumToYV12 = bgr15leToY_c; break;
+ case PIX_FMT_BGR555BE : c->lumToYV12 = bgr15beToY_c; break;
+ case PIX_FMT_RGB24 : c->lumToYV12 = rgb24ToY_c; break;
+ case PIX_FMT_RGB565LE : c->lumToYV12 = rgb16leToY_c; break;
+ case PIX_FMT_RGB565BE : c->lumToYV12 = rgb16beToY_c; break;
+ case PIX_FMT_RGB555LE : c->lumToYV12 = rgb15leToY_c; break;
+ case PIX_FMT_RGB555BE : c->lumToYV12 = rgb15beToY_c; break;
case PIX_FMT_RGB8 :
case PIX_FMT_BGR8 :
case PIX_FMT_PAL8 :
: "%"REG_d, "%"REG_S\
);
- static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
- const int16_t **lumSrc, int lumFilterSize,
- const int16_t *chrFilter, const int16_t **chrUSrc,
- const int16_t **chrVSrc,
- int chrFilterSize, const int16_t **alpSrc,
- uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW,
- const uint8_t *lumDither, const uint8_t *chrDither)
+ static void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
+ const int16_t **lumSrc, int lumFilterSize,
+ const int16_t *chrFilter, const int16_t **chrUSrc,
+ const int16_t **chrVSrc,
+ int chrFilterSize, const int16_t **alpSrc,
+ uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW)
++ uint8_t *aDest, int dstW, int chrDstW,
++ const uint8_t *lumDither, const uint8_t *chrDither)
{
+ int i;
if (uDest) {
x86_reg uv_off = c->uv_off;
+ for(i=0; i<8; i++) c->dither16[i] = chrDither[i]>>4;
YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0)
+ for(i=0; i<8; i++) c->dither16[i] = chrDither[(i+3)&7]>>4;
YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off)
}
+ for(i=0; i<8; i++) c->dither16[i] = lumDither[i]>>4;
if (CONFIG_SWSCALE_ALPHA && aDest) {
YSCALEYUV2YV12X(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0)
}
: "%"REG_a, "%"REG_d, "%"REG_S\
);
- static inline void RENAME(yuv2yuvX_ar)(SwsContext *c, const int16_t *lumFilter,
- const int16_t **lumSrc, int lumFilterSize,
- const int16_t *chrFilter, const int16_t **chrUSrc,
- const int16_t **chrVSrc,
- int chrFilterSize, const int16_t **alpSrc,
- uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW,
- const uint8_t *lumDither, const uint8_t *chrDither)
+ static void RENAME(yuv2yuvX_ar)(SwsContext *c, const int16_t *lumFilter,
+ const int16_t **lumSrc, int lumFilterSize,
+ const int16_t *chrFilter, const int16_t **chrUSrc,
+ const int16_t **chrVSrc,
+ int chrFilterSize, const int16_t **alpSrc,
+ uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW)
++ uint8_t *aDest, int dstW, int chrDstW,
++ const uint8_t *lumDither, const uint8_t *chrDither)
{
+ int i;
if (uDest) {
x86_reg uv_off = c->uv_off;
+ for(i=0; i<8; i++) c->dither32[i] = chrDither[i]<<12;
YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0)
+ for(i=0; i<8; i++) c->dither32[i] = chrDither[(i+3)&7]<<12;
YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off)
}
+ for(i=0; i<8; i++) c->dither32[i] = lumDither[i]<<12;
if (CONFIG_SWSCALE_ALPHA && aDest) {
YSCALEYUV2YV12X_ACCURATE(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0)
}
YSCALEYUV2YV12X_ACCURATE(LUM_MMX_FILTER_OFFSET, dest, dstW, 0)
}
- static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc,
- const int16_t *chrUSrc, const int16_t *chrVSrc,
- const int16_t *alpSrc,
- uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW,
- const uint8_t *lumDither, const uint8_t *chrDither)
+ static void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc,
+ const int16_t *chrUSrc, const int16_t *chrVSrc,
+ const int16_t *alpSrc,
+ uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW)
++ uint8_t *aDest, int dstW, int chrDstW,
++ const uint8_t *lumDither, const uint8_t *chrDither)
{
int p= 4;
const int16_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
}
}
- static inline void RENAME(yuv2yuv1_ar)(SwsContext *c, const int16_t *lumSrc,
- const int16_t *chrUSrc, const int16_t *chrVSrc,
- const int16_t *alpSrc,
- uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW,
- const uint8_t *lumDither, const uint8_t *chrDither)
+ static void RENAME(yuv2yuv1_ar)(SwsContext *c, const int16_t *lumSrc,
+ const int16_t *chrUSrc, const int16_t *chrVSrc,
+ const int16_t *alpSrc,
+ uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
- uint8_t *aDest, int dstW, int chrDstW)
++ uint8_t *aDest, int dstW, int chrDstW,
++ const uint8_t *lumDither, const uint8_t *chrDither)
{
int p= 4;
const int16_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
}
#endif /* !COMPILE_TEMPLATE_MMX2 */
- static inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src, int width, enum PixelFormat srcFormat)
-static av_always_inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src,
++static av_always_inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src,
+ int width, enum PixelFormat srcFormat)
{
if(srcFormat == PIX_FMT_BGR24) {
);
}
- static inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV, const uint8_t *src, int width, enum PixelFormat srcFormat)
-static void RENAME(bgr24ToY)(uint8_t *dst, const uint8_t *src,
++static void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src,
+ int width, uint32_t *unused)
+ {
+ RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
+ }
+
-static void RENAME(rgb24ToY)(uint8_t *dst, const uint8_t *src,
++static void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src,
+ int width, uint32_t *unused)
+ {
+ RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
+ }
+
-static av_always_inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV,
++static av_always_inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV,
+ const uint8_t *src, int width,
+ enum PixelFormat srcFormat)
{
__asm__ volatile(
"movq 24(%4), %%mm6 \n\t"
);
}
- static inline void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
- {
- RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
- }
-
- static inline void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
-static void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV,
++static void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV,
+ const uint8_t *src1, const uint8_t *src2,
+ int width, uint32_t *unused)
{
RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
assert(src1 == src2);
}
- static inline void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
- {
- RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
- }
-
- static inline void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
-static void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV,
++static void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV,
+ const uint8_t *src1, const uint8_t *src2,
+ int width, uint32_t *unused)
{
assert(src1==src2);
RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
}
#endif /* !COMPILE_TEMPLATE_MMX2 */
+static inline void RENAME(hScale16)(int16_t *dst, int dstW, const uint16_t *src, int srcW, int xInc,
+ const int16_t *filter, const int16_t *filterPos, long filterSize, int shift)
+{
+ int i, j;
+
+ assert(filterSize % 4 == 0 && filterSize>0);
+ if (filterSize==4 && shift<15) { // Always true for upscaling, sometimes for down, too.
+ x86_reg counter= -2*dstW;
+ filter-= counter*2;
+ filterPos-= counter/2;
+ dst-= counter/2;
+ __asm__ volatile(
+ "movd %5, %%mm7 \n\t"
+#if defined(PIC)
+ "push %%"REG_b" \n\t"
+#endif
+ "push %%"REG_BP" \n\t" // we use 7 regs here ...
+ "mov %%"REG_a", %%"REG_BP" \n\t"
+ ".p2align 4 \n\t"
+ "1: \n\t"
+ "movzwl (%2, %%"REG_BP"), %%eax \n\t"
+ "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t"
+ "movq (%1, %%"REG_BP", 4), %%mm1 \n\t"
+ "movq 8(%1, %%"REG_BP", 4), %%mm3 \n\t"
+ "movq (%3, %%"REG_a", 2), %%mm0 \n\t"
+ "movq (%3, %%"REG_b", 2), %%mm2 \n\t"
+ "pmaddwd %%mm1, %%mm0 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+ "movq %%mm0, %%mm4 \n\t"
+ "punpckldq %%mm3, %%mm0 \n\t"
+ "punpckhdq %%mm3, %%mm4 \n\t"
+ "paddd %%mm4, %%mm0 \n\t"
+ "psrad %%mm7, %%mm0 \n\t"
+ "packssdw %%mm0, %%mm0 \n\t"
+ "movd %%mm0, (%4, %%"REG_BP") \n\t"
+ "add $4, %%"REG_BP" \n\t"
+ " jnc 1b \n\t"
+
+ "pop %%"REG_BP" \n\t"
+#if defined(PIC)
+ "pop %%"REG_b" \n\t"
+#endif
+ : "+a" (counter)
+ : "c" (filter), "d" (filterPos), "S" (src), "D" (dst), "m"(shift)
+#if !defined(PIC)
+ : "%"REG_b
+#endif
+ );
+ } else if (filterSize==8 && shift<15) {
+ x86_reg counter= -2*dstW;
+ filter-= counter*4;
+ filterPos-= counter/2;
+ dst-= counter/2;
+ __asm__ volatile(
+ "movd %5, %%mm7 \n\t"
+#if defined(PIC)
+ "push %%"REG_b" \n\t"
+#endif
+ "push %%"REG_BP" \n\t" // we use 7 regs here ...
+ "mov %%"REG_a", %%"REG_BP" \n\t"
+ ".p2align 4 \n\t"
+ "1: \n\t"
+ "movzwl (%2, %%"REG_BP"), %%eax \n\t"
+ "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t"
+ "movq (%1, %%"REG_BP", 8), %%mm1 \n\t"
+ "movq 16(%1, %%"REG_BP", 8), %%mm3 \n\t"
+ "movq (%3, %%"REG_a", 2), %%mm0 \n\t"
+ "movq (%3, %%"REG_b", 2), %%mm2 \n\t"
+ "pmaddwd %%mm1, %%mm0 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+
+ "movq 8(%1, %%"REG_BP", 8), %%mm1 \n\t"
+ "movq 24(%1, %%"REG_BP", 8), %%mm5 \n\t"
+ "movq 8(%3, %%"REG_a", 2), %%mm4 \n\t"
+ "movq 8(%3, %%"REG_b", 2), %%mm2 \n\t"
+ "pmaddwd %%mm1, %%mm4 \n\t"
+ "pmaddwd %%mm2, %%mm5 \n\t"
+ "paddd %%mm4, %%mm0 \n\t"
+ "paddd %%mm5, %%mm3 \n\t"
+ "movq %%mm0, %%mm4 \n\t"
+ "punpckldq %%mm3, %%mm0 \n\t"
+ "punpckhdq %%mm3, %%mm4 \n\t"
+ "paddd %%mm4, %%mm0 \n\t"
+ "psrad %%mm7, %%mm0 \n\t"
+ "packssdw %%mm0, %%mm0 \n\t"
+ "movd %%mm0, (%4, %%"REG_BP") \n\t"
+ "add $4, %%"REG_BP" \n\t"
+ " jnc 1b \n\t"
+
+ "pop %%"REG_BP" \n\t"
+#if defined(PIC)
+ "pop %%"REG_b" \n\t"
+#endif
+ : "+a" (counter)
+ : "c" (filter), "d" (filterPos), "S" (src), "D" (dst), "m"(shift)
+#if !defined(PIC)
+ : "%"REG_b
+#endif
+ );
+ } else if (shift<15){
+ const uint16_t *offset = src+filterSize;
+ x86_reg counter= -2*dstW;
+ //filter-= counter*filterSize/2;
+ filterPos-= counter/2;
+ dst-= counter/2;
+ __asm__ volatile(
+ "movd %7, %%mm7 \n\t"
+ ".p2align 4 \n\t"
+ "1: \n\t"
+ "mov %2, %%"REG_c" \n\t"
+ "movzwl (%%"REG_c", %0), %%eax \n\t"
+ "movzwl 2(%%"REG_c", %0), %%edx \n\t"
+ "mov %5, %%"REG_c" \n\t"
+ "pxor %%mm4, %%mm4 \n\t"
+ "pxor %%mm5, %%mm5 \n\t"
+ "2: \n\t"
+ "movq (%1), %%mm1 \n\t"
+ "movq (%1, %6), %%mm3 \n\t"
+ "movq (%%"REG_c", %%"REG_a", 2), %%mm0 \n\t"
+ "movq (%%"REG_c", %%"REG_d", 2), %%mm2 \n\t"
+ "pmaddwd %%mm1, %%mm0 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+ "paddd %%mm3, %%mm5 \n\t"
+ "paddd %%mm0, %%mm4 \n\t"
+ "add $8, %1 \n\t"
+ "add $8, %%"REG_c" \n\t"
+ "cmp %4, %%"REG_c" \n\t"
+ " jb 2b \n\t"
+ "add %6, %1 \n\t"
+ "movq %%mm4, %%mm0 \n\t"
+ "punpckldq %%mm5, %%mm4 \n\t"
+ "punpckhdq %%mm5, %%mm0 \n\t"
+ "paddd %%mm0, %%mm4 \n\t"
+ "psrad %%mm7, %%mm4 \n\t"
+ "packssdw %%mm4, %%mm4 \n\t"
+ "mov %3, %%"REG_a" \n\t"
+ "movd %%mm4, (%%"REG_a", %0) \n\t"
+ "add $4, %0 \n\t"
+ " jnc 1b \n\t"
+
+ : "+r" (counter), "+r" (filter)
+ : "m" (filterPos), "m" (dst), "m"(offset),
+ "m" (src), "r" ((x86_reg)filterSize*2), "m"(shift)
+ : "%"REG_a, "%"REG_c, "%"REG_d
+ );
+ } else
+ for (i=0; i<dstW; i++) {
+ int srcPos= filterPos[i];
+ int val=0;
+ for (j=0; j<filterSize; j++) {
+ val += ((int)src[srcPos + j])*filter[filterSize*i + j];
+ }
+ dst[i] = FFMIN(val>>shift, (1<<15)-1); // the cubic equation does overflow ...
+ }
+}
+
+
#if COMPILE_TEMPLATE_MMX2
- static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
- int dstWidth, const uint8_t *src, int srcW,
- int xInc)
+ static void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
+ int dstWidth, const uint8_t *src,
+ int srcW, int xInc)
{
int16_t *filterPos = c->hLumFilterPos;
int16_t *filter = c->hLumFilter;