summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2015-08-09 17:11:53 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2015-08-09 17:11:53 +0200
commitc5ebeaa3085bef608a1ec76e8e6b24e6e98c428a (patch)
treee7bd92e8fba564b35a75e0cbe2842cfad82afad2
parent87100e828a59fa04dc892b45d8db2d690ce6a2a1 (diff)
downloadffmpeg-streaming-c5ebeaa3085bef608a1ec76e8e6b24e6e98c428a.zip
ffmpeg-streaming-c5ebeaa3085bef608a1ec76e8e6b24e6e98c428a.tar.gz
swscale/alphablend: Support SWS_ALPHA_BLEND_CHECKERBOARD
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--doc/scaler.texi3
-rw-r--r--libswscale/alphablend.c27
-rw-r--r--libswscale/options.c1
-rw-r--r--libswscale/swscale_internal.h1
4 files changed, 21 insertions, 11 deletions
diff --git a/doc/scaler.texi b/doc/scaler.texi
index 457347c..060a45c 100644
--- a/doc/scaler.texi
+++ b/doc/scaler.texi
@@ -130,6 +130,9 @@ Default value is @samp{none}.
@item uniform_color
Blend onto a uniform background color
+@item checkerboard
+Blend onto a checkerboard
+
@item none
No blending
diff --git a/libswscale/alphablend.c b/libswscale/alphablend.c
index 7c9fe6f..3bd71ba 100644
--- a/libswscale/alphablend.c
+++ b/libswscale/alphablend.c
@@ -32,10 +32,17 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
unsigned off = 1<<desc->comp[0].depth_minus1;
unsigned shift = desc->comp[0].depth_minus1 + 1;
unsigned max = (1<<shift) - 1;
- int target_table[3];
+ int target_table[2][3];
- for (plane = 0; plane < plane_count; plane++)
- target_table[plane] = plane && !(desc->flags & AV_PIX_FMT_FLAG_RGB) ? 1<<desc->comp[0].depth_minus1 : 0;
+ for (plane = 0; plane < plane_count; plane++) {
+ int a = 0, b = 0;
+ if (c->alphablend == SWS_ALPHA_BLEND_CHECKERBOARD) {
+ a = (1<<desc->comp[0].depth_minus1)/2;
+ b = 3*(1<<desc->comp[0].depth_minus1)/2;
+ }
+ target_table[0][plane] = plane && !(desc->flags & AV_PIX_FMT_FLAG_RGB) ? 1<<desc->comp[0].depth_minus1 : a;
+ target_table[1][plane] = plane && !(desc->flags & AV_PIX_FMT_FLAG_RGB) ? 1<<desc->comp[0].depth_minus1 : b;
+ }
av_assert0(plane_count == nb_components - 1);
if (desc->flags & AV_PIX_FMT_FLAG_PLANAR) {
@@ -47,16 +54,15 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
const uint16_t *s = src[plane ] + srcStride[plane] * y;
const uint16_t *a = src[plane_count] + srcStride[plane_count] * y;
uint16_t *d = dst[plane ] + dstStride[plane] * y;
- unsigned target = target_table[plane];
if ((!isBE(c->srcFormat)) == !HAVE_BIGENDIAN) {
for (x = 0; x < w; x++) {
- unsigned u = s[x]*a[x] + target*(max-a[x]) + off;
+ unsigned u = s[x]*a[x] + target_table[((x^y)>>5)&1][plane]*(max-a[x]) + off;
d[x] = av_clip((u + (u >> shift)) >> shift, 0, max);
}
} else {
for (x = 0; x < w; x++) {
unsigned aswap =av_bswap16(a[x]);
- unsigned u = av_bswap16(s[x])*aswap + target*(max-aswap) + off;
+ unsigned u = av_bswap16(s[x])*aswap + target_table[((x^y)>>5)&1][plane]*(max-aswap) + off;
d[x] = av_clip((u + (u >> shift)) >> shift, 0, max);
}
}
@@ -64,9 +70,8 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
const uint8_t *s = src[plane ] + srcStride[plane] * y;
const uint8_t *a = src[plane_count] + srcStride[plane_count] * y;
uint8_t *d = dst[plane ] + dstStride[plane] * y;
- unsigned target = target_table[plane];
for (x = 0; x < w; x++) {
- unsigned u = s[x]*a[x] + target*(255-a[x]) + 128;
+ unsigned u = s[x]*a[x] + target_table[((x^y)>>5)&1][plane]*(255-a[x]) + 128;
d[x] = (257*u) >> 16;
}
}
@@ -84,7 +89,7 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
for (x = 0; x < w; x++) {
for (plane = 0; plane < plane_count; plane++) {
int x_index = (plane_count + 1) * x;
- unsigned u = s[x_index + plane]*a[x_index] + target_table[plane]*(max-a[x_index]) + off;
+ unsigned u = s[x_index + plane]*a[x_index] + target_table[((x^y)>>5)&1][plane]*(max-a[x_index]) + off;
d[plane_count*x + plane] = av_clip((u + (u >> shift)) >> shift, 0, max);
}
}
@@ -93,7 +98,7 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
for (plane = 0; plane < plane_count; plane++) {
int x_index = (plane_count + 1) * x;
unsigned aswap =av_bswap16(a[x_index]);
- unsigned u = av_bswap16(s[x_index + plane])*aswap + target_table[plane]*(max-aswap) + off;
+ unsigned u = av_bswap16(s[x_index + plane])*aswap + target_table[((x^y)>>5)&1][plane]*(max-aswap) + off;
d[plane_count*x + plane] = av_clip((u + (u >> shift)) >> shift, 0, max);
}
}
@@ -105,7 +110,7 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
for (x = 0; x < w; x++) {
for (plane = 0; plane < plane_count; plane++) {
int x_index = (plane_count + 1) * x;
- unsigned u = s[x_index + plane]*a[x_index] + target_table[plane]*(255-a[x_index]) + 128;
+ unsigned u = s[x_index + plane]*a[x_index] + target_table[((x^y)>>5)&1][plane]*(255-a[x_index]) + 128;
d[plane_count*x + plane] = (257*u) >> 16;
}
}
diff --git a/libswscale/options.c b/libswscale/options.c
index 6ad6cbd..18a6594 100644
--- a/libswscale/options.c
+++ b/libswscale/options.c
@@ -81,6 +81,7 @@ static const AVOption swscale_options[] = {
{ "alphablend", "mode for alpha -> non alpha", OFFSET(alphablend),AV_OPT_TYPE_INT, { .i64 = SWS_ALPHA_BLEND_NONE}, 0, SWS_ALPHA_BLEND_NB-1, VE, "alphablend" },
{ "none", "ignore alpha", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_NONE}, INT_MIN, INT_MAX, VE, "alphablend" },
{ "uniform_color", "blend onto a uniform color", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_UNIFORM},INT_MIN, INT_MAX, VE, "alphablend" },
+ { "checkerboard", "blend onto a checkerboard", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_CHECKERBOARD},INT_MIN, INT_MAX, VE, "alphablend" },
{ NULL }
};
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index 01c5ad9..852dd94 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -78,6 +78,7 @@ typedef enum SwsDither {
typedef enum SwsAlphaBlend {
SWS_ALPHA_BLEND_NONE = 0,
SWS_ALPHA_BLEND_UNIFORM,
+ SWS_ALPHA_BLEND_CHECKERBOARD,
SWS_ALPHA_BLEND_NB,
} SwsAlphaBlend;
OpenPOWER on IntegriCloud