mp_image: do not assume trailing stride padding exists

Normally, the size of an mage plane is assumed to be stride*height. But
in theory, if stride is larger than width*bpp, the last line might not
be padded, simply because it's not necessary. FFmpeg's or mpv's image
allocators always guarantee that this padding exists (it wastes some
insignificant memory for avoiding such subtle issues), but some other
libraries might not.

I suspect one such case might be Xv via vo_xv (see #1698), although my X
server appears to provide full padding. In any case, it can't harm.
This commit is contained in:
wm4 2015-03-20 00:34:15 +01:00
parent 5f2a8474ae
commit 6b53897d75
1 changed files with 4 additions and 4 deletions

View File

@ -726,14 +726,14 @@ struct AVFrame *mp_image_to_av_frame_and_unref(struct mp_image *img)
void memcpy_pic(void *dst, const void *src, int bytesPerLine, int height,
int dstStride, int srcStride)
{
if (bytesPerLine == dstStride && dstStride == srcStride) {
if (bytesPerLine == dstStride && dstStride == srcStride && height) {
if (srcStride < 0) {
src = (uint8_t*)src + (height - 1) * srcStride;
dst = (uint8_t*)dst + (height - 1) * dstStride;
srcStride = -srcStride;
}
memcpy(dst, src, srcStride * height);
memcpy(dst, src, srcStride * (height - 1) + bytesPerLine);
} else {
for (int i = 0; i < height; i++) {
memcpy(dst, src, bytesPerLine);
@ -745,8 +745,8 @@ void memcpy_pic(void *dst, const void *src, int bytesPerLine, int height,
void memset_pic(void *dst, int fill, int bytesPerLine, int height, int stride)
{
if (bytesPerLine == stride) {
memset(dst, fill, stride * height);
if (bytesPerLine == stride && height) {
memset(dst, fill, stride * (height - 1) + bytesPerLine);
} else {
for (int i = 0; i < height; i++) {
memset(dst, fill, bytesPerLine);