1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

swscale/alphablend: Fix slice handling

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2021-09-30 19:00:56 +02:00
parent 9fbe54e4b2
commit 06d6726588

View File

@ -26,7 +26,7 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
int nb_components = desc->nb_components;
int plane, x, y;
int plane, x, ysrc;
int plane_count = isGray(c->srcFormat) ? 1 : 3;
int sixteen_bits = desc->comp[0].depth >= 9;
unsigned off = 1<<(desc->comp[0].depth - 1);
@ -50,14 +50,15 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
int w = plane ? c->chrSrcW : c->srcW;
int x_subsample = plane ? desc->log2_chroma_w: 0;
int y_subsample = plane ? desc->log2_chroma_h: 0;
for (y = srcSliceY >> y_subsample; y < AV_CEIL_RSHIFT(srcSliceH, y_subsample); y++) {
for (ysrc = 0; ysrc < AV_CEIL_RSHIFT(srcSliceH, y_subsample); ysrc++) {
int y = ysrc + (srcSliceY >> y_subsample);
if (x_subsample || y_subsample) {
int alpha;
unsigned u;
if (sixteen_bits) {
ptrdiff_t alpha_step = srcStride[plane_count] >> 1;
const uint16_t *s = (const uint16_t *)(src[plane ] + srcStride[plane ] * y);
const uint16_t *a = (const uint16_t *)(src[plane_count] + (srcStride[plane_count] * y << y_subsample));
const uint16_t *s = (const uint16_t *)(src[plane ] + srcStride[plane ] * ysrc);
const uint16_t *a = (const uint16_t *)(src[plane_count] + (srcStride[plane_count] * ysrc << y_subsample));
uint16_t *d = ( uint16_t *)(dst[plane ] + dstStride[plane ] * y);
if ((!isBE(c->srcFormat)) == !HAVE_BIGENDIAN) {
for (x = 0; x < w; x++) {
@ -82,8 +83,8 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
}
} else {
ptrdiff_t alpha_step = srcStride[plane_count];
const uint8_t *s = src[plane ] + srcStride[plane] * y;
const uint8_t *a = src[plane_count] + (srcStride[plane_count] * y << y_subsample);
const uint8_t *s = src[plane ] + srcStride[plane] * ysrc;
const uint8_t *a = src[plane_count] + (srcStride[plane_count] * ysrc << y_subsample);
uint8_t *d = dst[plane ] + dstStride[plane] * y;
for (x = 0; x < w; x++) {
if (y_subsample) {
@ -97,8 +98,8 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
}
} else {
if (sixteen_bits) {
const uint16_t *s = (const uint16_t *)(src[plane ] + srcStride[plane ] * y);
const uint16_t *a = (const uint16_t *)(src[plane_count] + srcStride[plane_count] * y);
const uint16_t *s = (const uint16_t *)(src[plane ] + srcStride[plane ] * ysrc);
const uint16_t *a = (const uint16_t *)(src[plane_count] + srcStride[plane_count] * ysrc);
uint16_t *d = ( uint16_t *)(dst[plane ] + dstStride[plane ] * y);
if ((!isBE(c->srcFormat)) == !HAVE_BIGENDIAN) {
for (x = 0; x < w; x++) {
@ -113,8 +114,8 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
}
}
} else {
const uint8_t *s = src[plane ] + srcStride[plane] * y;
const uint8_t *a = src[plane_count] + srcStride[plane_count] * y;
const uint8_t *s = src[plane ] + srcStride[plane] * ysrc;
const uint8_t *a = src[plane_count] + srcStride[plane_count] * ysrc;
uint8_t *d = dst[plane ] + dstStride[plane] * y;
for (x = 0; x < w; x++) {
unsigned u = s[x]*a[x] + target_table[((x^y)>>5)&1][plane]*(255-a[x]) + 128;
@ -127,10 +128,11 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
} else {
int alpha_pos = desc->comp[plane_count].offset;
int w = c->srcW;
for (y = srcSliceY; y < srcSliceH; y++) {
for (ysrc = 0; ysrc < srcSliceH; ysrc++) {
int y = ysrc + srcSliceY;
if (sixteen_bits) {
const uint16_t *s = (const uint16_t *)(src[0] + srcStride[0] * y + 2*!alpha_pos);
const uint16_t *a = (const uint16_t *)(src[0] + srcStride[0] * y + alpha_pos);
const uint16_t *s = (const uint16_t *)(src[0] + srcStride[0] * ysrc + 2*!alpha_pos);
const uint16_t *a = (const uint16_t *)(src[0] + srcStride[0] * ysrc + alpha_pos);
uint16_t *d = ( uint16_t *)(dst[0] + dstStride[0] * y);
if ((!isBE(c->srcFormat)) == !HAVE_BIGENDIAN) {
for (x = 0; x < w; x++) {
@ -151,8 +153,8 @@ int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
}
}
} else {
const uint8_t *s = src[0] + srcStride[0] * y + !alpha_pos;
const uint8_t *a = src[0] + srcStride[0] * y + alpha_pos;
const uint8_t *s = src[0] + srcStride[0] * ysrc + !alpha_pos;
const uint8_t *a = src[0] + srcStride[0] * ysrc + alpha_pos;
uint8_t *d = dst[0] + dstStride[0] * y;
for (x = 0; x < w; x++) {
for (plane = 0; plane < plane_count; plane++) {