From 7b203b5e05d9873e279f8432d4ffb3d9facc5e23 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 7 Oct 2012 01:21:29 +0200 Subject: img_convert: fix alignment for RGBA images draw_bmp.c uses libswscale, which has strict alignment requirements on input images. Since imp_convert.c is currently the only producer of RGBA sub-bitmaps, the overall code becomes easier if the alignment is done on image allocation, rather than forcing draw_bmp.c to create an aligned copy. talloc doesn't align to 16 bytes, as required by libswscale. Apparently, system malloc (glibc/Linux/32 bit) aligns to 8 bytes only, so talloc's own code to align to 16 bytes is ineffective. Work around by using mp_image to allocate the image. --- sub/img_convert.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'sub/img_convert.c') diff --git a/sub/img_convert.c b/sub/img_convert.c index 888380cf70..9437226c64 100644 --- a/sub/img_convert.c +++ b/sub/img_convert.c @@ -26,6 +26,9 @@ #include "img_convert.h" #include "sub.h" #include "spudec.h" +#include "libmpcodecs/img_format.h" +#include "libmpcodecs/mp_image.h" +#include "libmpcodecs/sws_utils.h" struct osd_conv_cache { struct sub_bitmap part; @@ -199,12 +202,14 @@ bool osd_conv_idx_to_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs) rgba_to_premultiplied_rgba(sb.palette, 256); *d = *s; - d->stride = s->w * 4; - d->bitmap = talloc_size(c->parts, s->h * d->stride); + struct mp_image *image = alloc_mpi(s->w, s->h, IMGFMT_BGRA); + talloc_steal(c->parts, image); + d->stride = image->stride[0]; + d->bitmap = image->planes[0]; - uint32_t *outbmp = d->bitmap; for (int y = 0; y < s->h; y++) { uint8_t *inbmp = sb.bitmap + y * s->stride; + uint32_t *outbmp = (uint32_t*)((uint8_t*)d->bitmap + y * d->stride); for (int x = 0; x < s->w; x++) *outbmp++ = sb.palette[*inbmp++]; } -- cgit v1.2.3