From 08aec55c59be9ddc638a655266edb5155ec42b73 Mon Sep 17 00:00:00 2001 From: kramm Date: Sun, 23 Nov 2008 13:59:28 +0000 Subject: [PATCH] corrected bpp alignment during saving --- lib/png.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/png.c b/lib/png.c index c548aa2..d71c19b 100644 --- a/lib/png.c +++ b/lib/png.c @@ -1342,8 +1342,15 @@ EXPORT void savePNG(const char*filename, unsigned char*data, int width, int heig long idatsize = 0; { int x,y; - int srcwidth = width * (bpp/8); - int linelen = 1 + ((srcwidth+3)&~3); + int bypp = bpp/8; + int srcwidth = width * bypp; + int linelen = 1 + srcwidth; + if(bypp==2) + linelen = 1 + ((srcwidth+1)&~1); + else if(bypp==3) + linelen = 1 + ((srcwidth+2)/3)*3; + else if(bypp==4) + linelen = 1 + ((srcwidth+3)&~3); unsigned char* line = (unsigned char*)malloc(linelen); unsigned char* bestline = (unsigned char*)malloc(linelen); memset(line, 0, linelen); -- 1.7.10.4