uint8_t *dst[], int dstStride[])
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
+ const int lum_w = c->srcW;
+ const int lum_h = c->srcH;
int nb_components = desc->nb_components;
int plane, x, ysrc;
int plane_count = isGray(c->srcFormat) ? 1 : 3;
int y_subsample = plane ? desc->log2_chroma_h: 0;
for (ysrc = 0; ysrc < AV_CEIL_RSHIFT(srcSliceH, y_subsample); ysrc++) {
int y = ysrc + (srcSliceY >> y_subsample);
- if (x_subsample || y_subsample) {
+ int subsample_row = y_subsample && (y << y_subsample) + 1 < lum_h;
+ if (x_subsample || subsample_row) {
int alpha;
unsigned u;
if (sixteen_bits) {
uint16_t *d = ( uint16_t *)(dst[plane ] + dstStride[plane ] * y);
if ((!isBE(c->srcFormat)) == !HAVE_BIGENDIAN) {
for (x = 0; x < w; x++) {
- if (y_subsample) {
- alpha = (a[2*x] + a[2*x + 1] + 2 +
- a[2*x + alpha_step] + a[2*x + alpha_step + 1]) >> 2;
+ const int xnext = FFMIN(2*x + 1, lum_w - 1);
+ if (subsample_row) {
+ alpha = (a[2*x] + a[xnext] + 2 +
+ a[2*x + alpha_step] + a[xnext + alpha_step]) >> 2;
} else
- alpha = (a[2*x] + a[2*x + 1]) >> 1;
+ alpha = (a[2*x] + a[xnext]) >> 1;
u = s[x]*alpha + target_table[((x^y)>>5)&1][plane]*(max-alpha) + off;
d[x] = av_clip((u + (u >> shift)) >> shift, 0, max);
}
} else {
for (x = 0; x < w; x++) {
- if (y_subsample) {
- alpha = (av_bswap16(a[2*x]) + av_bswap16(a[2*x + 1]) + 2 +
- av_bswap16(a[2*x + alpha_step]) + av_bswap16(a[2*x + alpha_step + 1])) >> 2;
+ const int xnext = FFMIN(2*x + 1, lum_w - 1);
+ if (subsample_row) {
+ alpha = (av_bswap16(a[2*x]) + av_bswap16(a[xnext]) + 2 +
+ av_bswap16(a[2*x + alpha_step]) + av_bswap16(a[xnext + alpha_step])) >> 2;
} else
- alpha = (av_bswap16(a[2*x]) + av_bswap16(a[2*x + 1])) >> 1;
+ alpha = (av_bswap16(a[2*x]) + av_bswap16(a[xnext])) >> 1;
u = av_bswap16(s[x])*alpha + target_table[((x^y)>>5)&1][plane]*(max-alpha) + off;
d[x] = av_clip((u + (u >> shift)) >> shift, 0, max);
}
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) {
- alpha = (a[2*x] + a[2*x + 1] + 2 +
- a[2*x + alpha_step] + a[2*x + alpha_step + 1]) >> 2;
+ const int xnext = FFMIN(2*x + 1, lum_w - 1);
+ if (subsample_row) {
+ alpha = (a[2*x] + a[xnext] + 2 +
+ a[2*x + alpha_step] + a[xnext + alpha_step]) >> 2;
} else
- alpha = (a[2*x] + a[2*x + 1]) >> 1;
+ alpha = (a[2*x] + a[xnext]) >> 1;
u = s[x]*alpha + target_table[((x^y)>>5)&1][plane]*(255-alpha) + 128;
d[x] = (257*u) >> 16;
}