diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2015-08-09 17:11:53 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2015-08-09 17:11:53 +0200 |
commit | c5ebeaa3085bef608a1ec76e8e6b24e6e98c428a (patch) | |
tree | e7bd92e8fba564b35a75e0cbe2842cfad82afad2 /libswscale/alphablend.c | |
parent | 87100e828a59fa04dc892b45d8db2d690ce6a2a1 (diff) | |
download | ffmpeg-c5ebeaa3085bef608a1ec76e8e6b24e6e98c428a.tar.gz |
swscale/alphablend: Support SWS_ALPHA_BLEND_CHECKERBOARD
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libswscale/alphablend.c')
-rw-r--r-- | libswscale/alphablend.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/libswscale/alphablend.c b/libswscale/alphablend.c index 7c9fe6f372..3bd71bac96 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; } } |