X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpng.c;h=f114e915525e61696614375921e190d07ae93712;hb=e0416f8532436f9570db3f72be075475d2e99c76;hp=c1ce8d0859d17ad2c27ada312c6f4330b48a8f4b;hpb=608c6b4c741f4f26258e7158c922b1215b855f25;p=swftools.git diff --git a/lib/png.c b/lib/png.c index c1ce8d0..f114e91 100644 --- a/lib/png.c +++ b/lib/png.c @@ -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)) { @@ -643,6 +655,10 @@ int getPNG(char*sname, int*destwidth, int*destheight, unsigned char**destdata) rgba[i].r = i*mult; rgba[i].g = i*mult; rgba[i].b = i*mult; + if(hasalphacolor) { + if(rgba[i].r == alphacolor[0]) + rgba[i].a = 0; + } } } else { if(!palette) { @@ -663,6 +679,12 @@ int getPNG(char*sname, int*destwidth, int*destheight, unsigned char**destdata) } else { rgba[i].a = 255; } + if(hasalphacolor) { + if(rgba[i].r == alphacolor[0] && + rgba[i].g == alphacolor[1] && + rgba[i].b == alphacolor[2]) + rgba[i].a = 0; + } } }