sd_lavc: align sub-bitmaps for the sake of libswscale

Since there are not many sub-rectangles, this doesn't cost too much. On
the other hand, it avoids frequent warnings with vo_xv.

Also, the second copy in mp_blur_rgba_sub_bitmap() can be dropped.
This commit is contained in:
wm4 2016-06-18 12:08:17 +02:00
parent 689cf04571
commit 9215a9e598
2 changed files with 11 additions and 7 deletions

View File

@ -44,8 +44,7 @@ struct osd_conv_cache *osd_conv_cache_new(void)
void mp_blur_rgba_sub_bitmap(struct sub_bitmap *d, double gblur)
{
struct mp_image *tmp1 = mp_image_alloc(IMGFMT_BGRA, d->w, d->h);
struct mp_image *tmp2 = mp_image_alloc(IMGFMT_BGRA, d->w, d->h);
if (tmp1 && tmp2) { // on OOM, skip region
if (tmp1) { // on OOM, skip region
struct mp_image s = {0};
mp_image_setfmt(&s, IMGFMT_BGRA);
mp_image_set_size(&s, d->w, d->h);
@ -54,12 +53,9 @@ void mp_blur_rgba_sub_bitmap(struct sub_bitmap *d, double gblur)
mp_image_copy(tmp1, &s);
mp_image_sw_blur_scale(tmp2, tmp1, gblur);
mp_image_copy(&s, tmp2);
mp_image_sw_blur_scale(&s, tmp1, gblur);
}
talloc_free(tmp1);
talloc_free(tmp2);
}
// If RGBA parts need scaling, scale them.

View File

@ -223,6 +223,10 @@ static void read_sub_bitmaps(struct sd *sd, struct sub *sub)
priv->packer->padding = padding;
// For the sake of libswscale, which in some cases takes sub-rects as
// source images, and wants 16 byte start pointer and stride alignment.
int align = 4;
for (int i = 0; i < avsub->num_rects; i++) {
struct AVSubtitleRect *r = avsub->rects[i];
struct sub_bitmap *b = &sub->inbitmaps[sub->count];
@ -238,7 +242,7 @@ static void read_sub_bitmaps(struct sd *sd, struct sub *sub)
b->bitmap = r; // save for later (dumb hack to avoid more complexity)
priv->packer->in[sub->count] = (struct pos){r->w, r->h};
priv->packer->in[sub->count] = (struct pos){r->w + (align - 1), r->h};
sub->count++;
}
@ -283,6 +287,10 @@ static void read_sub_bitmaps(struct sd *sd, struct sub *sub)
b->h = r->h;
b->x = r->x;
b->y = r->y;
// Choose such that the extended start position is aligned.
pos.x = MP_ALIGN_UP(pos.x - extend, align * 4) + extend;
b->src_x = pos.x;
b->src_y = pos.y;
b->stride = sub->data->stride[0];