mirror of
https://github.com/mpv-player/mpv
synced 2024-12-27 09:32:40 +00:00
video/mp_image: handle non-power-of-two alignment
Needed for odd formats like rgb24.
This commit is contained in:
parent
d67b0022aa
commit
50cd363c01
@ -39,6 +39,7 @@
|
||||
#define MPSWAP(type, a, b) \
|
||||
do { type SWAP_tmp = b; b = a; a = SWAP_tmp; } while (0)
|
||||
#define MP_ARRAY_SIZE(s) (sizeof(s) / sizeof((s)[0]))
|
||||
#define MP_DIV_UP(x, y) (((x) + (y) - 1) / (y))
|
||||
|
||||
// align must be a power of two (align >= 1), x >= 0
|
||||
#define MP_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1))
|
||||
@ -46,6 +47,9 @@
|
||||
#define MP_IS_ALIGNED(x, align) (!((x) & ((align) - 1)))
|
||||
#define MP_IS_POWER_OF_2(x) ((x) > 0 && !((x) & ((x) - 1)))
|
||||
|
||||
// align to non power of two
|
||||
#define MP_ALIGN_NPOT(x, align) ((align) ? MP_DIV_UP(x, align) * (align) : (x))
|
||||
|
||||
// Return "a", or if that is NOPTS, return "def".
|
||||
#define MP_PTS_OR_DEF(a, def) ((a) == MP_NOPTS_VALUE ? (def) : (a))
|
||||
// If one of the values is NOPTS, always pick the other one.
|
||||
|
@ -69,7 +69,7 @@ static int mp_image_layout(int imgfmt, int w, int h, int stride_align,
|
||||
int alloc_w = mp_chroma_div_up(w, desc.xs[n]);
|
||||
int alloc_h = MP_ALIGN_UP(h, 32) >> desc.ys[n];
|
||||
int line_bytes = (alloc_w * desc.bpp[n] + 7) / 8;
|
||||
out_stride[n] = MP_ALIGN_UP(line_bytes, stride_align);
|
||||
out_stride[n] = MP_ALIGN_NPOT(line_bytes, stride_align);
|
||||
out_plane_size[n] = out_stride[n] * alloc_h;
|
||||
}
|
||||
if (desc.flags & MP_IMGFLAG_PAL)
|
||||
|
Loading…
Reference in New Issue
Block a user