X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/rigol/blobdiff_plain/e8e713c3a536c59f94d6402d852f353e34fac2de..HEAD:/png.c?ds=sidebyside diff --git a/png.c b/png.c index 7606f2b..ac09767 100644 --- a/png.c +++ b/png.c @@ -68,7 +68,7 @@ unsigned char *lcd2png(unsigned char *lcd, int *len) unsigned char lut[256][3]; unsigned char *screen_deflated; int deflated_size; - unsigned char *image; + unsigned char *image = NULL; unsigned char *outpos; static const unsigned char png[] = {137, 80, 78, 71, 13, 10, 26, 10}; static unsigned char idat[] = {'I', 'D', 'A', 'T'}; @@ -117,6 +117,7 @@ unsigned char *lcd2png(unsigned char *lcd, int *len) strm.next_in = screen_conv; toalloc = 0; + strm.avail_out = 0; screen_deflated = NULL; flush = Z_NO_FLUSH; @@ -147,7 +148,6 @@ unsigned char *lcd2png(unsigned char *lcd, int *len) deflateEnd(&strm); - image = malloc(sizeof(png) + sizeof(ihdr) + 8 + /* 8 = length, csum */ sizeof(idat) + deflated_size + 8 + @@ -155,12 +155,16 @@ unsigned char *lcd2png(unsigned char *lcd, int *len) if (image == NULL) { perror("malloc"); + return NULL; } outpos = image; + + /* PNG signature */ memcpy(outpos, png, sizeof(png)); outpos += sizeof(png); + /* IHDR */ l = htonl(sizeof(ihdr) - 4); /* "IHDR" is not counted */ memcpy(outpos, &l, sizeof(l)); outpos += sizeof(l); @@ -170,6 +174,7 @@ unsigned char *lcd2png(unsigned char *lcd, int *len) memcpy(outpos, &l, sizeof(l)); outpos += sizeof(l); + /* IDAT */ l = htonl(deflated_size); memcpy(outpos, &l, sizeof(l)); outpos += sizeof(l); @@ -182,6 +187,7 @@ unsigned char *lcd2png(unsigned char *lcd, int *len) memcpy(outpos, &l, sizeof(l)); outpos += sizeof(l); + /* IEND */ l = htonl(sizeof(iend) - 4); /* "IEND" is not counted */ memcpy(outpos, &l, sizeof(l)); outpos += sizeof(l);