+ int i,s=0;
+ int x,y;
+ int pos=0;
+ unsigned char* old= (unsigned char*)malloc(header.width*2);
+ memset(old, 0, header.width*2);
+ *destdata = data2;
+ for(y=0;y<header.height;y++) {
+ int mode = imagedata[pos++]; //filter mode
+ unsigned char*src;
+ unsigned char*dest;
+ int x;
+ dest = &data2[(y*header.width)*4];
+
+ if(header.bpp == 8) {
+ /* one byte per pixel */
+ src = &imagedata[pos];
+ pos+=header.width*2;
+ } else {
+ /* not implemented yet */
+ fprintf(stderr, "ERROR: mode=4 bpp:%d\n", header.bpp);
+ free(data2);
+ return 0;
+ }
+
+ applyfilter2(mode, src, old, dest, header.width);
+ memcpy(old, dest, header.width*2);
+
+ for(x=header.width-1;x>=0;x--) {
+ unsigned char gray = dest[x*2+0];
+ unsigned char alpha = dest[x*2+1];
+ dest[x*4+0] = alpha;
+ dest[x*4+1] = gray;
+ dest[x*4+2] = gray;
+ dest[x*4+3] = gray;
+ }
+ }
+ free(old);
+ free(imagedata);
+ } else if(header.mode == 6 || header.mode == 2) {