From 5142a0be3ae3e1387f9dd5294755a09d1f263904 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Thu, 7 Jul 2011 16:08:15 -0700 Subject: [PATCH] export alpha channel (if present) when dumping to PGM format Change-Id: Ica1818937fa03b29a749887d28f49fe675c8b1db --- examples/cwebp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/cwebp.c b/examples/cwebp.c index 1d3ae477..9b97dc0a 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -573,7 +573,8 @@ static int DumpPicture(const WebPPicture* const picture, const char* PGM_name) { const int uv_width = (picture->width + 1) / 2; const int uv_height = (picture->height + 1) / 2; const int stride = (picture->width + 1) & ~1; - const int height = picture->height + uv_height; + const int alpha_height = picture->a ? picture->height : 0; + const int height = picture->height + uv_height + alpha_height; FILE* const f = fopen(PGM_name, "wb"); if (!f) return 0; fprintf(f, "P5\n%d %d\n255\n", stride, height); @@ -588,6 +589,11 @@ static int DumpPicture(const WebPPicture* const picture, const char* PGM_name) { if (fwrite(picture->v + y * picture->uv_stride, uv_width, 1, f) != 1) return 0; } + for (y = 0; y < alpha_height; ++y) { + if (fwrite(picture->a + y * picture->a_stride, picture->width, 1, f) != 1) + return 0; + if (picture->width & 1) fputc(0, f); // pad + } fclose(f); return 1; }