mirror of https://github.com/mpv-player/mpv
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:
parent
4deae5e4b5
commit
640db1ed3f
10
video/zimg.c
10
video/zimg.c
|
@ -561,10 +561,6 @@ static int bitmap_repack(void *user, unsigned i, unsigned x0, unsigned x1)
|
||||||
{
|
{
|
||||||
struct mp_zimg_repack *r = user;
|
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 =
|
uint8_t *p1 =
|
||||||
r->mpi->planes[0] + r->mpi->stride[0] * (ptrdiff_t)(i - r->mpi_y0);
|
r->mpi->planes[0] + r->mpi->stride[0] * (ptrdiff_t)(i - r->mpi_y0);
|
||||||
uint8_t *p2 =
|
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;
|
uint8_t swap = r->comp_size ? 0xFF : 0;
|
||||||
if (r->pack) {
|
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) {
|
for (int x = x0; x < x1; x += 8) {
|
||||||
uint8_t d = 0;
|
uint8_t d = 0;
|
||||||
int max_b = MPMIN(8, x1 - x);
|
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;
|
p1[x / 8] = d ^ swap;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
x0 &= ~0x7;
|
||||||
|
|
||||||
for (int x = x0; x < x1; x += 8) {
|
for (int x = x0; x < x1; x += 8) {
|
||||||
uint8_t d = p1[x / 8] ^ swap;
|
uint8_t d = p1[x / 8] ^ swap;
|
||||||
int max_b = MPMIN(8, x1 - x);
|
int max_b = MPMIN(8, x1 - x);
|
||||||
|
|
Loading…
Reference in New Issue