mirror of https://git.ffmpeg.org/ffmpeg.git
swscale/alphablend: Support SWS_ALPHA_BLEND_CHECKERBOARD
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
87100e828a
commit
c5ebeaa308
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 }
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue