mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
d5e4763243
commit
7b203b5e05
|
@ -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++];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue