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)) {
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];
}
struct png_header header;
int bypp;
U8*data2 = 0;
+ U8 alphacolor[3];
+ int hasalphacolor=0;
FILE *fi;
U8 *scanline;
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)) {
}
printf("\n");*/
}
- if(data)
- free(data);
+ if(data) {
+ free(data); data=0;
+ }
}
if(!zimagedata || uncompress(imagedata, &imagedatalen, zimagedata, zimagedatalen) != Z_OK) {
}
}
free(old);
+ free(imagedata);
} else if(header.mode == 6 || header.mode == 2) {
int i,s=0;
int x,y;
else // header.mode = 2
applyfilter3(mode, src, old, dest, header.width);
}
+ free(imagedata);
} else if(header.mode == 0 || header.mode == 3) {
COL*rgba = 0;
U8*tmpline = (U8*)malloc(header.width+1);
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) {
} 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;
+ }
}
}
free(tmpline);
free(destline);
free(rgba);
+ free(imagedata);
} else {
printf("expected PNG mode to be 2, 3 or 6 (is:%d)\n", header.mode);
return 0;
}
datalen2 = datalen3;
- data2 = malloc(datalen2);
+ data2 = (U8*)malloc(datalen2);
if((ret = compress (data2, &datalen2, data3, datalen3)) != Z_OK) {
fprintf(stderr, "zlib error in pic %d\n", ret);