zimg: don't assume zimg reads are 64 byte aligned

Only _writes_ are aligned, so the assumption doesn't work for reads. But
it's easy to fix by rounding down x0 to the next byte boundary. Writing
pixels outside of the read area is allowed, and we don't go out of
buffer bounds.

Patch by anon32, permission to do anything with it.
This commit is contained in:
wm4 2020-04-25 17:38:16 +02:00
parent 4deae5e4b5
commit 640db1ed3f
1 changed files with 6 additions and 4 deletions

View File

@ -561,10 +561,6 @@ static int bitmap_repack(void *user, unsigned i, unsigned x0, unsigned x1)
{
struct mp_zimg_repack *r = user;
// Supposedly zimg aligns this at least on 64 byte boundaries. Simplifies a
// lot for us.
assert(!(x0 & 7));
uint8_t *p1 =
r->mpi->planes[0] + r->mpi->stride[0] * (ptrdiff_t)(i - r->mpi_y0);
uint8_t *p2 =
@ -572,6 +568,10 @@ static int bitmap_repack(void *user, unsigned i, unsigned x0, unsigned x1)
uint8_t swap = r->comp_size ? 0xFF : 0;
if (r->pack) {
// Supposedly zimg aligns this at least on 64 byte boundaries. Simplifies a
// lot for us.
assert(!(x0 & 7));
for (int x = x0; x < x1; x += 8) {
uint8_t d = 0;
int max_b = MPMIN(8, x1 - x);
@ -580,6 +580,8 @@ static int bitmap_repack(void *user, unsigned i, unsigned x0, unsigned x1)
p1[x / 8] = d ^ swap;
}
} else {
x0 &= ~0x7;
for (int x = x0; x < x1; x += 8) {
uint8_t d = p1[x / 8] ^ swap;
int max_b = MPMIN(8, x1 - x);