summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-03-20 00:34:15 +0100
committerwm4 <wm4@nowhere>2015-03-20 00:34:15 +0100
commit6b53897d75c3b57d018ca3faa34d732acae86b79 (patch)
tree5dfba4687161e58c3fcb42a8bf1edc1b4ec0d2fa
parent5f2a8474aee2a0353a07a6a74a0312f5e5f5ef23 (diff)
downloadmpv-6b53897d75c3b57d018ca3faa34d732acae86b79.tar.bz2
mpv-6b53897d75c3b57d018ca3faa34d732acae86b79.tar.xz
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.
-rw-r--r--video/mp_image.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/video/mp_image.c b/video/mp_image.c
index 3280fd86aa..fd94f31dea 100644
--- a/video/mp_image.c
+++ b/video/mp_image.c
@@ -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);