git » fp-git.git » commit b5cbed2

linked experimental pop2 file format extractor

author ecalot
2006-02-14 05:23:38 UTC
committer ecalot
2006-02-14 05:23:38 UTC
parent 00aa3cf66a41126f80deeb5685f2e81193ef3a75

linked experimental pop2 file format extractor

PR/src/Makefile +14 -2
PR/src/include/compress.h +23 -3
PR/src/lib/formats/bmp.c +1 -1
PR/src/lib/layers/autodetect.c +4 -3
PR/src/lib/layers/dat.c +1 -1
PR/src/lib/object/image/image16.c +30 -48
PR/src/lib/object/image/image2.c +30 -48
PR/src/lib/object/image/image256.c +30 -48
PR/src/lib/object/image/image_common.c +30 -48

diff --git a/PR/src/Makefile b/PR/src/Makefile
index a063909..453e7ae 100644
--- a/PR/src/Makefile
+++ b/PR/src/Makefile
@@ -53,8 +53,8 @@ endif
 
 ACTIONS  = .import.o .export.o .classify.o
 XML      = .parse.o .search.o .unknown.o .translate.o .tree.o
-COMPRESS = .compress.o .lzg_compress.o .lzg_uncompress.o .rle_compress.o .rle_uncompress.o 
-LAYERS   = .dat.o .memory.o .list.o .reslist.o .disk.o .idlist.o .autodetect.o .stringformat.o .resourcematch.o
+COMPRESS = .compress.o .lzg_compress.o .lzg_uncompress.o .rle_compress.o .rle_uncompress.o .rlec_uncompress.o 
+LAYERS   = .dat.o .memory.o .list.o .reslist.o .pallist.o .disk.o .idlist.o .autodetect.o .stringformat.o .resourcematch.o .palette.o
 FORMAT   = .bmp.o .mid.o .pal.o .wav.o .plv.o
 CONSOLE  = .main.o .filedir.o
 MAIN     = .pr.o
@@ -153,6 +153,10 @@ $(XMLFILE): xml/resources.xml
 	$(INFO) Compiling resource list module...
 	$(CC) $(OPTIONS) -c lib/layers/reslist.c -o $@
 
+.pallist.o: lib/layers/pallist.c include/memory.h include/pallist.h
+	$(INFO) Compiling palette list module...
+	$(CC) $(OPTIONS) -c lib/layers/pallist.c -o $@
+
 .compress.o: lib/compression/main.c include/compress.h include/disk.h include/memory.h
 	$(INFO) Compiling main compression library...
 	$(CC) $(OPTIONS) -c lib/compression/main.c -o $@
@@ -173,6 +177,10 @@ $(XMLFILE): xml/resources.xml
 	$(INFO) Compiling RLE uncompression module...
 	$(CC) $(OPTIONS) -c lib/compression/rle_uncompress.c -o $@
 
+.rlec_uncompress.o: lib/compression/rlec_uncompress.c include/compress.h
+	$(INFO) Compiling RLEC uncompression module...
+	$(CC) $(OPTIONS) -c lib/compression/rlec_uncompress.c -o $@
+
 .pr.o: lib/pr.c include/classify.h include/common.h include/disk.h include/export.h include/idlist.h include/import.h include/memory.h include/unknown.h
 	$(INFO) Compiling main library primitives for both modes...
 	$(CC) $(OPTIONS) -c lib/pr.c -o $@
@@ -209,6 +217,10 @@ $(XMLFILE): xml/resources.xml
 	$(INFO) Compiling unknown string format parsing feature...
 	$(CC) $(OPTIONS) -c lib/layers/stringformat.c -o $@
 
+.palette.o: lib/layers/palette.c include/common.h
+	$(INFO) Compiling the palette object support...
+	$(CC) $(OPTIONS) -c lib/layers/palette.c -o $@
+
 .resourcematch.o: lib/layers/resourcematch.c include/search.h include/memory.h include/resourcematch.h
 	$(INFO) Compiling resource list parsing feature...
 	$(CC) $(OPTIONS) -c lib/layers/resourcematch.c -o $@
diff --git a/PR/src/include/compress.h b/PR/src/include/compress.h
index fe09811..4907bff 100644
--- a/PR/src/include/compress.h
+++ b/PR/src/include/compress.h
@@ -66,7 +66,7 @@ typedef struct { /* TODO: move to image.h */
 	int height;
 	unsigned char* pix;
 	tPalette pal;
-	unsigned char type; /* XY where X=B if 4 bits or X=0 if 1 bit; Y=algorithm */
+	unsigned char type; /* XY where X is F for 8 bits, B for 4 bits and 0 for 1 bit; Y=algorithm */
 }tImage;
 
 /* Prototypes */
@@ -79,7 +79,27 @@ int mExpandGraphic  (const unsigned char* array,tImage *image, int size);
 #define setHigh   compressionHigher=1
 #define unsetHigh compressionHigher=0
 
-#define getCarry(a) ((a)>>6)
-#define getAlgor(a) a&0x4F
+#define getCarry(a) ((((a)>>4)&7)+1)
+#define getAlgor(a) a&0x4F /* 0x0F */
+
+/* private declarations */
+
+/***************************************************************\
+|                Internal compression prototypes                |
+\***************************************************************/
+
+/* compress and sets the bytes */
+void compressLzg(const unsigned char* input, int inputSize,
+                 unsigned char* output, int *outputSize);
+void compressRle(const unsigned char* input, int inputSize,
+                 unsigned char* output, int *outputSize);
+
+/* decompress and allocates output */
+int expandLzg(const unsigned char* input, int inputSize,
+               unsigned char** output, int *outputSize);
+int expandRle(const unsigned char* input, int inputSize,
+               unsigned char** output, int *outputSize);
+int expandRleC(const unsigned char* input, int inputSize,
+               unsigned char** output, int *outputSize,int verif);
 
 #endif
diff --git a/PR/src/lib/formats/bmp.c b/PR/src/lib/formats/bmp.c
index f0e96f4..5c8951e 100644
--- a/PR/src/lib/formats/bmp.c
+++ b/PR/src/lib/formats/bmp.c
@@ -106,7 +106,7 @@ int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupE
 	/* initialize variables */
 	width=img.width;
 	height=img.height;
-	bits=1<<getCarry(img.type);
+	bits=getCarry(img.type);
 	colours=1<<bits;
 	headerSize=40;
 	offset=54+(colours<<2);
diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c
index 2a4cd18..29ed9c9 100644
--- a/PR/src/lib/layers/autodetect.c
+++ b/PR/src/lib/layers/autodetect.c
@@ -52,10 +52,11 @@ int verifyLevelHeader(const unsigned char *array, int size) {
 
 int verifyImageHeader(const unsigned char *array, int size) {
 	unsigned char imageBitRate;
-	imageBitRate=((unsigned char)array[6]&0xF0);
-	return (size>7) && (!array[5]) && ((imageBitRate==0xB0));
+	if (size<=7) return 0; /* false */
+	imageBitRate=(( ((unsigned char)array[6])>>4 ) & 7)+1;
+	return (size>7) && (((unsigned char)array[5])<2) && ((imageBitRate==4 || imageBitRate==8));
 	/* NOTE:
-	 * return (size>7) && (!array[5]) && ((imageBitRate==0xB0)||(imageBitRate==0x00));
+	 *   imageBitRate==1
 	 * works for monochrome images (but is very common and matches more than that)
 	 */
 }
diff --git a/PR/src/lib/layers/dat.c b/PR/src/lib/layers/dat.c
index 5dbb1c5..cc21500 100644
--- a/PR/src/lib/layers/dat.c
+++ b/PR/src/lib/layers/dat.c
@@ -410,7 +410,7 @@ void dat_readRes(tResource* res, tIndexCursor indexCursor) {
 }
 
 void dat_releaseCursor(tIndexCursor* indexCursor) {
-	free(indexCursor->order);
+	if (0&&indexCursor->popVersion==pop2) free(indexCursor->order); /* TODO: check*/
 }
 
 /***************************************************************\
diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c
index eeb84e3..d90a859 100644
--- a/PR/src/lib/object/image/image16.c
+++ b/PR/src/lib/object/image/image16.c
@@ -86,23 +86,7 @@ compress.c: Princed Resources : Image Compression Library
 |                  I M P L E M E N T A T I O N                  |
 \***************************************************************/
 
-/***************************************************************\
-|                Internal compression prototypes                |
-\***************************************************************/
-
-/* compress and sets the bytes */
-void compressLzg(const unsigned char* input, int inputSize,
-                 unsigned char* output, int *outputSize);
-void compressRle(const unsigned char* input, int inputSize,
-                 unsigned char* output, int *outputSize);
-
-/* decompress and allocates output */
-int expandLzg(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize);
-int expandRle(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize);
-int expandRleC(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize,int verif);
+int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize); 
 
 /***************************************************************\
 |                   Compression Level Manager                   |
@@ -173,15 +157,28 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 	image->width =array2short(data);
 	data+=2;
 
-	if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */
+	if (*(data++)>1) return COMPRESS_RESULT_FATAL; /* Verify format */
 	image->type=(unsigned char)(*(data++));
 	dataSizeInBytes-=7;
-	if (image->type&0xB0) {
+	switch (((image->type>>4)&7)+1) {
+	case 8:
+		image->widthInBytes=(image->width);
+		break;
+	case 4: 
 		image->widthInBytes=(image->width+1)/2;
-	} else {
+		break;
+	case 1:
 		image->widthInBytes=(image->width+7)/8;
+		break;
+	default:
+		return COMPRESS_RESULT_FATAL;
 	}
 
+	/* special format has a special function */
+	if (image->type==0xf3)
+		return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes);
+
+
 #define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
 	return COMPRESS_RESULT_FATAL
 #define checkResult if (result==COMPRESS_RESULT_FATAL)\
@@ -358,46 +355,31 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) {
 	return 1; /* true */
 }
 
-void pop2decompress(const char* from, const char* rle, const char* pix) { 
+int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) { 
 	/* This function is in an experimental state and hasn't yet been linked to the program */
-	unsigned char* input;
-	unsigned char* output;
-	unsigned char* output2;
+	unsigned char* tempOutput;
 
-	int width;
-	int is,os,os2,os3;
+	int tempOutputSize;
 	int osCheck;
-	FILE* out;
 
-	is=mLoadFileArray(from,&input);
-	if (!is) {
-		printf("Error\n");
-		return;
-	}
-	osCheck=input[7]<<8|input[6];
+	osCheck=array2short(input)-6;
+	input+=2;
 
-	printf("w=%d h=%d\n",width=input[3]<<8|input[2],input[1]<<8|input[0]);
-
-
-	out=fopen(rle,"wb");
-	os=osCheck;
-	printf("lzg=%d\n", os3=expandLzg(input+8,is-8,&output,&os));
-	fwrite(output,os,1,out);
-	fclose(out);
-
-	out=fopen(pix,"wb");
-	printf("rle=%d\n", expandRleC(output,os,&output2,&os2,width));
-	fwrite(output2,os2,1,out);
+	/*os=osCheck;*/
+	tempOutputSize=0;
+	printf("lzg=%d is=%d osc=%d\n", expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize),inputSize,osCheck);
 
+	printf("rle=%d\n", expandRleC(tempOutput,tempOutputSize,output,outputSize,verify));
+/*
 	printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os));
 	osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2];
 
-	printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,width), osCheck);
+	printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,verify), osCheck);
 	fwrite(output2,os2,1,out);
 
 	fclose(out);
 
-	printf("os=%d oscheck=%d\n",os,osCheck);
-	return;
+	printf("os=%d oscheck=%d\n",os,osCheck);*/
+	return COMPRESS_RESULT_SUCCESS;
 }
 
diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c
index eeb84e3..d90a859 100644
--- a/PR/src/lib/object/image/image2.c
+++ b/PR/src/lib/object/image/image2.c
@@ -86,23 +86,7 @@ compress.c: Princed Resources : Image Compression Library
 |                  I M P L E M E N T A T I O N                  |
 \***************************************************************/
 
-/***************************************************************\
-|                Internal compression prototypes                |
-\***************************************************************/
-
-/* compress and sets the bytes */
-void compressLzg(const unsigned char* input, int inputSize,
-                 unsigned char* output, int *outputSize);
-void compressRle(const unsigned char* input, int inputSize,
-                 unsigned char* output, int *outputSize);
-
-/* decompress and allocates output */
-int expandLzg(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize);
-int expandRle(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize);
-int expandRleC(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize,int verif);
+int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize); 
 
 /***************************************************************\
 |                   Compression Level Manager                   |
@@ -173,15 +157,28 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 	image->width =array2short(data);
 	data+=2;
 
-	if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */
+	if (*(data++)>1) return COMPRESS_RESULT_FATAL; /* Verify format */
 	image->type=(unsigned char)(*(data++));
 	dataSizeInBytes-=7;
-	if (image->type&0xB0) {
+	switch (((image->type>>4)&7)+1) {
+	case 8:
+		image->widthInBytes=(image->width);
+		break;
+	case 4: 
 		image->widthInBytes=(image->width+1)/2;
-	} else {
+		break;
+	case 1:
 		image->widthInBytes=(image->width+7)/8;
+		break;
+	default:
+		return COMPRESS_RESULT_FATAL;
 	}
 
+	/* special format has a special function */
+	if (image->type==0xf3)
+		return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes);
+
+
 #define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
 	return COMPRESS_RESULT_FATAL
 #define checkResult if (result==COMPRESS_RESULT_FATAL)\
@@ -358,46 +355,31 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) {
 	return 1; /* true */
 }
 
-void pop2decompress(const char* from, const char* rle, const char* pix) { 
+int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) { 
 	/* This function is in an experimental state and hasn't yet been linked to the program */
-	unsigned char* input;
-	unsigned char* output;
-	unsigned char* output2;
+	unsigned char* tempOutput;
 
-	int width;
-	int is,os,os2,os3;
+	int tempOutputSize;
 	int osCheck;
-	FILE* out;
 
-	is=mLoadFileArray(from,&input);
-	if (!is) {
-		printf("Error\n");
-		return;
-	}
-	osCheck=input[7]<<8|input[6];
+	osCheck=array2short(input)-6;
+	input+=2;
 
-	printf("w=%d h=%d\n",width=input[3]<<8|input[2],input[1]<<8|input[0]);
-
-
-	out=fopen(rle,"wb");
-	os=osCheck;
-	printf("lzg=%d\n", os3=expandLzg(input+8,is-8,&output,&os));
-	fwrite(output,os,1,out);
-	fclose(out);
-
-	out=fopen(pix,"wb");
-	printf("rle=%d\n", expandRleC(output,os,&output2,&os2,width));
-	fwrite(output2,os2,1,out);
+	/*os=osCheck;*/
+	tempOutputSize=0;
+	printf("lzg=%d is=%d osc=%d\n", expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize),inputSize,osCheck);
 
+	printf("rle=%d\n", expandRleC(tempOutput,tempOutputSize,output,outputSize,verify));
+/*
 	printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os));
 	osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2];
 
-	printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,width), osCheck);
+	printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,verify), osCheck);
 	fwrite(output2,os2,1,out);
 
 	fclose(out);
 
-	printf("os=%d oscheck=%d\n",os,osCheck);
-	return;
+	printf("os=%d oscheck=%d\n",os,osCheck);*/
+	return COMPRESS_RESULT_SUCCESS;
 }
 
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index eeb84e3..d90a859 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -86,23 +86,7 @@ compress.c: Princed Resources : Image Compression Library
 |                  I M P L E M E N T A T I O N                  |
 \***************************************************************/
 
-/***************************************************************\
-|                Internal compression prototypes                |
-\***************************************************************/
-
-/* compress and sets the bytes */
-void compressLzg(const unsigned char* input, int inputSize,
-                 unsigned char* output, int *outputSize);
-void compressRle(const unsigned char* input, int inputSize,
-                 unsigned char* output, int *outputSize);
-
-/* decompress and allocates output */
-int expandLzg(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize);
-int expandRle(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize);
-int expandRleC(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize,int verif);
+int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize); 
 
 /***************************************************************\
 |                   Compression Level Manager                   |
@@ -173,15 +157,28 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 	image->width =array2short(data);
 	data+=2;
 
-	if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */
+	if (*(data++)>1) return COMPRESS_RESULT_FATAL; /* Verify format */
 	image->type=(unsigned char)(*(data++));
 	dataSizeInBytes-=7;
-	if (image->type&0xB0) {
+	switch (((image->type>>4)&7)+1) {
+	case 8:
+		image->widthInBytes=(image->width);
+		break;
+	case 4: 
 		image->widthInBytes=(image->width+1)/2;
-	} else {
+		break;
+	case 1:
 		image->widthInBytes=(image->width+7)/8;
+		break;
+	default:
+		return COMPRESS_RESULT_FATAL;
 	}
 
+	/* special format has a special function */
+	if (image->type==0xf3)
+		return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes);
+
+
 #define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
 	return COMPRESS_RESULT_FATAL
 #define checkResult if (result==COMPRESS_RESULT_FATAL)\
@@ -358,46 +355,31 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) {
 	return 1; /* true */
 }
 
-void pop2decompress(const char* from, const char* rle, const char* pix) { 
+int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) { 
 	/* This function is in an experimental state and hasn't yet been linked to the program */
-	unsigned char* input;
-	unsigned char* output;
-	unsigned char* output2;
+	unsigned char* tempOutput;
 
-	int width;
-	int is,os,os2,os3;
+	int tempOutputSize;
 	int osCheck;
-	FILE* out;
 
-	is=mLoadFileArray(from,&input);
-	if (!is) {
-		printf("Error\n");
-		return;
-	}
-	osCheck=input[7]<<8|input[6];
+	osCheck=array2short(input)-6;
+	input+=2;
 
-	printf("w=%d h=%d\n",width=input[3]<<8|input[2],input[1]<<8|input[0]);
-
-
-	out=fopen(rle,"wb");
-	os=osCheck;
-	printf("lzg=%d\n", os3=expandLzg(input+8,is-8,&output,&os));
-	fwrite(output,os,1,out);
-	fclose(out);
-
-	out=fopen(pix,"wb");
-	printf("rle=%d\n", expandRleC(output,os,&output2,&os2,width));
-	fwrite(output2,os2,1,out);
+	/*os=osCheck;*/
+	tempOutputSize=0;
+	printf("lzg=%d is=%d osc=%d\n", expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize),inputSize,osCheck);
 
+	printf("rle=%d\n", expandRleC(tempOutput,tempOutputSize,output,outputSize,verify));
+/*
 	printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os));
 	osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2];
 
-	printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,width), osCheck);
+	printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,verify), osCheck);
 	fwrite(output2,os2,1,out);
 
 	fclose(out);
 
-	printf("os=%d oscheck=%d\n",os,osCheck);
-	return;
+	printf("os=%d oscheck=%d\n",os,osCheck);*/
+	return COMPRESS_RESULT_SUCCESS;
 }
 
diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c
index eeb84e3..d90a859 100644
--- a/PR/src/lib/object/image/image_common.c
+++ b/PR/src/lib/object/image/image_common.c
@@ -86,23 +86,7 @@ compress.c: Princed Resources : Image Compression Library
 |                  I M P L E M E N T A T I O N                  |
 \***************************************************************/
 
-/***************************************************************\
-|                Internal compression prototypes                |
-\***************************************************************/
-
-/* compress and sets the bytes */
-void compressLzg(const unsigned char* input, int inputSize,
-                 unsigned char* output, int *outputSize);
-void compressRle(const unsigned char* input, int inputSize,
-                 unsigned char* output, int *outputSize);
-
-/* decompress and allocates output */
-int expandLzg(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize);
-int expandRle(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize);
-int expandRleC(const unsigned char* input, int inputSize,
-               unsigned char** output, int *outputSize,int verif);
+int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize); 
 
 /***************************************************************\
 |                   Compression Level Manager                   |
@@ -173,15 +157,28 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 	image->width =array2short(data);
 	data+=2;
 
-	if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */
+	if (*(data++)>1) return COMPRESS_RESULT_FATAL; /* Verify format */
 	image->type=(unsigned char)(*(data++));
 	dataSizeInBytes-=7;
-	if (image->type&0xB0) {
+	switch (((image->type>>4)&7)+1) {
+	case 8:
+		image->widthInBytes=(image->width);
+		break;
+	case 4: 
 		image->widthInBytes=(image->width+1)/2;
-	} else {
+		break;
+	case 1:
 		image->widthInBytes=(image->width+7)/8;
+		break;
+	default:
+		return COMPRESS_RESULT_FATAL;
 	}
 
+	/* special format has a special function */
+	if (image->type==0xf3)
+		return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes);
+
+
 #define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
 	return COMPRESS_RESULT_FATAL
 #define checkResult if (result==COMPRESS_RESULT_FATAL)\
@@ -358,46 +355,31 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) {
 	return 1; /* true */
 }
 
-void pop2decompress(const char* from, const char* rle, const char* pix) { 
+int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) { 
 	/* This function is in an experimental state and hasn't yet been linked to the program */
-	unsigned char* input;
-	unsigned char* output;
-	unsigned char* output2;
+	unsigned char* tempOutput;
 
-	int width;
-	int is,os,os2,os3;
+	int tempOutputSize;
 	int osCheck;
-	FILE* out;
 
-	is=mLoadFileArray(from,&input);
-	if (!is) {
-		printf("Error\n");
-		return;
-	}
-	osCheck=input[7]<<8|input[6];
+	osCheck=array2short(input)-6;
+	input+=2;
 
-	printf("w=%d h=%d\n",width=input[3]<<8|input[2],input[1]<<8|input[0]);
-
-
-	out=fopen(rle,"wb");
-	os=osCheck;
-	printf("lzg=%d\n", os3=expandLzg(input+8,is-8,&output,&os));
-	fwrite(output,os,1,out);
-	fclose(out);
-
-	out=fopen(pix,"wb");
-	printf("rle=%d\n", expandRleC(output,os,&output2,&os2,width));
-	fwrite(output2,os2,1,out);
+	/*os=osCheck;*/
+	tempOutputSize=0;
+	printf("lzg=%d is=%d osc=%d\n", expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize),inputSize,osCheck);
 
+	printf("rle=%d\n", expandRleC(tempOutput,tempOutputSize,output,outputSize,verify));
+/*
 	printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os));
 	osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2];
 
-	printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,width), osCheck);
+	printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,verify), osCheck);
 	fwrite(output2,os2,1,out);
 
 	fclose(out);
 
-	printf("os=%d oscheck=%d\n",os,osCheck);
-	return;
+	printf("os=%d oscheck=%d\n",os,osCheck);*/
+	return COMPRESS_RESULT_SUCCESS;
 }