---
libswscale/output.c | 98 +++++++++++++-----------------------------
libswscale/swscale.c | 18 ++++++--
libswscale/x86/swscale_mmx.c | 8 ++--
3 files changed, 47 insertions(+), 77 deletions(-)
diff --git a/libswscale/output.c b/libswscale/output.c
index 8263da1..aa73813 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -132,6 +132,7 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
static av_always_inline void
yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
+ const uint8_t *dither, int offset,
int big_endian, int output_bits)
{
int i;
@@ -146,6 +147,7 @@ yuv2plane1_16_c_template(const int32_t *src, uint16_t
*dest, int dstW,
static av_always_inline void
yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
const int32_t **src, uint16_t *dest, int dstW,
+ const uint8_t *dither, int offset,
int big_endian, int output_bits)
{
int i;
@@ -179,6 +181,7 @@ yuv2planeX_16_c_template(const int16_t *filter, int
filterSize,
static av_always_inline void
yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
+ const uint8_t *dither, int offset,
int big_endian, int output_bits)
{
int i;
@@ -193,6 +196,7 @@ yuv2plane1_10_c_template(const int16_t *src, uint16_t
*dest, int dstW,
static av_always_inline void
yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
const int16_t **src, uint16_t *dest, int dstW,
+ const uint8_t *dither, int offset,
int big_endian, int output_bits)
{
int i;
@@ -211,13 +215,13 @@ yuv2planeX_10_c_template(const int16_t *filter, int
filterSize,
#undef output_pixel
-#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
+#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t, otypeX_t) \
static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
uint8_t *dest, int dstW, \
const uint8_t *dither, int offset)\
{ \
yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
- (uint16_t *) dest, dstW, is_be, bits); \
+ (otypeX_t *) dest, dstW, dither, offset, is_be,
bits); \
}\
static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int
filterSize, \
const int16_t **src, uint8_t *dest, int dstW, \
@@ -225,14 +229,15 @@ static void yuv2planeX_ ## bits ## BE_LE ## _c(const
int16_t *filter, int filter
{ \
yuv2planeX_## template_size ## _c_template(filter, \
filterSize, (const typeX_t **) src, \
- (uint16_t *) dest, dstW, is_be, bits); \
+ (otypeX_t *) dest, dstW, dither, offset, \
+ is_be, bits); \
}
-yuv2NBPS( 9, BE, 1, 10, int16_t)
-yuv2NBPS( 9, LE, 0, 10, int16_t)
-yuv2NBPS(10, BE, 1, 10, int16_t)
-yuv2NBPS(10, LE, 0, 10, int16_t)
-yuv2NBPS(16, BE, 1, 16, int32_t)
-yuv2NBPS(16, LE, 0, 16, int32_t)
+yuv2NBPS( 9, BE, 1, 10, int16_t, uint16_t)
+yuv2NBPS( 9, LE, 0, 10, int16_t, uint16_t)
+yuv2NBPS(10, BE, 1, 10, int16_t, uint16_t)
+yuv2NBPS(10, LE, 0, 10, int16_t, uint16_t)
+yuv2NBPS(16, BE, 1, 16, int32_t, uint16_t)
+yuv2NBPS(16, LE, 0, 16, int32_t, uint16_t)
static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
const int16_t **src, uint8_t *dest, int dstW,
@@ -299,21 +304,18 @@ static void yuv2nv12cX_c(SwsContext *c, const int16_t
*chrFilter, int chrFilterS
acc <<= 1; \
acc |= (val) >= (128 + 110)
#define output_pixel(pos, acc) \
- if (target == PIX_FMT_MONOBLACK) { \
+ if (is_black) { \
pos = acc; \
} else { \
pos = ~acc; \
}
static av_always_inline void
-yuv2mono_X_c_template(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, int dstW,
- int y, enum PixelFormat target)
+yuv2planeX_1_c_template(const int16_t *lumFilter, int lumFilterSize,
+ const int16_t **lumSrc, uint8_t *dest, int dstW,
+ const uint8_t *d128, int offset,
+ int is_black, int output_bits)
{
- const uint8_t * const d128=dither_8x8_220[y&7];
int i;
unsigned acc = 0;
@@ -341,48 +343,10 @@ yuv2mono_X_c_template(SwsContext *c, const int16_t
*lumFilter,
}
static av_always_inline void
-yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
- const int16_t *ubuf[2], const int16_t *vbuf[2],
- const int16_t *abuf[2], uint8_t *dest, int dstW,
- int yalpha, int uvalpha, int y,
- enum PixelFormat target)
+yuv2plane1_1_c_template(const int16_t *buf0, uint8_t *dest, int dstW,
+ const uint8_t *d128, int offset,
+ int is_black, int output_bits)
{
- const int16_t *buf0 = buf[0], *buf1 = buf[1];
- const uint8_t * const d128 = dither_8x8_220[y & 7];
- int yalpha1 = 4095 - yalpha;
- int i;
-
- for (i = 0; i < dstW - 7; i += 8) {
- int Y, acc = 0;
-
- Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
- accumulate_bit(acc, Y + d128[0]);
- Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
- accumulate_bit(acc, Y + d128[1]);
- Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
- accumulate_bit(acc, Y + d128[2]);
- Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
- accumulate_bit(acc, Y + d128[3]);
- Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
- accumulate_bit(acc, Y + d128[4]);
- Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
- accumulate_bit(acc, Y + d128[5]);
- Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
- accumulate_bit(acc, Y + d128[6]);
- Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
- accumulate_bit(acc, Y + d128[7]);
-
- output_pixel(*dest++, acc);
- }
-}
-
-static av_always_inline void
-yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
- const int16_t *ubuf[2], const int16_t *vbuf[2],
- const int16_t *abuf0, uint8_t *dest, int dstW,
- int uvalpha, int y, enum PixelFormat target)
-{
- const uint8_t * const d128 = dither_8x8_220[y & 7];
int i;
for (i = 0; i < dstW - 7; i += 8) {
@@ -404,6 +368,9 @@ yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
#undef output_pixel
#undef accumulate_bit
+yuv2NBPS(1, monoblack, 1, 1, int16_t, uint8_t)
+yuv2NBPS(1, monowhite, 0, 1, int16_t, uint8_t)
+
#define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
const int16_t **lumSrc, int lumFilterSize, \
@@ -436,9 +403,6 @@ static void name ## ext ## _1_c(SwsContext *c, const
int16_t *buf0, \
y, fmt); \
}
-YUV2PACKEDWRAPPER(yuv2mono,, white, PIX_FMT_MONOWHITE)
-YUV2PACKEDWRAPPER(yuv2mono,, black, PIX_FMT_MONOBLACK)
-
#define output_pixels(pos, Y1, U, Y2, V) \
if (target == PIX_FMT_YUYV422) { \
dest[pos + 0] = Y1; \
@@ -1235,7 +1199,7 @@ void ff_sws_init_output_funcs(SwsContext *c,
*yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c :
yuv2planeX_10LE_c;
*yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c :
yuv2plane1_10LE_c;
}
- } else {
+ } else if (av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1 == 7) {
*yuv2plane1 = yuv2plane1_8_c;
*yuv2planeX = yuv2planeX_8_c;
if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)
@@ -1427,14 +1391,12 @@ void ff_sws_init_output_funcs(SwsContext *c,
}
switch (dstFormat) {
case PIX_FMT_MONOWHITE:
- *yuv2packed1 = yuv2monowhite_1_c;
- *yuv2packed2 = yuv2monowhite_2_c;
- *yuv2packedX = yuv2monowhite_X_c;
+ *yuv2plane1 = yuv2plane1_1monowhite_c;
+ *yuv2planeX = yuv2planeX_1monowhite_c;
break;
case PIX_FMT_MONOBLACK:
- *yuv2packed1 = yuv2monoblack_1_c;
- *yuv2packed2 = yuv2monoblack_2_c;
- *yuv2packedX = yuv2monoblack_X_c;
+ *yuv2plane1 = yuv2plane1_1monoblack_c;
+ *yuv2planeX = yuv2planeX_1monoblack_c;
break;
case PIX_FMT_YUYV422:
*yuv2packed1 = yuv2yuyv422_1_c;
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index b231302..33f74af 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -34,6 +34,7 @@
#include "libavutil/bswap.h"
#include "libavutil/pixdesc.h"
+extern const uint8_t dither_8x8_220[8][8];
DECLARE_ALIGNED(8, const uint8_t, dither_8x8_128)[8][8] = {
{ 36, 68, 60, 92, 34, 66, 58, 90,},
{ 100, 4,124, 28, 98, 2,122, 26,},
@@ -343,7 +344,8 @@ static int swScale(SwsContext *c, const uint8_t* src[],
yuv2packed1_fn yuv2packed1 = c->yuv2packed1;
yuv2packed2_fn yuv2packed2 = c->yuv2packed2;
yuv2packedX_fn yuv2packedX = c->yuv2packedX;
- int should_dither = is9_OR_10BPS(c->srcFormat) || is16BPS(c->srcFormat);
+ int should_dither = is9_OR_10BPS(c->srcFormat) || is16BPS(c->srcFormat) ||
+ dstFormat == PIX_FMT_MONOBLACK || dstFormat == PIX_FMT_MONOWHITE;
/* vars which will change and which we need to store back in the context */
int dstY= c->dstY;
@@ -496,8 +498,12 @@ static int swScale(SwsContext *c, const uint8_t* src[],
updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex, lastInLumBuf,
lastInChrBuf);
#endif
if (should_dither) {
- c->chrDither8 = dither_8x8_128[chrDstY & 7];
- c->lumDither8 = dither_8x8_128[dstY & 7];
+ if (dstFormat == PIX_FMT_MONOWHITE || dstFormat ==
PIX_FMT_MONOBLACK) {
+ c->lumDither8 = dither_8x8_220[dstY & 7];
+ } else {
+ c->chrDither8 = dither_8x8_128[chrDstY & 7];
+ c->lumDither8 = dither_8x8_128[dstY & 7];
+ }
}
if (dstY >= dstH-2) {
// hmm looks like we can't use MMX here without overwriting this
array's tail
@@ -553,7 +559,8 @@ static int swScale(SwsContext *c, const uint8_t* src[],
chrVSrcPtr = tmpV;
}
- if (isPlanarYUV(dstFormat) || (isGray(dstFormat) &&
!isALPHA(dstFormat))) { //YV12 like
+ if (isPlanarYUV(dstFormat) || (isGray(dstFormat) &&
!isALPHA(dstFormat)) ||
+ dstFormat == PIX_FMT_MONOBLACK || dstFormat ==
PIX_FMT_MONOWHITE) { //YV12 like
const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
if (vLumFilterSize == 1) {
@@ -563,7 +570,8 @@ static int swScale(SwsContext *c, const uint8_t* src[],
lumSrcPtr, dest[0], dstW, c->lumDither8, 0);
}
- if (!((dstY&chrSkipMask) || isGray(dstFormat))) {
+ if (!((dstY&chrSkipMask) || isGray(dstFormat) ||
+ dstFormat == PIX_FMT_MONOBLACK || dstFormat ==
PIX_FMT_MONOWHITE)) {
if (yuv2nv12cX) {
yuv2nv12cX(c, vChrFilter + chrDstY * vChrFilterSize,
vChrFilterSize, chrUSrcPtr, chrVSrcPtr, dest[1], chrDstW);
} else if (vChrFilterSize == 1) {
diff --git a/libswscale/x86/swscale_mmx.c b/libswscale/x86/swscale_mmx.c
index c112cb8..9cb7745 100644
--- a/libswscale/x86/swscale_mmx.c
+++ b/libswscale/x86/swscale_mmx.c
@@ -278,18 +278,18 @@ void ff_sws_init_swScale_mmx(SwsContext *c)
default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
}
#define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case) \
-switch(c->dstBpc){ \
+switch(av_pix_fmt_descriptors[c->dstFormat].comp[0].depth_minus1 + 1){ \
case 16: do_16_case;
break; \
case 10: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt;
break; \
case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt;
break; \
- default: vscalefn = ff_yuv2planeX_8_ ## opt;
break; \
+ case 8: vscalefn = ff_yuv2planeX_8_ ## opt;
break; \
}
#define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
- switch(c->dstBpc){ \
+ switch(av_pix_fmt_descriptors[c->dstFormat].comp[0].depth_minus1 + 1){ \
case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_
## opt1; break; \
case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_
## opt2; break; \
case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_
## opt2; break; \
- default: vscalefn = ff_yuv2plane1_8_
## opt1; break; \
+ case 8: vscalefn = ff_yuv2plane1_8_
## opt1; break; \
}
#define case_rgb(x, X, opt) \
case PIX_FMT_ ## X: \
--
1.7.2.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel