From b8dcbf2f3539626aeaf2317e892d7c6c7bd5a145 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Tue, 26 Apr 2011 06:37:30 -0700 Subject: [PATCH] fix alpha-plane copy and crop methods the alpha-plane was not reallocated properly. Change-Id: I5db445c7086b3c7c5cf98631d714350119dd7c2a --- src/enc/picture.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/enc/picture.c b/src/enc/picture.c index 03109eee..c1aba764 100644 --- a/src/enc/picture.c +++ b/src/enc/picture.c @@ -81,9 +81,14 @@ int WebPPictureCopy(const WebPPicture* const src, WebPPicture* const dst) { if (src == dst) return 1; *dst = *src; dst->y = NULL; + dst->a = NULL; if (!WebPPictureAlloc(dst)) return 0; + if (src->a != NULL && !WebPPictureAddAlphaPlane(dst)) return 0; for (y = 0; y < dst->height; ++y) { memcpy(dst->y + y * dst->y_stride, src->y + y * src->y_stride, src->width); + if (dst->a != NULL) { + memcpy(dst->a + y * dst->width, src->a + y * src->width, src->width); + } } for (y = 0; y < (dst->height + 1) / 2; ++y) { memcpy(dst->u + y * dst->uv_stride, @@ -106,13 +111,19 @@ int WebPPictureCrop(WebPPicture* const pic, tmp = *pic; tmp.y = NULL; + tmp.a = NULL; tmp.width = width; tmp.height = height; if (!WebPPictureAlloc(&tmp)) return 0; + if (pic->a != NULL && !WebPPictureAddAlphaPlane(&tmp)) return 0; for (y = 0; y < height; ++y) { memcpy(tmp.y + y * tmp.y_stride, pic->y + (top + y) * pic->y_stride + left, width); + if (tmp.a) { + memcpy(tmp.a + y * tmp.width, + pic->a + (top + y) * pic->width + left, width); + } } for (y = 0; y < (height + 1) / 2; ++y) { const int offset = (y + top / 2) * pic->uv_stride + left / 2;