X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpng.c;h=49c3c3d0d6a50f1bd8be2075d45026a9878d7a70;hb=70c85e8a814e75b29883fc347a65f83af370249b;hp=53da2c4a455b25eadda37e563a2f46d0f0d52667;hpb=fcc4bcb489b321567b6df8a250494d6f899ecdf2;p=swftools.git diff --git a/lib/png.c b/lib/png.c index 53da2c4..49c3c3d 100644 --- a/lib/png.c +++ b/lib/png.c @@ -33,7 +33,7 @@ typedef struct _COL { int png_read_chunk(char (*head)[4], int*destlen, U8**destdata, FILE*fi) { unsigned int len; - unsigned char blen; + unsigned char blen[4]; if(destlen) *destlen=0; if(destdata) *destdata=0; if(!fread(&blen, 4, 1, fi)) { @@ -66,7 +66,7 @@ int png_read_chunk(char (*head)[4], int*destlen, U8**destdata, FILE*fi) unsigned int png_get_dword(FILE*fi) { unsigned int a; - unsigned char b; + unsigned char b[4]; fread(&b,4,1,fi); return b[0]<<24|b[1]<<16|b[2]<<8|b[3]; } @@ -463,6 +463,8 @@ int getPNG(char*sname, int*destwidth, int*destheight, unsigned char**destdata) struct png_header header; int bypp; U8*data2 = 0; + U8 alphacolor[3]; + int hasalphacolor=0; FILE *fi; U8 *scanline; @@ -509,6 +511,16 @@ int getPNG(char*sname, int*destwidth, int*destheight, unsigned char**destdata) alphapalettelen = len; data = 0; //don't free data //printf("found %d alpha colors\n", alphapalettelen); + } else if(header.mode == 0 || header.mode == 2) { + int t; + if(header.mode == 2) { + alphacolor[0] = data[1]; + alphacolor[1] = data[3]; + alphacolor[2] = data[5]; + } else { + alphacolor[0] = alphacolor[1] = alphacolor[2] = data[1]; + } + hasalphacolor = 1; } } if(!strncmp(tagid, "IDAT", 4)) { @@ -533,8 +545,9 @@ int getPNG(char*sname, int*destwidth, int*destheight, unsigned char**destdata) } printf("\n");*/ } - if(data) - free(data); + if(data) { + free(data); data=0; + } } if(!zimagedata || uncompress(imagedata, &imagedatalen, zimagedata, zimagedatalen) != Z_OK) { @@ -590,6 +603,7 @@ int getPNG(char*sname, int*destwidth, int*destheight, unsigned char**destdata) } } free(old); + free(imagedata); } else if(header.mode == 6 || header.mode == 2) { int i,s=0; int x,y; @@ -620,11 +634,24 @@ int getPNG(char*sname, int*destwidth, int*destheight, unsigned char**destdata) } else { old = &data2[(y-1)*header.width*4]; } - if(header.mode == 6) + if(header.mode == 6) { applyfilter4(mode, src, old, dest, header.width); - else // header.mode = 2 + } else { // header.mode = 2 applyfilter3(mode, src, old, dest, header.width); + /* replace alpha color */ + if(hasalphacolor) { + int x; + for(x=0;x