summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-10-07 01:21:29 +0200
committerwm4 <wm4@nowhere>2012-10-24 21:56:33 +0200
commit7b203b5e05d9873e279f8432d4ffb3d9facc5e23 (patch)
tree7b5bcbaef714ab7e6feaa7a7505d981c588a2c3e /sub
parentd5e47632430b93a03748007748ee1fc122932712 (diff)
downloadmpv-7b203b5e05d9873e279f8432d4ffb3d9facc5e23.tar.bz2
mpv-7b203b5e05d9873e279f8432d4ffb3d9facc5e23.tar.xz
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.
Diffstat (limited to 'sub')
-rw-r--r--sub/img_convert.c11
1 files changed, 8 insertions, 3 deletions
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++];
}